Skip to content

Commit a906f53

Browse files
committed
more wip on until implies eventually
1 parent ba192d5 commit a906f53

File tree

6 files changed

+91
-6
lines changed

6 files changed

+91
-6
lines changed

prover/lang/kore-lang.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,15 @@ only in this scenario*.
141141
```k
142142
syntax Variable ::= VariableName "{" Sort "}" [klabel(sortedVariable)]
143143
syntax SetVariable ::= SharpName [klabel(setVariable)]
144+
syntax Context ::= VariableName "[" Pattern "]" [klabel(context)]
144145
syntax Pattern ::= Int
145146
| Variable
146147
| SetVariable
147148
| Symbol
148149
| Symbol "(" Patterns ")" [klabel(apply)]
149150
151+
| Context
152+
150153
| "\\top" "(" ")" [klabel(top)]
151154
| "\\bottom" "(" ")" [klabel(bottom)]
152155
| "\\equals" "(" Pattern "," Pattern ")" [klabel(equals)]
@@ -326,8 +329,8 @@ module KORE-HELPERS
326329
327330
rule getReturnSort(\exists{Vs} P) => getReturnSort(P)
328331
329-
syntax Sort ::= "TopSort" [token]
330-
| "BottomSort" [token]
332+
syntax UpperName ::= "TopSort" [token]
333+
| "BottomSort" [token]
331334
332335
syntax Sort ::= unionSort(Sort, Sort) [function]
333336
rule unionSort(TopSort, S) => TopSort
@@ -771,10 +774,10 @@ Simplifications
771774
772775
// TODO: This should use an axiom, similar to `functional` instead: `axiom predicate(P)`
773776
rule isPredicatePattern(S:Symbol(ARGS)) => true
774-
requires getReturnSort(S(ARGS)) =/=K Heap
777+
requires getReturnSort(S(ARGS)) ==K Bool
775778
776779
rule isPredicatePattern(S:Symbol(ARGS)) => false
777-
requires getReturnSort(S(ARGS)) ==K Heap
780+
requires getReturnSort(S(ARGS)) =/=K Bool
778781
rule isPredicatePattern(emp(.Patterns)) => false
779782
rule isPredicatePattern(\exists{Vs} P) => isPredicatePattern(P)
780783
rule isPredicatePattern(\forall{Vs} P) => isPredicatePattern(P)
@@ -795,6 +798,8 @@ Simplifications
795798
rule isSpatialPattern(\or(_)) => false
796799
rule isSpatialPattern(S:Symbol(ARGS)) => true
797800
requires S =/=K sep andBool getReturnSort(S(ARGS)) ==K Heap
801+
rule isSpatialPattern(S:Symbol(ARGS)) => false
802+
requires getReturnSort(S(ARGS)) =/=K Heap
798803
rule isSpatialPattern(#hole { Bool }) => false
799804
rule isSpatialPattern(#hole { Heap }) => true
800805
rule isSpatialPattern(V:VariableName { Heap }) => true
@@ -856,6 +861,7 @@ Simplifications
856861
rule hasImplicationContext(\functionalPattern(P)) => hasImplicationContext(P)
857862
rule hasImplicationContext(\exists{ _ } P ) => hasImplicationContext(P)
858863
rule hasImplicationContext(\forall{ _ } P ) => hasImplicationContext(P)
864+
rule hasImplicationContext(\mu X . P) => hasImplicationContext(P)
859865
rule hasImplicationContext(implicationContext(_, _)) => true
860866
rule hasImplicationContextPs(.Patterns) => false
861867
rule hasImplicationContextPs(P, Ps)

prover/strategies/knaster-tarski.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,9 @@ Move #holes to the front
384384
```
385385

386386
```k
387-
rule <k> \implies(\and( \forall { UNIVs } implicationContext( \and(#hole { SORT }, _) , _ ) , _ ) , _ ) </k>
387+
rule <k> \implies(\and( \forall { UNIVs } implicationContext( \and(#hole { Bool }, _) , _ ) , _ ) , _ ) </k>
388+
<strategy> normalize-implication-context => noop ... </strategy>
389+
rule <k> \implies(\and( S:Symbol(\forall { UNIVs } implicationContext( \and(#hole { TopSort }, _) , _ )) , _ ) , _ ) </k>
388390
<strategy> normalize-implication-context => noop ... </strategy>
389391
rule <k> \implies(\and( sep(\forall { UNIVs } implicationContext( \and(sep(#hole { Heap }, _), _) , _ ) , _ ), _ ), _ ) </k>
390392
<strategy> normalize-implication-context => noop ... </strategy>
@@ -496,6 +498,50 @@ of heaps.
496498
</strategy>
497499
```
498500

