1 (* Copyright (C) 2002, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 open HelmLibraryObjects
28 let rec injection_tac ~term =
29 let injection_tac ~term status =
30 let (proof, goal) = status in
32 let module U = UriManager in
33 let module P = PrimitiveTactics in
34 let module T = Tacticals in
35 let _,metasenv,_,_ = proof in
36 let _,context,_ = CicUtil.lookup_meta goal metasenv in
37 let termty = (CicTypeChecker.type_of_aux' metasenv context term) in
38 ProofEngineTypes.apply_tactic
40 (C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2])
41 when (U.eq equri Logic.eq_URI) -> (
43 (C.MutInd (turi,typeno,exp_named_subst))
44 | (C.Appl (C.MutInd (turi,typeno,exp_named_subst)::_)) -> (
46 ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
47 (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
48 when (uri1 = uri2) && (typeno1 = typeno2) &&
49 (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) ->
50 (* raise (ProofEngineTypes.Fail "Injection: nothing to do") ; *) T.id_tac
51 | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::applist1)),
52 (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::applist2)))
53 when (uri1 = uri2) && (typeno1 = typeno2) && (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) ->
54 let rec traverse_list i l1 l2 =
57 | hd1::tl1,hd2::tl2 ->
59 ~start:(injection1_tac ~i ~term)
60 ~continuation:(traverse_list (i+1) tl1 tl2)
61 | _ -> raise (ProofEngineTypes.Fail "Discriminate: i 2 termini hanno in testa lo stesso costruttore, ma applicato a un numero diverso di termini. possibile???") ; T.id_tac
62 in traverse_list 1 applist1 applist2
63 | ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
64 (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
65 | ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
66 (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::_)))
67 | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::_)),
68 (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
69 | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::_)),
70 (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::_)))
71 when (consno1 <> consno2) || (exp_named_subst1 <> exp_named_subst2) ->
72 (* raise (ProofEngineTypes.Fail "Injection: not a projectable equality but a discriminable one") ; *) T.id_tac
73 | _ -> (* raise (ProofEngineTypes.Fail "Injection: not a projectable equality") ; *) T.id_tac
75 | _ -> raise (ProofEngineTypes.Fail "Injection: not a projectable equality")
77 | _ -> raise (ProofEngineTypes.Fail "Injection: not an equation")
80 ProofEngineTypes.mk_tactic (injection_tac ~term)
82 and injection1_tac ~term ~i =
83 let injection1_tac ~term ~i status =
84 let (proof, goal) = status in
85 (* precondizione: t1 e t2 hanno in testa lo stesso costruttore ma differiscono (o potrebbero differire?) nell'i-esimo parametro del costruttore *)
87 let module S = CicSubstitution in
88 let module U = UriManager in
89 let module P = PrimitiveTactics in
90 let module T = Tacticals in
91 let _,metasenv,_,_ = proof in
92 let _,context,_ = CicUtil.lookup_meta goal metasenv in
93 let termty = (CicTypeChecker.type_of_aux' metasenv context term) in
94 match termty with (* an equality *)
95 (C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2])
96 when (U.eq equri Logic.eq_URI) -> (
97 match tty with (* some inductive type *)
98 (C.MutInd (turi,typeno,exp_named_subst))
99 | (C.Appl (C.MutInd (turi,typeno,exp_named_subst)::_)) ->
100 prerr_endline ("XXXX term " ^ CicPp.ppterm term) ;
101 prerr_endline ("XXXX termty " ^ CicPp.ppterm termty) ;
102 prerr_endline ("XXXX t1 " ^ CicPp.ppterm t1) ;
103 prerr_endline ("XXXX t2 " ^ CicPp.ppterm t2) ;
104 prerr_endline ("XXXX tty " ^ CicPp.ppterm tty) ;
105 let t1',t2',consno = (* sono i due sottotermini che differiscono *)
107 ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::applist1)),
108 (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::applist2)))
109 when (uri1 = uri2) && (typeno1 = typeno2) && (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) -> (* controllo ridondante *)
110 (List.nth applist1 (i-1)),(List.nth applist2 (i-1)),consno2
111 | _ -> raise (ProofEngineTypes.Fail "Injection: qui non dovrei capitarci mai")
113 let tty' = (CicTypeChecker.type_of_aux' metasenv context t1') in
114 prerr_endline ("XXXX tty' " ^ CicPp.ppterm tty') ;
115 prerr_endline ("XXXX t1' " ^ CicPp.ppterm t1') ;
116 prerr_endline ("XXXX t2' " ^ CicPp.ppterm t2') ;
117 prerr_endline ("XXXX consno " ^ string_of_int consno) ;
119 match (CicEnvironment.get_obj turi) with
120 C.InductiveDefinition (ind_type_list,_,nr_ind_params_dx) ->
121 let _,_,_,constructor_list = (List.nth ind_type_list typeno) in
122 let i_constr_id,_ = List.nth constructor_list (consno - 1) in
124 (function (id,cty) ->
125 let reduced_cty = CicReduction.whd context cty in
128 C.Prod (_,_,target) when (k <= nr_ind_params_dx) ->
130 | C.Prod (binder,source,target) when (k > nr_ind_params_dx) ->
134 | C.Anonymous -> C.Name "y"
136 C.Lambda (binder',source,(aux target (k+1)))
138 let nr_param_constr = k - 1 - nr_ind_params_dx in
139 if (id = i_constr_id)
140 then C.Rel (nr_param_constr - i + 1)
141 else S.lift (nr_param_constr + 1) t1' (* + 1 per liftare anche il lambda agguinto esternamente al case *)
145 | _ -> raise (ProofEngineTypes.Fail "Discriminate: object is not an Inductive Definition: it's imposible")
147 prerr_endline ("XXXX cominciamo!") ;
148 ProofEngineTypes.apply_tactic
150 ~start:(P.cut_tac (C.Appl [(C.MutInd (equri,0,[])) ; tty' ; t1' ; t2']))
153 ~start:(injection_tac ~term:(C.Rel 1))
154 ~continuation:T.id_tac (* !!! qui devo anche fare clear di term tranne al primo passaggio *)
157 ~start:(ProofEngineTypes.mk_tactic
159 let (proof, goal) = status in
160 let _,metasenv,_,_ = proof in
161 let _,context,gty = CicUtil.lookup_meta goal metasenv in
162 prerr_endline ("XXXX goal " ^ string_of_int goal) ;
163 prerr_endline ("XXXX gty " ^ CicPp.ppterm gty) ;
164 prerr_endline ("XXXX old t1' " ^ CicPp.ppterm t1') ;
165 prerr_endline ("XXXX change " ^ CicPp.ppterm (C.Appl [ C.Lambda (C.Name "x", tty, C.MutCase (turi, typeno, (C.Lambda ((C.Name "x"),(S.lift 1 tty),(S.lift 2 tty'))), (C.Rel 1), pattern)); t1])) ;
168 (C.Appl (C.MutInd (_,_,_)::arglist)) ->
170 | _ -> raise (ProofEngineTypes.Fail "Injection: goal after cut is not correct")
172 prerr_endline ("XXXX new t1' " ^ CicPp.ppterm new_t1') ;
173 ProofEngineTypes.apply_tactic
195 ~start:(EqualityTactics.rewrite_simpl_tac ~term)
196 ~continuation:EqualityTactics.reflexivity_tac
200 | _ -> raise (ProofEngineTypes.Fail "Discriminate: not a discriminable equality")
202 | _ -> raise (ProofEngineTypes.Fail "Discriminate: not an equality")
204 ProofEngineTypes.mk_tactic (injection1_tac ~term ~i)
209 exception TwoDifferentSubtermsFound of int
211 (* term ha tipo t1=t2; funziona solo se t1 e t2 hanno in testa costruttori
214 let discriminate'_tac ~term =
215 let discriminate'_tac ~term status =
216 let (proof, goal) = status in
217 let module C = Cic in
218 let module U = UriManager in
219 let module P = PrimitiveTactics in
220 let module T = Tacticals in
221 let _,metasenv,_,_ = proof in
222 let _,context,_ = CicUtil.lookup_meta goal metasenv in
223 let termty = (CicTypeChecker.type_of_aux' metasenv context term) in
225 (C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2])
226 when (U.eq equri Logic.eq_URI) -> (
228 (C.MutInd (turi,typeno,exp_named_subst))
229 | (C.Appl (C.MutInd (turi,typeno,exp_named_subst)::_)) ->
231 let consno2 = (* bruuutto: uso un eccezione per terminare con successo! buuu!! :-/ *)
233 let rec traverse t1 t2 =
234 prerr_endline ("XXXX t1 " ^ CicPp.ppterm t1) ;
235 prerr_endline ("XXXX t2 " ^ CicPp.ppterm t2) ;
237 ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
238 (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
239 when (uri1 = uri2) && (typeno1 = typeno2) && (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) ->
241 | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::applist1)),
242 (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::applist2)))
243 when (uri1 = uri2) && (typeno1 = typeno2) && (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) ->
244 let rec traverse_list l1 l2 =
247 | hd1::tl1,hd2::tl2 -> traverse hd1 hd2; traverse_list tl1 tl2
248 | _ -> raise (ProofEngineTypes.Fail "Discriminate: i 2 termini hanno in testa lo stesso costruttore, ma applicato a un numero diverso di termini. possibile???")
249 in traverse_list applist1 applist2
251 | ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
252 (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
253 | ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
254 (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::_)))
255 | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::_)),
256 (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
257 | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::_)),
258 (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::_)))
259 when (consno1 <> consno2) || (exp_named_subst1 <> exp_named_subst2) ->
260 raise (TwoDifferentSubtermsFound consno2)
261 | _ -> raise (ProofEngineTypes.Fail "Discriminate: not a discriminable equality")
263 with (TwoDifferentSubtermsFound consno2) -> consno2
265 prerr_endline ("XXXX consno2 " ^ (string_of_int consno2)) ;
267 then raise (ProofEngineTypes.Fail "Discriminate: Discriminating terms are structurally equal")
271 (* a list of "True" except for the element in position consno2 which is "False" *)
272 match (CicEnvironment.get_obj turi) with
273 C.InductiveDefinition (ind_type_list,_,nr_ind_params) ->
274 prerr_endline ("XXXX nth " ^ (string_of_int (List.length ind_type_list)) ^ " " ^ (string_of_int typeno)) ;
275 let _,_,_,constructor_list = (List.nth ind_type_list typeno) in
276 prerr_endline ("XXXX nth " ^ (string_of_int (List.length constructor_list)) ^ " " ^ (string_of_int consno2)) ;
277 let false_constr_id,_ = List.nth constructor_list (consno2 - 1) in
278 prerr_endline ("XXXX nth funzionano ") ;
280 (function (id,cty) ->
281 let red_ty = CicReduction.whd context cty in (* dubbio: e' corretto ridurre in questo context ??? *)
284 C.Prod (_,_,target) when (k <= nr_ind_params) ->
286 | C.Prod (binder,source,target) when (k > nr_ind_params) ->
287 C.Lambda (binder,source,(aux target (k+1)))
289 if (id = false_constr_id)
290 then (C.MutInd(Logic.false_URI,0,[]))
291 else (C.MutInd(Logic.true_URI,0,[]))
295 | _ -> raise (ProofEngineTypes.Fail "Discriminate: object is not an Inductive Definition: it's imposible")
298 let (proof',goals') =
299 ProofEngineTypes.apply_tactic
300 (EliminationTactics.elim_type_tac
301 ~term:(C.MutInd(Logic.false_URI,0,[])))
306 let _,metasenv',_,_ = proof' in
307 let _,context',gty' =
308 CicUtil.lookup_meta goal' metasenv'
310 ProofEngineTypes.apply_tactic
321 (C.Lambda ((C.Name "x"),tty,(C.Sort C.Prop))),
330 prerr_endline ("XXXX rewrite<-: " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' (C.Appl [(C.MutInd (equri,0,[])) ; tty ; t1 ; t2])));
331 prerr_endline ("XXXX rewrite<-: " ^ CicPp.ppterm (C.Appl [(C.MutInd (equri,0,[])) ; tty ; t1 ; t2])) ;
332 prerr_endline ("XXXX equri: " ^ U.string_of_uri equri) ;
333 prerr_endline ("XXXX tty : " ^ CicPp.ppterm tty) ;
334 prerr_endline ("XXXX tt1': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t1)) ;
335 prerr_endline ("XXXX tt2': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t2)) ;
336 if (CicTypeChecker.type_of_aux' metasenv' context' t1) <> tty then prerr_endline ("XXXX tt1': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t1)) ;
337 if (CicTypeChecker.type_of_aux' metasenv' context' t2) <> tty then prerr_endline ("XXXX tt2': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t2)) ;
338 if (CicTypeChecker.type_of_aux' metasenv' context' t1) <> (CicTypeChecker.type_of_aux' metasenv' context' t2)
339 then prerr_endline ("XXXX tt1': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t1)) ; prerr_endline ("XXXX tt2': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t2)) ;
340 prerr_endline ("XXXX rewrite<- " ^ CicPp.ppterm term ^ " : " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' term));
342 ~start:(EqualityTactics.rewrite_back_simpl_tac ~term)
343 ~continuation:(IntroductionTactics.constructor_tac ~n:1)
346 | _ -> raise (ProofEngineTypes.Fail "Discriminate: ElimType False left more (or less) than one goal")
348 | _ -> raise (ProofEngineTypes.Fail "Discriminate: not a discriminable equality")
350 | _ -> raise (ProofEngineTypes.Fail "Discriminate: not an equality")
352 ProofEngineTypes.mk_tactic (discriminate'_tac ~term)
355 let discriminate_tac ~term =
356 let discriminate_tac ~term status =
357 ProofEngineTypes.apply_tactic
359 ~start:(* (injection_tac ~term) *) Tacticals.id_tac
360 ~continuation:(discriminate'_tac ~term)) (* NOOO!!! non term ma una (qualunque) delle nuove hyp introdotte da inject *)
363 ProofEngineTypes.mk_tactic (discriminate_tac ~term)
368 let decide_equality_tac =
369 (* il goal e' un termine della forma t1=t2\/~t1=t2; la tattica decide se l'uguaglianza
370 e' vera o no e lo risolve *)
376 let compare_tac ~term = Tacticals.id_tac
378 (* term is in the form t1=t2; the tactic leaves two goals: in the first you have to *)
379 (* demonstrate the goal with the additional hyp that t1=t2, in the second the hyp is ~t1=t2 *)
380 let module C = Cic in
381 let module U = UriManager in
382 let module P = PrimitiveTactics in
383 let module T = Tacticals in
384 let _,metasenv,_,_ = proof in
385 let _,context,gty = CicUtil.lookup_meta goal metasenv in
386 let termty = (CicTypeChecker.type_of_aux' metasenv context term) in
388 (C.Appl [(C.MutInd (uri, 0, [])); _; t1; t2]) when (uri = (U.uri_of_string "cic:/Coq/Init/Logic/eq.ind")) ->
390 let term' = (* (t1=t2)\/~(t1=t2) *)
392 (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic/or.ind"), 0, [])) ;
395 (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic/eq.ind"), 1, [])) ;
397 C.Appl [C.Const ((U.uri_of_string "cic:/Coq/Init/Logic/not.con"), []) ; t2]
402 ~start:(P.cut_tac ~term:term')
404 T.then_ ~start:(P.intros_tac) ~continuation:(P.elim_intros_simpl_tac ~term:(C.Rel 1)) ;
407 | (C.Appl [(C.MutInd (uri, 0, [])); _; t1; t2]) when (uri = (U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind")) ->
408 let term' = (* (t1=t2) \/ ~(t1=t2) *)
410 (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic/or.ind"), 0, [])) ;
413 (C.MutInd ((U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind"), 1, [])) ;
415 C.Appl [C.Const ((U.uri_of_string "cic:/Coq/Init/Logic/not.con"), []) ; t2]
420 ~start:(P.cut_tac ~term:term')
422 T.then_ ~start:(P.intros_tac) ~continuation:(P.elim_intros_simpl_tac ~term:(C.Rel 1)) ;
425 | _ -> raise (ProofEngineTypes.Fail "Compare: Not an equality")
431 (* DISCRIMINTATE SENZA INJECTION
433 exception TwoDifferentSubtermsFound of (Cic.term * Cic.term * int)
435 let discriminate_tac ~term status =
436 let module C = Cic in
437 let module U = UriManager in
438 let module P = PrimitiveTactics in
439 let module T = Tacticals in
440 let (proof, goal) = status in
441 let _,metasenv,_,_ = proof in
442 let _,context,_ = CicUtil.lookup_meta goal metasenv in
443 let termty = (CicTypeChecker.type_of_aux' metasenv context term) in
445 (C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2])
446 when (U.eq equri (U.uri_of_string "cic:/Coq/Init/Logic/eq.ind"))
447 or (U.eq equri (U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind")) -> (
449 (C.MutInd (turi,typeno,exp_named_subst))
450 | (C.Appl (C.MutInd (turi,typeno,exp_named_subst)::_)) ->
452 let (t1',t2',consno2') = (* bruuutto: uso un eccezione per terminare con successo! buuu!! :-/ *)
454 let rec traverse t1 t2 =
455 prerr_endline ("XXXX t1 " ^ CicPp.ppterm t1) ;
456 prerr_endline ("XXXX t2 " ^ CicPp.ppterm t2) ;
458 ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
459 (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
460 when (uri1 = uri2) && (typeno1 = typeno2) && (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) ->
462 | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::applist1)),
463 (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::applist2)))
464 when (uri1 = uri2) && (typeno1 = typeno2) && (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) ->
465 let rec traverse_list l1 l2 =
468 | hd1::tl1,hd2::tl2 -> traverse hd1 hd2; traverse_list tl1 tl2
469 | _ -> raise (ProofEngineTypes.Fail "Discriminate: i 2 termini hanno in testa lo stesso costruttore, ma applicato a un numero diverso di termini. possibile???")
470 in traverse_list applist1 applist2
472 | ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
473 (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
474 | ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
475 (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::_)))
476 | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::_)),
477 (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
478 | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::_)),
479 (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::_)))
480 when (consno1 <> consno2) || (exp_named_subst1 <> exp_named_subst2) ->
481 raise (TwoDifferentSubtermsFound (t1,t2,consno2))
482 | _ -> raise (ProofEngineTypes.Fail "Discriminate: not a discriminable equality")
484 with (TwoDifferentSubtermsFound (t1,t2,consno2)) -> (t1,t2,consno2)
486 prerr_endline ("XXXX consno2' " ^ (string_of_int consno2')) ;
488 then raise (ProofEngineTypes.Fail "Discriminate: Discriminating terms are structurally equal")
492 (* a list of "True" except for the element in position consno2' which is "False" *)
493 match (CicEnvironment.get_obj turi) with
494 C.InductiveDefinition (ind_type_list,_,nr_ind_params) ->
495 prerr_endline ("XXXX nth " ^ (string_of_int (List.length ind_type_list)) ^ " " ^ (string_of_int typeno)) ;
496 let _,_,_,constructor_list = (List.nth ind_type_list typeno) in
497 prerr_endline ("XXXX nth " ^ (string_of_int (List.length constructor_list)) ^ " " ^ (string_of_int consno2')) ;
498 let false_constr_id,_ = List.nth constructor_list (consno2' - 1) in
499 prerr_endline ("XXXX nth funzionano ") ;
501 (function (id,cty) ->
502 let red_ty = CicReduction.whd context cty in (* dubbio: e' corretto ridurre in questo context ??? *)
505 C.Prod (_,_,target) when (k <= nr_ind_params) ->
507 | C.Prod (binder,source,target) when (k > nr_ind_params) ->
508 C.Lambda (binder,source,(aux target (k+1)))
510 if (id = false_constr_id)
511 then (C.MutInd (U.uri_of_string "cic:/Coq/Init/Logic/False.ind") 0 [])
512 else (C.MutInd (U.uri_of_string "cic:/Coq/Init/Logic/True.ind") 0 [])
516 | _ -> raise (ProofEngineTypes.Fail "Discriminate: object is not an Inductive Definition: it's imposible")
519 let (proof',goals') =
520 EliminationTactics.elim_type_tac
521 ~term:(C.MutInd (U.uri_of_string "cic:/Coq/Init/Logic/False.ind") 0 [] )
526 let _,metasenv',_,_ = proof' in
527 let _,context',gty' =
528 CicUtil.lookup_meta goal' metasenv'
540 (C.Lambda ((C.Name "x"),tty,(C.Sort C.Prop))),
549 prerr_endline ("XXXX rewrite<-: " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' (C.Appl [(C.MutInd (equri,0,[])) ; tty ; t1' ; t2'])));
550 prerr_endline ("XXXX rewrite<-: " ^ CicPp.ppterm (C.Appl [(C.MutInd (equri,0,[])) ; tty ; t1' ; t2'])) ;
551 prerr_endline ("XXXX equri: " ^ U.string_of_uri equri) ;
552 prerr_endline ("XXXX tty : " ^ CicPp.ppterm tty) ;
553 prerr_endline ("XXXX tt1': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t1')) ;
554 prerr_endline ("XXXX tt2': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t2')) ;
555 if (CicTypeChecker.type_of_aux' metasenv' context' t1') <> tty then prerr_endline ("XXXX tt1': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t1')) ;
556 if (CicTypeChecker.type_of_aux' metasenv' context' t2') <> tty then prerr_endline ("XXXX tt2': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t2')) ;
557 if (CicTypeChecker.type_of_aux' metasenv' context' t1') <> (CicTypeChecker.type_of_aux' metasenv' context' t2')
558 then prerr_endline ("XXXX tt1': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t1')) ; prerr_endline ("XXXX tt2': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t2')) ;
560 let termty' = ProofEngineReduction.replace_lifting ~equality:(==) ~what:t1 ~with_what:t1' ~where:termty in
561 let termty'' = ProofEngineReduction.replace_lifting ~equality:(==) ~what:t2 ~with_what:t2' ~where:termty' in
563 prerr_endline ("XXXX rewrite<- " ^ CicPp.ppterm term ^ " : " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' term));
565 ~start:(EqualityTactics.rewrite_back_simpl_tac ~term:term)
566 ~continuation:(IntroductionTactics.constructor_tac ~n:1)
569 | _ -> raise (ProofEngineTypes.Fail "Discriminate: ElimType False left more (or less) than one goal")
571 | _ -> raise (ProofEngineTypes.Fail "Discriminate: not a discriminable equality")
573 | _ -> raise (ProofEngineTypes.Fail "Discriminate: not an equality")