Skip to content

ltennstedt/reciprocal

Repository files navigation

reciprocal: Mathematical library for the JVM

GitHub Actions Bugs Code Smells Coverage Duplicated Lines (%) Lines of Code Maintainability Rating Quality Gate Status Reliability Rating Security Rating Technical Debt Vulnerabilities

reciprocal is a free software library for the JVM that provides or will provide implementations of fractions, complex numbers, vectors, matrices, polynomials and geometric shapes and their arithmetic and properties.

What reciprocal will provide:

  • Fractions and complex numbers
  • Vectors and matrices
  • Determinant calculation
  • Polynomials
  • Circles and rectangles
  • Pseudorandom number generators
  • Kotlin module
  • Scala module
  • Custom assertions for AssertJ
  • Custom matchers for Kotest

What reciprocal will not provide:

  • Solver for equations
  • Matrix decomposition, reduction or factorization

Building

A JDK in version 17 and Maven in version 3.8 is needed to build this project.

mvn install site

Implementation details

  • Java 17
  • All types are immutable.
  • Absolutely no null values
  • Numbers extend java.lang.Number and fractions implements java.lang.Comparable
  • Comparators implement java.lang.Comparator
  • Numbers, vectors, matrices and polynomials implement java.io.Serializable
  • Classes of numbers, vectors and matrices are final.
  • Useful hashCode, equals and toString methods
  • Builders for vectors and matrices
  • Parameter validation and fast failing
  • Nullability annotations

Usage

class Class {
    void method() {
        // arithmetic methods follow the naming scheme of BigInteger/BigDecimal
        new Fraction(2L, 3L).add(new Fraction(3L, 4L));

        // getting an element of a vector or matrix
        vector.get(1);
        matrix.get(2, 3);

        // check if an element is contained in a vector or matrix
        if (vector.contains(0L)) {
            doSomethingCool();
        }

        // classic builders for vectors and matrices with a fluent API        
        LongVector.ofSize(3)
                .computationOfAbsentees(i -> new SecureRandom().nextLong()) // default: i -> 0L
                .set(1, 1L)
                .set(3, 2L)
                .build();
    }
}

Goals

Links