Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Class 7: CDNs, Sets, SAT

David Evans
September 13, 2016

Class 7: CDNs, Sets, SAT

cs2102: Discrete Mathematics
University of Virginia, Fall 2016

See course site for notes:
https://uvacs2102.github.io

David Evans

September 13, 2016
Tweet

More Decks by David Evans

Other Decks in Programming

Transcript

  1. Class 7: DHTs, Sets and SATs David Evans University of

    Virginia cs2102: Discrete Mathematics Charlottesville Airport, 23 December 2001
  2. Caching the Internet yahoo.com Router Router Router Router Router Router

    Client Client Client Client Cache Cache A Cache stores previous results. If the result is already known from the same request recently, it returns that result. Problem: how do Clients and Routers know which cache to try?
  3. Regular Hash Table Hash: Key, Size ® Number Maps a

    key (which could be any value) and a table size to a number between 0 and Size – 1. This is the position in the table where the Key should be stored. Index Key Value 0 1 2 3 4 5 6 7 8 yahoo.com 98.139.183.24 9 10 11 Python: Dictionary type Java: HashMap, Hashtable
  4. Regular Hash Table Hash: Key, Size ® Number Maps a

    key (which could be any value) and a table size to a number between 0 and Size – 1. This is the position in the table where the Key should be stored. Index Key Value 0 1 2 3 4 5 6 7 8 yahoo.com 98.139.183.24 9 10 11 Python: Dictionary type Java: HashMap, Hashtable Problem: assumes everyone knows the size of the table!
  5. yahoo.com Router Router Router Router Router Router Client Client Client

    Client Cache Cache To find the right cache, client/router would need to know mapping from URL to cache IP.
  6. Daniel Lewin May 14, 1970 – September 11, 2001 In

    true Danny form, he fought back against the terrorists in an effort to defend the stewardesses and the cockpit. To this day, those of us who knew him well can't figure out how only five terrorists managed to overpower him. Tom Leighton’s Remarks
  7. Data Types Mathematical • Defines a set of possible values

    and operations on those values • Nearly always infinite • Unbreakable abstraction: abstract, mathematical objects Programming Languages • Defines a set of possible values and operations on those values • Always finite (in practice), but often views as infinite • Represented in concrete way; may be abstract or exposed
  8. Sets Unordered collection of objects Infinite or finite Objects may

    be of any type not necessarily the same including sets 4 2102 { 1, 2, 3, …} : $ Each object only counts once (multiset has count for each object)
  9. Set Operation: element of (∈) ∈ is true iff is

    in the set 4 2102 { 1, 2, 3, …} : $
  10. Set Operation: not element of (∉) ∉ is true iff

    is not in the set 4 2102 { 1, 2, 3, …} : $
  11. Subset (⊆) ⊆ iff every element of A is an

    element of B. 4 2102 { 1, 2, 3, …} : $
  12. Subset (⊆) ⊆ iff every element of A is an

    element of B. 4 2102 { 1, 2, 3, …} : $ ⊆ ⟺ ∀ ∈ . ∈
  13. Complement Complement: ̅ A ∀ ∈ . ∈ ⟺ ∉

    ̅. D = “domain of discourse” (Universe)
  14. Set Operations Recap ∈ ⟺ is in the set Membership

    ∉ ⟺ ¬( ∈ ) ∉ ̅ ⟺ ∀ ∈ . ∈ . Complement ∀. ∈ − ⟺ ∈ ∧ ∉ . Difference ∀. ∈ ∩ ⟺ ∈ ∧ ∈ . Intersection ∀. ∈ ∪ ⟺ ∈ ∨ ∈ . Union ⊆ ⟺ ∀ ∈ . ∈ Subset Equality = ⟺ ⊆ ∧ ⊆ Non-membership Which ones are necessary?
  15. Everything is either in or not in a set ∀

    ∈ . ∈ ⊕ ∉ 4 2102 { 1, 2, 3, …} : $ D = “domain of discourse” (Universe)
  16. Set Self-Membership ∃ ∈ Sets . ∈ . @ABC =

    set of all things that are not the number 3 DEFG = set of all sets
  17. Conundrum @ABHIJKLA@BMN@N@O = the set of all sets that are

    not members of themselves Is @ABHIJKLA@BMN@N@O ∈ @ABHIJKLA@BMN@N@O?
  18. @ABHIJKLA@BMN@N@O = the set of all sets that are not

    members of themselves Is @ABHIJKLA@BMN@N@O ∈ @ABHIJKLA@BMN@N@O? Slack break…
  19. @ABHIJKLA@BMN@N@O = the set of all sets that are not

    members of themselves Is @ABHIJKLA@BMN@N@O ∈ @ABHIJKLA@BMN@N@O? Russell’s Paradox! Yes means @ABHIJKLA@BMN@N@O ∈ @ABHIJKLA@BMN@N@O , so @ABHIJKLA@BMN@N@O is a member of itself and should not be in @ABHIJKLA@BMN@N@O . No means @ABHIJKLA@BMN@N@O ∉ @ABHIJKLA@BMN@N@O , so @ABHIJKLA@BMN@N@O is not a member of itself and should be in @ABHIJKLA@BMN@N@O .
  20. @ABHIJKLA@BMN@N@O = the set of all sets that are not

    members of themselves Is @ABHIJKLA@BMN@N@O ∈ @ABHIJKLA@BMN@N@O? Russell’s Paradox! Yes means @ABHIJKLA@BMN@N@O ∈ @ABHIJKLA@BMN@N@O , so @ABHIJKLA@BMN@N@O is a member of itself and should not be in @ABHIJKLA@BMN@N@O . No means @ABHIJKLA@BMN@N@O ∉ @ABHIJKLA@BMN@N@O , so @ABHIJKLA@BMN@N@O is not a member of itself and should be in @ABHIJKLA@BMN@N@O . Be very disturbed! (We’ll get back to this later…or at least in cs3102)
  21. Building the SAT Solver 3SAT Note: since we don’t have

    the “magic box”, we’ll find the satisfying assignment directly.
  22. Watchlist: clauses made true by this literal Initialize: Put each

    clause in watchlist for its first literal
  23. Watchlist: clauses made true by this literal P : {

    P , $ } P : { C } Initialize: Put each clause in watchlist for its first literal
  24. Watchlist: clauses made true by this literal P : {

    P , $ } P : { C } Solve: try a variable = [true, false] update watchlists
  25. P : { P , $ } P : {

    C } update(…, false_literal, …): for each clause in watchlist[false_literal]: try to find an alternative satisfying literal P =
  26. P : { P , $ } P : {

    C } update(…, , …): # x1 = F for each clause in watchlist[false_literal]: try to find an alternative satisfying literal $ : { P } $ : { $ }
  27. P : { C } update(…, , …): ... #

    x1 = F update(…, , …): ... # x2 = F $ : { P } $ : { $ }
  28. P : { C } $ : { P }

    $ : { $ } update(…, , …): ... # x1 = F update(…, , …): ... # x2 = F
  29. P : { C } C : { P }

    $ : { $ } update(…, , …): ... # x1 = F update(…, , …): ... # x2 = F
  30. P : { C } C : { P }

    $ : { $ } update(…, , …): ... # x1 = F update(…, , …): ... # x2 = F update(…, , …): ... # x3 = F
  31. P : { C } C : { P }

    $ : { $ } update(…, , …): ... # x1 = F update(…, , …): ... # x2 = F update(…, , …): ... # x3 = F No way to satisfy C1 : need to backtrack
  32. P : { C } C : { P }

    $ : { $ } update(…, , …): ... # x1 = F update(…, , …): ... # x2 = F update(…, ~, …): ... # x3 = T
  33. P : { C } C : { P }

    $ : { $ } update(…, , …): ... # x1 = F update(…, , …): ... # x2 = F update(…, ~, …): ... # x3 = T All good! Found a satisfying assigment.
  34. Graph 3-Coloring Input: description of a graph Output: T iff

    there is a way to assign 3 colors to nodes, so there are no connected nodes with the same color C B A D
  35. Graph 3-Coloring Input: description of a graph Output: T iff

    there is a way to assign 3 colors to nodes, so there are no connected nodes with the same color C B A D 3SAT
  36. Graph 3-Coloring Input: description of a graph Output: T iff

    there is a way to assign 3 colors to nodes, so there are no connected nodes with the same color 3SAT P ∨ $ ∨ C ∧ P ∨ $ ∨ C ∧ (P ∨ $ ∨ C )
  37. Graph 3-Coloring Input: description of a graph Output: T iff

    there is a way to assign 3 colors to nodes, so there are no connected nodes with the same color C B A D 3SAT
  38. Pegboard Puzzle Input: pegboard configuration (any size) Output: T iff

    there is a sequence of valid moves leaving just one peg 3SAT
  39. 3SAT Route planning, scheduling courses, register allocation, pancakes, sudoko, protein

    folding, soap bubbles, March madness, ... Almost every interesting problem can be converted to a 3SAT instance!
  40. Charge • PS3 Due Friday (6:29pm) • Thursday: Functions and

    Relations (MCS 4.2-4.4) • Enjoy today’s fast Internet and remember Danny Lewin’s contribution to it • Later (and in cs3102 and cs4102): what it means to convert problems to 3SAT Daniel Lewin 14 May 1970 – 11 September 2001