+let iseq uri = UriManager.eq uri (Utils.eq_URI ());;
+
+let check_if_goal_is_identity env = function
+ | (goalproof,m,Cic.Appl[Cic.MutInd(uri,_,ens);eq_ty;left;right])
+ when left = right && iseq uri ->
+ let reflproof = Equality.Exact (Equality.refl_proof eq_ty left) in
+ Some (goalproof, reflproof, 0, Subst.empty_subst,m)
+ | _ -> None
+;;
+
+let rec check goal = function
+ | [] -> None
+ | f::tl ->
+ match f goal with
+ | None -> check goal tl
+ | (Some p) as ok -> ok
+;;
+
+let simplify_goal_set env goals passive active =
+ let active_goals, passive_goals = goals in
+ let find (_,_,g) where =
+ List.exists (fun (_,_,g1) -> Equality.meta_convertibility g g1) where
+ in
+ let simplified =
+ List.fold_left
+ (fun acc goal ->
+ match simplify_goal env goal ~passive active with
+ | _, g -> if find g acc then acc else g::acc)
+ (* active_goals active_goals *)
+ [] active_goals
+ in
+ if List.length active_goals <> List.length simplified then
+ prerr_endline "SEMPLIFICANDO HO SCARTATO...";
+ (simplified,passive_goals)
+ (*
+ HExtlib.list_uniq ~eq:(fun (_,_,t1) (_,_,t2) -> t1 = t2)
+ (List.sort (fun (_,_,t1) (_,_,t2) -> compare t1 t1)
+ ((*goals @*) simplified))
+ *)
+;;
+
+let check_if_goals_set_is_solved env active goals =
+ let active_goals, passive_goals = goals in
+ List.fold_left
+ (fun proof goal ->
+ match proof with
+ | Some p -> proof
+ | None ->
+ check goal [
+ check_if_goal_is_identity env;
+ check_if_goal_is_subsumed env (snd active)])
+ None active_goals
+;;
+
+let infer_goal_set env active goals =
+ let active_goals, passive_goals = goals in
+ let rec aux = function
+ | [] -> goals
+ | ((_,_,t1) as hd)::tl when
+ not (List.exists
+ (fun (_,_,t) -> Equality.meta_convertibility t t1)
+ active_goals)
+ ->
+ let selected = hd in
+ let passive_goals = tl in
+ let new' = Indexing.superposition_left env (snd active) selected in
+ selected::active_goals, passive_goals @ new'
+ | _::tl -> aux tl
+ in
+ aux passive_goals
+;;
+
+let infer_goal_set_with_current env current goals =
+ let active_goals, passive_goals = goals in
+ let _,table,_ = build_table [current] in
+ active_goals,
+ List.fold_left
+ (fun acc g ->
+ let new' = Indexing.superposition_left env table g in
+ acc @ new')
+ passive_goals active_goals
+;;
+
+
+
+let size_of_goal_set_a (l,_) = List.length l;;
+let size_of_goal_set_p (_,l) = List.length l;;
+
+(** given-clause algorithm with full reduction strategy: NEW implementation *)
+(* here goals is a set of goals in OR *)
+let given_clause
+ ((_,context,_) as env) goals theorems passive active max_iterations max_time
+=
+ let initial_time = Unix.gettimeofday () in
+ let iterations_left iterno =
+ let now = Unix.gettimeofday () in
+ let time_left = max_time -. now in
+ let time_spent_until_now = now -. initial_time in
+ let iteration_medium_cost =
+ time_spent_until_now /. (float_of_int iterno)
+ in
+ let iterations_left = time_left /. iteration_medium_cost in
+ int_of_float iterations_left
+ in
+ let rec step goals theorems passive active iterno =
+ if iterno > max_iterations then
+ (ParamodulationFailure "No more iterations to spend")
+ else if Unix.gettimeofday () > max_time then
+ (ParamodulationFailure "No more time to spend")
+ else
+ let _ = prerr_endline "simpl goal with active" in
+ let _ = <:start<simplify goal set active>> in
+ let goals = simplify_goal_set env goals passive active in
+ let _ = <:stop<simplify goal set active>> in
+ match check_if_goals_set_is_solved env active goals with
+ | Some p ->
+ prerr_endline
+ (Printf.sprintf "Found a proof in: %f\n"
+ (Unix.gettimeofday() -. initial_time));
+(* assert false;*)
+ ParamodulationSuccess p
+ | None ->
+ prerr_endline
+ (Printf.sprintf "%d #ACTIVES: %d #PASSIVES: %d #GOALSET: %d(%d)\n"
+ iterno (size_of_active active) (size_of_passive passive)
+ (size_of_goal_set_a goals) (size_of_goal_set_p goals));
+ (* PRUNING OF PASSIVE THAT WILL NEVER BE PROCESSED *)
+ let passive =
+ let selection_estimate = iterations_left iterno in
+ let kept = size_of_passive passive in
+ if kept > selection_estimate then
+ begin
+ (*Printf.eprintf "Too many passive equalities: pruning...";
+ prune_passive selection_estimate active*) passive
+ end
+ else
+ passive
+ in
+ kept_clauses := (size_of_passive passive) + (size_of_active active);
+ (* SELECTION *)
+ if passive_is_empty passive then
+ ParamodulationFailure "No more passive"(*maybe this is a success! *)
+ else
+ begin
+ let goals = infer_goal_set env active goals in
+ let current, passive = select env goals passive in
+ prerr_endline (Printf.sprintf "Selected = %s\n"
+ (Equality.string_of_equality ~env current));
+ (* SIMPLIFICATION OF CURRENT *)
+ let res =
+ forward_simplify env (Positive, current) ~passive active
+ in
+ match res with
+ | None -> step goals theorems passive active (iterno+1)
+ | Some current ->
+ (* GENERATION OF NEW EQUATIONS *)
+ prerr_endline "infer";
+ let new' = infer env current active in
+ prerr_endline "infer goal";
+ let goals = infer_goal_set_with_current env current goals in
+ let active =
+ let al, tbl = active in
+ al @ [current], Indexing.index tbl current
+ in
+ (* FORWARD AND BACKWARD SIMPLIFICATION *)
+ prerr_endline "fwd/back simpl";
+ let rec simplify new' active passive =
+ let new' = forward_simplify_new env new' ~passive active in
+ let active, passive, newa, retained, pruned =
+ backward_simplify env new' ~passive active
+ in
+ let passive =
+ List.fold_left filter_dependent passive pruned
+ in
+ match newa, retained with
+ | None, None -> active, passive, new'
+ | Some p, None
+ | None, Some p -> simplify (new' @ p) active passive
+ | Some p, Some rp -> simplify (new' @ p @ rp) active passive
+ in
+ let active, passive, new' = simplify new' active passive in
+ prerr_endline "simpl goal with new";
+ let goals =
+ let a,b,_ = build_table new' in
+ let _ = <:start<simplify_goal_set new>> in
+ <:stop<simplify_goal_set new
+ simplify_goal_set env goals passive (a,b)
+ >>
+ in
+ let passive = add_to_passive passive new' in
+ step goals theorems passive active (iterno+1)
+ end
+ in
+ step goals theorems passive active 1
+;;