Lecture 1: Logical Foundations Zak Kincaid January 13, 2016 Logics have two components: syntax and semantics Syntax: defines the well-formed phrases of the language. given by a formal grammar. Typically Semantics: defines the meaning of each phrase. The semantics of a logic are defined by developing a class of structures which can be used to interpret each phrase. 1 Propositional Logic 1.1 Syntax of propositional logic A propositional signature is a set of atomic propositions P = {p, q, r,..}. The syntax of propositional logic is given by the following calculus. A judgement ϕ : Formula(P ) should be read ϕ is a well-formed propositional formula over the signature P. true : Formula(P ) false : Formula(P ) p : Formula(P ) p P ϕ : Formula(P ) ϕ : Formula(P ) ϕ : Formula(P ) ψ : Formula(P ) ϕ ψ : Formula(P ) ϕ : Formula(P ) ψ : Formula(P ) ϕ ψ : Formula(P ) 1
The following OCaml data type encapsulates the above definition: type a formula = True False Proposition of a Not of ( a formula) Normal forms for propositional formulas: And of ( a formula) * ( a formula) Or of ( a formula) * ( a formula) Negation normal form if negation is only applied to propositions. For example, (p q) p is in negation normal form, (p q) is not. Conjunctive normal form if it is a conjunction of clauses. A clause is a disjunction of literals, and literal is either a proposition or a negated proposition. There is an exponential blow-up incurred when computing CNF. For example, p (q r) ( s r t) is in CNF. Most SAT solvers operate on CNF formulas. Given an (arbitrary) input formula ϕ, it is possible to compute an equi-satisfiable CNF formula of slize linear in ϕ (Tseytin transformation). Disjunctive normal form if it is a disjunction of cubes. A cube is a conjunction of literals. There is an exponential blow-up incurred when computing DNF. For example, p (q r) ( s r t) is in CNF. 1.2 Semantics of propositional logic Definition 1.1 (Interpretation). An interpretation over a propositional signature P is a function M : P {true, false}. Every propositional formula is a statement about propositional interpretations. The statement may or may not hold in a given interpretation, we write M = ϕ ( M satisfies ϕ, or M is a model of ϕ ) if the statement ϕ holds in the interpretation M. The precise meaning of this relationship is as follows: M = true 2
M = p M(p) = true M = ϕ M = ϕ M = ϕ ψ M = ϕ and M = ψ M = ϕ ψ M = ϕ or M = ψ The following OCaml function encapsulates this definition: let rec eval m phi = match phi with True -> true False -> false Proposition p -> m p Not psi -> not (eval m psi) And (psi, psi ) -> (eval m psi) && (eval m psi ) Or (psi, psi ) -> (eval m psi) (eval m psi ) Definition 1.2. Let P be a propositional signature, and let ϕ be a propositional formula over P. If M is an interpretation over P such that M = ϕ, then we say that M is a model of ϕ. Examples: p q has 3 models of over the signature {p, q}: 1. {p true, q true} 2. {p true, q false} 3. {p false, q false} If ϕ has a model, then ϕ is satisfiable. Examples: p q p q r p p If every interpretation is a model of ϕ, then ϕ is valid (or, ϕ is a tautology). Examples: p p (law of the excluded middle) 3
((p q) p) p (Peirce s law) Boolean satisfiability problem: Given a propositional formula ϕ, is ϕ satisfiable? This problem is NP-complete (Cook s theorem, [Cook, 1971]) but there are tools (see http://www.satcompetition.org/) and algorithms (DPLL [Davis and Putnam, 1960, Davis et al., 1962], local search [Selman et al., 1992]) for solving it which are efficient in practice. 2 First-order logic 2.1 Syntax of first-order logic Definition 2.1 (First-order signature). A (single-sorted) first-order signature is a triple Σ = F, R, ar where F is a set of function symbols, R is a set of relation symbols, and ar : F R N maps each symbol to its arity. We will sometimes use a short-hand to define signatures. We write a signature as two lists (separated by a semi-colon), where the first list gives function symbols and their arity, and the second list gives relation symbols and their arity. For example: (f/2, c/0; P/1, Q/2) denotes the signature {f, c}, {P, Q}, ar, where ar(f) = 2, ar(c) = 0, ar(p ) = 1, and ar(q) = 2. Example 2.1. The signature of linear integer arithmetic Σ LA is We can define some useful shorthand: (+/2, /1, 0/0, 1/0; </2, =/2) For any integer n and any term t, we can write n t to denote the term if n is positive, and if n is negative. t + t + + t }{{} n times (t } + t + {{ + } t) n times 4
For any integer n, we can use n to denote the term n 1 We can use s t to denote formula s = t s < t... The syntax of first-order logic over a given signature Σ is defined by the following calculus. There are two types of judgements, corresponding to the syntactic categories of terms and formulas. The judgement t : Term(Σ) is read as t is a well-formed term over Σ, and ϕ : Formula(Σ) as ϕ is a well-formed formula over Σ. v : Term(Σ) t 1 : Term(Σ)... t ar(f) : Term(Σ) f(t 1,..., t ar(f) ) : Term(Σ) t 1 : Term(Σ)... t ar(r) : Term(Σ) r(t 1,..., t ar(r) ) : Formula(Σ) false : Formula(Σ) ϕ : Formula(Σ) ϕ : Formula(Σ) true : Formula(Σ) ϕ : Formula(Σ) ψ : Formula(Σ) ϕ ψ : Formula(Σ) ϕ : Formula(Σ) v.ϕ : Formula(Σ) ϕ : Formula(Σ) ψ : Formula(Σ) ϕ ψ : Formula(Σ) ϕ : Formula(Σ) v.ϕ : Formula(Σ) For any formula ϕ (term t), we use fv(ϕ) (fv(t)) to denote the set of free 5
variables of ϕ (t). Formally, fv(v) {v} fv(f(t 1,..., t n )) fv(t 1 ) fv(t n ) fv(true) fv(false) fv( ϕ) fv(ϕ) fv(ϕ ψ) fv(ϕ) fv(ψ) fv(ϕ ψ) fv(ϕ) fv(ψ) fv( v.ϕ) fv(ϕ) \ {v} fv( v.ϕ) fv(ϕ) \ {v} Definition 2.2. A formula ϕ : Formula(Σ) is: A sentence if it has no free variables (fv(ϕ) = ) Ground if it is a sentence and it is free of quantifiers Conjunctive if it is ground and free of disjunction 2.2 Semantics of first-order logic Definition 2.3 (Structure). Let Σ = F, R, ar be a first-order signature. A Σ-structure M consists of a set U M (the domain or universe of M), along with a function f M : U } M {{ U M } U M ar(f) times for each function symbol f F, and a relation for each predicate symbol P R. P M U M U M }{{} ar(p ) times Given a structure M and a set of variables V, a valuation is a function ρ : V U M. 6
The semantics of terms is given by a function t (M, ρ) which maps a term t, a structure M, and a valuation ρ to a value in U M : v (M, ρ) = ρ(v) f(t 1,...t n ) (M, ρ) = f M ( t 1 (M, ρ),..., t n (M, ρ)) Like propositional logic, the semantics of formulas is given by a satisfaction relation =. However, since formulas may have free variables (which do not have a defefined interpretation withinin a structure), the left hand side of the satisfaction relation also includes a valuation. So M, ρ = ϕ should be thread that M satisfies ϕ when the free variables in ϕ are interpreted according to ρ. If ϕ has no free variables, we may omit ρ. Formally, the satisfaction relation is defined as follows: M, ρ = P (t 1,..., t m ) ( t 1 (M, ρ),..., t m (M, ρ)) P M M, ρ = ϕ M, ρ = ϕ M, ρ = ϕ ψ M, ρ = ϕ and M, ρ = ψ M, ρ = ϕ ψ M, ρ = ϕ or M, ρ = ψ M, ρ = v.ϕ m U M.M, ρ[v m] = ϕ M, ρ = v.ϕ m U M.M, ρ[v m] = ϕ 2.3 Sequent calculus Question: Given a first-order formula ϕ, how can we be assured that ϕ is valid? For propositional logic, we could just enumerate all interpretations and check that each one satisfies ϕ. For first order logic, this is impossible there are infinitely many stuctures! One answer to this question is to define a proof calculus, which is a formal system for deriving new truths from old old ones. In particular, we will define a sequent calculus. A judgement of a sequent calculus is a sequent Γ ϕ, where Γ is a set of formulas and ϕ is a formula. A sequent Γ ϕ should be read as Any structure which satisfies every formula in Γ also satisfies ϕ. 7
The inference rules are as follows: Identity -R 1 Γ ϕ -R 2 Γ ψ -R Γ ϕ Γ ψ -L Γ, ϕ 1, ϕ 2 ψ ϕ ϕ Γ ϕ ψ Γ ϕ ψ Γ ϕ ψ Γ, ϕ 1 ϕ 2 ψ -L Γ, ϕ 1 ψ Γ, ϕ 2 ψ Γ, ϕ 1 ϕ 2 ψ -L Γ ϕ Γ, ϕ ψ -R Γ false Γ ϕ -R Γ ϕ[x a] Γ x.ϕ a fresh -R Γ ϕ[x t] Γ x.ϕ -L Γ, ϕ[x t] ϕ Γ, x.ϕ ψ -L Γ ϕ Γ, x.ϕ ψ a fresh Theorem 2.4 (Soundness). For any set of assumptions Γ and any formula ϕ, if Γ ϕ then Γ ϕ. Proof. By induction on the derivation of the judgement Γ ϕ. The other direction is more difficult prove, but does hold: Theorem 2.5 (Completeness, [Gödel, 1929]). For any set of assumptions Γ and any formula ϕ, if Γ ϕ then Γ ϕ. 2.4 Theories Definition 2.6 (Theory). Let Σ be a first-order signature. A Σ-theory T is a set of Σ-sentences which is closed under deduction (i.e., if ϕ T and ϕ ψ, then ψ T ). Let Σ be a first-order signature, and let A be a set of Σ-sentences. Then A generates a theory, which we call T. We say that the set A axiomatizes T. If T is axiomatized by a recursive (i.e., decidable) set of axioms, then we say that T is recursively axiomatizable. Example 2.2. The theory of partial orders (over the signature ( ; /2)) has three axioms: Reflexivity: a.a a 8
Transitivity: a. b. c.(a b b c) a c Anti-symmetry: a. b.a b b a A theory T is decidable if there is a procedure which decides membership in T. As nice as it would be to pick either recursive or decidable and stick to it, nobody says decidably axiomatizable or recursive theory. Exercise 2.1. Let T be a recursively axiomatizable theory. Prove that: 1. Proof checking is decidable. 2. T is recursively enumerable (semi-decidable). Some examples of decidable theories: Equality logic Linear rational/integer/mixed arithmetic Bitvector arithmetic The ground fragment of some theories is decidable (i.e., there is a procedure which decides membership in the theory, but only for ground (quantifierfree) formulas): The theory axiomatized by Linear arithmetic with uninterpreted function symbols. A formula ϕ is T -satisfiable if there is some model of T which is a model of ϕ. A set of formulas Γ T -entails a formula ϕ, written Γ = T ϕ, if every model T that satisfies all formulas in Γ satisfies ϕ as well. Ground T -satisfiability problem: determine whether a given ground formula is T -satisfiable. Like SAT, SMT is intractable in theory, there but there are tools (see http://www.smtcomp.org/) and algorithms (DPLL(T )) which work well in practice. 9
References [Cook, 1971] Cook, S. A. (1971). The complexity of theorem-proving procedures. In Proceedings of the Third Annual ACM Symposium on Theory of Computing, STOC 71, pages 151 158, New York, NY, USA. ACM. [Davis et al., 1962] Davis, M., Logemann, G., and Loveland, D. (1962). A machine program for theorem-proving. Commun. ACM, 5(7):394 397. [Davis and Putnam, 1960] Davis, M. and Putnam, H. (1960). A computing procedure for quantification theory. J. ACM, 7(3):201 215. [Gödel, 1929] Gödel, K. (1929). Über die Vollständigkeit des Logikkalküls. PhD thesis, University Of Vienna. [Selman et al., 1992] Selman, B., Levesque, H., and Mitchell, D. (1992). A new method for solving hard satisfiability problems. In Proceedings of the Tenth National Conference on Artificial Intelligence, AAAI 92, pages 440 446. AAAI Press. 10