Parma Polyhedra Library requirements
C++ checked scalar named functions and result policies

C++ checked scalar named functions and result policies

1. Checked named unary functions and function policy
UID: PPL-SPEC-000907
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

Let N be Checked_Number<T, Policy> for a native integer type, mpz_class, mpq_class or a configured supported native floating format. For finite admitted entry values, floor_assign, ceil_assign, trunc_assign, neg_assign and abs_assign shall apply their corresponding _r numerical operation with Policy::ROUND_DEFAULT_FUNCTION. The one-argument form shall use the destination's own entry value; the two-argument form shall use the source's entry value and may have identical source and destination storage.

Each completed numerical operation shall deliver its Result exactly once to Policy::handle_result. The functions shall return void. No constructor or operator rounding default, implicit scalar conversion or extra conversion-handler decision shall be required. A handler exception shall propagate; the destination shall remain live and reusable, without requiring preservation of its previous payload. A distinct source shall remain unchanged.

Numerical values, result relations/classes, finite-range outcomes and operation-specific admitted directions shall follow 🔗 1. Native integer floor, ceiling and truncation identity, 🔗 2. Native integer negation and absolute value, 🔗 1. Exact named arithmetic on unbounded integer storage, 🔗 4. Rational sign assignments and integral-valued rounding operations, 🔗 1. Finite native floating-point floor, ceiling and truncation and 🔗 2. Exact finite native floating-point negation and absolute value, for their respective scalar families and operations. In particular, a floor/ceiling/truncation status shall describe the specified transformed result rather than assert that the original nonintegral source was unchanged.

Lifetimes, synchronization, resources, admitted numerical policies and required backend/hardware setup shall follow the underlying operation. No coefficient-constant initialization shall be required by these wrappers. An unsupported accepted result shall not promise a represented numerical payload; such storage shall be validly reassigned before numerical use.

RATIONALE:

Named transformations select the function policy separately from the policy used by arithmetic operators or construction.

INTERFACE:

Public header: <ppl.hh>; function templates in Parma_Polyhedra_Library for the admitted T and Policy:

template <typename T, typename Policy>
void floor_assign(Checked_Number<T, Policy>& x);

template <typename T, typename Policy>
void ceil_assign(Checked_Number<T, Policy>& x);

template <typename T, typename Policy>
void trunc_assign(Checked_Number<T, Policy>& x);

template <typename T, typename Policy>
void neg_assign(Checked_Number<T, Policy>& x);

template <typename T, typename Policy>
void abs_assign(Checked_Number<T, Policy>& x);

template <typename T, typename Policy>
void floor_assign(Checked_Number<T, Policy>& x,
                      const Checked_Number<T, Policy>& y);

template <typename T, typename Policy>
void ceil_assign(Checked_Number<T, Policy>& x,
                      const Checked_Number<T, Policy>& y);

template <typename T, typename Policy>
void trunc_assign(Checked_Number<T, Policy>& x,
                      const Checked_Number<T, Policy>& y);

template <typename T, typename Policy>
void neg_assign(Checked_Number<T, Policy>& x,
                      const Checked_Number<T, Policy>& y);

template <typename T, typename Policy>
void abs_assign(Checked_Number<T, Policy>& x,
                      const Checked_Number<T, Policy>& y);
VERIFICATION_CRITERIA:

Check every named transformation and arity with independent literal integer/fractional answers, finite signs and signed zero, same-source aliases and distinct source preservation. Use recording and throwing handlers and a policy that supplies only the function default. Require void return types, one callback, admitted range outcomes and live destination reuse after handler rejection.

SOURCE:

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/checkednamedfunctionsspec1.cc.

PPL-SPEC-000908
2. Checked named remainder and exact quotient
UID: PPL-SPEC-000908
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For the finite same-type, same-policy N scalar families in 🔗 1. Checked named unary functions and function policy, rem_assign(x, y, z) shall apply rem_assign_r(x, y, z, Policy::ROUND_DEFAULT_FUNCTION). exact_div_assign(x, y, z) shall apply division with ROUND_NOT_NEEDED independently of all policy rounding defaults. Each function shall return void and deliver the numerical Result exactly once to the destination policy's handler, after the operation. Exact division shall require a handler but no function, constructor or operator rounding default.

