Skip to main content

Crate use_math

Crate use_math 

Source
Expand description

§use-math

Feature-gated RustUse facade for concrete arithmetic helpers, prime utilities, polynomial primitives, equation helpers, approximate numerical helpers, vector primitives, interval primitives, geometry, checked counting, Catalan-family sequences, Geode-array primitives, progression helpers, integer helpers, boolean algebra helpers, small set helpers, explicit trigonometry helpers, descriptive statistics helpers, compact linear algebra helpers, finite algebra law helpers, raw-number helpers, complex numbers, numerical calculus, probability, real-number primitives, and rational arithmetic.
One dependency when you want one import surface. Focused crates stay available when you want the narrowest build or an explicit direct crate for one math domain.

Rust 1.95.0+ Edition 2024 Default feature full Features 27 optional modules License MIT or Apache-2.0

Surface · When to use it · Installation · Examples · Features · Constraints

use-math composes the focused RustUse math crates into one entry point while keeping their APIs direct and explicit. It re-exports the currently supported arithmetic, prime, polynomial, equation, interval, geometry, combinatorics, Catalan-family, Geode-array, progression, integer-helper, boolean-algebra, set-helper, trigonometry, descriptive statistics, compact linear algebra, finite algebra law, raw-number, complex-number, numerical-calculus, probability, real-number, and rational-number surfaces at the crate root, exposes nested modules for every focused crate in the workspace, surfaces vector primitives through use_math::vector, interval primitives through use_math::interval, prime utilities through use_math::prime, polynomial helpers through use_math::polynomial, equation helpers through use_math::equation, approximate numerical helpers through use_math::numerical, and keeps the shared prelude limited to the items that already have concrete ergonomic value.

Root re-exports
Call functions like checked_add, div_floor, factorial, catalan, hyper_catalan, geode_memoized, arithmetic_sum, classify_number, gcd, identity_element, implication, is_prime, prime_factors, quadratic_roots, solve_linear, solve_quadratic, is_ring, set_union, sin_deg, mean, solve_2x2, or types like Polynomial, Roots, LinearEquation, QuadraticEquation, TypeVector, Point2, IntegerSign, Bound, Interval, NumberCategory, Angle, Matrix2, Matrix3, Matrix4, Complex, Differentiator, Probability, Real, and Rational directly from use_math.
Nested modules
Use use_math::arithmetic, use_math::prime, use_math::polynomial, use_math::equation, use_math::numerical, use_math::vector, use_math::interval, use_math::geometry, use_math::combinatorics, use_math::geode, use_math::number, or use_math::algebra when you want crate-shaped namespacing.
Shared prelude
Pull common items from use_math::prelude when fast onboarding matters more than fully qualified imports.

§What this crate provides

