+++ /dev/null
-(* Copyright (C) 2000, 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/.
- *)
-
-(* AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
- *)
-
-(* boolean constants *******************************************************)
-
-let mql_false = []
-
-let mql_true = ["", []]
-
-(* set theoretic operations *************************************************)
-
-let rec set_sub v1 v2 =
- match (v1, v2) with
- | [], _ -> mql_true
- | _, [] -> mql_false
- | (h1, _) :: _, (h2, _) :: _ when h1 < h2 -> mql_false
- | (h1, _) :: _, (h2, _) :: t2 when h1 > h2 -> set_sub v1 t2
- | _ :: t1, _ :: t2 -> set_sub t1 t2
-
-let rec set_meet v1 v2 =
- match v1, v2 with
- | [], _
- | _, [] -> mql_false
- | (h1, _) :: t1, (h2, _) :: _ when h1 < h2 -> set_meet t1 v2
- | (h1, _) :: _, (h2, _) :: t2 when h1 > h2 -> set_meet v1 t2
- | _, _ -> mql_true
-
-let rec set_eq v1 v2 =
- match v1, v2 with
- | [], [] -> mql_true
- | (h1, _) :: t1, (h2, _) :: t2 when h1 = h2 -> set_eq t1 t2
- | _, _ -> mql_false
-
-let rec set_union v1 v2 =
- match v1, v2 with
- | [], v -> v
- | v, [] -> v
- | h1 :: t1, h2 :: t2 when h1 < h2 -> h1 :: set_union t1 v2
- | h1 :: t1, h2 :: t2 when h1 > h2 -> h2 :: set_union v1 t2
- | h1 :: t1, _ :: t2 -> h1 :: set_union t1 t2
-
-let rec set_intersect v1 v2 =
- match v1, v2 with
- | [], v -> []
- | v, [] -> []
- | h1 :: t1, h2 :: _ when h1 < h2 -> set_intersect t1 v2
- | h1 :: _, h2 :: t2 when h1 > h2 -> set_intersect v1 t2
- | h1 :: t1, _ :: t2 -> h1 :: set_intersect t1 t2
-
-let rec iter f = function
- | [] -> []
- | head :: tail -> set_union (f head) (iter f tail)
-
-(* MathQL specific set operations ******************************************)
-
-let mql_subj v = List.map (fun s -> (s, [])) v
-
-let rec mql_union s1 s2 =
- match s1, s2 with
- | [], s -> s
- | s, [] -> s
- | (r1, g1) :: t1, (r2, _) :: _ when r1 < r2 ->
- (r1, g1) :: mql_union t1 s2
- | (r1, _) :: _, (r2, g2) :: t2 when r1 > r2 ->
- (r2, g2) :: mql_union s1 t2
- | (r1, g1) :: t1, (_, g2) :: t2 ->
- (r1, set_union g1 g2) :: mql_union t1 t2
-
-let rec mql_iter f = function
- | [] -> []
- | head :: tail -> mql_union (f head) (mql_iter f tail)
-
-let rec mql_iter2 f l1 l2 = match l1, l2 with
- | [], [] -> []
- | h1 :: t1, h2 :: t2 -> mql_union (f h1 h2) (mql_iter2 f t1 t2)
- | _ -> raise (Invalid_argument "mql_iter2")
-
-let rec mql_prod g1 g2 =
- let mql_prod_aux a = iter (fun h -> [mql_union a h]) g2 in
- iter mql_prod_aux g1
-
-let rec mql_intersect s1 s2 =
- match s1, s2 with
- | [], s -> []
- | s, [] -> []
- | (r1, _) :: t1, (r2, _) :: _ when r1 < r2 -> mql_intersect t1 s2
- | (r1, _) :: _, (r2, _) :: t2 when r1 > r2 -> mql_intersect s1 t2
- | (r1, g1) :: t1, (_, g2) :: t2 ->
- (r1, set_intersect g1 g2) :: mql_intersect t1 t2
-
-let rec mql_diff s1 s2 =
- match s1, s2 with
- | [], _ -> []
- | s, [] -> s
- | (r1, g1) :: t1 , (r2, _) ::_ when r1 < r2 ->
- (r1, g1) :: (mql_diff t1 s2)
- | (r1, _) :: _, (r2, _) :: t2 when r1 > r2 -> mql_diff s1 t2
- | _ :: t1, _ :: t2 -> mql_diff t1 t2
-
-(* logic operations ********************************************************)
-
-let xor v1 v2 =
- let b = v1 <> mql_false in
- if b && v2 <> mql_false then mql_false else
- if b then v1 else v2
-
-(* numeric operations *******************************************************)
-
-exception NumberError of MathQL.result
-
-let int_of_set r =
- try match r with
- | [s, _] -> MQueryUtil.int_of_string s
- | _ -> raise (Failure "int_of_string")
- with Failure "int_of_string" -> raise (NumberError r)