Modular Arithmetic

(合同算術)

Discrete Mathematics I

13th lecture, December 22, 2017

http://www.sw.it.aoyama.ac.jp/2017/Math1/lecture13.html

Martin J. Dürst

AGU

© 2005-17 Martin J. Dürst Aoyama Gakuin University

Today's Schedule

 

Remaining Schedule

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.

補講について: 補講の内容は期末試験の対象。補講が別の補講とぶつかる場合には事前に申し出ること。

 

Questions about Final Exam

 

Last Week's Homework

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 lecture

 

Summary of Algebraic Structures

(hierarchy of objects)

 

Applications of Bitwise Operations

Operations work on 8, 16, 32, 64 or more bits concurrently

 

Other Bitwise Operations

 

Applications of Bitwise Operations

For many more advanced examples, see Hacker's Delight, Henry S. Warren, Jr., Addison-Wesley, 2003

 

Addition in Different Numeral Systems

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
sum in base 10 1 10 7 8 4 6
sum in base 7 1 13 10 11 4 6
Result 1 3 0 1 4 6

 

Addition using Bitwise Operations

Single Digit Addition
0 1
0 0 1
1 1 10

 

Example of Addition Using Bitwise Operations

Example: a0 = 46 = 101110、b0 = 55 = 110111

x 0 1 2 3
ax (sx-1) 101110 011001 1010101 1000101
bx (cx-1<<1) 110111 1001100 0010000 0100000
sx (a0^b0) 011001 1010101 1000101 1100101 = 101 (result)
cx (a0&b0) 100110 001000 0010000 0000000 = 0 (finished)
cx<<1 1001100 0010000 0100000 0000000

 

Modular Arithmetic

 

Congruence Relation

 

Properties of Congruence Equations

 

Properties of the Modulo Operation

Reason: a(mod n) a mod n, and so on

Where to use: a and c may be very large numbers, but a mod n and c mod n may be much smaller, so calculation becomes easier.

 

Modulo Operation

See English Wikipedia article on Modulo Operation

 

An Example of Using the Modulo Operation

Output some data, three items on a line.

A simple way:

int items = 0;
for (i=0; i<count; i++) {
    /* print out data[i] */
    items++;
    if (items==3) {
        printf("\n");
        items = 0;
    }
}

Using the modulo operation:

for (i=0; i<count; i++) {
    /* print out data[i] */
    if (i%3 == 2)
        printf("\n");
}

 

Congruence and Groups

 

Congruence and Division

Division and inverse for rationals: a/b = ca·1/b = a b-1 = c

Condition for (multiplicative) inverse b-1: b b-1 = 1

Condition for 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

The modular multiplicative inverse is only defined if n and b are coprime (i.e. GCD is 1)

Various methods to calculate, very time-consuming

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)

 

Application of Congruence: Simple Calculation of Remainder

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

 

Remainder Calculation: More Examples

318 mod 7 = ?

318 = (33)6 = 276 (mod 7) (-1)6 = 1

4110 mod 37 = ?

4110 (mod 37) 410 = 220 = 324 (mod 37) (-5)4 = 252 (mod 37) (-12)2 = (6 · 2)2 = 36 · 4 (mod 37) (-1) · 4 = -4 (mod 37) 33

 

Homework

Prepare for final exam

 

Student Survey

(授業改善のための学生アンケート)

WEB Survey

お願い: 自由記述に必ず良かった点、問題点を具体的に書きましょう

(悪い例: 発音が分かりにくい; 良い例: さ行が濁っているかどうか分かりにくい)

 

Glossary

rotation
回転
reflection
反射
hierarchy
階層
concurrent
同時
shift
シフト
invert
逆転、反転
modular arithmetic
合同算術
congruence (equation)
合同式
modulus
residue
剰余
modulo operation
剰余演算
congruence relation
合同関係
congruence class
合同類
residue class
剰余類
cyclic group
巡回群
modular multiplicative inverse
モジュラー逆数
operator
演算子
dividend
被除数
divisor
除数
implementation
実装