-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlst-toset.ath
More file actions
70 lines (51 loc) · 1.7 KB
/
Copy pathlst-toset.ath
File metadata and controls
70 lines (51 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Properties of list to set transformation function "l2s".
load "lst-in"
load "set-util"
load "bool"
extend-module Lst {
declare l2s: (S) [(Lst S)] -> (Set.Set S)
overload in Set.in
module toSet{
define [v h t] := [?v:'S ?h:'S ?t:(Lst 'S)]
assert toSet-axioms :=
(fun
[(l2s empty) = Set.null
(l2s (lst h t)) = (Set.insert h (l2s t))])
define [toSet-empty-axiom toSet-lst-axiom] := toSet-axioms
define [l] := [?l:(Lst 'S)]
# functional correctness
define toSet-fc :=
(forall l v . (v in l <==> v in (l2s l)))
by-induction toSet-fc {
(l as empty) =>
pick-any v
(!chain [(v in l)
<==> false [Lst.In.empty-C]
<==> (v in Set.null) [Set.NC]
<==> (v in (l2s l)) [toSet-empty-axiom]])
| (l as (lst h t)) =>
let {ih := (forall v . (v in t <==> v in (l2s t)))}
pick-any v
(!chain [(v in l)
<==> ((v = h) | v in t) [Lst.In.in-lst-axiom]
<==> ((v = h) | v in (l2s t)) [ih]
<==> (v in (Set.insert h (l2s t))) [Set.in-def]
<==> (v in (l2s l)) [toSet-lst-axiom]])
}
define [l1 l2] := [?l1:(Lst 'S) ?l2:(Lst 'S)]
assert in-equal :=
(forall l1 l2 v .
((l2s l1) = (l2s l2)) ==> (v in l1) = (v in l2))
conclude in-equal
pick-any l1:(Lst 'S) l2:(Lst 'S) v
assume a := ((l2s l1) = (l2s l2))
let {equiv := (!chain [(v in l1)
<==> (v in (l2s l1)) [toSet-fc]
<==> (v in (l2s l2)) [a]
<==> (v in l2) [toSet-fc]])}
(!chain<- [((v in l1) = (v in l2))
<== ((v in l1) <==> (v in l2)) [equiv2eq]])
} # close module Lst.toSet
} # close module Lst
#_ := (print "\nrl:\n" rl)
open Lst