First-Order Logic First-Order Theories

Roopsha Samanta

Partly based on slides by Aaron Bradley and Isil Dillig Roadmap

▸ Review: propositional logic ▸ Syntax and semantics of first-order logic (FOL) ▸ Semantic argument method for FOL validity ▸ Properties of FOL ▸ Overview of first-order theories Propositional logic (PL) syntax

Atom truth symbols ⊤ (“true”) and ⊥ (“false”) propositional variables �, �, �, �!, �!

Literal atom � or its negation ¬�

Formula literal or application of a logical connective to �, �!, �! ¬� “not” (negation) �! ∨ �! “or” (disjunction) �! ∧ �! “and” (conjunction) �! → �! “implies” (implication) �! ↔ �! “if and only if” (iff) PL semantics

Interpretation � : mapping of each propositional variable to a truth value

�: { � ↦ ⊤, � ↦⊥, … }

Satisfying : � evaluates to ⊤ under �, written � ⊨ �

Falsifying interpretation : � evaluates to ⊥ under �, written � ⊭ � PL semantics: inductive definition

Base Cases: Inductive Cases:

� ⊨ ⊤ � ⊨ ¬� iff � ⊭ � � ⊭ ⊥ � ⊨ �! ∨ �! iff � ⊨ �! or � ⊨ �! � ⊨ � iff � � = ⊤ � ⊨ �! ∧ �! iff � ⊨ �! and � ⊨ �! � ⊭ � iff � � = ⊥ � ⊨ �! → �! iff � ⊭ �! or � ⊨ �! � ⊨ �! ↔ �! iff � ⊨ �! and � ⊨ �!, or, � ⊭ �! and � ⊭ �! Satisfiability and Validity

� is satisfiable iff there exists � : � ⊨ �

� is valid iff for all � : � ⊨ �

Duality: � is valid iff ¬� is unsatisfiable

Procedure for deciding satisfiability or validity suffices! Deciding satisfiability

▸ SAT solvers!

▸ Basic techniques ▸ Truth table method: search-based ▸ Semantic argument method: deductive technique

▸ SAT solvers combine search and deduction Propositional Logic First-Order Logic (predicate logic/predicate calculus/ relational logic)

P ∧ � → � ∨ ¬� ∀�. � �, � → ∃�. ¬� �, �

▸ Simple, not very expressive ▸ Very expressive ▸ Decidable ▸ Semi-decidable ▸ Automated reasoning about ▸ Not fully automated satisfiability/validity Term Syntax of FOL constant, variable, or, �-ary function applied to � terms constants: �, �, � Atom variables: �, �, � ⊤, ⊥, or, � -ary functions: �, �, ℎ �-ary predicate applied to � terms � -ary predicates: �, �, � Literal atom or its negation logical connectives: ¬, ∨, ∧, →, ↔ quantifiers: ∃, ∀ FOL formula: Literal, or, application of logical connectives to an FOL formula, or, application of a quantifier to an FOL formula Quantifiers

existential quantifier: ∃�. � � “there exists an � such that � � ” universal quantifier: ∀�. � � “for all �, � � ” !

Quantified variable Scope of quantified variable

An occurrence of a variable is bound if Closed formula: no free variables it’s in the scope of some quantifier Open formula: some free variables An occurrence of a variable is free if it’s not in the scope of any quantifier Ground formula: no variables Semantics of FOL: first-order structure �, �

▸ Universe of discourse/domain, �: ▸ Non-empty set of values or objects of interest ▸ May be finite (set of students at Purdue), countably infinite (integers) or uncountable infinite (positive reals)

▸ Interpretation, �: Mapping of variables, functions and predicates to values in � ▸ � maps each variable symbol � to some value �[�] ∈ � ! ▸ � maps each �-ary function symbol � to some function �!: � → � ! ▸ � maps each �-ary predicate symbol � to some predicate �!: � → {����, �����} Evaluation of formulas

If � evaluates to ⊤ under �, �, we write �, � ⊨ � If � evaluates to ⊥ under �, �, we write �, � ⊭ �

▸ Evaluation of terms: � � �!, … , �! = � � � �! , … , � �! ▸ Evaluation of atoms: � � �!, … , �! = � � � �! , … , � �! Evaluation of formulas: inductive definition

Base Cases: Inductive Cases:

�, � ⊨ ⊤ �, � ⊨ ¬� iff �, � ⊭ � �, � ⊭ ⊥ �, � ⊨ �! ∨ �! iff �, � ⊨ �! or �, � ⊨ �! �, � ⊨ � �!, … , �! … iff � � �!, … , �! = ���� �, � ⊨ ∀�. � iff for all � ∈ �, � � ↦ � ⊨ � �, � ⊨ ∃�. � iff there exists � ∈ �, � � ↦ � ⊨ �

�-variant of �, � that agrees with �, � on everything except the variable �, with � � = �. Satisfiability and Validity

� is satisfiable iff there exists some structure �, � : �, � ⊨ �

