]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/acic_procedural/proceduralConversion.ml
- libraryObjects: new default "natural numbers" with the uri of nat.
[helm.git] / helm / software / components / acic_procedural / proceduralConversion.ml
index b3a247b02c448ca53aa7070a677d8f4574f97ef6..8c9a1ddc6f04b6e6bb37e9bd6156f2cebd18482a 100644 (file)
 module C    = Cic
 module E    = CicEnvironment
 module Un   = CicUniv
-module TC   = CicTypeChecker 
-module D    = Deannotate
+module TC   = CicTypeChecker
 module UM   = UriManager
 module Rd   = CicReduction
 module PEH  = ProofEngineHelpers
 module PT   = PrimitiveTactics
-
 module DTI  = DoubleTypeInference
 
-(* helpers ******************************************************************)
+module H    = ProceduralHelpers
 
-let cic = D.deannotate_term
+(* helpers ******************************************************************)
 
 let rec list_sub start length = function
    | _  :: tl when start  > 0 -> list_sub (pred start) length tl
@@ -61,7 +59,10 @@ let lift k n =
       | C.ARel (id, rid, m, b) as t -> 
          if m < k then t else 
         if m + n > 0 then C.ARel (id, rid, m + n, b) else
-        assert false
+        begin 
+           HLog.error (Printf.sprintf "ProceduralConversion.lift: %i %i" m n);
+           assert false
+        end
       | C.AConst (id, uri, xnss) -> C.AConst (id, uri, List.map (lift_xns k) xnss)
       | C.AVar (id, uri, xnss) -> C.AVar (id, uri, List.map (lift_xns k) xnss)
       | C.AMutInd (id, uri, tyno, xnss) -> C.AMutInd (id, uri, tyno, List.map (lift_xns k) xnss)
@@ -72,7 +73,7 @@ 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, ty, s, t) -> C.ALetIn (id, n, lift_term k s, lift_term k ty, lift_term (succ k) t)
+      | C.ALetIn (id, n, ty, s, t) -> C.ALetIn (id, n, lift_term k ty, lift_term k s, 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
@@ -118,19 +119,19 @@ let lift k n =
       in
       ann_term c
 
-let clear_absts m =
-   let rec aux k n = function
-      | C.AImplicit (_, None) as t         -> t
-      | C.ALambda (id, s, v, t) when k > 0 -> 
-         C.ALambda (id, s, v, aux (pred k) n t)
-      | C.ALambda (_, _, _, t) when n > 0  -> 
-         aux 0 (pred n) (lift 1 (-1) t)
-      | t                      when n > 0  ->
-           Printf.eprintf "CLEAR: %u %s\n" n (CicPp.ppterm (cic t));
-           assert false 
-      | t                                  -> t
-   in 
-   aux m
+let mk_arel k = C.ARel ("", "", k, "")
+
+let mk_aappl ts = C.AAppl ("", ts)
+
+let rec clear_absts f n k = function
+   | t when n = 0           -> f k t
+   | C.ALambda (_, _, _, t) -> clear_absts f (pred n) (succ k) t
+   | t                      ->
+      let u = match mk_aappl [lift (succ k) 1 t; mk_arel (succ k)] with
+         | C.AAppl (_, [ C.AAppl (id, ts); t]) -> C.AAppl (id, ts @ [t])
+         | t                                   -> t
+      in
+      clear_absts f (pred n) (succ k) u
 
 let hole id = C.AImplicit (id, Some `Hole)
 
@@ -181,11 +182,10 @@ let generalize n =
       | 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
-   gen_term 0
+   gen_term
 
 let mk_pattern psno predicate =
-   let body = generalize psno predicate in
-   clear_absts 0 psno body
+   clear_absts (generalize psno) psno 0 predicate 
 
 let get_clears c p xtypes = 
    let meta = C.Implicit None in
@@ -210,9 +210,9 @@ let get_clears c p xtypes =
            else 
               hd, names, v
         in
-        let p = C.LetIn (n, v, assert false, p) in
-        let it = C.LetIn (n, v, assert false, it) in
-        let et = C.LetIn (n, v, assert false, et) in
+        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
@@ -220,9 +220,9 @@ let get_clears c p xtypes =
         let et = C.Lambda (n, meta, et) in
         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, assert false, p) in
-        let it = C.LetIn (n, meta, assert false, it) in
-        let et = C.LetIn (n, meta, assert false, et) in
+        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
@@ -240,12 +240,17 @@ let clear c hyp =
    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 metasenv, ugraph = [], Un.default_ugraph in
+   let ety = H.get_type "elim_inferred_type" context using 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
+   let _metasenv, _subst, predicate, _arg, actual_args = 
+     PT.mk_predicate_for_elim 
+     ~context ~metasenv ~subst:[] ~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
+
+let does_not_occur = function
+   | C.AImplicit (_, None) -> true
+   | _                     -> false