SlideShare uma empresa Scribd logo
1 de 33
Baixar para ler offline
Truth, Deduction,
Computation
Lecture G
Untyped λ, Combinators
Vlad Patryshev
SCU
2013
β-reduction - weirder case
●
●
●
●

t = λx ((x x) x)
t t = ?
(λx ((x x) x)) (λx ((x x) x)) ⇒...
(((λx ((x x) x)) (λx ((x x) x)))
(λx ((x x) x)),
that is, ((t t) t) - ouch.
β-reduction - weirder, Javascript
weirder = function(x) { return x(x)(x(x)) }
weirder(
function(a) {
println("called with " + a);
return a
}
)
β-reduction - careful with names
t=λz (x y)
s=z
Try:
● (λx t) z =
● (λx (λz (x y))) z =
● λz (z y)
Wrong!
β-reduction - careful with names
t=λz (x y) = λw (x y)
s=z
Try:
● (λx t) z =
● (λx (λw (x y))) z =
● λw (x y)
Right
η-conversion rule
λx (F x) ⇔ F - where F does not contain x
Wait! What the difference with β?

● β: (λx (y x)) z ⇔ (y z)
● η: (λx (y x)) z ⇔ (y z)
η-conversion in Javascript
function(x) { return y(x) }
is functionally the same as
y
Church Numerals in Lambda
●
●
●
●
●

0 ≡ λ f (λ
1 ≡ λ f (λ
2 ≡ λ f (λ
etc
S(n) ≡ λ f

x x)
x (f x))
x (f (f x)))
(λ x (f ((n f) x)))
f taken (n+1) times
Church Numerals in Javascript
c0=function(f){return function(x){return x}}
c1=function(f){return function(x){return f(x)}}
c2=function(f){return function(x){return f(f(x))}}
// or just
def times(n)=function(f){ return n ? times(n-1)(f) : c0 }
//…
c1=times(1); c2=times(2) etc
//or
def next(n) = function(f) {
return function(x) { return f(n(f)(x)) }
}
Define addition in Lambda
f taken n times

f taken m times

add ≡ λ n λ m λ f λ x ((n f) ((m f) x)))

Let’s try 2+2=4...
Proof that 1+3=3+1, in plain Peano
According to the definition of the successor function s, we have that
s(0)=1, s(s(0))=2, s(s(s(0)))=3, s(s(s(s(0))))=4 and so forth. Then we have

3+1 = s(s(s(0))) + s(0)
= s(s(s(s(0))) + 0) by axiom x+s(y)=s(x+y)
= s(s(s(s(0))))

by axiom x+0=x

= 4

1+3 = s(0) + s(s(s(0)))
= s(s(0) + s(s(0))) by axiom x+s(y)=s(x+y)
= s(s(s(0) + s(0))) by axiom x+s(y)=s(x+y)
= s(s(s(s(0) + 0))) by axiom x+s(y)=s(x+y)
= s(s(s(s(0))))

by axiom x+0=x

=4

Hence we have proved that 3+1=1+3=4
Proof that 1+3=3+1, λ, page 1
S :⇔ λ abc.b(abc)
S0 = λ abc.b(abc) (λ sz.z)
= λ bc.b((λ sz.z) bc)
= λ bc.b((λ z.z) c)
= λ bc.b(c)
λ bc.b(c) = λ sz.s(z) = 1

S1 = λ abc.b(abc) (λ sz.s(z))
= λ bc.b((λ sz.s(z)) bc)
= λ bc.b((λ z.b(z)) c)
= λ bc.b(b(c))
λ bc.b(b(c)) = λ sz.s(s(z)) = 2

Thus, we have the following derivations for the successor function. It does exactly what it is supposed to do: starting from 0, it can produce any natural
number.
0 = 0
S0 = 1
S1 = SS0 = 2
S2 = SS1 = SSS0 = 3
S3 = SS2 = SSS1 = SSSS0 = 4
...

