X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Ftactics%2FdiscriminationTactics.ml;h=9d83ad595e8af2dfa6712afcfb04b0415f6fb7ae;hb=683978a2627cf1ce15673360f26806593d22f7b5;hp=5a25c00fa95fbf4b2d21a124b3fca2b3dd4df321;hpb=d8b78f30453f93a413ca98c3e858363e9d13e47c;p=helm.git diff --git a/helm/software/components/tactics/discriminationTactics.ml b/helm/software/components/tactics/discriminationTactics.ml index 5a25c00fa..9d83ad595 100644 --- a/helm/software/components/tactics/discriminationTactics.ml +++ b/helm/software/components/tactics/discriminationTactics.ml @@ -25,7 +25,10 @@ (* $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 *) @@ -142,7 +145,7 @@ let discriminate_tac ~term = in let discriminate'_tac ~term status = let (proof, goal) = status in - let _,metasenv,_,_, _ = proof in + let _,metasenv,_subst,_,_, _ = proof in let _,context,_ = CicUtil.lookup_meta goal metasenv in let termty,_ = CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph @@ -220,19 +223,18 @@ let rec injection_tac ~first_time ~term ~liftno ~continuation = 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 injection_tac ~term status = let (proof, goal) = status in - let _,metasenv,_,_, _ = proof in + let _,metasenv,_subst, _,_, _ = proof in let _,context,_ = CicUtil.lookup_meta goal metasenv in let term = CicSubstitution.lift liftno term 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] @@ -322,7 +324,6 @@ and injection1_tac ~term ~i ~liftno ~continuation = 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) @@ -334,12 +335,12 @@ and injection1_tac ~term ~i ~liftno ~continuation = * differiscono (o potrebbero differire?) nell'i-esimo parametro * del costruttore *) let term = CicSubstitution.lift liftno term in - let _,metasenv,_,_, _ = proof in + let _,metasenv,_subst,_,_, _ = proof in let _,context,_ = CicUtil.lookup_meta goal metasenv in 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 -> @@ -405,10 +406,15 @@ and injection1_tac ~term ~i ~liftno ~continuation = | _, _ -> 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 @@ -418,7 +424,7 @@ and injection1_tac ~term ~i ~liftno ~continuation = (* 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 *) @@ -428,7 +434,25 @@ and injection1_tac ~term ~i ~liftno ~continuation = | _ -> 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: @@ -441,9 +465,9 @@ and injection1_tac ~term ~i ~liftno ~continuation = ;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 _,metasenv,_subst,_,_, _ = proof in let _,context,gty =CicUtil.lookup_meta goal metasenv in let gty = Unshare.unshare gty in let new_t1' = @@ -451,25 +475,17 @@ and injection1_tac ~term ~i ~liftno ~continuation = | (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, [], @@ -488,7 +504,7 @@ and injection1_tac ~term ~i ~liftno ~continuation = term []) ~continuation:EqualityTactics.reflexivity_tac) ]) - status + status) | _ -> raise exn_noneq in PET.mk_tactic (injection1_tac ~term ~i)