ev() do not work



Yet another way is with subscripted values:

g[0,0]:1$
g[1,1]:-1$
etc.

Then you can (or not) also define the general case as a memoizing function:

g[x,y] := ...

Be careful about the semantics of this: g[x,y]:= defines a "memoizing
function", where it is assumed that g is a function of x and y only and
does not change with time; it remembers any values it calculates.

          -s

On Fri, Dec 14, 2012 at 11:03 AM, Robert Dodier <robert.dodier at gmail.com>wrote:

> On 2012-12-14, Dmitry Shkirmanov <piminusmeson at bk.ru> wrote:
>
> > (%i1) g(mu,nu):= if (mu=0 and nu =0) then  1
> >         elseif (mu=1 and nu =1) then -1
> >         elseif (mu=2 and nu =2) then -1
> >         elseif (mu=3 and nu =3) then -1
> >         elseif (   mu#nu   and ((mu=1 or mu=2 or mu=3 or mu=0)and(nu=1
> > or nu=2 or nu=3 or nu=0))   ) then 0
> >         else 'g(mu,nu)$
>
> A different way to express a function like this, which has various
> cases, is to use simplification rules. You make up one rule per case.
> If you think up additional cases, you just make more rules. If none of
> the rules apply, the expression is unchanged.
>
>   tellsimpafter (g(0, 0), 1);
>   tellsimpafter (g(1, 1), -1);
>   tellsimpafter (g(2, 2), -1);
>   tellsimpafter (g(3, 3), -1);
>   /* tellsimpafter rules are applied in the order they are declared.
>    * So this last one is applied only if none of the others were applied.
>    */
>   matchdeclare ([ii, jj], integerp);
>   tellsimpafter (g(ii, jj), 0);
>
>   g(m, n);
>    => g(m, n)
>   subst ([m = 1, n = 2], %);
>    => 0
>
> It might be useful to state rules that work for symbols too.
>
>   tellsimpafter (g(0, 0), 0);
>   matchdeclare (aa, lambda ([x], not equal (x, 0)));
>   tellsimpafter (g(aa, aa), -1);
>   matchdeclare (aa, all, bb, lambda ([x], not equal (x, aa)));
>   tellsimpafter (g(aa, bb), 0);
>
>   [g(0, 0), g(1, 1), g(2, 2), g(1, 2)];
>    => [0, - 1, - 1, 0]
>   g(m, m);
>    => g(m, m)
>   assume (m > 0);
>   g(m, m);
>    => -1
>   g(m, n);
>    => g(m, n)
>   assume (m > n);
>   g(m, n);
>    => 0
>
> Hope this helps,
>
> Robert Dodier
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>