CVO103: Programming Languages. Lecture 2 Inductive Definitions (2)

Similar documents
COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

Introduction to Kleene Algebras

Theory of Computation

COSE312: Compilers. Lecture 2 Lexical Analysis (1)

Strong Induction (Second Principle) Example: There are two piles of cards, players take turn: each turn: one player removes any number of cards from

Chapter 3: Propositional Calculus: Deductive Systems. September 19, 2008

(Ordinary) mathematical induction is a way to prove things about natural numbers. We can write it as a rule: φ(0) x. φ(x) φ(succ(x)) x.

Finite Automata Theory and Formal Languages TMV027/DIT321 LP Recap: Logic, Sets, Relations, Functions

CSE 20. Final Review. CSE 20: Final Review

What Is a Language? Grammars, Languages, and Machines. Strings: the Building Blocks of Languages

What is this course about?

Comp487/587 - Boolean Formulas

Introduction to Automata

University of Ottawa CSI 2101 Midterm Test Instructor: Lucia Moura. February 9, :30 pm Duration: 1:50 hs. Closed book, no calculators

Discrete Mathematics. Spring 2017

First-Order Logic. 1 Syntax. Domain of Discourse. FO Vocabulary. Terms

AAA616: Program Analysis. Lecture 3 Denotational Semantics

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

E.g. The set RE of regular expressions is given by the following rules:

Department of Computer Science University at Albany, State University of New York Solutions to Sample Discrete Mathematics Examination II (Fall 2007)

Propositional Logic and Semantics

CISC 876: Kolmogorov Complexity

Propositional Calculus - Hilbert system H Moonzoo Kim CS Division of EECS Dept. KAIST

1. Propositional Calculus

Lecture 2: Axiomatic semantics

COSE312: Compilers. Lecture 17 Intermediate Representation (2)

Suppose h maps number and variables to ɛ, and opening parenthesis to 0 and closing parenthesis

Context-Free Grammars (and Languages) Lecture 7

Chapter 11: Automated Proof Systems (1)

Logic. Definition [1] A logic is a formal language that comes with rules for deducing the truth of one proposition from the truth of another.

Handout: Proof of the completeness theorem

Predicate Logic. Xinyu Feng 09/26/2011. University of Science and Technology of China (USTC)

Predicate Logic. x. x + 0 = x. Predicate logic over integer expressions: a language of logical assertions, for example. Why discuss predicate logic?

Models of Computation,

02 Propositional Logic

Structural Induction

9/5/17. Fermat s last theorem. CS 220: Discrete Structures and their Applications. Proofs sections in zybooks. Proofs.

Equational Logic. Chapter Syntax Terms and Term Algebras

MODERN APPLIED ALGEBRA

Logic. Introduction to Artificial Intelligence CS/ECE 348 Lecture 11 September 27, 2001

Ch 3.2: Direct proofs

A brief introduction to Logic. (slides from

An Introduction to Modal Logic III

3 Propositional Logic

MATH 215 Final. M4. For all a, b in Z, a b = b a.

CSE 1400 Applied Discrete Mathematics Definitions

a. (6.25 points) where we let b. (6.25 points) c. (6.25 points) d. (6.25 points) B 3 =(x)[ H(x) F (x)], and (11)

2. Associative Law: A binary operator * on a set S is said to be associated whenever (A*B)*C = A*(B*C) for all A,B,C S.

Computational Theory

Complete Induction and the Well- Ordering Principle

Applied Logic. Lecture 1 - Propositional logic. Marcin Szczuka. Institute of Informatics, The University of Warsaw

On the Complexity of the Reflected Logic of Proofs

1 Alphabets and Languages

Introduction to Metalogic

Knowledge representation DATA INFORMATION KNOWLEDGE WISDOM. Figure Relation ship between data, information knowledge and wisdom.

Notes on Inductive Sets and Induction

Lecture 4: Proposition, Connectives and Truth Tables

We want to show P (n) is true for all integers

AAA616: Program Analysis. Lecture 7 The Octagon Abstract Domain

Propositional Logic: Models and Proofs

Learning Goals of CS245 Logic and Computation

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Example. Lemma. Proof Sketch. 1 let A be a formula that expresses that node t is reachable from s

Intelligent Agents. Formal Characteristics of Planning. Ute Schmid. Cognitive Systems, Applied Computer Science, Bamberg University

Chapter 0 Introduction. Fourth Academic Year/ Elective Course Electrical Engineering Department College of Engineering University of Salahaddin

Propositional Logics and their Algebraic Equivalents

d(ν) = max{n N : ν dmn p n } N. p d(ν) (ν) = ρ.

Logic. proof and truth syntacs and semantics. Peter Antal

A NEW FOUNDATION OF A COMPLETE BOOLEAN EQUATIONAL LOGIC

CSC236H Lecture 2. Ilir Dema. September 19, 2018

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

Chapter 5: Context-Free Languages

ICS141: Discrete Mathematics for Computer Science I

Your quiz in recitation on Tuesday will cover 3.1: Arguments and inference. Your also have an online quiz, covering 3.1, due by 11:59 p.m., Tuesday.

Informal Statement Calculus

Fall, 2017 CIS 262. Automata, Computability and Complexity Jean Gallier Solutions of the Practice Final Exam

03 Review of First-Order Logic

Inductive Definitions with Inference Rules 1 / 27

Properties of Context-Free Languages

CSE 311: Foundations of Computing I Autumn 2014 Practice Final: Section X. Closed book, closed notes, no cell phones, no calculators.

Modal Logic. UIT2206: The Importance of Being Formal. Martin Henz. March 19, 2014

Logic: The Big Picture

Theory of Computer Science

Introduction to Theoretical Computer Science

n n P} is a bounded subset Proof. Let A be a nonempty subset of Z, bounded above. Define the set

