SlideShare une entreprise Scribd logo
1  sur  36
Lambda Calculus
Mahsa Seifikar
Winter 94
• History
• Definition
• Syntax λ calculus
• Function in Lambda Calculus
• Reduction
• Encoding data type in λ calculus
• Order of Evaluation
• Functional Programming
2
History
It was introduced in 1930s by Alonzo Church
as a way of formalizing the concept of
effective computability.
 λ calculus is a universal model of
computation equivalent to a Turing machine.
It also can be called the smallest universal
programming language of the world.
3
History
All function programming language can be
viewed as syncretic variation of λ calculus.
Functional languages such as Lisp, Scheme, FP,
ML, Miranda, and Haskell are an attempt to
realize Church's lambda calculus in practical
form as a programming language.
4
Definition
Lambda expressions are composed of:
 Variables
 The abstraction symbols lambda 'λ' and dot '.'
 parentheses ‘(‘ , ‘)'
Note : variable is an identifier which can be any
of the letters a, b, c.
5
Syntax λ calculus
The set of λ-terms (notation Λ) is built up from
an infantine set of variables 𝑉 = {𝑣, 𝑣′
, 𝑣′′
, . . }
i. 𝑥 ∈ 𝑉
ii. 𝑀, 𝑁 ∈ Λ → 𝑀𝑁 ∈ Λ
iii. 𝑀 ∈ Λ, 𝑥 ∈ 𝑉 → λ𝑥𝑀 ∈ Λ
rule 2 are known as application and rule 3 are
known as abstraction .
6
Syntax λ calculus
BN-form
𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒 ∷= ‘v’| 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒‘′’
λ−𝑡𝑒𝑟𝑚 ∷= 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒 |
‘(’ λ − 𝑡𝑒𝑟𝑚 λ − 𝑡𝑒𝑟𝑚 ‘)’ |
‘(λ’𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒 λ − 𝑡𝑒𝑟𝑚‘)’
7
Syntax λ calculus
Application associate from the left.
– x y z : (x y) z
Abstraction associate from the right.
– lx. x ly. x y z : l x. (x (ly. ((x y) z)))
Outermost parentheses are dropped.
8
Function in Lambda Calculus
Function in the λ calculus
 focus on the rule for going from an argument to
result.
 Ignore the issues of naming the function and its
domain and range.
 Mathematical function : ∀𝑥 ∈ 𝐴, 𝑓 𝑥 = 𝑥
 In the λ calculus : (λ𝑥. 𝑥)
 Argument is called x, the output of the function is
x.
9
Function in Lambda Calculus
 The application of the identity function to a :
λ𝑥. 𝑥 𝑎
 The argument for the identify itself:
λ𝑥. 𝑥 λ𝑥. 𝑥
 Function take an argument, ignore it and return the
identity function:
λy .(λ𝑥. 𝑥)
 Function take an argument, return a function that
ignore its own argument and return the argument
original function:
λy .(λ𝑥. 𝑦)
10
Free Variables
The set of free variables M denoted by 𝐹𝑉 𝑀
𝐹𝑉 𝑥 = 𝑥
𝐹𝑉 λ𝑥. 𝑀 = 𝐹𝑉 𝑀 𝑥
𝐹𝑉 𝑀 𝑁 = 𝐹𝑉 𝑀 ∪ 𝐹𝑉 𝑁
Note : Variables that fall within the scope of an
abstraction are said to be bound. All other
variables are called free.
11
Substitution
Substituting N for the free occurrences of x in M
Denoted by M[x := N]
x[x := N] ≡ N
y[x := N] ≡ y, if x ≠ y
(M1 M2)[x := N] ≡ (M1[x := N]) (M2[x := N])
(λx.M)[x := N] ≡ λx.M(λy.M)[x := N] ≡ λy.(M[x := N]), if x ≠ y, provided y ∉ FV(N)
12
Lambda Reduction
𝛼 − 𝑟𝑒𝑑𝑢𝑐𝑡𝑖𝑜𝑛
 allows bound variable names to be changed.
 if x and y is variable and M is a λ expression:
λx . M → 𝛼 λy . M[x → 𝑦]
 Example :
λ𝑦 . λ𝑓 . 𝑓 𝑥 𝑦 → 𝛼 λ𝑧 . λ𝑓 . 𝑓 𝑥 𝑧
λ𝑧 . λ𝑓 . 𝑓 𝑥 𝑧 → 𝛼 λ𝑧 . λ𝑔 . 𝑔 𝑥 𝑧
13
Lambda Reduction
𝛽 − 𝑟𝑒𝑑𝑢𝑐𝑡𝑖𝑜𝑛
 applying functions to their arguments.
 If x is variable and M and N are λ expression:
