C++ integral coefficients
|
Type
|
Level
|
MID
|
UID
|
REFS
|
Title
|
Statement
|
Rationale
|
Comment
|
BIBLIOGRAPHY
|
STATUS
|
COMPONENT
|
APPLICABILITY
|
VERIFICATION_METHODS
|
VERIFICATION_CRITERIA
|
SOURCE
|
LANGUAGE
|
VISIBILITY
|
INTERFACE
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
SW_SPEC
|
1 |
|
|
Incoming links from:
6. Coefficient zero and one constant access
8. Reduction of an integral coefficient pair
2 |
The public Coefficient alias shall designate the configured integral coefficient type. The mpz profile shall select mpz_class (also named GMP_Integer). For each supported width n ∈ {8, 16, 32, 64}, checked-intN shall select Checked_Number<intN_t, Bounded_Integer_Coefficient_Policy> and native-intN shall select Checked_Number<intN_t, Checked_Number_Transparent_Policy<intN_t>>. Here N in a profile or type name denotes that selected width. The bounded profiles shall represent the mathematical integers from − 2n − 1 through 2n − 1 − 1, inclusive. The mpz profile shall have no fixed-width integer range limit; available resources still limit computations. A native profile shall not promise overflow checking. The selection shall not introduce a global 128-bit coefficient type or change the meaning of coordinate indices. Coefficient_traits shall be Coefficient_traits_template<Coefficient>. Its const_reference shall be const Coefficient& for mpz and both 64-bit bounded profiles, and Coefficient for the 8-, 16- and 32-bit bounded profiles. This trait shall determine whether a constant accessor returns a borrowed reference or a value, as specified by 🔗 6. Coefficient zero and one constant access. |
Profile identity determines range, overflow policy and whether returned constants are borrowed values. A common alias does not erase these configuration-dependent contracts. |
|
|
|
|
|
For all nine configured profiles, check the selected type, width, signed range and exact return-trait type at compile time. Check that the coefficient-kind selection is unique. Compile clients against the matching public header; distinguish these checks from unrelated native 128-bit capabilities. |
src/Coefficient_types.hh; src/GMP_Integer_types.hh; configure.ac; tests/coefficient2.cc. |
|
|
Public header: <ppl.hh>; names belong to Parma_Polyhedra_Library. The configured header shall expose one selected coefficient alias and its trait alias. Representative configured declarations: // mpz configuration: typedef mpz_class Coefficient; typedef Coefficient_traits_template<Coefficient> Coefficient_traits; // checked-int8 configuration instead: // typedef Checked_Number<int8_t, // Bounded_Integer_Coefficient_Policy> Coefficient; // native-int8 configuration instead: // typedef Checked_Number<int8_t, // Checked_Number_Transparent_Policy<int8_t>> Coefficient; The same bounded forms shall apply with int16_t, int32_t or int64_t for the other configured widths. |
||
|
SW_SPEC
|
2 |
|
|
Incoming links from:
3. Exact ordinary integral coefficient arithmetic
8. Coefficient scaling and truncated division by powers of two
1. Integral coefficient representation access and sign comparison
2. Coefficient negation and absolute-value assignment
3. Coefficient remainder assignment and exact division
4. Coefficient greatest common divisor and least common multiple
5. Extended integral greatest common divisor
6. Integral product accumulation and subtraction
7. Nonnegative integer square-root assignment
8. Reduction of an integral coefficient pair
9. Integral parity, additive inverses and extremum assignment
11 |
A default-constructed Coefficient shall have value zero. Construction from a representable native integral input and copying from a live coefficient shall preserve the source integer value. The common native input forms covered here are char, signed char, unsigned char, short, unsigned short, int, unsigned int, long and unsigned long. Copy assignment shall replace the target value with the source's entry value, return a reference to the target and preserve a distinct source. Self-copy assignment shall preserve the value. Later mutation of a value shall not change a distinct copy. Destruction of one value shall not invalidate another value or a separately owned copy of a constant. For live finite coefficient values, equality and ordering comparisons shall agree with equality and ordering of their mathematical integers and shall preserve the operands. These obligations shall hold independently of object identity and the current floating-point rounding direction. Construction and use shall satisfy the applicable initialized-thread protocol in 🔗 3. Thread initialization, default state and finalization. Callers shall prevent concurrent access to an object while another operation changes it. This contract's integral-input guarantee requires the input value to be representable in the selected profile. |
Coefficients must retain integer value semantics across the selected backend, even when that backend owns dynamically allocated limbs. |
|
|
|
|
|
Check default zero, positive and negative integral construction, copy construction, assignment return identity, self-assignment and independent later mutation. Compare all six predicates against an independent integer ordering, including bounded endpoints and large multi-limb GMP values. Destroy original values while retaining copies. Exercise assertion and nonassertion builds. |
src/Coefficient_types.hh; src/Checked_Number_inlines.hh; GMP integer provider; tests/coefficient2.cc. |
|
|
Public header: <ppl.hh>. The selected coefficient provider shall admit these forms in a C++ client function using PPL names: Coefficient zero; Coefficient x(7); Coefficient y(x); Coefficient& target = (y = x); y = y; bool equal = (x == y); bool different = (x != y); bool less = (x < y); bool less_equal = (x <= y); bool greater = (x > y); bool greater_equal = (x >= y); The literals illustrate admitted calls; the value guarantees apply to all representable operands in this contract. |
||
|
SW_SPEC
|
3 |
|
|
|
For live finite coefficients with mathematical entry values a and b, successfully materialized addition, subtraction and multiplication shall produce a + b, a − b and ab, respectively. Unary plus shall preserve the value and unary minus shall produce − a. Compound addition, subtraction and multiplication shall replace the target by the corresponding result computed from the operands' entry values and return a reference to the target. This shall include an operand that is the target itself. Prefix increment and decrement shall change the value by one and return a reference to the changed target. Postfix forms shall make the same change and return an independent value equal to the target's entry value. The mathematical result of every evaluated arithmetic step shall be representable in the selected bounded profile. Operand values shall remain unchanged unless they designate the assigned target. Results formed by the GMP expression-template provider shall be evaluated while their referenced operands remain alive. The initialized-thread and synchronization prerequisites of 🔗 2. Finite coefficient construction, copying and comparison shall apply. Checked overflow reporting is specified by 🔗 5. Checked coefficient overflow and result-policy dispatch; native overflow is outside the successful-result preconditions. |
Exact integer arithmetic is the common foundation of the domains. Entry-value semantics make self-aliasing and increment/decrement results precise without constraining backend expression representation. |
|
|
|
|
|
Compare zero, mixed signs, cancellation, products and representable endpoint-adjacent results with literal or independently computed integer answers. Check compound return identity, preservation of distinct operands, self-add/subtract/multiply within range, and prefix/postfix entry values. Include multi-limb GMP cases and avoid executing native overflow. Check results after independent operand mutations. |
src/Coefficient_types.hh; src/Checked_Number_inlines.hh; GMP integer provider; tests/coefficient2.cc. |
|
|
Public header: <ppl.hh>. The selected provider shall admit these materializing forms for live Coefficient operands a and b: Coefficient sum(a + b); Coefficient difference(a - b); Coefficient product(a * b); Coefficient positive(+a); Coefficient negative(-a); Coefficient& added = (a += b); Coefficient& subtracted = (a -= b); Coefficient& multiplied = (a *= b); Coefficient& incremented = ++a; Coefficient old_increment(a++); Coefficient& decremented = --a; Coefficient old_decrement(a--); Intermediate arithmetic expression types may differ between providers. Materializing the result as Coefficient shall produce the stated integer value. |
||
|
SW_SPEC
|
4 |
|
|
|
For live finite coefficients with entry values a and nonzero b, a successfully materialized quotient shall be q = trunc(a ⁄ b). A materialized remainder shall be r = a − bq, with |r| < |b|; a nonzero remainder shall have the sign of a. Quotient calculation shall require q to be representable. In a bounded profile, dividing the least representable integer by -1 shall therefore be outside this successful-quotient precondition. Remainder calculation shall admit every representable dividend and nonzero representable divisor, including that least-integer/-1 pair, and shall return zero for that pair. The mathematical definition of r shall not require the caller to compute an unrepresentable bounded quotient or intermediate product. Compound division and remainder shall compute the corresponding result from entry values, replace the target and return a reference to it. The divisor may designate that target when its entry value is nonzero. Distinct operands shall remain unchanged. No zero-divisor rejection guarantee shall be inferred from these valid-input contracts. Materialization, thread initialization and synchronization shall follow 🔗 3. Exact ordinary integral coefficient arithmetic. |
Negative operands distinguish truncation toward zero from floor division. Remainder can remain representable even where its corresponding bounded quotient is not. |
|
|
|
|
|
Use literal quotient/remainder answers for every sign combination, exact and inexact division, zero dividends, unit divisors and bounded endpoints. Verify reconstruction with an unbounded oracle, not overflowing bounded intermediates. Check MIN remainder -1 separately from the excluded native quotient. Exercise compound/self-aliasing forms and preserve distinct operands. |
src/Coefficient_types.hh; src/Checked_Number_inlines.hh; src/checked_int_inlines.hh; GMP integer provider; tests/coefficient2.cc. |
|
|
Public header: <ppl.hh>. For live Coefficient operands a and b satisfying the respective preconditions: Coefficient quotient(a / b); Coefficient remainder(a % b); Coefficient& divided = (a /= b); Coefficient& reduced = (a %= b); The quotient and remainder forms shall have the same stated conventions in GMP, checked bounded and native bounded profiles. |
||
|
SW_SPEC
|
5 |
|
|
Incoming links from:
3. Exact ordinary integral coefficient arithmetic
8. Coefficient scaling and truncated division by powers of two
2. Coefficient negation and absolute-value assignment
3. Coefficient remainder assignment and exact division
4. Coefficient greatest common divisor and least common multiple
5. Extended integral greatest common divisor
6. Integral product accumulation and subtraction
8. Reduction of an integral coefficient pair
5. Bounded integer coefficient policy configuration
8. Rational canonical-form inspection and coefficient component extraction
1. Exact scalar numerator and denominator extraction
11 |
For a checked bounded coefficient profile, an ordinary coefficient arithmetic operation in 🔗 3. Exact ordinary integral coefficient arithmetic, or quotient calculation in 🔗 4. Coefficient quotient and remainder with truncation toward zero, whose exact integer result is outside the selected range shall throw std::overflow_error instead of returning a successful wrapped result. This includes negation of the least representable integer, endpoint-crossing increment or decrement, and dividing the least representable integer by -1. Operand prerequisites other than representability shall still apply. After a supported arithmetic overflow exception, a surviving coefficient object shall remain destructible and assignable to a new representable value. Its previous value shall not be promised to remain unchanged. A constructor that throws shall not produce a usable object. Exception-message text shall not be prescribed. These promises shall not extend overflow checking to a native coefficient profile or promise rejection of a zero divisor. For checked profiles, Bounded_Integer_Coefficient_Policy::handle_result(r) shall return normally exactly when result_overflow(r) is zero and result_class(r) differs from VC_NAN. Otherwise it shall dispatch to throw_result_exception(r). Supported positive/negative overflow codes, including unknown intermediate overflow, shall produce std::overflow_error. V_NAN and V_CVT_STR_UNK shall produce std::domain_error. A normally returned inexact result classification shall not be reclassified as exact. |
Checked bounded storage must detect arithmetic range loss while retaining a usable failure state. Its result handler distinguishes overflow and invalid-number classes from ordinary precision relations. |
|
|
|
|
|
For each checked width, cross both range boundaries with addition, subtraction, multiplication, unary negation and increment/decrement. Require the exact exception category, then explicitly reassign and reuse surviving outputs without inspecting a promised old payload. Exercise accepted normal classifications, both signed overflow classes, invalid numeric input and unknown intermediate overflow. Cover all short-circuit outcomes in the policy handler. |
src/Coefficient_types.hh; src/Coefficient_inlines.hh; src/Checked_Number.cc; tests/coefficient2.cc. |
|
|
Public header: <ppl.hh>. In a checked coefficient configuration: struct Bounded_Integer_Coefficient_Policy { static void handle_result(Result r); }; The arithmetic call forms are specified by 🔗 3. Exact ordinary integral coefficient arithmetic and 🔗 4. Coefficient quotient and remainder with truncation toward zero. The policy operation shall be a static member. |
||
|
SW_SPEC
|
6 |
|
|
|
Within the calling thread's active initialization lifetime, Coefficient_zero() and Coefficient_one() shall return coefficients with values zero and one, respectively, through Coefficient_traits::const_reference as defined by 🔗 1. Configured integral coefficient type and return trait. Repeated access shall preserve those values. When the trait is a reference, repeated calls on the same thread within that lifetime shall refer to the same corresponding constant object. The caller shall not mutate that borrowed object or retain its use beyond the applicable initialized-thread lifetime. When the trait returns a value, the returned coefficient shall be an independent value. Making and modifying a value copy of either constant shall leave the constant unchanged. Initialization and finalization shall follow 🔗 1. Initialization owners and automatic C++ initialization and 🔗 3. Thread initialization, default state and finalization. In a thread-safe configuration, reference-returning constant storage shall belong to the calling thread and access by an initialized worker shall preserve another initialized thread's constants. Reinitialization shall not revive borrowed references from a preceding lifetime. |
Canonical zero and one avoid repeated construction while the return trait preserves the appropriate value or borrowing convention for the configured representation. |
|
|
|
|
|
Across all profiles, check values, exact result types, repeated reference identity where applicable and independent mutation of copies. Run balanced initialization lifetimes. In thread-safe builds, check independently initialized workers while another thread retains its constants. Use initialization failure/retry tests for incomplete GMP constant acquisition. Compile an installed-header client. |
src/Coefficient_defs.hh; src/Coefficient_inlines.hh; tests/coefficient1.cc; tests/coefficient2.cc; tests/initialization1.cc. |
|
|
Public header: <ppl.hh>. Declarations in Parma_Polyhedra_Library: Coefficient_traits::const_reference Coefficient_zero(); Coefficient_traits::const_reference Coefficient_one(); |
||
|
SW_SPEC
|
7 |
|
|
|
The internal coefficient-constant initialization stage shall be entered only when that thread has no active instance of the stage. In the mpz profile, successful Coefficient_constants_initialize() shall acquire and publish one owned zero coefficient and one owned unit coefficient for that thread. Neither pointer shall be published until both objects have been constructed. If supported recoverable construction failure occurs, partial acquisitions shall be destroyed, both published pointers shall remain null and a later initialization attempt shall be permitted. Coefficient_constants_finalize() shall require the initialized stage and completion of all dependent uses. It shall release both owned objects and clear both published pointers. The bounded profiles shall require no owned constant-stage allocation; their initialization and finalization functions shall perform no stage-resource operation. Their accessor storage shall follow 🔗 6. Coefficient zero and one constant access. The enclosing initialization transaction shall acquire and release this stage in dependency order under 🔗 3. Thread initialization, default state and finalization. Callers shall not interleave independent stage ownership protocols for the same thread. |
Publishing a complete pair prevents incomplete singleton ownership after failure. Explicit stage release makes retry and reverse-order initialization cleanup possible. |
|
|
|
|
|
Check repeated balanced stage lifetimes, published zero/one values and release of acquired storage. Inject each GMP stage allocation failure and verify null publication, resource cleanup and successful retry before testing dependent objects. Inspect bounded no-op implementations. Exercise enclosing library/thread rollback in initialization3 and initialization4. |
src/Coefficient.cc; tests/coefficient2.cc; tests/initialization3.cc; tests/initialization4.cc. |
|
|
Internal declarations in Parma_Polyhedra_Library: void Coefficient_constants_initialize(); void Coefficient_constants_finalize(); These operations form an internal initialization stage. Public clients shall use the library/thread initialization interfaces. |
||
|
SW_SPEC
|
8 |
|
|
Parents:
|
|
For a live finite coefficient with entry value a and an unsigned exponent e, successful mul_2exp_assign(x, y, e) shall assign a2e to x, where a is y's entry value. Successful div_2exp_assign(x, y, e) shall assign trunc(a ⁄ 2e) to x. Truncation shall be toward zero for either sign. The exponent zero shall preserve the input value. The destination may be the source itself. A distinct source shall remain unchanged. A successful bounded multiplication result shall be representable. For native bounded multiplication, the exponent shall additionally be less than the selected width. These conditions shall include multiplying -1 by the power whose exponent is one less than that width, producing the least representable integer without undefined intermediate signed overflow. Bounded division shall admit every unsigned int exponent; an exponent at least as large as the coefficient width shall produce zero. Checked bounded multiplication shall also admit every such exponent: a zero source shall produce zero, while a nonzero source with an exponent at least as large as the width shall report overflow. The mpz profile shall admit the unsigned int exponent range subject to available computational resources. Checked bounded multiplication whose result is outside the coefficient range, with other input prerequisites satisfied, shall report std::overflow_error and retain the surviving-output guarantee of 🔗 5. Checked coefficient overflow and result-policy dispatch. Native bounded operations shall not promise overflow detection. The initialized-thread and synchronization conditions of 🔗 2. Finite coefficient construction, copying and comparison shall apply. |
Scaling by powers of two is an integer operation, including at the negative range boundary. A representable result must not be invalidated by an overflowing signed intermediate. Division must retain the same truncation convention as ordinary integer quotient calculation. |
|
|
|
|
|
Check zero and nonzero exponents, positive and negative inputs, zero values, destination/source aliasing and preservation of distinct sources. Include the negative sign-bit boundary in every bounded width, multi-limb GMP values, and literal signed-division answers. Compare checked positive and negative overflow with the required exception and explicitly reassign surviving outputs. Run native valid-result cases under undefined-behavior sanitization and confirm that introducing an overflowing signed intermediate is detected by the boundary regression. |
src/GMP_Integer_defs.hh and src/GMP_Integer_inlines.hh: GMP helpers. src/Checked_Number_inlines.hh: bounded coefficient helper dispatch. src/checked_int_inlines.hh: bounded scaling and division. tests/coefficient2.cc: configured dyadic arithmetic and boundary cases. |
|
|
Public header: <ppl.hh>. For Coefficient operands in Parma_Polyhedra_Library, the selected provider shall admit: void mul_2exp_assign(Coefficient& x, const Coefficient& y, unsigned int exp); void div_2exp_assign(Coefficient& x, const Coefficient& y, unsigned int exp); For a bounded profile these callable forms are supplied by function-template instantiations for the configured coefficient type. |