Parma Polyhedra Library requirements
Internal dense and sparse coefficient-row storage
1. Internal coefficient-row values and valid use PPL-SPEC-000281

Dense_Row and Sparse_Row shall represent a finite coefficient vector (a0, …, an − 1) with independently declared logical size n. Size zero shall be valid. A row shall impose no mandatory constant or hidden coordinate. The affine expression interpretation shall instead belong to 🔗 1. Affine value, numerical prerequisites and shared zero. Dense storage shall retain every logical position; sparse storage shall permit implicit and explicitly stored zeroes with the same coefficient value, while exposing the stored-position distinction.

Operations shall require live valid rows, admitted sizes and indices, active library initialization where coefficient constants or scratch storage are used, and synchronization under 🔗 3. Thread initialization, default state and finalization. Successful arithmetic shall require all evaluated coefficient steps/results to be representable in the selected profile. Allocation/numerical exceptions may propagate. Failed construction shall release resources owned by the incomplete row; unchanged sources shall survive failure. A modified target shall remain destructible, without a universal rollback guarantee.

PPL-SPEC-000282
2. Dense zero construction, size and reserved capacity PPL-SPEC-000282

Default construction shall create a zero-sized row. Sized construction shall create exactly the requested number of zero coefficients. Construction with explicit capacity shall require size <= capacity <= max_size() and reserve that capacity without making additional logical coefficients. The size-only form shall initially reserve its requested size. max_size() shall return numeric_limits<size_t>::max() / sizeof(Coefficient); resource availability shall remain a separate condition from this reported limit.

PPL-SPEC-000283
3. Sparse zero construction and storage limits PPL-SPEC-000283

Sparse construction shall retain the requested logical size, initially with no stored entries. The compatibility capacity argument shall be ignored. size() shall report logical size and num_stored_elements() shall count stored positions, including explicitly stored zeroes. max_size() shall return CO_Tree::max_size(), the supported number of stored elements; logical extent and admissible dimension keys shall remain distinct from that storage count. The type shall opt out of the C++20 sized-range customization so that standard range distances count iterated entries, including explicitly stored zeroes, rather than the logical extent.

PPL-SPEC-000284
4. Owning row copies, sized copies and storage conversion PPL-SPEC-000284

Ordinary row copies shall preserve size and every coefficient, own independent storage and survive source mutation/destruction. Dense copies shall retain source capacity unless supplied another admitted capacity. A copy with specified size/capacity shall retain the common source prefix, discard removed positions and zero-extend added positions. Explicit dense capacity shall be at least result size; sparse compatibility capacity shall be ignored. Cross-storage construction shall preserve that same complete coefficient vector. Dense-to-sparse construction may omit zero entries; sparse-to-dense construction shall materialize implicit zeroes. Const-rvalue forms selecting copy constructors shall retain the source value.

PPL-SPEC-000285
5. Row assignment, whole-row swaps and destruction PPL-SPEC-000285

Successful copy assignment shall replace the complete vector, return the target, preserve its distinct source and admit self-assignment. Cross-storage assignment shall preserve values while retaining the target's row type. Copies shall remain independently mutable. Whole-row swaps shall exchange full vectors, including their sizes and owned storage; mixed dense/sparse swaps shall convert storage while exchanging vector values. Self-swaps shall retain value. iter_swap for two vector positions shall swap the owning dense rows. Destruction shall release owned coefficient and backing storage.

Replacement allocation failure shall preserve the source; target-state guarantees shall follow 🔗 1. Internal coefficient-row values and valid use.

For trivially destructible coefficient types, Dense_Row transfer construction from a non-const rvalue shall acquire the complete owned storage without allocating or throwing and leave its source empty and reusable. References to dense elements shall follow their storage; distinct-owner transfers shall invalidate element iterators.

For other coefficient types, dense construction from rvalues shall retain independent, source-preserving copy behavior. Dense assignment from rvalues shall retain independent, source-preserving copy behavior for every coefficient type; self-assignment shall preserve the value.

Sparse_Row construction and assignment from rvalues shall retain independent, source-preserving copy behavior, including logical extent and explicit stored zeroes. Its copy declarations shall prevent new backing-tree transfer operations from implicitly changing the row-level interface.

PPL-SPEC-000286
6. Dense resizing and reuse of reserved storage PPL-SPEC-000286

