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

Similar documents
CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

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

We ve studied the main models and concepts of the theory of computation:

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

Final Course Review. Reading: Chapters 1-9

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Derivations of a CFG. MACM 300 Formal Languages and Automata. Context-free Grammars. Derivations and parse trees

Propositional Logic Formal Syntax and Semantics. Computability and Logic

CS402 - Theory of Automata Glossary By

Definition 2.8: A CFG is in Chomsky normal form if every rule. only appear on the left-hand side, we allow the rule S ǫ.

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CT32 COMPUTER NETWORKS DEC 2015

STABILITY AND PARADOX IN ALGORITHMIC LOGIC

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Decision Properties for Context-free Languages

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

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

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

Answer Key #1 Phil 414 JL Shaheen Fall 2010

Computation Engineering Applied Automata Theory and Logic. Ganesh Gopalakrishnan University of Utah. ^J Springer

SAT Solver. CS 680 Formal Methods Jeremy Johnson

CSE 105 THEORY OF COMPUTATION

PROPOSITIONAL LOGIC (2)

Boolean Functions (Formulas) and Propositional Logic

ECS 120 Lesson 16 Turing Machines, Pt. 2

Binary Decision Diagrams

ONE-STACK AUTOMATA AS ACCEPTORS OF CONTEXT-FREE LANGUAGES *

CSE 20 DISCRETE MATH. Fall

Introduction to dependent types in Coq

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

Reflection in the Chomsky Hierarchy

CSC Discrete Math I, Spring Sets

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

CSE 105 THEORY OF COMPUTATION

USING QBF SOLVERS TO SOLVE GAMES AND PUZZLES. Zhihe Shen. Advisor: Howard Straubing

Warm-Up Problem. Let L be the language consisting of as constant symbols, as a function symbol and as a predicate symbol. Give an interpretation where

PS3 - Comments. Describe precisely the language accepted by this nondeterministic PDA.

CSE 105 THEORY OF COMPUTATION

Theory of Computation

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

Propositional Theories are Strongly Equivalent to Logic Programs

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

Propositional Logic. Part I

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

LOGIC AND DISCRETE MATHEMATICS

LL Parsing, LR Parsing, Complexity, and Automata

Ambiguous Grammars and Compactification

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Deductive Methods, Bounded Model Checking

Decidable Problems. We examine the problems for which there is an algorithm.

Theory Bridge Exam Example Questions Version of June 6, 2008

CS164: Midterm I. Fall 2003

CSE 20 DISCRETE MATH. Winter

Introduction to Computers & Programming

Towards a Logical Reconstruction of Relational Database Theory

The Satisfiability Problem [HMU06,Chp.10b] Satisfiability (SAT) Problem Cook s Theorem: An NP-Complete Problem Restricted SAT: CSAT, k-sat, 3SAT

Chapter 2 & 3: Representations & Reasoning Systems (2.2)

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic.

Computability Theory

8 NP-complete problem Hard problems: demo

Foundations of AI. 9. Predicate Logic. Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

Lecture 5. Logic I. Statement Logic

Theory of Computations Spring 2016 Practice Final Exam Solutions

Complexity Classes and Polynomial-time Reductions

Regular Expressions for Data Words

Propositional Calculus: Boolean Algebra and Simplification. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

1 Parsing (25 pts, 5 each)

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

Closure Properties of CFLs; Introducing TMs. CS154 Chris Pollett Apr 9, 2007.

To illustrate what is intended the following are three write ups by students. Diagonalization

Mixed Integer Linear Programming

LL(1) predictive parsing

Pushdown Automata. A PDA is an FA together with a stack.

Course Project 2 Regular Expressions

UNIT I PART A PART B

JNTUWORLD. Code No: R

CS 380/480 Foundations of Artificial Intelligence Winter 2007 Assignment 2 Solutions to Selected Problems

Computer Sciences Department

Computer-Aided Program Design

LR Parsing. The first L means the input string is processed from left to right.

More on Polynomial Time and Space

CS2 Language Processing note 3

A Characterization of the Chomsky Hierarchy by String Turing Machines

Programming Languages Third Edition

Introduction to Lexing and Parsing

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

Homework 1. Due Date: Wednesday 11/26/07 - at the beginning of the lecture

Chapter 3 (part 3) Describing Syntax and Semantics

Model checking pushdown systems

T.E. (Computer Engineering) (Semester I) Examination, 2013 THEORY OF COMPUTATION (2008 Course)

CSE P 501 Exam 8/5/04

Languages and Automata

2SAT Andreas Klappenecker

