438
Relations, Functions, and Matrices
Image(1) is the first image displayed. After that, at every clock tick (or at predefined intervals), the statements
i = i mod 5 + 1
DisplayImage = Image(i)
are executed. The effect is to cycle the index i through the values 2, 3, 4, 5, 1, and
so on, and to cycle the displayed images as Image(2), Image(3), Image(4), Image(5), Image(1), and so on.
The modulo function can also be used to decompose a multidigit integer into
its component digits.
example 59
To decompose a three-digit integer into the ones, tens, and hundreds digits, one can
use the following algorithm:
temp = number
ones = temp mod 10
temp = (temp − ones)∙10
tens = temp mod 10
temp = (temp − tens)∙10
hundreds = temp
■
PRaCtiCe 49 Given the integer 375, walk through the algorithm of Example 59 to separate the digits.
Modular Arithmetic Designs
The mod function can be used to make interesting quiltlike patterns by arranging
“tile” images (small square images) in tables based on addition modulo n and then
repeating these tables to form the completed quilt image.
4
addition modulo n is
defined on the set of integers 50, 1, 2, …, n − 16 by
x + n y = (x + y) mod n
4 This section on modular arithmetic designs was adapted with permission from http://britton.disted. camosun.
bc.ca/modart/jbmodart2.htm; the software used to generate the design is Cayley Quilter, available to download at http://www.wou.edu/~burtonl/cquilter.html
example 60
In this example we will use addition modulo 6. Addition modulo 6 applies to the
integers 50, 1, 2, 3, 4, 56 using the rule x + 6 y = (x + y) mod 6. The addition table follows. It shows, for example,
3 + 6 4 = (3 + 4) mod 6 = 7 mod 6 = 1
Relations, Functions, and Matrices
Image(1) is the first image displayed. After that, at every clock tick (or at predefined intervals), the statements
i = i mod 5 + 1
DisplayImage = Image(i)
are executed. The effect is to cycle the index i through the values 2, 3, 4, 5, 1, and
so on, and to cycle the displayed images as Image(2), Image(3), Image(4), Image(5), Image(1), and so on.
The modulo function can also be used to decompose a multidigit integer into
its component digits.
example 59
To decompose a three-digit integer into the ones, tens, and hundreds digits, one can
use the following algorithm:
temp = number
ones = temp mod 10
temp = (temp − ones)∙10
tens = temp mod 10
temp = (temp − tens)∙10
hundreds = temp
■
PRaCtiCe 49 Given the integer 375, walk through the algorithm of Example 59 to separate the digits.
Modular Arithmetic Designs
The mod function can be used to make interesting quiltlike patterns by arranging
“tile” images (small square images) in tables based on addition modulo n and then
repeating these tables to form the completed quilt image.
4
addition modulo n is
defined on the set of integers 50, 1, 2, …, n − 16 by
x + n y = (x + y) mod n
4 This section on modular arithmetic designs was adapted with permission from http://britton.disted. camosun.
bc.ca/modart/jbmodart2.htm; the software used to generate the design is Cayley Quilter, available to download at http://www.wou.edu/~burtonl/cquilter.html
example 60
In this example we will use addition modulo 6. Addition modulo 6 applies to the
integers 50, 1, 2, 3, 4, 56 using the rule x + 6 y = (x + y) mod 6. The addition table follows. It shows, for example,
3 + 6 4 = (3 + 4) mod 6 = 7 mod 6 = 1
