Search code examples
maxima

Substitute variable?


I'm trying to substitute L with :

f(x) := c * (x + L);
c: L;
f(x), L: Lα;

I expected the output:

Lα * (x + Lα)

instead I got

L * (x + Lα)

Maybe I should define f(x) instead?

kill(all);

define(
  f(x),
  c * (x + L)
);

c: L;
f(x), L: Lα;

Nope — same result.

Do I substitute L for in a wrong way?

Edit:

Turns out it is expected behaviour, as maxima evavluates expression only once. One can impose "infinite evaluation" via the flag infeval:

f(x), L: La, infeval;
 => La*(x + La)

Another solution is to use subst instead:

subst(
  Lα, L, f(x)
  );

(source)


Solution

  • You need to add an extra eval step to make this work:

    f(x) := c * (x + L);
    c: L;
    f(x), L: Lα, eval;
    

    Output:

    Lα (x + Lα)