Context-free Grammars and Languages

A Logic Primer. Stavros Tripakis University of California, Berkeley. Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 A Logic Primer 1 / 35

Problem 1: Suppose A, B, C and D are finite sets such that A B = C D and C = D. Prove or disprove: A = B.

Hoare Examples & Proof Theory. COS 441 Slides 11

Packet #1: Logic & Proofs. Applied Discrete Mathematics

Information Theory and Statistics Lecture 2: Source coding

Automata theory. An algorithmic approach. Lecture Notes. Javier Esparza

Lecture 4: More on Regexps, Non-Regular Languages

Lecture 1: Logical Foundations

Chapter 11: Automated Proof Systems

Roy L. Crole. Operational Semantics Abstract Machines and Correctness. University of Leicester, UK

Logic for Computer Science - Week 2 The Syntax of Propositional Logic

Lecture 3: Semantics of Propositional Logic

Lecture Notes on Inductive Definitions

Transcription:

CVO103: Programming Languages Lecture 2 Inductive Definitions (2) Hakjoo Oh 2018 Spring Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 1 / 20

Contents More examples of inductive definitions natural numbers, strings, booleans lists, binary trees arithmetic expressions, propositional logic Structural induction three example proofs Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 2 / 20

Natural Numbers The set of natural numbers: N = {0, 1, 2, 3,...} is inductively defined: Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 3 / 20

Natural Numbers The set of natural numbers: N = {0, 1, 2, 3,...} is inductively defined: 0 n n + 1 Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 3 / 20

Natural Numbers The set of natural numbers: N = {0, 1, 2, 3,...} is inductively defined: 0 n n + 1 The inference rules can be expressed by a grammar: n 0 n + 1 Interpretation: 0 is a natural number. If n is a natural number then so is n + 1. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 3 / 20

Strings The set of strings over alphabet {a,..., z}, e.g., ɛ, a, b,..., z, aa, ab,..., az, ba,... az, aaa,..., zzz, and so on. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 4 / 20

Strings The set of strings over alphabet {a,..., z}, e.g., ɛ, a, b,..., z, aa, ab,..., az, ba,... az, aaa,..., zzz, and so on. Inference rules: ɛ α aα α bα α zα Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 4 / 20

Strings The set of strings over alphabet {a,..., z}, e.g., ɛ, a, b,..., z, aa, ab,..., az, ba,... az, aaa,..., zzz, and so on. Inference rules: ɛ α aα α bα α zα or simply, ɛ α xα x {a,..., z} Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 4 / 20

Strings The set of strings over alphabet {a,..., z}, e.g., ɛ, a, b,..., z, aa, ab,..., az, ba,... az, aaa,..., zzz, and so on. Inference rules: ɛ α aα α bα α zα or simply, In grammar: ɛ α xα x {a,..., z} α ɛ xα (x {a,..., z}) Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 4 / 20

Boolean Values The set of boolean values: B = {true, false}. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 5 / 20

Boolean Values The set of boolean values: B = {true, false}. If a set is finite, just enumerate all of its elements by axioms: true false In grammar: b true false Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 5 / 20

Lists Examples of lists of integers: 1 nil 2 14 nil 3 3 14 nil 4 7 3 14 nil Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 6 / 20

Lists Examples of lists of integers: 1 nil 2 14 nil 3 3 14 nil 4 7 3 14 nil Inference rules: nil l n l n Z In grammar: l nil n l (n Z) Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 6 / 20

Lists A proof that 7 3 14 nil is a list of integers: nil 14 nil 14 Z 3 14 nil 3 Z 7 3 14 nil 7 Z The proof tree is also called derivation tree or deduction tree. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 7 / 20

