From 69f6ab5b05bcbeb0ced857415c7c48460ae0bdcb Mon Sep 17 00:00:00 2001 From: acondolu Date: Fri, 1 Jun 2018 16:17:19 +0200 Subject: [PATCH] Removed parameter from C --- ocaml/simple.ml | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/ocaml/simple.ml b/ocaml/simple.ml index e5e829a..a633149 100644 --- a/ocaml/simple.ml +++ b/ocaml/simple.ml @@ -12,7 +12,7 @@ type t = | A of t * t | L of t | B (* bottom *) - | C of int + | C (* constant *) ;; let delta = L(A(V 0, V 0));; @@ -23,7 +23,6 @@ let eta_eq' = | L t1, t2 -> aux l1 (l2+1) t1 t2 | t1, L t2 -> aux (l1+1) l2 t1 t2 | V a, V b -> a + l1 = b + l2 - | C a, C b -> a = b | A(t1,t2), A(u1,u2) -> aux l1 l2 t1 u1 && aux l1 l2 t2 u2 | _, _ -> false in aux ;; @@ -49,7 +48,7 @@ let string_of_t = let rec string_of_term_w_pars level = function | V v -> if v >= level then "`" ^ string_of_int (v-level) else string_of_bvar (level - v-1) - | C n -> "c" ^ string_of_int n + | C -> "C" | A _ | L _ as t -> "(" ^ string_of_term_no_pars level t ^ ")" | B -> "BOT" @@ -98,13 +97,10 @@ let rec is_inert = function | A(t,_) -> is_inert t | V _ -> true - | C _ + | C | L _ | B -> false ;; -let is_var = function V _ -> true | _ -> false;; -let is_lambda = function L _ -> true | _ -> false;; - let rec get_inert = function | V n -> (n,0) | A(t, _) -> let hd,args = get_inert t in hd,args+1 @@ -117,7 +113,7 @@ 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 + | B | C -> 0 ;; let rec subst level delift sub = @@ -128,8 +124,7 @@ let rec subst level delift sub = let t1 = subst level delift sub t1 in let t2 = subst level delift sub t2 in mk_app t1 t2 - | C _ as t -> t - | B -> B + | C | B as t -> t and mk_app t1 t2 = if t2 = B || (t1 = delta && t2 = delta) then B else match t1 with | B -> B @@ -141,8 +136,7 @@ and lift n = | V m -> V (if m >= lev then m + n else m) | L t -> L (aux (lev+1) t) | A (t1, t2) -> A (aux lev t1, aux lev t2) - | C _ as t -> t - | B -> B + | C | B as t -> t in aux 0 ;; let subst = subst 0 false;; @@ -158,8 +152,7 @@ print_endline ("-- SUBST " ^ string_of_t (V v) ^ " |-> " ^ string_of_t t); let get_subterm_with_head_and_args hd_var n_args = let rec aux lev = function - | C _ - | V _ | B -> None + | C | V _ | B -> None | L t -> aux (lev+1) t | A(t1,t2) as t -> let hd_var', n_args' = get_inert t1 in @@ -176,7 +169,7 @@ let rec purify = function | L t -> Pure.L (purify t) | A (t1,t2) -> Pure.A (purify t1, purify t2) | V n -> Pure.V n - | C _ -> Pure.V max_int (* FIXME *) + | C -> Pure.V (min_int/2) | B -> Pure.B ;; @@ -243,7 +236,7 @@ let compute_max_lambdas_at hd_var j = else no_leading_lambdas hd_var j t2) else id) (max (aux hd t1) (aux hd t2)) | L t -> aux (hd+1) t - | V _ -> 0 + | V _ | C -> 0 | _ -> assert false in aux hd_var ;; @@ -255,6 +248,9 @@ let print_cmd s1 s2 = print_endline (">> " ^ s1 ^ " " ^ s2);; let eat p = print_cmd "EAT" ""; let var, k = get_inert p.div in + match var with + | C | L _ | B | A _ -> assert false + | V var -> let phase = p.phase in let p = match phase with @@ -319,17 +315,17 @@ let rec auto p = let problem_of (label, div, convs, ps, var_names) = print_hline (); - let rec aux = function - | `Lam(_, t) -> L (aux t) - | `I ((v,_), args) -> Listx.fold_left (fun x y -> mk_app x (aux y)) (V v) args - | `Var(v,_) -> V v + let rec aux lev = function + | `Lam(_, t) -> L (aux (lev+1) t) + | `I (v, args) -> Listx.fold_left (fun x y -> mk_app x (aux lev y)) (aux lev (`Var v)) args + | `Var(v,_) -> if v >= lev && List.nth var_names (v-lev) = "C" then C else V v | `N _ | `Match _ -> assert false in assert (List.length ps = 0); let convs = List.rev convs in - let conv = List.fold_left (fun x y -> mk_app x (aux (y :> Num.nf))) (V (List.length var_names)) convs in + let conv = List.fold_left (fun x y -> mk_app x (aux 0 (y :> Num.nf))) (V (List.length var_names)) convs in let var_names = "@" :: var_names in let div = match div with - | Some div -> aux (div :> Num.nf) + | Some div -> aux 0 (div :> Num.nf) | None -> assert false in let varno = List.length var_names in let p = {orig_freshno=varno; freshno=1+varno; div; conv; sigma=[]; stepped=[]; phase=`One} in -- 2.39.2