0% found this document useful (0 votes)
7 views11 pages

DMFP Soln Selected

This document provides solutions to exercises in Discrete Mathematics and Functional Programming, aimed at aiding student self-evaluation. It includes solutions to various topics such as set notation, recursive functions, lists, propositions, proofs, relations, and equivalence relations. Each section corresponds to exercises from a textbook, with some sections omitted where no exercises or solutions are available.

Uploaded by

Tanmay Tripathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views11 pages

DMFP Soln Selected

This document provides solutions to exercises in Discrete Mathematics and Functional Programming, aimed at aiding student self-evaluation. It includes solutions to various topics such as set notation, recursive functions, lists, propositions, proofs, relations, and equivalence relations. Each section corresponds to exercises from a textbook, with some sections omitted where no exercises or solutions are available.

Uploaded by

Tanmay Tripathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Selected solutions to Discrete Mathematics and

Functional Programming
Thomas VanDrunen
August 13, 2013

This document is to provide a resource for students studying Discrete Mathe-


matics and Functional Programming either on their own or in an academic course.
The purpose is to aid student self-evaluation. Sections in this document are set to
reflect book sections from which the exercises come. Accordingly, some sections are
skipped here, either because the corresponding sections in the book have no exercises
or no solutions are provided.

1 Set
1.3 Set notation
1.3.2. False. 1.3.4. True. 1.3.6. False. 1.3.8. False. 1.3.10. True.

1.11 Making your own operations


1.11.3.
fun add(Int(x), Int(y)) = Int(x + y)
| add(Real(x), Real(y)) = Real(x + y)
| add(Int(x), Real(y)) = Real(real(x) + y)
| add(Real(x), Int(y)) = Real(x + real(y));
1.11.5.
fun replaceFries(Meal(e, Fries, b), s) = Meal(e, s, b)
| replaceFries(Meal(e, s1, b), s2) = Meal(e, s1, b);
1.11.8
(* included here for reference *)
datatype rational = Fraction of int * int;
fun subtract(Fraction(a, b), Fraction(c, d)) =
let val numerator = a * d - c * b;
val denominator = b * d;
val divisor = gcd(numerator, denominator);
in Fraction(numerator div divisor, denominator div divisor)
end;

1
1.12 Recursive functions
1.12.4

fun multiply(x, 0) = 0
| multiply(x, y) = x + multiply(x, y-1);

]1.12.6

fun arithSum(0) = 0
| arithSum(n) = n + arithSum(n-1) ;

2 List
2.1 Lists
2.1.1

[ tl( [ |{z} 12 , |{z}


5 , |{z} 6 ]) @ [ |{z}
8 , |{z} 9 ]]
| int {z int int
} | int {z int }
int list int list
| {z }
int list
| {z }
int list
| {z }
int list list

2.1.5

hd( [ |{z} 6 ]) :: [ |{z}


5 , |{z}
12 , |{z} 7 ]
2 , |{z}
int int int int int
| {z } | {z }
int list int list
| {z }
int
| {z }
int list

2.1.8

[ [ ( |{z}
2.3 , |{z}
5 ), ( |{z}
8.1 , |{z}
6 )], [] ]
|{z}
real int real int (real * int) list
| {z } | {z }
(real * int) (real * int)
| {z }
(real * int) list
| {z }
(real * int) list list

2.2 Functions on lists


2.2.4

fun count([]) = 0
| count(a::rest) = 1 + count(rest);

2
2.2.5

fun findNth([], n) = ~1
| findNth(a::rest, 0) = a
| findNth(a::rest, n) = findNth(rest, n-1)

2.2.6

fun reverse([]) = []
| reverse(a::rest) = reverse(rest) @ [a];

2.2.10

fun listify([]) = []
| listify(a::rest) = [a] :: listify(rest);

2.2.12

fun splitList([]) = ( [] , [] )
| splitList( (a, b )::rest) =
let
val (x, y) = splitList(rest);
in
( a::x , b::y)
end;

3 Proposition
3.3 Boolean values
3.3.4

fun turnToInts([]) = []
| turnToInts(true::rest) = 1::turnToInts(rest)
| turnToInts(false::rest) = 0::turnToInts(rest);

3.4 Logical equivalence


