src/HOL/Subst/Unify.thy
author paulson
Wed, 21 May 1997 10:53:38 +0200
changeset 3267 7203f4dbc0c5
parent 3192 a75558a4ed37
child 3298 5f0ed3caa991
permissions -rw-r--r--
Removed rprod from the WF relation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     1
(*  Title:      Subst/Unify
3267
7203f4dbc0c5 Removed rprod from the WF relation
paulson
parents: 3192
diff changeset
     2
    ID:         $Id$
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     3
    Author:     Konrad Slind, Cambridge University Computer Laboratory
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     4
    Copyright   1997  University of Cambridge
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     5
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     6
Unification algorithm
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     7
*)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     8
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
     9
Unify = Unifier + WF_Rel + 
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    10
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    11
datatype 'a subst = Fail | Subst ('a list)
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    12
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    13
consts
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    14
3267
7203f4dbc0c5 Removed rprod from the WF relation
paulson
parents: 3192
diff changeset
    15
   unifyRel :: "(('a uterm * 'a uterm) * ('a uterm * 'a uterm)) set"
7203f4dbc0c5 Removed rprod from the WF relation
paulson
parents: 3192
diff changeset
    16
   unify    :: "'a uterm * 'a uterm => ('a * 'a uterm) subst"
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    17
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    18
defs
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    19
3267
7203f4dbc0c5 Removed rprod from the WF relation
paulson
parents: 3192
diff changeset
    20
  (*Termination relation for the Unify function:
7203f4dbc0c5 Removed rprod from the WF relation
paulson
parents: 3192
diff changeset
    21
    --either the set of variables decreases
7203f4dbc0c5 Removed rprod from the WF relation
paulson
parents: 3192
diff changeset
    22
    --or the first argument does (in fact, both do)
7203f4dbc0c5 Removed rprod from the WF relation
paulson
parents: 3192
diff changeset
    23
  *)
7203f4dbc0c5 Removed rprod from the WF relation
paulson
parents: 3192
diff changeset
    24
  unifyRel_def  "unifyRel == inv_image  (finite_psubset ** measure uterm_size)
7203f4dbc0c5 Removed rprod from the WF relation
paulson
parents: 3192
diff changeset
    25
                               (%(M,N). (vars_of M Un vars_of N, M))"
3192
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    26
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    27
recdef unify "unifyRel"
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    28
  "unify(Const m, Const n)  = (if (m=n) then Subst[] else Fail)"
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    29
  "unify(Const m, Comb M N) = Fail"
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    30
  "unify(Const m, Var v)    = Subst[(v,Const m)]"
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    31
  "unify(Var v, M)          = (if (Var v <: M) then Fail else Subst[(v,M)])"
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    32
  "unify(Comb M N, Const x) = Fail"
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    33
  "unify(Comb M N, Var v)   = (if (Var v <: Comb M N) then Fail   
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    34
                               else Subst[(v,Comb M N)])"
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    35
  "unify(Comb M1 N1, Comb M2 N2) =   
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    36
      (case unify(M1,M2)  
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    37
        of Fail => Fail  
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    38
         | Subst theta => (case unify(N1 <| theta, N2 <| theta)  
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    39
                            of Fail => Fail  
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    40
                             | Subst sigma => Subst (theta <> sigma)))"
a75558a4ed37 New version, modified by Konrad Slind and LCP for TFL
paulson
parents:
diff changeset
    41
end