src/HOL/ex/Unification.thy
author krauss
Sun, 21 Aug 2011 22:13:04 +0200
changeset 44369 02e13192a053
parent 44368 91e8062605d5
child 44370 03d91bfad83b
permissions -rw-r--r--
tuned notation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41460
ea56b98aee83 removing obselete Id comments from HOL/ex theories
bulwahn
parents: 39754
diff changeset
     1
(*
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
     2
    Author:     Alexander Krauss, Technische Universitaet Muenchen
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
     3
*)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
     4
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
     5
header {* Case study: Unification Algorithm *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
     6
23219
87ad6e8a5f2c tuned document;
wenzelm
parents: 23024
diff changeset
     7
theory Unification
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
     8
imports Main
23219
87ad6e8a5f2c tuned document;
wenzelm
parents: 23024
diff changeset
     9
begin
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    10
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    11
text {* 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    12
  This is a formalization of a first-order unification
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    13
  algorithm. It uses the new "function" package to define recursive
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    14
  functions, which allows a better treatment of nested recursion. 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    15
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    16
  This is basically a modernized version of a previous formalization
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    17
  by Konrad Slind (see: HOL/Subst/Unify.thy), which itself builds on
23219
87ad6e8a5f2c tuned document;
wenzelm
parents: 23024
diff changeset
    18
  previous work by Paulson and Manna \& Waldinger (for details, see
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    19
  there).
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    20
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    21
  Unlike that formalization, where the proofs of termination and
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    22
  some partial correctness properties are intertwined, we can prove
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    23
  partial correctness and termination separately.
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    24
*}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    25
23219
87ad6e8a5f2c tuned document;
wenzelm
parents: 23024
diff changeset
    26
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    27
subsection {* Terms *}
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    28
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    29
text {* Binary trees with leaves that are constants or variables. *}
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    30
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    31
datatype 'a trm = 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    32
  Var 'a 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    33
  | 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
    34
  | Comb "'a trm" "'a trm" (infix "\<cdot>" 60)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    35
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    36
primrec vars_of :: "'a trm \<Rightarrow> 'a set"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    37
where
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    38
  "vars_of (Var v) = {v}"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    39
| "vars_of (Const c) = {}"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    40
| "vars_of (M \<cdot> N) = vars_of M \<union> vars_of N"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    41
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    42
fun occs :: "'a trm \<Rightarrow> 'a trm \<Rightarrow> bool" (infixl "\<prec>" 54) 
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    43
where
44369
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
    44
  "u \<prec> Var v \<longleftrightarrow> False"
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
    45
| "u \<prec> Const c \<longleftrightarrow> False"
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
    46
| "u \<prec> M \<cdot> N \<longleftrightarrow> u = M \<or> u = N \<or> u \<prec> M \<or> u \<prec> N"
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    47
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    48
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    49
lemma finite_vars_of[intro]: "finite (vars_of t)"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    50
  by (induct t) simp_all
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    51
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    52
lemma vars_var_iff: "v \<in> vars_of (Var w) \<longleftrightarrow> w = v"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    53
  by auto
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    54
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    55
lemma vars_iff_occseq: "x \<in> vars_of t \<longleftrightarrow> Var x \<prec> t \<or> Var x = t"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    56
  by (induct t) auto
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    57
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    58
lemma occs_vars_subset: "M \<prec> N \<Longrightarrow> vars_of M \<subseteq> vars_of N"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    59
  by (induct N) auto
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    60
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    61
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    62
subsection {* Substitutions *}
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    63
42463
f270e3e18be5 modernized specifications;
wenzelm
parents: 41460
diff changeset
    64
type_synonym 'a subst = "('a \<times> 'a trm) list"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    65
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    66
text {* Applying a substitution to a variable: *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    67
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    68
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
    69
where
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    70
  "assoc x d [] = d"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    71
| "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
    72
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    73
text {* Applying a substitution to a term: *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
    74
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
    75
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
    76
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
    77
  "(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
    78
| "(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
    79
| "(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
    80
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    81
definition subst_eq (infixr "\<doteq>" 52)
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    82
where
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    83
  "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
    84
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    85
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
    86
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
    87
  "[] \<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
    88
| "((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
    89
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    90
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    91
subsection {* Basic Laws *}
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    92
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    93
lemma subst_Nil[simp]: "t \<lhd> [] = t"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    94
by (induct t) auto
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    95
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    96
lemma subst_mono: "t \<prec> u \<Longrightarrow> t \<lhd> s \<prec> u \<lhd> s"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    97
by (induct u) auto
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    98
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
    99
lemma agreement: "(t \<lhd> r = t \<lhd> s) \<longleftrightarrow> (\<forall>v \<in> vars_of t. Var v \<lhd> r = Var v \<lhd> s)"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   100
by (induct t) auto
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   101
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   102
lemma repl_invariance: "v \<notin> vars_of t \<Longrightarrow> t \<lhd> (v,u) # s = t \<lhd> s"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   103
by (simp add: agreement)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   104
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   105
lemma Var_in_subst:
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   106
  "v \<in> vars_of t \<Longrightarrow> w \<in> vars_of (t \<lhd> (v, Var(w)) # s)"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   107
by (induct t) auto
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   108
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   109
lemma subst_refl[iff]: "s \<doteq> s"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   110
  by (auto simp:subst_eq_def)
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   111
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   112
lemma subst_sym[sym]: "\<lbrakk>s1 \<doteq> s2\<rbrakk> \<Longrightarrow> s2 \<doteq> s1"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   113
  by (auto simp:subst_eq_def)
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   114
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   115
lemma subst_trans[trans]: "\<lbrakk>s1 \<doteq> s2; s2 \<doteq> s3\<rbrakk> \<Longrightarrow> s1 \<doteq> s3"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   116
  by (auto simp:subst_eq_def)
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   117
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   118
text {* Composition of Substitutions *}
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   119
23219
87ad6e8a5f2c tuned document;
wenzelm
parents: 23024
diff changeset
   120
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   121
lemma comp_Nil[simp]: "\<sigma> \<lozenge> [] = \<sigma>"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   122
by (induct \<sigma>) auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   123
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   124
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
   125
proof (induct t)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   126
  case (Var v) thus ?case
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   127
    by (induct r) auto
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   128
qed auto
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   129
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   130
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
   131
  by (auto simp:subst_eq_def)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   132
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   133
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
   134
  by (auto simp:subst_eq_def)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   135
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   136
lemma comp_assoc: "(a \<lozenge> b) \<lozenge> c \<doteq> a \<lozenge> (b \<lozenge> c)"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   137
  by auto
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   138
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   139
lemma subst_cong: "\<lbrakk>\<sigma> \<doteq> \<sigma>'; \<theta> \<doteq> \<theta>'\<rbrakk> \<Longrightarrow> (\<sigma> \<lozenge> \<theta>) \<doteq> (\<sigma>' \<lozenge> \<theta>')"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   140
  by (auto simp: subst_eq_def)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   141
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   142
23219
87ad6e8a5f2c tuned document;
wenzelm
parents: 23024
diff changeset
   143
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   144
subsection {* Specification: Most general unifiers *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   145
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   146
definition Unifier :: "'a subst \<Rightarrow> 'a trm \<Rightarrow> 'a trm \<Rightarrow> bool"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   147
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
   148
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   149
definition MGU :: "'a subst \<Rightarrow> 'a trm \<Rightarrow> 'a trm \<Rightarrow> bool" where
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   150
  "MGU \<sigma> t u \<longleftrightarrow> 
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   151
   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
   152
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   153
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
   154
  "\<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
   155
  \<Longrightarrow> MGU \<sigma> t u"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   156
  by (simp only:Unifier_def MGU_def, auto)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   157
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   158
lemma MGU_sym[sym]:
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   159
  "MGU \<sigma> s t \<Longrightarrow> MGU \<sigma> t s"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   160
  by (auto simp:MGU_def Unifier_def)
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
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   163
definition Idem :: "'a subst \<Rightarrow> bool"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   164
where "Idem s \<longleftrightarrow> (s \<lozenge> s) \<doteq> s"
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   165
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   166
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   167
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   168
subsection {* The unification algorithm *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   169
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   170
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   171
text {* The unification algorithm: *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   172
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   173
function unify :: "'a trm \<Rightarrow> 'a trm \<Rightarrow> 'a subst option"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   174
where
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   175
  "unify (Const c) (M \<cdot> N)   = None"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   176
| "unify (M \<cdot> N)   (Const c) = None"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   177
| "unify (Const c) (Var v)   = Some [(v, Const c)]"
44369
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
   178
| "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
   179
                                        then None
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   180
                                        else Some [(v, M \<cdot> N)])"
44369
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
   181
| "unify (Var v)   M         = (if Var v \<prec> M
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   182
                                        then None
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   183
                                        else Some [(v, M)])"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   184
| "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
   185
| "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
   186
                                    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
   187
                                    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
   188
                                      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
   189
                                         Some \<sigma> \<Rightarrow> Some (\<theta> \<lozenge> \<sigma>)))"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   190
  by pat_completeness auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   191
39754
150f831ce4a3 no longer declare .psimps rules as [simp].
krauss
parents: 32960
diff changeset
   192
declare unify.psimps[simp]
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   193
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   194
subsection {* Partial correctness *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   195
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   196
text {* Some lemmas about occs and MGU: *}
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   197
44369
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
   198
lemma subst_no_occs: "\<not> Var v \<prec> t \<Longrightarrow> Var v \<noteq> 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
   199
  \<Longrightarrow> t \<lhd> [(v,s)] = t"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   200
by (induct t) auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   201
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   202
lemma MGU_Var[intro]: 
44369
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
   203
  assumes no_occs: "\<not> Var v \<prec> t"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   204
  shows "MGU [(v,t)] (Var v) t"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   205
proof (intro MGUI exI)
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
  show "Var v \<lhd> [(v,t)] = t \<lhd> [(v,t)]" using no_occs
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   207
    by (cases "Var v = t", auto simp:subst_no_occs)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   208
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
   209
  fix \<theta> assume th: "Var v \<lhd> \<theta> = t \<lhd> \<theta>" 
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   210
  show "\<theta> \<doteq> [(v,t)] \<lozenge> \<theta>" 
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   211
  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
   212
    fix s show "s \<lhd> \<theta> = s \<lhd> [(v,t)] \<lozenge> \<theta>" using th 
24444
448978b61556 induct: proper separation of initial and terminal step;
wenzelm
parents: 23777
diff changeset
   213
      by (induct s) auto
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   214
  qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   215
qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   216
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   217
declare MGU_Var[symmetric, intro]
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   218
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   219
lemma MGU_Const[simp]: "MGU [] (Const c) (Const d) = (c = d)"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   220
  unfolding MGU_def Unifier_def
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   221
  by auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   222
  
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   223
text {* If unification terminates, then it computes most general unifiers: *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   224
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   225
lemma unify_partial_correctness:
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   226
  assumes "unify_dom (M, N)"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   227
  assumes "unify M N = Some \<sigma>"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   228
  shows "MGU \<sigma> M N"
24444
448978b61556 induct: proper separation of initial and terminal step;
wenzelm
parents: 23777
diff changeset
   229
using assms
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   230
proof (induct M N arbitrary: \<sigma>)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   231
  case (7 M N M' N' \<sigma>) -- "The interesting case"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   232
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   233
  then obtain \<theta>1 \<theta>2 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   234
    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
   235
    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
   236
    and \<sigma>: "\<sigma> = \<theta>1 \<lozenge> \<theta>2"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   237
    and MGU_inner: "MGU \<theta>1 M M'" 
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   238
    and MGU_outer: "MGU \<theta>2 (N \<lhd> \<theta>1) (N' \<lhd> \<theta>1)"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   239
    by (auto split:option.split_asm)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   240
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   241
  show ?case
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   242
  proof
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   243
    from MGU_inner and MGU_outer
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   244
    have "M \<lhd> \<theta>1 = M' \<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
   245
      and "N \<lhd> \<theta>1 \<lhd> \<theta>2 = N' \<lhd> \<theta>1 \<lhd> \<theta>2"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   246
      unfolding MGU_def Unifier_def
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   247
      by 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
   248
    thus "M \<cdot> N \<lhd> \<sigma> = M' \<cdot> N' \<lhd> \<sigma>" unfolding \<sigma>
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   249
      by simp
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   250
  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
   251
    fix \<sigma>' assume "M \<cdot> N \<lhd> \<sigma>' = M' \<cdot> N' \<lhd> \<sigma>'"
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   252
    hence "M \<lhd> \<sigma>' = M' \<lhd> \<sigma>'"
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   253
      and Ns: "N \<lhd> \<sigma>' = N' \<lhd> \<sigma>'" by auto
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   254
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   255
    with MGU_inner obtain \<delta>
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   256
      where eqv: "\<sigma>' \<doteq> \<theta>1 \<lozenge> \<delta>"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   257
      unfolding MGU_def Unifier_def
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   258
      by auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   259
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
    from Ns have "N \<lhd> \<theta>1 \<lhd> \<delta> = N' \<lhd> \<theta>1 \<lhd> \<delta>"
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   261
      by (simp add:subst_eq_dest[OF eqv])
22999
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
    with MGU_outer obtain \<rho>
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   264
      where eqv2: "\<delta> \<doteq> \<theta>2 \<lozenge> \<rho>"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   265
      unfolding MGU_def Unifier_def
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   266
      by auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   267
    
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   268
    have "\<sigma>' \<doteq> \<sigma> \<lozenge> \<rho>" unfolding \<sigma>
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   269
      by (rule subst_eq_intro, auto simp:subst_eq_dest[OF eqv] subst_eq_dest[OF eqv2])
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   270
    thus "\<exists>\<gamma>. \<sigma>' \<doteq> \<sigma> \<lozenge> \<gamma>" ..
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   271
  qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   272
qed (auto split:split_if_asm) -- "Solve the remaining cases automatically"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   273
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   274
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   275
subsection {* Properties used in termination proof *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   276
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   277
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   278
text {* Elimination of variables by a substitution: *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   279
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   280
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
   281
  "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
   282
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
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
   284
  by (auto simp:elim_def)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   285
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   286
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
   287
  by (auto simp:elim_def)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   288
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   289
lemma elim_eqv: "\<sigma> \<doteq> \<theta> \<Longrightarrow> elim \<sigma> x = elim \<theta> x"
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   290
  by (auto simp:elim_def subst_eq_def)
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
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   293
text {* Replacing a variable by itself yields an identity subtitution: *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   294
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   295
lemma var_self[intro]: "[(v, Var v)] \<doteq> []"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   296
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
   297
  fix t show "t \<lhd> [(v, Var v)] = t \<lhd> []"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   298
    by (induct t) simp_all
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   299
qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   300
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   301
lemma var_same: "([(v, t)] \<doteq> []) = (t = Var v)"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   302
proof
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   303
  assume t_v: "t = Var 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
   304
  thus "[(v, t)] \<doteq> []"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   305
    by auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   306
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
   307
  assume id: "[(v, t)] \<doteq> []"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   308
  show "t = Var v"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   309
  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
   310
    have "t = Var v \<lhd> [(v, t)]" by simp
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   311
    also from id have "\<dots> = Var v \<lhd> []" ..
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   312
    finally show ?thesis by simp
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   313
  qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   314
qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   315
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
text {* A lemma about occs and elim *}
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   317
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   318
lemma remove_var:
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   319
  assumes [simp]: "v \<notin> vars_of s"
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   320
  shows "v \<notin> vars_of (t \<lhd> [(v, s)])"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   321
  by (induct t) simp_all
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   322
44369
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
   323
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
   324
  \<Longrightarrow> elim [(v,t)] v \<or> [(v,t)] \<doteq> []"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   325
proof (induct t)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   326
  case (Var x)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   327
  show ?case
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   328
  proof cases
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   329
    assume "v = x"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   330
    thus ?thesis
30909
bd4f255837e5 tuned proof
krauss
parents: 24444
diff changeset
   331
      by (simp add:var_same)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   332
  next
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   333
    assume neq: "v \<noteq> x"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   334
    have "elim [(v, Var x)] v"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   335
      by (auto intro!:remove_var simp:neq)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   336
    thus ?thesis ..
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   337
  qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   338
next
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   339
  case (Const c)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   340
  have "elim [(v, Const c)] v"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   341
    by (auto intro!:remove_var)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   342
  thus ?case ..
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   343
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
   344
  case (Comb M N)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   345
  
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
  hence ih1: "elim [(v, M)] v \<or> [(v, M)] \<doteq> []"
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   347
    and ih2: "elim [(v, N)] v \<or> [(v, N)] \<doteq> []"
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   348
    and nonoccs: "Var v \<noteq> M" "Var v \<noteq> N"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   349
    by auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   350
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   351
  from nonoccs have "\<not> [(v,M)] \<doteq> []"
30909
bd4f255837e5 tuned proof
krauss
parents: 24444
diff changeset
   352
    by (simp add:var_same)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   353
  with ih1 have "elim [(v, M)] v" by blast
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   354
  hence "v \<notin> vars_of (Var v \<lhd> [(v,M)])" ..
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   355
  hence not_in_M: "v \<notin> vars_of M" by simp
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   356
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
  from nonoccs have "\<not> [(v,N)] \<doteq> []"
30909
bd4f255837e5 tuned proof
krauss
parents: 24444
diff changeset
   358
    by (simp add:var_same)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   359
  with ih2 have "elim [(v, N)] v" by blast
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   360
  hence "v \<notin> vars_of (Var v \<lhd> [(v,N)])" ..
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   361
  hence not_in_N: "v \<notin> vars_of N" by simp
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   362
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   363
  have "elim [(v, M \<cdot> N)] v"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   364
  proof 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   365
    fix 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
   366
    show "v \<notin> vars_of (t \<lhd> [(v, M \<cdot> N)])"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   367
    proof (induct t)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   368
      case (Var x) thus ?case by (simp add: not_in_M not_in_N)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   369
    qed auto
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
  thus ?case ..
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   372
qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   373
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   374
text {* The result of a unification never introduces new variables: *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   375
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   376
lemma unify_vars: 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   377
  assumes "unify_dom (M, N)"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   378
  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
   379
  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
   380
  (is "?P M N \<sigma> t")
24444
448978b61556 induct: proper separation of initial and terminal step;
wenzelm
parents: 23777
diff changeset
   381
using assms
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   382
proof (induct M N arbitrary:\<sigma> t)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   383
  case (3 c v) 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   384
  hence "\<sigma> = [(v, Const c)]" by simp
24444
448978b61556 induct: proper separation of initial and terminal step;
wenzelm
parents: 23777
diff changeset
   385
  thus ?case by (induct t) auto
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   386
next
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   387
  case (4 M N v) 
44369
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
   388
  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
   389
  with 4 have "\<sigma> = [(v, M\<cdot>N)]" by simp
448978b61556 induct: proper separation of initial and terminal step;
wenzelm
parents: 23777
diff changeset
   390
  thus ?case by (induct t) auto
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   391
next
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   392
  case (5 v M)
44369
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
   393
  hence "\<not> Var v \<prec> M" by auto
24444
448978b61556 induct: proper separation of initial and terminal step;
wenzelm
parents: 23777
diff changeset
   394
  with 5 have "\<sigma> = [(v, M)]" by simp
448978b61556 induct: proper separation of initial and terminal step;
wenzelm
parents: 23777
diff changeset
   395
  thus ?case by (induct t) auto
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   396
next
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   397
  case (7 M N M' N' \<sigma>)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   398
  then obtain \<theta>1 \<theta>2 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   399
    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
   400
    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
   401
    and \<sigma>: "\<sigma> = \<theta>1 \<lozenge> \<theta>2"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   402
    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
   403
    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
   404
    by (auto split:option.split_asm)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   405
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   406
  show ?case
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   407
  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
   408
    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
   409
    
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   410
    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
   411
    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
   412
        \<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
   413
      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
   414
      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
   415
        by auto
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   416
      
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   417
      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
   418
      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
   419
        \<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
   420
        by auto
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   421
      hence "v \<in> vars_of t"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   422
      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
   423
        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
   424
        with True show ?thesis by (auto dest:l)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   425
      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
   426
        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
   427
        thus ?thesis by (rule l)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   428
      qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   429
      
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   430
      thus ?thesis by auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   431
    qed auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   432
  qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   433
qed (auto split: split_if_asm)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   434
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   435
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   436
text {* The result of a unification is either the identity
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   437
substitution or it eliminates a variable from one of the terms: *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   438
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   439
lemma unify_eliminates: 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   440
  assumes "unify_dom (M, N)"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   441
  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
   442
  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
   443
  (is "?P M N \<sigma>")
24444
448978b61556 induct: proper separation of initial and terminal step;
wenzelm
parents: 23777
diff changeset
   444
using assms
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   445
proof (induct M N arbitrary:\<sigma>)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   446
  case 1 thus ?case by simp
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   447
next
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   448
  case 2 thus ?case by simp
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   449
next
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   450
  case (3 c v)
44369
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
   451
  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
   452
  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
   453
  with occs_elim[OF no_occs]
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   454
  show ?case by auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   455
next
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   456
  case (4 M N v)
44369
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
   457
  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
   458
  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
   459
  with occs_elim[OF no_occs]
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   460
  show ?case by auto 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   461
next
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   462
  case (5 v M) 
44369
02e13192a053 tuned notation
krauss
parents: 44368
diff changeset
   463
  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
   464
  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
   465
  with occs_elim[OF no_occs]
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   466
  show ?case by auto 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   467
next 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   468
  case (6 c d) thus ?case
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   469
    by (cases "c = d") auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   470
next
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   471
  case (7 M N M' N' \<sigma>)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   472
  then obtain \<theta>1 \<theta>2 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   473
    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
   474
    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
   475
    and \<sigma>: "\<sigma> = \<theta>1 \<lozenge> \<theta>2"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   476
    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
   477
    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
   478
    by (auto split:option.split_asm)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   479
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   480
  from `unify_dom (M \<cdot> N, M' \<cdot> N')`
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   481
  have "unify_dom (M, M')"
23777
60b7800338d5 Renamed accessible part for predicates to accp.
berghofe
parents: 23373
diff changeset
   482
    by (rule accp_downward) (rule unify_rel.intros)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   483
  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
   484
    "\<And>t. vars_of (t \<lhd> \<theta>1) \<subseteq> vars_of M \<union> vars_of M' \<union> vars_of t"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 23219
diff changeset
   485
    by (rule unify_vars) (rule `unify M M' = Some \<theta>1`)
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   486
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   487
  from ih2 show ?case 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   488
  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
   489
    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
   490
    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
   491
      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
   492
      and el: "elim \<theta>2 v" by auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   493
    with no_new_vars show ?thesis unfolding \<sigma> 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   494
      by (auto simp:elim_def)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   495
  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
   496
    assume empty[simp]: "\<theta>2 \<doteq> []"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   497
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   498
    have "\<sigma> \<doteq> (\<theta>1 \<lozenge> [])" unfolding \<sigma>
44368
91e8062605d5 ported some lemmas from HOL/Subst/*;
krauss
parents: 44367
diff changeset
   499
      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
   500
    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
   501
    finally have "\<sigma> \<doteq> \<theta>1" .
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   502
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   503
    from ih1 show ?thesis
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   504
    proof
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   505
      assume "\<exists>v\<in>vars_of M \<union> vars_of M'. elim \<theta>1 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
   506
      with elim_eqv[OF `\<sigma> \<doteq> \<theta>1`]
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   507
      show ?thesis by auto
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   508
    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
   509
      note `\<sigma> \<doteq> \<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
   510
      also assume "\<theta>1 \<doteq> []"
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   511
      finally show ?thesis ..
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   512
    qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   513
  qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   514
qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   515
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   516
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   517
subsection {* Termination proof *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   518
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   519
termination unify
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   520
proof 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   521
  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
   522
                           \<lambda>(M, N). size M]"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   523
  show "wf ?R" by simp
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   524
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   525
  fix M N M' N' 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   526
  show "((M, M'), (M \<cdot> N, M' \<cdot> N')) \<in> ?R" -- "Inner call"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   527
    by (rule measures_lesseq) (auto intro: card_mono)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   528
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   529
  fix \<theta>                                   -- "Outer call"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   530
  assume inner: "unify_dom (M, M')"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   531
    "unify M M' = Some \<theta>"
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   532
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   533
  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
   534
  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
   535
  proof
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   536
    -- {* Either a variable is eliminated \ldots *}
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   537
    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
   538
    then obtain v 
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 30909
diff changeset
   539
      where "elim \<theta> v" 
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 30909
diff changeset
   540
      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
   541
    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
   542
    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
   543
      \<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
   544
      by auto
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   545
    
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   546
    thus ?thesis
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   547
      by (auto intro!: measures_less intro: psubset_card_mono)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   548
  next
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   549
    -- {* Or the substitution is empty *}
44367
74c08021ab2e changed constant names and notation to match HOL/Subst/*.thy, from which this theory is a clone.
krauss
parents: 42463
diff changeset
   550
    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
   551
    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
   552
      and "N' \<lhd> \<theta> = N'" by auto
22999
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   553
    thus ?thesis 
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   554
       by (auto intro!: measures_less intro: psubset_card_mono)
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   555
  qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   556
qed
c1ce129e6f9c Added unification case study (using new function package)
krauss
parents:
diff changeset
   557
39754
150f831ce4a3 no longer declare .psimps rules as [simp].
krauss
parents: 32960
diff changeset
   558
declare unify.psimps[simp del]
150f831ce4a3 no longer declare .psimps rules as [simp].
krauss
parents: 32960
diff changeset
   559
23219
87ad6e8a5f2c tuned document;
wenzelm
parents: 23024
diff changeset
   560
end