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 =
74 (* prerr_endline ("term: " ^ ppfot ft); *)
75 prerr_endline ("path: " ^ String.concat ","
76 (List.map string_of_int p1));
82 if i = n then aux t tl
83 else extract amount (0::vl) t)
88 NCic.Lambda("x", hole_type, aux ft (List.rev p1))
91 let mk_proof (bag : NCic.term Terms.bag) mp steps =
92 let module Subst = FoSubst in
94 let rec aux = function
96 | (j,_) :: tl when i = j -> 1
97 | _ :: tl -> 1 + aux tl
101 let vars_of i l = fst (List.assoc i l) in
102 let ty_of i l = snd (List.assoc i l) in
103 let close_with_lambdas vl t =
106 NCic.Lambda ("x"^string_of_int i, NCic.Implicit `Type, t))
109 let close_with_forall vl t =
112 NCic.Prod ("x"^string_of_int i, NCic.Implicit `Type, t))
116 let _, lit, vl, proof = Terms.M.find id bag in
117 let lit =match lit with
118 | Terms.Predicate t -> assert false
119 | Terms.Equation (l,r,ty,_) ->
120 Terms.Node [ Terms.Leaf eqP(); ty; l; r]
124 let rec aux ongoal seen = function
127 let amount = List.length seen in
128 let lit,vl,proof = get_literal id in
129 if not ongoal && id = mp then
130 ((*prerr_endline ("Reached m point, id=" ^ (string_of_int id));*)
131 NCic.LetIn ("clause_" ^ string_of_int id,
132 extract amount [] lit,
133 (NCic.Appl [eq_refl();NCic.Implicit `Type;NCic.Implicit `Term]),
134 aux true ((id,([],lit))::seen) (id::tl)))
137 | Terms.Exact _ when tl=[] ->
138 (* prerr_endline ("Exact (tl=[]) for " ^ (string_of_int id));*)
140 | Terms.Step _ when tl=[] -> assert false
142 (* prerr_endline ("Exact for " ^ (string_of_int id));*)
143 NCic.LetIn ("clause_" ^ string_of_int id,
144 close_with_forall vl (extract amount vl lit),
145 close_with_lambdas vl (extract amount vl ft),
147 ((id,(List.map (fun x -> Terms.Var x) vl,lit))::seen) tl)
148 | Terms.Step (_, id1, id2, dir, pos, subst) ->
149 let id, id1,(lit,vl,proof) =
150 if ongoal then id1,id,get_literal id1
151 else id,id1,(lit,vl,proof)
153 let vl = if ongoal then Subst.filter subst vl else vl in
155 let vars = List.rev (vars_of id seen) in
156 let args = List.map (Subst.apply_subst subst) vars in
157 let args = List.map (extract amount vl) args in
158 let rel_for_id = NCic.Rel (List.length vl + position id seen) in
159 if args = [] then rel_for_id
160 else NCic.Appl (rel_for_id::args)
162 let p_id1 = proof_of_id id1 in
163 let p_id2 = proof_of_id id2 in
164 let pred, hole_type, l, r =
165 let id1_ty = ty_of id1 seen in
167 match ty_of id2 seen with
168 | Terms.Node [ _; t; l; r ] ->
169 extract amount vl (Subst.apply_subst subst t),
170 extract amount vl (Subst.apply_subst subst l),
171 extract amount vl (Subst.apply_subst subst r)
174 (*prerr_endline "mk_predicate :";
175 if ongoal then prerr_endline "ongoal=true"
176 else prerr_endline "ongoal=false";
177 prerr_endline ("id=" ^ string_of_int id);
178 prerr_endline ("id1=" ^ string_of_int id1);
179 prerr_endline ("id2=" ^ string_of_int id2);
180 prerr_endline ("Positions :" ^
182 (List.map string_of_int pos)));*)
184 id2_ty amount (Subst.apply_subst subst id1_ty) pos vl,
189 if (ongoal=true) = (dir=Terms.Left2Right) then
194 NCic.LetIn ("clause_" ^ string_of_int id,
195 close_with_forall vl (extract amount vl lit),
196 (* NCic.Implicit `Type, *)
197 close_with_lambdas vl
198 (NCic.Appl [ eq_ind ; hole_type; l; pred; p_id1; r; p_id2 ]),
200 ((id,(List.map (fun x -> Terms.Var x) vl,lit))::seen) tl)