Global Grammar Constraints Toby Walsh National ICT Australia and University of New South Wales www.cse.unsw.edu.au/~tw Joint work with Claude-Guy Quimper.

Slides:



Advertisements
Similar presentations
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Advertisements

Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Lecture 24 MAS 714 Hartmut Klauck
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
CPSC Compiler Tutorial 4 Midterm Review. Deterministic Finite Automata (DFA) Q: finite set of states Σ: finite set of “letters” (input alphabet)
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Lecture # 8 Chapter # 4: Syntax Analysis. Practice Context Free Grammars a) CFG generating alternating sequence of 0’s and 1’s b) CFG in which no consecutive.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
Introduction to Computability Theory
CS5371 Theory of Computation
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
1 Normal Forms for Context-free Grammars. 2 Chomsky Normal Form All productions have form: variable and terminal.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
Normal forms for Context-Free Grammars
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
Parsing SLP Chapter 13. 7/2/2015 Speech and Language Processing - Jurafsky and Martin 2 Outline  Parsing with CFGs  Bottom-up, top-down  CKY parsing.
Prof. Busch - RPI1 Decidable Problems of Regular Languages.
Compilation 2007 Context-Free Languages Parsers and Scanners Michael I. Schwartzbach BRICS, University of Aarhus.
CS5371 Theory of Computation Lecture 12: Computability III (Decidable Languages relating to DFA, NFA, and CFG)
Final Exam Review Cummulative Chapters 0, 1, 2, 3, 4, 5 and 7.
Regular Model Checking Ahmed Bouajjani,Benget Jonsson, Marcus Nillson and Tayssir Touili Moran Ben Tulila
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
Week 14 - Friday.  What did we talk about last time?  Exam 3 post mortem  Finite state automata  Equivalence with regular expressions.
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Basics of automata theory
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Pushdown Automata (PDAs)
Grammars CPSC 5135.
Lexical Analysis Constructing a Scanner from Regular Expressions.
Overview of Previous Lesson(s) Over View  An NFA accepts a string if the symbols of the string specify a path from the start to an accepting state.
Regular Expressions Hopcroft, Motawi, Ullman, Chap 3.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
1 Turing’s Thesis. 2 Turing’s thesis: Any computation carried out by mechanical means can be performed by a Turing Machine (1930)
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Strings Basic data type in computational biology A string is an ordered succession of characters or symbols from a finite set called an alphabet Sequence.
CSCI 2670 Introduction to Theory of Computing October 13, 2005.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
Algorithms for hard problems Automata and tree automata Juris Viksna, 2015.
Grammar Set of variables Set of terminal symbols Start variable Set of Production rules.
Regular Expressions CS 130: Theory of Computation HMU textbook, Chapter 3.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Theory of Languages and Automata By: Mojtaba Khezrian.
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
David Rodriguez-Velazquez CS – 6800 Summer I
CS314 – Section 5 Recitation 3
PDAs Accept Context-Free Languages
PUSHDOWN AUTOMATA. PUSHDOWN AUTOMATA Hierarchy of languages Regular Languages  Finite State Machines, Regular Expression Context Free Languages 
Chapter 7 PUSHDOWN AUTOMATA.
Two issues in lexical analysis
REGULAR LANGUAGES AND REGULAR GRAMMARS
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Jaya Krishna, M.Tech, Assistant Professor
Context-free Languages
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Context-Free Grammars
Finite Automata.
Decidable Problems of Regular Languages
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Pushdown automata The Chinese University of Hong Kong Fall 2011
Normal Forms for Context-free Grammars
Presentation transcript:

Global Grammar Constraints Toby Walsh National ICT Australia and University of New South Wales Joint work with Claude-Guy Quimper To be presented at CP06

Global grammar constraints ● Often easy to specify a global constraint – ALLDIFFERENT([X1,..Xn]) iff Xi=/=Xj for i<j ● Difficult to build an efficient and effective propagator – Especially if we want global reasoning

Global grammar constraints ● Promising direction initiated by Beldiceanu, Carlsson, Pesant and Petit is to specify constraints via automata/grammar – Sequence of variables = string in some formal language – Satisfying assignment = string accepted by the grammar/automata

REGULAR constraint ● REGULAR(A,[X1,..Xn]) holds iff – X1.. Xn is a string accepted by the deterministic finite automaton A – Proposed by Pesant at CP 2004 – GAC algorithm using dynamic programming – However, DP is not needed since simple ternary encoding is just as efficient and effective – Encoding similar to that used by Beldiceanu et al for their automata with counters

REGULAR constraint ● Deterministic finite automaton (DFA) – – Q is finite set of states – Sigma is alphabet (from which strings formed) – T is transition function: Q x Sigma -> Q – q0 is starting state – F subseteq Q are accepting states ● DFAs accept precisely regular languages

REGULAR constraint ● Many global constraints are instances of REGULAR – AMONG – CONTIGUITY – LEX – PRECEDENCE – STRETCH –.. ● Domain consistency can be enforced in O(ndQ) time using dynamic programming

REGULAR constraint ● REGULAR constraint can be encoded into ternary constraints ● Introduce Qi+1 – state of the DFA after the ith transition ● Then post sequence of constraints – C(Xi,Qi,Qi+1) iff DFA goes from state Qi to Qi+1 on symbol Xi

REGULAR constraint ● REGULAR constraint can be encoded into ternary constraints ● Constraint graph is Berge-acyclic – Constraints only overlap on one variable – Enforcing GAC on ternary constraints achieves GAC on REGULAR in O(ndQ) time

REGULAR constraint ● REGULAR constraint can be encoded into ternary constraints ● Constraint graph is Berge-acyclic – Constraints only overlap on one variable – Enforcing GAC on ternary constraints achieves GAC on REGULAR in O(ndQ) time ● Encoding provides access to states of automata – Can be useful for expressing problems – E.g. minimizing number of times we are in a particular state

