SymJava

522 views
Skip to first unread message

yueming liu

unread,
Jan 15, 2015, 8:38:07 PM1/15/15
to sy...@googlegroups.com
Just finished a prototype of the project SymJava ( https://github.com/yuemingl/SymJava ) which is similar to sympy. Actually, I borrowed some ideas from sympy. Thanks all the sympy contributors. 

The reason to develop this library is that sympy can NOT run on JPython :(. I have another Java library FuturEye for numerical computation to solve PDE constrained inverse problems. Symbolic computation is important for this library since it will reduce a huge amount of time with automatic functional derivative computation.

Here is a piece of example code of SymJava:

Expr expr = x + y * z;

System.out.println(expr); //x + y*z

Expr expr2 = expr.subs(x, y*y);

System.out.println(expr2); //y^2 + y*z

System.out.println(expr2.diff(y)); //2*y + z

Func f = new Func("f1", expr2.diff(y));

System.out.println(f); //f1(y,z)

BytecodeFunc func = f.toBytecodeFunc(); //Similar to the lambdify in sympy

System.out.println(func.apply(1,2)); //4.0

There are two important features:

1. Operator Overloading is implemented by using https://github.com/amelentev/java-oo

2. Lambdify in sympy is implemented in SymJava by using BCEL library

Let me know if any one interested in this? Just send me an email: nkliuyuemingATgmail.com


Jason Moore

unread,
Jan 15, 2015, 8:44:11 PM1/15/15
to sy...@googlegroups.com
I'm curious why SymPy doesn't run in Jython. The core stuff is all pure Python. What prevents it from working with Jython?

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/8262f07b-a540-4b71-8e19-303da5141ead%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron Meurer

unread,
Jan 15, 2015, 8:46:26 PM1/15/15
to sy...@googlegroups.com
Thanks for sharing this. I'm glad to see symbolics being used, even if it isn't Python.

I would suggest putting a LICENSE in the project, so it is clear to people that they can use the code (if you're unsure what to use, I would suggest BSD, the same as SymPy).

Aaron Meurer

Aaron Meurer

unread,
Jan 15, 2015, 8:52:57 PM1/15/15
to sy...@googlegroups.com
There have been many issues, some of which have been fixed, and some which maybe weren't. See https://github.com/sympy/sympy/issues/4332. I'd actually like to have someone try it with the latest Jython and SymPy master to see what the error is. 

In the past, the issue has been that Jython has some issues with some of the advanced Python features we use in SymPy. For example, in the past somehow our class/metaclass/__slots__ configuration didn't work.

I personally don't think projects like Jython or IronPython are good ideas. If you need to use a Python library from another language it's better to try to interface with Python than to rewrite all of Python in that language. 

But to be clear, we would like for SymPy to support them, assuming the changes necessary aren't too drastic. 

Aaron Meurer

Joachim Durchholz

unread,
Jan 16, 2015, 4:29:26 AM1/16/15
to sy...@googlegroups.com
Am 16.01.2015 um 02:52 schrieb Aaron Meurer:
> There have been many issues, some of which have been fixed, and some which
> maybe weren't. See https://github.com/sympy/sympy/issues/4332. I'd actually
> like to have someone try it with the latest Jython and SymPy master to see
> what the error is.

I tried, but noticed that the standard Jython is 2.5 an SymPy needs at
least Python 2.6.
Also, Jython assumes it has access to a really ancient Google
Collections API, and cannot even start.

That said, the Jython guys are working on a 2.7 version which is
currently at beta 3, so all hope is not lost.
Installing Jython standalone involves running an installer, and I wasn't
prepared for that, so I punted on it for now.

> I personally don't think projects like Jython or IronPython are good ideas.
> If you need to use a Python library from another language it's better to
> try to interface with Python than to rewrite all of Python in that
> language.

Jython is a Python interpreter written in Java. You don't have to
rewrite the Python library, you just run it inside the JVM using Jython.

There's a lot of performance to be gained that way.
Also, they allow extending Java classes with Python code, and they don't
have a GIL (which is good news if the Java side is an application server
with dozens, hundreds or more threads serving requests).

So I wouldn't dismiss Jython as misguided so easily.
The real question is whether they can keep up with the advancing Python
technology, and sadly, it seems they cannot: their current plan is to
finish 2.7, then start with 3.x (probably 3.3).

> But to be clear, we would like for SymPy to support them, assuming the
> changes necessary aren't too drastic.

Anybody interested in trying with Jython 2.7b3?

Ondřej Čertík

unread,
Jan 17, 2015, 7:31:09 PM1/17/15
to sympy, nkliuy...@gmail.com
Very cool.

As Aaron said, the best is to simply figure out how to interface
CPython (as opposed to create an alternative implementation), for
example like Julia guys did it ---- they can call SymPy directly from
Julia, and it just uses the regular CPython interpreter.

Another thought is that we are also developing CSymPy
(https://github.com/sympy/csympy) in C++ with a C interface
(https://github.com/sympy/csympy/blob/34ab10dc6cb64f4a4739f5d094a39168b8081ab2/src/cwrapper.h),
for efficiency. It is just a simple .a or .so library and the C
interface allows you to call it from any language, like Python, Julia
or Java (http://en.wikipedia.org/wiki/Java_Native_Interface,
https://github.com/twall/jna/, ...). For your applications, can you
call C from Java?

If so, you can then either call CSymPy, or find a library (or write
one) that calls the CPython interpreter using C/API, similar to how
the Julia <-> Python interface works, then you can call SymPy
directly.

Ondrej

yueming liu

unread,
Jan 22, 2015, 2:13:44 PM1/22/15
to sy...@googlegroups.com

Update, Abstract function, derivative, gradient, dot product and functional derivative are supported in SymJava

Francesco Bonazzi

unread,
Jan 23, 2015, 10:23:28 AM1/23/15
to sy...@googlegroups.com
Have you ever thought about implementing some parts of your code in functional languages running on the Java Virtual Machine, such as Scala or Clojure?

Ondřej Čertík

unread,
Jan 23, 2015, 11:26:57 AM1/23/15
to sympy
Indeed, you should checkout Mateusz' mathematica parser in Scala:

https://github.com/mattpap/mathematica-parser

Ondrej

>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/085e13d2-6862-4e35-85dc-7fd119b95a0d%40googlegroups.com.

yueming liu

unread,
Jan 23, 2015, 12:51:09 PM1/23/15
to sy...@googlegroups.com
Yes, I have plan to implements an wrapper of the Java class in Scala. For example, you can use Dot( Grad(f), Grad(g) ) in Scala if the class Dot and Grad have method named apply() in Java. I really like the language features in Scala.

As I mentioned in my first post, the original motivation of SymJava isadding symbolic ability for my another Java numerical library Futureye. Due to the lack of operator overloading in Java at that time, I even created a project ScalaFEM (https://code.google.com/p/scala-fem/) that implements most of the components in Futureye. I have plan to finish ScalaFEM and adding SymJava in it too.

yueming liu

unread,
Jan 23, 2015, 12:51:33 PM1/23/15
to sy...@googlegroups.com
That's really cool.
Reply all
Reply to author
Forward
0 new messages