Now, let's prove 3+1 = 1+3.
Proof that 1+3=3+1, λ, page 2
Now, let's prove 3+1 = 1+3.
3+1 = 3S1 = (λsz.s(s(s(z))))(λabc.b(abc))(λxy.x(y))
= (λz.(λabc.b(abc)(λabc.b(abc)(λabc.b(abc)(z)))))(λxy.x(y))
= (λabc.b(abc)(λabc.b(abc)(λabc.b(abc))))(λxy.x(y)))
= SSS1 = 4
We can continue to tediously reduce the expression further instead of using the quick solution by reference above to get 3+1 = SSS1 = 4
3+1 = (λabc.b(abc)(λabc.b(abc)(λabc.b(abc))))(λxy.x(y)))
= (λabc.b(abc)(λabc.b(abc)(λbc.b((λxy.x(y))bc))))
= (λabc.b(abc)(λabc.b(abc)(λbc.b((λy.b(y))c))))
= (λabc.b(abc)(λabc.b(abc)(λbc.b(b(c)))))
= (λabc.b(abc)(λbc.b((λbc.b(b(c))bc)))
= (λabc.b(abc)(λbc.b((λc.b(b(c))c)))
= (λabc.b(abc)(λbc.b(b(b(c))))
= (λbc.b((λbc.b(b(b(c))bc))))
= (λbc.b((λc.b(b(b(c)c))))
= (λbc.b(b(b(b(c)))))
= 4

1+3 = 1S3 = (λsz.s(z))(λabc.b(abc))(λxy.x(x(x(y))))
= (λz.((λabc.b(abc))(z)))(λxy.x(x(x(y))))
= (λabc.b(abc))(λxy.x(x(x(y))))
= S3 = 4

We can continue to tediously reduce the expression further instead of using the quick solution by reference above to get 1+3 = S3 = 4
Proof that 1+3=3+1, λ, page 3
We can continue to tediously reduce the expression further instead of using the quick solution by reference above to get 1+3 = S3 = 4
1+3 = (λabc.b(abc))(λxy.x(x(x(y))))
= (λbc.b((λxy.x(x(x(y)))))bc)
= (λbc.b((λy.b(b(b(y)))))c)
= (λbc.b(b(b(b(c)))))
= 4

Hence, it's mathematically proven that 3+1 = 1+3 = 4 in Lambda calculus
Proof that 1+3=3+1, in JavaScript
// define
var zero = function(f){ return function(x){return x}}
var succ = function(n){return function(f){return function(x){return f(n(f)(x))}}}
var add = function(m){ return function(n){
return function(f){
return function(x){
return m(f)(n(f)(x))}}}}
// execute
function $(id){ return document.getElementById(id)}
var one

= succ(zero)

var two

= succ(one)

var three

= succ (two)

var four

= add(two)(two)

var three_plus_one

= add(three)(one)

var one_plus_three

= add(one)(three)

var numbers = [one, two, three, four, three_plus_one, one_plus_three,]
$('result').innerHTML = ''
for (var i = 0; i < numbers.length; i++){
var n = numbers[i];
$('result').innerHTML += numbers[i](function(n){return 1+n})(0);
$('result').innerHTML += ' = ';
$('result').innerHTML += numbers[i](function(n){return '(1+' + n + ')'})(0);
$('result').innerHTML += '<br />;
}
Proof that 1+3=3+1, in JavaScript
$('result').innerHTML = ''
for (var i = 0; i < numbers.length; i++){
var n = numbers[i];
$('result').innerHTML += numbers[i](function(n){return 1+n})(0);
$('result').innerHTML += ' = ';
$('result').innerHTML += numbers[i](function(n){return '(1+' + n + ')'})(0);
$('result').innerHTML += '<br />;
}

The following result can be obtained from onclick="eval(document.getElementById ("lambda").firstChild.nodeValue)".

1 = (1+0)
2 = (1+(1+0))
3 = (1+(1+(1+0)))
4 = (1+(1+(1+(1+0))))
4 = (1+(1+(1+(1+0))))
4 = (1+(1+(1+(1+0))))
Multiplication in Lambda
take it n times

f taken m times

mult ≡ λ n λ m λ f λ x (n (m f)) x)))

How about 2*2=4?

http://dankogai.typepad.com/blog/2006/03/lambda_calculus.html
Exponentiation? Even easier
mn = m * m*…*m // n times… so:
pow ≡ λ n λ m (n m)
Can we have booleans?
●
●
●
●
●
●

true
false
and
or
not
cond

≡
≡
≡
≡
≡
≡

λ
λ
λ
λ
λ
λ

x
x
x
x
x
c

λ y x
λ y y
λ y ((x
λ y ((x
(x (λ a
λ t λ f

y) x)
x) y)
λ c c) (λ a λc a))
((c t) f)

Try It!!!
λ Booleans in Javascript?
●
●
●
●
●

True=function(x){return function(y){return x}}
False=function(x){return function(y){return y}}
And=function(x){return function(y){return x(y)(x)}}
Or =function(x){return function(y){return x(x)(y)}}
Cond = function(c){
return function(t){
return function(f){
return cond(t)(f)
}}}

Try It!!!
you may need this:
function p(f) {println(f == True ? "TRUE" : f == False ? "FALSE" : f)}
Or we can try to reduce
1.
2.
3.
4.
5.

and true false =
(λ x λ y (x y x)) true false =
true false true =
(λ x λ y x) false true =
false
How cond works
1.
2.
3.
4.

cond true
λ c λ t λ
((true A)
((λ x λ y

A B =
f ((c t) f) true A B =
B) =
x) A) B = A

5.
6.
7.
8.

cond false A B =
λ c λ t λ f ((c t) f) false A B =
((false A) B) =
((λ x λ y y) A) B = B
Can we check a number for zero?
is_zero ≡ λ n n (λ x false) true
in Javascript:
is_zero=function(n){
return n(function(x){return false})(true)
}
Pair
● pair
≡ λ x λ y λ f (f x y)
● first ≡ λ p (p true)
● second ≡ λ p (p false)
Moses Schönfinkel

● Invented currying
● Invented combinators
● His other papers were burned by his neighbors
Combinators
All lambda expressions can be build from
these three:
S, K, I
No variables required.
Hold on.
Combinators
● I ≡ λx x
● K ≡ λx (λy x)
● S ≡ λx λ y λ z ((x z) (y z))
Combinator I
● I ≡ λx x
It is identity function;
in Javascript:
I = function(x) { return x }
Combinator K
● K ≡ λx (λy x)
It builds a constant function;
in Javascript:
K = function(x) {
return function(y){return x}
}
Combinator S
● S ≡ λx λ y λ z ((x z) (y z))
It expresses the idea of substitution;
in Javascript:
S = function(x) {
return function(y) {
return function(z) {
return x(z)(y(z))
}
}}
Using Combinators
● ((S K K) x) = (S K K x) = (K x (K x)) = x
So I = SKK
● true=K
● false=KI
● numbers?
Translating λ to Combinators
To convert an expression e in the lambda calculus to an
expression in SKI, define a function ϕ(e):

e

ϕ(e)

λx x

I

λx c

Kc

λx (α β) (S(λx ϕ(α))(λx ϕ(β)))
Now try Church Numerals...
That’s it for today

Mais conteúdo relacionado

Mais procurados

June Overview SN5 Math
June Overview SN5 MathJune Overview SN5 Math
June Overview SN5 Mathamcsquared
 
S1 3 derivadas_resueltas
S1 3 derivadas_resueltasS1 3 derivadas_resueltas
S1 3 derivadas_resueltasjesquerrev1
 
Presentacion calculo jan
Presentacion calculo janPresentacion calculo jan
Presentacion calculo janjantrevino
 
09 - Program verification
09 - Program verification09 - Program verification
09 - Program verificationTudor Girba
 
Quadratic function
Quadratic functionQuadratic function
Quadratic functionvickytg123
 
2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomials2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomialsmath260
 
MT T4 (Bab 3: Fungsi Kuadratik)
MT T4 (Bab 3: Fungsi Kuadratik)MT T4 (Bab 3: Fungsi Kuadratik)
MT T4 (Bab 3: Fungsi Kuadratik)hasnulslides
 
Integration
IntegrationIntegration
Integrationlecturer
 
Pc12 sol c04_4-2
Pc12 sol c04_4-2Pc12 sol c04_4-2
Pc12 sol c04_4-2Garden City
 
Presentacion calculo1
Presentacion calculo1Presentacion calculo1
Presentacion calculo1jantrevino
 
Polynomials Grade 10
Polynomials Grade 10Polynomials Grade 10
Polynomials Grade 10ingroy
 
11 graphs of first degree functions x
11 graphs of first degree functions x11 graphs of first degree functions x
11 graphs of first degree functions xmath260
 

Mais procurados (17)

June Overview SN5 Math
June Overview SN5 MathJune Overview SN5 Math
June Overview SN5 Math
 
Integral calculus
Integral calculusIntegral calculus
Integral calculus
 
S1 3 derivadas_resueltas
S1 3 derivadas_resueltasS1 3 derivadas_resueltas
S1 3 derivadas_resueltas
 
Presentacion calculo jan
Presentacion calculo janPresentacion calculo jan
Presentacion calculo jan
 
09 - Program verification
09 - Program verification09 - Program verification
09 - Program verification
 
Quadratic function
Quadratic functionQuadratic function
Quadratic function
 
2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomials2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomials
 
Graph a function
Graph a functionGraph a function
Graph a function
 
MT T4 (Bab 3: Fungsi Kuadratik)
MT T4 (Bab 3: Fungsi Kuadratik)MT T4 (Bab 3: Fungsi Kuadratik)
MT T4 (Bab 3: Fungsi Kuadratik)
 
Grph quad fncts
Grph quad fnctsGrph quad fncts
Grph quad fncts
 
Integration
IntegrationIntegration
Integration
 
Pc12 sol c04_4-2
Pc12 sol c04_4-2Pc12 sol c04_4-2
Pc12 sol c04_4-2
 
Presentacion calculo1
Presentacion calculo1Presentacion calculo1
Presentacion calculo1
 
Polynomials Grade 10
Polynomials Grade 10Polynomials Grade 10
Polynomials Grade 10
 
Inverse functions
Inverse functionsInverse functions
Inverse functions
 
1203 ch 12 day 3
1203 ch 12 day 31203 ch 12 day 3
1203 ch 12 day 3
 
11 graphs of first degree functions x
11 graphs of first degree functions x11 graphs of first degree functions x
11 graphs of first degree functions x
 

Destaque

Destaque (8)

Witchcraft & Quark
Witchcraft & QuarkWitchcraft & Quark
Witchcraft & Quark
 
Scala parsers Error Recovery in Production
Scala parsers Error Recovery in ProductionScala parsers Error Recovery in Production
Scala parsers Error Recovery in Production
 
Parse Everything With Elixir
Parse Everything With ElixirParse Everything With Elixir
Parse Everything With Elixir
 
Scala - Collections
Scala - CollectionsScala - Collections
Scala - Collections
 
Twitter bootstrap
Twitter bootstrapTwitter bootstrap
Twitter bootstrap
 
Autism - Pecha Kucha
Autism - Pecha KuchaAutism - Pecha Kucha
Autism - Pecha Kucha
 
Apache Lucene - Suggestions
Apache Lucene - SuggestionsApache Lucene - Suggestions
Apache Lucene - Suggestions
 
LT - Data Scientist
LT - Data ScientistLT - Data Scientist
LT - Data Scientist
 

Semelhante a Truth, deduction, computation lecture g

Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaPhilip Schwarz
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Philip Schwarz
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programmingDamian T. Gordon
 
Introduction to Recursion (Python)
Introduction to Recursion (Python)Introduction to Recursion (Python)
Introduction to Recursion (Python)Thai Pangsakulyanont
 
Truth, deduction, computation lecture f
Truth, deduction, computation   lecture fTruth, deduction, computation   lecture f
Truth, deduction, computation lecture fVlad Patryshev
 
Variations on the method of Coleman-Chabauty
Variations on the method of Coleman-ChabautyVariations on the method of Coleman-Chabauty
Variations on the method of Coleman-Chabautymmasdeu
 
ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)CrackDSE
 
