Parma Polyhedra Library requirements
Internal rectangular bit matrices

Internal rectangular bit matrices

PPL-SPEC-000461
1. Rectangular Boolean values and valid internal use
UID: PPL-SPEC-000461
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

Bit_Matrix shall own a rectangular Boolean array B with r rows and c columns. Its stored row i shall represent exactly {j ∣ 0 ≤ j < c∧Bij} under 🔗 1. Finite bit-set row values and valid use. Set bits outside the declared column range shall violate the matrix invariant, even though the corresponding Bit_Row value alone is valid.

Operations shall require live valid objects and indices, counts and capacity calculations within their supported representable and storage limits, with sufficient resources. Callers shall prevent concurrent access conflicting with mutation. No library or thread initialization object or coefficient-constant stage shall be required. Allocation or interruption failure shall not constitute a successful matrix result. Failed C++ construction shall release resources owned by its incomplete object. Surviving owners shall remain destructible; rollback shall apply only where the individual contract promises it. Ordinary allocation-failure recovery shall not be promised for fatal GMP allocation failure.

RATIONALE:

Incidence and saturation matrices need explicit coordinate meaning and width invariants independent of the configured coefficient type.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

class Bit_Matrix;
VERIFICATION_CRITERIA:

Compare all entries and both extents with independent Boolean arrays, exercise row-width checks, preserve separate lifetimes, and run without initialization in threaded and non-thread-safe configurations. Inject observable C++ allocation failures during construction.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.

PPL-SPEC-000462
2. Empty and explicitly shaped construction and extent queries
UID: PPL-SPEC-000462
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

Default construction shall produce shape 0×0. Construction with row and column counts shall produce that exact shape with every entry false, including shapes with zero rows or zero columns. num_rows() and num_columns() shall return the corresponding extents without mutation. max_num_rows() shall report the row-vector storage limit; it shall not promise that every shape up to that row count is practically allocatable or impose an independent column bound.

RATIONALE:

An empty collection of rows and a collection of empty rows have different shapes that transposition must retain.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

Bit_Matrix();
Bit_Matrix(dimension_type n_rows, dimension_type n_columns);
static dimension_type max_num_rows();
dimension_type num_rows() const;
dimension_type num_columns() const;
VERIFICATION_CRITERIA:

Check zero, one and rectangular extents, zero initialization, the reported row limit and preservation of column count when the row count is zero.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.

PPL-SPEC-000463
3. Owned copies, assignment, exchange and lifetime
UID: PPL-SPEC-000463
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

Copy construction and assignment shall preserve both source extents and all entries while establishing independent storage. Assignment shall return its target and admit self-assignment. A copy shall remain usable after source mutation or destruction. Copying an rvalue through these copy interfaces shall preserve its source. Destruction shall release the row-vector storage and the bit storage owned by its rows.

Member and free swaps shall exchange complete shapes and row contents, including storage ownership, and admit self-swap. The resulting owners shall remain independent.

RATIONALE:

Copied saturation data and temporary transposition results require separate ownership without accidental sharing.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

Bit_Matrix(const Bit_Matrix& y);
Bit_Matrix& operator=(const Bit_Matrix& y);
~Bit_Matrix();
void m_swap(Bit_Matrix& y);
void swap(Bit_Matrix& x, Bit_Matrix& y);
VERIFICATION_CRITERIA:

Check copy and assignment for empty, zero-width and populated shapes, self-assignment, source destruction, rvalue copying, independent mutations, self/member/free swaps and observable copy-construction allocation failure.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.

PPL-SPEC-000464
4. Borrowed indexed row access
UID: PPL-SPEC-000464
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

For 0 ≤ i < r, indexed access shall return a borrowed reference to stored row i, with a const reference for a const matrix. Mutating that row shall affect exactly its represented entries. Callers shall retain no reference across owner destruction or a matrix operation that can replace, reallocate, remove or reorder its row storage. Before using other matrix operations, callers shall ensure that every set position in a mutated row is below the current column count; the validity query may inspect a live row that violates this width condition.

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.

RATIONALE:

Algorithms update incidence rows directly, so borrowing and responsibility for the enclosing width must be explicit.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

Bit_Row& operator[](dimension_type k) &;
const Bit_Row& operator[](dimension_type k) const &;
VERIFICATION_CRITERIA:

Compare const and mutable views with literal row sets, modify independent rows across limb boundaries, and check that an out-of-width insertion is detected before restoring the width invariant. Check lvalue admission and temporary-owner rejection with compile-time client expressions. Preserve temporary iterator/view use and lvalue storage identity in runtime checks.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc. tests/rowstoragespec1.cc.

