deep_causality_algebra/algebra/ring.rs
1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5
6use crate::{AbelianGroup, Annihilating, Distributive, MulMonoid};
7
8/// Represents a **Ring** in abstract algebra.
9///
10/// A ring is an algebraic structure with two binary operations, addition and
11/// multiplication, that is more general than a `Field` because it does not
12/// require multiplicative inverses for all non-zero elements.
13///
14/// # Mathematical Definition
15///
16/// A set `R` is a ring if it satisfies the following laws:
17///
18/// 1. **Under Addition:** `R` forms an `AbelianGroup`.
19/// - Addition is associative: `(a + b) + c = a + (b + c)`
20/// - Addition is commutative: `a + b = b + a`
21/// - There is an additive identity `0`: `a + 0 = a`
22/// - Every element `a` has an additive inverse `-a`: `a + (-a) = 0`
23///
24/// 2. **Under Multiplication:** `R` forms a `MulMonoid`.
25/// - Multiplication is associative: `(a * b) * c = a * (b * c)`
26/// - There is a multiplicative identity `1`: `a * 1 = a`
27///
28/// 3. **Distributivity:** Multiplication distributes over addition.
29/// - `a * (b + c) = (a * b) + (a * c)` (Left distributivity)
30/// - `(a + b) * c = (a * c) + (b * c)` (Right distributivity)
31///
32/// [`Annihilating`](crate::Annihilating) is required even though `0 * a = 0` is *derivable* in a
33/// ring, because it is not derivable in a [`Semiring`](crate::Semiring) and every ring must remain
34/// a semiring. Carrying the marker at both rungs is what keeps that relation true.
35///
36/// This trait combines `AbelianGroup` and `MulMonoid` to enforce these properties.
37/// The distributivity law is implicitly assumed to be upheld by the `Add` and
38/// `Mul` implementations.
39pub trait Ring: AbelianGroup + MulMonoid + Distributive + Annihilating {}
40// This is a marker trait that combines other traits.
41// It guarantees that a type supports `+`, `-`, `*`, `0`, and `1`
42// with the expected algebraic properties of a ring.
43
44// Blanket Implementation
45impl<T> Ring for T where T: AbelianGroup + MulMonoid + Distributive + Annihilating {}