csc 107 – programming for science. george boole mathematician from english middle-class lived...

11
LECTURE 8: BOOLEAN LOGIC CSC 107 – Programming For Science

Upload: judith-simon

Post on 04-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching

LECTURE 8:BOOLEAN LOGIC

CSC 107 – Programming For Science

Page 2: CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching

George Boole

Mathematician from English middle-class Lived from 1815 – 1864 Started work at age 16 as a teaching

assistant Held two assistantships to support family Opened own school after many years of work Reached pinnacle of any job -- named a

Professor

Wrote Mathematical Analysis of Logic in 1847

Page 3: CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching

Mathematical Analysis of Logic Boole’s book proposed new logical

system World began with 2 values– though more

created Devised rules to add, subtract, & multiply

Work ignored during Boole’s lifetime System only had 2 values, so what was the

point? Basis for most technology in the

modern age All it took was a simple little discovery…

Page 4: CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching

Gate

Combines input(s) to generate output signal Like most electronics, uses “on-off” state Input is "off", if line drops below 2 volts From 2 - 5 volts, an input is considered on Gate is deep fried silicon if line goes above

5 volts, Like Boole’s logic, electronics have 2

values Simple gates combine to make modern

circuitry All initially part of Boolean algebra Basis of programming at the lowest, rawest

level

Page 5: CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching

Truth Table

Normal way that Boolean functions presented

All combinations of inputs shown in this table This is really easy, inputs must be true or

false Output shown for each of the possible

inputs Given how it sounds, not at all

complicated Very simple rules to follow to construct Does requires you count up to 2

Page 6: CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching

NOT Gate

Simplest gate: computes opposite of input Output false when input true; Output true when input false;

Written in C++ as !a a is gate’s input x is gate’s outputa x !a

true

false

a x

Page 7: CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching

OR Gate

Equivalent to addition in Boolean algebra If either input is true is going to be checked True when either a OR b are true; false

otherwise Written in C++ as a || b

a & b are inputs; x is outputa b x a || b

false falsefalse truetrue falsetrue true

a

bx

Page 8: CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching

AND Gate

Equivalent to multiplication in Boolean algebra If both inputs are true is going to be

checked True when a AND b are true; false otherwise

Written in C++ as a && b a & b are inputs; x is output

a b x a && b

false falsefalse truetrue falsetrue true

a

bx

Page 9: CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching

Gates in Computers

Computers more comfortable using numbers Plus, far less to write down in truth tables Use 0 to stand for false; Use 1 rather than

true For example of this, consider power

symbol Just a combination of 0 & 1

Ultimately, gate’s meaning does not change Use what is easier: C++ switches back and

forth

Page 10: CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching

Your Turn

Get in groups of 3 & work on following activity

Page 11: CSC 107 – Programming For Science. George Boole  Mathematician from English middle-class  Lived from 1815 – 1864  Started work at age 16 as a teaching

For Next Lecture

Read sections 7.2 – 7.2.1 for Monday How can we differ what our program does? How are bool variables and operations

used? Why are if-else statements so important

Week #3 weekly assignment due Tuesday Problems available on Angel If problem takes more than 10 minutes,

TALK TO ME!