Gr1 iocontract
Typed GR(1) assume-guarantee contracts with bounded next formulas.
The public representation separates temporal structure from Boolean/arithmetic cores. Each term belongs to one of three buckets:
INIT(phi)
phi must hold in the first state.
INV(phi)
phi must hold at every state (the GR(1) formula always phi).
LIV(phi)
phi must recur infinitely often (always eventually phi).
Several terms in a bucket are conjunctive. Liveness terms deliberately remain
separate: LIV(p), LIV(q) means that both p and q recur, not that
p and q must recur simultaneously.
Creating a contract from user-facing text¶
Use :meth:GR1IoContract.from_dict and declare every interface variable's
sort. Formula strings use base interface names; time indices are an internal
implementation detail::
contract = GR1IoContract.from_dict({
"input_vars": ["request", "temperature"],
"output_vars": ["grant"],
"variable_sorts": {
"request": "bool",
"grant": "bool",
"temperature": "real",
},
"assumptions": {
"init": ["temperature >= 0"],
"inv": ["temperature <= 100"],
"liv": ["request"],
},
"guarantees": {
"init": ["!grant"],
"inv": ["request -> X(grant)"],
"liv": ["grant"],
},
})
User-input naming rule¶
Users must enter and declare base variable names, such as q, grant,
and temperature. Do not enter flattened implementation names such as
q_0 or q_1 in input_vars, output_vars, variable_sorts, or
formula strings. Express temporal depth with the bounded-next operator::
# Correct user input
"input_vars": ["q"]
"variable_sorts": {"q": "bool"}
"inv": ["r = X(q)", "X(X(q)) -> r"]
# Incorrect user input: these names are reserved for internal Z3 use
"input_vars": ["q_0"]
"variable_sorts": {"q_0": "bool"}
"inv": ["r_0 = q_1"]
If q_0 is declared as user input, the parser treats the entire string
q_0 as a base name and its current-time internal symbol becomes
q_0_0. It does not mean the current value of q. Therefore always
write q for the current value, X(q) for the next value, and
X(X(q)) for the value two steps ahead.
Supported core syntax includes !/not, &/and, |/or,
->/=>, <->, comparisons, exact decimal and rational arithmetic,
parentheses, Boolean
literals, and nested X(...) or next(...). For example,
X(X(counter)) = counter + 2 is valid when counter is an integer.
The outer always and eventually operators are supplied by the bucket;
users do not write G, F, or U inside a core. Variables must be
declared as bool, int, or real so parsing and serialization never
guess a sort.
Next-state flattening and names¶
The parser retains an immutable :class:GR1SyntaxNode tree for structural
renaming and readable serialization, while translating p to p_0,
X(p) to p_1, and nested next operators to greater depths for Z3.
Contract interfaces always expose the base name p. Formula bookkeeping,
relevance, elimination, and renaming understand the relationship between a
base name and all of its flattened instances. Renaming p to r thus
renames p_0, p_1, and every other depth without accidental textual
replacement inside unrelated names.
Generated and serialized output follows the same user-facing convention.
For example, a QE result stored internally as q_1 == r_0 is displayed as
X(q) = r. Small mixed Boolean/linear QE formulas additionally undergo a
conservative interval canonicalization: Boolean modes are enumerated, exact
per-mode arithmetic bounds are extracted, and common bounds are factored from
conditioned implications. A candidate replaces the executable expression
only after Z3 proves it equivalent to the raw QE result. Unsupported formulas
fall back unchanged. core.raw_expr and :meth:GR1IoContract.debug_dump
retain the solver result, while normal printing uses bucket-oriented canonical
formulas and bounded X(...) syntax. Both forms are preserved in versioned
gr1_machine serialization for lossless restoration.
For programmatic construction, :class:GR1NextFlattener provides typed Z3
variables and an X operation::
fl = GR1NextFlattener()
request = fl.Bool("request")
grant = fl.Bool("grant")
core = fl.core("request -> X(grant)",
z3.Implies(request, fl.X(grant)))
Refinement and relaxation¶
Variable elimination implements the finite-window CAVE constructions. INIT
and INV terms are conjoined by bucket before quantifier elimination because
existential quantification does not distribute over conjunction. Refinement
uses universal implication from the context; relaxation existentially
projects the conjunction of context and target. Shifted invariant guards are
expanded through the greatest next depth involved, and output variables are
recovered from the resulting Z3 expression itself. In particular, INV
relaxation uses Gamma_inv^[0:h] through the target invariant's horizon;
the target and context roles remain distinct so a context relation such as
p=q contributes both p_0=q_0 and p_1=q_1 when needed.
GR(1) composition and quotient operate on canonical bucket obligations. Generic assumption saturation is contract-redundant when no hidden variable remains, but conjoining it into generated cores would erase whether a formula originated as INIT, INV, or a separate LIV liveness term. A GR(1)-specific algebra hook therefore preserves those canonical cores in the redundant case, while falling back to ordinary contextual relaxation whenever assumptions genuinely aid elimination. Quotient CAVE similarly keeps divisor guarantees distinct from system assumptions.
Every target liveness core enters the same complete candidate construction:
GF psi_i,0 uses universal implication from the invariant window alone,
and G psi_i,j uses that window and the j-th context liveness core, for
EVERY j. The synthetic horizon is the target's syntax depth; each genuine
support horizon is the maximum of target and support syntax depths. No
variable-overlap or viability filter precedes projection. Selection prefers a
true core, then a non-false core in canonical synthetic-first order, preserving
temporal tags; it makes no global weakestness or temporal Pareto claim.
Relaxation projects the complete liveness bucket and then removes true,
equivalent, and redundant liveness results. Its standalone decomposed
strongestness applies to the raw construction (simplify=False); optional
context-relative simplification is a later representation reduction.
LIV-only simplification also removes a common global next shift,
using GF(X^k(phi)) <=> GF(phi). Relative offsets are preserved: liveness
cores p_1 & q_2 and p_3 & q_4 share the canonical core p_0 & q_1,
whereas p_1 & q_2 and p_1 & q_3 remain distinct. This narrow rule is
not applied to INIT or INV and is not a general LTL simplifier. Separate
liveness obligations are never merged into one liveness core.
Unicode presentation is intentionally separate from storage. INIT terms may be
displayed as one conjunction, and INV terms may be displayed using
□phi ∧ □psi = □(phi ∧ psi). LIV terms are never placed beneath one shared
□◇: in general □◇phi ∧ □◇psi is not □◇(phi ∧ psi). These display
choices do not modify :class:GR1TermList, serialized text, or machine formulas.
At contract level, the Unicode view may additionally reduce guarantees under
assumptions. Such a display residual is accepted under the contextual condition
A => (G_internal <=> G_display); the full guarantee remains stored and is
used by every semantic operation and serialization API.
Post-CAVE semantic reduction¶
The six CAVE bounds are evaluated literally before redundancy reduction. A
separate GR(1)-specific postprocessor may then remove obligations already
established by stronger result buckets. In particular, G(phi) establishes
phi at time zero, so an INIT consequence implied by the flattened invariant
bucket can be removed or reduced modulo that context. Likewise G(phi)
implies GF(phi); more generally a LIV core is redundant when the finite
shifted invariant closure required by that core implies it. Every partial INIT
rewrite is guarded by the SMT proof
Gamma_inv_0 & residual <=> Gamma_inv_0 & original. These reductions are
post-processing only, are distinct from assumption-relative guarantee
reduction, and do not constitute a general LTL minimizer.
Operation-produced contracts retain the pre-reduction buckets in an immutable
canonical snapshot. Later composition, quotient, and CAVE elimination consume
that snapshot, while a/g and Unicode presentation retain the compact
reduced view. The optional versioned gr1_operation_buckets serialization
section preserves this distinction across round trips; older dictionaries use
their stored buckets as the canonical fallback.
Persistence and behavior checks¶
Human-facing bounded-next text is the primary serialized representation.
Versioned gr1_machine data preserves Z3-generated QE formulas that no
longer have a parser AST, together with explicit variable sorts, so contracts
round-trip after elimination and renaming.
:class:GR1Behavior represents either a finite trace or an ultimately
periodic lasso. INIT and every complete invariant window can be checked on a
finite trace. Liveness has trace semantics only when loop_start identifies
the repeating suffix. Emptiness is intentionally conservative: inconsistent
initial constraints are detected by SMT, while full infinite-state GR(1)
realizability is outside the scope of :meth:GR1TermList.is_empty.
GR1Behavior
dataclass
¶
A finite trace or an ultimately-periodic lasso used for behavior checks.
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
__post_init__()
¶
Validate the nonempty trace and optional repeating-suffix index.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the supplied value is invalid. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
GR1CoreFormula
dataclass
¶
Non-temporal core formula φ.
Use: - of(...) -> text-only formulas - of_expr(...) -> Z3-backed formulas, required for elimination - parse_gr1_core(...) -> parse a typed user-facing bounded-next formula
The only temporal operator allowed inside cores is Next, and it should be
flattened before manually creating a Z3 expression. GR1CoreParser performs
this flattening for string input. User text uses q and X(q);
q_0 and q_1 are reserved for the corresponding internal Z3
constants. Generated text is unflattened again for presentation while
expr and vars retain the exact machine-level symbols.
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 | |
vars
property
¶
Return flattened variables in deterministic name order.
Returns:
| Type | Description |
|---|---|
List[Var]
|
The computed List[Var] result. |
__str__()
¶
Return the readable core formula.
Returns:
| Type | Description |
|---|---|
str
|
The computed str result. |
contains_var(v)
¶
Return whether the exact flattened variable occurs in this core.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
Var
|
V. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The computed bool result. |
false()
staticmethod
¶
Return the variable-free unsatisfiable core.
Returns:
| Type | Description |
|---|---|
'GR1CoreFormula'
|
The computed 'GR1CoreFormula' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
of(text, vars, expr=None, syntax=None, raw_expr=None, serialized_machine=None, next_depth=0)
staticmethod
¶
Build a core, optionally attaching an expression and parser AST.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Human-readable formula text. |
required |
vars
|
Iterable[Var]
|
Variables occurring in the formula. |
required |
expr
|
Optional[Any]
|
Z3 expression to process. |
None
|
syntax
|
Optional[GR1SyntaxNode]
|
Optional parsed syntax tree. |
None
|
raw_expr
|
Optional[Any]
|
Original solver/QE expression retained for debugging. |
None
|
serialized_machine
|
Optional[Dict[str, Any]]
|
Optional serialized machine representation. |
None
|
next_depth
|
int
|
Original finite-window depth before simplification. |
0
|
Returns:
| Type | Description |
|---|---|
'GR1CoreFormula'
|
The computed 'GR1CoreFormula' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
of_expr(text, vars, expr, syntax=None, raw_expr=None, serialized_machine=None, next_depth=0)
staticmethod
¶
Build a core that is guaranteed to have a Z3 expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Human-readable formula text. |
required |
vars
|
Iterable[Var]
|
Variables occurring in the formula. |
required |
expr
|
Any
|
Z3 expression to process. |
required |
syntax
|
Optional[GR1SyntaxNode]
|
Optional parsed syntax tree. |
None
|
raw_expr
|
Optional[Any]
|
Original solver/QE expression retained for debugging. |
None
|
serialized_machine
|
Optional[Dict[str, Any]]
|
Optional serialized machine representation. |
None
|
next_depth
|
int
|
Original finite-window depth before simplification. |
0
|
Returns:
| Type | Description |
|---|---|
'GR1CoreFormula'
|
The computed 'GR1CoreFormula' result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the supplied value is invalid. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
rename_variable(source, target)
¶
Rename a base variable structurally in text, AST, and every Z3 depth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Var
|
Source variable or name. |
required |
target
|
Var
|
Target variable, name, or obligation. |
required |
Returns:
| Type | Description |
|---|---|
'GR1CoreFormula'
|
The computed 'GR1CoreFormula' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
true()
staticmethod
¶
Return the variable-free tautological core.
Returns:
| Type | Description |
|---|---|
'GR1CoreFormula'
|
The computed 'GR1CoreFormula' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
GR1CoreParser
¶
Parse typed bounded-next core formulas into flattened Z3 expressions.
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 | |
__init__(variable_sorts)
¶
Initialize from explicit name -> bool/int/real declarations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_sorts
|
Dict[str, Any]
|
Declared sort for each base variable. |
required |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
parse(formula_text)
¶
Parse one Boolean core, flattening nested X/next applications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula_text
|
str
|
User-facing bounded-next formula. |
required |
Returns:
| Type | Description |
|---|---|
'GR1CoreFormula'
|
The computed 'GR1CoreFormula' result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the supplied value is invalid. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
GR1IoContract
¶
Bases: IoContract[GR1TermList]
GR(1) IO contract whose assumptions and guarantees are GR1TermLists.
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 | |
__copy__()
¶
Return an independent copy including canonical operation buckets.
Returns:
| Type | Description |
|---|---|
'GR1IoContract'
|
Independent contract copy. |
__deepcopy__(memo)
¶
Return an independent deep copy including canonical operation buckets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memo
|
Dict[int, Any]
|
Deep-copy memoization dictionary. |
required |
Returns:
| Type | Description |
|---|---|
'GR1IoContract'
|
Independent contract copy. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
__init__(assumptions, guarantees, input_vars, output_vars, simplify=None, variable_sorts=None)
¶
Build a contract and validate or infer its persistent sort table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
assumptions
|
GR1TermList
|
Assumptions. |
required |
guarantees
|
GR1TermList
|
Guarantees. |
required |
input_vars
|
List[Var]
|
Input vars. |
required |
output_vars
|
List[Var]
|
Output vars. |
required |
simplify
|
Optional[bool]
|
Whether to simplify the supplied formulas. Internal operation construction inherits the operation's explicit raw versus final setting. |
None
|
variable_sorts
|
Optional[Dict[str, Any]]
|
Declared sort for each base variable. |
None
|
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
__str__()
¶
Return the normal bucket-oriented user-facing representation.
Returns:
| Type | Description |
|---|---|
str
|
User-facing contract text. |
canonical_debug_dump()
¶
Return canonical operation buckets without changing stored buckets.
Returns:
| Type | Description |
|---|---|
str
|
Canonical debug representation. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
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. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
compose_tactics(other, vars_to_keep=None, simplify=True, tactics_order=None)
¶
Compose while exposing elimination tactic statistics.
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
|
tactics_order
|
Optional[List[int]]
|
Preferred quantifier-elimination tactic order. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple['GR1IoContract', List[TacticStatistics]]
|
The computed Any result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
copy()
¶
Copy the contract while preserving declarations for unused variables.
Returns:
| Type | Description |
|---|---|
'GR1IoContract'
|
The computed 'GR1IoContract' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
debug_dump()
¶
Return bucketed raw solver/QE expressions for diagnostics.
Returns:
| Type | Description |
|---|---|
str
|
Diagnostic contract text. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
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. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
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. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
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. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
presentation_view(candidate_assumptions=None, candidate_guarantees=None, assumption_relative=True)
¶
Return detached, SMT-certified buckets intended only for rendering.
Automatic candidates use inexpensive Z3 tactics and Boolean-mode consequence mining. Optional caller candidates are hints, not trusted replacements: assumption safety buckets require unconditional equivalence, and guarantee safety buckets require equivalence under the appropriate shifted contract assumptions. LIV hints are deliberately ignored so distinct justice obligations cannot be synchronized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidate_assumptions
|
Optional[GR1TermList]
|
Optional proposed assumption presentation. |
None
|
candidate_guarantees
|
Optional[GR1TermList]
|
Optional proposed guarantee presentation. |
None
|
assumption_relative
|
bool
|
Whether guarantees are reduced under assumptions. |
True
|
Returns:
| Type | Description |
|---|---|
Tuple[GR1TermList, GR1TermList]
|
Detached assumption and guarantee presentation lists. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
pretty(annotate_redundancy=True)
¶
Return a sectioned bucket view using explicit G and GF.
Canonical expressions are split into readable conjunction lines. INIT guarantee atoms already implied by assumptions are omitted from this view only. Stored semantics and serialization remain unchanged. A LIV guarantee established by assumption INV/LIV support is retained but may be annotated as redundant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotate_redundancy
|
bool
|
Mark assumption-established liveness terms. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Human-readable contract text. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
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. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
quotient_tactics(other, additional_inputs=None, simplify=True, tactics_order=None)
¶
Compute a quotient while exposing tactic statistics.
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
|
tactics_order
|
Optional[List[int]]
|
Preferred quantifier-elimination tactic order. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple['GR1IoContract', List[TacticStatistics]]
|
The computed Tuple['GR1IoContract', List[TacticStatistics]] result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
rename_variable(source_var, target_var)
¶
Rename one base interface variable and all of its flattened copies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_var
|
Var
|
Source var. |
required |
target_var
|
Var
|
Target var. |
required |
Returns:
| Type | Description |
|---|---|
'GR1IoContract'
|
The computed 'GR1IoContract' result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If serialized data or variable sorts are invalid. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
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. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
to_dict()
¶
Serialize readable buckets, sorts, and versioned generated expressions.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
The computed Dict[str, Any] result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
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. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
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. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 | |
GR1NextFlattener
¶
Helper for constructing GR(1) core formulas with a syntactic next operator X.
Standard flattened naming convention
p is internally treated as p_0 X(p) becomes p_1 X(X(p)) becomes p_2
Example
fl = GR1NextFlattener() P = fl.Bool("p") Q = fl.Bool("q")
expr = fl.X(z3.And(P, fl.X(Q))) core = fl.core("X(p & X(q))", expr)
The expression above is flattened as
And(p_1, q_2)
Notes
- X only shifts uninterpreted constants appearing in the Z3 expression.
- It preserves the Z3 sort of each variable.
- The result is a normal GR1CoreFormula with explicit flattened Vars.
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 | |
Bool(name)
¶
Create and return the current-time Boolean name_0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variable name. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The computed Any result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
Int(name)
¶
Create and return the current-time integer name_0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variable name. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The computed Any result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
Real(name)
¶
Create and return the current-time real name_0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Variable name. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The computed Any result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
X(expr)
¶
Syntactic next operator.
Shifts every flattened variable in expr forward by one time step.
Examples:
X(p_0) = p_1 X(q_1) = q_2 X(p_0 & q_1) = p_1 & q_2
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
Any
|
Z3 expression to process. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The computed Any result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
__init__(*, current_suffix='_0', next_separator='_')
¶
Create a flattener with configurable current and depth separators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_suffix
|
str
|
Suffix representing the current state. |
'_0'
|
next_separator
|
str
|
Separator used before a next-state index. |
'_'
|
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
core(text, expr)
¶
Build a GR1CoreFormula from a flattened Z3 expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Human-readable formula text. |
required |
expr
|
Any
|
Z3 expression to process. |
required |
Returns:
| Type | Description |
|---|---|
'GR1CoreFormula'
|
The computed 'GR1CoreFormula' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
GR1SolverError
¶
GR1SyntaxNode
dataclass
¶
Immutable user-facing AST for a bounded-next GR(1) core.
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 | |
next_depth(depth=0)
¶
Return the greatest Next nesting preceding a variable leaf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depth
|
int
|
Current nesting depth. |
0
|
Returns:
| Type | Description |
|---|---|
int
|
Maximum Next depth. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
rename(source, target)
¶
Structurally rename exact variable leaves, including below X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source variable or name. |
required |
target
|
str
|
Target variable, name, or obligation. |
required |
Returns:
| Type | Description |
|---|---|
'GR1SyntaxNode'
|
The computed 'GR1SyntaxNode' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
to_text()
¶
Render canonical, user-facing bounded-next formula text.
Returns:
| Type | Description |
|---|---|
str
|
The computed str result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the supplied value is invalid. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
to_z3(variable_sorts, depth=0, expected_sort=None)
¶
Compile to Z3, flattening variables relative to depth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable_sorts
|
Dict[str, Any]
|
Declared sort for each base variable. |
required |
depth
|
int
|
Bounded-next depth. |
0
|
expected_sort
|
Optional[Any]
|
Expected sort inherited from the parent expression. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The computed Any result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the supplied value is invalid. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
GR1Tag
¶
Bases: str, Enum
Temporal bucket tags for initial, invariant, and liveness formulas.
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
GR1Term
dataclass
¶
Bases: Term
A single GR(1) term = (tag, core).
Semantics
Init
φ INV: □φ LIV: □◇φ
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 | |
vars
property
¶
Expose base interface variables rather than flattened instances.
Returns:
| Type | Description |
|---|---|
List[Var]
|
The computed List[Var] result. |
__eq__(other)
¶
Compare both temporal tag and core formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
Other term list or contract. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The computed Any result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
__hash__()
¶
Hash consistently with structural term equality.
Returns:
| Type | Description |
|---|---|
int
|
The computed Any result. |
__repr__()
¶
Return a concise debugging representation.
Returns:
| Type | Description |
|---|---|
str
|
The computed str result. |
__str__()
¶
Render the core together with its implicit temporal operator.
Returns:
| Type | Description |
|---|---|
str
|
The computed str result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
contains_var(var_to_seek)
¶
Test relevance by exact or base-variable name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var_to_seek
|
Var
|
Var to seek. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The computed bool result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
copy()
¶
Copy the immutable term while preserving AST and Z3 data.
Returns:
| Type | Description |
|---|---|
'GR1Term'
|
The computed 'GR1Term' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
rename_variable(source_var, target_var)
¶
Rename one base variable throughout the term's core.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_var
|
Var
|
Source var. |
required |
target_var
|
Var
|
Target var. |
required |
Returns:
| Type | Description |
|---|---|
'GR1Term'
|
The computed 'GR1Term' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
GR1TermList
¶
Bases: TermList
A conjunction of GR(1) terms.
Multiple LIV terms remain separate
LIV(φ1), LIV(φ2) means □◇φ1 ∧ □◇φ2,
not □◇(φ1 ∧ φ2).
Simplification canonicalizes only uniform global Next shifts of LIV cores; INIT and INV retain their original depths.
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 | |
__hash__()
¶
Hash the ordered conjunction of terms.
Returns:
| Type | Description |
|---|---|
int
|
The computed int result. |
__init__(term_list=None)
¶
Initialize from tagged terms; an omitted list denotes true.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
term_list
|
Optional[List[GR1Term]]
|
Term list. |
None
|
contains_behavior(behavior)
¶
Check a finite trace or ultimately-periodic lasso against this GR(1) list.
A plain sequence is interpreted as a finite prefix and can check INIT
and every complete INV window. LIV requires ``GR1Behavior`` with a
``loop_start``, because recurrence cannot be established by a finite
prefix. On a lasso, each liveness core must occur in the repeating loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
behavior
|
Any
|
Behavior or trace to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The computed bool result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
copy()
¶
Copy every term while preserving bucket order.
Returns:
| Type | Description |
|---|---|
'GR1TermList'
|
The computed 'GR1TermList' result. |
elim_vars_by_refining(context, vars_to_elim, simplify, tactics_order)
¶
SMT-style refinement elimination for GR(1).
INIT
forall p. [gamma_init ∧ Gamma_inv^[0:h_B] => phi_init], B={gamma_init, phi_init}
INV
forall p. [Gamma_inv^[0:h_B] => phi_inv], B={phi_inv}
Every LIV target, including elimination-free targets: construct GF(psi_i,0) from the invariant window alone, and G(psi_i,j) from the window and each context liveness core j. Synthetic horizon: d(phi_i); genuine: max(d(phi_i), d(gamma_liv,j)). Project every branch before deterministic tag-preserving selection. No relevance, viability, or mixed-wrapper dominance filtering occurs.
Context liveness terms are processed separately and are not conjoined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
'GR1TermList'
|
Context used by the operation. |
required |
vars_to_elim
|
List[Var]
|
Variables to eliminate. |
required |
simplify
|
bool
|
Whether to simplify the resulting formulas. |
required |
tactics_order
|
List[int]
|
Preferred quantifier-elimination tactic order. |
required |
Returns:
| Type | Description |
|---|---|
Tuple['GR1TermList', TacticStatistics]
|
The computed Tuple['GR1TermList', TacticStatistics] result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
elim_vars_by_refining_quotient_context(divisor_guarantees, system_assumptions, vars_to_elim, simplify, tactics_order)
¶
Refine canonical targets using canonical divisor guarantees.
System assumptions are deliberately not merged into this first CAVE
context: generic quotient processes them in its following refinement
pass. Merging them here changes canonical cores (for example r=q)
into guarded predicates (p -> r) before GR(1) bucket rules run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
divisor_guarantees
|
'GR1TermList'
|
Divisor guarantees. |
required |
system_assumptions
|
'GR1TermList'
|
System assumptions. |
required |
vars_to_elim
|
List[Var]
|
Variables to eliminate. |
required |
simplify
|
bool
|
Whether to simplify the resulting formulas. |
required |
tactics_order
|
List[int]
|
Preferred quantifier-elimination tactic order. |
required |
Returns:
| Type | Description |
|---|---|
Tuple['GR1TermList', TacticStatistics]
|
The computed Tuple['GR1TermList', TacticStatistics] result. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
divisor_guarantees
|
'GR1TermList'
|
Guarantees of the known component. |
required |
system_assumptions
|
'GR1TermList'
|
Assumptions of the target system. |
required |
vars_to_elim
|
List[Var]
|
Variables to eliminate. |
required |
simplify
|
bool
|
Whether to simplify before elimination. |
required |
tactics_order
|
List[int]
|
Ordered tactic identifiers. |
required |
Returns:
| Type | Description |
|---|---|
Tuple['GR1TermList', TacticStatistics]
|
The projected terms and tactic statistics. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
elim_vars_by_relaxing(context, vars_to_elim, simplify, tactics_order)
¶
SMT-style relaxation elimination for GR(1).
INIT
exists p. [gamma_init ∧ Gamma_inv^[0:h_B] ∧ phi_init], B={gamma_init, phi_init}
INV
exists p. [Gamma_inv^[0:h_B] ∧ phi_inv], B={phi_inv}, stored as INV
LIV
project every context and target liveness core separately, discard trivial projections, and remove equivalent or implied cores.
The remaining projected liveness terms remain separate LIV conjuncts. An empty INV bucket is true and still projects the invariant context. With simplify=False this returns the raw independently decomposed CAVE construction. With simplify=True it subsequently reduces obligations relative to context; standalone strongestness concerns the raw result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
'GR1TermList'
|
Context used by the operation. |
required |
vars_to_elim
|
List[Var]
|
Variables to eliminate. |
required |
simplify
|
bool
|
Whether to simplify the resulting formulas. |
required |
tactics_order
|
List[int]
|
Preferred quantifier-elimination tactic order. |
required |
Returns:
| Type | Description |
|---|---|
Tuple['GR1TermList', TacticStatistics]
|
The computed Tuple['GR1TermList', TacticStatistics] result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
elim_vars_by_relaxing_assumptions(context, vars_to_elim, simplify, tactics_order)
¶
Preserve canonical buckets across redundant assumption saturation.
Generic composition performs a final guarantee relaxation in the composed assumption context. If neither the target nor context still mentions a variable to hide, conjoining that context is redundant at contract level but replaces canonical GR(1) cores with saturated Boolean encodings. Keep the canonical cores in that case. If hiding is still required, use ordinary GR(1) relaxation because assumptions may be essential to the projection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
'GR1TermList'
|
Context used by the operation. |
required |
vars_to_elim
|
List[Var]
|
Variables to eliminate. |
required |
simplify
|
bool
|
Whether to simplify the resulting formulas. |
required |
tactics_order
|
List[int]
|
Preferred quantifier-elimination tactic order. |
required |
Returns:
| Type | Description |
|---|---|
Tuple['GR1TermList', TacticStatistics]
|
The computed Tuple['GR1TermList', TacticStatistics] result. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
'GR1TermList'
|
Context constraining the elimination. |
required |
vars_to_elim
|
List[Var]
|
Variables to eliminate. |
required |
simplify
|
bool
|
Whether to simplify before elimination. |
required |
tactics_order
|
List[int]
|
Ordered tactic identifiers. |
required |
Returns:
| Type | Description |
|---|---|
Tuple['GR1TermList', TacticStatistics]
|
The projected terms and tactic statistics. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 | |
elim_vars_by_relaxing_quotient_context(context, vars_to_elim, simplify, tactics_order)
¶
Project quotient assumptions with shift-closed divisor guarantees.
Keeping self as the target and divisor guarantees as context
lets the ordinary GR(1) INV rule construct Gamma_inv^[0:h] through the
target horizon instead of losing provenance in a prior TermList union.
INIT and separate LIV projection use the same canonical buckets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
'GR1TermList'
|
Context used by the operation. |
required |
vars_to_elim
|
List[Var]
|
Variables to eliminate. |
required |
simplify
|
bool
|
Whether to simplify the resulting formulas. |
required |
tactics_order
|
List[int]
|
Preferred quantifier-elimination tactic order. |
required |
Returns:
| Type | Description |
|---|---|
Tuple['GR1TermList', TacticStatistics]
|
The computed Tuple['GR1TermList', TacticStatistics] result. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
'GR1TermList'
|
Context constraining the elimination. |
required |
vars_to_elim
|
List[Var]
|
Variables to eliminate. |
required |
simplify
|
bool
|
Whether to simplify before elimination. |
required |
tactics_order
|
List[int]
|
Ordered tactic identifiers. |
required |
Returns:
| Type | Description |
|---|---|
Tuple['GR1TermList', TacticStatistics]
|
The projected terms and tactic statistics. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
from_bucket_formulas(*, init=None, inv=None, liv=None)
staticmethod
¶
Construct a GR1TermList from formulas grouped by bucket.
Multiple formulas in each bucket are conjunctive. In particular, multiple liveness formulas remain separate liveness terms: ∧_i □◇φ_i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init
|
Optional[List[GR1CoreFormula]]
|
Initial-condition formulas. |
None
|
inv
|
Optional[List[GR1CoreFormula]]
|
Invariant formulas. |
None
|
liv
|
Optional[List[GR1CoreFormula]]
|
Liveness formulas. |
None
|
Returns:
| Type | Description |
|---|---|
'GR1TermList'
|
The computed 'GR1TermList' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
from_bucket_strings(*, init=None, inv=None, liv=None, var_map=None, variable_sorts=None)
staticmethod
¶
Convenience constructor when formulas are strings.
With variable_sorts, formulas are parsed into Z3-backed bounded-next
cores. Without it, var_map preserves the legacy text-only behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init
|
Optional[List[str]]
|
Initial-condition formulas. |
None
|
inv
|
Optional[List[str]]
|
Invariant formulas. |
None
|
liv
|
Optional[List[str]]
|
Liveness formulas. |
None
|
var_map
|
Optional[FormulaVarMap]
|
Mapping from formula text to variable names. |
None
|
variable_sorts
|
Optional[VariableSortMap]
|
Declared sort for each base variable. |
None
|
Returns:
| Type | Description |
|---|---|
'GR1TermList'
|
The computed 'GR1TermList' result. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the supplied value is invalid. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
get_terms_with_vars(vars_to_seek)
¶
Return terms mentioning any sought base variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vars_to_seek
|
List[Var]
|
Vars to seek. |
required |
Returns:
| Type | Description |
|---|---|
'GR1TermList'
|
The computed 'GR1TermList' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
init_terms()
¶
Return initial-state terms in their existing order.
Returns:
| Type | Description |
|---|---|
List[GR1Term]
|
The computed List[GR1Term] result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
inv_terms()
¶
Return invariant terms in their existing order.
Returns:
| Type | Description |
|---|---|
List[GR1Term]
|
The computed List[GR1Term] result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
is_empty()
¶
Return True when finite-window SMT checks prove no infinite behavior.
The checks cover inconsistent initial/invariant cores and liveness cores
that cannot occur under the invariant. False is conservative for harder
overlap-consistency cases not decided by these finite checks.
Returns:
| Type | Description |
|---|---|
bool
|
The computed bool result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
liv_terms()
¶
Return separate liveness terms in their existing order.
Returns:
| Type | Description |
|---|---|
List[GR1Term]
|
The computed List[GR1Term] result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
refines(other)
¶
Sufficient GR(1) refinement check using Z3 expressions.
INIT first uses pointwise implication, then a bounded iterative
shift-closure of only the antecedent/source invariant terms.
INV uses the same bounded source-closure proof strategy. An UNSAT
finite-window certificate is sound; SAT means only that refinement
was not proved within the budget.
LIV is checked separately. Every target liveness term must be
established either by a pointwise-stronger source liveness core or by
a bounded iterative shift-closure of the source invariant bucket.
It also combines that closure with each source LIV core (W8).
Closure alone proves the target globally and therefore recurrently.
Its finite horizon is a proof-search budget, not a completeness bound.
This remains a structured sufficient GR(1) check, not a general LTL
implication solver. In particular, separate source liveness terms are
never conjoined inside one ``GF`` obligation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
'GR1TermList'
|
Other term list or contract. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The computed bool result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
simplify(context=None)
¶
Apply post-CAVE redundancy and optional assumption-relative reduction.
Exact CAVE evaluation precedes this method. Internal reduction first removes redundancies within and across this term list's GR(1) buckets; a supplied context is then used separately for assume-guarantee redundancy. Neither stage changes the six CAVE formulas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Optional['GR1TermList']
|
Context used by the operation. |
None
|
Returns:
| Type | Description |
|---|---|
'GR1TermList'
|
The computed 'GR1TermList' result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
to_bucket_dict()
¶
Serialize readable formula text grouped by temporal bucket.
Returns:
| Type | Description |
|---|---|
Dict[str, List[str]]
|
The computed Dict[str, List[str]] result. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
to_pretty_string(compact=False)
¶
Return a read-only Unicode rendering of this GR(1) term list.
Every INIT core is listed separately, every INV core receives its own
□, and every LIV core retains its own □◇ operator. Empty
bucket-view sections are omitted; a completely empty list renders as
true. No terms, formulas, metadata, or serialization are changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compact
|
bool
|
Return one semantic conjunction instead of bucket lines. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Unicode user-facing GR(1) text. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
canonicalize_mixed_linear_formula(expr, max_boolean_variables=3)
¶
Canonicalize a small Boolean-conditioned rectangular linear formula.
Boolean variables are enumerated up to max_boolean_variables. In each
satisfiable valuation, exact Optimize bounds are extracted for every
remaining Int/Real variable. The valuation is accepted only when the
resulting conjunction of intervals is equivalent to that cofactor. Global
envelope bounds are factored out and tighter per-mode bounds are rebuilt as
implications. Finally, the complete candidate is equivalence-checked.
The deliberately narrow implementation handles the common QE result in which every Boolean mode selects an axis-aligned interval or box. It is not a general linear-arithmetic or Boolean minimizer. Unsupported sorts, nonlinear/non-rectangular regions, strict/open bounds, excessive Boolean variables, or inconclusive checks return the original expression unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
Any
|
Quantifier-free Z3 Boolean expression. |
required |
max_boolean_variables
|
int
|
Maximum number of Boolean valuations to enumerate. |
3
|
Returns:
| Type | Description |
|---|---|
Any
|
A compact equivalent formula, or the original formula on fallback. |
Source code in pacti/src/pacti/iocontract/gr1_iocontract.py
parse_gr1_core(formula_text, variable_sorts)
¶
Parse a user-facing bounded-next formula into a Z3-backed GR(1) core.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula_text
|
str
|
User-facing bounded-next formula. |
required |
variable_sorts
|
Dict[str, Any]
|
Declared sort for each base variable. |
required |
Returns:
| Type | Description |
|---|---|
'GR1CoreFormula'
|
The computed 'GR1CoreFormula' result. |