Search code examples
listmaxima

Evaluate expression using lists maxima


I'd like the result of the below maxima input to be [6,12,18] but it results in 2ac. Can anyone help?

a:2;
c:[1,2,3];
b:'(a*c);
''b;
a:3;
''b;
f:'(b*2);
''f;

Solution

  • I think ev(f, infeval) is what you want. See ? ev for info about infeval and other evaluation flags.

    (%i1) c : [1, 2, 3];
    (%o1)                              [1, 2, 3]
    (%i2) b : '(a*c);
    (%o2)                                 a c
    (%i3) a : 3;
    (%o3)                                  3
    (%i4) f : '(b*2);
    (%o4)                                 2 b
    (%i5) f;
    (%o5)                                 2 b
    (%i6) ''f;
    (%o6)                                2 a c
    (%i7) ev (f);
    (%o7)                                2 a c
    (%i8) ev (f, infeval);
    (%o8)                             [6, 12, 18]
    

    You can also write ev(f, infeval); as just f, infeval; at the input prompt.

    That said, my advice is, don't try too hard to find tricky ways to evaluate stuff. It's easy to write something which has unexpected results and hard to understand. You'll have to find a balance between trying to get Maxima to do what your want, and accommodating Maxima's idiosyncrasies (i.e. changing your ideas to match Maxima's).