Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Exercise Week 2

Uploaded by

Mka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Exercise Week 2

Uploaded by

Mka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Exercises for week 2 (I2CA)

(1) 1) a ≡ b modk ↔ ∃z ∈ Z : a − b = z ∗ k

2) (y mod k) = x ↔
x = ϵ{b | y ≡ b mod k ∧ b ∈ [0 : k − 1]}.
3) (y tmod k) = x ↔
x = ϵ{b | y ≡ b mod k ∧ b ∈ [−k/2 : k/2 − 1]}. (k has to be even)

(2) 1) 195 ≡ 6mod10 is false, because 195 − 6 = 189 and ̸ ∃z ∈ Z such that 189 = 10 ∗ z
2) 195 ≡ 5mod10 is true, because (195 − 5) = 190 = 19 ∗ 10 so take z = 19
3) 195 ≡ −6mod10 is false, because ̸ ∃z ∈ Z such that 201 = 10 ∗ z
4) (195mod10) = 5 is true, because first of all 195 ≡ 5mod10 is true, at the same time
5 ∈ [0 : 9]
5) (195mod10) = −5 is false, because even though congruence relation holds for -5,
−5 ̸∈ [0 : 9]

6) (195tmod10) = −5 is true, because first of all 195 ≡ −5mod10 and at the same time
−5 ∈ [−10/2 : 10/2 − 1] = [−5 : 4]

(3) 1) (maxint + 1)tmodK = (K/2 − 1 + 1)tmodK = (K/2)tmodK now we subtract K un-


til we are in range, K/2−K = −K/2 ∈ [−K/2 : (K/2)−1] , thus answer is −K/2 = minint

2) (minint − 1)tmodK = (−K/2 − 1)tmodK now we add until we are in range −K/2 −
1 + K = K/2 − 1 → (−K/2 − 1)tmodK = K/2 − 1 = maxint
3) −minint tmodK = K/2 tmodK = −K/2 = minint as we discussed in (1) exercise this
is how signed binary numbers work in every statically typed programming language (as I
know so far) let’s take an example in Java.

Figure 1: byte has length of 8 bits, 27 − 1 = 127 range is [−128 : 127]

as a result we get -128.


(4) 1) [10110] = −1∗24 +22 +21 = −16+4+2 = −10 or let’s take complement component-wise
and add 1 ⟨01001⟩ + 1 = 9 + 1 = 10 thus the original number was -10.
2) [00110] = ⟨110⟩ = 2 + 4 = 6
3) [111111111111111111111110110] = [10110] = −10. (we used sign extension lemma,
useful lemma when we have a sign extension unit in our single core sequential processor).

(5) modulo 2n is missing (think about an example where without modulo it won’t hold)

(6) 1) 100001 − 010101 = 100001 + 101010 + 1mod26 = 1001011 + 1mod26 = 1001100mod26 =


001100 and if we interpret that number we get: ⟨001100⟩ = 12
you can check the result with following python code:
x = int ( ” 100001 ” , 2 )
y = int ( ” 010101 ” , 2 )
print ( x = y )

2) 100001 − 10 = 100001 − 000010 = 100001 + 111101 + 1mod26 = 1011110 + 1mod26 =


011111 and ⟨011111⟩ = 31
x=( int ( ” 100001 ” , 2 ) )
y=( int ( ” 10 ” , 2 ) )
print ( x=y )

(7) we prove by induction on y, x ∗ 0 = 0 ∗ x = 0 IH: x ∗ y = y ∗ x, we have to prove:


x ∗ S(y) = S(y) ∗ x x ∗ S(y) = x ∗ y + x = y ∗ x + x = (y + 1) ∗ x = S(y) ∗ x where we
used induction hypothesis where we exchanged x ∗ y with y ∗ x and then already proved
distributivity with respect to addition (1).

(8) ⟨1, 0⟩ = 1 ∗ 21 + 0 ∗ 20 = 1 ∗ 2 = 2 = 0 + 1 + 1 = 1 + 1 = 2

You might also like