Entry pointWhat it exposesBest fit
Root re-exportsDirect access to enabled arithmetic, modular arithmetic, prime utilities, polynomial primitives, non-conflicting equation helpers, interval, geometry, combinatorics, Catalan-family, Geode-array, progression, integer-helper, boolean-algebra, set-helper, trigonometry, descriptive statistics, compact linear algebra, finite algebra law, raw-number, complex-number, numerical-calculus, probability, real-number, and rational-number itemsCall sites that want short imports
use_math::arithmeticThe use-arithmetic crate as a nested moduleCode that prefers explicit arithmetic namespacing
use_math::modularThe use-modular crate as a nested module with normalized residues, congruence checks, inverses, exponentiation, and the Modular helper typeCode that wants explicit modular arithmetic namespacing
use_math::primeThe use-prime crate as a nested module with primality checks, next and previous prime search, factorization helpers, and sieve utilitiesCode that wants explicit prime-utility namespacing
use_math::polynomialThe use-polynomial crate as a nested module with Polynomial, evaluation, derivatives, arithmetic, and low-degree real-root helpersCode that wants explicit polynomial namespacing
use_math::equationThe use-equation crate as a nested module with Roots, RootSolver, linear and quadratic equation helpers, small 2x2 systems, and the optional low-degree polynomial bridge when both equation and polynomial are enabledCode that wants explicit equation-solving namespacing
use_math::numericalThe use-numerical crate as a nested module with epsilon comparisons, finite differences, deterministic integration rules, iterative root finding, and the optional interval-based bisection bridge when both numerical and interval are enabledCode that wants explicit approximate numerical namespacing
use_math::vectorThe use-vector crate as a nested module with Vector2, Vector3, Vector4, and vector operationsCode that wants reusable vector math without root-name collisions
use_math::intervalThe use-interval crate as a nested module with Bound, Interval, containment checks, overlap tests, and intersection operationsCode that wants explicit interval namespacing
use_math::matrixThe use-matrix crate as a nested module with Matrix2, Matrix3, Matrix4, and direct matrix operationsCode that wants explicit matrix namespacing
use_math::geometryThe use-geometry crate as a nested moduleCode that prefers explicit geometry namespacing
use_math::combinatoricsThe use-combinatorics crate as a nested moduleCode that prefers explicit combinatorics namespacing
use_math::geodeThe use-geode crate as a nested moduleCode that prefers explicit Geode-array namespacing
use_math::algebraThe use-algebra crate as a nested moduleCode that prefers explicit algebra namespacing
use_math::preludeCommon items from enabled concrete featuresSmall apps, examples, and quick starts
If you need to…Start here
Add one dependency and opt into math surfaces with featuresuse-math
Keep arithmetic-helper code isolateduse-arithmetic directly
Keep modular arithmetic isolateduse-modular directly
Keep prime utilities isolateduse-prime directly
Keep polynomial helpers isolateduse-polynomial directly
Keep equation helpers isolateduse-equation directly
Keep approximation-oriented numerical helpers isolateduse-numerical directly
Keep reusable vector primitives isolateduse-vector directly
Keep interval and bound primitives isolateduse-interval directly
Keep matrix primitives isolateduse-matrix directly
Keep geometry-only code isolateduse-geometry directly
Keep counting-only code isolateduse-combinatorics directly
Keep Catalan-family sequence helpers isolateduse-catalan directly
Keep Geode-array helpers isolateduse-geode directly
Keep progression helpers isolateduse-series directly
Keep finite algebra law helpers isolateduse-algebra directly
Keep integer-helper code isolateduse-integer directly
Keep boolean algebra helpers isolateduse-logic directly
Keep set helpers isolateduse-set directly
Keep trigonometry helpers isolateduse-trigonometry directly
Keep descriptive statistics helpers isolateduse-statistics directly
Keep solver-style linear helpers isolateduse-linear directly
Keep raw-number helpers isolateduse-number directly
Keep complex-number primitives isolateduse-complex directly
Keep numerical-calculus helpers isolateduse-calculus directly
Keep explicit probability primitives isolateduse-probability directly
Keep validated real-number helpers isolateduse-real directly
Keep exact rational arithmetic isolateduse-rational directly
Minimize both dependency weight and API widthThe focused crate directly

§When to choose the facade

Use the facade when consumer ergonomics matter more than squeezing the dependency graph to the smallest possible shape.

ScenarioChoose use-math?Why
You want one dependency for arithmetic helpers, prime utilities, polynomial primitives, equation helpers, vector primitives, interval primitives, matrix primitives, geometry, counting, Catalan-family sequences, Geode-array primitives, progression helpers, integer helpers, boolean algebra helpers, set helpers, trigonometry helpers, descriptive statistics helpers, solver-style linear helpers, raw-number helpers, complex primitives, numerical calculus, probability, real-number helpers, and rational arithmeticYesThe facade keeps imports unified behind features
You are building a small app or example projectYesRoot re-exports and the prelude reduce setup friction
You want namespace access to every focused crateUsually yesThe facade exposes every focused crate name consistently today
You only need geometryUsually nouse-geometry stays narrower and more explicit
You only need combinatoricsUsually nouse-combinatorics avoids unrelated modules
You only need Catalan-family sequence helpersUsually nouse-catalan keeps that counting surface narrow and explicit
You only need Geode-array primitivesUsually nouse-geode keeps finite type vectors and small exact Geode recurrences narrow and explicit
You only need arithmetic helpersUsually nouse-arithmetic keeps floor division and overflow-mode helpers explicit and local
You only need prime utilitiesUsually nouse-prime keeps primality, sieves, and factorization explicit and local
You only need polynomial helpersUsually nouse-polynomial keeps direct polynomial operations and low-degree roots explicit and local
You only need equation helpersUsually nouse-equation keeps direct solving helpers, small systems, and reusable root types explicit and local
You only need approximation-oriented numerical helpersUsually nouse-numerical keeps epsilon comparisons, deterministic integration rules, and iterative solvers explicit and local
You only need progression helpersUsually nouse-series keeps nth-term and partial-sum helpers narrow and explicit
You only need finite algebra law helpersUsually nouse-algebra keeps closure-based structure checks explicit and local
You only need integer helpersUsually nouse-integer keeps parity, divisibility, and gcd/lcm logic local
You only need boolean algebra helpersUsually nouse-logic keeps named truth-table helpers explicit and local
You only need set helpersUsually nouse-set keeps membership and set-operation intent explicit and local
You only need trigonometry helpersUsually nouse-trigonometry keeps degree/radian handling and trig evaluation explicit and local
You only need descriptive statistics helpersUsually nouse-statistics keeps mean, median, and variance summaries explicit and local
You only need reusable vector primitivesUsually nouse-vector keeps base vector math explicit without geometry or matrix-specific APIs
You only need reusable interval or bound primitivesUsually nouse-interval keeps generic interval semantics explicit and local
You only need matrix primitivesUsually nouse-matrix keeps matrix construction and direct matrix operations explicit and local
You only need solver-style linear helpersUsually nouse-linear keeps solve logic explicit while matrix and vector ownership stays focused
You only need raw-number helpersUsually nouse-number keeps plain f64 classification and shared constants explicit and local
You only need numerical calculusUsually nouse-calculus keeps the approximation policy local and direct
You only need probability primitivesUsually nouse-probability keeps event assumptions local and direct
You only need validated real-number helpersUsually nouse-real keeps floating-point validation and real-specific policy local
You only need exact rational arithmeticUsually nouse-rational keeps exact fraction normalization and arithmetic local

