On 5/16/07, Ryan Krauss <ryanlists at gmail.com> wrote:
>
> This seems really powerful and I am increasingly interested in
> learning to program in Maxima (and I planning to learn more lisp for
> emacs anyways). Can you give me a bit more explanation on the divsimp
> function. A brief comment for each line would help me learn a lot.
>
divsimp(ex,div):=
if atom(ex) /* Is ex a symbol or a number? i.e. has no
subparts */
then ex /* if so, return it */
elseif part(ex,0)="+" /* part 0 of an expression is its operator:
a+b+c is equivalent to "+"(a,b,c)
*/
then block( /* a block is like begin/end or {} -- it groups
a series of statements, possibly
with local variables */
[quorem /* list of local variables */
: /* can be initialized using var:val
instead of just var */
divide(ex,div)] /* divides ex by div and
returns [<quotient>,<remainder>] as a list */
, /* statements separated with commas */
factorsum(quorem[1]) /* quorem[1] is the quotient --
apply factorsum to it */
*factorsum(div)
+ factorsum(quorem[2]) /* quorem[2] is the remainder */
) /* close off the block */
else map( /* map a function over expression subparts; map(f,a*b) ==
f(a)*f(b)
lambda([q],divsimp(q,div)), /* lambda([q],...) is an
anonymous function, like
defining
fff(q):=... and then using fff here */
ex)$
To see what is going on, try trace(divsimp).
-s