Eduardo Cavazos wrote:
Some of the code as currently written isn't in idiomatic Scheme style.
This is because I ususally do a more or less direct translation of the
pseudo code from the book. I'd like to get things working and stable
first before I fancy things up. The code is easier to debug when it
still resembles what's in the book. The good news is that, with a bunch
of unit tests, converting to idiomatic code down the line can be done
with more confidence.
Now that I've worked through much of volume 1 of Cohen's computer
algebra texts, I've revisited and rewritten parts to use more Scheme idioms.
In a computer algebra system designed like MPL, the heart of the system
is the symbolic arithmetic. And the heart of the symbolic arithmetic is
the implementation of +, *, and ^; - and / are implemented in terms of
the others.
The new implementation of +, *, and ^ is at:
http://github.com/dharmatech/mpl/raw/master/sum-product-power.sls
It weighs in at 147 lines. Much of the concision is due to the use of
pattern matching via (xitomatl AS-match) (which is in turn a port of
Alex Shinn's pattern matcher). At some point, I may upgrade to Derick's
match library if I need to match against records.
If you can improve on the algorithm, I'd like to know!
Anyways, this is sort of a milestone for this side project of mine. I'd
always been curious about how computer algebra systems worked. The
commercial ones are black boxes (Mathematica, Maple). The big free ones
are quite complex (Axiom, Maxima). Now with a small, tractable, piece of
"the heart" of a basic computer algebra system in hand, I'm beginning
to understand "how they work". :-)
Ed