Search code examples
maxima

Maxima - Effect of the commas when not in a function


With Maxima, it is possible to replace an unknown by a value using at() statement. But this use a list, for the substitution, and the solve() statement don't return a list.

Code:

(%i1) g(x):=x^2+a;
                                         2
(%o1)                           g(x) := x  + a
(%i2) g(x),solve(x=3),a=2;
(%o2)                                11

I managed to compute a result using commas, but I can't create a function to do so:

(%i3) f(y) := g(x),solve(x=3),a=y;
(%o3)                          f(y) := g(x)
(%i4) f(2);
                                2
(%o4)                          x  + a

Is there a statement for which the commas acts like it acts directly in the line?


Edit:
Actually, it is possible to use at() with solve() to create the function f(), as solve() just return a list of lists. So the code would be:

(%i5) f(y) := at(at(g(x), solve(x=3)[1]), a=y);
(%o5)             f(y) := at(at(g(x), solve(x = 3) ), a = y)
(%i6) f(2);
(%o6)                                 11

Notice the [1] after solve(x=3) in the (%i5). It select the the first item (solution) of list.


Solution

  • Perhaps I'm answering the wrong question. Maybe what you want is ev(foo, bar, baz) -- ev is the function that is actually called when you write foo, bar, baz at the console input prompt. So the function would be written f(y) := ev (g(x), solve(x=3), a=y).

    However, bear in mind that there are several different kinds of functionality built into ev, so it is hard to understand (see the documentation for ev). Instead, consider using subst which is much simpler.