1 / 18

CS 320 Principles of Programming Languages Highlights of Lambda Calculus

CS 320 Principles of Programming Languages Highlights of Lambda Calculus. Dr. Herbert G. Mayer, PSU Status 10/14/2017. Syllabus. History Lambda Calculus Contributors Lambda Calculus vs. Turing Machine Lambda Calculus for NOT Y-Combinator References. History of Lambda Calculus.

mledford
Download Presentation

CS 320 Principles of Programming Languages Highlights of Lambda Calculus

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 320Principles of Programming Languages Highlights of Lambda Calculus Dr. Herbert G. Mayer, PSU Status 10/14/2017

  2. Syllabus • History • Lambda Calculus • Contributors • Lambda Calculus vs. Turing Machine • Lambda Calculus for NOT • Y-Combinator • References

  3. History of Lambda Calculus • Lambda Calculus, defined by Alonzo Church, MIT mathematician, early 20th century • Church was Alan Turing’s supervisor during Turing’s PhD studies! • Turing developed, and is famously known for his idea of the state-based Turing machine; aside from being famous for cracking German Enigma code during WW2 • D • Alonzo Church, 1903 - 1995

  4. History of Lambda Calculus • Church developed a functional notion of computation not requiring internal state; known as Lambda Calculus, AKA λC • λC is not a state machine; by contracts: Turing machine is a state machine! • Both models of computation are complete. I.e. any computable mathematical function can be solved with Turing machine or Lambda Calculus • Thus both computational models are equivalent • Equivalence is known as the Church-Turing thesis; AKA Computability thesis; AKA Church-Turing conjecture

  5. Lambda Calculus • Detail on YouTube, and copied from: https://www.youtube.com/watch?v=eis11j_iGMs • Key for λC: requires no internal state, hence no prior knowledge or data being carried to current computation (or to current machine) • Pure and simple mathematical function. Different from Turing machine that does have internal state • Notation for Lambda Calculus λC borrowed and derived by Church from Russell and Whitehead (Principia Mathematica, 3 volumes, 1901-1903)

  6. Contributors • Original notation by Russell: Ŷ which Church changed to ⌃y, then became λy. But var x used in math instead y, hence common notation: λx • The dot . (period) after λx. ends definition of any one input; there may be multiple inputs • The last dot . introduces output calculation to the right-hand side of that last dot . • Or we say: the dot separates all inputs from the output definition to the right of the last dot • Alan Turing, 1912 - 1954

  7. Lambda Calculus • Example: λx.x+1 • Meaning: Increment Function • Is a lambda function definition with input x. The function has no name; essential for Lambda Calculus • Single input here is x; there happens to be just one input • Period separates inputs from one another and from single output. Output here is x+1 • Function could have more inputs than one, in which case multiple λ symbols are used before last dot • Conventionally, the repetition of λ for multiple inputs can be skipped; simpler notation!

  8. Lambda Calculus • Another example: Add Function λx.λy.x+y • Meaning: We have a lambda function definition with 2 inputs. First input is x, second input is y • Period separates inputs from one another and from the output. Output is x+y • Also sometimes denoted without λ repeated, e.g.: λxy.x+y • Sample use of increment function, with real input. Note: function in parens, followed by actual input 5 (λx.x+1) 5

  9. Lambda Calculus’ 3 Basic Operations • Computed output will be 6, no surprise! • Clearly visible when input 5 substitutes x in this instance, resulting in output that is: 5+1 = 6 • More generally: Lambda Calculus λC has 3 basic operations, and nothing else; so λC is amazingly simple. Here all 3 basic operations of λC: • Values, such as variables, e.g. x in above examples • Methodof building functions, such as λxy.x+y • Way of applying functions, similar to sample shown above: (λx.x+3) 7 to yield 10 • λC is computationally complete. Any computable function can be expressed as a lambda function

  10. Lambda Calculus’ 3 Basic Operations • More conventional denotation of λ-expression, in one of three possible forms, as shown by prof. Li: M  x | λx.M | M1 M2 • x variable: x is name of a variable • λx.M abstraction: single-argument function • M1 M2 application: apply function M1 to argument M2 • Some examples: • λx.x • (λx.x)y • λf.λg.λx.f(gx)

  11. Lambda Calculus vs. Turing Machine • Also Turing machines are computationally complete • Thus the 2 methods are equivalent, a fact known as “The Church-Turing Thesis”. (hint: Midterm candidate question) • It may not look pretty or be brief, to let λC program perform a real computation, but it is doable • Haskell and ML can be viewed as very convenient (and way more readable, shorter) methods of writing Lambda Calculus programs • Both of these programming languages are based on λC

  12. Lambda Calculus • Except for its 3 basic operations, λC proper has no further “features”: no special data types, no recursion, no logical values • To use such features anyway, one has to program them, i.e. encode them in a simple “subprogram”, but within the λC framework! • May look wordy or clumsy, but any computable function can be encoded with these 3 simple basic operations! • Extreme point: λC doesn't even have logical constants, such as True or False! Must be encoded via simple programs; but CAN be done!

  13. Lambda Calculus for True False • Key observation for True, False: Used to make decisions. In one case we select the first value, in the other case we pick the second value! • For example, in (anonymous) function with 2 inputs x and y, for True just chose first input parameter as the output! (Yes, one could reverse it as well!) For False we pick the second input parameter λx.λy.x To be defined in λC as True • For False, one selects the second input parameter λx.λy.y Then this is defined in λC as False

  14. Lambda Calculus for NOT • Sounds arbitrary. But can be used as follows: • Can define logical Not operator. Given a Boolean operand b which could be True or False, use it in a λC function, and then apply it to True, or apply it to False. Then: λb.b False True Is Boolean Not in λC • Why or How? Apply Not to True, and see what we get out; should get False. Ditto with applying Not to False; should get True out. For True, shown below in blue ( λb.b False True ) True

  15. Lambda Calculus for NOT • Substitute input value True to input parameter b, and then expand the function; yielding True False True • Now substituting (actually “expanding”) the truth values by their function. Thus: True False True becomes: (λx.λy.x ) False True • That function picks the first input, and this results in (λx.λy.x ) False True; so the result becomes False! QED • Analogously, applying Not to False, results in True

  16. Y-Combinator, Haskell B. Curry • Famous λC expression, known as Y-combinator, developed by Haskell Curry • Y-combinator, also known as Y-operator, is key to do recursion in λC. See below: Y = λf.( λx.f( x x )) (λx.f( x x )) • Haskell was PhD student of David Hilbert • Haskell Brooks Curry, 1900-1982

  17. Y-Combinator, David Hilbert • To date we have no automated tools to prove correctness of general Java or C++ programs; λ code easier to prove • Even if we had, we’d still lack automated tools that ensure safeness from security leaks. Viruses can still be inserted into object code of provably correct SW D • As far as correctness proofs and safety guarantees are concerned, we are at the early development stages in the Computer Sciences

  18. References • T.b.d.

More Related