Dedekind 0.0.0
A structuralist C++23 Module Library
Loading...
Searching...
No Matches
total.cppm File Reference

The Laws of Total Algebra (The Algebraic Hierarchy). More...

#include <algorithm>
#include <concepts>
#include <cstddef>
#include <functional>
#include <limits>
#include <ranges>
#include <type_traits>
#include <utility>
import dedekind.category:chain;
Include dependency graph for total.cppm:

Classes

struct  dedekind::category::is_periodic< T, Op >
struct  dedekind::category::is_saturating< T, Op >
struct  dedekind::category::is_exact_total< T, Op >
 Path D to totality: the operation is total because the carrier is exact — arithmetic with no rounding, Op(a,b) defined and lossless up to the carrier's out-of-memory tripwire. The archetypes are the exact number fields (Rational = ℚ, QuadraticReal = ℚ(√D)) under + and *. Distinct from the three machine-finite paths, which are total by staying in a bounded range (wrap / stabilise / saturate); an exact carrier is total because its arithmetic is closed and exact. More...
struct  dedekind::category::is_periodic< T, std::plus< T > >
struct  dedekind::category::is_periodic< T, std::minus< T > >
struct  dedekind::category::is_periodic< T, std::multiplies< T > >
struct  dedekind::category::is_periodic< T, std::bit_xor< T > >
struct  dedekind::category::construction_base< D >
 A carrier's construction: D is built from a base algebra and computes with the base's operations. ::type is the base; ::times_mixes_plus says whether D's × multiplies out (a quotient of a polynomial ring, the Cauchy product: the base's × and +) or stays componentwise (a product, a subalgebra: the base's × alone). Declared once per construction leg in dedekind.algebra (H / P / S / F), never per carrier; a carrier declaring two legs is ambiguous here, honestly. More...
struct  dedekind::category::is_total_by_construction< T, Op >
 Path E to totality: by construction. Defined below is_total, which it recurses into on the base. More...
struct  dedekind::category::is_total< T, Op >
 The certificate. Op is taken up to cv/ref (a const Inf keys the same registration as Inf). More...
struct  dedekind::category::is_total< T, detail_involution::Reversed< Op > >
 The opposite operation is total where the operation is, read off the value form, which sees registrations on the struct and on the value. More...
struct  dedekind::category::is_total< T, Op >
 A qualified operation is total where the operation is: the paths read the unqualified operation, and so does every specialisation. More...
struct  dedekind::category::is_total_by_construction< D, std::plus< D > >
struct  dedekind::category::is_total_by_construction< D, std::multiplies< D > >
struct  dedekind::category::unit_registry< ConstantMorphism< A, B >, Op >
 unit_registry specialisation for ConstantMorphism<A, B>. Registers the constant-at-identity-element-of-B as the identity element of ConstantMorphism<A, B> under operation Op. More...
struct  dedekind::category::is_cyclic_group< T, Op >
 Opt-in trait: is (T, Op) a \emph{cyclic} abelian group? More...
struct  dedekind::category::cyclic_order< T, Op >
 The order \(n\) of a cyclic group (its cardinality). More...
struct  dedekind::category::is_cyclic_group< T, std::plus< T > >
struct  dedekind::category::cyclic_order< T, std::plus< T > >

Namespaces

namespace  dedekind::category

Concepts

concept  dedekind::category::IsPeriodic
 Taxonomic Decorator: Certifies that an operation is circular (wraps). This is the "Safety Certificate" for machine totality.
concept  dedekind::category::IsSaturating
 Taxonomic Decorator: certifies that an operation reaches out-of-range values via a saturating escalation (e.g.\ \(\pm \aleph_0\)) rather than wrapping or being undefined.
concept  dedekind::category::IsClosedUnder
 (S, Op) is closed under a binary operation: Op{}(s_1, s_2) returns a value of type S for any S-typed operands. The textbook closure axiom expressed structurally — no opt-in trait needed because closure is deducible from the operator's signature.
concept  dedekind::category::IsClosedUnderUnary
 Unary closure variant: Op{}(s) returns S for any S-typed operand. Cardinality has no IsClosedUnderUnary for std::negate<> (negation of a positive natural would need to land outside ℕ); that's the structural witness that -Cardinality is closure-forcing rather than closed.
concept  dedekind::category::IsClosedUnderEither
 (T, Op) is closed under Op, where Op may be either binary or unary. Distinct from IsClosedUnder (binary) so call sites that need a specific arity stay typo-proof.
concept  dedekind::category::IsConstructed
 D declares a construction: a base and the shape of its ×.
concept  dedekind::category::CommutativeRingLaws
 The base's laws that a multiplied-out × rests on.
concept  dedekind::category::IsTotal
 The Master Safety Certificate for Level 0: is_total, as a concept.
concept  dedekind::category::IsTotalArrow
 A Morphism whose domain species admits no undefined (hazard) values.
concept  dedekind::category::IsPointed
 A type T has a chosen identity element under operation Op.
concept  dedekind::category::IsMagma
 T × T → T (The Base Total Species).
concept  dedekind::category::IsUnitalMagma
 A Magma with a global Identity (0 or 1).
concept  dedekind::category::IsInvertible
 A pointed (T, Op) where every element has an Op-inverse.
concept  dedekind::category::IsLoop
 A UnitalMagma with Inverses (-x).
concept  dedekind::category::IsSemigroup
 An Associative Magma.
concept  dedekind::category::IsCommutativeSemigroup
 An Associative Magma where the operation is also commutative.
concept  dedekind::category::IsMonoid
 A Semigroup with a two-sided Identity element.
concept  dedekind::category::IsMonoidHomomorphism
 A map between two monoids, (T, Op) and its image under Op2, that carries the operation, declared on every pair, and the unit to the unit, computed (:morphism's PreservesUnit).
concept  dedekind::category::IsCommutativeMonoid
 A Monoid where the operation is commutative.
concept  dedekind::category::IsGroup
 A Monoid with two-sided Inverses (The Perfect Symmetry).
concept  dedekind::category::IsAbelianGroup
 A Commutative Group.
concept  dedekind::category::IsCyclicGroup
 A cyclic abelian group: the honest concept name for \(\mathbb{Z}/n\mathbb{Z}\) carriers and their machine-backed cousins.
concept  dedekind::category::IsRig
 A Semiring without Negatives (Addition is a Monoid).
concept  dedekind::category::IsRng
 A Ring without Identity (Multiplication is a Semigroup).
concept  dedekind::category::IsSemiring
 Alias for IsRig: a general multi-operation species.
concept  dedekind::category::IsRing
 The Perfect Species (Rig ∩ Rng).
concept  dedekind::category::IsCommutativeRing
 A Ring whose multiplication is commutative.
concept  dedekind::category::IsField
 The axiomatic field witness — a commutative ring whose multiplicative structure is an abelian group (zero excluded, by convention on is_invertible_v).
concept  dedekind::category::IsJoinSemilattice
 A Semilattice used as the "join" (least upper bound / ∨) half of a Lattice. In bool this is logical_or; in int it is max.
concept  dedekind::category::IsMeetSemilattice
 A Semilattice used as the "meet" (greatest lower bound / ∧) half of a Lattice. In bool this is logical_and; in int it is min.
concept  dedekind::category::IsLattice
 compatibility alias for order-lattice refinement.
concept  dedekind::category::IsDistributiveLattice
 compatibility alias for distributive order lattices.
concept  dedekind::category::IsBoundedLattice
 A IsLattice whose join and meet each carry an identity: the bottom \(\bot\) (unit<T>(Join{})) and top \(\top\) (unit<T>(Meet{})).
concept  dedekind::category::IsBooleanAlgebra
 The top of the Boolean-algebra variety Alg(∨,∧,¬,⊥,⊤): a complemented distributive bounded lattice — the ∨/∧/¬ analogue of IsField topping the (signature-expanded) ring variety.
concept  dedekind::category::HasClosureForcingShape
 Structural shape: Op{} sends (A, A) → B (binary) or A → B (unary) with A ≠ B. Pure deducible clause of IsClosureForcing. The universal-property side — that B is the smallest carrier closing Op over A — is carried by the is_closure_forcing_v opt-in trait below.
concept  dedekind::category::IsClosureForcing
 Composite: structural shape + opt-in canonicality. The full witness that Op is the closure-forcing operator A → B (or A × A → B), with B the canonical recipient.
concept  dedekind::category::IsCopies
 A range of n copies of one value, Bird's replicate n x, whose fold under a monoid is the power \(x^n\); n and the value known without walking it: copies_count(r) and copies_value(r), which each model supplies, declared above so that ordinary lookup finds them for models outside this namespace, the standard's among them.

Typedefs

using dedekind::category::XOR = std::bit_xor<unsigned int>
using dedekind::category::AND = std::bit_and<unsigned int>

Functions

template<typename A, typename B, typename Op = std::plus<B>>
requires IsPointed<B, Op>
constexpr auto dedekind::category::zero ()
 zero<A, B, Op>(): the constant morphism A → B that maps everything to the Op-identity element of B. Defaults to std::plus (additive identity, i.e. zero); with std::multiplies it is the constant at one.
template<std::ranges::input_range R, typename T = std::ranges::range_value_t<R>, typename Op = std::plus<T>>
requires IsMonoid<T, Op>
constexpr T dedekind::category::concat (R r, Op op={})
 The free monoid's fold, concat, the canonical fold of a monoid: a range folded under the operation from its unit (the Jlt paper's Listings 2 to 4). Its specialisation, licensed by associativity, folds n copies of one value, any IsCopies range, by the binary method, one squaring per bit of n (Knuth, TAOCP 2 §4.6.3). Resolution picks it over the plain fold, its parameter being the more specific.
template<IsCountWord N, IsConstantArrow F>
constexpr N dedekind::category::copies_count (const unfold_view< N, Mapped< N, StepCoalgebra< N, Prior< N > >, F > > &r)
 The counting chain of n under a constant arrow, n >> chain<N>() >> constant(x), is n copies of x, counted in the chain's own word.
template<IsCountWord N, IsConstantArrow F>
constexpr Cod< F > dedekind::category::copies_value (const unfold_view< N, Mapped< N, StepCoalgebra< N, Prior< N > >, F > > &r)
template<std::copy_constructible T, std::integral B>
requires (!std::same_as<B, bool>)
constexpr std::make_unsigned_t< B > dedekind::category::copies_count (const std::ranges::repeat_view< T, B > &r)
 The standard's views::repeat(x, n) is n copies of x; its value is read only where n is not zero.
template<std::copy_constructible T, std::integral B>
requires (!std::same_as<B, bool>)
constexpr T dedekind::category::copies_value (const std::ranges::repeat_view< T, B > &r)
template<typename T, typename Op, IsCountWord N>
requires IsMonoid<T, Op>
constexpr T dedekind::category::detail_concat::power (const T &x, N n, Op op)
 \(x^n\) as the square of \(x^{\lfloor n/2 \rfloor}\), one x more where n is odd: the concat of the first half of the copies, used twice, since the halves are equal. A descent on n by halving to its base case, one call per bit of n, licensed by associativity.
template<std::ranges::input_range R, typename T = std::ranges::range_value_t<R>, typename Op = std::plus<T>>
requires IsMonoid<T, Op> && IsCopies<R>
constexpr T dedekind::category::concat (R r, Op op={})
 concat on n copies of one value: its n-th power, by squaring its first half, licensed by associativity. The same signature as the plain fold and a stronger constraint, so resolution prefers it wherever IsCopies holds. The value is read only where there is a copy, as a model promises it.

Variables

template<typename T, typename Op>
constexpr bool dedekind::category::is_periodic_v = is_periodic<T, Op>::value
template<typename T, typename Op>
constexpr bool dedekind::category::is_saturating_v = is_saturating<T, Op>::value
template<typename T, typename Op>
constexpr bool dedekind::category::is_exact_total_v = is_exact_total<T, Op>::value
template<typename T, typename Op>
constexpr bool dedekind::category::is_total_by_construction_v
 Value form of is_total_by_construction.
template<typename T, typename Op>
constexpr bool dedekind::category::is_total_v = is_total<T, Op>::value
 Value form of is_total.
template<IsConstructed D>
constexpr bool dedekind::category::is_associative_v< D, std::plus< D > >
template<IsConstructed D>
constexpr bool dedekind::category::is_commutative_v< D, std::plus< D > >
template<IsConstructed D>
constexpr bool dedekind::category::is_associative_v< D, std::multiplies< D > >
template<IsConstructed D>
constexpr bool dedekind::category::is_commutative_v< D, std::multiplies< D > >
template<IsConstructed D>
constexpr bool dedekind::category::is_distributive_v< D, std::multiplies< D >, std::plus< D > >
template<typename A, typename B, typename Op>
constexpr bool dedekind::category::is_monotone_v< ConstantMorphism< A, B >, Op > = true
template<typename A, typename B, typename Op>
constexpr bool dedekind::category::is_antimonotone_v< ConstantMorphism< A, B >, Op > = true
template<typename T, typename Op>
constexpr bool dedekind::category::is_cyclic_group_v = is_cyclic_group<T, Op>::value
 Shorthand access to the is_cyclic_group trait.
template<typename T, typename Op>
constexpr std::size_t dedekind::category::cyclic_order_v = cyclic_order<T, Op>::value
template<typename T, typename Join, typename Meet, typename Not>
constexpr bool dedekind::category::is_complemented_v = false
 Opt-in complement law: T carries a complement Not w.r.t. the bounded lattice (Join, Meet), i.e. \(a \vee \neg a = \top\) and \(a \wedge \neg a = \bot\) for every a.
template<std::unsigned_integral T>
constexpr bool dedekind::category::is_complemented_v< T, std::bit_or<>, std::bit_and<>, std::bit_not<> > = true
 The bit lattice of an unsigned word is complemented by ~: a | ~a is every bit, a & ~a none. Not bool, whose ~ promotes (~true is -2) and is no involution (std::logical_not is bool's complement).
template<>
constexpr bool dedekind::category::is_complemented_v< bool, std::logical_or< bool >, std::logical_and< bool >, std::logical_not< bool > > = true
template<typename Op, typename A, typename B>
constexpr bool dedekind::category::is_closure_forcing_v = false
 Opt-in trait carrying the universal-property clause of IsClosureForcing — the engineer's honesty obligation that B is the canonical (smallest) carrier closing Op over A inputs. C++ concepts cannot quantify universally, so this part of the witness is asserted, not deduced. Pattern mirrors is_associative_v / is_saturating.
constexpr std::size_t dedekind::category::detail_concat_witness::ten = 10
constexpr std::size_t dedekind::category::detail_concat_witness::seven = 7

Detailed Description

The Laws of Total Algebra (The Algebraic Hierarchy).

@partition :total

total__The_Categorical_Foundation

« Język jest aparatem wyznaczającym obraz świata. Struktura kategorii jest fundamentem wszelkiego poznania naukowego. » (Language is an apparatus that determines the image of the world. The structure of categories is the foundation of all scientific knowledge.) — Kazimierz Ajdukiewicz, 'Język i Poznanie' (Language and Cognition)

This partition defines the "Laws of Harmony" for a single species T under a binary operation Op. Following the Polish School of Logic, we treat these structures as species that "mature" as they gain axioms—moving from the primal Magma to the perfect symmetry of an Abelian Group.

total__Std_Namespace_Mappings

This partition asserts bidirectional mappings between algebraic hierarchy concepts and standard C++ types:

Std type Highest algebraic structure
bool Rig (OR/AND), Boolean Algebra (OR/AND/NOT)
unsigned int Abelian Group (+), Ring (+,*), Ring (XOR,AND)
int Distributive Lattice (max,min)
double not a lattice: NaN breaks totality (see #934)
Note
"I obtained scientific guidance and stimulation mainly through personal mathematical contacts in Erlangen and in Gottingen. Above all I am indebted to E. Fischer, from whom I received the decisive impulse to study abstract algebra from an arithmetical viewpoint." – Emmy Noether, Habilitation curriculum vitae (1919)
See also
#275 nLab algebra/category hierarchy (work in progress): the quasigroup beside IsLoop.

Function Documentation

◆ power()

template<typename T, typename Op, IsCountWord N>
requires IsMonoid<T, Op>
T dedekind::category::detail_concat::power ( const T & x,
N n,
Op op )
constexpr

\(x^n\) as the square of \(x^{\lfloor n/2 \rfloor}\), one x more where n is odd: the concat of the first half of the copies, used twice, since the halves are equal. A descent on n by halving to its base case, one call per bit of n, licensed by associativity.

Parameters
xthe value.
nthe copies.
opthe operation.
Returns
the concat of the n copies.