Skip to content

Traroth/JMathematics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JMathematics

A symbolic mathematics library for Java. JMathematics represents mathematical entities exactly and performs formal operations on them — no floating-point approximation unless explicitly requested.

Features

Number types

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

Arithmetic

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/3

Rational arithmetic is exact (via BigInteger). Operations with irrationals produce RealExpression when they cannot be simplified further.

Sets

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)  // complement

Formal comparison

Exact comparison between real numbers via RealNumbers.compare():

  • Rational vs Rational: cross-multiplication (always decidable)
  • PowerNumber vs Rational: raising to a common power

Conventions

  • French mathematical convention: positive means >= 0, negative means <= 0
  • Formal mathematics: approximate() is only for display purposes, never for mathematical operations

Requirements

  • Java 25
  • Maven

Build

mvn compile

Test

mvn test

639 tests covering all number types and set operations.

License

LGPL v3

About

A symbolic mathematics library for Java. Exact arithmetic on integers, decimals, rationals, irrationals (roots, logarithms, trigonometric values, π, e) and complex numbers. Mathematical sets with formal inclusion and membership. No floating-point approximation — all operations are exact and formally provable.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages