Ancono
A programming view of mathematics besides a math library.
Install / Use
/learn @Ezrnest/AnconoREADME
Ancono
An object-oriented and functional view of mathematics besides a math library on JVM platform.
Introduction
Ancono aims to provide a programming view of mathematics, as well as a wide range of basic and advanced math tools, focusing both on simplicity and efficiency. It is also good to use it for studying purpose.
This library contains the following modules:
-
Math functions:
Basic math functions including GCD, LCM, mod, power and mod, mod inverse, Chinese remainder, factoring, primitive root and more.
-
Numbers:
Ancono implements fraction, complex, integers in finite fields and so on.
Users can choose their desired number models and operate the numbers with build-in methods. It is also possible for users to customize or add new number models, and they can be used with full compatibility.
See examples <a href="#numbers">here</a>.
-
Polynomials, multinomials and expression:
Ancono enables users to operate polynomials and multinomials over a field (or over some kind of ring). Methods of polynomial algebra, gcd, remainder, factorizing over Z/p and more are provided.
General expression internally stored as abstract syntax tree is also supported. Expressions can be simplified using simplification rules. Currently, basic simplification rules are implemented, and user can also add extensions if necessary.
See examples: <a href="#polynomials">polynomial</a>, <a href="#expressions">expression</a>.
-
Linear algebra
Ancono supports computations of matrices and vectors over a ring or over a field. Linear spaces and linear transformations are also included. A tensor class that is
like numpy's ndarray is also provided.
Matrix: determinant, rank, solution space, null space, characteristic polynomial, adjoint, QR, LU and Cholesky decomposition, Echelon, Frobenious normal forms and so on. Special methods for matrix over a ring or UFD are also provided.
Vector: inner product, outer product(in R^3), linear independent sets, Schmidt method and more.
Tensor: tensor algebra, inner, wedge, einsum, slicing, reshaping and so on.
See examples <a href="#linearAlg">here</a>.
-
Abstract algebra
A general framework of interfaces is defined. There are also some methods for finite groups and finite fields.
See examples <a href="#finiteGroups">here</a>.
-
Plane analytic geometry
Line, triangle, conic sections (including circle, ellipse, hyperbola and parabola) and affine transformations are provided in Ancono. Useful methods are available, including computing the intersection points, computing the four kinds of centers of a triangle and so much more.
See examples <a href="#planeAG">here</a>.
-
Number theory and Combinations
Ancono provides useful tools for number theory and combination, such as enumerating primes, factorization and permutations.
See examples <a href="#finiteGroups">here</a>.
-
Logic
With Ancono, user can construct and operate formulas of proposition logic and first order logic.
See examples <a href="#logic">here</a>.
-
Calculus
Utilities for derivatives, Taylor series, limits, differential forms and more are provided.
See examples <a href="#calculus">here</a>.
-
Probability
Probability spaces and random variables. Ancono provides a framework resembling the mathematic view of random variable. Stochastic processes are also included.
See examples <a href="#prob">here</a>.
-
Differential geometry
Curve and plane in 3-dimensional Euclidean space, computing curvature, torsion, Frenet frame, fundamental forms ...
See examples <a href="#dgeometry">here</a>.
-
Graph theory
Graphs, priority-first search, connected components, Euclidean cycle and so on.
This project is still being developed, more features will be available in the future.
Number models
Number model is a core concept in this library, it is like a generic type for objects but with additional set of operations.
Generally speaking, we treat mathematical objects in different ways in different situations. For example, the number 1
can be viewed as an integer, a rational number, a real number, a complex number or even a constant polynomial, depending
on the implicit context. In addition, in different cases we define different sets of operations on them. For example, we
can compare two real numbers (in natural order) but not two complex numbers. On the other hand, for computational and
complexity reasons, even the same mathematical object have to be treated differently in programming, such as int
,long, and BigInteger. Therefore, there does not exist a most general way to treat those objects, and we call a
concrete implementation for such an object in programming as a 'number model'.
Since we can use the same type in programming to represent different mathematical objects
(for example, int for both natural numbers and integers), we separate the number model type from the operations on it.
The latter is provided in a hierarchy of calculator interfaces, while the former can be arbitrary. We use the name '
number model' to refer to both the type and the operations.
Math objects (in Ancono the class MathObject) are usually based on number models. For example, we have matrices of
integers, rational numbers or so on. Although the number model can be different, the operations(or properties) defined
in math objects are in general the same (for example the matrix multiplication). When creating a math object, a
calculator is generally required.
Various number models are defined in Ancono, such as fraction, complex and expression. Generally, you can get the
corresponding calculator by calling the static method calculator(). Implementations of calculators of built-in number
types(int, long, double) are provided in Calculators.
If user want to use an external number model, simply implement the corresponding calculator interface and pass the instance of the calculator when needed. Then, it can be used just as other number models.
Calculator
Calculator interface defines a set of basic operations that might be used. Ancono uses a calculator to define all the operations other than creates general interface for all number models, because multiple kinds of operations can be defined on a number model class, and some number classes may be unmodifiable (such as primitive types).
With concepts in abstract algebra and corresponding interfaces, we have a more delicate structure for calculators. The hierarchy structure can be listed below:
-
EqualPredicateto define a equivalence relation. -
SemigroupCalculatorto define a binary operationapply(x,y).AbelSemiGroupCalandMulSemiGroupCalare another versions of the interface with the operation namedaddandmultiply. And inAbelSemiGroupCalthe operation is commutative. -
MonoidCalculatorto provide the identity element for the operationapply(x,y).The corresponding abelian and multiplicative versions are
AbelMonoidCalandMulMonoidCal. -
GroupCalculatorto provide the inversion of the operation, now the number model forms a group with respect to the calculator.The corresponding abelian and multiplicative versions are
AbelGroupCalandMulGroupCal. -
RingCalculatorThe number model now can add and multiply. Addition corresponds to the operation in the group, which should be commutative. -
UnitRingCalculatorto provide the multiplicative identity. -
DivisionRingCalculatorto provide the multiplicative inverse. -
FieldCalculatorThe number model now forms a field with respect to the calculator. -
QuotientCalculatorspecializes the field to be quotient field andRealCalculatorspecializes the field to be real, while providing primary functions likeexpandsin.
There are also extra interfaces for number models with special structure, such as EUDCalculator(calculator for
Euclidean domain) and FunctionCalculator(provides differential).
(To be detailed)
Math Object
The abstract class MathObject is the superclass of almost all Math objects in Ancono. The generic parameter of a
MathObject represents the type of number model that it uses. A math object always holds the
corresponding MathCalculator and one can get it via method getMathCalculator().
(To be detailed)
Examples
<a name="numbers">Using number models</a>:
Fraction:
var a=Fraction.of("1/2");
System.out.println(a);
var b=Fraction.ONE;
var c=a.add(b);
c=c.subtract(Fraction.ZERO);
c=c.multiply(a);
c=c.add(1);
System.out.println(c);
//Result: 7/4
With operator overloading in Kotlin, the code can be simplified as:
val a = Fraction.of("1/2")
val b = Fraction.ONE;
var c = ((a + b) - Fraction.ZERO) * a + 1
println(c)
Complex:
var cal=Calculators.doubleCal();
Complex<Double> z1=Complex.real(1.0,cal);
z1=z1.squareRoot();
Complex<Double> z2=Complex.of(1.0,2.0,cal);
Complex<Double> z3=z1.multiply(z2);
System.out.println(z3);
//Result: (1.0)+(2.0)i
Mobius transformation and extended complex:
var mc=Calculators.doubleDev(); // double calculator with deviation
var one=Complex.one(mc);
var i=Complex.i(mc);
var n_i=i.negate();
var f=MobiusTrans.Companion.to01Inf(one,i,n_i);
//creates a Mobius transformation that maps 1,i,-1 to 0,1,inf
System.out.println(f);
System.out.println(f.apply(i)); // 1
System.out.println(f.inverse().apply(Complex.inf(mc))); // -i
Calculations in Z mod p
var mc=Calculators.intModP(29);
System.out.println();
var matrix=Matrix.of(mc,2,2,
1,2,
3,4);
System.out.println("M = ");
matrix.printMatrix();
System.out.println("Inverse of M in Z mod 29 is");
var inv=matrix.inverse();
inv.printMatrix();
System.out.println("Check their product:");
Matrix.multiply(matrix,inv).printMatrix();
<a name="polynomials">Polynomials:</
Related Skills
node-connect
346.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
