X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Facic_procedural%2Facic2Procedural.ml;h=deb3088f22537b32e368a03b54de920e8776a488;hb=04f22df647f35080b499b720bca7bc0eb1794c64;hp=4d5e3a668f9724267e68f2b1b3f1562e78a0b806;hpb=6a5e51c1cf9a56c74a8b53a9b8bc5aa686c9780e;p=helm.git diff --git a/helm/software/components/acic_procedural/acic2Procedural.ml b/helm/software/components/acic_procedural/acic2Procedural.ml index 4d5e3a668..deb3088f2 100644 --- a/helm/software/components/acic_procedural/acic2Procedural.ml +++ b/helm/software/components/acic_procedural/acic2Procedural.ml @@ -38,6 +38,7 @@ module Pp = CicPp module PEH = ProofEngineHelpers module HEL = HExtlib module DTI = DoubleTypeInference +module NU = CicNotationUtil module Cl = ProceduralClassify module T = ProceduralTypes @@ -91,7 +92,7 @@ let push st = {st with case = 1 :: st.case} let inc st = {st with case = match st.case with - | [] -> assert false + | [] -> [] | hd :: tl -> succ hd :: tl } @@ -145,12 +146,6 @@ try with Not_found -> `Type (CicUniv.fresh()) with Invalid_argument _ -> failwith "A2P.get_sort" *) -let get_type msg st bo = -try - let ty, _ = TC.type_of_aux' [] st.context (H.cic bo) Un.oblivion_ugraph in - ty -with e -> failwith (msg ^ ": " ^ Printexc.to_string e) - let get_entry st id = let rec aux = function | [] -> assert false @@ -159,16 +154,6 @@ let get_entry st id = in aux st.context -let get_ind_names uri tno = -try - let ts = match E.get_obj Un.oblivion_ugraph uri with - | C.InductiveDefinition (ts, _, _, _), _ -> ts - | _ -> assert false - in - match List.nth ts tno with - | (_, _, _, cs) -> List.map fst cs -with Invalid_argument _ -> failwith "A2P.get_ind_names" - let string_of_atomic = function | C.ARel (_, _, _, s) -> s | C.AVar (_, uri, _) -> H.name_of_uri uri None None @@ -186,6 +171,8 @@ let get_sub_names head l = let names, _ = List.fold_left map ([], 1) l in List.rev names +let get_type msg st t = H.get_type msg st.context (H.cic t) + (* proof construction *******************************************************) let anonymous_premise = C.Name "PREMISE" @@ -377,7 +364,7 @@ and proc_appl st what hd tl = let classes2, tl2, _, where = split2_last classes tl in let script2 = List.rev (mk_arg st where) @ script in let synth2 = I.S.add 1 synth in - let names = get_ind_names uri tyno in + let names = H.get_ind_names uri tyno in let qs = proc_bkd_proofs (next st) synth2 names classes2 tl2 in if List.length qs <> List.length names then let qs = proc_bkd_proofs (next st) synth [] classes tl in @@ -431,16 +418,15 @@ and proc_proof st t = and proc_bkd_proofs st synth names classes ts = try - let get_note = - let names = ref (names, push st) in - fun f -> - match !names with - | [], st -> fun _ -> f st - | "" :: tl, st -> names := tl, st; fun _ -> f st - | hd :: tl, st -> - let note = case st hd in - names := tl, inc st; - fun b -> if b then T.Note note :: f st else f st + let get_names b = ref (names, if b then push st else st) in + let get_note f b names = + match !names with + | [], st -> f st + | "" :: tl, st -> names := tl, st; f st + | hd :: tl, st -> + let note = case st hd in + names := tl, inc st; + if b then T.Note note :: f st else f st in let _, dtext = test_depth st in let aux (inv, _) v = @@ -450,32 +436,46 @@ try in let ps = T.list_map2_filter aux classes ts in let b = List.length ps > 1 in - List.rev_map (fun f -> f b) ps + let names = get_names b in + List.rev_map (fun f -> f b names) ps with Invalid_argument s -> failwith ("A2P.proc_bkd_proofs: " ^ s) (* object costruction *******************************************************) -let is_theorem pars = - pars = [] || - List.mem (`Flavour `Theorem) pars || List.mem (`Flavour `Fact) pars || - List.mem (`Flavour `Remark) pars || List.mem (`Flavour `Lemma) pars - -let is_definition pars = - List.mem (`Flavour `Definition) pars - -let proc_obj st = function - | C.AConstant (_, _, s, Some v, t, [], pars) when is_theorem pars -> - 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 "tactics: %u\nnodes: %u" steps nodes in - T.Statement (`Theorem, Some s, t, None, "") :: ast @ [T.Qed text] - | C.AConstant (_, _, s, Some v, t, [], pars) when is_definition pars -> - [T.Statement (`Definition, Some s, t, Some v, "")] - | C.AConstant (_, _, s, None, t, [], pars) -> +let th_flavours = [`Theorem; `Lemma; `Remark; `Fact] + +let def_flavours = [`Definition] + +let get_flavour ?flavour attrs = + let rec aux = function + | [] -> List.hd th_flavours + | `Flavour fl :: _ -> fl + | _ :: tl -> aux tl + in + match flavour with + | Some fl -> fl + | None -> aux attrs + +let proc_obj ?flavour st = function + | C.AConstant (_, _, s, Some v, t, [], attrs) -> + begin match get_flavour ?flavour 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 "tactics: %u\nnodes: %u" steps nodes 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, "")] - | _ -> - failwith "not a theorem, definition, axiom" + | C.AInductiveDefinition (_, types, [], lpsno, attrs) -> + [T.Inductive (types, lpsno, "")] + | _ -> + failwith "not a theorem, definition, axiom or inductive type" (* interface functions ******************************************************) @@ -490,7 +490,7 @@ let procedural_of_acic_object ~ids_to_inner_sorts ~ids_to_inner_types ?depth case = [] } in HLog.debug "Procedural: level 2 transformation"; - let steps = proc_obj st anobj in + let steps = proc_obj st ?flavour anobj in HLog.debug "Procedural: grafite rendering"; List.rev (T.render_steps [] steps)