Lecture 1: Logical Foundations

Report 56 Downloads 126 Views
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. Typically given by a formal grammar. • 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 )

ϕ : Formula(P ) ¬ϕ : Formula(P )

p : Formula(P )

p∈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) | And of (’a formula) * (’a formula) | Or of (’a formula) * (’a formula) Normal forms for propositional formulas: • 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 6|= ϕ • 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 7→ true, q 7→ true} 2. {p → 7 true, q 7→ false} 3. {p → 7 false, q 7→ 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 Σ = hF, R, ari 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 h{f, c}, {P, Q}, ari, 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 (+/2, −/1, 0/0, 1/0; < /2, = /2) We can define some useful shorthand: • For any integer n and any term t, we can write n · t to denote the term t| + t +· {z · · + }t n times

if n is positive, and −(t| + t +· {z · · + }t) −n times

if n is negative. 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(Σ)

t1 : Term(Σ) ... tar(f ) : Term(Σ) f (t1 , ..., tar(f ) ) : Term(Σ)

t1 : Term(Σ) ... tar(r) : Term(Σ) r(t1 , ..., tar(r) ) : Formula(Σ)

true : Formula(Σ) ϕ : Formula(Σ) ¬ϕ : Formula(Σ)

false : Formula(Σ) ϕ : Formula(Σ) ψ : Formula(Σ) ϕ ∧ ψ : Formula(Σ)

ϕ : Formula(Σ) ψ : Formula(Σ) ϕ ∨ ψ : Formula(Σ)

ϕ : Formula(Σ) ∀v.ϕ : 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 (t1 , ..., tn )) , fv(t1 ) ∪· · · ∪ fv(tn ) 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 Σ = hF, R, ari be a first-order signature. A Σ-structure M consists of a set U M (the domain or universe of M ), along with a function M fM : U · · × U M} → U M | ×·{z ar(f ) times

for each function symbol f ∈ F , and a relation M PM ⊆ U · · × U M} | ×·{z ar(P ) times

for each predicate symbol P ∈ R. Given a structure M and a set of variables V , a valuation is a function ρ : V → UM. 6

The semantics of terms is given by a function JtK(M, ρ) which maps a term t, a structure M , and a valuation ρ to a value in U M : JvK(M, ρ) = ρ(v)

Jf (t1 , ...tn )K(M, ρ) = f M (Jt1 K(M, ρ), ..., Jtn K(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 (t1 , ..., tm ) M, ρ |= ¬ϕ M, ρ |= ϕ ∧ ψ M, ρ |= ϕ ∨ ψ

⇐⇒ ⇐⇒ ⇐⇒ ⇐⇒

(Jt1 K(M, ρ), ..., Jtm K(M, ρ)) ∈ P M M, ρ 6|= ϕ M, ρ |= ϕ and 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

ϕ`ϕ

∨-R1

∨-R2

∧-R

∧-L

Γ`ϕ Γ`ϕ∨ψ

Γ`ψ Γ`ϕ∨ψ

Γ`ϕ Γ`ψ Γ`ϕ∧ψ

Γ, ϕ1 , ϕ2 ` ψ Γ, ϕ1 ∧ ϕ2 ` ψ

∀-R

∨-L

¬-L

¬-R

Γ, ϕ1 ` ψ Γ, ϕ2 ` ψ Γ, ϕ1 ∨ ϕ2 ` ψ

Γ`ϕ Γ, ¬ϕ ` ψ

Γ ` false Γ ` ¬ϕ

Γ ` ϕ[x 7→ a] a fresh Γ ` ∀x.ϕ

∃-L

∃-R

∀-L

Γ ` ϕ[x 7→ t] Γ ` ∃x.ϕ

Γ, ϕ[x 7→ t] ` ϕ Γ, ∀x.ϕ ` ψ

Γ`ϕ a fresh Γ, ∃x.ϕ ` ψ

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¨odel, 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¨odel, 1929] G¨odel, K. (1929). Uber die Vollst¨andigkeit des Logikkalk¨ uls. 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