λ-calculus and church encodings

Slides:



Advertisements
Lignende præsentationer
Relationsarbejde på Vejrup skole
Advertisements

Overskrift her Navn på oplægsholder Navn på KU- enhed For at ændre ”Enhedens navn” og ”Sted og dato”: Klik i menulinjen, vælg ”Indsæt” > ”Sidehoved / Sidefod”.
Folk og klima People and climate. Folk og klima Jo flere mennesker på kloden, desto mere udslip af CO 2, og så bliver klimaforandringerne endnu værre.
Overskrift her Navn på oplægsholder Navn på KU- enhed For at ændre ”Enhedens navn” og ”Sted og dato”: Klik i menulinjen, vælg ”Indsæt” > ”Sidehoved / Sidefod”.
Tekst starter uden punktopstilling For at få punkt- opstilling på teksten, brug forøg indrykning For at få venstre- stillet tekst uden punktopstilling,
Magtteori I 7. September 2005.
1 The Case Research Strategy in Studies of Information Systems Af:Izak Benbasat, David K. Goldstein og Melissa Mead Publiceret: MIS Quaterly i 1987.
Algoritmer og Datastrukturer 1 Greylisting Gerth Stølting Brodal.
Database Normalization without Mathmatics
CUSTOMER JOURNEYS 12/9.
For at ændre ”Enhedens navn” og ”Sted og dato”: Klik i menulinjen. vælg ”Indsæt” > ”Sidehoved / Sidefod”. Indføj ”Sted og dato” i feltet for dato og ”Enhedens.
Agenda 1.Informationer 1.Excel i fb.m. projekt 2 2.Reserver tid til projekt 2 3.Øvelse: a / b = c 2.Opsamling fra sidst 3.Estimation (konfidensintervaller)
For at ændre ”Enhedens navn” og ”Sted og dato”: Klik i menulinjen, vælg ”Indsæt” > ”Sidehoved / Sidefod”. Indføj ”Sted og dato” i feltet for dato og ”Enhedens.
Tekstslide i punktform Rubrik, helst 1 linje Brug ”Forøg/Formindsk indryk” for at få de forskellige niveauer frem Danish Standards  Signe Annette Boegh.
Paradigmer i Programmering 4. IO + oversigt over udtryk.
Indsæt nyt billede: Format: B 254 x 190,5 mm Efter indsættelse, højreklik på billedet og placér det bagerst. Delete det gamle foto Restrictions on access.
Opgave 53 Erhvervsøkonomi / Managerial Economics
Sætningsanalyse Velkommen- hvad vil jeg gennemgå
Totally Tits the free way is the right way
Lektion 7 Læsestof: Kopier fra Caranno
Electric power is electric particles moving through metal, semiconductor or graphite and special fluids (electrolysis). Some kind of gas are able to conduct.
DATATYPER. For at tilpasse hvert felt i databasen til dets formål og dermed øge funktionalitet 1 bit er tilstrækkelig til at angive køn (0/1) men for.
Aktuel Mediebrug Bo Kampmann Walther FS2015 –
10. Datastrukturer. 2 Nordjyllands Erhvervakademi Collections library Datastrukturer i.NET kaldes normalt Collections Findes i namespace System.Collections.
Paradigmer i Programmering 2. Sammensatte typer Tupler og lister Programmering med rekursion Programmering med pipe-lines Programmering med polymorfe.
Paradigmer i Programmering 1. Program for idag : Funktioner og udtryk i SML : Øvelse : Frokost – 14.00: Deklarative.
Paradigmer i Programmering 1. Plan for kurset 4 x Mads R, 4 x Torben B, 2 x opgave MR: Funktionsprogrammering, SML TB: Logikprogrammering, Prolog Opgave:
Informationssøgning Eksempler på nyttige hjemmesider.
QA.  Først indløbne spørgsmål  Derefter er ordet frit  Own laptops in the exam: Rules do not say anything about this, but specify printed aids and.
M-læring -. Innovationsdilemmaet We can do amazing things with technology, and we’re filling the world with amazing systems devices, but we find it hard.
Interview service in Statistics Denmark Structure and Surveys.
Saint Ambrose High School. Cut cylinders and cones – Standard Grade If you are sitting an SQA Credit paper in Graphic Communication, you will be required.
OPERATIONEL ANALYSE AF WEBADFÆRD OAW – LEKTIONSGANG 7.
Sted og dato (Indsæt --> Diasnummer) Dias 1 Navn på enhed (Indsæt --> Diasnummer) Davenport et al. (2000) Vs Adelman et. Al (2002) Possible states for.
Paradigmer i Programmering 3. Højere ordens funktioner Idag: Højere ordens funktioner Algebraiske datatyper Næste gang: I/O, Filer, interaktive programmer.
OPERATIONEL ANALYSE AF WEBADFÆRD OAW – LEKTIONSGANG 4.
 Jens Bennedsen 2002Objektorienteret systemudvikling GRASP mønstre Basale ansvarsplaceringsregler.