( λ𝑥. 𝑀 ) 𝑁 → 𝛽 𝑀[ 𝑥 → 𝑁]
 Example:
( ( λn . n∗x ) y) → y∗x
14
Lambda Reduction
Reversing β-reduction produce the
β-abstraction.
𝑀 𝑥 → 𝑁 → 𝛽 λ𝑥 . 𝑀 𝑁
β-abstraction and β-reduction taken together
give β-conversion
15
Lambda Reduction
ɳ − 𝑟𝑒𝑑𝑢𝑐𝑡𝑖𝑜𝑛
 which captures a notion of extensionality.
 If x is variables and M is a λ expression , and x has
no free occurrence in M :
λ𝑥 . 𝐸 𝑥 →ɳ 𝐸
 Example:
λ𝑥 . 𝑠𝑞𝑟 𝑥 →ɳ 𝑠𝑞𝑟
16
Lambda Reduction
The general reduction relation n is the union
of 𝛼 , 𝛽 and ɳ :
𝑛 = 𝛼 ∪ 𝛽 ∪ ɳ
When we use → 𝑛
𝛼
emphasize that
(→ 𝑛= → 𝑛
𝛼 ∪ → 𝑛
𝛽
∪ → 𝑛
ɳ
)
17
Encoding data type in λ calculus
Booleans
 Boolean is a function that give two choices selects
one of them.
𝑡𝑟𝑢𝑒 = l 𝑥. l 𝑦. 𝑥
𝑓𝑎𝑙𝑠𝑒 = l 𝑥. l 𝑦. 𝑦
18
Encoding data type in λ calculus
Logic Operator
 with two false term and true term, we can define
some logic operator:
and = λ𝑝. λ𝑞. 𝑝 𝑞 𝑝
or = λ𝑝. λ𝑞. 𝑝 𝑝 𝑞
not = λ𝑝. λ𝑎. λ𝑏. 𝑝 𝑏 𝑎
𝑖𝑓 = l 𝑣. l 𝑡. l 𝑓. 𝑣 𝑡 𝑓
 Symbol f and t correspond with to “false” and
“true” .
19
Encoding data type in λ calculus
Logic Operator
 For example :
𝑖𝑓 𝑡𝑟𝑢𝑒 𝑀 𝑁 = 𝑛 𝑀
𝑖𝑓 𝑡𝑟𝑢𝑒 𝑀 𝑁 = l 𝑣. l 𝑡. l 𝑓. 𝑣 𝑡 𝑓 l 𝑥. l 𝑦. 𝑥 𝑀 𝑁
→ 𝑛
𝑏 l 𝑡. l 𝑓. l 𝑥. l 𝑦. 𝑥 𝑡 𝑓 𝑀 𝑁
→ 𝑛
𝑏 l 𝑓. l 𝑥. l 𝑦. 𝑥 𝑀 𝑓 𝑁
→ 𝑛
𝑏
l 𝑥. l 𝑦. 𝑥 𝑀 𝑁
→ 𝑛
𝑏 l 𝑦. 𝑀 𝑁
→ 𝑛
𝑏 𝑀
20
Encoding data type in λ calculus
Natural Number
 A natural number n is encoded by a function of
two arguments, f and x, where the function
applies f to x, n times.
0 ≔ λ𝑓. λ𝑥. 𝑥
1 ≔ λ𝑓. λ𝑥. 𝑓 𝑥
2 ≔ λ𝑓. λ𝑥. 𝑓 𝑓 𝑥
3 ≔ λ𝑓. λ𝑥. 𝑓 (𝑓 (𝑓 𝑥))
21
Encoding data type in λ calculus
Natural Number
 the function add1 represent a number n and
produce a number n+1.
𝑎𝑑𝑑1 = λ𝑛. λ𝑓. λ𝑥. 𝑓 (𝑛 𝑓 𝑥 )
 The function applies first argument to second
argument n+1.
22
Encoding data type in λ calculus
Natural Number
 To add to numbers n and m, we apply add1 to n m
time
𝑎𝑑𝑑 = λ𝑛. λ𝑚. 𝑚 𝑎𝑑𝑑1 𝑛
 Multiplication can be defined as
𝑚𝑢𝑙𝑡 = 𝑚. 𝑛. 𝑚 𝑎𝑑𝑑 𝑛 0
 Iszero also
𝑖𝑠𝑧𝑒𝑟𝑜 = λ𝑛. 𝑛 λ𝑥. 𝑓𝑎𝑙𝑠𝑒 𝑡𝑟𝑢𝑒
23
Encoding data type in λ calculus
 Pair
