Logic for Computer Science. Lecture Notes, Study notes of Computer Science

This set of lecture notes has been prepared as a material for a logic course given ... Logical formalisms are applied in many areas of computer science.

Typology: Study notes

2021/2022

Uploaded on 08/01/2022

fioh_ji
fioh_ji 🇰🇼

4.5

(70)

814 documents

1 / 125

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Logic for Computer Science. Lecture Notes
Andrzej Szalas
College of Economics and Computer Science, Olsztyn, Poland
and
Department of Computer Science, University of Link¨oping, Sweden
http://www.ida.liu.se/andsz
February 2002
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Logic for Computer Science. Lecture Notes and more Study notes Computer Science in PDF only on Docsity!

Logic for Computer Science. Lecture Notes

Andrzej Szalas

College of Economics and Computer Science, Olsztyn, Poland

and

Department of Computer Science, University of Link¨oping, Sweden

http://www.ida.liu.se/∼andsz

February 2002

Part I

Introduction to Logics

10 CHAPTER 1. INTRODUCTION

  • knowledge representation and commonsense reasoning.

This set of lecture notes is mainly based on the books [BDRS95, BDRS98, DLSS02, Sza92, Sza95] and papers [DLS97, NOS99]. An excellent textbook on mathematical logic is [EFT94]. These sources contain a comprehensive list of the relevant literature.

1.2 Introduction to Logics

Logical formalisms are applied in many areas of computer science. The extensive use of those formalisms resulted in defining hundreds of logics that fit nicely to particular application areas. Let us then first clarify what do we mean by a logic.

Recall first the rˆole of logic in the clarification of human reasoning. In order to make the reasoning fruitful, first of all we have to decide what is the subject of reasoning or, in other words, what are we going to talk about and what language are we going to use. The next step is to associate a precise meaning to basic notions of the language, in order to avoid ambiguities and misunderstandings. Finally we have to state clearly what kind of opinions (sentences) can be formu- lated in the language we deal with and, moreover, which of those opinions are true (valid), and which are false (invalid). Now we can investigate the subject of reasoning via the validity of expressed opinions. Such an abstraction defines a specific logic.

Traditionally, there are two methodologies^1 to introduce a logic:

  • syntactically, via a notion of a proof and proof system
  • semantically, via a notion of a model, satisfiability and truth.

Both methodologies first require to chose a language that suits best a particular application. Of course we use different vocabulary talking about politics and about computer science. Moreover, we even use different linguistic tools. Logical language is defined by means of basic concepts, formulas and logical connectives or operators. Thus a syntax of the language is to be defined, so that one obtains a precise definition what are well formed sentences or formulas.

Having a language syntax defined, one knows how to “speak” correctly and does not know what do the spoken sentences mean and whether these are true or false. Thus a meaning (also called an interpretation) is to be attached to any well formed formula of the logic. The meaning is given either by the notion of provability, or satisfiability. Namely, a sentence (formula) is considered valid provided that it can be proved (syntactical approach) or it is valid in models accepted as semantical structures (semantical approach).

(^1) And it is often desirable and even necessary to follow both methodologies, assuming that they lead to compatible results.

1.3. INTRODUCTION TO PROOF SYSTEMS 11

I find the semantical approach more fundamental and consider the syntactic approach as (still extremely important) tool. Thus logic will always be presented here primarily via the underlying semantics, showing also how various types of proof systems for the logics can be constructed. We then accept the following definition of logic.

Definition 1.2.1 By a logic we shall mean triple L = 〈F, C, |=〉, where:

  • F is a set of well-formed formulas
  • C is a class of possible interpretations (models)
  • |=⊆ C × F is a satisfiability relation.

For I ∈ C and α ∈ F , if I |= α then we say that interpretation I satisfies formula α or I is a model od α. For C′^ ⊆ C and F ′^ ⊆ F , by C′^ |= F ′^ we shall mean that for any interpretation I ∈ C′^ and any formula α ∈ F ′^ we have that I |= α.

A formula is a tautology of L iff for any interpretation I ∈ C, we have that I |= α. A formula is satisfiable iff there is an interpretation I ∈ C, such that I |= α.

Another fundamental notion in logics is that of consequence. Namely, Definition 1.2.1 provides us with a meaning of a formula, but at that abstract level we still do not know what it means that a formula is a consequence of other formulas. In the following definition we clarify the concept.

