SUBST problem



On 10/12/06, Dominique MICOLLET > (%i1) f(x):=a*x+b;
> (%i3) f_n(x):=subst(%,f(x));
> (%o3)                      f_n(x) := SUBST(%, f(x))
> (%i4) f_n(2);
> Improper argument to SUBST:

Nothing in a function definition is evaluated when you define it --
only when you call it.  You can see this in your %o3 line.

To substitute in a value at function-definition time, use the special
operation '' (two single-quotes in a row):

(%o2)  27
(%i3)  f():= ''%;
(%o3)                                     f() := 27

If you want to evaluate an entire expression at function-definition
time, enclose it in ''( ... ).  Consider:

     h(x) := factor(x^2-1);
        =>
           h(x) := factor(x^2-1)
vs.
     g(x) := ''(factor(x^2-1));
         =>
        g(x):= (x-1)*(x+1)

    h(sqrt(5)) => 2*2
    g(sqrt(5)) => (sqrt(5)-1)*(sqrt(5)+1)

Hope this helps.

                -s