Adobe
Adobe

Reputation: 13467

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)

Upvotes: 0

Views: 4717

Answers (2)

Jaime Villate
Jaime Villate

Reputation: 261

Use subst instead of ev.

(%i1) f(x) := c * (x + L)$
(%i2) c: L$
(%i3) subst(L=La,f(x));
(%o3) La (x + La)

But keep in mind that the function continues to be c*(x+L). The symbol c has been bound to L and if you then bind the symbol L to La, c will continue to be bound to L and not to La. Maxima variables work as in Lisp, which might be different to what you are used to in other languages.

Upvotes: 0

Thor
Thor

Reputation: 47089

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α)

Upvotes: 1

Related Questions