X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=ocaml%2Fsimple.ml;h=44b9aa2a871d74619fdcbe88599580ce4c7b2d70;hb=484254ec5f3e94aa86ffdc2bf7c07c46e42be8d7;hp=bac3ddf98a532784a587fa90cd9cbd67ca1f1e0a;hpb=2b941d27823cb7d06bbf83353c21779c866f3161;p=fireball-separation.git diff --git a/ocaml/simple.ml b/ocaml/simple.ml index bac3ddf..44b9aa2 100644 --- a/ocaml/simple.ml +++ b/ocaml/simple.ml @@ -100,6 +100,8 @@ let freshvar ({freshno} as p) = {p with freshno=freshno+1}, freshno+1 ;; +(* CSC: rename? is an applied C an inert? + is_inert and get_inert work inconsistently *) let rec is_inert = function | A(t,_) -> is_inert t @@ -108,12 +110,31 @@ let rec is_inert = | L _ | B -> false ;; +let rec is_constant = + function + C -> true + | V _ -> false + | B -> assert false + | A(t,_) + | L t -> is_constant t +;; + let rec get_inert = function | V _ | C as t -> (t,0) | A(t, _) -> let hd,args = get_inert t in hd,args+1 | _ -> assert false ;; +let args_of_inert = + let rec aux acc = + function + | V _ | C -> acc + | A(t, a) -> aux (a::acc) t + | _ -> assert false + in + aux [] +;; + (* precomputes the number of leading lambdas in a term, after replacing _v_ w/ a term starting with n lambdas *) let rec no_leading_lambdas v n = function @@ -201,8 +222,6 @@ let sanity p = ;; (* drops the arguments of t after the n-th *) -(* FIXME! E' usato in modo improprio contando sul fatto - errato che ritorna un inerte lungo esattamente n *) let inert_cut_at n t = let rec aux t = match t with @@ -216,19 +235,18 @@ let inert_cut_at n t = ;; (* return the index of the first argument with a difference - (the first argument is 0) - precondition: p.div and t have n+1 arguments - *) -let find_eta_difference p t argsno = - let t = inert_cut_at argsno t in - let rec aux t u k = match t, u with - | V _, V _ -> [] - | A(t1,t2), A(u1,u2) -> - print_endline (string_of_t t2 ^ " vs " ^ string_of_t u2); - if not (eta_eq t2 u2) then (k-1)::aux t1 u1 (k-1) - else aux t1 u1 (k-1) - | _, _ -> assert false - in aux p.div t argsno + (the first argument is 0) *) +let find_eta_difference p t = + let divargs = args_of_inert p.div in + let conargs = args_of_inert t in + let rec aux k divargs conargs = + match divargs,conargs with + [],_ -> [] + | _::_,[] -> [k] + | t1::divargs,t2::conargs -> + (if not (eta_eq t1 t2) then [k] else []) @ aux (k+1) divargs conargs + in + aux 0 divargs conargs ;; let compute_max_lambdas_at hd_var j = @@ -248,6 +266,18 @@ let compute_max_lambdas_at hd_var j = let print_cmd s1 s2 = print_endline (">> " ^ s1 ^ " " ^ s2);; +(* returns Some i if i is the smallest integer s.t. p holds for the i-th + element of the list in input *) +let smallest_such_that p = + let rec aux i = + function + [] -> None + | hd::_ when (print_endline (string_of_t hd) ; p hd) -> Some i + | _::tl -> aux (i+1) tl + in + aux 0 +;; + (* eat the arguments of the divergent and explode. It does NOT perform any check, may fail if done unsafely *) let eat p = @@ -260,17 +290,21 @@ print_cmd "EAT" ""; let p = match phase with | `One -> + let i = + match smallest_such_that (fun x -> not (is_constant x)) (args_of_inert p.div) with + Some i -> i + | None -> assert false (*CSC: backtrack? *) in let n = 1 + max - (compute_max_lambdas_at var (k-1) p.div) - (compute_max_lambdas_at var (k-1) p.conv) in + (compute_max_lambdas_at var (k-i-1) p.div) + (compute_max_lambdas_at var (k-i-1) p.conv) in (* apply fresh vars *) let p, t = fold_nat (fun (p, t) _ -> let p, v = freshvar p in p, A(t, V (v + k)) - ) (p, V 0) n in + ) (p, V (k-1-i)) n in let p = {p with phase=`Two} in let t = A(t, delta) in - let t = fold_nat (fun t m -> A(t, V (k-m))) t (k-1) in + let t = fold_nat (fun t m -> if k-m = i then t else A(t, V (k-m))) t k in let subst = var, mk_lams t k in let p = subst_in_problem subst p in let _, args = get_inert p.div in @@ -312,7 +346,7 @@ let auto p = then ( (* let tms = List.sort (fun t1 t2 -> - compare (snd (get_inert t1)) (snd (get_inert t2))) tms in *) List.iter (fun t -> try - let js = find_eta_difference p t n_args in + let js = find_eta_difference p t in (* print_endline (String.concat ", " (List.map string_of_int js)); *) if js = [] then problem_fail p "no eta difference found (div subterm of conv?)"; let js = List.rev js in