]> matita.cs.unibo.it Git - helm.git/commitdiff
- Procedural: new flag "level=n" to control the reconstruction level (defaults to...
authorFerruccio Guidi <ferruccio.guidi@unibo.it>
Tue, 5 May 2009 18:57:21 +0000 (18:57 +0000)
committerFerruccio Guidi <ferruccio.guidi@unibo.it>
Tue, 5 May 2009 18:57:21 +0000 (18:57 +0000)
13 files changed:
helm/software/components/acic_procedural/.depend
helm/software/components/acic_procedural/.depend.opt
helm/software/components/acic_procedural/Makefile
helm/software/components/acic_procedural/acic2Procedural.ml
helm/software/components/acic_procedural/procedural1.ml [new file with mode: 0644]
helm/software/components/acic_procedural/procedural1.mli [new file with mode: 0644]
helm/software/components/acic_procedural/procedural2.ml
helm/software/components/acic_procedural/procedural2.mli
helm/software/components/acic_procedural/proceduralHelpers.ml
helm/software/components/acic_procedural/proceduralHelpers.mli
helm/software/components/grafite/grafiteAst.ml
helm/software/components/grafite/grafiteAstPp.ml
helm/software/components/grafite_parser/grafiteParser.ml

index 189d36ff1a19a3dd0cffacaa95c327037b6f8152..fde9f7d6369449aad7dfc4d11a115214de7b4fcc 100644 (file)
@@ -1,3 +1,4 @@
+procedural1.cmi: proceduralTypes.cmi 
 procedural2.cmi: proceduralTypes.cmi 
 proceduralTeX.cmi: proceduralTypes.cmi 
 proceduralHelpers.cmo: proceduralHelpers.cmi 
@@ -14,6 +15,8 @@ proceduralMode.cmo: proceduralClassify.cmi proceduralMode.cmi
 proceduralMode.cmx: proceduralClassify.cmx proceduralMode.cmi 
 proceduralConversion.cmo: proceduralHelpers.cmi proceduralConversion.cmi 
 proceduralConversion.cmx: proceduralHelpers.cmx proceduralConversion.cmi 
+procedural1.cmo: procedural1.cmi 
+procedural1.cmx: procedural1.cmi 
 procedural2.cmo: proceduralTypes.cmi proceduralHelpers.cmi \
     proceduralConversion.cmi proceduralClassify.cmi procedural2.cmi 
 procedural2.cmx: proceduralTypes.cmx proceduralHelpers.cmx \
@@ -22,7 +25,7 @@ proceduralTeX.cmo: proceduralTypes.cmi proceduralHelpers.cmi \
     proceduralTeX.cmi 
 proceduralTeX.cmx: proceduralTypes.cmx proceduralHelpers.cmx \
     proceduralTeX.cmi 
-acic2Procedural.cmo: proceduralTypes.cmi proceduralTeX.cmi procedural2.cmi \
-    acic2Procedural.cmi 
-acic2Procedural.cmx: proceduralTypes.cmx proceduralTeX.cmx procedural2.cmx \
-    acic2Procedural.cmi 
+acic2Procedural.cmo: proceduralTypes.cmi proceduralTeX.cmi \
+    proceduralHelpers.cmi procedural2.cmi procedural1.cmi acic2Procedural.cmi 
+acic2Procedural.cmx: proceduralTypes.cmx proceduralTeX.cmx \
+    proceduralHelpers.cmx procedural2.cmx procedural1.cmx acic2Procedural.cmi 
index 189d36ff1a19a3dd0cffacaa95c327037b6f8152..fde9f7d6369449aad7dfc4d11a115214de7b4fcc 100644 (file)
@@ -1,3 +1,4 @@
+procedural1.cmi: proceduralTypes.cmi 
 procedural2.cmi: proceduralTypes.cmi 
 proceduralTeX.cmi: proceduralTypes.cmi 
 proceduralHelpers.cmo: proceduralHelpers.cmi 
@@ -14,6 +15,8 @@ proceduralMode.cmo: proceduralClassify.cmi proceduralMode.cmi
 proceduralMode.cmx: proceduralClassify.cmx proceduralMode.cmi 
 proceduralConversion.cmo: proceduralHelpers.cmi proceduralConversion.cmi 
 proceduralConversion.cmx: proceduralHelpers.cmx proceduralConversion.cmi 
+procedural1.cmo: procedural1.cmi 
+procedural1.cmx: procedural1.cmi 
 procedural2.cmo: proceduralTypes.cmi proceduralHelpers.cmi \
     proceduralConversion.cmi proceduralClassify.cmi procedural2.cmi 
 procedural2.cmx: proceduralTypes.cmx proceduralHelpers.cmx \
@@ -22,7 +25,7 @@ proceduralTeX.cmo: proceduralTypes.cmi proceduralHelpers.cmi \
     proceduralTeX.cmi 
 proceduralTeX.cmx: proceduralTypes.cmx proceduralHelpers.cmx \
     proceduralTeX.cmi 
-acic2Procedural.cmo: proceduralTypes.cmi proceduralTeX.cmi procedural2.cmi \
-    acic2Procedural.cmi 
-acic2Procedural.cmx: proceduralTypes.cmx proceduralTeX.cmx procedural2.cmx \
-    acic2Procedural.cmi 
+acic2Procedural.cmo: proceduralTypes.cmi proceduralTeX.cmi \
+    proceduralHelpers.cmi procedural2.cmi procedural1.cmi acic2Procedural.cmi 
+acic2Procedural.cmx: proceduralTypes.cmx proceduralTeX.cmx \
+    proceduralHelpers.cmx procedural2.cmx procedural1.cmx acic2Procedural.cmi 
index 5acd1d21d1e47007b4eab996405dffe77d6b4b55..ce878a21b200018cc4c76a25d23256b1585f0668 100644 (file)
@@ -8,6 +8,7 @@ INTERFACE_FILES =                \
        proceduralTypes.mli      \
        proceduralMode.mli       \
        proceduralConversion.mli \
+       procedural1.mli          \
        procedural2.mli          \
        proceduralTeX.mli        \
        acic2Procedural.mli      \
index c8168aa4795860700e75ac5d2b376214dd535abb..4ce01707cd9d32431f160c1bd28a1f67b6ca05d6 100644 (file)
  * http://cs.unibo.it/helm/.
  *)
 
