Fundamentals and lambda calculus
|
|
- Felix Brown
- 6 years ago
- Views:
Transcription
1 Fundamentals and lambda calculus
2 Again: JavaScript functions JavaScript functions are first-class Syntax is a bit ugly/terse when you want to use functions as values; recall block scoping: (function () { //... do something }) (); New version has cleaner syntax called arrow functions Semantics not always the same (this has different meaning), but for this class should always be safe to use
3 In this lecture
4 In this lecture
5 In this lecture
6 In this lecture λ
7 What is the lambda calculus? Simplest reasonable programming language Only has one feature: functions
8 Why study it? Captures the idea of first-class functions Good system for studying the concept of variable binding that appears in almost all languages Historically important Competing model of computation introduced by Church as an alternative to Turing machines: substitution (you ll see this today) = symbolic comp Influenced Lisp (thus JS), ML, Haskell, C++, etc.
9 Why else? Base for studying many programming languages You can use lambda calculus and extended it in different ways to study languages and features E.g., we can study the difference between strict languages like JavaScript and lazy ones like Haskell λ + evaluation strategy E.g., we can study different kinds of type systems Simply-typed λ calculus, polymorphic, etc.
10 Why else? Most PL papers describe language models that build on lambda calculus Understanding λ will help you interpret what you are reading in PL research papers Understanding λ will help you get started with other formal/theoretical foundations: Operational semantics Denotational semantics
11 Before we get started, some terminology Syntax (grammar) The symbols used to write a program E.g., (x + y) is a grammatical expression Semantics The actions that occur when a program is executed PL implementation: Syntax -> Semantics
12 Before we get started, some terminology Syntax (grammar) The symbols used to write a program E.g., (x + y) is a grammatical expression Semantics The actions that occur when a program is executed PL implementation: Syntax -> Semantics
13 Before we get started, some terminology Syntax (grammar) The symbols used to write a program E.g., (x + y) is a grammatical expression Semantics The actions that occur when a program is executed PL implementation: Syntax -> Semantics
14 Week 2 Syntax of λ calculus Semantics of λ calculus Informal substitution Free and bound variables Formal substitution Evaluation order
15 Lambda calculus Language syntax (grammar): Expressions: e ::= x λx.e e 1 e 2 Variables: x Functions or λ abstractions: λx.e This is the same as x => e in JavaScript! Function application: e 1 e 2 This is the same as e 1 (e2) in JavaScript!
16 Example terms λx.(2+x) Same as: x => (2 + x) (λx.(2 + x)) 5 Same as: (x => (2 + x)) (5) (λf.(f 3)) (λx.(x + 1)) Same as: (f => (f (3))) (x => (x+1))
17 Example terms λx.(2+x) LIES! What is this 2 and +? (Sugar.) Same as: x => (2 + x) (λx.(2 + x)) 5 Same as: (x => (2 + x)) (5) (λf.(f 3)) (λx.(x + 1)) Same as: (f => (f (3))) (x => (x+1))
18 Example terms λx.(2+x) Same as: x => (2 + x) (λx.(2 + x)) 5 Same as: (x => (2 + x)) (5) (λf.(f 3)) (λx.(x + 1)) Same as: (f => (f (3))) (x => (x+1))
19 Example terms λx.(2+x) Same as: x => (2 + x) (λx.(2 + x)) 5 Same as: (x => (2 + x)) (5) (λf.(f 3)) (λx.(x + 1)) Same as: (f => (f (3))) (x => (x+1))
20 Example terms λx.(2+x) Same as: x => (2 + x) (λx.(2 + x)) 5 Same as: (x => (2 + x)) (5) (λf.(f 3)) (λx.(x + 1)) Same as: (f => (f (3))) (x => (x+1))
21 JavaScript to λ calculus Let s look at function composition: (f f)(x) In JavaScript: f => (x => f (f (x))) ((f => (x => f (f (x)))) (x => x+1)) (4) In λ: λf.(λx. f (f x)) ((λf.(λx. f (f x)) (λx.x+1)) 4
22 JavaScript to λ calculus Let s look at function composition: (f f)(x) In JavaScript: f => (x => f (f (x))) ((f => (x => f (f (x)))) (x => x+1)) (4) In λ: λf.(λx. f (f x)) ((λf.(λx. f (f x)) (λx.x+1)) 4
23 JavaScript to λ calculus Let s look at function composition: (f f)(x) In JavaScript: f => (x => f (f (x))) ((f => (x => f (f (x)))) (x => x+1)) (4) In λ: λf.(λx. f (f x)) ((λf.(λx. f (f x)) (λx.x+1)) 4
24 Understanding λ calculus syntax λ-calculus syntax: e ::= x λx.e e 1 e 2 Is λ(x+y). 3 a valid term? (A: yes, B: no) Is λx. 3 a valid term? (A: yes, B: no) Is λx. (x x) a valid term? (A: yes, B: no) Is λx. x (x y) a valid term? (A: yes, B: no)
25 Understanding λ calculus syntax λ-calculus syntax: e ::= x λx.e e 1 e 2 Is λ(x+y). 3 a valid term? (A: yes, B: no) Is λx. 3 a valid term? (A: yes, B: no) Is λx. (x x) a valid term? (A: yes, B: no) Is λx. x (x y) a valid term? (A: yes, B: no)
26 Understanding λ calculus syntax λ-calculus syntax: e ::= x λx.e e 1 e 2 Is λ(x+y). 3 a valid term? (A: yes, B: no) Is λx. 3 a valid term? (A: yes, B: no) Is λx. (x x) a valid term? (A: yes, B: no) Is λx. x (x y) a valid term? (A: yes, B: no)
27 Understanding λ calculus syntax λ-calculus syntax: e ::= x λx.e e 1 e 2 Is λ(x+y). 3 a valid term? (A: yes, B: no) Is λx. 3 a valid term? (A: yes, B: no) Is λx. (x x) a valid term? (A: yes, B: no) Is λx. x (x y) a valid term? (A: yes, B: no)
28 Understanding λ calculus syntax λ-calculus syntax: e ::= x λx.e e 1 e 2 Is λ(x+y). 3 a valid term? (A: yes, B: no) Is λx. 3 a valid term? (A: yes, B: no) Is λx. (x x) a valid term? (A: yes, B: no) Is λx. x (x y) a valid term? (A: yes, B: no)
29 More compact syntax Function application is left associative e1 e 2 e 3 (e 1 e 2 ) e 3 Lambdas binds all the way to right: only stop when you find unmatched closing paren ) λx.λy.λz.e λx.(λy.(λz.e)) Why? Lambda abstraction has lowest precedence!
30 Understanding compact syntax Write the parens: λx.x x A: λx.(x x) B: (λx.x) x
31 Understanding compact syntax Write the parens: λx.x x A: λx.(x x) B: (λx.x) x
32 Understanding compact syntax Write the parens: λy.λx.x x = A: λy.(λx.x) x B: λy.(λx.(x x)) C: (λy.(λx.x)) x
33 Understanding compact syntax Write the parens: λy.λx.x x = A: λy.(λx.x) x B: λy.(λx.(x x)) C: (λy.(λx.x)) x
34 Understanding compact syntax Is (λy.λx.x) x = λy.λx.x x? A: yes B: no
35 Understanding compact syntax Is (λy.λx.x) x = λy.λx.x x? A: yes B: no
36 Parsing rules Applications are left associative Precedence: application > lambda abstraction
37 Add parentheses λy.λx.x x λz.y λw.w λy.λx.(x x) λz.y λw.w λy.λx.((x x) λz.y) λw.w λy.λx.(((x x) λz.y) λw.w) λy.λx.(((x x) λz.y) (λw.w)) A: λy.λx.(((x x) (λz.y)) (λw.w)) B: λy.λx.(((x x) (λz.y) (λw.w)))
38 Add parentheses λy.λx.x x λz.y λw.w λy.λx.(x x) λz.y λw.w λy.λx.((x x) λz.y) λw.w λy.λx.(((x x) λz.y) λw.w) λy.λx.(((x x) λz.y) (λw.w)) A: λy.λx.(((x x) (λz.y)) (λw.w)) B: λy.λx.(((x x) (λz.y) (λw.w)))
39 Add parentheses λy.λx.x x λz.y λw.w λy.λx.(x x) λz.y λw.w λy.λx.((x x) λz.y) λw.w λy.λx.(((x x) λz.y) λw.w) λy.λx.(((x x) λz.y) (λw.w)) A: λy.λx.(((x x) (λz.y)) (λw.w)) First unmatched closing paren B: λy.λx.(((x x) (λz.y) (λw.w)))
40 Even more compact syntax Can always variables left of the period λx.λy.λz.e λxyz.e This makes the term look like a 3 argument function Can implement multiple-argument function using single-argument functions: called currying (bonus) We won t use this syntax, but you may see in the wild
41 Week 2 Syntax of λ calculus Semantics of λ calculus Informal substitution Free and bound variables Formal substitution Evaluation order
42 Semantics of λ calculus Reduce a term to another as much as we can If we can t reduce it any further, the term is said to be in normal form How? Rewrite terms! What does that mean?! Substitution!
43 Example terms Example: (λx.(2 + x)) 5 (2 + 5) 7 In JavaScript: (x => (2 + x)) (5) (2 + 5) 7 Example: (λf.(f 3)) (λx.(x + 1)) ((λx.(x + 1)) 3) (3 + 1) 4 In JavaScript: (f => (f (3))) (x => (x+1)) ((x => (x+1)) (3) (3+1) 4
44 Example terms Example: (λx.(2 + x)) 5 (2 + 5) 7 In JavaScript: (x => (2 + x)) (5) (2 + 5) 7 Example: (λf.(f 3)) (λx.(x + 1)) ((λx.(x + 1)) 3) (3 + 1) 4 In JavaScript: (f => (f (3))) (x => (x+1)) ((x => (x+1)) (3) (3+1) 4
45 Example terms Example: (λx.(2 + x)) 5 (2 + 5) 7 In JavaScript: (x => (2 + x)) (5) (2 + 5) 7 Example: (λf.(f 3)) (λx.(x + 1)) ((λx.(x + 1)) 3) (3 + 1) 4 In JavaScript: (f => (f (3))) (x => (x+1)) ((x => (x+1)) (3) (3+1) 4
46 Example terms Example: (λx.(2 + x)) 5 (2 + 5) 7 In JavaScript: (x => (2 + x)) (5) (2 + 5) 7 Example: (λf.(f 3)) (λx.(x + 1)) ((λx.(x + 1)) 3) (3 + 1) 4 In JavaScript: (f => (f (3))) (x => (x+1)) ((x => (x+1)) (3) (3+1) 4
47 Example terms Example: (λx.(2 + x)) 5 (2 + 5) 7 In JavaScript: (x => (2 + x)) (5) (2 + 5) 7 Example: (λf.(f 3)) (λx.(x + 1)) ((λx.(x + 1)) 3) (3 + 1) 4 In JavaScript: (f => (f (3))) (x => (x+1)) ((x => (x+1)) (3) (3+1) 4
48 Example terms Example: (λx.(2 + x)) 5 (2 + 5) 7 In JavaScript: (x => (2 + x)) (5) (2 + 5) 7 Example: (λf.(f 3)) (λx.(x + 1)) ((λx.(x + 1)) 3) (3 + 1) 4 In JavaScript: (f => (f (3))) (x => (x+1)) ((x => (x+1)) (3) (3+1) 4
49 Example terms Example: (λx.(2 + x)) 5 (2 + 5) 7 In JavaScript: (x => (2 + x)) (5) (2 + 5) 7 Example: (λf.(f 3)) (λx.(x + 1)) ((λx.(x + 1)) 3) (3 + 1) 4 In JavaScript: (f => (f (3))) (x => (x+1)) ((x => (x+1)) (3) (3+1) 4
50 Example terms Example: (λx.(2 + x)) 5 (2 + 5) 7 In JavaScript: (x => (2 + x)) (5) (2 + 5) 7 Example: (λf.(f 3)) (λx.(x + 1)) ((λx.(x + 1)) 3) (3 + 1) 4 In JavaScript: (f => (f (3))) (x => (x+1)) ((x => (x+1)) (3) (3+1) 4
51 Example terms Example: (λx.(2 + x)) 5 (2 + 5) 7 In JavaScript: (x => (2 + x)) (5) (2 + 5) 7 Example: (λf.(f 3)) (λx.(x + 1)) ((λx.(x + 1)) 3) (3 + 1) 4 In JavaScript: (f => (f (3))) (x => (x+1)) ((x => (x+1)) (3) (3+1) 4
52 Easy! Pattern for function application: substitute the term you are applying the function to for the argument variable
53 Substitution (not right) Def: Substitution: e 1 [x := e 2 ] Replace every occurrence of x in e1 with e 2 General reduction rule for λ calculus: (λx.e 1 ) e 2 e 1 [x := e 2 ] Function application rewritten to e 1 (the function body) with every x in e 1 substituted with e 2 (argument)
54 Substitution (not right) Def: Substitution: e 1 [x := e 2 ] Replace every occurrence of x in e1 with e 2 General reduction rule for λ calculus: (λx.e 1 ) e 2 e 1 [x := e 2 ] Function application rewritten to e 1 (the function body) with every x in e 1 substituted with e 2 (argument)
55 Simple examples Reduce (λx.(2 + x)) 5 (2 + 5) 7 Reduce: (λx.λy.λz.y+3) = (((λx.λy.λz.y+3) 4) 5) 6 ((λy.λz.y+3) 5) 6 (λz.5+3) 6 (5+3) 8
56 Simple examples Reduce (λx.(2 + x)) 5 (2 + 5) 7 Reduce: (λx.λy.λz.y+3) = (((λx.λy.λz.y+3) 4) 5) 6 ((λy.λz.y+3) 5) 6 (λz.5+3) 6 (5+3) 8
57 Simple examples Reduce (λx.(2 + x)) 5 (2 + 5) 7 Reduce: (λx.λy.λz.y+3) = (((λx.λy.λz.y+3) 4) 5) 6 ((λy.λz.y+3) 5) 6 (λz.5+3) 6 (5+3) 8
58 Simple examples (cont) Reduce (λx.(λy.2) 3) 5 (λx. 2) 5 2 Reduce: ((λx.(λy.2)) 3) 5 ((λy.2) 5) 2 Is (λx.(λy.2) 3) 5 = ((λx.(λy.2)) 3) 5? A: yes, B: no
59 Simple examples (cont) Reduce (λx.(λy.2) 3) 5 (λx. 2) 5 2 Reduce: ((λx.(λy.2)) 3) 5 ((λy.2) 5) 2 Is (λx.(λy.2) 3) 5 = ((λx.(λy.2)) 3) 5? A: yes, B: no
60 Simple examples (cont) Reduce (λx.(λy.2) 3) 5 (λx. 2) 5 2 Reduce: ((λx.(λy.2)) 3) 5 ((λy.2) 5) 2 Is (λx.(λy.2) 3) 5 = ((λx.(λy.2)) 3) 5? A: yes, B: no
61 Simple examples (cont) Reduce (λx.(λy.2) 3) 5 (λx. 2) 5 2 Reduce: ((λx.(λy.2)) 3) 5 ((λy.2) 5) 2 Is (λx.(λy.2) 3) 5 = ((λx.(λy.2)) 3) 5? A: yes, B: no
62 A more complicated example
63 A more complicated example Reduce the following: (λx. (λa. x + a) 7) 4
64 A more complicated example Reduce the following: (λx. (λa. x + a) 7) 4 (λa. 4 + a) 7
65 A more complicated example Reduce the following: (λx. (λa. x + a) 7) 4 (λa. 4 + a)
66 A more complicated example Reduce the following: (λx. (λa. x + a) 7) 4 (λa. 4 + a)
67 Let s make this even more fun!
68 Let s make this even more fun! Instead of 4, let s apply function to (a + 5) (λx. (λa. x + a) 7) (a + 5)
69 Let s make this even more fun! Instead of 4, let s apply function to (a + 5) (λx. (λa. x + a) 7) (a + 5) (λa. (a + 5) + a) 7
70 Let s make this even more fun! Instead of 4, let s apply function to (a + 5) (λx. (λa. x + a) 7) (a + 5) (λa. (a + 5) + a) 7 (7 + 5) + 7
71 Let s make this even more fun! Instead of 4, let s apply function to (a + 5) (λx. (λa. x + a) 7) (a + 5) (λa. (a + 5) + a) 7 (7 + 5)
72 Let s make this even more fun! Instead of 4, let s apply function to (a + 5) (λx. (λa. x + a) 7) (a + 5) (λa. (a + 5) + a) 7 (7 + 5) A: yes, B: no Is this right?
73 Let s make this even more fun! Instead of 4, let s apply function to (a + 5) (λx. (λa. x + a) 7) (a + 5) (λa. (a + 5) + a) 7 (7 + 5) A: yes, B: no Is this right?
74 Substitution is surprisingly complex Recall our reduction rule for application: (λx.e 1 ) e 2 e 1 [x := e 2 ] This function application reduces to e 1 (the function body) where every x in e 1 is substituted with e 2 (value we re applying func to) Where did we go wrong? When we substituted: (λx. (λa. x + a) 7) (a + 5) (λa. (a + 5) + a) 7 the a is captured!
75 Example to do at home
76 Example to do at home Reduce the following ((λf.(λx. f (f x))) (λx.x+1)) 4
77 Example to do at home Reduce the following ((λf.(λx. f (f x))) (λx.x+1)) 4 (λx. (λx.x+1) ((λx.x+1) x)) 4
78 Example to do at home Reduce the following ((λf.(λx. f (f x))) (λx.x+1)) 4 (λx. (λx.x+1) ((λx.x+1) x)) 4 (λx.x+1) ((λx.x+1) 4)
79 Example to do at home Reduce the following ((λf.(λx. f (f x))) (λx.x+1)) 4 (λx. (λx.x+1) ((λx.x+1) x)) 4 (λx.x+1) ((λx.x+1) 4) (λx.x+1) (4+1)
80 Example to do at home Reduce the following ((λf.(λx. f (f x))) (λx.x+1)) 4 (λx. (λx.x+1) ((λx.x+1) x)) 4 (λx.x+1) ((λx.x+1) 4) (λx.x+1) (4+1) 4+1+1
81 Example to do at home Reduce the following ((λf.(λx. f (f x))) (λx.x+1)) 4 (λx. (λx.x+1) ((λx.x+1) x)) 4 (λx.x+1) ((λx.x+1) 4) (λx.x+1) (4+1)
82 Example to do at home
83 Example to do at home Reduce the following (λf.(λx. f (f x))) (λy.y+x)
84 Example to do at home Reduce the following (λf.(λx. f (f x))) (λy.y+x) λx. (λy.y+x) ((λy.y+x) x)
85 Example to do at home Reduce the following (λf.(λx. f (f x))) (λy.y+x) λx. (λy.y+x) ((λy.y+x) x) λx. (λy.y+x) (x+x)
86 Example to do at home Reduce the following (λf.(λx. f (f x))) (λy.y+x) λx. (λy.y+x) ((λy.y+x) x) λx. (λy.y+x) (x+x) λx. (x+x+x)
87 Example to do at home Reduce the following (λf.(λx. f (f x))) (λy.y+x) λx. (λy.y+x) ((λy.y+x) x) λx. (λy.y+x) (x+x) λx. (x+x+x)???? that s not a function that adds x to argument two times
88 Another way to see the problem Syntactic sugar: let x = e 1 in e 2 (λx.e 2 ) e 1 Let syntax makes this easy to see: let x = a + 5 in let x = a + 5 in let a = 7 in let a = 7 in x + a (a + 5) + a Very obviously wrong! But, guess what: your C macro preprocessor does this!
89 Another way to see the problem Syntactic sugar: let x = e 1 in e 2 (λx.e 2 ) e 1 Let syntax makes this easy to see: let x = a + 5 in let x = a + 5 in let a = 7 in let a = 7 in x + a (a + 5) + a Very obviously wrong! But, guess what: your C macro preprocessor does this!
90 Fixing the problem How can we fix this? 1.Rename variables! let x = a+5 in let x = a+5 in let x = a+5 in let a = 7 in let a123 = 7 in let a123 = 7 in x + a x + a123 (a+5) + a123 2.Do the dumb substitution!
91 Fixing the problem How can we fix this? 1.Rename variables! let x = a+5 in let x = a+5 in let x = a+5 in let a = 7 in let a123 = 7 in let a123 = 7 in x + a x + a123 (a+5) + a123 2.Do the dumb substitution!
92 Fixing the problem How can we fix this? 1.Rename variables! let x = a+5 in let x = a+5 in let x = a+5 in let a = 7 in let a123 = 7 in let a123 = 7 in x + a x + a123 (a+5) + a123 2.Do the dumb substitution!
93 Why is this the way to go? Def: variable x is bound in λx.(x+y) Can we always rename bound variables? A: yes, B:no Yes! Bound variables are just placeholders Above: x is not special, we could have used z We say they are equivalent: λx.(x+y) =α λz.(z+y) Renaming amounts to converting bound variable names to avoid capture: e.g., λx.(x+y) to λz.(z+y)
94 Can we rename everything? Can we rename y in λx.(x+y)? (A: yes, B: no) No! We don t know what y may be, so we must keep it as is! Intuition: Can change the name of your function argument variables but not of variables from the outer scope E.g., x. P(x, y) or i {1,,10} x i + y
95 Can we rename everything? Can we rename y in λx.(x+y)? (A: yes, B: no) No! We don t know what y may be, so we must keep it as is! Intuition: Can change the name of your function argument variables but not of variables from the outer scope E.g., x. P(x, y) or i {1,,10} x i + y
96 Can we rename everything? Can we rename y in λx.(x+y)? (A: yes, B: no) No! We don t know what y may be, so we must keep it as is! Intuition: Can change the name of your function argument variables but not of variables from the outer scope E.g., x. P(x, y) or i {1,,10} x i + y
97 Week 2 Syntax of λ calculus Semantics of λ calculus Informal substitution Free and bound variables Formal substitution Evaluation order
98 Let s think about this more formally
99 Def: free variables If a variable is not bound by a λ, we say that it is free e.g., y is free in λx.(x+y) is x free? No! A: yes, We B: say no x is bound in λx.(x+y) We can compute the free variables of any term: FV(x) = {x} FV(λx.e) = FV(e) \ {x} think: build out! FV(e 1 e 2 ) = FV(e 1 ) FV(e 2 )
100 Def: free variables If a variable is not bound by a λ, we say that it is free e.g., y is free in λx.(x+y) is x free? No! A: yes, We B: say no x is bound in λx.(x+y) We can compute the free variables of any term: FV(x) = {x} FV(λx.e) = FV(e) \ {x} think: build out! FV(e 1 e 2 ) = FV(e 1 ) FV(e 2 )
101 Def: free variables If a variable is not bound by a λ, we say that it is free e.g., y is free in λx.(x+y) is x free? No! A: yes, We B: say no x is bound in λx.(x+y) We can compute the free variables of any term: FV(x) = {x} FV(λx.e) = FV(e) \ {x} think: build out! FV(e 1 e 2 ) = FV(e 1 ) FV(e 2 )
102 Def: free variables If a variable is not bound by a λ, we say that it is free e.g., y is free in λx.(x+y) is x free? No! We say x is bound in λx.(x+y) We can compute the free variables of any term: FV(x) = {x} FV(λx.e) = FV(e) \ {x} think: build out! FV(e 1 e 2 ) = FV(e 1 ) FV(e 2 )
103 Def: Capture-avoiding substitution Capture-avoiding substitution: x[x:=e] = e y[x:=e] = y if y x (e1 e 2 )[x := e] = (e 1 [x := e]) (e 2 [ x:= e]) (λx.e 1 )[x := e] = λx.e 1 (λy.e1 )[x := e 2 ] = λy.e 1 [x := e 2 ] if y x and y FV(e 2 ) Why the if? If y is free in e2 this would capture it!
104 Def: Capture-avoiding substitution Capture-avoiding substitution: x[x:=e] = e y[x:=e] = y if y x (e1 e 2 )[x := e] = (e 1 [x := e]) (e 2 [ x:= e]) (λx.e 1 )[x := e] = λx.e 1 (λy.e1 )[x := e 2 ] = λy.e 1 [x := e 2 ] if y x and y FV(e 2 ) Why the if? If y is free in e2 this would capture it!
105 Def: Capture-avoiding substitution Capture-avoiding substitution: x[x:=e] = e y[x:=e] = y if y x (e1 e 2 )[x := e] = (e 1 [x := e]) (e 2 [ x:= e]) (λx.e 1 )[x := e] = λx.e 1 (λy.e1 )[x := e 2 ] = λy.e 1 [x := e 2 ] if y x and y FV(e 2 ) Why the if? If y is free in e2 this would capture it!
106 Def: Capture-avoiding substitution Capture-avoiding substitution: x[x:=e] = e y[x:=e] = y if y x (e1 e 2 )[x := e] = (e 1 [x := e]) (e 2 [ x:= e]) (λx.e 1 )[x := e] = λx.e 1 (λy.e1 )[x := e 2 ] = λy.e 1 [x := e 2 ] if y x and y FV(e 2 ) Why the if? If y is free in e2 this would capture it!
107 Def: Capture-avoiding substitution Capture-avoiding substitution: x[x:=e] = e y[x:=e] = y if y x (e1 e 2 )[x := e] = (e 1 [x := e]) (e 2 [ x:= e]) (λx.e 1 )[x := e] = λx.e 1 (λy.e1 )[x := e 2 ] = λy.e 1 [x := e 2 ] if y x and y FV(e 2 ) Why the if? If y is free in e2 this would capture it!
108 Def: Capture-avoiding substitution Capture-avoiding substitution: x[x:=e] = e y[x:=e] = y if y x (e1 e 2 )[x := e] = (e 1 [x := e]) (e 2 [ x:= e]) (λx.e 1 )[x := e] = λx.e 1 (λy.e1 )[x := e 2 ] = λy.e 1 [x := e 2 ] if y x and y FV(e 2 ) Why the if? If y is free in e2 this would capture it!
109 Def: Capture-avoiding substitution Capture-avoiding substitution: x[x:=e] = e y[x:=e] = y if y x (e1 e 2 )[x := e] = (e 1 [x := e]) (e 2 [ x:= e]) (λx.e 1 )[x := e] = λx.e 1 (λy.e1 )[x := e 2 ] = λy.e 1 [x := e 2 ] if y x and y FV(e 2 ) Why the if? If y is free in e2 this would capture it!
110 Def: Capture-avoiding substitution Capture-avoiding substitution: x[x:=e] = e y[x:=e] = y if y x (e1 e 2 )[x := e] = (e 1 [x := e]) (e 2 [ x:= e]) (λx.e 1 )[x := e] = λx.e 1 (λy.e1 )[x := e 2 ] = λy.e 1 [x := e 2 ] if y x and y FV(e 2 ) Why the if? If y is free in e2 this would capture it!
111 Lambda calculus: equational theory α-renaming or α-conversion λx.e = λy.e[x:=y] where y FV(e) β-reduction (λx.e1 ) e 2 = e 1 [x:=e 2 ] η-conversion λx.(e x) = e where x FV(e) We define our relation using these equations!
112 Back to our example
113 Back to our example What we should have done: (λx. (λa. x + a) 7) (a + 5)
114 Back to our example What we should have done: (λx. (λa. x + a) 7) (a + 5) =α (λx. (λb. x + b) 7) (a + 5)
115 Back to our example What we should have done: (λx. (λa. x + a) 7) (a + 5) =α (λx. (λb. x + b) 7) (a + 5) =β (λb. (a + 5) + b) 7
116 Back to our example What we should have done: (λx. (λa. x + a) 7) (a + 5) =α (λx. (λb. x + b) 7) (a + 5) =β (λb. (a + 5) + b) 7 =β (a + 5) + 7
117 Back to our example What we should have done: (λx. (λa. x + a) 7) (a + 5) =α (λx. (λb. x + b) 7) (a + 5) =β (λb. (a + 5) + b) 7 =β (a + 5) + 7 =β a + 12
118 The to do at home example
119 The to do at home example What you should have done: (λf.(λx. f (f x)) (λy.y+x)
120 The to do at home example What you should have done: (λf.(λx. f (f x)) (λy.y+x) =α (λf.(λz. f (f z)) (λy.y+x)
121 The to do at home example What you should have done: (λf.(λx. f (f x)) (λy.y+x) =α (λf.(λz. f (f z)) (λy.y+x) =β λz. (λy.y+x) ((λy.y+x) z)
122 The to do at home example What you should have done: (λf.(λx. f (f x)) (λy.y+x) =α (λf.(λz. f (f z)) (λy.y+x) =β λz. (λy.y+x) ((λy.y+x) z) =β λz. (λy.y+x) (z+x)
123 The to do at home example What you should have done: (λf.(λx. f (f x)) (λy.y+x) =α (λf.(λz. f (f z)) (λy.y+x) =β λz. (λy.y+x) ((λy.y+x) z) =β λz. (λy.y+x) (z+x) =β λz. z+x+x
124 Week 2 Syntax of λ calculus Semantics of λ calculus Informal substitution Free and bound variables Formal substitution Evaluation order
125 Evaluation order What should we reduce first in (λx.x) ((λy.y) z)? A: The inner term: (λy.y) z B: The outer term: (λx.x) ((λy.y) z) Does it matter? No! They both reduce to z!
126 Evaluation order What should we reduce first in (λx.x) ((λy.y) z)? A: The inner term: (λy.y) z B: The outer term: (λx.x) ((λy.y) z) Does it matter? No! They both reduce to z!
127 Church-Rosser Theorem: If you reduce to a normal form, it doesn t matter what order you do the reductions. This is known as confluence. Does this mean that reduction order doesn t matter for any program? A: yes B: no
128 Church-Rosser Theorem: If you reduce to a normal form, it doesn t matter what order you do the reductions. This is known as confluence. Does this mean that reduction order doesn t matter for any program? A: yes B: no
129 Does evaluation order really not matter?
130 Does evaluation order really not matter? Consider a curious term called Ω Ω (λx.x x) (λx.x x)
131 Does evaluation order really not matter? Consider a curious term called Ω Ω (λx.x x) (λx.x x) =β (x x)[ x:= (λx.x x)]
132 Does evaluation order really not matter? Consider a curious term called Ω Ω (λx.x x) (λx.x x) =β (x x)[ x:= (λx.x x)] =β (λx.x x) (λx.x x)
133 Does evaluation order really not matter? Consider a curious term called Ω Ω (λx.x x) (λx.x x) =β (x x)[ x:= (λx.x x)] =β (λx.x x) (λx.x x) = Ω Deja vu!
134 Ω Ω Ω Ω Ω Ω (Ω has no normal form)
135 Does evaluation order really not matter? Consider a function that ignores its argument: (λx.y) What happens when we call it on Ω? (λx.y) Ω
136 Does evaluation order really not matter? Consider a function that ignores its argument: (λx.y) What happens when we call it on Ω? y (λx.y) Ω
137 Does evaluation order really not matter? Consider a function that ignores its argument: (λx.y) What happens when we call it on Ω? (λx.y) Ω y (λx.y) Ω
138 Does evaluation order really not matter? Consider a function that ignores its argument: (λx.y) What happens when we call it on Ω? (λx.y) Ω y (λx.y) Ω y
139 Does evaluation order really not matter? Consider a function that ignores its argument: (λx.y) What happens when we call it on Ω? (λx.y) Ω y (λx.y) Ω y (λx.y) Ω
140 Does evaluation order really not matter? Consider a function that ignores its argument: (λx.y) What happens when we call it on Ω? y y y y (λx.y) Ω (λx.y) Ω (λx.y) Ω (λx.y) Ω
141 Does evaluation order really not matter? Nope! Evaluation order does matter!
142 Call-by-value Reduce function, then reduce args, then apply e 1 e 2 (λx.e 1 ) e 2 (λx.e 1 ) n e 1 [x:=n] JavaScript s evaluation strategy is call-by-value (ish) What does this program do? (x => 33) ((x => x(x)) (x => x(x))) RangeError: Maximum call stack size exceeded
143 Call-by-value Reduce function, then reduce args, then apply e 1 e 2 (λx.e 1 ) e 2 (λx.e 1 ) n e 1 [x:=n] JavaScript s evaluation strategy is call-by-value (ish) What does this program do? (x => 33) ((x => x(x)) (x => x(x))) RangeError: Maximum call stack size exceeded
144 Call-by-value Reduce function, then reduce args, then apply e 1 e 2 (λx.e 1 ) e 2 (λx.e 1 ) n e 1 [x:=n] JavaScript s evaluation strategy is call-by-value (ish) What does this program do? (x => 33) ((x => x(x)) (x => x(x))) RangeError: Maximum call stack size exceeded
145 Call-by-value Reduce function, then reduce args, then apply e 1 e 2 (λx.e 1 ) e 2 (λx.e 1 ) n e 1 [x:=n] JavaScript s evaluation strategy is call-by-value (ish) What does this program do? (x => 33) ((x => x(x)) (x => x(x))) RangeError: Maximum call stack size exceeded
146 Call-by-value Reduce function, then reduce args, then apply e 1 e 2 (λx.e 1 ) e 2 (λx.e 1 ) n e 1 [x:=n] JavaScript s evaluation strategy is call-by-value (ish) What does this program do? (x => 33) ((x => x(x)) (x => x(x))) RangeError: Maximum call stack size exceeded
147 Call-by-name Reduce function then apply e 1 e 2 (λx.e 1 ) e 2 e 1 [x:=e 2 ] Haskell s evaluation strategy is call-by-name It only does what is absolutely necessary! Actually it s call-by-need = call-by-name + sharing
148 Call-by-name Reduce function then apply e 1 e 2 (λx.e 1 ) e 2 e 1 [x:=e 2 ] Haskell s evaluation strategy is call-by-name It only does what is absolutely necessary! Actually it s call-by-need = call-by-name + sharing
149 Call-by-name Reduce function then apply e 1 e 2 (λx.e 1 ) e 2 e 1 [x:=e 2 ] Haskell s evaluation strategy is call-by-name It only does what is absolutely necessary! Actually it s call-by-need = call-by-name + sharing
150 Call-by-name Reduce function then apply e 1 e 2 (λx.e 1 ) e 2 e 1 [x:=e 2 ] Haskell s evaluation strategy is call-by-name It only does what is absolutely necessary! Actually it s call-by-need = call-by-name + sharing
151 Summary A term may have many redexes (subterms can reduce) Evaluation strategy says which redex to evaluate Evaluation not guaranteed to find normal form Call-by-value: evaluate function & args before β reduce Call-by-name: evaluate function, then β-reduce
152 Today Syntax of λ calculus Semantics of λ calculus Free and bound variables Substitution Evaluation order
153 Takeaway λ-calculus is a forma system Simplest reasonable programming language -Ramsey Binders show up everywhere! Know your capture-avoiding substitution!
154 Bonus!
155 Recursive functions in λ-calculus Suppose you want to implement factorial in λ-calculus λn. if n 1 then 1 else n * (fac (n-1)) Is this right? A: yes, B: no Why not? fac is not a thing!
156 Recursive functions in λ-calculus Suppose you want to implement factorial in λ-calculus λn. if n 1 then 1 else n * (fac (n-1)) Is this right? A: yes, B: no Why not? fac is not a thing!
157 Recursive functions in λ-calculus Suppose you want to implement factorial in λ-calculus λn. if n 1 then 1 else n * (fac (n-1)) Is this right? A: yes, B: no Why not? fac is not a thing!
158 The Y combinator X
159 combinator Like Ω, there is a special term Y in lambda calculus Y λf. (λx. f (x x)) (λx. f (x x)) Why is this interesting? It reduces as follows Y f =β f (Y f) =β f (f (Y f)) =β f ( f (Y f) )
160 combinator Like Ω, there is a special term Y in lambda calculus Y λf. (λx. f (x x)) (λx. f (x x)) Why is this interesting? It reduces as follows Y f =β f (Y f) =β f (f (Y f)) Def: Fixed-point of a function f is a value x such that f x = x =β f ( f (Y f) )
161 How can we use this? Let s go back to factorial example. f λfac.λn. if n 1 then 1 else n * (fac (n-1)) factorial Y f =β f (Y f) = f factorial = (λfac.λn. if n 1 then 1 else n * (fac (n-1))) factorial =β λn. if n 1 then 1 else n * (factorial (n-1))
162 How can we use this? Apply as usual: factorial 2 =β (f (Y f)) 2 =β (λn. if n 1 then 1 else n * (factorial (n-1))) 2 =β if 2 1 then 1 else 2 * (factorial (2-1)) =β if 2 1 then 1 else 2 * (factorial 1) =β 2 * (factorial 1)
163 How can we use this? Apply as usual: =β 2 * (factorial 1) =β 2 * ((f factorial) 1) =β 2 * ((λn. if n 1 then 1 else n * (factorial (n-1))) 1) =β 2 * (if 1 1 then 1 else 1 * (factorial (1-1))) =β 2 * (if 1 1 then 1 else 1 * (factorial 0)) =β 2 * 1 =β 2
Fundamentals and lambda calculus. Deian Stefan (adopted from my & Edward Yang s CSE242 slides)
Fundamentals and lambda calculus Deian Stefan (adopted from my & Edward Yang s CSE242 slides) Logistics Assignments: Programming assignment 1 is out Homework 1 will be released tomorrow night Podcasting:
More informationIntroduction to Lambda Calculus. Lecture 7 CS /08/09
Introduction to Lambda Calculus Lecture 7 CS 565 02/08/09 Lambda Calculus So far, we ve explored some simple but non-interesting languages language of arithmetic expressions IMP (arithmetic + while loops)
More informationCMSC 330: Organization of Programming Languages. Lambda Calculus
CMSC 330: Organization of Programming Languages Lambda Calculus 1 Turing Completeness Turing machines are the most powerful description of computation possible They define the Turing-computable functions
More informationIntroduction to Lambda Calculus. Lecture 5 CS 565 1/24/08
Introduction to Lambda Calculus Lecture 5 CS 565 1/24/08 Lambda Calculus So far, we ve explored some simple but non-interesting languages language of arithmetic expressions IMP (arithmetic + while loops)
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 Summer 2017 1 100 years ago Albert Einstein proposed special theory of relativity in 1905 In the paper On the Electrodynamics of
More informationCMSC 330: Organization of Programming Languages. Lambda Calculus
CMSC 330: Organization of Programming Languages Lambda Calculus 1 100 years ago Albert Einstein proposed special theory of relativity in 1905 In the paper On the Electrodynamics of Moving Bodies 2 Prioritätsstreit,
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 1 Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Use currying
More informationLambda Calculus. Lecture 4 CS /26/10
Lambda Calculus Lecture 4 CS 565 10/26/10 Pure (Untyped) Lambda Calculus The only value is a function Variables denote functions Functions always take functions as arguments Functions always return functions
More informationProgramming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.
CMSC 330: Organization of Programming Languages Lambda Calculus Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Ø Use currying or tuples
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 1 Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Ø Use currying
More informationIntroduction to the Lambda Calculus
Introduction to the Lambda Calculus Overview: What is Computability? Church s Thesis The Lambda Calculus Scope and lexical address The Church-Rosser Property Recursion References: Daniel P. Friedman et
More information1 Scope, Bound and Free Occurrences, Closed Terms
CS 6110 S18 Lecture 2 The λ-calculus Last time we introduced the λ-calculus, a mathematical system for studying the interaction of functional abstraction and functional application. We discussed the syntax
More informationType Systems Winter Semester 2006
Type Systems Winter Semester 2006 Week 4 November 8 November 15, 2006 - version 1.1 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial
More informationPure Lambda Calculus. Lecture 17
Pure Lambda Calculus Lecture 17 Lambda Calculus Lambda Calculus (λ-calculus) is a functional notation introduced by Alonzo Church in the early 1930s to formalize the notion of computability. Pure λ-calculus
More information5. Introduction to the Lambda Calculus. Oscar Nierstrasz
5. Introduction to the Lambda Calculus Oscar Nierstrasz Roadmap > What is Computability? Church s Thesis > Lambda Calculus operational semantics > The Church-Rosser Property > Modelling basic programming
More informationChapter 5: The Untyped Lambda Calculus
Chapter 5: The Untyped Lambda Calculus What is lambda calculus for? Basics: syntax and operational semantics Programming in the Lambda Calculus Formalities (formal definitions) What is Lambda calculus
More informationCOMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland
COMP 1130 Lambda Calculus based on slides by Jeff Foster, U Maryland Motivation Commonly-used programming languages are large and complex ANSI C99 standard: 538 pages ANSI C++ standard: 714 pages Java
More informationLecture 5: The Untyped λ-calculus
Lecture 5: The Untyped λ-calculus Syntax and basic examples Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Static Analysis Pratikakis (CSD) Untyped λ-calculus I CS49040,
More information11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations
Outline FP Foundations, Scheme In Text: Chapter 15 Mathematical foundations Functional programming λ-calculus LISP Scheme 2 Imperative Languages We have been discussing imperative languages C/C++, Java,
More informationINF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS. Instructors: Crista Lopes Copyright Instructors.
INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS Instructors: Crista Lopes Copyright Instructors. History Formal mathematical system Simplest programming language Intended for studying functions, recursion
More informationLambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators
Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer Polytechnic Institute February 11, 2010 C. Varela 1
More informationCIS 500 Software Foundations Fall September 25
CIS 500 Software Foundations Fall 2006 September 25 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial programming language, then the
More informationIntroductory Example
CSc 520 Principles of Programming Languages 21: Lambda Calculus Introduction Christian Collberg Department of Computer Science University of Arizona collberg@cs.arizona.edu Copyright c 2005 Christian Collberg
More informationLambda Calculus. Lambda Calculus
Lambda Calculus Formalism to describe semantics of operations in functional PLs Variables are free or bound Function definition vs function abstraction Substitution rules for evaluating functions Normal
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Tuesday, February 19, 2013 The lambda calculus (or λ-calculus) was introduced by Alonzo Church and Stephen Cole Kleene in
More informationRecursive Definitions, Fixed Points and the Combinator
Recursive Definitions, Fixed Points and the Combinator Dr. Greg Lavender Department of Computer Sciences University of Texas at Austin Recursive Self-Reference Recursive self-reference occurs regularly
More informationCITS3211 FUNCTIONAL PROGRAMMING
CITS3211 FUNCTIONAL PROGRAMMING 9. The λ calculus Summary: This lecture introduces the λ calculus. The λ calculus is the theoretical model underlying the semantics and implementation of functional programming
More informationConcepts of programming languages
Concepts of programming languages Lecture 5 Wouter Swierstra 1 Announcements Submit your project proposal to me by email on Friday; The presentation schedule in now online Exercise session after the lecture.
More informationOne of a number of approaches to a mathematical challenge at the time (1930): Constructibility
λ Calculus Church s λ Calculus: Brief History One of a number of approaches to a mathematical challenge at the time (1930): Constructibility (What does it mean for an object, e.g. a natural number, to
More informationThe Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements
CIS 500 Software Foundations Fall 2004 27 September IS 500, 27 September 1 The Lambda Calculus IS 500, 27 September 3 Announcements Homework 1 is graded. Pick it up from Cheryl Hickey (Levine 502). We
More informationThe Untyped Lambda Calculus
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationCS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus
CS 4110 Programming Languages & Logics Lecture 17 Programming in the λ-calculus 10 October 2014 Announcements 2 Foster Office Hours 11-12 Enjoy fall break! Review: Church Booleans 3 We can encode TRUE,
More information9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete
Dr A Sahu Dept of Computer Science & Engineering IIT Guwahati Why study? Lambda calculus Syntax Evaluation Relationship to programming languages Church Rosser theorem Completeness of Lambda Calculus: Turing
More informationCSE 505: Concepts of Programming Languages
CSE 505: Concepts of Programming Languages Dan Grossman Fall 2003 Lecture 6 Lambda Calculus Dan Grossman CSE505 Fall 2003, Lecture 6 1 Where we are Done: Modeling mutation and local control-flow Proving
More informationLast class. CS Principles of Programming Languages. Introduction. Outline
Last class CS6848 - Principles of Programming Languages Principles of Programming Languages V. Krishna Nandivada IIT Madras Interpreters A Environment B Cells C Closures D Recursive environments E Interpreting
More informationlambda calculus History 11/28/13 Jianguo Lu A formal system designed to inves:gate func:on defini:on, func:on applica:on, and recursion.
lambda calculus Jianguo Lu 1 History Lambda calculus A formal system designed to inves:gate func:on defini:on, func:on applica:on, and recursion. Introduced by Alonzo Church in 1930s. The calculus can
More informationFormal Semantics. Aspects to formalize. Lambda calculus. Approach
Formal Semantics Aspects to formalize Why formalize? some language features are tricky, e.g. generalizable type variables, nested functions some features have subtle interactions, e.g. polymorphism and
More informationLambda Calculus. Adrian Groza. Department of Computer Science Technical University of Cluj-Napoca
Lambda Calculus Adrian Groza Department of Computer Science Technical University of Cluj-Napoca Outline 1 λ-calculus 2 Operational Semantics Syntax Conversions Normal Form 3 Lambda Calculus as a Functional
More informationActivity. CSCI 334: Principles of Programming Languages. Lecture 4: Fundamentals II. What is computable? What is computable?
Activity CSCI 334: Principles of Programming Languages Lecture 4: Fundamentals II Write a function firsts that, when given a list of cons cells, returns a list of the left element of each cons. ( (a. b)
More informationComputer Science 203 Programming Languages Fall Lecture 10. Bindings, Procedures, Functions, Functional Programming, and the Lambda Calculus
1 Computer Science 203 Programming Languages Fall 2004 Lecture 10 Bindings, Procedures, Functions, Functional Programming, and the Lambda Calculus Plan Informal discussion of procedures and bindings Introduction
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC 330 Spring 2017 1 Review A lambda calculus expression is defined as e ::= x variable λx.e abstraction (fun def) e e application
More informationAdvanced Topics in Programming Languages Lecture 3 - Models of Computation
Advanced Topics in Programming Languages Lecture 3 - Models of Computation Andrey Leshenko Maxim Borin 16/11/2017 1 Lambda Calculus At the beginning of the last century, several attempts were made to theoretically
More informationFoundations. Yu Zhang. Acknowledgement: modified from Stanford CS242
Spring 2013 Foundations Yu Zhang Acknowledgement: modified from Stanford CS242 https://courseware.stanford.edu/pg/courses/317431/ Course web site: http://staff.ustc.edu.cn/~yuzhang/fpl Reading Concepts
More informationdynamically typed dynamically scoped
Reference Dynamically Typed Programming Languages Part 1: The Untyped λ-calculus Jim Royer CIS 352 April 19, 2018 Practical Foundations for Programming Languages, 2/e, Part VI: Dynamic Types, by Robert
More informationλ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods
Course 2D1453, 2006-07 Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Alonzo Church, 1903-1995 Church-Turing thesis First
More informationFunctions as data. Massimo Merro. 9 November Massimo Merro The Lambda language 1 / 21
Functions as data Massimo Merro 9 November 2011 Massimo Merro The Lambda language 1 / 21 The core of sequential programming languages In the mid 1960s, Peter Landin observed that a complex programming
More informationConstraint-based Analysis. Harry Xu CS 253/INF 212 Spring 2013
Constraint-based Analysis Harry Xu CS 253/INF 212 Spring 2013 Acknowledgements Many slides in this file were taken from Prof. Crista Lope s slides on functional programming as well as slides provided by
More informationLambda Calculus. Variables and Functions. cs3723 1
Lambda Calculus Variables and Functions cs3723 1 Lambda Calculus Mathematical system for functions Computation with functions Captures essence of variable binding Function parameters and substitution Can
More informationLambda Calculus and Extensions as Foundation of Functional Programming
Lambda Calculus and Extensions as Foundation of Functional Programming David Sabel and Manfred Schmidt-Schauß 29. September 2015 Lehrerbildungsforum Informatik Last update: 30. September 2015 Overview
More informationThe Untyped Lambda Calculus
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationCMSC330. Objects, Functional Programming, and lambda calculus
CMSC330 Objects, Functional Programming, and lambda calculus 1 OOP vs. FP Object-oriented programming (OOP) Computation as interactions between objects Objects encapsulate mutable data (state) Accessed
More informationVU Semantik von Programmiersprachen
VU Semantik von Programmiersprachen Agata Ciabattoni Institute für Computersprachen, Theory and Logic group (agata@logic.at) (A gentle) Introduction to λ calculus p. 1 Why shoud I studyλcalculus? p. 2
More informationLambda Calculus-2. Church Rosser Property
Lambda Calculus-2 Church-Rosser theorem Supports referential transparency of function application Says if it exists, normal form of a term is UNIQUE 1 Church Rosser Property Fundamental result of λ-calculus:
More informationCSCI.4430/6969 Programming Languages Lecture Notes
CSCI.4430/6969 Programming Languages Lecture Notes August 28, 2006 1 Brief History of Programming Languages Ada Augusta, the Countess of Lovelace, the daughter of the poet Lord Byron, is attributed as
More informationLambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,
Lambda Calculus Type Systems, Lectures 3 Jevgeni Kabanov Tartu, 13.02.2006 PREVIOUSLY ON TYPE SYSTEMS Arithmetical expressions and Booleans Evaluation semantics Normal forms & Values Getting stuck Safety
More informationElixir, functional programming and the Lambda calculus.
Elixir, functional programming and the Lambda calculus. Programming II - Elixir Version Johan Montelius Spring Term 2018 Introduction In this tutorial you re going to explore lambda calculus and how it
More informationFrom the λ-calculus to Functional Programming Drew McDermott Posted
From the λ-calculus to Functional Programming Drew McDermott drew.mcdermott@yale.edu 2015-09-28 Posted 2015-10-24 The λ-calculus was intended from its inception as a model of computation. It was used by
More informationDenotational Semantics; Lambda Calculus Basics Section and Practice Problems Week 4: Tue Feb 13 Fri Feb 16, 2018
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Denotational Semantics; Lambda Calculus Basics Week 4: Tue Feb 13 Fri Feb 16, 2018 1 Denotational Semantics (a) Give the
More informationIntroduction to the λ-calculus
Announcements Prelim #2 issues: o Problem 5 grading guide out shortly o Problem 3 (hashing) issues Will be on final! Friday RDZ office hours are 11-12 not 1:30-2:30 1 Introduction to the λ-calculus Today
More informationUntyped Lambda Calculus
Advanced Topics in Programming Languages Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and Programming
More informationFormal Systems and their Applications
Formal Systems and their Applications Dave Clarke (Dave.Clarke@cs.kuleuven.be) Acknowledgment: these slides are based in part on slides from Benjamin Pierce and Frank Piessens 1 Course Overview Introduction
More informationPure (Untyped) λ-calculus. Andrey Kruglyak, 2010
Pure (Untyped) λ-calculus Andrey Kruglyak, 2010 1 Pure (untyped) λ-calculus An example of a simple formal language Invented by Alonzo Church (1936) Used as a core language (a calculus capturing the essential
More informationThe Untyped Lambda Calculus
Resources: The slides of this lecture were derived from x = 1 [Järvi], with permission of the original author, by copy & let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationCS 242. Fundamentals. Reading: See last slide
CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language
More informationUntyped Lambda Calculus
Concepts in Programming Languages Recitation 5: Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and
More informationFunctional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur
Functional Programming and λ Calculus Amey Karkare Dept of CSE, IIT Kanpur 0 Software Development Challenges Growing size and complexity of modern computer programs Complicated architectures Massively
More informationCMPUT 325 : Lambda Calculus Basics. Lambda Calculus. Dr. B. Price and Dr. R. Greiner. 13th October 2004
CMPUT 325 : Lambda Calculus Basics Dr. B. Price and Dr. R. Greiner 13th October 2004 Dr. B. Price and Dr. R. Greiner CMPUT 325 : Lambda Calculus Basics 1 Lambda Calculus Lambda calculus serves as a formal
More informationMore Lambda Calculus and Intro to Type Systems
More Lambda Calculus and Intro to Type Systems Plan Heavy Class Participation Thus, wake up! Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems Overview Static, Dyamic
More informationLexicografie computationala Feb., 2012
Lexicografie computationala Feb., 2012 Anca Dinu University of Bucharest Introduction When we construct meaning representations systematically, we integrate information from two different sources: 1. The
More informationCS 6110 S14 Lecture 1 Introduction 24 January 2014
CS 6110 S14 Lecture 1 Introduction 24 January 2014 1 Introduction What is a program? Is it just something that tells the computer what to do? Yes, but there is much more to it than that. The basic expressions
More informationCS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 7 Lambda Calculus Dan Grossman Spring 2011 Where we are Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now:
More informationCOMP80 Lambda Calculus Programming Languages Slides Courtesy of Prof. Sam Guyer Tufts University Computer Science History Big ideas Examples:
COMP80 Programming Languages Slides Courtesy of Prof. Sam Guyer Lambda Calculus Formal system with three parts Notation for functions Proof system for equations Calculation rules called reduction Idea:
More informationFunctional Programming
Functional Programming COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Original version by Prof. Simon Parsons Functional vs. Imperative Imperative programming
More informationChapter 5: The Untyped Lambda Calculus
Chapter 5: The Untyped Lambda Calculus What is lambda calculus for? Basics: syntax and operational semantics Programming in the Lambda Calculus Formalities (formal definitions) What is Lambda calculus
More informationThe Untyped Lambda Calculus
CS738: Advanced Compiler Optimizations The Untyped Lambda Calculus Amey Karkare karkare@cse.iitk.ac.in http://www.cse.iitk.ac.in/~karkare/cs738 Department of CSE, IIT Kanpur Reference Book Types and Programming
More informationLambda Calculus and Type Inference
Lambda Calculus and Type Inference Björn Lisper Dept. of Computer Science and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ August 17, 2007 Lambda Calculus and Type
More informationPart I. Historical Origins
Introduction to the λ-calculus Part I CS 209 - Functional Programming Dr. Greg Lavender Department of Computer Science Stanford University Historical Origins Foundations of Mathematics (1879-1936) Paradoxes
More informationWhereweare. CS-XXX: Graduate Programming Languages. Lecture 7 Lambda Calculus. Adding data structures. Data + Code. What about functions
Whereweare CS-XXX: Graduate Programming Languages Lecture 7 Lambda Calculus Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now: Didn t IMP leave
More informationLecture Notes on Data Representation
Lecture Notes on Data Representation 15-814: Types and Programming Languages Frank Pfenning Lecture 9 Tuesday, October 2, 2018 1 Introduction In this lecture we ll see our type system in action. In particular
More informationCSC173 Lambda Calculus Lambda Calculus Evaluation (10 min) Evaluate this expression (β-reduce with normal-order evaluation):
CSC173 Lambda Calculus 014 Please write your name on the bluebook. You may use two sides of handwritten notes. There are 90 possible points and 75 is a perfect score. Stay cool and please write neatly.
More informationA Quick Overview. CAS 701 Class Presentation 18 November Department of Computing & Software McMaster University. Church s Lambda Calculus
A Quick Overview CAS 701 Class Presentation 18 November 2008 Lambda Department of Computing & Software McMaster University 1.1 Outline 1 2 3 Lambda 4 5 6 7 Type Problem Lambda 1.2 Lambda calculus is a
More informationIntroduction to the Lambda Calculus. Chris Lomont
Introduction to the Lambda Calculus Chris Lomont 2010 2011 2012 www.lomont.org Leibniz (1646-1716) Create a universal language in which all possible problems can be stated Find a decision method to solve
More informationImplementing functional languages with abstract machines
Implementing functional languages with abstract machines Hayo Thielecke University of Birmingham http://www.cs.bham.ac.uk/~hxt December 9, 2015 Contents Introduction Lambda calculus and programming languages
More informationCS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e
More informationRecursion. Lecture 6: More Lambda Calculus Programming. Fixed Points. Recursion
Recursion Lecture 6: More Lambda Calculus Programming CSC 131! Fall, 2014!! Kim Bruce Recursive definitions are handy! - fact = λn. cond (iszero n) 1 (Mult n (fact (Pred n)))! - Not a legal definition
More informationFall 2013 Midterm Exam 10/22/13. This is a closed-book, closed-notes exam. Problem Points Score. Various definitions are provided in the exam.
Programming Languages Fall 2013 Midterm Exam 10/22/13 Time Limit: 100 Minutes Name (Print): Graduate Center I.D. This is a closed-book, closed-notes exam. Various definitions are provided in the exam.
More informationHomework. Lecture 7: Parsers & Lambda Calculus. Rewrite Grammar. Problems
Homework Lecture 7: Parsers & Lambda Calculus CSC 131 Spring, 2019 Kim Bruce First line: - module Hmwk3 where - Next line should be name as comment - Name of program file should be Hmwk3.hs Problems How
More informationCS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012
CS-XXX: Graduate Programming Languages Lecture 9 Simply Typed Lambda Calculus Dan Grossman 2012 Types Major new topic worthy of several lectures: Type systems Continue to use (CBV) Lambda Caluclus as our
More informationResources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in...
Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationThe Lambda Calculus. notes by Don Blaheta. October 12, A little bondage is always a good thing. sk
The Lambda Calculus notes by Don Blaheta October 2, 2000 A little bondage is always a good thing. sk We ve seen that Scheme is, as languages go, pretty small. There are just a few keywords, and most of
More informationMore Lambda Calculus and Intro to Type Systems
#1 More Lambda Calculus and Intro to Type Systems #2 Plan Heavy Class Participation Thus, wake up! (not actually kidding) Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems
More informationOverview. A normal-order language. Strictness. Recursion. Infinite data structures. Direct denotational semantics. Transition semantics
Overview A normal-order language Strictness Recursion Infinite data structures Direct denotational semantics Transition semantics Lazy (call-by-need) evaluation and its semantics A Normal-Order Language
More informationProgramming Languages (CSCI 4430/6430) History, Syntax, Semantics, Essentials, Paradigms
Programming Languages (CSCI 4430/6430) History, Syntax, Semantics, Essentials, Paradigms Carlos Varela Rennselaer Polytechnic Institute August 30, 2016 C. Varela 1 The first programmer ever Ada Augusta,
More informationProgramming Languages
Programming Languages Lambda Calculus and Scheme CSCI-GA.2110-003 Fall 2011 λ-calculus invented by Alonzo Church in 1932 as a model of computation basis for functional languages (e.g., Lisp, Scheme, ML,
More informationCS522 - Programming Language Semantics
1 CS522 - Programming Language Semantics Lambda Calculus and Combinatory Logic Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 In this part of the course we discuss
More informationFunctional Programming
Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used
More informationReview. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals
Review CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics e ::= λx. e x ee c v ::= λx. e c (λx. e) v e[v/x] e 1 e 2 e 1 e 2 τ ::= int τ τ Γ ::= Γ,x : τ e 2 e 2 ve 2 ve 2 e[e /x]:
More informationCITS3211 FUNCTIONAL PROGRAMMING. 14. Graph reduction
CITS3211 FUNCTIONAL PROGRAMMING 14. Graph reduction Summary: This lecture discusses graph reduction, which is the basis of the most common compilation technique for lazy functional languages. CITS3211
More informationBasic Foundations of Isabelle/HOL
Basic Foundations of Isabelle/HOL Peter Wullinger May 16th 2007 1 / 29 1 Introduction into Isabelle s HOL Why Type Theory Basic Type Syntax 2 More HOL Typed λ Calculus HOL Rules 3 Example proof 2 / 29
More information> module Lambda where > import Data.List -- I need some standard list functions
Lecture 9 Lambda Calculus We now look at lambda calculus, the theoretical stuff that underlies functional programming. It was introduced by Alonzo Church to formalise two key concepts when dealing with
More information