Parma Polyhedra Library requirements
C++ integral coefficient helper operations
PPL-SPEC-000051
1. Integral coefficient representation access and sign comparison PPL-SPEC-000051

For a live finite Coefficient, raw_value(x) shall return a reference to its underlying stored integer. The mutable overload shall refer to mutable storage and the const overload shall refer to const storage. In the mpz profile, that object shall be x itself and the referenced type shall be mpz_class. In bounded profiles it shall be the configured signed native integer member; both member x.raw_value() and free raw_value(x) shall refer to that same member. A returned reference shall remain valid only while its owning coefficient remains alive. A caller changing the raw value shall supply a finite value representable by that storage and satisfy its policy invariants; raw mutation shall not perform an arithmetic overflow check.

sgn(x) shall return -1, 0 or 1 exactly when the entry integer value is negative, zero or positive. cmp(x, y) shall return an int whose sign agrees with the ordering of the entry integer values. The magnitude of a nonzero comparison result shall not be prescribed. Neither query shall change either coefficient. These queries shall admit the entire selected integer range, including the bounded minimum.

The initialized-thread and object-synchronization conditions of 🔗 2. Finite coefficient construction, copying and comparison shall apply. Distinct source objects shall remain unchanged. The mpz profile shall be subject to available computational resources.

PPL-SPEC-000052
2. Coefficient negation and absolute-value assignment PPL-SPEC-000052

For live finite coefficients with source entry value a, neg_assign(x, y) shall assign  − a and abs_assign(x, y) shall assign |a|, where y supplies a. The one-argument forms shall apply the same operation to the destination's own entry value. The two-argument destination may be the source itself.

A successful bounded result shall be representable. In checked profiles, negating or taking the absolute value of the least representable integer shall report std::overflow_error and retain the surviving-output guarantee of 🔗 5. Checked coefficient overflow and result-policy dispatch. A native bounded caller shall satisfy the representability precondition.

The initialized-thread and object-synchronization conditions of 🔗 2. Finite coefficient construction, copying and comparison shall apply. Distinct source objects shall remain unchanged. The mpz profile shall be subject to available computational resources.

PPL-SPEC-000053
3. Coefficient remainder assignment and exact division PPL-SPEC-000053

For source entry values a and nonzero b, rem_assign(x, y, z) shall assign r = a − btrunc(a ⁄ b), where y supplies a and z supplies b. A nonzero remainder shall have the dividend's sign and satisfy |r| < |b|. This shall admit the bounded minimum divided by -1 and assign zero without requiring a representable quotient.

exact_div_assign(x, y, z) shall require nonzero b and exact divisibility of a by b. On success it shall assign a ⁄ b. The quotient shall be representable for successful bounded use. A checked quotient outside that range shall report std::overflow_error with the surviving-output guarantee of 🔗 5. Checked coefficient overflow and result-policy dispatch. No invalid divisor or nondivisibility rejection shall be promised.

For either operation the destination may be either source, including when both sources denote the same nonzero object; calculations shall use entry values.

The initialized-thread and object-synchronization conditions of 🔗 2. Finite coefficient construction, copying and comparison shall apply. Distinct source objects shall remain unchanged. The mpz profile shall be subject to available computational resources.

PPL-SPEC-000054
4. Coefficient greatest common divisor and least common multiple PPL-SPEC-000054

For live finite source entry values a and b, gcd_assign(x, y, z) shall assign the nonnegative greatest common divisor g. It shall assign zero for two zero sources and |a| when the other source is zero. lcm_assign(x, y, z) shall assign zero if either source is zero; otherwise it shall assign the positive least common multiple |a ⁄ g| |b|.

The destination may be either source, and the two sources may be the same object. Each calculation shall use their entry values. A successful bounded result shall be representable. For native bounded least-common-multiple calculation with two nonzero sources, both source absolute values shall additionally be representable. Native intermediate arithmetic shall be representable; in particular, no overflow shall be required to form a representable result.

In checked profiles, an unrepresentable nonnegative divisor or multiple, or an unrepresentable intermediate absolute value, shall report std::overflow_error with the surviving-output guarantee of 🔗 5. Checked coefficient overflow and result-policy dispatch. The zero-multiple case shall not require taking the absolute value of a nonzero source.

The initialized-thread and object-synchronization conditions of 🔗 2. Finite coefficient construction, copying and comparison shall apply. Distinct source objects shall remain unchanged. The mpz profile shall be subject to available computational resources.

PPL-SPEC-000055
5. Extended integral greatest common divisor PPL-SPEC-000055

