| V of var\r
| A of t * t\r
| L of t\r
- | B (* bottom *)\r
- | C of int\r
;;\r
\r
let delta = L(A(V 0, V 0));;\r
| L t1, t2 -> aux l1 (l2+1) t1 t2\r
| t1, L t2 -> aux (l1+1) l2 t1 t2\r
| V a, V b -> a + l1 = b + l2\r
- | C a, C b -> a = b\r
| A(t1,t2), A(u1,u2) -> aux l1 l2 t1 u1 && aux l1 l2 t2 u2\r
| _, _ -> false\r
in aux ;;\r
let rec string_of_term_w_pars level = function\r
| V v -> if v >= level then "`" ^ string_of_int (v-level) else\r
string_of_bvar (level - v-1)\r
- | C n -> "c" ^ string_of_int n\r
| A _\r
| L _ as t -> "(" ^ string_of_term_no_pars level t ^ ")"\r
- | B -> "BOT"\r
and string_of_term_no_pars_app level = function\r
| A(t1,t2) -> string_of_term_no_pars_app level t1 ^ " " ^ string_of_term_w_pars level t2\r
| _ as t -> string_of_term_w_pars level t\r
; div : t\r
; conv : t\r
; sigma : (var * t) list (* substitutions *)\r
- ; stepped : var list\r
; phase : [`One | `Two] (* :'( *)\r
}\r
\r
let string_of_problem p =\r
let lines = [\r
- "[stepped] " ^ String.concat " " (List.map string_of_int p.stepped);\r
"[DV] " ^ string_of_t p.div;\r
"[CV] " ^ string_of_t p.conv;\r
] in\r
String.concat "\n" lines\r
;;\r
\r
+exception B;;\r
exception Done of (var * t) list (* substitution *);;\r
exception Fail of int * string;;\r
\r
function\r
| A(t,_) -> is_inert t\r
| V _ -> true\r
- | C _\r
- | L _ | B -> false\r
+ | L _ -> false\r
;;\r
\r
let is_var = function V _ -> true | _ -> false;;\r
| L t -> 1 + no_leading_lambdas (v+1) n t\r
| A _ as t -> let v', m = get_inert t in if v = v' then max 0 (n - m) else 0\r
| V v' -> if v = v' then n else 0\r
- | B | C _ -> 0\r
;;\r
\r
let rec subst level delift sub =\r
let t1 = subst level delift sub t1 in\r
let t2 = subst level delift sub t2 in\r
mk_app t1 t2\r
- | C _ as t -> t\r
- | B -> B\r
-and mk_app t1 t2 = if t2 = B || (t1 = delta && t2 = delta) then B\r
+and mk_app t1 t2 = if t1 = delta && t2 = delta then raise B\r
else match t1 with\r
- | B -> B\r
| L t1 -> subst 0 true (0, t2) t1\r
| _ -> A (t1, t2)\r
and lift n =\r
| V m -> V (if m >= lev then m + n else m)\r
| L t -> L (aux (lev+1) t)\r
| A (t1, t2) -> A (aux lev t1, aux lev t2)\r
- | C _ as t -> t\r
- | B -> B\r
in aux 0\r
;;\r
let subst = subst 0 false;;\r
\r
let subst_in_problem ((v, t) as sub) p =\r
print_endline ("-- SUBST " ^ string_of_t (V v) ^ " |-> " ^ string_of_t t);\r
- {p with\r
- div=subst sub p.div;\r
- conv=subst sub p.conv;\r
- stepped=v::p.stepped;\r
- sigma=sub::p.sigma}\r
+ let sigma = sub::p.sigma in\r
+ let div = try subst sub p.div with B -> raise (Done sigma) in\r
+ let conv = try subst sub p.conv with B -> raise (Fail(-1,"p.conv diverged")) in\r
+ {p with div; conv; sigma}\r
;;\r
\r
let get_subterm_with_head_and_args hd_var n_args =\r
let rec aux lev = function\r
- | C _\r
- | V _ | B -> None\r
+ | V _ -> None\r
| L t -> aux (lev+1) t\r
| A(t1,t2) as t ->\r
let hd_var', n_args' = get_inert t1 in\r
| L t -> Pure.L (purify t)\r
| A (t1,t2) -> Pure.A (purify t1, purify t2)\r
| V n -> Pure.V n\r
- | C _ -> Pure.V max_int (* FIXME *)\r
- | B -> Pure.B\r
;;\r
\r
let check p sigma =\r
\r
let sanity p =\r
print_endline (string_of_problem p); (* non cancellare *)\r
- if p.conv = B then problem_fail p "p.conv diverged";\r
- if p.div = B then raise (Done p.sigma);\r
if p.phase = `Two && p.div = delta then raise (Done p.sigma);\r
if not (is_inert p.div) then problem_fail p "p.div converged";\r
p\r
else id) (max (aux hd t1) (aux hd t2))\r
| L t -> aux (hd+1) t\r
| V _ -> 0\r
- | _ -> assert false\r
in aux hd_var\r
;;\r
\r
| Some div -> aux (div :> Num.nf)\r
| None -> assert false in\r
let varno = List.length var_names in\r
- let p = {orig_freshno=varno; freshno=1+varno; div; conv; sigma=[]; stepped=[]; phase=`One} in\r
+ let p = {orig_freshno=varno; freshno=1+varno; div; conv; sigma=[]; phase=`One} in\r
(* initial sanity check *)\r
sanity p\r
;;\r