Modulo Arithmetic and Casting Out Nines

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Modulo Arithmetic and

Casting out Nines


How to Check Results

– Redo calculations in different order

– Estimate answer

– Modulo arithmetic

– Casting out nines


Estimate Answer

Round numbers to single digits

Perform calculation

For multiply add the errors to obtain error estimate in result
Example Estimating Multiplication

Suppose we want to estimate 15 × 25

15 rounds to 20 with error of -5/20 = -25%

25 rounds to 30 with error of -5/30 = -17%

Estimate is 20 × 30 with error of -25 -17 = -42%

≈ 600 × (1-.4) = 360

Exact answer is 375
Modulo Arithmetic

X mod n is the remainder of X
divided by n

23 mod 10 = 3

23 mod 2 = 1

17 mod 5 = 2

20 mod 9 = 2
Remainder Tests
Base Remainder mod Base
2 0 if last digit is 0,2,4,6, or 8; 1 if last digit 1,3,5,7, or 9
3 0 if digit sum is 3,6, or 9; 1 for 1,4, or 7; 2 for 2,5, or 8.
4 Remainder of rightmost 2 digist ÷4.
5 Last digit if <5; last digit -5 if in {5,6,7,8,9}.
6 Number is divisible by both 2 and 3.
9 Sum of digits if SOD ≠ 9; 0 if SOD = 9.
Uses of Modulo Arithmetic
Checksums: ISBN numbers, international bank account numbers

Public Key Encryption

Music: 12-tone scale

Day of the week.

Arithmetic: Checking and casting out nines.

Generating passwords
Checking with Modulo Arithmetic

Perform arithmetic on numbers and obtain answer

Reduce each number to a single-digit checksum using mod

Perform same arithmetic operations on the checksums

The checksum of the answer will be the same as the


arithmetic result on the checksums
Using modulo arithmetic to check

If x + y = z then (x mod n) + (y mod n) = z mod n

This means we can use a single digit checksum


to test our answers

Some checksums are (3, 9, 10) easy to calculate


Example: n = 10

X mod 10 is just the last digit of the number

16 mod 10 = 6; 35 mod 10 = 5; 51 mod 10 = 1

16 + 35 = 51

(6+5) mod 10 = 1

51 mod 10 =1, so the sum checks
More interesting: N = 9
Addition Casting Out Nines
Numbers Checksums
388885 4
+815636 2
+897025 4
+ 93137 5
+ 41544 0
+324038 2
2560265 8
Checks!
Subtraction Mod 9

-x is the value that sums with x to 0

x + -x = 0

In mod 9 arithmetic -x is the value that sums to 9

-1 mod 9 = 9 - 1 = 8

-2 mod 9 = 9 - 2 = 7

etc
Subtraction Casting Out Nines


707649 mod 9 = (7+7+6+4) mod 9 = 2+4 = 6

435342 mod 9 = 3

707649 - 435342 = 272307

272307 mod 9 = 3

(6 - 3) mod 9 = 3

The difference checks!
Casting out Nines
Reduces complicated arithmetic to single digit operations

Can be used to check addition, subtraction, and multiplication

Check division by multiplying the result and adding remainder

Example:

20/8 = 2 rem 4

20 = 2 × 8 + 4 (can be tested with this)


Casting Out 9s: Example

92.31569 + 231 + 9.277 + 98.04


+ 2.8056
A) 433.43829  
B) 433.44829  
C) 433.53829
D) 434.43829
Casting Out 9s Solution
Check by casting out 9s

92.31569 + 231 + 9.277 + 98.04 + 2.8056


Checksums: 8 + 6 + 7 + 3 + 3 = 0
A) 433.43829 checksum 0   Correct answer
B) 433.44829 checksum 1 
C) 433.53829 checksum 1
D) 434.43829 checksum 1
Quiz 9, Question 22
Use casting out nines to select the correct answer:
7642.16 + 6805.74 + 2460.93 + 9162.30 = ?

number residue answers residues


7642.16 8
26061.13 1
6805.74 3
2460.93 6 26071.13 2
9162.30 3 26070.13 1
residue sum is 2
26071.23 3
Quiz 9, Question 23
Use casting out nines to select the correct answer:
7642.16 - 6805.74 + 2460.93 - 9162.30 = ?

number residue answers residues


7642.16 8 5864.95 1
-6805.74 9-3=6
2460.93 6 -5864.95 9-1=8
-9162.30 9-3=6 -5884.95 9-3=6
sum of residues = 8
5884.95 3

You might also like