]> matita.cs.unibo.it Git - helm.git/blob - components/tactics/discriminationTactics.ml
Bug fixed in injection: a missing lift bugged the tactic when the constructor
[helm.git] / components / tactics / discriminationTactics.ml
1 (* Copyright (C) 2002, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (* $Id$ *)
27
28 let debug_print = fun _ -> ()
29
30 let rec injection_tac ~term =
31  let injection_tac ~term status = 
32   let (proof, goal) = status in
33   let module C = Cic in
34   let module U = UriManager in
35   let module P = PrimitiveTactics in
36   let module T = Tacticals in
37   let _,metasenv,_,_ = proof in
38   let _,context,_ = CicUtil.lookup_meta goal metasenv in
39   let termty,_ = (* TASSI: FIXME *)
40     CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph
41   in
42     ProofEngineTypes.apply_tactic
43       (match termty with
44           (C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2])
45              when LibraryObjects.is_eq_URI equri -> (
46            match tty with
47               (C.MutInd (turi,typeno,exp_named_subst))
48             | (C.Appl (C.MutInd (turi,typeno,exp_named_subst)::_)) -> (
49                    match t1,t2 with
50                       ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
51                        (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
52                          when (uri1 = uri2) && (typeno1 = typeno2) && 
53                               (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) ->
54                        (* raise (ProofEngineTypes.Fail "Injection: nothing to do") ; *) T.id_tac
55                     | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::applist1)),
56                        (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::applist2)))
57                          when (uri1 = uri2) && (typeno1 = typeno2) && (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) ->
58                        let rec traverse_list i l1 l2 =
59                          match l1,l2 with
60                             [],[] -> T.id_tac
61                           | hd1::tl1,hd2::tl2 -> 
62                              T.then_ 
63                               ~start:
64                                 (injection1_tac ~i
65                                   ~term:(CicSubstitution.lift (i-1) term))
66                               ~continuation:(traverse_list (i+1) tl1 tl2)
67                           | _ -> raise (ProofEngineTypes.Fail (lazy "Discriminate: i 2 termini hanno in testa lo stesso costruttore, ma applicato a un numero diverso di termini. possibile???"))
68                        in traverse_list 1 applist1 applist2
69                     | ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
70                        (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
71                     | ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
72                        (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::_)))
73                     | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::_)),
74                        (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
75                     | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::_)),
76                        (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::_)))
77                          when (consno1 <> consno2) || (exp_named_subst1 <> exp_named_subst2) ->
78                        (* raise (ProofEngineTypes.Fail "Injection: not a projectable equality but a discriminable one") ; *) T.id_tac
79                     | _ -> (* raise (ProofEngineTypes.Fail "Injection: not a projectable equality") ; *) T.id_tac
80                    )
81             | _ -> raise (ProofEngineTypes.Fail (lazy "Injection: not a projectable equality"))
82            )
83         | _ -> raise (ProofEngineTypes.Fail (lazy "Injection: not an equation"))
84       ) status
85  in 
86   ProofEngineTypes.mk_tactic (injection_tac ~term)
87
88 and injection1_tac ~term ~i = 
89  let injection1_tac ~term ~i status =
90   let (proof, goal) = status in
91   (* precondizione: t1 e t2 hanno in testa lo stesso costruttore ma differiscono (o potrebbero differire?) nell'i-esimo parametro del costruttore *)
92    let module C = Cic in
93    let module S = CicSubstitution in
94    let module U = UriManager in
95    let module P = PrimitiveTactics in
96    let module T = Tacticals in
97    let _,metasenv,_,_ = proof in
98    let _,context,_ = CicUtil.lookup_meta goal metasenv in
99    let termty,_ = (* TASSI: FIXME *)
100      CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph in
101      match termty with (* an equality *)
102          (C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2])
103              when LibraryObjects.is_eq_URI equri -> (
104            match tty with (* some inductive type *)
105               (C.MutInd (turi,typeno,exp_named_subst))
106             | (C.Appl (C.MutInd (turi,typeno,exp_named_subst)::_)) ->
107                let t1',t2',consno = (* sono i due sottotermini che differiscono *)
108                 match t1,t2 with
109                    ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::applist1)),
110                     (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::applist2)))
111                       when (uri1 = uri2) && (typeno1 = typeno2) && (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) -> (* controllo ridondante *)
112                     (List.nth applist1 (i-1)),(List.nth applist2 (i-1)),consno2
113                  | _ -> assert false
114                in
115                 let tty',_ = 
116                   CicTypeChecker.type_of_aux' metasenv context t1' 
117                     CicUniv.empty_ugraph  in
118                 let pattern =
119                       match fst(CicEnvironment.get_obj 
120                                   CicUniv.empty_ugraph turi ) with
121                          C.InductiveDefinition (ind_type_list,_,nr_ind_params_dx,_)  ->
122                           let _,_,_,constructor_list = (List.nth ind_type_list typeno) in
123                            let i_constr_id,_ = List.nth constructor_list (consno - 1) in
124                             List.map
125                              (function (id,cty) ->
126                                let reduced_cty = CicReduction.whd context cty in
127                                 let rec aux t k =
128                                  match t with
129                                     C.Prod (_,_,target) when (k <= nr_ind_params_dx) ->
130                                      aux target (k+1)
131                                   | C.Prod (binder,source,target) when (k > nr_ind_params_dx) ->
132                                     let binder' =
133                                       match binder with
134                                          C.Name b -> C.Name b
135                                        | C.Anonymous -> C.Name "y"
136                                      in
137                                       C.Lambda (binder',source,(aux target (k+1)))
138                                   | _ ->
139                                      let nr_param_constr = k - 1 - nr_ind_params_dx in
140                                       if (id = i_constr_id)
141                                        then C.Rel (nr_param_constr - i + 1)
142                                        else S.lift (nr_param_constr + 1) t1' (* + 1 per liftare anche il lambda agguinto esternamente al case *)
143                                 in aux reduced_cty 1
144                              )
145                              constructor_list
146                        | _ -> raise (ProofEngineTypes.Fail (lazy "Discriminate: object is not an Inductive Definition: it's imposible"))
147                 in
148                 ProofEngineTypes.apply_tactic   
149                  (T.thens 
150                   ~start:(P.cut_tac (C.Appl [(C.MutInd (equri,0,[])) ; tty' ; t1' ; t2']))
151                   ~continuations:[
152                     T.then_ 
153                      ~start:(injection_tac ~term:(C.Rel 1))
154                      ~continuation:T.id_tac (* !!! qui devo anche fare clear di term tranne al primo passaggio *) 
155                     ;
156                     T.then_ 
157                      ~start:(ProofEngineTypes.mk_tactic 
158                        (fun status ->    
159                          let (proof, goal) = status in
160                          let _,metasenv,_,_ = proof in
161                           let _,context,gty = CicUtil.lookup_meta goal metasenv in
162                            let new_t1' = 
163                             match gty with 
164                                (C.Appl (C.MutInd (_,_,_)::arglist)) -> 
165                                 List.nth arglist 1
166                              | _ -> raise (ProofEngineTypes.Fail (lazy "Injection: goal after cut is not correct"))
167                            in
168                             ProofEngineTypes.apply_tactic 
169                             (ReductionTactics.change_tac
170                                ~pattern:(ProofEngineTypes.conclusion_pattern
171                                 (Some new_t1'))
172                                (fun _ m u ->
173                                  C.Appl [ C.Lambda (C.Name "x", tty,
174                                   C.MutCase (turi, typeno,
175                                    (C.Lambda ((C.Name "x"),
176                                     (S.lift 1 tty),
177                                     (S.lift 2 tty'))),
178                                    (C.Rel 1), pattern
179                                   )
180                                  );
181                                  t1], m, u))
182                         status
183                        ))
184                      ~continuation:
185                        (T.then_
186                          ~start:
187                            (EqualityTactics.rewrite_simpl_tac
188                              ~direction:`LeftToRight
189                              ~pattern:(ProofEngineTypes.conclusion_pattern None)
190                              term)
191                          ~continuation:EqualityTactics.reflexivity_tac
192                        )
193                    ])     
194                   status
195             | _ -> raise (ProofEngineTypes.Fail (lazy "Discriminate: not a discriminable equality"))
196            )
197         | _ -> raise (ProofEngineTypes.Fail (lazy "Discriminate: not an equality"))
198  in
199   ProofEngineTypes.mk_tactic (injection1_tac ~term ~i)
200 ;;
201
202 exception TwoDifferentSubtermsFound of int 
203
204 (* term ha tipo t1=t2; funziona solo se t1 e t2 hanno in testa costruttori
205 diversi *)
206
207 let discriminate'_tac ~term =
208  let module C = Cic in
209  let module U = UriManager in
210  let module P = PrimitiveTactics in
211  let module T = Tacticals in
212  let true_URI =
213   match LibraryObjects.true_URI () with
214      Some uri -> uri
215    | None -> raise (ProofEngineTypes.Fail (lazy "You need to register the default \"true\" definition first. Please use the \"default\" command")) in
216  let false_URI =
217   match LibraryObjects.false_URI () with
218      Some uri -> uri
219    | None -> raise (ProofEngineTypes.Fail (lazy "You need to register the default \"false\" definition first. Please use the \"default\" command")) in
220  let fail msg = raise (ProofEngineTypes.Fail (lazy ("Discriminate: " ^ msg))) in
221  let find_discriminating_consno t1 t2 =
222    let rec aux t1 t2 =
223      match t1, t2 with
224      | C.MutConstruct _, C.MutConstruct _ when t1 = t2 -> None
225      | C.Appl ((C.MutConstruct _ as constr1) :: args1),
226        C.Appl ((C.MutConstruct _ as constr2) :: args2)
227        when constr1 = constr2 ->
228          let rec aux_list l1 l2 =
229            match l1, l2 with
230            | [], [] -> None
231            | hd1 :: tl1, hd2 :: tl2 ->
232                (match aux hd1 hd2 with
233                | None -> aux_list tl1 tl2
234                | Some _ as res -> res)
235            | _ -> (* same constructor applied to a different number of args *)
236                assert false
237          in
238          aux_list args1 args2
239      | ((C.MutConstruct (_,_,consno1,subst1)),
240        (C.MutConstruct (_,_,consno2,subst2)))
241      | ((C.MutConstruct (_,_,consno1,subst1)),
242        (C.Appl ((C.MutConstruct (_,_,consno2,subst2)) :: _)))
243      | ((C.Appl ((C.MutConstruct (_,_,consno1,subst1)) :: _)),
244        (C.MutConstruct (_,_,consno2,subst2)))
245      | ((C.Appl ((C.MutConstruct (_,_,consno1,subst1)) :: _)),
246        (C.Appl ((C.MutConstruct (_,_,consno2,subst2)) :: _)))
247        when (consno1 <> consno2) || (subst1 <> subst2) ->
248          Some consno2
249      | _ -> fail "not a discriminable equality"
250    in
251    aux t1 t2
252  in
253  let mk_pattern turi typeno consno context left_args =
254     (* a list of "True" except for the element in position consno which
255      * is "False" *)
256     match fst (CicEnvironment.get_obj CicUniv.empty_ugraph turi) with
257     | C.InductiveDefinition (ind_type_list,_,nr_ind_params,_)  ->
258         let _,_,_,constructor_list = List.nth ind_type_list typeno in 
259         let false_constr_id,_ = List.nth constructor_list (consno - 1) in
260         List.map 
261           (fun (id,cty) ->
262             (* dubbio: e' corretto ridurre in questo context ??? *)
263             let red_ty = CicReduction.whd context cty in
264             let rec aux t k =
265               match t with
266               | C.Prod (_,_,target) when (k <= nr_ind_params) ->
267                   CicSubstitution.subst (List.nth left_args (k-1))
268                     (aux target (k+1))
269               | C.Prod (binder,source,target) when (k > nr_ind_params) ->
270                   C.Lambda (binder, source, (aux target (k+1)))
271               | _ -> 
272                   if (id = false_constr_id)
273                   then (C.MutInd(false_URI,0,[]))
274                   else (C.MutInd(true_URI,0,[]))
275             in
276             (CicSubstitution.lift 1 (aux red_ty 1)))
277           constructor_list
278     | _ -> (* object is not an inductive definition *)
279         assert false
280  in
281  let discriminate'_tac ~term status = 
282   let (proof, goal) = status in
283   let _,metasenv,_,_ = proof in
284   let _,context,_ = CicUtil.lookup_meta goal metasenv in
285   let termty,_ = 
286     CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph
287   in
288   match termty with
289   | (C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2])
290     when LibraryObjects.is_eq_URI equri ->
291       let turi,typeno,exp_named_subst,left_args = 
292         match tty with
293         | (C.MutInd (turi,typeno,exp_named_subst)) ->
294             turi,typeno,exp_named_subst,[]
295         | (C.Appl (C.MutInd (turi,typeno,exp_named_subst)::left_args)) ->
296             turi,typeno,exp_named_subst,left_args
297         | _ -> fail "not a discriminable equality"
298       in
299       let consno =
300         match find_discriminating_consno t1 t2 with
301         | Some consno -> consno
302         | None -> fail "discriminating terms are structurally equal"
303       in
304       let pattern = mk_pattern turi typeno consno context left_args in
305       let (proof',goals') = 
306         ProofEngineTypes.apply_tactic 
307           (EliminationTactics.elim_type_tac
308             (C.MutInd (false_URI, 0, [])))
309           status 
310       in
311       (match goals' with
312       | [goal'] -> 
313           let _,metasenv',_,_ = proof' in
314           let _,context',gty' = CicUtil.lookup_meta goal' metasenv' in
315           ProofEngineTypes.apply_tactic
316             (T.then_
317               ~start:
318                 (ReductionTactics.change_tac 
319                   ~pattern:(ProofEngineTypes.conclusion_pattern (Some gty'))
320                   (fun _ m u ->
321                     C.Appl [
322                       C.Lambda ( C.Name "x", tty,
323                         C.MutCase (turi, typeno,
324                           (C.Lambda ((C.Name "x"),
325                            (CicSubstitution.lift 1 tty),
326                            (C.Sort C.Prop))),
327                           (C.Rel 1), pattern));
328                       t2 ], m, u))
329               ~continuation:
330                 (T.then_
331                   ~start:
332                     (EqualityTactics.rewrite_simpl_tac
333                       ~direction:`RightToLeft
334                       ~pattern:(ProofEngineTypes.conclusion_pattern None)
335                       term)
336                   ~continuation:
337                     (IntroductionTactics.constructor_tac ~n:1)))
338             (proof',goal')
339       | [] -> fail "ElimType False left no goals"
340       | _ -> fail "ElimType False left more than one goal")
341     | _ -> fail "not an equality"
342   in
343   ProofEngineTypes.mk_tactic (discriminate'_tac ~term)
344
345 let discriminate_tac ~term = 
346  let discriminate_tac ~term status =
347   ProofEngineTypes.apply_tactic 
348   (Tacticals.then_
349     ~start:(* (injection_tac ~term) *) Tacticals.id_tac
350     ~continuation:(discriminate'_tac ~term)) (* NOOO!!! non term ma una (qualunque) delle nuove hyp introdotte da inject *)
351    status
352  in
353   ProofEngineTypes.mk_tactic (discriminate_tac ~term)
354
355 (* DISCRIMINTATE SENZA INJECTION 
356
357 exception TwoDifferentSubtermsFound of (Cic.term * Cic.term * int) 
358
359 let discriminate_tac ~term status =
360   let module C = Cic in
361   let module U = UriManager in
362   let module P = PrimitiveTactics in
363   let module T = Tacticals in
364   let (proof, goal) = status in
365    let _,metasenv,_,_ = proof in
366     let _,context,_ = CicUtil.lookup_meta goal metasenv in
367      let termty = (CicTypeChecker.type_of_aux' metasenv context term) in
368       match termty with
369          (C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2]) 
370           when (U.eq equri (U.uri_of_string "cic:/Coq/Init/Logic/eq.ind")) 
371             or (U.eq equri (U.uri_of_string "cic:/Coq/Init/Logic_Type/eqT.ind")) -> (
372            match tty with
373               (C.MutInd (turi,typeno,exp_named_subst))
374             | (C.Appl (C.MutInd (turi,typeno,exp_named_subst)::_)) ->
375
376                 let (t1',t2',consno2') = (* bruuutto: uso un eccezione per terminare con successo! buuu!! :-/ *)
377                  try
378                   let rec traverse t1 t2 =
379 debug_print (lazy ("XXXX t1 " ^ CicPp.ppterm t1)) ;
380 debug_print (lazy ("XXXX t2 " ^ CicPp.ppterm t2)) ;
381                    match t1,t2 with
382                       ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
383                        (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
384                          when (uri1 = uri2) && (typeno1 = typeno2) && (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) ->
385                        t1,t2,0
386                     | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::applist1)),
387                        (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::applist2))) 
388                          when (uri1 = uri2) && (typeno1 = typeno2) && (consno1 = consno2) && (exp_named_subst1 = exp_named_subst2) ->
389                        let rec traverse_list l1 l2 =
390                          match l1,l2 with
391                             [],[] -> t1,t2,0
392                           | hd1::tl1,hd2::tl2 -> traverse hd1 hd2; traverse_list tl1 tl2
393                           | _ -> raise (ProofEngineTypes.Fail "Discriminate: i 2 termini hanno in testa lo stesso costruttore, ma applicato a un numero diverso di termini. possibile???")
394                        in traverse_list applist1 applist2
395
396                     | ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
397                        (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
398                     | ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1)),
399                        (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::_)))
400                     | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::_)),
401                        (C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2)))
402                     | ((C.Appl ((C.MutConstruct (uri1,typeno1,consno1,exp_named_subst1))::_)),
403                        (C.Appl ((C.MutConstruct (uri2,typeno2,consno2,exp_named_subst2))::_)))
404                          when (consno1 <> consno2) || (exp_named_subst1 <> exp_named_subst2) ->
405                        raise (TwoDifferentSubtermsFound (t1,t2,consno2))
406                     | _ -> raise (ProofEngineTypes.Fail "Discriminate: not a discriminable equality")
407                   in traverse t1 t2
408                  with (TwoDifferentSubtermsFound (t1,t2,consno2)) -> (t1,t2,consno2)
409                 in
410 debug_print (lazy ("XXXX consno2' " ^ (string_of_int consno2'))) ;
411                  if consno2' = 0 
412                   then raise (ProofEngineTypes.Fail "Discriminate: Discriminating terms are structurally equal")
413                   else
414
415                    let pattern = 
416                      (* a list of "True" except for the element in position consno2' which is "False" *)
417                      match fst(CicEnvironment.get_obj turi 
418                                  CicUniv.empty_ugraph) with
419                         C.InductiveDefinition (ind_type_list,_,nr_ind_params)  ->
420 debug_print (lazy ("XXXX nth " ^ (string_of_int (List.length ind_type_list)) ^ " " ^ (string_of_int typeno))) ;
421                          let _,_,_,constructor_list = (List.nth ind_type_list typeno) in 
422 debug_print (lazy ("XXXX nth " ^ (string_of_int (List.length constructor_list)) ^ " " ^ (string_of_int consno2'))) ;
423                           let false_constr_id,_ = List.nth constructor_list (consno2' - 1) in
424 debug_print (lazy "XXXX nth funzionano ") ;
425                            List.map 
426                             (function (id,cty) ->
427                               let red_ty = CicReduction.whd context cty in (* dubbio: e' corretto ridurre in questo context ??? *)
428                                let rec aux t k =
429                                 match t with
430                                    C.Prod (_,_,target) when (k <= nr_ind_params) ->
431                                     aux target (k+1)
432                                  | C.Prod (binder,source,target) when (k > nr_ind_params) -> 
433                                     C.Lambda (binder,source,(aux target (k+1)))
434                                  | _ -> 
435                                     if (id = false_constr_id)
436                                      then (C.MutInd (U.uri_of_string "cic:/Coq/Init/Logic/False.ind") 0 [])
437                                      else (C.MutInd (U.uri_of_string "cic:/Coq/Init/Logic/True.ind") 0 [])
438                                in aux red_ty 1
439                             ) 
440                             constructor_list
441                       | _ -> raise (ProofEngineTypes.Fail "Discriminate: object is not an Inductive Definition: it's imposible")
442                    in
443
444                     let (proof',goals') = 
445                      EliminationTactics.elim_type_tac 
446                       ~term:(C.MutInd (U.uri_of_string "cic:/Coq/Init/Logic/False.ind") 0 [] ) 
447                       status 
448                     in
449                      (match goals' with
450                          [goal'] -> 
451                           let _,metasenv',_,_ = proof' in
452                            let _,context',gty' =
453                              CicUtil.lookup_meta goal' metasenv'
454                            in
455                             T.then_
456                              ~start:
457                               (P.change_tac 
458                                ~what:gty' 
459                                ~with_what:
460                                 (C.Appl [
461                                   C.Lambda (
462                                    C.Name "x", tty, 
463                                    C.MutCase (
464                                     turi, typeno,
465                                     (C.Lambda ((C.Name "x"),tty,(C.Sort C.Prop))),
466                                     (C.Rel 1), pattern
467                                    )
468                                   ); 
469                                   t2']
470                                 )
471                               )
472                              ~continuation:
473                               (
474 debug_print (lazy ("XXXX rewrite<-: " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' (C.Appl [(C.MutInd (equri,0,[])) ; tty ; t1' ; t2']))));
475 debug_print (lazy ("XXXX rewrite<-: " ^ CicPp.ppterm (C.Appl [(C.MutInd (equri,0,[])) ; tty ; t1' ; t2']))) ;
476 debug_print (lazy ("XXXX equri: " ^ U.string_of_uri equri)) ;
477 debug_print (lazy ("XXXX tty : " ^ CicPp.ppterm tty)) ;
478 debug_print (lazy ("XXXX tt1': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t1'))) ;
479 debug_print (lazy ("XXXX tt2': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t2'))) ;
480 if (CicTypeChecker.type_of_aux' metasenv' context' t1') <> tty then debug_print (lazy ("XXXX tt1': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t1'))) ;
481 if (CicTypeChecker.type_of_aux' metasenv' context' t2') <> tty then debug_print (lazy ("XXXX tt2': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t2'))) ;
482 if (CicTypeChecker.type_of_aux' metasenv' context' t1') <> (CicTypeChecker.type_of_aux' metasenv' context' t2') 
483  then debug_print (lazy ("XXXX tt1': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux'
484  metasenv' context' t1'))) ; debug_print (lazy ("XXXX tt2': " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' t2'))) ;
485
486                                let termty' = ProofEngineReduction.replace_lifting ~equality:(==) ~what:t1 ~with_what:t1' ~where:termty in
487                                 let termty'' = ProofEngineReduction.replace_lifting ~equality:(==) ~what:t2 ~with_what:t2' ~where:termty' in
488
489 debug_print (lazy ("XXXX rewrite<- " ^ CicPp.ppterm term ^ " : " ^ CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv' context' term)));
490                                  T.then_
491                                    ~start:(EqualityTactics.rewrite_back_simpl_tac ~term:term)
492                                    ~continuation:(IntroductionTactics.constructor_tac ~n:1) 
493                               )
494                              (proof',goal')
495                        | _ -> raise (ProofEngineTypes.Fail "Discriminate: ElimType False left more (or less) than one goal")
496                      )    
497             | _ -> raise (ProofEngineTypes.Fail "Discriminate: not a discriminable equality")
498            )
499        | _ -> raise (ProofEngineTypes.Fail "Discriminate: not an equality")
500 ;;
501
502 *)
503
504
505