Parma Polyhedra Library requirements
C++ coordinate selections: Variables_Set
1. Public coordinate-index set and value lifecycle UID: PPL-SPEC-000021 STATUS: APPROVED COMPONENT: GEOMETRIC_DESCRIPTORS APPLICABILITY: IF_CPP VERIFICATION_METHODS: Test, Analysis, Inspection, Review LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

The public C++ interface shall expose Variables_Set as a public derivative of std::set<dimension_type>. Its stored value shall be a finite set of distinct indices enumerated in increasing numerical order. A coordinate-valid set shall contain only indices i < Variable : : max_space_dimension(). The empty set shall be coordinate-valid. A set shall select coordinates without imposing an ambient dimension on an object that consumes the selection.

The inherited C++20 std::set<dimension_type> interface shall remain available subject to the overloads actually declared by Variables_Set. Base-class constructors and assignment overloads shall not be implicitly added to the public derived interface. Construction from arbitrary iterator ranges shall be performed by default construction followed by inherited range insertion. Raw-index base operations may store any dimension_type value; they shall not validate coordinate admissibility. Before using the set as a coordinate selection or calling a member that requires coordinate validity, clients shall establish the validity of every stored index, for example using OK().

Implicit copy construction and copy assignment shall have the C++20 value and exception behavior of the std::set base. Successful copies shall contain exactly the source indices with independently owned nodes. Implicit moves shall transfer the value according to the standard base-container rules; moved-from objects shall remain valid with the state permitted by those rules. Destruction shall release owned nodes. A Variables_Set shall not be deleted through a pointer to its nonvirtual base destructor.

Operations on existing objects shall require live container objects. Callers shall obey the supported library/thread regime, serialize modifications of a shared instance and prevent unsynchronized modification while another call observes or copies it. No automatic invalid-lifetime or concurrent-use detection shall be required.

RATIONALE:

Coordinate selections need an ordered, duplicate-free representation with ordinary value ownership. Public inheritance exposes raw storage operations, so representable indices and valid coordinate indices are distinct contracts.

INTERFACE:

Public header: <ppl.hh>. Public type declaration:

namespace Parma_Polyhedra_Library {
  class Variables_Set : public std::set<dimension_type> {
    // Member declarations are given in the following contracts.
  };
}

The following contracts describe declared members and applicable inherited operations. Copy/move members and destruction are implicitly declared.

VERIFICATION_CRITERIA:

Compile an installed-public-header C++20 client using the type, base conversion, copy/move operations and declared members. Check independent copies, lvalue assignment, self-copy assignment and permitted reuse of moved-from objects. Inject copy-construction and copy-assignment allocation failures, verifying source preservation and the target-state guarantees of the standard base container. Inspect owned-node cleanup and synchronization preconditions.

SOURCE:

src/Variables_Set_defs.hh: public inheritance and implicit value members. tests/variablesset1.cc: value, mutation and allocation-failure cases.

PPL-SPEC-000022
2. Empty, singleton and inclusive-range construction UID: PPL-SPEC-000022 STATUS: APPROVED COMPONENT: GEOMETRIC_DESCRIPTORS APPLICABILITY: IF_CPP VERIFICATION_METHODS: Test, Analysis, Inspection, Review LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

Successful default construction shall create an empty Variables_Set. Successful construction from a valid Variable v shall create exactly {v.id()}. Successful construction from valid variables v and w shall create exactly {i ∣ v.id() ≤ i ≤ w.id()} when v.id() <= w.id() and the empty set otherwise. Both endpoints shall be included. No ambient dimension or additional indices shall be introduced.

Failure to allocate storage shall propagate the applicable C++ exception and release resources acquired for the incomplete object. Inputs shall remain unchanged. No successfully constructed destination shall be returned on failure.

RATIONALE:

Empty selections, individual coordinates and inclusive consecutive selections are the primitive construction forms used by coordinate operations.

INTERFACE:

Public constructor declarations:

