Introduction
Finding prime numbers is a common task in mathematics. This circuit will identify the prime numbers between zero and fifteen.
Definition
A number is defined as prime if it has exactly two divisors, itself and one.
By definition, the numbers zero and one are neither prime nor composite.
Logic Design
For this particular problem, the truth table looks like this: number binary ( a
3 a
2 a
1 a
0
) p/c/n
10
11
12
13
7
8
9
14
15
5
6
3
4
0
1
2
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111 c p c p c c p c c p c p c n n p
The prime numbers are highlighted in red . There are 6 input combinations that give a TRUE output; for all other input combinations the output is FALSE.
A truth table for the output, prime , which is TRUE for a prime number, looks like the following.
(The inputs have been grey-coded to produce a Karnaugh map.) a
3 a
2 a
1 a
0
00 01 11 10
00 0 0 1 1
01 0 1 1 0
11 0 1 0 0
10 0 0 1 0
Note that there are exactly 6 cells in the Karnaugh map with a one, corresponding to the six numbers which are prime. All the other cells are zero.
Simplifying Equation
In this case, a Karnaugh map was used to determine simplified sum-of-products logic equations.
a
3 a
2 a
1 a
0
00 01 11 10
00 0 0 1 1
01 0 1 1 0
11 0 1 0 0
10 0 0 1 0
Another grouping can be used to get the remaining ones.
a
3 a
2 a
1 a
0
00 01 11 10
00 0 0 1 1
01 0 1 1 0
11 0 1 0 0
10 0 0 1 0
The resulting SOP equation is prime = a
3 a
2 a
1
+ a
3 a
2 a
0
+ a
2 a
1 a
0
+ a
2 a
1 a
0
Testing Equation
Maxima was used to test the equation.
2
3
5
7
11
13
Circuit Drawing and
Simulation
The circuit looks like this:
The two AND gates which implement the terms highlighted in the Karnaugh can be identified by coloured dots on them.
The simulation output looks like this:
2 3 5 7 11 13
You can see that the ouput is only high for the highlighted cases; i.e. where the input number is prime.
This verifies that circuit correctly implements the equation.
Testing
All possibilities were tested to see that prime was only true for 2,3,5,7,11, and 13.
This verifies that the equation is correct.
Prime should only be true for 2,3,5,7,11, and 13
PC/CP220 Lab 2015