-module L    = Librarian
+module C  = Cic
+module L  = Librarian
+module G  = GrafiteAst
 
+module H  = ProceduralHelpers
 module T  = ProceduralTypes
+module P1 = Procedural1
 module P2 = Procedural2
 module X  = ProceduralTeX
 
 let tex_formatter = ref None
 
+(* object costruction *******************************************************)
+
+let th_flavours = [`Theorem; `Lemma; `Remark; `Fact]
+
+let def_flavours = [`Definition; `Variant]
+
+let get_flavour sorts params context v attrs =
+   let rec aux = function
+      | []               -> 
+         if H.is_acic_proof sorts context v then List.hd th_flavours
+        else List.hd def_flavours
+      | `Flavour fl :: _ -> fl
+      | _ :: tl          -> aux tl
+   in
+   let flavour_map x y = match x, y with
+      | None, G.IPAs flavour -> Some flavour
+      | _                    -> x
+   in   
+   match List.fold_left flavour_map None params with
+      | Some fl -> fl
+      | None    -> aux attrs
+
+let proc_obj ?(info="") proc_proof sorts params context = function
+   | C.AConstant (_, _, s, Some v, t, [], attrs)         ->
+      begin match get_flavour sorts params context v attrs with
+         | flavour when List.mem flavour th_flavours  ->
+            let ast = proc_proof v in
+            let steps, nodes = T.count_steps 0 ast, T.count_nodes 0 ast in
+            let text = Printf.sprintf "%s\n%s%s: %u\n%s: %u\n%s"
+              "COMMENTS" info "Tactics" steps "Final nodes" nodes "END"
+           in
+            T.Statement (flavour, Some s, t, None, "") :: ast @ [T.Qed text]
+         | flavour when List.mem flavour def_flavours ->
+            [T.Statement (flavour, Some s, t, Some v, "")]
+        | _                                  ->
+            failwith "not a theorem, definition, axiom or inductive type"
+      end
+   | C.AConstant (_, _, s, None, t, [], attrs)           ->
+      [T.Statement (`Axiom, Some s, t, None, "")]
+   | C.AInductiveDefinition (_, types, [], lpsno, attrs) ->
+      [T.Inductive (types, lpsno, "")] 
+   | _                                          ->
+      failwith "not a theorem, definition, axiom or inductive type"
+
 (* interface functions ******************************************************)
 