Variables_Set();
explicit Variables_Set(Variable v);
Variables_Set(Variable v, Variable w);
VERIFICATION_CRITERIA:

Check empty, zero singleton, greatest valid singleton, equal endpoints, small inclusive intervals and reversed intervals, including a reversed interval whose first endpoint is the greatest valid index. Compare all stored indices with an independent sequence. Inject failures at each actual allocation in singleton and range construction; check input preservation and successful reconstruction. Do not attempt to allocate a set spanning the entire index range.

SOURCE:

src/Variables_Set_inlines.hh: empty and singleton constructors. src/Variables_Set.cc: inclusive-range constructor. tests/variablesset1.cc: construction and failed-construction cases.

PPL-SPEC-000023
3. Index insertion and inherited ordered-set operations UID: PPL-SPEC-000023 STATUS: APPROVED COMPONENT: GEOMETRIC_DESCRIPTORS APPLICABILITY: IF_CPP VERIFICATION_METHODS: Test, Analysis, Inspection, Review LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

For a live Variables_Set, successful insert(v) with a valid Variable shall add exactly v.id(). Inserting an already present index shall not create a duplicate. The declared overload shall coexist with the inherited C++20 std::set<dimension_type> insertion overloads. Raw insertion shall store the supplied index value without constructing or validating a Variable.

Inherited insertion, emplacement, extraction, merging, erasure, clearing, lookup, bounds, comparison and iteration shall have the C++20 semantics of the base container. Forward traversal shall enumerate each stored index once in increasing order; reverse traversal shall enumerate them in decreasing order. Insertion shall preserve existing element references and iterators. Erasure shall invalidate references and iterators to erased elements according to the base-container rules. Callers shall satisfy the standard preconditions for iterator ranges, hints, node ownership and allocator compatibility. A node's key may be changed only while detached, under the inherited node-handle rules. Coordinate use of inserted or changed keys shall additionally require the validity conditions of 🔗 1. Public coordinate-index set and value lifecycle.

Failed single-element insert allocation shall propagate std::bad_alloc without changing the set. Range insertion and other inherited operations shall have their standard operation-specific exception guarantees; no transactional rollback of an entire partially completed range insertion shall be implied.

RATIONALE:

Standard container interoperability supports coordinate-selection algorithms without silently changing raw indices into another mathematical object.

INTERFACE:

Declared overload and inherited insertion exposure:

void insert(Variable v);
using std::set<dimension_type>::insert;

Other inherited operations retain their standard signatures. The using declaration shown expresses the exposed base overload set; the implementation may name that base using a private alias.

VERIFICATION_CRITERIA:

Compare insertion and mutation histories with an independent sorted sequence. Exercise Variable and raw-index insertion, duplicate insertion, hints, iterator ranges, initializer lists, emplacement, node extraction/reinsertion and merge. Check traversal in both directions, lookup and bounds at present/absent indices, iterator/reference stability, erasure and clear. Inject failed new-node insertion and check the complete unchanged set before retry. Check raw invalid indices through storage operations and OK(), without using them as coordinates.

SOURCE:

src/Variables_Set_defs.hh: public base operations and insertion overloads. src/Variables_Set_inlines.hh: insertion of a Variable index. tests/variablesset1.cc: ordered-container histories and failed insertion.

PPL-SPEC-000024
4. Coordinate-set dimension and maximum dimension UID: PPL-SPEC-000024 STATUS: APPROVED COMPONENT: GEOMETRIC_DESCRIPTORS APPLICABILITY: IF_CPP VERIFICATION_METHODS: Test, Analysis, Inspection, Review LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

Variables_Set::max_space_dimension() shall return the same value as Variable::max_space_dimension(). For a coordinate-valid set S, space_dimension() shall return zero when S = ⌀ and 1 + maxS otherwise. Both queries shall leave the set unchanged.

