lecture 3 logic and boolean algebra
play

Lecture 3: Logic and Boolean algebra gradescope Homework #1 is up - PowerPoint PPT Presentation

cse 311: foundations of computing Spring 2015 Lecture 3: Logic and Boolean algebra gradescope Homework #1 is up (and has been since Friday). It is due Friday, October 9 th at 11:59pm. You should have received (i) An invitation from Gradescope


  1. cse 311: foundations of computing Spring 2015 Lecture 3: Logic and Boolean algebra

  2. gradescope Homework #1 is up (and has been since Friday). It is due Friday, October 9 th at 11:59pm. You should have received (i) An invitation from Gradescope [if not, email cse311-staff ASAP] (ii) An email from me about (i) [if not, go to the course web page and sign up for the class email list] Note: Homework and extra credit are separate assignments.

  3. more gates X Y Z X 0 0 1 Z NAND 0 1 1 Y 1 0 1 ยฌ(๐‘Œ โˆง ๐‘) 1 1 0 X Y Z 0 0 1 X NOR Z 0 1 0 Y 1 0 0 ยฌ(๐‘Œ โˆจ ๐‘) 1 1 0 X Y Z X XOR 0 0 0 Z 0 1 1 Y ๐‘Œ โŠ• ๐‘ 1 0 1 1 1 0 XNOR X Y Z ๐‘Œ โ†” ๐‘, ๐‘Œ = ๐‘ 0 0 1 X Z 0 1 0 Y 1 0 0 1 1 1

  4. review: logical equivalence Terminology: A compound proposition is aโ€ฆ Tautology if it is always true โ€“ Contradiction if it is always false โ€“ โ€“ Contingency if it can be either true or false p ๏ƒš ๏ƒ˜ p Tautology! Contradiction! p ๏ƒ… p Contingency! ( p ๏‚ฎ q ) ๏ƒ™ p ( p ๏ƒ™ q ) ๏ƒš ( p ๏ƒ™ ๏ƒ˜ q ) ๏ƒš ( ๏ƒ˜ p ๏ƒ™ q ) ๏ƒš ( ๏ƒ˜ p ๏ƒ™ ๏ƒ˜ q ) Tautology!

  5. logical equivalence A and B are logically equivalent if and only if A ๏‚ซ B is a tautology i.e. A and B have the same truth table The notation A ๏‚บ B denotes A and B are logically equivalent. Example: p ๏‚บ ๏ƒ˜ ๏ƒ˜ p ๏ƒ˜ p ๏ƒ˜ ๏ƒ˜ p p ๏‚ซ ๏ƒ˜ ๏ƒ˜ p p T F T T F T F T

  6. review: de Morganโ€™s laws ยฌ ๐‘ž โˆจ ๐‘Ÿ โ‰ก ยฌ ๐‘ž โˆง ยฌ ๐‘Ÿ ยฌ ๐‘ž โˆง ๐‘Ÿ โ‰ก ยฌ ๐‘ž โˆจ ยฌ ๐‘Ÿ if ! ( front != null && value > front.data ) front = new ListNode(value, front); else { ListNode current = front; while ! ( current.next == null || current.next.data >= value ) current = current.next; current.next = new ListNode(value, current.next); } This code inserts value into a sorted linked list. The first if runs when: front is null or value is smaller than the first item. The while loop stops when: weโ€™ve reached the end of the list or the next value is bigger.

  7. review: law of implication ๐‘ž โ†’ ๐‘Ÿ โ‰ก (ยฌ ๐‘ž โˆจ ๐‘Ÿ) p ๏‚ฎ q ๏ƒ˜ p ๏ƒ˜ p ๏ƒš q ( p ๏‚ฎ q ) ๏‚ซ ( ๏ƒ˜ p ๏ƒš q ) p q T T T F T T T F F F F T F T T T T T F F T T T T

  8. computing equivalence Describe an algorithm for computing if two logical expressions/circuits are equivalent. What is the run time of the algorithm? Compute the entire truth table for both of them! There are 2 ๐‘œ entries in the column for ๐‘œ variables.

  9. some familiar properties of arithmetic โ€ข ๐‘ฆ + ๐‘ง = ๐‘ง + ๐‘ฆ (commutativity) โ€“ ๐‘ž โˆจ ๐‘Ÿ โ‰ก ๐‘Ÿ โˆจ ๐‘ž โ€“ ๐‘ž โˆง ๐‘Ÿ โ‰ก ๐‘Ÿ โˆง ๐‘ž โ€ข ๐‘ฆ โ‹… ๐‘ง + ๐‘จ = ๐‘ฆ โ‹… ๐‘ง + ๐‘ฆ โ‹… ๐‘จ (distributivity) โ€“ ๐‘ž โˆง ๐‘Ÿ โˆจ ๐‘  โ‰ก ๐‘ž โˆง ๐‘Ÿ โˆจ (๐‘ž โˆง ๐‘ ) โ€“ ๐‘ž โˆจ ๐‘Ÿ โˆง ๐‘  โ‰ก ๐‘ž โˆจ ๐‘Ÿ โˆง (๐‘ž โˆจ ๐‘ ) ๐‘ฆ + ๐‘ง + ๐‘จ = ๐‘ฆ + (๐‘ง + ๐‘จ) (associativity) โ€ข โ€“ ๐‘ž โˆจ ๐‘Ÿ โˆจ ๐‘  โ‰ก ๐‘ž โˆจ ๐‘Ÿ โˆจ ๐‘  โ€“ ๐‘ž โˆง ๐‘Ÿ โˆง ๐‘  โ‰ก ๐‘ž โˆง (๐‘Ÿ โˆง ๐‘ )

  10. properties of logical connectives You will always get this list. โ€ข Identity โ€“ ๐‘ž โˆง T โ‰ก ๐‘ž โ€ข Associative โ€“ ๐‘ž โˆจ F โ‰ก ๐‘ž ๐‘ž โˆจ ๐‘Ÿ โˆจ ๐‘  โ‰ก ๐‘ž โˆจ ๐‘Ÿ โˆจ ๐‘  ๐‘ž โˆง ๐‘Ÿ โˆง ๐‘  โ‰ก ๐‘ž โˆง ๐‘Ÿ โˆง ๐‘  โ€ข Domination โ€“ ๐‘ž โˆจ T โ‰ก T โ€ข Distributive โ€“ ๐‘ž โˆง F โ‰ก F ๐‘ž โˆง ๐‘Ÿ โˆจ ๐‘  โ‰ก ๐‘ž โˆง ๐‘Ÿ โˆจ (๐‘ž โˆง ๐‘ ) ๐‘ž โˆจ ๐‘Ÿ โˆง ๐‘  โ‰ก ๐‘ž โˆจ ๐‘Ÿ โˆง (๐‘ž โˆจ ๐‘ ) โ€ข Idempotent โ€ข Absorption โ€“ ๐‘ž โˆจ ๐‘ž โ‰ก ๐‘ž ๐‘ž โˆจ ๐‘ž โˆง ๐‘Ÿ โ‰ก ๐‘ž โ€“ ๐‘ž โˆง ๐‘ž โ‰ก ๐‘ž ๐‘ž โˆง ๐‘ž โˆจ ๐‘Ÿ โ‰ก ๐‘ž โ€ข Negation Commutative โ€ข ๐‘ž โˆจ ยฌ๐‘ž โ‰ก T โ€“ ๐‘ž โˆจ ๐‘Ÿ โ‰ก ๐‘Ÿ โˆจ ๐‘ž ๐‘ž โˆง ยฌ๐‘ž โ‰ก F โ€“ ๐‘ž โˆง ๐‘Ÿ โ‰ก ๐‘Ÿ โˆง ๐‘ž

  11. understanding connectives โ€ข Reflect basic rules of reasoning and logic โ€ข Allow manipulation of logical formulas โ€“ Simplification โ€“ Testing for equivalence โ€ข Applications โ€“ Query optimization โ€“ Search optimization and caching โ€“ Artificial intelligence / machine learning โ€“ Program verification

  12. equivalences related to implication ๐‘ž โ†’ ๐‘Ÿ โ‰ก ยฌ ๐‘ž โˆจ ๐‘Ÿ โ‰ก ยฌ๐‘Ÿ ๏‚ฎ ยฌ๐‘ž ๐‘ž โ†’ ๐‘Ÿ ๐‘ž ๏‚ฎ ๐‘Ÿ โˆง (๐‘Ÿ โ†’ ๐‘ž) ๐‘ž โ†” ๐‘Ÿ โ‰ก ๐‘ž โ†” ๐‘Ÿ โ‰ก ยฌ ๐‘ž โ†” ยฌ ๐‘Ÿ

  13. logical proofs To show P is equivalent to Q โ€“ Apply a series of logical equivalences to sub-expressions to convert P to Q To show P is a tautology โ€“ Apply a series of logical equivalences to sub-expressions to convert P to T

  14. prove this is a tautology ๐‘ž โˆง ๐‘Ÿ โ†’ (๐‘ž โˆจ ๐‘Ÿ)

  15. prove this is a tautology (๐‘ž โˆง (๐‘ž โ†’ ๐‘Ÿ)) โ†’ ๐‘Ÿ

  16. prove these are equivalent (๐‘ž โ†’ ๐‘Ÿ) โ†’ ๐‘  ๐‘ž โ†’ (๐‘Ÿ โ†’ ๐‘ )

  17. prove these are not equivalent (๐‘ž โ†’ ๐‘Ÿ) โ†’ ๐‘  ๐‘ž โ†’ (๐‘Ÿ โ†’ ๐‘ )

  18. Boolean logic Combinational Logic โ€“ output = F(input) Sequential Logic โ€“ output t = F(output t-1 , input t ) โ€ข output dependent on history โ€ข concept of a time step (clock, t) Boolean Algebra consisting ofโ€ฆ George โ€œhomeopathyโ€ Boole โ€“ a set of elements B = {0, 1} โ€“ binary operations { + , โ€ข } (OR, AND) โ€“ and a unary operation { โ€™ } ( NOT)

  19. a combinatorial logic example Sessions of class: We would like to compute the number of lectures or quiz sections remaining at the start of a given day of the week. โ€“ Inputs: Day of the Week, Lecture/Section flag โ€“ Output: Number of sessions left Examples: Input: (Wednesday, Lecture) Output: 2 Input: (Monday, Section) Output: 1

  20. implementation in software public int classesLeft (weekday, lecture_flag) { switch (day) { case SUNDAY: case MONDAY: return lecture_flag ? 3 : 1; case TUESDAY: case WEDNESDAY: return lecture_flag ? 2 : 1; case THURSDAY: return lecture_flag ? 1 : 1; case FRIDAY: return lecture_flag ? 1 : 0; case SATURDAY: return lecture_flag ? 0 : 0; } }

  21. implementation with combinational logic Encoding: โ€“ How many bits for each input/output? โ€“ Binary number for weekday โ€“ One bit for each possible output Weekday Lecture? 1 2 3 0

  22. defining our inputs public int classesLeft (weekday, lecture_flag) { switch (day) { case SUNDAY: Weekday Number Binary case MONDAY: Sunday 0 (000) 2 return lecture_flag ? 3 : 1; Monday 1 (001) 2 case TUESDAY: case WEDNESDAY: Tuesday 2 (010) 2 return lecture_flag ? 2 : 1; Wednesday 3 (011) 2 case THURSDAY: Thursday 4 (100) 2 return lecture_flag ? 1 : 1; case FRIDAY: Friday 5 (101) 2 return lecture_flag ? 1 : 0; Saturday 6 (110) 2 case SATURDAY: return lecture_flag ? 0 : 0; } }

  23. converting to a truth table Weekday Lecture? c0 c1 c2 c3 Weekday Number Binary Sunday 0 (000) 2 000 0 0 1 0 0 Monday 1 (001) 2 000 1 0 0 0 1 Tuesday 2 (010) 2 001 0 0 1 0 0 Wednesday 3 (011) 2 001 1 0 0 0 1 Thursday 4 (100) 2 010 0 0 1 0 0 Friday 5 (101) 2 010 1 0 0 1 0 Saturday 6 (110) 2 011 0 0 1 0 0 011 1 0 0 1 0 100 - 0 1 0 0 101 0 1 0 0 0 101 1 0 1 0 0 110 - 1 0 0 0 111 - - - - -

  24. truth table โ‡’ logic (part one) DAY d2d1d0 L c0 c1 c2 c3 SunS 000 0 0 1 0 0 SunL 000 1 0 0 0 1 MonS 001 0 0 1 0 0 MonL 001 1 0 0 0 1 TueS 010 0 0 1 0 0 TueL 010 1 0 0 1 0 WedS 011 0 0 1 0 0 c3 = (DAY == SUN and LEC) or (DAY == MON and LEC) WedL 011 1 0 0 1 0 Thu 100 - 0 1 0 0 c3 = (d2 == 0 && d1 == 0 && d0 == 0 && L == 1) || FriS 101 0 1 0 0 0 (d2 == 0 && d1 == 0 && d0 == 1 && L == 1) FriL 101 1 0 1 0 0 Sat 110 - 1 0 0 0 c3 = d2 โ€™ โ€ข d1 โ€™ โ€ข d0 โ€™ โ€ขL + d2 โ€™ โ€ขd1 โ€™ โ€ขd0โ€ขL - 111 - - - - -

  25. truth table โ‡’ logic (part two) DAY d2d1d0 L c0 c1 c2 c3 SunS 000 0 0 1 0 0 SunL 000 1 0 0 0 1 MonS 001 0 0 1 0 0 MonL 001 1 0 0 0 1 TueS 010 0 0 1 0 0 TueL 010 1 0 0 1 0 c3 = d2 โ€™ โ€ข d1 โ€™ โ€ขd0 โ€™ โ€ขL + d2 โ€™ โ€ขd1 โ€™ โ€ขd0โ€ขL WedS 011 0 0 1 0 0 WedL 011 1 0 0 1 0 c2 = (DAY == TUE and LEC) or Thu 100 - 0 1 0 0 (DAY == WED and LEC) FriS 101 0 1 0 0 0 FriL 101 1 0 1 0 0 c2 = d2 โ€™โ€ข d1โ€ขd0 โ€™โ€ข L + d2 โ€™โ€ข d1โ€ขd0โ€ขL Sat 110 - 1 0 0 0 - 111 - - - - -

  26. truth table โ‡’ logic (part three) DAY d2d1d0 L c0 c1 c2 c3 SunS 000 0 0 1 0 0 SunL 000 1 0 0 0 1 MonS 001 0 0 1 0 0 MonL 001 1 0 0 0 1 TueS 010 0 0 1 0 0 TueL 010 1 0 0 1 0 c3 = d2 โ€™ โ€ข d1 โ€™ โ€ขd0 โ€™ โ€ขL + d2 โ€™ โ€ขd1 โ€™ โ€ขd0โ€ขL WedS 011 0 0 1 0 0 c2 = d2 โ€™โ€ข d1 โ€ขd0 โ€™โ€ข L + d2 โ€™โ€ข d1 โ€ขd0โ€ขL WedL 011 1 0 0 1 0 Thu 100 - 0 1 0 0 c1 = FriS 101 0 1 0 0 0 [you do this one] FriL 101 1 0 1 0 0 Sat 110 - 1 0 0 0 c0 = d2 โ€ข d1 โ€™ โ€ข d0 โ€ขL โ€™ + d2โ€ขd1 โ€ขd0 โ€™ - 111 - - - - -

  27. logic โ‡’ gates DAY d2d1d0 L c0 c1 c2 c3 c3 = d2 โ€™ โ€ข d1 โ€™ โ€ขd0 โ€™ โ€ขL + d2 โ€™ โ€ขd1 โ€™ โ€ขd0โ€ขL SunS 000 0 0 1 0 0 SunL 000 1 0 0 0 1 MonS 001 0 0 1 0 0 d2 NOT MonL 001 1 0 0 0 1 AND TueS 010 0 0 1 0 0 d1 NOT TueL 010 1 0 0 1 0 OR WedS 011 0 0 1 0 0 d0 AND WedL 011 1 0 0 1 0 NOT Thu 100 - 0 1 0 0 L FriS 101 0 1 0 0 0 FriL 101 1 0 1 0 0 (multiple input AND gates) Sat 110 - 1 0 0 0 [LEVEL UP] - 111 - - - - -

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend