Parma Polyhedra Library requirements
C++ unbounded integer named arithmetic

C++ unbounded integer named arithmetic

UID:
VERSION:
CLASSIFICATION:
PREFIX:
Type
Level
MID
UID
REFS
Title
Statement
Rationale
Comment
BIBLIOGRAPHY
STATUS
COMPONENT
APPLICABILITY
VERIFICATION_METHODS
VERIFICATION_CRITERIA
SOURCE
LANGUAGE
VISIBILITY
INTERFACE
SW_SPEC
1
PPL-SPEC-000511

The source and destination objects shall be live mpz_class values, independently of the configured Coefficient alias. add_assign_r, sub_assign_r and mul_assign_r shall assign the exact sum, difference and product of the source integers. neg_assign_r and abs_assign_r shall assign exact negation and absolute value. floor_assign_r, ceil_assign_r and trunc_assign_r shall preserve an integer source's value. Every operation shall return V_EQ for each valid rounding direction, with or without ROUND_STRICT_RELATION.

The output may alias any source, and read-only sources may alias each other. Distinct sources shall remain unchanged. Calls shall require available resources for unbounded arithmetic and access synchronized against mutation. The stored integers and intermediates shall have no configured fixed-width coefficient limit. No library/thread initialization owner, coefficient-constant stage, floating-point backend setup, hardware direction, inexact flag or irrational-precision setting shall be required. Arithmetic/resource failure shall not be a successful result; no universal output rollback shall be promised after a reported failure.

Named numerical operations must retain unbounded integer semantics even when the globally configured coefficient type has a bounded range.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ
Test, Analysis, Inspection

Check literal small and very large signed integer arithmetic oracles, zero and cancellation, all eight requests, every permitted alias and unchanged distinct sources in all coefficient configurations.

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

CPP
Public

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

Result add_assign_r(mpz_class& to, const mpz_class& x,
                    const mpz_class& y, Rounding_Dir dir);
Result sub_assign_r(mpz_class& to, const mpz_class& x,
                    const mpz_class& y, Rounding_Dir dir);
Result mul_assign_r(mpz_class& to, const mpz_class& x,
                    const mpz_class& y, Rounding_Dir dir);
Result neg_assign_r(mpz_class& to, const mpz_class& from, Rounding_Dir dir);
Result abs_assign_r(mpz_class& to, const mpz_class& from, Rounding_Dir dir);
Result floor_assign_r(mpz_class& to, const mpz_class& from, Rounding_Dir dir);
Result ceil_assign_r(mpz_class& to, const mpz_class& from, Rounding_Dir dir);
Result trunc_assign_r(mpz_class& to, const mpz_class& from, Rounding_Dir dir);
SW_SPEC
2
PPL-SPEC-000512
PPL-SPEC-000512
Exact unbounded integer product accumulation

For live mpz_class objects and resources as in 🔗 1. Exact named arithmetic on unbounded integer storage, add_mul_assign_r shall replace the entry value z by z + ab and sub_mul_assign_r shall replace it by z − ab, where a and b are the entry source values. Both operations shall return V_EQ for every valid rounding request. Sources may alias each other or the accumulator, including all three arguments sharing one object. Every occurrence in the formula shall use its entry value. Distinct source objects shall remain unchanged. Resource, synchronization, range and initialization conditions shall follow 🔗 1. Exact named arithmetic on unbounded integer storage.

An accumulator alias changes which entry values must be retained; the fused assignment remains exact regardless of coefficient configuration.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ
Test, Analysis, Inspection

Use independent literal results for all sign combinations, zero factors, very large products, separate operands and each accumulator/source alias, including all-three aliasing. Check all eight result requests and unchanged distinct sources.

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

CPP
Public

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

Result add_mul_assign_r(mpz_class& to, const mpz_class& x,
                        const mpz_class& y, Rounding_Dir dir);
Result sub_mul_assign_r(mpz_class& to, const mpz_class& x,
                        const mpz_class& y, Rounding_Dir dir);
SW_SPEC
3
PPL-SPEC-000513
Directed unbounded integer division and explicit delegated convention

For the mpz_class objects and prerequisites in 🔗 1. Exact named arithmetic on unbounded integer storage, the divisor b shall be nonzero. Let q = a ⁄ b denote the exact rational quotient. div_assign_r with ROUND_DOWN shall assign ⌊q⌋ and return V_GE; with ROUND_UP it shall assign ⌈q⌉ and return V_LE. With ROUND_STRICT_RELATION, a directed request shall instead return V_EQ when q is integral, otherwise V_GT for downward rounding or V_LT for upward rounding.

ROUND_IGNORE shall use the ceiling convention and return a relation containing q ≤ to. A strict delegated request shall identify equality or strict inequality. ROUND_NOT_NEEDED shall require b to divide a exactly, assign the exact integer quotient and return a relation admitting equality; with ROUND_STRICT_RELATION it shall return V_EQ. The exactness decision shall use entry operands even when the output aliases either source. Other alias, preservation, resource, initialization and hardware independence conditions shall follow 🔗 1. Exact named arithmetic on unbounded integer storage.

Integer storage requires an explicit floor, ceiling or delegated convention for a nonintegral quotient. Entry-operand exactness prevents an aliased write from changing the reported relation.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ
Test, Analysis, Inspection

Use an independent integer long-division oracle for all source signs, exact and inexact division, zero dividends and large magnitudes. Check all valid admitted requests, relation strictness, source/destination aliases, shared operands, reconstruction inequalities and source preservation.

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

CPP
Public

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