The returned dimension shall describe the smallest space enclosing the selected coordinates. It shall not count the selected coordinates or prescribe the ambient dimension of a consuming object. space_dimension() shall require a coordinate-valid set under 🔗 1. Public coordinate-index set and value lifecycle; raw storage of an invalid index shall not establish a supported dimension query.

RATIONALE:

A sparse selection may contain few coordinates while requiring a much larger enclosing space. An empty selection has enclosing dimension zero.

INTERFACE:

Public declarations:

static dimension_type max_space_dimension();
dimension_type space_dimension() const;
VERIFICATION_CRITERIA:

Check empty sets, index zero, sparse sets, insertion and removal of the greatest stored index, clear, and a singleton at the greatest valid index. Independently compare against zero or one plus the largest index and verify unchanged contents. Check equality of the Variable and Variables_Set maximum dimension queries.

SOURCE:

src/Variables_Set_inlines.hh: dimension queries. tests/variablesset1.cc: sparse and boundary dimension cases.

PPL-SPEC-000025
5. Inherited set swap and element ownership UID: PPL-SPEC-000025 STATUS: APPROVED COMPONENT: GEOMETRIC_DESCRIPTORS APPLICABILITY: IF_CPP VERIFICATION_METHODS: Test, Analysis, Inspection, Review LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

For live Variables_Set objects satisfying the inherited allocator compatibility preconditions, inherited member swap shall exchange their complete stored sets with the C++20 base-container semantics. A successful self-swap shall preserve the value. References and iterators to stored elements shall remain associated with those elements in the receiving container, subject to the standard exception for past-the-end iterators. Swap shall not require coordinate validity of raw stored indices.

RATIONALE:

Ownership exchange must preserve coordinate indices and existing element references without introducing a hidden copy of a selection.

INTERFACE:

Inherited member callable form, where base_type denotes std::set<dimension_type>:

void swap(base_type& other);

The actual inherited exception specification follows the C++20 base container.

VERIFICATION_CRITERIA:

Swap distinct empty/nonempty and differently sized sets. Check exact contents, reference and iterator association, dimensions for valid sets and self-swap. Arm allocation failure across member swap and verify it completes without allocating under the selected standard allocator configuration.

SOURCE:

src/Variables_Set_defs.hh: inherited std::set member swap. tests/variablesset1.cc: ownership, reference stability and allocation-free swap.

PPL-SPEC-000026
6. Coordinate-set diagnostic output and formatter prerequisites UID: PPL-SPEC-000026 STATUS: APPROVED COMPONENT: GEOMETRIC_DESCRIPTORS APPLICABILITY: IF_CPP VERIFICATION_METHODS: Test, Analysis, Inspection, Review LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

Diagnostic output shall observe a coordinate-valid set without modifying its indices. With compatible ordinary character formatting and successful output, operator<< shall write "{", each selected Variable in increasing index order preceded by one space, a comma after every Variable except the last, and the final text " }". Thus an empty set shall write "{ }". Variable text shall be produced by the active Variable formatter at each write. The operator shall return the supplied stream reference. It shall not add a newline or request a flush. print() shall perform this output to std::cerr.

Calls shall require the library/thread initialization protocol of 🔗 1. Initialization owners and automatic C++ initialization and 🔗 3. Thread initialization, default state and finalization to have established a valid active Variable formatter under 🔗 7. Active Variable formatter and initialized thread state. Formatter dispatch shall follow 🔗 8. Variable names, formatter dispatch and output failures. Clients shall synchronize formatter changes, shared streams and shared-set access under the supported thread regime. The formatter shall not mutate the printed set during output. Stream formatting and error reporting shall follow ordinary C++ insertion semantics. Formatter exceptions and stream exceptions shall propagate; ordinary nonthrowing stream failures shall remain observable through the stream state. Partial output may remain after failure, while the set shall remain unchanged.

RATIONALE:

Diagnostic text is a formatted view of coordinates and depends on the same initialization and formatter state as individual Variable output.

INTERFACE:

Public declarations:

std::ostream& IO_Operators::operator<<(std::ostream& s,
                                     const Variables_Set& vs);
