X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=components%2Facic_procedural%2FproceduralTypes.ml;h=8a60f9658047118ad4c8c0ddc7b2dc4674d19326;hb=24dd4569daf1d35bffaa813b8164058d8643f14d;hp=ae153fe3d1d5b2b3abbe25f2c5bbd33ec8b49368;hpb=c4df237cf74270f9e4aa164d5fe0415181406a49;p=helm.git diff --git a/components/acic_procedural/proceduralTypes.ml b/components/acic_procedural/proceduralTypes.ml index ae153fe3d..8a60f9658 100644 --- a/components/acic_procedural/proceduralTypes.ml +++ b/components/acic_procedural/proceduralTypes.ml @@ -23,10 +23,13 @@ * http://cs.unibo.it/helm/. *) -module H = HExtlib -module C = Cic -module G = GrafiteAst -module N = CicNotationPt +module HEL = HExtlib +module C = Cic +module I = CicInspect +module G = GrafiteAst +module N = CicNotationPt + +module H = ProceduralHelpers (* functions to be moved ****************************************************) @@ -45,15 +48,20 @@ let list_map2_filter map l1 l2 = in filter [] (list_rev_map2 map l1 l2) +let list_init f i = + let rec aux a j = if j < 0 then a else aux (f j :: a) (pred j) in + aux [] i + (****************************************************************************) -type name = string +type name = string option +type hyp = string type what = Cic.annterm type how = bool type using = Cic.annterm type count = int type note = string -type where = (name * name) option +type where = (hyp * name) option type inferred = Cic.annterm type pattern = Cic.annterm @@ -68,7 +76,8 @@ type step = Note of note | Elim of what * using option * pattern * note | Apply of what * note | Change of inferred * what * where * pattern * note - | ClearBody of name * note + | Clear of hyp list * note + | ClearBody of hyp * note | Branch of step list list * note (* annterm constructors *****************************************************) @@ -77,14 +86,21 @@ let mk_arel i b = Cic.ARel ("", "", i, b) (* grafite ast constructors *************************************************) -let floc = H.dummy_floc +let floc = HEL.dummy_floc let mk_note str = G.Comment (floc, G.Note (floc, str)) -let mk_nlnote str a = - if str = "" then mk_note "" :: a else mk_note str :: mk_note "" :: a +let mk_tacnote str a = + if str = "" then mk_note "" :: a else mk_note "" :: mk_note str :: a + +let mk_notenote str a = + if str = "" then a else mk_note str :: a -let mk_theorem name t = +let mk_thnote str a = + if str = "" then a else mk_note "" :: mk_note str :: a + +let mk_theorem name t = + let name = match name with Some name -> name | None -> assert false in let obj = N.Theorem (`Theorem, name, t, None) in G.Executable (floc, G.Command (floc, G.Obj (floc, obj))) @@ -101,15 +117,17 @@ let mk_id punctation = let tactic = G.IdTac floc in mk_tactic tactic punctation -let mk_intros xi ids punctation = - let tactic = G.Intros (floc, xi, ids) in +let mk_intros xi xids punctation = + let tactic = G.Intros (floc, (xi, xids)) in mk_tactic tactic punctation let mk_cut name what punctation = + let name = match name with Some name -> name | None -> assert false in let tactic = G.Cut (floc, Some name, what) in mk_tactic tactic punctation let mk_letin name what punctation = + let name = match name with Some name -> name | None -> assert false in let tactic = G.LetIn (floc, what, name) in mk_tactic tactic punctation @@ -124,7 +142,7 @@ let mk_rewrite direction what where pattern punctation = let mk_elim what using pattern punctation = let pattern = None, [], Some pattern in - let tactic = G.Elim (floc, what, using, pattern, Some 0, []) in + let tactic = G.Elim (floc, what, using, pattern, (Some 0, [])) in mk_tactic tactic punctation let mk_apply t punctation = @@ -139,6 +157,10 @@ let mk_change t where pattern punctation = let tactic = G.Change (floc, pattern, t) in mk_tactic tactic punctation +let mk_clear ids punctation = + let tactic = G.Clear (floc, ids) in + mk_tactic tactic punctation + let mk_clearbody id punctation = let tactic = G.ClearBody (floc, id) in mk_tactic tactic punctation @@ -158,22 +180,23 @@ let mk_vb = G.Shift floc (* rendering ****************************************************************) let rec render_step sep a = function - | Note s -> mk_note s :: a - | Theorem (n, t, s) -> mk_theorem n t :: mk_note s :: a - | Qed s -> mk_qed :: mk_nlnote s a - | Id s -> mk_id sep :: mk_nlnote s a - | Intros (c, ns, s) -> mk_intros c ns sep :: mk_nlnote s a - | Cut (n, t, s) -> mk_cut n t sep :: mk_nlnote s a - | LetIn (n, t, s) -> mk_letin n t sep :: mk_nlnote s a - | Rewrite (b, t, w, e, s) -> mk_rewrite b t w e sep :: mk_nlnote s a - | Elim (t, xu, e, s) -> mk_elim t xu e sep :: mk_nlnote s a - | Apply (t, s) -> mk_apply t sep :: mk_nlnote s a - | Change (t, _, w, e, s) -> mk_change t w e sep :: mk_nlnote s a - | ClearBody (n, s) -> mk_clearbody n sep :: mk_nlnote s a + | Note s -> mk_notenote s a + | Theorem (n, t, s) -> mk_theorem n t :: mk_thnote s a + | Qed s -> mk_qed :: mk_tacnote s a + | Id s -> mk_id sep :: mk_tacnote s a + | Intros (c, ns, s) -> mk_intros c ns sep :: mk_tacnote s a + | Cut (n, t, s) -> mk_cut n t sep :: mk_tacnote s a + | LetIn (n, t, s) -> mk_letin n t sep :: mk_tacnote s a + | Rewrite (b, t, w, e, s) -> mk_rewrite b t w e sep :: mk_tacnote s a + | Elim (t, xu, e, s) -> mk_elim t xu e sep :: mk_tacnote s a + | Apply (t, s) -> mk_apply t sep :: mk_tacnote s a + | Change (t, _, w, e, s) -> mk_change t w e sep :: mk_tacnote s a + | Clear (ns, s) -> mk_clear ns sep :: mk_tacnote s a + | ClearBody (n, s) -> mk_clearbody n sep :: mk_tacnote s a | Branch ([], s) -> a | Branch ([ps], s) -> render_steps sep a ps | Branch (ps :: pss, s) -> - let a = mk_ob :: mk_nlnote s a in + let a = mk_ob :: mk_tacnote s a in let a = List.fold_left (render_steps mk_vb) a (List.rev pss) in mk_punctation sep :: render_steps mk_cb a ps @@ -185,7 +208,7 @@ and render_steps sep a = function | p :: ((Branch (_ :: _ :: _, _) :: _) as ps) -> render_steps sep (render_step mk_sc a p) ps | p :: ps -> - render_steps sep (render_step mk_dot a p) ps + render_steps sep (render_step mk_sc a p) ps let render_steps a = render_steps mk_dot a @@ -199,3 +222,23 @@ let rec count_step a = function | _ -> succ a and count_steps a = List.fold_left count_step a + +let rec count_node a = function + | Note _ + | Theorem _ + | Qed _ + | Id _ + | Intros _ + | Clear _ + | ClearBody _ -> a + | Cut (_, t, _) + | LetIn (_, t, _) + | Apply (t, _) -> I.count_nodes a (H.cic t) + | Rewrite (_, t, _, p, _) + | Elim (t, _, p, _) + | Change (t, _, _, p, _) -> + let a = I.count_nodes a (H.cic t) in + I.count_nodes a (H.cic p) + | Branch (ss, _) -> List.fold_left count_nodes a ss + +and count_nodes a = List.fold_left count_node a