# Solutions to First Midterm Exam

### Directions:

• This is a closed book and notes exam.
• No computer or calculators of any kind are allowed.
• Please make sure that your phone is turned off and out of reach.
• There are seven questions for 100 total points. Scale was A = 95, C = 75.
• If you finish early, please read over your solutions and make sure that they are clear and correct. Use any extra time to improve their correctness and clarity.
• Partial credit will be given for partial solutions. Good luck!

```  Q1: 20 points
Q2: 15 points
Q3: 10 points
Q4: 15 points
Q5: 15 points
Q6: 10 points
Q7: 15 points
Total: 100 points
```

Question text is in black, solutions in blue.

• Question 1 (20): Determine whether the following rules define functions from the given domain to co-domain, and if so, whether they are 1:1, onto, both, or neither. If you say that the function is 1:1 and onto, then also describe its inverse. Recall that Σb = {0, 1}.

• (a) a: RR where a(x) = x3

This is a function and is both 1:1 and onto. The inverse function is a-1(x) = x1/3, the cube root of x.

• (b) b: Σb × Σb → Σb × Σb where b(x, y) = (x ⊕ y, y)

This is a function and is both 1:1 and onto. The function's inverse is itself.

• (c) c: RR where c(x) = 1/x

This is not a function from the given domain to the given co-domain, since c(0) is not defined.

• (d) d: ZZ where d(x) = x ⋅ |x|

This is a function and is 1:1, but not onto. Since the domain elements are integers, the range elements are perfect squares (or their additve inverses) and not every integer is a perfect square.

• (e) e: N × NZ where e(x, y) = 6x - 3y

This is a function but is neither 1:1 nor onto. For example, e(1, 2) = e(2, 4), and every integer in the range is a multiple of 3.

• Question 2 (15): Let r be the proposition "it is raining", let c be "I go to class today", let h be "I did my homework", let b be "I go bicycling today", and let g be "I will have a great day". Write PropCalc formulas to express each of the following. Then convert each of your formulas to CNF. (Recall that CNF is conjunctive normal form: and's of or's of literals.)

• (a) If I've done my homework and I go to class then I will have a great day.

The statement translates as "((h ∧ c) → g)". To get CNF, we first use the definition of implication to get "¬(h ∧ c) ∨ g). We then use DeMorgan to get "(¬h ∨ ¬c) ∨ g". Because ∨ is associative, we can remove the parentheses to get "¬h ∨ ¬c ∨ g". This is an or-clause and is also the and of one or-clause, so it is in CNF.

• (b) If I go bicycling and do not go to class then I will have a great day, but I won't go bicycling if it is raining.

The statement translates as "((b ∧ ¬c) → g) ∧ (r → ¬b)". (Note that "but" just means "and" here, with an additional connotation not captured by the PropCalc statement. Also note that all those parentheses are necessary because different boolean operators are in general not associative with each other.)

To get CNF, we first use the definition of implication twice to get "(¬(b ∧ ¬c) ∨ g) ∧ (¬r ∨ b)". We then use DeMorgan (and associativity of ∨) to get "(¬b ∨ c ∨ g) ∧ (¬r ∨ ¬b)" which is the and of two or-clauses and is thus in CNF.

• Question 3 (10): Define {a, b}* = {λ, a, b, aa, ab, ba, bb, aaa,...} to be the set of all finite strings from the alphabet {a, b}. A finite string is a finite sequence of symbols, including λ which is the empty string. Argue that {a, b}* is countably infinite, i.e., it has the same cardinality as N.

There are at least two possible proofs. It is possible to construct a 1:1 correspondence (a function that is both 1:1 and onto, also called a bijection) from {a, b}* to N with a bit of care. The strings are listed in a standard order with smaller strings first and alphabetical order among strings of the same length. We can get a bijection by mapping each string to its position in this order starting from 0, but I may or may not have been fully convinced by your definition of this order. The nicest definition I know of this map is take w in {a, b}*, convert it to binary by mapping a to 0 and b to 1, prepend a 1, and subtract 1.

