A symbolic mathematics library for Java. JMathematics represents mathematical entities exactly and performs formal operations on them — no floating-point approximation unless explicitly requested.
Complete number hierarchy with exact representations:
| Type | Set | Description |
|---|---|---|
NaturalNumber |
N | Non-negative integers |
IntegerNumber |
Z | Strictly negative integers |
DecimalNumber |
D | Exact decimals (e.g. 3.14) |
RationalNumber |
Q | Irreducible fractions (e.g. 1/3) |
NamedConstant |
R | Pi, e |
PowerNumber |
R | a^b, covers roots |
LogarithmNumber |
R | log_a(b), ln |
TrigonometricNumber |
R | sin, cos, tan, arcsin, arccos, arctan |
RealExpression |
R | Composite expressions (e.g. 2 + sqrt(3)) |
ComplexNumber |
C | a + bi |
Every number simplifies to its canonical form at construction:
IntegerNumber.of(5) returns a NaturalNumber,
RationalNumber.of(1, 4) returns a DecimalNumber (0.25),
PowerNumber.of(4, 1/2) returns NaturalNumber(2).
Cross-type arithmetic via RealNumbers:
RealNumbers.add(NaturalNumber.of(1), RationalNumber.of(1, 3)) // -> 4/3
RealNumbers.multiply(RationalNumber.of(2, 3), RationalNumber.of(3, 4)) // -> 0.5
RealNumbers.negate(NaturalNumber.of(5)) // -> -5
RealNumbers.divide(NaturalNumber.of(7), NaturalNumber.of(3)) // -> 7/3Rational arithmetic is exact (via BigInteger). Operations with irrationals
produce RealExpression when they cannot be simplified further.
Mathematical sets as first-class objects:
- ClassicalNumberSet — N, Z, D, Q, R, C with sign and zero
restrictions (26 predefined variants via
NumberSets) - EnumerationSet — finite sets by enumeration
- IntervalSet — bounded intervals with open/closed bounds
- UnionSet / IntersectionSet — n-ary, with flattening and deduplication
- DifferenceSet — binary (A \ B)
Operations via Sets facade:
Sets.union(setA, setB, setC)
Sets.intersection(setA, setB)
Sets.difference(universe, excluded) // complementExact comparison between real numbers via RealNumbers.compare():
- Rational vs Rational: cross-multiplication (always decidable)
- PowerNumber vs Rational: raising to a common power
- French mathematical convention: positive means >= 0, negative means <= 0
- Formal mathematics:
approximate()is only for display purposes, never for mathematical operations
- Java 25
- Maven
mvn compilemvn test639 tests covering all number types and set operations.
LGPL v3