Division/remainder shall require a nonzero divisor. Remainder shall use the truncated-quotient convention and numerical outcome contract in 🔗 3. Exact native truncated quotient and remainder, 🔗 4. Exact truncated unbounded integer quotient and remainder, 🔗 5. Truncated rational quotient and signed rational remainder or 🔗 2. Exact truncating remainder of finite native floating values. Exact quotient admissibility and results shall follow the exactness request for 🔗 2. Directed native integer division and delegated truncation, 🔗 3. Directed unbounded integer division and explicit delegated convention, 🔗 3. Exact finite rational addition, subtraction, multiplication and division or 🔗 3. Finite native floating-point division by a nonzero value, respectively. For native-integer or mpz_class storage, exact division shall require mathematical divisibility. Bounded checked range outcomes shall retain 🔗 3. Coefficient remainder assignment and exact division and 🔗 4. Checked native arithmetic range outcomes; a handler-returning unsupported outcome shall not permit use of an unspecified payload.

The destination may be either source; every mathematical occurrence shall use its entry value. Distinct sources shall remain unchanged. The handler exception, surviving destination, object, resource, synchronization and backend/hardware conditions of 🔗 1. Checked named unary functions and function policy shall apply, including serialization of any shared rational remainder temporaries.

RATIONALE:

Exact quotient has a fixed exactness request, while remainder is a named function with a function rounding default; their policy requirements differ.

INTERFACE:

Public header: <ppl.hh>; function templates in Parma_Polyhedra_Library for the admitted T and Policy:

template <typename T, typename Policy>
void rem_assign(Checked_Number<T, Policy>& x, const Checked_Number<T, Policy>& y,
                const Checked_Number<T, Policy>& z);

template <typename T, typename Policy>
void exact_div_assign(Checked_Number<T, Policy>& x, const Checked_Number<T, Policy>& y,
                      const Checked_Number<T, Policy>& z);
VERIFICATION_CRITERIA:

Check zero and signed finite remainders and exactly divisible quotients across scalar families, nonzero all-source aliases and either source alias. Use a handler-only policy with no rounding defaults for exact division, a function-only policy for remainder, literal results/statuses, void return types and handler exceptions with reusable destinations. Preserve the independently specified checked range obligations.

SOURCE:

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/checkednamedfunctionsspec1.cc.

3. Checked integral divisor functions and Bezout outputs
UID: PPL-SPEC-000909
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For N = Checked_Number<T, Policy> with native integer or mpz_class storage, gcd_assign, lcm_assign and gcdext_assign shall invoke their corresponding _r operation using Policy::ROUND_DEFAULT_FUNCTION. The result shall be delivered exactly once to that policy's handler, after all numerical output updates, and the wrapper shall return void. No constructor or operator default, implicit conversion or separate output-policy handler call shall be required.

Native gcd/lcm and their checked finite-range outcomes shall follow 🔗 2. Native integer greatest common divisor and least common multiple; native Bezout output/intermediate representability and output/source separation shall follow 🔗 1. Bounded native integer Bezout assignment. Unbounded divisor and Bezout meanings shall follow 🔗 1. Exact unbounded integer greatest common divisor and least common multiple and 🔗 2. Exact unbounded integer Bezout coefficients. All outputs shall be live same-type, same-policy objects. In particular, Bezout outputs shall obey their pairwise separation and source-alias conditions, and no unique coefficient pair beyond the prescribed identity shall be required. Gcd/lcm aliases shall use source entry values.

A distinct source shall remain unchanged. Handler exceptions shall propagate, leaving surviving output objects live and reusable without a rollback promise. Numerical policies, admitted directions, resources, synchronization and initialization independence shall follow the named underlying operation.

