]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/library/cicElim.ml
weakly/strictly positive checks relaxed to allow metavariables that are not
[helm.git] / helm / software / components / library / cicElim.ml
index aacace7b5614e975d718cb7bf8750683f205b7f2..9f3bda42304490f51701271d8f83e54c27aa675c 100644 (file)
@@ -150,14 +150,20 @@ let rec mk_rels consno = function
   | 0 -> []
   | n -> Cic.Rel (n+consno) :: mk_rels consno (n-1)
 
-let rec strip_pi = function
-  | Cic.Prod (_, _, tgt) -> strip_pi tgt
+let rec strip_pi ctx t = 
+  match CicReduction.whd ~delta:true ctx t with
+  | Cic.Prod (n, s, tgt) -> strip_pi (Some (n,Cic.Decl s) :: ctx) tgt
   | t -> t
 
-let rec count_pi = function
-  | Cic.Prod (_, _, tgt) -> count_pi tgt + 1
+let strip_pi t = strip_pi [] t
+
+let rec count_pi ctx t = 
+  match CicReduction.whd ~delta:true ctx t with
+  | Cic.Prod (n, s, tgt) -> count_pi (Some (n,Cic.Decl s)::ctx) tgt + 1
   | t -> 0
 
+let count_pi t = count_pi [] t
+
 let rec type_of_p sort dependent leftno indty = function
   | Cic.Prod (n, src, tgt) when leftno = 0 ->
       let n =
@@ -424,4 +430,32 @@ debug_print (lazy (CicPp.ppterm eliminator_body));
   | _ ->
       failwith (sprintf "not an inductive definition (%s)"
         (UriManager.string_of_uri uri))
+;;
+
+let generate_elimination_principles ~add_obj ~add_coercion uri obj =
+ match obj with
+  | Cic.InductiveDefinition (indTypes,_,_,attrs) ->
+     let _,inductive,_,_ = List.hd indTypes in
+     if not inductive then []
+     else
+      let _,all_eliminators =
+        List.fold_left
+          (fun (i,res) _ ->
+            let elim sort =
+              try Some (elim_of ~sort uri i)
+              with Can_t_eliminate -> None
+            in
+             i+1,
+              HExtlib.filter_map 
+               elim [ Cic.Prop; Cic.Set; (Cic.Type (CicUniv.fresh ())) ] @ res
+          ) (0,[]) indTypes
+      in
+      List.fold_left
+        (fun lemmas (uri,obj) -> add_obj uri obj @ uri::lemmas) 
+        [] all_eliminators
+  | _ -> []
+;;
+
 
+let init () = 
+  LibrarySync.add_object_declaration_hook generate_elimination_principles;;