Las expresiones algebraicas y Factorización de productos notables
Las expresiones algebraicas y Factorización de productos notables Las expresiones algebraicas y Factorización de productos notables
Las expresiones algebraicas y Factorización de productos notables MariannaPatacnMosque
 
Integral Calculus Anti Derivatives reviewer
Integral Calculus Anti Derivatives reviewerIntegral Calculus Anti Derivatives reviewer
Integral Calculus Anti Derivatives reviewerJoshuaAgcopra
 
functions limits and continuity
functions limits and continuityfunctions limits and continuity
functions limits and continuityPume Ananda
 
Rosser's theorem
Rosser's theoremRosser's theorem
Rosser's theoremWathna
 
Module 2 exponential functions
Module 2   exponential functionsModule 2   exponential functions
Module 2 exponential functionsdionesioable
 
Density theorems for anisotropic point configurations
Density theorems for anisotropic point configurationsDensity theorems for anisotropic point configurations
Density theorems for anisotropic point configurationsVjekoslavKovac1
 

Semelhante a Truth, deduction, computation lecture g (20)

Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
Introduction to Recursion (Python)
Introduction to Recursion (Python)Introduction to Recursion (Python)
Introduction to Recursion (Python)
 
Truth, deduction, computation lecture f
Truth, deduction, computation   lecture fTruth, deduction, computation   lecture f
Truth, deduction, computation lecture f
 