+let get_proc_proof ~ids_to_inner_sorts ~ids_to_inner_types params context =
+   let level_map x y = match x, y with
+      | None, G.IPLevel level -> Some level
+      | _                     -> x
+   in   
+   match List.fold_left level_map None params with
+      | None
+      | Some 2 ->   
+         P2.proc_proof 
+            (P2.init ~ids_to_inner_sorts ~ids_to_inner_types params context)
+      | Some 1 ->
+         P1.proc_proof 
+            (P1.init ~ids_to_inner_sorts ~ids_to_inner_types params context)
+      | Some n ->
+         failwith (
+           "Procedural reconstruction level not supported: " ^ 
+           string_of_int n
+        )
+
 let procedural_of_acic_object ~ids_to_inner_sorts ~ids_to_inner_types 
    ?info params anobj = 
-   let st = P2.init ~ids_to_inner_sorts ~ids_to_inner_types params [] in
+   let proc_proof = 
+      get_proc_proof ~ids_to_inner_sorts ~ids_to_inner_types params []
+   in 
    L.time_stamp "P : LEVEL 2  ";
    HLog.debug "Procedural: level 2 transformation";
-   let steps = P2.proc_obj st ?info anobj in
+   let steps = proc_obj ?info proc_proof ids_to_inner_sorts params [] anobj in
    let _ = match !tex_formatter with
       | None     -> ()
       | Some frm -> X.tex_of_steps frm ids_to_inner_sorts steps
@@ -50,9 +119,11 @@ let procedural_of_acic_object ~ids_to_inner_sorts ~ids_to_inner_types
 
 let procedural_of_acic_term ~ids_to_inner_sorts ~ids_to_inner_types params
    context annterm = 
-   let st = P2.init ~ids_to_inner_sorts ~ids_to_inner_types params context in
+   let proc_proof =
+      get_proc_proof ~ids_to_inner_sorts ~ids_to_inner_types params context
+   in
    HLog.debug "Procedural: level 2 transformation";
-   let steps = P2.proc_proof st annterm in
+   let steps = proc_proof annterm in
    let _ = match !tex_formatter with
       | None     -> ()
       | Some frm -> X.tex_of_steps frm ids_to_inner_sorts steps
