Deciding Presburger Arithmetic Using Automata

Download Report

Transcript Deciding Presburger Arithmetic Using Automata

Deciding Presburger Arithmetic
Using Automata
1
PARIXIT PRASAD
Department of Computer Science and Automaton
Indian Institute of Science, Bangalore
December 4, 2013
Parixit Prasad | CSA - IISC
December 4, 2013
Structure of presentation
2
 Recall
 Finite Automata
 Presburger Arithmetic
 Sets of Integers recognized by a Finite Automaton
 Presburger Formulas to Finite Automata
 Automata Associated with equalities
 Automata Associated with inequalities
 Closure Properties and Automata for arbitrary
formulas
 Deciding satisfiability of a formula
Parixit Prasad | CSA - IISC
December 4, 2013
Finite Automata
3
 A Finite Automaton is a tuple (Q,∑,δ,q0,F).
› Q = Finite set of states
› ∑ = Finite set of input symbols
› δ  (Qx∑xQ)
› q0  Q (the start state)
› F  Q (Finite set of final states)
 A run of the automaton on the word ω  ∑* is a word ρ  Q* , such that:
› ρ[1] = q0
› If ρ[i] = p and ρ[i+1] = q , then (p, ω[i],q)  δ
 A successful run ρ on ω is when ρ[n+1]  F , where n=|ω|
 A string is accepted by the automaton when there is a successful run on that
string.
 Class of languages accepted by finite automaton is closed under union,
intersection and complementation.
Parixit Prasad | CSA - IISC
December 4, 2013
Presburger Arithmetic
4
 A Basic term in presburger arithmetic consists of first order variable,
constants 0 & 1 and sums of basic terms.
› x+x+x+y+1+1 is a basic term which can also be written as 3x+y+2
 The Atomic formulas are equalities and inequalities between basic terms.
› x-2y = -2 is an atomic formula with equality.
› x-2y ≤ -2 is an atomic formula with inequality.
 The Formulas are first-order formulas build on atomic formulas using the
connectives Λ(conjunction), V(disjunction), ¬(negation), x (existential
quantification), x (universal quantification).
› x, y.(x=2y V x=2y+1) is a formula.
› Τ is the empty conjunction (valid formula).
›  is the empty disjunction (unsatisfiable formula).
Parixit Prasad | CSA - IISC
December 4, 2013
Presburger Arithmetic (Contd.)
5
 The Free variables of a formula φ are defined as:
› FV(φ) = variables which are not quantified in φ
› FV(φ1 V φ2) = FV(φ1) U FV(φ2)
› FV(x.φ) = FV(φ) \ {x}
 The interpretation domain of the formulas is the set of natural numbers N,
with 0, 1, +, =, ≤ having their usual meaning.
 A solution of the formula φ is an assignment of x1,x2,…,xn in N which satisfies
φ, where FV(φ)={x1,x2,…,xn}
› ( x↦2, y↦1 ) is one solution of x+3 = 4y+1
› ( x↦4 ) is one solution of y.(x=2y)
Parixit Prasad | CSA - IISC
December 4, 2013
Sets of Integers recognized by Finite Automaton
6
 Every Natural number can be written as a word in base-k (k≥1) over the
alphabet set {0,1,…,(k-1)}
› 29 in base-2 is written as
 Since we want to read the word from LSB to MSB, we write the word from
right to left, with LSB in left and MSB in right.
› 29 in base-2 is written as
Parixit Prasad | CSA - IISC
December 4, 2013
Integers recognized by Finite Automaton(Contd.)
7
 There is a mapping from {0,1,…,(k-1)}* to N denoted by ~k which maps each
word in base-k to its corresponding Natural number.
› 101110
maps to 29
 n-tuples of natural number can be represented in base-k as a single word over
the alphabet set {0,1,…,(k-1)}n
› {0,1,…,(k-1)}3 set is {0,1,…,(k-1)} x {0,1,…,(k-1)} x {0,1,…,(k-1)}
› (13,29,6) (base-10) can be written in base-2 over the alphabet set {0,1}3
as:
1 0 1 1 0 0 0
1 0 1 1 1 0 0
0 1 1 0 0 0 0
Parixit Prasad | CSA - IISC
December 4, 2013
Presburger Formula to Finite Automata
8
1.
Build automaton for the atomic formulas in the given
formula
›
›
Automata Associated with equalities
Automata Associated with inequalities
2. Use these automaton to create the automata for the given
formula
Parixit Prasad | CSA - IISC
December 4, 2013
Automata associated with equality
9
 For every atomic formula
