-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 (print_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 ->
- let x = var_of_string x in
- aux (instantiate p x 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 (print_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 (print_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.t_of_nf (div :> nf)) p.div in
- let conv = List.map (fun t -> ToScott.t_of_nf (t :> nf)) p.conv in
- let ps = List.map (fun t -> ToScott.t_of_nf (t :> nf)) p.ps in
- let sigma = List.map (fun (x,inst) -> x, ToScott.t_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
-
-(*
- prerr_endline "---------<PPP>---------";
-let rec print_e e =
- "[" ^ String.concat ";" (List.map (fun (e,t,[]) -> print_e e ^ ":" ^ Pure.print t) e) ^ "]"
-in
- prerr_endline (print_e e);
- List.iter (fun (t,t_ok) ->
- prerr_endline ("T0= " ^ Pure.print t ^ "\nTM= " ^ Pure.print (Pure.unwind (e,t,[])) ^ "\nOM= " ^ Pure.print t_ok);
- (*assert (Pure.unwind (e,t,[]) = t_ok)*)
- ) (List.combine ps ps_ok);
-*)
- prerr_endline "--------<REDUCE>---------";
- (function Some div ->
- print_endline (Pure.print div);
- let t = Pure.mwhd (e',div,[]) in
- prerr_endline ("*:: " ^ (Pure.print t));
- prerr_endline (print !bomb);
- assert (t = ToScott.t_of_nf (!bomb:>nf))
- | None -> ()) div;
- List.iter (fun n ->
- prerr_endline ("_::: " ^ (Pure.print n));
- let t = Pure.mwhd (e,n,[]) in
- prerr_endline ("_:: " ^ (Pure.print t))
- ) conv ;
- List.iteri (fun i n ->
- prerr_endline ((string_of_int i) ^ "::: " ^ (Pure.print n));
- let t = Pure.mwhd (e,n,[]) in
- prerr_endline ((string_of_int i) ^ ":: " ^ (Pure.print t));
- assert (t = Scott.mk_n i)
- ) ps ;
- prerr_endline "-------- </DONE> --------"
- ) problems
-
-(********************** problems *******************)
-
-let zero = `Var(0,0);;
-
-let append_zero =
- function
- | `I _
- | `Var _ as i -> cast_to_i_n_var (mk_app i zero)
- | _ -> assert false