src/HOL/Subst/Unifier.thy
author wenzelm
Mon, 16 Mar 2009 18:24:30 +0100
changeset 30549 d2d7874648bd
parent 24823 bfb619994060
child 38140 05691ad74079
permissions -rw-r--r--
simplified method setup;
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
begin
968
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
    12
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    13
definition
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    14
  Unifier   :: "[('a * 'a uterm)list, 'a uterm, 'a uterm] => bool" where
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    15
  "Unifier s t u \<longleftrightarrow> t <| s = u <| s"
968
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
    16
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    17
definition
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    18
  MoreGeneral :: "[('a * 'a uterm)list, ('a * 'a uterm)list] => bool" (infixr ">>" 52) where
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    19
  "r >> s \<longleftrightarrow> (\<exists>q. s =$= r <> q)"
968
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
    20
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    21
definition
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    22
  MGUnifier :: "[('a * 'a uterm)list, 'a uterm, 'a uterm] => bool" where
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    23
  "MGUnifier s t u \<longleftrightarrow> Unifier s t u & (\<forall>r. Unifier r t u --> s >> r)"
968
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
    24
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    25
definition
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    26
  Idem :: "('a * 'a uterm)list => bool" where
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    27
  "Idem s \<longleftrightarrow> (s <> s) =$= s"
15635
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
lemmas unify_defs = Unifier_def MoreGeneral_def MGUnifier_def
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    31
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
subsection{*Unifiers*}
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    34
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    35
lemma Unifier_Comb [iff]: "Unifier s (Comb t u) (Comb v w) = (Unifier s t v & Unifier s u w)"
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    36
  by (simp add: Unifier_def)
15635
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    37
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
lemma Cons_Unifier: "[| v ~: vars_of t; v ~: vars_of u; Unifier s t u |] ==> Unifier ((v,r)#s) t u"
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    40
  by (simp add: Unifier_def repl_invariance)
15635
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    41
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
subsection{* Most General Unifiers*}
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    44
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    45
lemma mgu_sym: "MGUnifier s t u = MGUnifier s u t"
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    46
  by (simp add: unify_defs eq_commute)
15635
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    47
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
lemma MoreGen_Nil [iff]: "[] >> s"
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    50
  by (auto simp add: MoreGeneral_def)
15635
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    51
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    52
lemma MGU_iff: "MGUnifier s t u = (ALL r. Unifier r t u = s >> r)"
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    53
  apply (unfold unify_defs)
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    54
  apply (auto intro: ssubst_subst2 subst_comp_Nil)
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    55
  done
15635
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    56
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    57
lemma MGUnifier_Var [intro!]: "~ Var v <: t ==> MGUnifier [(v,t)] (Var v) t"
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    58
  apply (simp (no_asm) add: MGU_iff Unifier_def MoreGeneral_def del: subst_Var)
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    59
  apply safe
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    60
   apply (rule exI)
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    61
   apply (erule subst, rule Cons_trivial [THEN subst_sym])
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    62
  apply (erule ssubst_subst2)
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    63
  apply (simp (no_asm_simp) add: Var_not_occs)
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    64
  done
15635
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    65
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
subsection{*Idempotence*}
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
lemma Idem_Nil [iff]: "Idem([])"
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    70
  by (simp add: Idem_def)
15635
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_iff: "Idem(s) = (sdom(s) Int srange(s) = {})"
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    73
  by (simp add: Idem_def subst_eq_iff invariance dom_range_disjoint)
15635
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 Var_Idem [intro!]: "~ (Var(v) <: t) ==> Idem([(v,t)])"
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    76
  by (simp add: vars_iff_occseq Idem_iff srange_iff empty_iff_all_not)
15635
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 Unifier_Idem_subst: 
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    79
  "[| Idem(r); Unifier s (t<|r) (u<|r) |]  
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    80
    ==> Unifier (r <> s) (t <| r) (u <| r)"
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    81
  by (simp add: Idem_def Unifier_def comp_subst_subst)
15635
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    82
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    83
lemma Idem_comp:
24823
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    84
  "[| Idem(r);  Unifier s (t <| r) (u <| r);  
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    85
      !!q. Unifier q (t <| r) (u <| r) ==> s <> q =$= q  
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    86
    |] ==> Idem(r <> s)"
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    87
  apply (frule Unifier_Idem_subst, blast) 
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    88
  apply (force simp add: Idem_def subst_eq_iff)
bfb619994060 modernized specifications;
wenzelm
parents: 15635
diff changeset
    89
  done
15635
8408a06590a6 converted HOL-Subst to tactic scripts
paulson
parents: 3268
diff changeset
    90
968
3cdaa8724175 converted Subst with curried function application
clasohm
parents:
diff changeset
    91
end