views:

290

answers:

4

I'm an Android Developer and as part of my next app I will need to evaluate a large variety of user created mathematical expressions and equations. I am looking for a good java library that is lightweight and can evaluate mathematical expressions using user defined variables and constants, trig and exponential functions, etc.

I've looked around and Jep seems to be popular, but I would like to hear more suggestions, especially from people who have used these libraries before.

+3  A: 

I wrote this many years ago; it has the qualities you mention and it's still getting used in new educational applets, apparently.

Update: Compared to JEval 0.9.4:

  • this ran >100 times faster on a small benchmark I tried, on my MacBook
  • the .jar is 6 times smaller
  • it produces more-helpful error messages (or at least tries to)
  • the syntax for variables is like 'x' instead of '#{x}'
  • calling it for numeric calculations is simpler (JEval seems to need to convert to/from strings, if I understand it right)
  • it has the ^ exponentiation operator
  • it has fewer features (no string functions, etc.)

Compared to Jep-3.3.0-trial:

  • it's free
  • it ran >5 times as fast on the same benchmark (evaluating 3.14159*x^2 for a million different values of x)
  • the .jar is 20 times smaller
  • it usually produces more-helpful error messages
  • it has many fewer features
Darius Bacon
+1  A: 

JEval is a good alternative. I abandoned Jep due to it becoming commercial. The only concern is that JEval seems to be a little dormant at the moment (last release in 2008).

gpampara
+1  A: 

I wrote a simple but capable Math Expression Evaluator a while back, which is free and open-source. It's main advantage is being fast and tiny - both are a good thing with hand-held devices. If it meets your need you are welcome to use it.

Software Monkey
Nice an small, but I'm afraid I need support for more advanced functions and expressions.
CodeFusionMobile
I tried this and it seems to work great. Nice and simple. Thanks!
dreeves
A: 

This doesn't exactly fit my initial conditions, but I found a wonderful parser written in C++. I'm trying to figure out Android's Native code support to see if I can use it. It's exactly what I need.

Here's the documentation for the project.
http://www.codeproject.com/KB/recipes/MathieuMathParser.aspx

CodeFusionMobile