| B (* bottom *)\r
;;\r
\r
+let delta = L(A(V 0, V 0));;\r
+\r
let eta_eq =\r
let rec aux l1 l2 t1 t2 = match t1, t2 with\r
| L t1, L t2 -> aux l1 l2 t1 t2\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 t2 = subst level delift sub t2 in\r
mk_app t1 t2\r
| B -> B\r
-and mk_app t1 t2 = match t1 with\r
+and mk_app t1 t2 = if t1 = delta && t2 = delta then B else match t1 with\r
| B | _ when t2 = B -> B\r
| L t1 -> subst 0 true (0, t2) t1\r
| t1 -> A (t1, t2)\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.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
;;\r
\r
+(* drops the arguments of t after the n-th *)\r
+let inert_cut_at n t =\r
+ let rec aux t =\r
+ match t with\r
+ | V _ as t -> 0, t\r
+ | A(t1,_) as t ->\r
+ let k', t' = aux t1 in\r
+ if k' = n then n, t'\r
+ else k'+1, t\r
+ | _ -> assert false\r
+ in snd (aux t)\r
+;;\r
+\r
+let find_eta_difference p t n_args =\r
+ let t = inert_cut_at n_args t in\r
+ let rec aux t u k = match t, u with\r
+ | V _, V _ -> assert false (* div subterm of conv *)\r
+ | A(t1,t2), A(u1,u2) ->\r
+ if not (eta_eq t2 u2) then (print_endline((string_of_t t2) ^ " <> " ^ (string_of_t u2)); k)\r
+ else aux t1 u1 (k-1)\r
+ | _, _ -> assert false\r
+ in aux p.div t n_args\r
+;;\r
+\r
+let compute_max_lambdas_at hd_var j =\r
+ let rec aux hd = function\r
+ | A(t1,t2) ->\r
+ (if get_inert t1 = (hd, j)\r
+ then max ( (*FIXME*)\r
+ if is_inert t2 && let hd', j' = get_inert t2 in hd' = hd\r
+ then let hd', j' = get_inert t2 in j - j'\r
+ else no_leading_lambdas t2)\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
let print_cmd s1 s2 = print_endline (">> " ^ s1 ^ " " ^ s2);;\r
\r
(* eat the arguments of the divergent and explode.\r
It does NOT perform any check, may fail if done unsafely *)\r
let eat p =\r
print_cmd "EAT" "";\r
- let var, n = get_inert p.div in\r
- let subst = var, mk_lams B n in\r
+ let var, k = get_inert p.div in\r
+ let phase = p.phase in\r
+ let p, t =\r
+ match phase with\r
+ | `One ->\r
+ let n = 1 + max\r
+ (compute_max_lambdas_at var k p.div)\r
+ (compute_max_lambdas_at var k p.conv) in\r
+ (* apply fresh vars *)\r
+ let p, t = fold_nat (fun (p, t) _ ->\r
+ let p, v = freshvar p in\r
+ p, A(t, V (v + k))\r
+ ) (p, V 0) n in\r
+ let p = {p with phase=`Two} in p, A(t, delta)\r
+ | `Two -> p, delta in\r
+ let subst = var, mk_lams t k in\r
let p = subst_in_problem subst p in\r
+ let p = if phase = `One then {p with div = (match p.div with A(t,_) -> t | _ -> assert false)} else p in\r
sanity p; p\r
;;\r
\r
print_hline ();\r
let [@warning "-8"] [div; conv], var_names = parse ([div; conv]) in\r
let varno = List.length var_names in\r
- let p = {orig_freshno=varno; freshno=1+varno; div; conv; sigma=[]; stepped=[]} in\r
+ let p = {orig_freshno=varno; freshno=1+varno; div; conv; sigma=[]; stepped=[]; phase=`One} in\r
(* initial sanity check *)\r
sanity p; p\r
;;\r
| Done _ -> ()\r
;;\r
\r
-(* drops the arguments of t after the n-th *)\r
-let inert_cut_at n t =\r
- let rec aux t =\r
- match t with\r
- | V _ as t -> 0, t\r
- | A(t1,_) as t ->\r
- let k', t' = aux t1 in\r
- if k' = n then n, t'\r
- else k'+1, t\r
- | _ -> assert false\r
- in snd (aux t)\r
-;;\r
-\r
-let find_eta_difference p t n_args =\r
- let t = inert_cut_at n_args t in\r
- let rec aux t u k = match t, u with\r
- | V _, V _ -> assert false (* div subterm of conv *)\r
- | A(t1,t2), A(u1,u2) ->\r
- if not (eta_eq t2 u2) then (print_endline((string_of_t t2) ^ " <> " ^ (string_of_t u2)); k)\r
- else aux t1 u1 (k-1)\r
- | _, _ -> assert false\r
- in aux p.div t n_args\r
-;;\r
-\r
-let compute_max_lambdas_at hd_var j =\r
- let rec aux hd = function\r
- | A(t1,t2) ->\r
- (if get_inert t1 = (hd, j)\r
- then max ( (*FIXME*)\r
- if is_inert t2 && let hd', j' = get_inert t2 in hd' = hd\r
- then let hd', j' = get_inert t2 in j - j'\r
- else no_leading_lambdas t2)\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
let rec auto p =\r
let hd_var, n_args = get_inert p.div in\r
match get_subterm_with_head_and_args hd_var n_args p.conv with\r
| None ->\r
- (try problem_fail (eat p) "Auto did not complete the problem" with Done sigma -> sigma)\r
+ (try\r
+ let phase = p.phase in\r
+ let p = eat p in\r
+ if phase = `Two\r
+ then problem_fail p "Auto.2 did not complete the problem"\r
+ else auto p\r
+ with Done sigma -> sigma)\r
| Some t ->\r
let j = find_eta_difference p t n_args - 1 in\r
let k = 1 + max\r