PPL-SPEC-000465
5. General resizing preserves the common rectangle
UID: PPL-SPEC-000465
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

A successful resize(r2, c2) shall establish shape r2×c2. For each coordinate retained in both the old and new rectangles it shall preserve the previous entry. Every newly introduced entry shall be false. Removed rows and columns shall be discarded, so later growth shall not restore their former true values. The operation shall admit unchanged extents and all combinations of zero extents.

RATIONALE:

Growth and truncation must preserve coordinate associations rather than the incidental GMP capacity of retained rows.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

void resize(dimension_type new_n_rows, dimension_type new_n_columns);
VERIFICATION_CRITERIA:

Compare complete Boolean arrays through all small shape pairs and larger limb-boundary histories, including simultaneous row growth and column shrinkage, retained vector capacity and reallocation.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.

PPL-SPEC-000466
6. Trailing removal and clearing
UID: PPL-SPEC-000466
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

With a count no greater than the row count, trailing-row removal shall discard exactly that suffix and preserve all retained entries and the column count. With a count no greater than the column count, trailing-column removal shall decrease the width by that count and preserve the row count and remaining entries. This column operation shall require all removed columns to be false; it shall not replace the bit-clearing semantics of general resizing. Both removals shall admit a zero count.

clear() shall release row-vector and owned bit storage and establish shape 0×0, from which ordinary construction by mutation shall remain possible.

RATIONALE:

Cheap removal of already-zero columns has a stronger caller precondition than truncating arbitrary columns.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

void remove_trailing_rows(dimension_type n);
void remove_trailing_columns(dimension_type n);
void clear();
VERIFICATION_CRITERIA:

Check zero, partial and complete suffix removal with valid zero columns, preserve retained entries, and verify clear/rebuild histories and zero managed storage after clear.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.

PPL-SPEC-000467
7. Transposition and transposed assignment
UID: PPL-SPEC-000467
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

Transposition of a shape r×c shall produce shape c×r and satisfy B’ji = Bij at every original coordinate. Transposed assignment shall replace its target with the transpose of the source, preserving a distinct source. It shall also admit the source being its target. A recoverable failure before the replacement is installed shall preserve the target. Zero extents shall be exchanged exactly, and transposing twice shall restore the original shape and entries.

RATIONALE:

Transposition exchanges incidence coordinates and needs a complete temporary owner for safe replacement and self-aliasing.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

void transpose();
void transpose_assign(const Bit_Matrix& y);
VERIFICATION_CRITERIA:

Check rectangular, square, empty-row and empty-column shapes, individual true coordinates across limb boundaries, double transpose, distinct/source-target aliases and observable allocation failure before replacement.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.

PPL-SPEC-000468
8. Row sorting and duplicate elimination
UID: PPL-SPEC-000468
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

A successful sort_rows() shall preserve the column count and replace the row sequence by its distinct row values in increasing Bit_Row comparison order, as defined by 🔗 8. Least-significant differing-position total order. At the least position where two row values differ, the row without that bit shall precede the row with it. Sorting shall preserve each retained row's complete bit set, admit zero or one row, and be idempotent. Sorting shall not preserve former row-index associations.

RATIONALE:

Sorted row sets support exact binary search; bit-set order differs from comparison of binary integers.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

void sort_rows();
VERIFICATION_CRITERIA:

Use an independent Boolean lexicographic comparator, compare the complete distinct sequence across permutations and duplicates, and include zero-column, one-row and empty matrices.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.

PPL-SPEC-000469
9. Membership in a sorted row sequence
UID: PPL-SPEC-000469
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

Given a matrix whose row sequence is actually nondecreasing under the order in 🔗 8. Row sorting and duplicate elimination, sorted_contains(row) shall return true exactly when one stored row has the same finite set of true positions as the query. It shall preserve the matrix and query and admit a query borrowed from the matrix. A query may contain positions beyond the matrix width, in which case it cannot equal a valid stored row. An empty matrix shall report absence.

RATIONALE:

Binary search requires actual sortedness rather than an unrecorded intention to sort.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

bool sorted_contains(const Bit_Row& row) const;
VERIFICATION_CRITERIA:

Check every small candidate row against an independent set of stored rows, duplicate sorted inputs, empty matrices, borrowed queries and absent high-position queries.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.

PPL-SPEC-000470
10. Recycled row insertion transfers ownership
UID: PPL-SPEC-000470
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

A successful recycled-row insertion shall append the donor's previous bit set and preserve all earlier rows and the column count. The donor shall be a separate live row, not borrowed from the target matrix, with all set positions below the matrix width. The resulting row count shall fit the row-storage limit. After successful return the donor shall be empty and reusable; the appended row shall own its storage independently of subsequent assignment to or destruction of the donor.

