]> matita.cs.unibo.it Git - fireball-separation.git/blobdiff - ocaml/lambda4.ml
still stepping on negative variables
[fireball-separation.git] / ocaml / lambda4.ml
index f71f36005f220d09bdea65baf15aed2f181181bd..c627151eeb5e7f98764b8d98c6ef3e9a852427af 100644 (file)
@@ -448,10 +448,11 @@ List.iter (fun l -> prerr_endline (String.concat " " (List.map string_of_var l))
 let instantiate p x n =
  (if hd_of_i_var (cast_to_i_var !bomb) = x
    then failwithProblem p ("BOMB (" ^ string_of_nf !bomb ^ ") cannot be instantiated!"));
- (* ACL FIXME compute arity of x correctly below! *)
- let arity_of_x = -666 in
+ let arity_of_x = max_arity_tms x (all_terms p) in
+ (if arity_of_x < 0 then failwithProblem p "step on a var of negative arity");
  (* AC: FIXME compute arities correctly below! *)
- let arities = Array.to_list (Array.make (n+1) 0) in
+ let arities = Num.compute_arities x (n+1) (all_terms p :> nf list) in
+ (* let arities = Array.to_list (Array.make (n+1) 0) in *)
  let p,vars = make_fresh_vars p arities in
  (* let p,zero = make_fresh_var p in *)
  (* let zero = Listx.Nil zero in *)
@@ -481,7 +482,10 @@ let auto_instantiate (n,p) =
     | [], y::_ ->
       prerr_endline ("INSTANTIATING CRITICAL TO EAT " ^ string_of_var y); y
     | [], [] ->
-     let heads = List.sort compare (filter_map (fun t -> match t with `Var _ -> None | x -> hd_of x) ((match p.div with Some t -> [(t :> i_n_var)] | _ -> []) @ p.ps)) in
+     let heads =
+      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
          [] -> assert false
        | x::_ ->
@@ -494,7 +498,9 @@ let auto_instantiate (n,p) =
 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) (all_terms p)) with
+  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);
@@ -730,7 +736,7 @@ in
 
 (********************** problems *******************)
 
-let zero = `Var(0,-1);;
+let zero = `Var(0,0);;
 
 let append_zero =
  function
@@ -757,7 +763,7 @@ let magic_conv ~div ~conv ~nums cmds =
   let special_k = compute_special_k (Listx.from_list all_tms) in (* compute initial special K *)
   (* casts *)
   let div = option_map cast_to_i_var div in
-  let conv = List.map cast_to_i_n_var conv in
+  let conv = Util.filter_map (function #i_n_var as t -> Some (cast_to_i_n_var t) | _ -> None) conv in
   let tms = List.map cast_to_i_n_var tms in
 
   let ps = List.map append_zero tms in (* crea lista applicando zeri o dummies *)