[!TIP] The facade is intentionally thin. It is not a second abstraction layer over the focused crates.

§Installation

Default features enable the current full surface:

[dependencies]
use-math = "0.0.6"

Geometry only:

[dependencies]
use-math = { version = "0.0.6", default-features = false, features = ["geometry"] }

Combinatorics only:

[dependencies]
use-math = { version = "0.0.6", default-features = false, features = ["combinatorics"] }

Interval only:

[dependencies]
use-math = { version = "0.0.6", default-features = false, features = ["interval"] }

Modular only:

[dependencies]
use-math = { version = "0.0.6", default-features = false, features = ["modular"] }

Prime only:

[dependencies]
use-math = { version = "0.0.6", default-features = false, features = ["prime"] }

Polynomial only:

[dependencies]
use-math = { version = "0.0.6", default-features = false, features = ["polynomial"] }

Equation only:

[dependencies]
use-math = { version = "0.0.6", default-features = false, features = ["equation"] }

Numerical only:

[dependencies]
use-math = { version = "0.0.6", default-features = false, features = ["numerical"] }

§Quick examples

§Checked counting from the root

use use_math::{combinations, factorial, permutations};

assert_eq!(factorial(5)?, 120);
assert_eq!(permutations(5, 3)?, 60);
assert_eq!(combinations(5, 2)?, 10);

§Catalan-family counting from the root

use use_math::{catalan, fuss_catalan};

assert_eq!(catalan(4)?, 14);
assert_eq!(fuss_catalan(3, 3)?, 12);

§Geode-array helpers from the root

use use_math::{TypeVector, geode_memoized, hyper_catalan};

let vector = TypeVector::new(vec![0, 1])?;

assert_eq!(hyper_catalan(&vector)?, 1);
assert_eq!(use_math::geode::geode(&vector)?, 3);
assert_eq!(geode_memoized(&vector)?, 3);

§Progression helpers from the root

use use_math::{arithmetic_nth_term, arithmetic_sum, geometric_nth_term, geometric_sum};

assert_eq!(arithmetic_nth_term(3, 2, 4)?, 11);
assert_eq!(arithmetic_sum(3, 2, 5)?, 35);
assert_eq!(geometric_nth_term(2, 3, 4)?, 162);
assert_eq!(geometric_sum(2, 3, 4)?, 80);

§Boolean algebra helpers from the root

use use_math::{equivalence, exclusive_or, implication, majority, nand, nor};

assert!(implication(false, true));
assert!(equivalence(true, true));
assert!(exclusive_or(true, false));
assert!(!nand(true, true));
assert!(nor(false, false));
assert!(majority(true, true, false));

§Set helpers from the root

use use_math::{
	are_disjoint, contains_member, is_subset, set_difference, set_intersection,
	set_symmetric_difference, set_union,
};

let left = [1, 2, 2, 3];
let right = [3, 4, 2, 5];

assert!(contains_member(&left, &1));
assert!(is_subset(&[2, 3], &right));
assert!(!are_disjoint(&left, &right));
assert_eq!(set_union(&left, &right), vec![1, 2, 3, 4, 5]);
assert_eq!(set_intersection(&left, &right), vec![2, 3]);
assert_eq!(set_difference(&left, &right), vec![1]);
assert_eq!(set_symmetric_difference(&left, &right), vec![1, 4, 5]);

§Trigonometry helpers from the root

use use_math::{Angle, cos_deg, degrees_to_radians, normalize_degrees, radians_to_degrees, sin_deg, tan_deg};

let acute = Angle::from_degrees(30.0);
let wrapped = Angle::from_degrees(765.0).normalized();

assert!((acute.radians() - degrees_to_radians(30.0)).abs() < 1.0e-12);
assert!((acute.degrees() - radians_to_degrees(acute.radians())).abs() < 1.0e-12);
assert!((wrapped.degrees() - 45.0).abs() < 1.0e-12);
assert!((normalize_degrees(-90.0) - 270.0).abs() < 1.0e-12);
assert!((acute.sin() - 0.5).abs() < 1.0e-12);
assert!((cos_deg(60.0) - 0.5).abs() < 1.0e-12);
assert!((sin_deg(30.0) - 0.5).abs() < 1.0e-12);
assert!((tan_deg(45.0) - 1.0).abs() < 1.0e-12);

