| author | wenzelm |
| Fri, 21 Aug 2015 20:47:53 +0200 | |
| changeset 61001 | ea38a1922a0b |
| parent 60519 | 84b8e5c2580e |
| child 61764 | ac6e5de1a50b |
| permissions | -rw-r--r-- |
| 60519 | 1 |
(* Author: Stefan Berghofer, Lukas Bulwahn, TU Muenchen *) |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
2 |
|
| 60500 | 3 |
section \<open>A table-based implementation of the reflexive transitive closure\<close> |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
4 |
|
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
5 |
theory Transitive_Closure_Table |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
6 |
imports Main |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
7 |
begin |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
8 |
|
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
9 |
inductive rtrancl_path :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'a list \<Rightarrow> 'a \<Rightarrow> bool"
|
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
10 |
for r :: "'a \<Rightarrow> 'a \<Rightarrow> bool" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
11 |
where |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
12 |
base: "rtrancl_path r x [] x" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
13 |
| step: "r x y \<Longrightarrow> rtrancl_path r y ys z \<Longrightarrow> rtrancl_path r x (y # ys) z" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
14 |
|
| 60519 | 15 |
lemma rtranclp_eq_rtrancl_path: "r\<^sup>*\<^sup>* x y \<longleftrightarrow> (\<exists>xs. rtrancl_path r x xs y)" |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
16 |
proof |
| 60519 | 17 |
show "\<exists>xs. rtrancl_path r x xs y" if "r\<^sup>*\<^sup>* x y" |
18 |
using that |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
19 |
proof (induct rule: converse_rtranclp_induct) |
| 34912 | 20 |
case base |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
21 |
have "rtrancl_path r y [] y" by (rule rtrancl_path.base) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
22 |
then show ?case .. |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
23 |
next |
| 34912 | 24 |
case (step x z) |
| 60500 | 25 |
from \<open>\<exists>xs. rtrancl_path r z xs y\<close> |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
26 |
obtain xs where "rtrancl_path r z xs y" .. |
| 60500 | 27 |
with \<open>r x z\<close> have "rtrancl_path r x (z # xs) y" |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
28 |
by (rule rtrancl_path.step) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
29 |
then show ?case .. |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
30 |
qed |
| 60519 | 31 |
show "r\<^sup>*\<^sup>* x y" if "\<exists>xs. rtrancl_path r x xs y" |
32 |
proof - |
|
33 |
from that obtain xs where "rtrancl_path r x xs y" .. |
|
34 |
then show ?thesis |
|
35 |
proof induct |
|
36 |
case (base x) |
|
37 |
show ?case |
|
38 |
by (rule rtranclp.rtrancl_refl) |
|
39 |
next |
|
40 |
case (step x y ys z) |
|
41 |
from \<open>r x y\<close> \<open>r\<^sup>*\<^sup>* y z\<close> show ?case |
|
42 |
by (rule converse_rtranclp_into_rtranclp) |
|
43 |
qed |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
44 |
qed |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
45 |
qed |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
46 |
|
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
47 |
lemma rtrancl_path_trans: |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
48 |
assumes xy: "rtrancl_path r x xs y" |
| 60519 | 49 |
and yz: "rtrancl_path r y ys z" |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
50 |
shows "rtrancl_path r x (xs @ ys) z" using xy yz |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
51 |
proof (induct arbitrary: z) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
52 |
case (base x) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
53 |
then show ?case by simp |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
54 |
next |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
55 |
case (step x y xs) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
56 |
then have "rtrancl_path r y (xs @ ys) z" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
57 |
by simp |
| 60500 | 58 |
with \<open>r x y\<close> have "rtrancl_path r x (y # (xs @ ys)) z" |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
59 |
by (rule rtrancl_path.step) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
60 |
then show ?case by simp |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
61 |
qed |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
62 |
|
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
63 |
lemma rtrancl_path_appendE: |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
64 |
assumes xz: "rtrancl_path r x (xs @ y # ys) z" |
| 60519 | 65 |
obtains "rtrancl_path r x (xs @ [y]) y" and "rtrancl_path r y ys z" |
66 |
using xz |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
67 |
proof (induct xs arbitrary: x) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
68 |
case Nil |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
69 |
then have "rtrancl_path r x (y # ys) z" by simp |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
70 |
then obtain xy: "r x y" and yz: "rtrancl_path r y ys z" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
71 |
by cases auto |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
72 |
from xy have "rtrancl_path r x [y] y" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
73 |
by (rule rtrancl_path.step [OF _ rtrancl_path.base]) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
74 |
then have "rtrancl_path r x ([] @ [y]) y" by simp |
| 60519 | 75 |
then show thesis using yz by (rule Nil) |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
76 |
next |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
77 |
case (Cons a as) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
78 |
then have "rtrancl_path r x (a # (as @ y # ys)) z" by simp |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
79 |
then obtain xa: "r x a" and az: "rtrancl_path r a (as @ y # ys) z" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
80 |
by cases auto |
| 60519 | 81 |
show thesis |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
82 |
proof (rule Cons(1) [OF _ az]) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
83 |
assume "rtrancl_path r y ys z" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
84 |
assume "rtrancl_path r a (as @ [y]) y" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
85 |
with xa have "rtrancl_path r x (a # (as @ [y])) y" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
86 |
by (rule rtrancl_path.step) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
87 |
then have "rtrancl_path r x ((a # as) @ [y]) y" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
88 |
by simp |
| 60519 | 89 |
then show thesis using \<open>rtrancl_path r y ys z\<close> |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
90 |
by (rule Cons(2)) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
91 |
qed |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
92 |
qed |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
93 |
|
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
94 |
lemma rtrancl_path_distinct: |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
95 |
assumes xy: "rtrancl_path r x xs y" |
| 60519 | 96 |
obtains xs' where "rtrancl_path r x xs' y" and "distinct (x # xs')" |
97 |
using xy |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
98 |
proof (induct xs rule: measure_induct_rule [of length]) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
99 |
case (less xs) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
100 |
show ?case |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
101 |
proof (cases "distinct (x # xs)") |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
102 |
case True |
| 60500 | 103 |
with \<open>rtrancl_path r x xs y\<close> show ?thesis by (rule less) |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
104 |
next |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
105 |
case False |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
106 |
then have "\<exists>as bs cs a. x # xs = as @ [a] @ bs @ [a] @ cs" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
107 |
by (rule not_distinct_decomp) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
108 |
then obtain as bs cs a where xxs: "x # xs = as @ [a] @ bs @ [a] @ cs" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
109 |
by iprover |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
110 |
show ?thesis |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
111 |
proof (cases as) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
112 |
case Nil |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
113 |
with xxs have x: "x = a" and xs: "xs = bs @ a # cs" |
| 35423 | 114 |
by auto |
| 60500 | 115 |
from x xs \<open>rtrancl_path r x xs y\<close> have cs: "rtrancl_path r x cs y" |
| 35423 | 116 |
by (auto elim: rtrancl_path_appendE) |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
117 |
from xs have "length cs < length xs" by simp |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
118 |
then show ?thesis |
| 35423 | 119 |
by (rule less(1)) (iprover intro: cs less(2))+ |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
120 |
next |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
121 |
case (Cons d ds) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
122 |
with xxs have xs: "xs = ds @ a # (bs @ [a] @ cs)" |
| 35423 | 123 |
by auto |
| 60500 | 124 |
with \<open>rtrancl_path r x xs y\<close> obtain xa: "rtrancl_path r x (ds @ [a]) a" |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
125 |
and ay: "rtrancl_path r a (bs @ a # cs) y" |
| 35423 | 126 |
by (auto elim: rtrancl_path_appendE) |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
127 |
from ay have "rtrancl_path r a cs y" by (auto elim: rtrancl_path_appendE) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
128 |
with xa have xy: "rtrancl_path r x ((ds @ [a]) @ cs) y" |
| 35423 | 129 |
by (rule rtrancl_path_trans) |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
130 |
from xs have "length ((ds @ [a]) @ cs) < length xs" by simp |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
131 |
then show ?thesis |
| 35423 | 132 |
by (rule less(1)) (iprover intro: xy less(2))+ |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
133 |
qed |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
134 |
qed |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
135 |
qed |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
136 |
|
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
137 |
inductive rtrancl_tab :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool"
|
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
138 |
for r :: "'a \<Rightarrow> 'a \<Rightarrow> bool" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
139 |
where |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
140 |
base: "rtrancl_tab r xs x x" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
141 |
| step: "x \<notin> set xs \<Longrightarrow> r x y \<Longrightarrow> rtrancl_tab r (x # xs) y z \<Longrightarrow> rtrancl_tab r xs x z" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
142 |
|
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
143 |
lemma rtrancl_path_imp_rtrancl_tab: |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
144 |
assumes path: "rtrancl_path r x xs y" |
| 60519 | 145 |
and x: "distinct (x # xs)" |
146 |
and ys: "({x} \<union> set xs) \<inter> set ys = {}"
|
|
147 |
shows "rtrancl_tab r ys x y" |
|
148 |
using path x ys |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
149 |
proof (induct arbitrary: ys) |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
150 |
case base |
| 60519 | 151 |
show ?case |
152 |
by (rule rtrancl_tab.base) |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
153 |
next |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
154 |
case (step x y zs z) |
| 60519 | 155 |
then have "x \<notin> set ys" |
156 |
by auto |
|
157 |
from step have "distinct (y # zs)" |
|
158 |
by simp |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
159 |
moreover from step have "({y} \<union> set zs) \<inter> set (x # ys) = {}"
|
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
160 |
by auto |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
161 |
ultimately have "rtrancl_tab r (x # ys) y z" |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
162 |
by (rule step) |
| 60519 | 163 |
with \<open>x \<notin> set ys\<close> \<open>r x y\<close> show ?case |
164 |
by (rule rtrancl_tab.step) |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
165 |
qed |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
166 |
|
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
167 |
lemma rtrancl_tab_imp_rtrancl_path: |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
168 |
assumes tab: "rtrancl_tab r ys x y" |
| 60519 | 169 |
obtains xs where "rtrancl_path r x xs y" |
170 |
using tab |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
171 |
proof induct |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
172 |
case base |
| 60519 | 173 |
from rtrancl_path.base show ?case |
174 |
by (rule base) |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
175 |
next |
| 60519 | 176 |
case step |
177 |
show ?case |
|
178 |
by (iprover intro: step rtrancl_path.step) |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
179 |
qed |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
180 |
|
| 60519 | 181 |
lemma rtranclp_eq_rtrancl_tab_nil: "r\<^sup>*\<^sup>* x y \<longleftrightarrow> rtrancl_tab r [] x y" |
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
182 |
proof |
| 60519 | 183 |
show "rtrancl_tab r [] x y" if "r\<^sup>*\<^sup>* x y" |
184 |
proof - |
|
185 |
from that obtain xs where "rtrancl_path r x xs y" |
|
186 |
by (auto simp add: rtranclp_eq_rtrancl_path) |
|
187 |
then obtain xs' where xs': "rtrancl_path r x xs' y" and distinct: "distinct (x # xs')" |
|
188 |
by (rule rtrancl_path_distinct) |
|
189 |
have "({x} \<union> set xs') \<inter> set [] = {}"
|
|
190 |
by simp |
|
191 |
with xs' distinct show ?thesis |
|
192 |
by (rule rtrancl_path_imp_rtrancl_tab) |
|
193 |
qed |
|
194 |
show "r\<^sup>*\<^sup>* x y" if "rtrancl_tab r [] x y" |
|
195 |
proof - |
|
196 |
from that obtain xs where "rtrancl_path r x xs y" |
|
197 |
by (rule rtrancl_tab_imp_rtrancl_path) |
|
198 |
then show ?thesis |
|
199 |
by (auto simp add: rtranclp_eq_rtrancl_path) |
|
200 |
qed |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
201 |
qed |
|
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
202 |
|
| 60519 | 203 |
declare rtranclp_rtrancl_eq [code del] |
204 |
declare rtranclp_eq_rtrancl_tab_nil [THEN iffD2, code_pred_intro] |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
205 |
|
| 60519 | 206 |
code_pred rtranclp |
207 |
using rtranclp_eq_rtrancl_tab_nil [THEN iffD1] by fastforce |
|
|
33649
854173fcd21c
added a tabled implementation of the reflexive transitive closure
bulwahn
parents:
diff
changeset
|
208 |
|
| 46359 | 209 |
end |