===============================================================================
22c:181 Formal Methods in Software Engineering, Spring 2012
Exercise Set 1 -- Selected solutions
===============================================================================
1. Specify using comprehension notation:
- Odd positive integers
{ x : Z | x > 0 /\ x mod 2 = 1 }
- The squares of integers
{ x : N | (exists y : Z | x = y*y) }
2. Express the following logic properties on sets without using the # operator
(NOTE: let S represent the set in question)
- Set has at least one element
exists x | x in S
also
S != {}
- Set has no elements
not (exists x | x in S)
also
S = {}
- Set has exactly one element
exists x : S | (forall y : S | y = x)
also
exists a | S = {a}
- Set has at least two elements
exists x : S | (exists y : S | y != x )
- Set has exactly two elements
exists x : S | (exists y : S | y != x /\ (forall z : S | z = x \/ z = y))
also
exists x | (exists y | x != y /\ S = {x,y})
3. In the following, if an operator fails to preserve a property give an example
a. What operators preserve function-ness?
- Intersection?
Yes.
- Union?
No.
Let f = { (1,1) } and let g = { (1,2) }. These are both partial functions,
but (f U g) is not since it maps 1 to both 1 and 2.
- Set Difference?
Yes.
b. What operators preserve onto-ness?
- Intersection?
No.
Let f = { (2,1), (3,1), (4,2) } and g = { (1,2), (2,1) }. These are both
onto wrt the set {1,2}. But their intersection is { (2,1) } is not.
- Union?
Yes.
- Set difference?
No.
Let f and g both be the function { (1,1) }, which is onto wrt the set {1}.
Their difference {} is not onto.
c. What operators preserve 1-1-ness?
- Intersection?
Yes.
- Union?
No.
Let f = { (1,1) } and g = { (2,1) }. (f union g) = { (1,1), (2,1) }
maps distinct elements, 1 and 2, to the element 1.
- Set difference?
Yes.
4. In the following if an operator fails to preserve a property give an example.
What properties, i.e. function-ness, onto-ness, 1-1-ness, are preserved by
these relation operators?
- Composition (;)
Preserves function-ness, onto-ness, 1-1-ness
- Closure (+)
Does not preserve function-ness
({ (a,b), (b,c) }+ = { (a,b), (a,c), (b,c) }, maps a to to both b and c)
Preserves onto-ness
Does not preserve 1-1-ness
({ (a,b), (b,c) }+ = { (a,b), (a,c), (b,c) }, maps both a and b to c)
- Transpose (~)
Does not preserve function-ness
(~{ (a,c), (b,c) } = { (c,a), (c,b) })
Does not preserve onto-ness
({ (a,a), (a,b) }, an onto function from {a,b} to itself.
~{ (a,a), (a,b) } = { (a,a), (b,a) } is not onto wrt {a,b})
Preserves 1-1-ness