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

interdisciplinary computing (domcode)

Igor Wiedler
November 14, 2015

interdisciplinary computing (domcode)

Igor Wiedler

November 14, 2015
Tweet

More Decks by Igor Wiedler

Other Decks in Programming

Transcript

  1. interdisciplinary
    computing
    ~
    theory and practice

    View full-size slide

  2. @igorwhilefalse

    View full-size slide

  3. #HackTheStigma

    View full-size slide

  4. interdisciplinary
    thinking

    View full-size slide

  5. knitting
    ~
    theorem proving

    View full-size slide

  6. grammars
    ~
    linguistics

    View full-size slide

  7. finance
    ~
    information theory

    View full-size slide

  8. information theory
    ~
    statistics

    View full-size slide

  9. algorithms
    ~
    feminism

    View full-size slide

  10. code complexity
    ~
    applied psychology

    View full-size slide

  11. computation
    ~
    formal logic

    View full-size slide

  12. formal logic
    ~
    electronics

    View full-size slide

  13. electronics
    ~
    physics

    View full-size slide

  14. physics
    ~
    information theory

    View full-size slide

  15. computation
    ~
    cosmic rays

    View full-size slide

  16. Chapter I

    Theory

    View full-size slide

  17. weaving programs

    View full-size slide

  18. @sydneypadua

    View full-size slide

  19. from maths to logic

    View full-size slide

  20. from logic to
    electronics

    View full-size slide

  21. • 1600: leibniz devises binary numbers
    • 1800: boole + de morgan supply the laws
    • 1937: 1-bit binary adder
    • 1947: transistors
    • 1947: error correcting codes
    • 1948: information theory
    • 1965: cosmic radiowave background
    • 1969: unix
    • 1972: c programming language

    View full-size slide

  22. • 1600: leibniz devises binary numbers
    • 1800: boole + de morgan supply the laws
    • 1937: 1-bit binary adder
    • 1947: transistors
    • 1947: error correcting codes
    • 1948: information theory
    • 1965: cosmic radiowave background
    • 1969: unix
    • 1972: c programming language

    View full-size slide

  23. • 1600: leibniz devises binary numbers
    • 1800: boole + de morgan supply the laws
    • 1937: 1-bit binary adder
    • 1947: transistors
    • 1947: error correcting codes
    • 1948: information theory
    • 1965: cosmic radiowave background
    • 1969: unix
    • 1972: c programming language

    View full-size slide

  24. self-reference and
    something something
    quines

    View full-size slide

  25. data = %q{
    program = "data = %q{#{data}}" + data
    puts program
    }
    program = "data = %q{#{data}}" + data
    puts program

    View full-size slide

  26. artsnfood.blogspot.com

    View full-size slide

  27. Chapter II

    Practice

    View full-size slide

  28. logic programming

    View full-size slide

  29. µKanren
    (define (var c) (vector c))
    (define (var? x) (vector? x))
    (define (var=? x1 x2) (= (vector-ref x1 0) (vector-ref x2 0)))
    (define (walk u s)
    (let ((pr (and (var? u) (assp (lambda (v) (var=? u v)) s))))
    (if pr (walk (cdr pr) s) u)))
    (define (ext-s x v s) `((,x . ,v) . ,s))
    (define (== u v)
    (lambda (s/c)
    (let ((s (unify u v (car s/c))))
    (if s (unit `(,s . ,(cdr s/c))) mzero))))
    (define (unit s/c) (cons s/c mzero))
    (define mzero '())
    (define (unify u v s)
    (let ((u (walk u s)) (v (walk v s)))
    (cond
    ((and (var? u) (var? v) (var=? u v)) s)
    ((var? u) (ext-s u v s))
    ((var? v) (ext-s v u s))
    ((and (pair? u) (pair? v))
    (let ((s (unify (car u) (car v) s)))
    (and s (unify (cdr u) (cdr v) s))))
    (else (and (eqv? u v) s)))))
    (define (call/fresh f)
    (lambda (s/c)
    (let ((c (cdr s/c)))
    ((f (var c)) `(,(car s/c) . ,(+ c 1))))))
    (define (disj g1 g2) (lambda (s/c) (mplus (g1 s/c) (g2 s/c))))
    (define (conj g1 g2) (lambda (s/c) (bind (g1 s/c) g2)))
    (define (mplus $1 $2)
    (cond
    ((null? $1) $2)
    ((procedure? $1) (lambda () (mplus $2 ($1))))
    (else (cons (car $1) (mplus (cdr $1) $2)))))
    (define (bind $ g)
    (cond
    ((null? $) mzero)
    ((procedure? $) (lambda () (bind ($) g)))
    (else (mplus (g (car $)) (bind (cdr $) g)))))

    View full-size slide

  30. • ∧ conjunction
    • ∨ disjunction
    • = unification
    • ∃ variables

    View full-size slide

  31. (run 1 (q) (== q 'hello))
    ;=> (hello)

    View full-size slide

  32. (run 1 (q) (== #t #f))
    ;=> ()

    View full-size slide

  33. (run 1 (q)
    (== q 'doughnut)
    (== q 'bagel))
    ;=> ()

    View full-size slide

  34. (run* (q)
    (conde
    [(== q 'doughnut)]
    [(== q 'bagel)]))
    ;=> (doughnut bagel)

    View full-size slide

  35. theorem proving

    View full-size slide

  36. (run* (q)
    (conde
    [(== q 'doughnut)]
    [(== q 'bagel)]))
    ∃q(doughnut(q) ∨ bagel(q))

    View full-size slide

  37. ∃q(doughnut(q) ∨ bagel(q))
    doughnut(q) ∨ bagel(q)
    -------------------
    doughnut(q)
    ∨&e1

    View full-size slide

  38. ∃q(doughnut(q) ∨ bagel(q))
    doughnut(q) ∨ bagel(q)
    -------------------
    bagel(q)
    ∨&e2

    View full-size slide

  39. the never ending
    search for answers

    View full-size slide

  40. (define nevero
    (conde
    [(== #t #f)]
    [nevero]))
    (run 1 (q) nevero)

    View full-size slide

  41. run
    (run 1 (q) nevero)

    View full-size slide

  42. run
    nevero
    (run 1 (q) nevero)

    View full-size slide

  43. run
    nevero
    (define nevero
    (conde
    [(== #t #f)]
    [nevero]))

    View full-size slide

  44. run
    nevero
    (== #t #f)
    (define nevero
    (conde
    [(== #t #f)]
    [nevero]))

    View full-size slide

  45. run
    nevero
    (== #t #f)
    X
    (define nevero
    (conde
    [(== #t #f)]
    [nevero]))

    View full-size slide

  46. run
    nevero
    (== #t #f)
    X
    nevero
    (define nevero
    (conde
    [(== #t #f)]
    [nevero]))

    View full-size slide

  47. run
    nevero
    (== #t #f)
    X
    nevero
    (define nevero
    (conde
    [(== #t #f)]
    [nevero]))

    View full-size slide

  48. (== #t #f)
    run
    nevero
    (== #t #f)
    X
    nevero
    (define nevero
    (conde
    [(== #t #f)]
    [nevero]))

    View full-size slide

  49. (== #t #f)
    run
    nevero
    (== #t #f)
    X
    nevero
    X
    (define nevero
    (conde
    [(== #t #f)]
    [nevero]))

    View full-size slide

  50. (== #t #f)
    run
    nevero
    (== #t #f)
    X
    nevero
    X
    ...
    (define nevero
    (conde
    [(== #t #f)]
    [nevero]))

    View full-size slide

  51. entscheidungsproblem

    View full-size slide

  52. simulating concrete
    machines

    View full-size slide

  53. XOR
    XOR
    AND OR
    NOR

    View full-size slide

  54. (define bit-xoro
    (lambda (x y r)
    (conde
    ((== 0 x) (== 0 y) (== 0 r))
    ((== 1 x) (== 0 y) (== 1 r))
    ((== 0 x) (== 1 y) (== 1 r))
    ((== 1 x) (== 1 y) (== 0 r)))))
    (define bit-ando
    (lambda (x y r)
    (conde
    ((== 0 x) (== 0 y) (== 0 r))
    ((== 1 x) (== 0 y) (== 0 r))
    ((== 0 x) (== 1 y) (== 0 r))
    ((== 1 x) (== 1 y) (== 1 r)))))

    View full-size slide

  55. (define half-addero
    (lambda (x y r c)
    (all
    (bit-xoro x y r)
    (bit-ando x y c))))

    View full-size slide

  56. (define full-addero
    (lambda (b x y r c)
    (fresh (w xy wz)
    (half-addero x y w xy)
    (half-addero w b r wz)
    (bit-xoro xy wz c))))

    View full-size slide

  57. (define +o
    (lambda (n m k)
    (addero 0 n m k)))
    (define -o
    (lambda (n m k)
    (+o m k n)))

    View full-size slide

  58. (run* (x y)
    (+o x y '(1 0 1)))
    ;=> (((1 0 1) ())
    ; (() (1 0 1))
    ; ((1) (0 0 1))
    ; ((0 0 1) (1))
    ; ((1 1) (0 1))
    ; ((0 1) (1 1)))

    View full-size slide

  59. parsing grammars?!

    View full-size slide

  60. flickr.com/photos/strangeloop2015/21793631118

    View full-size slide

  61. exp := var | abs | app
    abs := "λ" var "." exp
    app := "(" exp " " exp ")"

    View full-size slide

  62. exp := var | abs | app
    abs := "λ" var "." exp
    app := "(" exp " " exp ")"
    x
    λx.x
    λx.x x
    (λx.x) (λx.x)
    ...

    View full-size slide

  63. (define exp
    (lambda (e)
    (conde
    [(symbolo e)]
    [(fresh (v e2)
    (symbolo v)
    (exp e2)
    (== e `(λ ,v . ,e2)))]
    [(fresh (e1 e2)
    (exp e1)
    (exp e2)
    (== e `(,e1 ,e2)))])))

    View full-size slide

  64. (run 10 (q) (exp q))
    ;=> (x
    ; (λ x . x)
    ; (x x)
    ; ...)

    View full-size slide

  65. society6.com/product/binary-search-tree--comp-sci-series_print

    View full-size slide

  66. flickr.com/photos/drjason/280369547

    View full-size slide

  67. making use of the
    church-turing thesis

    View full-size slide

  68. (define eval-expo
    (lambda (exp env val)
    (conde
    ((fresh (v)
    (== `(quote ,v) exp)
    (not-in-envo 'quote env)
    (noo 'closure v)
    (== v val)))
    ((fresh (a*)
    (== `(list . ,a*) exp)
    (not-in-envo 'list env)
    (noo 'closure a*)
    (proper-listo a* env val)))
    ((symbolo exp) (lookupo exp env val))
    ((fresh (rator rand x body env^ a)
    (== `(,rator ,rand) exp)
    (eval-expo rator env `(closure ,x ,body ,env^))
    (eval-expo rand env a)
    (eval-expo body `((,x . ,a) . ,env^) val)))
    ((fresh (x body)
    (== `(lambda (,x) ,body) exp)
    (symbolo x)
    (not-in-envo 'lambda env)
    (== `(closure ,x ,body ,env) val))))))
    (define not-in-envo
    (lambda (x env)
    (conde
    ((fresh (y v rest)
    (== `((,y . ,v) . ,rest) env)
    (=/= y x)
    (not-in-envo x rest)))
    ((== '() env)))))
    (define proper-listo
    (lambda (exp env val)
    (conde
    ((== '() exp)
    (== '() val))
    ((fresh (a d t-a t-d)
    (== `(,a . ,d) exp)
    (== `(,t-a . ,t-d) val)
    (eval-expo a env t-a)
    (proper-listo d env t-d))))))
    (define lookupo
    (lambda (x env t)
    (fresh (rest y v)
    (== `((,y . ,v) . ,rest) env)
    (conde
    ((== y x) (== v t))
    ((=/= y x) (lookupo x rest t))))))
    github.com/webyrd/quines

    View full-size slide

  69. (run 1 (q)
    (eval-expo '((lambda (x) x) 'me!) '() q))
    ;=> (me!)

    View full-size slide

  70. (run 3 (q)
    (eval-expo q '() 'me!))
    ;=> ('me!
    ; ((lambda (_.0) 'me!) '_.1)
    ; ((lambda (_.0) _.0) 'me!))

    View full-size slide

  71. (run 1 (q)
    (eval-expo q '() q))
    ;=> ((lambda (_.0) (list _.0 (list 'quote _.0)))
    ; '(lambda (_.0) (list _.0 (list 'quote _.0))))

    View full-size slide

  72. • ∧ conjunction (implicit)
    • ∨ disjunction (conde)
    • = unification (==)
    • ∃ variables (fresh)

    View full-size slide

  73. artsnfood.blogspot.com

    View full-size slide

  74. (21) The Reasoned Schemer

    Daniel Friedman, William Byrd, Oleg Kiselyov
    (22) Quine Generation via Relational Interpreters

    William Byrd, Eric Holk, Daniel Friedman
    (23) µKanren

    Jason Hemann, Daniel Friedman
    (4) How to Replace Failure by a List of Successes

    Philip Wadler
    (7) Unspeakable Things

    Laurie Penny

    View full-size slide

  75. Thanks! Questions?

    •minikanren.org
    •gif.industries
    •@igorwhilefalse

    View full-size slide

  76. (1) Knitting for Fun: A Recursive Sweater

    Anna Bernasconi, Chiara Bodei, Linda Pagli
    (2) Weaving and Programming: More Related
    Than You (Probably) Realize!

    Allie Jones
    (3) From Text to Textiles!

    Lea Albaugh
    (4) How to Replace Failure by a List of
    Successes

    Philip Wadler
    (5) A Mathematical Theory of Communication

    Claude Shannon

    View full-size slide

  77. (6) Harassed by Algorithms

    Joanne McNeil
    (7) Unspeakable Things

    Laurie Penny
    (8) Cognitive Psychology and Programming
    Language Design

    Ben Shneiderman
    (9) Gödel, Escher, Bach

    Douglas Hofstadter
    (10) The Annotated Turing

    Charles Petzold

    View full-size slide

  78. (11) Clause and Effect

    William Clocksin
    (12) Code

    Charles Petzold
    (13) Bitsquatting

    Artem Dinaburg
    (14) Redis Crashes - a small rant about software
    reliability

    Salvatore Sanfilippo
    (15) The Thrilling Adventures of Lovelace and
    Babbage

    Sydney Padua

    View full-size slide

  79. (16) Logicomix: An Epic Search for Truth

    Apostolos Doxiadis, Christos Papadimitriou
    (17) Pioneer Programmer

    Jean Jennings Bartik
    (18) The C Programming Language

    Brian Kernighan, Dennis Ritchie
    (19) Understanding Computation

    Tom Stuart
    (20) Quantum Electrodynamics

    Richard Feynman

    View full-size slide

  80. (21) The Reasoned Schemer

    Daniel Friedman, William Byrd, Oleg Kiselyov
    (22) Quine Generation via Relational
    Interpreters

    William Byrd, Eric Holk, Daniel Friedman
    (23) µKanren

    Jason Hemann, Daniel Friedman
    (24) Propositions as Types

    Philip Wadler
    (25) Unflattening

    Nick Sousanis

    View full-size slide