author | desharna |
Wed, 29 Jun 2022 15:36:19 +0200 | |
changeset 75637 | 66a9aa769d63 |
parent 75635 | 3ba38a119739 |
child 75638 | aaa22adef039 |
permissions | -rw-r--r-- |
44372 | 1 |
(* Title: HOL/ex/Unification.thy |
2 |
Author: Martin Coen, Cambridge University Computer Laboratory |
|
3 |
Author: Konrad Slind, TUM & Cambridge University Computer Laboratory |
|
4 |
Author: Alexander Krauss, TUM |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
5 |
*) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
6 |
|
61343 | 7 |
section \<open>Substitution and Unification\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
8 |
|
23219 | 9 |
theory Unification |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
10 |
imports Main |
23219 | 11 |
begin |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
12 |
|
61343 | 13 |
text \<open> |
44428 | 14 |
Implements Manna \& Waldinger's formalization, with Paulson's |
44372 | 15 |
simplifications, and some new simplifications by Slind and Krauss. |
16 |
||
44428 | 17 |
Z Manna \& R Waldinger, Deductive Synthesis of the Unification |
44372 | 18 |
Algorithm. SCP 1 (1981), 5-48 |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
19 |
|
44372 | 20 |
L C Paulson, Verifying the Unification Algorithm in LCF. SCP 5 |
21 |
(1985), 143-170 |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
22 |
|
44372 | 23 |
K Slind, Reasoning about Terminating Functional Programs, |
24 |
Ph.D. thesis, TUM, 1999, Sect. 5.8 |
|
25 |
||
26 |
A Krauss, Partial and Nested Recursive Function Definitions in |
|
56790
f54097170704
prefer plain ASCII / latex over not-so-universal Unicode;
wenzelm
parents:
44428
diff
changeset
|
27 |
Higher-Order Logic, JAR 44(4):303-336, 2010. Sect. 6.3 |
61343 | 28 |
\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
29 |
|
23219 | 30 |
|
61343 | 31 |
subsection \<open>Terms\<close> |
44368 | 32 |
|
61343 | 33 |
text \<open>Binary trees with leaves that are constants or variables.\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
34 |
|
58310 | 35 |
datatype 'a trm = |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
36 |
Var 'a |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
37 |
| Const 'a |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
38 |
| Comb "'a trm" "'a trm" (infix "\<cdot>" 60) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
39 |
|
44368 | 40 |
primrec vars_of :: "'a trm \<Rightarrow> 'a set" |
41 |
where |
|
42 |
"vars_of (Var v) = {v}" |
|
43 |
| "vars_of (Const c) = {}" |
|
44 |
| "vars_of (M \<cdot> N) = vars_of M \<union> vars_of N" |
|
45 |
||
46 |
fun occs :: "'a trm \<Rightarrow> 'a trm \<Rightarrow> bool" (infixl "\<prec>" 54) |
|
47 |
where |
|
44369 | 48 |
"u \<prec> Var v \<longleftrightarrow> False" |
49 |
| "u \<prec> Const c \<longleftrightarrow> False" |
|
50 |
| "u \<prec> M \<cdot> N \<longleftrightarrow> u = M \<or> u = N \<or> u \<prec> M \<or> u \<prec> N" |
|
44368 | 51 |
|
52 |
||
53 |
lemma finite_vars_of[intro]: "finite (vars_of t)" |
|
54 |
by (induct t) simp_all |
|
55 |
||
56 |
lemma vars_iff_occseq: "x \<in> vars_of t \<longleftrightarrow> Var x \<prec> t \<or> Var x = t" |
|
57 |
by (induct t) auto |
|
58 |
||
59 |
lemma occs_vars_subset: "M \<prec> N \<Longrightarrow> vars_of M \<subseteq> vars_of N" |
|
60 |
by (induct N) auto |
|
61 |
||
62 |
||
61343 | 63 |
subsection \<open>Substitutions\<close> |
44368 | 64 |
|
42463 | 65 |
type_synonym 'a subst = "('a \<times> 'a trm) list" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
66 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
67 |
fun assoc :: "'a \<Rightarrow> 'b \<Rightarrow> ('a \<times> 'b) list \<Rightarrow> 'b" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
68 |
where |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
69 |
"assoc x d [] = d" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
70 |
| "assoc x d ((p,q)#t) = (if x = p then q else assoc x d t)" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
71 |
|
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
72 |
primrec subst :: "'a trm \<Rightarrow> 'a subst \<Rightarrow> 'a trm" (infixl "\<lhd>" 55) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
73 |
where |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
74 |
"(Var v) \<lhd> s = assoc v (Var v) s" |
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
75 |
| "(Const c) \<lhd> s = (Const c)" |
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
76 |
| "(M \<cdot> N) \<lhd> s = (M \<lhd> s) \<cdot> (N \<lhd> s)" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
77 |
|
44368 | 78 |
definition subst_eq (infixr "\<doteq>" 52) |
79 |
where |
|
80 |
"s1 \<doteq> s2 \<longleftrightarrow> (\<forall>t. t \<lhd> s1 = t \<lhd> s2)" |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
81 |
|
44368 | 82 |
fun comp :: "'a subst \<Rightarrow> 'a subst \<Rightarrow> 'a subst" (infixl "\<lozenge>" 56) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
83 |
where |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
84 |
"[] \<lozenge> bl = bl" |
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
85 |
| "((a,b) # al) \<lozenge> bl = (a, b \<lhd> bl) # (al \<lozenge> bl)" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
86 |
|
44368 | 87 |
lemma subst_Nil[simp]: "t \<lhd> [] = t" |
88 |
by (induct t) auto |
|
89 |
||
90 |
lemma subst_mono: "t \<prec> u \<Longrightarrow> t \<lhd> s \<prec> u \<lhd> s" |
|
91 |
by (induct u) auto |
|
92 |
||
93 |
lemma agreement: "(t \<lhd> r = t \<lhd> s) \<longleftrightarrow> (\<forall>v \<in> vars_of t. Var v \<lhd> r = Var v \<lhd> s)" |
|
94 |
by (induct t) auto |
|
95 |
||
96 |
lemma repl_invariance: "v \<notin> vars_of t \<Longrightarrow> t \<lhd> (v,u) # s = t \<lhd> s" |
|
97 |
by (simp add: agreement) |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
98 |
|
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
99 |
lemma remove_var: "v \<notin> vars_of s \<Longrightarrow> v \<notin> vars_of (t \<lhd> [(v, s)])" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
100 |
by (induct t) simp_all |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
101 |
|
44368 | 102 |
lemma subst_refl[iff]: "s \<doteq> s" |
103 |
by (auto simp:subst_eq_def) |
|
104 |
||
105 |
lemma subst_sym[sym]: "\<lbrakk>s1 \<doteq> s2\<rbrakk> \<Longrightarrow> s2 \<doteq> s1" |
|
106 |
by (auto simp:subst_eq_def) |
|
107 |
||
108 |
lemma subst_trans[trans]: "\<lbrakk>s1 \<doteq> s2; s2 \<doteq> s3\<rbrakk> \<Longrightarrow> s1 \<doteq> s3" |
|
109 |
by (auto simp:subst_eq_def) |
|
110 |
||
44371
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
111 |
lemma subst_no_occs: "\<not> Var v \<prec> t \<Longrightarrow> Var v \<noteq> t |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
112 |
\<Longrightarrow> t \<lhd> [(v,s)] = t" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
113 |
by (induct t) auto |
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
114 |
|
44368 | 115 |
lemma comp_Nil[simp]: "\<sigma> \<lozenge> [] = \<sigma>" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
116 |
by (induct \<sigma>) auto |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
117 |
|
44368 | 118 |
lemma subst_comp[simp]: "t \<lhd> (r \<lozenge> s) = t \<lhd> r \<lhd> s" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
119 |
proof (induct t) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
120 |
case (Var v) thus ?case |
44368 | 121 |
by (induct r) auto |
122 |
qed auto |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
123 |
|
44368 | 124 |
lemma subst_eq_intro[intro]: "(\<And>t. t \<lhd> \<sigma> = t \<lhd> \<theta>) \<Longrightarrow> \<sigma> \<doteq> \<theta>" |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
125 |
by (auto simp:subst_eq_def) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
126 |
|
44368 | 127 |
lemma subst_eq_dest[dest]: "s1 \<doteq> s2 \<Longrightarrow> t \<lhd> s1 = t \<lhd> s2" |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
128 |
by (auto simp:subst_eq_def) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
129 |
|
44368 | 130 |
lemma comp_assoc: "(a \<lozenge> b) \<lozenge> c \<doteq> a \<lozenge> (b \<lozenge> c)" |
131 |
by auto |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
132 |
|
44368 | 133 |
lemma subst_cong: "\<lbrakk>\<sigma> \<doteq> \<sigma>'; \<theta> \<doteq> \<theta>'\<rbrakk> \<Longrightarrow> (\<sigma> \<lozenge> \<theta>) \<doteq> (\<sigma>' \<lozenge> \<theta>')" |
134 |
by (auto simp: subst_eq_def) |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
135 |
|
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
136 |
lemma var_self: "[(v, Var v)] \<doteq> []" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
137 |
proof |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
138 |
fix t show "t \<lhd> [(v, Var v)] = t \<lhd> []" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
139 |
by (induct t) simp_all |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
140 |
qed |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
141 |
|
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
142 |
lemma var_same[simp]: "[(v, t)] \<doteq> [] \<longleftrightarrow> t = Var v" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
143 |
by (metis assoc.simps(2) subst.simps(1) subst_eq_def var_self) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
144 |
|
75637
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
145 |
lemma vars_of_subst_conv_Union: "vars_of (t \<lhd> \<eta>) = \<Union>(vars_of ` (\<lambda>x. Var x \<lhd> \<eta>) ` vars_of t)" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
146 |
by (induction t) simp_all |
23219 | 147 |
|
61343 | 148 |
subsection \<open>Unifiers and Most General Unifiers\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
149 |
|
44368 | 150 |
definition Unifier :: "'a subst \<Rightarrow> 'a trm \<Rightarrow> 'a trm \<Rightarrow> bool" |
151 |
where "Unifier \<sigma> t u \<longleftrightarrow> (t \<lhd> \<sigma> = u \<lhd> \<sigma>)" |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
152 |
|
44368 | 153 |
definition MGU :: "'a subst \<Rightarrow> 'a trm \<Rightarrow> 'a trm \<Rightarrow> bool" where |
154 |
"MGU \<sigma> t u \<longleftrightarrow> |
|
155 |
Unifier \<sigma> t u \<and> (\<forall>\<theta>. Unifier \<theta> t u \<longrightarrow> (\<exists>\<gamma>. \<theta> \<doteq> \<sigma> \<lozenge> \<gamma>))" |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
156 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
157 |
lemma MGUI[intro]: |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
158 |
"\<lbrakk>t \<lhd> \<sigma> = u \<lhd> \<sigma>; \<And>\<theta>. t \<lhd> \<theta> = u \<lhd> \<theta> \<Longrightarrow> \<exists>\<gamma>. \<theta> \<doteq> \<sigma> \<lozenge> \<gamma>\<rbrakk> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
159 |
\<Longrightarrow> MGU \<sigma> t u" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
160 |
by (simp only:Unifier_def MGU_def, auto) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
161 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
162 |
lemma MGU_sym[sym]: |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
163 |
"MGU \<sigma> s t \<Longrightarrow> MGU \<sigma> t s" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
164 |
by (auto simp:MGU_def Unifier_def) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
165 |
|
44371
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
166 |
lemma MGU_is_Unifier: "MGU \<sigma> t u \<Longrightarrow> Unifier \<sigma> t u" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
167 |
unfolding MGU_def by (rule conjunct1) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
168 |
|
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
169 |
lemma MGU_Var: |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
170 |
assumes "\<not> Var v \<prec> t" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
171 |
shows "MGU [(v,t)] (Var v) t" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
172 |
proof (intro MGUI exI) |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
173 |
show "Var v \<lhd> [(v,t)] = t \<lhd> [(v,t)]" using assms |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
174 |
by (metis assoc.simps(2) repl_invariance subst.simps(1) subst_Nil vars_iff_occseq) |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
175 |
next |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
176 |
fix \<theta> assume th: "Var v \<lhd> \<theta> = t \<lhd> \<theta>" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
177 |
show "\<theta> \<doteq> [(v,t)] \<lozenge> \<theta>" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
178 |
proof |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
179 |
fix s show "s \<lhd> \<theta> = s \<lhd> [(v,t)] \<lozenge> \<theta>" using th |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
180 |
by (induct s) auto |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
181 |
qed |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
182 |
qed |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
183 |
|
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
184 |
lemma MGU_Const: "MGU [] (Const c) (Const d) \<longleftrightarrow> c = d" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
185 |
by (auto simp: MGU_def Unifier_def) |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
186 |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
187 |
|
61343 | 188 |
subsection \<open>The unification algorithm\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
189 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
190 |
function unify :: "'a trm \<Rightarrow> 'a trm \<Rightarrow> 'a subst option" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
191 |
where |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
192 |
"unify (Const c) (M \<cdot> N) = None" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
193 |
| "unify (M \<cdot> N) (Const c) = None" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
194 |
| "unify (Const c) (Var v) = Some [(v, Const c)]" |
44369 | 195 |
| "unify (M \<cdot> N) (Var v) = (if Var v \<prec> M \<cdot> N |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
196 |
then None |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
197 |
else Some [(v, M \<cdot> N)])" |
44369 | 198 |
| "unify (Var v) M = (if Var v \<prec> M |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
199 |
then None |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
200 |
else Some [(v, M)])" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
201 |
| "unify (Const c) (Const d) = (if c=d then Some [] else None)" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
202 |
| "unify (M \<cdot> N) (M' \<cdot> N') = (case unify M M' of |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
203 |
None \<Rightarrow> None | |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
204 |
Some \<theta> \<Rightarrow> (case unify (N \<lhd> \<theta>) (N' \<lhd> \<theta>) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
205 |
of None \<Rightarrow> None | |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
206 |
Some \<sigma> \<Rightarrow> Some (\<theta> \<lozenge> \<sigma>)))" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
207 |
by pat_completeness auto |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
208 |
|
61343 | 209 |
subsection \<open>Properties used in termination proof\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
210 |
|
61343 | 211 |
text \<open>Elimination of variables by a substitution:\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
212 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
213 |
definition |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
214 |
"elim \<sigma> v \<equiv> \<forall>t. v \<notin> vars_of (t \<lhd> \<sigma>)" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
215 |
|
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
216 |
lemma elim_intro[intro]: "(\<And>t. v \<notin> vars_of (t \<lhd> \<sigma>)) \<Longrightarrow> elim \<sigma> v" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
217 |
by (auto simp:elim_def) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
218 |
|
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
219 |
lemma elim_dest[dest]: "elim \<sigma> v \<Longrightarrow> v \<notin> vars_of (t \<lhd> \<sigma>)" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
220 |
by (auto simp:elim_def) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
221 |
|
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
222 |
lemma elim_eq: "\<sigma> \<doteq> \<theta> \<Longrightarrow> elim \<sigma> x = elim \<theta> x" |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
223 |
by (auto simp:elim_def subst_eq_def) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
224 |
|
44369 | 225 |
lemma occs_elim: "\<not> Var v \<prec> t |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
226 |
\<Longrightarrow> elim [(v,t)] v \<or> [(v,t)] \<doteq> []" |
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
227 |
by (metis elim_intro remove_var var_same vars_iff_occseq) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
228 |
|
61343 | 229 |
text \<open>The result of a unification never introduces new variables:\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
230 |
|
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
231 |
declare unify.psimps[simp] |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
232 |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
233 |
lemma unify_vars: |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
234 |
assumes "unify_dom (M, N)" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
235 |
assumes "unify M N = Some \<sigma>" |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
236 |
shows "vars_of (t \<lhd> \<sigma>) \<subseteq> vars_of M \<union> vars_of N \<union> vars_of t" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
237 |
(is "?P M N \<sigma> t") |
24444
448978b61556
induct: proper separation of initial and terminal step;
wenzelm
parents:
23777
diff
changeset
|
238 |
using assms |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
239 |
proof (induct M N arbitrary:\<sigma> t) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
240 |
case (3 c v) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
241 |
hence "\<sigma> = [(v, Const c)]" by simp |
24444
448978b61556
induct: proper separation of initial and terminal step;
wenzelm
parents:
23777
diff
changeset
|
242 |
thus ?case by (induct t) auto |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
243 |
next |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
244 |
case (4 M N v) |
44369 | 245 |
hence "\<not> Var v \<prec> M \<cdot> N" by auto |
24444
448978b61556
induct: proper separation of initial and terminal step;
wenzelm
parents:
23777
diff
changeset
|
246 |
with 4 have "\<sigma> = [(v, M\<cdot>N)]" by simp |
448978b61556
induct: proper separation of initial and terminal step;
wenzelm
parents:
23777
diff
changeset
|
247 |
thus ?case by (induct t) auto |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
248 |
next |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
249 |
case (5 v M) |
44369 | 250 |
hence "\<not> Var v \<prec> M" by auto |
24444
448978b61556
induct: proper separation of initial and terminal step;
wenzelm
parents:
23777
diff
changeset
|
251 |
with 5 have "\<sigma> = [(v, M)]" by simp |
448978b61556
induct: proper separation of initial and terminal step;
wenzelm
parents:
23777
diff
changeset
|
252 |
thus ?case by (induct t) auto |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
253 |
next |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
254 |
case (7 M N M' N' \<sigma>) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
255 |
then obtain \<theta>1 \<theta>2 |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
256 |
where "unify M M' = Some \<theta>1" |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
257 |
and "unify (N \<lhd> \<theta>1) (N' \<lhd> \<theta>1) = Some \<theta>2" |
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
258 |
and \<sigma>: "\<sigma> = \<theta>1 \<lozenge> \<theta>2" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
259 |
and ih1: "\<And>t. ?P M M' \<theta>1 t" |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
260 |
and ih2: "\<And>t. ?P (N\<lhd>\<theta>1) (N'\<lhd>\<theta>1) \<theta>2 t" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
261 |
by (auto split:option.split_asm) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
262 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
263 |
show ?case |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
264 |
proof |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
265 |
fix v assume a: "v \<in> vars_of (t \<lhd> \<sigma>)" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
266 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
267 |
show "v \<in> vars_of (M \<cdot> N) \<union> vars_of (M' \<cdot> N') \<union> vars_of t" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
268 |
proof (cases "v \<notin> vars_of M \<and> v \<notin> vars_of M' |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30909
diff
changeset
|
269 |
\<and> v \<notin> vars_of N \<and> v \<notin> vars_of N'") |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
270 |
case True |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
271 |
with ih1 have l:"\<And>t. v \<in> vars_of (t \<lhd> \<theta>1) \<Longrightarrow> v \<in> vars_of t" |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30909
diff
changeset
|
272 |
by auto |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
273 |
|
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
274 |
from a and ih2[where t="t \<lhd> \<theta>1"] |
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
275 |
have "v \<in> vars_of (N \<lhd> \<theta>1) \<union> vars_of (N' \<lhd> \<theta>1) |
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
276 |
\<or> v \<in> vars_of (t \<lhd> \<theta>1)" unfolding \<sigma> |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30909
diff
changeset
|
277 |
by auto |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
278 |
hence "v \<in> vars_of t" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
279 |
proof |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
280 |
assume "v \<in> vars_of (N \<lhd> \<theta>1) \<union> vars_of (N' \<lhd> \<theta>1)" |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30909
diff
changeset
|
281 |
with True show ?thesis by (auto dest:l) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
282 |
next |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
283 |
assume "v \<in> vars_of (t \<lhd> \<theta>1)" |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30909
diff
changeset
|
284 |
thus ?thesis by (rule l) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
285 |
qed |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
286 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
287 |
thus ?thesis by auto |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
288 |
qed auto |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
289 |
qed |
62390 | 290 |
qed (auto split: if_split_asm) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
291 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
292 |
|
61343 | 293 |
text \<open>The result of a unification is either the identity |
294 |
substitution or it eliminates a variable from one of the terms:\<close> |
|
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
295 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
296 |
lemma unify_eliminates: |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
297 |
assumes "unify_dom (M, N)" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
298 |
assumes "unify M N = Some \<sigma>" |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
299 |
shows "(\<exists>v\<in>vars_of M \<union> vars_of N. elim \<sigma> v) \<or> \<sigma> \<doteq> []" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
300 |
(is "?P M N \<sigma>") |
24444
448978b61556
induct: proper separation of initial and terminal step;
wenzelm
parents:
23777
diff
changeset
|
301 |
using assms |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
302 |
proof (induct M N arbitrary:\<sigma>) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
303 |
case 1 thus ?case by simp |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
304 |
next |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
305 |
case 2 thus ?case by simp |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
306 |
next |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
307 |
case (3 c v) |
44369 | 308 |
have no_occs: "\<not> Var v \<prec> Const c" by simp |
24444
448978b61556
induct: proper separation of initial and terminal step;
wenzelm
parents:
23777
diff
changeset
|
309 |
with 3 have "\<sigma> = [(v, Const c)]" by simp |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
310 |
with occs_elim[OF no_occs] |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
311 |
show ?case by auto |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
312 |
next |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
313 |
case (4 M N v) |
44369 | 314 |
hence no_occs: "\<not> Var v \<prec> M \<cdot> N" by auto |
24444
448978b61556
induct: proper separation of initial and terminal step;
wenzelm
parents:
23777
diff
changeset
|
315 |
with 4 have "\<sigma> = [(v, M\<cdot>N)]" by simp |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
316 |
with occs_elim[OF no_occs] |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
317 |
show ?case by auto |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
318 |
next |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
319 |
case (5 v M) |
44369 | 320 |
hence no_occs: "\<not> Var v \<prec> M" by auto |
24444
448978b61556
induct: proper separation of initial and terminal step;
wenzelm
parents:
23777
diff
changeset
|
321 |
with 5 have "\<sigma> = [(v, M)]" by simp |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
322 |
with occs_elim[OF no_occs] |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
323 |
show ?case by auto |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
324 |
next |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
325 |
case (6 c d) thus ?case |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
326 |
by (cases "c = d") auto |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
327 |
next |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
328 |
case (7 M N M' N' \<sigma>) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
329 |
then obtain \<theta>1 \<theta>2 |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
330 |
where "unify M M' = Some \<theta>1" |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
331 |
and "unify (N \<lhd> \<theta>1) (N' \<lhd> \<theta>1) = Some \<theta>2" |
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
332 |
and \<sigma>: "\<sigma> = \<theta>1 \<lozenge> \<theta>2" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
333 |
and ih1: "?P M M' \<theta>1" |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
334 |
and ih2: "?P (N\<lhd>\<theta>1) (N'\<lhd>\<theta>1) \<theta>2" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
335 |
by (auto split:option.split_asm) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
336 |
|
61343 | 337 |
from \<open>unify_dom (M \<cdot> N, M' \<cdot> N')\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
338 |
have "unify_dom (M, M')" |
23777 | 339 |
by (rule accp_downward) (rule unify_rel.intros) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
340 |
hence no_new_vars: |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
341 |
"\<And>t. vars_of (t \<lhd> \<theta>1) \<subseteq> vars_of M \<union> vars_of M' \<union> vars_of t" |
61343 | 342 |
by (rule unify_vars) (rule \<open>unify M M' = Some \<theta>1\<close>) |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
343 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
344 |
from ih2 show ?case |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
345 |
proof |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
346 |
assume "\<exists>v\<in>vars_of (N \<lhd> \<theta>1) \<union> vars_of (N' \<lhd> \<theta>1). elim \<theta>2 v" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
347 |
then obtain v |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
348 |
where "v\<in>vars_of (N \<lhd> \<theta>1) \<union> vars_of (N' \<lhd> \<theta>1)" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
349 |
and el: "elim \<theta>2 v" by auto |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
350 |
with no_new_vars show ?thesis unfolding \<sigma> |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
351 |
by (auto simp:elim_def) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
352 |
next |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
353 |
assume empty[simp]: "\<theta>2 \<doteq> []" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
354 |
|
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
355 |
have "\<sigma> \<doteq> (\<theta>1 \<lozenge> [])" unfolding \<sigma> |
44368 | 356 |
by (rule subst_cong) auto |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
357 |
also have "\<dots> \<doteq> \<theta>1" by auto |
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
358 |
finally have "\<sigma> \<doteq> \<theta>1" . |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
359 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
360 |
from ih1 show ?thesis |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
361 |
proof |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
362 |
assume "\<exists>v\<in>vars_of M \<union> vars_of M'. elim \<theta>1 v" |
61343 | 363 |
with elim_eq[OF \<open>\<sigma> \<doteq> \<theta>1\<close>] |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
364 |
show ?thesis by auto |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
365 |
next |
61343 | 366 |
note \<open>\<sigma> \<doteq> \<theta>1\<close> |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
367 |
also assume "\<theta>1 \<doteq> []" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
368 |
finally show ?thesis .. |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
369 |
qed |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
370 |
qed |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
371 |
qed |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
372 |
|
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
373 |
declare unify.psimps[simp del] |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
374 |
|
61343 | 375 |
subsection \<open>Termination proof\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
376 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
377 |
termination unify |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
378 |
proof |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
379 |
let ?R = "measures [\<lambda>(M,N). card (vars_of M \<union> vars_of N), |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
380 |
\<lambda>(M, N). size M]" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
381 |
show "wf ?R" by simp |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
382 |
|
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
383 |
fix M N M' N' :: "'a trm" |
67443
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents:
62390
diff
changeset
|
384 |
show "((M, M'), (M \<cdot> N, M' \<cdot> N')) \<in> ?R" \<comment> \<open>Inner call\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
385 |
by (rule measures_lesseq) (auto intro: card_mono) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
386 |
|
67443
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents:
62390
diff
changeset
|
387 |
fix \<theta> \<comment> \<open>Outer call\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
388 |
assume inner: "unify_dom (M, M')" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
389 |
"unify M M' = Some \<theta>" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
390 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
391 |
from unify_eliminates[OF inner] |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
392 |
show "((N \<lhd> \<theta>, N' \<lhd> \<theta>), (M \<cdot> N, M' \<cdot> N')) \<in>?R" |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
393 |
proof |
61933 | 394 |
\<comment> \<open>Either a variable is eliminated \ldots\<close> |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
395 |
assume "(\<exists>v\<in>vars_of M \<union> vars_of M'. elim \<theta> v)" |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
396 |
then obtain v |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30909
diff
changeset
|
397 |
where "elim \<theta> v" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30909
diff
changeset
|
398 |
and "v\<in>vars_of M \<union> vars_of M'" by auto |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
399 |
with unify_vars[OF inner] |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
400 |
have "vars_of (N\<lhd>\<theta>) \<union> vars_of (N'\<lhd>\<theta>) |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30909
diff
changeset
|
401 |
\<subset> vars_of (M\<cdot>N) \<union> vars_of (M'\<cdot>N')" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30909
diff
changeset
|
402 |
by auto |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
403 |
|
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
404 |
thus ?thesis |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
405 |
by (auto intro!: measures_less intro: psubset_card_mono) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
406 |
next |
61933 | 407 |
\<comment> \<open>Or the substitution is empty\<close> |
44367
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
408 |
assume "\<theta> \<doteq> []" |
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
409 |
hence "N \<lhd> \<theta> = N" |
74c08021ab2e
changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents:
42463
diff
changeset
|
410 |
and "N' \<lhd> \<theta> = N'" by auto |
22999
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
411 |
thus ?thesis |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
412 |
by (auto intro!: measures_less intro: psubset_card_mono) |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
413 |
qed |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
414 |
qed |
c1ce129e6f9c
Added unification case study (using new function package)
krauss
parents:
diff
changeset
|
415 |
|
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
416 |
|
61343 | 417 |
subsection \<open>Unification returns a Most General Unifier\<close> |
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
418 |
|
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
419 |
lemma unify_computes_MGU: |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
420 |
"unify M N = Some \<sigma> \<Longrightarrow> MGU \<sigma> M N" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
421 |
proof (induct M N arbitrary: \<sigma> rule: unify.induct) |
67443
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents:
62390
diff
changeset
|
422 |
case (7 M N M' N' \<sigma>) \<comment> \<open>The interesting case\<close> |
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
423 |
|
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
424 |
then obtain \<theta>1 \<theta>2 |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
425 |
where "unify M M' = Some \<theta>1" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
426 |
and "unify (N \<lhd> \<theta>1) (N' \<lhd> \<theta>1) = Some \<theta>2" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
427 |
and \<sigma>: "\<sigma> = \<theta>1 \<lozenge> \<theta>2" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
428 |
and MGU_inner: "MGU \<theta>1 M M'" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
429 |
and MGU_outer: "MGU \<theta>2 (N \<lhd> \<theta>1) (N' \<lhd> \<theta>1)" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
430 |
by (auto split:option.split_asm) |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
431 |
|
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
432 |
show ?case |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
433 |
proof |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
434 |
from MGU_inner and MGU_outer |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
435 |
have "M \<lhd> \<theta>1 = M' \<lhd> \<theta>1" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
436 |
and "N \<lhd> \<theta>1 \<lhd> \<theta>2 = N' \<lhd> \<theta>1 \<lhd> \<theta>2" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
437 |
unfolding MGU_def Unifier_def |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
438 |
by auto |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
439 |
thus "M \<cdot> N \<lhd> \<sigma> = M' \<cdot> N' \<lhd> \<sigma>" unfolding \<sigma> |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
440 |
by simp |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
441 |
next |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
442 |
fix \<sigma>' assume "M \<cdot> N \<lhd> \<sigma>' = M' \<cdot> N' \<lhd> \<sigma>'" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
443 |
hence "M \<lhd> \<sigma>' = M' \<lhd> \<sigma>'" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
444 |
and Ns: "N \<lhd> \<sigma>' = N' \<lhd> \<sigma>'" by auto |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
445 |
|
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
446 |
with MGU_inner obtain \<delta> |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
447 |
where eqv: "\<sigma>' \<doteq> \<theta>1 \<lozenge> \<delta>" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
448 |
unfolding MGU_def Unifier_def |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
449 |
by auto |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
450 |
|
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
451 |
from Ns have "N \<lhd> \<theta>1 \<lhd> \<delta> = N' \<lhd> \<theta>1 \<lhd> \<delta>" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
452 |
by (simp add:subst_eq_dest[OF eqv]) |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
453 |
|
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
454 |
with MGU_outer obtain \<rho> |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
455 |
where eqv2: "\<delta> \<doteq> \<theta>2 \<lozenge> \<rho>" |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
456 |
unfolding MGU_def Unifier_def |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
457 |
by auto |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
458 |
|
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
459 |
have "\<sigma>' \<doteq> \<sigma> \<lozenge> \<rho>" unfolding \<sigma> |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
460 |
by (rule subst_eq_intro, auto simp:subst_eq_dest[OF eqv] subst_eq_dest[OF eqv2]) |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
461 |
thus "\<exists>\<gamma>. \<sigma>' \<doteq> \<sigma> \<lozenge> \<gamma>" .. |
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
462 |
qed |
62390 | 463 |
qed (auto simp: MGU_Const intro: MGU_Var MGU_Var[symmetric] split: if_split_asm) |
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
464 |
|
44372 | 465 |
|
61343 | 466 |
subsection \<open>Unification returns Idempotent Substitution\<close> |
44372 | 467 |
|
468 |
definition Idem :: "'a subst \<Rightarrow> bool" |
|
469 |
where "Idem s \<longleftrightarrow> (s \<lozenge> s) \<doteq> s" |
|
470 |
||
44371
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
471 |
lemma Idem_Nil [iff]: "Idem []" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
472 |
by (simp add: Idem_def) |
44370
03d91bfad83b
tuned proofs, sledgehammering overly verbose parts
krauss
parents:
44369
diff
changeset
|
473 |
|
44371
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
474 |
lemma Var_Idem: |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
475 |
assumes "~ (Var v \<prec> t)" shows "Idem [(v,t)]" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
476 |
unfolding Idem_def |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
477 |
proof |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
478 |
from assms have [simp]: "t \<lhd> [(v, t)] = t" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
479 |
by (metis assoc.simps(2) subst.simps(1) subst_no_occs) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
480 |
|
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
481 |
fix s show "s \<lhd> [(v, t)] \<lozenge> [(v, t)] = s \<lhd> [(v, t)]" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
482 |
by (induct s) auto |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
483 |
qed |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
484 |
|
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
485 |
lemma Unifier_Idem_subst: |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
486 |
"Idem(r) \<Longrightarrow> Unifier s (t \<lhd> r) (u \<lhd> r) \<Longrightarrow> |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
487 |
Unifier (r \<lozenge> s) (t \<lhd> r) (u \<lhd> r)" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
488 |
by (simp add: Idem_def Unifier_def subst_eq_def) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
489 |
|
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
490 |
lemma Idem_comp: |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
491 |
"Idem r \<Longrightarrow> Unifier s (t \<lhd> r) (u \<lhd> r) \<Longrightarrow> |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
492 |
(!!q. Unifier q (t \<lhd> r) (u \<lhd> r) \<Longrightarrow> s \<lozenge> q \<doteq> q) \<Longrightarrow> |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
493 |
Idem (r \<lozenge> s)" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
494 |
apply (frule Unifier_Idem_subst, blast) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
495 |
apply (force simp add: Idem_def subst_eq_def) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
496 |
done |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
497 |
|
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
498 |
theorem unify_gives_Idem: |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
499 |
"unify M N = Some \<sigma> \<Longrightarrow> Idem \<sigma>" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
500 |
proof (induct M N arbitrary: \<sigma> rule: unify.induct) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
501 |
case (7 M M' N N' \<sigma>) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
502 |
|
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
503 |
then obtain \<theta>1 \<theta>2 |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
504 |
where "unify M N = Some \<theta>1" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
505 |
and \<theta>2: "unify (M' \<lhd> \<theta>1) (N' \<lhd> \<theta>1) = Some \<theta>2" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
506 |
and \<sigma>: "\<sigma> = \<theta>1 \<lozenge> \<theta>2" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
507 |
and "Idem \<theta>1" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
508 |
and "Idem \<theta>2" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
509 |
by (auto split: option.split_asm) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
510 |
|
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
511 |
from \<theta>2 have "Unifier \<theta>2 (M' \<lhd> \<theta>1) (N' \<lhd> \<theta>1)" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
512 |
by (rule unify_computes_MGU[THEN MGU_is_Unifier]) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
513 |
|
61343 | 514 |
with \<open>Idem \<theta>1\<close> |
44371
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
515 |
show "Idem \<sigma>" unfolding \<sigma> |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
516 |
proof (rule Idem_comp) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
517 |
fix \<sigma> assume "Unifier \<sigma> (M' \<lhd> \<theta>1) (N' \<lhd> \<theta>1)" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
518 |
with \<theta>2 obtain \<gamma> where \<sigma>: "\<sigma> \<doteq> \<theta>2 \<lozenge> \<gamma>" |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
519 |
using unify_computes_MGU MGU_def by blast |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
520 |
|
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
521 |
have "\<theta>2 \<lozenge> \<sigma> \<doteq> \<theta>2 \<lozenge> (\<theta>2 \<lozenge> \<gamma>)" by (rule subst_cong) (auto simp: \<sigma>) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
522 |
also have "... \<doteq> (\<theta>2 \<lozenge> \<theta>2) \<lozenge> \<gamma>" by (rule comp_assoc[symmetric]) |
61343 | 523 |
also have "... \<doteq> \<theta>2 \<lozenge> \<gamma>" by (rule subst_cong) (auto simp: \<open>Idem \<theta>2\<close>[unfolded Idem_def]) |
44371
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
524 |
also have "... \<doteq> \<sigma>" by (rule \<sigma>[symmetric]) |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
525 |
finally show "\<theta>2 \<lozenge> \<sigma> \<doteq> \<sigma>" . |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
526 |
qed |
3a10392fb8c3
added proof of idempotence, roughly after HOL/Subst/Unify.thy
krauss
parents:
44370
diff
changeset
|
527 |
qed (auto intro!: Var_Idem split: option.splits if_splits) |
39754 | 528 |
|
75635
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
529 |
|
75637
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
530 |
subsection \<open>Unification Returns Substitution With Minimal Range \<close> |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
531 |
|
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
532 |
definition range_vars where |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
533 |
"range_vars \<sigma> = \<Union> {vars_of (Var x \<lhd> \<sigma>) |x. Var x \<lhd> \<sigma> \<noteq> Var x}" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
534 |
|
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
535 |
lemma vars_of_subst_subset: "vars_of (N \<lhd> \<sigma>) \<subseteq> vars_of N \<union> range_vars \<sigma>" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
536 |
proof (rule subsetI) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
537 |
fix x assume "x \<in> vars_of (N \<lhd> \<sigma>)" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
538 |
thus "x \<in> vars_of N \<union> range_vars \<sigma>" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
539 |
proof (induction N) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
540 |
case (Var y) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
541 |
then show ?case |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
542 |
unfolding range_vars_def vars_of.simps |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
543 |
by force |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
544 |
next |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
545 |
case (Const y) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
546 |
then show ?case by simp |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
547 |
next |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
548 |
case (Comb N1 N2) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
549 |
then show ?case |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
550 |
by auto |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
551 |
qed |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
552 |
qed |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
553 |
|
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
554 |
lemma range_vars_comp_subset: "range_vars (\<sigma>\<^sub>1 \<lozenge> \<sigma>\<^sub>2) \<subseteq> range_vars \<sigma>\<^sub>1 \<union> range_vars \<sigma>\<^sub>2" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
555 |
proof (rule subsetI) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
556 |
fix x assume "x \<in> range_vars (\<sigma>\<^sub>1 \<lozenge> \<sigma>\<^sub>2)" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
557 |
then obtain x' where |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
558 |
x'_\<sigma>\<^sub>1_\<sigma>\<^sub>2: "Var x' \<lhd> \<sigma>\<^sub>1 \<lhd> \<sigma>\<^sub>2 \<noteq> Var x'" and x_in: "x \<in> vars_of (Var x' \<lhd> \<sigma>\<^sub>1 \<lhd> \<sigma>\<^sub>2)" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
559 |
unfolding range_vars_def by auto |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
560 |
|
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
561 |
show "x \<in> range_vars \<sigma>\<^sub>1 \<union> range_vars \<sigma>\<^sub>2" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
562 |
proof (cases "Var x' \<lhd> \<sigma>\<^sub>1 = Var x'") |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
563 |
case True |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
564 |
with x'_\<sigma>\<^sub>1_\<sigma>\<^sub>2 x_in show ?thesis |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
565 |
unfolding range_vars_def by auto |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
566 |
next |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
567 |
case x'_\<sigma>\<^sub>1_neq: False |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
568 |
show ?thesis |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
569 |
proof (cases "Var x' \<lhd> \<sigma>\<^sub>1 \<lhd> \<sigma>\<^sub>2 = Var x' \<lhd> \<sigma>\<^sub>1") |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
570 |
case True |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
571 |
with x'_\<sigma>\<^sub>1_\<sigma>\<^sub>2 x_in x'_\<sigma>\<^sub>1_neq show ?thesis |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
572 |
unfolding range_vars_def by auto |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
573 |
next |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
574 |
case False |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
575 |
with x_in obtain y where "y \<in> vars_of (Var x' \<lhd> \<sigma>\<^sub>1)" and "x \<in> vars_of (Var y \<lhd> \<sigma>\<^sub>2)" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
576 |
by (smt (verit, best) UN_iff image_iff vars_of_subst_conv_Union) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
577 |
with x'_\<sigma>\<^sub>1_neq show ?thesis |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
578 |
unfolding range_vars_def by force |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
579 |
qed |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
580 |
qed |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
581 |
qed |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
582 |
|
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
583 |
theorem unify_gives_minimal_range: |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
584 |
"unify M N = Some \<sigma> \<Longrightarrow> range_vars \<sigma> \<subseteq> vars_of M \<union> vars_of N" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
585 |
proof (induct M N arbitrary: \<sigma> rule: unify.induct) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
586 |
case (1 c M N) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
587 |
thus ?case by simp |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
588 |
next |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
589 |
case (2 M N c) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
590 |
thus ?case by simp |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
591 |
next |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
592 |
case (3 c v) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
593 |
hence "\<sigma> = [(v, Const c)]" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
594 |
by simp |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
595 |
thus ?case |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
596 |
by (simp add: range_vars_def) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
597 |
next |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
598 |
case (4 M N v) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
599 |
hence "\<sigma> = [(v, M \<cdot> N)]" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
600 |
by (metis option.discI option.sel unify.simps(4)) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
601 |
thus ?case |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
602 |
by (auto simp: range_vars_def) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
603 |
next |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
604 |
case (5 v M) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
605 |
hence "\<sigma> = [(v, M)]" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
606 |
by (metis option.discI option.inject unify.simps(5)) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
607 |
thus ?case |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
608 |
by (auto simp: range_vars_def) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
609 |
next |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
610 |
case (6 c d) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
611 |
hence "\<sigma> = []" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
612 |
by (metis option.distinct(1) option.sel unify.simps(6)) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
613 |
thus ?case |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
614 |
by (simp add: range_vars_def) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
615 |
next |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
616 |
case (7 M N M' N') |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
617 |
from "7.prems" obtain \<theta>\<^sub>1 \<theta>\<^sub>2 where |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
618 |
"unify M M' = Some \<theta>\<^sub>1" and "unify (N \<lhd> \<theta>\<^sub>1) (N' \<lhd> \<theta>\<^sub>1) = Some \<theta>\<^sub>2" and "\<sigma> = \<theta>\<^sub>1 \<lozenge> \<theta>\<^sub>2" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
619 |
apply simp |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
620 |
by (metis (no_types, lifting) option.case_eq_if option.collapse option.discI option.sel) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
621 |
|
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
622 |
from "7.hyps"(1) have range_\<theta>\<^sub>1: "range_vars \<theta>\<^sub>1 \<subseteq> vars_of M \<union> vars_of M'" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
623 |
using \<open>unify M M' = Some \<theta>\<^sub>1\<close> by simp |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
624 |
|
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
625 |
from "7.hyps"(2) have "range_vars \<theta>\<^sub>2 \<subseteq> vars_of (N \<lhd> \<theta>\<^sub>1) \<union> vars_of (N' \<lhd> \<theta>\<^sub>1)" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
626 |
using \<open>unify M M' = Some \<theta>\<^sub>1\<close> \<open>unify (N \<lhd> \<theta>\<^sub>1) (N' \<lhd> \<theta>\<^sub>1) = Some \<theta>\<^sub>2\<close> by simp |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
627 |
hence range_\<theta>\<^sub>2: "range_vars \<theta>\<^sub>2 \<subseteq> vars_of N \<union> vars_of N' \<union> range_vars \<theta>\<^sub>1" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
628 |
using vars_of_subst_subset[of _ \<theta>\<^sub>1] by auto |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
629 |
|
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
630 |
have "range_vars \<sigma> = range_vars (\<theta>\<^sub>1 \<lozenge> \<theta>\<^sub>2)" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
631 |
unfolding \<open>\<sigma> = \<theta>\<^sub>1 \<lozenge> \<theta>\<^sub>2\<close> by simp |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
632 |
also have "... \<subseteq> range_vars \<theta>\<^sub>1 \<union> range_vars \<theta>\<^sub>2" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
633 |
by (rule range_vars_comp_subset) |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
634 |
also have "... \<subseteq> range_vars \<theta>\<^sub>1 \<union> vars_of N \<union> vars_of N'" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
635 |
using range_\<theta>\<^sub>2 by auto |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
636 |
also have "... \<subseteq> vars_of M \<union> vars_of M' \<union> vars_of N \<union> vars_of N'" |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
637 |
using range_\<theta>\<^sub>1 by auto |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
638 |
finally show ?case |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
639 |
by auto |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
640 |
qed |
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
641 |
|
66a9aa769d63
added definition range_vars and lemmas vars_of_subst_conv_Union, vars_of_subst_subset, range_vars_comp_subset, and unify_gives_minimal_range
desharna
parents:
75635
diff
changeset
|
642 |
|
75635
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
643 |
subsection \<open>Idempotent Most General Unifier\<close> |
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
644 |
|
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
645 |
definition IMGU :: "'a subst \<Rightarrow> 'a trm \<Rightarrow> 'a trm \<Rightarrow> bool" where |
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
646 |
"IMGU \<mu> t u \<longleftrightarrow> Unifier \<mu> t u \<and> (\<forall>\<theta>. Unifier \<theta> t u \<longrightarrow> \<theta> \<doteq> \<mu> \<lozenge> \<theta>)" |
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
647 |
|
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
648 |
lemma IMGU_iff_Idem_and_MGU: "IMGU \<mu> t u \<longleftrightarrow> Idem \<mu> \<and> MGU \<mu> t u" |
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
649 |
unfolding IMGU_def Idem_def MGU_def |
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
650 |
by (smt (verit, best) subst_comp subst_eq_def) |
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
651 |
|
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
652 |
lemma unify_computes_IMGU: |
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
653 |
"unify M N = Some \<sigma> \<Longrightarrow> IMGU \<sigma> M N" |
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
654 |
by (simp add: IMGU_iff_Idem_and_MGU unify_computes_MGU unify_gives_Idem) |
3ba38a119739
added definition IMGU and lemmas IMGU_iff_Idem_and_MGU and unify_computes_IMGU
desharna
parents:
67443
diff
changeset
|
655 |
|
23219 | 656 |
end |