REGULAR constraint ● STRETCH([X1,..Xn]) holds iff – Any stretch of consecutive values is between shortest(v) and longest(v) length – Any change (v1,v2) is in some permitted set, P – For example, you can only have 3 consecutive night shifts and a night shift must be followed by a day off

REGULAR constraint ● STRETCH([X1,..Xn]) holds iff – Any stretch of consecutive values is between shortest(v) and longest(v) length – Any change (v1,v2) is in some permitted set, P ● DFA – Qi is – Q0= – T(,a)= if q+1<=longest(a) – T(,b)= if (a,b) in P and q>=shortest(a) – All states are accepting

NFA constraint ● Automaton does not need to be deterministic ● Non-deterministic finite automaton (NFA) still only accept regular languages – But may require exponentially fewer states – Important as O(ndQ) running time for propagator – E.g. 0* (1|2)^k 2 (1|2)* 2 (1|2)^k 0* – Where 0=closed, 1=production, 2=maintenance ● Can use the same ternary encoding

Soft REGULAR constraint ● May wish to be “near” to a regular string ● Near could be – Hamming distance – Edit distance ● SoftREGULAR(A,[X1,..Xn],N) holds iff – X1..Xn is at distance N from a string accepted by the finite automaton A – Can encode this into a sequence of 5-ary constraints

Soft REGULAR constraint ● SoftREGULAR(A,[X1,..Xn],N) – Consider Hamming distance (edit distance similar though a little more complex) – Qi+1 is state of automaton after the ith transition – Di+1 is Hamming distance up to the ith variable – Post sequence of constraints ● C(Xi,Qi,Qi+1,Di,Di+1) where ● Di+1=Di if T(Xi,Qi)=Qi+1 else Di+1=1+Di

Soft REGULAR constraint ● SoftREGULAR(A,[X1,..Xn],N) – To propagate – Dynamic programming ● Pass support along sequence – Just post the 5-ary constraints ● Accept less than GAC – Tuple up the variables

Cyclic forms of REGULAR ● REGULAR+(A,[X1,..,Xn]) – X1.. XnX1 is accepted by A – Can convert into REGULAR by increasing states by factor of d where d is number of initial symbols – qi => (qi,initial value) – T(qi,a)=qj => T((qi,b),a)=(qj,b) – Thereby pass along value taken by X1 so it can be checked on last transition

Cyclic forms of REGULAR ● REGULARo(A,[X1,..,Xn]) – Xi.. X1+(i+n-1)mod n is accepted by A for each 1<=i<=n – Can decompose into n instances of the REGULAR constraint – However, this hinders propagation ● Suppose A accepts just alternating sequences of 0 and 1 ● Xi in {0,1} and REGULARo(A,[X1,X2.X3]) – Unfortunately enforcing GAC on REGULARo is NP- hard

Cyclic forms of REGULAR ● REGULARo(A,[X1,..,Xn]) – Reduction from Hamiltonian cycle – Consider polynomial sized automaton A1 that accepts any sequence in which the 1st character is never repeated – Consider polynomial sized automaton A2 that accepts any walk in a graph ● T(a,b)=b iff (a,b) in edges of graph – Consider polynomial sized automaton A1 intersect A2 – This accepts only those strings corresponding to Hamiltonian cycles

Other generalizations of REGULAR ● REGULAR FIX(A,[X1,..Xn],[B1,..Bm]) iff – REGULAR(A,[X1,..Xn]) and Bi=1 iff exists j. Xj=I – Certain values must occur within the sequence – For example, there must be a maintenance shift – Unfortunately NP-hard to enforce GAC on this

Other generalizations of REGULAR ● REGULAR FIX(A,[X1,..Xn],[B1,..Bm]) – Simple reduction from Hamiltonian path – Automaton A accepts any walk on a graph – n=m and Bi=1 for all i

Chomsky hierarchy ● Regular languages ● Context-free languages ● Context-sensitive languages ●..

Chomsky hierarchy ● Regular languages – GAC propagator in O(ndQ) time ● Conext-free languages – GAC propagator in O(n^3) time and O(n^2) space – Asymptotically optimal as same as parsing! ● Conext-sensitive languages – Checking if a string is in the language PSPACE- complete – Undecidable to know if empty string in grammar and thus to detect domain wipeout and enforce GAC!

Context-free grammars ● Possible applications – Hierarchy configuration – Bioinformatics – Natual language parsing – … ● CFG(G,[X1,…Xn]) holds iff – X1.. Xn is a string accepted by the context free grammar G

Context-free grammars ● CFG(G,[X1,…Xn]) – Consider a block stacking example – S -> NP | P | PN | NPN – N -> n | nN – P -> aa | bb | aPa | bPb – These rules give n* w rev(w) n* where w is (a|b)* – Not expressible using a regular language ● Chomsky normal form – Non-terminal -> Terminal – Non-terminal -> Non-terminal Non-terminal

CFG propagator ● Adapt CYK parser ● Works on Chomsky normal form – Non-terminal -> Terminal – Non-terminal -> Non-terminal Non-terminal ● Using dynamic programming to compute supports ● Bottom up – Enforces GAC in Theta(n^3) time Simultaneously and independently proposed by Sellmannn [CP06]

CFG propagator ● Adapt Earley chart parser – Carry support information ● Works on grammar in any form ● More top down – Better on tightly restricted grammars ● Enforces GAC in O(n^3) time – Best case is better as not Theta(n^3)

Conclusions ● Global grammar constraints – Specify wide range of global constraints – Provide efficient and effective propagators automatically – Nice marriage of formal language theory and constraint programming!