CicSubstitution.subst (Cic.Rel 1) t
;;
+let head_of_apply = function | Cic.Appl (hd::_) -> hd | t -> t;;
+let tail_of_apply = function | Cic.Appl (_::tl) -> tl | t -> [];;
+let count_args t = List.length (tail_of_apply t);;
+let rec build_nat =
+ let u = UriManager.uri_of_string "cic:/matita/nat/nat/nat.ind" in
+ function
+ | 0 -> Cic.MutConstruct(u,0,1,[])
+ | n ->
+ Cic.Appl [Cic.MutConstruct(u,0,2,[]);build_nat (n-1)]
+;;
+let tyof context menv t =
+ try
+ fst(CicTypeChecker.type_of_aux' menv context t CicUniv.empty_ugraph)
+ with
+ | CicTypeChecker.TypeCheckerFailure _
+ | CicTypeChecker.AssertFailure _ -> assert false
+;;
+let rec lambdaof left context = function
+ | Cic.Prod (n,s,t) ->
+ Cic.Lambda (n,s,lambdaof left context t)
+ | Cic.Appl [Cic.MutInd (uri, 0,_);ty;l;r]
+ when LibraryObjects.is_eq_URI uri -> if left then l else r
+ | t ->
+ let names = Utils.names_of_context context in
+ prerr_endline ("lambdaof: " ^ (CicPp.pp t names));
+ assert false
+;;
-let canonical t =
+let canonical t context menv =
let rec remove_refl t =
match t with
| Cic.Appl (((Cic.Const(uri_trans,ens))::tl) as args)
Cic.LetIn (name,remove_refl bo,remove_refl rest)
| _ -> t
in
- let rec canonical t =
+ let rec canonical context t =
match t with
- | Cic.LetIn(name,bo,rest) -> Cic.LetIn(name,canonical bo,canonical rest)
+ | Cic.LetIn(name,bo,rest) ->
+ let context' = (Some (name,Cic.Def (bo,None)))::context in
+ Cic.LetIn(name,canonical context bo,canonical context' rest)
| Cic.Appl (((Cic.Const(uri_sym,ens))::tl) as args)
when LibraryObjects.is_sym_eq_URI uri_sym ->
(match p_of_sym ens tl with
| Cic.Appl ((Cic.Const(uri,ens))::tl)
when LibraryObjects.is_sym_eq_URI uri ->
- canonical (p_of_sym ens tl)
+ canonical context (p_of_sym ens tl)
| Cic.Appl ((Cic.Const(uri_trans,ens))::tl)
when LibraryObjects.is_trans_eq_URI uri_trans ->
let ty,l,m,r,p1,p2 = open_trans ens tl in
mk_trans uri_trans ty r m l
- (canonical (mk_sym uri_sym ty m r p2))
- (canonical (mk_sym uri_sym ty l m p1))
+ (canonical context (mk_sym uri_sym ty m r p2))
+ (canonical context (mk_sym uri_sym ty l m p1))
+ | Cic.Appl (([Cic.Const(uri_feq,ens);ty1;ty2;f;x;y;p])) ->
+
+ let eq_f_sym =
+ Cic.Const (UriManager.uri_of_string
+ "cic:/matita/logic/equality/eq_f1.con",[])
+ in
+ Cic.Appl (([eq_f_sym;ty1;ty2;f;x;y;p]))
+
+(*
+ let sym_eq = Cic.Const(uri_sym,ens) in
+ let eq_f = Cic.Const(uri_feq,[]) in
+ let b = Cic.MutConstruct (UriManager.uri_of_string
+ "cic:/matita/datatypes/bool/bool.ind",0,1,[])
+ in
+ let u = ty1 in
+ let ctx = f in
+ let n = build_nat (count_args p) in
+ let h = head_of_apply p in
+ let predl = lambdaof true context (tyof context menv h) in
+ let predr = lambdaof false context (tyof context menv h) in
+ let args = tail_of_apply p in
+ let appl =
+ Cic.Appl
+ ([Cic.Const(UriManager.uri_of_string
+ "cic:/matita/paramodulation/rewrite.con",[]);
+ eq; sym_eq; eq_f; b; u; ctx; n; predl; predr; h] @
+ args)
+ in
+ appl
+*)
+(*
| Cic.Appl (((Cic.Const(uri_ind,ens)) as he)::tl)
when LibraryObjects.is_eq_ind_URI uri_ind ||
LibraryObjects.is_eq_ind_r_URI uri_ind ->
Cic.Appl
[he;ty;what;pred;
canonical (mk_sym uri_sym ty l r p1);other;canonical p2]
+*)
| Cic.Appl [Cic.MutConstruct (uri, 0, 1,_);_;_] as t
when LibraryObjects.is_eq_URI uri -> t
- | _ -> Cic.Appl (List.map canonical args))
- | Cic.Appl l -> Cic.Appl (List.map canonical l)
+ | _ -> Cic.Appl (List.map (canonical context) args))
+ | Cic.Appl l -> Cic.Appl (List.map (canonical context) l)
| _ -> t
in
- remove_refl (canonical t)
+ remove_refl (canonical context t)
;;
let ty_of_lambda = function
| _ -> assert false
;;
+let mk_feq uri_feq ty ty1 left pred right t =
+ Cic.Appl [Cic.Const(uri_feq,[]);ty;ty1;pred;left;right;t]
+;;
+
let contextualize uri ty left right t =
let hole = Cic.Implicit (Some `Hole) in
(* aux [uri] [ty] [left] [right] [ctx] [t]
mk_trans uri_trans ctx_ty a b c paeqb pbeqc
| t when ctx_d = hole -> t
| t ->
- let uri_sym = LibraryObjects.sym_eq_URI ~eq:uri in
- let uri_ind = LibraryObjects.eq_ind_URI ~eq:uri in
+(* let uri_sym = LibraryObjects.sym_eq_URI ~eq:uri in *)
+(* let uri_ind = LibraryObjects.eq_ind_URI ~eq:uri in *)
+ let uri_feq =
+ UriManager.uri_of_string "cic:/matita/logic/equality/eq_f.con"
+ in
let pred =
- (* ctx_d will go under a lambda, but put_in_ctx substitutes Rel 1 *)
- let r = CicSubstitution.lift 1 (put_in_ctx ctx_d left) in
+(* let r = CicSubstitution.lift 1 (put_in_ctx ctx_d left) in *)
let l =
let ctx_d = CicSubstitution.lift 1 ctx_d in
put_in_ctx ctx_d (Cic.Rel 1)
in
- let lty = CicSubstitution.lift 1 ctx_ty in
- Cic.Lambda (Cic.Name "foo",ty,(mk_eq uri lty l r))
+(* let lty = CicSubstitution.lift 1 ctx_ty in *)
+(* Cic.Lambda (Cic.Name "foo",ty,(mk_eq uri lty l r)) *)
+ Cic.Lambda (Cic.Name "foo",ty,l)
in
- let d_left = put_in_ctx ctx_d left in
- let d_right = put_in_ctx ctx_d right in
- let refl_eq = mk_refl uri ctx_ty d_left in
- mk_sym uri_sym ctx_ty d_right d_left
- (mk_eq_ind uri_ind ty left pred refl_eq right t)
+(* let d_left = put_in_ctx ctx_d left in *)
+(* let d_right = put_in_ctx ctx_d right in *)
+(* let refl_eq = mk_refl uri ctx_ty d_left in *)
+(* mk_sym uri_sym ctx_ty d_right d_left *)
+(* (mk_eq_ind uri_ind ty left pred refl_eq right t) *)
+ (mk_feq uri_feq ty ctx_ty left pred right t)
in
aux uri ty left right hole ty t
;;
aux proof
;;
-let build_goal_proof eq l initial ty se =
+let build_goal_proof eq l initial ty se context menv =
let se = List.map (fun i -> Cic.Meta (i,[])) se in
let lets = get_duplicate_step_in_wfo l initial in
let letsno = List.length lets in
cic, p))
lets (letsno-1,initial)
in
- canonical (contextualize_rewrites proof (CicSubstitution.lift letsno ty)),
+ canonical
+ (contextualize_rewrites proof (CicSubstitution.lift letsno ty))
+ context menv,
se
;;
exception Empty_list;;
-let passive_is_empty = function
- | ([], _), _ -> true
- | _ -> false
+type passives = Equality.equality list * EqualitySet.t;;
+type actives = Equality.equality list * Indexing.Index.t;;
+
+(* initializes the passive set of equalities
+ * XXX I think EqualitySet.elements should be ok (to eliminate duplicates)
+ *)
+let make_passive pos =
+ let set =
+ List.fold_left (fun s e -> EqualitySet.add e s) EqualitySet.empty pos
+ in
+ (*EqualitySet.elements*) pos, set
;;
-let no_more_passive_goals = function
- | _,[] -> true
+let make_active () = [], Indexing.empty ;;
+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 *)
| _ -> false
;;
-
-let size_of_passive ((passive_list, ps), _) = List.length passive_list
-(* EqualitySet.cardinal ps *)
-;;
+type goals = Equality.goal list * Equality.goal list
-let size_of_active (active_list, _) = List.length active_list
-;;
+let no_more_passive_goals g = match g with | _,[] -> true | _ -> false;;
+
let age_factor = 0.01;;
let goal =
match (List.rev goals) with goal::_ -> goal | _ -> assert false
in
- let (pos_list, pos_set), passive_table = passive in
+ let pos_list, pos_set = passive in
let remove eq l = List.filter (fun e -> Equality.compare e eq <> 0) l in
if !weight_age_ratio > 0 then
weight_age_counter := !weight_age_counter - 1;
match !weight_age_counter with
| 0 -> (
weight_age_counter := !weight_age_ratio;
- let rec skip_giant pos_list pos_set passive_table =
+ let rec skip_giant pos_list pos_set =
match pos_list with
| (hd:EqualitySet.elt)::tl ->
let w,_,_,_,_ = Equality.open_equality hd in
- let passive_table =
- Indexing.remove_index passive_table hd
- in
let pos_set = EqualitySet.remove hd pos_set in
if w < 500 then
- hd, ((tl, pos_set), passive_table)
+ hd, (tl, pos_set)
else
- (prerr_endline ("\n\n\nGIANT SKIPPED: "^string_of_int w^"\n\n\n");
- skip_giant tl pos_set passive_table)
+ (prerr_endline
+ ("+++ skipping giant of size "^string_of_int w^" +++");
+ skip_giant tl pos_set)
| _ -> assert false
in
- skip_giant pos_list pos_set passive_table)
+ skip_giant pos_list pos_set)
| _ when (!symbols_counter > 0) ->
(symbols_counter := !symbols_counter - 1;
let cardinality map =
(others + (abs (common - card))), e1
in
let _, current = EqualitySet.fold f pos_set initial in
- let passive_table =
- Indexing.remove_index passive_table current
- in
current,
- ((remove current pos_list, EqualitySet.remove current pos_set),
- passive_table))
+ (remove current pos_list, EqualitySet.remove current pos_set))
| _ ->
symbols_counter := !symbols_ratio;
let my_min e1 e2 =
let w1,_,_,_,_ = Equality.open_equality e1 in
- let w2,_,_,_,_ = Equality.open_equality e2 in
- if w1 < w2 then e1 else e2
+ let w2,_,_,_,_ = Equality.open_equality e2 in
+ if w1 < w2 then e1 else e2
in
let rec my_min_elt min = function
| [] -> min
- | hd::tl -> my_min_elt (my_min hd min) tl
+ | hd::tl -> my_min_elt (my_min hd min) tl
in
-(* let current = EqualitySet.min_elt pos_set in *)
+(* let current = EqualitySet.min_elt pos_set in *)
let current = my_min_elt (List.hd pos_list) (List.tl pos_list) in
- let passive_table =
- Indexing.remove_index passive_table current
- in
- current,
- ((remove current pos_list, EqualitySet.remove current pos_set),
- passive_table)
+ current,(remove current pos_list, EqualitySet.remove current pos_set)
;;
+
let filter_dependent passive id =
- prerr_endline ("+++++++++++++++passives "^
- ( string_of_int (size_of_passive passive)));
- let (pos_list, pos_set), passive_table = passive in
- let passive =
+ let pos_list, pos_set = passive in
+ let passive,no_pruned =
List.fold_right
- (fun eq ((list,set),table) ->
+ (fun eq ((list,set),no) ->
if Equality.depend eq id then
- (let _,_,_,_,id_eq = Equality.open_equality eq in
- if id_eq = 9228 then
- prerr_endline ("\n\n--------filtering "^(string_of_int id_eq));
- ((list,
- EqualitySet.remove eq set),
- Indexing.remove_index table eq))
+ (list, EqualitySet.remove eq set), no + 1
else
- ((eq::list, set),table))
- pos_list (([],pos_set),passive_table) in
- prerr_endline ("+++++++++++++++passives "^
- ( string_of_int (size_of_passive passive)));
- passive
-;;
-
-
-(* initializes the passive set of equalities *)
-let make_passive pos =
- let set_of equalities =
- List.fold_left (fun s e -> EqualitySet.add e s) EqualitySet.empty equalities
- in
- let table =
- List.fold_left (fun tbl e -> Indexing.index tbl e) Indexing.empty pos
+ (eq::list, set), no)
+ pos_list (([],pos_set),0)
in
- (pos, set_of pos),
- table
-;;
-
-
-let make_active () =
- [], Indexing.empty
+ if no_pruned > 0 then
+ prerr_endline ("+++ pruning "^ string_of_int no_pruned ^" passives +++");
+ passive
;;
(* adds to passive a list of equalities new_pos *)
let add_to_passive passive new_pos preferred =
- let (pos_list, pos_set), table = passive in
+ let pos_list, pos_set = passive in
let ok set equality = not (EqualitySet.mem equality set) in
let pos = List.filter (ok pos_set) new_pos in
- let table =
- List.fold_left (fun tbl e -> Indexing.index tbl e) table pos
- in
let add set equalities =
List.fold_left (fun s e -> EqualitySet.add e s) set equalities
in
(fun e -> List.exists (fun x -> Equality.compare x e = 0) preferred)
pos
in
- (pos_head @ pos_list @ pos_tail, add pos_set pos),
- table
+ assert(pos_head = []);
+ pos_head @ pos_list @ pos_tail, add pos_set pos
;;
(* TODO *)
fst (aux false (true,false) left right)
;;
-(* buttare via sign *)
-
(** simplifies current using active and passive *)
-let forward_simplify
- eq_uri env (sign,current) ?passive (active_list, active_table)
-=
+let forward_simplify eq_uri env current (active_list, active_table) =
let _, context, _ = env in
- let passive_table =
- match passive with
- | None -> None
- | Some ((_, _), pt) -> Some pt
- in
let demodulate table current =
let newmeta, newcurrent =
- Indexing.demodulation_equality eq_uri !maxmeta env table sign current in
+ Indexing.demodulation_equality eq_uri !maxmeta env table current
+ in
maxmeta := newmeta;
- if Equality.is_identity env newcurrent then
- None
- else
- Some newcurrent
+ if Equality.is_identity env newcurrent then None else Some newcurrent
in
let rec demod current =
if Utils.debug_metas then
if Utils.debug_metas then
ignore ((function None -> () | Some x ->
ignore (Indexing.check_target context x "demod1");()) res);
- match res with
- | None -> None
- | Some newcurrent ->
- match passive_table with
- | None -> res
- | Some passive_table ->
- match demodulate passive_table newcurrent with
- | None -> None
- | Some newnewcurrent ->
- if Equality.compare newcurrent newnewcurrent <> 0 then
- demod newnewcurrent
- else Some newnewcurrent
+ res
in
let res = demod current in
match res with
| None -> None
| Some c ->
- if Indexing.in_index active_table c then
+ if Indexing.in_index active_table c ||
+ check_for_deep_subsumption env active_table c
+ then
None
- else
- match passive_table with
- | None ->
- if check_for_deep_subsumption env active_table c then
- None
- else
- res
-(*
- if Indexing.subsumption env active_table c = None then
- res
- else
- None
-*)
- | Some passive_table ->
- if Indexing.in_index passive_table c then None
- else
- if check_for_deep_subsumption env active_table c then
- None
- else
-(* if Indexing.subsumption env active_table c = None then*)
- (match Indexing.subsumption env passive_table c with
- | None -> res
- | Some (_,c',_) ->
- None
- (*prerr_endline "\n\nPESCO DALLE PASSIVE LA PIU' GENERALE\n\n";
- Some c'*))
-(*
- else
- None
-*)
+ else
+ res
;;
(** simplifies new using active and passive *)
-let forward_simplify_new eq_uri env new_pos ?passive active =
+let forward_simplify_new eq_uri env new_pos active =
if Utils.debug_metas then
begin
let m,c,u = env in
new_pos;)
end;
let active_list, active_table = active in
- let passive_table =
- match passive with
- | None -> None
- | Some ((_, _), pt) -> Some pt
- in
- let demodulate sign table target =
+ let demodulate table target =
let newmeta, newtarget =
- Indexing.demodulation_equality eq_uri !maxmeta env table sign target
+ Indexing.demodulation_equality eq_uri !maxmeta env table target
in
maxmeta := newmeta;
newtarget
in
(* we could also demodulate using passive. Currently we don't *)
- let new_pos =
- List.map (demodulate Utils.Positive active_table) new_pos
- in
+ let new_pos = List.map (demodulate active_table) new_pos in
let new_pos_set =
List.fold_left
(fun s e ->
in
let new_pos = EqualitySet.elements new_pos_set in
- let subs =
- match passive_table with
- | None ->
- (fun e -> (Indexing.subsumption env active_table e = None))
- | Some passive_table ->
- (fun e -> ((Indexing.subsumption env active_table e = None) &&
- (Indexing.subsumption env passive_table e = None)))
- in
- let is_duplicate =
- match passive_table with
- | None ->
- (fun e -> not (Indexing.in_index active_table e))
- | Some passive_table ->
- (fun e ->
- not ((Indexing.in_index active_table e) ||
- (Indexing.in_index passive_table e)))
- in
- List.filter subs (List.filter is_duplicate new_pos)
+ let subs e = Indexing.subsumption env active_table e = None in
+ let is_duplicate e = not (Indexing.in_index active_table e) in
+ List.filter subs (List.filter is_duplicate new_pos)
;;
(** simplifies a goal with equalities in active and passive *)
-let rec simplify_goal env goal ?passive (active_list, active_table) =
- let passive_table =
- match passive with
- | None -> None
- | Some ((_, _), pt) -> Some pt
- in
+let rec simplify_goal env goal (active_list, active_table) =
let demodulate table goal = Indexing.demodulation_goal env table goal in
- let changed, goal =
- match passive_table with
- | None -> demodulate active_table goal
- | Some passive_table ->
- let changed, goal = demodulate active_table goal in
-(* let changed', goal = demodulate passive_table goal in*)
- (changed (*|| changed'*)), goal
- in
+ let changed, goal = demodulate active_table goal in
changed,
if not changed then
goal
else
- snd (simplify_goal env goal ?passive (active_list, active_table))
+ snd (simplify_goal env goal (active_list, active_table))
;;
-let simplify_goals env goals ?passive active =
+let simplify_goals env goals active =
let a_goals, p_goals = goals in
- let p_goals =
- List.map
- (fun g -> snd (simplify_goal env g ?passive active))
- p_goals
- in
- let a_goals =
- List.map
- (fun g -> snd (simplify_goal env g ?passive active))
- a_goals
- in
+ let p_goals = List.map (fun g -> snd (simplify_goal env g active)) p_goals in
+ let a_goals = List.map (fun g -> snd (simplify_goal env g active)) a_goals in
a_goals, p_goals
;;
equality::res, newn,pruned
else
match
- forward_simplify
- eq_uri env (Utils.Positive, equality) (new_pos, new_table)
+ forward_simplify eq_uri env equality (new_pos, new_table)
with
| None -> res, newn, id::pruned
| Some e ->
(** simplifies passive using new *)
let backward_simplify_passive eq_uri env new_pos new_table min_weight passive =
let (pl, ps), passive_table = passive in
- let f sign equality (resl, ress, newn) =
+ let f equality (resl, ress, newn) =
let ew, _, _, _ , _ = Equality.open_equality equality in
if ew < min_weight then
equality::resl, ress, newn
else
match
- forward_simplify eq_uri env (sign, equality) (new_pos, new_table)
+ forward_simplify eq_uri env equality (new_pos, new_table)
with
| None -> resl, EqualitySet.remove equality ress, newn
| Some e ->
let ress = EqualitySet.remove equality ress in
resl, ress, e::newn
in
- let pl, ps, newp = List.fold_right (f Utils.Positive) pl ([], ps, []) in
+ let pl, ps, newp = List.fold_right f pl ([], ps, []) in
let passive_table =
List.fold_left
(fun tbl e -> Indexing.index tbl e) Indexing.empty pl
;;
-let backward_simplify eq_uri env new' ?passive active =
+let backward_simplify eq_uri env new' active =
let new_pos, new_table, min_weight = build_table new' in
-(*
- List.fold_left
- (fun (l, t, w) e ->
- let ew, _, _, _ , _ = Equality.open_equality e in
- e::l, Indexing.index t e, min ew w)
- ([], Indexing.empty, 1000000) new'
- in
-*)
let active, newa, pruned =
backward_simplify_active eq_uri env new_pos new_table min_weight active
in
- match passive with
- | None ->
- active, (make_passive []), newa, None, pruned
- | Some passive ->
- active, passive, newa, None, pruned
-(* prova
- let passive, newp =
- backward_simplify_passive env new_pos new_table min_weight passive in
- active, passive, newa, newp *)
+ active, newa, None, pruned
;;
let close eq_uri env new' given =
let pl, passive_table =
match passive with
| None -> [], None
- | Some ((pn, _), (pp, _), pt) ->
- let pn = List.map (fun e -> (Utils.Negative, e)) pn
- and pp = List.map (fun e -> (Utils.Positive, e)) pp in
- pn @ pp, Some pt
+ | Some ((pn, _), (pp, _), pt) -> pn @ pp, Some pt
in
let a_theorems, p_theorems = theorems in
let demodulate table theorem =
(fun t e -> Indexing.index t e)
Indexing.empty active
in
- let res = forward_simplify eq_uri env (Utils.Positive,e) (active, tbl) in
+ let res = forward_simplify eq_uri env e (active, tbl) in
match others with
| hd::tl -> (
match res with
| (Some p) as ok -> ok
;;
-let simplify_goal_set env goals ?passive active =
+let simplify_goal_set env goals active =
let active_goals, passive_goals = goals in
let find (_,_,g) where =
List.exists (fun (_,_,g1) -> Equality.meta_convertibility g g1) where
in
List.fold_left
(fun (acc_a,acc_p) goal ->
- match simplify_goal env goal ?passive active with
+ match simplify_goal env goal active with
| changed, g ->
if changed then
if find g acc_p then acc_a,acc_p else acc_a,g::acc_p
aux passive_goals
;;
-(* old
-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_passive_goals =
- if CicUtil.is_meta_closed t1 then
- passive_goals
- else
- let new' = Indexing.superposition_left env (snd active) selected in
- passive_goals @ new'
- in
- selected::active_goals, new_passive_goals
- | _::tl -> aux tl
- in
- aux passive_goals
-;;
-*)
-
let infer_goal_set_with_current env current goals active =
let active_goals, passive_goals =
simplify_goal_set env goals active
int_of_float iterations_left
in
let rec step goals theorems passive active iterno =
+ pp_goals "xxx" goals context;
if iterno > max_iterations then
(ParamodulationFailure "No more iterations to spend")
else if Unix.gettimeofday () > max_time then
if iterno mod 40 = 0 then
begin
let active = List.map Equality.id_of (fst active) in
- let passive = List.map Equality.id_of (fst (fst passive)) in
+ let passive = List.map Equality.id_of (fst passive) in
let goal = ids_of_goal_set goals in
Equality.collect active passive goal
end;
("Selected : " ^
Equality.string_of_equality ~env current);
let res =
- forward_simplify eq_uri env (Utils.Positive, current) active
+ forward_simplify eq_uri env current active
in
match res with
| None -> step goals theorems passive active (iterno+1)
prerr_endline "fwd/back simpl";
let rec simplify new' active passive head =
let new' =
- forward_simplify_new eq_uri env new' ~passive active
+ forward_simplify_new eq_uri env new' active
in
- let active, passive, newa, retained, pruned =
- backward_simplify eq_uri env new' ~passive active
+ let active, newa, retained, pruned =
+ backward_simplify eq_uri env new' active
in
let passive =
List.fold_left filter_dependent passive pruned
let goals =
let a,b,_ = build_table new' in
let _ = <:start<simplify_goal_set new>> in
- let rc = simplify_goal_set env goals ~passive (a,b) in
+ let rc = simplify_goal_set env goals (a,b) in
let _ = <:stop<simplify_goal_set new>> in
rc
in
(active, passive)
else
let current, passive = select env ([goal],[]) passive in
- let res = forward_simplify eq_uri env (Utils.Positive, current) ~passive active in
+ let res = forward_simplify eq_uri env current active in
match res with
| None ->
saturate_equations eq_uri env goal accept_fun passive active
(* alla fine new' contiene anche le attive semplificate!
* quindi le aggiungo alle passive insieme alle new *)
let rec simplify new' active passive =
- let new' = forward_simplify_new eq_uri env new' ~passive active in
- let active, passive, newa, retained, pruned =
- backward_simplify eq_uri env new' ~passive active in
+ let new' = forward_simplify_new eq_uri env new' active in
+ let active, newa, retained, pruned =
+ backward_simplify eq_uri env new' active in
let passive =
List.fold_left filter_dependent passive pruned in
match newa, retained with
saturate_equations eq_uri env goal accept_fun passive active
;;
-let main dbd full term metasenv ugraph = ()
-(*
-let main dbd full term metasenv ugraph =
- let module C = Cic in
- let module T = CicTypeChecker in
- let module PET = ProofEngineTypes in
- let module PP = CicPp in
- let proof = None, (1, [], term)::metasenv, C.Meta (1, []), term in
- let status = PET.apply_tactic (PrimitiveTactics.intros_tac ()) (proof, 1) in
- let proof, goals = status in
- let goal' = List.nth goals 0 in
- let _, metasenv, meta_proof, _ = proof in
- let _, context, goal = CicUtil.lookup_meta goal' metasenv in
- let eq_indexes, equalities, maxm = Inference.find_equalities context proof in
- let lib_eq_uris, library_equalities, maxm =
-
- Inference.find_library_equalities dbd context (proof, goal') (maxm+2)
- in
- let library_equalities = List.map snd library_equalities in
- maxmeta := maxm+2; (* TODO ugly!! *)
- let irl = CicMkImplicit.identity_relocation_list_for_metavariable context in
- let new_meta_goal, metasenv, type_of_goal =
- let _, context, ty = CicUtil.lookup_meta goal' metasenv in
- Utils.debug_print
- (lazy
- (Printf.sprintf "\n\nTIPO DEL GOAL: %s\n\n" (CicPp.ppterm ty)));
- Cic.Meta (maxm+1, irl),
- (maxm+1, context, ty)::metasenv,
- ty
- in
- let env = (metasenv, context, ugraph) in
- let t1 = Unix.gettimeofday () in
- let theorems =
- if full then
- let theorems = Inference.find_library_theorems dbd env (proof, goal') lib_eq_uris in
- let context_hyp = Inference.find_context_hypotheses env eq_indexes in
- context_hyp @ theorems, []
- else
- let refl_equal =
- let us = UriManager.string_of_uri (LibraryObjects.eq_URI ()) in
- UriManager.uri_of_string (us ^ "#xpointer(1/1/1)")
- in
- let t = CicUtil.term_of_uri refl_equal in
- let ty, _ = CicTypeChecker.type_of_aux' [] [] t CicUniv.empty_ugraph in
- [(t, ty, [])], []
- in
- let t2 = Unix.gettimeofday () in
- Utils.debug_print
- (lazy
- (Printf.sprintf "Time to retrieve theorems: %.9f\n" (t2 -. t1)));
- let _ =
- Utils.debug_print
- (lazy
- (Printf.sprintf
- "Theorems:\n-------------------------------------\n%s\n"
- (String.concat "\n"
- (List.map
- (fun (t, ty, _) ->
- Printf.sprintf
- "Term: %s, type: %s" (CicPp.ppterm t) (CicPp.ppterm ty))
- (fst theorems)))))
- in
- (*try*)
- let goal =
- ([],Equality.BasicProof (Equality.empty_subst ,new_meta_goal)), [], goal
- in
- let equalities = simplify_equalities env
- (equalities@library_equalities) in
- let active = make_active () in
- let passive = make_passive equalities in
- Printf.printf "\ncurrent goal: %s\n"
- (let _, _, g = goal in CicPp.ppterm g);
- Printf.printf "\ncontext:\n%s\n" (PP.ppcontext context);
- Printf.printf "\nmetasenv:\n%s\n" (Utils.print_metasenv metasenv);
- Printf.printf "\nequalities:\n%s\n"
- (String.concat "\n"
- (List.map
- (Equality.string_of_equality ~env) equalities));
-(* (equalities @ library_equalities))); *)
- print_endline "--------------------------------------------------";
- let start = Unix.gettimeofday () in
- print_endline "GO!";
- start_time := Unix.gettimeofday ();
- let res =
- let goals = make_goals goal in
- (if !use_fullred then given_clause_fullred else given_clause_fullred)
- dbd env goals theorems passive active
- in
- let finish = Unix.gettimeofday () in
- let _ =
- match res with
- | ParamodulationFailure ->
- Printf.printf "NO proof found! :-(\n\n"
- | ParamodulationSuccess (Some ((cicproof,cicmenv),(proof, env))) ->
- Printf.printf "OK, found a proof!\n";
- let oldproof = Equation.build_proof_term proof in
- let newproof,_,newenv,_ =
- CicRefine.type_of_aux'
- cicmenv context cicproof CicUniv.empty_ugraph
- in
- (* REMEMBER: we have to instantiate meta_proof, we should use
- apply the "apply" tactic to proof and status
- *)
- let names = Utils.names_of_context context in
- prerr_endline "OLD PROOF";
- print_endline (PP.pp proof names);
- prerr_endline "NEW PROOF";
- print_endline (PP.pp newproof names);
- let newmetasenv =
- List.fold_left
- (fun m eq ->
- let (_, _, _, menv,_) = Equality.open_equality eq in
- m @ menv)
- metasenv equalities
- in
- let _ =
- (*try*)
- let ty, ug =
- CicTypeChecker.type_of_aux' newmetasenv context proof ugraph
- in
- print_endline (string_of_float (finish -. start));
- Printf.printf
- "\nGOAL was: %s\nPROOF has type: %s\nconvertible?: %s\n\n"
- (CicPp.pp type_of_goal names) (CicPp.pp ty names)
- (string_of_bool
- (fst (CicReduction.are_convertible
- context type_of_goal ty ug)));
- (*with e ->
- Printf.printf "\nEXCEPTION!!! %s\n" (Printexc.to_string e);
- Printf.printf "MAXMETA USED: %d\n" !maxmeta;
- print_endline (string_of_float (finish -. start));*)
- in
- ()
-
- | ParamodulationSuccess None ->
- Printf.printf "Success, but no proof?!?\n\n"
- in
- if Utils.time then
- begin
- prerr_endline
- ((Printf.sprintf ("infer_time: %.9f\nforward_simpl_time: %.9f\n" ^^
- "forward_simpl_new_time: %.9f\n" ^^
- "backward_simpl_time: %.9f\n")
- !infer_time !forward_simpl_time !forward_simpl_new_time
- !backward_simpl_time) ^
- (Printf.sprintf "passive_maintainance_time: %.9f\n"
- !passive_maintainance_time) ^
- (Printf.sprintf " successful unification/matching time: %.9f\n"
- !Indexing.match_unif_time_ok) ^
- (Printf.sprintf " failed unification/matching time: %.9f\n"
- !Indexing.match_unif_time_no) ^
- (Printf.sprintf " indexing retrieval time: %.9f\n"
- !Indexing.indexing_retrieval_time) ^
- (Printf.sprintf " demodulate_term.build_newtarget_time: %.9f\n"
- !Indexing.build_newtarget_time) ^
- (Printf.sprintf "derived %d clauses, kept %d clauses.\n"
- !derived_clauses !kept_clauses))
- end
-(*
- with exc ->
- print_endline ("EXCEPTION: " ^ (Printexc.to_string exc));
- raise exc
-*)
-;;
-*)
-
let default_depth = !maxdepth
and default_width = !maxwidth;;
let initial = Equality.add_subst subsumption_subst newproof in
Equality.build_goal_proof
eq_uri goalproof initial type_of_goal side_effects
+ context proof_menv
in
prerr_endline ("PROOF: " ^ CicPp.pp goal_proof names);
let goal_proof = Subst.apply_subst subsumption_subst goal_proof in
(Cic.Meta(i,irl)) ::acc3,Some (Cic.Meta(i,irl)))
([],[],[],None)
(List.filter
- (fun (i,_,_) -> List.mem i metas_still_open_in_proof)
- proof_menv)
+ (fun (i,_,_) -> List.mem i metas_still_open_in_proof)
+ proof_menv)
in
let replace where =
(* we need this fake equality since the metas of the hypothesis may be
proof, open_goals
;;
+let main _ _ _ _ _ = () ;;
+
let retrieve_and_print dbd term metasenv ugraph =
let module C = Cic in
let module T = CicTypeChecker in
Utils.debug_print (lazy "RETR: SIMPLYFYING EQUALITIES...");
let rec simpl e others others_simpl =
let (u, e) = e in
- let active = List.map (fun (u, e) -> (Utils.Positive, e))
- (others @ others_simpl) in
+ let active = (others @ others_simpl) in
let tbl =
List.fold_left
(fun t (_, e) -> Indexing.index t e)
Indexing.empty active
in
- let res = forward_simplify eq_uri env (Utils.Positive, e) (active, tbl) in
+ let res = forward_simplify eq_uri env e (active, tbl) in
match others with
| hd::tl -> (
match res with
let passive =
match rp with
- | (p, _), _ ->
+ | p, _ ->
EqualitySet.elements (List.fold_left addfun EqualitySet.empty p)
in
let active =
begin
let opengoal = Equality.Exact (Cic.Meta(maxm,irl)) in
let proofterm,_ =
- Equality.build_goal_proof eq_uri newproof opengoal ty []
+ Equality.build_goal_proof
+ eq_uri newproof opengoal ty [] context metasenv
in
let extended_metasenv = (maxm,context,newty)::metasenv in
let extended_status =
List.fold_left
(fun (maxm,acc) e ->
let maxm,eq =
- Indexing.demodulation_equality
- eq_uri maxm env table Utils.Positive e
+ Indexing.demodulation_equality eq_uri maxm env table e
in
maxm,eq::acc)
(maxm,[]) eql