Subject: Re: How to make and apply rules dynamically?
From: Robert Dodier
Date: Mon, 6 Feb 2006 18:33:15 -0700
hi dileep,
> if rule is x(I,J)*x(K,L)
> then it does not apply to x(i1,j1)*r(j1)*x(k1,l1).
> How should I deal with this?
not sure if you want to avoid matching x(i1,j1)*r(j1)*x(k1,l1),
or if you want to match it and can't make it work ...
to match it: put an extra variable in the defrule to collect
multiplicative terms not matching x(a,b)*x(c,d):
matchdeclare ([a, b, c, d, e], all);
defrule (r1, x(a,b)*x(c,d)*e, FOO(a,b,c,d)*e);
to avoid matching: put only literal x terms in defrule:
(with same matchdeclare as above)
defrule (r2, x(a,b)*x(c,d), FOO(a,b,c,d));
then
apply1 (x(i1,j1)*r(j1)*x(k1,l1), r1); => r(j1) FOO(k1, l1, i1, j1)
/* e = r(j1) here */
apply1 (x(i1,j1)*r(j1)*x(k1,l1), r2); => x(i1, j1) r(j1) x(k1, l1)
/* no match here */
apply1 (x(i1,j1)*x(k1,l1), r1); => FOO(k1, l1, i1, j1) /* e = 1 here */
apply1 (x(i1,j1)*x(k1,l1), r2); => FOO(k1, l1, i1, j1)
hth
robert dodier