Re: Rubi, mathics, python and jnil.

Richard Fateman <[email protected]> Sun, 3 May 2026 17:06:42 -0400
Newsgroups gmane.comp.mathematics.maxima.general
Message-ID <CADB8Zm5aaqrdsiz5jkO43CXXKyPVj_jMEM+B-57n5q8KSgPSag@mail.gmail.com>
There has been, for quite some time, an implementation of the Mathematica
pattern matcher  (the version of that time)
in Lisp, starting in 1991. It also includes a parser.
 The MockMMA code has been appropriated in a couple of projects. I just
found a copy
here
https://github.com/dubrousky/mockmma/blob/master/README

Now to integrate this code directly in Maxima, the simplest way would be to
have a subsystem
to_MockMMA();....
   with a Return_and_Convert_to_Maxima[expression];

To somehow "use" Mathematica's pattern matching in Maxima, you would have
to adopt the
Mathematica  (uh, Wolfram Language) syntax like  f[ a_?pred,b__]:= blah
blah ... into Maxima.
There is a natural AST for this since the WL has a FullForm that is
tantamount to lisp, e.g.
a+b in FullForm is Plus[a,b].   It is unlikely to be popular to write this
way.

I have not updated MockMMA in years, but it seems others have made it work
in different lisp
dialects etc.

I expect that my pattern matching code would have to be modestly updated to
include the
"improvements" in the language. Perhaps the bad design items I repaired
were repaired
by Wolfram Inc.  (I may have pointed them out at the time).  And there may
be bugs
in my code. MockMMA includes a rational function package which (as I
recall) uses
vectors instead of lists as used in Maxima.
  A  more complicated integration of systems would be necessary if you
wished to use
Maxima within pattern matching -- e.g. expressing a predicate within a
pattern match
as Maxima code.

Thus
p[x_?NumberQ] := x^2
in TWL would call the MockMMA NumberQ.
If you wanted to call the Maxima number testing predicate numberp you
might need something like this..
to_MockMMA();
p[x_?Maxima_RT[numberp] ] :=x^2

What Maxima_RT[x_] does is a Round Trip. That is, whatever x_ matches in
the MockMMA subsystem is converted to Maxima semantics.
then the Maxima function numberp is applied, presumably returning true or
false.
then a program must convert to a MockMMA datum, presumably something like
the atoms True or False.

Now I suppose you could try to incorporate the syntax of Mathematica in
some ways,
and some of it does not especially interfere with Maxima syntax. But some
does.

Good luck.
RJF


On Sun, May 3, 2026 at 3:01 PM Dan Stanger <[email protected]>
wrote:

> Hello All,
> About 22 years ago, there was a project jnil, which translated java into
> lisp. It worked by loading java code into Eclipse and using JLinker, an ACL
> tool to communicate with a lisp program which did the translation by
> retrieving information about the java code to perform the translation.
> Python has an abstract syntax tree (AST) module which provides similar
> functionality to the Eclipse usage but can provide text output. Mathics is
> a mathematica clone written in Python which has advanced enough to load
> rubi. Using Antlr, an existing python grammar can produce a s expression
> output of a concrete syntax tree. I am writing a grammar file for the
> Python AST output which should enable a modified jnil to convert the
> mathics pattern matching code into lisp, which should provide an easier
> integration with Maxima.
> Dan Stanger
> _______________________________________________
> Maxima-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>

_______________________________________________
Maxima-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maxima-discuss