§Descriptive statistics from the root

use use_math::{mean, median, population_std_dev, population_variance, sample_std_dev, sample_variance};

let values = [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0];
let sample = [1.0, 2.0, 3.0, 4.0];

assert!((mean(&values)? - 5.0).abs() < 1.0e-12);
assert!((median(&values)? - 4.5).abs() < 1.0e-12);
assert!((population_variance(&values)? - 4.0).abs() < 1.0e-12);
assert!((population_std_dev(&values)? - 2.0).abs() < 1.0e-12);
assert!((sample_variance(&sample)? - 1.666_666_666_666_666_7).abs() < 1.0e-12);
assert!((sample_std_dev(&sample)? - 1.290_994_448_735_805_6).abs() < 1.0e-12);

§Linear algebra helpers from the root

use use_math::{Matrix2, solve_2x2};
use use_math::vector::Vector2;

let matrix = Matrix2::new(2.0, 1.0, 5.0, 3.0);
let solution = solve_2x2(matrix, Vector2::new(1.0, 2.0))?;

assert_eq!(solution, Vector2::new(1.0, -1.0));
assert_eq!(matrix * solution, Vector2::new(1.0, 2.0));
assert_eq!(Matrix2::IDENTITY * matrix, matrix);

§Raw-number helpers from the root

use use_math::{
	GOLDEN_RATIO, NumberCategory, NumberSign, SQRT_3, classify_number,
	classify_number_sign, is_finite_number,
};

assert_eq!(classify_number(f64::NAN), NumberCategory::Nan);
assert_eq!(classify_number(f64::from_bits(1)), NumberCategory::Subnormal);
assert_eq!(classify_number_sign(-12.5), Some(NumberSign::Negative));
assert_eq!(classify_number_sign(f64::NAN), None);
assert!(is_finite_number(3.5));
assert!(!is_finite_number(f64::INFINITY));
assert!(((GOLDEN_RATIO * GOLDEN_RATIO) - (GOLDEN_RATIO + 1.0)).abs() < 1.0e-12);
assert!(((SQRT_3 * SQRT_3) - 3.0).abs() < 1.0e-12);

§Finite algebra law helpers from the root

use use_math::{identity_element, is_abelian_group, is_distributive_over, is_ring};

let residues = [0_u8, 1, 2];
let add_mod_3 = |left, right| (left + right) % 3;
let mul_mod_3 = |left, right| (left * right) % 3;

assert_eq!(identity_element(&residues, add_mod_3), Some(0));
assert!(is_abelian_group(&residues, add_mod_3));
assert!(is_distributive_over(&residues, mul_mod_3, add_mod_3));
assert!(is_ring(&residues, add_mod_3, mul_mod_3));

§Integer helpers from the root

use use_math::{IntegerSign, classify_sign, gcd, is_divisible_by, lcm};

assert_eq!(classify_sign(-12), IntegerSign::Negative);
assert!(is_divisible_by(84, 7)?);
assert_eq!(gcd(-54, 24), 6);
assert_eq!(lcm(-6, 15)?, 30);

§Geometry from the root

use use_math::{Orientation2, Point2, Triangle, distance_2d, midpoint_2d, try_orientation_2d};

let a = Point2::try_new(0.0, 0.0)?;
let b = Point2::try_new(4.0, 0.0)?;
let c = Point2::try_new(0.0, 3.0)?;
let triangle = Triangle::try_new(a, b, c)?;

assert_eq!(distance_2d(a, b), 4.0);
assert_eq!(midpoint_2d(a, c), Point2::try_new(0.0, 1.5)?);
assert_eq!(try_orientation_2d(a, b, c)?, Orientation2::CounterClockwise);
assert_eq!(triangle.area(), 6.0);

§Geometry extras behind the feature gate

use use_math::{Aabb2, Orientation2, Point2, orientation_2d_with_tolerance};

let a = Point2::try_new(0.0, 0.0)?;
let b = Point2::try_new(4.0, 0.0)?;
let c = Point2::try_new(0.0, 3.0)?;
let bounds = Aabb2::from_points(a, c);

assert!(bounds.contains_point(Point2::new(0.0, 1.5)));
assert_eq!(orientation_2d_with_tolerance(a, b, c, 0.0)?, Orientation2::CounterClockwise);

§Numerical calculus from the root

use use_math::{Differentiator, IntegrationInterval, Integrator, LimitApproximator};

let differentiator = Differentiator::try_new(1.0e-5)?;
let interval = IntegrationInterval::try_new(0.0, 1.0)?;
let integrator = Integrator::try_new(128)?;
let limit = LimitApproximator::try_new(1.0e-6, 1.0e-5)?;