a1x1 + a2x2 + … + anxn = b (where a1, a2,…, an, b  Z)
we construct the automaton by repeating the following inference rule until
no more states or transitions can be added:
𝑞𝑐𝑄
𝑞𝑑𝑄, 𝑞𝑐 , θ, 𝑞𝑑 δ
𝑎1θ1 + ⋯ + 𝑎𝑛θ𝑛 = 2 𝑐
𝑐 − 𝑎1θ1 − ⋯ − 𝑎𝑛θ𝑛
𝑖𝑓 𝑑 =
2
θ = (θ1, … , θ𝑛)
where, θi  {0,1}
clearly, θ {0,1}n
Parixit Prasad | CSA - IISC
December 4, 2013
Automata associated with equality (Contd.)
10
 The resulting automata would be (Q, ∑, δ, qb, F)
› Q = {qi’s computed by the inference rule}
› ∑ = {0,1}n
› δ  (Qx∑xQ) computed by the reference rule
› qb is the initial state
› F=
{𝑞0}, if 𝑞0𝑄
∅, otherwise
Parixit Prasad | CSA - IISC
December 4, 2013
Automata associated with equality (Example)
11
 Consider the equation :
x-2y = -2
› We have b=-2 , so the initial state q-2Q
 Let c=b
 Compute the solutions θ=(x↦θ1, y↦θ2) of the equation: x-2y =2 c
› The solutions are {(x ↦ 0, y ↦ 0), (x ↦ 0, y ↦ 1)} for c=-2
 Compute the new states for each θ and the transition to them from c
› For θ=(x ↦ 0, y ↦ 0), d =
𝑐−0+0
2
=
−2−0−0
=
2
-1
• add q-1Q
0
• add (q-2, ,q-1)δ
0
 Similarly calculate the state and transition for other θ’s
 Repeat for each new state until no more new states can be added.
Parixit Prasad | CSA - IISC
December 4, 2013
Automaton for: x-2y=-2
12
1
0
0
0
q-1
1
1
1
1
q-2
0
1
q1
1
0
q0
0
1
0
0
Parixit Prasad | CSA - IISC
December 4, 2013
Getting solutions from the automaton
13
 For every successful run of the automaton, we get one solution.
 For example, for the successful run ρ = q-2 q-1 q-1 q0 q1 q0
q-2
0
−
0
→
1
q-1 −
0
→
1
q-1 −
1
→
0
q0 −
1
→
1
q1 −
0
→ q0
› x = 01101 = 22
› y = 00110 = 12
› This is one solution to the equation: x-2y=-2
Parixit Prasad | CSA - IISC
December 4, 2013
Observations on the automaton
14
 For an automaton for: a1x2+a2x2+…+anxn=b
1. The absolute value of the states are bounded by:
max(|b|,
𝑛
𝑖=1 |𝑎𝑖|)
2. Any successful run starting from qc gives a solution to:
a1x2+a2x2+…+anxn=c
Parixit Prasad | CSA - IISC
December 4, 2013
Automata associated with inequality
15
 Every inequality can be written in the form of:
a1x1 + a2x2 + … + anxn ≤ b (where a1, a2,…, an, b  Z)
we construct the automaton by repeating the following inference rule until
no more states or transitions can be added:
𝑞𝑐𝑄
𝑞𝑑𝑄, 𝑞𝑐 , θ, 𝑞𝑑 δ
𝑖𝑓 𝑑 = ⌊
𝑐 − 𝑎1θ1 − ⋯ − 𝑎𝑛θ𝑛
⌋
2
θ = θ1, … , θ𝑛
where, θi  {0,1}
clearly, θ {0,1}n
we apply this formula for all possible combinations of θ
Parixit Prasad | CSA - IISC
December 4, 2013
Automata associated with inequality (Contd.)
16
 The resulting automata would be (Q, ∑, δ, qb, F)
