Extended Set syntax for GEMPACK Release 10.0-002 (April 2010)

New set complement operator "\"

As before, the set operator "-" is used to denote the set complement. The elements of the complement are all the elements in <setname1> which are not in <setname2>. You can only use set operator "-" in the expression "<setname1> - <setname2>" if every element in <setname2> is also in <setname1>.

For Release 10.0-002 or later, we have introduced another set complement operator "\". If
<setname> = <setname1> \ <setname2>
then, as with "-", the elements of <setname> are all elements of <setname1> which are not elements of <setname2>. However, there is no longer the requirement that every element of <setname2> is also an element of <setname1>. That is, when you use "\", there may be some elements of <setname2> which are not elements of <setname1>.

Suppose, for example, that we have the two statements

SET SET1 (c1-c5) ;
SET SET2 (c3, c1, d5) ;

Notice that element "d5" is in set SET2 but not in SET1. Then the statement

SET3 = SET1 - SET2 ;

is not allowed while the statement

SET4 = SET1 \ SET2 ;

is valid and the elements of SET4 will be c2, c4 and c5.

We call "SET1 - SET2" the set complement of SET2 in SET1 while we call "SET3 \ SET4" the relative complement of SET4 in SET3. The word "relative" is used to indicate that not every element of the set after the operator needs to be an element of the set before the operator.

Simple examples of union, intersection and complements

! given: !
Set DomCOM # Domestic Commodities# (Food, Manufact, Services) ;
Set ExportCOM #Export Commodities# (ExportFood, Manufact) ;

! Union !
Set AllCOM2 # Domestic and Export Commodities UNION # = DomCOM UNION ExportCOM ;
! result: Food, Manufact, Services, ExportFood !

! Intersection !
Set CommonCOM # Commodities which are both Domestic and Export Commodities#
            = DomCOM INTERSECT ExportCOM ;
! result: Manufact !

! Complement !
Set NonExportCOM # Domestic commodities which are not exported #  = DomCOM - CommonCOM ;
! result: Food, Services !

! Disjoint Set Union !
Set ALLCOM # Domestic and Export Commodities + # =  ExportCOM + NonExportCOM ;
! result: ExportFood, Manufact, Food, Services!

Longer set expressions

For Release 10.0-002 or later, we allow longer set expressions involving the set operators UNION, INTERSECT, "+", "-" and "\". You are also allowed to use brackets "(" or ")" to indicate the order of doing these operations. [But other types of brackets "[", "]", "{" and "}" are not allowed in set expressions.]

These operators can appear on the right-hand side of a SET statement (that is, after "="). Also on this right-hand side can be the names of sets already declared in the TAB file. And, as well as sets, you are allowed to give a name in quotes "" which indicates a single element. Examples should make this clear.

 SET SET1 (c1-c5) ;
SET SET2 (c3, c1, d5) ;
SET SET3 (d1-d7) ;
SET SET4 (domestic, imported) ;
SET SetExp1 = SET1 UNION SET2 + "cars" ;
SET SetExp2 = SET1 - SET2 + "imports" ;
SET SetExp3 = SET1 \ (SET2 - "c1") ;
SET SetExp4 = "hous" + "gov" + "exp" ;
SET SetExp5 = SET4 UNION (SET2 INTERSECT SET3) + "wool" ; 

You should be able to figure out the elements of the sets SetExp1 to SetExp5 determined by the set expressions above, especially when we tell you that (in the absence of brackets indicating otherwise) operations are carried out from left to right. That is, for example, the expression
SET1 - SET2 - SET3
is evaluated as
(SET1 - SET2) - SET3.

Set expressions can involve the 5 set operators UNION, INTERSECT, "+", "-" and "\". non-intertemporal sets whose elements will be known at run time. single elements in quotes.

In order for "+" to be valid, the two sets whose elements are being "+"ed must be disjoint.

In order for "-" to be valid, every element of the set whose elements are being "-"ed must be in the set doing the "-"ing.

Consider the following examples.

SET NewSet1 = Set1 UNION Set2 + Set3 - Set4 ;
SET NewSet2 = Set5 - (Set6 + Set7) ;

For the first of these statements to be valid, Set3 must have no elements which are also in (Set1 UNION Set2) and every element in Set4 must be in (Set1 UNION Set2 + Set3).

For the second of these statements to be valid, Set7 must have no elements which are also in Set6 and every element in (Set6 + Set7) must also be in Set5.

Of course if you use brackets, they must make sense. For example

SET NewSet1 = (NewSet2 - NewSet3) + (NewSet5 ;

is not valid since the brackets do not make sense.

So now you can have a set expression on the RHS of a SET statment as in

SET <set_name> [#<information># ] = <set-expression>  ;

Special Rule
As with Release 10 and earlier, if you specify a simple set complement

SET <set_name> = <setname1> - <setname2> ;

then set <setname2> must have been already declared as a SUBSET of <setname1> (in a SUBSET statement).

Implied Subsets

Consider the statement

SET NewSet1 = Set2 UNION Set3 UNION Set4 ;

Clearly Set2, Set3 and Set4 will all be subsets of NewSet1. TABLO adds these SUBSET statements in this case.

There are several other cases where TABLO adds the "obvious" SUBSET statements.

Rules for Implied Subset Statements

1. If all operators are UNION and/or + then every RHS set is subset of LHS set. [This is true even if there are some brackets on the RHS.]
2. If all operators are INTERSECT then LHS set is subset of every RHS set. [This is true even if there are some brackets on the RHS.]
3. If RHS ends <expression> UNION Set2 then Set2 is subset of LHS set.
4. If RHS ends <expression> Union Set2 then Set2 is subset of LHS set.
5. If RHS ends <expression> INTERSECT Set2 then LHS is subset of Set2.
6. Simple complement. If just one "-" or "\" operation between two sets Set1 = Set2 - Set3 [or Set1 = Set2 \ Set3], then Set1 is Subset of Set2.

There may be other cases when you know that your set expression implies a SUBSET relationship. But TABLO may not be as clever as you are. So, if in doubt, add the SUBSET statement yourself. If TABLO also figured it out, you will be told that your SUBSET statement is redundant. But if you leave it out and TABLO does not figure it out, you may get an error later in your TAB file. That is why you should include the statement if in doubt.