]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_tactics/nCicElim.ml
1) sort computation undone (it used to be bugged anyway)
[helm.git] / helm / software / components / ng_tactics / nCicElim.ml
index a124b28388d3fa83d38ad6a6a8d444724d963215..b493edb6a22f295750a96141dd74f6a5d0a68385 100644 (file)
@@ -38,10 +38,11 @@ let mk_appl =
  function
     [] -> assert false
   | [x] -> x
+  | CicNotationPt.Appl l1 :: l2 -> CicNotationPt.Appl (l1 @ l2)
   | l -> CicNotationPt.Appl l
 ;;
 
-let mk_elim uri leftno [it] (outsort,suffix) =
+let mk_elim uri leftno it (outsort,suffix) pragma =
  let _,ind_name,ty,cl = it in
  let srec_name = ind_name ^ "_" ^ suffix in
  let rec_name = mk_id srec_name in
@@ -98,7 +99,7 @@ let mk_elim uri leftno [it] (outsort,suffix) =
                       params @
                       [p_name] @
                       k_names @
-                      List.map (fun _ -> CicNotationPt.Implicit)
+                      List.map (fun _ -> CicNotationPt.Implicit `JustOne)
                        (List.tl args) @
                       [mk_appl (name::abs)])))
               | _ -> mk_id name,None
@@ -148,29 +149,36 @@ let mk_elim uri leftno [it] (outsort,suffix) =
      (function x::_ -> x | _ -> assert false) 80 
      (CicNotationPres.mpres_of_box boxml)));
 *)
-  CicNotationPt.Theorem (`Definition,srec_name,CicNotationPt.Implicit,Some res)
+  CicNotationPt.Theorem
+   (`Definition,srec_name,
+      CicNotationPt.Implicit `JustOne,Some res,pragma)
 ;;
 
 let ast_of_sort s =
+  let headrm prefix s =
+    try 
+      let len_prefix = String.length prefix in 
+      assert (String.sub s 0 len_prefix = prefix);
+      String.sub s len_prefix (String.length s - len_prefix)
+    with Invalid_argument _ -> assert false
+  in
   match s with
-     NCic.Prop -> `Prop,"ind"
-   | NCic.Type u ->
-      let u = NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] (NCic.Sort s) in
-      (try
-        if String.sub u 0 4 = "Type" then
-         `NType (String.sub u 4 (String.length u - 4)), "rect_" ^ u
-        else if String.sub u 0 5 = "CProp" then
-         `NCProp (String.sub u 5 (String.length u - 5)), "rect_" ^ u
-        else
-         (prerr_endline u;
-         assert false)
-       with Failure _ -> assert false)
+   | NCic.Prop -> `Prop,"ind"
+   | NCic.Type []  -> `NType "", "rect_Type"
+   | NCic.Type ((`Type,u) :: _) ->
+       let name = NUri.name_of_uri u in
+       `NType (headrm "Type" name), "rect_" ^ name
+   | NCic.Type ((`CProp,u) :: _) ->
+       let name = NUri.name_of_uri u in
+       `NCProp (headrm "Type" name), 
+       "rect_" ^ Str.replace_first (Str.regexp "Type") "CProp" name
+   | _ -> assert false
 ;;
 
 let mk_elims (uri,_,_,_,obj) =
   match obj with
-     NCic.Inductive (true,leftno,itl,_) ->
-      List.map (fun s -> mk_elim uri leftno itl (ast_of_sort s))
+    NCic.Inductive (true,leftno,[itl],_) ->
+      List.map (fun s -> mk_elim uri leftno itl (ast_of_sort s) (`Elim s))
        (NCic.Prop::
          List.map (fun s -> NCic.Type s) (NCicEnvironment.get_universes ()))
    | _ -> []
@@ -194,6 +202,8 @@ let rec nth_prod projs n ty =
   | _ -> assert false
 ;;
 
+(* this code should be unified with NTermCicContent.nast_of_cic0,
+   but the two contexts have different types *)
 let rec pp rels =
  function
     NCic.Rel i -> List.nth rels (i - 1)
