Skip to main content

Crate use_algebra

Crate use_algebra 

Source
Expand description

§use-algebra

Small finite algebra law helpers for `RustUse`.
Explicit group-like and ring-like law checks over caller-supplied finite sample sets.

Rust 1.95.0+ Edition 2024 Algebra laws License MIT or Apache-2.0

Surface · When to use it · Installation · Examples · Scope

use-algebra provides a deliberately small finite-law surface. The first concrete slice focuses on explicit checks over a caller-supplied sample set and caller-supplied operations: closure, associativity, commutativity, identity discovery, inverse checks, and combined predicates for monoids, groups, abelian groups, distributive laws, and rings.

Binary-law predicates
is_closed_under, is_associative, and is_commutative keep algebraic-law checks explicit over finite sample sets.
Identity and inverse helpers
identity_element and has_inverses cover the common building blocks for monoids and groups.
Structure checks
is_monoid, is_group, is_abelian_group, is_distributive_over, and is_ring provide compact finite checks for common algebraic structures.

§What this crate provides

AreaRoot exportsBest fit
Basic law checksis_closed_under, is_associative, is_commutativeFinite structure checks over explicit sample sets and operations
Identity and inverse checksidentity_element, has_inversesBuilding monoid and group checks without a trait hierarchy
Combined structure predicatesis_monoid, is_group, is_abelian_group, is_distributive_over, is_ringSmall algebra experiments, education, and validation helpers
If you need to…Start here
Check whether a binary operation stays inside a sample setis_closed_under(...)
Discover a two-sided identity element inside a sample setidentity_element(...)
Check whether every value has a two-sided inversehas_inverses(...)
Validate a finite abelian group or ring modelis_abelian_group(...) or is_ring(...)

§When to use it directly

Choose use-algebra directly when finite algebra-law checks are the only surface you need and you want to keep that concern narrower than the umbrella facade.

ScenarioUse use-algebra directly?Why
You want explicit law checks over a finite sample setYesThe crate stays small and does not force a trait hierarchy
You are teaching or validating modular arithmetic structuresYesThe helpers work directly with caller-supplied operations
You need symbolic algebra or generic numeric towersNoThose are intentionally out of scope for this first slice
You need matrix-specific or geometry-specific abstractionsUsually noThose belong in adjacent focused crates

§Installation

[dependencies]
use-algebra = "0.0.1"

§Quick examples

§Check a finite abelian group

use use_algebra::{identity_element, is_abelian_group};

let residues = [0_u8, 1, 2];
let add_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));

§Check a finite ring

use use_algebra::{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!(is_distributive_over(&residues, mul_mod_3, add_mod_3));
assert!(is_ring(&residues, add_mod_3, mul_mod_3));

[!IMPORTANT] These helpers check the laws over the exact finite sample set and exact operations you provide. They do not prove a law for values outside that set.

§Scope

  • The current surface is intentionally small and concrete.
  • The first slice focuses on finite sample-set checks over caller-supplied binary operations.
  • These helpers are law predicates, not symbolic algebra or theorem-proving tools.
  • Linear algebra and calculus-specific abstractions belong in adjacent focused crates.

§Status

use-algebra is a concrete pre-1.0 crate in the RustUse docs surface. The API remains intentionally small while adjacent numeric and linear crates continue to grow around it. Algebraic-structure utilities for RustUse.

Re-exports§

pub use laws::has_inverses;
pub use laws::identity_element;
pub use laws::is_abelian_group;
pub use laws::is_associative;
pub use laws::is_closed_under;
pub use laws::is_commutative;
pub use laws::is_distributive_over;
pub use laws::is_group;
pub use laws::is_monoid;
pub use laws::is_ring;

Modules§

laws
Finite-sample algebraic law helpers.
prelude
Common ergonomic imports for use-algebra.