› Q = {qi’s computed by the inference rule}
› ∑ = {0,1}n
› δ  (Qx∑xQ) computed by the reference rule
› qb is the initial state
› F = {qc|c≥0}
Parixit Prasad | CSA - IISC
December 4, 2013
Automata associated with inequality (Example)
17
 Consider the equation :
x-2y ≤ -2
› We have b=-2 , so the initial state q-2Q
 Let c=b
 Take θ=(x↦θ1, y↦θ2), where θ1, θ2  {0,1}
› θ  {(x ↦ 0, y ↦ 0), (x ↦ 0, y ↦ 1) , (x ↦ 1, y ↦ 0) , (x ↦ 1, y ↦ 1)}
 Compute the new states for each θ and the transition to them from c
› For θ=(x ↦ 0, y ↦ 0), d = ⌊
𝑐−0+0
2
⌋=⌊
−2−0−0
2
⌋ = -1
• add q-1Q
0
• add (q-2, ,q-1)δ
0
 Similarly calculate the state and transition for other θ’s
 Repeat for each new state until no more new states can be added.
Parixit Prasad | CSA - IISC
December 4, 2013
Automaton for: x-2y≤-2
18
0 1
,
0 0
q-1
1
0
1 0
,
1 0
q-2
0
1
0 1
,
1 1
1
0
q0
0 1
,
1 1
0 1
,
0 0
q1
0
1
0,1
0 1
Parixit Prasad | CSA - IISC
December 4, 2013
Getting solutions from the automaton
19
 For every successful run of the automaton, we get one solution.
 For example, for the successful run ρ = q-2 q-1 q-1 q0 q1 q0
q-2
1
−
1
→
1
q-1 −
0
→
0
q-1 −
1
→
0
q0 −
1
→
1
q1 −
0
→ q0
› x = 11001 = 19
› y = 10110 = 13
› This is one solution to the equation: x-2y≤-2
Parixit Prasad | CSA - IISC
December 4, 2013
Closure Properties and automata for arbitrary formula
20
 Let Aφ(x1,x2,…,xn) be an automaton over alphabet {0,1}n which accepts the
solutions of the formula φ.
› Then FV(φ)  {x1,x2,…,xn}
› xi ∉ FV(φ) ⇒ accepting or not accepting a word in the automaton will not
depend on the ith track.
 Exercise:
How to compute Aφ(x1,x2,…,xn,y)? Given Aφ(x1,x2,…,xn) and y ∉ FV(φ).
Parixit Prasad | CSA - IISC
December 4, 2013
Automata for arbitrary formulas (Contd.)
21
 Given 2 Automata A𝜑 (𝑥) and A𝜑 (𝑥)
1
2
› A𝜑 Λ𝜑 (𝑥) can be computed by the intersection of the two given automaton
1
2
› A𝜑 V𝜑 (𝑥) can be computed by the union of the two given automaton
1
2
› We have to make sure that 𝑥 contains FV(φ1) U FV(φ2), which can be
done easily.
 Given Automata Aφ, we can construct A¬φ by taking complement of Aφ.
 A∃𝑥. 𝜑 can be computed from Aφ by projection, i.e. in Aφ simply forgetting about
the track corresponding to x in the transition labels.
 Since ∀𝑥. 𝜑 is logically equivalent to ¬∃𝑥. ¬𝜑, we can easily compute
A∀𝑥. 𝜑 using Aφ
Parixit Prasad | CSA - IISC
December 4, 2013
An example of Projection
22
 Automaton for: ∃y. (x-2y = -2)
1
0
q-1
1
q1
1
q-2
1
0
q0
0
0
Parixit Prasad | CSA - IISC
December 4, 2013
Deciding satisfiability of a formula
23
 We can apply induction on the Presburger formula φ to compute an
automaton 𝐴′φ which accepts the set of solutions of φ.
 By computing 𝐴′φ , deciding satisfiability of φ reduces to deciding the
emptiness of the language of 𝐴′φ, which can be done in linear time w.r.t
number of states.
Parixit Prasad | CSA - IISC
December 4, 2013
Thank you
24
Questions…
Parixit Prasad | CSA - IISC
December 4, 2013