1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
//! Where ℚ sits in the algebra tower.
//!
//! `Rational<T>` is a **field**, and these four markers plus `Invertible` are what carry it
//! there: the tower derives `Ring`, `CommutativeRing`, and `Field` automatically from them
//! together with the structural `Add`/`Mul`/`Div`/`Zero`/`One` impls.
//!
//! Each is a promise the compiler cannot check, so each is stated deliberately:
//!
//! | Law | Why it holds for `a/b` |
//! | :--- | :--- |
//! | `Commutative` | `(a/b)·(c/d) = ac/bd = ca/db = (c/d)·(a/b)`, inherited from `T` |
//! | `Associative` | likewise, from associativity of `T` |
//! | `Distributive` | `(a/b)·((c/d)+(e/f))` expands to the same fraction either way |
//! | `AbelianGroup` | additive inverse `-a/b`, identity `0/1` |
//! | `Annihilating` | `0/1 · a/b = 0/b`, which reduces to `0/1` |
//! | `Invertible` | every non-zero `a/b` has `b/a`, which is the field axiom |
//!
//! `Invertible` is the one that distinguishes ℚ from ℤ. The integers reach `CommutativeRing` and
//! stop there, because integer `/` truncates rather than inverts. Constructing ℚ as the field of
//! fractions is precisely the act of supplying the missing inverses, so ℚ earns the marker that
//! ℤ cannot have.
//!
//! Deliberately absent: [`Real`](deep_causality_algebra::Real). ℚ is not closed under the
//! analytic operations — there is no rational `sqrt(2)`, `exp(1)`, or `ln(2)` — so claiming the
//! analytic axis would be false. ℚ is a field without being analytic, the mirror of `Dual<T>`,
//! which is analytic without being a field.
use ;
use crate::;
use IntegralDomain;
use ;
use ;
// Addition carries the integer parts separately and adds the fractions over their least
// common denominator. Both additive laws follow from the ring laws of `T`.
// Reached through the `AbelianGroup` blanket now that the additive markers are present.
// `0/1 · a/b = 0/b`, which reduces to `0/1`. In a ring this is a theorem, but `Semiring` takes it
// as an axiom — the derivation needs an additive inverse — so it is stated rather than assumed.
// ℚ is a field, so it has no zero divisors: `a·b = 0` with `a ≠ 0` gives `b = a⁻¹·a·b = 0`.
// ℚ has characteristic zero: `n · 1` is the fraction `n/1`, which is zero only for `n = 0`.
// Stated per type rather than blanket-implemented, because it is a promise the compiler cannot
// check.
//
// This is what admits `Rational<T>` to the operations that divide by an integer, and what keeps 𝔽₂
// out of them. See `deep_causality_algebra::DivisibleByIntegers`.