Result div_assign_r(mpz_class& to, const mpz_class& x,
                    const mpz_class& y, Rounding_Dir dir);
SW_SPEC
4
PPL-SPEC-000514
Exact truncated unbounded integer quotient and remainder

For the mpz_class objects and prerequisites in 🔗 1. Exact named arithmetic on unbounded integer storage, with nonzero divisor b, idiv_assign_r shall assign n = trunc(a ⁄ b) toward zero and rem_assign_r shall assign r = a − nb exactly. They shall satisfy |r| < |b|; a nonzero r shall have the dividend's sign. All valid rounding requests, including strict and exactness requests, shall return V_EQ and shall not change these conventions. No divisibility precondition shall be imposed by ROUND_NOT_NEEDED because the specified truncated quotient and remainder are themselves exact integers.

Each output may alias either source, the sources may alias each other, and all entry values shall retain their formula meaning. Distinct source objects shall remain unchanged. Resource, range, synchronization and initialization independence shall follow 🔗 1. Exact named arithmetic on unbounded integer storage.

Truncated quotient and remainder differ from directed rational division and together provide an exact dividend reconstruction for negative as well as positive operands.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ
Test, Analysis, Inspection

Independently derive quotient and remainder by integer long division. Check all sign combinations, zero, unit divisors, exact and inexact division and very large operands, reconstruction, strict magnitude and sign rules, all eight requests and aliases.

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

CPP
Public

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

Result idiv_assign_r(mpz_class& to, const mpz_class& x,
                     const mpz_class& y, Rounding_Dir dir);
Result rem_assign_r(mpz_class& to, const mpz_class& x,
                    const mpz_class& y, Rounding_Dir dir);
SW_SPEC
5
PPL-SPEC-000515
Unbounded integer arithmetic with powers of two

For mpz_class objects and prerequisites in 🔗 1. Exact named arithmetic on unbounded integer storage, let e be an unsigned exponent and m = 2e. Resources shall suffice for the requested power and output; there shall be no native shift-width precondition on e. add_2exp_assign_r, sub_2exp_assign_r and mul_2exp_assign_r shall assign exactly a + m, a − m and am, respectively, and return V_EQ for every valid rounding request.

div_2exp_assign_r shall round a ⁄ m downward or upward with the same directed value and relation rules as 🔗 3. Directed unbounded integer division and explicit delegated convention. ROUND_IGNORE shall truncate toward zero and return a relation admitting the actual comparison; a strict delegated request shall distinguish equality and strict inequality. ROUND_NOT_NEEDED shall require m to divide a, assign the exact quotient and return a relation admitting equality; a strict exactness request shall return V_EQ. This delegated truncation convention shall apply to power-of-two division independently of the ceiling convention for general div_assign_r.

Source/destination aliases, source preservation and other prerequisites shall follow 🔗 1. Exact named arithmetic on unbounded integer storage. Shared scratch-integer pools used to form an additive power shall be serialized in a build without thread-safe support; thread-safe configurations shall use calling-thread pools. No FPU setup, initialized library owner or coefficient-constant stage shall be needed.

Unbounded integer shifts must not inherit a native coefficient width limit, while division still needs an explicit rounding convention and exactness precondition.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ
Test, Analysis, Inspection

Exercise exponent zero, native-width boundaries and exponents above every bounded coefficient width with literal or independently derived integer powers. Check all signs, exact/inexact division, strict and delegated outcomes, aliases, source preservation and exactness requests when divisible.

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

CPP
Public

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

Result add_2exp_assign_r(mpz_class& to, const mpz_class& from,
                         unsigned exp, Rounding_Dir dir);
Result sub_2exp_assign_r(mpz_class& to, const mpz_class& from,
                         unsigned exp, Rounding_Dir dir);
Result mul_2exp_assign_r(mpz_class& to, const mpz_class& from,
                         unsigned exp, Rounding_Dir dir);
Result div_2exp_assign_r(mpz_class& to, const mpz_class& from,
                         unsigned exp, Rounding_Dir dir);
SW_SPEC
6
PPL-SPEC-000516
PPL-SPEC-000516
Exact centered and nonnegative unbounded integer residues

For mpz_class objects, exponent e and modulus m = 2e as in 🔗 5. Unbounded integer arithmetic with powers of two, umod_2exp_assign_r shall assign the unique integer residue u ∈ [0, m) congruent to the source a modulo m. For e > 0, smod_2exp_assign_r shall assign the unique congruent integer s ∈ [ − m ⁄ 2, m ⁄ 2). For e = 0, both operations shall assign zero. At a positive half-modulus tie, the centered operation shall select the negative half-modulus.

Both operations shall be exact and return V_EQ for every valid rounding request, including strict and exactness requests, without a divisibility precondition. Output/source aliases shall be permitted and distinct sources shall remain unchanged. Range, resources, synchronization, initialization and hardware independence shall follow 🔗 1. Exact named arithmetic on unbounded integer storage. The exponent shall not be limited by a native shift width or the configured coefficient range.

Exact modular reduction needs explicit interval and half-modulus tie conventions, including the degenerate modulus one.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ
Test, Analysis, Inspection

Check positive and negative inputs, zero, exact multiples, both half-modulus boundaries and their neighbors, exponent zero and very large powers. Derive independent quotient/remainder witnesses, prove congruence and interval bounds, and test all eight requests and aliases.

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

CPP
Public

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

Result smod_2exp_assign_r(mpz_class& to, const mpz_class& from,
                          unsigned exp, Rounding_Dir dir);
Result umod_2exp_assign_r(mpz_class& to, const mpz_class& from,
                          unsigned exp, Rounding_Dir dir);