Binary Trees Examples of binary trees: 1 leaf 2 (2, leaf, leaf) 3 (1, (2, leaf, leaf), leaf) 4 (1, (2, leaf, leaf), (3, (4, leaf, leaf), leaf)) Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 8 / 20

Binary Trees Examples of binary trees: 1 leaf 2 (2, leaf, leaf) 3 (1, (2, leaf, leaf), leaf) 4 (1, (2, leaf, leaf), (3, (4, leaf, leaf), leaf)) Inference rules: In grammar: leaf t 1 t 2 (n, t 1, t 2 ) n Z t leaf (n, t, t) (n Z) Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 8 / 20

Binary Trees A proof that is a binary tree: (1, (2, leaf, leaf), (3, (4, leaf, leaf), leaf)) leaf (2, leaf, leaf) 2 Z leaf (4, leaf, leaf) 4 Z (3, (4, leaf, leaf), leaf) 3 Z 1 Z (1, (2, leaf, leaf), (3, (4, leaf, leaf), leaf)) Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 9 / 20

Binary Trees: a different version Binary tree examples: 1, (1, nil), (1, 2), ((1, 2), nil), ((1, 2), (3, 4)). Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 10 / 20

Binary Trees: a different version Binary tree examples: 1, (1, nil), (1, 2), ((1, 2), nil), ((1, 2), (3, 4)). Inference rules: In grammar: n n Z t (t, nil) t (nil, t) t n (n Z) (t, nil) (nil, t) (t, t) A proof that ((1, 2), (3, nil)) is a binary tree: 1 2 3 (1, 2) (3, nil) ((1, 2), (3, nil)) t 1 t 2 (t 1, t 2 ) Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 10 / 20

Expressions Expression examples: 2, 2, 1 + 2, 1 + (2 ( 3)), etc. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 11 / 20

Expressions Expression examples: 2, 2, 1 + 2, 1 + (2 ( 3)), etc. Inference rules: n n Z e e 1 e 2 e 1 e 2 e e 1 + e 2 e 1 e 2 In grammar: Example: e n (n Z) e e + e e e (e) 3 3 2 ( 3) 2 ( 3) 1 (2 ( 3)) 1 + (2 ( 3)) e (e) Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 11 / 20

Propositional Logic Examples: T, F T F T F (T F ) (T F ) T (F T ) Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 12 / 20

Propositional Logic Syntax: Semantics ( [f ]): f T F f f f f f f f [T ] = true [F ] = false [ f ] = not [f ] [f 1 f 2 ] = [f 1 ] andalso [f 2 ] [f 1 f 2 ] = [f 1 ] orelse [f 2 ] [f 1 f 2 ] = [f 1 ] implies [f 2 ] Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 13 / 20