Resizing shall retain the common prefix, discard removed coefficients and initialize newly introduced coefficients to zero. Removed values shall not reappear after regrowth. resize(n) shall retain current capacity when sufficient. Otherwise, with prior capacity c and maximum capacity M, it shall grow capacity to max(n, min(M, c + floor(c/2))), evaluating the sum without overflow. Thus construction from zero capacity and large one-shot expansions shall allocate the requested extent; repeated small growth shall reserve fewer than half as many spare slots as the requested extent at each reallocation. Retaining capacity after shrinking or an explicit reservation shall remain permitted. resize(n,c) shall require admitted n <= c and set capacity exactly c; zero capacity shall release backing storage. shrink(n) shall require n <= size() and retain capacity. expand_within_capacity(n) shall require size() <= n <= capacity and add zeroes without replacing backing storage. Position changes/reallocation shall invalidate affected borrowed references and iterators.

PPL-SPEC-000287
7. Sparse resizing and removal of trailing stored positions PPL-SPEC-000287

Sparse resizing shall retain the common coefficient prefix, erase stored entries outside a shortened extent and zero-extend an enlarged extent without materializing the new zeroes. shrink(n) shall require n <= size(); expand_within_capacity(n) shall require size() <= n and need no reserved-capacity argument. Size zero shall erase all stored entries. Changing logical extent shall not change values at retained coordinates.

PPL-SPEC-000288
8. Indexed coefficient access and borrowed values PPL-SPEC-000288

Indexed access and get(i) shall require i < size() and return the coefficient at that position. Const access shall not materialize missing sparse entries. Mutable dense access shall borrow the owned coefficient; mutable sparse access shall retain an existing stored coefficient or insert a stored zero and return its mutable reference. Mutating that reference shall update only its indexed value. A reference to an absent sparse value shall borrow the library zero constant and require its lifetime.

Borrowed references shall not outlive their owners or the documented storage invalidation of an operation. Sparse insertion/removal or reorganization may invalidate previously borrowed entries and iterators. Values must be copied before an operation that can invalidate their reference, except where entry argument capture is explicitly specified.

Member overloads that return references, iterators or nonowning views into the owner shall require an lvalue owner. Matching rvalue calls that would produce such borrows shall be rejected during overload resolution. Temporary iterator and row-view values shall remain usable while their backing owner remains alive. Const coefficient queries whose declared result type is an independent value shall also remain admitted for temporary owners.

PPL-SPEC-000289
9. Dense row iterator positions and bidirectional traversal PPL-SPEC-000289

Dense iterators shall enumerate every index in increasing order, including zero-valued positions; end() shall have index size(). Valid dereference shall borrow the corresponding coefficient; mutable dereference shall permit updating it. Increment/decrement shall require valid next/previous positions. Prefix shall return the advanced iterator by reference; postfix shall return the entry-position copy. Const conversion and copied/assigned iterator positions shall preserve owner and index. Equality shall compare owner and index. Defaults shall admit copying, assignment, destruction and OK() before assignment to a live position. Iterators shall not outlive their row.

Member overloads that return references, iterators or nonowning views into the owner shall require an lvalue owner. Matching rvalue calls that would produce such borrows shall be rejected during overload resolution. Temporary iterator and row-view values shall remain usable while their backing owner remains alive. Direct const-iterator construction shall also reject a temporary row owner.

PPL-SPEC-000290
10. Sparse stored-entry traversal and cached end references PPL-SPEC-000290

stored_entries() shall return a borrowed view bound to a live lvalue row. The view shall visit exactly the stored positions, including explicit zeroes, and expose their count through constant-time size() and empty() independently of logical width. Mutable and read-only views shall be sized bidirectional ranges; mutable cursors shall permit value updates without changing stored keys or count. A const view object shall retain its bound row's mutability. Temporary row owners shall be rejected.

The view shall store the row binding without allocating or owning storage. Copies and queries shall follow the current row object through valid mutations and swaps; iterators already obtained retain the row's existing invalidation conditions. Iterators shall not depend on the view object's lifetime. The view need not have an unbound default state.

Sparse iterators shall enumerate exactly stored entries in increasing index order, including explicitly stored zeroes. Implicit zeroes shall not appear. Dereference and index() shall report the stored coefficient and its key; mutable dereference shall permit replacement without changing the key. Bidirectional traversal and const conversion shall follow CO_Tree iterator contracts. A referenced end()/cend() sentinel shall belong to its live row and remain updated by mutations, while copied iterator values shall obey operation-specific invalidation. Swapping rows shall not transfer ownership of a cached reference to an end sentinel. Cached end references shall be available only from lvalue rows; mutable and const temporary owners shall be rejected. No sentinel shall be dereferenced.

Member overloads that return references, iterators or nonowning views into the owner shall require an lvalue owner. Matching rvalue calls that would produce such borrows shall be rejected during overload resolution. Temporary iterator and row-view values shall remain usable while their backing owner remains alive.

11. Indexed row search, lower bounds and hint independence PPL-SPEC-000291

