(合同算術)
http://www.sw.it.aoyama.ac.jp/2014/Math1/lecture13.html
© 2005-15 Martin J. Dürst Aoyama Gakuin University
About makeup classes: The material in the makeup class is part of the final exam. If you have another makeup class at the same time, please inform the teacher as soon as possible.
補講について: 補講の内容は期末試験の対象。補講が別の補講とぶつかる場合には事前に申し出ること。
In the definition of a Boolean algebra, the following was correct as printed:
(前回配布した資料のまま正しかった)
If we define isomorphic groups as being "the same", there are two different groups of size 4. Give an example of each group as a Cayley table.
Hint: Check all the conditions (axioms) for a group. There will be a deduction if you use the same elements of the group as another student.
Solution 1: Cyclic group of order 4, interesting examples: Addition modulo 4, rotation by multiples of 90°, {1, 2, 3, 4} and multiplication modulo 5
[都合により削除]
Solution 2: Klein group, interesting examples: bitstrings of length 2 with XOR, reflections and rotations by 180°
[都合により削除]
Draw the Hasse diagram of a Boolean algebra of order 4 (16 elements). There will be a deduction if you use the same elements of the group as another student.
Solution: For examples, see handouts of last week
(hierarchy of objects)
Operations work on 8, 16, 32, or 64 bits concurrently
b << n
in C and many other programming
languagesb
by n
positions
to the left (more significant direction)n
bits its on the right are set to 0n
bits in b
disappearb <<
n
is equivalent to b ×2nb >> n
in C and many other programming
languagesb
by n
positions
to the right (less significant direction)n
bits on the left are set to 0 or to the value of the
leftmost bit in b
,n
bits in b
disappearb >> n
is equivalent to b /
2na | m
a & ~m
a ^ m
a | (1<<n)
(rightmost bit is number 0)a & ~(1<<n)
(rightmost bit is number 0)a ^ (1<<n)
(rightmost bit is number 0)For many more advanced examples, see Hacker's Delight, Henry S. Warren, Jr., Addison-Wesley, 2003
Works the same as in decimal system:
Example (base 7):
Operand 1 | 3 | 6 | 5 | 1 | 2 | |
Operand 2 | 6 | 0 | 3 | 3 | 4 | |
carry | 1 | 1 | 1 | |||
Result | 1 | 3 | 0 | 1 | 4 | 6 |
0 | 1 | |
---|---|---|
0 | 0 | 1 |
1 | 1 | 10 |
^
b0, and&
b0<<
1, repeat until c is 0a ≡(mod n) b ⇔ a - b = qn ⇔ a = q1n + r ∧ b = q2n + r ∧ 0 ≦ r < n
Reason: a ≡(mod n) a mod n, and so on
Division for rationals: a/b = c ⇔a b-1 = c; b b-1 = 1 (inverse)
Modular multiplicative inverse): bb-1 ≡ 1
n | b | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
---|---|---|---|---|---|---|---|---|---|
2 | - | 1 | |||||||
3 | - | 1 | 2 | ||||||
4 | - | 1 | - | 3 | |||||
5 | - | 1 | 3 | 2 | 4 | ||||
6 | - | 1 | - | - | - | 5 | |||
7 | - | 1 | 4 | 5 | 2 | 3 | 6 | ||
8 | - | 1 | - | 3 | - | 5 | - | 7 |
Only defined if n are b coprime (i.e. GCD is 1)
Various methods to calculate
a/b (mod n) is defined as a b-1 (mod n)
Example: 3/4 (mod 7) = 3 · 4-1 (mod 7) = 3 · 2 (mod 7) = 6
(Check: 6 · 4 (mod 7) = 24 (mod 7) = 3)
%
(C, Ruby and many other programming
languages)、mod (Mathematics)remainder for negative operands | |||||||
---|---|---|---|---|---|---|---|
operands | always non-negative | same sign as divisor | same sign as dividend | ||||
a | n | q | r | q | r | q | r |
11 | 7 | 1 | 4 | 1 | 4 | 1 | 4 |
-11 | 7 | -2 | 3 | -2 | 3 | 1 | -4 |
11 | -7 | -1 | 4 | -2 | -3 | -1 | 4 |
-11 | -7 | 2 | 3 | 1 | -4 | -1 | -4 |
Programming languages,... | Pascal, this lecture | Ruby, Python, MS Excel | C (ISO 1999), Java, JavaScript, Perl, PHP |
See English Wikipedia article on Modulo Operation
Output some data items, three items on a line.
A simple way:
int items = 0; for (i=0; i<length; i++, items++) { /* print out data[i] */ if (items==3) { printf("\n"); items = 0; } }
Using the modulo operation:
for (i=0; i<length; i++) { /* print out data[i] */ if (i%3 == 2) printf("\n"); }
Example: 216 mod 29 = ?
216 = 25 · 25 · 25 · 2
216 = 25 · 25 · 25 · 2 = 32 · 32 · 32 · 2 ≡(mod 29) 3 · 3 · 3 · 2 = 54 ≡(mod 29) 25