src/HOL/Subst/Unifier.thy
author haftmann
Tue, 10 Jul 2007 17:30:50 +0200
changeset 23709 fd31da8f752a
parent 15635 8408a06590a6
child 24823 bfb619994060
permissions -rw-r--r--
moved lfp_induct2 here
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15635
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
     1
(*  ID:         $Id$
1476
608483c2122a expanded tabs; incorporated Konrad's changes
clasohm
parents: 1374
diff changeset
     2
    Author:     Martin Coen, Cambridge University Computer Laboratory
968
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
     3
    Copyright   1993  University of Cambridge
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
     4
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
     5
*)
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
     6
15635
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
     7
header{*Definition of Most General Unifier*}
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
     8
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
     9
theory Unifier
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    10
imports Subst
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    11
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    12
begin
968
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
    13
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
    14
consts
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
    15
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents: 1476
diff changeset
    16
  Unifier   :: "[('a * 'a uterm)list, 'a uterm, 'a uterm] => bool"
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents: 1476
diff changeset
    17
  ">>"      :: "[('a * 'a uterm)list, ('a * 'a uterm)list] => bool" (infixr 52)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents: 1476
diff changeset
    18
  MGUnifier :: "[('a * 'a uterm)list, 'a uterm, 'a uterm] => bool"
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents: 1476
diff changeset
    19
  Idem      :: "('a * 'a uterm)list => bool"
968
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
    20
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents: 1476
diff changeset
    21
defs
968
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
    22
15635
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    23
  Unifier_def:      "Unifier s t u == t <| s = u <| s"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    24
  MoreGeneral_def:  "r >> s == ? q. s =$= r <> q"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    25
  MGUnifier_def:    "MGUnifier s t u == Unifier s t u & 
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    26
                                        (!r. Unifier r t u --> s >> r)"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    27
  Idem_def:         "Idem(s) == (s <> s) =$= s"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    28
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    29
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    30
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    31
lemmas unify_defs = Unifier_def MoreGeneral_def MGUnifier_def
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    32
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    33
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    34
subsection{*Unifiers*}
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    35
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    36
lemma Unifier_Comb [iff]: "Unifier s (Comb t u) (Comb v w) = (Unifier s t v & Unifier s u w)"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    37
by (simp add: Unifier_def)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    38
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    39
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    40
lemma Cons_Unifier: "[| v ~: vars_of t; v ~: vars_of u; Unifier s t u |] ==> Unifier ((v,r)#s) t u"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    41
by (simp add: Unifier_def repl_invariance)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    42
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    43
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    44
subsection{* Most General Unifiers*}
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    45
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    46
lemma mgu_sym: "MGUnifier s t u = MGUnifier s u t"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    47
by (simp add: unify_defs eq_commute)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    48
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    49
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    50
lemma MoreGen_Nil [iff]: "[] >> s"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    51
by (auto simp add: MoreGeneral_def)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    52
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    53
lemma MGU_iff: "MGUnifier s t u = (ALL r. Unifier r t u = s >> r)"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    54
apply (unfold unify_defs)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    55
apply (auto intro: ssubst_subst2 subst_comp_Nil)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    56
done
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    57
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    58
lemma MGUnifier_Var: "~ Var v <: t ==> MGUnifier [(v,t)] (Var v) t"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    59
apply (simp (no_asm) add: MGU_iff Unifier_def MoreGeneral_def del: subst_Var)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    60
apply safe
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    61
apply (rule exI)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    62
apply (erule subst, rule Cons_trivial [THEN subst_sym])
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    63
apply (erule ssubst_subst2)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    64
apply (simp (no_asm_simp) add: Var_not_occs)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    65
done
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    66
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    67
declare MGUnifier_Var [intro!]
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    68
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    69
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    70
subsection{*Idempotence*}
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    71
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    72
lemma Idem_Nil [iff]: "Idem([])"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    73
by (simp add: Idem_def)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    74
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    75
lemma Idem_iff: "Idem(s) = (sdom(s) Int srange(s) = {})"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    76
by (simp add: Idem_def subst_eq_iff invariance dom_range_disjoint)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    77
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    78
lemma Var_Idem [intro!]: "~ (Var(v) <: t) ==> Idem([(v,t)])"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    79
by (simp add: vars_iff_occseq Idem_iff srange_iff empty_iff_all_not)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    80
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    81
lemma Unifier_Idem_subst: 
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    82
  "[| Idem(r); Unifier s (t<|r) (u<|r) |]  
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    83
   ==> Unifier (r <> s) (t <| r) (u <| r)"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    84
by (simp add: Idem_def Unifier_def comp_subst_subst)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    85
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    86
lemma Idem_comp:
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    87
     "[| Idem(r);  Unifier s (t <| r) (u <| r);  
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    88
         !!q. Unifier q (t <| r) (u <| r) ==> s <> q =$= q  
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    89
      |] ==> Idem(r <> s)"
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    90
apply (frule Unifier_Idem_subst, blast) 
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    91
apply (force simp add: Idem_def subst_eq_iff)
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    92
done
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    93
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    94
968
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
    95
end