void print() const;
VERIFICATION_CRITERIA:

Check literal empty and sparse output, ordering, return-reference identity, absence of newline/flush, custom formatters and forwarding through print(). Check pending width/fill behavior using the actual sequence of character and text insertions. Exercise nonthrowing and throwing stream failures and a throwing formatter, verifying unchanged indices and restoration of test-owned formatter and stream state. Review initialization and thread prerequisites.

SOURCE:

src/Variables_Set_defs.hh and src/Variables_Set.cc: output operator. src/globals_defs.hh: generated print forwarding definition. tests/variablesset1.cc: output, formatter and stream-failure cases.

PPL-SPEC-000027
7. Reloadable coordinate-set text export UID: PPL-SPEC-000027 STATUS: APPROVED COMPONENT: GEOMETRIC_DESCRIPTORS APPLICABILITY: IF_CPP VERIFICATION_METHODS: Test, Analysis, Inspection, Review LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

For a live Variables_Set and a stream with decimal integer formatting, zero pending field width and the classic C locale, successful ascii_dump(s) shall write a newline, "variables( ", the number of stored indices, " )", a newline, and then each raw stored index in increasing order followed by one space. An empty set shall have no index payload. The operation shall append no additional characters or explicit flush after this sequence. It shall leave the set unchanged and shall not invoke the Variable formatter and shall also permit raw indices that fail coordinate validity. The no-argument overload shall write the same representation to std::cerr under those formatting conditions.

For coordinate-valid input and compatible producer/consumer formatting, successful loading of this representation under 🔗 8. Coordinate-set text loading and partial failure state shall preserve the selected indices and enclosing dimension. The format shall not promise compatibility with every library version or with arbitrary incompatible locale, numeric base or formatting settings. Stream failure shall follow C++ stream state and exception-mask semantics; partial output may remain and the source set shall remain unchanged.

RATIONALE:

Machine-oriented coordinate indices must be reloadable independently of custom human-readable coordinate names.

INTERFACE:

Public declarations:

void ascii_dump(std::ostream& s) const;
void ascii_dump() const;
VERIFICATION_CRITERIA:

Compare exact empty and sparse dumps against independently written literals. Round-trip valid sets including the greatest valid index and compare all indices and dimensions. Verify dump ignores a throwing Variable formatter, forwards the no-argument overload to std::cerr and preserves the source after nonthrowing or throwing stream failure.

SOURCE:

src/Variables_Set.cc: stream dump implementation. src/globals_defs.hh: generated no-argument dump forwarding definition. tests/variablesset1.cc: literal frames, reload and dump-failure cases.

PPL-SPEC-000028
8. Coordinate-set text loading and partial failure state UID: PPL-SPEC-000028 STATUS: APPROVED COMPONENT: GEOMETRIC_DESCRIPTORS APPLICABILITY: IF_CPP VERIFICATION_METHODS: Test, Analysis, Inspection, Review LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

ascii_load(s) shall first clear the destination's existing indices. With whitespace-skipping extraction enabled, decimal integer conversion and the classic C locale, it shall accept an opening token "variables(", a nonnegative dimension_type count, a closing token ")" and exactly that count of nonnegative indices below Variable::max_space_dimension(). On successful loading it shall return true and contain exactly the set of extracted indices. Duplicate payload indices shall be collapsed and payload order need not be sorted. Tokens following the declared payload shall remain available to the caller. Loading shall not invoke the Variable formatter.

Missing, wrong, unextractable or out-of-range required fields shall return false unless the stream's exception mask causes an exception. A false result shall leave the destination empty if the header failed, or containing exactly the successfully inserted prefix of payload indices if a payload extraction failed. Allocation or stream exceptions shall propagate; the old value shall not be restored, and successfully inserted prefix indices may remain. The destination shall remain a live base-container object available for inspection, clear, reassignment and destruction. No unchanged-state guarantee shall be implied.

