Logic for Computer Science Transparency No. 1-1 Chapter 1 Introduction Cheng-Chia Chen.

23
Logic for Computer Science Transparency No. 1-1 Chapter 1 Introduction Cheng-Chia Chen
  • date post

    18-Dec-2015
  • Category

    Documents

  • view

    223
  • download

    2

Transcript of Logic for Computer Science Transparency No. 1-1 Chapter 1 Introduction Cheng-Chia Chen.

Logic for Computer Science

Transparency No. 1-1

Chapter 1

Introduction

Cheng-Chia Chen

Logic for Computer Science

Transparency No. 1-2

Introduction

• What is logic ?

• some inadequate definitions of logic

• Why studying logic ?

• Basic terms used in the discussion of logic

Proposition, inference, premise, conclusion, argument...

• Elements of a logic

• A glimpse of the simple formal logic: propositional logic

Logic for Computer Science

Transparency No. 1-3

What is logic ?

What is logic ?

Logic is the study of the methods and principles used to distinguish between good(correct) from bad(incorrect) reasonings.

( 區辨推理形式之好壞或正確與否的方法與原則的研究 )

Logic for Computer Science

Transparency No. 1-4

Inadequate definitions of logic Logic is the science of the law of thought.

the study of psychology! logic is not a branch of psychology All reasoning is thinking, but not all thinking(mental

activity) is reasoning. Logic is the science of reasoning.

much better, but still not correct! Human reasoning is a special kind of thinking, in which inference takes place

and problems are solved.

Still a kind of mental activity and hence a part of psychologist's subject matter. Human reasoning process is extremely complex and highly emotional,

consisting of awkward trial-and-error procedures illuminated by sudden and sometimes apparently irrelevant flash of insight.

Logicians are only concerned with the correctness of the whole process of reasoning. They don't care about how the reasoning process

takes place.

Logic for Computer Science

Transparency No. 1-5

What logic is concerned

Concerns of logicians: Does conclusions reached followed from the premised used

or assumed? Do the premises provide good reasons for accepting the con

clusions ? If the premises do provide adequate grounds for affirming th

e conclusion, or if accepting the premises does warrant asserting the conclusions to be true, then we say that the reasoning is correct; o/w it is incorrect.

Central problem logic deals with: distinctions between correct and incorrect reasoning All kinds of reasonings are of interest to the logicians, but th

e special concern for its correctness is the logicians' focus.

Logic for Computer Science

Transparency No. 1-6

Why studying logic ? As a human being:

ability to make correct arguments ability to distinguish between correct and incorrect

arguments.

As a CS student: Knowledge of logic is fundamental to various fields of

computer science.

Logic for Computer Science

Transparency No. 1-7

Why Studying Logic ? Applications in CS

Hardware logic design (hardware specification and verification)

Database (formal modeling, expressiveness of query languages, relational algebra and SQL),

Algorithms (complexity and expressiveness), Computation theory (general notions of computability), Software engineering (specification and verification), Programming languages (semantics, functional programmin

g, logic programming), Applications in artificial intelligence (& semantic web):

Knowledge and problem representation: Logic can serve as a language for representing knowledge and problems of various domains.

Automated reasoning: Accompanied with an automated theorem prover corresponding to a logic, the goal of automated problem solving (by computer) can be achieved.

Logic for Computer Science

Transparency No. 1-8

Basic functions of language

• Three basic functions of language– informative(declarative):

» used to communicate information (and misinformation)

» i.e., used to describe the world.

» formulate and affirm (or deny) propositions

» to present arguments

» include true or false propositions.

– expressive:

» used to express feelings, emotions, attitudes etc.

» e.g., poetry.

– directive:

» e.g., command and request

» to cause (or prevent) overt actions

» give me a book!; x <- x+1.

Logic for Computer Science

Transparency No. 1-9

Basic terms used in logic• propositions

– statements; what are asserted using declarative sentences,

– always either true or false - although its truth or falsity may be unknown.

– e.g, It's raining. God exists

• c.f. sentences and propositions– Sentence is a syntactic notion and belongs to a particular language, while propos

ition is a semantic notion and is not particular to any language.

– The same propositions can be asserted by many different sentences even in a language.

– e.g., John won the election; The election was won by John.

– In different contexts, the same sentence may be used to make very different statements.

– eg., The present president was born in Taiwan.

– 1995 R.O.C => Lee, the sentence expresses a true proposition !

– 1985 or not ROC => a false proposition.

Logic for Computer Science

Transparency No. 1-10

