]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/tactics/inversion.ml
- Procedural: generation of "exact" is now complete
[helm.git] / helm / software / components / tactics / inversion.ml
index 0ff369a9a6d4b4367cfeec9bce090c386eeeb029..3b4000ea4fb6fa1da810db0d300da3455a401ff3 100644 (file)
@@ -123,7 +123,8 @@ let rec foo_prod nright right_param_tys rightparameters l2 base_rel goalty
      (CicSubstitution.lift 1 termty)
      isSetType (CicSubstitution.lift 1 term))
    | [] -> ProofEngineReduction.replace_lifting 
-    ~equality:(ProofEngineReduction.alpha_equivalence)
+    ~equality:(fun _ -> CicUtil.alpha_equivalence)
+    ~context:[]
     ~what: (if isSetType
      then (rightparameters_ @ [term] ) 
      else (rightparameters_ ) )
@@ -151,7 +152,8 @@ let rec foo_lambda nright right_param_tys nright_ right_param_tys_
    | [] when isSetType -> Cic.Lambda (
     (Cic.Name ("lambda" ^ (string_of_int nright))),
     (ProofEngineReduction.replace_lifting
-     ~equality:(ProofEngineReduction.alpha_equivalence)
+     ~equality:(fun _ -> CicUtil.alpha_equivalence)
+     ~context:[]
      ~what: (rightparameters_ ) 
      ~with_what: (List.map (CicSubstitution.lift (-1)) created_vars)
      ~where:termty), (* type of H with replaced right parameters *)
@@ -171,6 +173,7 @@ let isSetType paramty = ((Pervasives.compare
   (get_sort_type paramty)
   (Cic.Sort Cic.Prop)) != 0) 
 
+exception EqualityNotDefinedYet
 let private_inversion_tac ~term =
  let module T = CicTypeChecker in
  let module R = CicReduction in
@@ -180,12 +183,16 @@ let private_inversion_tac ~term =
  let private_inversion_tac ~term (proof, goal) =
  
  (*DEBUG*) debug_print (lazy  ("private inversion begins"));
- let (_,metasenv,_,_) = proof in
- let uri_of_eq = LibraryObjects.eq_URI () in
+ let _,metasenv,_subst,_,_, _ = proof in
+ let uri_of_eq =
+  match LibraryObjects.eq_URI () with
+     None -> raise EqualityNotDefinedYet
+  | Some uri -> uri
+ in
  let (_,context,goalty) = CicUtil.lookup_meta goal metasenv in
- let termty,_ = T.type_of_aux' metasenv context term CicUniv.empty_ugraph in
+ let termty,_ = T.type_of_aux' metasenv context term CicUniv.oblivion_ugraph in
  let uri = baseuri_of_term termty in  
- let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
+ let o,_ = CicEnvironment.get_obj CicUniv.oblivion_ugraph uri in
  let (_,_,typeno,_) =
   match termty with
    C.MutInd (uri,typeno,exp_named_subst) -> (uri,exp_named_subst,typeno,[])
@@ -208,9 +215,8 @@ let private_inversion_tac ~term =
  let parameters_tys =  
   (List.map 
    (fun t -> (
-    match (T.type_of_aux' metasenv context t CicUniv.empty_ugraph) with
-     (term,graph) -> term
-     |_ -> assert false))
+    match (T.type_of_aux' metasenv context t CicUniv.oblivion_ugraph) with
+     (term,graph) -> term))
    parameters) 
  in
  let consno = List.length cons_list in
@@ -220,7 +226,7 @@ let private_inversion_tac ~term =
   parameters_tys goalty uri_of_eq in
  (*DEBUG*)  debug_print (lazy ("cut term " ^ CicPp.ppterm cut_term));
   debug_print (lazy ("CONTEXT before apply HCUT: " ^ 
-   (CicMetaSubst.ppcontext [] context )));
+   (CicMetaSubst.ppcontext ~metasenv [] context )));
   debug_print (lazy ("termty " ^ CicPp.ppterm termty));
  (* cut DXn=DXn \to GOAL *)
  let proof1,gl1 = PET.apply_tactic (P.cut_tac cut_term) (proof,goal) in