let slope = differentiator.derivative_at(|x| x.powi(2), 3.0)?;
let area = integrator.simpson(|x| x * x, interval)?;
let sinc_limit = limit.at(
	|x| {
		if x == 0.0 {
			1.0
		} else {
			x.sin() / x
		}
	},
	0.0,
)?;

assert!((slope - 6.0).abs() < 1.0e-6);
assert!((area - (1.0 / 3.0)).abs() < 1.0e-6);
assert!((sinc_limit - 1.0).abs() < 1.0e-5);

§Approximate numerical helpers through the namespace

use use_math::numerical::{RootOptions, approx_eq, bisection};

assert!(approx_eq(0.1 + 0.2, 0.3, 1.0e-12));

let root = bisection(
	|x| x * x - 2.0,
	1.0,
	2.0,
	RootOptions::default(),
)?;

assert!((root - 2.0_f64.sqrt()).abs() < 1.0e-8);

§Probability from the root

use use_math::{Bernoulli, Probability, independent_intersection, independent_union};

let rain = Probability::from_fraction(1, 4)?;
let traffic = Probability::try_new(0.5)?;
let commute = Bernoulli::new(rain);

assert!((independent_intersection(rain, traffic).value() - 0.125).abs() < 1.0e-12);
assert!((independent_union(rain, traffic).value() - 0.625).abs() < 1.0e-12);
assert_eq!(commute.failure_probability(), Probability::try_new(0.75)?);

§Real-number helpers from the root

use use_math::{Real, RealInterval, approx_eq};

let interval = RealInterval::try_new(-2.0, 6.0)?;
let midpoint = interval.midpoint();
let clamped = interval.clamp(Real::try_new(8.0)?);

assert_eq!(clamped, Real::try_new(6.0)?);
assert!(approx_eq(midpoint, Real::try_new(2.0)?, 1.0e-12)?);

§Rational arithmetic from the root

use use_math::Rational;

let half = Rational::try_new(1, 2)?;
let third = Rational::try_new(1, 3)?;

assert_eq!(half.checked_add(third)?, Rational::try_new(5, 6)?);
assert_eq!(half.checked_div(third)?, Rational::try_new(3, 2)?);

§Feature model

FeatureEnablesDefault
arithmeticRe-exports from use-arithmetic, including checked and overflow-mode arithmetic helpers, floor-division helpers, and the use_math::arithmetic namespaceNo
geometryRe-exports from use-geometry, including Aabb2 and tolerance-aware orientation helpersNo
combinatoricsRe-exports from use-combinatoricsNo
catalanRe-exports from use-catalan, including catalan, fuss_catalan, and CatalanErrorNo
geodeRe-exports from use-geode, including TypeVector, hyper_catalan, geode_memoized, and the use_math::geode namespaceNo
algebraRe-exports from use-algebra, including finite algebra-law helpers such as identity_element, is_abelian_group, and is_ringNo
modularRe-exports from use-modular, including normalized residues, Modular, congruence checks, inverses, exponentiation, and the use_math::modular namespaceNo
primeRe-exports from use-prime, including primality checks, next/previous prime search, factorization helpers, sieves, and the use_math::prime namespaceNo
polynomialRe-exports from use-polynomial, including Polynomial, evaluation, derivatives, arithmetic, low-degree real-root helpers, and the use_math::polynomial namespaceNo
equationRe-exports from use-equation, including Roots, RootSolver, LinearEquation, QuadraticEquation, LinearSystem2, solve_linear, solve_quadratic, and the use_math::equation namespace. The low-degree polynomial bridge is also available when polynomial is enabled.No
numericalRe-exports the use-numerical crate as use_math::numerical, including epsilon comparison, finite-difference helpers, deterministic integration rules, iterative root finding, and the optional bisection_interval bridge when interval is also enabledNo
seriesRe-exports from use-series, including arithmetic and geometric progression helpersNo
integerRe-exports from use-integer, including IntegerSign, divisibility helpers, and gcd/lcmNo
intervalRe-exports from use-interval, including Bound, Interval, containment checks, overlap tests, intersections, and the use_math::interval namespace. When numerical is also enabled, this feature also enables use_math::numerical::bisection_interval.No
logicRe-exports from use-logic, including implication, equivalence, XOR, NAND, NOR, and majority helpersNo
setRe-exports from use-set, including membership predicates and order-preserving set operationsNo
trigonometryRe-exports from use-trigonometry, including Angle, degree/radian conversion helpers, normalization helpers, and sin_deg/cos_deg/tan_degNo
statisticsRe-exports from use-statistics, including StatisticsError, mean/median, variance, and standard-deviation helpersNo
matrixRe-exports from use-matrix, including Matrix2, Matrix3, Matrix4, determinants, transpose helpers, and inverses for 2x2 and 3x3 matricesNo
linearRe-exports from use-linear, including solve_2x2 and LinearError; the linear feature also enables the matrix and vector facade surfacesNo
vectorRe-exports the use-vector crate as use_math::vector, including Vector2, Vector3, Vector4, normalization, distance, interpolation, and Vector3::crossNo
numberRe-exports from use-number, including floating-point classification helpers and shared numeric constantsNo
complexRe-exports from use-complex, including Complex and ImaginaryNo
calculusRe-exports from use-calculus, including Differentiator, Integrator, and limit helpersNo
probabilityRe-exports from use-probability, including Probability, Bernoulli, and independent-event helpersNo
rationalRe-exports from use-rational, including Rational and RationalErrorNo
realRe-exports from use-real, including Real, RealInterval, and approx_eqNo
fullEvery focused crate feature in the workspaceYes