Basic terms used in logic (con't)

• inference ( 推論 ):– referring to the process by which one proposition is arrived at and affirmed on the basis

of one or more other propositions accepted as the starting point of the process.

– e.g,

– Human is mortal. ---- premise 1

– Since Confucius is a man, ---- premise 2

– Confucius is mortal. ---- conclusion inferred from premise (1) and (2)

• Argument ( 論斷 , 論證 ) :– A group of propositions of which one (the conclusion) is claimed to follow from the othe

rs (the premises) which are regarded as providing support for the truth of that one.

• Premises:– Propositions that are assumed or asserted in an inferences or argument for reaching a c

onclusion.

• Conclusion:– Propositions that are concluded in an inference arguments.

Logic for Computer Science

Transparency No. 1-11

Elements of a logic• Elements of a logic

– vocabulary and language» providing basic vocabulary for expressing "What are to be asserte

d".– syntax:

» characterizing well-formed expressions (WFF) for expressing propositions

– axiomatics: (or called calculus)» methods for specifying all valid arguments or reasonings» usually consists of inference rules and axioms» different styles of specifications

• Hilbert-style calculus; natural deduction; sequent calculus, tableau methods, resolution ...

– semantics:» used to make precise that a proposition is true (or false) and that a

n inference rule is valid etc.– decidability and complexity analysis

» determining if the logic under discussion is decidable and, if yes, what its computational complexity is.

Logic for Computer Science

Transparency No. 1-12

Elements of a logic (cont'd)

– automated proving methods

» development of efficient methods for automated/semi-automated theorem proving.

• Formal logic

– The study of logic in which all elements of logic are treated precisely (or formally) with mathematical rigor.

– Unlike natural or programming languages, the language (and syntax) of a logic is usually very easy and deserves less attentions of logicians.

– Traditional logicians are more concerned with axiomatics, semantics and decidability of a logic.

– Computer scientists, AI researcher are also interested in the complexity and efficient proof methods of a logic.

Logic for Computer Science

Transparency No. 1-13

Example (a glimpse of propositional loic)

Propositional logic (PL) the logic of 'or', 'and', 'not', 'if' (material implication) and ‘iff’ etc.

The language: 1. vocabulary L = PV LC, where

2. PV= { p1, p2,...}: a (countable) set of symbols, each called a propositional variable. used to represent propositions of domains of interest. e.g., p1 = "It is raining now"; p2 = " A1 is the father of A2"; etc.

3. (LC includes ) logical connectives: /\ (and), \/(or), ~ (not), => (if), <=> (iff; if and only if; or equivalence),

and more (XOR, NAND, NOR, 0, 1 etc.)

4. and auxiliary symbols (separator symbols) (, ).

Logic for Computer Science

Transparency No. 1-14

The syntax of PL

Well-formed formulas (WFF is a subset of L*)

1. Every propositional variable is a (well-formed) formula.

2. If A, B are wff, then so are (A /\ B), (A\/B), (A => B), (A <=> B) and ~A.

3. Only strings that can be obtained by a finite number of applications of rule 1 and 2 are well-formed formulas.

Examples:

1. (p1 \/ (p2 /\ p1)), 2. (p1 => (p2 \/ (p3 <=> ( ~p1 /\ p2)))

3. (p1 \/ q), 4. (p1),

5. (~(p1 /\ p2) ) Problem: Which of the above strings are wffs ? Rigorously speaking, some of the above expressions are not wffs. H

owever, since syntax is not our main concern, as far as ambiguity does not arise, we do admit these as wffs.

Logic for Computer Science

Transparency No. 1-15

The semantics of PL

Interpretation: An interpretation I for L is a truth-assignment for PV, i.e., a mappi

ng from PV to the truth set {0 , 1 }. Note: The semantical content of a proposition variable in actual situa

tion is not our concern; we only care about whether it is true or false in actual situations. So, two possible different situations interpreting each propositional variable with the same truth value are abstracted in semantics by the same interpretation.

For each propositional variable p, if I(p) = 1, we say p is true; otherwise (I(p)=0), p is said to be false.

How can we extend the truth/false definition from PV to all wffs ? (Below text define the meaning of all logic connectives.)

notation: we use the symbols: I |= A to mean that the formula A is true under interpretation I. Mathematically, |= is a binary relation between interpretations and wffs

(i.e., a subset of (the set of all interpretations x wffs))

Logic for Computer Science

Transparency No. 1-16

Truth conditions of wffs in propositional logic

Definition of |= (The satisfaction relation)1. I |= p, where p is a propositional variable, if I(p) = 1.

2. I |= (A /\ B) if I |= A and I |= B.

3. I |= A \/ B if I |= A or I |= B.

4. I |= A=> B if I |= B whenever I |= A.

5. I |= A <=> B if I |= A =>B and I |= B => A

6. I |= ~A if it is not the case that I |= A.

If I |= A, we say I is a model of A.

Logic for Computer Science

Transparency No. 1-17

logical consequence relation

Logical consequence relation (|=) Given a (possibly infinite or empty) set of formulas =

{A1,A2,...,An,...} and a formula A, we say A is a logical consequence of , in symbols,

|= A, if for any interpretation I, if all formulas in are true in I, then

A is true in I, i.e., for all I, if I |= Ai for every Ai in , then I |= A. I.e, Every model of is a model of A.

notations: 1. |= A is abbreviated as A1,...,An |= A if ={A1,A2,..An} is

finite.

2. |= A is abbreviated as |= A.

Note: Both the satisfaction relation and the logical consequence relation are denoted by the same symbol |=.

Logic for Computer Science

Transparency No. 1-18

Formalization of the validity of an argument in PL

Formalization of the validity of an argument (or inference) in PL. An argument with premises A1,...,An and conclusion A is valid iff it is impossible that (I.e., there exists no case in which) A1,...,

An are all true but A is false iff for every interpretation I, if A1,...,An are true in I, then so are A. iff A is a logical consequence of A1,...,An iff A1,...,An |= A

Other notions: a formula or a set of formulas is said to be satisfiable if it has a

model. (i.e., there is an interpretation I, such that every formula is true in I.)

a formula A or a set of formulas is said to be valid if it is true in all interpretations.

note: A is valid iff |= A; {A1,...,An} is valid iff |= A1 /\A2.../\An.

Logic for Computer Science

Transparency No. 1-19

Decision problems in PL

Decision problems: The satisfiability problem (SAT):

Given an arbitrary formula A, determine if A is satisfiable (I.e., true in some interpretation).

The validity problem(VALID): Given an arbitrary formula A, determine if A is valid (I.e., true in all

interpretations). The logical consequence problem:

Given a finite set of formulas and a formula A, determine if A is a logical consequence of .

Model-checking problem: Given a formula A and an interpretation I, determine if I is a model

of A.

Note: All the above problems for PL are well known to be decidable(I.e., there exists a program for solving each problem)

Logic for Computer Science

Transparency No. 1-20

Complexity results of PL

It is known that SAT is NP-complete, the model-checking problem can be solved in polynomial time, while the other two are CoNP-complete.

(deduction theorem)

A1,...,An |= A iff A1,...,A(n-1) |= An => A

Corollary: A1,...,An |= A iff |= A1 =>(A2=>( ... (An=>A)...) If is restricted to finite sets, the binary logical consequence re

lation is interreducible to the unary validity relation, which are easier to handle.

So the concerned relation (binary |=) may now be replaced by the unary validity relation (unary |=) .

Logic for Computer Science

Transparency No. 1-21

Axiomatics for PL

While semantics deals with the meaning of wffs, axiomatics deals with how we can systematically derive valid formulas. I.e., semantics is concerned about meaning and axiomatics is concer

ned about inference. An axiom system (for PL) is a pair S = (A, R ) where

A is a subset of the set of all wffs, called the set of axioms of PL, R is a finite set { R1, R2,…,Rn} of relations among wffs, called rules of

inferences.

For each Ri, if (A1,…,Ak, A) Ri for some A1,…,Ak,A, then A is called a direct consequence of the set {A1,…,Ak} by the rule Ri.

Notes: A represent the set of wffs that we accept as valid explicitly and need

not be inferred. R is used to formalize inference rules that can be used to infer new va

lid wffs (consequence) from existing known valid formulas (premises)

Logic for Computer Science

Transparency No. 1-22

Axiom system for PL

S = (A,R): an axiom system The set of theorems of S is defined inductively as follows:

Every wff A A is a theorem of S . If A1,…,Ak are theorem of S and (A1,…,Ak,A) Ri for some Ri in R, the

n A is a theorem of S . A is a theorem of S only if it can be obtained by finite applications of st

ep 1 and 2. The set { A | A is a theorem of S } is called the theory of S. A proof of a theorem A of S is a witness of A being a theorem of S.

Formally, it is a sequence A1,…,An of wffs s.t.,

1. An = A,

2. for all i = 1,..,n, either (1) Ai is an axiom or

(2) Ai can be inferred from previous wffs by some rules, i.e.,

there are Ai1,…,Aik with j1,…,jk < i and (Aj1,…,Ajk,Ai) Rt for some Rt R.

Logic for Computer Science

Transparency No. 1-23

Soundness and completeness of a logic system

Let VAL be the set of all valid formulas of some logic L Let Th be the set of theorems of an axiom system S We say S is a sound (correct) axiomatization of L if Th VAL. (

i.e., every theorem of S is valid). We say S is a complete axiomatization of L if VAL Th. ( i.e., All

valid wffs van be proved from S ). If S is sound and complete for L we way S is an (sound and com

plete) axiom system for L. An axiom system for PL: H = (A, R) where A include all wffs of one

of the forms:1. A -> (B -> A)

2. (A-> (B -> C)) -> ((A -> B) -> (A -> C))

3. ( ~B -> ~A) -> (A -> B), and R = { MP } where

MP = { (A, A->B, B) | A , B are wffs}