From: Ferruccio Guidi Date: Wed, 4 Feb 2004 18:44:43 +0000 (+0000) Subject: an optimization was inserted X-Git-Url: http://matita.cs.unibo.it/gitweb/?p=helm.git;a=commitdiff_plain;h=17c63a69e22b8186e14dd4d8098574b566fedf14 an optimization was inserted --- diff --git a/helm/ocaml/mathql/.depend b/helm/ocaml/mathql/.depend index 6d18bd83c..8aa1d9b8d 100644 --- a/helm/ocaml/mathql/.depend +++ b/helm/ocaml/mathql/.depend @@ -1,10 +1,10 @@ listAvs.cmi: avs.cmo avsUtil.cmi: mathQL.cmo +mQueryUtil.cmo: mQueryUtil.cmi +mQueryUtil.cmx: mQueryUtil.cmi listAvs.cmo: avs.cmo listAvs.cmi listAvs.cmx: avs.cmx listAvs.cmi mathQL.cmo: avs.cmo listAvs.cmi mathQL.cmx: avs.cmx listAvs.cmx -avsUtil.cmo: mathQL.cmo avsUtil.cmi -avsUtil.cmx: mathQL.cmx avsUtil.cmi -mQueryUtil.cmo: mQueryUtil.cmi -mQueryUtil.cmx: mQueryUtil.cmi +avsUtil.cmo: mQueryUtil.cmi mathQL.cmo avsUtil.cmi +avsUtil.cmx: mQueryUtil.cmx mathQL.cmx avsUtil.cmi diff --git a/helm/ocaml/mathql/avs.ml b/helm/ocaml/mathql/avs.ml index 485354037..7b092a935 100644 --- a/helm/ocaml/mathql/avs.ml +++ b/helm/ocaml/mathql/avs.ml @@ -76,10 +76,10 @@ module type Type = sig val diff : avs -> avs -> avs - val append : avs -> avs -> avs - val d_union : avs -> avs -> avs (* with attr. distribution *) val peek : avs -> peek_t + val optimize : avs -> avs + end diff --git a/helm/ocaml/mathql/avsUtil.ml b/helm/ocaml/mathql/avsUtil.ml index 65bcadb15..1f0199772 100644 --- a/helm/ocaml/mathql/avsUtil.ml +++ b/helm/ocaml/mathql/avsUtil.ml @@ -52,24 +52,25 @@ let val_true = avs_of_bool true (* iterators ****************************************************************) let grp_iter f al = - List.fold_left (fun s a -> I.grp_union s (f a)) I.grp_empty al + List.fold_left (fun s a -> I.grp_union s (f a)) I.grp_empty (List.rev al) let grp_iter2 f al bl = - List.fold_left2 (fun s a b -> I.grp_union s (f a b)) I.grp_empty al bl + List.fold_left2 (fun s a b -> I.grp_union s (f a b)) + I.grp_empty (List.rev al) (List.rev bl) -let iter f al = List.fold_left (fun s a -> I.union s (f a)) I.empty al - -let append_iter f al = List.fold_left (fun s a -> I.append (f a) s) I.empty al +let iter f al = List.fold_left (fun s a -> I.union s (f a)) + I.empty (List.rev al) (* other ********************************************************************) let grp_make_x p vl = grp_iter (I.grp_make p) vl let x_grp_make_x p rs = - let aux g s _ = I.grp_make p s in + let aux g s _ = I.grp_union g (I.grp_make p s) in I.iter aux I.grp_empty rs -let make_x s gl = iter (I.make s) gl +let make_x s gl = + if gl = [] then avs_of_string s else iter (I.make s) gl let count v = I.iter (fun n _ _ -> succ n) 0 v diff --git a/helm/ocaml/mathql/avsUtil.mli b/helm/ocaml/mathql/avsUtil.mli index ac8888c17..886b6ca6c 100644 --- a/helm/ocaml/mathql/avsUtil.mli +++ b/helm/ocaml/mathql/avsUtil.mli @@ -45,8 +45,6 @@ val make_x : string -> MathQL.group list -> MathQL.result val iter : ('a -> MathQL.result) -> 'a list -> MathQL.result -val append_iter : ('a -> MathQL.result) -> 'a list -> MathQL.result - val count : MathQL.result -> int val avs_of_bool : bool -> MathQL.result diff --git a/helm/ocaml/mathql/listAvs.ml b/helm/ocaml/mathql/listAvs.ml index e25fc61c7..591dc3fe2 100644 --- a/helm/ocaml/mathql/listAvs.ml +++ b/helm/ocaml/mathql/listAvs.ml @@ -133,8 +133,13 @@ let rec union s1 s2 = let grp_union = union let prod g1 g2 = - let aux a = set_iter (fun h -> [union a h]) g2 in - set_iter aux g1 + match g1, g2 with + | [], [] -> [] + | _, [] -> g1 + | [], _ -> g2 + | _, _ -> + let aux a = set_iter (fun h -> [union a h]) g2 in + set_iter aux g1 let rec d_union s1 s2 = match s1, s2 with @@ -177,13 +182,13 @@ let rec diff s1 s2 = | (r1, _) :: _, (r2, _) :: t2 when r1 > r2 -> diff s1 t2 | _ :: t1, _ :: t2 -> diff t1 t2 -(* concatenation ************************************************************) - -let append v1 v2 = v1 @ v2 - (* peeking ******************************************************************) let peek = function | [] -> Empty | [s, gl] -> Single (s, gl) | (s, gl) :: _ -> Many (s, gl) + +(* optimization *************************************************************) + +let optimize = List.rev