|
C(++)ECCO
C++ Error Control COding: a header-only library for ECC simulations and experiments, modeling complete coding systems across arbitrary finite fields and complex inter-field relationships - Christian Senger <senger@inue.uni-stuttgart.de>
|
Prime field π½_p β β€/pβ€ More...
#include <fields.hpp>

Public Types | |
| using | label_t = ::CECCO::label_t<p> |
Public Member Functions | |
| constexpr | Fp () noexcept |
| Default constructor: 0. | |
| constexpr | Fp (int l) |
| Construct from int, reducing modulo p (handles negative values). | |
| constexpr | Fp (const Fp &other) noexcept=default |
| constexpr | Fp (Fp &&other) noexcept=default |
| template<FiniteFieldType S, MOD ext_modulus, LutMode mode> | |
| Fp (const Ext< S, ext_modulus, mode > &other) | |
| Extract a prime-field element from an extension field (downcast). | |
| template<FiniteFieldType MAIN, FiniteFieldType... OTHERS> requires SubfieldOf<Iso<MAIN, OTHERS...>, Fp<p>> | |
| Fp (const Iso< MAIN, OTHERS... > &other) | |
| Extract a prime-field element from an Iso containing this prime subfield. | |
| ~Fp () noexcept=default | |
| constexpr Fp & | operator= (int l) noexcept |
| Assign int, reducing modulo p. | |
| constexpr Fp & | operator= (const Fp &rhs) noexcept=default |
| constexpr Fp & | operator= (Fp &&rhs) noexcept=default |
| template<FiniteFieldType S, MOD ext_modulus, LutMode mode> | |
| Fp & | operator= (const Ext< S, ext_modulus, mode > &other) |
| Project an extension-field element to π½_p (copy-and-swap; same semantics as the constructor). | |
| template<FiniteFieldType MAIN, FiniteFieldType... OTHERS> | |
| Fp & | operator= (const Iso< MAIN, OTHERS... > &other) |
| Project an Iso element to π½_p (copy-and-swap; same semantics as the constructor). | |
| constexpr bool | operator== (const Fp &rhs) const noexcept |
| constexpr Fp | operator- () const &noexcept |
| Additive inverse (lvalue): returns a new element with -label mod p. | |
| constexpr Fp & | operator- () &&noexcept |
| Additive inverse (rvalue): in place. | |
| constexpr Fp & | operator+= (const Fp &rhs) noexcept |
| *this = (label + rhs.label) mod p | |
| constexpr Fp & | operator-= (const Fp &rhs) noexcept |
| *this = (label β rhs.label) mod p | |
| constexpr Fp & | operator*= (const Fp &rhs) noexcept |
| *this = (label Β· rhs.label) mod p | |
| constexpr Fp & | operator*= (int s) noexcept |
| *this = (label Β· s) mod p (repeated addition) | |
| Fp & | operator/= (const Fp &rhs) |
| *this = (label Β· rhs.labelβ»ΒΉ) mod p; throws std::invalid_argument if rhs is zero | |
| Fp & | randomize () |
| Uniform random element in {0, β¦, p β 1}. | |
| Fp & | randomize_force_change () |
| Like randomize but guaranteed to differ from the current value. | |
| size_t | get_multiplicative_order () const |
| Multiplicative order in π½_p*. | |
| size_t | get_additive_order () const |
| Additive order: 1 for zero, p otherwise. | |
| constexpr size_t | get_label () const noexcept |
| Underlying integer label in {0, β¦, p β 1}. | |
| constexpr bool | has_positive_sign () const noexcept |
| Always true (finite fields are unordered). | |
| constexpr bool | is_zero () const noexcept |
| True iff this is the additive identity. | |
| constexpr Fp & | erase () noexcept |
| Mark this element as erased (encoded as label == max(label_t)). | |
| constexpr Fp & | unerase () noexcept |
| Clear the erasure flag, resetting to the additive identity. | |
| constexpr bool | is_erased () const noexcept |
| Test whether this element is currently erased. | |
| template<FiniteFieldType S, MOD ext_modulus, LutMode mode> | |
| Fp< p > & | operator= (const Ext< S, ext_modulus, mode > &rhs) |
| template<FiniteFieldType MAIN, FiniteFieldType... OTHERS> | |
| Fp< p > & | operator= (const Iso< MAIN, OTHERS... > &rhs) |
| Public Member Functions inherited from CECCO::details::Field< Fp< p > > | |
| Fp< p > & | operator= (int l)=delete |
| Assign from int β derived must implement. | |
| constexpr bool | operator!= (const Fp< p > &rhs) const |
| Inequality, defined as !(*this == rhs). | |
| constexpr Fp< p > | operator+ () const & |
| Unary + on an lvalue: returns a copy. | |
| Fp< p > | operator- () const &noexcept=delete |
| Additive inverse on an lvalue β derived must implement. | |
| Fp< p > & | operator+= (const Fp< p > &rhs) noexcept=delete |
| *this += rhs β derived must implement | |
| Fp< p > & | operator-= (const Fp< p > &rhs) noexcept=delete |
| *this -= rhs β derived must implement | |
| Fp< p > & | operator*= (const Fp< p > &rhs) noexcept=delete |
| *this *= rhs β derived must implement | |
| Fp< p > & | operator/= (const Fp< p > &rhs)=delete |
| *this /= rhs; throws std::invalid_argument if rhs is zero β derived must implement | |
| Field & | randomize ()=delete |
| Uniform random element of the field β derived must implement; may return the same value. | |
| Field & | randomize_force_change ()=delete |
| Like randomize but guaranteed to differ from the current value β derived must implement. | |
| size_t | get_multiplicative_order () const=delete |
| Smallest k > 0 with this^k == 1; throws std::invalid_argument if *this is zero. | |
| size_t | get_additive_order () const=delete |
| Smallest k > 0 with k * *this == 0; for finite fields of characteristic p this is p (or 1 for zero); for β it is 1 for zero and 0 (infinite) otherwise. | |
| bool | has_positive_sign () const noexcept=delete |
| True if the element is "positive" (always true for finite fields; sign of numerator for β). | |
| bool | is_zero () const noexcept=delete |
| True if *this is the additive identity. | |
| Field & | erase () noexcept=delete |
| Mark this element as erased (out-of-field marker for erasure decoding). | |
| Field & | unerase () noexcept=delete |
| Clear the erasure flag, resetting to additive identity. | |
| bool | is_erased () const noexcept=delete |
| Test whether this element is currently erased. | |
Static Public Member Functions | |
| static std::string | get_info () |
| Human-readable description: "prime field with p elements". | |
| static constexpr size_t | get_characteristic () noexcept |
| static constexpr Fp | get_generator () noexcept |
| Generator (primitive root) of π½_p*; precomputed label is Gen. | |
| static constexpr size_t | get_p () noexcept |
| static constexpr size_t | get_m () noexcept |
| static constexpr size_t | get_q () noexcept |
| static constexpr size_t | get_size () noexcept |
| static constexpr bool | is_constexpr_ready () noexcept |
| Always true for prime fields. | |
| static void | show_tables () |
| Print all lookup tables to std::cout (debugging aid). | |
| static constexpr bool | ready () |
| Compile-time signal that all LUTs are constructed. | |
Static Public Attributes | |
| static constexpr label_t | Gen = details::compute_primitive_root<Fp>() |
| Primitive element (generator) of F_p*. | |
Precomputed Lookup Tables | |
Compile-time generated tables for field operations | |
| static constexpr Lut2D | lut_add = details::compute_modular_addition_table<label_t, p>() |
| Addition lookup table: lut_add(a,b) = (a + b) mod p. | |
| static constexpr Lut2D | lut_mul = details::compute_modular_multiplication_table<label_t, p>() |
| Multiplication lookup table: lut_mul(a,b) = (a * b) mod p. | |
| static constexpr Lut1D | lut_neg = details::compute_additive_inverses_direct<label_t, p>() |
| Additive inverse lookup table: lut_neg[a] = (-a) mod p. | |
| static constexpr Lut1D | lut_inv = details::compute_multiplicative_inverses_direct<label_t, p>() |
| Multiplicative inverse lookup table: lut_inv[a] = a^(-1) mod p. | |
| static constexpr Lut1D | lut_mul_ord = details::compute_multiplicative_orders<label_t, p>(lut_mul) |
Multiplicative order lookup table: lut_mul_ord[a] = multiplicative order of a in π½_p \{0}. | |
| static constexpr bool | luts_ready |
Additional Inherited Members | |
| Protected Member Functions inherited from CECCO::details::Field< Fp< p > > | |
| ~Field () noexcept=default | |
| Protected Member Functions inherited from CECCO::details::Base | |
| Base ()=default | |
Prime field π½_p β β€/pβ€
| p | Prime modulus, 2 β€ p β€ 65521 (largest prime fitting in uint16_t) |
Elements are stored as label_t integers in {0, 1, β¦, p β 1} (width is the smallest unsigned type that fits p). Arithmetic is direct mod-p by default; define CECCO_USE_LUTS_FOR_FP to switch to LUTs (rarely advisable). The primality of p is enforced by static_assert.
Definition at line 1647 of file fields.hpp.
| using CECCO::Fp< p >::label_t = ::CECCO::label_t<p> |
Definition at line 1651 of file fields.hpp.
|
inlineconstexprnoexcept |
Default constructor: 0.
Definition at line 1654 of file fields.hpp.

