[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Axiom-mail] Going mad with pattern matching
From: |
Martin Rubey |
Subject: |
Re: [Axiom-mail] Going mad with pattern matching |
Date: |
29 May 2007 14:21:26 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
Dear Alasdair,
I did now go through your example. It seems that you hit a bug, but
fortunately, there is an easy workaround. THe problem is with rules of the
form:
rule ...a...b... | p(a,b) == ...
It seems that in this case, the predicate p is never tested, who knows why.
The workaround is to use the "suchThat" function. Find the modified ruleset
below. I know that this looks a bit clumsy, but I do not have the time
currently to debug it completely.
Some comments:
* rules are applied recursively. Thus, repeating ztrans on the right hand side
is unnecessary.
(42) -> t := rule a+b == zt(a, b)
(42) b + a == 'zt(a,b)
Type: RewriteRule(Integer,Integer,Expression Integer)
(43) -> t(a+b+c)
(43) zt(a,zt(c,b))
Type: Expression Integer
* I believe that your second rule (my rule r1) contained a misprint. Please
check.
* maybe the invocation of ruleset is unnecessary, and you can simply write the
suchThat expressions within the rule pile. I did not try.
All the best,
Martin
zt:=operator 'zt
help(z,a) ==
tmp := z/(z-1)
for i in 1..a repeat
tmp:=-D(tmp,z)
tmp
myFreeOf? l == freeOf?(l.1, l.2)
r0 := rule zt(f+g,n,z) == zt(f,n,z)+zt(g,n,z)
r1 := suchThat(rule zt(a*f,n,z) == a*zt(f,n,z), [a, n], myFreeOf?)
r2 := suchThat(rule zt(a,n,z) == a*z/(z-1), [a, n], myFreeOf?)
r3 := suchThat(rule zt(a^n,n,z) == z/(z-a), [a, n], myFreeOf?)
r4 := rule zt(0,n,z) == 0
r5 := rule zt(1,n,z) == z/(z-1)
r6 := rule zt(n,n,z) == z/(z-1)^2
r7 := rule zt(n^(a | integer?(a) and a>1),n,z) == help(z, a)
ztransrules := ruleset([r0,r1,r2,r3,r4,r5,r6,r7])$Ruleset(INT, INT, EXPR INT)
ztrans(f,n,z)==ztransrules zt(f,n,z)
Martin Rubey <address@hidden> writes:
> "Alasdair McAndrew" <address@hidden> writes:
>
> > Thanks, Martin,
> >
> > As always I am helped by you! I have two questions; maybe you can answer
> > them:
> >
> > 1) How do I include linearity in the pattern matching rules? At present,
> > the command
> >
> > ztrans(2+3^n,nz)
> >
> > which should return the result
> >
> > 2z/(z-1)+z/(z-3)
> >
> > produces
> >
> > (2+3^n)z/(z-1).
> >
> > That is, the pattern matcher incorrectly applies the rule
> >
> > zt(a | freeOf?(a,n),n,z) == a*z/(z-1)
> >
> > even though 2+3^n is not free of n!
>
> I doubt this. I'm a little short on time though. Thus, please do me a
> favour:
> replace all rules with little local functions -- as I have done with "help".
> Then you can say
>
> )trace help
>
> (replace "help" with the name of the functions you want to trace)
>
> and you should see which rule was invoked. To see the arguments in a nicer
> form, you can use
>
> )trace help )mathprint
>
> but this works only after help was invoked already once.
>
>
> > 2) How do I force answers to be returned in factored form?
>
> Later... Short answer: you need to coerce them to an appropriate domain.
>
> Martin
>
>
>
> _______________________________________________
> Axiom-mail mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/axiom-mail
- [Axiom-mail] Going mad with pattern matching, Alasdair McAndrew, 2007/05/28
- Re: [Axiom-mail] Going mad with pattern matching, Martin Rubey, 2007/05/28
- Re: [Axiom-mail] Going mad with pattern matching, Martin Rubey, 2007/05/28
- Re: [Axiom-mail] Going mad with pattern matching, Alasdair McAndrew, 2007/05/28
- Re: [Axiom-mail] Going mad with pattern matching, Martin Rubey, 2007/05/29
- Re: [Axiom-mail] Going mad with pattern matching,
Martin Rubey <=
- Re: [Axiom-mail] Going mad with pattern matching, Bill Page, 2007/05/29
- Re: [Axiom-mail] Going mad with pattern matching, Martin Rubey, 2007/05/29
- Re: [Axiom-mail] Going mad with pattern matching, Alasdair McAndrew, 2007/05/30
- Re: [Axiom-mail] Going mad with pattern matching, Martin Rubey, 2007/05/30
- Re: [Axiom-mail] Going mad with pattern matching, Alasdair McAndrew, 2007/05/30
- Re: [Axiom-mail] Going mad with pattern matching, Martin Rubey, 2007/05/30
- Re: [Axiom-mail] Going mad with pattern matching, Bill Page, 2007/05/29