[Maxima] Newbie question about quotation
macrakis at alum.mit.edu
Wed Dec 27 09:45:46 CST 2006
> How does one create a function in maxima like "sum(-) " which
> protects its first argument against premature evaluation?
Well, the direct answer is to use a macro definition --
describe("::="). In general, I think this is a bad idea, because it
complicates the meaning of your program and makes it hard to compose
functionality naturally. We recently went through this discussion
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
ff(k) := if oddp(k) then 0 else if evenp(k) then 1 else funmake(ff,k)
This works better even with 'sum'. Try, for example sum(ff(i),i,0,n)
with your definition and with this definition. Unfortunately, neither
solution works perfectly -- if you later substitute 3 for n in the
result of the above sum, Maxima doesn't evaluate the ff's until you
explicitly ask it to (using ev(...,ff) or ev(...,nouns) ). This is
partly because 'sum' is a bit too clever; I believe we will need to
revise it when we come up with a better solution (which we don't have
You can also specify that your function should take a quoted argument.
More information about the Maxima