First-order logic theories
20 de Maio de 2019
First-order logic theories Decidability
Decision problems Validity “Is the formula ϕ valid?” Satisfiability “Is the formula ϕ satisfiable?” Consequence “Is the formula ϕ a consequence of ψ?” Equivalence “Is the formula ϕ equivalent to ψ?”
These problems can be solved as instances of the others:
ϕ is valid iff ¬ϕ is not satisfiable ϕ is satisfiable iff ¬ϕ is not valid ϕ |= ψ iff ¬(ϕ → ψ) is not satisfiable ϕ ≡ ψ iff ϕ |= ψ and ψ |= ϕ
First-order logic theories Decidability
A solution to a decision problem is a procedure that, given instances of the problem as input, always terminates with an “yes” or “no” answer as output.
We say that a decision problem is decidable if it has a solution, otherwise it is undecidable. In propositional logic (PL) deciding satisfiability can always be done (in theory), using a truth table.
Theorem (Church & Turing) The validity/satisfiability in FOL (first-order logic) is undecidable.
The validity in FOL implies verifying all the possible models.
First-order logic theories Semi-decidability
There is a procedure that terminates with a “yes” answer when a FOL formula is valid. Theorem Validity in FOL is semi-decidable.
A problem is semi-decidable if there exists a procedure that: • terminates with the answer “yes” if and only if “yes” is the correct answer; • if the correct answer is “no”, terminates with a “no” answer or does not terminate. Contrary to a decidable problem, there is only a guarantee of termination when the correct answer is “yes”.
First-order logic theories Logical fragments
One can reduce the validity (satisfiability) of FOL formulas to the existence of appropriate instance of a quantifier free formula (using Herbrandisation/Skolemisation).
• If the vocabulary has a finite set of constants and no other functional symbols then the set of terms is finite. • If one restricts to formulas with a prenex normal form of the form ∀x∃yψ, then one only introduces constants by Herbrandisation. A FOL formula can be equivalent to a formula satisfying the condition above:
∃x∀y(P(x) ∨ Q(y)) ≡ ∃xP(x) ∨ ∀yQ(y) ≡ ∀y∃x(P(x) ∨ Q(y))
First-order logic theories Decidable fragments
There exist decidable fragments of FOL:
Monadic predicate logic: • only monadic predicates; • no functional symbols.
The Bernays-Schonfinkel class of formulas: • formulas that can be written with all the quantifiers at the beginning of the formulas; • the existential quantifiers appear before the universal quantifiers; • no functional symbols.
First-order logic theories FOL with equality
There are two approaches when we deal with equality in FOL. FOL without equality We treat the equality predicate (=), as any other predicate, that is, as a non-logical symbol.
FOL with equality We treat the equality predicate (=), as a logical symbol, with a fixed interpretation. For a particular structure A and interpretation s: A |=s t1 = t2 iff s(t1) = s(t2)
The last approach allows us to fix the cardinality of the domain:
∃x1x2∀y(y = x1 ∨ y = x2)
First-order logic theories First Order Theories
The non-logical of FOL do not have a pre-determined meaning:
For example, the formula 1 + 1 > 3 is satisfiable.
Sometimes we are not interested in validity in general, but with respect to a theory that fixes the interpretation of certain predicates and functional symbols.
• Theory of equality • Theory of natural numbers • Theory of real numbers • Theory of arrays or lists, etc...
First-order logic theories First-order theories
A theory T is a set of formulas closed by logic consequence (i.e. T |= φ iff φ ∈ T ) First-order theory A first-order theory T consists of: • a vocabulary V (set of constants, functional and relational symbols)
• a set AT of axioms (closed formulas)
Note that: • The symbols of V are such symbols without a pre-determined meaning • The axioms of T provide the meaning
A theory T is finitely (resp. recursively) axiomatisable if it possesses a finite (resp. recursive) set of axioms.
First-order logic theories T -Validity and T -Satisfiability
T -structure A T -structure (or T -model) is a structure that satisfies all the axioms of T .
Validity-T A T -formula ϕ is T -valid iff every T -structure satisfies ϕ.
Satisfiability-T A T -formula ϕ is T -satisfiability iff any T -structure satisfies ϕ.
Equivalence-T Two T -formulas ϕ and ψ are T -equivalents iff the same T -structures satisfies ϕ and ψ.
First-order logic theories Theory of equality TE
The vocabulary of the theory of equality TE consists of • the equality (=), which is the only interpreted symbol; • constants, functional and predicate symbols, which are not interpreted (except when related to =).
Axioms of TE : • ∀x.x = x • ∀x, y.x = y → y = x • ∀x, y, z.x = y ∧ y = z → x = z • for each positive integer n and n-ary function f , V ∀x1,..., xn, y1,..., yn. i xi = yi → f (x1,..., xn) = f (y1,..., yn) • for each positive integer n and n-ary predicate symbol P, V ∀x1,..., xn, y1,..., yn. i xi = yi → P(x1,..., xn) ↔ P(y1,..., yn)
Validity in TE is undecidable, but efficiently decidable in the quantifier-free fragment (qff) of TE . First-order logic theories A decision procedure for satisfiability qff TE
Consider a decision procedure for formulas consisting of conjunctions of literals, and allowing functions, but no predicates.
Eliminating predicates Consider the following transformation yielding equi-satisfiable formulas with no predicates. For each relational symbol P:
1 introduce a new functional symbol fP ;
2 write P(t1,..., tn) as fP (t1,..., tn) = t where t is a new constant.
Example Transform x = y → (P(x) ∨ P(y)) into an equi-satisfiable formula.
First-order logic theories Theory of equality TE
Axioms of TE : • ∀x.x = x • ∀x, y.x = y → y = x • ∀x, y, z.x = y ∧ y = z → x = z • for each positive integer n and n-ary function f , V ∀x1,..., xn, y1,..., yn. i xi = yi → f (x1,..., xn) = f (y1,..., yn)
Example Are the following formulas, satisfiable, unsatisfiable or valid? • x 6= y ∧ f (x) = f (y) • x = g(y, z) → f (x) = f (g(y, z)) • f (a) = a ∧ f (f (a)) 6= a • f (f (f (a))) = a ∧ f (f (f (f (f (a))))) = a ∧ f (a) 6= a
First-order logic theories Theory of equality TE
We decide satisfiability for TE using the congruence closure algorithm that computes the congruence closure of the binary relation defined by formula. Equivalence relation A binary relation R over A is an equivalence relation if: 1 ∀a ∈ A.aRa (reflexive)
2 ∀a1, a2 ∈ A.a1Ra2 → a2Ra1 (symmetric)
3 ∀a1, a2, a3 ∈ A.a1Ra2 ∧ a2Ra3 → a1Ra3 (transitive).
Which of the following are equivalence relations: ≡n over Z, ≥ over N, |x| = |y| over R?
First-order logic theories Congruence relations
Congruence relation A congruence relation R is an equivalence relation over a set A equiped with a set of functions F = {f1,..., fn}, such that, for every f ∈ F: ^ ∀a1,..., an, b1,..., bn. ai Rbi → f (a1,..., an) R f (b1,..., bn) i
Are the relations = over N, ≡n over Z and |x| = |y| over R, together with the successor function, congruence relations? Equivalence and Congruence classes For every a ∈ A, the equivalence class of a under R is the set:
[a]R = {b ∈ A : aRb}.
In a congruence relation, this set is called the congruence class.
First-order logic theories Equivalence and Congruence closures
The equivalence closure RE of a binary relation R over A is the smallest equivalence relation that includes R. That is, RE is the the equivalence relation satisfying the following: E 1 R ⊆ R E 2 for every other equivalence relations S: R ⊆ S → R ⊆ S
Similarly one defines the congruence closure RC of a binary relation R over A as the smallest congruence relation that includes R.
Example Consider the set A = {1, 2, 3} and function f such that: f (1) = 2, f (2) = 3, f (3) = 3. What is the congruence closure of R = {(1, 2)}?
First-order logic theories Satisfiability using Congruence Relations
The satisfiability of a TE formula is defined in terms of the congruence closure over the subterm set SF of the formula, that is, the set of all subterms of F .
Consider the TE formula:
F : s1 = t1 ∧ · · · ∧ sm = tm ∧ sm+1 6= tm+1 ∧ · · · ∧ sn 6= tn
Then considere the relation RF on SF , RF = {(si , ti ) | i ∈ {1,..., m}}
Theorem
F is satisfiable if the congruence closure ∼ of RF satisfies si 6∼ ti , ∀i ∈ {m + 1,..., n}.
First-order logic theories Congruence Closure Algorithm
Algorithm
Consider a formula F in TE and the subset set SF .
• Construct the congruence closure ∼ of SF .
• If si ∼ ti for any i ∈ {m + 1,..., n}, F is unsatisfiable, otherwise F is satisfiable.
Let us represent ∼ as a set of congruence classes: if t1 and t2 are in the same set, then t1 ∼ t2, otherwise t1 6∼ t2.
We start by determining the subterm set SF , and ∼ by placing each subterm in a separate set.
If s1 = t1, then merge the classes of s1 and t1.
First-order logic theories Example
For F : f (a, b) = a ∧ f (f (a, b), b) 6= a, consider the initial congruence classes:
{{a, f (a, b)}, {b}, {f (f (a, b), b)}}
From a ∼ f (a, b) and b ∼ b we get
{{a, f (a, b), f (f (a, b), b)}, {b}}
Since a and f (f (a, b), b) are in the same class, we have a ∼ f (f (a, b), b)
This contradicts f (f (a, b), b) 6= a.
First-order logic theories Example
How about F : f (f (f (a))) = a ∧ f (f (f (f (f (a))))) = a ∧ f (a) 6= a?
• What is the subterm set SF ? • We get the initial set of congruence classes:
{{a}, {f (a)}, {f 2(a)}, {f 3(a)}, {f 4(a)}, {f 5(a)}}
• After processing f 3(a) = a one gets, by merging its classes:
{{a, f 3(a)}, {f (a)}{f 2(a)}, {f 4(a)}, {f 5(a)}}
• From f 3(a) = a, we infer using function congruence f 4(a) = f (a) e f 5(a) = f 2(a):
First-order logic theories Example
• Therefore we merge the corresponding classes:
{{a, f 3(a)}, {f (a), f 4(a)}, {f 2(a), f 5(a)}}
• From f 5(a) = a, we merge the corresponding classes:
{{a, f 2(a), f 3(a), f 5(a)}}, {f (a), f 4(a)}
• From a = f 2(a), we infer by congruence f (a) = f 3(a), thus we get {{a, f (a), f 2(a), f 3(a), f 4(a), f 5(a)}}
• Since f (a) and a are in same congruence class, this contradicts f (a) 6= a, therefore F is not satisfiable.
First-order logic theories Natural and integer numbers
First incompleteness theorem of G¨odel(1931) Any recursively enumerable theory capable of expressing elementary arithmetic cannot be simultaneously be consistent and complete. In particular, for each recursively enumerable consistent theory, that can demonstrate elementary arithmetic statements, there exists a true statement that is not provable in the theory.
• A semantic theory Th(M), where M interpretative each symbol with its mathematical symbol in the domain of interpretation, is always a complete theory. • Therefore, the semantic theories of natural and integer numbers cannot be axiomatized.
First-order logic theories Peano arithmetic TPA (1889)
The theory of Peano arithmetic TPA (1889) is a first-order approximation of the theory of natural numbers.
• Vocabulary: VPA = {0, 1, +, ×, =}
• Axioms of TPA :
• axioms of TE • ∀x.¬(x + 1 = 0) • ∀x, y.x + 1 = y + 1 → y = x • ∀x.x + 0 = x • ∀x, y.x + (y + 1) = (x + y) + 1 • ∀x.x × 0 = 0 • ∀x, y.x × (y + 1) = (x × y) + x • for every formula ϕ with FV (ϕ) = {x} ϕ[0/x] ∧ (∀x.ϕ → ϕ[x + 1/x]) → ∀x.ϕ
TPA is incomplete and undecidable (G¨odel,Turing, Post, Church), including the quantifier-free fragment (Matiyasevich, 1970).
First-order logic theories Presburger’s arithmetic TN
The theory of Presburger’s arithmetic TN is the additive fragment of the Peano theory.
• Vocabulary: VN = {0, 1, +, =} • Axioms of TN :
• axioms of TE • ∀x.¬(x + 1 = 0) • ∀x, y.x + 1 = y + 1 → y = x • ∀x.x + 0 = x • ∀x, y.x + (y + 1) = (x + y) + 1 • for every formula ϕ with FV (ϕ) = {x} ϕ[0/x] ∧ (∀x.ϕ → ϕ[x + 1/x]) → ∀x.ϕ
TN is complete and decidable (Presburger, 1929), but with double-exponential complexity.
First-order logic theories Linear integer arithmetic TZ
• Vocabulary:
VZ = {..., −2, −1, 0, 1, 2,..., −3·, −2·, 2·, 3·,..., +, −, =, >} • ..., −2, −1, 0, 1, 2,... are constants • ..., −3·, −2·, 2·, 3·,... are unary functions • +, −, =, > have the usual meaning
Relation between TN and TZ TN e TZ have the same expressiveness:
• For each formula VN there exists an equi-satisfiable formula VZ
• For each formula VZ there exists an equi-satisfiable formula VN
Therefore TZ is equally complete and decidable.
How do we decide the validity of TZ (using TN)?
First-order logic theories TZ versus TN
Consider the formula TZ ∀x, y∃z.y + 3x − 4 > −2z • For each variable v over the integers, introduce two variables vp and vn over the non-negative integers.
∀xp, xn, yp, yn∃zpzn.(yp − yn) + 3(xp − xn) − 4 > −2(zp − zn)
• Eliminate negation:
∀xp, xn, yp, yn∃zpzn.yp + 3xp + 2zp > 2zn + yn + 3xn + 4
• Eliminate > and numbers:
∀xp, xn, yp, yn∃zpzn∃u. ¬(u = 0) ∧ yp + xp + xp + xp + zp + zp = zn + zn + yn + xn + xn + xn + 1 + 1 + 1 + 1 + u
The obtained formula TN is equi-satisfiable. First-order logic theories TN versus TZ
The formula TN ∀x∃y.x = y + 1
is equi-satisfiable to the formula TZ: ∀x.x > −1 → ∃y.y > −1 ∧ x = y + 1
Exercise
Apply the algorithm that converts formulas of VZ into formulas VN equi-satisfiable to the following formula:
∀w, x.∃y, z.x + 2y − z − 7 > −3w + 4.
First-order logic theories Linear rationale arithmetic TQ
• The complete theory of the rational numbers (with addition and multiplication) is undecidable, since it can encode the property of being a natural number.
• The theory of linear arithmetic over the rationals TQ is decidable in a more efficient way than the corresponding theory in the integers.
• Vocabulary: VQ = {0, 1, +, −, =, ≥}. • Axioms: 10 (see Manna’s book - The calculus of computation).
• Rational coefficients can be expressed in TQ: the formula 5 4 2 x + 3 y ≥ 6 can be written as the formula TQ 15x + 8y ≥ 36.
• TQ is decidable and its quantifier-free fragment is decidable in an efficient way.
First-order logic theories Theory of reals TR
Surprisingly, the theory of reals TR is decidable, even in the presence of multiplication and quantifiers.
• Vocabulary: VR = {0, 1, +, ×, −, =, ≥}. • Axioms: 17 (see Manna’s book).
• TR is decidable (Tarski, 1930). • However has double exponential complexity.
First-order logic theories = Arrays TA and TA
• Arrays are modeled in logic as applicative data structures.
• Vocabulary: VA = {read, write, =} • Axioms:
• reflexivity, symmetry and transitivity of TE • ∀a, i, j.i = j → read(a, i) = read(a, j) • ∀a, i, j, v.i = j → read(write(a, i, v), j) = v • ∀a, i, j, v.¬i = j → read(write(a, i, v), j) = read(a, j) • = is only defined between elements of arrays
= • A theory TA corresponds to TA together with an axiom to capture = between arrays (extensionality)
∀a, b.(∀i.read(a, i) = read(b, i)) ↔ a = b
= The theories TA and TA are both undecidable but its quantifier-free fragments are decidable.
First-order logic theories Other theories
Binary arrays of fixed size • Model binary operations in machine language: 2n-modular operations, shift operations, etc... • The decision procedures for this theory, are based in appropriate encodings for propositional logic.
Algebraic data structures • Theories that describe data structures naturally occurring in programming, such as lists, stacks, binary trees, etc. • These theories are build over the theory of equality with non-interpreted functions and are usually decidable in an efficient way in its quantifier-free fragments.
...
First-order logic theories Combining theories
In practice, the majority of the formulas one wishes to verify need a combination of various theories. x + 2 = y → f (read(write(a, x, 3), y − 2) = f (y − x + 1) Theories involved in this formula: • equality and uninterpreted functions • arrays • arithmetic
T1 ∪ T2 The combined theory of T1 ∪ T2, T1 and T2, such that V1 ∩ V2 = {=} is given by:
• Vocabulary: V1 ∪ V2
• Axioms: A1 ∪ A2.
How to decide T1 ∪ T2 based on the decision procedures of T1 and T2? First-order logic theories Combining theories
Nelson & Oppen, 1979
The satisfiability of the quantifier-free fragment (qff) of T1 ∪ T2 is decidable if:
• the satisfiability of the qff of T1 is decidable
• the satisfiability of the qff of Ts is decidable • some technical requirements are satisfied
• One can extend algorithms to combine an arbitrary number of theories: one combines two, then one combines this algorithm with another theory, and so on. • Most of the existing methods are based on the Nelson-Oppen composition.
First-order logic theories Restrictions of Nelson-Oppen
Nelson-Oppen method imposes the following restrictions:
1 Only allows combining quantifier-free fragments 2 Only allows combining formulas without disjunctions, which is not a major limitation, since one can convert to DNF 3 Signatures can only share equality.
4 Theories T1 and T2 must be stably infinite:
A theory T is stably infinite iff every satisfiable qff formula is satisfiable in a universe of discourse with infinite cardinality
First-order logic theories Example
Consider a theory with Σ = {a, b, =} and a single axiom ∀x.x = a ∨ x = b
If one considers a universe U with more than 2 distinct elements, then there is at least one element that is not equal to a or b, thus violating the axiom.
Therefore all the models of the theory are finite, and hence the theory is not stably infinite.
The theories TE , TQ, TZ, TA, are stably infinite.
First-order logic theories Nelson-Oppen Method
Consists of two-different phases: 1 Purification: Separate formula F in T1 ∪ T2 into two formulas F1 in T1 and F2 in T2 (which are considered “pure” formulas). • F1 belongs only to T1 • F2 belongs only to T2 • F1 ∧ F2 is equi-satisfiable to F The resulting formula is not equivalent, but this is good enough for satisfiability. 2 Equality propagation: Propagate relevant equalities between theories. The equality propagation phase is defined differently in convex and non-convex theories. Convex theory In a convex theory, if a formula F implies a disjunction of equalities, then F also implies at least one of these equalities. Otherwise, the theory is non-convex.
First-order logic theories Purification method
Exhaustively apply the following to F :
1 For f (..., ti ,... ), such that f ∈ Σi , but ti is not a term in Ti , replace ti with a fresh variable z and add z = ti .
2 For P(..., ti ,... ), such that P ∈ Σi , but ti is not a term in Ti , replace ti with a fresh variable a and add w = ti .
Example
Consider the formula x ≤ f (x) + 1 in TE ∪ TQ. Because f (x) is not in TQ, one replaces it with a new variable y. The resulting purified formula is:
x ≤ y + 1 ∧ y = f (x)
First-order logic theories Examples
Consider f (x + g(y)) ≤ g(a) + f (b) in TE ∪ TQ. • The term x + g(y) is not pure, thus:
f (x + z1) ≤ g(a) + f (b) ∧ z1 = g(y)
• The term f (x + z1) is not pure, thus:
f (z2) ≤ g(a) + f (b) ∧ z1 = g(y) ∧ z2 = x + z1
• The terms g(a) and f (b) are not pure, thus:
f (z2) ≤ z3 +z4 ∧z1 = g(y)∧z2 = x +z1 ∧z3 = g(a)∧z4 = f (b)
• The term f (z2) is not pure, thus:
z5 ≤ z3+z4∧z1 = g(y)∧z2 = x+z1∧z3 = g(a)∧z4 = f (b)∧z5 = f (z2)
First-order logic theories Equality propagation
For equality propagation one needs to distinguish convex from non-convex theories. Example
Consider the formula F : 1 ≤ x ∧ x ≤ 2 in TZ. Although F implies x = 1 ∨ x = 2, it does not imply either x = 1 or x = 2 on its own.
Thus TZ is not convex. Both TQ and TE are convex.
It is easier to combine decision procedures for convex theories.
First-order logic theories Nelson-Oppen for Convex Theories
Satisfiability in T1 ∪ T2
Consider a formula F in T1 ∪ T2 (both convex).
1 Obtain F1 ∧ F2 by purification;
2 Separately run decision procedures to decide sat. of F1, F2. If either one is unsat, then F is unsatisfiable.
3 If F1 and F2 are sat, theories must exchange all implied equalities, since satisfiability of F1 and F2, does not imply satisfiability of F . For example: x + y = 2 ∧ x = 1 ∧ f (x) 6= f (y) We consider implied equalities on shared variables, that is, variables which occur both in F1 and F2.
First-order logic theories Nelson-Oppen for Convex Theories
Equality propagation • For every pair x, y of shared variables, consider the following implications:
1 F1 → x = y 2 F2 → x = y 0 • If (1) holds but (2) does not, let F2 : F2 ∧ x = y. 0 • If (2) holds but (1) does not, let F1 : F1 ∧ x = y. 0 0 • Check satisfiability of F1 and F2. • Terminate if one of the formulas becomes unsat or no new equalities can be exchanged.
Example
Decide in TE ∪ TQ the satisfiability of the formula: f (f (x) − f (y)) 6= f (z) ∧ x ≤ y ∧ y + z ≤ x ∧ 0 ≤ z
First-order logic theories Non-convex theories
• This technique does not work for non-convex theories, since a formula might imply a disjunction of equalities, but not any individual equality.
• For the following TE ∪ TZ formula: 1 ≤ x ∧ x ≤ 2 ∧ f (x) 6= f (1) ∧ f (x) 6= f (2)
Purifying will give two satisfiable formulas that do not imply any equalities, despite the original formula not being satisfiable (verify!!!). • We must also query and propagate disjunctions of equalities.
• If a formula implies x1 = y1 ∨ · · · ∨ xn = yn, create n th sub-problems where we conjoin xi = yi in i sub-problem. Return sat if any sub-problem is satisfiable, and unsat otherwise.
First-order logic theories Examples
Example
Apply the method to the TE ∪ TZ formula: 1 ≤ x ∧ x ≤ 2 ∧ f (x) 6= f (1) ∧ f (x) 6= f (2)
Example
Apply the method to the TE ∪ TZ formula: 1 ≤ x ∧ x ≤ 3 ∧ f (x) 6= f (1) ∧ f (x) 6= f (3) ∧ f (1) 6= f (2)
First-order logic theories SMT - Satisfiability Modulo Theories
The problem of Satisfiability Modulo Theories (SMT) is a variant of the satisfiability problem (SAT) for first-order logic, where the interpretation of symbols is restricted to a combination of specific theories (i.e., the problem of determining, for a theory T and a given formula ϕ, if ϕ is T -satisfiable).
Usually the SMT solvers deal with the satisfiability of FOL formulas in CNF and without quantifiers, using: • a SAT solver • “state-of-the-art” theory solvers
In the last decades the SMT procedures have evolved in a dramatic way in terms of efficiency and expressiveness.
Some SMT solvers: Z3, Yices, MathSAT, Barcelogic, CVC4, Alt-Ergo, ...
First-order logic theories The SMT-LIB repository
• A catalogue of theory declarations: semi-formal specifications of relevant theories: • Definition of the vocabulary and the meaning of the symbols of the theory • A catalogue of logic declarations: semi-formal specifications of fragments of (combinations of) theories • A logic consists of one or more theories, together with some restrictions on the type of expressions that can be used • A library of “benchmarks” • Utility tools (parsers, converters,...) • Links for documentations, solvers, etc... • See http://www.smtlib.org.
First-order logic theories