]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/acic_procedural/proceduralConversion.ml
Procedural : added some missing cases
[helm.git] / helm / software / components / acic_procedural / proceduralConversion.ml
index 68b47341c05caff79f8972eb645c16c8fef30d73..324141af46b0783c535ab07eab7720dbdb801663 100644 (file)
@@ -30,6 +30,8 @@ module TC   = CicTypeChecker
 module D    = Deannotate
 module UM   = UriManager
 module Rd   = CicReduction
+module PEH  = ProofEngineHelpers
+module PT   = PrimitiveTactics
 
 module DTI  = DoubleTypeInference
 
@@ -70,12 +72,52 @@ let lift k n =
       | C.AMutCase (id, sp, i, outty, t, pl) -> C.AMutCase (id, sp, i, lift_term k outty, lift_term k t, List.map (lift_term k) pl)
       | C.AProd (id, n, s, t) -> C.AProd (id, n, lift_term k s, lift_term (succ k) t)
       | C.ALambda (id, n, s, t) -> C.ALambda (id, n, lift_term k s, lift_term (succ k) t)
-      | C.ALetIn (id, n, s, t) -> C.ALetIn (id, n, lift_term k s, lift_term (succ k) t)
+      | C.ALetIn (id, n, ty, s, t) -> C.ALetIn (id, n, lift_term k s, lift_term k ty, lift_term (succ k) t)
       | C.AFix (id, i, fl) -> C.AFix (id, i, List.map (lift_fix (List.length fl) k) fl)
       | C.ACoFix (id, i, fl) -> C.ACoFix (id, i, List.map (lift_cofix (List.length fl) k) fl)
    in
    lift_term k
 
+   let fake_annotate id c =
+      let get_binder c m =
+         try match List.nth c (pred m) with
+            | Some (C.Name s, _) -> s
+            | _ -> assert false
+         with
+            | Invalid_argument _ -> assert false
+      in
+      let mk_decl n v = Some (n, C.Decl v) in
+      let mk_def n v ty = Some (n, C.Def (v, ty)) in
+      let mk_fix (name, _, ty, bo) = mk_def (C.Name name) bo ty in
+      let mk_cofix (name, ty, bo) = mk_def (C.Name name) bo ty in
+      let rec ann_xns c (uri, t) = uri, ann_term c t
+      and ann_ms c = function
+         | None -> None
+         | Some t -> Some (ann_term c t)
+      and ann_fix newc c (name, i, ty, bo) =
+         id, name, i, ann_term c ty, ann_term (List.rev_append newc c) bo
+      and ann_cofix newc c (name, ty, bo) =
+         id, name, ann_term c ty, ann_term (List.rev_append newc c) bo
+      and ann_term c = function
+         | C.Sort sort -> C.ASort (id, sort)
+         | C.Implicit ann -> C.AImplicit (id, ann)
+         | C.Rel m -> C.ARel (id, id, m, get_binder c m)
+         | C.Const (uri, xnss) -> C.AConst (id, uri, List.map (ann_xns c) xnss)
+         | C.Var (uri, xnss) -> C.AVar (id, uri, List.map (ann_xns c) xnss)
+         | C.MutInd (uri, tyno, xnss) -> C.AMutInd (id, uri, tyno, List.map (ann_xns c) xnss)
+         | C.MutConstruct (uri, tyno, consno, xnss) -> C.AMutConstruct (id, uri,tyno,consno, List.map (ann_xns c) xnss)
+         | C.Meta (i, mss) -> C.AMeta(id, i, List.map (ann_ms c) mss)
+         | C.Appl ts -> C.AAppl (id, List.map (ann_term c) ts)
+         | C.Cast (te, ty) -> C.ACast (id, ann_term c te, ann_term c ty)
+         | C.MutCase (sp, i, outty, t, pl) -> C.AMutCase (id, sp, i, ann_term c outty, ann_term c t, List.map (ann_term c) pl)
+         | C.Prod (n, s, t) -> C.AProd (id, n, ann_term c s, ann_term (mk_decl n s :: c) t)
+         | C.Lambda (n, s, t) -> C.ALambda (id, n, ann_term c s, ann_term (mk_decl n s :: c) t)
+         | C.LetIn (n, s, ty, t) -> C.ALetIn (id, n, ann_term c s, ann_term c ty, ann_term (mk_def n s ty :: c) t)
+         | C.Fix (i, fl) -> C.AFix (id, i, List.map (ann_fix (List.rev_map mk_fix fl) c) fl)
+         | C.CoFix (i, fl) -> C.ACoFix (id, i, List.map (ann_cofix (List.rev_map mk_cofix fl) c) fl)
+      in
+      ann_term c
+
 let clear_absts m =
    let rec aux k n = function
       | C.AImplicit (_, None) as t         -> t