RATIONALE:

One policy decision describes each multi-output numerical operation; it must not become one decision per output object.

INTERFACE:

Public header: <ppl.hh>; function templates in Parma_Polyhedra_Library for the admitted T and Policy:

template <typename T, typename Policy>
void gcd_assign(Checked_Number<T, Policy>& g, const Checked_Number<T, Policy>& a,
                const Checked_Number<T, Policy>& b);

template <typename T, typename Policy>
void lcm_assign(Checked_Number<T, Policy>& m, const Checked_Number<T, Policy>& a,
                const Checked_Number<T, Policy>& b);

template <typename T, typename Policy>
void gcdext_assign(Checked_Number<T, Policy>& g, Checked_Number<T, Policy>& s,
                   Checked_Number<T, Policy>& t, const Checked_Number<T, Policy>& a,
                   const Checked_Number<T, Policy>& b);
VERIFICATION_CRITERIA:

Check zero/equal/coprime/noncoprime integer sources with literal gcd/lcm results and an independent unbounded Bezout identity. Admit only valid bounded intermediate arithmetic. Exercise gcd/lcm destination aliases and separated Bezout outputs, function-only policy capabilities, exactly one handler call, void return types, exceptions and live-output reassignment.

SOURCE:

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/checkednamedfunctionsspec1.cc.

PPL-SPEC-000910
4. Checked named product accumulation
UID: PPL-SPEC-000910
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For the finite same-type, same-policy N scalar families in 🔗 1. Checked named unary functions and function policy, add_mul_assign(x, y, z) and sub_mul_assign(x, y, z) shall call their corresponding product- accumulation _r operation using Policy::ROUND_DEFAULT_FUNCTION. The complete returned numerical Result shall be delivered exactly once to the policy handler; the wrapper shall return void. There shall be no extra handler decision for a product intermediate, constructor default or operator default.

The mathematical entry-destination value, all source/destination alias patterns and numerical outcomes shall follow 🔗 1. Native integer accumulated products and intermediate overflow, 🔗 2. Exact unbounded integer product accumulation, 🔗 7. Exact rational product accumulation and subtraction or 🔗 1. Finite native floating addition of an accumulated product, 🔗 2. Finite native floating subtraction of an accumulated product and 🔗 3. Configured native accumulation precision and truthful result relations, for the selected scalar family. In particular, native integral intermediate failure and native floating fused/nonfused precision shall retain their stated contracts; these wrappers shall not promise a stronger single-step numerical algorithm.

Distinct sources shall remain unchanged. Handler exceptions and surviving destinations, lifetimes, supported directions, resources, synchronization and required native floating setup shall follow 🔗 1. Checked named unary functions and function policy and the numerical operation.

RATIONALE:

The wrapper reports the result already chosen by the numerical accumulation algorithm without introducing an additional intermediate policy decision.

INTERFACE:

Public header: <ppl.hh>; function templates in Parma_Polyhedra_Library for the admitted T and Policy:

template <typename T, typename Policy>
void add_mul_assign(Checked_Number<T, Policy>& x, const Checked_Number<T, Policy>& y,
                    const Checked_Number<T, Policy>& z);

template <typename T, typename Policy>
void sub_mul_assign(Checked_Number<T, Policy>& x, const Checked_Number<T, Policy>& y,
                    const Checked_Number<T, Policy>& z);
VERIFICATION_CRITERIA:

Use literal accumulated sum/difference answers, zero/product cancellation and each admitted source/destination alias. Record one function-policy result and check no constructor/operator default is needed. Check void return type, direction-sensitive finite answers, source preservation, one throwing handler and surviving destination reuse, using the existing numerical contracts for intermediate failures.

SOURCE:

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/checkednamedfunctionsspec1.cc.