< 𝑀, 𝑁 > = λ𝑠. 𝑠 𝑀 𝑁
𝑚𝑘𝑝𝑎𝑖𝑟 = λ𝑥. λ𝑦. λ𝑠. 𝑠 𝑥 𝑦
𝑓𝑠𝑡 = λ𝑝. 𝑝 𝑡𝑟𝑢𝑒
𝑠𝑐𝑛𝑑 = λ𝑝. 𝑝 𝑓𝑎𝑙𝑠𝑒
 A linked list can be defined as either NIL for the empty list, or
the pair of an element and a smaller list.
 The predicate NULL tests for the value NIL.
𝑛𝑢𝑙𝑙 = λ𝑝. 𝑝 (λ𝑥. 𝑦. 𝑓𝑎𝑙𝑠𝑒)
𝑛𝑖𝑙𝑙 = λ𝑥. 𝑡𝑟𝑢𝑒
24
Encoding data type in λ calculus
Recursive Function
 Is the definition of a function using the function itself.
𝐹 𝑛 = 1, 𝑖𝑓 𝑛 = 0; 𝑒𝑙𝑠𝑒 𝑛 ∗ 𝐹 𝑛 − 1
 Can be defined in the λ calculus using a function
which calls a function y and generates itself.
𝑌 = (λ 𝑓. λ 𝑥. 𝑓 𝑥𝑥 λ 𝑥. 𝑓 (𝑥𝑥) )
25
Encoding data type in λ calculus
Recursive Function
 Y f is the fixed point of f expand to :
𝑌 𝑓
λℎ. λ𝑥. ℎ 𝑥 𝑥 λ𝑥. ℎ 𝑥 𝑥 𝑓
λ𝑥. 𝑓 𝑥 𝑥 (λ𝑥. 𝑓 (𝑥 𝑥))
𝑓 ( λ𝑥. 𝑓 𝑥 𝑥 (λ𝑥. 𝑓 (𝑥 𝑥)))
𝑓 (𝑌 𝑓)
26
Encoding data type in λ calculus
Recursive Function
 For example, given n=4 to factorial function:
(Y F) 4
F (Y F) 4
(λr.λn.(1, if n = 0; else n × (r (n−1)))) (Y F) 4
(λn.(1, if n = 0; else n × ((Y F) (n−1)))) 4
1, if 4 = 0; else 4 × ((Y F) (4−1))
4 × (F (Y F) (4−1))
4 × ((λn.(1, if n = 0; else n × ((Y F) (n−1)))) (4−1))
4 × (1, if 3 = 0; else 3 × ((Y F) (3−1)))
4 × (3 × (F (Y F) (3−1)))
27
Encoding data type in λ calculus
Recursive Function
4 × (3 × ((λn.(1, if n = 0; else n × ((Y F) (n−1)))) (3−1)))
4 × (3 × (1, if 2 = 0; else 2 × ((Y F) (2−1))))
4 × (3 × (2 × (F (Y F) (2−1))))
4 × (3 × (2 × ((λn.(1, if n = 0; else n × ((Y F) (n−1)))) (2−1))))
4 × (3 × (2 × (1, if 1 = 0; else 1 × ((Y F) (1−1)))))
4 × (3 × (2 × (1 × (F (Y F) (1−1)))))
4 × (3 × (2 × (1 × ((λn.(1, if n = 0; else n × ((Y F) (n−1)))) (1−1)))))
4 × (3 × (2 × (1 × (1, if 0 = 0; else 0 × ((Y F) (0−1))))))
4 × (3 × (2 × (1 × (1))))
24
28
Normal Form
An expression is a normal form if it can’t be
reduced by → 𝑛
𝛽
or → 𝑛
ɳ
.
 M has normal form 𝑀 = 𝑛 𝑁 and N is a
normal form.
If 𝐿 = 𝑛 𝑀, 𝐿 = 𝑛 𝑁, and both M and N are
normal form, then 𝑀 = 𝛼 𝑁.
If an expression has a normal form, then may
be an infinite reduction sequence for the
expression that never reaches normal form.
29
Church-Rosser Theorem
Reduction in any way can eventually produce
the same result.
If 𝐸1 ↔ 𝐸2, then there exist an E such that
𝐸1 → 𝐸 and 𝐸2 → 𝐸.
If 𝐸1 → 𝐸2, and is a normal form, then there is
a normal-order reduction of 𝐸1to 𝐸2.
Normal-order reduction will always produce a
normal form, if one exists.
30
Order of Evaluation
In programming languages, we do not reduce the
bodies of functions (under a l).
Functions are considered values.
Call by Name
 No reduction are performed inside abstraction .
 Also call left-most, lazy evaluation.
 Call by Value
 Reduced only when its right hand side has reduced to a