3.4.5
p ∧ (∼ q ∨ (p∧ ∼ p))
≡ p ∧ (∼ q ∨ F Negation
≡ p∧ ∼ q Identity

3.4.6

3
(q ∧ p)∨ ∼ (p∨ ∼ q)
≡ (q ∧ p) ∨ (∼ p ∧ q) DeMorgan’s and double negative
≡ q ∧ (p∨ ∼ p) Distributive (and commutative)
≡ q∧T Negation
≡ q Identity

3.4.7
((q ∧ (p ∧ (p ∨ q))) ∨ (q∧ ∼ p))∧ ∼ q
≡ ((q ∧ p) ∨ (q∧ ∼ p))∧ ∼ q Absorption
≡ (q ∧ (p∨ ∼ p))∧ ∼ q Distributivity
≡ (q ∧ T )∧ ∼ q Negation
≡ q∧ ∼ q Identity
≡ F Negation

4 Proof
4.2 Subset proofs
4.2.1.
Proof. Suppose a ∈ A. [By generalization, a ∈ A or a ∈ B.] By
definition of union, a ∈ A ∪ B. Therefore, by definition of subset, A ⊆
A ∪ B. 2

4.2.8.
Proof (long version). Suppose x ∈ A × (B − C). By definition of
Cartesian product, x = (a, d) for some a ∈ A and d ∈ B − C. By
definition of difference, d ∈ B and d ∈
/ C.
By definition of Cartesian product, (a, d) ∈ A × B. Also by definition of
Cartesian product, this time used negatively, (a, d) ∈
/ A × C.
[That is, we rewrite d ∈/ C. as ∼ (d ∈ C). By generalization, ∼ (d ∈
C ∧ a ∈ A). By definition of Cartesian product, ∼ ((a, d) ∈ A × C). This
can be rewritten as (a, d) ∈
/ A × C.]
By definition of difference, (a, d) ∈ (A × B) − (A × C). By substitution,
x ∈ (A × B) − (A × C). Therefore, by definition of subset, A × (B − C) ⊆
(A × B) − (A × C). 2
Proof (short version). Suppose (a, d) ∈ A × (B − C). By definition
of Cartesian product, a ∈ A and d ∈ B − C.
By definition of difference, d ∈ B and d ∈
/ C. By definition of Cartesian
product, (a, d) ∈ A × B and (a, d) ∈/ A × C.
By definition of difference, (a, d) ∈ (A × B) − (A × C). Therefore, by
definition of subset, A × (B − C) ⊆ (A × B) − (A × C). 2

4
5 Relation
5.3 Image, inverse, and composition
Ex 5.3.5.

Proof. Suppose R is a relation over A and suppose (a, b) ∈ R.


Further suppose x ∈ IR (b). By definition of image, (b, x) ∈ R. By
definition of composition (a, x) ∈ R ◦ R. By definition of image again,
x ∈ IR◦R (b). Therefore, by definition of subset, IR (b) ⊆ IR◦R (a). 2

Ex 5.3.7.

Proof. Suppose R is a relation over A and that (a, b) ∈ R.


[Note that (a, b) ∈ R implies that both a and b must be elements of A.]
Suppose x ∈ IR (b). By definition of image, (b, x) ∈ IR (b). Since (a, b) ∈
R, we have (a, x) ∈ R ◦ R by definition of composition. Moreover x ∈
IR◦R (a) by definition of image.
Therefore IR (b) ⊆ IR◦R (a) by definition of subset. 2

Ex 5.3.10.

Proof. First suppose (x, y) ∈ iB ◦ R. By definition of function compo-


sition, there exists b ∈ B such that (x, b) ∈ R and (b, y) ∈ iB .
By definition of the identity relation, b = y. By substitution, (x, y) ∈ R.
Hence iB ◦ R ⊆ R by definition of subset.
Next suppose (x, y) ∈ R. By how R is defined, we know x ∈ A and
y ∈ B.
By definition of the identity relation, (y, y) ∈ iB . By definition of com-
position, (x, y) ∈ iB ◦ R. Hence R ⊆ iB ◦ R.
Therefore, by definition of set equality, iB ◦ R = R. 2

5.4 Properties of relations


Ex 5.4.6.

Proof. Suppose x ∈ Z. By arithmetic, x − x = 0 = 0 · 2, and so x − x


is even by definition. So (x, x) ∈ R by how R is defined. Therefore R is
reflexive by definition. 2

Ex 5.4.7.

5
Proof. Suppose x, y ∈ Z such that (x, y) ∈ R. By how R is definited,
x − y is even. By definition of even, there exists c ∈ Z such that x − y =
2 · c. By arithmetic, y − x = 2 · -c, which is even by definition. (y, x) ∈ R
by how R is defined. Therefore R is symmetric by definition. 2

Ex 5.4.8.

Proof. Suppose x, y, z ∈ Z such that (x, y), (y, z) ∈ R. By how R is


defined, x − y and y − z are even. By definition of even, there exist
c, d ∈ Z such that x − y = 2 · c and y − z = 2 · d. By arithmetic and
algebra,
x − z = x + (y − y) − z
= x−y+y−x
= 2·c+2·d
= 2 · (c + d)

Since c + d ∈ Z, x − z is even by definition, and (x, z) ∈ R by how R is


defined. Therefore, R is transitive by definition. 2

Let R and S be relations on a set X and let A ⊆ X.


Ex 5.4.21.

Proof. Suppose R and S are both reflexive. Suppose x ∈ X. By defini-


tion of reflexive, (x, x) ∈ R and (x, x) ∈ S. By definition of intersection,
(x, x) ∈ R ∩ S. Therefore R ∩ S is reflexive by definition. 2

6
Ex 5.4.23.

Proof. Suppose R and S are both symmetric. Suppose further that


(x, y) ∈ (S ◦ R) ∪ (R ◦ S).
By definition of union, (x, y) ∈ S ◦ R or (x, y) ∈ R ◦ S.
Case 1: Suppose (x, y) ∈ S ◦ R. Then there exists z ∈ X such that
(x, z) ∈ R and (z, y) ∈ S. Since R and S are symmetric, (z, x) ∈ R
and (y, z) ∈ S, by definition of symmetric. By definition of composition,
(y, z) ∈ R ◦ S. Hence (y, z) ∈ (S ◦ R) ∪ (R ◦ S) by definition of union.
Case 2: Similar to case 1, just interchange S and R.
Either way, (y, z) ∈ (S ◦R)∪(R◦S), and so (S ◦R)∪(R◦S) is symmetric
by definition 2

Ex 5.4.25.

Proof. Suppose a ∈ A. Since R is reflexive, (a, a) ∈ R. By definition of


image, a ∈ IR (A). Therefore A ⊆ IR (A) by definition of subset. 2

6 Equivalence relations
Ex 5.5.4.

Proof. Suppose R is reflexive and for all a, b, c ∈ A, if (a, b) ∈ R and


(b, c) ∈ R, then (c, a) ∈ R.
Reflexivity: Given.
Symmetry: Suppose x, y ∈ A such that (x, y) ∈ R. Since R is reflexive,
(y, y) ∈ R. By the assumed property [taking a = x, b = y and c = y],
(y, x) ∈ R. Hence R is symmetric by definition.
Transitivity: Suppose x, y, z ∈ A such that (x, y) ∈ R an (y, z) ∈ R. By
the assumed property, (z, x) ∈ R. By symmetry (proven in the previous
part of this proof), (x, z) ∈ R. Hence R is transitive by definition.
Therefore R is an equivalence relation by definition. 2

Ex 5.5.6.

Proof. Suppose R is an equivalence relation and (a, b) ∈ R. Then


suppose x ∈ IR (a). By definition of image, (a, x) ∈ R. By definition
of symmetry, (b, a) ∈ R. By definition of transitivity, (b, x) ∈ R. By
definition of image x ∈ IR (b). Hence by definition of subset, IR (a) ⊆
IR (b).
Next suppose x ∈ IR (b). By definition of image, (b, x) ∈ R. By definition
of transitivity, (a, x) ∈ R. Hence by definition of subset, IR (b) ⊆ IR (a).
Therefore, by definition of set equality, IR (a) = IR (b). 2

7
6.7 Transitive closure
Ex 5.7.2.

Proof. Suppose R is a relation on A.


[R ∪ iA is reflexive:] Suppose a ∈ A. (a, a) ∈ iA by definition of identity
relation. (a, a) ∈ R ∪ iA by definition of union. Hence R ∪ iA is reflexive
by definition.
[R ⊆ R ∪ iA :] Suppose (a, b) ∈ R. Then (a, b) ∈ R ∪ iA by definition of
uniion. Hence R ⊆ R ∪ iA . (Alternately, we could have cited Exercise
4.2.1. Or, if I wasn’t so mean, I could let you just say “by definition of
union.”)
[R ∪ iA is the smallest such relation:] Suppose S is a reflexive relation
such that R ⊆ S. Suppose further (a, b) ∈ R ∪iA . By definition of union,
(a, b) ∈ R or (a, b) ∈ iA .
Case 1: Suppose (a, b) ∈ R. Then (a, b) ∈ S by definition of subset
(since we supposed R ⊆ S).
Case 2: Suppose (a, b) ∈ iA . Then, by definition of identity relation,
a = b. (a, a) ∈ S by definition of reflexive (since we suppose S is
reflexive). (a, b) ∈ S by substitution.
Either way, (a, b) ∈ S and hence R ∪ iA ⊆ S by definition of subset.
Therefore, R ∪ iA is the reflexive closure of R. 2

7 Function
7.4 Images and inverse images
Ex 7.4.1.
Suppose A, b ⊆ X. Further suppose y ∈ F (A ∩ B).
By definition of image, there exists x ∈ A ∩ B such that f (x) = y. By
definition of intersection, x ∈ A and x ∈ B. By definition of image,
y ∈ F (A) and y ∈ F (B). By definition of intersection again, y ∈
F (A) ∩ F (B).
Therefore, by definition of subset, F (A ∩ B) ⊆ F (A) ∩ F (B). 2

Ex 7.4.3.
Attempted proof. Suppose A, B ∈ X. Further suppose y ∈ F (A − B).
By definition of image, there exists x ∈ A − B such that f (x) = y. By
definition of difference, x ∈ A and x ∈
/ B.
By definition of image, y ∈ F (A). Also by definition of image, used
negatively, y ∈
/ F (B), right?

8
NO! Just because x ∈ / B and f (x) = y does not mean that there isn’t
some other element in B that also hits y. Thus here is our counterex-
ample:

X = {x, b}; A = {x}; B = {b}; Y = {y}; f = {(x, y), (b, y)}


F (A − B) = F ({x} − {b}) = F ({x}) = {y}
F (A) − F (B) = F ({x}) − F ({b}) = {y} − {y} = ∅

7.4.4.

Suppose A ⊆ B ⊆ X.
First suppose y ∈ F (B). By definition of image, there exists x ∈ B such
that f (x) = y.
Now, either x ∈ A of x ∈/ A by the negation law. [How did we come up
with that? We looked ahead and noticed that we want either y ∈ F (B−A)
or y ∈ F (A) and saw how that would depend on x ∈ A or x ∈ / A.]
Case 1: Suppose x ∈ A. Then, by definition of image, y ∈ F (A). By
definition of union, y ∈ F (B − A) ∪ F (A).
Case 2: Suppose x ∈ / A. Then, by definition of difference, x ∈ B − A,
and by definition of image, y ∈ F (B − A). By definition of union,
y ∈ F (B − A) ∪ F (A).
Either way, y ∈ F (B − A) ∪ F (A) and hence F (B) ⊆ F (B − A) ∪ F (A)
by definition of subset.
Next suppose y ∈ F (B −A)∪F (A). By definition of union, y ∈ F (B −A)
or y ∈ F (A).
Case 1: Suppose y ∈ F (B − A). By definition of image, there exists
x ∈ B − A such that f (x) = y. By definition of difference, x ∈ B. So
y ∈ F (B) by definition of image.
Case 2: Suppose y ∈ F (A). By definition of image, there exists x ∈ A
such that f (x) = y. By definition of subset, x ∈ B. So y ∈ F (B) by
definition of image.
Either way, y ∈ F (B), and hence F (B − A) ∪ F (A) ⊆ F (B) by definition
of subset.
Therefore, by definition of set equality, F (B) = F (B − A) ∪ F (A). 2

Ex 7.4.6.

Proof. Suppose A ⊆ B ⊆ Y . Further suppose x ∈ F −1 (A).


By definition of inverse image, there exists y ∈ A such that f (x) = y.
By definition of subset, y ∈ B. By definition of inverse image again,
x ∈ F −1 (B).
Therefore, by definition of subset, F −1 (A) ⊆ F −1 (B). 2

9
In the proof above, we could also do without the variable y. It’s simply another
name for that same mathematical object that we call f (x):

Proof. Suppose A ⊆ B ⊆ Y . Further suppose x ∈ F −1 (A).


By definition of inverse image, f (x) ∈ A. By definition of subset, f (x) ∈
B. By definition of inverse image again, x ∈ F −1 (B).
Therefore, by definition of subset, F −1 (A) ⊆ F −1 (B). 2

Ex 7.4.7.

Proof. Suppose A, B ∈ Y .
First suppose x ∈ F −1 (A ∪ B). By definition of inverse image, f (x) ∈
A ∪ B. By definition of union, f (x) ∈ A and f (x) ∈ B.
Case 1: Suppose f (x)inA. By definition of image, x ∈ F −1 (A). By
definition of union, x ∈ F −1 (A) ∪ F −1 (B).
Case 2: Similarly, if f (x) ∈ B, x ∈ F −1 (A) ∪ F −1 (B).
Either way, x ∈ F −1 (A)∪F −1 (B) and so F −1 (A∪B) ⊆ F −1 (A)∪F −1 (B)
by definition of subset.
Next suppose x ∈ F −1 (A) ∪ F −1 (B). By definition of union, x ∈ F −1 (A)
or x ∈ F −1 (B).
Case 1: Suppose x ∈ F −1 (A). By definition of inverse image, f (x) ∈ A.
By definition of union, f (x) ∈ A ∪ B. By definition of inverse image
again, x ∈ F −1 (A ∪ B).
Case 2: Similarly, if x ∈ F −1 (B), x ∈ F −1 (A ∪ B). Either way, x ∈
F −1 (A ∪ B) and so F −1 (A) ∪ F −1 (B) ⊆ F −1 (A ∪ B).
Therefore, by definition of set equality, F −1 (A ∪ B) = F −1 (A) ∪ F −1 (B).
2

7.6 Function properties


7.6.4.

Proof. Suppose A ⊆ X and f is one-to-one. Further suppose x ∈


F −1 (F (A)). By definition of inverse image, f (x) ∈ F (A).
[By definition if image, x ∈ A, right? NO! At least, not immediately.
From what we have said so far, we know that something in A maps to
f (x), but we don’t yet know that x is that something. In other words, we
need to use the definition of one-to-one—and use it correctly.]
By definition of image, there exists some a ∈ A such that f (a) = f (x).
Then by definition of one-to-one, a = x. So x ∈ A by substitution.
Therefore F −1 (F (A)) ⊆ A by definition of subset. 2

10
Ex 7.6.5.
Proof. Suppose A ⊆ Y and f is onto. Further suppose y ∈ A.
By definition of onto, there exists x ∈ X such that f (x) = y. By
definition of inverse image, x ∈ F −1 (A). By definition of image, y ∈
F (F −1 (A)).
Therefore, by definition of subset, A ⊆ F (F −1 (A)). 2

Ex 7.8.4.
Proof. Suppose f : A → B and g : B → C are both onto.
[Now, we want to prove “ontoness.” Of which function? g ◦ f . How
do we prove ontoness? We pick something from the codomain of the
function we’re proving to be onto and show that it is hit. What is the
codomain of g ◦ f ? C.]
Further suppose c ∈ C. [We need to come up with something in the
domain of g ◦ f that hits c. The domain is A. We will use the fact that
f and g are both onto.] By definition of not, there exists b ∈ B such
that g(b) = c. Similarly there exists a ∈ A such that f (a) = b. Now,

g ◦ f (a) = g(f (a)) by definition of function composition


= g(b) by substitution
= c by substitution

Therefore g ◦ f is onto by definition. 2

Ex 7.8.8.
Proof. Suppose f : A → B, g : A → B, h : B → C, h is onto, and
h ◦ f = h ◦ g.
[This is a proof of function equality. Remember those? The two functions
we’re showing to be equal are f and g. How do we prove two functions
are equal? We pick an element in their (mutual) domain and show that
the two functions map it to the same thing. What is the domain of f
and g? A.]
Suppose a ∈ A. [We need to show f (a) = g(a).] Then

h(f (a)) = h ◦ f (a) by definition of function composition


= h ◦ g(a) by definition of function equality, since h ◦ f = h ◦ g
= h(g(a)) by definition of function composition

Since h(f (a)) = h(g(a)), we then have that f (a) = g(a) by definition of
onto (because h is onto). Therefore, by definition of function equality,
f = g. 2

11

You might also like