Re: Going mad with pattern matching
"Alasdair McAndrew" <[email protected]>
| Newsgroups | gmane.comp.mathematics.axiom.user |
|---|---|
| Message-ID | <[email protected]> |
Thank you, Bill & Martin, for your help! I would like, if possible, to develop a z-transform routine for Axiom, and I would have thought that pattern matching was the way to go. I have a z-transform package for Reduce, written by Wolfram Koepf in 1995, which relies heavily on pattern matching, and I have the beginnings of one for Maxima, which I started writing last year. I think Martin's wizardry will be the basis of the rest. I am now wrestling with partial fractions... Axiom is very particular about the types it admits to partial fractions; the type EXPR INT can't be used. And, my humblest apologies for a typo - the penultimate line of the help function should read "tmp:=-z*D(tmp,z)". I also notice, while hunting through /src/algebra, that there is an "applyRules" function; but as with "suchThat", it's not mentioned in the documentation; at least, not in the Rules and Pattern Matching section (6.21) of the Axiom book. Maybe these two functions are part of the source code for rules, and not meant to be used by casual users? Or maybe the documentation for rules should be rewritten to include these? So many thoughts, so little time.... (& so small a brain...) cheers, Alasdair On 5/29/07, Bill Page <[email protected]> wrote: > > Quoting Martin Rubey: > > > > > 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. > > Martin, could you please say two words (or a little more?) about > where you found information and examples of how to use suchThat > and ruleset? Sometimes finding out *how* to find out is more > important than the specific answer. > > > Find the modified ruleset below. > > ... > > zt:=operator 'zt > > > > help(z,a) == > > tmp := z/(z-1) > > for i in 1..a repeat > > tmp:=-D(tmp,z) > > tmp > > > > Note that there is a problem in this expression. It does not > correctly compute the ztrans of 'n^a'. > > > 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?) > > That's pretty cool! I've never seen that anywhere before... > > > 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) > > > > How can one decide on the proper package call to Ruleset? > > > ztrans(f,n,z)==ztransrules zt(f,n,z) > > > > ... > > Regards, > Bill Page. > _______________________________________________ Axiom-mail mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/axiom-mail