A true result shall certify a coordinate-valid set with exactly the loaded indices and their enclosing dimension as checked by 🔗 10. Coordinate-validity checking of raw indices.

RATIONALE:

A nontransactional parser must make replacement and valid-prefix state explicit.

INTERFACE:

Public declaration:

bool ascii_load(std::istream& s);
VERIFICATION_CRITERIA:

Load independent empty, sparse, unsorted and duplicate-containing literals into nonempty receivers. Check allowed whitespace, exact payload framing and an unconsumed trailing marker. Exercise every bounded truncation, wrong markers, nonnumeric and overflowing counts/indices; check the exact retained prefix before reset. Reject signed-negative counts and out-of-range coordinate indices. Inject allocation failure at payload insertion and throwing stream extraction, checking live prefix state and successful later clear/reload.

SOURCE:

src/Variables_Set.cc: ascii_load clear, token parsing and index insertion. tests/variablesset1.cc: valid, malformed and exceptional loading cases.

PPL-SPEC-000029
9. Coordinate-set memory estimates UID: PPL-SPEC-000029 STATUS: APPROVED COMPONENT: GEOMETRIC_DESCRIPTORS APPLICABILITY: IF_CPP VERIFICATION_METHODS: Test, Analysis, Inspection, Review LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

For a live Variables_Set, external_memory_in_bytes() shall return the implementation's per-node estimate multiplied by the number of stored indices. Its per-node estimate shall account for one dimension index, three pointers and one stored tree-color enumeration. It shall be independent of the numerical values of the indices, and shall be zero for an empty set. Where the reported arithmetic is representable in memory_size_type, total_memory_in_bytes() shall equal sizeof(Variables_Set) plus that external estimate. Both queries shall leave the set unchanged and shall also permit raw indices outside the coordinate-valid range.

These results shall be storage estimates under the stated node-layout model. They shall not certify allocator bookkeeping, alignment padding, actual standard-library node layout or process resident memory.

RATIONALE:

Stable estimates support relative resource observations while exposing the layout assumptions instead of presenting them as exact allocator measurements.

INTERFACE:

Public declarations:

memory_size_type external_memory_in_bytes() const;
memory_size_type total_memory_in_bytes() const;
VERIFICATION_CRITERIA:

Check empty, singleton and larger sets for zero external estimate, positive linear growth and the total/external identity. Compare equal-sized sets with different indices and verify changes through duplicate insertion, erasure, clear, copy and swap. Inspect the per-node arithmetic against its documented model; do not equate the estimate with allocator or resident-memory counters.

SOURCE:

src/Variables_Set_inlines.hh: per-node memory estimate and total query. tests/variablesset1.cc: memory estimates across value histories.

10. Coordinate-validity checking of raw indices UID: PPL-SPEC-000030 STATUS: APPROVED COMPONENT: GEOMETRIC_DESCRIPTORS APPLICABILITY: IF_CPP VERIFICATION_METHODS: Test, Analysis, Inspection, Review LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

For any live Variables_Set satisfying its base-container invariants, OK() shall return true exactly when every stored raw index is strictly less than Variable::max_space_dimension(). It shall return true for an empty set. An index equal to the maximum dimension, one greater than that limit, or not_a_dimension() shall make the result false. Invalid raw coordinate indices shall be a defined check outcome and shall not cause std::length_error. The check shall leave every stored index unchanged.

RATIONALE:

Raw inherited operations and syntactic loading can introduce indices that do not denote Variables. A boolean invariant check must inspect that state safely before coordinate-semantic operations are attempted.

INTERFACE:

Public declaration:

bool OK() const;
VERIFICATION_CRITERIA:

Check empty and sparse valid sets, the greatest valid index, and each distinct invalid boundary index alone and mixed with valid indices. Insert invalid values through raw base operations and through text loading. Require false without an exception and compare complete contents before and after each check. Verify clear or removal restores validity.

SOURCE:

src/Variables_Set.cc: raw-index validity check. tests/variablesset1.cc: valid/invalid boundary checking and restoration.