[!NOTE] full is the default today because the facade exists to smooth over multi-crate integration. Disable defaults when you need tighter control over compile surface. Every focused crate feature exposes a nested module, while only non-conflicting surfaces are also re-exported at the crate root.

§Design constraints

  • The facade stays close to the focused crates instead of inventing a separate object model.
  • Small APIs are preferred over broad trait-heavy abstractions.
  • Depend on the focused crates directly when the facade would be wider than you need.
  • Facade-only wrapper types, macros, and a second abstraction layer are intentionally out of scope.

§Status

use-math is a concrete pre-1.0 facade crate in the RustUse docs surface. The API remains intentionally thin while every focused crate in the workspace now exposes a concrete public surface. Utility-first facade for RustUse math crates.

Re-exports§

pub use use_arithmetic as arithmetic;
pub use use_algebra as algebra;
pub use use_calculus as calculus;
pub use use_catalan as catalan;
pub use use_combinatorics as combinatorics;
pub use use_complex as complex;
pub use use_geometry as geometry;
pub use use_integer as integer;
pub use use_interval as interval;
pub use use_modular as modular;
pub use use_prime as prime;
pub use use_polynomial as polynomial;
pub use use_equation as equation;
pub use use_numerical as numerical;
pub use use_matrix as matrix;
pub use use_linear as linear;
pub use use_vector as vector;
pub use use_logic as logic;
pub use use_number as number;
pub use use_probability as probability;
pub use use_rational as rational;
pub use use_real as real;
pub use use_series as series;
pub use use_set as set;
pub use use_statistics as statistics;
pub use use_trigonometry as trigonometry;

Modules§

factorization
Prime factorization helpers.
geode
prelude
sieve
Prime sieves and sieve-backed prime generation.

Structs§

Aabb2
An axis-aligned bounding box represented by inclusive minimum and maximum corners.
Angle
Explicit angle value stored in radians.
Bernoulli
A Bernoulli distribution with a single success probability.
Circle
A circle in 2D Euclidean space.
Complex
A complex number stored in rectangular form.
Differentiator
Finite-difference differentiation configuration.
Imaginary
A standalone imaginary value.
IntegrationInterval
A finite interval for definite integration.
Integrator
Numerical integration configuration.
Interval
A mathematical interval described by a lower and upper bound.
LimitApproximator
Symmetric two-sided limit approximation settings.
Line2
An infinite 2D line represented by two sample points.
LinearEquation
A linear equation of the form ax + b = 0.
LinearSystem2
A 2x2 linear system of the form:
Matrix2
A 2x2 matrix stored in row-major order.
Matrix3
A 3x3 matrix stored in row-major order.
Matrix4
A 4x4 matrix stored in row-major order.
Modular
A normalized modular residue paired with its positive modulus.
Point2
A 2D point represented with f64 coordinates.
Polynomial
A polynomial whose coefficients are stored in ascending power order.
Probability
A validated probability value in the closed interval [0, 1].
QuadraticEquation
A quadratic equation of the form ax^2 + bx + c = 0.
Rational
A normalized exact rational number.
Real
A validated finite f64 value.
RealInterval
A checked closed interval [min, max] over finite real values.
Segment2
A finite line segment between two 2D points.
Triangle
A constructed 2D triangle represented by three vertices.
TypeVector
Finite hyper-Catalan type vectors of the form [m2, m3, m4, ...].
Vector2
A 2D vector represented with f64 components.

Enums§