You get more flexibility in defining your functions if you quote the Schroeder-Bernstein Theorem (done in lecture), which says that if there are 1:1 functions from X to Y and from Y to X, then there is a bijection between the two sets and they thus by definition have the same cardinality. We can get a 1:1 function from {a, b}* to N by mapping a's to 1's and b's to 2's, then interpreting the result as a decimal number. (Many of you wanted to map a's to 0's and b's to 1's and interpret the result as binary. This is not 1:1 because, for example, f(a) = f(aa) = 0 -- the binary strings 0 and 00 represent the same number. An easy 1:1 function from N just takes the number n to the string an, so that g(0) = λ and g(3) = aaa.

• Question 4 (15): Use Euclid's algorithm to solve the following problems:

• (a) Compute gcd(119, 15).

119 = 7 ⋅ 15 + 14, 15 = 1 ⋅ 14 + 1; 14 = 14 ⋅ 1 + 0, 1 is the last positive number occurring and is this the gcd.

• (b) Express gcd(119, 5) as a linear combination of 119 and 15.

119 = 1 ⋅ 119 + 0 ⋅ 15, 15 = 0 ⋅ 119 + 1 ⋅ 15, 14 = 1 ⋅ 119 - 7 ⋅ 15, 1 = -1 ⋅ 119 + 8 ⋅ 15.

• (c) If 15 has a multiplicative inverse modulo 119, compute it. If not, explain why not.

There is an inverse because the gcd is 1. From (b) we see that 8 ⋅ 15 ≡ 1 (mod 119), so 8 is the multiplicative inverse.

• Question 5 (15): Use Euclid's algorithm to solve the following problems:

• (a) Compute gcd(253, 66).

253 = 3 ⋅ 66 + 55, 66 = 1 ⋅ 55 + 11, 55 = 5 ⋅ 11 + 0. Here 11 is the last positive number occurring and is thus the gcd.

• (b) Express gcd(253, 66) as a linear combination of 253 and 66.

253 = 1 ⋅ 253 + 0 ⋅ 66, 66 = 0 ⋅ 253 + 1 ⋅ 66, 55 = 1 ⋅ 253 - 3 ⋅ 66, 11 = -1 ⋅ 253 + 4 ⋅ 66.

• (c) If 66 has a multiplicative inverse modulo 253, compute it. If not, explain why not.

There is no multiplicative inverse because the gcd of the two numbers is not 1. The gcd, 11, divides any linear combination of 253 and 66, but if y were the desired inverse we would have k ⋅ 253 + y ⋅ 66 = 1 for some integer k, and 11 does not divide 1.

• Question 6 (10): Compute 99 mod 11. Please use the repeated-squaring method taught in class.

Since the binary for 9 is 1000, we see that 99 = 98 ⋅ 91 and so the same equation holds modulo 11. We successively compute 9 ≡ 9 (mod 11), 92 = 81 ≡ 4 (mod 11), 94 = (92)2 ≡ 42 = 16 ≡ 5 (mod 11), and 98 = (94)2 ≡ 52 ≡ 3 (mod 11). Then 99 ≡ 3 ⋅ 9 ≡ 5 (mod 11).

• Question 7 (10): Find the smallest natural number that satisfies the following congruences: x ≡ 3 (mod 4), x ≡ 4 (mod 5), and x ≡ 1 (mod 7). Please use the method taught in class.

We know by the Chinese Remainder Theorem that x ≡ c (mod 4⋅5⋅7), where c = 3⋅5⋅7⋅y1 + 4⋅4⋅7⋅y2 + 1⋅4⋅5⋅y3 and y1, y2, and y3 are the appropriate multiplicative inverses. We compute that y1 = (35)-1 (mod 4) = 3, that y2 = (28)-1 (mod 5) = 2, and that y3 = (20)-1 (mod 7) = -1 or 6. Then c is 315 + 224 - 20 = 519 or 315 + 224 + 120 = 659, and either of these numbers reduced modulo 140 is 99. We can and should check that 99 meets the three given congruences.