Variations on the method of Coleman-Chabauty
Variations on the method of Coleman-ChabautyVariations on the method of Coleman-Chabauty
Variations on the method of Coleman-Chabauty
 
ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)ISI MSQE Entrance Question Paper (2008)
ISI MSQE Entrance Question Paper (2008)
 
Algebra
AlgebraAlgebra
Algebra
 
Las expresiones algebraicas y Factorización de productos notables
Las expresiones algebraicas y Factorización de productos notables Las expresiones algebraicas y Factorización de productos notables
Las expresiones algebraicas y Factorización de productos notables
 
04-Sets-Relations-A.pdf
04-Sets-Relations-A.pdf04-Sets-Relations-A.pdf
04-Sets-Relations-A.pdf
 
Integral Calculus Anti Derivatives reviewer
Integral Calculus Anti Derivatives reviewerIntegral Calculus Anti Derivatives reviewer
Integral Calculus Anti Derivatives reviewer
 
functions limits and continuity
functions limits and continuityfunctions limits and continuity
functions limits and continuity
 
Função quadrática
Função quadráticaFunção quadrática
Função quadrática
 
Tema Numeros Reales
Tema Numeros RealesTema Numeros Reales
Tema Numeros Reales
 
Appendex
AppendexAppendex
Appendex
 
