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.

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).

###

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.

### Primary Features:

- Basic math operators, with inferred precedence (^ * × · / ÷ % + -).
- Explicit precedence with parenthesis.
- Implicit multiplication of bracketed subexpressions.
- Correct right-associativity of exponentials (power operator).
- Direct support for hexadecimal numbers prefixed by 0x.
- Constants and variables.
- Extensible operators.
- Extensible functions.
- 20 KiB footprint.

### Example

```
MathEval math=new MathEval();
math.setVariable("Top", 5);
math.setVariable("Left", 20);
math.setVariable("Bottom",15);
math.setVariable("Right", 60);
System.out.println("Middle: "+math.evaluate("floor((Right+1-Left)/2)"));
```

###

Try https://code.google.com/p/expressionoasis/. It is an extensible Expression Evaluation framework and will meet such requirements.

###

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

###

There is a new commercial tool called formula4j, which may be of interest to some.