Re: rule sets and patterns, was ...Re: [ Homological Algebra in Maxima]
Subject: Re: rule sets and patterns, was ...Re: [ Homological Algebra in Maxima]
From: Carl McTague
Date: Sat, 14 Jun 2003 09:37:57 -0400
Hi again Professor Fateman,
I played around with your suggestions a little bit inside Maxima, but
wasn't quite satisfied. However, I discovered that the gpl'd CAS
Yacas has come quite a long way and has a very powerful pattern
matcher and nice language for specifying them! (cf
http://yacas.sourceforge.net/) I have in fact been able to carry out a
straight-forward translation of my homological math'a example (see
below).
Tell me if I'm wrong, but it seems like Maxima's evaluation scheme is
quite different than math'a (or yacas). It seems more
straight-forward, program-evaluation-like than intrinsically
rewrite-system-like. I could imagine that can lead to faster and more
controlled computations, but it often makes things seem a bit less
flexible, at least when used naively. For example, if I do GCD[m,n]
in math'a [or Gcd(m,n) in yacas] and m and n aren't bound, then
GCD[m,n] simply remains unaltered wherever it appears. But in Maxima
(and perhaps this is really just a poor implementation of GCD and not
a critique of the Maxima evaluation scheme in general) you get
GCD(m,n) => 1! These sorts of barbs seem to arise quite often when I
use Maxima and they mess up all kinds of boundary conditions.
Is that a fair criticism of the Maxima evaluation scheme? Are there
ways around that kind of behavior? It seems as though you can get the
rewrite-like behavior in Maxima if you want, but you essentially need
to provide and invoke the infrastructure yourself. Is that right?
Also, I'm not quite sure I understood your comment about syntactic
vs. semantic rewriting, probably mostly because all the rewrite
literature I've ever read concerned syntactic matching. Humans
certainly do both and so it seems like semantic matching might be
nice, but seems extremely difficult to do and define well in general.
Thanks for putting up with my naive questions,
Carl
Yacas version of my simple homological algebra example:
Tens(0,_G) <-- 0;
Tens(_G,0) <-- 0;
Tens(Z,_G) <-- G;
Tens(_G,Z) <-- G;
Tens(Z(_n),Z(_m)) <-- Z(Gcd(n,m));
Tens(_A + _B, _G) <-- Tens(A,G) + Tens(B,G);
Tor(Z, _G) <-- 0;
Tor(_G, Z) <-- 0;
Tor(0, _G) <-- 0;
Tor(_G, 0) <-- 0;
Tor(Z(_n), Z(_m)) <-- Z(Gcd(n, m));
Tor(_A + _B, _G) <-- Tor(A, G) + Tor(B, G);
Tor(_A, _G + _H) <-- Tor(A, G) + Tor(A, H);
Hom(Z, Z) <-- Z;
Hom(Z(_n), Z) <-- 0;
Hom(Z, Z(_n)) <-- 0;
Hom(0, _G) <-- 0;
Hom(Z(_n), Z(_m)) <-- Z(Gcd(n, m));
Hom(_A + _B, _G) <-- Hom(A, G) + Hom(B, G);
Hom(_A, _G + _H) <-- Hom(A, G) + Hom(A, H);
Hom(n_IsInteger * _A, _G) <-- n*Hom(A, G);
Ext(Z, _G) <-- 0;
Ext(0, _G) <-- 0;
Ext(Z(_n), Z) <-- Z(n);
Ext(Z(n), Z(m)) <-- Z(Gcd(n, m));
Ext(_A + _B, _G) <-- Ext(A, G) + Ext(B, G);
Ext(_A, _G + _H) <-- Ext(A, G) + Ext(A, H);
Ext(n_IsInteger * _A, _G) <-- n*Ext(A, G);
kunneth(C,D) := LocalSymbols(l,i,n,CC,DD)
[l:=Length(C)+Length(D)-2;
CC:=Concat(C,FillList(0,2*l)); DD:=Concat(D,FillList(0,2*l));
Push(Table(Sum(i,0,n,Tens(CC[i+1],DD[n-i+1]))+
Sum(i,0,n-1,Tor(CC[i+1],DD[n-1-i+1])),n,1,l,1),Z);];
s2rp5 := kunneth({Z,0,Z}, {Z,Z(2),0,Z(2),0,Z});
lnklmj := kunneth({Z,Z(n),0,Z}, {Z,Z(m),0,Z});
s1s1s3 := kunneth(kunneth({Z,Z}, {Z,Z}), {Z,0,0,Z});
cp2cp3 := kunneth({Z,0,Z,0,Z}, {Z,0,Z,0,Z,0,Z});
Print(s2rp5);
Print(lnklmj);
Print(s1s1s3);
Print(cp2cp3);
uctCohomology(C) := LocalSymbols(CC,n) [CC:=Append(C,0);
Push(Table(Hom(CC[n+1],Z)+Ext(CC[n-1+1],Z),n,1,Length(C),1),Z);];
Print(uctCohomology(s2rp5));
Print(uctCohomology(lnklmj));
Print(uctCohomology(s1s1s3));
Print(uctCohomology(cp2cp3));