2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
12 (* $Id: orderings.ml 9869 2009-06-11 22:52:38Z denes $ *)
16 OCic2NCic.reference_of_oxuri
17 (UriManager.uri_of_string
18 "cic:/matita/logic/equality/eq.ind#xpointer(1/1)")
25 OCic2NCic.reference_of_oxuri
26 (UriManager.uri_of_string
27 "cic:/matita/logic/equality/eq_ind.con")
34 OCic2NCic.reference_of_oxuri
35 (UriManager.uri_of_string
36 "cic:/matita/logic/equality/eq_elim_r.con")
43 OCic2NCic.reference_of_oxuri
44 (UriManager.uri_of_string
45 "cic:/matita/logic/equality/eq.ind#xpointer(1/1/1)")
50 let extract lift vl t =
51 let rec pos i = function
52 | [] -> raise Not_found
53 | j :: tl when j <> i -> 1+ pos i tl
56 let vl_len = List.length vl in
57 let rec extract = function
58 | Terms.Leaf x -> NCicSubstitution.lift (vl_len+lift) x
60 (try NCic.Rel (pos j vl) with Not_found -> NCic.Implicit `Term)
61 | Terms.Node l -> NCic.Appl (List.map extract l)
66 let mk_predicate hole_type amount ft p1 vl =
75 Pp.Pp(NCicBlob.NCicBlob(
77 let metasenv = [] let subst = [] let context = []
80 prerr_endline ("term: " ^ Pp.pp_foterm ft);
81 prerr_endline ("path: " ^ String.concat ","
82 (List.map string_of_int p1));
83 prerr_endline ("leading to: " ^ Pp.pp_foterm t);
89 if i = n then aux t tl
90 else extract amount (0::vl) t)
95 NCic.Lambda("x", hole_type, aux ft (List.rev p1))
98 let mk_proof (bag : NCic.term Terms.bag) mp steps =
99 let module Subst = FoSubst in
101 let rec aux = function
103 | (j,_) :: tl when i = j -> 1
104 | _ :: tl -> 1 + aux tl
108 let vars_of i l = fst (List.assoc i l) in
109 let ty_of i l = snd (List.assoc i l) in
110 let close_with_lambdas vl t =
113 NCic.Lambda ("x"^string_of_int i, NCic.Implicit `Type, t))
116 let close_with_forall vl t =
119 NCic.Prod ("x"^string_of_int i, NCic.Implicit `Type, t))
123 let (_, lit, vl, proof),_,_ = Terms.get_from_bag id bag in
124 let lit =match lit with
125 | Terms.Predicate t -> assert false
126 | Terms.Equation (l,r,ty,_) ->
127 Terms.Node [ Terms.Leaf eqP(); ty; l; r]
131 let rec aux ongoal seen = function
134 let amount = List.length seen in
135 let lit,vl,proof = get_literal id in
136 if not ongoal && id = mp then
137 ((*prerr_endline ("Reached m point, id=" ^ (string_of_int id));*)
138 NCic.LetIn ("clause_" ^ string_of_int id,
139 extract amount [] lit,
140 (NCic.Appl [eq_refl();NCic.Implicit `Type;NCic.Implicit `Term]),
141 aux true ((id,([],lit))::seen) (id::tl)))
144 | Terms.Exact _ when tl=[] ->
145 (* prerr_endline ("Exact (tl=[]) for " ^ (string_of_int id));*)
147 | Terms.Step _ when tl=[] -> assert false
149 (* prerr_endline ("Exact for " ^ (string_of_int id));*)
150 NCic.LetIn ("clause_" ^ string_of_int id,
151 close_with_forall vl (extract amount vl lit),
152 close_with_lambdas vl (extract amount vl ft),
154 ((id,(List.map (fun x -> Terms.Var x) vl,lit))::seen) tl)
155 | Terms.Step (_, id1, id2, dir, pos, subst) ->
156 let id, id1,(lit,vl,proof) =
157 if ongoal then id1,id,get_literal id1
158 else id,id1,(lit,vl,proof)
160 let vl = if ongoal then [](*Subst.filter subst vl*) else vl in
162 let vars = List.rev (vars_of id seen) in
163 let args = List.map (Subst.apply_subst subst) vars in
164 let args = List.map (extract amount vl) args in
165 let rel_for_id = NCic.Rel (List.length vl + position id seen) in
166 if args = [] then rel_for_id
167 else NCic.Appl (rel_for_id::args)
169 let p_id1 = proof_of_id id1 in
170 let p_id2 = proof_of_id id2 in
171 let pred, hole_type, l, r =
172 let id1_ty = ty_of id1 seen in
174 match ty_of id2 seen with
175 | Terms.Node [ _; t; l; r ] ->
176 extract amount vl (Subst.apply_subst subst t),
177 extract amount vl (Subst.apply_subst subst l),
178 extract amount vl (Subst.apply_subst subst r)
181 (*prerr_endline "mk_predicate :";
182 if ongoal then prerr_endline "ongoal=true"
183 else prerr_endline "ongoal=false";
184 prerr_endline ("id=" ^ string_of_int id);
185 prerr_endline ("id1=" ^ string_of_int id1);
186 prerr_endline ("id2=" ^ string_of_int id2);
187 prerr_endline ("Positions :" ^
189 (List.map string_of_int pos)));*)
191 id2_ty amount (Subst.apply_subst subst id1_ty) pos vl,
196 if (ongoal=true) = (dir=Terms.Left2Right) then
201 NCic.LetIn ("clause_" ^ string_of_int id,
202 close_with_forall vl (extract amount vl lit),
203 (* NCic.Implicit `Type, *)
204 close_with_lambdas vl
205 (NCic.Appl [ eq_ind ; hole_type; l; pred; p_id1; r; p_id2 ]),
207 ((id,(List.map (fun x -> Terms.Var x) vl,lit))::seen) tl)