-prerr_endline "########## main ##########";;
-
-(* Commands:
- v ==> v := \a. a k1 .. kn \^m.0
- + ==> v := \^k. numero for every v such that ...
- * ==> tries v as long as possible and then +v as long as possible
-*)
-let main problems =
- let rec aux ({ps} as p) n l =
- if List.for_all (function `N _ -> true | _ -> false) ps && p.div = None then begin
- p
- end else
- let _ = prerr_endline (string_of_problem "main" p) in
- let x,l =
- match l with
- | cmd::l -> cmd,l
- | [] -> read_line (),[] in
- let cmd =
- if x = "+" then
- `DoneWith
- else if x = "*" then
- `Auto
- else
- `Step x in
- match cmd with
- | `DoneWith -> assert false (*aux (eat p) n l*) (* CSC: TODO *)
- | `Step x -> assert false
- (* let x = var_of_string x in
- aux (instantiate p x 1 n) n l *)
- | `Auto -> aux (auto p n) n l
- in
- List.iter
- (fun (p,n,cmds) ->
- Console.print_hline();
- bomb := `Var (-1,-666);
- let p_finale = aux p n cmds in
- let freshno,sigma = p_finale.freshno, p_finale.sigma in
- prerr_endline ("------- <DONE> ------\n ");
- (* prerr_endline (string_of_problem "Original problem" p); *)
- prerr_endline "---------------------";
- let l = Array.to_list (Array.init (freshno + 1) string_of_var) in
- prerr_endline (" BOMB == " ^ print ~l !bomb);
- prerr_endline "---------------------";
- List.iter (fun (x,inst) -> prerr_endline (string_of_var x ^ " := " ^ print ~l inst)) sigma;
-(*
- prerr_endline "----------------------";
- let ps =
- List.fold_left (fun ps (x,inst) ->
- (* CSC: XXXX Is the subst always sorted correctly? Otherwise, implement a recursive subst *)
- (* In this non-recursive version, the intermediate states may containt Matchs *)
- List.map (fun t -> let t = subst false x inst (t :> nf) in cast_to_i_num_var t) ps)
- (p.ps :> i_num_var list) sigma in
- prerr_endline (string_of_problem {p with ps= List.map (function t -> cast_to_i_n_var t) ps; freshno});
- List.iteri (fun i (n,more_args) -> assert (more_args = 0 && n = `N i)) ps ;
-*)
- prerr_endline "---------<OPT>----------";
- let sigma = optimize_numerals p_finale in (* optimize numerals *)
- let l = Array.to_list (Array.init (freshno + 1) string_of_var) in
- List.iter (fun (x,inst) -> prerr_endline (string_of_var x ^ " := " ^ print ~l inst)) sigma;
- prerr_endline "---------<PURE>---------";
- let div = option_map (fun div -> ToScott.scott_of_nf (div :> nf)) p.div in
- let conv = List.map (fun t -> ToScott.scott_of_nf (t :> nf)) p.conv in
- let ps = List.map (fun t -> ToScott.scott_of_nf (t :> nf)) p.ps in
- let sigma = List.map (fun (x,inst) -> x, ToScott.scott_of_nf inst) sigma in
- (*let ps_ok = List.fold_left (fun ps (x,inst) ->
- List.map (Pure.subst false x inst) ps) ps sigma in*)
- let e = env_of_sigma freshno sigma true in
- let e' = env_of_sigma freshno sigma false in
+let solve (p, todo) =
+ let completeness, to_run =
+ match todo with
+ | `CompleteUnseparable s -> `Complete, `False s
+ | `CompleteSeparable _ -> `Complete, `True
+ | `Uncomplete -> `Uncomplete, `True in
+ completeness, match to_run with
+ | `False s -> `Unseparable s
+ | `True ->
+ try
+ `Separable (run p)
+ with
+ Backtrack _ -> `Unseparable "backtrack"
+;;