Define a variable which evaluates when expression is evaluated, but not substitutes its definition to expression

Viewed 47

Let's say, I want to declare an elliptic integral as

K(k):=elliptic_kc (k^2);

k:=<something like tanh()*coth()...>

The problem is that maxima will always substitute elliptic_kc(x^2) in place of K(x), and k's definition in place of k. I want to prevent it, while still allowing numeric evaluation of K(), k, and simplifying expressions with these symbols.

... A function, can be declared as "noun" for disabling substitution. But this also disables its evaluation.

1 Answers

Well, I use various strategies. Sometimes one approach works better than another.

(1) Put a single quote ' on function names to nounify that specific function call. At a later time, ev(expr, nouns) verbifies any nouns, so the functions are called. E.g. foo: 'integrate(sin(x), x); yields a noun expression. Then ev(foo, nouns); (which can be abbreviated to foo, nouns; at the console input) to actually calculate it.

(2) Don't define functions, but just let them be undefined symbols. Then substitute a lambda expression when you want to evaluate them. E.g. foo: f(2); then later subst(f = lambda([x], x + 1), foo);.

(3) Don't assign values, but let them be undefined, then substitute values later on. E.g. foo: a + b; then later subst([a = 123, b = y*z], foo);.

Related