mathematic to maxima translation



Hi John,

excellent work!

I am brand spanking new to Maxima and am a Mathematica user.

I just wanted to quickly comment that in MMA:

1*2+3*4 is the same as 1 2 + 3 4 (the space is the same as multiplcation)

Of course, this is also true when using variables.

For example ab is a single variable whereas a*b or a b are two variables.

Much code is written in this shorthand method.

I haven't reviewed everything you have done - but was curious if you were
also going to try to do this for functional programming constructs over
procedural constructs?

For example (example 1):

v = {1, 2, 0, 3, 4, 0}
{1, 2, 0, 3, 4, 0}

v1 = MapAt[0 &, v, Position[v, 0] - 1]
{1, 0, 0, 3, 0, 0}

v2 = Select[v1, # != 0 &]
{1, 3}

Example 2: (same as example 1 - but different code)
v = {1, 2, 0, 3, 4, 0}
{1, 2, 0, 3, 4, 0}

v //. {{a___, _, 0, b___} -> {a, b}, {0, b___} -> {b}}
{1, 3}

This can get quite complicated and quickly.

Of course functional programming is where it is at in these environments -
and the speed and elegance is clear.

Since I am no expert - this reference has been cited as a good one for
functional programming - and maybe you are an expert - so forgive my
ignorance.

For more on fp techniques in the context of longer programs see
http://book.realworldhaskell.org/
where there is a preliminary copy of a book, "Real World Haskell" to
be published soon by O'Reilly.

Many tutorials and books are to be found at www.haskell.org

Thanks for the excellent work - I am still so new to Maxima that I have a
lot to learn!

~A



On Tue, Sep 23, 2008 at 12:00 AM, John Lapeyre <pdl at johnlapeyre.com> wrote:

> Here is a new version of the compatibility functions, along
> with an Mma to Maxima translator:
>
> http://www.johnlapeyre.com/mmacompat/index.html
>
> (It is currently not very Windows friendly, but that can be
> fixed)
>
> There is a link there to the output of the entire current
> test suite of the translator, where you can see a subset of
> what has been implemented up to now.
>
> I still don't have access to Mma, which is really starting
> to be a hindrance (but I will get it sooner or later). If
> anyone does play with it and has any feed back (about
> failures,etc) I'd be happy to have it. Eg legal Mma syntax
> that this fails to parse.  I am thinking mostly about basic
> stuff that is implemented, like brackets and braces, but
> anything else is OK too. But sending simple Mma code that
> fails, and so forth would be nice.
>
>  Most of it is syntax translation.
> I only started one semi-complicated function translation,
> the Mma For function to Maxima for statement. It handles
> several common cases already. It looks like this will be a quite
> do-able approach to several functions.  (eg some of Table's
> functions could be recoded into create_list, which is more
> efficient).
>
>
> Thanks!
> John
>
> -------------------------------------
> Here is an example of the test results:
>
> ======== Test *Griffiths QI code*  1 ============
> == Mma code:
>
>   bin2ket[ls_]:= Module[{ket,ln=Length[ls],m},
>               ket=Table[0,{2^ln}];
>               m=1+Fold[2*#1+#2&,0,ls];
>               ++ket[[m]]; ket]
>
> == Expected Maxima translation:
>
>   bin2ket(ls) := block([ket, ln : Length(ls), m], ket : Table(0, [2 ^ ln]),
> m : 1 + Fold(lambda([arg2,arg1],2 * arg1 + arg2), 0, ls),
> ((ket[m]):(ket[m])+1),
> ket)
>
>   == Parse Test 2 succeeded
>   == Translation Test 2 succeeded
>   == Maxima Interpretation Test 2 succeeded
> == Maxima Regression Test Results: 2
>  ********************** Problem 1 ***************
>  Input:
>  bin2ket([0,1,1,0])
>
>
>  Result:
>  [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0]
>
>  ... Which was correct.
>  1/1 tests passed.
>  (%o5) []
>
>
> ==================================
> Test *Griffiths QI code* results
> (2/2) parses succeeded.
> (2/2) translations succeeded.
> (2/2) interprets succeeded.
> (1/1) passed in  Maxima regression for Test 2
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>