|
constexpr |
Construct from int, reducing modulo p (handles negative values).
Definition at line 1879 of file fields.hpp.
|
constexprdefaultnoexcept |
|
constexprdefaultnoexcept |
Extract a prime-field element from an extension field (downcast).
| S | Base of the source extension field |
| ext_modulus | Modulus of the source extension field |
| std::invalid_argument | if other is not in the prime subfield |
Uses a cached CECCO::Embedding from Fp<p> to Ext<S, ext_modulus, mode>; since π½_p is the minimal subfield of any extension over it, this is the canonical reverse lookup. Source and target must share the characteristic (enforced by static_assert).
Definition at line 1887 of file fields.hpp.
| CECCO::Fp< p >::Fp | ( | const Iso< MAIN, OTHERS... > & | other | ) |
Extract a prime-field element from an Iso containing this prime subfield.
| std::invalid_argument | if no Iso component contains an element in π½_p |
Tries the MAIN representation first, then each of OTHERS, until one yields a successful downcast to Fp<p>.
Definition at line 1908 of file fields.hpp.
Mark this element as erased (encoded as label == max(label_t)).
Definition at line 2160 of file fields.hpp.
| size_t CECCO::Fp< p >::get_additive_order | ( | ) | const |
Additive order: 1 for zero, p otherwise.
Definition at line 2125 of file fields.hpp.
|
inlinestaticconstexprnoexcept |
Definition at line 1744 of file fields.hpp.
Generator (primitive root) of π½_p*; precomputed label is Gen.
Definition at line 1750 of file fields.hpp.
|
inlinestatic |
Human-readable description: "prime field with p elements".
Definition at line 1739 of file fields.hpp.
|
inlineconstexprnoexcept |
Underlying integer label in {0, β¦, p β 1}.
Definition at line 1747 of file fields.hpp.
|
inlinestaticconstexprnoexcept |
Definition at line 1753 of file fields.hpp.
| size_t CECCO::Fp< p >::get_multiplicative_order | ( | ) | const |
Multiplicative order in π½_p*.
| std::invalid_argument | if *this is zero |
Definition at line 2112 of file fields.hpp.
|
inlinestaticconstexprnoexcept |
Definition at line 1752 of file fields.hpp.
|
inlinestaticconstexprnoexcept |
Definition at line 1754 of file fields.hpp.
|
inlinestaticconstexprnoexcept |
Definition at line 1755 of file fields.hpp.
|
inlineconstexprnoexcept |
Always true (finite fields are unordered).
Definition at line 1769 of file fields.hpp.
|
inlinestaticconstexprnoexcept |
Always true for prime fields.
Prime fields' arithmetic interface is constexpr regardless of CECCO_USE_LUTS_FOR_FP, so a CompileTime CECCO::Ext can always be built on top.
Definition at line 1763 of file fields.hpp.
|
inlineconstexprnoexcept |
Test whether this element is currently erased.
Definition at line 1784 of file fields.hpp.
|
inlineconstexprnoexcept |
True iff this is the additive identity.
Definition at line 1771 of file fields.hpp.
*this = (label Β· rhs.label) mod p
Definition at line 2032 of file fields.hpp.
*this = (label Β· s) mod p (repeated addition)
Definition at line 2051 of file fields.hpp.
*this = (label + rhs.label) mod p
Definition at line 1998 of file fields.hpp.
Additive inverse (rvalue): in place.
Definition at line 1983 of file fields.hpp.
Additive inverse (lvalue): returns a new element with -label mod p.
Definition at line 1966 of file fields.hpp.
*this = (label β rhs.label) mod p
Definition at line 2015 of file fields.hpp.
*this = (label Β· rhs.labelβ»ΒΉ) mod p; throws std::invalid_argument if rhs is zero
Definition at line 2062 of file fields.hpp.
Project an extension-field element to π½_p (copy-and-swap; same semantics as the constructor).
Definition at line 1950 of file fields.hpp.
| Fp & CECCO::Fp< p >::operator= | ( | const Iso< MAIN, OTHERS... > & | other | ) |
Project an Iso element to π½_p (copy-and-swap; same semantics as the constructor).
| Fp< p > & CECCO::Fp< p >::operator= | ( | const Iso< MAIN, OTHERS... > & | rhs | ) |
Definition at line 1959 of file fields.hpp.
Assign int, reducing modulo p.
Definition at line 1941 of file fields.hpp.
|
inlineconstexprnoexcept |
Definition at line 1705 of file fields.hpp.
Uniform random element in {0, β¦, p β 1}.
Definition at line 2076 of file fields.hpp.
Like randomize but guaranteed to differ from the current value.
Definition at line 2094 of file fields.hpp.
|
inlinestaticconstexpr |
Compile-time signal that all LUTs are constructed.
Used by extension fields built on top of π½_p to defer their own LUT computation until the base field is fully instantiated, avoiding compiler recursion-depth issues.
Definition at line 1793 of file fields.hpp.
|
static |
Print all lookup tables to std::cout (debugging aid).
Definition at line 2134 of file fields.hpp.
Clear the erasure flag, resetting to the additive identity.
Definition at line 2166 of file fields.hpp.
|
staticconstexpr |
Primitive element (generator) of F_p*.
Smallest primitive root mod p, computed at compile time via constexpr power enumeration using Fp's own multiplication.
Definition at line 1831 of file fields.hpp.
|
staticconstexpr |
Addition lookup table: lut_add(a,b) = (a + b) mod p.
Definition at line 1850 of file fields.hpp.
|
staticconstexpr |
Multiplicative inverse lookup table: lut_inv[a] = a^(-1) mod p.
Definition at line 1859 of file fields.hpp.
|
staticconstexpr |
Multiplication lookup table: lut_mul(a,b) = (a * b) mod p.
Definition at line 1853 of file fields.hpp.
|
staticconstexpr |
Multiplicative order lookup table: lut_mul_ord[a] = multiplicative order of a in π½_p \{0}.
Definition at line 1862 of file fields.hpp.
|
staticconstexpr |
Additive inverse lookup table: lut_neg[a] = (-a) mod p.
Definition at line 1856 of file fields.hpp.
|
staticconstexpr |
Definition at line 1864 of file fields.hpp.