RATIONALE:

Explicit ownership transfer avoids copying bit storage while retaining the matrix-width invariant.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

void add_recycled_row(Bit_Row& row);
VERIFICATION_CRITERIA:

Append external empty and populated donors through repeated capacity growth and reuse, check that each donor is empty, assign new values to and destroy donors, and compare all earlier and appended rows with independent literal arrays.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/bitrowreuse1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.

PPL-SPEC-000471
11. Matrix equality includes both extents and all entries
UID: PPL-SPEC-000471
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

Equality shall return true exactly when both row and column counts agree and every corresponding entry agrees. Inequality shall be its logical negation. The result shall ignore unused allocated capacity and admit aliases. Distinct zero-row widths and distinct zero-column row counts shall remain unequal.

RATIONALE:

Finite bit-set rows alone cannot distinguish different declared rectangular shapes.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

bool operator==(const Bit_Matrix& x, const Bit_Matrix& y);
// Inequality uses C++20 rewriting of operator==.
VERIFICATION_CRITERIA:

Check Boolean inequality expressions in both operand orders through C++20 equality rewriting, retaining the stated equality and mismatch behavior. Compare equal values reached through different allocation histories, every shape mismatch, individual entry changes and self-comparisons.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.

PPL-SPEC-000472
12. ASCII representation and loading
UID: PPL-SPEC-000472
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

With decimal numeric formatting and numeric Boolean output selected on the stream, ASCII output shall emit the decimal row count, x and decimal column count, followed in row-major order by each entry as 0 or 1. Whitespace shall separate these tokens; each row shall have its own output line. No-argument output shall use the library diagnostic-output destination std::cerr. print() shall emit a diagnostic to std::cerr identifying that no user-level output operator is defined for Bit_Matrix.

With decimal numeric input formatting, admissible dimensions and resources, loading shall read the shape header and exactly that many integer entry tokens, replace the target's complete shape and entries, and return true. Zero entry tokens shall denote false and nonzero integer tokens true. Invalid header tokens, invalid integer tokens or premature end of input shall return false; the target shall remain a live valid matrix, without a promise to preserve its preceding shape or entries. Tokens following a complete representation shall remain available to the caller. Successful dump/load round trips shall preserve both extents and every entry.

RATIONALE:

Reloadable matrix data needs explicit shape, Boolean interpretation and failure-state rules.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

void ascii_dump(std::ostream& s) const;
void ascii_dump() const;
void print() const;
bool ascii_load(std::istream& s);
VERIFICATION_CRITERIA:

Check exact dump tokens and lines, round trips of zero and rectangular shapes, replacement of old true bits by false, nonzero integer entry interpretation, trailing tokens, each malformed header category and truncation at every token boundary.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.

PPL-SPEC-000473
13. Invariant, ordering and allocated-memory queries
UID: PPL-SPEC-000473
STATUS: APPROVED
COMPONENT: CORE_DATA_STRUCTURES
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Internal
RELATIONS (Parent):
STATEMENT:

For live rows with valid bit-row storage, OK() shall return true exactly when every row is valid and no row has a set position at or beyond the declared column count. In builds with assertions enabled, check_sorted() shall return true exactly when the stored rows are nondecreasing under their comparison order; duplicates shall be allowed.

External memory shall equal the allocated row-vector capacity in bytes plus the external memory owned by each live bit row. Total memory shall add sizeof(Bit_Matrix). These queries shall describe allocated storage, including unused capacity retained after shrinkage, and shall preserve the matrix.

RATIONALE:

Validity, sortedness and allocated capacity are distinct properties that algorithms and storage diagnostics inspect.

INTERFACE:

Internal source header: Bit_Matrix_defs.hh. Names belong to Parma_Polyhedra_Library. Member signatures apply to Bit_Matrix.

bool OK() const;
#ifndef NDEBUG
bool check_sorted() const;
#endif
memory_size_type external_memory_in_bytes() const;
memory_size_type total_memory_in_bytes() const;
VERIFICATION_CRITERIA:

Check valid and temporarily out-of-width rows, all adjacent-order outcomes and duplicates, memory identities and row-storage lower bounds through growth and shrinkage; compare exact row-vector payload with the allocation recorder in bitmatrixmemory1.

SOURCE:

src/Bit_Matrix_defs.hh; src/Bit_Matrix_inlines.hh; src/Bit_Matrix.cc; tests/bitmatrixspec1.cc; tests/matrix1.cc; tests/bitmatrixmemory1.cc.