find(i) shall require an in-size index. Dense rows shall return its position even when zero; sparse rows shall return the stored entry if present and end() otherwise. lower_bound(i) shall admit i <= size() and return the first dense/stored sparse position with index at least i, or end() if none. A hint shall be a valid position or end sentinel for the same unchanged row and shall not affect the result. Const and mutable forms shall agree; searches shall not materialize sparse zeroes.

Member overloads that return references, iterators or nonowning views into the owner shall require an lvalue owner. Matching rvalue calls that would produce such borrows shall be rejected during overload resolution. Temporary iterator and row-view values shall remain usable while their backing owner remains alive.

PPL-SPEC-000292
12. Insertion and replacement with argument-value independence PPL-SPEC-000292

Insertion shall require i < size() and return the indexed position. An explicit value shall replace that coefficient using its entry value, including when borrowed from another entry of the same row. No duplicate key shall be created. A value-free insertion shall retain an existing value, or create a stored zero in a missing sparse position. Dense value-free insertion shall return the existing logical slot unchanged. Hints shall have the validity and result-independence specified by 🔗 11. Indexed row search, lower bounds and hint independence. Sparse insertions may reorganize storage and invalidate earlier borrowed positions.

Member overloads that return references, iterators or nonowning views into the owner shall require an lvalue owner. Matching rvalue calls that would produce such borrows shall be rejected during overload resolution. Temporary iterator and row-view values shall remain usable while their backing owner remains alive.

PPL-SPEC-000293
13. Reset and clear preserve logical size PPL-SPEC-000293

clear() shall set every logical coefficient to zero while retaining size; sparse clear shall remove every stored entry. Indexed reset shall zero the chosen in-size coefficient, removing its sparse entry if any. Dense range reset shall require first <= last <= size() and change exactly that half-open range. Dense iterator reset shall zero its live slot and return the following logical slot. Sparse iterator reset shall erase its stored slot and return the following stored slot; an iterator range shall erase exactly its stored half-open interval and return the first retained successor. Sparse_Row::reset_after(i) shall require i < size() and remove every stored position at or after i. Empty ranges shall be admitted.

Member overloads that return references, iterators or nonowning views into the owner shall require an lvalue owner. Matching rvalue calls that would produce such borrows shall be rejected during overload resolution. Temporary iterator and row-view values shall remain usable while their backing owner remains alive.

PPL-SPEC-000294
14. Coordinate insertion and deletion preserve coefficient association PPL-SPEC-000294

add_zeroes_and_shift(n,i) shall require i <= size() and admitted nonoverflowing result size/keys. It shall insert n zero positions before i and shift every old position at or after i upward by n. Zero insertion shall preserve the vector. delete_element_and_shift(i) shall require i < size(), remove just that coefficient and shift all later indices down by one. Dense deletion shall retain capacity. Implicit sparse zeroes shall stay implicit unless already explicitly represented. Dense shifts/deletions and sparse deletions shall invalidate prior iterators. Sparse insertion of zero positions shall preserve stored-entry iterator values and update affected indices, retaining their coefficient association.

For erase_and_reindex(index_map,new_size), index_map shall contain size() entries. Selected coordinates shall be marked not_a_dimension(); the remaining images shall enumerate [0,new_size) in order. The result shall be the stable subsequence of retained coefficients with the specified size. Dense rows shall retain capacity. Sparse rows shall retain surviving explicit stored zeroes without materializing implicit zeroes. The operation shall invalidate ordinary iterators and coefficient references. If a sparse erasure allocation fails, the row shall remain valid at its old size and numbering, with possibly some selected stored entries already erased.

PPL-SPEC-000295
15. Coefficient swaps and constrained sparse key relocation PPL-SPEC-000295

Indexed swaps shall require two in-size indices and exchange exactly their coefficient values, including implicit sparse zeroes. Iterator swaps shall require two live dereferenceable positions of the same row and exchange their values without exchanging their keys. Self-swaps shall retain value. Sparse fast_swap(i,pos) shall require an in-size index and lower_bound(i) == pos != end(); it shall move that stored entry to i, leaving its previous position implicitly zero. Its iterator shall remain valid and report the new index, and unrelated entries shall be retained.

PPL-SPEC-000296
16. GCD normalization of raw coefficient vectors PPL-SPEC-000296

For a nonzero row, normalize() shall divide every coefficient by the positive greatest common divisor of all coefficient magnitudes. All-zero rows, including empty rows, shall be unchanged. Size and coefficient signs shall be retained. A common sign shall not be reversed. This operation shall change vector value when the common divisor exceeds one; it shall not be a representation-only operation. Numerical prerequisites shall follow 🔗 1. Internal coefficient-row values and valid use.