01 FUNCTIONS.pptx
01 FUNCTIONS.pptx01 FUNCTIONS.pptx
01 FUNCTIONS.pptx
 
Rosser's theorem
Rosser's theoremRosser's theorem
Rosser's theorem
 
Functions limits and continuity
Functions limits and continuityFunctions limits and continuity
Functions limits and continuity
 
Module 2 exponential functions
Module 2   exponential functionsModule 2   exponential functions
Module 2 exponential functions
 
Density theorems for anisotropic point configurations
Density theorems for anisotropic point configurationsDensity theorems for anisotropic point configurations
Density theorems for anisotropic point configurations
 

Mais de Vlad Patryshev

Formal methods 8 - category theory (last one)
Formal methods   8 - category theory (last one)Formal methods   8 - category theory (last one)
Formal methods 8 - category theory (last one)Vlad Patryshev
 
Formal methods 6 - elements of algebra
Formal methods   6 - elements of algebraFormal methods   6 - elements of algebra
Formal methods 6 - elements of algebraVlad Patryshev
 
Formal methods 5 - Pi calculus
Formal methods   5 - Pi calculusFormal methods   5 - Pi calculus
Formal methods 5 - Pi calculusVlad Patryshev
 
Formal methods 4 - Z notation
Formal methods   4 - Z notationFormal methods   4 - Z notation
Formal methods 4 - Z notationVlad Patryshev
 
Formal methods 3 - languages and machines
Formal methods   3 - languages and machinesFormal methods   3 - languages and machines
Formal methods 3 - languages and machinesVlad Patryshev
 
Formal methods 2 - languages and machines
Formal methods   2 - languages and machinesFormal methods   2 - languages and machines
Formal methods 2 - languages and machinesVlad Patryshev
 
Formal methods 1 - introduction
Formal methods   1 - introductionFormal methods   1 - introduction
Formal methods 1 - introductionVlad Patryshev
 
Formal methods 7 - category theory
Formal methods   7 - category theoryFormal methods   7 - category theory
Formal methods 7 - category theoryVlad Patryshev
 
Truth, deduction, computation lecture i (last one)
Truth, deduction, computation   lecture i (last one)Truth, deduction, computation   lecture i (last one)
Truth, deduction, computation lecture i (last one)Vlad Patryshev
 
Truth, deduction, computation lecture h
Truth, deduction, computation   lecture hTruth, deduction, computation   lecture h
Truth, deduction, computation lecture hVlad Patryshev
 
Truth, deduction, computation lecture e
Truth, deduction, computation   lecture eTruth, deduction, computation   lecture e
Truth, deduction, computation lecture eVlad Patryshev
 
Truth, deduction, computation lecture d
Truth, deduction, computation   lecture dTruth, deduction, computation   lecture d
Truth, deduction, computation lecture dVlad Patryshev
 
Truth, deduction, computation lecture c
Truth, deduction, computation   lecture cTruth, deduction, computation   lecture c
Truth, deduction, computation lecture cVlad Patryshev
 
Truth, deduction, computation lecture b
Truth, deduction, computation   lecture bTruth, deduction, computation   lecture b
Truth, deduction, computation lecture bVlad Patryshev
 
Truth, deduction, computation lecture a
Truth, deduction, computation   lecture aTruth, deduction, computation   lecture a
Truth, deduction, computation lecture aVlad Patryshev
 
Truth, deduction, computation lecture 9
Truth, deduction, computation   lecture 9Truth, deduction, computation   lecture 9
Truth, deduction, computation lecture 9Vlad Patryshev
 
Truth, deduction, computation lecture 8
Truth, deduction, computation   lecture 8Truth, deduction, computation   lecture 8
Truth, deduction, computation lecture 8Vlad Patryshev
 
Truth, deduction, computation lecture 7
Truth, deduction, computation   lecture 7Truth, deduction, computation   lecture 7
Truth, deduction, computation lecture 7Vlad Patryshev
 
Truth, deduction, computation lecture 6
Truth, deduction, computation   lecture 6Truth, deduction, computation   lecture 6
Truth, deduction, computation lecture 6Vlad Patryshev
 
Truth, deduction, computation; lecture 5
Truth, deduction, computation;  lecture 5Truth, deduction, computation;  lecture 5
Truth, deduction, computation; lecture 5Vlad Patryshev
 

Mais de Vlad Patryshev (20)

Formal methods 8 - category theory (last one)
Formal methods   8 - category theory (last one)Formal methods   8 - category theory (last one)
Formal methods 8 - category theory (last one)
 
