Search code examples
javapythonjythonsympycomputer-algebra-systems

Using SymPy (or another CAS) with Java


I am currently developing a project in JavaFX that accepts a mathematical expression and evaluates it. I have managed to get basic operations and a good deal of algebra to work. I have also managed to perform definite integrations using the trapezoid rule.

The main problem I am facing is with indefinite integration. I looked up many symbolic computation libraries online like JCalculus, JavaCalculus, JScience, SymJa and others. But none of them were as good as SymPy in terms of functionality. I wanted to know if there is a way to send commands to SymPy from Java and receive the result back into Java.

I am thinking of providing an installer for my JavaFX app that will install Python and SymPy if necessitated by the solution. I also tried to understand Jython, believing that it would somehow by related to the problem but I could not understand its purpose and its usage.

Please help me. I am quite good at Java and JavaFX but my knowledge of Python is severely low and restricted. Step by step instructions and sample code is extremely appreciated.

Thanks in advance.


Solution

  • If you somehow manage to write sympy equivalent python code from your java input in a file, you can get the output of that code very easily.

    Process p = Runtime.getRuntime().exec("python yourfile.py");
    

    Take a look at this.