diff --git a/helm/software/components/acic_procedural/procedural1.ml b/helm/software/components/acic_procedural/procedural1.ml
new file mode 100644 (file)
index 0000000..550dd07
--- /dev/null
@@ -0,0 +1,51 @@
+(* Copyright (C) 2003-2005, HELM Team.
+ * 
+ * This file is part of HELM, an Hypertextual, Electronic
+ * Library of Mathematics, developed at the Computer Science
+ * Department, University of Bologna, Italy.
+ * 
+ * HELM is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * HELM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HELM; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA  02111-1307, USA.
+ * 
+ * For details, see the HELM World-Wide-Web page,
+ * http://cs.unibo.it/helm/.
+ *)
+
+module C    = Cic
+module A    = Cic2acic
+module G    = GrafiteAst
+
+module T    = ProceduralTypes
+
+type status = {
+   sorts    : (C.id, A.sort_kind) Hashtbl.t;
+   types    : (C.id, A.anntypes) Hashtbl.t;
+   params   : G.inline_param list;
+   context  : C.context
+}
+
+(* interface functions ******************************************************)
+
+let proc_proof st what =
+   let dtext = "" in
+   [T.Exact (what, dtext)]
+
+let init ~ids_to_inner_sorts ~ids_to_inner_types params context =
+   {
+      sorts       = ids_to_inner_sorts;
+      types       = ids_to_inner_types;
+      params      = params;
+      context     = context
+   }
diff --git a/helm/software/components/acic_procedural/procedural1.mli b/helm/software/components/acic_procedural/procedural1.mli
new file mode 100644 (file)
index 0000000..83de9d4
--- /dev/null
@@ -0,0 +1,34 @@
+(* Copyright (C) 2003-2005, HELM Team.
+ * 
+ * This file is part of HELM, an Hypertextual, Electronic
+ * Library of Mathematics, developed at the Computer Science
+ * Department, University of Bologna, Italy.
+ * 
+ * HELM is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * HELM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HELM; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA  02111-1307, USA.
+ * 
+ * For details, see the HELM World-Wide-Web page,
+ * http://cs.unibo.it/helm/.
+ *)
+
+type status
+
+val init:   
+   ids_to_inner_sorts:(Cic.id, Cic2acic.sort_kind) Hashtbl.t ->
+   ids_to_inner_types:(Cic.id, Cic2acic.anntypes) Hashtbl.t -> 
+   GrafiteAst.inline_param list-> Cic.context -> status
+
+val proc_proof: 
+   status -> Cic.annterm -> ProceduralTypes.step list
index 958fc4abbd0f80b5db55d89c48872193859260b0..ed30f767b1c9c5175d590d6113cdda4c0d86c691 100644 (file)
@@ -140,15 +140,6 @@ try
    with Not_found -> None
 with Invalid_argument _ -> failwith "A2P.get_inner_types"
 
