CS160: Foundations in Programming: Spring 2015

The purpose of this lab is to learn sets and functions:

- Go over sets in math
- Perform basic set operations

Given that:

- N = {0,1,2,3,4,...} is the set of natural numbers
- Z = {...,-2,-1,0,1,2,...} is the set of all integers
- Z
^{+}= {1,2,3,4,....} is the set of all positive integers - R is the set of all real numbers

- For each of these pairs of sets, determine whether the first is a subset
of the second, the second a subset of the first, or neither is a subset
of the other.
- The set of students in this class, and the set of students who are majoring in Computer Science in this class.
- the set of mammals, the set of land mammals.
- the set of students studying computer science, the set of students studying mathematics

- For each of the following sets, identify the cardinality of the set.
- {1,3,5,7,2,4,6,7,8,10}
- x ∈ N | 0 ≤ x ≤ 64
- x ∈ Z | -10 < x < 10 and x is even
- x ∈ Z
^{+}| x ≤ 6 - the set of primary colors
- the set of months in the year
- the set of midterms in this class

- List the members of these sets
- (x | x is a real number such that x
^{2}= 1) - (x | x is a positive integer less than 7)
- (x | x is a squared integer and x < 99)
- (x | x is an integer such that x
^{2}= 3)

- (x | x is a real number such that x
- For the following sets: A = {4, 6, 8, 10}, B = {3, 4, 5, 6, 7, 9, 11};
- What is the cardinality of A and B?
- What is the union of A and B?
- What is the intersection of A and B?
- What is the complement of A, if the universal set is N?
- What is A minus B?
- What is B minus A?
- Does A minus B = B minus A?
- The TA will draw a Venn diagram that shows why.

- f(x) = Math.sqrt(x), where x and f(x) are defined as doubles and x ≥ 0.

- f(x) = Math.floor(x), where x is defined as a double and f(x) as an integer.

- f(x) = x + 5, where x and f(x) are integers.

- f(x) = x
^{3}, where x is an integer.

- f(x) = x
^{2}- 6x + 8, where x is an integer.

- f(x) = x % 16, where x is a positive integer.

- f(x) = x.length(), where x is a Java string with 4-8 characters, and f(x) is an integer.

- f(x) = x.substring(1, 6), where x is a Java string with exactly 8 characters.