PPL-SPEC-000911
5. Checked named scaling by powers of two
UID: PPL-SPEC-000911
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For the finite same-type, same-policy N scalar families in 🔗 1. Checked named unary functions and function policy, mul_2exp_assign(x, y, exp) and div_2exp_assign(x, y, exp) shall call the corresponding _r operation with Policy::ROUND_DEFAULT_FUNCTION and the supplied unsigned int exponent. The numerical Result shall be delivered exactly once to the handler after the operation; the wrapper shall return void and require no constructor or operator rounding default.

Exponent admission, exact multiplication and directed division meanings, range outcomes and represented precision shall follow 🔗 1. Native integer arithmetic with exact powers of two, 🔗 2. Directed native integer division by powers of two, 🔗 5. Unbounded integer arithmetic with powers of two, 🔗 6. Exact rational operations with powers of two and 🔗 2. Finite native multiplication and division by a power of two, for the respective scalar family. The exponent shall not be narrowed or interpreted as a signed exponent.

The destination may be the source, using its entry value. A distinct source shall remain unchanged. Handler exceptions, surviving destination reuse and the object/resource/synchronization/rounding/backend conditions of 🔗 1. Checked named unary functions and function policy and the underlying operation shall apply.

RATIONALE:

Named scaling preserves the exponent and function-policy choice while reusing the scalar family's directed numerical semantics.

INTERFACE:

Public header: <ppl.hh>; function templates in Parma_Polyhedra_Library for the admitted T and Policy:

template <typename T, typename Policy>
void mul_2exp_assign(Checked_Number<T, Policy>& x, const Checked_Number<T, Policy>& y,
                     unsigned int exp);

template <typename T, typename Policy>
void div_2exp_assign(Checked_Number<T, Policy>& x, const Checked_Number<T, Policy>& y,
                     unsigned int exp);
VERIFICATION_CRITERIA:

Check zero/nonzero exponents, multiplication and inexact integral division with literal power-of-two answers and status relations. Exercise source aliases, same-type source preservation, function-only policies, void return, one callback and handler rejection/reuse under admitted exponent/backend conditions.

SOURCE:

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/checkednamedfunctionsspec1.cc.

PPL-SPEC-000912
6. Checked named nonnegative square root
UID: PPL-SPEC-000912
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For the finite same-type, same-policy N scalar families in 🔗 1. Checked named unary functions and function policy, with a nonnegative source, sqrt_assign(x, y) shall call sqrt_assign_r using Policy::ROUND_DEFAULT_FUNCTION. It shall deliver the numerical Result exactly once to the handler and return void. No constructor or operator rounding default shall be required.

Native integral, unbounded integral, canonical rational and supported native floating roots shall follow 🔗 1. Directed native integer square-root assignment, 🔗 3. Directed unbounded integer square roots, 🔗 2. Finite rational square root at the selected irrational precision and 🔗 1. Directed and delegated square root of a finite native value, respectively. In particular, rational roots shall use the calling precision and its ownership/synchronization conditions in 🔗 3. Selection and ownership of irrational rational precision; the wrapper shall not select a different precision. Admitted exactness requests shall retain their underlying root prerequisites.

The destination may be the source, using its entry value. A distinct source shall remain unchanged. Handler exceptions, live destination reuse, object/resource/synchronization conditions and required backend/hardware setup shall follow 🔗 1. Checked named unary functions and function policy and the numerical root operation.

RATIONALE:

Square-root storage and exactness are selected by the numerical backend and precision; the named wrapper adds the function policy decision only.

INTERFACE:

Public header: <ppl.hh>; function templates in Parma_Polyhedra_Library for the admitted T and Policy:

template <typename T, typename Policy>
void sqrt_assign(Checked_Number<T, Policy>& x, const Checked_Number<T, Policy>& y);
VERIFICATION_CRITERIA:

Check zero, perfect squares and direction-sensitive nonperfect integral roots with independent literal root inequalities. Include a rational root at a controlled precision, source aliases, preserved source/precision, function-only policy capability, void return, one numerical callback and handler rejection followed by valid destination reuse.

SOURCE:

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/checkednamedfunctionsspec1.cc.