Thanks for the information.
I would still like to know where
SIMP, MEXPT, MDEFINE
etc are defined in the source files.
-sen
On Fri, 19 Jan 2007, Stavros Macrakis wrote:
>> In maxima, one can get the following lines
>> (%i5) f(x):= x^2;
>> 2
>> (%o5) f(x) := x
>> (%i6) ?print(%);
>> ((MDEFINE SIMP) (($F) $X) ((MEXPT) $X 2))
>>
>> So, the function (latex notation) $f(x) = x^2$ has the (I suppose)
>> maxima lisp representation as
>>
>> ((MDEFINE SIMP) (($F) $X) ((MEXPT) $X 2))
>
> I'm not sure what the relevance of the Latex form is here, but...
>
>> In gcl, one would define this function as
>> (defun f (x) (expt x 2))
>> Of course there is a similarity, but these are *not* the same.
>
> They are very different. In Lisp, "expt" is a function which gets
> executed. In Maxima, mexpt is an expression constructor which is
> simplified. There is not mexpt function in Maxima -- it *represents*
> exponentiation.
>
> To evaluate (expt x 2), Lisp calls an internal function on the value
> of x (which must be a number) and 2.
>
> To evaluate ((mexpt) x 2), Maxima first substitutes the value of x
> into that expression giving, e.g. ((mexpt) 3 2). The main simplifier
> routine looks up the simplification routine for mexpt, which is on its
> property list. simpexpt then transforms that expression to 9.
>
> In the case of a symbolic expression, Lisp of course will simply give an error.
>
> The Maxima expression f(2*y) first evaluates and simplifies the
> argument 2*y, giving
> ((mtimes simp) 2 $y)
> It then substitutes that value for the formal variable $x, giving
> ((mexpt) ((mtimes simp) 2 $y) 2)
> Conceptually, the simpexpt routine transforms this to
> ((mtimes) ((mexpt) 2 2) ((mexpt simp) $y 2))
> The inner ((mexpt) 2 2) is simplified to 4, and the overall expression
> is simplified by simptimes to
> ((mtimes simp) 4 ((mexpt simp) $y 2))
>
> I hope that makes things clearer.
>
> If you want to see this in action, try
>
> f(x):=x^2$
> ?trace(?meval,?simplifya,?simptimes,?simplus)$
> f(2*y)$
>
> To turn off Lisp tracing, ?untrace()
>
> -s
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
--
---------------------------------------------------------------------------
| Sheldon E. Newhouse | e-mail: sen1 at math.msu.edu |
| Mathematics Department | |
| Michigan State University | telephone: 517-355-9684 |
| E. Lansing, MI 48824-1027 USA | FAX: 517-432-1562 |
---------------------------------------------------------------------------