Module 1: Propositional Logic. CPSC 121: Models of Computation. Module 1: Coming up... Module 1: Coming up...

Similar documents
Logic in Computer Science: Logic Gates

Gates, Circuits, and Boolean Algebra

Binary Adders: Half Adders and Full Adders

1. True or False? A voltage level in the range 0 to 2 volts is interpreted as a binary 1.

Section IV.1: Recursive Algorithms and Recursion Trees

Session 6 Number Theory

Session 7 Fractions and Decimals

Handout #1: Mathematical Reasoning

Circuits and Boolean Expressions

3. Mathematical Induction

Understanding Logic Design

CS311 Lecture: Sequential Circuits

CSE140: Midterm 1 Solution and Rubric

Lab 1: Full Adder 0.0

CHAPTER 2. Logic. 1. Logic Definitions. Notation: Variables are used to represent propositions. The most common variables used are p, q, and r.

def: An axiom is a statement that is assumed to be true, or in the case of a mathematical system, is used to specify the system.

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

FORDHAM UNIVERSITY CISC Dept. of Computer and Info. Science Spring, Lab 2. The Full-Adder

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Mathematical Induction

Properties of Real Numbers

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Offline 1-Minesweeper is NP-complete

2011, The McGraw-Hill Companies, Inc. Chapter 5

Figure 8-1 Four Possible Results of Adding Two Bits

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

Introduction. The Quine-McCluskey Method Handout 5 January 21, CSEE E6861y Prof. Steven Nowick

Karnaugh Maps. Circuit-wise, this leads to a minimal two-level implementation

Excel & Visual Basic for Applications (VBA)

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

BOOLEAN ALGEBRA & LOGIC GATES

United States Naval Academy Electrical and Computer Engineering Department. EC262 Exam 1

Lecture Notes on Linear Search

Clock Arithmetic and Modular Systems Clock Arithmetic The introduction to Chapter 4 described a mathematical system

Lecture Notes in Discrete Mathematics. Marcel B. Finan Arkansas Tech University c All Rights Reserved

Don t Slow Me Down with that Calculator Cliff Petrak (Teacher Emeritus) Brother Rice H.S. Chicago cpetrak1@hotmail.com

Programming A PLC. Standard Instructions

MATHEMATICAL INDUCTION. Mathematical Induction. This is a powerful method to prove properties of positive integers.

Bits Superposition Quantum Parallelism

E XPLORING QUADRILATERALS

Question: What is the probability that a five-card poker hand contains a flush, that is, five cards of the same suit?

Regions in a circle. 7 points 57 regions

Lecture 8: Synchronous Digital Systems

Specimen 2015 am/pm Time allowed: 1hr 30mins

COMPUTER SCIENCE TRIPOS

2 SYSTEM DESCRIPTION TECHNIQUES

Boolean Algebra Part 1

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2

Chapter 1: Digital Systems and Binary Numbers

Logic gates. Chapter. 9.1 Logic gates. MIL symbols. Learning Summary. In this chapter you will learn about: Logic gates

Boolean Algebra. Boolean Algebra. Boolean Algebra. Boolean Algebra

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Sources: On the Web: Slides will be available on:

The Peruvian coin flip Cryptographic protocols

(Refer Slide Time: 00:01:16 min)

Take-Home Exercise. z y x. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas

COMPUTER SCIENCE. Paper 1 (THEORY)

CHAPTER 3. Methods of Proofs. 1. Logical Arguments and Formal Proofs

A Prime Investigation with 7, 11, and 13

Programmable Logic Controllers Definition. Programmable Logic Controllers History

Digital circuits make up all computers and computer systems. The operation of digital circuits is based on

Today s topics. Digital Computers. More on binary. Binary Digits (Bits)

Cosmological Arguments for the Existence of God S. Clarke

Conversion Between Analog and Digital Signals

Two's Complement Adder/Subtractor Lab L03

DEDUCTIVE & INDUCTIVE REASONING

Lecture 7: NP-Complete Problems

CALCULATIONS & STATISTICS

Mathematical Induction

8 Primes and Modular Arithmetic

Chapter 3. if 2 a i then location: = i. Page 40

Karnaugh Maps & Combinational Logic Design. ECE 152A Winter 2012

