diff options
Diffstat (limited to 'lib/stdlib/doc/src/sofs.xml')
-rw-r--r-- | lib/stdlib/doc/src/sofs.xml | 1370 |
1 files changed, 753 insertions, 617 deletions
diff --git a/lib/stdlib/doc/src/sofs.xml b/lib/stdlib/doc/src/sofs.xml index 37c41501ae..4cf1984d46 100644 --- a/lib/stdlib/doc/src/sofs.xml +++ b/lib/stdlib/doc/src/sofs.xml @@ -1,282 +1,307 @@ -<?xml version="1.0" encoding="latin1" ?> +<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE erlref SYSTEM "erlref.dtd"> <erlref> <header> <copyright> - <year>2001</year><year>2012</year> + <year>2001</year><year>2016</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> - The contents of this file are subject to the Erlang Public License, - Version 1.1, (the "License"); you may not use this file except in - compliance with the License. You should have received a copy of the - Erlang Public License along with this software. If not, it can be - retrieved online at http://www.erlang.org/. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 - Software distributed under the License is distributed on an "AS IS" - basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - the License for the specific language governing rights and limitations - under the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. </legalnotice> <title>sofs</title> <prepared>Hans Bolinder</prepared> - <responsible>nobody</responsible> + <responsible></responsible> <docno></docno> - <approved>nobody</approved> - <checked>no</checked> + <approved></approved> + <checked></checked> <date>2001-08-25</date> <rev>PA1</rev> - <file>sofs.sgml</file> + <file>sofs.xml</file> </header> <module>sofs</module> - <modulesummary>Functions for Manipulating Sets of Sets</modulesummary> + <modulesummary>Functions for manipulating sets of sets.</modulesummary> <description> - <p>The <c>sofs</c> module implements operations on finite sets and + <p>This module provides operations on finite sets and relations represented as sets. Intuitively, a set is a collection of elements; every element belongs to the set, and the set contains every element.</p> + <p>Given a set A and a sentence S(x), where x is a free variable, a new set B whose elements are exactly those elements of A for which S(x) holds can be formed, this is denoted B = {x in A : S(x)}. Sentences are expressed using the logical operators "for some" (or "there exists"), "for all", "and", "or", "not". If the existence of a set containing all the - specified elements is known (as will always be the case in this - module), we write B = {x : S(x)}. </p> - <p>The <em>unordered set</em> containing the elements a, b and c - is denoted {a, b, c}. This notation is not to be - confused with tuples. The <em>ordered pair</em> of a and b, with - first <em>coordinate</em> a and second coordinate b, is denoted - (a, b). An ordered pair is an <em>ordered set</em> of two - elements. In this module ordered sets can contain one, two or - more elements, and parentheses are used to enclose the elements. - Unordered sets and ordered sets are orthogonal, again in this - module; there is no unordered set equal to any ordered set.</p> - <p>The set that contains no elements is called the <em>empty set</em>. - If two sets A and B contain the same elements, then A - is <marker id="equal"></marker><em>equal</em> to B, denoted - A = B. Two ordered sets are equal if they contain the - same number of elements and have equal elements at each - coordinate. If a set A contains all elements that B contains, - then B is a <marker id="subset"></marker><em>subset</em> of A. - The <marker id="union"></marker><em>union</em> of two sets A and B is - the smallest set that contains all elements of A and all elements of - B. The <marker id="intersection"></marker><em>intersection</em> of two - sets A and B is the set that contains all elements of A that - belong to B. - Two sets are <marker id="disjoint"></marker><em>disjoint</em> if their - intersection is the empty set. - The <marker id="difference"></marker><em>difference</em> of - two sets A and B is the set that contains all elements of A that - do not belong to B. - The <marker id="symmetric_difference"></marker><em>symmetric - difference</em> of - two sets is the set that contains those element that belong to - either of the two sets, but not both. - The <marker id="union_n"></marker><em>union</em> of a collection - of sets is the smallest set that contains all the elements that - belong to at least one set of the collection. - The <marker id="intersection_n"></marker><em>intersection</em> of - a non-empty collection of sets is the set that contains all elements - that belong to every set of the collection.</p> - <p>The <marker id="Cartesian_product"></marker><em>Cartesian - product</em> of - two sets X and Y, denoted X × Y, is the set - {a : a = (x, y) for some x in X and for - some y in Y}. - A <marker id="relation"></marker><em>relation</em> is a subset of - X × Y. Let R be a relation. The fact that - (x, y) belongs to R is written as x R y. Since - relations are sets, the definitions of the last paragraph - (subset, union, and so on) apply to relations as well. - The <marker id="domain"></marker><em>domain</em> of R is the - set {x : x R y for some y in Y}. - The <marker id="range"></marker><em>range</em> of R is the - set {y : x R y for some x in X}. - The <marker id="converse"></marker><em>converse</em> of R is the - set {a : a = (y, x) for some - (x, y) in R}. If A is a subset of X, then - the <marker id="image"></marker><em>image</em> of - A under R is the set {y : x R y for some - x in A}, and if B is a subset of Y, then - the <marker id="inverse_image"></marker><em>inverse image</em> of B is - the set {x : x R y for some y in B}. If R is a - relation from X to Y and S is a relation from Y to Z, then - the <marker id="relative_product"></marker><em>relative product</em> of - R and S is the relation T from X to Z defined so that x T z - if and only if there exists an element y in Y such that - x R y and y S z. - The <marker id="restriction"></marker><em>restriction</em> of R to A is - the set S defined so that x S y if and only if there exists an - element x in A such that x R y. If S is a restriction - of R to A, then R is - an <marker id="extension"></marker><em>extension</em> of S to X. - If X = Y then we call R a relation <em>in</em> X. - The <marker id="field"></marker><em>field</em> of a relation R in X - is the union of the domain of R and the range of R. - If R is a relation in X, and - if S is defined so that x S y if x R y and - not x = y, then S is - the <marker id="strict_relation"></marker><em>strict</em> relation - corresponding to - R, and vice versa, if S is a relation in X, and if R is defined - so that x R y if x S y or x = y, - then R is the <marker id="weak_relation"></marker><em>weak</em> relation - corresponding to S. A relation R in X is <em>reflexive</em> if - x R x for every element x of X; it is - <em>symmetric</em> if x R y implies that - y R x; and it is <em>transitive</em> if - x R y and y R z imply that x R z.</p> - <p>A <marker id="function"></marker><em>function</em> F is a relation, a - subset of X × Y, such that the domain of F is - equal to X and such that for every x in X there is a unique - element y in Y with (x, y) in F. The latter condition can - be formulated as follows: if x F y and x F z - then y = z. In this module, it will not be required - that the domain of F be equal to X for a relation to be - considered a function. Instead of writing - (x, y) in F or x F y, we write - F(x) = y when F is a function, and say that F maps x - onto y, or that the value of F at x is y. Since functions are - relations, the definitions of the last paragraph (domain, range, - and so on) apply to functions as well. If the converse of a - function F is a function F', then F' is called - the <marker id="inverse"></marker><em>inverse</em> of F. - The relative product of two functions F1 and F2 is called - the <marker id="composite"></marker><em>composite</em> of F1 and F2 - if the range of F1 is a subset of the domain of F2. </p> - <p>Sometimes, when the range of a function is more important than - the function itself, the function is called a <em>family</em>. - The domain of a family is called the <em>index set</em>, and the - range is called the <em>indexed set</em>. If x is a family from - I to X, then x[i] denotes the value of the function at index i. - The notation "a family in X" is used for such a family. When the - indexed set is a set of subsets of a set X, then we call x - a <marker id="family"></marker><em>family of subsets</em> of X. If x - is a family of subsets of X, then the union of the range of x is - called the <em>union of the family</em> x. If x is non-empty - (the index set is non-empty), - the <em>intersection of the family</em> x is the intersection of - the range of x. In this - module, the only families that will be considered are families - of subsets of some set X; in the following the word "family" - will be used for such families of subsets.</p> - <p>A <marker id="partition"></marker><em>partition</em> of a set X is a - collection S of non-empty subsets of X whose union is X and - whose elements are pairwise disjoint. A relation in a set is an - <em>equivalence relation</em> if it is reflexive, symmetric and - transitive. If R is an equivalence relation in X, and x is an - element of X, - the <marker id="equivalence_class"></marker><em>equivalence - class</em> of x with respect to R is the set of all those - elements y of X for which x R y holds. The equivalence - classes constitute a partitioning of X. Conversely, if C is a - partition of X, then the relation that holds for any two - elements of X if they belong to the same equivalence class, is - an equivalence relation induced by the partition C. If R is an - equivalence relation in X, then - the <marker id="canonical_map"></marker><em>canonical map</em> is - the function that maps every element of X onto its equivalence class. - </p> - <p><marker id="binary_relation"></marker>Relations as defined above - (as sets of ordered pairs) will from now on be referred to as - <em>binary relations</em>. We call a set of ordered sets - (x[1], ..., x[n]) an <marker id="n_ary_relation"></marker> - <em>(n-ary) relation</em>, and say that the relation is a subset of - the <marker id="Cartesian_product_tuple"></marker>Cartesian product - X[1] × ... × X[n] where x[i] is - an element of X[i], 1 <= i <= n. - The <marker id="projection"></marker><em>projection</em> of an n-ary - relation R onto coordinate i is the set {x[i] : - (x[1], ..., x[i], ..., x[n]) in R for some - x[j] in X[j], 1 <= j <= n - and not i = j}. The projections of a binary relation R - onto the first and second coordinates are the domain and the - range of R respectively. The relative product of binary - relations can be generalized to n-ary relations as follows. Let - TR be an ordered set (R[1], ..., R[n]) of binary - relations from X to Y[i] and S a binary relation from - (Y[1] × ... × Y[n]) to Z. - The <marker id="tuple_relative_product"></marker><em>relative - product</em> of - TR and S is the binary relation T from X to Z defined so that - x T z if and only if there exists an element y[i] in - Y[i] for each 1 <= i <= n such that - x R[i] y[i] and - (y[1], ..., y[n]) S z. Now let TR be a an - ordered set (R[1], ..., R[n]) of binary relations from - X[i] to Y[i] and S a subset of - X[1] × ... × X[n]. - The <marker id="multiple_relative_product"></marker><em>multiple - relative product</em> of TR and S is defined to be the - set {z : z = ((x[1], ..., x[n]), (y[1],...,y[n])) - for some (x[1], ..., x[n]) in S and for some - (x[i], y[i]) in R[i], - 1 <= i <= n}. - The <marker id="natural_join"></marker><em>natural join</em> of - an n-ary relation R - and an m-ary relation S on coordinate i and j is defined to be - the set {z : z = (x[1], ..., x[n], - y[1], ..., y[j-1], y[j+1], ..., y[m]) - for some (x[1], ..., x[n]) in R and for some - (y[1], ..., y[m]) in S such that - x[i] = y[j]}.</p> - <p><marker id="sets_definition"></marker>The sets recognized by this - module will be represented by elements of the relation Sets, defined as - the smallest set such that:</p> + specified elements is known (as is always the case in this + module), this is denoted B = {x : S(x)}.</p> + <list type="bulleted"> - <item>for every atom T except '_' and for every term X, - (T, X) belongs to Sets (<em>atomic sets</em>); + <item> + <p>The <em>unordered set</em> containing the elements a, b, and c is + denoted {a, b, c}. This notation is not to be confused with + tuples.</p> + <p>The <em>ordered pair</em> of a and b, with first <em>coordinate</em> + a and second coordinate b, is denoted (a, b). An ordered pair + is an <em>ordered set</em> of two elements. In this module, ordered + sets can contain one, two, or more elements, and parentheses are + used to enclose the elements.</p> + <p>Unordered sets and ordered sets are orthogonal, again in this + module; there is no unordered set equal to any ordered set.</p> </item> - <item>(['_'], []) belongs to Sets (the <em>untyped empty set</em>); + <item> + <p>The <em>empty set</em> contains no elements.</p> + <p>Set A is <marker id="equal"></marker><em>equal</em> to set B if they + contain the same elements, which is denoted A = B. Two + ordered sets are equal if they contain the same number of elements + and have equal elements at each coordinate.</p> + <p>Set B is a <marker id="subset"></marker><em>subset</em> of set A + if A contains all elements that B contains.</p> + <p>The <marker id="union"></marker><em>union</em> of two sets A and B + is the smallest set that contains all elements of A and all elements + of B.</p> + <p>The <marker id="intersection"></marker><em>intersection</em> of two + sets A and B is the set that contains all elements of A that belong + to B.</p> + <p>Two sets are <marker id="disjoint"></marker><em>disjoint</em> if + their intersection is the empty set.</p> + <p>The <marker id="difference"></marker><em>difference</em> of two sets + A and B is the set that contains all elements of A that do not belong + to B.</p> + <p>The <marker id="symmetric_difference"></marker><em>symmetric + difference</em> of two sets is the set that contains those element + that belong to either of the two sets, but not both.</p> + <p>The <marker id="union_n"></marker><em>union</em> of a collection + of sets is the smallest set that contains all the elements that + belong to at least one set of the collection.</p> + <p>The <marker id="intersection_n"></marker><em>intersection</em> of + a non-empty collection of sets is the set that contains all elements + that belong to every set of the collection.</p> </item> - <item>for every tuple T = {T[1], ..., T[n]} and - for every tuple X = {X[1], ..., X[n]}, if - (T[i], X[i]) belongs to Sets for every - 1 <= i <= n then (T, X) belongs - to Sets (<em>ordered sets</em>); + <item> + <p>The <marker id="Cartesian_product"></marker><em>Cartesian + product</em> of two sets X and Y, denoted X × Y, is + the set {a : a = (x, y) for some x in X and + for some y in Y}.</p> + <p>A <marker id="relation"></marker><em>relation</em> is a subset of + X × Y. Let R be a relation. The fact that (x, y) + belongs to R is written as x R y. As relations are sets, + the definitions of the last item (subset, union, and so on) apply to + relations as well.</p> + <p>The <marker id="domain"></marker><em>domain</em> of R is the set + {x : x R y for some y in Y}.</p> + <p>The <marker id="range"></marker><em>range</em> of R is the set + {y : x R y for some x in X}.</p> + <p>The <marker id="converse"></marker><em>converse</em> of R is the + set {a : a = (y, x) for some + (x, y) in R}.</p> + <p>If A is a subset of X, the <marker id="image"></marker><em>image</em> + of A under R is the set {y : x R y for some + x in A}. If B is a subset of Y, the + <marker id="inverse_image"></marker><em>inverse image</em> of B is the + set {x : x R y for some y in B}.</p> + <p>If R is a relation from X to Y, and S is a relation from Y to Z, the + <marker id="relative_product"></marker><em>relative product</em> of R + and S is the relation T from X to Z defined so that x T z + if and only if there exists an element y in Y such that + x R y and y S z.</p> + <p>The <marker id="restriction"></marker><em>restriction</em> of R to A + is the set S defined so that x S y if and only if there + exists an element x in A such that x R y.</p> + <p>If S is a restriction of R to A, then R is an + <marker id="extension"></marker><em>extension</em> of S to X.</p> + <p>If X = Y, then R is called a relation <em>in</em> X.</p> + <p>The <marker id="field"></marker><em>field</em> of a relation R in X + is the union of the domain of R and the range of R.</p> + <p>If R is a relation in X, and if S is defined so that x S y + if x R y and not x = y, then S is the + <marker id="strict_relation"></marker><em>strict</em> relation + corresponding to R. Conversely, if S is a relation in X, and if R is + defined so that x R y if x S y or x = y, + then R is the <marker id="weak_relation"></marker><em>weak</em> + relation corresponding to S.</p> + <p>A relation R in X is <em>reflexive</em> if x R x for every + element x of X, it is <em>symmetric</em> if x R y implies + that y R x, and it is <em>transitive</em> if + x R y and y R z imply that x R z.</p> + </item> + <item> + <p>A <marker id="function"></marker><em>function</em> F is a relation, + a subset of X × Y, such that the domain of F is equal + to X and such that for every x in X there is a unique element y in Y + with (x, y) in F. The latter condition can be formulated as + follows: if x F y and x F z, then y = z. + In this module, it is not required that the domain of F is equal to X + for a relation to be considered a function.</p> + <p>Instead of writing (x, y) in F or x F y, we + write F(x) = y when F is a function, and say that F maps x + onto y, or that the value of F at x is y.</p> + <p>As functions are relations, the definitions of the last item (domain, + range, and so on) apply to functions as well.</p> + <p>If the converse of a function F is a function F', then F' is called + the <marker id="inverse"></marker><em>inverse</em> of F.</p> + <p>The relative product of two functions F1 and F2 is called + the <marker id="composite"></marker><em>composite</em> of F1 and F2 + if the range of F1 is a subset of the domain of F2.</p> + </item> + <item> + <p>Sometimes, when the range of a function is more important than the + function itself, the function is called a <em>family</em>.</p> + <p>The domain of a family is called the <em>index set</em>, and the + range is called the <em>indexed set</em>.</p> + <p>If x is a family from I to X, then x[i] denotes the value of the + function at index i. The notation "a family in X" is used for such a + family.</p> + <p>When the indexed set is a set of subsets of a set X, we call x a + <marker id="family"></marker><em>family of subsets</em> of X.</p> + <p>If x is a family of subsets of X, the union of the range of x is + called the <em>union of the family</em> x.</p> + <p>If x is non-empty (the index set is non-empty), the <em>intersection + of the family</em> x is the intersection of the range of x.</p> + <p>In this module, the only families that are considered are families + of subsets of some set X; in the following, the word "family" is + used for such families of subsets.</p> + </item> + <item> + <p>A <marker id="partition"></marker><em>partition</em> of a set X is a + collection S of non-empty subsets of X whose union is X and whose + elements are pairwise disjoint.</p> + <p>A relation in a set is an <em>equivalence relation</em> if it is + reflexive, symmetric, and transitive.</p> + <p>If R is an equivalence relation in X, and x is an element of X, the + <marker id="equivalence_class"></marker><em>equivalence class</em> of + x with respect to R is the set of all those elements y of X for which + x R y holds. The equivalence classes constitute a + partitioning of X. Conversely, if C is a partition of X, the relation + that holds for any two elements of X if they belong to the same + equivalence class, is an equivalence relation induced by the + partition C.</p> + <p>If R is an equivalence relation in X, the + <marker id="canonical_map"></marker><em>canonical map</em> is the + function that maps every element of X onto its equivalence class.</p> + </item> + <item> + <p><marker id="binary_relation"></marker>Relations as defined above + (as sets of ordered pairs) are from now on referred to as <em>binary + relations</em>.</p> + <p>We call a set of ordered sets (x[1], ..., x[n]) an + <marker id="n_ary_relation"></marker><em>(n-ary) relation</em>, and + say that the relation is a subset of the + <marker id="Cartesian_product_tuple"></marker>Cartesian product + X[1] × ... × X[n], where x[i] is + an element of X[i], 1 <= i <= n.</p> + <p>The <marker id="projection"></marker><em>projection</em> of an n-ary + relation R onto coordinate i is the set {x[i] : + (x[1], ..., x[i], ..., x[n]) in R for some + x[j] in X[j], 1 <= j <= n and + not i = j}. The projections of a binary relation R onto the + first and second coordinates are the domain and the range of R, + respectively.</p> + <p>The relative product of binary relations can be generalized to n-ary + relations as follows. Let TR be an ordered set + (R[1], ..., R[n]) of binary relations from X to Y[i] + and S a binary relation from + (Y[1] × ... × Y[n]) to Z. The + <marker id="tuple_relative_product"></marker><em>relative product</em> + of TR and S is the binary relation T from X to Z defined so that + x T z if and only if there exists an element y[i] in Y[i] + for each 1 <= i <= n such that + x R[i] y[i] and + (y[1], ..., y[n]) S z. Now let TR be a an + ordered set (R[1], ..., R[n]) of binary relations from + X[i] to Y[i] and S a subset of + X[1] × ... × X[n]. + The <marker id="multiple_relative_product"></marker><em>multiple + relative product</em> of TR and S is defined to be the set + {z : z = ((x[1], ..., x[n]), (y[1],...,y[n])) + for some (x[1], ..., x[n]) in S and for some + (x[i], y[i]) in R[i], 1 <= i <= n}.</p> + <p>The <marker id="natural_join"></marker><em>natural join</em> of an + n-ary relation R and an m-ary relation S on coordinate i and j is + defined to be the set + {z : z = (x[1], ..., x[n], + y[1], ..., y[j-1], y[j+1], ..., y[m]) + for some (x[1], ..., x[n]) in R and for some + (y[1], ..., y[m]) in S such that + x[i] = y[j]}.</p> + </item> + <item> + <p><marker id="sets_definition"></marker>The sets recognized by this + module are represented by elements of the relation Sets, which is + defined as the smallest set such that:</p> + <list type="bulleted"> + <item> + <p>For every atom T, except '_', and for every term X, + (T, X) belongs to Sets (<em>atomic sets</em>).</p> + </item> + <item> + <p>(['_'], []) belongs to Sets (the <em>untyped empty + set</em>).</p> + </item> + <item> + <p>For every tuple T = {T[1], ..., T[n]} and + for every tuple X = {X[1], ..., X[n]}, if + (T[i], X[i]) belongs to Sets for every + 1 <= i <= n, then (T, X) belongs + to Sets (<em>ordered sets</em>).</p> + </item> + <item> + <p>For every term T, if X is the empty list or a non-empty + sorted list [X[1], ..., X[n]] without duplicates + such that (T, X[i]) belongs to Sets for every + 1 <= i <= n, then ([T], X) + belongs to Sets (<em>typed unordered sets</em>).</p> + </item> + </list> + <p>An <marker id="external_set"></marker><em>external set</em> is an + element of the range of Sets.</p> + <p>A <marker id="type"></marker><em>type</em> is an element of the + domain of Sets.</p> + <p>If S is an element (T, X) of Sets, then T is a + <marker id="valid_type"></marker><em>valid type</em> of X, T is the + type of S, and X is the external set of S. + <seealso marker="#from_term/2"><c>from_term/2</c></seealso> creates a + set from a type and an Erlang term turned into an external set.</p> + <p>The sets represented by Sets are the elements of the range of + function Set from Sets to Erlang terms and sets of Erlang terms:</p> + <list type="bulleted"> + <item>Set(T,Term) = Term, where T is an atom</item> + <item>Set({T[1], ..., T[n]}, {X[1], ..., + X[n]}) = (Set(T[1], X[1]), ..., + Set(T[n], X[n]))</item> + <item>Set([T], [X[1], ..., X[n]]) = + {Set(T, X[1]), ..., Set(T, X[n])}</item> + <item>Set([T], []) = {}</item> + </list> + <p>When there is no risk of confusion, elements of Sets are identified + with the sets they represent. For example, if U is the result of + calling <seealso marker="#union/2"><c>union/2</c></seealso> with S1 + and S2 as arguments, then U is said to be the union of S1 and S2. + A more precise formulation is that Set(U) is the union of Set(S1) + and Set(S2).</p> </item> - <item>for every term T, if X is the empty list or a non-empty - sorted list [X[1], ..., X[n]] without duplicates - such that (T, X[i]) belongs to Sets for every - 1 <= i <= n, then ([T], X) - belongs to Sets (<em>typed unordered sets</em>).</item> - </list> - <p>An <marker id="external_set"></marker><em>external set</em> is an - element of the range of Sets. - A <marker id="type"></marker><em>type</em> - is an element of the domain of Sets. If S is an element - (T, X) of Sets, then T is - a <marker id="valid_type"></marker><em>valid type</em> of X, - T is the type of S, and X is the external set - of S. <seealso marker="#from_term">from_term/2</seealso> creates a - set from a type and an Erlang term turned into an external set.</p> - <p>The actual sets represented by Sets are the elements of the - range of the function Set from Sets to Erlang terms and sets of - Erlang terms:</p> - <list type="bulleted"> - <item>Set(T,Term) = Term, where T is an atom;</item> - <item>Set({T[1], ..., T[n]}, {X[1], ..., X[n]}) - = (Set(T[1], X[1]), ..., Set(T[n], X[n]));</item> - <item>Set([T], [X[1], ..., X[n]]) - = {Set(T, X[1]), ..., Set(T, X[n])};</item> - <item>Set([T], []) = {}.</item> </list> - <p>When there is no risk of confusion, elements of Sets will be - identified with the sets they represent. For instance, if U is - the result of calling <c>union/2</c> with S1 and S2 as - arguments, then U is said to be the union of S1 and S2. A more - precise formulation would be that Set(U) is the union of Set(S1) - and Set(S2).</p> + <p>The types are used to implement the various conditions that - sets need to fulfill. As an example, consider the relative + sets must fulfill. As an example, consider the relative product of two sets R and S, and recall that the relative product of R and S is defined if R is a binary relation to Y and - S is a binary relation from Y. The function that implements the relative - product, <seealso marker="#relprod_impl">relative_product/2</seealso>, checks + S is a binary relation from Y. The function that implements the + relative product, <seealso marker="#relative_product/2"> + <c>relative_product/2</c></seealso>, checks that the arguments represent binary relations by matching [{A,B}] against the type of the first argument (Arg1 say), and [{C,D}] against the type of the second argument (Arg2 say). The fact @@ -289,33 +314,51 @@ ensure that W is equal to Y. The untyped empty set is handled separately: its type, ['_'], matches the type of any unordered set.</p> - <p>A few functions of this module (<c>drestriction/3</c>, - <c>family_projection/2</c>, <c>partition/2</c>, - <c>partition_family/2</c>, <c>projection/2</c>, - <c>restriction/3</c>, <c>substitution/2</c>) accept an Erlang + + <p>A few functions of this module + (<seealso marker="#drestriction/3"><c>drestriction/3</c></seealso>, + <seealso marker="#family_projection/2"><c>family_projection/2</c></seealso>, + <seealso marker="#partition/2"><c>partition/2</c></seealso>, + <seealso marker="#partition_family/2"><c>partition_family/2</c></seealso>, + <seealso marker="#projection/2"><c>projection/2</c></seealso>, + <seealso marker="#restriction/3"><c>restriction/3</c></seealso>, + <seealso marker="#substitution/2"><c>substitution/2</c></seealso>) + accept an Erlang function as a means to modify each element of a given unordered set. <marker id="set_fun"></marker>Such a function, called - SetFun in the following, can be - specified as a functional object (fun), a tuple - <c>{external, Fun}</c>, or an integer. If SetFun is - specified as a fun, the fun is applied to each element of the - given set and the return value is assumed to be a set. If SetFun - is specified as a tuple <c>{external, Fun}</c>, Fun is applied - to the external set of each element of the given set and the - return value is assumed to be an external set. Selecting the - elements of an unordered set as external sets and assembling a - new unordered set from a list of external sets is in the present - implementation more efficient than modifying each element as a - set. However, this optimization can only be utilized when the - elements of the unordered set are atomic or ordered sets. It - must also be the case that the type of the elements matches some - clause of Fun (the type of the created set is the result of - applying Fun to the type of the given set), and that Fun does - nothing but selecting, duplicating or rearranging parts of the - elements. Specifying a SetFun as an integer I is equivalent to - specifying <c>{external, fun(X) -> element(I, X) end}</c>, - but is to be preferred since it makes it possible to handle this - case even more efficiently. Examples of SetFuns:</p> + SetFun in the following, can be specified as a functional object (fun), + a tuple <c>{external, Fun}</c>, or an integer:</p> + + <list type="bulleted"> + <item> + <p>If SetFun is specified as a fun, the fun is applied to each element + of the given set and the return value is assumed to be a set.</p> + </item> + <item> + <p>If SetFun is specified as a tuple <c>{external, Fun}</c>, Fun is + applied to the external set of each element of the given set and the + return value is assumed to be an external set. Selecting the + elements of an unordered set as external sets and assembling a + new unordered set from a list of external sets is in the present + implementation more efficient than modifying each element as a + set. However, this optimization can only be used when the + elements of the unordered set are atomic or ordered sets. It + must also be the case that the type of the elements matches some + clause of Fun (the type of the created set is the result of + applying Fun to the type of the given set), and that Fun does + nothing but selecting, duplicating, or rearranging parts of the + elements.</p> + </item> + <item> + <p>Specifying a SetFun as an integer I is equivalent to + specifying <c>{external, fun(X) -> + element(I, X) end}</c>, but is to be preferred, as it + makes it possible to handle this case even more efficiently.</p> + </item> + </list> + + <p>Examples of SetFuns:</p> + <pre> fun sofs:union/1 fun(S) -> sofs:partition(1, S) end @@ -324,22 +367,31 @@ fun(S) -> sofs:partition(1, S) end {external, fun({_,{_,C}}) -> C end} {external, fun({_,{_,{_,E}=C}}) -> {E,{E,C}} end} 2</pre> + <p>The order in which a SetFun is applied to the elements of an - unordered set is not specified, and may change in future - versions of sofs.</p> + unordered set is not specified, and can change in future + versions of this module.</p> + <p>The execution time of the functions of this module is dominated by the time it takes to sort lists. When no sorting is needed, the execution time is in the worst case proportional to the sum of the sizes of the input arguments and the returned value. A - few functions execute in constant time: <c>from_external</c>, - <c>is_empty_set</c>, <c>is_set</c>, <c>is_sofs_set</c>, - <c>to_external</c>, <c>type</c>.</p> + few functions execute in constant time: + <seealso marker="#from_external/2"><c>from_external/2</c></seealso>, + <seealso marker="#is_empty_set/1"><c>is_empty_set/1</c></seealso>, + <seealso marker="#is_set/1"><c>is_set/1</c></seealso>, + <seealso marker="#is_sofs_set/1"><c>is_sofs_set/1</c></seealso>, + <seealso marker="#to_external/1"><c>to_external/1</c></seealso> + <seealso marker="#type/1"><c>type/1</c></seealso>.</p> + <p>The functions of this module exit the process with a <c>badarg</c>, <c>bad_function</c>, or <c>type_mismatch</c> message when given badly formed arguments or sets the types of which are not compatible.</p> - <p>When comparing external sets the operator <c>==/2</c> is used.</p> + + <p>When comparing external sets, operator <c>==/2</c> is used.</p> </description> + <datatypes> <datatype> <name name="anyset"></name> @@ -397,10 +449,11 @@ fun(S) -> sofs:partition(1, S) end </datatype> <datatype> <!-- Parameterized opaque types are NYI: --> - <name><marker id="type-tuple_of">tuple_of(T)</marker></name> + <name>tuple_of(T)</name> <desc><p>A tuple where the elements are of type <c>T</c>.</p></desc> </datatype> </datatypes> + <funcs> <func> <name name="a_function" arity="1"/> @@ -409,24 +462,25 @@ fun(S) -> sofs:partition(1, S) end <desc> <p>Creates a <seealso marker="#function">function</seealso>. <c>a_function(F, T)</c> is equivalent to - <c>from_term(F, T)</c>, if the result is a function. If + <c>from_term(F, T)</c> if the result is a function. If no <seealso marker="#type">type</seealso> is explicitly - given, <c>[{atom, atom}]</c> is used as type of the - function.</p> + specified, <c>[{atom, atom}]</c> is used as the + function type.</p> </desc> </func> + <func> <name name="canonical_relation" arity="1"/> <fsummary>Return the canonical map.</fsummary> <desc> <p>Returns the binary relation containing the elements - (E, Set) such that Set belongs to <anno>SetOfSets</anno> and E - belongs to Set. If SetOfSets is - a <seealso marker="#partition">partition</seealso> of a set X and - R is the equivalence relation in X induced by SetOfSets, then the - returned relation is - the <seealso marker="#canonical_map">canonical map</seealso> from - X onto the equivalence classes with respect to R.</p> + (E, Set) such that Set belongs to <c><anno>SetOfSets</anno></c> + and E belongs to Set. If <c>SetOfSets</c> is + a <seealso marker="#partition">partition</seealso> of a set X and + R is the equivalence relation in X induced by <c>SetOfSets</c>, + then the returned relation is + the <seealso marker="#canonical_map">canonical map</seealso> from + X onto the equivalence classes with respect to R.</p> <pre> 1> <input>Ss = sofs:from_term([[a,b],[b,c]]),</input> <input>CR = sofs:canonical_relation(Ss),</input> @@ -434,13 +488,14 @@ fun(S) -> sofs:partition(1, S) end [{a,[a,b]},{b,[a,b]},{b,[b,c]},{c,[b,c]}]</pre> </desc> </func> + <func> <name name="composite" arity="2"/> <fsummary>Return the composite of two functions.</fsummary> <desc> <p>Returns the <seealso marker="#composite">composite</seealso> of - the functions <anno>Function1</anno> and - <anno>Function2</anno>.</p> + the functions <c><anno>Function1</anno></c> and + <c><anno>Function2</anno></c>.</p> <pre> 1> <input>F1 = sofs:a_function([{a,1},{b,2},{c,2}]),</input> <input>F2 = sofs:a_function([{1,x},{2,y},{3,z}]),</input> @@ -449,13 +504,14 @@ fun(S) -> sofs:partition(1, S) end [{a,x},{b,y},{c,y}]</pre> </desc> </func> + <func> <name name="constant_function" arity="2"/> - <fsummary>Create the function that maps each element of a + <fsummary>Create the function that maps each element of a set onto another set.</fsummary> <desc> <p>Creates the <seealso marker="#function">function</seealso> - that maps each element of the set Set onto AnySet.</p> + that maps each element of set <c>Set</c> onto <c>AnySet</c>.</p> <pre> 1> <input>S = sofs:set([a,b]),</input> <input>E = sofs:from_term(1),</input> @@ -464,12 +520,13 @@ fun(S) -> sofs:partition(1, S) end [{a,1},{b,1}]</pre> </desc> </func> + <func> <name name="converse" arity="1"/> <fsummary>Return the converse of a binary relation.</fsummary> <desc> <p>Returns the <seealso marker="#converse">converse</seealso> - of the binary relation <anno>BinRel1</anno>.</p> + of the binary relation <c><anno>BinRel1</anno></c>.</p> <pre> 1> <input>R1 = sofs:relation([{1,a},{2,b},{3,a}]),</input> <input>R2 = sofs:converse(R1),</input> @@ -477,39 +534,42 @@ fun(S) -> sofs:partition(1, S) end [{a,1},{a,3},{b,2}]</pre> </desc> </func> + <func> <name name="difference" arity="2"/> <fsummary>Return the difference of two sets.</fsummary> <desc> - <p>Returns the <seealso marker="#difference">difference</seealso> of - the sets <anno>Set1</anno> and <anno>Set2</anno>.</p> + <p>Returns the <seealso marker="#difference">difference</seealso> of + the sets <c><anno>Set1</anno></c> and <c><anno>Set2</anno></c>.</p> </desc> </func> + <func> <name name="digraph_to_family" arity="1"/> <name name="digraph_to_family" arity="2"/> <fsummary>Create a family from a directed graph.</fsummary> <desc> <p>Creates a <seealso marker="#family">family</seealso> from - the directed graph <anno>Graph</anno>. Each vertex a of - <anno>Graph</anno> is - represented by a pair (a, {b[1], ..., b[n]}) - where the b[i]'s are the out-neighbours of a. If no type is - explicitly given, [{atom, [atom]}] is used as type of - the family. It is assumed that <anno>Type</anno> is - a <seealso marker="#valid_type">valid type</seealso> of the - external set of the family.</p> + the directed graph <c><anno>Graph</anno></c>. Each vertex a of + <c><anno>Graph</anno></c> is + represented by a pair (a, {b[1], ..., b[n]}), + where the b[i]:s are the out-neighbors of a. If no type is + explicitly specified, [{atom, [atom]}] is used as type of + the family. It is assumed that <c><anno>Type</anno></c> is + a <seealso marker="#valid_type">valid type</seealso> of the + external set of the family.</p> <p>If G is a directed graph, it holds that the vertices and edges of G are the same as the vertices and edges of <c>family_to_digraph(digraph_to_family(G))</c>.</p> </desc> </func> + <func> <name name="domain" arity="1"/> <fsummary>Return the domain of a binary relation.</fsummary> <desc> - <p>Returns the <seealso marker="#domain">domain</seealso> of - the binary relation <anno>BinRel</anno>.</p> + <p>Returns the <seealso marker="#domain">domain</seealso> of + the binary relation <c><anno>BinRel</anno></c>.</p> <pre> 1> <input>R = sofs:relation([{1,a},{1,b},{2,b},{2,c}]),</input> <input>S = sofs:domain(R),</input> @@ -517,14 +577,15 @@ fun(S) -> sofs:partition(1, S) end [1,2]</pre> </desc> </func> + <func> <name name="drestriction" arity="2"/> <fsummary>Return a restriction of a binary relation.</fsummary> <desc> <p>Returns the difference between the binary relation - <anno>BinRel1</anno> + <c><anno>BinRel1</anno></c> and the <seealso marker="#restriction">restriction</seealso> - of <anno>BinRel1</anno> to <anno>Set</anno>.</p> + of <c><anno>BinRel1</anno></c> to <c><anno>Set</anno></c>.</p> <pre> 1> <input>R1 = sofs:relation([{1,a},{2,b},{3,c}]),</input> <input>S = sofs:set([2,4,6]),</input> @@ -535,14 +596,15 @@ fun(S) -> sofs:partition(1, S) end <c>difference(R, restriction(R, S))</c>.</p> </desc> </func> + <func> <name name="drestriction" arity="3"/> <fsummary>Return a restriction of a relation.</fsummary> <desc> - <p>Returns a subset of <anno>Set1</anno> containing those elements - that do - not yield an element in <anno>Set2</anno> as the result of applying - <anno>SetFun</anno>.</p> + <p>Returns a subset of <c><anno>Set1</anno></c> containing those + elements that do not give + an element in <c><anno>Set2</anno></c> as the result of applying + <c><anno>SetFun</anno></c>.</p> <pre> 1> <input>SetFun = {external, fun({_A,B,C}) -> {B,C} end},</input> <input>R1 = sofs:relation([{a,aa,1},{b,bb,2},{c,cc,3}]),</input> @@ -554,24 +616,27 @@ fun(S) -> sofs:partition(1, S) end <c>difference(S1, restriction(F, S1, S2))</c>.</p> </desc> </func> + <func> <name name="empty_set" arity="0"/> <fsummary>Return the untyped empty set.</fsummary> <desc> - <p>Returns the <seealso marker="#sets_definition">untyped empty + <p>Returns the <seealso marker="#sets_definition">untyped empty set</seealso>. <c>empty_set()</c> is equivalent to <c>from_term([], ['_'])</c>.</p> </desc> </func> + <func> <name name="extension" arity="3"/> <fsummary>Extend the domain of a binary relation.</fsummary> <desc> - <p>Returns the <seealso marker="#extension">extension</seealso> of - <anno>BinRel1</anno> such that - for each element E in <anno>Set</anno> that does not belong to the - <seealso marker="#domain">domain</seealso> of <anno>BinRel1</anno>, - <anno>BinRel2</anno> contains the pair (E, AnySet).</p> + <p>Returns the <seealso marker="#extension">extension</seealso> of + <c><anno>BinRel1</anno></c> such that for + each element E in <c><anno>Set</anno></c> that does not belong to the + <seealso marker="#domain">domain</seealso> of + <c><anno>BinRel1</anno></c>, <c><anno>BinRel2</anno></c> contains the + pair (E, <c>AnySet</c>).</p> <pre> 1> <input>S = sofs:set([b,c]),</input> <input>A = sofs:empty_set(),</input> @@ -581,31 +646,33 @@ fun(S) -> sofs:partition(1, S) end [{a,[1,2]},{b,[3]},{c,[]}]</pre> </desc> </func> + <func> <name name="family" arity="1"/> <name name="family" arity="2"/> <fsummary>Create a family of subsets.</fsummary> <desc> - <p>Creates a <seealso marker="#family">family of subsets</seealso>. - <c>family(F, T)</c> is equivalent to - <c>from_term(F, T)</c>, if the result is a family. If + <p>Creates a <seealso marker="#family">family of subsets</seealso>. + <c>family(F, T)</c> is equivalent to + <c>from_term(F, T)</c> if the result is a family. If no <seealso marker="#type">type</seealso> is explicitly - given, <c>[{atom, [atom]}]</c> is used as type of the - family.</p> + specified, <c>[{atom, [atom]}]</c> is used as the + family type.</p> </desc> </func> + <func> <name name="family_difference" arity="2"/> <fsummary>Return the difference of two families.</fsummary> <desc> - <p>If <anno>Family1</anno> and <anno>Family2</anno> - are <seealso marker="#family">families</seealso>, then - <anno>Family3</anno> is the family + <p>If <c><anno>Family1</anno></c> and <c><anno>Family2</anno></c> + are <seealso marker="#family">families</seealso>, then + <c><anno>Family3</anno></c> is the family such that the index set is equal to the index set of - <anno>Family1</anno>, and <anno>Family3</anno>[i] is the - difference between <anno>Family1</anno>[i] - and <anno>Family2</anno>[i] if <anno>Family2</anno> maps i, - <anno>Family1</anno>[i] otherwise.</p> + <c><anno>Family1</anno></c>, and <c><anno>Family3</anno></c>[i] is + the difference between <c><anno>Family1</anno></c>[i] + and <c><anno>Family2</anno></c>[i] if <c><anno>Family2</anno></c> + maps i, otherwise <c><anno>Family1</anno>[i]</c>.</p> <pre> 1> <input>F1 = sofs:family([{a,[1,2]},{b,[3,4]}]),</input> <input>F2 = sofs:family([{b,[4,5]},{c,[6,7]}]),</input> @@ -614,19 +681,20 @@ fun(S) -> sofs:partition(1, S) end [{a,[1,2]},{b,[3]}]</pre> </desc> </func> + <func> <name name="family_domain" arity="1"/> <fsummary>Return a family of domains.</fsummary> <desc> - <p>If <anno>Family1</anno> is + <p>If <c><anno>Family1</anno></c> is a <seealso marker="#family">family</seealso> - and <anno>Family1</anno>[i] is a binary relation for every i - in the index set of <anno>Family1</anno>, - then <anno>Family2</anno> is the family with the same index - set as <anno>Family1</anno> such - that <anno>Family2</anno>[i] is + and <c><anno>Family1</anno></c>[i] is a binary relation for every i + in the index set of <c><anno>Family1</anno></c>, + then <c><anno>Family2</anno></c> is the family with the same index + set as <c><anno>Family1</anno></c> such + that <c><anno>Family2</anno></c>[i] is the <seealso marker="#domain">domain</seealso> of - <anno>Family1</anno>[i].</p> + <c><anno>Family1</anno>[i]</c>.</p> <pre> 1> <input>FR = sofs:from_term([{a,[{1,a},{2,b},{3,c}]},{b,[]},{c,[{4,d},{5,e}]}]),</input> <input>F = sofs:family_domain(FR),</input> @@ -634,43 +702,46 @@ fun(S) -> sofs:partition(1, S) end [{a,[1,2,3]},{b,[]},{c,[4,5]}]</pre> </desc> </func> + <func> <name name="family_field" arity="1"/> <fsummary>Return a family of fields.</fsummary> <desc> - <p>If <anno>Family1</anno> is + <p>If <c><anno>Family1</anno></c> is a <seealso marker="#family">family</seealso> - and <anno>Family1</anno>[i] is a binary relation for every i - in the index set of <anno>Family1</anno>, - then <anno>Family2</anno> is the family with the same index - set as <anno>Family1</anno> such - that <anno>Family2</anno>[i] is + and <c><anno>Family1</anno></c>[i] is a binary relation for every i + in the index set of <c><anno>Family1</anno></c>, + then <c><anno>Family2</anno></c> is the family with the same index + set as <c><anno>Family1</anno></c> such + that <c><anno>Family2</anno></c>[i] is the <seealso marker="#field">field</seealso> of - <anno>Family1</anno>[i].</p> + <c><anno>Family1</anno></c>[i].</p> <pre> 1> <input>FR = sofs:from_term([{a,[{1,a},{2,b},{3,c}]},{b,[]},{c,[{4,d},{5,e}]}]),</input> <input>F = sofs:family_field(FR),</input> <input>sofs:to_external(F).</input> [{a,[1,2,3,a,b,c]},{b,[]},{c,[4,5,d,e]}]</pre> <p><c>family_field(Family1)</c> is equivalent to - <c>family_union(family_domain(Family1), family_range(Family1))</c>.</p> + <c>family_union(family_domain(Family1), + family_range(Family1))</c>.</p> </desc> </func> + <func> <name name="family_intersection" arity="1"/> <fsummary>Return the intersection of a family of sets of sets.</fsummary> <desc> - <p>If <anno>Family1</anno> is + <p>If <c><anno>Family1</anno></c> is a <seealso marker="#family">family</seealso> - and <anno>Family1</anno>[i] is a set of sets for every i in - the index set of <anno>Family1</anno>, - then <anno>Family2</anno> is the family with the same index - set as <anno>Family1</anno> such - that <anno>Family2</anno>[i] is + and <c><anno>Family1</anno></c>[i] is a set of sets for every i in + the index set of <c><anno>Family1</anno></c>, + then <c><anno>Family2</anno></c> is the family with the same index + set as <c><anno>Family1</anno></c> such + that <c><anno>Family2</anno></c>[i] is the <seealso marker="#intersection_n">intersection</seealso> - of <anno>Family1</anno>[i].</p> - <p>If <anno>Family1</anno>[i] is an empty set for some i, then + of <c><anno>Family1</anno></c>[i].</p> + <p>If <c><anno>Family1</anno></c>[i] is an empty set for some i, the process exits with a <c>badarg</c> message.</p> <pre> 1> <input>F1 = sofs:from_term([{a,[[1,2,3],[2,3,4]]},{b,[[x,y,z],[x,y]]}]),</input> @@ -679,17 +750,18 @@ fun(S) -> sofs:partition(1, S) end [{a,[2,3]},{b,[x,y]}]</pre> </desc> </func> + <func> <name name="family_intersection" arity="2"/> <fsummary>Return the intersection of two families.</fsummary> <desc> - <p>If <anno>Family1</anno> and <anno>Family2</anno> - are <seealso marker="#family">families</seealso>, - then <anno>Family3</anno> is the family such that the index - set is the intersection of <anno>Family1</anno>'s and - <anno>Family2</anno>'s index sets, - and <anno>Family3</anno>[i] is the intersection of - <anno>Family1</anno>[i] and <anno>Family2</anno>[i].</p> + <p>If <c><anno>Family1</anno></c> and <c><anno>Family2</anno></c> + are <seealso marker="#family">families</seealso>, + then <c><anno>Family3</anno></c> is the family such that the index + set is the intersection of <c><anno>Family1</anno></c>:s and + <c><anno>Family2</anno></c>:s index sets, + and <c><anno>Family3</anno></c>[i] is the intersection of + <c><anno>Family1</anno></c>[i] and <c><anno>Family2</anno></c>[i].</p> <pre> 1> <input>F1 = sofs:family([{a,[1,2]},{b,[3,4]},{c,[5,6]}]),</input> <input>F2 = sofs:family([{b,[4,5]},{c,[7,8]},{d,[9,10]}]),</input> @@ -698,17 +770,18 @@ fun(S) -> sofs:partition(1, S) end [{b,[4]},{c,[]}]</pre> </desc> </func> + <func> <name name="family_projection" arity="2"/> <fsummary>Return a family of modified subsets.</fsummary> <desc> - <p>If <anno>Family1</anno> is - a <seealso marker="#family">family</seealso> - then <anno>Family2</anno> is the family with the same index - set as <anno>Family1</anno> such - that <anno>Family2</anno>[i] is the result of - calling <anno>SetFun</anno> with <anno>Family1</anno>[i] as - argument.</p> + <p>If <c><anno>Family1</anno></c> is + a <seealso marker="#family">family</seealso>, + then <c><anno>Family2</anno></c> is the family with the same index + set as <c><anno>Family1</anno></c> such + that <c><anno>Family2</anno></c>[i] is the result of + calling <c><anno>SetFun</anno></c> with <c><anno>Family1</anno></c>[i] + as argument.</p> <pre> 1> <input>F1 = sofs:from_term([{a,[[1,2],[2,3]]},{b,[[]]}]),</input> <input>F2 = sofs:family_projection(fun sofs:union/1, F1),</input> @@ -716,19 +789,20 @@ fun(S) -> sofs:partition(1, S) end [{a,[1,2,3]},{b,[]}]</pre> </desc> </func> + <func> <name name="family_range" arity="1"/> <fsummary>Return a family of ranges.</fsummary> <desc> - <p>If <anno>Family1</anno> is + <p>If <c><anno>Family1</anno></c> is a <seealso marker="#family">family</seealso> - and <anno>Family1</anno>[i] is a binary relation for every i - in the index set of <anno>Family1</anno>, - then <anno>Family2</anno> is the family with the same index - set as <anno>Family1</anno> such - that <anno>Family2</anno>[i] is + and <c><anno>Family1</anno></c>[i] is a binary relation for every i + in the index set of <c><anno>Family1</anno></c>, + then <c><anno>Family2</anno></c> is the family with the same index + set as <c><anno>Family1</anno></c> such + that <c><anno>Family2</anno></c>[i] is the <seealso marker="#range">range</seealso> of - <anno>Family1</anno>[i].</p> + <c><anno>Family1</anno></c>[i].</p> <pre> 1> <input>FR = sofs:from_term([{a,[{1,a},{2,b},{3,c}]},{b,[]},{c,[{4,d},{5,e}]}]),</input> <input>F = sofs:family_range(FR),</input> @@ -736,22 +810,23 @@ fun(S) -> sofs:partition(1, S) end [{a,[a,b,c]},{b,[]},{c,[d,e]}]</pre> </desc> </func> + <func> <name name="family_specification" arity="2"/> <fsummary>Select a subset of a family using a predicate.</fsummary> <desc> - <p>If <anno>Family1</anno> is + <p>If <c><anno>Family1</anno></c> is a <seealso marker="#family">family</seealso>, - then <anno>Family2</anno> is + then <c><anno>Family2</anno></c> is the <seealso marker="#restriction">restriction</seealso> of - <anno>Family1</anno> to those elements i of the index set - for which <anno>Fun</anno> applied - to <anno>Family1</anno>[i] returns - <c>true</c>. If <anno>Fun</anno> is a - tuple <c>{external, Fun2}</c>, Fun2 is applied to + <c><anno>Family1</anno></c> to those elements i of the index set + for which <c><anno>Fun</anno></c> applied + to <c><anno>Family1</anno></c>[i] returns + <c>true</c>. If <c><anno>Fun</anno></c> is a + tuple <c>{external, Fun2}</c>, then <c>Fun2</c> is applied to the <seealso marker="#external_set">external set</seealso> - of <anno>Family1</anno>[i], otherwise <anno>Fun</anno> is - applied to <anno>Family1</anno>[i].</p> + of <c><anno>Family1</anno></c>[i], otherwise <c><anno>Fun</anno></c> + is applied to <c><anno>Family1</anno></c>[i].</p> <pre> 1> <input>F1 = sofs:family([{a,[1,2,3]},{b,[1,2]},{c,[1]}]),</input> <input>SpecFun = fun(S) -> sofs:no_elements(S) =:= 2 end,</input> @@ -760,23 +835,24 @@ fun(S) -> sofs:partition(1, S) end [{b,[1,2]}]</pre> </desc> </func> + <func> <name name="family_to_digraph" arity="1"/> <name name="family_to_digraph" arity="2"/> <fsummary>Create a directed graph from a family.</fsummary> <desc> - <p>Creates a directed graph from - the <seealso marker="#family">family</seealso> <anno>Family</anno>. + <p>Creates a directed graph from + <seealso marker="#family">family</seealso> <c><anno>Family</anno></c>. For each pair (a, {b[1], ..., b[n]}) - of <anno>Family</anno>, the vertex - a as well the edges (a, b[i]) for + of <c><anno>Family</anno></c>, vertex + a and the edges (a, b[i]) for 1 <= i <= n are added to a newly created directed graph.</p> - <p>If no graph type is given <seealso marker="digraph#new/0"> - digraph:new/0</seealso> is used for - creating the directed graph, otherwise the <anno>GraphType</anno> - argument is passed on as second argument to - <seealso marker="digraph#new/1">digraph:new/1</seealso>.</p> + <p>If no graph type is specified, <seealso marker="digraph#new/0"> + <c>digraph:new/0</c></seealso> is used for + creating the directed graph, otherwise argument + <c><anno>GraphType</anno></c> is passed on as second argument to + <seealso marker="digraph#new/1"><c>digraph:new/1</c></seealso>.</p> <p>It F is a family, it holds that F is a subset of <c>digraph_to_family(family_to_digraph(F), type(F))</c>. Equality holds if <c>union_of_family(F)</c> is a subset of @@ -785,16 +861,17 @@ fun(S) -> sofs:partition(1, S) end a <c>cyclic</c> message.</p> </desc> </func> + <func> <name name="family_to_relation" arity="1"/> <fsummary>Create a binary relation from a family.</fsummary> <desc> - <p>If <anno>Family</anno> is + <p>If <c><anno>Family</anno></c> is a <seealso marker="#family">family</seealso>, - then <anno>BinRel</anno> is the binary relation containing + then <c><anno>BinRel</anno></c> is the binary relation containing all pairs (i, x) such that i belongs to the index set - of <anno>Family</anno> and x belongs - to <anno>Family</anno>[i].</p> + of <c><anno>Family</anno></c> and x belongs + to <c><anno>Family</anno></c>[i].</p> <pre> 1> <input>F = sofs:family([{a,[]}, {b,[1]}, {c,[2,3]}]),</input> <input>R = sofs:family_to_relation(F),</input> @@ -802,19 +879,20 @@ fun(S) -> sofs:partition(1, S) end [{b,1},{c,2},{c,3}]</pre> </desc> </func> + <func> <name name="family_union" arity="1"/> <fsummary>Return the union of a family of sets of sets.</fsummary> <desc> - <p>If <anno>Family1</anno> is + <p>If <c><anno>Family1</anno></c> is a <seealso marker="#family">family</seealso> - and <anno>Family1</anno>[i] is a set of sets for each i in - the index set of <anno>Family1</anno>, - then <anno>Family2</anno> is the family with the same index - set as <anno>Family1</anno> such - that <anno>Family2</anno>[i] is + and <c><anno>Family1</anno></c>[i] is a set of sets for each i in + the index set of <c><anno>Family1</anno></c>, + then <c><anno>Family2</anno></c> is the family with the same index + set as <c><anno>Family1</anno></c> such + that <c><anno>Family2</anno></c>[i] is the <seealso marker="#union_n">union</seealso> of - <anno>Family1</anno>[i].</p> + <c><anno>Family1</anno></c>[i].</p> <pre> 1> <input>F1 = sofs:from_term([{a,[[1,2],[2,3]]},{b,[[]]}]),</input> <input>F2 = sofs:family_union(F1),</input> @@ -824,19 +902,20 @@ fun(S) -> sofs:partition(1, S) end <c>family_projection(fun sofs:union/1, F)</c>.</p> </desc> </func> + <func> <name name="family_union" arity="2"/> <fsummary>Return the union of two families.</fsummary> <desc> - <p>If <anno>Family1</anno> and <anno>Family2</anno> - are <seealso marker="#family">families</seealso>, - then <anno>Family3</anno> is the family such that the index - set is the union of <anno>Family1</anno>'s - and <anno>Family2</anno>'s index sets, - and <anno>Family3</anno>[i] is the union - of <anno>Family1</anno>[i] and <anno>Family2</anno>[i] if - both maps i, <anno>Family1</anno>[i] - or <anno>Family2</anno>[i] otherwise.</p> + <p>If <c><anno>Family1</anno></c> and <c><anno>Family2</anno></c> + are <seealso marker="#family">families</seealso>, + then <c><anno>Family3</anno></c> is the family such that the index + set is the union of <c><anno>Family1</anno></c>:s + and <c><anno>Family2</anno></c>:s index sets, + and <c><anno>Family3</anno></c>[i] is the union + of <c><anno>Family1</anno></c>[i] and <c><anno>Family2</anno></c>[i] + if both map i, otherwise <c><anno>Family1</anno></c>[i] + or <c><anno>Family2</anno></c>[i].</p> <pre> 1> <input>F1 = sofs:family([{a,[1,2]},{b,[3,4]},{c,[5,6]}]),</input> <input>F2 = sofs:family([{b,[4,5]},{c,[7,8]},{d,[9,10]}]),</input> @@ -845,40 +924,43 @@ fun(S) -> sofs:partition(1, S) end [{a,[1,2]},{b,[3,4,5]},{c,[5,6,7,8]},{d,[9,10]}]</pre> </desc> </func> + <func> <name name="field" arity="1"/> <fsummary>Return the field of a binary relation.</fsummary> <desc> <p>Returns the <seealso marker="#field">field</seealso> of the - binary relation <anno>BinRel</anno>.</p> + binary relation <c><anno>BinRel</anno></c>.</p> <pre> 1> <input>R = sofs:relation([{1,a},{1,b},{2,b},{2,c}]),</input> <input>S = sofs:field(R),</input> <input>sofs:to_external(S).</input> [1,2,a,b,c]</pre> - <p><c>field(R)</c> is equivalent - to <c>union(domain(R), range(R))</c>.</p> + <p><c>field(R)</c> is equivalent + to <c>union(domain(R), range(R))</c>.</p> </desc> </func> + <func> <name name="from_external" arity="2"/> <fsummary>Create a set.</fsummary> <desc> <p>Creates a set from the <seealso marker="#external_set">external - set</seealso> <anno>ExternalSet</anno> - and the <seealso marker="#type">type</seealso> <anno>Type</anno>. - It is assumed that <anno>Type</anno> is + set</seealso> <c><anno>ExternalSet</anno></c> and + the <seealso marker="#type">type</seealso> <c><anno>Type</anno></c>. + It is assumed that <c><anno>Type</anno></c> is a <seealso marker="#valid_type">valid - type</seealso> of <anno>ExternalSet</anno>.</p> + type</seealso> of <c><anno>ExternalSet</anno></c>.</p> </desc> </func> + <func> <name name="from_sets" arity="1" clause_i="1"/> <fsummary>Create a set out of a list of sets.</fsummary> <desc> - <p>Returns the <seealso marker="#sets_definition">unordered - set</seealso> containing the sets of the list - <anno>ListOfSets</anno>.</p> + <p>Returns the <seealso marker="#sets_definition">unordered + set</seealso> containing the sets of list + <c><anno>ListOfSets</anno></c>.</p> <pre> 1> <input>S1 = sofs:relation([{a,1},{b,2}]),</input> <input>S2 = sofs:relation([{x,3},{y,4}]),</input> @@ -887,31 +969,33 @@ fun(S) -> sofs:partition(1, S) end [[{a,1},{b,2}],[{x,3},{y,4}]]</pre> </desc> </func> + <func> <name name="from_sets" arity="1" clause_i="2"/> <fsummary>Create an ordered set out of a tuple of sets.</fsummary> <desc> - <p>Returns the <seealso marker="#sets_definition">ordered - set</seealso> containing the sets of the non-empty tuple - <anno>TupleOfSets</anno>.</p> + <p>Returns the <seealso marker="#sets_definition">ordered + set</seealso> containing the sets of the non-empty tuple + <c><anno>TupleOfSets</anno></c>.</p> </desc> </func> + <func> <name name="from_term" arity="1"/> <name name="from_term" arity="2"/> <fsummary>Create a set.</fsummary> <desc> - <p><marker id="from_term"></marker>Creates an element - of <seealso marker="#sets_definition">Sets</seealso> by - traversing the term <anno>Term</anno>, sorting lists, - removing duplicates and - deriving or verifying a <seealso marker="#valid_type">valid - type</seealso> for the so obtained external set. An - explicitly given <seealso marker="#type">type</seealso> - <anno>Type</anno> + <p><marker id="from_term"></marker>Creates an element + of <seealso marker="#sets_definition">Sets</seealso> by + traversing term <c><anno>Term</anno></c>, sorting lists, + removing duplicates, and + deriving or verifying a <seealso marker="#valid_type">valid + type</seealso> for the so obtained external set. An + explicitly specified <seealso marker="#type">type</seealso> + <c><anno>Type</anno></c> can be used to limit the depth of the traversal; an atomic - type stops the traversal, as demonstrated by this example - where "foo" and {"foo"} are left unmodified:</p> + type stops the traversal, as shown by the following example + where <c>"foo"</c> and <c>{"foo"}</c> are left unmodified:</p> <pre> 1> <input>S = sofs:from_term([{{"foo"},[1,1]},{"foo",[2,2]}], [{atom,[atom]}]),</input> @@ -919,12 +1003,12 @@ fun(S) -> sofs:partition(1, S) end [{{"foo"},[1]},{"foo",[2]}]</pre> <p><c>from_term</c> can be used for creating atomic or ordered sets. The only purpose of such a set is that of later - building unordered sets since all functions in this module + building unordered sets, as all functions in this module that <em>do</em> anything operate on unordered sets. Creating unordered sets from a collection of ordered sets - may be the way to go if the ordered sets are big and one + can be the way to go if the ordered sets are big and one does not want to waste heap by rebuilding the elements of - the unordered set. An example showing that a set can be + the unordered set. The following example shows that a set can be built "layer by layer":</p> <pre> 1> <input>A = sofs:from_term(a),</input> @@ -934,19 +1018,25 @@ fun(S) -> sofs:partition(1, S) end <input>Ss = sofs:from_sets([P1,P2]),</input> <input>sofs:to_external(Ss).</input> [{a,[1,2,3]},{b,[4,5,6]}]</pre> - <p>Other functions that create sets are <c>from_external/2</c> - and <c>from_sets/1</c>. Special cases of <c>from_term/2</c> - are <c>a_function/1,2</c>, <c>empty_set/0</c>, - <c>family/1,2</c>, <c>relation/1,2</c>, and <c>set/1,2</c>.</p> + <p>Other functions that create sets are + <seealso marker="#from_external/2"><c>from_external/2</c></seealso> + and <seealso marker="#from_sets/1"><c>from_sets/1</c></seealso>. + Special cases of <c>from_term/2</c> are + <seealso marker="#a_function/1"><c>a_function/1,2</c></seealso>, + <seealso marker="#empty_set/0"><c>empty_set/0</c></seealso>, + <seealso marker="#family/1"><c>family/1,2</c></seealso>, + <seealso marker="#relation/1"><c>relation/1,2</c></seealso>, and + <seealso marker="#set/1"><c>set/1,2</c></seealso>.</p> </desc> </func> + <func> <name name="image" arity="2"/> <fsummary>Return the image of a set under a binary relation.</fsummary> <desc> - <p>Returns the <seealso marker="#image">image</seealso> of the - set <anno>Set1</anno> under the binary - relation <anno>BinRel</anno>.</p> + <p>Returns the <seealso marker="#image">image</seealso> of + set <c><anno>Set1</anno></c> under the binary + relation <c><anno>BinRel</anno></c>.</p> <pre> 1> <input>R = sofs:relation([{1,a},{2,b},{2,c},{3,d}]),</input> <input>S1 = sofs:set([1,2]),</input> @@ -955,32 +1045,35 @@ fun(S) -> sofs:partition(1, S) end [a,b,c]</pre> </desc> </func> + <func> <name name="intersection" arity="1"/> <fsummary>Return the intersection of a set of sets.</fsummary> <desc> - <p>Returns - the <seealso marker="#intersection_n">intersection</seealso> of - the set of sets <anno>SetOfSets</anno>.</p> + <p>Returns + the <seealso marker="#intersection_n">intersection</seealso> of + the set of sets <c><anno>SetOfSets</anno></c>.</p> <p>Intersecting an empty set of sets exits the process with a <c>badarg</c> message.</p> </desc> </func> + <func> <name name="intersection" arity="2"/> <fsummary>Return the intersection of two sets.</fsummary> <desc> - <p>Returns - the <seealso marker="#intersection">intersection</seealso> of - <anno>Set1</anno> and <anno>Set2</anno>.</p> + <p>Returns + the <seealso marker="#intersection">intersection</seealso> of + <c><anno>Set1</anno></c> and <c><anno>Set2</anno></c>.</p> </desc> </func> + <func> <name name="intersection_of_family" arity="1"/> <fsummary>Return the intersection of a family.</fsummary> <desc> - <p>Returns the intersection of - the <seealso marker="#family">family</seealso> <anno>Family</anno>. + <p>Returns the intersection of + <seealso marker="#family">family</seealso> <c><anno>Family</anno></c>. </p> <p>Intersecting an empty family exits the process with a <c>badarg</c> message.</p> @@ -991,12 +1084,13 @@ fun(S) -> sofs:partition(1, S) end [2]</pre> </desc> </func> + <func> <name name="inverse" arity="1"/> <fsummary>Return the inverse of a function.</fsummary> <desc> <p>Returns the <seealso marker="#inverse">inverse</seealso> - of the function <anno>Function1</anno>.</p> + of function <c><anno>Function1</anno></c>.</p> <pre> 1> <input>R1 = sofs:relation([{1,a},{2,b},{3,c}]),</input> <input>R2 = sofs:inverse(R1),</input> @@ -1004,14 +1098,15 @@ fun(S) -> sofs:partition(1, S) end [{a,1},{b,2},{c,3}]</pre> </desc> </func> + <func> <name name="inverse_image" arity="2"/> - <fsummary>Return the inverse image of a set under + <fsummary>Return the inverse image of a set under a binary relation.</fsummary> <desc> <p>Returns the <seealso marker="#inverse_image">inverse - image</seealso> of <anno>Set1</anno> under the binary - relation <anno>BinRel</anno>.</p> + image</seealso> of <c><anno>Set1</anno></c> under the binary + relation <c><anno>BinRel</anno></c>.</p> <pre> 1> <input>R = sofs:relation([{1,a},{2,b},{2,c},{3,d}]),</input> <input>S1 = sofs:set([c,d,e]),</input> @@ -1020,42 +1115,46 @@ fun(S) -> sofs:partition(1, S) end [2,3]</pre> </desc> </func> + <func> <name name="is_a_function" arity="1"/> <fsummary>Test for a function.</fsummary> <desc> - <p>Returns <c>true</c> if the binary relation <anno>BinRel</anno> + <p>Returns <c>true</c> if the binary relation <c><anno>BinRel</anno></c> is a <seealso marker="#function">function</seealso> or the - untyped empty set, <c>false</c> otherwise.</p> + untyped empty set, otherwise <c>false</c>.</p> </desc> </func> + <func> <name name="is_disjoint" arity="2"/> <fsummary>Test for disjoint sets.</fsummary> <desc> - <p>Returns <c>true</c> if <anno>Set1</anno> - and <anno>Set2</anno> - are <seealso marker="#disjoint">disjoint</seealso>, <c>false</c> - otherwise.</p> + <p>Returns <c>true</c> if <c><anno>Set1</anno></c> + and <c><anno>Set2</anno></c> + are <seealso marker="#disjoint">disjoint</seealso>, otherwise + <c>false</c>.</p> </desc> </func> + <func> <name name="is_empty_set" arity="1"/> <fsummary>Test for an empty set.</fsummary> <desc> - <p>Returns <c>true</c> if <anno>AnySet</anno> is an empty - unordered set, <c>false</c> otherwise.</p> + <p>Returns <c>true</c> if <c><anno>AnySet</anno></c> is an empty + unordered set, otherwise <c>false</c>.</p> </desc> </func> + <func> <name name="is_equal" arity="2"/> <fsummary>Test two sets for equality.</fsummary> <desc> - <p>Returns <c>true</c> if the <anno>AnySet1</anno> - and <anno>AnySet2</anno> - are <seealso marker="#equal">equal</seealso>, <c>false</c> - otherwise. This example shows that <c>==/2</c> is used when - comparing sets for equality:</p> + <p>Returns <c>true</c> if <c><anno>AnySet1</anno></c> + and <c><anno>AnySet2</anno></c> + are <seealso marker="#equal">equal</seealso>, otherwise + <c>false</c>. The following example shows that <c>==/2</c> is + used when comparing sets for equality:</p> <pre> 1> <input>S1 = sofs:set([1.0]),</input> <input>S2 = sofs:set([1]),</input> @@ -1063,50 +1162,55 @@ fun(S) -> sofs:partition(1, S) end true</pre> </desc> </func> + <func> <name name="is_set" arity="1"/> <fsummary>Test for an unordered set.</fsummary> <desc> - <p>Returns <c>true</c> if <anno>AnySet</anno> is - an <seealso marker="#sets_definition">unordered set</seealso>, and - <c>false</c> if <anno>AnySet</anno> is an ordered set or an + <p>Returns <c>true</c> if <c><anno>AnySet</anno></c> is + an <seealso marker="#sets_definition">unordered set</seealso>, and + <c>false</c> if <c><anno>AnySet</anno></c> is an ordered set or an atomic set.</p> </desc> </func> + <func> <name name="is_sofs_set" arity="1"/> <fsummary>Test for an unordered set.</fsummary> <desc> - <p>Returns <c>true</c> if <anno>Term</anno> is + <p>Returns <c>true</c> if <c><anno>Term</anno></c> is an <seealso marker="#sets_definition">unordered set</seealso>, an - ordered set or an atomic set, <c>false</c> otherwise.</p> + ordered set, or an atomic set, otherwise <c>false</c>.</p> </desc> </func> + <func> <name name="is_subset" arity="2"/> <fsummary>Test two sets for subset.</fsummary> <desc> - <p>Returns <c>true</c> if <anno>Set1</anno> is - a <seealso marker="#subset">subset</seealso> - of <anno>Set2</anno>, <c>false</c> otherwise.</p> + <p>Returns <c>true</c> if <c><anno>Set1</anno></c> is + a <seealso marker="#subset">subset</seealso> + of <c><anno>Set2</anno></c>, otherwise <c>false</c>.</p> </desc> </func> + <func> <name name="is_type" arity="1"/> <fsummary>Test for a type.</fsummary> <desc> - <p>Returns <c>true</c> if the term <anno>Term</anno> is - a <seealso marker="#type">type</seealso>.</p> + <p>Returns <c>true</c> if term <c><anno>Term</anno></c> is + a <seealso marker="#type">type</seealso>.</p> </desc> </func> + <func> <name name="join" arity="4"/> <fsummary>Return the join of two relations.</fsummary> <desc> - <p>Returns the <seealso marker="#natural_join">natural - join</seealso> of the relations <anno>Relation1</anno> - and <anno>Relation2</anno> on coordinates <anno>I</anno> and - <anno>J</anno>.</p> + <p>Returns the <seealso marker="#natural_join">natural + join</seealso> of the relations <c><anno>Relation1</anno></c> + and <c><anno>Relation2</anno></c> on coordinates <c><anno>I</anno></c> + and <c><anno>J</anno></c>.</p> <pre> 1> <input>R1 = sofs:relation([{a,x,1},{b,y,2}]),</input> <input>R2 = sofs:relation([{1,f,g},{1,h,i},{2,3,4}]),</input> @@ -1115,18 +1219,19 @@ true</pre> [{a,x,1,f,g},{a,x,1,h,i},{b,y,2,3,4}]</pre> </desc> </func> + <func> <name name="multiple_relative_product" arity="2"/> - <fsummary>Return the multiple relative product of a tuple of binary + <fsummary>Return the multiple relative product of a tuple of binary relations and a relation.</fsummary> <desc> - <p>If <anno>TupleOfBinRels</anno> is a non-empty tuple + <p>If <c><anno>TupleOfBinRels</anno></c> is a non-empty tuple {R[1], ..., R[n]} of binary relations - and <anno>BinRel1</anno> is a binary relation, - then <anno>BinRel2</anno> is - the <seealso marker="#multiple_relative_product">multiple relative - product</seealso> of the ordered set - (R[i], ..., R[n]) and <anno>BinRel1</anno>.</p> + and <c><anno>BinRel1</anno></c> is a binary relation, + then <c><anno>BinRel2</anno></c> is + the <seealso marker="#multiple_relative_product">multiple relative + product</seealso> of the ordered set + (R[i], ..., R[n]) and <c><anno>BinRel1</anno></c>.</p> <pre> 1> <input>Ri = sofs:relation([{a,1},{b,2},{c,3}]),</input> <input>R = sofs:relation([{a,b},{b,c},{c,a}]),</input> @@ -1135,22 +1240,24 @@ true</pre> [{1,2},{2,3},{3,1}]</pre> </desc> </func> + <func> <name name="no_elements" arity="1"/> <fsummary>Return the number of elements of a set.</fsummary> <desc> <p>Returns the number of elements of the ordered or unordered - set <anno>ASet</anno>.</p> + set <c><anno>ASet</anno></c>.</p> </desc> </func> + <func> <name name="partition" arity="1"/> <fsummary>Return the coarsest partition given a set of sets.</fsummary> <desc> - <p>Returns the <seealso marker="#partition">partition</seealso> of - the union of the set of sets <anno>SetOfSets</anno> such that two - elements are considered equal if they belong to the same - elements of <anno>SetOfSets</anno>.</p> + <p>Returns the <seealso marker="#partition">partition</seealso> of + the union of the set of sets <c><anno>SetOfSets</anno></c> such that + two elements are considered equal if they belong to the same + elements of <c><anno>SetOfSets</anno></c>.</p> <pre> 1> <input>Sets1 = sofs:from_term([[a,b,c],[d,e,f],[g,h,i]]),</input> <input>Sets2 = sofs:from_term([[b,c,d],[e,f,g],[h,i,j]]),</input> @@ -1159,13 +1266,14 @@ true</pre> [[a],[b,c],[d],[e,f],[g],[h,i],[j]]</pre> </desc> </func> + <func> <name name="partition" arity="2"/> <fsummary>Return a partition of a set.</fsummary> <desc> - <p>Returns the <seealso marker="#partition">partition</seealso> of - <anno>Set</anno> such that two elements are considered equal - if the results of applying <anno>SetFun</anno> are equal.</p> + <p>Returns the <seealso marker="#partition">partition</seealso> of + <c><anno>Set</anno></c> such that two elements are considered equal + if the results of applying <c><anno>SetFun</anno></c> are equal.</p> <pre> 1> <input>Ss = sofs:from_term([[a],[b],[c,d],[e,f]]),</input> <input>SetFun = fun(S) -> sofs:from_term(sofs:no_elements(S)) end,</input> @@ -1174,17 +1282,18 @@ true</pre> [[[a],[b]],[[c,d],[e,f]]]</pre> </desc> </func> + <func> <name name="partition" arity="3"/> <fsummary>Return a partition of a set.</fsummary> <desc> <p>Returns a pair of sets that, regarded as constituting a - set, forms a <seealso marker="#partition">partition</seealso> of - <anno>Set1</anno>. If the - result of applying <anno>SetFun</anno> to an element - of <anno>Set1</anno> yields an element in <anno>Set2</anno>, - the element belongs to <anno>Set3</anno>, otherwise the - element belongs to <anno>Set4</anno>.</p> + set, forms a <seealso marker="#partition">partition</seealso> of + <c><anno>Set1</anno></c>. If the + result of applying <c><anno>SetFun</anno></c> to an element of + <c><anno>Set1</anno></c> gives an element in <c><anno>Set2</anno></c>, + the element belongs to <c><anno>Set3</anno></c>, otherwise the + element belongs to <c><anno>Set4</anno></c>.</p> <pre> 1> <input>R1 = sofs:relation([{1,a},{2,b},{3,c}]),</input> <input>S = sofs:set([2,4,6]),</input> @@ -1192,23 +1301,23 @@ true</pre> <input>{sofs:to_external(R2),sofs:to_external(R3)}.</input> {[{2,b}],[{1,a},{3,c}]}</pre> <p><c>partition(F, S1, S2)</c> is equivalent to - <c>{restriction(F, S1, S2), + <c>{restriction(F, S1, S2), drestriction(F, S1, S2)}</c>.</p> </desc> </func> + <func> <name name="partition_family" arity="2"/> <fsummary>Return a family indexing a partition.</fsummary> <desc> - <p>Returns the <seealso marker="#family">family</seealso> - <anno>Family</anno> where the indexed set is - a <seealso marker="#partition">partition</seealso> - of <anno>Set</anno> such that two elements are considered - equal if the results of applying <anno>SetFun</anno> are the - same value i. This i is the index that <anno>Family</anno> - maps onto - the <seealso marker="#equivalence_class">equivalence - class</seealso>.</p> + <p>Returns <seealso marker="#family">family</seealso> + <c><anno>Family</anno></c> where the indexed set is + a <seealso marker="#partition">partition</seealso> + of <c><anno>Set</anno></c> such that two elements are considered + equal if the results of applying <c><anno>SetFun</anno></c> are the + same value i. This i is the index that <c><anno>Family</anno></c> + maps onto the <seealso marker="#equivalence_class">equivalence + class</seealso>.</p> <pre> 1> <input>S = sofs:relation([{a,a,a,a},{a,a,b,b},{a,b,b,b}]),</input> <input>SetFun = {external, fun({A,_,C,_}) -> {A,C} end},</input> @@ -1217,16 +1326,16 @@ true</pre> [{{a,a},[{a,a,a,a}]},{{a,b},[{a,a,b,b},{a,b,b,b}]}]</pre> </desc> </func> + <func> <name name="product" arity="1"/> <fsummary>Return the Cartesian product of a tuple of sets.</fsummary> <desc> - <p>Returns the <seealso marker="#Cartesian_product_tuple">Cartesian - product</seealso> of the non-empty tuple of sets - <anno>TupleOfSets</anno>. If (x[1], ..., x[n]) is - an element of the n-ary relation <anno>Relation</anno>, then - x[i] is drawn from element i - of <anno>TupleOfSets</anno>.</p> + <p>Returns the <seealso marker="#Cartesian_product_tuple">Cartesian + product</seealso> of the non-empty tuple of sets + <c><anno>TupleOfSets</anno></c>. If (x[1], ..., x[n]) is + an element of the n-ary relation <c><anno>Relation</anno></c>, then + x[i] is drawn from element i of <c><anno>TupleOfSets</anno></c>.</p> <pre> 1> <input>S1 = sofs:set([a,b]),</input> <input>S2 = sofs:set([1,2]),</input> @@ -1236,13 +1345,14 @@ true</pre> [{a,1,x},{a,1,y},{a,2,x},{a,2,y},{b,1,x},{b,1,y},{b,2,x},{b,2,y}]</pre> </desc> </func> + <func> <name name="product" arity="2"/> <fsummary>Return the Cartesian product of two sets.</fsummary> <desc> - <p>Returns the <seealso marker="#Cartesian_product">Cartesian - product</seealso> of <anno>Set1</anno> - and <anno>Set2</anno>.</p> + <p>Returns the <seealso marker="#Cartesian_product">Cartesian + product</seealso> of <c><anno>Set1</anno></c> + and <c><anno>Set2</anno></c>.</p> <pre> 1> <input>S1 = sofs:set([1,2]),</input> <input>S2 = sofs:set([a,b]),</input> @@ -1253,17 +1363,18 @@ true</pre> <c>product({S1, S2})</c>.</p> </desc> </func> + <func> <name name="projection" arity="2"/> <fsummary>Return a set of substituted elements.</fsummary> <desc> <p>Returns the set created by substituting each element of - <anno>Set1</anno> by the result of - applying <anno>SetFun</anno> to the element.</p> - <p>If <anno>SetFun</anno> is a number i >= 1 and - <anno>Set1</anno> is a relation, then the returned set is + <c><anno>Set1</anno></c> by the result of + applying <c><anno>SetFun</anno></c> to the element.</p> + <p>If <c><anno>SetFun</anno></c> is a number i >= 1 and + <c><anno>Set1</anno></c> is a relation, then the returned set is the <seealso marker="#projection">projection</seealso> of - <anno>Set1</anno> onto coordinate i.</p> + <c><anno>Set1</anno></c> onto coordinate i.</p> <pre> 1> <input>S1 = sofs:from_term([{1,a},{2,b},{3,a}]),</input> <input>S2 = sofs:projection(2, S1),</input> @@ -1271,12 +1382,13 @@ true</pre> [a,b]</pre> </desc> </func> + <func> <name name="range" arity="1"/> <fsummary>Return the range of a binary relation.</fsummary> <desc> <p>Returns the <seealso marker="#range">range</seealso> of the - binary relation <anno>BinRel</anno>.</p> + binary relation <c><anno>BinRel</anno></c>.</p> <pre> 1> <input>R = sofs:relation([{1,a},{1,b},{2,b},{2,c}]),</input> <input>S = sofs:range(R),</input> @@ -1284,6 +1396,7 @@ true</pre> [a,b,c]</pre> </desc> </func> + <func> <name name="relation" arity="1"/> <name name="relation" arity="2"/> @@ -1291,27 +1404,28 @@ true</pre> <desc> <p>Creates a <seealso marker="#relation">relation</seealso>. <c>relation(R, T)</c> is equivalent to - <c>from_term(R, T)</c>, if T is - a <seealso marker="#type">type</seealso> and the result is a - relation. If <anno>Type</anno> is an integer N, then - <c>[{atom, ..., atom}])</c>, where the size of the - tuple is N, is used as type of the relation. If no type is - explicitly given, the size of the first tuple of - <anno>Tuples</anno> is + <c>from_term(R, T)</c>, if T is + a <seealso marker="#type">type</seealso> and the result is a + relation. If <c><anno>Type</anno></c> is an integer N, then + <c>[{atom, ..., atom}])</c>, where the tuple size + is N, is used as type of the relation. If no type is + explicitly specified, the size of the first tuple of + <c><anno>Tuples</anno></c> is used if there is such a tuple. <c>relation([])</c> is equivalent to <c>relation([], 2)</c>.</p> </desc> </func> + <func> <name name="relation_to_family" arity="1"/> <fsummary>Create a family from a binary relation.</fsummary> <desc> - <p>Returns the <seealso marker="#family">family</seealso> - <anno>Family</anno> such that the index set is equal to - the <seealso marker="#domain">domain</seealso> of the binary - relation <anno>BinRel</anno>, and <anno>Family</anno>[i] is - the <seealso marker="#image">image</seealso> of the set of i - under <anno>BinRel</anno>.</p> + <p>Returns <seealso marker="#family">family</seealso> + <c><anno>Family</anno></c> such that the index set is equal to + the <seealso marker="#domain">domain</seealso> of the binary + relation <c><anno>BinRel</anno></c>, and <c><anno>Family</anno></c>[i] + is the <seealso marker="#image">image</seealso> of the set of i + under <c><anno>BinRel</anno></c>.</p> <pre> 1> <input>R = sofs:relation([{b,1},{c,2},{c,3}]),</input> <input>F = sofs:relation_to_family(R),</input> @@ -1319,20 +1433,21 @@ true</pre> [{b,[1]},{c,[2,3]}]</pre> </desc> </func> + <func> <name name="relative_product" arity="1"/> <name name="relative_product" arity="2" clause_i="1"/> <fsummary>Return the relative product of a list of binary relations - and a binary relation.</fsummary> + and a binary relation.</fsummary> <desc> - <p>If <anno>ListOfBinRels</anno> is a non-empty list + <p>If <c><anno>ListOfBinRels</anno></c> is a non-empty list [R[1], ..., R[n]] of binary relations and - <anno>BinRel1</anno> - is a binary relation, then <anno>BinRel2</anno> is the <seealso - marker="#tuple_relative_product">relative product</seealso> + <c><anno>BinRel1</anno></c> + is a binary relation, then <c><anno>BinRel2</anno></c> is the + <seealso marker="#tuple_relative_product">relative product</seealso> of the ordered set (R[i], ..., R[n]) and - <anno>BinRel1</anno>.</p> - <p>If <anno>BinRel1</anno> is omitted, the relation of equality + <c><anno>BinRel1</anno></c>.</p> + <p>If <c><anno>BinRel1</anno></c> is omitted, the relation of equality between the elements of the <seealso marker="#Cartesian_product_tuple">Cartesian product</seealso> of the ranges of R[i], @@ -1344,33 +1459,33 @@ true</pre> <input>R2 = sofs:relative_product([TR, R1]),</input> <input>sofs:to_external(R2).</input> [{1,{a,u}},{1,{aa,u}},{2,{b,v}}]</pre> - <p>Note that <c>relative_product([R1], R2)</c> is + <p>Notice that <c>relative_product([R1], R2)</c> is different from <c>relative_product(R1, R2)</c>; the - list of one element is not identified with the element - itself.</p> + list of one element is not identified with the element itself.</p> </desc> </func> + <func> <name name="relative_product" arity="2" clause_i="2"/> - <fsummary>Return the relative product of + <fsummary>Return the relative product of two binary relations.</fsummary> <desc> - <p><marker id="relprod_impl"></marker>Returns - the <seealso marker="#relative_product">relative - product</seealso> of the binary relations <anno>BinRel1</anno> - and <anno>BinRel2</anno>.</p> + <p>Returns the <seealso marker="#relative_product">relative + product</seealso> of the binary relations <c><anno>BinRel1</anno></c> + and <c><anno>BinRel2</anno></c>.</p> </desc> </func> + <func> <name name="relative_product1" arity="2"/> - <fsummary>Return the relative_product of + <fsummary>Return the relative_product of two binary relations.</fsummary> <desc> - <p>Returns the <seealso marker="#relative_product">relative - product</seealso> of - the <seealso marker="#converse">converse</seealso> of the - binary relation <anno>BinRel1</anno> and the binary - relation <anno>BinRel2</anno>.</p> + <p>Returns the <seealso marker="#relative_product">relative + product</seealso> of + the <seealso marker="#converse">converse</seealso> of the + binary relation <c><anno>BinRel1</anno></c> and the binary + relation <c><anno>BinRel2</anno></c>.</p> <pre> 1> <input>R1 = sofs:relation([{1,a},{1,aa},{2,b}]),</input> <input>R2 = sofs:relation([{1,u},{2,v},{3,c}]),</input> @@ -1381,13 +1496,14 @@ true</pre> <c>relative_product(converse(R1), R2)</c>.</p> </desc> </func> + <func> <name name="restriction" arity="2"/> <fsummary>Return a restriction of a binary relation.</fsummary> <desc> <p>Returns the <seealso marker="#restriction">restriction</seealso> of - the binary relation <anno>BinRel1</anno> - to <anno>Set</anno>.</p> + the binary relation <c><anno>BinRel1</anno></c> + to <c><anno>Set</anno></c>.</p> <pre> 1> <input>R1 = sofs:relation([{1,a},{2,b},{3,c}]),</input> <input>S = sofs:set([1,2,4]),</input> @@ -1396,13 +1512,14 @@ true</pre> [{1,a},{2,b}]</pre> </desc> </func> + <func> <name name="restriction" arity="3"/> <fsummary>Return a restriction of a set.</fsummary> <desc> - <p>Returns a subset of <anno>Set1</anno> containing those - elements that yield an element in <anno>Set2</anno> as the - result of applying <anno>SetFun</anno>.</p> + <p>Returns a subset of <c><anno>Set1</anno></c> containing those + elements that gives an element in <c><anno>Set2</anno></c> as the + result of applying <c><anno>SetFun</anno></c>.</p> <pre> 1> <input>S1 = sofs:relation([{1,a},{2,b},{3,c}]),</input> <input>S2 = sofs:set([b,c,d]),</input> @@ -1411,28 +1528,30 @@ true</pre> [{2,b},{3,c}]</pre> </desc> </func> + <func> <name name="set" arity="1"/> <name name="set" arity="2"/> <fsummary>Create a set of atoms or any type of sets.</fsummary> <desc> - <p>Creates an <seealso marker="#sets_definition">unordered - set</seealso>. <c>set(L, T)</c> is equivalent to + <p>Creates an <seealso marker="#sets_definition">unordered + set</seealso>. <c>set(L, T)</c> is equivalent to <c>from_term(L, T)</c>, if the result is an unordered set. If no <seealso marker="#type">type</seealso> is - explicitly given, <c>[atom]</c> is used as type of the set.</p> + explicitly specified, <c>[atom]</c> is used as the set type.</p> </desc> </func> + <func> <name name="specification" arity="2"/> <fsummary>Select a subset using a predicate.</fsummary> <desc> <p>Returns the set containing every element - of <anno>Set1</anno> for which <anno>Fun</anno> - returns <c>true</c>. If <anno>Fun</anno> is a tuple - <c>{external, Fun2}</c>, Fun2 is applied to the + of <c><anno>Set1</anno></c> for which <c><anno>Fun</anno></c> + returns <c>true</c>. If <c><anno>Fun</anno></c> is a tuple + <c>{external, Fun2}</c>, <c>Fun2</c> is applied to the <seealso marker="#external_set">external set</seealso> of - each element, otherwise <anno>Fun</anno> is applied to each + each element, otherwise <c><anno>Fun</anno></c> is applied to each element.</p> <pre> 1> <input>R1 = sofs:relation([{a,1},{b,2}]),</input> @@ -1443,14 +1562,15 @@ true</pre> [[{a,1},{b,2}]]</pre> </desc> </func> + <func> <name name="strict_relation" arity="1"/> - <fsummary>Return the strict relation corresponding to + <fsummary>Return the strict relation corresponding to a given relation.</fsummary> <desc> - <p>Returns the <seealso marker="#strict_relation">strict + <p>Returns the <seealso marker="#strict_relation">strict relation</seealso> corresponding to the binary - relation <anno>BinRel1</anno>.</p> + relation <c><anno>BinRel1</anno></c>.</p> <pre> 1> <input>R1 = sofs:relation([{1,1},{1,2},{2,1},{2,2}]),</input> <input>R2 = sofs:strict_relation(R1),</input> @@ -1458,13 +1578,14 @@ true</pre> [{1,2},{2,1}]</pre> </desc> </func> + <func> <name name="substitution" arity="2"/> <fsummary>Return a function with a given set as domain.</fsummary> <desc> <p>Returns a function, the domain of which - is <anno>Set1</anno>. The value of an element of the domain - is the result of applying <anno>SetFun</anno> to the + is <c><anno>Set1</anno></c>. The value of an element of the domain + is the result of applying <c><anno>SetFun</anno></c> to the element.</p> <pre> 1> <input>L = [{a,1},{b,2}].</input> @@ -1481,24 +1602,24 @@ true</pre> 1> <input>I = sofs:substitution(fun(A) -> A end, sofs:set([a,b,c])),</input> <input>sofs:to_external(I).</input> [{a,a},{b,b},{c,c}]</pre> - <p>Let SetOfSets be a set of sets and BinRel a binary - relation. The function that maps each element Set of - SetOfSets onto the <seealso marker="#image">image</seealso> - of Set under BinRel is returned by this function:</p> + <p>Let <c>SetOfSets</c> be a set of sets and <c>BinRel</c> a binary + relation. The function that maps each element <c>Set</c> of + <c>SetOfSets</c> onto the <seealso marker="#image">image</seealso> + of <c>Set</c> under <c>BinRel</c> is returned by the following + function:</p> <pre> images(SetOfSets, BinRel) -> Fun = fun(Set) -> sofs:image(BinRel, Set) end, sofs:substitution(Fun, SetOfSets).</pre> - <p>Here might be the place to reveal something that was more - or less stated before, namely that external unordered sets - are represented as sorted lists. As a consequence, creating - the image of a set under a relation R may traverse all + <p>External unordered sets are represented as sorted lists. So, + creating the image of a set under a relation R can traverse all elements of R (to that comes the sorting of results, the - image). In <c>images/2</c>, BinRel will be traversed once - for each element of SetOfSets, which may take too long. The - following efficient function could be used instead under the - assumption that the image of each element of SetOfSets under - BinRel is non-empty:</p> + image). In <seealso marker="#image/2"><c>image/2</c></seealso>, + <c>BinRel</c> is traversed once + for each element of <c>SetOfSets</c>, which can take too long. The + following efficient function can be used instead under the + assumption that the image of each element of <c>SetOfSets</c> under + <c>BinRel</c> is non-empty:</p> <pre> images2(SetOfSets, BinRel) -> CR = sofs:canonical_relation(SetOfSets), @@ -1506,13 +1627,14 @@ images2(SetOfSets, BinRel) -> sofs:relation_to_family(R).</pre> </desc> </func> + <func> <name name="symdiff" arity="2"/> <fsummary>Return the symmetric difference of two sets.</fsummary> <desc> - <p>Returns the <seealso marker="#symmetric_difference">symmetric + <p>Returns the <seealso marker="#symmetric_difference">symmetric difference</seealso> (or the Boolean sum) - of <anno>Set1</anno> and <anno>Set2</anno>.</p> + of <c><anno>Set1</anno></c> and <c><anno>Set2</anno></c>.</p> <pre> 1> <input>S1 = sofs:set([1,2,3]),</input> <input>S2 = sofs:set([2,3,4]),</input> @@ -1521,68 +1643,81 @@ images2(SetOfSets, BinRel) -> [1,4]</pre> </desc> </func> + <func> <name name="symmetric_partition" arity="2"/> <fsummary>Return a partition of two sets.</fsummary> <desc> - <p>Returns a triple of sets: <anno>Set3</anno> contains the - elements of <anno>Set1</anno> that do not belong - to <anno>Set2</anno>; <anno>Set4</anno> contains the - elements of <anno>Set1</anno> that belong - to <anno>Set2</anno>; <anno>Set5</anno> contains the - elements of <anno>Set2</anno> that do not belong - to <anno>Set1</anno>.</p> + <p>Returns a triple of sets:</p> + <list type="bulleted"> + <item><c><anno>Set3</anno></c> contains the elements of + <c><anno>Set1</anno></c> that do not belong to + <c><anno>Set2</anno></c>. + </item> + <item><c><anno>Set4</anno></c> contains the elements of + <c><anno>Set1</anno></c> that belong to <c><anno>Set2</anno></c>. + </item> + <item><c><anno>Set5</anno></c> contains the elements of + <c><anno>Set2</anno></c> that do not belong to + <c><anno>Set1</anno></c>. + </item> + </list> </desc> </func> + <func> <name name="to_external" arity="1"/> <fsummary>Return the elements of a set.</fsummary> <desc> - <p>Returns the <seealso marker="#external_set">external - set</seealso> of an atomic, ordered or unordered set.</p> + <p>Returns the <seealso marker="#external_set">external + set</seealso> of an atomic, ordered, or unordered set.</p> </desc> </func> + <func> <name name="to_sets" arity="1"/> - <fsummary>Return a list or a tuple of the elements of set.</fsummary> + <fsummary>Return a list or a tuple of the elements of a set.</fsummary> <desc> - <p>Returns the elements of the ordered set <anno>ASet</anno> + <p>Returns the elements of the ordered set <c><anno>ASet</anno></c> as a tuple of sets, and the elements of the unordered set - <anno>ASet</anno> as a sorted list of sets without + <c><anno>ASet</anno></c> as a sorted list of sets without duplicates.</p> </desc> </func> + <func> <name name="type" arity="1"/> <fsummary>Return the type of a set.</fsummary> <desc> <p>Returns the <seealso marker="#type">type</seealso> of an - atomic, ordered or unordered set.</p> + atomic, ordered, or unordered set.</p> </desc> </func> + <func> <name name="union" arity="1"/> <fsummary>Return the union of a set of sets.</fsummary> <desc> <p>Returns the <seealso marker="#union_n">union</seealso> of the - set of sets <anno>SetOfSets</anno>.</p> + set of sets <c><anno>SetOfSets</anno></c>.</p> </desc> </func> + <func> <name name="union" arity="2"/> <fsummary>Return the union of two sets.</fsummary> <desc> <p>Returns the <seealso marker="#union">union</seealso> of - <anno>Set1</anno> and <anno>Set2</anno>.</p> + <c><anno>Set1</anno></c> and <c><anno>Set2</anno></c>.</p> </desc> </func> + <func> <name name="union_of_family" arity="1"/> <fsummary>Return the union of a family.</fsummary> <desc> - <p>Returns the union of - the <seealso marker="#family">family</seealso> <anno>Family</anno>. - </p> + <p>Returns the union of <seealso marker="#family">family</seealso> + <c><anno>Family</anno></c>.</p> <pre> 1> <input>F = sofs:family([{a,[0,2,4]},{b,[0,1,2]},{c,[2,3]}]),</input> <input>S = sofs:union_of_family(F),</input> @@ -1590,16 +1725,17 @@ images2(SetOfSets, BinRel) -> [0,1,2,3,4]</pre> </desc> </func> + <func> <name name="weak_relation" arity="1"/> - <fsummary>Return the weak relation corresponding to + <fsummary>Return the weak relation corresponding to a given relation.</fsummary> <desc> <p>Returns a subset S of the <seealso marker="#weak_relation">weak relation</seealso> W - corresponding to the binary relation <anno>BinRel1</anno>. + corresponding to the binary relation <c><anno>BinRel1</anno></c>. Let F be the <seealso marker="#field">field</seealso> of - <anno>BinRel1</anno>. The + <c><anno>BinRel1</anno></c>. The subset S is defined so that x S y if x W y for some x in F and for some y in F.</p> <pre> @@ -1613,11 +1749,11 @@ images2(SetOfSets, BinRel) -> <section> <title>See Also</title> - <p><seealso marker="dict">dict(3)</seealso>, - <seealso marker="digraph">digraph(3)</seealso>, - <seealso marker="orddict">orddict(3)</seealso>, - <seealso marker="ordsets">ordsets(3)</seealso>, - <seealso marker="sets">sets(3)</seealso></p> + <p><seealso marker="dict"><c>dict(3)</c></seealso>, + <seealso marker="digraph"><c>digraph(3)</c></seealso>, + <seealso marker="orddict"><c>orddict(3)</c></seealso>, + <seealso marker="ordsets"><c>ordsets(3)</c></seealso>, + <seealso marker="sets"><c>sets(3)</c></seealso></p> </section> </erlref> |