501+
```k
502+
syntax UpperName ::= "#rest" [token]
503+
rule <k> \implies( \and( S:Symbol ( \forall { UNIVs }
504+
implicationContext(\and(CTXLHS), CTXRHS)
505+
)
506+
, LHS:Patterns
507+
)
508+
, RHS:Pattern
509+
)
510+
</k>
511+
<strategy> kt-collapse
512+
=> with-each-match( #matchAssoc( terms: S( #hole { TopSort } )
513+
, pattern: #rest[CTXLHS]
514+
, variables: #rest { TopSort }
515+
, subst: .Map
516+
, rest: .Patterns
517+
)
518+
, kt-collapse
519+
, kt-collapse-no-match
520+
)
521+
...
522+
</strategy>
523+
```
524+
525+
```k
526+
rule <k> \implies( \and( S:Symbol ( \forall { .Patterns }
527+
implicationContext( \and(_), CTXRHS )
528+
)
529+
, LHS:Patterns
530+
)
531+
, RHS:Pattern
532+
)
533+
=> \implies( \and( subst({SUBST[#rest { TopSort }]}:>Pattern, #hole { TopSort }, CTXRHS)
534+
, LHS
535+
)
536+
, RHS
537+
)
538+
</k>
539+
<strategy> ( #matchResult(subst: SUBST, rest: .Patterns) ~> kt-collapse )
540+
=> noop
541+
...
542+
</strategy>
543+
```
544+
499545
In the context of the heuristics we implement, this becomes the following, where
500546
REST is obtained via matching:
501547

prover/strategies/matching.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ Work around OCaml not producing reasonable error messages:
9191
Recurse over assoc-only constructors (including `pto`):
9292

9393
```k
94+
// TODO: matching over context patterns
95+
rule #matchAssoc( terms: S:Symbol(T), .Patterns
96+
, pattern: V[T], .Patterns
97+
, variables: Vs
98+
, subst: SUBST
99+
, rest: REST
100+
)
101+
=> #matchResult( subst: SUBST V { getReturnSort(S(T)) } |-> S( #hole { getReturnSort(T) })
102+
, rest: .Patterns
103+
)
104+
, .MatchResults
105+
requires V { getReturnSort(S(T)) } in Vs
106+
94107
// Base case
95108
rule #matchAssoc( terms: .Patterns
96109
, pattern: .Patterns

prover/strategies/simplification.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ Bring predicate constraints to the top of a term.
341341
342342
syntax Pattern ::= #liftConstraints(Pattern) [function]
343343
syntax Patterns ::= #liftConstraintsPs(Patterns) [function]
344+
// rule #liftConstraints(S:Symbol(\and(P1, P2, Ps), ARGs)) => #liftConstraints(\and(S(P1, ARGs), S(\and(P2, Ps), ARGs)))
345+
// rule #liftConstraints(S:Symbol(\and(P, .Patterns), ARGs)) => #liftConstraints(\and(S(P, ARGs)))
344346
rule #liftConstraints(\and(Ps)) => \and(#liftConstraintsPs(Ps))
345347
rule #liftConstraintsPs(.Patterns) => .Patterns
346348
rule #liftConstraintsPs(sep(\and(.Patterns), .Patterns), REST) => #liftConstraintsPs(REST)

prover/t/ltl/until-implies-eventually.kore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ right-unfold-Nth(0, 1)
3737
phi-implies-phi
3838
*/
3939

40-
strategy normalize . kt . right-unfold-Nth(0, 0) . normalize . patterns-equal . rhs-top
40+
strategy normalize . kt . ( ( right-unfold-Nth(0, 0) . normalize . patterns-equal . rhs-top )
41+
| ( right-unfold-Nth(0, 1) . normalize . lift-constraints . wait . patterns-equal . rhs-top )
42+
)

prover/t/unit/match-assoc.k

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ module TEST-MATCH-ASSOC
110110
// Match constructor against variable
111111
rule test("match-assoc", 9)
112112
=> symbol pto ( Loc, Data ) : Heap
113+
symbol c ( Data ) : Data
113114
assert( #error("Constructors do not match")
114115
, .MatchResults
115116
== #matchAssoc( terms: X0 { Loc }, Y0 { Data }
@@ -120,4 +121,19 @@ module TEST-MATCH-ASSOC
120121
)
121122
)
122123
.Declarations
124+
// Match multiple occurances of a variable
125+
rule test("match-assoc", 10)
126+
=> symbol c ( Data ) : Data
127+
assert( #matchResult( subst: X0 |-> c( #hole { Data } )
128+
, rest: .Patterns
129+
)
130+
, .MatchResults
131+
== #matchAssoc( terms: c( W { Data } )
132+
, pattern: X0[W { Data }]
133+
, variables: X0 { Data }
134+
, subst: .Map
135+
, rest: .Patterns
136+
)
137+
)
138+
.Declarations
123139
endmodule

0 commit comments

Comments
 (0)