Skip to content

Commit e5a79fc

Browse files
authored
Add uninterpreted Set implementation to Prelude.lean (#4738)
Tackling #4725, this PR adds an uninterpreted implementation for the `Set` sort.
1 parent 9be6e60 commit e5a79fc

File tree

2 files changed

+60
-12
lines changed

2 files changed

+60
-12
lines changed

pyk/src/pyk/k2lean4/Prelude.lean

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,73 @@ axiom nodupAx : forall m, List.Nodup (keysAx K m)
8181
noncomputable def MapHook (K V : Type) : MapHookSig K V :=
8282
{ map := mapCAx,
8383
unit := unitAx,
84-
cons := (consAx K V),
85-
lookup := (lookupAx K V),
86-
lookup? := (lookupAx? K V),
87-
update := (updateAx K V),
88-
delete := (deleteAx K),
84+
cons := consAx K V,
85+
lookup := lookupAx K V,
86+
lookup? := lookupAx? K V,
87+
update := updateAx K V,
88+
delete := deleteAx K,
8989
concat := concatAx,
9090
difference := differenceAx,
9191
updateMap := updateMapAx,
92-
removeAll := (removeAllAx K),
93-
keys := (keysAx K),
94-
in_keys := (in_keysAx K),
95-
values := (valuesAx V),
92+
removeAll := removeAllAx K,
93+
keys := keysAx K,
94+
in_keys := in_keysAx K,
95+
values := valuesAx V,
9696
size := sizeAx,
9797
includes := includesAx,
98-
choice := (choiceAx K),
99-
nodup := (nodupAx K) }
98+
choice := choiceAx K,
99+
nodup := nodupAx K }
100100

101101
end MapHookDef
102102

103+
namespace SetHookDef
104+
/-
105+
Implementation of immutable, associative, commutative sets of `KItem`.
106+
The sets are nilpotent, i.e., the concatenation of two sets containing elements in common is `#False` (note however, this may be silently allowed during concrete execution).
107+
If you intend to add an element to a set that might already be present in the set, use the `|Set` operator instead.
108+
-/
109+
110+
structure SetHookSig (T : Type) where
111+
set : Type -- Carrier, such as `T → Prop`
112+
unit : set
113+
concat : set → set → Option set
114+
setItem : T → set
115+
union : set → set → set
116+
intersection : set → set → set
117+
difference : set → set → set
118+
inSet : T → set → Bool
119+
inclusion : set → set → Bool
120+
size : set → Int
121+
choice : set → T
122+
123+
variable (T : Type)
124+
axiom setCAx : Type
125+
axiom unitAx : setCAx
126+
axiom concatAx : setCAx → setCAx → Option setCAx
127+
axiom setItemAx : T → setCAx
128+
axiom unionAx : setCAx → setCAx → setCAx
129+
axiom intersectionAx : setCAx → setCAx → setCAx
130+
axiom differenceAx : setCAx → setCAx → setCAx
131+
axiom inSetAx : T → setCAx → Bool
132+
axiom inclusionAx : setCAx → setCAx → Bool
133+
axiom sizeAx : setCAx → Int
134+
axiom choiceAx : setCAx → T
135+
136+
noncomputable def SetHook (T : Type) : SetHookSig T :=
137+
{ set := setCAx,
138+
unit := unitAx,
139+
concat := concatAx,
140+
setItem := setItemAx T,
141+
union := unionAx,
142+
intersection := intersectionAx,
143+
difference := differenceAx,
144+
inSet := inSetAx T,
145+
inclusion := inclusionAx,
146+
size := sizeAx,
147+
choice := choiceAx T }
148+
149+
end SetHookDef
150+
103151
class Inj (From To : Type) : Type where
104152
inj (x : From) : To
105153

pyk/src/pyk/k2lean4/k2lean4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _collection(self, sort: str) -> Structure:
153153
val = Term(f'List {item}')
154154
case CollectionKind.SET:
155155
(item,) = sorts
156-
val = Term(f'List {item}')
156+
val = Term(f'(SetHook {item}).set')
157157
case CollectionKind.MAP:
158158
key, value = sorts
159159
val = Term(f'(MapHook {key} {value}).map')

0 commit comments

Comments
 (0)