(* exceptions *)
exception Pacman
exception Bottom
+exception Lambda
exception Backtrack of string
(*
For Scott's encoding, two.
*)
let num_more_args = 2;;
+(* verbosity *)
let _very_verbose = false;;
+(** Display measure of every term when printing problem *)
+let _measure_of_terms = false;;
let verbose s =
if _very_verbose then prerr_endline s
let string_of_measure = string_of_int;;
let string_of_problem label ({freshno; div; conv; ps; deltas} as p) =
+ let aux_measure_terms t = if _measure_of_terms then "(" ^ string_of_int (measure_of_term t) ^ ") " else "" in
let deltas = String.concat ("\n# ") (List.map (fun r -> String.concat " <> " (List.map (fun (i,_) -> string_of_int i) !r)) deltas) in
let l = p.var_names in
String.concat "\n" ([
) else "# ";
"#";
"$" ^ p.label;
- (match div with None -> "# no D" | Some div -> "D ("^string_of_int (measure_of_term div)^")"^ print ~l (div :> nf));
+ (match div with None -> "# D" | Some div -> "D " ^ aux_measure_terms div ^ print ~l (div :> nf));
]
- @ List.map (fun t -> if t = convergent_dummy then "#C" else "C ("^string_of_int (measure_of_term t)^") " ^ print ~l (t :> nf)) conv
- @ List.mapi (fun i t -> string_of_int i ^ " ("^string_of_int (measure_of_term t)^") " ^ print ~l (t :> nf)) ps
+ @ List.map (fun t -> if t = convergent_dummy then "# C" else "C " ^ aux_measure_terms t ^ print ~l (t :> nf)) conv
+ @ List.mapi (fun i t -> string_of_int i ^ " " ^ aux_measure_terms t ^ print ~l (t :> nf)) ps
@ [""])
;;
let freshno,new_t,acc_new_ps =
try
expand_match (freshno,ps,acc_new_ps) t
- with Pacman -> freshno,convergent_dummy,acc_new_ps
+ with Pacman | Lambda -> freshno,convergent_dummy,acc_new_ps
| Bottom -> raise (Backtrack "Bottom in conv") in
aux_conv ps (freshno,acc_conv@[new_t],acc_new_ps) todo_conv
let t = mk_match (`N i) orig bs_lift bs (args :> nf list) in
(*prerr_endline ("NUOVO t:" ^ print (fst t :> nf) ^ " more_args=" ^ string_of_int (snd t));*)
expand_match (freshno,acc_ps,acc_new_ps) t
- | `Lam _ -> assert false (* algorithm invariant/loose typing *)
+ | `Lam _ -> raise Lambda (* assert false (* algorithm invariant/loose typing *) *)
| `Bottom -> raise Bottom
| `Pacman -> raise Pacman
| #i_n_var as x ->
aux showstoppers xs
with
Dangerous ->
- aux (sort_uniq (h::showstoppers)) ps in
-
- let showstoppers = sort_uniq (aux showstoppers ps) in
- let dangerous_conv =
- List.map (dangerous_conv p arities showstoppers) (conv :> nf_nob list) in
+ aux (sort_uniq (h::showstoppers)) ps
+ in
+ let showstoppers = sort_uniq (aux showstoppers ps) in
+ let dangerous_conv =
+ List.map (dangerous_conv p arities showstoppers) (conv :> nf_nob list) in
prerr_endline ("dangerous_conv lenght:" ^ string_of_int (List.length dangerous_conv));
List.iter (fun l -> prerr_endline (String.concat " " (List.map (string_of_var p.var_names) l))) dangerous_conv;
- let showstoppers' = showstoppers @ List.concat dangerous_conv in
- let showstoppers' = sort_uniq (match div with
- | None -> showstoppers'
- | Some div ->
- if List.exists ((=) (hd_of_i_var div)) showstoppers'
- then showstoppers' @ free_vars (div :> nf) else showstoppers') in
- if showstoppers <> showstoppers' then edible p arities showstoppers' else showstoppers', dangerous_conv
+ let showstoppers' = showstoppers @ List.concat dangerous_conv in
+ let showstoppers' = sort_uniq (match div with
+ | None -> showstoppers'
+ | Some div ->
+ if List.exists ((=) (hd_of_i_var div)) showstoppers'
+ then showstoppers' @ free_vars (div :> nf) else showstoppers') in
+ if showstoppers <> showstoppers' then edible p arities showstoppers' else showstoppers', dangerous_conv
;;
let precompute_edible_data {ps; div} xs =
let showstoppers_eat = List.filter
(fun x -> not (List.mem x showstoppers_step))
showstoppers_eat in
-List.iter (fun v -> prerr_endline ("DANGEROUS STEP: " ^ (string_of_var p.var_names) v)) showstoppers_step;
-List.iter (fun v -> prerr_endline ("DANGEROUS EAT: " ^ (string_of_var p.var_names) v)) showstoppers_eat;
+ List.iter (fun v -> prerr_endline ("DANGEROUS STEP: " ^ (string_of_var p.var_names) v)) showstoppers_step;
+ List.iter (fun v -> prerr_endline ("DANGEROUS EAT: " ^ (string_of_var p.var_names) v)) showstoppers_eat;
p, showstoppers_step, showstoppers_eat
;;
| `Bottom
| `Pacman
| `Var _ -> 0 in
- Listx.max (Listx.map (fun t -> max (aux 0 t) (aux' true t)) tms)
+ Listx.max (Listx.map (aux 0) tms) + Listx.max (Listx.map (aux' true) tms)
;;
let choose_step p =
| x::_ ->
prerr_endline ("INSTANTIATING TO EAT " ^ string_of_var p.var_names 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
- | Some x ->
- prerr_endline ("INSTANTIATING AND HOPING " ^ string_of_var p.var_names x);
- x
- with
- Not_found ->
- let arity_of_x = max_arity_tms x (all_terms p) in
- assert (Util.option_get arity_of_x > 0);
- 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 =
- try
- (match hd_of (snd (List.hd (List.sort (fun c1 c2 -> - compare (fst c1) (fst c2)) (filter_map (function `I _ as t -> Some (compute_special_k (Listx.Nil (t :> nf)),t) | _ -> None) (all_terms p))))) with
- None -> assert false
- | Some x ->
- prerr_endline ("INSTANTIATING AND HOPING " ^ string_of_var x);
- x)
- with
- Not_found -> x
-in*)
let arity_of_x = Util.option_get (max_arity_tms x (all_terms p)) in
let safe_arity_of_x = safe_arity_of_var p x in
x, min arity_of_x safe_arity_of_x