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