monadic second-order logic - tata institute of …pandya/grad/aut06/lect3.pdf0.5 setg r a y0 0.5...
TRANSCRIPT
0.5setgray0
0.5setgray1
Monadic Second-Order LogicAutomata: Theory and Practice
Paritosh K. Pandya
(TIFR, Mumbai, India)
Unversity of Trento
10-24 May 2005
Trento’2005 – p. 1/31
First-order logic
Language for describing properties of MathematicalStructures.
Precise and rigorous.Rules and techniques for sound inference.
Structure = (Domain, Constants, Functions, Relations)Domain
�
Set of values.Constants Some specific values with names.Functions Operation
� � � �Relations Operation
� � � ��� � �.
Trento’2005 – p. 2/31
Arithmetic
Natural Numbers �
Peano Arithmetic:
�� �� ��� � � � � � � � � � � � � � ���Presburger Arithmetic:
� �� �� � � � � � � � � � � ��
Successor Arithmetic:
���� � � � ��� � � � � � � � ��
Real Arithmetic
��� � � � � � �� � �� � �� � �� � ��
Signature (Symbol set)
� � � !� "�Signature gives symbols that can be used in Formulae.
Example:
�$# %&(' )* � �� � � �+� � � � � and�$,- '. /10 -2 ' - � �� � � �+� � � .
Trento’2005 – p. 3/31
First Order Logic (2)
3 ��
First Order Logic with Equality over signature�
Example:
�# %&(' ) * � �� � � � � � � � � . Following are3 ��
formulae.465 467�8 � � 5 9 � � 7� : 5 � 7 ; �465 467 46<8 5 � 7 � <� � 5 � 7 � 5 � <465 467�8 5 � 7 : = <8 5 � < 9 < � 7�465 8 5� �> � � 5�
Trento’2005 – p. 4/31
First Order Logic (2)
3 ��
First Order Logic with Equality over signature�
Example:
�# %&(' ) * � �� � � � � � � � � . Following are3 ��
formulae.465 467�8 � � 5 9 � � 7� : 5 � 7 ; �465 467 46<8 5 � 7 � <� � 5 � 7 � 5 � <465 467�8 5 � 7 : = <8 5 � < 9 < � 7�465 8 5� �> � � 5�
Syntax
� @? � 8 8 8� �� A ? � @B A C? 9 CB A D C A = 5 8 C
where term is� A E ? � 8 8 8� �� .
Trento’2005 – p. 4/31
First Order Logic (2)
3 ��
First Order Logic with Equality over signature�
Example:
�# %&(' ) * � �� � � � � � � � � . Following are3 ��
formulae.465 467�8 � � 5 9 � � 7� : 5 � 7 ; �465 467 46<8 5 � 7 � <� � 5 � 7 � 5 � <465 467�8 5 � 7 : = <8 5 � < 9 < � 7�465 8 5� �> � � 5�
Syntax
� @? � 8 8 8� �� A ? � @B A C? 9 CB A D C A = 5 8 C
where term is� A E ? � 8 8 8� �� .�
structure
F
hasDomain
A F AE G
and
� Gas interpretation of
E
and
�
Trento’2005 – p. 4/31
Semantics
Notation:
C 5? � 5B � 8 8 8� 5�� means
H�I � � C� J K 5? � 8 8 8� 5� L
F� ? � 8 8 8� � � A� C 5? � 8 8 8� 5��
Defined as usual. (omitted.)
Example:
� � �� A� 4678 5� 7> 5 � 7�Sentence is formula without free variables.Example:
� A� 465 8 5 � 5 � � �.
Trento’2005 – p. 5/31
First-order logic of Finite Words
Finite word
� � M ? B 8 8 8 ON 8 8 8 ��P ?Q�R � � S 8 8 8 T 8 8 8 UWV �
XZY 5�
At position 5the letter is .� 5� 7�
Position 7is next to position 5.5 � 7Position 5is before position 7.
Example Every is followed by[4 5 8 XZY 5� : = 78 � 5� 7� 9 X / 7�
Trento’2005 – p. 6/31
Finite Word Structure
Specifications F.O. Sentences with equality over�]\ #- * .
Signature
�\ #- * � �� � � XZY � Y ^ _� .
A word ` a b c
gives the word structure
Given sentence
C
over
�\ #- * , we can evaluate` A� C
Langauge of a sentence
C
3 C� dfe g� K ` a h c A ` A� C L
Trento’2005 – p. 7/31
Finite Word Structure
Specifications F.O. Sentences with equality over�]\ #- * .
Signature
�\ #- * � �� � � XZY � Y ^ _� .
A word ` a b c
gives the word structure` � i � j `� � � \ � � \ � X \Y � Y ^ _�where for ` � M B 8 8 8 �P ? ,i � j `� � K �� 8 8 8� UV � L
.� \ k � l �
iff
l � k � �X \Y k �
iff � &
Given sentence
C
over�\ #- * , we can evaluate` A� C
Langauge of a sentence
C
3 C� dfe g� K ` a h c A ` A� C L
Trento’2005 – p. 7/31
Examples
Let
b � K � [�� L
.
Ek I R 5� de g� D = 78 � 7� 5�
. Similarly,
� R 5�.
C dfe g� = 5 8 Ek I R 5� 9 XZY 5� 9= 78 � 5� 7� 9 � R 7� 9 X / 7� � �Then, [ A� C [� mA� C no mA� C
All words s.t. between an and the next
[
there are atleast two�465 4678 XZY 5� 9 5 � 7 9 X / 7� 9 46<8 5 � < � 7 : D X / 7� �
: = <� = <S 8 5 �� <� � <S �� 7 9 Xqp <� � 9 Xqp <S� �
Trento’2005 – p. 8/31
Monadic Second Order Logic ( )
First order logic extended with
Set variables
r? � rB � 8 8 8. These are also calledmonadic predicates.
construct
r& �
. Some people write a r& .
Quantification over set variables:= r& 8 C and
4r& 8 C.Semantics Let
s& J A F A F� s? � 8 8 8� sN � ? � 8 8 8� � � A� C r? � 8 8 8� rN � 5? � 8 8 8� 5��
Example 7is upper bound of set
s � � K � � t� u L � � � � A� 4 5 8 s 5� � 5 v 7
Trento’2005 – p. 9/31
MSO over words
Examples:
Even length finite words over
h
.= r 8 465 8 Ek I R 5� : r 5� � 9 4 78 � 5� 7� 9 r 5� : D r 7� � 9 4 78 � 5� 7� 9 D r 5� : r 7� � 9 � R 5� : D r 5� �
Exercise Infinite words where every even position hasletter .
Question (a) What is the class of (finite word) languagesdefinable using
�w? (b) What is the class of � languages
definable using�w
?
Trento’2005 – p. 10/31
Buchi Theorems
Theorem 1 (Buchi60, Elgot61) A language (fromb c
) isrecognisable by a finite state automaton if and only if it is�w ��
definable, and both conversions are effective.
Theorem 2 (Buchi61) A language (fromb x
) is recognisableby a Nondeterministic Buchi Automataon if and only if it is�w ��
definable, and both conversions are effective.
Trento’2005 – p. 11/31
Proof of Theorem 1 (NFA to )
Let
h � X� by� z� {� !
with
X � K �� 8 8 8� T L
.Consider ` � M 8 8 8 �P ? , run | �� 8 8 8 | U� .r& contains positions
l
where | l � � k
.}
is
& ~�� � 465 D r& 5� 9 r � 5� � � 9 465 8 Ek I R 5� : > & ^ � r& 5� � 9 465� 78 � 5� 7� :> � &�� Y � � � ^ � r& 5� 9 XZY 5� 9 r � 7� � � 9 465 8 � R 5� : > � ^ � r � 5� � 9 XZY 5� �
Claim accepts ` iff` A� = rM 8 8 8 rN 8 }
Trento’2005 – p. 12/31
Logic �
Simplified
� w
with no first-order variables.
Atomic Formulaer J �
, set
r
is subset of
��k U� r�
set
r
has exactly one element.��� r� ��
sets
r� �
are singleton andelement in
�
is successor of element in
r
.r J XZY . Subset
We can translate
�wto
�w M .Example:
465 8 XZY 5� : = 7�8 � 5� 7� 9 � 7� �
becomes:
4r 8 �k U� r� 9 r J XZY := � 8 �k U � �� 9 ���� r� �� 9 � J ��
Trento’2005 – p. 13/31
Models of �
A model for
C r? � 8 8 8� r �� is
`� s? � 8 8 8� s � � .
Example
4r 8 �k U� r� 9 r J XZY := � 8 �k U� �� 9 ��� r� �� 9 � J ��Model
[ [� K �� � � t� � L�
Example
4�� 8 � { � " �� 9 � J rM 9 � J X /9 ��� � �� � � : J rM �
Model
[ [ [ [ � K �� � � S� u� � L �
Trento’2005 – p. 14/31
Continued
Representation
` � s? � 8 8 8� s � � as word overb � � b1� K �� � L �
.
Example Model
[ [� K �� � � t� � L �
is encoded aspos 0 1 2 3 4word a b a a bP0 1 1 0 1 1Example Model
[ [� K �� � L � K �� t L �is encoded as
pos 0 1 2 3word a b a aP0 1 1 0 0P1 1 0 0 1
Trento’2005 – p. 15/31
Proof ( � to Automata)
Given
C r? � 8 8 8� r �� construct
h�� C�
over alphabetb1� K �� � L �
. Each letter (is a column vector that) has theform
� � [? � [B � 8 8 8� [ � � . .
Example
r �� 9 4Q 8 r Q� : =6� 8 ��� Q� � � 9 � �� � .
Construction
h� C�
is by Induction on the structure of
C
.The construction is bottom-up. Automata for subformulaeare combined to make the automaton for whole formula.
Trento’2005 – p. 16/31
Atomic Formulae
h�� r& J r � �h�� �k U� r& � �h�� ��� r � � rN � �
h�� r � J XZY � .
Trento’2005 – p. 17/31
Proof (cont)
h� C? 9 CB � � h� C? � � h� CB �h� C? > CB � � h� C? � � h� CB � .h� D C� � h�� C�
= r& 8 C r? � 8 8 8� r ��
Use projection to “erase”
r& in the automaton forC r? � 8 8 8� r �� .i.e.h = r& 8 C r? � 8 8 8� r �� � � ����� h C r? � 8 8 8� r � � �
Complexity Non-elementary. Every
>
or
= r 8 C addsnondeterminism. Complexity grows by one exponent withevery alternation of
= rand D.
Corollary Any�w ��
formula can be written as
� �w ��
formula.Trento’2005 – p. 18/31
Tool MONA
Validity checker for MSO on Words.
Given
C r? � 8 8 8� r �� constructs automatonh C�
overalphabet
K �� � L �
.
Finds a model and counter-model of the formula byfinding accepting/rejecting path.
Finds if formula is valid or unsatisfiable.
Efficient BDD-based representation of transition table.Keeps automata in minimal, deterministic form.
D. Basin, CAV 2001 tutorial:http://www.inf.ethz.ch/personal/basin/teaching/scripts/cav01.pdfN. Klarlund MONA Overview:http://www.clairgrove.com/papers/Mona-tutorial.pdf
Trento’2005 – p. 19/31
MONA Example
Example
4 5 8 � Ek I R 5� : s 5� � 9 � R 5� : X 5� � 9 D � R 5� : D X 5� � �
4
2
XX
XX
3 X1
X0
0 1
XX
11
0X
10
Trento’2005 – p. 20/31
Finite Tree Languages
Tree Domain
i � j � � K �� � L c
with conditionsi � j � is finite, 5� a i � j � : 5 a i � j �5� a i � j � � 5� a i � j � .
Tree
�� i � j � � b
.Use
�¡ for all
b
=labelled tries. Tree language
3 J � .
Example All trees such that any subtree with label at itsroot has a node inside labelled
[.
Trento’2005 – p. 21/31
MSO over finite trees
Logic MSO with equality over signature �M � �? � � � XZY � Y ^ � .�M 5� 7�
means node 7is left child of 5.�? 5� 7�
means node 7is right child of 5.5 � 7means 5is a proper ancestor of 7.The individual variables range over tree nodes, i.e.
i � j � .
Example
4 5 8 XZY 5� : = 7�8 5 � 7 9 X / 7� �
Formally
� i � j � � �M � �? � � � XZY � Y ^ � .Then for sentence
C, we have
3 C� � K A A� C L
.
Trento’2005 – p. 22/31
Tree Automaton
A bottom-up tree automaton
h � X� by� ¢� �M � !�where�M a X
is the initial state,
! J X
is the set of final states.¢ J X� b1� X� X
.
A run | on tree
is a map |� i � j � � Xsatisfying
transition relation. Run is accepting if | ¤£ � a !.
Initialize leaf � with symbol to � using
�� � � �M � �M � a ¢�
Label non-leaf � with symbol to � using
� � � � � ? � � B � a ¢�
provided children of � are labelled � ? and � B .
Theorem (Thatcher,Wright) A set of finite trees isrecognizable by finite tree automata iff it is MSO definable.
Trento’2005 – p. 23/31
Tree Automaton
A bottom-up tree automaton
h � X� by� ¢� �M � !�where�M a X
is the initial state,
! J X
is the set of final states.¢ J X� b1� X� X
.
A run | on tree
is a map |� i � j � � Xsatisfying
transition relation. Run is accepting if | ¤£ � a !.
Initialize leaf � with symbol to � using
�� � � �M � �M � a ¢�
Label non-leaf � with symbol to � using
� � � � � ? � � B � a ¢�
provided children of � are labelled � ? and � B .
Theorem (Thatcher,Wright) A set of finite trees isrecognizable by finite tree automata iff it is MSO definable.
Trento’2005 – p. 23/31
Tree Automaton
A bottom-up tree automaton
h � X� by� ¢� �M � !�where�M a X
is the initial state,
! J X
is the set of final states.¢ J X� b1� X� X
.
A run | on tree
is a map |� i � j � � Xsatisfying
transition relation. Run is accepting if | ¤£ � a !.
Initialize leaf � with symbol to � using
�� � � �M � �M � a ¢�
Label non-leaf � with symbol to � using
� � � � � ? � � B � a ¢�
provided children of � are labelled � ? and � B .
Theorem (Thatcher,Wright) A set of finite trees isrecognizable by finite tree automata iff it is MSO definable.
Trento’2005 – p. 23/31
Proof of Buchi Theorem 2
Exactly follows the proof of Theorem 1, but using BuchiAutomata.
The theory has been extended to MSO over finite andinfinite trees.
Even MSO over graphs can be defined.
Trento’2005 – p. 24/31
MSO ove Infinite Words
Word ¥ � M ? 8 8 8 a b x
gives structure¥ � i � j � Q ¦6 � � �� � � XZY �
where
i � j ¥� � �, the set of natural numbers.
Logic
�w b x �
. We can specify properties of omegawords using FOL or MSO sentence
C. This logic is also
called S1S.
� Language
3 x C� de g� K ¥ a h x A ¥ A� C L
Examples
Every is followed by[465 8 XZY 5� : = 78 � 5� 7� 9 X / 7�
occurs infinitely often in the � word.465= 78 5 � 7 9 XZY 7�
.
Trento’2005 – p. 25/31
Logic WS1S
Logic WS1S has same syntax as S1S. Domain is� � K �� � � S� 8 8 8 L.Set variables take finite subsetes of �.Example
C de g� = r 8 r �� 9 465 8 r 5� : = 78 5 � 7 9 r 7�
.Then
A� §? § C
. However
mA� ¨ §? § C. (Why?)
Models of WS1S formulae are finite words.
WS1S can be decided using Finite State Automata.(Details in Classroom)
We can decide Presburger Arithmetic Sentences usingWS1S. (Details in Classroom.)
Trento’2005 – p. 26/31
Presburger Arithmetic in WS1S
Preburger arithmetic formulae are First Order Logicwith Equality formulae using signature
�� � � � � � � .Multiplication symbol is not alloweed.
The formulae are interpreted overNaturnal Numbers
©
.
Example:
465 8 = 78 5 � � � 7Encoding of Numbers
Encode number U as reverse binary string I [k U U� .Further encode this binary string as finite set � U� � i � U�
giving positions of�
bits in I [k U U� .
Example: I [k U �� � � � �. Hence, � U� � i � �� � K � � S L
.
Map � U� � i � � K r J %& � © L � ©
is a bijection.
Trento’2005 – p. 27/31
Encoding Presburger Formulae
Encoding Formulae
We can model a variable 5over natural numbers by aset variable
r
.
We define a formula
s 3ª � r� �� ��and
3 � � � r� ��
such thats 3ª � � U� � i � 5� � � U� � i � 7� � � U� � i � �� � � 5 � 7� <3 � � � � U� � i � 5� � � U� � i � 7� � � 5 � 7.
The encoding of
s 3ª �is a WS1S formula mimicing the
binary full adder circuit. Define
3 � � �
using
s 3ª �
andequality.
Trento’2005 – p. 28/31
(Cont)
Given Presburger formula
C 5? � 8 8 8� 5�� we can defineWS1S formula
« C r? � 8 8 8� r �� such that©¬� j ? � 8 8 8� j � A�C 5? � 8 8 8� 5� � � ©¬� � U� � i � j ? � � 8 8 8� � U� � i � j �� A�« C r? � 8 8 8� r �� .
Example: For
C� 4 5 8� 5kR R 78 5 � � � 7we have
« C
as4r 8 = � 8 = � 8 s 3ª � r� K � L � �� 9 3 � � � �� ��
.
Trento’2005 – p. 29/31
Omega Tree Automata
A muller omega-tree automaton
h� X� by� ¢� �M � ! ��withz J X� b1� X� X
.
Trento’2005 – p. 30/31
Omega Tree Automata
A muller omega-tree automaton
h� X� by� ¢� �M � ! ��withz J X� b1� X� X
.
A run | of
h
on omega-tree
is a map |� K �� � L � � b
s.t.| ¤£ � � �M and for all 5 a K �� � � L �, we have | 5� � 5� � | 5�� � | 5� � � a ¢.
Trento’2005 – p. 30/31
Omega Tree Automata
A muller omega-tree automaton
h� X� by� ¢� �M � ! ��withz J X� b1� X� X
.
A run | of
h
on omega-tree
is a map |� K �� � L � � b
s.t.| ¤£ � � �M and for all 5 a K �� � � L �, we have | 5� � 5� � | 5�� � | 5� � � a ¢.
The run is accepting if every infinite path from root satisfiesthe Muller acceptance condition.
Trento’2005 – p. 30/31
Omega Tree Automata
A muller omega-tree automaton
h� X� by� ¢� �M � ! ��withz J X� b1� X� X
.
A run | of
h
on omega-tree
is a map |� K �� � L � � b
s.t.| ¤£ � � �M and for all 5 a K �� � � L �, we have | 5� � 5� � | 5�� � | 5� � � a ¢.
The run is accepting if every infinite path from root satisfiesthe Muller acceptance condition.
Example Construct Muller Omega-tree automaton whichaccepts all trees having at least one path with infinitelymany
[
. (AlphabetK � [ L
).
Trento’2005 – p. 30/31