On Monday, January 26, 2015 at 6:11:33 PM UTC+1, lapeyre....@gmail.com 
wrote:
>
> I found that I can progress most quickly modeling on Mathematica. The 
> design is fairly simple and consistent. Of course the documentation is 
> vague in some places, but so far, it is not a problem. Of course, even if 
> you know logically what the rules should do, there is still the matter of 
> building data structures and applying them.  I am more concerned now in 
> getting correct logical behavior than efficient application of rules. I 
> want to see a cohesive system. A lot of risk is reduced, because we know 
> Mathematica works. But, it is good to develop ideas about efficient 
> implementation at the same time, and there is no avoiding it when doing 
> commutative matching.
>

Have you had a look at Mathics?
https://github.com/mathics/Mathics

It is an open source Wolfram Mathematica interpreter written in Python, and 
uses SymPy as a callback for math algorithms.

You may try it from your browser:
http://www.mathics.net/


> I installed sympy, but have not played with it yet, but I definitely will. 
> I've looked just a bit at the code. If you have any experience optimizing 
> pattern matching, or other resources, I'd like to hear about it.
>
>
If you wish to try sympy out, I may suggest to run *" isympy -I "* from the 
console.

Another resource is Richard Fateman's  mma4max 
> <http://www.cs.berkeley.edu/~fateman/lisp/mma4max/>, which I see has 
> updates since I last built it. It aims more or less to implement mma in 
> common lisp. In fact it has a Julia-compatible license and a complete 
> parser written in common lisp. IIRC the comments show that the pattern 
> matcher is not perfect, but I think it is complete.
>

That's better than Mathics concerning the license, as Mathics is GPL.

Anyways, I saw you use a lot of conventions from Mathematica, e.g. *x_* 
with a trailing underscore to define parameters and *x_Integer* to restrict 
the types. But unlike Mathematica, _ is not an operator in Julia. Maybe 
there could be some confusion, what about using *:: *instead, or something 
like that?

Concerning the expression tree, Mathematica has an attribute "Orderless" to 
determine whether a type of node is commutative (e.g. *Times, Plus*). 
Julia's operators are dispatched according to the types of their arguments, 
so * may be commutative for some types, while not commutative for other 
types (most notably, for matrices it's not). In Mathematica you have to use 
the dot "." to multiply matrices, which creates a different kind of node 
(Dot). On the other hand in SymPy multiplicative commutativity is handled 
as an assumption on the single arguments of the *"Times" *node (Mul in 
SymPy).

In [2]: x = symbols('x')

In [3]: y, z = symbols('y z', commutative=False)

In [4]: x*y == y*x
Out[4]: True

In [5]: y*z == z*y
Out[5]: False


Here *x* is multiplicatively commutative, *y* and *z *are not.

I prefer this approach to that of Mathematica, unfortunately it is harder 
to implement.

Reply via email to