Bound
A lower or upper bound for an interval endpoint.
CalculusError
Errors returned by numerical-calculus helpers.
CatalanError
Errors returned by checked Catalan-family helpers.
CombinatoricsError
Errors returned by checked combinatorics helpers.
GeodeError
Errors returned by checked Geode helpers.
GeometryError
Errors returned by validated geometry constructors.
IntegerError
Errors produced by integer helper operations.
IntegerSign
Sign classification for a signed integer value.
LinearError
Errors returned by linear helpers when a system cannot be solved.
NumberCategory
Broad categories for raw f64 values.
NumberSign
Sign classes for raw numeric values that are not NaN.
Orientation2
The winding order of three 2D points.
ProbabilityError
Errors returned by validated probability helpers.
RationalError
Errors returned by validated rational-number helpers.
RealError
Errors returned by validated real-number helpers.
Roots
Real-root outcomes for the small equation helpers in this crate.
SeriesError
Errors returned by checked progression helpers.
StatisticsError
Errors returned by statistics helpers when the input cannot support the requested summary.

Constants§

GOLDEN_RATIO
The golden ratio as an f64.
GOLDEN_RATIO_F32
The golden ratio as an f32.
SQRT_3
The square root of three as an f64.
SQRT_3_F32
The square root of three as an f32.

Traits§

CheckedArithmetic
Primitive integer types supported by the checked arithmetic wrappers.
RootSolver
Shared trait for equation types that can solve themselves.
SaturatingArithmetic
Primitive integer types supported by the saturating arithmetic wrappers.
WrappingArithmetic
Primitive integer types supported by the wrapping arithmetic wrappers.

Functions§