Propositional Logic [(T (T F )) F ] = [[T (T F ) ] implies [F ] = ( [T ] andalso [T F ]) implies false = (true andalso ( [T ] orelse [F ])) implies false = (true andalso (true orelse false)) implies false = false Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 14 / 20

Structural Induction A technique for proving properties about inductively defined sets. To prove that a proposition P (s) is true for all structures s, prove the following: 1 (Base case) P is true on simple structures (those without substructures) 2 (Inductive case) If P is true on the substructures of s, then it is true on s itself. The assumption is called induction hypothesis (I.H.). Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 15 / 20

Example 1 Let S be the set defined by the following inference rules: x y 3 x + y Prove that for all x S, x is divisible by 3. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 16 / 20

Example 1 Let S be the set defined by the following inference rules: 3 x y x + y Prove that for all x S, x is divisible by 3. Proof. By structural induction. (Base case) The base case is when x is 3. Obviously, x is divisible by 3. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 16 / 20

Example 1 Let S be the set defined by the following inference rules: 3 x y x + y Prove that for all x S, x is divisible by 3. Proof. By structural induction. (Base case) The base case is when x is 3. Obviously, x is divisible by 3. (Inductive case) The induction hypothesis (I.H.) is Let x = 3k 1 and y = 3k 2. x is divisible by 3, y is divisible by 3. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 16 / 20

Example 1 Let S be the set defined by the following inference rules: 3 x y x + y Prove that for all x S, x is divisible by 3. Proof. By structural induction. (Base case) The base case is when x is 3. Obviously, x is divisible by 3. (Inductive case) The induction hypothesis (I.H.) is x is divisible by 3, y is divisible by 3. Let x = 3k 1 and y = 3k 2. Using I.H., we derive x + y is divisible by 3 as follows: x + y = 3k 1 + 3k 2 by I.H. = 3(k 1 + k 2 ) Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 16 / 20

Example 2 Let S be the set defined by the following inference rules: () x (x) x y xy Prove that every element of the set has the same number of ( s and ) s. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 17 / 20

Example 2 Let S be the set defined by the following inference rules: () x (x) x y xy Prove that every element of the set has the same number of ( s and ) s. Proof Restate the claim formally: If x S then l(x) = r(x) where l(x) and r(x) denote the number of ( s and ) s, respectively. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 17 / 20

Example 2 Let S be the set defined by the following inference rules: () x (x) x xy y Prove that every element of the set has the same number of ( s and ) s. Proof Restate the claim formally: If x S then l(x) = r(x) where l(x) and r(x) denote the number of ( s and ) s, respectively. We prove it by structural induction: (Base case): The base case is when x = (). Then l(x) = 1 = r(x). Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 17 / 20

Example 2 (Inductive case): There are two inductive cases: x x y (x) xy Induction hypotheses (I.H.): l(x) = r(x), l(y) = r(y). Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 18 / 20

Example 2 (Inductive case): There are two inductive cases: x x y (x) xy Induction hypotheses (I.H.): l(x) = r(x), l(y) = r(y). The first case. We prove l((x)) = r((x)): l((x)) = l(x) + 1 by definition of l((x)) = r(x) + 1 by I.H. = r((x)) by definition of r((x)) Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 18 / 20

Example 2 (Inductive case): There are two inductive cases: x x y (x) xy Induction hypotheses (I.H.): l(x) = r(x), l(y) = r(y). The first case. We prove l((x)) = r((x)): l((x)) = l(x) + 1 by definition of l((x)) = r(x) + 1 by I.H. = r((x)) by definition of r((x)) The second case. We prove l(xy) = r(xy): l(xy) = l(x) + l(y) by definition of l(xy) = r(x) + r(y) by I.H. = r(xy) by definition of r(xy) Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 18 / 20

Example 3 Let T be the set of binary trees: t 1 t 2 leaf (n, t 1, t 2 ) n Z Prove that for all such trees, the number of leaves is always one more than the number of internal nodes. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 19 / 20

Example 3 Let T be the set of binary trees: t 1 t 2 leaf (n, t 1, t 2 ) n Z Prove that for all such trees, the number of leaves is always one more than the number of internal nodes. Proof. Restate the claim more formally: If t T then l(t) = i(t) + 1 where l(t) and i(t) denote the number of leaves and internal nodes, respectively. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 19 / 20

Example 3 Let T be the set of binary trees: t 1 t 2 leaf (n, t 1, t 2 ) n Z Prove that for all such trees, the number of leaves is always one more than the number of internal nodes. Proof. Restate the claim more formally: If t T then l(t) = i(t) + 1 where l(t) and i(t) denote the number of leaves and internal nodes, respectively. We prove it by structural induction: (Base case): The base case is when t = leaf, where l(t) = 1 and i(t) = 0. Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 19 / 20

Example 3 Let T be the set of binary trees: t 1 t 2 leaf (n, t 1, t 2 ) n Z Prove that for all such trees, the number of leaves is always one more than the number of internal nodes. Proof. Restate the claim more formally: If t T then l(t) = i(t) + 1 where l(t) and i(t) denote the number of leaves and internal nodes, respectively. We prove it by structural induction: (Base case): The base case is when t = leaf, where l(t) = 1 and i(t) = 0. (Inductive case): The induction hypothesis: l(t 1 ) = i(t 1 ) + 1, l(t 2 ) = i(t 2 ) + 1 Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 19 / 20

Example 3 Let T be the set of binary trees: t 1 t 2 leaf (n, t 1, t 2 ) n Z Prove that for all such trees, the number of leaves is always one more than the number of internal nodes. Proof. Restate the claim more formally: If t T then l(t) = i(t) + 1 where l(t) and i(t) denote the number of leaves and internal nodes, respectively. We prove it by structural induction: (Base case): The base case is when t = leaf, where l(t) = 1 and i(t) = 0. (Inductive case): The induction hypothesis: l(t 1 ) = i(t 1 ) + 1, l(t 2 ) = i(t 2 ) + 1 Using I.H., we prove l((n, t 1, t 2 )) = i((n, t 1, t 2 )) + 1: l((n, t 1, t 2 )) = l(t 1 ) + l(t 2 ) = i(t 1 ) + 1 + i(t 2 ) + 1 by induction hypothesis = i(n, t 1, t 2 ) + 1 Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 19 / 20

Summary Computer science is full of inductive definitions. primitive values: booleans, characters, integers, strings, etc compound values: lists, trees, graphs, etc language syntax and semantics Structural induction a general technique for reasoning about inductively defined sets Hakjoo Oh CVO103 2018 Spring, Lecture 2 March 13, 2018 20 / 20