X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=ocaml%2Fnum.ml;h=5f97abbca4f7217912637aa1954577ba9e0f6503;hb=0a53fcf64c6f9475b7e7de590304d71133095bc7;hp=85a2bfa7583c6aaa82d70719ca5880da38207a32;hpb=eb8bb784b35d303a1c239f30008cba79f658f4b3;p=fireball-separation.git diff --git a/ocaml/num.ml b/ocaml/num.ml index 85a2bfa..5f97abb 100644 --- a/ocaml/num.ml +++ b/ocaml/num.ml @@ -2,6 +2,9 @@ open Util open Util.Vars open Pure +(* debug options *) +let debug_display_arities = false;; + (************ Syntax ************************************) (* Normal forms*) @@ -116,15 +119,15 @@ let rec string_of_term l = | `I _ as t -> "(" ^ string_of_term_no_pars_app l (t :> nf) ^ ")" | `Lam _ as t -> "(" ^ string_of_term_no_pars_lam l t ^ ")" | `Match(t,(v,ar),bs_lift,bs,args) -> - "[match("^print_name l v ^ ":" ^ string_of_int ar^") " ^ string_of_term_no_pars l (t :> nf) ^ - " with " ^ String.concat " | " (List.map (fun (n,t) -> string_of_int n ^ " => " ^ string_of_term l (lift bs_lift t)) !bs) ^ "] " ^ - String.concat " " (List.map (string_of_term l) args) ^ ")" - and string_of_term_no_pars_app l = function - | `I((n,ar), args) -> print_name l n ^ ":" ^ string_of_int ar ^ " " ^ String.concat " " (List.map (string_of_term_w_pars l) (Listx.to_list args)) + "["^ string_of_var v ^ (if debug_display_arities then ":"^ string_of_int ar else "") ^",match " ^ string_of_term_no_pars l (t :> nf) ^ + " with " ^ String.concat " | " (List.map (fun (n,t) -> string_of_int n ^ " => " ^ string_of_term l (lift bs_lift (t :> nf))) !bs) ^ "] " ^ + String.concat " " (List.map (string_of_term l) (args :> nf list)) ^ ")" + and string_of_term_no_pars_app l = function + | `I((n,ar), args) -> print_name l n ^ (if debug_display_arities then ":" ^ string_of_int ar else "") ^ " " ^ String.concat " " (List.map (string_of_term_w_pars l) (Listx.to_list args :> nf list)) | #nf as t -> string_of_term_w_pars l t and string_of_term_no_pars_lam l = function | `Lam(_,t) -> let name = string_of_var (List.length l) in - "λ" ^ name ^ ". " ^ (string_of_term_no_pars_lam (name::l) t) + "λ" ^ name ^ ". " ^ (string_of_term_no_pars_lam (name::l) t) | _ as t -> string_of_term_no_pars l t and string_of_term_no_pars l : nf -> string = function | `Lam _ as t -> string_of_term_no_pars_lam l t @@ -158,12 +161,12 @@ let cast_to_i_num_var = prerr_endline (print (t :> nf)); assert false (* algorithm failed *) -let set_arity arity = function +let rec set_arity arity = function | `Var(n,_) -> `Var(n,arity) -| `Lam(false, `N _) -| `Lam(false, `Lam _) as t -> t -| `Lam(false, `Match(t,(n,_),bs_lift,bs,args)) -> `Lam(false, `Match(t,(n,arity),bs_lift,bs,args)) -| _ -> assert false +| `N _ as t -> t +| `Lam(false, t) -> `Lam(false, set_arity arity t) +| `Match(t,(n,_),bs_lift,bs,args) -> `Match(t,(n,arity),bs_lift,bs,args) +| `I _ | `Lam _ -> assert false let minus1 n = if n = min_int then n else n - 1;; @@ -198,9 +201,10 @@ and mk_match t (n,ar) bs_lift bs args = | `I _ | `Var _ | `Match _ -> `Match(t,(n,ar),bs_lift,bs,args) and subst truelam delift_by_one what (with_what : nf) (where : nf) = - let aux_propagate_arity ar = function - | `Lam(false,`Match(`I(v,args),(x,_),liftno,bs,args')) when not delift_by_one -> - `Lam(false,`Match(`I(v,args),(x,ar),liftno,bs,args')) + let rec aux_propagate_arity ar = function + | `Lam(false, t) when not delift_by_one -> `Lam(false, aux_propagate_arity ar t) + | `Match(`I(v,args),(x,_),liftno,bs,args') when not delift_by_one -> + `Match(`I(v,args),(x,ar),liftno,bs,args') | `Var(i,oldar) -> `Var(i, if truelam then (assert (oldar = min_int); ar) else oldar) | _ as t -> t in let rec aux_i_num_var l =