|
Dedekind 0.0.0
A structuralist C++23 Module Library
|
Dual numbers ๐ป = a + bฮต with ฮตยฒ = 0 โ forward-mode AD carrier. More...
#include <concepts>#include <functional>#include <limits>#include <type_traits>import dedekind.sets;import dedekind.numbers;import dedekind.geometry;import dedekind.category;import dedekind.algebra;
Namespaces | |
| namespace | dedekind::category |
Concepts | |
| concept | dedekind::analysis::dual_admits |
Typedefs | |
| using | dedekind::analysis::๐ป_โ = Dual<dedekind::numbers::Rational<>> |
| using | dedekind::analysis::โ_ = dedekind::numbers::Rational<> |
Functions | |
| template<typename F> | |
| constexpr F | dedekind::analysis::component (const Dual< F > &d, dedekind::category::At< 1 >) |
Canonical product projections for Dual (the ADL component hook of dedekind::category::ฯ_1 / ฯ_2): ๐ป's storage is val / der, not the pair-like .first / .second the default projection reads, so we provide the overload here. This is what makes Dual satisfy IsProduct uniformly with Complex (P-leg), while value() / derivative() stay as the domain-specific aliases that agree with ฯ_1 / ฯ_2. | |
| template<typename F> | |
| constexpr F | dedekind::analysis::component (const Dual< F > &d, dedekind::category::At< 2 >) |
Variables | |
| constexpr ๐ป_โ | dedekind::analysis::eps {โ_{0}, โ_{1}} |
| constexpr ๐ป_โ | dedekind::analysis::x_seed {โ_{3}, โ_{1}} |
| constexpr Dual< int > | dedekind::analysis::eps_int {0, 1} |
| constexpr auto | dedekind::analysis::๐ป |
| The canonical dual-number universe ๐ป = ๐ธ<Dual<QuadraticReal<2>>, Boole, โถ_1> โ the coat-hanger ๐ป = Dual(โ) over the genuine โ = โ(โ2) (mirroring โ and โ). | |
| constexpr auto | dedekind::analysis::embed_โ_๐ป |
The Birkhoff S leg \(\mathbb{R}\hookrightarrow\mathbb{D}\) over the coat-hanger: QuadraticReal<2> โ Dual<QuadraticReal<2>>, \(r\mapsto r+0\varepsilon\) (primal r, tangent 0). | |
| template<typename F> | |
| constexpr bool | dedekind::category::is_invertible_v< dedekind::analysis::Dual< F >, std::plus< dedekind::analysis::Dual< F > > > |
| template<> | |
| constexpr bool | dedekind::category::is_monic_arrow_v< std::decay_t< decltype(dedekind::analysis::embed_โ_๐ป)> > |
Dual numbers ๐ป = a + bฮต with ฮตยฒ = 0 โ forward-mode AD carrier.
@partition :dual
This file relocated from dedekind.numbers:dual to dedekind.analysis:dual at PR #513: the construction is algebraically a quotient ring, but its structural meaning is differential — dual numbers are forward-mode automatic differentiation, and the partition's natural neighbours are :ftc (numerical derivative bridge), :forms (differential one-forms), and :hamilton (Hamiltonian flow on Dual-carrier symplectic state). The :analysis layer is downstream of :numbers in the build graph, so all numeric-carrier consumers (Rational<Z>, Complex<R>, IEEE<F>) remain reachable.
Reifies Dual Numbers a + bฮต where ฮตยฒ = 0. This provides the algebraic foundation for Forward-Mode Automatic Differentiation (AD).
The construction Dual(R) = R[ฮต]/(ฮตยฒ) is well-defined over any commutative ring R. The Dual<F> constraint is std::semiregular<F> and not std::floating_point<F> (IEEE floats are not a ring): integer carriers (Dual<int>, Dual<SignedExtensionalCardinal<>>) and the modular ring (Dual<unsigned int>) instantiate cleanly and close the ring-operator surface.
Note on division semantics: Dual<F>::operator/ and inverse() delegate to F's division (F{1}/val plus -der/(val*val)), so the operator surface syntactically compiles for any F that supplies a / operator — including F=int, where the integer-division semantics give truncating, non-field results. The syntactic predicate algebra::HasFieldOperators<Dual<F>> is therefore NOT a guarantee that Dual<F> is field-shaped at the axiomatic level; it merely reports that the operator surface is closed. The field-axiomatic distinction is a job for the strict category::IsField concept (which is intentionally not specialised on Dual<int>); this file pins HasFieldOperators<Dual <โ>> as a positive witness and the ring-shape concepts (HasRingOperators, IsAlgebra) as the load-bearing claims for the integer-carrier extensions.
The algebraic-geometric reading of dual numbers over an arbitrary base ring — Spec(R[ฮต]/(ฮตยฒ)) as the scheme of tangent vectors at a point — is the textbook anchor for this generality (Hartshorne, Algebraic Geometry, Exercise II.2.8; Eisenbud, Commutative Algebra with a View Toward Algebraic Geometry, ยง16.5).
Forward-mode AD on Dual<F> is the symbolic / exact route from a function to its derivative: f(x + ฮต) yields the primal in the value component and the derivative in the tangent component, mechanically, without any numerical approximation. The numerical counterpart is dedekind::analysis::ftc::derivative_at (central difference) in dedekind.analysis:ftc, which uses a small step h on a std::floating_point carrier. The two routes agree on smooth functions. Their structural divergence: :ftc currently gates on IsNumericalBridgeScalar = HasFieldOperators<R> && std::floating_point<resolved_value_t<R>>, so the analytic side is floating-point-only by design; Dual<F> generalises to discrete carriers without that restriction (the witnesses below pin one rung per supported carrier). An open architectural question is whether a downstream partition (e.g. dedekind.analysis:dual_ad) should host the AD-meaning of dual numbers and cross-link both :dual and :ftc as parallel implementations of "compute the
derivative of f at x" — tracked separately, not in scope for the carrier-witness slice this file currently lands.
DualVector<F,N> with a directional seed, and Jacobians computed from Dual. | using dedekind::analysis::๐ป_โ = Dual<dedekind::numbers::Rational<>> |
|
inlineconstexprexport |
The canonical dual-number universe ๐ป = ๐ธ<Dual<QuadraticReal<2>>, Boole, โถ_1> โ the coat-hanger ๐ป = Dual(โ) over the genuine โ = โ(โ2) (mirroring โ and โ).
Per #559's chosen direction (option A): the named species symbols denote universe values (constexpr instances of ๐ธ over the carrier), not classifier-alias types. All seven species symbols (๐น, โ, โค, โ, โ, โ, ๐ป) carry the canonical element <๐ป> scout spelling.
Post-HSP retarget: the carrier of ๐ป is Dual<QuadraticReal<2>> โ the 2nd-order quotient โ[ฮต]/(ฮตยฒ) over the coat-hanger โ.
Cardinality is set explicitly to โถ_1 (continuum) โ ๐ป is in bijection with โ ร โ via the (a, b) coefficient pair (the same shape that gives โ its โถ_1) โ overriding ๐ธ's โต_0 default. It is the cardinality of the ๐ป modelled, not a logic: equality on โ(โ2)[ฮต] is decidable, so ๐ป answers in Boole.
Textbook construction: ๐ป = โ[ฮต]/(ฮตยฒ), a polynomial quotient: the H leg of the construction taxonomy, registered as quotient_algebra_base<Dual<F>>::type = F (below), which forwards the base's laws to ๐ป.
|
inlineconstexprexport |
The Birkhoff S leg \(\mathbb{R}\hookrightarrow\mathbb{D}\) over the coat-hanger: QuadraticReal<2> โ Dual<QuadraticReal<2>>, \(r\mapsto r+0\varepsilon\) (primal r, tangent 0).
A genuine monic ring embedding (an EmbedsAsSubalgebra S-leg, the ๐ป sibling of embed_โ_โ / embed_โ_โ): โ is the constant subring \(\{\,\varepsilon\text{-part}=0\,\}\subset\mathbb{D}\) (the value-0-tangent duals). Witnessed by computation below.