(* $Id$ *)
-let debug_print = fun _ -> ()
+let debug = false
+let debug_print =
+ if debug then (fun x -> prerr_endline (Lazy.force x)) else (fun _ -> ())
+;;
(* term ha tipo t1=t2; funziona solo se t1 e t2 hanno in testa costruttori
diversi *)
let module T = Tacticals in
let module PST = ProofEngineStructuralRules in
let module PET = ProofEngineTypes in
-(* let prerr_endline s = prerr_endline (String.make liftno ' ' ^ s) in *)
let are_convertible hd1 hd2 metasenv context =
fst (CR.are_convertible ~metasenv context hd1 hd2 CicUniv.empty_ugraph)
in
let termty,_ =
CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph
in
-(* prerr_endline ("\ninjection su: " ^ pp context termty); *)
+ debug_print (lazy ("\ninjection su: " ^ pp context termty));
let tac =
match termty with
| C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2]
let module P = PrimitiveTactics in
let module PET = ProofEngineTypes in
let module T = Tacticals in
-(* let prerr_endline s = prerr_endline (String.make liftno ' ' ^ s) in *)
let give_name seed = function
| C.Name _ as name -> name
| C.Anonymous -> C.Name (incr seed; "y" ^ string_of_int !seed)
let termty,_ =
CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph
in
-(* prerr_endline ("\ninjection1 su : " ^ pp context termty); *)
+ debug_print (lazy ("\ninjection1 su : " ^ pp context termty));
match termty with (* an equality *)
| C.Appl [(C.MutInd (equri, 0, [])) ; tty ; t1 ; t2]
when LibraryObjects.is_eq_URI equri ->
| _, _ -> assert false
in
let abstracted_tty =
- match CicSubstitution.lift paramsno tty with
+ let tty =
+ List.fold_left (fun x y -> CicSubstitution.subst y x) tty left_params
+ in
+ (* non lift, ma subst coi left! *)
+ match S.lift 1 tty with
| C.MutInd _ as tty' -> tty'
| C.Appl l ->
let keep,abstract = HExtlib.split_nth (paramsno +1) l in
+ let keep = List.map (S.lift paramsno) keep in
C.Appl (keep@mk_rels (List.length abstract))
| _ -> assert false
in
(* this is in general wrong, do as in cases_tac *)
to_lambdas (skip_prods left_params ty)
(C.Lambda
- (C.Name "x", abstracted_tty,
+ (C.Name "cased", abstracted_tty,
(* here we should capture right parameters *)
(* 1 for his Lambda, one for the Lambda outside the match
* and then one for each to_lambda *)
| _ -> raise exn_discrnonind
in
let cutted = C.Appl [C.MutInd (equri,0,[]) ; tty' ; t1' ; t2'] in
-(* prerr_endline ("CUT: " ^ pp context cutted); *)
+ let changed =
+ C.Appl [ C.Lambda (C.Name "x", tty,
+ C.MutCase (turi,typeno,outtype,C.Rel 1,patterns)) ; t1]
+ in
+ (* check if cutted and changed are well typed and if t1' ~ changed *)
+ let go_on =
+ try
+ let _,g = CicTypeChecker.type_of_aux' metasenv context cutted
+ CicUniv.empty_ugraph
+ in
+ let _,g = CicTypeChecker.type_of_aux' metasenv context changed g in
+ fst (CicReduction.are_convertible ~metasenv context t1' changed g)
+ with
+ | CicTypeChecker.TypeCheckerFailure _ -> false
+ in
+ if not go_on then
+ PET.apply_tactic Tacticals.id_tac status
+ else
+ (debug_print (lazy ("CUT: " ^ pp context cutted));
PET.apply_tactic
(T.thens ~start: (P.cut_tac cutted)
~continuations:
;T.then_
~start:(PET.mk_tactic
(fun status ->
-(* prerr_endline "riempo il cut"; *)
+ debug_print (lazy "riempo il cut");
let (proof, goal) = status in
let _,metasenv,_,_, _ = proof in
let _,context,gty =CicUtil.lookup_meta goal metasenv in
| (C.Appl (C.MutInd (_,_,_)::_::t::_)) -> t
| _ -> raise exn_injwronggoal
in
- let changed =
- C.Appl [
- C.Lambda (C.Name "x", tty,
- C.MutCase (turi,typeno,outtype,C.Rel 1,patterns))
- ; t1]
- in
-(*
- prerr_endline
- ("metto questo: " ^ pp context changed);
- prerr_endline
- ("al posto di questo: " ^ pp context new_t1');
- prerr_endline
- ("nel goal: " ^ pp context gty);
- prerr_endline
- ("nel contesto:\n" ^ CicPp.ppcontext context);
- prerr_endline
- ("e poi rewrite con: "^pp context term);
-*)
- let rc =
+ debug_print
+ (lazy ("metto questo: " ^ pp context changed));
+ debug_print
+ (lazy ("al posto di questo: " ^ pp context new_t1'));
+ debug_print
+ (lazy ("nel goal: " ^ pp context gty));
+ debug_print
+ (lazy ("nel contesto:\n" ^ CicPp.ppcontext context));
+ debug_print
+ (lazy ("e poi rewrite con: "^pp context term));
+ let rc =
PET.apply_tactic
(ReductionTactics.change_tac
~pattern:(None, [],
term [])
~continuation:EqualityTactics.reflexivity_tac)
])
- status
+ status)
| _ -> raise exn_noneq
in
PET.mk_tactic (injection1_tac ~term ~i)