@@ -201,11 +211,45 @@ let rec pp rels =
      CicNotationPt.Ident
       (NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] t,None)
   | NCic.Sort s -> CicNotationPt.Sort (fst (ast_of_sort s))
+  | NCic.Meta _
+  | NCic.Implicit _ -> assert false
   | NCic.Appl l -> CicNotationPt.Appl (List.map (pp rels) l)
   | NCic.Prod (n,s,t) ->
      let n = mk_id n in
       CicNotationPt.Binder (`Pi, (n,Some (pp rels s)), pp (n::rels) t)
-  | _ -> assert false (* not implemented yet *)
+  | NCic.Lambda (n,s,t) ->
+     let n = mk_id n in
+      CicNotationPt.Binder (`Lambda, (n,Some (pp rels s)), pp (n::rels) t)
+  | NCic.LetIn (n,s,ty,t) ->
+     let n = mk_id n in
+      CicNotationPt.LetIn ((n, Some (pp rels ty)), pp rels s, pp (n::rels) t)
+  | NCic.Match (NReference.Ref (uri,_) as r,outty,te,patterns) ->
+    let name = NUri.name_of_uri uri in
+    let case_indty = Some (name, None) in
+    let constructors, leftno =
+     let _,leftno,tys,_,n = NCicEnvironment.get_checked_indtys r in
+     let _,_,_,cl  = List.nth tys n in
+      cl,leftno
+    in
+    let rec eat_branch n rels ty pat =
+      match (ty, pat) with
+      | NCic.Prod (name, s, t), _ when n > 0 ->
+         eat_branch (pred n) rels t pat
+      | NCic.Prod (_, _, t), NCic.Lambda (name, s, t') ->
+          let cv, rhs = eat_branch 0 ((mk_id name)::rels) t t' in
+           (mk_id name, Some (pp rels s)) :: cv, rhs
+      | _, _ -> [], pp rels pat
+    in
+    let patterns =
+      try
+        List.map2
+          (fun (_, name, ty) pat ->
+            let capture_variables,rhs = eat_branch leftno rels ty pat in
+             CicNotationPt.Pattern (name, None, capture_variables), rhs
+          ) constructors patterns
+      with Invalid_argument _ -> assert false
+    in
+     CicNotationPt.Case (pp rels te, case_indty, Some (pp rels outty), patterns)
 ;;
 
 let mk_projection leftno tyname consname consty (projname,_,_) i =
@@ -228,23 +272,26 @@ let mk_projection leftno tyname consname consty (projname,_,_) i =
       @ names in
      let outtype = pp rels outtype in
      let outtype= CicNotationPt.Binder (`Lambda, (arg, Some arg_ty), outtype) in
-      CicNotationPt.Binder
-       (`Lambda, (arg,Some arg_ty),
-         CicNotationPt.Case (arg,None,Some outtype,[branch]))
+      [arg, Some arg_ty], CicNotationPt.Case (arg,None,Some outtype,[branch])
    | _,NCic.Prod (name,_,t) ->
       let name = mk_id name in
-       CicNotationPt.Binder
-        (`Lambda, (name,None), aux (name::names) t (leftno - 1))
+      let params,body = aux (name::names) t (leftno - 1) in
+       (name,None)::params, body
    | _,_ -> assert false
  in
- let res = aux [] consty leftno in
+ let params,bo = aux [] consty leftno in
+ let pprojname = mk_id projname in
+ let res =
+  CicNotationPt.LetRec (`Inductive,
+   [params, (pprojname,None), bo, leftno], pprojname) in
 (* prerr_endline
    (BoxPp.render_to_string
      ~map_unicode_to_tex:false
      (function x::_ -> x | _ -> assert false)
      80 (CicNotationPres.render (fun _ -> None)
      (TermContentPres.pp_ast res)));*)
-  CicNotationPt.Theorem (`Definition,projname,CicNotationPt.Implicit,Some res)
+  CicNotationPt.Theorem
+   (`Definition,projname,CicNotationPt.Implicit `JustOne,Some res,`Projection)
 ;;
 
 let mk_projections (_,_,_,_,obj) =