1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589
|
<HTML>
<HEAD>
<!-- refpage -->
<TITLE>sofs</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Erlang Systems]" SRC="min_head.gif"></A>
<H1>sofs</H1>
</CENTER>
<H3>MODULE</H3>
<UL>
sofs</UL>
<H3>MODULE SUMMARY</H3>
<UL>
Functions for Manipulating Sets of Sets</UL>
<H3>DESCRIPTION</H3>
<UL>
<P>The <CODE>sofs</CODE> module implements 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>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>The <STRONG>unordered set</STRONG> containing the elements a, b and c
is denoted {a, b, c}. This notation is not to be
confused with tuples. The <STRONG>ordered pair</STRONG> of a and b, with
first <STRONG>coordinate</STRONG> a and second coordinate b, is denoted
(a, b). An ordered pair is an <STRONG>ordered set</STRONG> 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>The set that contains no elements is called the <STRONG>empty
set</STRONG>. If two sets A and B contain the same elements, then A
is <A NAME="equal"><!-- Empty --></A><STRONG>equal</STRONG> 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 <A NAME="subset"><!-- Empty --></A><STRONG>subset</STRONG> of A. The
<A NAME="union"><!-- Empty --></A><STRONG>union</STRONG> of two sets A and B is the
smallest set that contains all elements of A and all elements of
B. The <A NAME="intersection"><!-- Empty --></A><STRONG>intersection</STRONG> of two
sets A and B is the set that contains all elements of A that
belong to B. Two sets are <A NAME="disjoint"><!-- Empty --></A><STRONG>disjoint</STRONG> if their intersection is the
empty set. The <A NAME="difference"><!-- Empty --></A><STRONG>difference</STRONG> of
two sets A and B is the set that contains all elements of A that
do not belong to B. The <A NAME="symmetric_difference"><!-- Empty --></A><STRONG>symmetric difference</STRONG> of two
sets is the set that contains those element that belong to
either of the two sets, but not both. The <A NAME="union_n"><!-- Empty --></A><STRONG>union</STRONG> 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 <A NAME="intersection_n"><!-- Empty --></A><STRONG>intersection</STRONG> of a non-empty
collection of sets is the set that contains all elements that
belong to every set of the collection.
<P>The <A NAME="Cartesian_product"><!-- Empty --></A><STRONG>Cartesian product</STRONG>
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 <A NAME="relation"><!-- Empty --></A><STRONG>relation</STRONG> 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
<A NAME="domain"><!-- Empty --></A><STRONG>domain</STRONG> of R is the set {x :
x R y for some y in Y}. The <A NAME="range"><!-- Empty --></A><STRONG>range</STRONG> of R is the set {y :
x R y for some x in X}. The <A NAME="converse"><!-- Empty --></A><STRONG>converse</STRONG> of R is the set {a :
a = (y, x) for some (x, y) in R}. If A
is a subset of X, then the <A NAME="image"><!-- Empty --></A><STRONG>image</STRONG> 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 <A NAME="inverse_image"><!-- Empty --></A><STRONG>inverse image</STRONG> 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
<A NAME="relative_product"><!-- Empty --></A><STRONG>relative product</STRONG> 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 <A NAME="restriction"><!-- Empty --></A><STRONG>restriction</STRONG> 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 X = Y
then we call R a relation <STRONG>in</STRONG> X. The <A NAME="field"><!-- Empty --></A><STRONG>field</STRONG> 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 <A NAME="strict_relation"><!-- Empty --></A><STRONG>strict</STRONG> 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 <A NAME="weak_relation"><!-- Empty --></A><STRONG>weak</STRONG> relation
corresponding to S. A relation R in X is <STRONG>reflexive</STRONG> if
x R x for every element x of X; it is
<STRONG>symmetric</STRONG> if x R y implies that
y R x; and it is <STRONG>transitive</STRONG> if
x R y and y R z imply that x R z.
<P>A <A NAME="function"><!-- Empty --></A><STRONG>function</STRONG> 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 <A NAME="inverse"><!-- Empty --></A><STRONG>inverse</STRONG> of F. The relative product of two
functions F1 and F2 is called the <A NAME="composite"><!-- Empty --></A><STRONG>composite</STRONG> of F1 and F2 if the range of
F1 is a subset of the domain of F2.
<P>Sometimes, when the range of a function is more important than
the function itself, the function is called a <STRONG>family</STRONG>.
The domain of a family is called the <STRONG>index set</STRONG>, and the
range is called the <STRONG>indexed set</STRONG>. 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
<A NAME="family"><!-- Empty --></A><STRONG>family of subsets</STRONG> of X. If x is a
family of subsets of X, then the union of the range of x is
called the <STRONG>union of the family</STRONG> x. If x is non-empty
(the index set is non-empty), the <STRONG>intersection of the
family</STRONG> 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>A <A NAME="partition"><!-- Empty --></A><STRONG>partition</STRONG> 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
<STRONG>equivalence relation</STRONG> if it is reflexive, symmetric and
transitive. If R is an equivalence relation in X, and x is an
element of X, the <A NAME="equivalence_class"><!-- Empty --></A><STRONG>equivalence
class</STRONG> 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 <A NAME="canonical_map"><!-- Empty --></A><STRONG>canonical map</STRONG> is the function that
maps every element of X onto its equivalence class.
<P>Relations as defined above (as sets of ordered pairs) will from
now on be referred to as <STRONG>binary relations</STRONG>. We call a
set of ordered sets (x[1], ..., x[n]) an <STRONG>(n-ary)
relation</STRONG>, and say that the relation is a subset of the
<A NAME="Cartesian_product_tuple"><!-- Empty --></A> Cartesian product
X[1] × ... × X[n] where x[i] is
an element of X[i], 1 <= i <= n. The
<A NAME="projection"><!-- Empty --></A><STRONG>projection</STRONG> 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 a 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
<A NAME="tuple_relative_product"><!-- Empty --></A><STRONG>relative product</STRONG> 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 <A NAME="multiple_relative_product"><!-- Empty --></A><STRONG>multiple relative
product</STRONG> of TR and 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 <A NAME="natural_join"><!-- Empty --></A><STRONG>natural join</STRONG> 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><A NAME="sets_definition"><!-- Empty --></A>The sets recognized by this module
will be represented by elements of the relation Sets, defined as
the smallest set such that:
<P><UL>
<LI>for every atom T except '_' and for every term X,
(T, X) belongs to Sets (<STRONG>atomic sets</STRONG>);
</LI><BR>
<LI>(['_'], []) belongs to Sets (the <STRONG>untyped empty
set</STRONG>);
</LI><BR>
<LI>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 (<STRONG>ordered sets</STRONG>);
</LI><BR>
<LI>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 (<STRONG>typed unordered sets</STRONG>).
</LI><BR>
</UL>
<P>An <A NAME="external_set"><!-- Empty --></A><STRONG>external set</STRONG> is an
element in the range of Sets. A <A NAME="type"><!-- Empty --></A><STRONG>type</STRONG>
is an element in the domain of Sets. If S is an element
(T, X) of Sets, then T is a <A NAME="valid_type"><!-- Empty --></A><STRONG>valid type</STRONG> of X, T is the type of S,
and X is the external set of S. <A HREF="#from_term">from_term/2</A> creates a set from a
type and an Erlang term turned into an external set.
<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><UL>
<LI>Set(T,Term) = Term, where T is an atom;
</LI><BR>
<LI>Set({T[1], ..., T[n]}, {X[1], ..., X[n]})
 = (Set(T[1], X[1]), ..., Set(T[n], X[n]));