For live finite source entry values a and b, successful gcdext_assign(g, s, t, a, b) shall assign the nonnegative greatest common divisor to g and integer coefficients to s and t satisfying as + bt = g. For two zero inputs, g shall be zero; no particular Bezout coefficients shall be required. Other cases shall also not prescribe a unique pair of Bezout coefficients.

The three output objects shall be pairwise distinct and shall be distinct from both source objects. The source objects may be the same object. This contract shall not admit other aliasing. All bounded output values and each evaluated Euclidean coefficient, quotient, product and difference shall be representable for successful bounded use. When the second source is nonzero, the absolute values of both bounded sources shall additionally be representable. When the second source is zero, the first absolute value shall be representable.

Checked unrepresentable source absolute-value acquisition shall report std::overflow_error with the surviving-output guarantee of 🔗 5. Checked coefficient overflow and result-policy dispatch. This shall not promise that the unchecked native intermediate expressions within the extended Euclidean algorithm report overflow; the stated intermediate preconditions remain applicable in every bounded profile.

The initialized-thread and object-synchronization conditions of 🔗 2. Finite coefficient construction, copying and comparison shall apply. Distinct source objects shall remain unchanged. The mpz profile shall be subject to available computational resources.

6. Integral product accumulation and subtraction PPL-SPEC-000056

For destination and source entry values d, a and b, successful add_mul_assign(x, y, z) shall assign d + ab and successful sub_mul_assign(x, y, z) shall assign d − ab. The destination may be either or both sources, and the two sources may be the same object; each operand shall be interpreted at entry.

Successful bounded use shall require both the product ab and the final sum or difference to be representable. These shall be two arithmetic steps, with no promise of a wider fused accumulator. A checked overflow in either step shall report std::overflow_error with the surviving-output guarantee of 🔗 5. Checked coefficient overflow and result-policy dispatch. This shall include an unrepresentable product whose addition to or subtraction from the destination could have cancelled into range: the operation may fail at that intermediate step. Native bounded callers shall satisfy both representability conditions.

The initialized-thread and object-synchronization conditions of 🔗 2. Finite coefficient construction, copying and comparison shall apply. Distinct source objects shall remain unchanged. The mpz profile shall be subject to available computational resources.

PPL-SPEC-000057
7. Nonnegative integer square-root assignment PPL-SPEC-000057

For a live finite source with nonnegative entry value a, sqrt_assign(x, y) shall assign q = ⌊√(a)⌋. Equivalently q ≥ 0 and q2 ≤ a < (q + 1)2. The destination may be the source itself and shall use its entry value. Every nonnegative input representable in the selected profile shall be admitted; verifying the mathematical inequalities shall not require the caller to form their possibly unrepresentable bounded squares. No negative input rejection guarantee shall be inferred from this contract.

The initialized-thread and object-synchronization conditions of 🔗 2. Finite coefficient construction, copying and comparison shall apply. Distinct source objects shall remain unchanged. The mpz profile shall be subject to available computational resources.

PPL-SPEC-000058
8. Reduction of an integral coefficient pair PPL-SPEC-000058

For finite source entry values a and b, not both zero, normalize2(x, y, n_x, n_y) shall assign a ⁄ g and b ⁄ g to the corresponding outputs, where g = gcd(a, b) > 0. It shall preserve each nonzero source's sign, produce a pair with greatest common divisor one, and preserve the ratio where defined.

The two outputs shall be distinct. n_x may be x and n_y may be y; other aliasing shall be excluded. For bounded successful use, the nonnegative gcd and both exact quotients shall be representable. Native intermediate arithmetic shall be representable. A checked gcd or quotient overflow shall report std::overflow_error with the surviving-output guarantee of 🔗 5. Checked coefficient overflow and result-policy dispatch.

The initialized-thread and object-synchronization conditions of 🔗 2. Finite coefficient construction, copying and comparison shall apply. Distinct source objects shall remain unchanged. The mpz profile shall be subject to available computational resources.

PPL-SPEC-000059
9. Integral parity, additive inverses and extremum assignment PPL-SPEC-000059

For live finite Coefficient values, is_even(x) shall return true exactly when the integer value of x is divisible by two. is_additive_inverse(x, y) shall return true exactly when their mathematical integer sum is zero, without requiring evaluation of a bounded sum. It shall return false when the mathematical inverse of x is outside the selected integer range. Both predicates shall admit every representable source value, preserve their inputs and return bool.

For entry values a and b, min_assign(x, y) and max_assign(x, y) shall assign min(a, b) and max(a, b), respectively. The destination and source may be the same object. These assignments shall admit the full selected range and shall preserve a distinct source.

The initialized-thread and object-synchronization conditions of 🔗 2. Finite coefficient construction, copying and comparison shall apply. Distinct source objects shall remain unchanged. The mpz profile shall be subject to available computational resources.