(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

Transcription:

CMPSCI 601: Recall From Last Time Lecture 5 Definition: A context-free grammar (CFG) is a 4- tuple, variables = nonterminals, terminals, rules = productions,,, are all finite. 1

( ) $ Pumping Lemma for Regular Sets: Let be a DFA. Let. Let s.t.. Then s.t. the following all hold:, and!" # CFL Pumping Lemma: Let $ be a CFL. Then there is a constant, depending only on $, such that if %&' ) $ and, then there exist strings ( such that:, and ) ' *, and ) +, and for all " ) # N, ( # 2

Prop: Prop: N is not a CFL. N is not a CFL. Any CFL satisfies the conclusion of the CFL Pumping Lemma, but it is not true that any non-cfl must fail to satisfy it. There are other tools that can show a language to be a non-cfl. These include stronger forms of the Pumping Lemma and more closure properties. If $ is a CFL and a regular language, then $ must be regular. Proving this, however, requires a different characterization of the CFL s. 3

CMPSCI 601: Pushdown Automata (PDA s) Lecture 5 Definition: A pushdown automaton (PDA) is a 7- tuple, finite set of states, input alphabet, stack alphabet, start state, initial stack symbol, final states. finite set of transitions, PDA NFA stack 4

Theorem 5.1 Let $ following are equivalent: 1. $ 2. $, for some CFG., for some PDA. 3. $ is a context-free language. be any language. Then the Proof: We give only a sketch here there are detailed proofs in [HMU], [LP], and [S]. To prove (1) implies (2), we can build a bottom-up parser or top-down parser, similar to those used in real-world compilers except that the latter are deterministic. 5

The top-down parser is a PDA that: begins by pushing onto its stack may pop a terminal from the stack if can at the same time read a matching input letter, may execute a rule $, ends by popping the by popping $ and pushing when done with the input The proof that the language of any PDA is a CFL (that (2) implies (1)) is of less practical interest. Given states and, let $ be the set of strings that could take the PDA from state with empty stack to state with empty stack. We have all rules of the form $ $ $, and a rule $ $ whenever moves of the PDA warrant it. 6

CMPSCI 601: Boolean Logic: Syntax Lecture 5 Boolean variables: A boolean variable represents an atomic statement that may be either true or false. There may be infinitely many of these available. Boolean expressions: atomic:, ( top ), ( bottom ),,,,, for Boolean expressions Note that any particular expression is a finite string, and thus may use only finitely many variables. A literal is an atomic expression or its negation:,,,. As you may know, the choice of operators is somewhat arbitary as long as we have a complete set, one that suffices to simulate all boolean functions. On HW#1 we argued that is already a complete set. 7

The expressions form a context-free language. As we mentioned before, we may cheat by omitting parentheses, etc., as long as the parsing is clear. Even with the cheating it s not too hard to tell whether a string is a valid expression. Examples of boolean expressions: 8

CMPSCI 601: Boolean Logic: Semantics Lecture 5 A boolean expression has a meaning, a truth value of true or false, once we know the truth values of all the individual variables. A truth assignment is a function true false, where is the set of all variables. An assignment is appropriate to an expression if it assigns a value to all variables used in. The double-turnstile symbol (read as models ) denotes the relationship between a truth assignment and an expression. The statement (read as models ) simply says is true under. 9

If is appropriate to, we define when induction on the structure of : is true and is false for any, A variable is true iff says that it is, If, iff both and If, iff either or both, If, unless and If, iff and both true or both false. is true by, or, are 10

Definition 5.2 and are semantically equivalent iff for all appropriate to and, Examples: 11

Proposition 5.3 Every boolean expression,, is equivalent to one in Conjunctive Normal Form (CNF), and to one in Disjunctive Normal Form (DNF). Proof: DNF: look at the truth table for : 0 0 0 1 0 0 0 1 1 1 0 1 0 0 1 0 1 1 0 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 CNF: put in DNF. Use De Morgan s law: # # 12

Definition 5.4 A boolean expression there exists. is valid iff for all appropriate to, is satisfiable iff. VALID SAT UNSAT Proposition 5.5 For any boolean expression, UNSAT VALID UNSAT VALID VALID UNSAT Proposition 5.6 is unsatisfiable iff. is satisfiable iff. is valid iff. 13

CMPSCI 601: Relations With Other Models Lecture 5 A boolean expression specifies a boolean function of its variables. It s natural to ask how the computation of this function fits into our other models of computation. A boolean expression of length can be converted into an SLP of length, by induction on the definition of the expression. If we already have SLP s computing and *, we can concatenate them and then with more instructions compute any of the expressions,,, or. 14

