Mathematica-style pattern-matching in Maxima
Richard Fateman <fateman <at> berkeley.edu>
2014-07-24 15:16:47 GMT
(July 24, 2014)
copy the directory http://www.cs.berkeley.edu/~fateman/lisp/mma4max
I've mucked around with the MockMMA code from years ago. This code
does a lot more than pattern matching (e.g. symbolic integration,
rational simplification ....) but the part that is specifically being
interfaced and described here with respect to Maxima is the pattern
matcher. I'm assuming you know something of pattern matching in
Mathematica. If not, the next few paragraphs will not make much sense.
From the README file
This is a touch-up for Maxima, GCL in particular, allowing what
appears to be direct access to the pattern matching in MockMMA.
Actually there is some translation to and from the MockMMA representation
Until someone comes up with an alternative simple Maxima
syntax for patterns like those in Mathematica, we will use the
roughly equivalent FullForm style patterns. Though we use () instead of .
_ is Blank()
a_ is Pattern(a,Blank())
a__ is Pattern(a,BlankSequence())
a___ is Pattern(a,BlankNullSequence())
a_foo is Pattern(a,Blank(foo))
a?fooq is PatternTest(a,fooq)
Now if you don't like to write these things explicitly
you can, for example, write z:Pattern(a,BlankNullSequence())
and use z in patterns.
There are a host of uses of patterns in Mathematica that we do
not explicitly or implicitly support, e.g. member, subst,
but which could be programmed.
We can (already do) support in MockMMA the pattern-replacement
evaluation typical of Mathematica. However, this is in conflict
with the usual Maxima evaluation process, and so the support here
implicitly is for the Maxima user to convert the data into the
mma format, mess around with it for a while with a different
model of evaluation, and convert it back.
Here's what we support "out of the box" here, as of July 24, 2014.
A program sm (for simple match)
sm(p,e,vars) is how it is called.
p is a pattern
e is an expression to be matched
vars is a list of variables whose binding is of interest.
the README file continues with installation instructions etc.
I'm happy to receive comments. However, be alerted to the possibility
that the bugs you find may be your "user errors" in designing patterns,
rather than the pattern matching code itself. So look carefully.
Not that the code is so perfectly written etc. Just that
in my own personal experience, I'm far more likely to write a bad
pattern than to newly discover a bug in the matching code.
There is a file hey.batch with about 140 patterns in MockMMA syntax
testing various features. And a whole bunch of other stuff after
that to exercise MockMMA's general programming. None of this will
work directly in Maxima because the syntax is not Maxima syntax.
It is entirely possible to have Maxima read MockMMA syntax, e.g.
but then where do you go with that? Also there are sticky parts
of the parsing program with respect to low-level input of characters..
it doesn't seem to work with wxmaxima but is ok in simpler modes.
Maybe switching readtables is problem??
This stuff described here sm(p,e,vars) does not use the parser.
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.