Chapter 1: Inductive Sets of Data Recall definition of list  '() is a list.  If l is a list and a is any object, then (cons a l ) is a list More generally:

Slides:



Advertisements
Similar presentations
Product & Quotient Rules Higher Order Derivatives
Advertisements

22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Recursive Definitions and Structural Induction
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
331 Final Fall Details 3:30-5:30 Monday, December 16 ITE 229 (this room!) Comprehensive with more emphasis on material since the midterm Look at.
ICE1341 Programming Languages Spring 2005 Lecture #5 Lecture #5 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Chapter 4 Normal Forms for CFGs Chomsky Normal Form n Defn A CFG G = (V, , P, S) is in chomsky normal form if each rule in G has one of.
CS5371 Theory of Computation
ISBN Chapter 3 More Syntax –BNF –Derivations –Practice.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 4 Updated by Marek Perkowski.
Fall 2007CS 2251 Miscellaneous Topics Deque Recursion and Grammars.
A basis for computer theory and A means of specifying languages
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
Chapter 3: Formal Translation Models
SchemeCOP Introduction to Scheme. SchemeCOP Scheme Meta-language for coding interpreters –“ clean ” semantics Scheme = LISP + ALGOL –simple.
Plt /8/ Inductive Sets of Data Programming Language Essentials 2nd edition Chapter 1.2 Recursively Specified Programs.
331 Final Spring Details 6-8 pm next Monday Comprehensive with more emphasis on material since the midterm Study example finals and midterm exams.
Section 5.3. Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction.
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
Context-Free Grammars Normal Forms Chapter 11. Normal Forms A normal form F for a set C of data objects is a form, i.e., a set of syntactically valid.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
CS 152: Programming Language Paradigms February 17 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
CS 331, Principles of Programming Languages Chapter 2.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
Chapter 2: Data Abstraction 2.2 An Abstraction for Inductive Data Types Recall inductive BNF definition of binary trees: ::= | ( ) To write programs using.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
1 L= { w c w R : w  {a, b}* } is accepted by the PDA below. Use a construction like the one for intersection for regular languages to design a PDA that.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Recursive Definitions of Properties of Data Structures  Recursive.
331 Final Fall Details 3:30-5:30 Friday December 17 th LH4 Comprehensive with more emphasis on material since the midterm Study example finals and.
D Goforth COSC Translating High Level Languages.
18-October-2002cse Symbols © 2002 University of Washington1 Symbols CSE 413, Autumn 2002 Programming Languages
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
Context Free Grammars CFGs –Add recursion to regular expressions Nested constructions –Notation expression  identifier | number | - expression | ( expression.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
CS 331, Principles of Programming Languages Chapter 2.
Recursive Data Structures and Grammars Themes –Recursive Description of Data Structures –Grammars and Parsing –Recursive Definitions of Properties of Data.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Recursive Definitions of Properties of Data Structures  Recursive.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
Classifications LanguageGrammarAutomaton Regular, right- linear Right-linear, left-linear DFA, NFA Context-free PDA Context- sensitive LBA Recursively.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
Transparency No. P2C5-1 Formal Language and Automata Theory Part II Chapter 5 The Pumping Lemma and Closure properties for Context-free Languages.
Discrete Structures ICS252 Chapter 5 Lecture 2. Languages and Grammars prepared By sabiha begum.
Cs466(Prasad)L6Proof1 Induction Proofs Equivalent Statements in Proofs.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Context-Free Grammars Normal Forms Chapter 11. Normal Forms A normal form F for a set C of data objects is a form, i.e., a set of syntactically valid.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Autumn 2012 CSE
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
Spring 16 CSCI 4430, A Milanova/BG Ryder 1 Announcements HW5 due March 28 Homework Server link is up I will have office hours, Fri or Mon, check Announcements.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
1 Proving Properties of Recursive Functions and Data Structures CS 270 Math Foundations of CS Jeremy Johnson.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Chapter 1: Inductive Sets of Data
Chapter 2: Data Abstraction 2
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Chapter 1 Review: BNF Grammar for lists:
2.2.2 Abstract Syntax Recall BNF definition of l-calculus expressions:
Relationship to Left- and Rightmost Derivations
2.2.2 Abstract Syntax Recall BNF definition of l-calculus expressions:
Presentation transcript:

Chapter 1: Inductive Sets of Data Recall definition of list  '() is a list.  If l is a list and a is any object, then (cons a l ) is a list More generally:  Define a simplest element  Define remaining elements by induction

Inductive Sets of Data Can define (natural) numbers this way:  0 is a number  If i is a number, then (s i) is a number E.g., 3 is (s (s (s 0))) – “Church numerals” Russell & Whitehead (1925): try to build all of arithmethic like this (fails because of Gödel's Incompleteness theorem)

Backus-Nauer Form (BNF) Simplifies description of inductive data types ::= 0, 1, 2, … ::= ( ) ::= (. ) [where (a. b) is like (cons a b)] Consists of Terminals: 0 ). ( Non-terminals: Productions: ::= ()

BNF Can only describe context-free structures; e.g., ::= (. ) is inadequate for binary search trees: which require a context-sensitive description

BNF: Notation Disjunction (this or that): | ::= | Kleene Star (zero or more): {}* ::= ({ }*) Kleene Plus (one or more): {}+ ::= ({ }+

Induction What can we do with these (BNF) inductive definitions? 1) Prove theorems about data structures. E.g. given ::= | ( ) prove that a bintree always has an even # of parens

Induction Basis: A tree derived from ::= has zero parens. Zero is even. Inductive step: Assume that the relation holds for two bin trees b 1, with 2m ≥ 0 parens, and b 2, with 2n ≥ 0 parens. Using the rule ::= ( ) we make a new bin tree b 3 = (b 1 b 2 ) from these, which has length 2m+2n+2 = 2[m+n+1], which is even. There is no other way to make a bin tree. Hence the relation holds for any bin tree with zero or more parens, Q.E.D.

Induction ; count parentheses in a binary tree (define count-bt-parens (lambda (bt) (if (atom? bt) 0; base case (+ (count-bt-parens (car bt)) (count-bt-parens (cadr bt)) 2)))); inductive step What can we do with these (BNF) inductive definitions? 2) Write programs that manipulate inductive data

Program mirrors BNF description mirrors proof. Important Points (if (atom? bt) 0 Basis: A tree derived from ::= has zero parens. ::=

Program mirrors BNF description mirrors proof: ::= ( ) (+ (count-bt-parens (car bt)) (count-bt-parens (cadr bt)) 2)))) Inductive step: Assume that the relation holds for two bin trees b 1, with 2m ≥ 0 parens, and b 2, with 2n ≥ 0 parens....

Follow the Grammar! When defining a program based on structural induction, the structure of the program should be patterned after the structure of the data.

Program assumes we're passing it a binary tree: dynamic type-checking (vs. Java, static / compile-time type check) Easier to make type errors: > (count-bt-parens '(dont taze me bro)) car: expects argument of type ; given (dont taze me bro) Another Point

Another Example ; remove first occurrence of symbol from ; list of symbols (define remove-first (lambda(s los) (if (null? los) '() (if (eqv? (car los) s) (cdr los) (cons (car los) (remove-first s (cdr los))))))) ::= ( ) | (. )