Skip to main content

Crate yui_core

Crate yui_core 

Source
Expand description

§yui-core

crates.io docs.rs License: MIT

The foundational crate of the yui workspace: algebraic trait hierarchy, concrete numeric types, polynomials, linear combinations, and supporting algorithms / extension traits.

§Layout

src/
├── abst/    — algebraic trait hierarchy: Ring, EucRing, Field, RMod, ...
├── conc/    — concrete instantiations: Ratio, FF, Sign, Poly, Lc, BitSeq
├── ext/     — extension traits: IteratorExt, RangeExt, IntoDigits, ...
├── algo/    — TopSort, UnionFind, KeyedUnionFind, rep_comb
└── util/    — formatting, data-dir resolution, thread-safe counter

§Algebraic hierarchy

The traits in abst/ form the algebraic supertrait stack that everything else is generic over:

              MathType                  (basic shape + math_symbol())
                 │
           ┌─────┴─────┐
           ↓           ↓
         AddMon       Mon               (zero, +)        (one, ×)
           ↓           │
         AddGrp        │                (negation)
           └─────┬─────┘
                 ↓
               Ring     ──────►  RMod   (module over a ring R)
                 ↓
              EucRing                   (gcd, div_rem)
                 ↓
               Field                    (every nonzero invertible)

Arrows denote supertrait inheritance: Ring: AddGrp + Mon, EucRing: Ring, etc. RMod takes its scalar ring R: Ring as an associated type, not a supertrait.

A typical where-clause:

fn foo<R>(x: &R) -> R
where R: Ring, for<'x> &'x R: RingOps<R>
{ ... }

The for<'x> HRTB on the reference impl is required throughout; the auto_impl_ops crate derives the four Add/Mul reference variants from a single +=/*=.

§Concrete types

conc/num/:

  • IntType impls for i32 / i64 / i128 / BigInt.
  • Ratio<T> — fractions over a Euclidean ring; Ratio<i64> and Ratio<BigInt> are the rationals.
  • FF<p> — finite field 𝔽ₚ for prime p. For 𝔽₂, prefer the specialized FF2 (uses XOR/AND directly on a bool).
  • QuadInt<I, D> — quadratic integers in ℤ[ω] for ω = (1+√D)/2 or √D; aliases GaussInt, EisenInt.
  • Sign — the multiplicative group {±1}, with the GetSign trait.

conc/poly/:

  • Poly<X, R> — univariate polynomial.
  • LPoly<X, R> — univariate Laurent variant.
  • Poly2, Poly3 (fixed arity), PolyN<X, R> (multivariate), plus their Laurent variants.

conc/lc/:

  • Lc<X, R> — formal linear combination Σ rᵢxᵢ with keys X: LcKey and coefficients in R: Ring. Elements of the free R-module over the key set.

conc/misc/:

  • bitseq::BitSeq<I> — packed sequence of bits over a word I, length up to I::BITS. Aliases BitSeq8, BitSeq16, BitSeq32, BitSeq64, BitSeq128 pin the width.

§Quick example

use yui_core::num::Ratio;

let a = Ratio::new(1_i64, 2);
let b = Ratio::new(1_i64, 3);
assert_eq!((&a + &b).to_string(), "5/6");
assert_eq!((&a * &b).to_string(), "1/6");

§Feature flags

  • serdeSerialize/Deserialize for the concrete types.

§License

This library is licensed under the MIT License.


This README was generated by Claude.

Modules§

abst
The algebraic trait hierarchy: MathType and IndexType at the base, then AddMon → AddGrp, Mon → Ring → EucRing → Field, and RMod for modules.
algo
General-purpose algorithms: topological sort, disjoint sets, and a stars-and-bars combinatorics helper.
bitmap
Compact bitmap over a small element type. BitMap<E, S> is a single word S (the storage) whose bit e.into() is set iff e is present. S = u128 covers element indices 0..128, and U256 doubles that; extend by impl-ing BitStorage for a wider type.
bitseq
A single Bit, and a packed sequence of bits BitSeq over a generic word I.
ext
Extension traits adding small conveniences to std and num types.
lc
Lc<X, R>: a formal linear combination of keys X with coefficients in a ring R — the element type of every chain module in this workspace.
num
Concrete number types: integers, rationals, finite fields, quadratic integers, and the multiplicative sign group.
poly
Polynomials and their monomials, in one, two, three or indexed-many variables, ordinary or Laurent.
u256
U256: a 256-bit word, used as a wide BitStorage for BitMap.
util
Non-mathematical support code: formatting, parse errors, LaTeX rendering, data-directory resolution, logging and a thread-safe counter.