GR(1) contracts¶
GR1IoContract and GR1SolverError are imported from pacti.iocontract.
pacti.iocontract.gr1_iocontract.GR1IoContract
¶
GR(1) IO contract whose assumptions and guarantees are GR1TermLists.
from_buckets(*, input_vars, output_vars, a_init=None, a_inv=None, a_liv=None, g_init=None, g_inv=None, g_liv=None, simplify=True)
staticmethod
¶
Construct a contract from pre-built cores grouped by GR(1) bucket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_vars
|
List[str]
|
Input vars. |
required |
output_vars
|
List[str]
|
Output vars. |
required |
a_init
|
Optional[List[GR1CoreFormula]]
|
A init. |
None
|
a_inv
|
Optional[List[GR1CoreFormula]]
|
A inv. |
None
|
a_liv
|
Optional[List[GR1CoreFormula]]
|
A liv. |
None
|
g_init
|
Optional[List[GR1CoreFormula]]
|
G init. |
None
|
g_inv
|
Optional[List[GR1CoreFormula]]
|
G inv. |
None
|
g_liv
|
Optional[List[GR1CoreFormula]]
|
G liv. |
None
|
simplify
|
bool
|
Whether to simplify the resulting formulas. |
True
|
Returns:
| Type | Description |
|---|---|
'GR1IoContract'
|
The computed 'GR1IoContract' result. |
from_dict(contract, var_map=None, simplify=True, variable_sorts=None)
staticmethod
¶
Restore typed user text, falling back to versioned machine formulas.
``variable_sorts`` may be passed explicitly or embedded in ``contract``.
Legacy ``var_map`` input creates text-only cores and cannot support QE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contract
|
Dict[str, Any]
|
Contract. |
required |
var_map
|
Optional[FormulaVarMap]
|
Mapping from formula text to variable names. |
None
|
simplify
|
bool
|
Whether to simplify the resulting formulas. |
True
|
variable_sorts
|
Optional[VariableSortMap]
|
Declared sort for each base variable. |
None
|
Returns:
| Type | Description |
|---|---|
'GR1IoContract'
|
The computed 'GR1IoContract' result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If serialized data or variable sorts are invalid. |
compose(other, vars_to_keep=None, simplify=True)
¶
Compose contracts, optionally preserving named internal variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'GR1IoContract'
|
Other term list or contract. |
required |
vars_to_keep
|
Optional[List[str]]
|
Vars to keep. |
None
|
simplify
|
bool
|
Whether to simplify the resulting formulas. |
True
|
Returns:
| Type | Description |
|---|---|
'GR1IoContract'
|
The computed 'GR1IoContract' result. |
quotient(other, additional_inputs=None, simplify=True)
¶
Compute a quotient with optional additional input names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'GR1IoContract'
|
Other term list or contract. |
required |
additional_inputs
|
Optional[VariableInputs]
|
Additional inputs. |
None
|
simplify
|
bool
|
Whether to simplify the resulting formulas. |
True
|
Returns:
| Type | Description |
|---|---|
'GR1IoContract'
|
The computed 'GR1IoContract' result. |
merge(other)
¶
Merge two contracts while preserving every GR(1) bucket.
GR(1) is closed under contract merge: assumptions and guarantees are
conjoined bucket by bucket. INIT and INV terms are concatenated as
ordinary conjunctions. LIV terms are also concatenated as distinct
clauses, so GF(phi) & GF(psi) never becomes GF(phi & psi).
No abstraction, projection, quantifier elimination, or CAVE machinery
is invoked.
Interface variables follow :meth:IoContract.merge: inputs and outputs
are stable unions, and the constructor rejects variables classified as
both input and output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'GR1IoContract'
|
GR(1) contract to merge with this contract. |
required |
Returns:
| Type | Description |
|---|---|
'GR1IoContract'
|
Exact bucket-preserving conjunction of both contracts. |
Raises:
| Type | Description |
|---|---|
IncompatibleArgsError
|
If contract types, interfaces, or sorts are incompatible. |
refines(other)
¶
Tell whether the given contract is a refinement of another.
Return self <= other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
IoContract_t
|
contract being compared with self. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the calling contract refines the argument. |
Raises:
| Type | Description |
|---|---|
IncompatibleArgsError
|
Refinement cannot be computed. |
rename_variables(variable_mappings)
¶
Apply a sequence of base-variable renamings to a copied contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_mappings
|
List[Tuple[str, str]]
|
Variable mappings. |
required |
Returns:
| Type | Description |
|---|---|
'GR1IoContract'
|
The computed 'GR1IoContract' result. |
to_dict()
¶
Serialize readable buckets, sorts, and versioned generated expressions.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
The computed Dict[str, Any] result. |
to_machine_dict()
¶
Return :meth:to_dict with the public serialized-contract type.
Returns:
| Type | Description |
|---|---|
ser_gr1_contract
|
The computed ser_gr1_contract result. |
to_pretty_string(compact=False, assumption_relative=True, candidate_assumptions=None, candidate_guarantees=None)
¶
Return an observational Unicode assume-guarantee contract view.
This is an additional presentation API. The existing ASCII
:meth:pretty, :meth:debug_dump, serialization, and __str__
behavior remain unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compact
|
bool
|
Render |
False
|
assumption_relative
|
bool
|
Reduce only the displayed guarantees under
assumptions using SMT-verified GR(1) rules. Set to |
True
|
candidate_assumptions
|
Optional[GR1TermList]
|
Optional presentation-only safety formulas. They are accepted only when unconditionally equivalent. |
None
|
candidate_guarantees
|
Optional[GR1TermList]
|
Optional presentation-only safety formulas. They are accepted only when equivalent under shifted assumptions. These are formatting settings only. In contrast, the
|
None
|
Returns:
| Type | Description |
|---|---|
str
|
Unicode user-facing contract text. |
pacti.iocontract.gr1_iocontract.GR1SolverError
¶
Bases: RuntimeError
A required solver decision or quantifier elimination was unavailable.