4. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Related Works Hoare Logic
Hoare Logic Rules
tPu skip tPu tP[E/x]u x := E tPu
tPu S tQu tQu T tRu
tPu S; T tRu
tB ^ Pu S tQu t␣B ^ Pu T tQu
tPu if B then S else T endif tQu
P1 ñ P2 tP2u S tQ2u Q2 ñ Q1
tP1u S tQ1u
tP ^ Bu S tPu
tPu while B do S done t␣B ^ Pu
Wang Shengyi (NUS) Mechanized Ramification April 17, 2015 4 / 43
5. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Related Works Hoare Logic
Example I
J
tx + 1 ď 10u x := x + 1 tx ď 10u
tx ď 10 ^ x ă 10u x := x + 1 tx ď 10u
tx ď 10u while x < 10 do x := x + 1 done t␣x ă 10 ^ x ď 10u
tx ď 10u while x < 10 do x := x + 1 done tx = 10u
tP[E/x]u x:=E tPu
P1ñP2 tP2u S tQ2u Q2ñQ1
tP1u S tQ1u
tP^Bu S tPu
tPu while B do S done t␣B^Pu
P1ñP2 tP2u S tQ2u Q2ñQ1
tP1u S tQ1u
Wang Shengyi (NUS) Mechanized Ramification April 17, 2015 5 / 43
32. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Related Works Hoare Logic
Loop Invariant of Example II
(D α, β. list α i ^ list β j ^ α:
0 = α:
¨ β)
^ (@k. reach(i, k) ^ reach(j, k) ñ k = nil)
reach(i, j)
def
= D n ě 0. reachn(i, j) reachn+1(i, j)
def
= D a, k. i ÞÑ a, k ^ reachn(k, j)
reach0(i, j)
def
= i = j list ϵ i
def
= i = nil list (a ¨ α) i
def
= D j. i ÞÑ a, j ^ list α j
Wang Shengyi (NUS) Mechanized Ramification April 17, 2015 7 / 43
33. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Related Works Hoare Logic
Loop Invariant of Example II
(D α, β. list α i ^ list β j ^ α:
0 = α:
¨ β) ^ list γ x
^ (@k. reach(i, k) ^ reach(j, k) ñ k = nil)
^ (@k. reach(x, k) ^ (reach(i, k) _ reach(j, k)) ñ k = nil))
reach(i, j)
def
= D n ě 0. reachn(i, j) reachn+1(i, j)
def
= D a, k. i ÞÑ a, k ^ reachn(k, j)
reach0(i, j)
def
= i = j list ϵ i
def
= i = nil list (a ¨ α) i
def
= D j. i ÞÑ a, j ^ list α j
Wang Shengyi (NUS) Mechanized Ramification April 17, 2015 7 / 43
37. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Related Works Separation Logic
Loop Invariant of Example II
Hoare Logic:
(D α, β. list α i ^ list β j ^ α:
0 = α:
¨ β)
^(@k. reach(i, k) ^ reach(j, k) ñ k = nil)
reach(i, j)
def
= D n ě 0. reachn(i, j) reachn+1(i, j)
def
= D a, k. i ÞÑ a, k ^ reachn(k, j)
reach0(i, j)
def
= i = j list ϵ i
def
= i = nil list (a ¨ α) i
def
= D j. i ÞÑ a, j ^ list α j
Separation Logic:
D α, β. list α i › list β j ^ α:
0 = α:
¨ β
list ϵ i
def
= i = nil list (a ¨ α) i
def
= D j. i ÞÑ a, j › list α j
Wang Shengyi (NUS) Mechanized Ramification April 17, 2015 11 / 43
38. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Related Works Separation Logic
Loop Invariant of Example II
Hoare Logic:
(D α, β. list α i ^ list β j ^ α:
0 = α:
¨ β) ^ list γ x
^(@k. reach(i, k) ^ reach(j, k) ñ k = nil)
^ (@k. reach(x, k) ^ (reach(i, k) _ reach(j, k)) ñ k = nil))
reach(i, j)
def
= D n ě 0. reachn(i, j) reachn+1(i, j)
def
= D a, k. i ÞÑ a, k ^ reachn(k, j)
reach0(i, j)
def
= i = j list ϵ i
def
= i = nil list (a ¨ α) i
def
= D j. i ÞÑ a, j ^ list α j
Separation Logic:
D α, β. list α i › list β j ^ α:
0 = α:
¨ β
list ϵ i
def
= i = nil list (a ¨ α) i
def
= D j. i ÞÑ a, j › list α j
Wang Shengyi (NUS) Mechanized Ramification April 17, 2015 11 / 43
52. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Related Works Mechanized Semantic Library
Separation Algebra
Coq Definition of h1 ‘ h2 = h
Class Join (t: Type) : Type := join: t Ñ t Ñ t Ñ Prop.
Class Perm alg (t: Type) {J: Join t} : Type :=
mkPerm {
join eq: @ {x y z z’}, join x y z Ñ join x y z’ Ñ z = z’;
join assoc: @ {a b c d e}, join a b d Ñ join d c e Ñ
{f : t & join b c f ^ join a f e};
join comm: @ {a b c}, join a b c Ñ join b a c;
join positivity: @ {a a’ b b’}, join a a’ b Ñ join b b’ a Ñ a=b
}.
Wang Shengyi (NUS) Mechanized Ramification April 17, 2015 19 / 43
62. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Formalization of Graphs Mathematical Graphs
Mathematical Graphs
Class BiMathGraph (Vertex Data : Type) (nV : Vertex) {EV: EqDec Vertex} :=
{
bm bi :> BiGraph Vertex Data;
bm ma :> MathGraph Vertex Data nV;
pg the same: m pg = b pg
}.
Wang Shengyi (NUS) Mechanized Ramification April 17, 2015 27 / 43
63. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Formalization of Graphs Mathematical Graphs
Lemmas about Mathematical Graphs
Lemma finite reachable computable:
@ (mg : MathGraph V D null) x l, valid x Ñ
(@ y, reachable m pg x y Ñ In y l) Ñ D l’, reachable list m pg x l’ ^ NoDup l’.
Definition reachable list (pg : PreGraph V D) (x : V) (L : list V) : Prop :=
valid x ^ @ y, In y L Ø reachable pg x y.
Wang Shengyi (NUS) Mechanized Ramification April 17, 2015 28 / 43
65. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Formalization of Graphs Mathematical Graphs
It is Extremely Hard
• We essentially need to determine a list of the reachable vertices in a graph.
Obvious idea: BFS.
• Contructing BFS is hard.
• It could go into a loop, which is why BFS must track already visited nodes.
• The graph could have infinite nodes, which is why BFS must have an upper
bound argument. (a computer’s memory is finite).
• Coq does not support general recursion.
Wang Shengyi (NUS) Mechanized Ramification April 17, 2015 29 / 43
66. .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Formalization of Graphs Mathematical Graphs
It is Extremely Hard
• We essentially need to determine a list of the reachable vertices in a graph.
Obvious idea: BFS.
• Contructing BFS is hard.
• It could go into a loop, which is why BFS must track already visited nodes.
• The graph could have infinite nodes, which is why BFS must have an upper
bound argument. (a computer’s memory is finite).
• Coq does not support general recursion.
• It is still hard to prove the result of BFS is the whole reachable set.
• When BFS reaches an already-visited node, how do we know it will not forget
about its children?
• When BFS terminates, there are two situations to prove.
• Reachable nodes are those nodes with a path. The exploration path and the
given path need not be at all similar.
Wang Shengyi (NUS) Mechanized Ramification April 17, 2015 29 / 43