� is valid iff for all structures �, � : �, � ⊨ �

Duality: � is valid iff ¬� is unsatisfiable Semantic argument method for validity

Proof by contradiction: 1. Assume � is not valid 2. Apply proof rules 3. Contradiction (i.e, ⊥) along every branch of proof tree ⇒ � is valid 4. Otherwise, � is not valid Semantic argument method for validity !,! ⊨ ¬! !,! ⊭ ¬! !,! ⊭ ! !,! ⊨ !

!,! ⊨ ! ∧ ! !,! ⊭ ! ∧ ! �, � ⊨ ∀�. � !,! ⊨ ! (for any � ∈ �) !,! ⊭ ! | !,! ⊭ ! �, �[� ↦ �] ⊨ � !,! ⊨ !

�, � ⊭ ∀�. � !,! ⊨ ! → ! !,! ⊭ ! → ! �, �[� ↦ �] ⊭ � (for some fresh � ∈ �) !,! ⊭ ! | !,! ⊨ ! !,! ⊨ ! !,! ⊭ ! … �, � ⊨ ∃�. � (for some fresh � ∈ �) �, �[� ↦ �] ⊨ � !,! ⊨ ! !!,…,!! �, � ⊭ ∃�. � !,! ⊭ ! !!,…,!! (for any � ∈ �) ! ! ! ! ! !"# !"" !∈[!,!] �, �[� ↦ �] ⊭ � ! ! !,! ⊨ ! Soundness and Completeness of Proof Rules

Soundness: If every branch of semantic argument proof derives ⊥, then � is valid

Completeness: If � is valid, there exists a finite-length semantic argument proof in which every branch derives ⊥. Undecidability of FOL

A problem is decidable if there exists a procedure that, for any input: 1. halts and says “yes” if answer is positive, and 2. halts and says “no” if answer is negative (Such a procedure is called an algorithm or a decision procedure)

Undecidability of FOL [Church and Turing]: Deciding the validity of an FOL formula is undecidable

Deciding the validity of a PL formula is decidable The truth table method is a decision procedure Semi-decidability of FOL

A problem is semi-decidable iff there exists a procedure that, for any input: 1. halts and says “yes” if answer is positive, and 2. may not terminate if answer is negative.

Semi-decidability of FOL: For every valid FOL formula, there exists a procedure (semantic argument method) that always terminates and says “yes”. If an FOL formula is invalid, there exists no procedure that is guaranteed to terminate. ▸ FOL is very expressive, powerful and undecidable in general

▸ Some application domains do not need the full power of FOL

▸ First-order theories are useful for reasoning about specific applications ▸ e.g., programs with arithmetic operations over integers

▸ Specialized, efficient decision procedures! First-Order Theories

Signature Σ! : set of constant, function, and predicate symbols Axioms �! : set of closed formulas over Σ!

Axioms provide the meaning of symbols in Σ!

Σ!-formula : constructed from symbols of Σ!, and variables, logical connectives, and quantifiers

�-model : a first-order structure � = �, � such that � ⊨ � for all � ∈ �! Satisfiability and Validity Modulo �

� is satisfiable modulo � iff there exists some �-model � : � ⊨ �

� is valid modulo � (written � ⊨ �) iff for all �-models � : � ⊨ �

The theory � consists of all closed formulas that are valid modulo �

▸ How is validity modulo � different from FOL-validity? ▸ If a formula is valid in FOL, is it also valid modulo � for any �? ▸ If a formula is valid modulo � for some �, is it valid in FOL? Decidability of a theory

A theory � is decidable iff for every formula �, there is an algorithm that : 1. terminates and answers “yes” if � is valid modulo �, and 2. terminates and answers “no”, if F is not valid modulo �

Next: decidable first-order theories, and theories with decidable fragments Common first-order theories

▸ Theory of equality (with uninterpreted functions)

▸ Peano arithmetic (first-order arithmetic)

▸ Presburger arithmetic

▸ Theory of rationals

▸ Theory of arrays Theory of equality �!

Signature ▸ = binary predicate, interpreted by axioms ▸ all constant, function, and predicate symbols

Σ! ≔ =, �, �, �, … , �, �, ℎ, … , �, �, � Theory of equality �!

Axioms 1. ∀�. � = � (reflexivity) Equivalence 2. ∀�, �. (� = �) → � = � (symmetry) relation 3. ∀�, �, �. (� = � ∧ � = �) → � = � (transitivity) 4. for �-ary function symbol �, (function congruence)

∀�!, … … , �!, �!, … . �!. (⋀i �! = �!) → � �!, … … , �! = � �!, … . , �! 5. for each �-ary predicate symbol �, (predicate congruence)

