You may build expressions where several set operators are combined. When several set operators are included in the same expression, the expression is evaluated from left to right. So if you for example have three sets s1, s2 and s3, the expression
s1.isect(s2).union(s3)will give a set consisting of all codes either in the sets s1 and s2, or in set s3:
Figure 1 - Set Example 1
s1.isect(s2).union(s3)To force a sub-expression to be evaluated before other expressions, you can insert entire expressions inside the parentheses of the set methods. In the expression
s1.isect(s2.union(s3))the sub-expression s2.union(s3) will be evaluated first, and then the intersection between the result of this sub-expression and the set s1 is computed. The result is a set consisting of all codes both in s1and in either of s2 or s3:
Figure 2 - Set Example 2
s1.isect(s2.union(s3))Figure 3 - Set Example 3
You have three sets: s1, s2 and s3. s1 consists of the codes 1,2,5,7,10,11, s2 consists of the codes 3,4,5,8,11,13 and s3 consists of the codes 2,4,5,6,9,10,12, as indicated in the illustration above.
What elements will the sets returned from the following expressions contain?
- s1.union(s3.diff(s2))
- s1.union(s3).diff(s2)
- s1.isect(s2.diff(s3))
- s1.isect(s2).union(s2.isect(s3)).union(s3.isect(s1))
The answers are given in APPENDIX A Answers to Exercises.