@@ -234,7 +240,7 @@ let private_inversion_tac ~term =
  (*DEBUG*) debug_print (lazy  ("after apply HCUT;reflexivity 
   in private inversion"));
  (* apply (ledx_ind( lambda x. lambda y, ...)) *)
- let (t1,metasenv,t3,t4) = proof2 in
+ let t1,metasenv,_subst,t3,t4, attrs = proof2 in
  let goal2 = List.hd (List.tl gl1) in
  let (_,context,_) = CicUtil.lookup_meta goal2 metasenv in
  (* rightparameters type list *)
@@ -251,21 +257,21 @@ let private_inversion_tac ~term =
  debug_print 
   (lazy ("Right param: " ^ (CicPp.ppterm (Cic.Appl rightparameters))));
  debug_print (lazy ("CONTEXT before refinement: " ^ 
-  (CicMetaSubst.ppcontext [] context )));
+  (CicMetaSubst.ppcontext ~metasenv [] context )));
   (*DEBUG*) debug_print (lazy  ("private inversion: term before refinement: " ^ 
    CicPp.ppterm t));
  let (ref_t,_,metasenv'',_) = CicRefine.type_of_aux' metasenv context t 
-  CicUniv.empty_ugraph 
+  CicUniv.oblivion_ugraph 
  in
  (*DEBUG*) debug_print (lazy  ("private inversion: termine after refinement: "
   ^ CicPp.ppterm ref_t));
- let proof2 = (t1,metasenv'',t3,t4) in
+ let proof2 = (t1,metasenv'',_subst,t3,t4, attrs) in
  let my_apply_tac =
   let my_apply_tac status =
    let proof,goals = 
     ProofEngineTypes.apply_tactic (P.apply_tac ref_t) status in
    let patched_new_goals =
-    let (_,metasenv''',_,_) = proof in
+    let (_,metasenv''',_subst,_,_, _) = proof in
     let new_goals = ProofEngineHelpers.compare_metasenvs
      ~oldmetasenv:metasenv ~newmetasenv:metasenv''
     in
@@ -299,17 +305,20 @@ let inversion_tac ~term =
  let module PET = ProofEngineTypes in
  let inversion_tac ~term (proof, goal) =
  (*DEBUG*) debug_print (lazy ("inversion begins"));
-  let (_,metasenv,_,_) = proof in
+  let _,metasenv,_subst,_,_, _ = proof in
   let (_,context,goalty) = CicUtil.lookup_meta goal metasenv in
-  let termty,_ = T.type_of_aux' metasenv context term CicUniv.empty_ugraph in
-  let uri = baseuri_of_term termty in  
-  let obj,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
+  let termty,_ = T.type_of_aux' metasenv context term CicUniv.oblivion_ugraph in
+  let uri, typeno = 
+    match termty with
+      | Cic.MutInd (uri,typeno,_) 
+      | Cic.Appl(Cic.MutInd (uri,typeno,_)::_) -> uri,typeno
+      | _ -> assert false
+  in
+  (* let uri = baseuri_of_term termty in *)
+  let obj,_ = CicEnvironment.get_obj CicUniv.oblivion_ugraph uri in
   let name,nleft,arity,cons_list =
    match obj with
     Cic.InductiveDefinition (tys,_,nleft,_) ->
-     (*we suppose there is only one inductiveType in the definition, 
-     so typeno=0 identically *)
-     let typeno = 0 in
      let (name,_,arity,cons_list) = List.nth tys typeno in 
         (name,nleft,arity,cons_list)
    |_ -> assert false
@@ -327,19 +336,19 @@ let inversion_tac ~term =
    for n = 1 to arity_consno do
     a := (Cic.Implicit None)::(!a)
    done;
-  (* apply    i_inv             ? ...?      H).     *)
-  Cic.Appl ([Cic.Const(uri,[])] @ !a @ [Cic.Rel 1])
+   (* apply    i_inv             ? ...?      H).     *)
+   Cic.Appl ([Cic.Const(uri,[])] @ !a @ [term])
   in
   let t = appl_term (arity_length + (List.length cons_list)) inversor_uri in
-  let (t1,metasenv,t3,t4) = proof in
+  let (t1,metasenv,_subst,t3,t4, attrs) = proof in
   let (ref_t,_,metasenv'',_) = CicRefine.type_of_aux' metasenv context t
-  CicUniv.empty_ugraph 
+  CicUniv.oblivion_ugraph 
   in
-  let proof = (t1,metasenv'',t3,t4) in
+  let proof = (t1,metasenv'',_subst,t3,t4, attrs) in
   let proof3,gl3 = 
      ProofEngineTypes.apply_tactic (P.apply_tac ref_t) (proof,goal) in
   let patched_new_goals =
-     let (_,metasenv''',_,_) = proof3 in
+     let (_,metasenv''',_subst,_,_, _) = proof3 in
      let new_goals = ProofEngineHelpers.compare_metasenvs
       ~oldmetasenv:metasenv ~newmetasenv:metasenv''
      in