Parma Polyhedra Library requirements
Internal rectangular coefficient matrices
1. Internal rectangular coefficient matrices and valid use PPL-SPEC-000361

For Row equal to Dense_Row or Sparse_Row, Matrix<Row> shall represent a rectangular coefficient array with independent row and column counts. Every retained row shall have exactly the matrix column count; entry Mij shall be the row coefficient at index j. Zero rows, zero columns and zero-by-zero shape shall all be admitted and remain distinct shapes. The raw row contracts shall follow 🔗 1. Internal coefficient-row values and valid use. No affine, constraint or generator interpretation shall be imposed by the matrix.

Calls shall require live valid matrices, valid positions/iterators, admitted nonoverflowing size calculations and sufficient resources. Mutable row access shall require clients to restore the common width before a call requiring matrix validity. Initialization, numerical and synchronization prerequisites shall follow 🔗 1. Internal coefficient-row values and valid use. Failed construction shall release storage owned by the incomplete matrix. Recoverable mutation failure may propagate; unchanged sources shall survive and modified targets shall remain destructible without a universal rectangular-state or rollback guarantee.

PPL-SPEC-000362
2. Zero-filled square and rectangular matrix construction PPL-SPEC-000362

Default construction shall produce zero-by-zero shape. Square construction shall produce n rows and columns. Rectangular construction shall preserve both requested counts, including zero in either count. Every coefficient shall initially be zero, and sparse rows shall initially have no stored entries. Construction shall use the row type selected by the template.

PPL-SPEC-000363
3. Owning matrix copies, assignment and whole-matrix swaps PPL-SPEC-000363

Implicit copy construction/assignment shall preserve shape and all entries, produce independent row owners, admit self-assignment and return the target from assignment. A copy shall survive its source mutation/destruction. Implicit moves shall transfer the source entry value to the target and leave the source valid for destruction and reassignment, with unspecified shape and entries. Member/free swaps shall exchange full matrix values and dimensions, including self-swap. Destruction shall release row and coefficient storage owned by the matrix. Failure shall follow 🔗 1. Internal rectangular coefficient matrices and valid use.

PPL-SPEC-000364
4. Matrix shape, row capacity and reservation PPL-SPEC-000364

Shape queries shall report logical row and column counts independently of allocated capacity. has_no_rows() shall mean row count zero, including a nonzero column count. capacity() shall report reserved row slots at least as large as row count. reserve_rows(n) shall retain shape and values and provide at least n row slots; a request no larger than current capacity shall retain capacity. Reallocation may invalidate row references/iterators. max_num_rows() shall return std::vector<Row>().max_size() and max_num_columns() shall return Row::max_size(). These reported limits shall not guarantee that every allocation below them succeeds.

PPL-SPEC-000365
5. Matrix resizing, prefix preservation and clear PPL-SPEC-000365

Resizing shall set the requested rectangular shape, preserve every entry in the common old/new row-and-column rectangle, discard removed entries and initialize newly introduced entries to zero. Removed values shall not reappear on regrowth. The one-argument form shall set a square shape. clear() shall produce zero rows and columns; it need not release reserved row capacity. Successful resizing shall restore every retained row to the common width. Existing iterators/references shall be invalidated as specified by changes to the row vector and row storage.

PPL-SPEC-000366
6. Appending zero rows and columns PPL-SPEC-000366

add_zero_rows(n) and add_zero_columns(m) shall require positive counts and admitted resulting shapes. They shall append exactly that many zero rows or columns, retaining all old entries at their old coordinates. The combined form shall require both positive counts and append both zero blocks. Zero columns in old/new rows shall follow the selected raw row representation.

PPL-SPEC-000367
7. Copy-appending a row with source independence PPL-SPEC-000367

add_row(x) shall require x.size() == num_columns() and an admitted additional row. It shall append an owned copy of the source entry value, preserve all old rows/width and preserve an external source. The source may be a row borrowed from the target matrix; its entry value shall be captured before growth can invalidate that reference. Mutating the appended row shall not modify its source. Existing matrix-row iterators may be invalidated.

PPL-SPEC-000368
8. Recycling an external row into a matrix PPL-SPEC-000368

