On 12/27/06, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
> I think it is a better idea to (a) write the underlying functions so
> they act better and (b) quote when necessary. In the longer term,
> this is a problem we need to deal with in a more general way.
>
> For your function ff, instead of writing
>
> > ff(k):=if oddp(k) then 0 else 1
>
> try
>
> ff(k) := if oddp(k) then 0 else if evenp(k) then 1 else funmake(ff,k)
This is really an illustration of one of Maxima's weakest points --
the obvious thing (i.e., what is consistent with other aspects of
Maxima) doesn't work.
The underlying problem is that Maxima's Boolean functions
were all originally implemented solely as programming constructs.
It is more useful to handle unevaluated Boolean and conditional
expressions just like unevaluated arithmetic expressions.
The naive definition of ff works OK when oddp returns true or false
only for integers and Maxima is comfortable with unevaluated
conditional expressions:
:lisp (defun $oddp (x) (if ($integerp x) (equal ($remainder x 2) 1)
`(($oddp) ,x)))
load (boolsimp);
oddp (a + b);
=> oddp(b + a)
ff(k):=if oddp(k) then 0 else 1;
ff (i);
=> if oddp(i) then 0 else 1
sum (ff(i), i, 0, 10);
=> 6
sum (ff(i), i, 0, n);
=> 'sum(if oddp(i) then 0 else 1,i,0,n)
ev (%, n = 10);
=> (if oddp(10) then 0 else 1) + (if oddp(9) then 0 else 1)
+ (if oddp(8) then 0 else 1) + (if oddp(7) then 0 else 1)
+ (if oddp(6) then 0 else 1) + (if oddp(5) then 0 else 1)
+ (if oddp(4) then 0 else 1) + (if oddp(3) then 0 else 1)
+ (if oddp(2) then 0 else 1) + (if oddp(1) then 0 else 1)
+ (if oddp(0) then 0 else 1)
ev (%);
=> 6
The long (if oddp(10) then 0 else 1) + ... probably would not be
produced if oddp were a simplifying function.
The general solution to this problem and others like it, I believe,
is just to make Maxima treat Boolean expressions like arithmetic ones.
This is well within reach.
All the best,
Robert Dodier