Introduction to formal semantics -

2.1. Inductive Reasoning EXAMPLE A

Gates. J. Robert Jump Department of Electrical And Computer Engineering Rice University Houston, TX 77251

Basic Logic Gates Richard E. Haskell

Counters and Decoders

earlier in the semester: The Full adder above adds two bits and the output is at the end. So if we do this eight times, we would have an 8-bit adder.

CHAPTER 7 INTRODUCTION TO SAMPLING DISTRIBUTIONS

Seven-Segment LED Displays

Lecture 17 : Equivalence and Order Relations DRAFT

The last three chapters introduced three major proof techniques: direct,

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

COMBINATIONAL CIRCUITS

Count the Dots Binary Numbers

Chapter 5. Selection 5-1

Section 1.5 Exponents, Square Roots, and the Order of Operations

Let s put together a Manual Processor

An Integer Square Root Algorithm

Two-level logic using NAND gates

CS 3719 (Theory of Computation and Algorithms) Lecture 4

CPSC 121: Models of Computation Assignment #4, due Wednesday, July 22nd, 2009 at 14:00

Student Exploration: Circuits

1.2 Solving a System of Linear Equations

Transcription:

CPSC 121: Models of Computation By the start of the class, you should be able to: Translate back and forth between simple natural language statements and propositional logic. Evaluate the truth of propositional logic statements using truth tables. Translate back and forth between propositional logic statements and circuits that assess the truth of those statements. CPSC 121 2015W T1 2 Module 1: Coming up... Module 1: Coming up... What is coming up Second pre-class quiz: due tomorrow at 19:00. Assigned reading for the quiz: Epp, 4 th edition: 2.2 Epp, 3 rd edition: 1.2 Rosen, 6 th or 7 th edition: 1.1 from page 6 onwards. Assignment #1 due Monday September 28 th, 2015 at 17:00. assignment box #21 is in room ICCS X235. CPSC 121 2015W T1 3 What is coming up Third pre-class quiz: due Wednesday September 23 rd at 19:00. Assigned reading for the quiz: Epp, 4th edition: 2.5 Epp, 3rd edition: 1.5 Rosen, any edition: not much http://en.wikipedia.org/wiki/binary_numeral_system Also read: http://www.ugrad.cs.ubc.ca/~cs121/2009w1/handouts/signedbinary-decimal-conversions.html CPSC 121 2015W T1 4

CPSC 121 2015W T1 6 CPSC 121: the BIG questions: We are not yet ready to directly address any of the big questions. But this module lays out the ground work for all of them. By the end of this module, you should be able to: Build computational systems to solve real problems, using both propositional logic expressions and equivalent digital logic circuits, The light switches problem from the 1st pre-class quiz. The 7- or 4-segment LED displays we will discuss in class. CPSC 121 2015W T1 7 Module 1.1: From circuits to propositions Module outline: From circuits to propositions Light switches 7-segment displays More exercises How do we find the logical expression that corresponds to a circuit's output First we write the operator for the gate that produces the circuit's output. The circuit for the first of that gate's inputs will be the operator's left argument. The circuit for the second of that gate's inputs will be the operator's right argument. This is our first algorithm! CPSC 121 2015W T1 8 CPSC 121 2015W T1 9

Module 1.1: From circuits to propositions Module 1.1: From circuits to propositions Example: ( ( a c) v ( a b ) ) ^ ~( ( a b) ( c d) ) What does this circuit compute Note: when you write a truth table, always list the combinations in the same order. For instance, with 3 variables the first column contains 4 false followed by 4 true. the second column contains 2 false, 2 true, 2 false, 2 true. and the third column alternates false with true. With k variables, the first column has 2 k-1 false and then 2 k-1 true, the second column has 2 k-2 false and then 2 k-2 true (twice), etc. CPSC 121 2015W T1 10 CPSC 121 2015W T1 11 Module 1.1: From circuits to propositions What logical expression corresponds to the following circuit Module outline: From circuits to propositions Light switches 7-segment displays More exercises CPSC 121 2015W T1 12 CPSC 121 2015W T1 13

