let connect_to_auto = true;;
+let debug_print = Utils.debug_print;;
(* profiling statistics... *)
let infer_time = ref 0.;;
let set =
List.fold_left (fun s e -> EqualitySet.add e s) EqualitySet.empty eq_list
in
- (*EqualitySet.elements set*) eq_list, set (* see applys.ma *)
+ (* we have the invariant that the list and the set have the same
+ * cardinality *)
+ EqualitySet.elements set, set
;;
+
let make_empty_active () = [], Indexing.empty ;;
let make_active eq_list =
eq_list, List.fold_left Indexing.index Indexing.empty eq_list
let size_of_passive (passive_list, _) = List.length passive_list;;
let size_of_active (active_list, _) = List.length active_list;;
+
let passive_is_empty = function
| [], s when EqualitySet.is_empty s -> true
| [], s -> assert false (* the set and the list should be in sync *)
;;
-
+(*
let simplify_theorems bag env theorems ?passive (active_list, active_table) =
let pl, passive_table =
match passive with
let p_theorems = List.map (mapfun passive_table) p_theorems in
List.fold_left (foldfun passive_table) ([], p_theorems) a_theorems
;;
-
+*)
let rec simpl bag eq_uri env e others others_simpl =
let active = others @ others_simpl in
let pp_goal_set msg goals names =
let active_goals, passive_goals = goals in
- prerr_endline ("////" ^ msg);
- prerr_endline ("ACTIVE G: " ^
+ debug_print (lazy ("////" ^ msg));
+ debug_print (lazy ("ACTIVE G: " ^
(String.concat "\n " (List.map (fun (_,_,g) -> CicPp.pp g names)
- active_goals)));
- prerr_endline ("PASSIVE G: " ^
+ active_goals))));
+ debug_print (lazy ("PASSIVE G: " ^
(String.concat "\n " (List.map (fun (_,_,g) -> CicPp.pp g names)
- passive_goals)))
+ passive_goals))))
;;
let check_if_goal_is_subsumed bag ((_,ctx,_) as env) table (goalproof,menv,ty) =
Equality.mk_equality bag
(0,Equality.Exact (Cic.Implicit None),(eq_ty,left,right,Utils.Eq),menv)
in
-(* match Indexing.subsumption env table goal_equation with*)
- match Indexing.unification env table goal_equation with
+ match Indexing.subsumption env table goal_equation with
+ (* match Indexing.unification env table goal_equation with *)
| Some (subst, equality, swapped ) ->
(*
prerr_endline
| _ -> None
;;
-let find_all_subsumed bag env table (goalproof,menv,ty) =
+let find_all_subsumed bag maxm env table (goalproof,menv,ty) =
match ty with
| Cic.Appl[Cic.MutInd(uri,_,_);eq_ty;left;right]
when LibraryObjects.is_eq_URI uri ->
let goal_equation =
- Equality.mk_equality bag
- (0,Equality.Exact (Cic.Implicit None),(eq_ty,left,right,Utils.Eq),menv)
+ (Equality.mk_equality bag
+ (0,Equality.Exact (Cic.Implicit None),(eq_ty,left,right,Utils.Eq),menv))
in
- List.map
+ List.map
(fun (subst, equality, swapped ) ->
let (_,p,(ty,l,r,_),m,id) = Equality.open_equality equality in
let cicmenv = Subst.apply_subst_metasenv subst (m @ menv) in
+ Indexing.check_for_duplicates cicmenv "from subsumption";
let p =
if swapped then
Equality.symmetric bag eq_ty l id uri m
else
p
in (goalproof, p, id, subst, cicmenv))
- (Indexing.unification_all env table goal_equation)
+ (Indexing.subsumption_all env table goal_equation)
+ (* (Indexing.unification_all env table goal_equation) *)
| _ -> assert false
;;
(let _,context,_ = env in
try
let s,m,_ =
- Founif.unification m m context left right CicUniv.empty_ugraph
+ Founif.unification [] m context left right CicUniv.empty_ugraph
in
let reflproof = Equality.Exact (Equality.refl_proof uri eq_ty left) in
let m = Subst.apply_subst_metasenv s m in
Some (goalproof, reflproof, 0, s,m)
- with _ -> None)
+ with CicUnification.UnificationFailure _ -> None)
| _ -> None
;;
let names = Utils.names_of_context context in
List.iter
(fun _,_,g ->
- prerr_endline
- (Printf.sprintf "Current goal: %s = %s\n" label (CicPp.pp g names)))
+ debug_print (lazy
+ (Printf.sprintf "Current goal: %s = %s\n" label (CicPp.pp g names))))
(fst goals);
List.iter
(fun _,_,g ->
- prerr_endline
- (Printf.sprintf "PASSIVE goal: %s = %s\n" label (CicPp.pp g names)))
+ debug_print (lazy
+ (Printf.sprintf "PASSIVE goal: %s = %s\n" label (CicPp.pp g names))))
(snd goals);
;;
let print_status iterno goals active passive =
- prerr_endline
+ debug_print (lazy
(Printf.sprintf "\n%d #ACTIVES: %d #PASSIVES: %d #GOALSET: %d(%d)"
iterno (size_of_active active) (size_of_passive passive)
- (size_of_goal_set_a goals) (size_of_goal_set_p goals))
+ (size_of_goal_set_a goals) (size_of_goal_set_p goals)))
;;
(** given-clause algorithm with full reduction strategy: NEW implementation *)
in
match check_if_goals_set_is_solved bag env active goals with
| Some p ->
- prerr_endline
+ debug_print (lazy
(Printf.sprintf "\nFound a proof in: %f\n"
- (Unix.gettimeofday() -. initial_time));
+ (Unix.gettimeofday() -. initial_time)));
ParamodulationSuccess (p,active,passive)
| None ->
(* SELECTION *)
if s_iterno < saturation_steps then
let current, passive = select env goals passive in
(* SIMPLIFICATION OF CURRENT *)
- prerr_endline
+ debug_print (lazy
("Selected : " ^
- Equality.string_of_equality ~env current);
+ Equality.string_of_equality ~env current));
forward_simplify bag eq_uri env current active, passive
else
None, passive
try
let _ = CicUtil.lookup_meta i metasenv in metasenv
with CicUtil.Meta_not_found _ ->
- prerr_endline ("not found: "^(string_of_int i));
+ debug_print (lazy ("not found: "^(string_of_int i)));
let metasenv,j = CicMkImplicit.mk_implicit_type metasenv [] context in
(i,context,Cic.Meta(j,irl))::metasenv
in
let metasenv,s = aux metasenv n s in
let metasenv,t = aux metasenv (n+1) t in
metasenv,Cic.Prod(name,s,t)
- | Cic.LetIn(name,s,t) ->
+ | Cic.LetIn(name,s,ty,t) ->
let metasenv,s = aux metasenv n s in
+ let metasenv,ty = aux metasenv n ty in
let metasenv,t = aux metasenv (n+1) t in
- metasenv,Cic.LetIn(name,s,t)
+ metasenv,Cic.LetIn(name,s,ty,t)
+ | Cic.Const(uri,ens) ->
+ let metasenv,ens =
+ List.fold_right
+ (fun (v,a) (metasenv,ens) ->
+ let metasenv,a' = aux metasenv n a in
+ metasenv,(v,a')::ens)
+ ens (metasenv,[])
+ in
+ metasenv,Cic.Const(uri,ens)
| t -> metasenv,t
in
aux metasenv 0 p
;;
-let fix_metasenv metasenv context =
+let fix_metasenv context metasenv =
List.fold_left
(fun m (i,c,t) ->
let m,t = fix_proof m context false t in
let m = List.filter (fun (j,_,_) -> j<>i) m in
- (i,c,t)::m)
+ (i,context,t)::m)
metasenv metasenv
;;
+
(* status: input proof status
* goalproof: forward steps on goal
* newproof: backward steps
bag status
goalproof newproof subsumption_id subsumption_subst proof_menv
=
- if proof_menv = [] then prerr_endline "+++++++++++++++VUOTA"
- else prerr_endline (CicMetaSubst.ppmetasenv [] proof_menv);
+ if proof_menv = [] then debug_print (lazy "+++++++++++++++VUOTA")
+ else debug_print (lazy (CicMetaSubst.ppmetasenv [] proof_menv));
let proof, goalno = status in
- let uri, metasenv, meta_proof, term_to_prove = proof in
+ let uri, metasenv, _subst, meta_proof, term_to_prove, attrs = proof in
let _, context, type_of_goal = CicUtil.lookup_meta goalno metasenv in
let eq_uri = eq_of_goal type_of_goal in
let names = Utils.names_of_context context in
- prerr_endline "Proof:";
- prerr_endline
+ debug_print (lazy "Proof:");
+ debug_print (lazy
(Equality.pp_proof bag names goalproof newproof subsumption_subst
- subsumption_id type_of_goal);
+ subsumption_id type_of_goal));
(*
prerr_endline ("max weight: " ^
(string_of_int (Equality.max_weight goalproof newproof)));
(ProofEngineHelpers.compare_metasenvs
~newmetasenv:metasenv ~oldmetasenv:proof_menv) in
let goal_proof, side_effects_t =
- let initial = (* Equality.add_subst subsumption_subst*) newproof in
+ let initial = Equality.add_subst subsumption_subst newproof in
Equality.build_goal_proof bag
eq_uri goalproof initial type_of_goal side_effects
context proof_menv
in
+(* Equality.draw_proof bag names goalproof newproof subsumption_id; *)
let goal_proof = Subst.apply_subst subsumption_subst goal_proof in
- let real_menv = fix_metasenv (proof_menv@metasenv) context in
+ (* assert (metasenv=[]); *)
+ let real_menv = fix_metasenv context (proof_menv@metasenv) in
let real_menv,goal_proof =
fix_proof real_menv context false goal_proof in
(*
let real_menv,fixed_proof = fix_proof proof_menv context false goal_proof in
(* prerr_endline ("PROOF: " ^ CicPp.pp goal_proof names); *)
*)
+ let pp_error goal_proof names error exn =
+ prerr_endline "THE PROOF DOES NOT TYPECHECK! <begin>";
+ prerr_endline (CicPp.pp goal_proof names);
+ prerr_endline "THE PROOF DOES NOT TYPECHECK!";
+ prerr_endline error;
+ prerr_endline "THE PROOF DOES NOT TYPECHECK! <end>";
+ raise exn
+ in
+ let old_insert_coercions = !CicRefine.insert_coercions in
let goal_proof,goal_ty,real_menv,_ =
(* prerr_endline ("parte la refine per: " ^ (CicPp.pp goal_proof names)); *)
try
- CicRefine.type_of_aux' real_menv context goal_proof CicUniv.empty_ugraph
+ debug_print (lazy (CicPp.ppterm goal_proof));
+ CicRefine.insert_coercions := false;
+ let res =
+ CicRefine.type_of_aux'
+ real_menv context goal_proof CicUniv.empty_ugraph
+ in
+ CicRefine.insert_coercions := old_insert_coercions;
+ res
with
- | CicUtil.Meta_not_found _
- | CicRefine.RefineFailure _
- | CicRefine.Uncertain _
- | CicRefine.AssertFailure _
+ | CicRefine.RefineFailure s
+ | CicRefine.Uncertain s
+ | CicRefine.AssertFailure s as exn ->
+ CicRefine.insert_coercions := old_insert_coercions;
+ pp_error goal_proof names (Lazy.force s) exn
+ | CicUtil.Meta_not_found i as exn ->
+ CicRefine.insert_coercions := old_insert_coercions;
+ pp_error goal_proof names ("META NOT FOUND: "^string_of_int i) exn
| Invalid_argument "list_fold_left2" as exn ->
- prerr_endline "THE PROOF DOES NOT TYPECHECK!";
- prerr_endline (CicPp.pp goal_proof names);
- prerr_endline "THE PROOF DOES NOT TYPECHECK!";
+ CicRefine.insert_coercions := old_insert_coercions;
+ pp_error goal_proof names "Invalid_argument: list_fold_left2" exn
+ | exn ->
+ CicRefine.insert_coercions := old_insert_coercions;
raise exn
in
let subst_side_effects,real_menv,_ =
| CicUnification.AssertFailure s -> assert false
(* fail "Maybe the local context of metas in the goal was not an IRL" s *)
in
- prerr_endline "+++++++++++++ FINE UNIF";
+ Utils.debug_print (lazy "+++++++++++++ FINE UNIF");
let final_subst =
(goalno,(context,goal_proof,type_of_goal))::subst_side_effects
in
*)
let proof, real_metasenv =
ProofEngineHelpers.subst_meta_and_metasenv_in_proof
- proof goalno (CicMetaSubst.apply_subst final_subst)
+ proof goalno final_subst
(List.filter (fun i,_,_ -> i<>goalno ) real_menv)
in
let open_goals =
let pump_actives context bag maxm active passive saturation_steps max_time =
reset_refs();
maxmeta := maxm;
+(*
let max_l l =
List.fold_left
(fun acc e -> let _,_,_,menv,_ = Equality.open_equality e in
List.fold_left (fun acc (i,_,_) -> max i acc) acc menv)
0 l in
- let active_l = fst active in
- let passive_l = fst passive in
- let ma = max_l active_l in
- let mp = max_l passive_l in
+*)
+(* let active_l = fst active in *)
+(* let passive_l = fst passive in *)
+(* let ma = max_l active_l in *)
+(* let mp = max_l passive_l in *)
match LibraryObjects.eq_URI () with
| None -> active, passive, !maxmeta
| Some eq_uri ->
let all_subsumed bag maxm status active passive =
maxmeta := maxm;
let proof, goalno = status in
- let uri, metasenv, meta_proof, term_to_prove = proof in
+ let uri, metasenv, _subst, meta_proof, term_to_prove, attrs = proof in
let _, context, type_of_goal = CicUtil.lookup_meta goalno metasenv in
let env = metasenv,context,CicUniv.empty_ugraph in
let cleaned_goal = Utils.remove_local_context type_of_goal in
+ let canonical_menv,other_menv =
+ List.partition (fun (_,c,_) -> c = context) metasenv in
+ (* prerr_endline ("other menv = " ^ (CicMetaSubst.ppmetasenv [] other_menv)); *)
+ let metasenv = List.map (fun (i,_,ty)-> (i,[],ty)) canonical_menv in
let goal = [], List.filter (fun (i,_,_)->i<>goalno) metasenv, cleaned_goal in
- prerr_endline (string_of_int (List.length (fst active)));
+ debug_print (lazy (string_of_int (List.length (fst active))));
(* we simplify using both actives passives *)
let table =
List.fold_left
(fun (l,tbl) eq -> eq::l,(Indexing.index tbl eq))
active (list_of_passive passive) in
+ let (_,_,ty) = goal in
+ debug_print (lazy ("prima " ^ CicPp.ppterm ty));
let _,goal = simplify_goal bag env goal table in
let (_,_,ty) = goal in
- prerr_endline (CicPp.ppterm ty);
- let subsumed = find_all_subsumed bag env (snd table) goal in
+ debug_print (lazy ("in mezzo " ^ CicPp.ppterm ty));
+ let subsumed = find_all_subsumed bag !maxmeta env (snd table) goal in
+ debug_print (lazy ("dopo " ^ CicPp.ppterm ty));
let subsumed_or_id =
match (check_if_goal_is_identity env goal) with
None -> subsumed
| Some id -> id::subsumed in
+ debug_print (lazy "dopo subsumed");
let res =
List.map
(fun
(goalproof,newproof,subsumption_id,subsumption_subst, proof_menv) ->
+ let subst, proof, gl =
build_proof bag
- status goalproof newproof subsumption_id subsumption_subst proof_menv)
- subsumed_or_id in
+ status goalproof newproof subsumption_id subsumption_subst proof_menv
+ in
+ let uri, metasenv, subst, meta_proof, term_to_prove, attrs = proof in
+ let newmetasenv =
+ other_menv @
+ List.filter
+ (fun x,_,_ -> not (List.exists (fun y,_,_ -> x=y) other_menv)) metasenv
+ in
+ let proof = uri, newmetasenv, subst, meta_proof, term_to_prove, attrs in
+ (subst, proof,gl)) subsumed_or_id
+ in
res, !maxmeta
=
reset_refs();
maxmeta := maxm;
+ let active_l = fst active in
+(*
let max_l l =
List.fold_left
(fun acc e -> let _,_,_,menv,_ = Equality.open_equality e in
List.fold_left (fun acc (i,_,_) -> max i acc) acc menv)
0 l
in
- let active_l = fst active in
let passive_l = fst passive in
let ma = max_l active_l in
let mp = max_l passive_l in
+*)
let proof, goalno = status in
- let uri, metasenv, meta_proof, term_to_prove = proof in
+ let uri, metasenv, _subst, meta_proof, term_to_prove, attrs = proof in
let _, context, type_of_goal = CicUtil.lookup_meta goalno metasenv in
let eq_uri = eq_of_goal type_of_goal in
let cleaned_goal = Utils.remove_local_context type_of_goal in
+ let canonical_menv,other_menv =
+ List.partition (fun (_,c,_) -> c = context) metasenv in
+ (* prerr_endline ("other menv = " ^ (CicMetaSubst.ppmetasenv [] other_menv)); *)
Utils.set_goal_symbols cleaned_goal; (* DISACTIVATED *)
- let metasenv' = List.filter (fun (i,_,_)->i<>goalno) metasenv in
+ let canonical_menv = List.map (fun (i,_,ty)-> (i,[],ty)) canonical_menv in
+ let metasenv' = List.filter (fun (i,_,_)->i<>goalno) canonical_menv in
let goal = [], metasenv', cleaned_goal in
let env = metasenv,context,CicUniv.empty_ugraph in
- prerr_endline ">>>>>> ACTIVES >>>>>>>>";
- List.iter (fun e -> prerr_endline (Equality.string_of_equality ~env e))
+ debug_print (lazy ">>>>>> ACTIVES >>>>>>>>");
+ List.iter (fun e -> debug_print (lazy (Equality.string_of_equality ~env e)))
active_l;
- prerr_endline ">>>>>>>>>>>>>>";
+ debug_print (lazy ">>>>>>>>>>>>>>");
let goals = make_goal_set goal in
match
-(* given_caluse non prende in input maxm ????? *)
given_clause bag eq_uri env goals passive active
goal_steps saturation_steps max_time
with
build_proof bag
status goalproof newproof subsumption_id subsumption_subst proof_menv
in
+ let uri, metasenv, subst, meta_proof, term_to_prove, attrs = proof in
+ let proof = uri, other_menv@metasenv, subst, meta_proof, term_to_prove, attrs in
Some (subst, proof,gl),a,p, !maxmeta
;;
+
let add_to_passive eql passives =
add_to_passive passives eql eql
;;