Lecture 5: Formation Tree and Parsing Algorithm

Similar documents
Warmup Problem. Translate the following sentence from English into Propositional Logic. I want to eat ice cream even though I am on a diet.

Propositional Logic Formal Syntax and Semantics. Computability and Logic

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

2.2 Set Operations. Introduction DEFINITION 1. EXAMPLE 1 The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is, EXAMPLE 2

AXIOMS FOR THE INTEGERS

15 212: Principles of Programming. Some Notes on Grammars and Parsing

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Syntax Analysis Check syntax and construct abstract syntax tree

4&5 Binary Operations and Relations. The Integers. (part I)

Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

Lexical and Syntax Analysis

Propositional Logic. Andreas Klappenecker

Propositional Logic. Part I

Lexical and Syntax Analysis. Top-Down Parsing

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 9 Normal Forms

Integers and Mathematical Induction

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

CSE 20 DISCRETE MATH. Fall

Chapter 3: Propositional Languages

CSE 20 DISCRETE MATH. Winter

This book is licensed under a Creative Commons Attribution 3.0 License

Stating the obvious, people and computers do not speak the same language.

Recursively Defined Functions

Languages and Compilers

Caveat lector: This is the first edition of this lecture note. Please send bug reports and suggestions to

Parsers. Xiaokang Qiu Purdue University. August 31, 2018 ECE 468

Lecture 5. Logic I. Statement Logic

Recursive Definitions Structural Induction Recursive Algorithms

CS152: Programming Languages. Lecture 2 Syntax. Dan Grossman Spring 2011

Artificial Intelligence. Chapters Reviews. Readings: Chapters 3-8 of Russell & Norvig.

WUCT121. Discrete Mathematics. Graphs

Propositional Calculus: Boolean Functions and Expressions. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

CMSC th Lecture: Graph Theory: Trees.

14.1 Encoding for different models of computation

7. The Gauss-Bonnet theorem

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Trees Rooted Trees Spanning trees and Shortest Paths. 12. Graphs and Trees 2. Aaron Tan November 2017

CS 220: Discrete Structures and their Applications. Recursive objects and structural induction in zybooks

MA513: Formal Languages and Automata Theory Topic: Context-free Grammars (CFG) Lecture Number 18 Date: September 12, 2011

Consider a description of arithmetic. It includes two equations that define the structural types of digit and operator:

Quiz 1: Functions and Procedures

Foundations of Computer Science Spring Mathematical Preliminaries

Math 5593 Linear Programming Lecture Notes

1. [5 points each] True or False. If the question is currently open, write O or Open.

LECTURE 2 An Introduction to Boolean Algebra

Non-context-Free Languages. CS215, Lecture 5 c

Formal Predicate Calculus. Michael Meyling

Lecture 3: Art Gallery Problems and Polygon Triangulation

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Lecture 22 Tuesday, April 10

Point-Set Topology 1. TOPOLOGICAL SPACES AND CONTINUOUS FUNCTIONS

Introduction to Automata Theory. BİL405 - Automata Theory and Formal Languages 1

Discrete Mathematics Lecture 4. Harper Langston New York University

Wednesday, September 9, 15. Parsers

Parsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs:

Intro to semantics; Small-step semantics Lecture 1 Tuesday, January 29, 2013

CHAPTER 10 GRAPHS AND TREES. Alessandro Artale UniBZ - artale/