value (variable or lambda abstraction).
 Also call Eager evaluation.
31
Order of Evaluation
Call by Name
– Difficult to implement.
– Order of side effects not predictable.
Call by Value
– Easy to implement efficiently.
– Might not terminate even if CBN might terminate.
– Example: (lx. l z.z) ((ly. yy) (lu. uu))
Outside the functional programming language
community, only CBV is used.
32
Functional Programming
• The lambda calculus is a prototypical
functional programming language.
– Higher order function
– No side-effect
• In practice, many functional programming
language are not “pure”, they permit.
– Supposed to avoid them
33
Functional Programming
Two main camps
– Haskell - Pure, lazy function language , no side-
effects
– ml (SML-OCaml) call- by- value with side-effects
Old still around : lisp scheme
– Disadvantage : no static typing
34
Functional Programming
• Functional ideas move to other languages.
• Garbage collection was designed for lisp ,now no
mast new languages us GC.
• Generics in C++/Java com from ML polymorphism
,or Haskell type classes
• Higher-order function and closures (used in Ruby,
exist in C# proposed to be in java soon) are
everywhere in function languages.
• Many object-oriented abstraction principles
come from ML’s module system.
35
References
Matthias Felleisen, “Programming Language
AND Lambda Calculus”.
Raul Rojas, “A Tutorial Introduction to the
Lambda Calculus”.
36

Contenu connexe

Tendances (20)

Compiler design lab programs
Compiler design lab programs Compiler design lab programs
Compiler design lab programs
 
INTRODUCTION TO LISP
INTRODUCTION TO LISPINTRODUCTION TO LISP
INTRODUCTION TO LISP
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Theory of Computation Unit 3
Theory of Computation Unit 3Theory of Computation Unit 3
Theory of Computation Unit 3
 
Backpropagation: Understanding How to Update ANNs Weights Step-by-Step
Backpropagation: Understanding How to Update ANNs Weights Step-by-StepBackpropagation: Understanding How to Update ANNs Weights Step-by-Step
Backpropagation: Understanding How to Update ANNs Weights Step-by-Step
 
polymorphism and virtual function
polymorphism and virtual functionpolymorphism and virtual function
polymorphism and virtual function
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Network flow problems
Network flow problemsNetwork flow problems
Network flow problems
 
AI_Planning.pdf
AI_Planning.pdfAI_Planning.pdf
AI_Planning.pdf
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
Haskell
HaskellHaskell
Haskell
 
Rule Based System
Rule Based SystemRule Based System
Rule Based System
 
AI Lecture 3 (solving problems by searching)
AI Lecture 3 (solving problems by searching)AI Lecture 3 (solving problems by searching)
AI Lecture 3 (solving problems by searching)
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
 
AI local search
AI local searchAI local search
AI local search
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Programming with LEX & YACC
Programming with LEX & YACCProgramming with LEX & YACC
Programming with LEX & YACC
 

Similaire à Lambda Calculus

Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture TwoAngelo Corsaro
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 
Lecture 2 family of fcts
Lecture 2   family of fctsLecture 2   family of fcts
Lecture 2 family of fctsnjit-ronbrown
 
On fuctional programming, high order functions, ML
On fuctional programming, high order functions, MLOn fuctional programming, high order functions, ML
On fuctional programming, high order functions, MLSimone Di Maulo
 
Programming modulo representations
Programming modulo representationsProgramming modulo representations
Programming modulo representationsMarco Benini
 
Functional Programming Concepts for Imperative Programmers
Functional Programming Concepts for Imperative ProgrammersFunctional Programming Concepts for Imperative Programmers
Functional Programming Concepts for Imperative ProgrammersChris
 
Lesson 1
Lesson 1Lesson 1
Lesson 1urenaa
 
Indefinite Integral
Indefinite IntegralIndefinite Integral
Indefinite IntegralRich Elle
 
List-based Monadic Computations for Dynamic Languages
List-based Monadic Computations for Dynamic LanguagesList-based Monadic Computations for Dynamic Languages
List-based Monadic Computations for Dynamic LanguagesWim Vanderbauwhede
 
Semi-Supervised Regression using Cluster Ensemble
Semi-Supervised Regression using Cluster EnsembleSemi-Supervised Regression using Cluster Ensemble
Semi-Supervised Regression using Cluster EnsembleAlexander Litvinenko
 
WEEK-4-Piecewise-Function-and-Rational-Function.pptx
WEEK-4-Piecewise-Function-and-Rational-Function.pptxWEEK-4-Piecewise-Function-and-Rational-Function.pptx
WEEK-4-Piecewise-Function-and-Rational-Function.pptxExtremelyDarkness2
 
Introduction to lambda calculus
Introduction to lambda calculusIntroduction to lambda calculus
Introduction to lambda calculusAfaq Siddiqui
 
Programming modulo representations
Programming modulo representationsProgramming modulo representations
Programming modulo representationsMarco Benini
 
Lesson 1
Lesson 1Lesson 1
Lesson 1urenaa
 
Interpolation
InterpolationInterpolation
InterpolationCAALAAA
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsEelco Visser
 

Similaire à Lambda Calculus (20)

Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture Two
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Lar calc10 ch05_sec1
Lar calc10 ch05_sec1Lar calc10 ch05_sec1
Lar calc10 ch05_sec1
 
Lecture 2 family of fcts
Lecture 2   family of fctsLecture 2   family of fcts
Lecture 2 family of fcts
 
05 dataflow
05 dataflow05 dataflow
05 dataflow
 
On fuctional programming, high order functions, ML
On fuctional programming, high order functions, MLOn fuctional programming, high order functions, ML
On fuctional programming, high order functions, ML
 
Programming Hp33s talk v3
Programming Hp33s talk v3Programming Hp33s talk v3
Programming Hp33s talk v3
 
Programming modulo representations
Programming modulo representationsProgramming modulo representations
Programming modulo representations
 
Functional Programming Concepts for Imperative Programmers
Functional Programming Concepts for Imperative ProgrammersFunctional Programming Concepts for Imperative Programmers
Functional Programming Concepts for Imperative Programmers
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 
R lecture co4_math 21-1
R lecture co4_math 21-1R lecture co4_math 21-1
R lecture co4_math 21-1
 
Indefinite Integral
Indefinite IntegralIndefinite Integral
Indefinite Integral
 
List-based Monadic Computations for Dynamic Languages
List-based Monadic Computations for Dynamic LanguagesList-based Monadic Computations for Dynamic Languages
List-based Monadic Computations for Dynamic Languages
 
Semi-Supervised Regression using Cluster Ensemble
Semi-Supervised Regression using Cluster EnsembleSemi-Supervised Regression using Cluster Ensemble
Semi-Supervised Regression using Cluster Ensemble
 
WEEK-4-Piecewise-Function-and-Rational-Function.pptx
WEEK-4-Piecewise-Function-and-Rational-Function.pptxWEEK-4-Piecewise-Function-and-Rational-Function.pptx
WEEK-4-Piecewise-Function-and-Rational-Function.pptx
 
Introduction to lambda calculus
Introduction to lambda calculusIntroduction to lambda calculus
Introduction to lambda calculus
 
Programming modulo representations
Programming modulo representationsProgramming modulo representations
Programming modulo representations
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 
Interpolation
InterpolationInterpolation
Interpolation
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 

Dernier

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
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
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Dernier (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
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
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

Lambda Calculus

  • 2. • History • Definition • Syntax λ calculus • Function in Lambda Calculus • Reduction • Encoding data type in λ calculus • Order of Evaluation • Functional Programming 2
  • 3. History It was introduced in 1930s by Alonzo Church as a way of formalizing the concept of effective computability.  λ calculus is a universal model of computation equivalent to a Turing machine. It also can be called the smallest universal programming language of the world. 3
  • 4. History All function programming language can be viewed as syncretic variation of λ calculus. Functional languages such as Lisp, Scheme, FP, ML, Miranda, and Haskell are an attempt to realize Church's lambda calculus in practical form as a programming language. 4
  • 5. Definition Lambda expressions are composed of:  Variables  The abstraction symbols lambda 'λ' and dot '.'  parentheses ‘(‘ , ‘)' Note : variable is an identifier which can be any of the letters a, b, c. 5
  • 6. Syntax λ calculus The set of λ-terms (notation Λ) is built up from an infantine set of variables 𝑉 = {𝑣, 𝑣′ , 𝑣′′ , . . } i. 𝑥 ∈ 𝑉 ii. 𝑀, 𝑁 ∈ Λ → 𝑀𝑁 ∈ Λ iii. 𝑀 ∈ Λ, 𝑥 ∈ 𝑉 → λ𝑥𝑀 ∈ Λ rule 2 are known as application and rule 3 are known as abstraction . 6
  • 7. Syntax λ calculus BN-form 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒 ∷= ‘v’| 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒‘′’ λ−𝑡𝑒𝑟𝑚 ∷= 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒 | ‘(’ λ − 𝑡𝑒𝑟𝑚 λ − 𝑡𝑒𝑟𝑚 ‘)’ | ‘(λ’𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒 λ − 𝑡𝑒𝑟𝑚‘)’ 7
  • 8. Syntax λ calculus Application associate from the left. – x y z : (x y) z Abstraction associate from the right. – lx. x ly. x y z : l x. (x (ly. ((x y) z))) Outermost parentheses are dropped. 8
  • 9. Function in Lambda Calculus Function in the λ calculus  focus on the rule for going from an argument to result.  Ignore the issues of naming the function and its domain and range.  Mathematical function : ∀𝑥 ∈ 𝐴, 𝑓 𝑥 = 𝑥  In the λ calculus : (λ𝑥. 𝑥)  Argument is called x, the output of the function is x. 9
  • 10. Function in Lambda Calculus  The application of the identity function to a : λ𝑥. 𝑥 𝑎  The argument for the identify itself: λ𝑥. 𝑥 λ𝑥. 𝑥  Function take an argument, ignore it and return the identity function: λy .(λ𝑥. 𝑥)  Function take an argument, return a function that ignore its own argument and return the argument original function: λy .(λ𝑥. 𝑦) 10
  • 11. Free Variables The set of free variables M denoted by 𝐹𝑉 𝑀 𝐹𝑉 𝑥 = 𝑥 𝐹𝑉 λ𝑥. 𝑀 = 𝐹𝑉 𝑀 𝑥 𝐹𝑉 𝑀 𝑁 = 𝐹𝑉 𝑀 ∪ 𝐹𝑉 𝑁 Note : Variables that fall within the scope of an abstraction are said to be bound. All other variables are called free. 11
  • 12. Substitution Substituting N for the free occurrences of x in M Denoted by M[x := N] x[x := N] ≡ N y[x := N] ≡ y, if x ≠ y (M1 M2)[x := N] ≡ (M1[x := N]) (M2[x := N]) (λx.M)[x := N] ≡ λx.M(λy.M)[x := N] ≡ λy.(M[x := N]), if x ≠ y, provided y ∉ FV(N) 12
  • 13. Lambda Reduction 𝛼 − 𝑟𝑒𝑑𝑢𝑐𝑡𝑖𝑜𝑛  allows bound variable names to be changed.  if x and y is variable and M is a λ expression: λx . M → 𝛼 λy . M[x → 𝑦]  Example : λ𝑦 . λ𝑓 . 𝑓 𝑥 𝑦 → 𝛼 λ𝑧 . λ𝑓 . 𝑓 𝑥 𝑧 λ𝑧 . λ𝑓 . 𝑓 𝑥 𝑧 → 𝛼 λ𝑧 . λ𝑔 . 𝑔 𝑥 𝑧 13
  • 14. Lambda Reduction 𝛽 − 𝑟𝑒𝑑𝑢𝑐𝑡𝑖𝑜𝑛  applying functions to their arguments.  If x is variable and M and N are λ expression: ( λ𝑥. 𝑀 ) 𝑁 → 𝛽 𝑀[ 𝑥 → 𝑁]  Example: ( ( λn . n∗x ) y) → y∗x 14
  • 15. Lambda Reduction Reversing β-reduction produce the β-abstraction. 𝑀 𝑥 → 𝑁 → 𝛽 λ𝑥 . 𝑀 𝑁 β-abstraction and β-reduction taken together give β-conversion 15
  • 16. Lambda Reduction ɳ − 𝑟𝑒𝑑𝑢𝑐𝑡𝑖𝑜𝑛  which captures a notion of extensionality.  If x is variables and M is a λ expression , and x has no free occurrence in M : λ𝑥 . 𝐸 𝑥 →ɳ 𝐸  Example: λ𝑥 . 𝑠𝑞𝑟 𝑥 →ɳ 𝑠𝑞𝑟 16
  • 17. Lambda Reduction The general reduction relation n is the union of 𝛼 , 𝛽 and ɳ : 𝑛 = 𝛼 ∪ 𝛽 ∪ ɳ When we use → 𝑛 𝛼 emphasize that (→ 𝑛= → 𝑛 𝛼 ∪ → 𝑛 𝛽 ∪ → 𝑛 ɳ ) 17
  • 18. Encoding data type in λ calculus Booleans  Boolean is a function that give two choices selects one of them. 𝑡𝑟𝑢𝑒 = l 𝑥. l 𝑦. 𝑥 𝑓𝑎𝑙𝑠𝑒 = l 𝑥. l 𝑦. 𝑦 18
  • 19. Encoding data type in λ calculus Logic Operator  with two false term and true term, we can define some logic operator: and = λ𝑝. λ𝑞. 𝑝 𝑞 𝑝 or = λ𝑝. λ𝑞. 𝑝 𝑝 𝑞 not = λ𝑝. λ𝑎. λ𝑏. 𝑝 𝑏 𝑎 𝑖𝑓 = l 𝑣. l 𝑡. l 𝑓. 𝑣 𝑡 𝑓  Symbol f and t correspond with to “false” and “true” . 19
  • 20. Encoding data type in λ calculus Logic Operator  For example : 𝑖𝑓 𝑡𝑟𝑢𝑒 𝑀 𝑁 = 𝑛 𝑀 𝑖𝑓 𝑡𝑟𝑢𝑒 𝑀 𝑁 = l 𝑣. l 𝑡. l 𝑓. 𝑣 𝑡 𝑓 l 𝑥. l 𝑦. 𝑥 𝑀 𝑁 → 𝑛 𝑏 l 𝑡. l 𝑓. l 𝑥. l 𝑦. 𝑥 𝑡 𝑓 𝑀 𝑁 → 𝑛 𝑏 l 𝑓. l 𝑥. l 𝑦. 𝑥 𝑀 𝑓 𝑁 → 𝑛 𝑏 l 𝑥. l 𝑦. 𝑥 𝑀 𝑁 → 𝑛 𝑏 l 𝑦. 𝑀 𝑁 → 𝑛 𝑏 𝑀 20
  • 21. Encoding data type in λ calculus Natural Number  A natural number n is encoded by a function of two arguments, f and x, where the function applies f to x, n times. 0 ≔ λ𝑓. λ𝑥. 𝑥 1 ≔ λ𝑓. λ𝑥. 𝑓 𝑥 2 ≔ λ𝑓. λ𝑥. 𝑓 𝑓 𝑥 3 ≔ λ𝑓. λ𝑥. 𝑓 (𝑓 (𝑓 𝑥)) 21
  • 22. Encoding data type in λ calculus Natural Number  the function add1 represent a number n and produce a number n+1. 𝑎𝑑𝑑1 = λ𝑛. λ𝑓. λ𝑥. 𝑓 (𝑛 𝑓 𝑥 )  The function applies first argument to second argument n+1. 22
  • 23. Encoding data type in λ calculus Natural Number  To add to numbers n and m, we apply add1 to n m time 𝑎𝑑𝑑 = λ𝑛. λ𝑚. 𝑚 𝑎𝑑𝑑1 𝑛  Multiplication can be defined as 𝑚𝑢𝑙𝑡 = 𝑚. 𝑛. 𝑚 𝑎𝑑𝑑 𝑛 0  Iszero also 𝑖𝑠𝑧𝑒𝑟𝑜 = λ𝑛. 𝑛 λ𝑥. 𝑓𝑎𝑙𝑠𝑒 𝑡𝑟𝑢𝑒 23
  • 24. Encoding data type in λ calculus  Pair < 𝑀, 𝑁 > = λ𝑠. 𝑠 𝑀 𝑁 𝑚𝑘𝑝𝑎𝑖𝑟 = λ𝑥. λ𝑦. λ𝑠. 𝑠 𝑥 𝑦 𝑓𝑠𝑡 = λ𝑝. 𝑝 𝑡𝑟𝑢𝑒 𝑠𝑐𝑛𝑑 = λ𝑝. 𝑝 𝑓𝑎𝑙𝑠𝑒  A linked list can be defined as either NIL for the empty list, or the pair of an element and a smaller list.  The predicate NULL tests for the value NIL. 𝑛𝑢𝑙𝑙 = λ𝑝. 𝑝 (λ𝑥. 𝑦. 𝑓𝑎𝑙𝑠𝑒) 𝑛𝑖𝑙𝑙 = λ𝑥. 𝑡𝑟𝑢𝑒 24
  • 25. Encoding data type in λ calculus Recursive Function  Is the definition of a function using the function itself. 𝐹 𝑛 = 1, 𝑖𝑓 𝑛 = 0; 𝑒𝑙𝑠𝑒 𝑛 ∗ 𝐹 𝑛 − 1  Can be defined in the λ calculus using a function which calls a function y and generates itself. 𝑌 = (λ 𝑓. λ 𝑥. 𝑓 𝑥𝑥 λ 𝑥. 𝑓 (𝑥𝑥) ) 25
  • 26. Encoding data type in λ calculus Recursive Function  Y f is the fixed point of f expand to : 𝑌 𝑓 λℎ. λ𝑥. ℎ 𝑥 𝑥 λ𝑥. ℎ 𝑥 𝑥 𝑓 λ𝑥. 𝑓 𝑥 𝑥 (λ𝑥. 𝑓 (𝑥 𝑥)) 𝑓 ( λ𝑥. 𝑓 𝑥 𝑥 (λ𝑥. 𝑓 (𝑥 𝑥))) 𝑓 (𝑌 𝑓) 26
  • 27. Encoding data type in λ calculus Recursive Function  For example, given n=4 to factorial function: (Y F) 4 F (Y F) 4 (λr.λn.(1, if n = 0; else n × (r (n−1)))) (Y F) 4 (λn.(1, if n = 0; else n × ((Y F) (n−1)))) 4 1, if 4 = 0; else 4 × ((Y F) (4−1)) 4 × (F (Y F) (4−1)) 4 × ((λn.(1, if n = 0; else n × ((Y F) (n−1)))) (4−1)) 4 × (1, if 3 = 0; else 3 × ((Y F) (3−1))) 4 × (3 × (F (Y F) (3−1))) 27
  • 28. Encoding data type in λ calculus Recursive Function 4 × (3 × ((λn.(1, if n = 0; else n × ((Y F) (n−1)))) (3−1))) 4 × (3 × (1, if 2 = 0; else 2 × ((Y F) (2−1)))) 4 × (3 × (2 × (F (Y F) (2−1)))) 4 × (3 × (2 × ((λn.(1, if n = 0; else n × ((Y F) (n−1)))) (2−1)))) 4 × (3 × (2 × (1, if 1 = 0; else 1 × ((Y F) (1−1))))) 4 × (3 × (2 × (1 × (F (Y F) (1−1))))) 4 × (3 × (2 × (1 × ((λn.(1, if n = 0; else n × ((Y F) (n−1)))) (1−1))))) 4 × (3 × (2 × (1 × (1, if 0 = 0; else 0 × ((Y F) (0−1)))))) 4 × (3 × (2 × (1 × (1)))) 24 28
  • 29. Normal Form An expression is a normal form if it can’t be reduced by → 𝑛 𝛽 or → 𝑛 ɳ .  M has normal form 𝑀 = 𝑛 𝑁 and N is a normal form. If 𝐿 = 𝑛 𝑀, 𝐿 = 𝑛 𝑁, and both M and N are normal form, then 𝑀 = 𝛼 𝑁. If an expression has a normal form, then may be an infinite reduction sequence for the expression that never reaches normal form. 29
  • 30. Church-Rosser Theorem Reduction in any way can eventually produce the same result. If 𝐸1 ↔ 𝐸2, then there exist an E such that 𝐸1 → 𝐸 and 𝐸2 → 𝐸. If 𝐸1 → 𝐸2, and is a normal form, then there is a normal-order reduction of 𝐸1to 𝐸2. Normal-order reduction will always produce a normal form, if one exists. 30
  • 31. Order of Evaluation In programming languages, we do not reduce the bodies of functions (under a l). Functions are considered values. Call by Name  No reduction are performed inside abstraction .  Also call left-most, lazy evaluation.  Call by Value  Reduced only when its right hand side has reduced to a value (variable or lambda abstraction).  Also call Eager evaluation. 31
  • 32. Order of Evaluation Call by Name – Difficult to implement. – Order of side effects not predictable. Call by Value – Easy to implement efficiently. – Might not terminate even if CBN might terminate. – Example: (lx. l z.z) ((ly. yy) (lu. uu)) Outside the functional programming language community, only CBV is used. 32
  • 33. Functional Programming • The lambda calculus is a prototypical functional programming language. – Higher order function – No side-effect • In practice, many functional programming language are not “pure”, they permit. – Supposed to avoid them 33
  • 34. Functional Programming Two main camps – Haskell - Pure, lazy function language , no side- effects – ml (SML-OCaml) call- by- value with side-effects Old still around : lisp scheme – Disadvantage : no static typing 34
  • 35. Functional Programming • Functional ideas move to other languages. • Garbage collection was designed for lisp ,now no mast new languages us GC. • Generics in C++/Java com from ML polymorphism ,or Haskell type classes • Higher-order function and closures (used in Ruby, exist in C# proposed to be in java soon) are everywhere in function languages. • Many object-oriented abstraction principles come from ML’s module system. 35
  • 36. References Matthias Felleisen, “Programming Language AND Lambda Calculus”. Raul Rojas, “A Tutorial Introduction to the Lambda Calculus”. 36

Notes de l'éditeur

  1. Baraye hazf noghte o parantez miain az ghanonaye bala estefade mikonim k estedafe azashono b hadeaqal bresoim. Tozihaye bishtar bde
  2. Barreeesi halat haye khase function abstarct
  3. Inja bgo k to zaban haye static scope alph conv mitone baraye name resolution estefade bshe