PPL-SPEC-000297
17. Support-aware callback combinations PPL-SPEC-000297

For equal-sized rows and pointwise callback functions obeying the following identities, combination shall produce the vector obtained by applying g(x[i],y[i]) to each entry. Callbacks shall modify only their first coefficient argument; they shall not change another row position, row structure or external state on which another callback result depends. They shall admit aliased first/source arguments for self-operand calls. Invocation count/order shall not be promised. For combine_needs_first, g(0,b) shall leave zero unchanged and f(a) shall equal g(a,0). For combine_needs_second, g(a,0) shall leave a unchanged and h(0,b) shall equal g(0,b). For general combine, g(0,0) shall leave zero unchanged, with both f/h identities. Exact final values shall be independent of stored zeroes and storage type. Self-operand calls shall use each position's entry value as both operands. Sparse result zeroes may remain stored or be removed.

18. Whole-row linear combinations across row storage PPL-SPEC-000298

With nonzero scalar coefficients c1 and c2, whole-row combination shall assign xi :  = c1xi + c2yi from entry values. Dense/dense member or free forms shall require equal logical sizes. Sparse/sparse forms shall require distinct rows of equal size. The dense-destination/sparse-source whole-row free form shall require equal logical sizes. The sparse-destination/dense-source whole-row free form shall require x.size() >= y.size() and treat absent trailing source coordinates as zero. Target size shall be retained and distinct source values preserved. Dense self-operand calls shall use each position's entry value for both operands. Scalars shall remain live and independent of coefficients modified by the operation. Numerical/failure prerequisites shall follow 🔗 1. Internal coefficient-row values and valid use.

PPL-SPEC-000299
19. Range-limited linear combinations preserve outside coordinates PPL-SPEC-000299

Range combination shall require start <= end within both logical sizes, nonzero scalars and the operand/scalar independence conditions of 🔗 18. Whole-row linear combinations across row storage. It shall assign xi :  = c1xi + c2yi from entry values exactly for start ≤ i < end, leaving every other target coordinate unchanged. Empty windows shall preserve the complete vector. Storage pairing and optimized scalar cases shall not change that result.

PPL-SPEC-000300
20. Row equality compares complete logical vectors PPL-SPEC-000300

Equality shall return true exactly when logical sizes and all corresponding coefficient values agree. Dense/sparse pairing, allocation capacity and explicit versus implicit sparse zeroes shall not affect equality. Inequality shall be its Boolean negation. Equality shall preserve both operands and shall not equate rows merely because one has additional trailing zeroes.

PPL-SPEC-000301
21. Dense-row ASCII export and reload PPL-SPEC-000301

ascii_dump(s) shall emit the logical size followed by all coefficients in index order, using size n a0 ... syntax and a terminating newline. ascii_load(s) shall accept a complete compatible representation with an admitted size and representable coefficients, replace size/values and return true. Size zero shall be admitted. A malformed keyword, missing size or missing/malformed coefficient shall return false; trailing input shall be left for subsequent parsing. No rollback shall be promised after failure; owned resources and surviving target destruction shall follow 🔗 1. Internal coefficient-row values and valid use. The zero-argument dump and print forms shall write this representation to the designated diagnostic stream.

PPL-SPEC-000302
22. Sparse-row ASCII export, stored entries and validation PPL-SPEC-000302

Sparse ASCII export shall report logical size, stored-element count and ascending indexed coefficients, including explicitly stored zeroes, in size n elements k [ i ]= a ... syntax with a terminating newline. Loading a complete compatible representation shall replace logical extent and stored entries and return true. Size zero with zero stored entries shall be valid. Malformed or missing keywords, counts, indices and coefficients, counts greater than the logical extent, and repeated, out-of-order or out-of-extent indices shall report false rather than successful construction of an invalid row. Trailing input shall remain available. No rollback shall be promised on failure; target ownership shall follow 🔗 1. Internal coefficient-row values and valid use. Diagnostic dump/print forms shall use this reloadable representation.

PPL-SPEC-000303
23. Row invariants and memory-accounting queries PPL-SPEC-000303

OK() shall report satisfaction of row structural invariants without changing values. Dense invariants shall include size <= capacity <= max_size() and backing-storage consistency; OK(n) shall additionally compare logical size with n. Sparse invariants shall require every stored index below logical size; its compatibility OK(capacity) shall ignore that argument.

Memory queries shall return nonnegative accounting estimates without changing values. For both row types, total shall equal sizeof(row) + external. Dense external accounting shall include actual reserved coefficient slots and external storage owned by live coefficients. Sparse external accounting shall follow its coefficient tree. Compatibility capacity arguments shall not change the reported current storage; neither query shall promise exact allocator bookkeeping or available memory.