Lambda Calculus (Logic)

Lambda calculus is regarded as the most simplest programming language in the world. It serves as a basis for logic that powers applications in Computer Science.

Lambda calculus is made from three templates.

First

a

Second

(λa.__)

Third

(__ __)

We can substitute any templates into any of the blanks in any template

In lambda calculus, everything is a function and can be applied on one another

In lambda calculus. (λa.a) is a function that takes in a to output a

(λa.function + argument  aoutput)
def func(a):
	return a

to pass in an argument lets say b. we apply function (λa.a) on b. Thus, passing b as an input into the function, replacing all values of a with b.

((λa.a) b)=b
func(b) # b

to pass more than one argument, lets say. Lets assume we have defined +

def func(a, b, c):
	return a+b+c

we have to define lambda for a, b and c

(λa.(λb.(λc.a+b+c) 3 ) 2 ) 1

Going from outer to inner brackets. Replace all a with 1, b with 2 and c with 3.

(λa.(λb.(λc.a+b+c) 3 ) 2 ) 1λb.(λc.1+b+c) 3) 2(λc.1+2+c) 31+2+3

we can express it as a short hand

λa.λb.λc.(a+b+c)

Boolean Logic

True and False are selectors. True selects the first element while False selects the second.

True:

T:=(λx.λy.x)

False

F:=(λx.λy.y)

For example

(T a b)=a

And

(F a b)=b

NOT

NOT T = F
NOT F = T

NOT=λx.(x  F  T)

Such that

NOT T=(λx.(x  F  T)) T=(T F T)=F

And

NOT F=λx.(x  F  T) F=(F F T)=T

AND

T AND T = T
T AND F = F
F AND T = F
F AND F = F

AND=λx.λy.(x y F)

OR

T OR T = T
T OR F = T
F OR T = T
F OR F = F

OR=λx.λy.(x T y)

NAND

T NAND T = F
T NAND F = T
F NAND T = T
F NAND F = T

NAND=λx.λy.(NOT (AND x y))

NOR

T NOR T = F
T NOR F = F
F NOR T = F
F NOR F = T

NOR=λx.λy.(NOT (OR x y))

From these gates, you can theoretically compute and create any function that a computer can do.

Numbers

A number is defined as

1=fx2=ffx3=fffx=n=λf.λx.(fnx)

It takes in a function f and a value x.

Thus

(n f x)=ffn timesx

Let a successor be defined as

SUCC(n)=n+1

Thus

SUCC=λn.λf.λx.(f(n f x))

Thus addition is defined as

+=λm.λn.λf.(m SUCC n)

And multiplication is defined as

×=λm.λn.λf.λx.m(n f) x