Formal methods 6 - elements of algebra
Formal methods   6 - elements of algebraFormal methods   6 - elements of algebra
Formal methods 6 - elements of algebra
 
Formal methods 5 - Pi calculus
Formal methods   5 - Pi calculusFormal methods   5 - Pi calculus
Formal methods 5 - Pi calculus
 
Formal methods 4 - Z notation
Formal methods   4 - Z notationFormal methods   4 - Z notation
Formal methods 4 - Z notation
 
Formal methods 3 - languages and machines
Formal methods   3 - languages and machinesFormal methods   3 - languages and machines
Formal methods 3 - languages and machines
 
Formal methods 2 - languages and machines
Formal methods   2 - languages and machinesFormal methods   2 - languages and machines
Formal methods 2 - languages and machines
 
Formal methods 1 - introduction
Formal methods   1 - introductionFormal methods   1 - introduction
Formal methods 1 - introduction
 
Formal methods 7 - category theory
Formal methods   7 - category theoryFormal methods   7 - category theory
Formal methods 7 - category theory
 
Truth, deduction, computation lecture i (last one)
Truth, deduction, computation   lecture i (last one)Truth, deduction, computation   lecture i (last one)
Truth, deduction, computation lecture i (last one)
 
Truth, deduction, computation lecture h
Truth, deduction, computation   lecture hTruth, deduction, computation   lecture h
Truth, deduction, computation lecture h
 
Truth, deduction, computation lecture e
Truth, deduction, computation   lecture eTruth, deduction, computation   lecture e
Truth, deduction, computation lecture e
 
Truth, deduction, computation lecture d
Truth, deduction, computation   lecture dTruth, deduction, computation   lecture d
Truth, deduction, computation lecture d
 
Truth, deduction, computation lecture c
Truth, deduction, computation   lecture cTruth, deduction, computation   lecture c
Truth, deduction, computation lecture c
 
Truth, deduction, computation lecture b
Truth, deduction, computation   lecture bTruth, deduction, computation   lecture b
Truth, deduction, computation lecture b
 
Truth, deduction, computation lecture a
Truth, deduction, computation   lecture aTruth, deduction, computation   lecture a
Truth, deduction, computation lecture a
 
Truth, deduction, computation lecture 9
Truth, deduction, computation   lecture 9Truth, deduction, computation   lecture 9
Truth, deduction, computation lecture 9
 
Truth, deduction, computation lecture 8
Truth, deduction, computation   lecture 8Truth, deduction, computation   lecture 8
Truth, deduction, computation lecture 8
 
Truth, deduction, computation lecture 7
Truth, deduction, computation   lecture 7Truth, deduction, computation   lecture 7
Truth, deduction, computation lecture 7
 
Truth, deduction, computation lecture 6
Truth, deduction, computation   lecture 6Truth, deduction, computation   lecture 6
Truth, deduction, computation lecture 6
 
Truth, deduction, computation; lecture 5
Truth, deduction, computation;  lecture 5Truth, deduction, computation;  lecture 5
Truth, deduction, computation; lecture 5
 

