chapte chapter 1 nuts and ts and bolts
play

Chapte Chapter 1: Nuts and ts and Bolts CS105: Great Insights in - PowerPoint PPT Presentation

Chapte Chapter 1: Nuts and ts and Bolts CS105: Great Insights in Com ights in Computer Science Comput omputers Design: a hierarchy of par hy of parts Interactions between par een parts are simple and well-defined They are


  1. And, Or, nd, Or, Not tant logical operations are and , • The most important logi or , and not . x and y is True only if ue only if both x and y are True. • x or y is True only if ue only if either x or y are True. • • not x is True only if x ue only if x is False. • A lot like their English m nglish meanings, but unambiguous.

  2. And, Or, nd, Or, Not A not A A B A or B A B A and B False True False False False False F False False True False False True False False True True True F False True True False False True True True True True True • Order of operations: Parenthes : Parentheses, not, and, or

  3. Relating And/ ng And/Or/Not • Note: not (not x ) = x • DeMorgan’s Law : not fl : not flips ands and ors • not ( x and y ) = (not (not x ) or (not y ) • not ( x or y ) = (not x ) and ( ) and (not y )

  4. DeMorgan’s Law eMorgan’s Law Example • x : Car is registered. • y : Car displays a valid R alid Rutgers permit. • accepted = x and y • not ( accepted ) if • either Car is not regist registered (not x ) • or Car does not displa display a valid permit (not y) • not (x and y) = (not x) or t x) or (not y)

  5. More Exampl e Examples • x = True, y = False, z = F = False • not x = ? not z = ? • x and y = ? y or z = ? • y or ( x and not z ) = ?

  6. Implementing ementing Logic • Clearly, our brains can handl ns can handle these sorts of expressions. • But, can we automate them automate them?

  7. Implementing ementing Logic • Clearly, our brains can handl ns can handle these sorts of expressions. • But, can we automate them automate them? • Yes, obviously, but let’s , but let’s start with a really simple way to do it befor to do it before we move on to fancier stuff.

  8. Simple C mple Circuit A = True Switch A is either tOn = True lightOn = on or off making the light either on or off: lightOn=A . A = False Symbols: battery False lightOn = switch bulb ground (completes circuit) http://scratch.mit.edu/projects/cs105/35907 105/35907

  9. Multiple Sw iple Switches A = False Switches A and B are wired in parallel : either will B = True light the bulb. http://scratch.m tch.mit.edu/pr Switches C and D ojects/cs105/ s105/35909 are wired in series : C = True D = False both are needed to light the bulb. http://scratch.mit.edu/pr ojects/cs105/35905

  10. Multiple C tiple Circuits A light1 = ? B light2 = ? Special switches allow a singl a single mechanical switch to control two circuits ircuits simultaneously.

  11. Multiple C tiple Circuits A B light1 A F F F T T F light1 = ? T T B ligh light2 = ? A B light2 F F F T T F T T

  12. Multiple C tiple Circuits A B light1 A F F F T T F light1 = ? T T B ligh light2 = ? A B light2 F F F T T F T T

  13. Multiple C tiple Circuits A B light1 A F F F F T T F light1 = ? T T B ligh light2 = ? A B light2 F F F T T F T T

  14. Multiple C tiple Circuits A B light1 A F F F F T T F light1 = ? T T B ligh light2 = ? A B light2 F F F T T F T T

  15. Multiple C tiple Circuits A B light1 A F F F F T T F light1 = ? T T B ligh light2 = ? A B light2 F F F F T T F T T

  16. Multiple C tiple Circuits A B light1 A F F F F T T F light1 = ? T T B ligh light2 = ? A B light2 F F F F T T F T T

  17. Multiple C tiple Circuits A B light1 A F F F F T T F light1 = ? T T B ligh light2 = ? A B light2 F F F F T T F T T

  18. Multiple C tiple Circuits A B light1 A F F F F T T T F light1 = ? T T B ligh light2 = ? A B light2 F F F F T T F T T

  19. Multiple C tiple Circuits A B light1 A F F F F T T T F light1 = ? T T B ligh light2 = ? A B light2 F F F F T T F T T

  20. Multiple C tiple Circuits A B light1 A F F F F T T T F light1 = ? T T B ligh light2 = ? A B light2 F F F F T F T F T T

  21. Multiple C tiple Circuits A B light1 A F F F F T T T F light1 = ? T T B ligh light2 = ? A B light2 F F F F T F T F T T

  22. Multiple C tiple Circuits A B light1 A F F F F T T T F light1 = ? T T B ligh light2 = ? A B light2 F F F F T F T F T T

  23. Multiple C tiple Circuits A B light1 A F F F F T T T F T light1 = ? T T B ligh light2 = ? A B light2 F F F F T F T F T T

  24. Multiple C tiple Circuits A B light1 A F F F F T T T F T light1 = ? T T B ligh light2 = ? A B light2 F F F F T F T F T T

  25. Multiple C tiple Circuits A B light1 A F F F F T T T F T light1 = ? T T B ligh light2 = ? A B light2 F F F F T F T F F T T

  26. Multiple C tiple Circuits A B light1 A F F F F T T T F T light1 = ? T T B ligh light2 = ? A B light2 F F F F T F T F F T T

  27. Multiple C tiple Circuits A B light1 A F F F F T T T F T light1 = ? T T B ligh light2 = ? A B light2 F F F F T F T F F T T

  28. Multiple C tiple Circuits A B light1 A F F F F T T T F T light1 = ? T T T B ligh light2 = ? A B light2 F F F F T F T F F T T

  29. Multiple C tiple Circuits A B light1 A F F F F T T T F T light1 = ? T T T B ligh light2 = ? A B light2 F F F F T F T F F T T

  30. Multiple C tiple Circuits A B light1 A F F F F T T T F T light1 = ? T T T B ligh light2 = ? A B light2 F F F F T F T F F T T T

  31. Multiple C tiple Circuits A B light1 A F F F F T T T F T light1 = ? T T T B ligh light2 = ? A B light2 F F F F T F T F F T T T

  32. Multiple C tiple Circuits A light1 = A or B B light2 = ? ligh A B light2 F F F F T F T F F T T T

  33. Multiple C tiple Circuits A light1 = A or B B light2 = A and B

  34. miniNim miniN • There’s a pile of objects of objects, say 10. • On her turn, a player can tak ayer can take away either one or two objects. • Players alternate. • The player to take the l e the last object wins.

  35. Ideas? Ideas? • The Strategy?

  36. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5-object version. • We’ll design a strategy for the computer “C” to beat the beat the user “U”.

  37. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. • We’ll design a strategy for the computer “C” to beat the user “U”.

  38. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the computer “C” to beat the user “U”.

  39. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the ?? computer “C” to beat the user “U”.

  40. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the C takeOne computer “C” to beat the user “U”.

  41. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the computer “C” to beat 3 left the user “U”.

  42. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the computer “C” to beat 3 left the user “U”. takeOne takeTwo

  43. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the computer “C” to beat 3 left the user “U”. takeOne takeTwo C C

  44. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the ?? computer “C” to beat 3 left the user “U”. takeOne takeTwo C C

  45. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the ?? computer “C” to beat 3 left the user “U”. takeOne takeTwo C C

  46. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the C takeOne computer “C” to beat 3 left the user “U”. takeOne takeTwo C C

  47. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the computer “C” to beat 3 left 2 left the user “U”. takeOne takeTwo C C

  48. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the computer “C” to beat 3 left 2 left the user “U”. takeOne takeTwo takeOne takeTwo C C

  49. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the computer “C” to beat 3 left 2 left the user “U”. takeOne takeTwo takeOne takeTwo C C C

  50. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the computer “C” to beat 3 left 2 left the user “U”. takeOne takeTwo takeOne takeTwo C C C

  51. Nim5Bot: Game ot: Game Tree • Let’s start by considering the 5- 5 left object version. takeOne takeTwo • We’ll design a strategy for the computer “C” to beat 3 left 2 left the user “U”. takeOne takeTwo takeOne takeTwo C U C C

  52. Nim5Bot: Game ot: Game Tree • Let’s start by considering 5 left the 5-object version. • We’ll design a strategy for takeOne takeTwo the computer “C” to beat the beat the user “U”. 3 left 2 left takeOne takeTwo takeOne takeTwo C C C U

  53. Backwards I ards Induction • There’s a powerful idea ful idea here: • Many decision making making problems can be solved optimally by reas y by reasoning backwards from the end of the gam the end of the game. • We know how to win to win from 1 or 2. • We use this to win from to win from 4 or 5. • We use this to win from to win from 7 or 8. • Chess: removed pieces pieces don’t return.

  54. Further Consi her Considerations • To win miniNim: if poss if possible, remove pieces to leave opponent with a m ith a multiple of 3. • Why does it work? W ork? We win if opponent has 3; if opponent has a m has a multiple of 3, can leave her with next smaller aller multiple of 3. • What if goal is to not take the last object? • What if we can take 1, 2, or take 1, 2, or 3 objects per round? 2 or 3? 1 or 3? Is 3? 1 or 3? Is there a general rule?

  55. Complete Ni ete Nim5 Logic 5 left • fiveLeft = True • threeLeft = fiveLeft and takeOne One 1 takeOne 1 takeTwo 1 twoLeft = fiveLeft and takeTwo 1 • C-Win = (threeLeft and (takeOne • One 2 or takeTwo 2 )) or (twoLeft and 3 left 2 left takeOne 2 ) U-Win = twoLeft and takeTwo 2 • takeOne 2 takeTwo 2 takeOne 2 takeTwo 2 C C C U

  56. Nim5 Ci m5 Circuit fiveLeft threeLeft http://scratch.mit.edu/pro jects/cs105/35736 takeTwo 2 U-Win takeOne 1 takeTwo 1 takeOne 2 C-Win tw twoLeft

  57. What a Headache! a Headache! • Encoding Nim10 with s 10 with switches is a nightmare. Why? • Since some switches itches are used in multiple places, needs more than a doubl ore than a double-throw switch. • Since values are reus are reused, hard to keep track of different circuits. • Appears to need a separ to need a separate circuit for each output: Gets too com too complex too fast.

  58. Bits, Inside nside and Out Inputs: Switches Outputs: Lights You win! takeOne 1 takeTwo 1 takeOne 2 takeTwo 2 I win! Nim Player

  59. Bits, Inside nside and Out Inputs: Switches Outputs: Lights Inside: Logi de: Logic A = False light1On = False AND OR AND OR B = True AND OR AND OR light2On = True NOT NOT OT

  60. Need a New a New Approach • Let’s consider an alternate w an alternate way of building “and” and “or” logic. • Makes simple things things more complex. • Makes complex things things much simpler! • That’s a tradeoff we can adeoff we can deal with.

  61. The Magi he Magic Box

  62. The Magi he Magic Box

  63. The Magi he Magic Box

  64. The Magi he Magic Box

  65. The Magi he Magic Box

  66. The Magi he Magic Box

  67. The Magi he Magic Box

  68. How does i does it Work? A lightOn = ? ?

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