Syntax Analysis. Amitabha Sanyal. ( as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

Horn Formulae. CS124 Course Notes 8 Spring 2018

Syntax Analysis. Prof. James L. Frankel Harvard University. Version of 6:43 PM 6-Feb-2018 Copyright 2018, 2015 James L. Frankel. All rights reserved.

A Survey of Mathematics with Applications 8 th Edition, 2009

Characterization of Boolean Topological Logics

SECTION 5.1. Sequences

CMPSCI 250: Introduction to Computation. Lecture #14: Induction and Recursion (Still More Induction) David Mix Barrington 14 March 2013

Sometimes an ambiguous grammar can be rewritten to eliminate the ambiguity.

Chapter Summary. Mathematical Induction Recursive Definitions Structural Induction Recursive Algorithms

Lecture 3 Tao Wang 1

Lecture 1. 1 Notation

STABILITY AND PARADOX IN ALGORITHMIC LOGIC

Introduction to Sets and Logic (MATH 1190)

A Simple Syntax-Directed Translator

Programming Languages Third Edition

1.7 The Heine-Borel Covering Theorem; open sets, compact sets

p x i 1 i n x, y, z = 2 x 3 y 5 z

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

Programming Languages Fall 2013

Upcoming ACM Events Linux Crash Course Date: Time: Location: Weekly Crack the Coding Interview Date:

Midterm Exam. CSCI 3136: Principles of Programming Languages. February 20, Group 2

1 Elementary number theory

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

10/9/17. Using recursion to define objects. CS 220: Discrete Structures and their Applications

CS 512, Spring 2017: Take-Home End-of-Term Examination

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION

Chapter 3 (part 3) Describing Syntax and Semantics

Where Can We Draw The Line?

Syntax Analysis: Context-free Grammars, Pushdown Automata and Parsing Part - 4. Y.N. Srikant

Basic Properties The Definition of Catalan Numbers

CSE 105 THEORY OF COMPUTATION

if s has property P and c char, then c s has property P.

(a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are rational they can be written as the ratio of integers a 1

Syntax Analysis Part I

Lecture Notes on Binary Decision Diagrams

An Algorithm for Transformation of Finite Automata to Regular Expressions

Transcription:

Discrete Mathematics (II) Spring 2012 Lecture 5: Formation Tree and Parsing Algorithm Lecturer: Yi Li 1 Overview In this lecture, we completely focus on syntax of proposition. And the term proposition does always mean well-defined proposition without explicit declaration. The most important topic is to make sure the unique readability of a well defined proposition. And then a proposition is associated with a tree, called formation tree. Therefore, we find the properties of a well-defined proposition based on its tree form. Finally, we introduce a parsing algorithm to check the validity of a sequence of symbols, with a formation tree as a by-product. 2 Some properties of proposition 2.1 Ambiguity In everyday language, we sometimes could speak some sentence which could be understood totally with different meaning, which is called ambiguous. Example 1. Consider the following sentences: 1. The lady hit the man with an umbrella. 2. He gave her cat food. 3. They are looking for teachers of French, German and Japanese. Once you read these sentences, you way wonder: 1. Is the lady using an umbrella to hit or is she hitting a man who is carrying an umbrella? 2. Is he giving cat food to her or is he giving her cat some food? 3. Are they looking for teachers who can each teach one language or all three languages? You may find more examples. Here, the ambiguity is not caused by the meaning/semantics of some word. The reason is just the way to group words in different approaches. Similarly, you could encounter the same trouble when you write a piece of segment of code. The example is the way to nest if and else. You can also consider the following expression 4/2 2. Without the help of parentheses, proposition could also run into the same problem. Consider the following example. 1

Example 2. Consider the following proposition A 1 A 2 A 3, which is definitely not well-defined. Solution. We have two possible different propositions 1. (A 1 A 2 ) A 3 2. A 1 (A 2 A 3 ) Of course, they have different abbrevation truth tables. Mathematics is rigid. One of the responsibilities of mathematical logic is to eliminate ambiguity from mathematics. So we should first eliminate ambiguity in mathematical logic. 2.2 Parentheses Theorem 1. Every well-defined proposition has the same number of left as right parentheses. Proof. Consider the symbols without parentheses first. And then prove it by induction with more complicated propositions according to the construction of a complicated proposition. Here, we actually use the depth of nested connectives, which will be introduced in the next section. Theorem 2. Any proper initial segement of a well defined proposition contains an excess of left parenthesiss. Thus no proper initial segement of a well defined propositon can itself be a well defined propositions. Go back to lecture three if your forget what is a proper initial segment. Proof. Prove it by induction from simple to complicated propositions. And we also need Theorem 1. 3 Formation Tree A proposition is a sequence of symbols. The structure determines the reading of a proposition. In this section, we are to map a proposition to a tree, named formation tree. It will help us to read a proposition. Definition 3 (Top-down). A formation tree is a finite tree T of binary sequences whose nodes are all labele with propositions. The labeling satisfies the following conditions: 2

1. The leaves are labeled with propositional letters. 2. if a node σ is labeled with a proposition of the form (α β), (α β), (α β) or (α β), its immediate successors, σˆ0 and σˆ1, are labeled with α and β (in that order). 3. if a node σ is labeled with a proposition of the form ( α), its unique immediate successor, σˆ0, is labeled with α. How to map a well-defined proposition to a tree? Consider the following example. Example 3. The formation tree of (A B), ((A B) C). It is easy to draw its formation tree for this example. However, when a proposition is complicated enough, it is not easy. Just rethink your approach. We may follow the procedure of constructing a proposition from a propositional letters in a bottom-up way, even we define it in a top-down approach. These two examples are specified. What about the other propositions? Given proposition, we have the following questions: 1. Is there a formation tree? 2. Is it unique? It is lucky that we have the following Theorem. Theorem 4. Each well-defined proposition has a unique formation tree associated with it. Proof. (Sketch) 1. Existence of the formation tree by induction on depth. 2. Uniqueness of the formation tree by induction on depth. From now on, we sometimes call the labeled tree of a proposition associated formation tree. Once we have formation tree of a proposition, we can define these following terms. Definition 5. Given an associated formation tree, we have 1. The depth of a proposition is the depth of associated formation tree. 2. The support of a proposition is the set of propositional letters that occur as labels of the leaves of the associated formation tree. Actually, all inductive proof could be based on the depth of a proposition. 3

4 Parsing There are infinitely many sequence of symbols. How to identify which is well-defined and which is not? If we want to build a proof system executed on a computer it is very important to construct first a method to check whether it is valid or not. 4.1 Algorithm As a well-defined propostition can be uniquely mapped into a formation tree, which is easy to check every node well-defined or not. We can now introduce a reacursive algorith to analyze sequence of symbols. 1. If all leaf nodes are labeled with proposition letters, stop it. Otherwise select a leaf node having expressions other than letter and examine it. 2. The first symbol must be (. if the second symbol is, jump to step 4. Otherwise go to step 3. 3. (a) Scan the expression from the left until first reaching (α, where α is a nonempty expression having a balance between ( and ). (b) The α is the first of the two constituents. (c) The next symbol must be,,, or. (d) The remainder of the expression, β) must consist of a an expression β and ). (e) Extend the tree by adding α and β as left and right immediate successor respectively. 4. The first two symbols are now known to be (. The remainder of the expression, β) must consist of a an expression β and ). Then we extend the tree by adding β as its immediate successor. Goto step 1. In algorithm, we omit the procedure to exit for sequence which is not well-defined. Check every node, if a internal node is not well defined or terminal node is not a proposition letter, the algorithm just stops and asserts a non-well-defined sequence. What s most important is that the algorithm checks the sequence recursively. It is the similar to the approach to define a well-defined proposition. 4.2 Parentheses Parentheses are tedious for us to handle. We can introduce some rule to reduce the number of parentheses without ambiguity. 1. The outermost parenthesis need not be explicitly mentioned. 2. The negation symbol applies to as little as possible. 3. The conjuction and disjunction symbols apply to as little as possible. 4

4. Where one connective symbols is used repeatedly, grouping is to the right. All these explicit rules make our parsing algorithm complicated if you want to accommodate the right proposition other than well-defined ones for convenience. Furthermore, you should prove that explicit rule would not result in ambiguity. 4.3 Polish notation Rules are not convenient. However there is a smart way to get rid of parentheses permanently, it is just the Polish notation. As we have already known, any connective is just a function with one or two parameters. We can represent a proposition as following without any parentheses: 1. D (α) = α. 2. D (α, β) = αβ. 3. D (α, β) = αβ. 4. D (α, β) = αβ. 5. D (α, β) = αβ. It is called Polish notation. Actually, it can be expanded to any n-ary function. Consider the following example, which is translated from a well-defined proposition. Example 4. Determine the well defined proposition of AD B CB. It is easy to recover the well-defined form. Do it as an exercise. Yah! We do eliminate parentheses successfully. But what is your feeling about Polish notation when you try to figure out what it represents. In fact, it is an approach very suitable for machine but human. To us, the well-defined way is much better. There are several approached to translate Polish representation into regular one, which is left as an exercise. 5 Appendix: Inductive definition In our class, many definitions are defined recursively or inductively. We just introduce Definition 6. A set S is closed under a single operation f(s 1,..., s n ) if and only if every s 1,..., s n S, f(s 1,..., s n ) S Definition 7. The closure of a set S under (all) the operations in a set T is the smallest C such that 5

1. S C and 2. if f T is n-ary and s 1,..., s n C, then f(s 1,..., s n ) C. With these concepts, we have an Theorem on the property of inductive definition. Theorem 8. Suppose that S is closed under the operations of T, there is a smallest closure C such that S C. Proof. Given a set D, S D and D is closed under the operations of T. Consider the set C = {D S D D is closed under the operations of T }. It is obvious that S C. And C is the smallest set according to definition of C. As a direct application of Theorem 8, we have the following Theorem about well-defined Definition: Theorem 9. If S is a set of well defined propositions and is closed under all five connectives, then S is the set of all well defined propositions Exercises 1. Show that there are no well-defined propositions of length 2, 3, or 6, but that any other positive length is possible. 2. Given an example such that (α β) = (γ δ) but α γ, where α and β are well-defined and γ and δ are two expressions. 3. Draw formation tree of the following propositions: (a) ((A B) (( C) D)). (b) ((( A) B) (A ( B))). 4. Let α be a well-defined proposition; let c be the number of places at which binary connective symbols(,,, ) occur in α; let s be the number of places at which proposition letters occur in α. Show by using the induction principle that s = c + 1. 5. Determine the Polish notation of proposition or vice versa. (a) ((A B) (( C) D)). (b) ((( A) B) (A ( B))). (c) AB C D. 6. Design a algorithm which can translate Polish notation of proposition into well defined proposition without stack or with at most one. 7. Design a algorithm to translate a well-defined proposition into a Polish notation form. 6