Algoritmer og Datastrukturer 1 DAIMI Greylisting Gerth Stølting Brodal Aarhus Universitet.
 Jens Bennedsen 2002Objektorienteret systemudvikling GRASP mønstre Basale ansvarsplaceringsregler.
ANALYSE AF WEBADFÆRD - OAW OAW – LEKTIONSGANG 4. ANALYSE AF WEBADFÆRD - OAW SUMMARY, LECTURE 3 (Extended) Common Log File Format Host, Ident, Authuser,
6.1 Polygons Convex verse Concave. Definition of a Polygon A polygon is a figure on a plane with three or more sides that meet at a vertex.
Mikkel deMib Svendsen Duplicate Content & Multiple Site Issue Mikkel deMib Svendsen
Omsætning af en model til en RDB Jesper Tørresø DAB1 F Marts 2008.
De glade 60’ere. The Beatles Facts: -Grundlagt Engelsk rock band -Over 5 mil. solgte lp’er.
1 Pulse check Project Half Double. 2 Pulse Check – let’s start with the baseline 1.Are you confident that your current work is creating impact for the.
1 (c) W. J. Dally Digital Design: A Systems Approach Lecture 12: Timing.
GIS and statistical data analysis Copenhagen September 11, 2013.
Beskæftigelsesråd Syddanmark Ove Gaardboe ”Hvornår er man syg og hvornår er man rask?” Hvor lang tid varer en influenza? Hvorfor kom de mon i dag?
Vælg layout 1. Højreklik uden for dit slide 2. Vælg et passende layout fra “drop ned” menuen Ønskes bullet brug da: Bullets generelt: For at få punktopstilling.
THE PARADOX OF NORMALITY – THE RETURN OF NORMALCY AND ITS CONSEQUENCES (NORMALITETENS PARADOKS – NORMALITETENS GENKOMST OG DENS KONSEKVENSER) Dr. Anders.
Drug/Device Combination Products IFF erfagruppemøde
Finansiering og håndtering af potentielle investorer
Buy Doxycycline Online Us
Institutional Investor investing in infrastructure
Completing secondary education
Introduction to synopsis writing
Incidence, risk and resilience for suicide attempts among children and youth born in and living in Denmark in 2007 By MSc. Erik Christiansen.
Oplæg på seminar omkring bosætning i landdistrikterne
Compositional Design Principles “SemiCiv”
Software Testing Software testing.
Denitrification in the root zone
MaaS i Europe Rasmus Lindholm.
why this period? why not the same as for the international strategy
Hvor er værdien af intern kommunikation?
. Oh, store Gud med fem vers
AIDA Reinsurance Working Party Meeting
Kirkens kit – akademiets kant
I Herrens Hænder In the hands of God 4 vers
Algoritmer og Datastrukturer 1
The US-China trade war and its consequences
Præsentationens transcript:

λ-calculus and church encodings Compiling to λ λ-calculus and church encodings

e ::= (lambda (x) e) | (e e) | x

Alonzo Church

β Ω = (U U) = ((λ (u) (u u)) Ω (λ (u) (u u)))

Church encoding

e ::= (letrec ([x (lambda (x …) e)])) | (let ([x e] …) e) | (if e e e) | (+ e e) | (* e e) | (cons e e) | (car e) | (cdr e) | d d ::= ℕ | #t | #f | ‘() x ::= <vars>

e ::= (letrec ([x (lambda (x …) e)])) | (let ([x e] …) e) | (if e e e) | (+ e e) | (* e e) | (cons e e) | (car e) | (cdr e) | d d ::= ℕ | #t | #f | ‘() x ::= <vars> e ::= ) e) )

Desugaring Let

(let ([x e] …) ebody)

(let ([x e] …) ebody) ((λ (x …) ebody) e …)

Currying

Gottlob Frege Moses Schönfinkel

(λ (x) (λ (y) (λ (z) e))) (λ (x y z) e) (λ (x) e) (λ (x) e) (λ () e) (λ (_) e)

(f a b c d) ((((f a) b) c) d) (f a) (f a) (f) (f f)

e ::= (letrec ([x (lambda (x) e)])) | (e e) | x | (if e e e) | ((+ e) e) | ((* e) e) | ((cons e) e) | (car e) | (cdr e) | d d ::= ℕ | #t | #f | ‘() x ::= <vars>

Conditionals & Booleans

