Prolog boundary contracts
- PPL-LLR-000011 Coordinate identity and ambient dimension (Specifies)
- PPL-LLR-000012 Affine meaning of linear expressions (Specifies)
- PPL-LLR-000013 Meaning of linear constraints (Specifies)
- PPL-LLR-000014 Meaning of linear congruences (Specifies)
- PPL-LLR-000015 Distinct meanings of geometric generators (Specifies)
- PPL-LLR-000210 Prolog mathematical term interpretation (Specifies)
- PPL-LLR-000214 Mathematical consistency of corresponding binding operations (Specifies)
For each configured supported Prolog engine, supported integral terms, affine expressions, constraints, congruences and generators shall be interpreted with their documented native mathematical meaning. '$VAR'(I) shall denote the zero-based coordinate I. Unary negation, addition, subtraction and integral scalar multiplication shall preserve affine meaning. Relations shall preserve equality and strict/non-strict order. Point and closure-point coordinates shall be divided by the supplied nonzero divisor; lines and rays denote directions. Returned terms may be normalized but shall denote the native result.
Values shall be representable by both the engine and configured native coefficient type. A bounded engine does not acquire arbitrary-size integers from GMP in the native library. Malformed or nonlinear expressions and invalid native objects shall follow 🔗 2. Prolog success failure and exception outcomes.
The common term protocol must express the same mathematics independently of the selected foreign runtime.
Common numerical term protocol:
'$VAR'(I) -E E + F E - F N * E E = F E =< F E < F E >= F E > F point(E, D) closure_point(E, D) ray(E) line(E)
Here I is a valid coordinate index, N an integral coefficient and E/F supported affine expressions. Lists of such terms are the system interfaces accepted and returned by configured domain and solver predicates. Grid-point, parameter and congruence terms follow the common Prolog manual's rational-divisor and modulus conventions.
Across each available configured engine, compare coefficient round trips and independently reconstructed expressions/constraints/generators. Cover signs, zero, multiple indices, all relation and generator kinds, and each engine/native range intersection; check unsupported numeric and malformed cases separately.
interfaces/Prolog/Prolog_interface_sysindep.dox; interfaces/Prolog/ppl_prolog_common.cc; interfaces/Prolog/tests/pl_check.pl.
A true numerical predicate shall succeed; a false numerical predicate shall fail normally. Result-producing predicates shall unify the documented output terms on success. Incompatible output bindings shall cause ordinary failure, without changing that into a numerical falsehood or promising rollback of foreign mutations. Newly allocated owned results whose output cannot be unified shall be released.
Malformed arguments and supported native failures shall be reported through the selected engine's Prolog exception mechanism. Native exception unwinding shall be contained at the foreign boundary. Error terms shall distinguish the common invalid-argument/type/range, arithmetic-overflow, allocation, native logic/runtime and supported interruption categories according to the engine adapter. Ordinary false queries shall not be used to conceal those errors.
Logical falsehood, failed output unification and an inability to perform a numerical operation have different meanings.
Configured ppl_* predicates use the success/failure and output arguments specified by the common and generated Prolog predicate documentation. On a supported error they raise the common binding error term through the selected engine adapter; callers may use catch/3. For example:
ppl_MIP_Problem_is_satisfiable(Problem) ppl_MIP_Problem_solve(Problem, Status) ppl_delete_MIP_Problem(Problem)
Handles shall satisfy 🔗 3. Prolog owned domain and MIP handles through 🔗 5. Prolog PIP owner and tree generations, as applicable.
Check true/false numerical queries, literal output bindings, incompatible outputs and constructor cleanup. Catch malformed/type/stale-handle errors and supported native categories on each configured engine; inspect containment and error-reporting cleanup.
interfaces/Prolog/ppl_prolog_common_defs.hh; interfaces/Prolog/ppl_prolog_common.cc; interfaces/Prolog/tests/pl_check.pl.
Constructors shall return an opaque typed handle owning the new domain or MIP object. Copy constructors shall create an independent owned object. Deletion shall release the object and invalidate all aliases of its identity. Native access shall first check live owner identity and required native type; malformed, stale, unknown and wrong-type handles shall raise invalid-argument errors through 🔗 2. Prolog success failure and exception outcomes.
Owner identities shall not wrap or be reused, including across finalization and reinitialization. Registry exhaustion shall reject construction rather than revive an old identity. MIP clear, swap and normal updates shall preserve live problem handles. Finalization shall release registered owned objects. A failed constructor/copy output unification shall discard the unpublished allocation. Term collection and backtracking alone shall not delete a foreign owned object.
Non-reused typed identities distinguish ownership from native addresses, preventing stale terms from accessing recycled storage.
Configured domain construction/copy/deletion predicates and the common MIP operations, including:
ppl_new_MIP_Problem_from_space_dimension(Dimension, Handle) ppl_new_MIP_Problem_from_MIP_Problem(Source, Copy) ppl_delete_MIP_Problem(Handle)
Handles are opaque terms; applications shall not construct or inspect their encoding. Registry lookup, native use and mutation obey the interface lock.
Check independent copies, deletion/repeated deletion and every MIP entry point with malformed, wrong-type and stale handles. Exercise failed output unification, concrete destruction, address reuse, identity exhaustion and finalize/reinitialize sequences, including checked coefficients narrower than handle identities.
interfaces/Prolog/ppl_prolog_domain_handles.hh; interfaces/Prolog/ppl_prolog_common.cc; interfaces/Prolog/tests/domain_handles1.cc; interfaces/Prolog/tests/pl_check.pl.
Powerset iterator and disjunct access shall validate live owner identity, required native type and captured owner generation. Potentially normalizing queries and mutations shall invalidate dependent views; documented stable metadata queries shall preserve them. Swap shall invalidate views of both owners. Borrowed disjuncts shall be read-only; copying one shall produce an independent writable object.
Traversal shall reject end dereference, advancement past the end, movement before the beginning and operations combining different owners. Range removal shall reject reversed ranges. Single removal shall refresh its returned cursor while invalidating other captured cursors and views. Stale iterators shall remain explicitly deletable without dereferencing their former native node until library finalization. Failed view-output unification shall not leak a registry object. Invalid uses shall raise invalid-argument errors.
An iterator address alone cannot establish ownership or validity after a container changes.
Configured Pointset_Powerset construction/copy, begin_iterator, end_iterator, iterator-copy, increment/decrement/equality, get_disjunct, single/range-removal and iterator-deletion predicates, with the concrete names generated for the selected disjunct type. Iterators are explicitly owned handles; disjuncts are borrowed read-only views of their registered owner.
Check each boundary, foreign-owner and reversed-range case, read-only rejection, independent copies, normalizing versus stable queries, both swap operands, owner deletion, cursor refresh, failed output unification and release of stale iterators.
interfaces/Prolog/ppl_prolog_domain_handles.hh; generated Prolog domain predicates; interfaces/Prolog/tests/domain_handles1.cc; interfaces/Prolog/tests/pl_check.pl.
PIP problem and tree handles shall validate live typed owner identity before native access. A tree view shall additionally match the current problem generation and required node kind. Mutations, clear, swap of either operand, problem deletion and finalization shall invalidate prior tree views. Repeated stable solution queries shall preserve valid current-generation identities.
Unknown, malformed, stale and wrong-kind handles shall raise invalid-argument errors. Owner and view identity counters shall reject exhaustion rather than wrap; finalization/reinitialization and native-address reuse shall not revive old terms. Registry storage for old tree generations shall be reclaimed when invalidated. Failed constructor/copy/view output unification shall discard unpublished owned resources without deleting an independently owned object.
PIP solves and mutations can replace an entire tree while reusing native addresses; ownership and generation must therefore be checked independently.
Common ppl_new_PIP_Problem*, ppl_delete_PIP_Problem, ppl_PIP_Problem_solution, optimizing-solution, mutation and swap predicates, and ppl_PIP_Tree_Node_* queries. Root, descendant and bottom handles belong to a particular live problem generation; a tree view never owns the problem's native tree allocation.
Check every mutation and both swap sides, node-kind errors, roots/descendants/bottom, deletion, repeated deletion, address reuse, failed unification, generation-storage bounds, counter exhaustion and finalization/reinitialization.
interfaces/Prolog/ppl_prolog_pip_handles.hh; interfaces/Prolog/ppl_prolog_common.cc; interfaces/Prolog/tests/pip_handles1.cc; interfaces/Prolog/tests/pl_check.pl.
ppl_initialize shall establish the common native state if it is not already initialized; a repeated request shall succeed harmlessly. ppl_finalize shall release binding-owned interruption resources and registered objects and leave the interface uninitialized; a repeated request shall also be harmless. A subsequent initialization shall permit a new valid period of use without making old handles valid. Fixed interface atom names cached during initialization shall remain valid across the engine's atom and string garbage collection.
Each engine adapter shall invoke initialization through its documented loading hook or require explicit initialization before numerical predicate use. After finalization, clients shall use only lifecycle operations until the next initialization. The protocol does not require diagnosis of every violation of these call-state preconditions.
Engine loading hooks differ, while the common lifecycle must remain safe under repeated requests.
ppl_initialize ppl_finalize
Both predicates have arity zero. Automatic hooks depend on the configured Prolog runtime and loading mode; they establish the same common lifecycle.
Check repeated initialize/finalize, use in two valid periods, stale-handle rejection across those periods and each configured engine loading hook. Inspect timer, registry and initialization-owner cleanup. In a fresh XSB engine, collect atoms before using cached names, then check the first returned control-parameter atom in two initialization periods.
interfaces/Prolog/ppl_prolog_common.cc; engine adapters; interfaces/Prolog/tests/pl_check.pl; interfaces/Prolog/XSB/xsb_cached_atoms_gc.P.
Option terms shall select the identically named native meanings: true or false, universe or empty, bits_8, bits_16, bits_32, bits_64 or bits_128, unsigned or signed_2_complement, and overflow_wraps, overflow_undefined or overflow_impossible. min and max select optimization direction; polynomial, simplex and any select complexity. The documented pricing, cutting and pivot atoms shall select the corresponding native solver controls. Unsupported option terms shall be rejected through 🔗 2. Prolog success failure and exception outcomes; policies retain native preconditions and guarantees.
Prolog option terms have no static type guarantee; admission must reject unsupported terms without changing the requested native policy.
Option arguments of the documented Prolog predicates: Boolean and empty/universe selection; bounded-integer width, representation and overflow; optimization mode; complexity class; and MIP/PIP control-parameter names and values. These terms are interpreted by the corresponding term_to_* conversion helpers.
Compare every accepted atom with its native policy or enumerator. Inspect all rejection paths and generated option forwarding. Exercise each accepted option and malformed, non-atom, unbound and unknown values through the supported public predicates, distinguishing conversion errors from a false numerical result.
interfaces/Prolog/ppl_prolog_common.cc; interfaces/Prolog/ppl_prolog_common_defs.hh; interfaces/Prolog/Prolog_interface.dox.