aabb_from_points
Creates a bounding box from any two corners.
approx_eq
Compares two real values with an explicit non-negative tolerance.
are_coprime
Returns whether two integers share no positive common divisor other than one.
are_disjoint
Returns whether left and right share no common members.
arithmetic_nth_term
Returns the zero-based indexth term of an arithmetic progression.
arithmetic_sum
Returns the sum of the first terms values of an arithmetic progression.
catalan
Returns the nth Catalan number using checked u128 arithmetic.
catalan_from_geode_dimension
Returns the one-dimensional Catalan value that matches [n].
central_difference
Approximates the first derivative with a central difference.
checked_add
Returns left + right, or None on overflow.
checked_div_ceil
Returns the mathematical ceiling of dividend / divisor.
checked_div_floor
Returns the mathematical floor of dividend / divisor.
checked_factorial
Returns n! using checked u128 arithmetic.
checked_is_divisible_by
Returns whether value is evenly divisible by divisor.
checked_lcm
Computes the least common multiple of two unsigned integers.
checked_mod_floor
Returns the mathematical floor-style remainder of dividend / divisor.
checked_mul
Returns left * right, or None on overflow.
checked_product_factorials
Returns the checked product of each factorial in values.
checked_sub
Returns left - right, or None on overflow.
classify_number
Classifies a raw f64 by floating-point category.
classify_number_sign
Classifies the sign of a raw f64 while keeping NaN explicit.
classify_sign
Classifies a signed integer as negative, zero, or positive.
combinations
Returns the number of unordered selections of size k from n items.
contains_member
Returns whether value is a member of set.
cos_deg
Evaluates cos for a degrees input.
degrees_to_radians
Converts a degrees value into radians.
diagonal_geode_2d
Returns the diagonal Geode coefficient for [n, n].
diagonal_geode_3d
Returns the diagonal Geode coefficient for [n, n, n].
diagonal_geode_4d
Returns the diagonal Geode coefficient for [n, n, n, n].
distance_2d
Returns the Euclidean distance between two 2D points.
distance_squared_2d
Returns the squared Euclidean distance between two 2D points.
div_ceil
Returns the mathematical ceiling of dividend / divisor.
div_floor
Returns the mathematical floor of dividend / divisor.
equivalence
Returns whether two boolean values are logically equivalent.
exact_divide
Returns an exact integer quotient.
exclusive_or
Returns the exclusive-or of two boolean values.
face_count
Returns the total face count F = m2 + m3 + m4 + ....
factorial
Returns n! using checked u128 arithmetic.
factorization
Returns the prime factorization of n as (prime, exponent) pairs.
fuss_catalan
Returns the nth Fuss-Catalan number for a positive order.
gcd
Computes the non-negative greatest common divisor of two signed integers.
geode_memoized
Returns the Geode coefficient G[m] using internal memoization.
geode_on_first_axis
Returns the Geode coefficient along the first axis [n].
geometric_nth_term
Returns the zero-based indexth term of a geometric progression.
geometric_sum
Returns the sum of the first terms values of a geometric progression.
has_inverses
Returns whether every value in elements has a two-sided inverse with respect to identity and operation.
hyper_catalan
Returns the finite-type hyper-Catalan coefficient for m.
identity_element
Returns a two-sided identity element for operation, if one exists in elements.
implication
Returns the material implication left -> right.
independent_intersection
Returns the probability of two independent events both happening.
independent_union
Returns the probability of at least one of two independent events happening.
is_abelian_group
Returns whether elements with operation form an abelian group.
is_associative
Returns whether operation is associative over elements.
is_closed_under
Returns whether applying operation to any pair of values in elements yields another member of elements.
is_commutative
Returns whether operation is commutative over elements.
is_composite
Returns true when n is composite.
is_congruent
Returns true when a and b are congruent modulo modulus.
is_distributive_over
Returns whether multiply distributes over add from both sides on elements.
is_divisible_by
Returns whether value is evenly divisible by divisor.
is_even
Returns whether an integer is evenly divisible by two.
is_finite_number
Returns whether a raw f64 is finite.
is_group
Returns whether elements with operation form a group.
is_monoid
Returns whether elements with operation form a monoid.
is_odd
Returns whether an integer leaves a remainder of one when divided by two.
is_prime
Returns true when n is prime.
is_ring
Returns whether elements with add and multiply form a ring.
is_subset
Returns whether every unique value in left appears in right.
lcm
Computes the non-negative least common multiple of two signed integers.
linear_root
Returns the real root of ax + b = 0.
majority
Returns whether at least two of three inputs are true.
mean
Returns the arithmetic mean of values.
median
Returns the median of values.
midpoint_2d
Returns the midpoint between two 2D points.
mod_add
Computes (a + b) mod modulus and returns the normalized residue.
mod_floor
Returns the mathematical floor-style remainder of dividend / divisor.
mod_inverse
Computes the multiplicative inverse of value modulo modulus.
mod_mul
Computes (a * b) mod modulus and returns the normalized residue.
mod_normalize
Normalizes value into the residue class 0..modulus.
mod_pow
Computes base.pow(exponent) mod modulus using exponentiation by squaring.
mod_sub
Computes (a - b) mod modulus and returns the normalized residue.
nand
Returns the NAND of two boolean values.
next_prime
Returns the smallest prime strictly greater than n.
nor
Returns the NOR of two boolean values.
normalize_degrees
Normalizes a degrees value into the interval [0, 360).
normalize_radians
Normalizes a radians value into the interval [0, 2π).
orientation_2d
Returns the winding order of three 2D points.
orientation_2d_with_tolerance
Returns the winding order of three 2D points using an explicit area tolerance.
permutations
Returns the number of ordered selections of size k from n items.
polygon_edge_count
Returns E = 1 + 2m2 + 3m3 + 4m4 + ... using checked u128 arithmetic.
polygon_vertex_count
Returns V = 2 + m2 + 2m3 + 3m4 + ... using checked u128 arithmetic.
population_std_dev
Returns the population standard deviation of values.
population_variance
Returns the population variance of values.
previous_prime
Returns the largest prime strictly less than n.
prime_factors
Returns the prime factors of n, including repeated multiplicities.
primes_up_to
Returns every prime less than or equal to limit.
quadratic_roots
Returns the real roots of ax^2 + bx + c = 0.
radians_to_degrees
Converts a radians value into degrees.
sample_std_dev
Returns the sample standard deviation of values using Bessel’s correction.
sample_variance
Returns the sample variance of values using Bessel’s correction.
saturating_add
Returns the saturating sum of left and right.
saturating_mul
Returns the saturating product of left and right.
saturating_sub
Returns the saturating difference of left and right.
second_central_difference
Approximates the second derivative with a central difference.
set_difference
Returns the unique members of left \ right in the order they first appear in left.
set_intersection
Returns the unique members of left ∩ right in the order they first appear in left.
set_symmetric_difference
Returns the unique members that appear in exactly one of left or right.
set_union
Returns the unique members of left ∪ right in first-seen order.
sieve
Returns a boolean sieve up to and including limit.
simpson_integral
Approximates a definite integral with Simpson’s rule.
sin_deg
Evaluates sin for a degrees input.
solve_2x2
Solves matrix * x = rhs for x.
solve_linear
Solves the linear equation ax + b = 0.
solve_polynomial_degree_1_or_2
Solves a polynomial when its degree is 0, 1, or 2.
solve_quadratic
Solves the quadratic equation ax^2 + bx + c = 0 over the real numbers.
symmetric_limit
Approximates a two-sided limit with one symmetric sample scale.
tan_deg
Evaluates tan for a degrees input.
trapezoidal_integral
Approximates a definite integral with the trapezoidal rule.
triangle_area
Returns the 2D triangle area.
triangle_twice_area
Returns twice the unsigned 2D triangle area.
triangle_twice_signed_area
Returns twice the signed 2D triangle area using the shoelace formula.
try_orientation_2d
Returns the winding order of three 2D points with finite coordinates.
try_orientation_2d_with_tolerance
Returns the winding order of three finite 2D points using an explicit area tolerance.
unique_prime_factors
Returns the unique prime factors of n in ascending order.
wrapping_add
Returns the wrapping sum of left and right.
wrapping_mul
Returns the wrapping product of left and right.
wrapping_sub
Returns the wrapping difference of left and right.