(if #t eT eF) (if #f eT eF) eT eF

((λ (t f) t) (if #t eT eF) ((λ (t f) f) (if #f eT eF) ((λ (t f) t) vT vF) ((λ (t f) f) vT vF) vT vF

((λ (t f) t) eT Ω) .........

((λ (t f) (t)) (λ () eT) (λ () Ω)) vT

Turn all values into verbs! (Focus on the behaviors that are implicit in values.)

e ::= (letrec ([x (lambda (x) e)])) | (e e) | x | ((+ e) e) | ((* e) e) | ((cons e) e) | (car e) | (cdr e) | d d ::= ℕ | ‘() x ::= <vars>

Natural Numbers

(λ (f) (λ (x) (fN x))) 0: (λ (f) (λ (x) x)) 1: (λ (f) (λ (x) (f x))) 2: (λ (f) (λ (x) (f (f x)))) 3: (λ (f) (λ (x) (f (f (f x)))))

church+ = (λ (n) (λ (m) (λ (f) (λ (x) …))))

church+ = (λ (n) (λ (m) (λ (f) (λ (x) ((n f) ((m f) x))))))

church* = (λ (n) (λ (m) (λ (f) (λ (x) …))))

church* = (λ (n) (λ (m) (λ (f) (λ (x) ((n (m f)) x)))))

M fN = fN*M

e ::= (letrec ([x (lambda (x) e)])) | (e e) | x | ((cons e) e) | (car e) | (cdr e) | d d ::= ‘() x ::= <vars>

Lists

We need to be able to case-split. The fundamental problem: We need to be able to case-split. The solution: We take two callbacks as with #t, #f!

‘() = (λ (when-cons) (λ (when-null) (cons a b) = (λ (when-cons) (λ (when-null) (when-cons a b)))

e ::= (letrec ([x (lambda (x) e)])) | (e e) | x x ::= <vars>

Y combinator

(letrec ([fact (λ (n) (if (= n 0) 1 (* n (fact (- n 1)))))]) (fact 5))

(letrec ([fact (λ (fact) (λ (n) (if (= n 0) 1 (* n (fact (- n 1)))))]) (fact 5))

(letrec ([mk (λ (fact) (λ (n) (if (= n 0) 1 (* n (fact (- n 1)))))]) ((mk mk) 5))

(letrec ([mk (λ (mk) (λ (n) (if (= n 0) 1 (* n ((mk mk) (- n 1)))))]) ((mk mk) 5))

Y

(It’s a fixed-point combinator!) (Y f) = f (Y f) (It’s a fixed-point combinator!)

Y = (U (λ (y) (λ (f) (f (λ (x) (((y y) f) x)))))

(letrec ([fact (Y (λ (fact) (λ (n) (if (= n 0) 1 (* n (fact (- n 1)))))]) (fact 5))

e ::= (lambda (x) e) | (e e) | x

De-churching (define (church->nat cv) ) (define (church->list cv) (define (church->bool cv)

De-churching (define (church->nat cv) ((cv add1) 0)) (define (church->list cv) ) (define (church->bool cv)

De-churching (define (church->nat cv) ((cv add1) 0)) (define (church->list cv) ((cv (λ (car) (λ (cdr) (cons car (church->list cdr))))) (λ (na) ‘()))) (define (church->bool cv) )

De-churching (define (church->nat cv) ((cv add1) 0)) (define (church->list cv) ((cv (λ (car) (λ (cdr) (cons car (church->list cdr))))) (λ (na) ‘()))) (define (church->bool cv) ((cv (λ () #t)) (λ () #f)))

(letrec ([map (λ (f lst) (if (null? lst) '() (cons (f (car lst)) (map f (cdr lst)))))]) (map (λ (x) (+ 1 x)) '(0 5 3)))

> (map church->nat (church->list lst)) '(1 6 4) (define lst (((((((((λ (Y-comb) (λ (church:null?) (λ (church:cons) (λ (church:car) (λ (church:cdr) (λ (church:+) (λ (church:*) (λ (church:not) ((λ (map) ((map (λ (x) ((church:+ (λ (f) (λ (x) (f x)))) x))) ((church:cons (λ (f) (λ (x) x))) ((church:cons (λ (f) (λ (x) (f (f (f (f (f x)))))))) (λ (f) (λ (x) (f (f (f x)))))) (λ (when-cons) (λ (when-null) (when-null (λ (x) x))))))))) (Y-comb (λ (map) (λ (lst) (((church:null? lst) (λ (unused) (when-null (λ (x) x)))))) ((church:cons (f (church:car lst))) ((map f) (church:cdr lst)))))))))))))))))) ((λ (y) (λ (mk) (mk (λ (x) (((y y) mk) x))))) (λ (y) (λ (mk) (mk (λ (x) (((y y) mk) x))))))) (λ (pair) ((pair (λ (a) (λ (b) (λ (ft) (λ (ff) (ff (λ (x) x))))))) (λ (unused) (λ (ft) (λ (ff) (ft (λ (x) x)))))))) (λ (b) (λ (when-cons) (λ (when-null) ((when-cons a) b)))))) ((pair (λ (a) (λ (b) a))) (λ (unused) (λ (x) x))))) ((pair (λ (a) (λ (b) b))) (λ (unused) (λ (x) x))))) (λ (n0) (λ (n1) (λ (f) (λ (x) ((n1 f) ((n0 f) x))))))) (λ (n0) (λ (n1) (λ (f) (λ (x) ((n0 (n1 f)) x)))))) (λ (bool) ((bool (λ (unused) (λ (ft) (λ (ff) (ff (λ (x) x)))))) (λ (unused) (λ (ft) (λ (ff) (ft (λ (x) x))))))))) > (map church->nat (church->list lst)) '(1 6 4)

Now we can write a church encoder!