</LI><BR>
<LI>Set([T], [X[1], ..., X[n]])
 = {Set(T, X[1]), ..., Set(T, X[n])};
</LI><BR>
<LI>Set([T], []) = {}.
</LI><BR>
</UL>
<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 <CODE>union/2</CODE> 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>The types are used to implement the various conditions that
sets need to 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, <A HREF="#relprod_impl">relative_product/2</A>, 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
that [{A,B}] matches the type of Arg1 is to be interpreted as
Arg1 representing a binary relation from X to Y, where X is
defined as all sets Set(x) for some element x in Sets the type
of which is A, and similarly for Y. In the same way Arg2 is
interpreted as representing a binary relation from W to Z.
Finally it is checked that B matches C, which is sufficient for
ensuring that W is equal to Y. The untyped empty set is handled
separately: its type, ['_'], matches the type of any unordered
set.
<P>A few functions of this module (<CODE>drestriction/3</CODE>,
<CODE>family_projection/2</CODE>, <CODE>partition/2</CODE>,
<CODE>partition_family/2</CODE>, <CODE>projection/2</CODE>,
<CODE>restriction/3</CODE>, <CODE>substitution/2</CODE>) accept Erlang
functions as a means to modify each element of a given unordered
set. Such a function, called SetFun in the following, can be
specified as a function, a tuple <CODE>{external, Fun}</CODE>, or an
integer. The two latter alternatives are optimizations; instead
of a set, the argument presented to the function is an external
set, which in the present implementation can be done more
efficiently. This optimization can however only be applied 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 <CODE>{external, fun(X) -> element(I, X)}</CODE>,
but is to be preferred since it makes it possible to handle this
case even more efficiently. Examples of SetFuns:
<PRE>{sofs, union}
fun(S) -> sofs:partition(1, S) end
{external, fun(A) -> A end}
{external, fun({A,_,C}) -> {C,A} end}
{external, fun({_,{_,C}}) -> C end}
{external, fun({_,{_,{_,E}=C}}) -> {E,{E,C}} end}
2</PRE>
<P>The order in which functions are applied to elements is not
specified, and may change in future versions of sofs.
<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: <CODE>from_external</CODE>,
<CODE>is_empty_set</CODE>, <CODE>is_set</CODE>, <CODE>is_sofs_set</CODE>,
<CODE>to_external</CODE>, <CODE>type</CODE>.
<P>The functions of this module exit the process with a
<CODE>badarg</CODE>, <CODE>bad_function</CODE>, or <CODE>type_mismatch</CODE>
message when given badly formed arguments or sets the types of
which are not compatible.
<P><STRONG>Types</STRONG>
<PRE>anyset() = - an unordered, ordered or atomic set -
binary_relation() = - a binary relation -
bool() = true | false
external_set() = - an external set -
family() = - a family (of subsets) -
function() = - a function -
ordset() = - an ordered set -
relation() = - an n-ary relation -
set() = - an unordered set -
set_of_sets() = - an unordered set of set() -
set_fun() = integer() >= 1
| {external, fun(external_set()) -> external_set()}
| fun(anyset()) -> anyset()
spec_fun() = {external, fun(external_set()) -> bool()}
| fun(anyset()) -> bool()
type() = - a type -</PRE>
</UL>
<H3>EXPORTS</H3>
<P><A NAME="a_function%2"><STRONG><CODE>a_function(Tuples [, Type]) -> Function</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Function = function()</CODE></STRONG><BR>
<STRONG><CODE>Tuples = [tuple()]</CODE></STRONG><BR>
<STRONG><CODE>Type = type()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Creates a <A HREF="#function">function</A>.
<CODE>a_function(F, T)</CODE> is equivalent to <CODE>from_term(F,
T)</CODE>, if the result is a function. If no <A HREF="#type">type</A> is explicitly given,
<CODE>[{atom, atom}]</CODE> is used as type of the function.
</UL>
<P><A NAME="canonical_relation%1"><STRONG><CODE>canonical_relation(SetOfSets) -> BinRel</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel = binary_relation()</CODE></STRONG><BR>
<STRONG><CODE>SetOfSets = set_of_sets()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the binary relation containing the elements
(E, Set) such that Set belongs to SetOfSets and E
belongs to Set. If SetOfSets is a <A HREF="#partition">partition</A> of a set X and R is
the equivalence relation in X induced by SetOfSets, then the
returned relation is the <A HREF="#canonical_map">canonical map</A> from X onto
the equivalence classes with respect to R.
<PRE>1> <STRONG>Ss = sofs:from_term([[a,b],[b,c]]),</STRONG>
<STRONG>CR = sofs:canonical_relation(Ss),</STRONG>
<STRONG>sofs:to_external(CR).</STRONG>
[{a,[a,b]},{b,[a,b]},{b,[b,c]},{c,[b,c]}]</PRE>
</UL>
<P><A NAME="composite%2"><STRONG><CODE>composite(Function1, Function2) -> Function3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Function1 = Function2 = Function3 = function()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#composite">composite</A> of the functions
Function1 and Function2.
<PRE>1> <STRONG>F1 = sofs:a_function([{a,1},{b,2},{c,2}]),</STRONG>
<STRONG>F2 = sofs:a_function([{1,x},{2,y},{3,z}]),</STRONG>
<STRONG>F = sofs:composite(F1, F2),</STRONG>
<STRONG>sofs:to_external(F).</STRONG>
[{a,x},{b,y},{c,y}]</PRE>
</UL>
<P><A NAME="constant_function%2"><STRONG><CODE>constant_function(Set, AnySet) -> Function</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>AnySet = anyset()</CODE></STRONG><BR>
<STRONG><CODE>Function = function()</CODE></STRONG><BR>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Creates the <A HREF="#function">function</A>
that maps each element of the set Set onto AnySet.
<PRE>1> <STRONG>S = sofs:set([a,b]),</STRONG>
<STRONG>E = sofs:from_term(1),</STRONG>
<STRONG>R = sofs:constant_function(S, E),</STRONG>
<STRONG>sofs:to_external(R).</STRONG>
[{a,1},{b,1}]</PRE>
</UL>
<P><A NAME="converse%1"><STRONG><CODE>converse(BinRel1) -> BinRel2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel1 = BinRel2 = binary_relation()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#converse">converse</A>
of the binary relation BinRel1.
<PRE>1> <STRONG>R1 = sofs:relation([{1,a},{2,b},{3,a}]),</STRONG>
<STRONG>R2 = sofs:converse(R1),</STRONG>
<STRONG>sofs:to_external(R2).</STRONG>
[{a,1},{a,3},{b,2}]</PRE>
</UL>
<P><A NAME="difference%2"><STRONG><CODE>difference(Set1, Set2) -> Set3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Set1 = Set2 = Set3 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#difference">difference
</A> of the sets Set1 and Set2.
</UL>
<P><A NAME="digraph_to_family%2"><STRONG><CODE>digraph_to_family(Graph [, Type]) -> Family</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Graph = digraph() - see digraph(3) -</CODE></STRONG><BR>
<STRONG><CODE>Family = family()</CODE></STRONG><BR>
<STRONG><CODE>Type = type()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Creates a <A HREF="#family">family</A> from
the directed graph Graph. Each vertex a of Graph is
represented by a pair (a, {b[1], ..., b[n]})
where the b[i]'s are the out-neighbours of a.
<CODE>digraph_to_family(G)</CODE> is equivalent to
<CODE>digraph_to_family(G, [{atom, [atom]}])</CODE>. It is
assumed that Type is a <A HREF="#valid_type">valid
type</A> of the external set of the family.
<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
<CODE>family_to_digraph(digraph_to_family(G))</CODE>.
</UL>
<P><A NAME="domain%1"><STRONG><CODE>domain(BinRel) -> Set</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel = binary_relation()</CODE></STRONG><BR>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#domain">domain
</A> of the binary relation BinRel.
<PRE>1> <STRONG>R = sofs:relation([{1,a},{1,b},{2,b},{2,c}]),</STRONG>
<STRONG>S = sofs:domain(R),</STRONG>
<STRONG>sofs:to_external(S).</STRONG>
[1,2]</PRE>
</UL>
<P><A NAME="drestriction%2"><STRONG><CODE>drestriction(BinRel1, Set) -> BinRel2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel1 = BinRel2 = binary_relation()</CODE></STRONG><BR>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the difference between the binary relation BinRel1
and the <A HREF="#restriction">restriction</A>
of BinRel1 to Set; <CODE>drestriction(R, S)</CODE> is equivalent
to <CODE>difference(R, restriction(R, S))</CODE>.
<PRE>1> <STRONG>R1 = sofs:relation([{1,a},{2,b},{3,c}]),</STRONG>
<STRONG>S = sofs:set([2,4,6]),</STRONG>
<STRONG>R2 = sofs:drestriction(R1, S),</STRONG>
<STRONG>sofs:to_external(R2).</STRONG>
[{1,a},{3,c}]</PRE>
</UL>
<P><A NAME="drestriction%3"><STRONG><CODE>drestriction(SetFun, Set1, Set2) -> Set3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>SetFun = set_fun()</CODE></STRONG><BR>
<STRONG><CODE>Set1 = Set2 = Set3 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a subset of Set1 containing those elements that do
not yield an element in Set2 as the result of applying
SetFun; <CODE>drestriction(F, S1, S2)</CODE> is equivalent to
<CODE>difference(S1, restriction(F, S1, S2))</CODE>.
<PRE>1> <STRONG>SetFun = {external, fun({_A,B,C}) -> {B,C} end},</STRONG>
<STRONG>R1 = sofs:relation([{a,aa,1},{b,bb,2},{c,cc,3}]),</STRONG>
<STRONG>R2 = sofs:relation([{bb,2},{cc,3},{dd,4}]),</STRONG>
<STRONG>R3 = sofs:drestriction(SetFun, R1, R2),</STRONG>
<STRONG>sofs:to_external(R3).</STRONG>
[{a,aa,1}]</PRE>
</UL>
<P><A NAME="empty_set%0"><STRONG><CODE>empty_set() -> Set</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#sets_definition">untyped
empty set</A>. <CODE>empty_set()</CODE> is equivalent to
<CODE>from_term([], ['_'])</CODE>.
</UL>
<P><A NAME="family%2"><STRONG><CODE>family(Tuples [, Type]) -> Family</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family = family()</CODE></STRONG><BR>
<STRONG><CODE>Tuples = [tuple()]</CODE></STRONG><BR>
<STRONG><CODE>Type = type()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Creates a <A HREF="#family">family of
subsets</A>. <CODE>family(F, T)</CODE> is equivalent to
<CODE>from_term(F, T)</CODE>, if the result is a family. If no
<A HREF="#type">type</A> is explicitly given,
<CODE>[{atom, [atom]}]</CODE> is used as type of the family.
</UL>
<P><A NAME="family_difference%2"><STRONG><CODE>family_difference(Family1, Family2) -> Family3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family1 = Family2 = Family3 = family()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If Family1 and Family2 are <A HREF="#family">families</A>, then Family3 the family
such that the index set is equal to the index set of
Family1, and Family3[i] is the difference between Family1[i]
and Family2[i] if Family2 maps i, Family1[i] otherwise.
<PRE>1> <STRONG>F1 = sofs:family([{a,[1,2]},{b,[3,4]}]),</STRONG>
<STRONG>F2 = sofs:family([{b,[4,5]},{c,[6,7]}]),</STRONG>
<STRONG>F3 = sofs:family_difference(F1, F2),</STRONG>
<STRONG>sofs:to_external(F3).</STRONG>
[{a,[1,2]},{b,[3]}]</PRE>
</UL>
<P><A NAME="family_domain%1"><STRONG><CODE>family_domain(Family1) -> Family2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family1 = Family2 = family()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If Family1 is a <A HREF="#family">family</A>
and Family1[i] is a binary relation for every i in the index
set of Family1, then Family2 is the family with the same
index set as Family1 such that Family2[i] is the <A HREF="#domain">domain</A> of Family1[i].
<PRE>1> <STRONG>FR = sofs:from_term([{a,[{1,a},{2,b},{3,c}]},{b,[]},{c,[{4,d},{5,e}]}]),</STRONG>
<STRONG>F = sofs:family_domain(FR),</STRONG>
<STRONG>sofs:to_external(F).</STRONG>
[{a,[1,2,3]},{b,[]},{c,[4,5]}]</PRE>
</UL>
<P><A NAME="family_field%1"><STRONG><CODE>family_field(Family1) -> Family2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family1 = Family2 = family()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If Family1 is a <A HREF="#family">family</A>
and Family1[i] is a binary relation for every i in the index
set of Family1, then Family2 is the family with the same
index set as Family1 such that Family2[i] is the <A HREF="#field">field</A> of Family1[i];
<CODE>family_field(Family1)</CODE> is equivalent to
<CODE>family_union(family_domain(Family1),
family_range(Family1))</CODE>.
<PRE>1> <STRONG>FR = sofs:from_term([{a,[{1,a},{2,b},{3,c}]},{b,[]},{c,[{4,d},{5,e}]}]),</STRONG>
<STRONG>F = sofs:family_field(FR),</STRONG>
<STRONG>sofs:to_external(F).</STRONG>
[{a,[1,2,3,a,b,c]},{b,[]},{c,[4,5,d,e]}]</PRE>
</UL>
<P><A NAME="family_intersection%1"><STRONG><CODE>family_intersection(Family1) -> Family2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family1 = Family2 = family()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If Family1 is a <A HREF="#family">family</A>
and Family1[i] is a set of sets for every i in the index set
of Family1, then Family2 is the family with the same index
set as Family1 such that Family2[i] is the <A HREF="#intersection_n">intersection</A> of
Family1[i].
<P>If Family1[i] is an empty set for some i, then the process
exits with a <CODE>badarg</CODE> message.
<PRE>1> <STRONG>F1 = sofs:from_term([{a,[[1,2,3],[2,3,4]]},{b,[[x,y,z],[x,y]]}]),</STRONG>
<STRONG>F2 = sofs:family_intersection(F1),</STRONG>
<STRONG>sofs:to_external(F2).</STRONG>
[{a,[2,3]},{b,[x,y]}]</PRE>
</UL>
<P><A NAME="family_intersection%2"><STRONG><CODE>family_intersection(Family1, Family2) -> Family3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family1 = Family2 = Family3 = family()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If Family1 and Family2 are <A HREF="#family">families</A>, then Family3 is the
family such that the index set is the intersection of
Family1's and Family2's index sets, and Family3[i] is the
intersection of Family1[i] and Family2[i].
<PRE>1> <STRONG>F1 = sofs:family([{a,[1,2]},{b,[3,4]},{c,[5,6]}]),</STRONG>
<STRONG>F2 = sofs:family([{b,[4,5]},{c,[7,8]},{d,[9,10]}]),</STRONG>
<STRONG>F3 = sofs:family_intersection(F1, F2),</STRONG>
<STRONG>sofs:to_external(F3).</STRONG>
[{b,[4]},{c,[]}]</PRE>
</UL>
<P><A NAME="family_projection%2"><STRONG><CODE>family_projection(SetFun, Family1) -> Family2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>SetFun = set_fun()</CODE></STRONG><BR>
<STRONG><CODE>Family1 = Family2 = family()</CODE></STRONG><BR>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If Family1 is a <A HREF="#family">family</A>
then Family2 is the family with the same index set as
Family1 such that Family2[i] is the result of calling SetFun
with Family1[i] as argument.
<PRE>1> <STRONG>F1 = sofs:from_term([{a,[[1,2],[2,3]]},{b,[[]]}]),</STRONG>
<STRONG>F2 = sofs:family_projection({sofs, union}, F1),</STRONG>
<STRONG>sofs:to_external(F2).</STRONG>
[{a,[1,2,3]},{b,[]}]</PRE>
</UL>
<P><A NAME="family_range%1"><STRONG><CODE>family_range(Family1) -> Family2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family1 = Family2 = family()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If Family1 is a <A HREF="#family">family</A>
and Family1[i] is a binary relation for every i in the index
set of Family1, then Family2 is the family with the same
index set as Family1 such that Family2[i] is the <A HREF="#range">range</A> of Family1[i].
<PRE>1> <STRONG>FR = sofs:from_term([{a,[{1,a},{2,b},{3,c}]},{b,[]},{c,[{4,d},{5,e}]}]),</STRONG>
<STRONG>F = sofs:family_range(FR),</STRONG>
<STRONG>sofs:to_external(F).</STRONG>
[{a,[a,b,c]},{b,[]},{c,[d,e]}]</PRE>
</UL>
<P><A NAME="family_specification%2"><STRONG><CODE>family_specification(Fun, Family1) -> Family2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Fun = spec_fun()</CODE></STRONG><BR>
<STRONG><CODE>Family1 = Family2 = family()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If Family1 is a <A HREF="#family">family</A>,
then Family2 is the <A HREF="#restriction"> restriction</A> of Family1 to those elements i of the
index set for which Fun applied to Family1[i] returns
<CODE>true</CODE>. If Fun is a tuple <CODE>{external, Fun2}</CODE>, Fun2
is applied to the <A HREF="#external_set">external
set</A> of Family1[i], otherwise Fun is applied to
Family1[i].
<PRE>1> <STRONG>F1 = sofs:family([{a,[1,2,3]},{b,[1,2]},{c,[1]}]),</STRONG>
<STRONG>SpecFun = fun(S) -> sofs:no_elements(S) =:= 2 end,</STRONG>
<STRONG>F2 = sofs:family_specification(SpecFun, F1),</STRONG>
<STRONG>sofs:to_external(F2).</STRONG>
[{b,[1,2]}]</PRE>
</UL>
<P><A NAME="family_to_digraph%2"><STRONG><CODE>family_to_digraph(Family [, GraphType]) -> Graph</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Graph = digraph()</CODE></STRONG><BR>
<STRONG><CODE>Family = family()</CODE></STRONG><BR>
<STRONG><CODE>GraphType = - see digraph(3) -</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Creates a directed graph from the <A HREF="#family">family</A> Family. For each pair
(a, {b[1], ..., b[n]}) of Family, the vertex
a as well the edges (a, b[i]) for
1 <= i <= n are added to a newly
created directed graph.
<P>If no graph type is given, <CODE>digraph:new/1</CODE> is used for
creating the directed graph, otherwise the GraphType
argument is passed on as second argument to
<CODE>digraph:new/2</CODE>.
<P>It F is a family, it holds that F is a subset of
<CODE>digraph_to_family(family_to_digraph(F), type(F))</CODE>.
Equality holds if <CODE>union_of_family(F)</CODE> is a subset of
<CODE>domain(F)</CODE>.
<P>Creating a cycle in an acyclic graph exits the process with
a <CODE>cyclic</CODE> message.
</UL>
<P><A NAME="family_to_relation%1"><STRONG><CODE>family_to_relation(Family) -> BinRel</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family = family()</CODE></STRONG><BR>
<STRONG><CODE>BinRel = binary_relation()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If Family is a <A HREF="#family">family</A>,
then BinRel is the binary relation containing all pairs
(i, x) such that i belongs to the index set of Family
and x belongs to Family[i].
<PRE>1> <STRONG>F = sofs:family([{a,[]}, {b,[1]}, {c,[2,3]}]),</STRONG>
<STRONG>R = sofs:family_to_relation(F),</STRONG>
<STRONG>sofs:to_external(R).</STRONG>
[{b,1},{c,2},{c,3}]</PRE>
</UL>
<P><A NAME="family_union%1"><STRONG><CODE>family_union(Family1) -> Family2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family1 = Family2 = family()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If Family1 is a <A HREF="#family">family</A>
and Family1[i] is a set of sets for each i in the index set
of Family1, then Family2 is the family with the same index
set as Family1 such that Family2[i] is the <A HREF="#union_n">union</A> of Family1[i];
<CODE>family_union(F)</CODE> is equivalent to
<CODE>family_projection({sofs,union}, F)</CODE>.
<PRE>1> <STRONG>F1 = sofs:from_term([{a,[[1,2],[2,3]]},{b,[[]]}]),</STRONG>
<STRONG>F2 = sofs:family_union(F1),</STRONG>
<STRONG>sofs:to_external(F2).</STRONG>
[{a,[1,2,3]},{b,[]}]</PRE>
</UL>
<P><A NAME="family_union%2"><STRONG><CODE>family_union(Family1, Family2) -> Family3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family1 = Family2 = Family3 = family()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If Family1 and Family2 are <A HREF="#family">families</A>, then Family3 is the
family such that the index set is the union of Family1's and
Family2's index sets, and Family3[i] is the union of
Family1[i] and Family2[i] if both maps i, Family1[i] or
Family2[i] otherwise.
<PRE>1> <STRONG>F1 = sofs:family([{a,[1,2]},{b,[3,4]},{c,[5,6]}]),</STRONG>
<STRONG>F2 = sofs:family([{b,[4,5]},{c,[7,8]},{d,[9,10]}]),</STRONG>
<STRONG>F3 = sofs:family_union(F1, F2),</STRONG>
<STRONG>sofs:to_external(F3).</STRONG>
[{a,[1,2]},{b,[3,4,5]},{c,[5,6,7,8]},{d,[9,10]}]</PRE>
</UL>
<P><A NAME="field%1"><STRONG><CODE>field(BinRel) -> Set</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel = binary_relation()</CODE></STRONG><BR>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#field">field</A> of the
binary relation BinRel; <CODE>field(R)</CODE> is equivalent to
<CODE>union(domain(R), range(R))</CODE>.
<PRE>1> <STRONG>R = sofs:relation([{1,a},{1,b},{2,b},{2,c}]),</STRONG>
<STRONG>S = sofs:field(R),</STRONG>
<STRONG>sofs:to_external(S).</STRONG>
[1,2,a,b,c]</PRE>
</UL>
<P><A NAME="from_external%2"><STRONG><CODE>from_external(ExternalSet, Type) -> AnySet</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>ExternalSet = external_set()</CODE></STRONG><BR>
<STRONG><CODE>AnySet = anyset()</CODE></STRONG><BR>
<STRONG><CODE>Type = type()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Creates a set from the <A HREF="#external_set">external set</A> ExternalSet
and the <A HREF="#type">type</A> Type. It is
assumed that Type is a <A HREF="#valid_type">valid
type</A> of ExternalSet.
</UL>
<P><A NAME="from_sets%1"><STRONG><CODE>from_sets(ListOfSets) -> Set</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
<STRONG><CODE>ListOfSets = [anyset()]</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#sets_definition">unordered
set</A> containing the sets of the list ListOfSets.
<PRE>1> <STRONG>S1 = sofs:relation([{a,1},{b,2}]),</STRONG>
<STRONG>S2 = sofs:relation([{x,3},{y,4}]),</STRONG>
<STRONG>S = sofs:from_sets([S1,S2]),</STRONG>
<STRONG>sofs:to_external(S).</STRONG>
[[{a,1},{b,2}],[{x,3},{y,4}]]</PRE>
</UL>
<P><A NAME="from_sets%1"><STRONG><CODE>from_sets(TupleOfSets) -> Ordset</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Ordset = ordset()</CODE></STRONG><BR>
<STRONG><CODE>TupleOfSets = tuple-of(anyset())</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#sets_definition">ordered
set</A> containing the sets of the non-empty tuple
TupleOfSets.
</UL>
<P><A NAME="from_term%2"><STRONG><CODE>from_term(Term [, Type]) -> AnySet</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>AnySet = anyset()</CODE></STRONG><BR>
<STRONG><CODE>Term = term()</CODE></STRONG><BR>
<STRONG><CODE>Type = type()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P><A NAME="from_term"><!-- Empty --></A>Creates an element of <A HREF="#sets_definition">Sets</A> by traversing the
term Term, sorting lists, removing duplicates and deriving
or verifying a <A HREF="#valid_type">valid
type</A> for the so obtained external set.
<CODE>from_term(T)</CODE> is equivalent to <CODE>from_term(T,
['_'])</CODE>. An explicitly given <A HREF="#type">type</A> Type 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:
<PRE>1> <STRONG>S = sofs:from_term([{{"foo"},[1,1]},{"foo",[2,2]}], [{atom,[atom]}]),</STRONG>
<STRONG>sofs:to_external(S).</STRONG>
[{{"foo"},[1]},{"foo",[2]}]</PRE>
<P><CODE>from_term</CODE> 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
that <STRONG>do</STRONG> 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
does not want to waste heap by rebuilding the elements of
the unordered set. An example showing that a set can be
built "layer by layer":
<PRE>1> <STRONG>A = sofs:from_term(a),</STRONG>
<STRONG>S = sofs:set([1,2,3]),</STRONG>
<STRONG>P1 = sofs:from_sets({A,S}),</STRONG>
<STRONG>P2 = sofs:from_term({b,[6,5,4]}),</STRONG>
<STRONG>Ss = sofs:from_sets([P1,P2]),</STRONG>
<STRONG>sofs:to_external(Ss).</STRONG>
[{a,[1,2,3]},{b,[4,5,6]}]</PRE>
<P>Other functions that create sets are <CODE>from_external/2</CODE>
and <CODE>from_sets/1</CODE>. Special cases of <CODE>from_term/2</CODE>
are <CODE>a_function/1,2</CODE>, <CODE>empty_set/0</CODE>,
<CODE>family/1,2</CODE>, <CODE>relation/1,2</CODE>, and <CODE>set/1,2</CODE>.
</UL>
<P><A NAME="image%2"><STRONG><CODE>image(BinRel, Set1) -> Set2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel = binary_relation()</CODE></STRONG><BR>
<STRONG><CODE>Set1 = Set2 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#image">image</A> of the
set Set1 under the binary relation BinRel.
<PRE>1> <STRONG>R = sofs:relation([{1,a},{2,b},{2,c},{3,d}]),</STRONG>
<STRONG>S1 = sofs:set([1,2]),</STRONG>
<STRONG>S2 = sofs:image(R, S1),</STRONG>
<STRONG>sofs:to_external(S2).</STRONG>
[a,b,c]</PRE>
</UL>
<P><A NAME="intersection%1"><STRONG><CODE>intersection(SetOfSets) -> Set</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
<STRONG><CODE>SetOfSets = set_of_sets()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#intersection_n">intersection</A> of the set
of sets SetOfSets.
<P>Intersecting an empty set of sets exits the process with a
<CODE>badarg</CODE> message.
</UL>
<P><A NAME="intersection%2"><STRONG><CODE>intersection(Set1, Set2) -> Set3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Set1 = Set2 = Set3 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#intersection"> intersection</A> of Set1 and Set2.
</UL>
<P><A NAME="intersection_of_family%1"><STRONG><CODE>intersection_of_family(Family) -> Set</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family = family()</CODE></STRONG><BR>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the intersection of the <A HREF="#family">family</A> Family.
<P>Intersecting an empty family exits the process with a
<CODE>badarg</CODE> message.
<PRE>1> <STRONG>F = sofs:family([{a,[0,2,4]},{b,[0,1,2]},{c,[2,3]}]),</STRONG>
<STRONG>S = sofs:intersection_of_family(F),</STRONG>
<STRONG>sofs:to_external(S).</STRONG>
[2]</PRE>
</UL>
<P><A NAME="inverse%1"><STRONG><CODE>inverse(Function1) -> Function2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Function1 = Function2 = function()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#inverse">inverse</A>
of the function Function1.
<PRE>1> <STRONG>R1 = sofs:relation([{1,a},{2,b},{3,c}]),</STRONG>
<STRONG>R2 = sofs:inverse(R1),</STRONG>
<STRONG>sofs:to_external(R2).</STRONG>
[{a,1},{b,2},{c,3}]</PRE>
</UL>
<P><A NAME="inverse_image%2"><STRONG><CODE>inverse_image(BinRel, Set1) -> Set2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel = binary_relation()</CODE></STRONG><BR>
<STRONG><CODE>Set1 = Set2 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#inverse_image">inverse
image</A> of Set1 under the binary relation BinRel.
<PRE>1> <STRONG>R = sofs:relation([{1,a},{2,b},{2,c},{3,d}]),</STRONG>
<STRONG>S1 = sofs:set([c,d,e]),</STRONG>
<STRONG>S2 = sofs:inverse_image(R, S1),</STRONG>
<STRONG>sofs:to_external(S2).</STRONG>
[2,3]</PRE>
</UL>
<P><A NAME="is_a_function%1"><STRONG><CODE>is_a_function(BinRel) -> Bool</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
<STRONG><CODE>BinRel = binary_relation()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns <CODE>true</CODE> if the binary relation BinRel is a
<A HREF="#function">function</A> or the
untyped empty set, <CODE>false</CODE> otherwise.
</UL>
<P><A NAME="is_disjoint%2"><STRONG><CODE>is_disjoint(Set1, Set2) -> Bool</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
<STRONG><CODE>Set1 = Set2 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns <CODE>true</CODE> if Set1 and Set2 are <A HREF="#disjoint">disjoint</A>, <CODE>false</CODE>
otherwise.
</UL>
<P><A NAME="is_empty_set%1"><STRONG><CODE>is_empty_set(AnySet) -> Bool</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>AnySet = anyset()</CODE></STRONG><BR>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns <CODE>true</CODE> if Set is an empty unordered set,
<CODE>false</CODE> otherwise.
</UL>
<P><A NAME="is_equal%2"><STRONG><CODE>is_equal(AnySet1, AnySet2) -> Bool</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>AnySet1 = AnySet2 = anyset()</CODE></STRONG><BR>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns <CODE>true</CODE> if the AnySet1 and AnySet2 are <A HREF="#equal">equal</A>, <CODE>false</CODE> otherwise.
</UL>
<P><A NAME="is_set%1"><STRONG><CODE>is_set(AnySet) -> Bool</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>AnySet = anyset()</CODE></STRONG><BR>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns <CODE>true</CODE> if AnySet is an <A HREF="#sets_definition">unordered set</A>, and
<CODE>false</CODE> if AnySet is an ordered set or an atomic set.
</UL>
<P><A NAME="is_sofs_set%1"><STRONG><CODE>is_sofs_set(Term) -> Bool</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
<STRONG><CODE>Term = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns <CODE>true</CODE> if Term is an <A HREF="#sets_definition">unordered set</A>, an
ordered set or an atomic set, <CODE>false</CODE> otherwise.
</UL>
<P><A NAME="is_subset%2"><STRONG><CODE>is_subset(Set1, Set2) -> Bool</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
<STRONG><CODE>Set1 = Set2 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns <CODE>true</CODE> if Set1 is a <A HREF="#subset">subset</A> of Set2, <CODE>false</CODE>
otherwise.
</UL>
<P><A NAME="is_type%1"><STRONG><CODE>is_type(Term) -> Bool</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Bool = bool()</CODE></STRONG><BR>
<STRONG><CODE>Term = term()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns <CODE>true</CODE> if the term Term is a <A HREF="#type">type</A>.
</UL>
<P><A NAME="join%4"><STRONG><CODE>join(Relation1, I, Relation2, J) -> Relation3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Relation1 = Relation2 = Relation3 = relation()</CODE></STRONG><BR>
<STRONG><CODE>I = J = integer() > 0</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#natural_join">natural
join</A> of the relations Relation1 and Relation2 on
coordinates I and J.
<PRE>1> <STRONG>R1 = sofs:relation([{a,x,1},{b,y,2}]),</STRONG>
<STRONG>R2 = sofs:relation([{1,f,g},{1,h,i},{2,3,4}]),</STRONG>
<STRONG>J = sofs:join(R1, 3, R2, 1),</STRONG>
<STRONG>sofs:to_external(J).</STRONG>
[{a,x,1,f,g},{a,x,1,h,i},{b,y,2,3,4}]</PRE>
</UL>
<P><A NAME="multiple_relative_product%2"><STRONG><CODE>multiple_relative_product(TupleOfBinRels, BinRel1) ->
BinRel2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>TupleOfBinRels = tuple-of(BinRel)</CODE></STRONG><BR>
<STRONG><CODE>BinRel = BinRel1 = BinRel2 = binary_relation()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If TupleOfBinRels is a non-empty tuple
{R[1], ..., R[n]} of binary relations and BinRel1
is a binary relation, then BinRel2 is the <A HREF="#multiple_relative_product">multiple relative
product</A> of the ordered set
(R[i], ..., R[n]) and BinRel1.
<PRE>1> <STRONG>Ri = sofs:relation([{a,1},{b,2},{c,3}]),</STRONG>
<STRONG>R = sofs:relation([{a,b},{b,c},{c,a}]),</STRONG>
<STRONG>MP = sofs:multiple_relative_product({Ri, Ri}, R),</STRONG>
<STRONG>sofs:to_external(sofs:range(MP)).</STRONG>
[{1,2},{2,3},{3,1}]</PRE>
</UL>
<P><A NAME="no_elements%1"><STRONG><CODE>no_elements(ASet) -> NoElements</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>ASet = set() | ordset()</CODE></STRONG><BR>
<STRONG><CODE>NoElements = integer() >= 0 </CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the number of elements of the ordered or unordered
set ASet.
</UL>
<P><A NAME="partition%1"><STRONG><CODE>partition(SetOfSets) -> Partition</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>SetOfSets = set_of_sets()</CODE></STRONG><BR>
<STRONG><CODE>Partition = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#partition">partition</A> of the union of the
set of sets SetOfSets such that two elements are considered
equal if they are members of the same elements of SetOfSets.
<PRE>1> <STRONG>Sets1 = sofs:from_term([[a,b,c],[d,e,f],[g,h,i]]),</STRONG>
<STRONG>Sets2 = sofs:from_term([[b,c,d],[e,f,g],[h,i,j]]),</STRONG>
<STRONG>P = sofs:partition(sofs:union(Sets1, Sets2)),</STRONG>
<STRONG>sofs:to_external(P).</STRONG>
[[a],[b,c],[d],[e,f],[g],[h,i],[j]]</PRE>
</UL>
<P><A NAME="partition%2"><STRONG><CODE>partition(SetFun, Set) -> Partition</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>SetFun = set_fun()</CODE></STRONG><BR>
<STRONG><CODE>Partition = set()</CODE></STRONG><BR>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#partition">partition</A> of Set such that two
elements are considered equal if the results of applying
SetFun are equal.
<PRE>1> <STRONG>Ss = sofs:from_term([[a],[b],[c,d],[e,f]]),</STRONG>
<STRONG>SetFun = fun(S) -> sofs:from_term(sofs:no_elements(S)) end,</STRONG>
<STRONG>P = sofs:partition(SetFun, Ss),</STRONG>
<STRONG>sofs:to_external(P).</STRONG>
[[[a],[b]],[[c,d],[e,f]]]</PRE>
</UL>
<P><A NAME="partition_family%2"><STRONG><CODE>partition_family(SetFun, Set) -> Family</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family = family()</CODE></STRONG><BR>
<STRONG><CODE>SetFun = set_fun()</CODE></STRONG><BR>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#family">family</A>
Family where the indexed set is a <A HREF="#partition">partition</A> of Set such that two
elements are considered equal if the results of applying
SetFun are the same value i. This i is the index that Family
maps onto the <A HREF="#equivalence_class">equivalence class</A>.
<PRE>1> <STRONG>S = sofs:relation([{a,a,a,a},{a,a,b,b},{a,b,b,b}]),</STRONG>
<STRONG>SetFun = {external, fun({A,_,C,_}) -> {A,C} end},</STRONG>
<STRONG>F = sofs:partition_family(SetFun, S),</STRONG>
<STRONG>sofs:to_external(F).</STRONG>
[{{a,a},[{a,a,a,a}]},{{a,b},[{a,a,b,b},{a,b,b,b}]}]</PRE>
</UL>
<P><A NAME="product%1"><STRONG><CODE>product(TupleOfSets) -> Relation</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Relation = relation()</CODE></STRONG><BR>
<STRONG><CODE>TupleOfSets = tuple-of(set())</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#Cartesian_product_tuple"> Cartesian product</A> of the non-empty tuple of sets
TupleOfSets. If (x[1], ..., x[n]) is an element of
the n-ary relation Relation, then x[i] is drawn from element
i of TupleOfSets.
<PRE>1> <STRONG>S1 = sofs:set([a,b]),</STRONG>
<STRONG>S2 = sofs:set([1,2]),</STRONG>
<STRONG>S3 = sofs:set([x,y]),</STRONG>
<STRONG>P3 = sofs:product({S1,S2,S3}),</STRONG>
<STRONG>sofs:to_external(P3).</STRONG>
[{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>
</UL>
<P><A NAME="product%2"><STRONG><CODE>product(Set1, Set2) -> BinRel</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel = binary_relation()</CODE></STRONG><BR>
<STRONG><CODE>Set1 = Set2 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#Cartesian_product">Cartesian
product</A> of Set1 and Set2. <CODE>product(S1, S2)</CODE> is
equivalent to <CODE>product({S1, S2})</CODE>.
<PRE>1> <STRONG>S1 = sofs:set([1,2]),</STRONG>
<STRONG>S2 = sofs:set([a,b]),</STRONG>
<STRONG>R = sofs:product(S1, S2),</STRONG>
<STRONG>sofs:to_external(R).</STRONG>
[{1,a},{1,b},{2,a},{2,b}]</PRE>
</UL>
<P><A NAME="projection%2"><STRONG><CODE>projection(SetFun, Set1) -> Set2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>SetFun = set_fun()</CODE></STRONG><BR>
<STRONG><CODE>Set1 = Set2 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the set created by substituting each element of
Set1 by the result of applying SetFun to the element.
<P>If SetFun is a number i >= 1 and Set1 is a
relation, then the returned set is the <A HREF="#projection">projection</A> of Set1 onto
coordinate i.
<PRE>1> <STRONG>S1 = sofs:from_term([{1,a},{2,b},{3,a}]),</STRONG>
<STRONG>S2 = sofs:projection(2, S1),</STRONG>
<STRONG>sofs:to_external(S2).</STRONG>
[a,b]</PRE>
</UL>
<P><A NAME="range%1"><STRONG><CODE>range(BinRel) -> Set</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel = binary_relation()</CODE></STRONG><BR>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#range">range</A> of the
binary relation BinRel.
<PRE>1> <STRONG>R = sofs:relation([{1,a},{1,b},{2,b},{2,c}]),</STRONG>
<STRONG>S = sofs:range(R),</STRONG>
<STRONG>sofs:to_external(S).</STRONG>
[a,b,c]</PRE>
</UL>
<P><A NAME="relation%2"><STRONG><CODE>relation(Tuples [, Type]) -> Relation</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>N = integer()</CODE></STRONG><BR>
<STRONG><CODE>Type = N | type()</CODE></STRONG><BR>
<STRONG><CODE>Relation = relation()</CODE></STRONG><BR>
<STRONG><CODE>Tuples = [tuple()]</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Creates a <A HREF="#relation">relation</A>.
<CODE>relation(R, T)</CODE> is equivalent to <CODE>from_term(R,
T)</CODE>, if T is a <A HREF="#type">type</A> and
the result is a relation. If Type is an integer N, then
<CODE>[{atom, ..., atom}])</CODE>, 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 Tuples is
used if there is such a tuple. <CODE>relation([])</CODE> is
equivalent to <CODE>relation([], 2)</CODE>.
</UL>
<P><A NAME="relation_to_family%1"><STRONG><CODE>relation_to_family(BinRel) -> Family</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family = family()</CODE></STRONG><BR>
<STRONG><CODE>BinRel = binary_relation()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#family">family</A>
Family such that the index set is equal to the <A HREF="#domain">domain</A> of the binary relation
BinRel, and Family[i] is the <A HREF="#image">image</A> of the set of i under
BinRel.
<PRE>1> <STRONG>R = sofs:relation([{b,1},{c,2},{c,3}]),</STRONG>
<STRONG>F = sofs:relation_to_family(R),</STRONG>
<STRONG>sofs:to_external(F).</STRONG>
[{b,[1]},{c,[2,3]}]</PRE>
</UL>
<P><A NAME="relative_product%2"><STRONG><CODE>relative_product(TupleOfBinRels [, BinRel1]) -> BinRel2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>TupleOfBinRels = tuple-of(BinRel)</CODE></STRONG><BR>
<STRONG><CODE>BinRel = BinRel1 = BinRel2 = binary_relation()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>If TupleOfBinRels is a non-empty tuple
{R[1], ..., R[n]} of binary relations and BinRel1
is a binary relation, then BinRel2 is the <A HREF="#tuple_relative_product">relative product</A>
of the ordered set (R[i], ..., R[n]) and BinRel1.
<P>If BinRel1 is omitted, the relation of equality between the
elements of the <A HREF="#Cartesian_product_tuple"> Cartesian product</A> of the ranges of R[i],
range R[1] × ... × range R[n],
is used instead (intuitively, nothing is "lost").
<PRE>1> <STRONG>TR = sofs:relation([{1,a},{1,aa},{2,b}]),</STRONG>
<STRONG>R1 = sofs:relation([{1,u},{2,v},{3,c}]),</STRONG>
<STRONG>R2 = sofs:relative_product({TR, R1}),</STRONG>
<STRONG>sofs:to_external(R2).</STRONG>
[{1,{a,u}},{1,{aa,u}},{2,{b,v}}]</PRE>
<P>Note that <CODE>relative_product({R1}, R2)</CODE> is
different from <CODE>relative_product(R1, R2)</CODE>; the
tuple of one element is not identified with the element
itself.
</UL>
<P><A NAME="relative_product%2"><STRONG><CODE>relative_product(BinRel1, BinRel2) -> BinRel3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel1 = BinRel2 = BinRel3 = binary_relation()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P><A NAME="relprod_impl"><!-- Empty --></A>Returns the <A HREF="#relative_product">relative product</A> of the
binary relations BinRel1 and BinRel2.
</UL>
<P><A NAME="relative_product1%2"><STRONG><CODE>relative_product1(BinRel1, BinRel2) -> BinRel3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel1 = BinRel2 = BinRel3 = binary_relation()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#relative_product">relative
product</A> of the <A HREF="#converse">converse</A> of the binary relation
BinRel1 and the binary relation BinRel2;
<CODE>relative_product1(R1, R2)</CODE> is equivalent to
<CODE>relative_product(converse(R1), R2)</CODE>, but is more
efficient.
<PRE>1> <STRONG>R1 = sofs:relation([{1,a},{1,aa},{2,b}]),</STRONG>
<STRONG>R2 = sofs:relation([{1,u},{2,v},{3,c}]),</STRONG>
<STRONG>R3 = sofs:relative_product1(R1, R2),</STRONG>
<STRONG>sofs:to_external(R3).</STRONG>
[{a,u},{aa,u},{b,v}]</PRE>
</UL>
<P><A NAME="restriction%2"><STRONG><CODE>restriction(BinRel1, Set) -> BinRel2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel1 = BinRel2 = binary_relation()</CODE></STRONG><BR>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#restriction"> restriction</A> of the binary relation BinRel1 to Set.
<PRE>1> <STRONG>R1 = sofs:relation([{1,a},{2,b},{3,c}]),</STRONG>
<STRONG>S = sofs:set([1,2,4]),</STRONG>
<STRONG>R2 = sofs:restriction(R1, S),</STRONG>
<STRONG>sofs:to_external(R2).</STRONG>
[{1,a},{2,b}]</PRE>
</UL>
<P><A NAME="restriction%3"><STRONG><CODE>restriction(SetFun, Set1, Set2) -> Set3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>SetFun = set_fun()</CODE></STRONG><BR>
<STRONG><CODE>Set1 = Set2 = Set3 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a subset of Set1 containing those elements that
yield an element in Set2 as the result of applying SetFun.
<PRE>1> <STRONG>S1 = sofs:relation([{1,a},{2,b},{3,c}]),</STRONG>
<STRONG>S2 = sofs:set([b,c,d]),</STRONG>
<STRONG>S3 = sofs:restriction(2, S1, S2),</STRONG>
<STRONG>sofs:to_external(S3).</STRONG>
[{2,b},{3,c}]</PRE>
</UL>
<P><A NAME="set%2"><STRONG><CODE>set(Terms [, Type]) -> Set</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
<STRONG><CODE>Terms = [term()]</CODE></STRONG><BR>
<STRONG><CODE>Type = type()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Creates an <A HREF="#sets_definition">unordered
set</A>. <CODE>set(L, T)</CODE> is equivalent to
<CODE>from_term(L, T)</CODE>, if the result is an unordered set.
If no <A HREF="#type">type</A> is explicitly
given, <CODE>[atom]</CODE> is used as type of the set.
</UL>
<P><A NAME="specification%2"><STRONG><CODE>specification(Fun, Set1) -> Set2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Fun = spec_fun()</CODE></STRONG><BR>
<STRONG><CODE>Set1 = Set2 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the set containing every element of Set1 for which
Fun returns <CODE>true</CODE>. If Fun is a tuple <CODE>{external,
Fun2}</CODE>, Fun2 is applied to the <A HREF="#external_set">external set</A> of each
element, otherwise Fun is applied to each element.
<PRE>1> <STRONG>R1 = sofs:relation([{a,1},{b,2}]),</STRONG>
<STRONG>R2 = sofs:relation([{x,1},{x,2},{y,3}]),</STRONG>
<STRONG>S1 = sofs:from_sets([R1,R2]),</STRONG>
<STRONG>S2 = sofs:specification({sofs,is_a_function}, S1),</STRONG>
<STRONG>sofs:to_external(S2).</STRONG>
[[{a,1},{b,2}]]</PRE>
</UL>
<P><A NAME="strict_relation%1"><STRONG><CODE>strict_relation(BinRel1) -> BinRel2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel1 = BinRel2 = binary_relation()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#strict_relation">strict
relation</A> corresponding to the binary relation
BinRel1.
<PRE>1> <STRONG>R1 = sofs:relation([{1,1},{1,2},{2,1},{2,2}]),</STRONG>
<STRONG>R2 = sofs:strict_relation(R1),</STRONG>
<STRONG>sofs:to_external(R2).</STRONG>
[{1,2},{2,1}]</PRE>
</UL>
<P><A NAME="substitution%2"><STRONG><CODE>substitution(SetFun, Set1) -> Set2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>SetFun = set_fun()</CODE></STRONG><BR>
<STRONG><CODE>Set1 = Set2 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a function, the domain of which is Set1. The value
of an element of the domain is the result of applying SetFun
to the element.
<PRE>1> <STRONG>L = [{a,1},{b,2}].</STRONG>
[{a,1},{b,2}]
2> <STRONG>sofs:to_external(sofs:projection(1,sofs:relation(L))).</STRONG>
[a,b]
3> <STRONG>sofs:to_external(sofs:substitution(1,sofs:relation(L))).</STRONG>
[{{a,1},a},{{b,2},b}]
4> <STRONG>SetFun = {external, fun({A,_}=E) -> {E,A} end},</STRONG>
<STRONG>sofs:to_external(sofs:projection(SetFun,sofs:relation(L))).</STRONG>
[{{a,1},a},{{b,2},b}]</PRE>
<P>The relation of equality between the elements of {a,b,c}:
<PRE>1> <STRONG>I = sofs:substitution(fun(A) -> A end, sofs:set([a,b,c])),</STRONG>
<STRONG>sofs:to_external(I).</STRONG>
[{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 <A HREF="#image">image</A>
of Set under BinRel is returned by this function:
<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
elements of R (to that comes the sorting of results, the
image). In <CODE>images/2</CODE>, BinRel will be traversed once
for each element of SetOfSets, which may take too long. The
following efficient function could be used instead, assuming
that SetOfSets does not contain an empty set and that BinRel
is non-empty:
<PRE>images2(SetOfSets, BinRel) ->
CR = sofs:canonical_relation(SetOfSets),
R = sofs:relative_product1(CR, BinRel),
sofs:relation_to_family(R).</PRE>
</UL>
<P><A NAME="symdiff%2"><STRONG><CODE>symdiff(Set1, Set2) -> Set3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Set1 = Set2 = Set3 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#symmetric_difference"> symmetric difference</A> (or the Boolean sum) of Set1
and Set2.
<PRE>1> <STRONG>S1 = sofs:set([1,2,3]),</STRONG>
<STRONG>S2 = sofs:set([2,3,4]),</STRONG>
<STRONG>P = sofs:symdiff(S1, S2),</STRONG>
<STRONG>sofs:to_external(P).</STRONG>
[1,4]</PRE>
</UL>
<P><A NAME="symmetric_partition%2"><STRONG><CODE>symmetric_partition(Set1, Set2) -> {Set3, Set4, Set5}</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Set1 = Set2 = Set3 = Set4 = Set5 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a triple of three sets: Set3 contains the elements
of Set1 that do not belong to Set2; Set4 contains the
elements of Set1 that belong to Set2; Set5 contains the
elements of Set2 that do not belong to Set1.
</UL>
<P><A NAME="to_external%1"><STRONG><CODE>to_external(AnySet) -> ExternalSet</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>ExternalSet = external_set()</CODE></STRONG><BR>
<STRONG><CODE>AnySet = anyset()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#external_set">external
set</A> of an atomic, ordered or unordered set.
</UL>
<P><A NAME="to_sets%1"><STRONG><CODE>to_sets(ASet) -> Sets</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>ASet = set() | ordset()</CODE></STRONG><BR>
<STRONG><CODE>Sets = tuple_of(AnySet) | [AnySet]</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the elements of the ordered set ASet as a tuple of
sets, and the elements of the unordered set ASet as a sorted
list of sets without duplicates.
</UL>
<P><A NAME="type%1"><STRONG><CODE>type(AnySet) -> Type</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>AnySet = anyset()</CODE></STRONG><BR>
<STRONG><CODE>Type = type()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#type">type</A> of an
atomic, ordered or unordered set.
</UL>
<P><A NAME="union%1"><STRONG><CODE>union(SetOfSets) -> Set</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
<STRONG><CODE>SetOfSets = set_of_sets()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#union_n">union</A> of the
set of sets SetOfSets.
</UL>
<P><A NAME="union%2"><STRONG><CODE>union(Set1, Set2) -> Set3</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Set1 = Set2 = Set3 = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the <A HREF="#union">union</A> of
Set1 and Set2.
</UL>
<P><A NAME="union_of_family%1"><STRONG><CODE>union_of_family(Family) -> Set</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>Family = family()</CODE></STRONG><BR>
<STRONG><CODE>Set = set()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns the union of the <A HREF="#family">family</A> Family.
<PRE>1> <STRONG>F = sofs:family([{a,[0,2,4]},{b,[0,1,2]},{c,[2,3]}]),</STRONG>
<STRONG>S = sofs:union_of_family(F),</STRONG>
<STRONG>sofs:to_external(S).</STRONG>
[0,1,2,3,4]</PRE>
</UL>
<P><A NAME="weak_relation%1"><STRONG><CODE>weak_relation(BinRel1) -> BinRel2</CODE></STRONG></A><BR>
<P><UL>Types:
<UL>
<STRONG><CODE>BinRel1 = BinRel2 = binary_relation()</CODE></STRONG><BR>
</UL>
</UL>
<UL>
<P>Returns a subset S of the <A HREF="#weak_relation">weak relation</A> W
corresponding to the binary relation BinRel1. Let F be the
<A HREF="#field">field</A> of BinRel1. 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.
<PRE>1> <STRONG>R1 = sofs:relation([{1,1},{1,2},{3,1}]),</STRONG>
<STRONG>R2 = sofs:weak_relation(R1),</STRONG>
<STRONG>sofs:to_external(R2).</STRONG>
[{1,1},{1,2},{2,2},{3,1},{3,3}]</PRE>
</UL>
<H3>See Also</H3>
<UL>
<P><A HREF="dict.html">dict(3)</A>,
<A HREF="digraph.html">digraph(3)</A>,
<A HREF="orddict.html">orddict(3)</A>,
<A HREF="ordsets.html">ordsets(3)</A>,
<A HREF="sets.html">sets(3)</A>
</UL>
<H3>AUTHORS</H3>
<UL>
Hans Bolinder - support@erlang.ericsson.se<BR>
</UL>
<CENTER>
<HR>
<FONT SIZE=-1>stdlib 1.10<BR>
Copyright © 1991-2001
<A HREF="http://www.erlang.se">Ericsson Utvecklings AB</A><BR>
<!--#include virtual="/ssi/otp_footer.html"-->
</FONT>
</CENTER>
</BODY>
</HTML>
|