I am using batchfile for defining a function say func(exp) which can be
called by passing exp. I am using apply because I am using variable for
rulename. Rulename is generated and defined dynamically in the code in
func(exp). Therefore I have to use apply like this:
apply(apply1,[expression,rulename]
But the problem is the following:
(the following thing is not from the batchfile I have used for the code, I
am just testing on command prompt to show the results)
(%i1) sumexpand:true;
(%o1) true
(%i2) matchdeclare([I,L,J,K,e],all);
(%o2) done
(%i3) defrule(r1,x(I,L)*x(J,K)*e,(r(L)*d(L, K)*d(I, J) + r(L)*r(L, 1)*d(L,
K)*(1 - d(I, J)) + r(L)*r(K)*(1 - d(I, J))*(1 - d(L, K)))*e);
(%o3) r1 : e x(I, L) x(J, K) -> e ((1 - d(I, J)) r(L) r(L, 1) d(L, K)
+ d(I, J) r(L) d(L, K) + (1 - d(I, J)) r(K) r(L) (1 - d(L,
K)))
(%i5) eq1:sum(x(i1, l)*f(i1), i1, 1, n)* sum(x(i2, m)*f(i2), i2, 1, n);
n n
==== ====
\ \
(%o5) > > f(i1) x(i1, l) f(i2) x(i2, m)
/ /
==== ====
i1 = 1 i2 = 1
(%i7) apply(apply1,[eq1,r1]);
n n
==== ====
\ \
(%o7) > f(i3) > f(i4) ((1 - d(i4, i3)) r(m) r(m, 1) d(m, l)
/ /
==== ====
i3 = 1 i4 = 1
+ d(i4, i3) r(m) d(m, l) + (1 - d(i4, i3)) r(l) r(m) (1 - d(m,
l)))
But does not work for product of 3 terms:
(%i9) matchdeclare([I,J,K,L,M,N,e],all);
(%o9) done
(%i10) defrule(r1,x(I,L)*x(J,K)*x(M,N)*e,(r(L)*d(L, K)*d(I, J) + r(M)*r(L,
1)*d(N, K)*(1 - d(I, J)) + r(L)*r(K)*(1 - d(I, J))*(1 - d(L, K)))*e);
(%o10) r1 : e x(I, L) x(J, K) x(M, N) ->
e ((1 - d(I, J)) r(L, 1) r(M) d(N, K) + d(I, J) r(L) d(L, K)
+ (1 - d(I, J)) r(K) r(L) (1 - d(L, K)))
(%i13) eq1:sum(x(i1, l)*f(i1), i1, 1, n)* sum(x(i2, l)*f(i2), i2, 1,
n)*sum(x(i3, l)*f(i3), i3, 1, n);
n n n
==== ==== ====
\ \ \
(%o13) > > > f(i10) x(i10, l) f(i11) x(i11, l) f(i12)
/ / /
==== ==== ====
i11 = 1 i12 = 1 i10 = 1
x(i12, l)
(%i14) apply(apply1,[eq1,r1]);
n n n
==== ==== ====
\ \ \
(%o14) > > > f(i18) x(i18, l) f(i19) x(i19, l) f(i20)
/ / /
==== ==== ====
i19 = 1 i20 = 1 i18 = 1
x(i20, l)
(%i15) apply1(eq1,r1);
n n n
==== ==== ====
\ \ \
(%o15) > f(i11) > f(i12) > f(i10)
/ / /
==== ==== ====
i11 = 1 i12 = 1 i10 = 1
(r(i10) (1 - d(i12, i11)) r(l, 1) d(l, l) + d(i12, i11) r(l) d(l, l)
2
+ (1 - d(i12, i11)) r (l) (1 - d(l, l)))
Dileep
-----Original Message-----
From: Richard Fateman [mailto:fateman at cs.berkeley.edu]
Sent: Wednesday, February 08, 2006 12:43 AM
To: dp2 at cise.ufl.edu
Cc: macrakis at alum.mit.edu; dp2 at cise.ufl.edu; Robert Dodier;
maxima at math.utexas.edu
Subject: Re: [Maxima] What is wrong with this rule?
----- Original Message -----
From: <dp2 at cise.ufl.edu>
To: "Richard Fateman" <fateman at cs.berkeley.edu>
Cc: <macrakis at alum.mit.edu>; <dp2 at cise.ufl.edu>; "Robert Dodier"
<robert.dodier at gmail.com>; <maxima at math.utexas.edu>
Sent: Tuesday, February 07, 2006 8:27 PM
Subject: Re: [Maxima] What is wrong with this rule?
> Can I call that lisp function by using "?".
The function is called m1, but the arguments are not going to look
like macsyma expressions.
So the answer is no.
> Also why the same rule runs if
> we use apply1 simply as I gave example in the previous email. The problem
> is only when apply(apply1...) is used.
I don't know why you are using apply.
If you want to write a program that looks for an operator "*" that
has 3,4, ... arguments, each of the form x(a,b),
and does what you want, it should be possible.
> Do you have any alternative solution for the problem, in which I have to
> apply in this way: x(i,j)*x(k,l)*x(m,n)->some function; it should match
> even the product is x(a,b)*f(a)*x(c,d)*f(d)*x(e,f).
> And similarly for the product of four,five,.... since I am generating
> rules at the time function is called.
> Regards
> Dileep
>
>> The matcher does not backtrack at all.
>> There is one that does, in the integration package
>> but it is not available except from lisp. There are other possibilities
>> (e.g. a Mathematica-style
>> pattern matcher in Lisp) but that would need a lot more syntactic
>> mechanism
>> for the user.
>>
>> RJF
>>
>>
>>
>> Stavros Macrakis wrote:
>>
>>
>>>> if you have a rule like e*f(x)*g(y), then it could try to match
>>>> 3*f(4)*g(5) by matching
>>>> e= 3*f(4) and then failing.
>>>>
>>>> You don't want e to match "anything at all". You want e to match
>>>> something not involving any f( ..).
>>>>
>>>>
>>>
>>> Sure, it might try matching e=3*f(4) to start, but when it fails, it
>>> had better backtrack and try e=3. If it doesn't, that seems like a bug.
>>>
>>> _______________________________________________
>>> Maxima mailing list
>>> Maxima at math.utexas.edu
>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>>
>>>
>>>
>>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>