CPSC 121: Models of Computation

Similar documents
4. Write a sum-of-products representation of the following circuit. Y = (A + B + C) (A + B + C)

CPSC 121: Models of Computation. Module 8: Sequential Circuits

Propositional Calculus. Math Foundations of Computer Science

CPSC 121: Models of Computation. Module 6: Rewriting predicate logic statements

(Refer Slide Time 3:31)

Propositional Calculus: Boolean Algebra and Simplification. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

Outline. Introduction. 2 Proof of Correctness. 3 Final Notes. Precondition P 1 : Inputs include

COMP combinational logic 1 Jan. 18, 2016

CPSC 121: Models of Computation. Module 5: Predicate Logic

Warmup Problem. Translate the following sentence from English into Propositional Logic. I want to eat ice cream even though I am on a diet.

Write a code fragment that prints yes if xc is in the interval and no if it is not.

Combinational Circuits Digital Logic (Materials taken primarily from:

Announcements. Chapter 2 - Part 1 1

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

Bawar Abid Abdalla. Assistant Lecturer Software Engineering Department Koya University

Propositional Calculus. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

CPSC 121: Models of Computation PART 1 REVIEW OF TEXT READING

T02 Tutorial Slides for Week 2

CS/COE 0447 Example Problems for Exam 2 Spring 2011

(Refer Slide Time 6:48)

Conditionals: Making Choices

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #06 Loops: Operators

Lecture 14: Lower Bounds for Tree Resolution

ELEMENTARY NUMBER THEORY AND METHODS OF PROOF

CSE 20 DISCRETE MATH. Fall

Module 3: Representing Values in a Computer

EE292: Fundamentals of ECE

Institut for Matematik & Datalogi November 15, 2010 Syddansk Universitet. DM528: Combinatorics, Probability and Randomized Algorithms Ugeseddel 3

Designing Computer Systems Boolean Algebra

Contents. Chapter 3 Combinational Circuits Page 1 of 34

Does this program exist? Limits of computability. Does this program exist? A helper function. For example, if the string program is

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

CSC 101: Lab #5 Prelab Boolean Logic Practice Due Date: 5:00pm, day after lab session

Slide Set 5. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Binary Decision Diagrams

CS1800 Discrete Structures Final Version A

Combinational Circuits

6.001 Notes: Section 4.1

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

6. Combinational Circuits. Building Blocks. Digital Circuits. Wires. Q. What is a digital system? A. Digital: signals are 0 or 1.

CPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM

Homework 1. Due Date: Wednesday 11/26/07 - at the beginning of the lecture

(Refer Slide Time: 1:43)

Specifying logic functions

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

Propositional Calculus. Math Foundations of Computer Science

Software and Hardware

A Survey of Mathematics with Applications 8 th Edition, 2009

Chapter 2: Universal Building Blocks. CS105: Great Insights in Computer Science

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

61A Lecture 3. Friday, September 5

Lecture 9. Monday, January 31 CS 205 Programming for the Sciences - Lecture 9 1

Binary Values. CSE 410 Lecture 02

Randomized Algorithms, Hash Functions

npm run pull npm start

Lecture 3: More SQL Basics

CSE 20 DISCRETE MATH. Winter

Binary Adders: Half Adders and Full Adders

LECTURE 2 An Introduction to Boolean Algebra

Continuing with whatever we saw in the previous lectures, we are going to discuss or continue to discuss the hardwired logic design.

CprE 281: Digital Logic

Boolean Algebra & Digital Logic

Combinational Devices and Boolean Algebra

CPSC 121: Models of Computation Assignment #5

Outline. Definition. 2 Height-Balance. 3 Searches. 4 Rotations. 5 Insertion. 6 Deletions. 7 Reference. 1 Every node is either red or black.

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 9 Notes. Class URL:

Unit 2: Data Storage CS 101, Fall 2018

Lecture 2: Big-Step Semantics

CPSC 121: Models of Computation. Module 3: Representing Values in a Computer

An IPS for TQBF Intro to Approximability

QUESTION BANK FOR TEST

Introduction to Sets and Logic (MATH 1190)

Graph Coloring. Margaret M. Fleck. 3 May This lecture discusses the graph coloring problem (section 9.8 of Rosen).

H212 Introduction to Software Systems Honors

60-265: Winter ANSWERS Exercise 4 Combinational Circuit Design

Flow Control. So Far: Writing simple statements that get executed one after another.

Notes. Notes. Introduction. Notes. Propositional Functions. Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry.

TA: Jade Cheng ICS 241 Recitation Lecture Notes #12 November 13, 2009

Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

W4231: Analysis of Algorithms

Searching Algorithms/Time Analysis

COMS 1003 Fall Introduction to Computer Programming in C. Bits, Boolean Logic & Discrete Math. September 13 th

Lecture 1 Contracts : Principles of Imperative Computation (Fall 2018) Frank Pfenning

Lecture 5. Chapter 2: Sections 4-7

LECTURE 4. Logic Design

Logic Gates and Boolean Algebra ENT263

THE PRINCIPLE OF INDUCTION. MARK FLANAGAN School of Electrical, Electronic and Communications Engineering University College Dublin

Propositional Logic Formal Syntax and Semantics. Computability and Logic

Mathematical Logic Part One

Binary Search and Worst-Case Analysis

that system. weighted value associated with it. numbers. a number. the absence of a signal. MECH 1500 Quiz 2 Review Name: Class: Date:

Bawar Abid Abdalla. Assistant Lecturer Software Engineering Department Koya University

Combinational Logic & Circuits

Chapter 3: Theory of Modular Arithmetic 1. Chapter 3: Theory of Modular Arithmetic

Homework 1 CS 1050 A Due:

Embedded Systems Design Prof. Anupam Basu Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Lecture #21 March 31, 2004 Introduction to Gates and Circuits

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

Information Science 1

Transcription:

CPSC 121: Models of Computation Unit 1 Propositional Logic Based on slides by Patrice Belleville and Steve Wolfman Last Updated: 2017-09-09 12:04 AM

Pre Lecture Learning Goals By the start of the class, you should be able to: ranslate back and forth between simple natural language statements and propositional logic. Evaluate the truth of propositional logic statements using truth tables. ranslate back and forth between propositional logic statements and circuits that assess the truth of those statements. Unit 1 - Propositional Logic 2

Quiz 1 eedback We will discuss the open-ended question a bit later. Unit 1 - Propositional Logic 3

What is coming up? Second pre-class quiz is due: Wednesday, Sept 13, 7:00pm. Assigned reading for the quiz: Epp, 4th edition: 2.2 Epp, 3rd edition: 1.2 Rosen, 6th or 7th edition: 1.1 from page 6 onwards. Assignment #1: due Monday September 25th, 2017 at 16:00. Assignment box : #31 in room ICCS X235. Unit 1 - Propositional Logic 4

What is coming up? hird pre-class quiz is due: Wednesday, Sept 20, 7:00pm. 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 Unit 1 - Propositional Logic 5

In-Class Learning Goals By the end of this unit, you should be able to: Build computational systems to solve real problems, using both propositional logic expressions and equivalent digital logic circuits. o he light switches problem from the 1st pre-class quiz. o he 7- or 4-segment LED displays we will discuss in class. Building ground work for the Course Big Goals: How do we model computational systems? How do we build devices to compute? Unit 1 - Propositional Logic 6

Module Outline Making a truth table rom circuits to propositions Light switches 7-segment displays More exercises Unit 1 - Propositional Logic 7

Making a ruth able In what order do we list the combinations in a truth table? Nevertheless, our recommendation is to always list the combinations in the same order. Why? We can start with false or true, but in this course we'll always start with false. You will see later why. Unit 1 - Propositional Logic 8

Making a ruth able (cont') In this course we will always list the combinations in the following order. or tables with 3 variables o the first column contains 4 false followed by 4 true. o the second column contains 2 false, 2 true, 2 false, 2 true. o 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. Unit 1 - Propositional Logic 9

Making a ruth able (cont') Another way to list the combinations is to start with the last column and one variable which will be assigned and add one variable at a time duplicating what you have so far and setting the new variable to for the first copy and for the second Unit 1 - Propositional Logic 10

Module Outline Making a truth table rom circuits to propositions Light switches 7-segment displays More exercises Unit 1 - Propositional Logic 11

Example 1 What does this circuit compute? Unit 1 - Propositional Logic 12

Circuits to Logic Expressions How do we find the logical expression that corresponds to a circuit's output? irst we write the operator for the gate that produces the circuit's output. he operator's left argument is the expression that corresponds to the circuit for the first input of that gate. he operator's right argument is the expression that corresponds to the circuit for the second input of that gate. Build the logical expression for the left and right argument the same way. his is our first algorithm! Unit 1 - Propositional Logic 13

Example 1 What does this circuit compute? ( ( a c ) v ( a b ) ) ^ ~( ( a b ) ( c d ) Unit 1 - Propositional Logic 14

Example 2 What logical expression corresponds to the following circuit? Unit 1 - Propositional Logic 15

Module Outline Making a truth table rom circuits to propositions Light switches 7-segment displays More exercises Unit 1 - Propositional Logic 16

Problem: hree-switch Light Design a circuit that changes the state of the light whenever any of the three switches that control it is flipped. Ideally your solution would work with any number of switches!? Unit 1 - Propositional Logic 17

How do we approach this?? ry to understand the story : what are the inputs and outputs? ormalize the problem: Let a,b,c represent 3 switches from left to right Solve in propositional logic: may create a truth table with the inputs and outputs ry a simpler problem: o start with 1 switch; then try 2; then try 3 switches. o see if we can generalize to n switches. est your answer: try some cases, or check some properties Unit 1 - Propositional Logic 18

One Switch : Identifying Inputs/Outputs? Which is the most useful input for this problem? A. the switch is flipped B. the switch is on C. the light is on D. the light changed state Which is the most useful output for this problem? A. the switch is flipped B. the switch is on C. the light is on D. the light changed state Unit 1 - Propositional Logic 19

One Switch : Understand the Problem? Is the light on or off when the switch is 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. Unit 1 - Propositional Logic 20

One Switch Let s use: ruth table: S = switch is on out = light is on? Which of the following circuits solves the problem? A. B. C. D. All of the above Unit 1 - Propositional Logic 21

wo Switches Make sure we understand the problem first. Is the light on or off when both switches are on? A. On in every correct solution. B. Off in every correct solution. C. Depends, but a correct solution should always do the same thing with the same settings for the switches.. D. Depends, and a correct solution might do different things at different times with the same settings for the switches. E. Neither on nor off.? Unit 1 - Propositional Logic 22

wo Switches? Circuit design tip: if you are not sure where to start while designing a circuit, irst build the truth table. hen turn it into a circuit. or the two switches problem: We can decide arbitrarily what the output is when all switches are O. his determines the output for all other cases! Let's see how... ruth table (suppose light is O when all switches are O): Unit 1 - Propositional Logic 23

wo Switches wo switches: which circuit(s) work(s)?? Unit 1 - Propositional Logic 24

hree Switches ill in the circuit s truth table: Which output column(s) is(are) correct?? A B C D E s 1 s 2 s 3 out out out out None of them Unit 1 - Propositional Logic 25

hree Switches Suppose we decided to have the light O when all switches are O. What pattern do we observe? he light is ON if What is the formula for it? Now to generalize to n switches... What do you think the answer is?? How can we convince ourselves that it is correct? Mathematical induction Unit 1 - Propositional Logic 26

Module Outline Making a truth table rom circuits to propositions Light switches 7-segment displays More exercises Unit 1 - Propositional Logic 27

7-Segment LED Display Problem: design a circuit that displays the numbers 0 through 9 using seven LEDs (lights) in the shape illustrated below. Unit 1 - Propositional Logic 28

7-LED Display - Input Values Understanding the story: How many different input values our circuit should understand? a. 1 b. 7 c. 10 d. 4 e. None of these Unit 1 - Propositional Logic 29

7-LED Display How do we represent these input values? Use some number of logical (true/false) values (propositional variables). Each integer is represented by 1 specific combination of logical values. Could we do this randomly? o Yes! But we won't o How many of you know about binary representation? How many values we can represent with 1 propositional variable : 2 propositional variables : 3 " " : n " " : 30

7-LED Display Input Wires What is the smallest number of different inputs (input wires) the circuit must have? a. 1 b. 7 c. 10 d. 4 e. None of these 31

7-LED Display-Representing Inputs Here's how we will represent the inputs: # a b c d 0 1 2 3 4 5 6 7 8 9... Notice the order: 's first. Unit 1 - Propositional Logic 32

7-LED Display-Outputs Understanding Outputs: How many outputs (output wires) are there? a. 1 b. 4 c. 7 d. 10 e. None of the above Unit 1 - Propositional Logic 33

Simulate 7-LED Display Let's simulate it with people (raising their hands)... Which other person's algorithm do you need to know about? a. No one else's b. Your neighbours c. he person opposite to you d. Everybody else's e. None of the above. 34 Unit 1 - Propositional Logic 34

Analyzing One Segment What s the truth table for the lower-left segment? # a b c d 0 1 2 3 4 5 6 7 8 9 a. out b. c. d. out out out 0 2 6 8 4 7 9 3 1 5 e. None of these. 35

Logical Statement for the Segment rom the truth table, we can make an expression for each true row and OR them together. # a b c d out 0 1 2 3 4 5 6 7 8 9 Which logical statement is true only in this row? a. ~a ~b c ~d b. a b c d c. ~a ~b c ~d d. a b ~c d e. None of these 36

Logical Statement for the Segment Let' s complete the expression for the lower-left segment # a b c d out 0 1 2 3 4 5 6 7 8 9 ( ) ( ) ( ) ( ) 37

Alternative to able with Many s We can use the rows and negate the statement! # a b c d out 0 1 2 3 4 5 6 7 8 9 Which of these correctly models this LED? a. ~(~a b ~c d) ~(~a b c ~d) b. ~(a ~b c ~d) ~(a ~b ~c d) c. ~[(~a b ~c d) (~a b c ~d)] d. ~[(a ~b c ~d) (a ~b ~c d)] e. None of these 38

Another Way # a b c d out 0 1 2 3 4 5 6 7 8 9 Looking back at the bottom-left segment: here 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? Unit 1 - Propositional Logic 39

Module Outline Making a truth table rom circuits to propositions Light switches 7-segment displays More exercises Unit 1 - Propositional Logic 41

Exercises: 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? inish 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. Unit 1 - Propositional Logic 42

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. Unit 1 - Propositional Logic 43