Module 1.2: Light switches Module 1.2: Light switches Consider again: Design a light that changes state whenever any of the switches that control it is flipped. Ideally your solution would work with any number! How do we approach this Start simple: 1 switch. Then try 2 switches. Then try 3 switches. Then see if we can generalize to n switches. Design a light that changes state whenever any of the switches that control it is flipped. Ideally your solution would work with any number! One switch: first decide on the inputs and output. Which of these should appear in our circuit, as either input or output a) f: the switch is flipped b) s: the switch is on c) l: the light is on d) c: the light changed state CPSC 121 2015W T1 14 CPSC 121 2015W T1 15 Module 1.2: Light switches Module 1.2: Light switches Two switches: make sure we understand the problem first. Is the light on or off when both switches are on a) Always on. b) Always off. c) Depends, but a correct solution should always do the same thing. d) Depends, and a correct solution might do different things at different times. Two switches: which circuit(s) work(s) CPSC 121 2015W T1 16 CPSC 121 2015W T1 17

Module 1.2: Light switches Module 1.2: Light switches Circuit design tip: if you are not sure where to start while designing a circuit, First build the truth table. Then turn it into a circuit. For the three switches problem: We can decide arbitrarily what the output is when all three switches are OFF. This determines the output for all other cases! Let's see how... CPSC 121 2015W T1 18 What pattern do we observe The light is ON if Now to generalize to n switches... What do you think the answer is How can we convince ourselves that it is correct Mathematical induction CPSC 121 2015W T1 19 Module outline: From circuits to propositions Light switches 7-segment displays More exercises Problem: design a circuit that displays the numbers 0 through 9 using seven LEDs (lights) in the shape illustrated below. CPSC 121 2015W T1 20 CPSC 121 2015W T1 21

How do we represent the inputs Use logical (true/false) values. Each integer represented by 1 specific combination of input values. Could we do this randomly Yes! But we won't How many of you know about binary representation Understanding: how many inputs (wires going into the circuit) should there be a) 0 b) 1 c) 4 d) 7 e) 10 f) None of the above CPSC 121 2015W T1 22 CPSC 121 2015W T1 23 Here's how we will do it: Number Value 1 Value 2 Value 3 Value 4 0 F F F F 1 F F F T 2 F F T F 3 F F T T 4 F T F F 5 F T F T 6 F T T F 7 F T T T 8 T F F F 9 T F F T Understanding: how many outputs (lights) are there a) 0 b) 1 c) 4 d) 7 e) 10 f) None of the above CPSC 121 2015W T1 24 CPSC 121 2015W T1 25

Let's try it out by hand... Which other person's algorithm do you need to know about a) No one else's b) Your neighbours c) The person opposite to you d) Everybody else's e) None of the above. CPSC 121 2015W T1 26 Let us look at the bottom-left segment. Which is the correct truth table Number Value 1 Value 2 Value 3 Value 4 0 F F F F 1 F F F T 2 F F T F 3 F F T T 4 F T F F 5 F T F T 6 F T T F 7 F T T T 8 T F F F (a) (b) (c) (d) (e) T T T 0 0 F F F 3 2 T T F 4 6 F F T 8 8 T F T F F F T T F F F F T T T 9 T F F T F F F CPSC 121 2015W T1 27 From the truth table, we can Write a proposition for each row Or the propositions together. This works for every truth table, but may give a circuit that is much larger than necessary. Let us look at the middle segment now: How many rows of the truth table contain T How can we avoid having that many terms with 4 variables each CPSC 121 2015W T1 28 Looking back at the bottom-left segment: There may be a simpler proposition, which will translate into a smaller circuit. Can you find a pattern in the rows for which the segment should be on CPSC 121 2015W T1 29

Module 1.4: More exercises Module outline: From circuits to propositions Light switches 7-segment displays More exercises CPSC 121 2015W T1 30 Prove that our two solutions for the lower-left segment are not logically equivalent. You should do this by providing values for the variables, so the two propositions have different truth values. Why are they both correct solutions, despite that Finish the problem by building circuits for the other 5 segments. Design a circuit that takes three bits as input, and outputs the binary representation for their sum. CPSC 121 2015W T1 31 Module 1.4: More exercises Build a circuit that displays the numbers 1 through 9 represented by four boolean values p, q, r, and s on a 4-segment boolean display. CPSC 121 2015W T1 32