@@ -133,9 +175,9 @@ let generalize n =
       | C.ALambda (id, _, s, t) ->
          let s, t = gen_term k s, gen_term (succ k) t in
          if is_meta [s; t] then meta id else C.ALambda (id, anon, s, t)
-      | C.ALetIn (id, _, s, t) -> 
-         let s, t = gen_term k s, gen_term (succ k) t in
-         if is_meta [s; t] then meta id else C.ALetIn (id, anon, s, t)
+      | C.ALetIn (id, _, s, ty, t) -> 
+         let s, ty, t = gen_term k s, gen_term k ty, gen_term (succ k) t in
+         if is_meta [s; t] then meta id else C.ALetIn (id, anon, s, ty, t)
       | C.AFix (id, i, fl) -> C.AFix (id, i, List.map (gen_fix (List.length fl) k) fl)
       | C.ACoFix (id, i, fl) -> C.ACoFix (id, i, List.map (gen_cofix (List.length fl) k) fl)
    in
@@ -145,44 +187,48 @@ let mk_pattern psno predicate =
    let body = generalize psno predicate in
    clear_absts 0 psno body
 
-let get_clears c p xet = 
+let get_clears c p xtypes = 
    let meta = C.Implicit None in
-   let rec aux c names p et = function
+   let rec aux c names p it et = function
       | []                                                -> 
          List.rev c, List.rev names         
       | Some (C.Name name as n, C.Decl v) as hd :: tl     ->
          let hd, names, v = 
-           if DTI.does_not_occur 1 p && DTI.does_not_occur 1 et then 
+           if DTI.does_not_occur 1 p && DTI.does_not_occur 1 it && DTI.does_not_occur 1 et then 
               Some (C.Anonymous, C.Decl v), name :: names, meta 
            else 
               hd, names, v
         in
         let p = C.Lambda (n, v, p) in
+        let it = C.Prod (n, v, it) in
         let et = C.Prod (n, v, et) in
-        aux (hd :: c) names p et tl
+        aux (hd :: c) names p it et tl
       | Some (C.Name name as n, C.Def (v, x)) as hd :: tl ->
          let hd, names, v = 
-           if DTI.does_not_occur 1 p && DTI.does_not_occur 1 et then 
+           if DTI.does_not_occur 1 p && DTI.does_not_occur 1 it && DTI.does_not_occur 1 et then 
               Some (C.Anonymous, C.Def (v, x)), name :: names, meta
            else 
               hd, names, v
         in
-        let p = C.LetIn (n, v, p) in
-        let et = C.LetIn (n, v, et) in
-        aux (hd :: c) names p et tl
+        let p = C.LetIn (n, v, x, p) in
+        let it = C.LetIn (n, v, x, it) in
+        let et = C.LetIn (n, v, x, et) in
+        aux (hd :: c) names p it et tl
       | Some (C.Anonymous as n, C.Decl v) as hd :: tl     ->
         let p = C.Lambda (n, meta, p) in
+        let it = C.Lambda (n, meta, it) in
         let et = C.Lambda (n, meta, et) in
-        aux (hd :: c) names p et tl
+        aux (hd :: c) names p it et tl
       | Some (C.Anonymous as n, C.Def (v, _)) as hd :: tl ->
-        let p = C.LetIn (n, meta, p) in
-        let et = C.LetIn (n, meta, et) in
-        aux (hd :: c) names p et tl
+        let p = C.LetIn (n, meta, meta, p) in
+        let it = C.LetIn (n, meta, meta, it) in
+        let et = C.LetIn (n, meta, meta, et) in
+        aux (hd :: c) names p it et tl
       | None :: tl                                        -> assert false
    in
-   match xet with 
-      | Some et -> aux [] [] p et c
-      | None    -> c, []
+   match xtypes with 
+      | Some (it, et) -> aux [] [] p it et c
+      | None          -> c, []
 
 let clear c hyp =
    let rec aux c = function
@@ -192,3 +238,14 @@ let clear c hyp =
       | entry :: tail -> aux (entry :: c) tail
    in
    aux [] c
+
+let elim_inferred_type context goal arg using cpattern =
+   let metasenv, ugraph = [], Un.empty_ugraph in 
+   let ety, _ugraph = TC.type_of_aux' metasenv context using ugraph in
+   let _splits, args_no = PEH.split_with_whd (context, ety) in
+   let _metasenv, predicate, _arg, actual_args = PT.mk_predicate_for_elim 
+      ~context ~metasenv ~ugraph ~goal ~arg ~using ~cpattern ~args_no
+   in
+   let ty = C.Appl (predicate :: actual_args) in
+   let upto = List.length actual_args in
+   Rd.head_beta_reduce ~delta:false ~upto ty