Unification/unification.ml
author Christian Urban <urbanc@in.tum.de>
Mon, 24 Sep 2018 12:18:57 +0100
changeset 556 38985a02db84
parent 107 5c816239deaa
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
107
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
(** 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
  * the Nominal Unification algorithm by Urban, Pitts & Gabbay 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
  * June, 2003
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
*)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
open List;;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
exception Fail;;                               (* exception for unification failure *) 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
(* terms *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
type term = 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
    Unit                                       (* units *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
  | Atm   of string                            (* atoms *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
  | Susp  of (string * string) list * string   (* suspensions *)          
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  | Fun   of string * term                     (* function symbols *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
  | Abst  of string * term                     (* abstracted terms *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  | Pair  of term * term;;                     (* pairs *)  
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
(* swapping operation on atoms *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
let swap (a,b) c =                             
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  if a=c then b else if b=c then a else c;;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
let swaps pi c = fold_right swap pi c;;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
(* permutation on terms *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
let rec perm pi t =       
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
  match t with	
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
      Unit              -> Unit
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
    | Atm(a)            -> Atm(swaps pi a)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
    | Susp(pi',x)       -> Susp(pi@pi',x)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
    | Fun(name,t')      -> Fun(name, perm pi t') 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
    | Abst(a,t')        -> Abst(swaps pi a,perm pi t')
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
    | Pair(t1,t2)       -> Pair(perm pi t1,perm pi t2);;	
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
(* substitution operation 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
 * - implements the simple operation of "hole filling" or "context substitution"
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
 *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
let rec subst t sigma =     
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  match t with 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
      Unit           -> Unit
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
    | Atm(a)         -> Atm(a)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
    | Susp(pi,y)     -> (try (perm pi (assoc y sigma)) with Not_found -> Susp(pi,y))
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
    | Fun(name,t')   -> Fun(name,subst t' sigma)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
    | Abst(a,t')     -> Abst(a,subst t' sigma)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
    | Pair(t1,t2)    -> Pair(subst t1 sigma,subst t2 sigma);;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
	
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
(* substitution composition *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
let rec subst_compose sigma = 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
  match sigma with
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
      [] -> []
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
    | h::tail -> h::(map (fun (v,t) -> (v,subst t [h])) (subst_compose tail));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
(* occurs check *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
let rec occurs x t =
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  match t with 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
      Unit                   -> false
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
    | Atm(a)                 -> false
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
    | Susp(pi,y)             -> if x=y then true else false
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
    | Fun(_,t') | Abst(_,t') -> occurs x t' 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
    | Pair(t1,t2)            -> (occurs x t1) || (occurs x t2);;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
(* deletes duplicates from a list 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
 *  - used for calculating disagreement sets
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
 *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
let rec delete_dups l =             
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
  match l with                               
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
      []   -> []
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
    | h::t -> let t' = delete_dups t in if mem h t' then t' else (h::t');;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
(* disagreement set 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
 * - takes two permutation (lists of pairs of atoms) as arguments
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
 *) 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
let rec ds pi pi' =    
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  let (l1,l2) = split (pi@pi') 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  in filter (fun a -> (swaps pi a)!=(swaps pi' a)) (delete_dups (l1@l2))
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
(* eliminates a solved equation *) 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
let eliminate (v,t) (eprobs,fprobs) =  
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  if occurs v t
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
  then raise Fail
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
  else (map (fun (t1,t2) -> (subst t1 [(v,t)],subst t2 [(v,t)])) eprobs,
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
        map (fun (a,t')  -> (a,subst t' [(v,t)])) fprobs);;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
(***************)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
(* unification *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
(***************)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
(* checks and solves all freshness problems *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
let rec check fprobs =                        
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  match fprobs with
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
      [] -> []
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
    | (a,Unit)::tail        -> check tail
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
    | (a,Atm(b))::tail      -> if a=b then raise Fail else check tail 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
    | (a,Susp(pi,x))::tail  -> (swaps (rev pi) a,x)::(check tail)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
    | (a,Fun(_,t))::tail    -> check ((a,t)::tail)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
    | (a,Abst(b,t))::tail   -> if a=b then (check tail) else (check ((a,t)::tail))                  
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
    | (a,Pair(t1,t2))::tail -> check ((a,t1)::(a,t2)::tail);;  
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
(* solves all equational problems *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
let rec solve eprobs fprobs = solve_aux eprobs fprobs [] 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
and solve_aux eprobs fprobs sigma =
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  match eprobs with 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
      [] -> (subst_compose sigma, delete_dups (check fprobs))
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
    | (Unit,Unit)::tail -> solve_aux tail fprobs sigma
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
    | (Atm(a),Atm(b))::tail -> if a=b then (solve_aux tail fprobs sigma) else raise Fail
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
    | (Susp(pi,x),Susp(pi',x'))::tail when x=x' ->                     
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
        let new_fps = map (fun a -> (a,Susp([],x))) (ds pi pi') 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
	in solve_aux tail (new_fps @ fprobs) sigma 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
    | (Susp(pi,x),t)::tail | (t,Susp(pi,x))::tail ->
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
	let new_sigma = (x,perm (rev pi) t) in
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
	let (new_eprobs,new_fprobs) = eliminate new_sigma (tail,fprobs) 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
	in solve_aux new_eprobs new_fprobs (new_sigma::sigma)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
    | (Fun(n1,t1),Fun(n2,t2))::tail -> 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
	if  n1 = n2 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
	then solve_aux ((t1,t2)::tail) fprobs sigma
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
	else raise Fail
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
    | (Abst(a1,t1),Abst(a2,t2))::tail ->
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
	if a1 = a2 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
	then solve_aux ((t1,t2)::tail) fprobs sigma
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
	else solve_aux ((t1,perm [(a1,a2)] t2)::tail) ((a1,t2)::fprobs) sigma
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
    | (Pair(t1,t2),Pair(s1,s2))::tail ->
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
	solve_aux ((t1,s1)::(t2,s2)::tail) fprobs sigma
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
    | _ -> raise Fail;;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
   
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
(************)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
(* Examples *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
(************)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
(* a few variables*)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
let x = Susp([],"X")
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
and y = Susp([],"Y")
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
and z = Susp([],"Z");;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
(* lam a.(X a) =? lam b.(c b)     --> [X:=c] *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
let t1 = Abst("a",Pair(x,Atm("a")));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
let t2 = Abst("b",Pair(Atm("c"),Atm("b")));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
solve [(t1,t2)] [];; 
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
(* lam a.(X a) =? lam b.(a b)     --> fails      *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
let t1 = Abst("a",Pair(x,Atm("a")));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
let t2 = Abst("b",Pair(Atm("a"),Atm("b")));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
solve [(t1,t2)] [];;    
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
(* lam a.(X a) =? lam b.(X b)     --> a#X, b#X   *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
let t1 = Abst("a",Pair(x,Atm("a")));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
let t2 = Abst("b",Pair(x,Atm("b")));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
solve [(t1,t2)] [];;    
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
(* lam a.(X a) =? lam b.(Y b)     --> [X:=(a b)oY]  a#Y *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
(*                                --> [Y:=(b a)oX]  b#X *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
let t1 = Abst("a",Pair(x,Atm("a")));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
let t2 = Abst("b",Pair(y,Atm("b")));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
solve [(t1,t2)] [];;   
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
solve [(t2,t1)] [];;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
(* quiz-questions from the paper *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
let m1 = Susp([],"M1")
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
and m2 = Susp([],"M2")
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
and m3 = Susp([],"M3")
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
and m4 = Susp([],"M4")
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
and m5 = Susp([],"M5")
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
and m6 = Susp([],"M6")
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
and m7 = Susp([],"M7");;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
(* 1 --> fail *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
let t1 = Abst("a",Abst("b",Pair(m1,Atm("b"))));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
let t2 = Abst("b",Abst("a",Pair(Atm("a"),m1)));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
solve [(t1,t2)] [];;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
(* 2 --> [M2:=b ,M3:=a] *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
let t1 = Abst("a",Abst("b",Pair(m2,Atm("b"))));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
let t2 = Abst("b",Abst("a",Pair(Atm("a"),m3)));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
solve [(t1,t2)] [];;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
(* 3 --> [M4:=(a b)o M5] *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
let t1 = Abst("a",Abst("b",Pair(Atm("b"),m4)));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
let t2 = Abst("b",Abst("a",Pair(Atm("a"),m5)));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
solve [(t1,t2)] [];;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
(* 4 --> [M6:=(b a)oM7] b#M7 *)
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
let t1 = Abst("a",Abst("b",Pair(Atm("b"),m6)));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
let t2 = Abst("a",Abst("a",Pair(Atm("a"),m7)));;
5c816239deaa added Unification subdirectory
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
solve [(t1,t2)] [];;