X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Facic_procedural%2Facic2Procedural.ml;h=4ce01707cd9d32431f160c1bd28a1f67b6ca05d6;hb=cdd3fc617825db73ce08a0cb700e2a8e115b4fb3;hp=043bd6e3a6637cb0cb4915822c52013462467363;hpb=1b36fc4540d93ff21c1afcf485e47e3fe3f26ddb;p=helm.git diff --git a/helm/software/components/acic_procedural/acic2Procedural.ml b/helm/software/components/acic_procedural/acic2Procedural.ml index 043bd6e3a..4ce01707c 100644 --- a/helm/software/components/acic_procedural/acic2Procedural.ml +++ b/helm/software/components/acic_procedural/acic2Procedural.ml @@ -23,50 +23,110 @@ * http://cs.unibo.it/helm/. *) +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 ?depth ?flavour prefix anobj = - let st = { - sorts = ids_to_inner_sorts; - types = ids_to_inner_types; - max_depth = depth; - depth = 0; - context = []; - case = [] - } in - L.time_stamp "P : LEVEL 1 "; - HLog.debug "Procedural: level 1 transformation"; - let steps = proc_obj st ?flavour ?info anobj in + ?info params anobj = + 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 = 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 st.sorts steps + | Some frm -> X.tex_of_steps frm ids_to_inner_sorts steps in L.time_stamp "P : RENDERING"; HLog.debug "Procedural: grafite rendering"; let r = List.rev (T.render_steps [] steps) in L.time_stamp "P : DONE "; r -let procedural_of_acic_term ~ids_to_inner_sorts ~ids_to_inner_types ?depth - prefix context annterm = - let st = { - sorts = ids_to_inner_sorts; - types = ids_to_inner_types; - max_depth = depth; - depth = 0; - context = context; - case = [] - } in - HLog.debug "Procedural: level 1 transformation"; - let steps = proc_proof st annterm in +let procedural_of_acic_term ~ids_to_inner_sorts ~ids_to_inner_types params + context annterm = + 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 = proc_proof annterm in let _ = match !tex_formatter with | None -> () - | Some frm -> X.tex_of_steps frm st.sorts steps + | Some frm -> X.tex_of_steps frm ids_to_inner_sorts steps in HLog.debug "Procedural: grafite rendering"; List.rev (T.render_steps [] steps)