Parma Polyhedra Library requirements
C++ unbounded integer divisors and square roots

C++ unbounded integer divisors and square roots

1. Exact unbounded integer greatest common divisor and least common multiple
UID: PPL-SPEC-000517
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP, SCALAR_MPZ
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For live mpz_class sources with entry values a and b, gcd_assign_r shall assign their nonnegative greatest common divisor g. Two zero sources shall yield zero; when exactly one source is zero, g shall be the other source's absolute value. lcm_assign_r shall assign zero when either source is zero, otherwise shall assign the positive integer |a ⁄ g| |b|.

Both operations shall return V_EQ for every valid rounding request, including strict and exactness requests. The output may alias either source and both sources may be the same object; the formula shall use their entry values. Distinct sources shall remain unchanged. Unbounded resource, object-synchronization and initialization/hardware independence conditions shall follow 🔗 1. Exact named arithmetic on unbounded integer storage. No configured bounded-coefficient range shall limit either operation.

RATIONALE:

Nonnegative normalization and explicit zero conventions give common divisors and multiples a portable exact meaning, independently of the selected coefficient profile.

INTERFACE:

Public header: <ppl.hh>; effective template instantiations in Parma_Polyhedra_Library:

Result gcd_assign_r(mpz_class& to, const mpz_class& x,
                    const mpz_class& y, Rounding_Dir dir);
Result lcm_assign_r(mpz_class& to, const mpz_class& x,
                    const mpz_class& y, Rounding_Dir dir);
VERIFICATION_CRITERIA:

Compare with an independent Euclidean oracle using shift/subtract long division. Check all source signs and zero combinations, coprime and reducible pairs, large integer literals, all destination/source aliases, all eight requests and preserved distinct sources.

SOURCE:

src/checked_mpz_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/unboundedintegerfunctionspec1.cc.

2. Exact unbounded integer Bezout coefficients
UID: PPL-SPEC-000518
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP, SCALAR_MPZ
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For live mpz_class sources with entry values a and b, gcdext_assign_r shall assign the nonnegative greatest common divisor to g and integers to s and t satisfying as + bt = g. For two zero sources, g shall be zero; no particular pair of Bezout coefficients shall be required. No unique pair shall be prescribed in other cases either.

The three output objects shall be pairwise distinct and distinct from both source objects. The source objects may be the same object. The operation shall return V_EQ for every valid rounding request, including strict and exactness requests, and preserve both sources. Available resources shall suffice for the unbounded outputs and intermediates. Synchronization, initialization independence and absence of configured coefficient/FPU limits shall follow 🔗 1. Exact named arithmetic on unbounded integer storage.

RATIONALE:

The Bezout identity specifies the result independently of backend choices among multiple valid coefficients. Explicit output separation prevents accidental assumptions about multiple-output aliasing.

INTERFACE:

Public header: <ppl.hh>; effective template instantiations in Parma_Polyhedra_Library:

Result gcdext_assign_r(mpz_class& g, mpz_class& s, mpz_class& t,
                       const mpz_class& x, const mpz_class& y,
                       Rounding_Dir dir);
VERIFICATION_CRITERIA:

Check the independent expected gcd, nonnegativity and Bezout reconstruction for every source sign and zero combination, equal shared sources, coprime/noncoprime inputs and large integers. Test all eight requests, changed outputs, source preservation and hardware-mode independence.

SOURCE:

src/checked_mpz_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/unboundedintegerfunctionspec1.cc.

PPL-SPEC-000519
3. Directed unbounded integer square roots
UID: PPL-SPEC-000519
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP, SCALAR_MPZ
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For a live nonnegative mpz_class source with value a, let r = √(a) denote the exact nonnegative real root. sqrt_assign_r with ROUND_DOWN shall assign ⌊r⌋ and with ROUND_UP shall assign ⌈r⌉. A perfect-square source shall return V_EQ for either direction. Otherwise, downward rounding shall return V_GT and upward rounding shall return V_LT. Adding ROUND_STRICT_RELATION shall retain these definite classifications.

ROUND_IGNORE shall select the floor and return a relation admitting r ≥ to. A strict delegated request shall distinguish V_EQ from V_GT. ROUND_NOT_NEEDED shall require a to be a perfect square, assign the exact root and return a relation admitting equality; a strict exactness request shall return V_EQ. The result shall never depend on irrational_precision.

The destination may alias the source, using its entry value. A distinct source shall remain unchanged. Resource, range, synchronization and initialization/hardware independence conditions shall follow 🔗 1. Exact named arithmetic on unbounded integer storage. Shared scratch-integer pools used for directed root remainders shall be serialized in a build without thread-safe support; thread-safe configurations shall use calling-thread pools.

RATIONALE:

An unbounded integer root is an adjacent integer bound on the real square root and is independent of the rational square-root precision grid.

INTERFACE:

Public header: <ppl.hh>; effective template instantiations in Parma_Polyhedra_Library:

Result sqrt_assign_r(mpz_class& to, const mpz_class& from,
                     Rounding_Dir dir);
VERIFICATION_CRITERIA:

Use an independent integer bisection oracle and squared inequalities. Check zero, one, perfect squares and their neighbors, very large inputs, both directed relations, delegated and admitted exactness requests, aliases, unchanged sources and all available hardware modes.

SOURCE:

src/checked_mpz_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/unboundedintegerfunctionspec1.cc.