]> matita.cs.unibo.it Git - fireball-separation.git/commitdiff
Fixed indentation and logging
authoracondolu <andrea.condoluci@unibo.it>
Tue, 11 Jul 2017 14:38:26 +0000 (16:38 +0200)
committeracondolu <andrea.condoluci@unibo.it>
Fri, 25 May 2018 08:07:23 +0000 (10:07 +0200)
(cherry picked from commit 4985769db038aa060b47ab40f673aaaacea54742)

ocaml/lambda4.ml

index 570691e1be16101622515e0d8c55a70bceda31bc..ee69a2143bd100f8c514e31e7a0137e11254f810 100644 (file)
@@ -476,55 +476,55 @@ let instantiate p x n =
 ;;
 
 let compute_special_k tms =
 let rec aux k (t: nf) = Pervasives.max k (match t with
   | `Lam(b,t) -> aux (k + if b then 1 else 0) t
   | `I(n, tms) -> Listx.max (Listx.map (aux 0) tms)
   | `Match(t, _, liftno, bs, args) ->
-        List.fold_left max 0 (List.map (aux 0) ((t :> nf)::args@List.map snd !bs))
-    | `N _ -> 0
   | `Var _ -> 0
 ) in Listx.max (Listx.map (aux 0) tms)
+ let rec aux k (t: nf) = Pervasives.max k (match t with
+ | `Lam(b,t) -> aux (k + if b then 1 else 0) t
+ | `I(n, tms) -> Listx.max (Listx.map (aux 0) tms)
+ | `Match(t, _, liftno, bs, args) ->
+     List.fold_left max 0 (List.map (aux 0) ((t :> nf)::args@List.map snd !bs))
+ | `N _
+ | `Var _ -> 0
+ ) in Listx.max (Listx.map (aux 0) tms)
 ;;
 
 let auto_instantiate (n,p) =
 let p, showstoppers_step, showstoppers_eat = critical_showstoppers p in
+ let p, showstoppers_step, showstoppers_eat = critical_showstoppers p in
  let x =
   match showstoppers_step, showstoppers_eat with
-    | [], y::_ ->
-      prerr_endline ("INSTANTIATING CRITICAL TO EAT " ^ string_of_var y); y
-    | [], [] ->
+  | [], y::_ ->
+     prerr_endline ("INSTANTIATING CRITICAL TO EAT " ^ string_of_var y); y
+  | [], [] ->
      let heads =
       (* Choose only variables still alive (with arity > 0) *)
       List.sort compare (filter_map (
        fun t -> match t with `Var _ -> None | x -> if arity_of_hd x <= 0 then None else hd_of x
       ) ((match p.div with Some t -> [(t :> i_n_var)] | _ -> []) @ p.ps)) in
      (match heads with
-         [] -> (
-          try
+      | [] ->
+         (try
            fst (List.find (((<) 0) ++ snd) (concat_map free_vars' (p.conv :> nf list)))
           with
-           Not_found -> assert false
-          )
-       | x::_ ->
-          prerr_endline ("INSTANTIATING TO EAT " ^ string_of_var x);
-          x)
+           Not_found -> assert false)
+      | x::_ ->
+         prerr_endline ("INSTANTIATING TO EAT " ^ string_of_var x);
+         x)
   | x::_, _ ->
       prerr_endline ("INSTANTIATING " ^ string_of_var x);
       x in
 (* Strategy that  decreases the special_k to 0 first (round robin)
 1:11m42 2:14m5 3:11m16s 4:14m46s 5:12m7s 6:6m31s *)
-let x =
- try
-  match hd_of (List.find (fun t ->
-   compute_special_k (Listx.Nil (t :> nf)) > 0 && arity_of_hd t > 0
-   ) (all_terms p)) with
-      None -> assert false
+ let x =
+  try
+   match
+    hd_of (List.find (fun t ->
+     compute_special_k (Listx.Nil (t :> nf)) > 0 && arity_of_hd t > 0
+     ) (all_terms p))
+   with
+    | None -> assert false
     | Some x ->
        prerr_endline ("INSTANTIATING AND HOPING " ^ string_of_var x);
        x
- with
-  Not_found -> x
-in
+  with
+   Not_found -> x in
 (* Instantiate in decreasing order of compute_special_k
 1:15m14s 2:13m14s 3:4m55s 4:4m43s 5:4m34s 6:6m28s 7:3m31s
 let x =
@@ -550,25 +550,23 @@ let rec auto_eat (n,p) =
  let m = problem_measure p in
  let (n,p') = auto_instantiate (n,p) in
  match eat p' with
  `Finished p -> p
| `Finished p -> p
  | `Continue p ->
      prerr_endline "{{{{{{{{ Computing measure inafter auto_instantiate }}}}}}";
-     let m' = problem_measure p in
-     let delta = compare m m' in
-     print_endline ("compare " ^ string_of_measure m' ^ " " ^ string_of_measure m ^ "= " ^ string_of_int delta);
+     let delta = problem_measure p - m in
      (* let delta = m - problem_measure p' in *)
-     if delta <= 0 then (
-      failwith
-      (* prerr_endline *)
-      ("Measure did not decrease (delta=" ^ string_of_int delta ^ ")"))
-     else prerr_endline ("$ Measure decreased by " ^ string_of_int delta);
+     if delta >= 0
+      then
+       (failwith
+       ("Measure did not decrease (+=" ^ string_of_int delta ^ ")"))
+      else prerr_endline ("$ Measure decreased of " ^ string_of_int delta);
      auto_eat (n,p)
 ;;
 
 let auto p n =
  prerr_endline ("@@@@ FIRST INSTANTIATE PHASE (" ^ string_of_int n ^ ") @@@@");
  match eat p with
  `Finished p -> p
| `Finished p -> p
  | `Continue p -> auto_eat (n,p)
 ;;