prime number identifier - wilfrid laurier...

1
Prime Number Identifier Terry Sturtevant Department of Physics and Computer Science, Wilfrid Laurier University 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 0 0000 n 1 0001 n 2 0010 p 3 0011 p 4 0100 c 5 0101 p 6 0110 c 7 0111 p 8 1000 c 9 1001 c 10 1010 c 11 1011 p 12 1100 c 13 1101 p 14 1110 c 15 1111 c 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 1 a 0 00 01 11 10 a 3 a 2 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 1 a 0 00 01 11 10 a 3 a 2 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 1 a 0 00 01 11 10 a 3 a 2 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 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. 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: 23 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 Prime should only be true for 2,3,5,7,11, and 13 PC/CP120 Lab 2013

Upload: phamliem

Post on 12-Aug-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Prime Number IdentifierTerry Sturtevant

Department of Physics and Computer Science, Wilfrid Laurier University

IntroductionFinding prime numbers is a common task in mathematics. This circuit will identify the primenumbers between zero and fifteen.

DefinitionA number is defined as prime if it has exactly two divisors, itself and one. By definition, thenumbers zero and one are neither prime nor composite.

Logic DesignFor this particular problem, the truth table looks like this:

number binary (a3a2a1a0) p/c/n0 0000 n1 0001 n2 0010 p3 0011 p4 0100 c5 0101 p6 0110 c7 0111 p8 1000 c9 1001 c

10 1010 c11 1011 p12 1100 c13 1101 p14 1110 c15 1111 c

The prime numbers are highlighted in red. There are 6 input combinations that give a TRUEoutput; 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.)

a1a000 01 11 10

a3a2

00 0 0 1 101 0 1 1 011 0 1 0 010 0 0 1 0

Note that there are exactly 6 cells in the Karnaugh map with a one, corresponding to the sixnumbers which are prime. All the other cells are zero.

Simplifying EquationIn this case, a Karnaugh map was used to determine simplified sum-of-products logic equations.

a1a000 01 11 10

a3a2

00 0 0 1 101 0 1 1 011 0 1 0 010 0 0 1 0

Another grouping can be used to get the remaining ones.

a1a000 01 11 10

a3a2

00 0 0 1 101 0 1 1 011 0 1 0 010 0 0 1 0

The resulting SOP equation is

prime = a3 a2 a1 + a3 a2 a0 + a2 a1 a0 + a2 a1 a0

Testing EquationMaxima was used to test the equation.

� 2� 3

� 5� 7

� 11

� 13

All possibilities were tested to see that prime was only true for 2,3,5,7,11, and 13. This verifiesthat the equation is correct.

Circuit Drawing andSimulation

The circuit looks like this:

The two AND gates which implement the terms highlighted in the Karnaugh can be identified bycoloured 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 isprime. This verifies that circuit correctly implements the equation.

Testing

Prime should only be true for 2,3,5,7,11, and 13

PC/CP120 Lab 2013