There is colt.
Answer from miku on Stack OverflowThe Colt library provides fundamental general-purpose data structures optimized for numerical data, such as resizable arrays, dense and sparse matrices (multi-dimensional arrays), linear algebra, associative containers and buffer management.
The Jet library contains mathematical and statistical tools for data analysis, powerful histogramming functionality, Random Number Generators and Distributions useful for (event) simulations, and more.
The CoreJava library contains C-like print formatting. The Concurrent library contains standardized, efficient utility classes commonly encountered in parallel & concurrent programming.
What is the best math library to use with java? - Stack Overflow
I need a Java library that simplifies math equations - Software Recommendations Stack Exchange
java - Should I import a math library, and if so how? - Stack Overflow
Java math libraries?
Videos
There is colt.
The Colt library provides fundamental general-purpose data structures optimized for numerical data, such as resizable arrays, dense and sparse matrices (multi-dimensional arrays), linear algebra, associative containers and buffer management.
The Jet library contains mathematical and statistical tools for data analysis, powerful histogramming functionality, Random Number Generators and Distributions useful for (event) simulations, and more.
The CoreJava library contains C-like print formatting. The Concurrent library contains standardized, efficient utility classes commonly encountered in parallel & concurrent programming.
Apache Commons Math might be helpful. So might JAMA.
UPDATE: In the 2.5 years since I last answered this, I've become aware of Apache's Mahout and WEKA. Both are excellent Java libraries for data analysis.
Both are more appropriate answers for the narrower concern of data mining.
You can use the Symja - Java computer algebra and symbolic math library.
import org.matheclipse.core.eval.ExprEvaluator;
import org.matheclipse.core.expression.F;
import org.matheclipse.core.interfaces.IAST;
import org.matheclipse.core.interfaces.IExpr;
import org.matheclipse.core.interfaces.ISymbol;
import org.matheclipse.parser.client.SyntaxError;
public class Example {
public static void main(String[] args) {
try {
ExprEvaluator util = new ExprEvaluator(false, (short) 100);
// Convert an expression to the internal Java form:
// Note: single character identifiers are case sensitive
// (the "D()" function identifier must be written as upper case character)
String javaForm = util.toJavaForm("4*x + x - 20 + 10");
// prints: Plus(ZZ(-20L),x,Times(C4,x),C10)
System.out.println("Out[1]: " + javaForm.toString());
// Use the Java form to create an expression with F.* static methods:
ISymbol x = F.Dummy("x");
IAST function = F.Plus(F.ZZ(-20L), x, F.Times(F.C4, x), F.C10);
IExpr result = util.eval(function);
// print: -10+5*x
System.out.println("Out[2]: " + result.toString());
} catch (SyntaxError e) {
// catch Symja parser errors here
System.out.println(e.getMessage());
} catch (RuntimeException rex) {
System.out.println(rex.getMessage());
}
}
}
DataMelt (http://jwork.org/dmelt) does this. Here is an example (I use Jython, but you can use Java too)
from jhplot.math import *
from jhplot import *
j=Symbolic("jscl") # using jscl engine
print j.simplify("(x + 1)^(1/x)") == "(1+x)^(1/x)"
print j.simplify("(x^2-1)/(x-1)") == "1+x"
This code returns "true" for all such simplifications
E and PI are not functions, they're static fields (data members). That code will output their values correctly. You don't have to import anything, the Math class is in the java.lang package, which is imported by default. (It's the only package imported by default, I believe.)
You don't have to import anything here. The java.lang.Math class should already be available as java.lang package is imported by default
One thing I learned this year is that maybe I should figure out how to use some math libraries/packages.
There are two problems that I ended up using a little outside help with. One was doing a polyfit. Especially, I have a list of input values and output results and I want the computer to tell me a function that matches. This is good for things where I'm sure there is a simple math relation, I just can't see it. For example in one problem, I had a series of numbers and needed polyfit to tell me I was actually looking at 5 + 2x + x^2 or something like that.
I ended up using python and numpy for that, which worked but I'd like to add that sort of capability to my Java tool kit.
The other, I kinda worked around but it would be nice to have is a symbolic math solver.
I've poked at Symja which has a enticing named solver:
https://bitbucket.org/axelclk/symja_android_library/wiki/Solve
But I'm having trouble getting the dependencies to run. Anyone have anything they like?
In case it matters, I'm using bazel to build, which means I can easily include anything that is on maven.