> De : Albert Reiner
> Envoyé : mardi 26 avril 2005 14:14
> À : maxima@math.utexas.edu
>
> ["laurent couraud" , Tue, 26 Apr 2005 00:23:48 +0200]:
> > In fact the final goal is to compute the number of atom in an EXPANDed form of expression.
> >
> > To do that I have tried:
> ...
>
> You might want to try something like the following:
>
> ,----
> | natoms(expr) :=
> | if expr = 0
> | then 0
> | else if atom(expr)
> | then 1
> | else 0 + apply("+", maplist(natoms, args(expr))) $
> ^
> --------------'
> |
> | natoms(0); ==> 0 //
> | natoms(1); ==> 1 //
> | natoms(a+b); ==> 2 //
> | natoms(a+b+(c*2^(3+a))); ==> 6 //
> `----
>
Thanks, but it is not really what I want.
I want to count only formal parameters/varies.
For example :
If I call your natoms() function on "2*a+5*b" I take 4 but what I want is 2.
And when I have a power I want that natoms give me the value of the power.
To define more precisely the result that I want :
For simplicity and generality suppose that m, n, p, are numeric integer.
And x1, x2, ...... xi are formal parameters or varies.
Natoms(0) => 0
Natoms(n) => 1
Natoms(x1) => 1
Natoms(x1+x2) => 2
Natoms(n*x1+m*x2) => 2
Natoms(x1-x2) => 2
Natoms(n*x1-m*x2) => 2
Natoms(x1^n) => n
Natoms(n*x1-m*x2*x3^p) => p+2
> In most cases mapatom() is more likely to be what you want than
> atom(), BTW.
In fact with your function I have discover the function args().
Then when I did a bad call on it I saw that it call fullmap.
I think that fullmap is more appropriate for what I want because mapatom
give a Boolean.
Note that:
1) natoms is called always on fully expanded expressions
2) Expressions are only polynomial with only _numeric_ power
then I don't have a case like c*2^(3+a)
I want that natoms reflect in a particular way the "complexity" of expression,
And, for that, formal parameters or varies have more weight than
numeric coefficient. This is the reason for what I don't want to count numeric
coefficient. For power, a^2 is like a*a then it count as 2 atoms
in "my complexity".
Laurent