∀�!, … … , �!, �!, … . �!. (⋀i �! = �!) → ((p �!, … … , �! ↔ � �!, … . , �! ) Decidability results for �!

�! is undecidable

Quantifier-free fragment of �! is (efficiently) decidable Theories with natural numbers and integers

Natural numbers ℕ = 0,1,2, … Integers ℤ = … , −2, −1, 0,1,2, …

Peano arithmetic ��� : natural numbers with addition and multiplication

Presburger arithmetic � : natural numbers with addition ℕ

Theory of integers �ℤ : integers with +, - , >

28 Peano arithmetic ���

Signature ▸ 0, 1 constants ▸ +, . binary functions ▸ = binary predicate

Σ!" = 0, 1, +, . , = Peano arithmetic ���

Axioms ▸ Includes equality axioms: reflexivity, symmetry, transitivity ▸ In addition: 1. ∀�. ¬ � + 1 = 0 (zero) 2. ∀�. � + 0 = � (plus zero) 3. ∀�. �. 0 = 0 (times zero) 4. ∀�, �. (� + 1 = � + 1) ⟶ � = � (successor) 5. ∀�, �. � + � + 1 = � + � + 1 (plus successor) 6. ∀�, �. �. � + 1 = �. � + � (times successor) 7. (� 0 ∧ (∀�. � � → �[� + 1])) → ∀�. � � (induction)

Can we express <, ≤, >, ≥ in �!" ? Decidability and completeness results for ���

Validity in �!" is undecidable

Validity in quantifier-free fragment of �!" is also undecidable [Matiyasevitch, 1970]

�!" does not capture true arithmetic [Gödel]

There are valid propositions of number theory that are not valid in �!"

Drop multiplication to get decidability and completeness! Presburger arithmetic �ℕ

Signature ▸ 0, 1 constants ▸ + binary function ▸ = binary predicate

Σℕ = 0, 1, +, = Presburger arithmetic �ℕ

Axioms ▸ Includes equality axioms: reflexivity, symmetry, transitivity ▸ In addition: 1. ∀�. ¬ � + 1 = 0 (zero)

2. ∀�. � + 0 = � (plus zero)

3. ∀�, �. (� + 1 = � + 1) ⟶ � = � (successor)

4. ∀�, �. � + � + 1 = � + � + 1 (plus successor)

5. (� 0 ∧ (∀�. � � → �[� + 1])) → ∀�. � � (induction) Decidability and completeness results for �ℕ

Validity in quantifier-free fragment of �ℕ is decidable (coNP-complete)

Validity in �ℕ is also decidable [Presburger, 1929]

�ℕ is also complete: for every closed formula �, �ℕ ⊨ � or �ℕ ⊨ ¬�

�ℕ admits quantifier elimination: for every formula �, there exists an equivalent quantifier-free formula �’ Theory of integers �ℤ Signature ▸ … , −2, −1, 0, 1, 2, … constants ▸ … , −3 ⋅, −2 ⋅, 2 ⋅, 3 ⋅, … unary functions ▸ +, − binary functions ▸ =, > binary predicates

Σℤ = … , −2, −1, 0, 1, 2, … , −3 ⋅, −2 ⋅, 2 ⋅, 3 ⋅, … , +, − , =, >

▸ Also referred to as the theory of linear arithmetic over integers ▸ Equivalent in expressiveness to Presburger arithemetic ▸ More convenient notation Theory of rationals �ℚ

Signature ▸ 0, 1 constants ▸ + binary function ▸ =, ≥ binary predicates

Σℚ = 0, 1, +, =, ≥

Can we express > in �ℚ ? Theory of rationals �ℚ

Too many axioms, won’t discuss.

Every formula valid in � is valid in � , but not vice versa ℤ ℚ Decidability results for �ℚ

Validity in �ℚ is decidable

Validity in conjunctive quantifier-free fragment of �ℕ is (efficiently) decidable Theory of arrays ��

Signature ▸ �[�] binary function “read(�,�)” ▸ �⟨� ⊲ �⟩ ternary function “write(�, �, �)”

Σ� = ⋅ ⋅ ,⋅ ⟨⋅⊲⋅⟩, = Theory of arrays ��

Axioms ▸ Includes equality axioms: reflexivity, symmetry, transitivity ▸ In addition: 1. ∀�, �, �. � = � → � � = � � (array congruence)

2. ∀�, �, �, �. � = � → �⟨� ⊲ �⟩ � = � (read-over-write 1)

3. ∀�, �, �, �. � ≠ � → �⟨� ⊲ �⟩ � = � � (read-over-write 2) Decidability results for ��

Validity in �! is not decidable

Quantifier-free fragment of �! is decidable Combination of Theories

Given theories �! and �! that have the = predicate, define combined theory �! ∪ �!:

Signature Σ! ∪ Σ!

Axioms �! ∪ �! Decision procedures for combined theories

If 1. quantifier-free fragment of �!is decidable 2. quantifier-free fragment of �!is decidable 3. and �! and �! meet certain technical requirements then quantifier-free fragment of of �! ∪ �! is also decidable. [Nelson and Oppen] Summary

▸ Review: propositional logic ▸ Syntax and semantics of first-order logic (FOL) ▸ Semantic argument method for FOL validity ▸ Properties of FOL ▸ Overview of first-order theories