Último

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Último (20)

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Truth, deduction, computation lecture g

  • 1. Truth, Deduction, Computation Lecture G Untyped λ, Combinators Vlad Patryshev SCU 2013
  • 2. β-reduction - weirder case ● ● ● ● t = λx ((x x) x) t t = ? (λx ((x x) x)) (λx ((x x) x)) ⇒... (((λx ((x x) x)) (λx ((x x) x))) (λx ((x x) x)), that is, ((t t) t) - ouch.
  • 3. β-reduction - weirder, Javascript weirder = function(x) { return x(x)(x(x)) } weirder( function(a) { println("called with " + a); return a } )
  • 4. β-reduction - careful with names t=λz (x y) s=z Try: ● (λx t) z = ● (λx (λz (x y))) z = ● λz (z y) Wrong!
  • 5. β-reduction - careful with names t=λz (x y) = λw (x y) s=z Try: ● (λx t) z = ● (λx (λw (x y))) z = ● λw (x y) Right
  • 6. η-conversion rule λx (F x) ⇔ F - where F does not contain x Wait! What the difference with β? ● β: (λx (y x)) z ⇔ (y z) ● η: (λx (y x)) z ⇔ (y z)
  • 7. η-conversion in Javascript function(x) { return y(x) } is functionally the same as y
  • 8. Church Numerals in Lambda ● ● ● ● ● 0 ≡ λ f (λ 1 ≡ λ f (λ 2 ≡ λ f (λ etc S(n) ≡ λ f x x) x (f x)) x (f (f x))) (λ x (f ((n f) x))) f taken (n+1) times
  • 9. Church Numerals in Javascript c0=function(f){return function(x){return x}} c1=function(f){return function(x){return f(x)}} c2=function(f){return function(x){return f(f(x))}} // or just def times(n)=function(f){ return n ? times(n-1)(f) : c0 } //… c1=times(1); c2=times(2) etc //or def next(n) = function(f) { return function(x) { return f(n(f)(x)) } }
  • 10. Define addition in Lambda f taken n times f taken m times add ≡ λ n λ m λ f λ x ((n f) ((m f) x))) Let’s try 2+2=4...
  • 11. Proof that 1+3=3+1, in plain Peano According to the definition of the successor function s, we have that s(0)=1, s(s(0))=2, s(s(s(0)))=3, s(s(s(s(0))))=4 and so forth. Then we have 3+1 = s(s(s(0))) + s(0) = s(s(s(s(0))) + 0) by axiom x+s(y)=s(x+y) = s(s(s(s(0)))) by axiom x+0=x = 4 1+3 = s(0) + s(s(s(0))) = s(s(0) + s(s(0))) by axiom x+s(y)=s(x+y) = s(s(s(0) + s(0))) by axiom x+s(y)=s(x+y) = s(s(s(s(0) + 0))) by axiom x+s(y)=s(x+y) = s(s(s(s(0)))) by axiom x+0=x =4 Hence we have proved that 3+1=1+3=4
  • 12. Proof that 1+3=3+1, λ, page 1 S :⇔ λ abc.b(abc) S0 = λ abc.b(abc) (λ sz.z) = λ bc.b((λ sz.z) bc) = λ bc.b((λ z.z) c) = λ bc.b(c) λ bc.b(c) = λ sz.s(z) = 1 S1 = λ abc.b(abc) (λ sz.s(z)) = λ bc.b((λ sz.s(z)) bc) = λ bc.b((λ z.b(z)) c) = λ bc.b(b(c)) λ bc.b(b(c)) = λ sz.s(s(z)) = 2 Thus, we have the following derivations for the successor function. It does exactly what it is supposed to do: starting from 0, it can produce any natural number. 0 = 0 S0 = 1 S1 = SS0 = 2 S2 = SS1 = SSS0 = 3 S3 = SS2 = SSS1 = SSSS0 = 4 ... Now, let's prove 3+1 = 1+3.
  • 13. Proof that 1+3=3+1, λ, page 2 Now, let's prove 3+1 = 1+3. 3+1 = 3S1 = (λsz.s(s(s(z))))(λabc.b(abc))(λxy.x(y)) = (λz.(λabc.b(abc)(λabc.b(abc)(λabc.b(abc)(z)))))(λxy.x(y)) = (λabc.b(abc)(λabc.b(abc)(λabc.b(abc))))(λxy.x(y))) = SSS1 = 4 We can continue to tediously reduce the expression further instead of using the quick solution by reference above to get 3+1 = SSS1 = 4 3+1 = (λabc.b(abc)(λabc.b(abc)(λabc.b(abc))))(λxy.x(y))) = (λabc.b(abc)(λabc.b(abc)(λbc.b((λxy.x(y))bc)))) = (λabc.b(abc)(λabc.b(abc)(λbc.b((λy.b(y))c)))) = (λabc.b(abc)(λabc.b(abc)(λbc.b(b(c))))) = (λabc.b(abc)(λbc.b((λbc.b(b(c))bc))) = (λabc.b(abc)(λbc.b((λc.b(b(c))c))) = (λabc.b(abc)(λbc.b(b(b(c)))) = (λbc.b((λbc.b(b(b(c))bc)))) = (λbc.b((λc.b(b(b(c)c)))) = (λbc.b(b(b(b(c))))) = 4 1+3 = 1S3 = (λsz.s(z))(λabc.b(abc))(λxy.x(x(x(y)))) = (λz.((λabc.b(abc))(z)))(λxy.x(x(x(y)))) = (λabc.b(abc))(λxy.x(x(x(y)))) = S3 = 4 We can continue to tediously reduce the expression further instead of using the quick solution by reference above to get 1+3 = S3 = 4
  • 14. Proof that 1+3=3+1, λ, page 3 We can continue to tediously reduce the expression further instead of using the quick solution by reference above to get 1+3 = S3 = 4 1+3 = (λabc.b(abc))(λxy.x(x(x(y)))) = (λbc.b((λxy.x(x(x(y)))))bc) = (λbc.b((λy.b(b(b(y)))))c) = (λbc.b(b(b(b(c))))) = 4 Hence, it's mathematically proven that 3+1 = 1+3 = 4 in Lambda calculus
  • 15. Proof that 1+3=3+1, in JavaScript // define var zero = function(f){ return function(x){return x}} var succ = function(n){return function(f){return function(x){return f(n(f)(x))}}} var add = function(m){ return function(n){ return function(f){ return function(x){ return m(f)(n(f)(x))}}}} // execute function $(id){ return document.getElementById(id)} var one = succ(zero) var two = succ(one) var three = succ (two) var four = add(two)(two) var three_plus_one = add(three)(one) var one_plus_three = add(one)(three) var numbers = [one, two, three, four, three_plus_one, one_plus_three,] $('result').innerHTML = '' for (var i = 0; i < numbers.length; i++){ var n = numbers[i]; $('result').innerHTML += numbers[i](function(n){return 1+n})(0); $('result').innerHTML += ' = '; $('result').innerHTML += numbers[i](function(n){return '(1+' + n + ')'})(0); $('result').innerHTML += '<br />; }
  • 16. Proof that 1+3=3+1, in JavaScript $('result').innerHTML = '' for (var i = 0; i < numbers.length; i++){ var n = numbers[i]; $('result').innerHTML += numbers[i](function(n){return 1+n})(0); $('result').innerHTML += ' = '; $('result').innerHTML += numbers[i](function(n){return '(1+' + n + ')'})(0); $('result').innerHTML += '<br />; } The following result can be obtained from onclick="eval(document.getElementById ("lambda").firstChild.nodeValue)". 1 = (1+0) 2 = (1+(1+0)) 3 = (1+(1+(1+0))) 4 = (1+(1+(1+(1+0)))) 4 = (1+(1+(1+(1+0)))) 4 = (1+(1+(1+(1+0))))
  • 17. Multiplication in Lambda take it n times f taken m times mult ≡ λ n λ m λ f λ x (n (m f)) x))) How about 2*2=4? http://dankogai.typepad.com/blog/2006/03/lambda_calculus.html
  • 18. Exponentiation? Even easier mn = m * m*…*m // n times… so: pow ≡ λ n λ m (n m)
  • 19. Can we have booleans? ● ● ● ● ● ● true false and or not cond ≡ ≡ ≡ ≡ ≡ ≡ λ λ λ λ λ λ x x x x x c λ y x λ y y λ y ((x λ y ((x (x (λ a λ t λ f y) x) x) y) λ c c) (λ a λc a)) ((c t) f) Try It!!!
  • 20. λ Booleans in Javascript? ● ● ● ● ● True=function(x){return function(y){return x}} False=function(x){return function(y){return y}} And=function(x){return function(y){return x(y)(x)}} Or =function(x){return function(y){return x(x)(y)}} Cond = function(c){ return function(t){ return function(f){ return cond(t)(f) }}} Try It!!! you may need this: function p(f) {println(f == True ? "TRUE" : f == False ? "FALSE" : f)}
  • 21. Or we can try to reduce 1. 2. 3. 4. 5. and true false = (λ x λ y (x y x)) true false = true false true = (λ x λ y x) false true = false
  • 22. How cond works 1. 2. 3. 4. cond true λ c λ t λ ((true A) ((λ x λ y A B = f ((c t) f) true A B = B) = x) A) B = A 5. 6. 7. 8. cond false A B = λ c λ t λ f ((c t) f) false A B = ((false A) B) = ((λ x λ y y) A) B = B
  • 23. Can we check a number for zero? is_zero ≡ λ n n (λ x false) true in Javascript: is_zero=function(n){ return n(function(x){return false})(true) }
  • 24. Pair ● pair ≡ λ x λ y λ f (f x y) ● first ≡ λ p (p true) ● second ≡ λ p (p false)
  • 25. Moses Schönfinkel ● Invented currying ● Invented combinators ● His other papers were burned by his neighbors
  • 26. Combinators All lambda expressions can be build from these three: S, K, I No variables required. Hold on.
  • 27. Combinators ● I ≡ λx x ● K ≡ λx (λy x) ● S ≡ λx λ y λ z ((x z) (y z))
  • 28. Combinator I ● I ≡ λx x It is identity function; in Javascript: I = function(x) { return x }
  • 29. Combinator K ● K ≡ λx (λy x) It builds a constant function; in Javascript: K = function(x) { return function(y){return x} }
  • 30. Combinator S ● S ≡ λx λ y λ z ((x z) (y z)) It expresses the idea of substitution; in Javascript: S = function(x) { return function(y) { return function(z) { return x(z)(y(z)) } }}
  • 31. Using Combinators ● ((S K K) x) = (S K K x) = (K x (K x)) = x So I = SKK ● true=K ● false=KI ● numbers?
  • 32. Translating λ to Combinators To convert an expression e in the lambda calculus to an expression in SKI, define a function ϕ(e): e ϕ(e) λx x I λx c Kc λx (α β) (S(λx ϕ(α))(λx ϕ(β))) Now try Church Numerals...