Definition 1.2.2 Let L = 〈F, C, |=〉 be a logic. Then we say that a formula α ∈ F is a semantic consequence of a set of formulas F ′^ ⊆ F iff for any interpretation I ∈ C we have that

I |= F ′^ implies I |= α.

1.3 Introduction to Proof Systems

Observe that the definition of tautologies does not provide us with any tools for systematically proving that a given formula is indeed a tautology of a given logic or is a consequence of a set of formulas.

One of possible ways of providing such tools is to define suitable proof systems. Traditionally proof systems are often used to define new logic instead of defining them via semantics. Then one immediately obtains tools for proving the validity of formulas.

Hilbert-like axiomatic methods based on proof systems are accepted as a basis for formal and verifiable reasoning about both tautologies and properties of

1.3. INTRODUCTION TO PROOF SYSTEMS 13

from sets of formulas, so sequent calculus allows us to derive sequents from other sequents. Moreover, Gentzen- and Hilbert-like proofs go in opposite directions. That is to say, in Hilbert-like systems the formula to be proved is obtained in the final stage of the proof, while in a Gentzen-like proof it is a starting point of the proof. The Gentzen-like (naˆıve) proof procedure can then be formulated as follows, where formula α is to be proved valid.

Start the whole proof from sequent ∅ ⇒ {α}. If the sequent (or all other sequents obtained during derivation, if any) is (are) indecom- posable (i.e. rules are no longer applicable) then check whether all of the final sequents are axioms. If the answer is yes, then α is proved valid, otherwise it is invalid. If some sequent is decomposable then first decompose it and then repeat the described procedure.

Axioms in Gentzen-like proof systems are usually very simple. For instance, any sequent A ⇒ B such that A ∩ B = ∅ is an axiom in many proof systems for tautologies. Derivation rules, however, take the more complicated form S  B, where S is a set of sequents and B is a sequent. A rule S  B is often denoted

by

B

S

Note that Hilbert-like proof systems are easy to use while reasoning about the- ories. One has only to add specific axioms of a theory to axioms of logic and then to apply derivation rules. Many theories do have nice Gentzen-like ax- iomatizations. However, obtaining them is often not a trivial task. Moreover, implementation of Gentzen-like axiomatizations of theories raises new problems and considerably complicates the process of finding proofs.

Let us summarize the above discussion with the following definitions.

Definition 1.3.1 Let L be a logic.

  • By a sequent of logic L we mean any expression of the form A ⇒ B, where A and B are finite sets of formulas of L.
  • By a Gentzen-like proof system for logic L we mean any pair 〈GAx, G〉 such that - GAx, called a set of axioms, is any set of sequents of L, - G is any set of derivation rules of the form S  s, where S is a set of sequents of L, and s is a sequent of L.
  • We say that sequent s is indecomposable in a given Gentzen-like proof system iff s is an axiom or no rule of the system is applicable to s. A sequent is called decomposable iff it is not indecomposable.
  • By a Hilbert-like proof system for logic L we mean any pair 〈HAx, H〉 such that

14 CHAPTER 1. INTRODUCTION

  • HAx, called a set of axioms, is any set of formulas of L,
  • H is any set of derivation rules of the form A  p, where A is a set of formulas of L, and p is a formula of L.

Note that separating axioms from rules in the case of Hilbert-like proof systems is not necessary. Such a separation, however, allows us to treat both Gentzen- and Hilbert-like proof systems uniformly. Note also that axioms and derivation rules are usually given by schemes rather than by specific sequents, formulas or sets. For instance, writing p, p → q  q we always think of p and q as variables ranging over set of formulas. Thus the above scheme of rules defines (usually infinitely) many rules that can be obtained by substituting p and q with specific formulas.

Definition 1.3.2 Let P = 〈Ax, C〉 be a Gentzen (Hilbert)-like proof system for logic L. By a proof in P we mean a rooted tree labelled by sequents (formulas) such that

  • the height of the tree is finite,
  • all leaves are labelled by elements of Ax (sequents or formulas, respec- tively),
  • any node n in the tree is labelled either by an element of Ax, or by sequent (formula) s for which there is a derivation rule D  s in C with D = {t|t is a label of a son of n in the tree}.

We say that the sequent (formula) s is provable in P iff there is a proof in P with a root labelled by s.

Since we are not going to discuss here applications of Gentzen-style proofs of theories, the next definition concerns Hilbert-like proof systems only.

