From 7f2867ee172be351c32c9ff959be8c0079d0f0dc Mon Sep 17 00:00:00 2001 From: acondolu Date: Fri, 1 Jun 2018 10:18:20 +0200 Subject: [PATCH] More comments and better variable names --- ocaml/simple.ml | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ocaml/simple.ml b/ocaml/simple.ml index 8e4f619..35874b6 100644 --- a/ocaml/simple.ml +++ b/ocaml/simple.ml @@ -111,10 +111,12 @@ let rec get_inert = function | _ -> assert false ;; -let rec no_leading_lambdas hd_var j = function - | L t -> 1 + no_leading_lambdas (hd_var+1) j t - | A _ as t -> let hd_var', n = get_inert t in if hd_var = hd_var' then max 0 (j - n) else 0 - | V n -> if n = hd_var then j else 0 +(* 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 + | L t -> 1 + no_leading_lambdas (v+1) n t + | A _ as t -> let v', m = get_inert t in if v = v' then max 0 (n - m) else 0 + | V v' -> if v = v' then n else 0 | B | C _ -> 0 ;; @@ -145,12 +147,12 @@ and lift n = ;; let subst = subst 0 false;; -let subst_in_problem sub p = -print_endline ("-- SUBST " ^ string_of_t (V (fst sub)) ^ " |-> " ^ string_of_t (snd sub)); +let subst_in_problem ((v, t) as sub) p = +print_endline ("-- SUBST " ^ string_of_t (V v) ^ " |-> " ^ string_of_t t); {p with div=subst sub p.div; conv=subst sub p.conv; - stepped=(fst sub)::p.stepped; + stepped=v::p.stepped; sigma=sub::p.sigma} ;; @@ -162,6 +164,7 @@ let get_subterm_with_head_and_args hd_var n_args = | A(t1,t2) as t -> let hd_var', n_args' = get_inert t1 in if hd_var' = hd_var + lev && n_args <= 1 + n_args' + (* the `+1` above is because of t2 *) then Some (lift ~-lev t) else match aux lev t2 with | None -> aux lev t1 @@ -182,7 +185,7 @@ let check p sigma = let div = purify p.div in let conv = purify p.conv in let sigma = List.map (fun (v,t) -> v, purify t) sigma in - let freshno = List.fold_right (fun (x,_) -> max x) sigma 0 in + let freshno = List.fold_right (max ++ fst) sigma 0 in let env = Pure.env_of_sigma freshno sigma in assert (Pure.diverged (Pure.mwhd (env,div,[]))); print_endline " D diverged."; @@ -201,6 +204,8 @@ 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 @@ -213,6 +218,7 @@ let inert_cut_at n t = in snd (aux t) ;; +(* FIXME! eta_difference dovrebbe restituire un int partendo da 0 *) let find_eta_difference p t n_args = let t = inert_cut_at n_args t in let rec aux t u k = match t, u with -- 2.39.2