Given any SLP and any of its instructions, the output of the instruction is a boolean expression, and thus there is some boolean expression that computes it. Can we be sure that a short SLP leads to a short expression? We can if the SLP is read-once, meaning that each non-input variable occurs only once on the right-hand side of an instruction. You ll prove on HW#2 that the value of th instruction of a read-once SLP has an expression of length. It is unknown whether every polynomial-size SLP can be made read-once while keeping the size polynomial. As we may prove later in the course, this is equivalent to the question of whether every polynomial-size SLP can be given depth while keeping its size polynomial. It is generally conjectured that it cannot. 15

What about the first-order model and boolean expressions? We can convert a or quantifier into a boolean expression using or. For example, can be equivalently written where each of the * s is one of the input bits. By induction, we can prove that a first-order formula of quantifier depth corresponds to a boolean expression (in the atomic variables) of length. (Try this!) In this case it is known that there are polynomial-length boolean expressions that cannot be converted into firstorder formulas, so that the boolean expresssions are strictly more powerful. We won t get to the proof of this (due to Mike Sipser and three others, in 1981) in this course. * 16

We have defined several properties of boolean expressions: validity, satisfiability, and their negations. It is natural to ask now difficult it is for an algorithm to take an expression as input and determine whether it is valid or satisfiable. The method of truth tables gives us a way to answer these problems, though not a very satisfactory one. Given a formula in variables, there are different settings of the variables rows of the truth table. We know how to evaluate the formula in each of these settings, and thus given enough time we know how to create the entire truth table and see whether there is at least one true row or at least one false row. Of course except for very small this running time is prohibitively large. Is there a better way to answer the questions? We don t know, and we will see that this possibility is tied to the major open questions of complexity theory. One thing we do know is that in some circumstances we can determine the validity or satisfiability of an expression without computing its entire truth table, by giving a formal proof in some system. This is our next topic. 17

# CMPSCI 601: The Fitch Proof System Lecture 5 If two expressions are equivalent, or if one is a tautological consequence of the other, this fact can be established by truth tables. But the lines of the truth table are far too many to work with unless " is small. We need a more efficient method to establish tautologies. [BE] provides a proof system called Fitch or. At this point in the course we are concerned with the propositional subset of Fitch, leaving out rules dealing with quantifiers. 18

A Fitch proof is a sequence of expressions, each one of which is justified in terms of previous ones. There are twelve proof rules that tell us when a statement is justified. Fitch has no axioms (statements assumed to be true without proof) but we typically start with some premises and reach a conclusion that follows from those premises. If from a set of premises we can derive, we write, read as proves. This single turnstile symbol is not to be confused with the double turnstile symbol. 19

CMPSCI 601: s Propositional Proof Rules Lecture 5 These are conveniently listed on pages 557-9 of [BE]. Intro: From Elim: From Intro: From, derive, derive, derive. Elim: From, if you have derived separately from each, derive. Intro: If you have derived from, derive. Elim: From, derive. Intro: From and, derive. Elim: From, derive (any!) Intro: If you have derived from, derive. Elim: From and, derive (also called modus ponens). Intro: If you have derived from and have derived from, derive. Elim: From and, derive... 20

As you practice with the Fitch software, there are two things you learn how to do. You must learn when a move is legal, and then when a move is a good idea. In chess, we call a player a beginner once they know all the moves, but after a lifetime of play they will still have more to learn about how to play well. The first natural computational problem that Fitch creates is determining whether a proof is valid. The software does this for your proofs, and you learn to do it mentally as you look for proofs. 21

A proof is valid if each step is valid, and a step is valid if it follows from previous steps by a rule. Eight of the rules require certain other statements to be available, meaning that they are active premises or have been proved within the current scope. But four of the rules Elim, Intro, Intro, and Intro, require not previous statements but previous proofs. This means that Fitch proofs have a nested structure, with derivations nested within other derivations. We can define the available statements at any given point in the proof, as those that are in the current derivation or any of the derivations containing the current one. As computer scientists we naturally think of a stack to maintain the nesting structure. At any given time we are engaged in a derivation that has certain active premises. Since premises are inherited by subderivations, we can keep them in a stack. 22

Testing validity of a step thus involves a single pass over the current premise stack and the current derivation, to see whether all the required statements or derivations for the step are there. This doesn t look to be a very difficult task. We haven t yet formalized the notion of polynomial time yet in this course, but once we do we can see that checking a Fitch proof for validity takes polynomial time in the length of the proof. What about the second problem, of finding a reasonably short valid proof when one exists? This is more difficult, of course, falling into the category of artificial intelligence. There are useful heuristics, but no reliable general method. We ll show in the next lecture that every valid statement has a proof in Fitch. But even this completeness theorem won t tell us whether a short (i.e., polynomial-length) proof exists for every tautology. This latter question is open, as we ll see. 23