![Page 1: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/1.jpg)
Edward KmettGUANXI
LOGIC PROGRAMMING A LA CARTE
![Page 3: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/3.jpg)
![Page 4: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/4.jpg)
![Page 5: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/5.jpg)
![Page 6: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/6.jpg)
![Page 7: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/7.jpg)
Marvin Minsky Aug 9, 1927 - Jan 24, 2016
![Page 8: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/8.jpg)
![Page 9: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/9.jpg)
(MINI)KANRENLOGIC PROGRAMMING IN SCHEME
https://mitpress.mit.edu/books/reasoned-schemer-second-edition
![Page 10: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/10.jpg)
KANREN
![Page 11: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/11.jpg)
vs.
KANREN GUANXI
![Page 13: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/13.jpg)
![Page 14: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/14.jpg)
–Gandalf the Grey, about Barliman Butterbur
“He thinks less than he talks, and slower; yet he can see
through a brick wall in time (as they say in Bree).”
https://github.com/webyrd/Barliman
![Page 15: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/15.jpg)
![Page 16: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/16.jpg)
LOGICTclass MonadPlus m => MonadLogic m where msplit :: m a -> m (Maybe (a, m a))
reflect :: Maybe (a, m a) -> m areflect Nothing = mzeroreflect (Just (a, as)) = pure a <|> as
msplit >=> reflect = id
![Page 17: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/17.jpg)
LOGICT IS NOT DEPTH-FIRST
PROS
• Like breadth-first, it won’t get lost in a blind alley forever.
CONS
• This means it must keep manual environments around
• Not compatible w/ incremental SMT solvers
• It uses a ton of memory.
![Page 18: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/18.jpg)
TYPED LOGIC VARIABLES IN HASKELLUSE REAL REFERENCES THEN BACKTRACK
https://gup.ub.gu.se/file/207634
![Page 19: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/19.jpg)
• Idea: Learn to avoid where you’ve been. CDCL in SAT solvers does this already.
• Rapid restarts are a huge deal in SMT solving
![Page 20: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/20.jpg)
PROPAGATORSMONOTONE FUNCTIONS BETWEEN JOIN SEMILATTICES
https://www.youtube.com/watch?v=acZkF6Q2XKs
![Page 21: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/21.jpg)
UNION-FINDWORKHORSE OF THE UNIFICATION WORLD
![Page 22: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/22.jpg)
MONOID AND GROUP ACTIONSclass Monoid m => Group m where inv :: m -> m
-- act mempty = id-- act (m <> n) = act m . act nclass Monoid m => MonoidAction m s where act :: m -> s -> s
type GroupAction m s = (Group m, MonoidAction m s)
![Page 23: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/23.jpg)
UNIFICATION MODULO GROUP ACTION
x = act a y
z = act b y
y = act (inv a) x
z = act b (act (inv a)) x = act (b <> inv a) x
![Page 24: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/24.jpg)
USEFUL GROUP ACTIONS
• x = y + c (integer addition)
• x = (id | not) y (two element group)
• x = { +1, -1 } y + b (affine trans. w/ unit scale)
![Page 25: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/25.jpg)
O(1) GROUP ACTIONS ON CONTAINERSMANDATORY FOR OPTIMAL ASYMPTOTIC PERFORMANCE
Monoidal Parsing - Scala World 2017
https://www.youtube.com/watch?v=Txf7swrcLYs
![Page 26: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/26.jpg)
REFLECTION WITHOUT REMORSEFREE MONADS WITH BETTER ASYMPTOTICS SAFE DELIMITED CONTINUATIONS
![Page 27: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/27.jpg)
NATURAL DOMAIN SMTPERFORM CONFLICT DIRECTED CLAUSE LEARNING DIRECTLY IN THE SEMANTIC DOMAIN
![Page 28: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/28.jpg)
Key Observation: Guessing “too early” on some vertex separator can be a massive asymptotic performance win if your constraints are too hard to maintain!
NATURAL DOMAINS
• INTERVALS O(n)
• OCTAGONS O(n^4)
• POLYHEDRA O(2^n)
• PRESBURGER O(2^2^2^n)
![Page 29: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/29.jpg)
OTHER RESULTS
• Pay attention to K-L divergence in sampling. Feeding random bits to an arithmetic decoder beats the baseline strategy NeuralKanren was tested against! We can draw without replacement if I track where in the sample space I’ve been and that can be stored succinctly in 2n + o(n) bits per decision functionally, as the application state! Way smaller than all those environments.
• There is a close connection to property-based testing when you’re trying to find a syntax tree with some property.
• Seminaive evaluation of Datalog offers lessons about topological sorting the propagator network as well as tracking changes since last use rather than directly performing semilattice joins.
• Adding nondeterminism fixes a lot of the headaches of using propagators to describe SAT and many other domains.
• Luby-style rapid restarts are very important for performance
• Use brute force when appropriate! Dancing Links, Dancing with Decision Diagrams.
• Dropping the ‘dancing links’ part of the dancing links algorithm and replacing it with SIMD bit operations makes the tasks easily parallelizable and able to be run on a GPU
• Atze van der Ploeg’s “Key” type makes heterogeneous maps very easy to work with and keeps popping up.
• For the most part this is embarassingly parallel, 1000 machines takes Barliman well below the Doherty threshold.
![Page 30: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/30.jpg)
WANT MORE?
IRC: irc.freenode.net ##coda
Git: http://github.com/ekmett/guanxi
Twitch: http://twitch.tv/ekmett
![Page 31: GUANXI Edward Kmett...–Gandalf the Grey, about Barliman Butterbur “He thinks less than he talks, and slower; yet he can see through a brick wall in time (as they say in Bree).”](https://reader034.vdocuments.us/reader034/viewer/2022042918/5f5dae5c09092350850ff2dc/html5/thumbnails/31.jpg)
QUESTIONS?