Definition 1.3.3 Let P = 〈HAx, H〉 be a Hilbert-like proof system for logic L. By a syntactic consequence (w.r.t. P ) of a set of formulas A we mean any formula provable in the proof system 〈HAx ∪ A, H〉. The set of syntactic consequences (w.r.t. P ) of set A is denoted by CP (A).

We conclude this section with an informal discussion of soundness and com- pleteness. As mentioned in the introduction, soundness is always the most fundamental property of any reasonable proof system. Soundness means that all proved conclusions are semantically true. In terms of procedures, one can define soundness as correctness of the procedure implementing the proof system. All the results of the procedure must then be correct. Completeness, however, means that all semantically true conclusions can be obtained as results of the procedure. In other words, soundness means that all answers given by a proof system are correct, while completeness means that all correct answers can be obtained using the proof system. As soundness is then always required, com- pleteness serves as a measure of the quality of proof systems.

16 CHAPTER 1. INTRODUCTION

Chapter 2

Propositional Calculus

2.1 Introduction

According to the methodology described in section 1.2 we first have to decide upon the language we deal with.

Propositional logic is used to investigate properties of complex sentences built from elementary sentences by using propositional connectives like negation, con- junction, disjunction, implication, etc. Whether complex sentences are true or not, depends solely on logical values of elementary sentences involved in them. For example, elementary sentence p implies elementary sentence q if and when p is false or q is true. Thus in classical propositional logic we need a language containing constants denoting truth values, a set of propositional variables that serve to represent elementary sentences, and the set of propositional connectives used to build complex sentences. The sentences (or formulas) of the logic are formed from elementary sentences by applying propositional connectives. The meaning associated with complex sentences is given by valuations of elementary sentences together with a method of calculating values of complex sentences from their components.

2.2 Syntax of Propositional Calculus

Let V 0 be a set of propositional variables (or boolean variables), i.e. variables representing truth values True, False standing for true and false, respectively. The set {True, False} is denoted by Bool. We further assume that truth values are ordered, False ≤ True, and use min(.. .) and max(.. .) to denote minimum and maximum of a given set of truth values.

We build propositional formulas (sentences) from truth values and propositional variables by applying propositional connectives ¬, ∧, ∨, →, ≡, standing for nega-

2.4. THE COMPLEXITY OF PROPOSITIONAL CALCULUS 19

Any formula can be equivalently transformed into CNF, DNF and NNF. The transformation, into CNF or DNF may exponentially increase the size of the formula, while the transformation into NNF may increase or decrease the size of the formula by a constant factor.

Algorithm 2.3.1 Input: Formula α ∈ F 0.

Output: Formula β ∈ F 0 such that β ≡ α and β is in NNF.

Algorithm: Move negation inside of the formula α using the following rules, until no rule is applicable:

sub-formula substitute by ¬True False ¬False True ¬¬γ γ ¬(α ∨ β) (¬α) ∧ (¬β) ¬(α ∧ β) (¬α) ∨ (¬β) ¬(α → β) α ∧ (¬β) ¬(α ≡ β) [α ∧ (¬β)] ∨ [(¬α) ∧ β]

2.4 The Complexity of Propositional Calculus

Theorem 2.4.1 [Cook] The problem of checking satisfiability of propositional formulas is NPTime-complete. Checking whether a formula is a propositional tautology is a co-NPTime-complete problem.

There are some special cases where the reasoning is in PTime. One of the most interesting cases is provided by the following theorem.

Theorem 2.4.2 The problem of checking satisfiability of propositional Horn clauses is in PTime.

2.5 Exercises

  1. Design an algorithm to transform a given propositional formula into an equivalent propositional formula in the CNF.
  2. Using the algorithm provided as a solution to exercise 1, transform formula (p 1 ∧ q 1 ) ∨ (p 2 ∧ q 2 ) ∨ (p 3 ∧ q 3 ) into the CNF.
  3. Find a formula size of which grows exponentially after the transformation defined by algorithm designed in exercise 1.
  4. Design an algorithm to transform a given propositional formula into an equivalent propositional formula in the DNF.

20 CHAPTER 2. PROPOSITIONAL CALCULUS

  1. Using the algorithm provided as a solution to exercise 4, transform formula (p 1 ∨ q 1 ∨ r 1 ) ∧ (p 2 ∨ q 2 ∨ r 2 ) into the DNF.
  2. Design PTime algorithms for:
    • checking the satisfiability of a formula in DNF
    • checking the validity of a formula in CNF.