add_recycled_row(x) shall require a live row of matching column count that is not a row of the matrix, plus admitted additional row count. It shall append the source entry vector while preserving all old matrix values. On success, the donor shall be a valid all-zero row of the same column count; its capacity shall be unspecified. The operation may transfer owned storage rather than copy coefficient values. Violations of matching-width or independent-donor preconditions need not be detected in release builds. Borrowed matrix-row iterators may be invalidated by append.

PPL-SPEC-000369
9. Removing contiguous or trailing matrix rows PPL-SPEC-000369

Trailing-row removal shall require n <= num_rows() and remove exactly the last n rows while retaining column count. Iterator-range removal shall require a valid ordered half-open range in the same matrix, including an empty range; it shall retain the unselected rows in their original order and keep column count. Removing every row shall retain the declared width. Removed row storage shall be released; later appended zero rows shall not recover old coefficients.

PPL-SPEC-000370
10. Inserting and removing matrix columns PPL-SPEC-000370

add_zero_columns(n,i) shall require i <= num_columns() and an admitted nonoverflowing result shape. It shall insert n zero columns before i and shift all old columns at or after i up by n; zero insertion shall preserve the array. remove_column(i) shall require an in-width column, erase it from every row and shift later indices down by one. Trailing-column removal shall require n <= num_columns() and remove just the last n columns. Row count shall be retained, including zero rows. These transformations shall preserve every surviving coefficient association.

PPL-SPEC-000371
11. Column swaps and encoded nonzero-index permutation cycles PPL-SPEC-000371

Column swaps shall require two in-width indices and exchange their entries in every row; index zero and self-swaps shall be admitted. Encoded permutation cycles shall require a nonempty vector containing complete disjoint cycles of length at least two, each terminated by zero. Every listed index shall be nonzero and strictly below column count. The final element shall be a zero terminator. For each cycle, the old coefficient at each listed column shall move to the following listed column, with the last wrapping to the first. Unlisted columns, especially column zero, shall remain unchanged. Both operations shall retain shape; row-level borrowed positions may be invalidated.

PPL-SPEC-000372
12. Borrowed matrix rows and row-sequence iterators PPL-SPEC-000372

Indexed access shall require i < num_rows() and borrow the corresponding row. Const access shall not modify sparse support. Mutable access shall permit coefficient updates within common width; changing a borrowed row's size shall require restoring rectangularity under 🔗 1. Internal rectangular coefficient matrices and valid use. Row iterators shall enumerate every retained row in order, including zero-width rows, using the standard random-access vector position semantics of Swapping_Vector. Const/mutable positions shall agree; prefix/postfix advancement shall retain the usual advanced/entry-position results. Borrowed rows and iterators shall not outlive the matrix or survive invalidating row-vector operations.

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-000373
13. Matrix equality includes both dimensions and every entry PPL-SPEC-000373

Matrix equality shall return true exactly when both logical dimensions and all corresponding row coefficient vectors agree. Extra zero rows or columns shall affect equality. Row capacity, allocation identity and explicit versus implicit sparse zeroes shall not affect equality. Inequality shall be its Boolean negation. Comparison shall not modify either operand.

PPL-SPEC-000374
14. Matrix ASCII reload validates rectangular row sizes PPL-SPEC-000374

ASCII export shall emit r x c followed by a newline and the compatible row-type ASCII representation of each retained row in order. Loading a complete compatible representation shall replace both dimensions and every entry and return true only for a valid rectangular result. Zero-row/nonzero- column and nonzero-row/zero-column representations shall be admitted. Malformed/missing shape tokens or row encodings, including a row size that differs from the declared width, shall return false. Trailing input shall remain available for further parsing. The dimensions shall fit the container limits and any limits supplied by the enclosing record. Matrix row storage shall grow as the rows are decoded. Failure need not roll back prior changes; owned storage and surviving target destruction shall follow 🔗 1. Internal rectangular coefficient matrices and valid use. Diagnostic dump/print forms shall emit this same reloadable representation.

PPL-SPEC-000375
15. Matrix rectangularity inspection and memory accounting PPL-SPEC-000375

OK() shall report whether every retained row's logical size equals the matrix column count; no-row matrices shall satisfy that width invariant for any declared admitted column count. It shall not replace the separate raw-row invariant queries. Memory queries shall preserve matrix values. Total memory shall equal sizeof(matrix) + external; external memory shall include reserved row-vector slots and external storage owned by each live row. The returned count shall be a storage-accounting estimate, with no promise of exact allocator overhead or future allocation success.