-let is_proof st v =
-try
-   let id = Ut.id_of_annterm v in
-   try match Hashtbl.find st.sorts id with
-      | `Prop -> true
-      | _     -> false
-   with Not_found -> H.is_proof st.context (H.cic v)
-with Invalid_argument _ -> failwith "P1.is_proof"
-
 let get_entry st id =
    let rec aux = function
       | []                                        -> assert false
@@ -458,48 +449,7 @@ try
 
 with Invalid_argument s -> failwith ("A2P.proc_bkd_proofs: " ^ s)
 
-(* object costruction *******************************************************)
-
-let th_flavours = [`Theorem; `Lemma; `Remark; `Fact]
-
-let def_flavours = [`Definition; `Variant]
-
-let get_flavour st v attrs =
-   let rec aux = function
-      | []               -> 
-         if is_proof st v then List.hd th_flavours else List.hd def_flavours
-      | `Flavour fl :: _ -> fl
-      | _ :: tl          -> aux tl
-   in
-   let flavour_map x y = match x, y with
-      | None, G.IPAs flavour -> Some flavour
-      | _                    -> x
-   in   
-   match List.fold_left flavour_map None st.params with
-      | Some fl -> fl
-      | None    -> aux attrs
-
-let proc_obj ?(info="") st = function
-   | C.AConstant (_, _, s, Some v, t, [], attrs)         ->
-      begin match get_flavour st v attrs with
-         | flavour when List.mem flavour th_flavours  ->
-            let ast = proc_proof st v in
-            let steps, nodes = T.count_steps 0 ast, T.count_nodes 0 ast in
-            let text = Printf.sprintf "%s\n%s%s: %u\n%s: %u\n%s"
-              "COMMENTS" info "Tactics" steps "Final nodes" nodes "END"
-           in
-            T.Statement (flavour, Some s, t, None, "") :: ast @ [T.Qed text]
-         | flavour when List.mem flavour def_flavours ->
-            [T.Statement (flavour, Some s, t, Some v, "")]
-        | _                                  ->
-            failwith "not a theorem, definition, axiom or inductive type"
-      end
-   | C.AConstant (_, _, s, None, t, [], attrs)           ->
-      [T.Statement (`Axiom, Some s, t, None, "")]
-   | C.AInductiveDefinition (_, types, [], lpsno, attrs) ->
-      [T.Inductive (types, lpsno, "")] 
-   | _                                          ->
-      failwith "not a theorem, definition, axiom or inductive type"
+(* initialization ***********************************************************)
 
 let init ~ids_to_inner_sorts ~ids_to_inner_types params context =
    let depth_map x y = match x, y with
index 71cbe4253d0c0cdc053ba982111ed831d8163168..7abfb6f1ce3c939fd09e9c49cd9d65fd7e12dfb8 100644 (file)
@@ -33,7 +33,4 @@ val init:
 val proc_proof: 
    status -> Cic.annterm -> ProceduralTypes.step list
 
-val proc_obj: 
-   ?info:string -> status -> Cic.annobj -> ProceduralTypes.step list
-
 val debug: bool ref
index 3628e5944b93a4708fd2e4fc6ae98bde8e5d6789..b2f73f311a9d932374fb4694432c6be0a2469469 100644 (file)
@@ -335,3 +335,10 @@ let acic_bc c t =
       | t -> t
    in 
    bc c t
+
+let is_acic_proof sorts context v =
+   let id = Ut.id_of_annterm v in
+   try match Hashtbl.find sorts id with
+      | `Prop -> true
+      | _     -> false
+   with Not_found -> is_proof context (cic v)
index 358012c8765de46f551660d0fca12e62cccfc463..203224371f72f724b01bd472b85c9f3edac98d18 100644 (file)
@@ -71,3 +71,6 @@ val cic_bc:
    Cic.context -> Cic.term -> Cic.term
 val acic_bc:
    Cic.context -> Cic.annterm -> Cic.annterm
+val is_acic_proof:
+   (Cic.id, Cic2acic.sort_kind) Hashtbl.t -> Cic.context -> Cic.annterm ->
+   bool
index 4006320be2a2a58e770e8cf80efdbecce13939db..039d5bfa4e446cb306baaa82e17ddff71c84ae46 100644 (file)
@@ -148,10 +148,11 @@ type search_kind = [ `Locate | `Hint | `Match | `Elim ]
 type print_kind = [ `Env | `Coer ]
 
 type inline_param = IPPrefix of string
-                  | IPProcedural
-                  | IPDepth of int
                  | IPAs of Cic.object_flavour
+                  | IPProcedural
                   | IPNoDefaults 
+                 | IPLevel of int
+                  | IPDepth of int
 
 type ('term,'lazy_term) macro = 
   (* Whelp's stuff *)
index ce7fdcfdf07c120df09274a994cf17de7b82d1d8..6806713a4e9375a4c20ca4009d666c54d62720ea 100644 (file)
@@ -282,8 +282,9 @@ let pp_macro ~term_pp ~lazy_term_pp =
         | IPPrefix prefix -> "prefix = \"" ^ prefix ^ "\""
        | IPAs flavour -> flavour_pp flavour
        | IPProcedural -> "procedural"
-       | IPDepth depth -> "depth = " ^ string_of_int depth
        | IPNoDefaults -> "nodefaults"
+       | IPDepth depth -> "depth = " ^ string_of_int depth
+       | IPLevel level -> "level = " ^ string_of_int level
      in
      let s = String.concat " " (List.map pp_param l) in
      if s = "" then s else " " ^ s
index e2ab011dac927cd33a05c4c741240a9c8766ed36..ecdee9f7bd9a80be1e1dc1909e9595bfa0750c63 100644 (file)
@@ -453,10 +453,11 @@ EXTEND
   inline_params:[
    [ params = LIST0 
       [ IDENT "prefix"; SYMBOL "="; prefix = QSTRING -> G.IPPrefix prefix  
-      | IDENT "procedural" -> G.IPProcedural
       | flavour = inline_flavour -> G.IPAs flavour
-      | IDENT "depth"; SYMBOL "="; depth = int -> G.IPDepth depth 
+      | IDENT "procedural" -> G.IPProcedural
       | IDENT "nodefaults" -> G.IPNoDefaults
+      | IDENT "depth"; SYMBOL "="; depth = int -> G.IPDepth depth 
+      | IDENT "level"; SYMBOL "="; level = int -> G.IPLevel level 
       ] -> params
    ]
 ];