CS 320 Principles of Programming Languages

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Advertisements

INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS Instructors: Crista Lopes Copyright © Instructors.
Foundations of Programming Languages: Introduction to Lambda Calculus
CS5371 Theory of Computation Lecture 11: Computability Theory II (TM Variants, Church-Turing Thesis)
The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
Comp 205: Comparative Programming Languages Semantics of Functional Languages Term- and Graph-Rewriting The λ-calculus Lecture notes, exercises, etc.,
Propositional Calculus Math Foundations of Computer Science.
Functional Programing Referencing material from Programming Language Pragmatics – Third Edition – by Michael L. Scott Andy Balaam (Youtube.com/user/ajbalaam)
Introduction to Proofs
Class 37: Computability in Theory and Practice cs1120 Fall 2011 David Evans 21 November 2011 cs1120 Fall 2011 David Evans 21 November 2011.
CMSC 330: Organization of Programming Languages Lambda Calculus Introduction λ.
Algorithms and their Applications CS2004 ( ) Dr Stephen Swift 1.2 Introduction to Algorithms.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and.
1 ML fun x -> e e 1 e 2 0, 1, 2,..., +, -,... true, false, if e then e else e patterns datatypes exceptions structures functors let f x = e variables These.
Chapter Fifteen: Functional Programming Languages Lesson 12.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
June 11, 2002© Howard Huang1 Boolean algebra Last time we talked about Boolean functions, Boolean expressions, and truth tables. Today we’ll learn.
Extra slides for Chapter 3: Propositional Calculus & Normal Forms Based on Prof. Lila Kari’s slides For CS2209A, 2009 By Dr. Charles Ling;
-Calculus Kangwon National University 임현승 Programming Languages These slides are based on the slides by Prof. Sungwoo Park at POSTECH.
CMSC 330: Organization of Programming Languages Lambda Calculus and Types.
ECE 171 Digital Circuits Chapter 4 Boolean Algebra Herbert G. Mayer, PSU Status 2/1/2016 Copied with Permission from prof. Mark PSU ECE.
Alonzo Church: Mathematician. Philosopher. Computer Scientist? Who is Alonzo Church? Alonzo Church was a man who was very important to the computer science.
Spring, 2011 –– Computational Thinking – Dennis Kafura – CS 2984 Lambda Calculus Introduction.
Section 1.7. Section Summary Mathematical Proofs Forms of Theorems Direct Proofs Indirect Proofs Proof of the Contrapositive Proof by Contradiction.
CS 154 Formal Languages and Computability April 5 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
MA/CSSE 474 Theory of Computation Universal Turing Machine Church-Turing Thesis Delayed due dates for HWs See updated schedule page. No class meeting.
Functional Programming
GCSE/IGCSE-FM Functions
Control Structures I Chapter 3
CS 3723 Programming Languages
CS 550 Programming Languages Jeremy Johnson
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
Lambda Calculus CSE 340 – Principles of Programming Languages
Gödel's Legacy: The Limits Of Logics
Propositional Calculus: Boolean Functions and Expressions
2.7 Combining Functions.
Relational Algebra Chapter 4 1.
Computability and Complexity
Lecture 3 of Computer Science II
CS 611: Lecture 9 More Lambda Calculus: Recursion, Scope, and Substitution September 17, 1999 Cornell University Computer Science Department Andrew Myers.
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
CS154, Lecture 7: Turing Machines.
Boolean algebra Last time we talked about Boolean functions, Boolean expressions, and truth tables. Today we’ll learn how to how use Boolean algebra to.
Propositional Calculus: Boolean Functions and Expressions
Lecture 2 Propositional Logic
Propositional Calculus: Boolean Algebra and Simplification
Transformations of Functions
Complexity 6-1 The Class P Complexity Andrei Bulatov.
CSCE 411 Design and Analysis of Algorithms
The Foundations: Logic and Proofs
Relational Algebra Chapter 4 1.
Theory of Computation Turing Machines.
Functions Computers take inputs and produce outputs, just like functions in math! Mathematical functions can be expressed in two ways: We can represent.
This Lecture Substitution model
Copied with Permission from prof. Mark PSU ECE
Amazing fact #3: -calculus is Turing-complete!
Announcements Quiz 6 HW7 due Tuesday, October 30
CSCE 314: Programming Languages Dr. Dylan Shell
Class 33: Making Recursion M.C. Escher, Ascending and Descending
From now on: Combinatorial Circuits:
L Calculus.
ECE 352 Digital System Fundamentals
This Lecture Substitution model
Proofs are Programs: 19th Century Logic and 21st Century Computing
CSE S. Tanimoto Lambda Calculus
This Lecture Substitution model
Amazing fact #3: -calculus is Turing-complete!
CO Games Development 2 Week 21 Turing Machines & Computability
Presentation transcript:

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 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

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

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)

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

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!

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

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 Method of 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

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)

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

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!

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

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

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

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

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

References T.b.d.