building long expressions



Several approaches are possible here.

One is infeval, as Robert suggested.

Another is to define things bottom-up instead of top-down:

     c: f+g$
     b:d+e$
     a:b+c$

Another is to use functions:

     a():= b() + c()$
     b():=d()+e()$
etc.
     then call a().  If a function is not explicitly defined, the function
call will remain in symbolic form.

I do *not* recommend using ''xxx -- this substitutes the value of xxx at
expression-reading time, and so can be useful in some cases (e.g. when
defining a function by substituting in calculated expressions), but ***will
not work as you expect in code***.

I would also be very careful with infeval, but it can still be useful.

          -s

On Thu, May 19, 2011 at 01:43, Steven Boege <sjboege at yahoo.com> wrote:

> I would like to build long expressions or functions.
>
> I tried it this way:
>
> (%i1) a:b+c;
> (%o1)                                c + b
> (%i2) b:d+e;
> (%o2)                                e + d
> (%i3) c:f+g;
> (%o3)                                g + f
> (%i4) a;
> (%o4)                                c + b
>
> I was hoping to see
>
> (%o4)                                g + f + e + d
>
> instead of
>
> (%o4)                                c + b
>
> So then I read a few tutorials and realized that I needed to tell Maxima to
> recalculate a.
>
> (%i5) ''a;
> (%o5)                            g + f + e + d
>
> OK.
>
> Next I tried to change one of the values upon which a is dependent:
>
> %i6) a;
> (%o6)                                c + b
> (%i7) d:0;
> (%o7)                                  0
> (%i8) ''a;
> (%o8)                            g + f + e + d
> (%i9) d;
> (%o9)                                  0
> (%i10) ''a;
> (%o10)                           g + f + e + d
>
> So d was set to 0, but a doesn't realize that.  I clearly am looking at
> this wrong.  Since d = 0, please explain why I didn't get:
>
> (%o10)                           g + f + e
>
> Next I tried functions:
> %i1) a(x):=b(x)+c(x);
> (%o1)                         a(x) := b(x) + c(x)
> (%i2) b(x):=d(x)+e(x);
> (%o2)                         b(x) := d(x) + e(x)
> (%i3) c(x):=f(x)+g(x);
> (%o3)                         c(x) := f(x) + g(x)
> (%i4) a(x);
> (%o4)                      g(x) + f(x) + e(x) + d(x)
> (%i5)  g(x):= value1;
> (%o5)                           g(x) := value1
> (%i6) f(x):=value2;
> (%o6)                           f(x) := value2
> (%i7) e(x):=value3;
> (%o7)                           e(x) := value3
> (%i8) d(x):=value4;
> (%o8)                           d(x) := value4
> (%i9) a(x);
> (%o9)                  value4 + value3 + value2 + value1
> (%i10) value4:0;
> (%o10)                                 0
> (%i11) a(x);
> (%o11)                     value3 + value2 + value1
>
> This seems to work.  But how would I clear the definition for value4?
> Also, I had to add "(x)" to the function definitions even though it's not
> really a function of x.  But if I leave the "(x)" out, Maxima complains.
>
> I looked for answers in the faq, but didn't find anything.  Thanks for
> reading.  Please consider taking a few minutes to get me rolling with this.
>
> Steve
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>