[Tutor] symbolic algebra; Jython

Christopher Smith csmith@blakeschool.org
Fri Oct 25 13:02:08 2002


This is a followup to the August 2001 discussion about symbolic algebra 
systems.

I found such a system that is more advanced than Pythonica...but it's
written in java.  But...I just completed an installation and successful 
test of Jython, a program which feels like Python but allows you to 
access java classes as if they were just another python module.  
Specifically, I did a test of the symbolic algebra manipulation system.

After binding the Jython-21.jar with the option set to get stdin from
the Message Window (and otherwise typing in everything as specified at
http://www.jython.org/MacOS_Install.html) I was able to create a
working Jython application.

I put the symbolic folder in the same folder as the newly created
Jython application and then successfully ran through the small test
suite found in mathtest.java which is part of the symbolic algebra
system download:

####

Jython 2.1 on java1.1.8 (JIT: MRJ22Jitc.01) Type "copyright", "credits"
or "license" for more information.
>>> from symbolic import * m=Math_interpreter() #create an instance of
>>> the manipulator m.calculate("DIFF(SINH(x^2),x)") #derivative of
>>> sinh(x^2) wrt x
'(((2*x)*exp(x^2))+((exp(-x^2)*x)*2))/2'
>>> m.setOutputMode(Math_interpreter.TEX_OUTPUT) m.getLastResult()
'\\frac{{{{2}{x}}{exp\\left({{x}^{2}}\\right)}}+{{{exp\\left({-{x}^{2}}
\\right)}{x}}{2}}}{2}'
>>> m.setOutputMode(Math_interpreter.INFIX_OUTPUT)
>>> m.calculate("INT(x^2*SIN(x),x)")
'(2*((sin(x)*x)+cos(x)))-(x^2*cos(x))'
>>> m.setOutputMode(Math_interpreter.STRUCTURED_OUTPUT)
>>> m.getLastResult()
'                         2        \n2 (sin(x) x + cos(x)) - x  cos(x)
\n'
>>> print _ #let's see it printed not repr'ed
2 2 (sin(x) x + cos(x)) - x  cos(x)

>>> 

####

A demo of a java applet online which allows you to manipulate algebraic
expressions is located along with the reference page at
http://www.mb.hs-wismar.de/Mitarbeiter/Pawletta/00Uwe/formel.html.

The symbolic folder of classes can be downloaded from
http://www.mb.hs-wismar.de/Mitarbeiter/Pawletta/00Uwe/symjpack.tar.gz
(a quick download at only 36 K).

Jython and directions for the MacOS installation are at
http://www.jython.org/MacOS_Install.html; the Jython home, from where
versions for other systems can be downloaded is at
http://www.jython.org/index.html.


/c