23
Logic in Computer Science Transparency No. 3.1-1 Chapter 3 Propositional Logic 3.1. The syntax

Logic in Computer Science Transparency No. 3.1-1 Chapter 3 Propositional Logic 3.1. The syntax

  • View
    231

  • Download
    4

Embed Size (px)

Citation preview

Logic in Computer Science

Transparency No. 3.1-1

Chapter 3

Propositional Logic

3.1. The syntax

Propositional Logic: syntax

Transparency No. 3.1-2

Key contents

Vocabulary: Syntax:

wffs(合法句式 ) subformulas occurrences of subformulas

Semantics:(語意 ) Interpretations Truth conditions models, logical equivalence, logical

consequence validity, satisfiability.

Properties of PL0 deduction theorem, substitution theorem some equivalences functional completeness

Normal forms: CNF, DNF, [clausal forms]

Axiomatics: (公設化 ) Calculus An axiom system for PL0 Soundness(正確性 ) Completeness(完備性 ) Compactness (緻密性 )

[Proof methods: Analytic tableaux method resolution ]

Propositional Logic: syntax

Transparency No. 3.1-3

Propositional Logic PL0 (The language)

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

Vocabulary: ( = PV LC where) 1. 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.

2. (LC is ) logical connectives: 1. (and), (or), ~ (not), ∧ ∨ (if), (iff; if and only if;

or equivalence),

[2. and more (XOR, NAND, NOR, False, True etc.) if

needed ]

3. Parentheses: (, ).

Propositional Logic: syntax

Transparency No. 3.1-4

Syntax: well-formed formulas(wff)

Wff is a subset of * and is defined inductively as follows:1. Every propositional variable (also called atom) pi is a (well-f

ormed) formula.

2. If A, B are wffs, then so are (A B), (A B), (A ∧ ∨ B), (A B) and ~A.

Some wffs and some non-wffs: 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 ?

Notes:

1. We use A,B,C,… for wffs and p,q,r, for propositional variables.

Propositional Logic: syntax

Transparency No. 3.1-5

Abbreviations and conventions about wffs

Conventions: wffs are also called sentences or simply formulas. Wffs which are not atoms are called compound formulas. use A,B, C,... to represent arbitrary wffs use p, q, r,... to represent arbitrary propositional variables

Parentheses are omitted if ambiguity cannot occur. A\/B\/C abbreviates ((A\/B)\/C) precedence of connectives:

~ > > > ∧ ∨ > e.g.,

1. p q r means ((p q) r)∧ ∨ ∧ ∨2. p q ~ r ∨ ∧ p q s means ((p (q ~r)) ∨ ∨ ∧ (q ∨

s))

Propositional Logic: syntax

Transparency No. 3.1-6

Immediate subformulas and primary connecive

Def: I-sub(A) = immediate subformulas of A, and

pconn(A) = primary connective of A are defined as 1. I-sub(p) = {}, I-sub( (B @ C) ) = {B, C}, I-sub( ~B ) = {A}. 2. pconn(p) is undefined, pconn((B@C)) = @, pconn(~B) =

~.

where @ is /\, \/,-> or <->.

Any wff in I-sub(A) is called an immediate subformula of A.

Example: What about ((p->(q->r))->((p-.q)->(p->r))) ?

Theorem: [Unique readability of wffs:] Every compound wff has a unique primary connective and [a unique set of] immediate subformulas.

Propositional Logic: syntax

Transparency No. 3.1-7

Some lemmas about Wffs

1. Ever wff has the same number of ‘(‘ and ‘)’.

Pf: by structural ind.

base case: A = p is an atom: then #l(A) = 0 = #r(A).

ind. step: case 1. A = (B @C).

#l(A) = 1 + #l(B) + #l(C)

= 1 + #r(B) + #r(C) --- by ind. hyp.

= #r(A).

case 2. A = ~B. Similar to case 1.

Def: : two strings. is a prefix of iff s.t. = . is a proper prefix of iff and is a prefix of .

Propositional Logic: syntax

Transparency No. 3.1-8

some lemmas about wffs (cont’d)

2. If A is a wff and is a proper prefix of A, then either is a (possibly empty) sequence of ~ or has more left parentheses then right parentheses.

Pf: A = p. trivial. A = ~B. Suppose = ~ and B = , where .

=> (by ind. hyp) is either a seq of ~ or #l() > #r(). => is either a seq of ~ or #l() > #r(). A = (B @ C). Four cases need to be considered. 1. = ‘(‘. ok! 2. = ‘(’. where is a prefix of B. 3. = ‘(B@’. 4. = ‘(B@ ’, where is a prefix of C. qed

Corollary: If A is a wff and is a proper prefix of A, then is not a wff.

Propositional Logic: syntax

Transparency No. 3.1-9

Proof of unique readability

Pf: 1. [existence:] induction on the structure of wff A. Base case: A = p is an atom. Ok. Since A is not a compound wff. Ind. step: case 1: A = (B @ C), where @ is /\,\/,-> or <->.

Then {B, C} is a set of immediate subformulas of A, and @ is the primary connective of A.

case 2: A = ~B, then {B} is a set of immediate subformula of A and ~ is a primary connective of A. qed

2. [uniqueness:] base case: A = p. trivial. A is compound. case analysis: 1. A = ~B = ~C. => B = C. ok.

2. A = (B1 @1 C1) = (B2 @2 C2). if B1 B2, then B1 is a proper prefix of B2 or vice versa. => either B1 or B2 is not a wff.

if B1 = B2 => @1 = @2 and C1 = C2.

3. A = ~B = (C @ D). impossible! since ~ (. qed

Propositional Logic: syntax

Transparency No. 3.1-10

The Subformulas of wffs

Definition: [subformulas] For each wff A, the set sub(A) of all subformulas of A is def

ined inductively as follows: 1. If A = p, where p is a propositional variable, then sub(p)

= {p}. 2. If A = B @ C, where @ is either /\,\/,-> or , then sub(A) = sub(B) U sub(C) U {A}. 3. If A = ~B, then sub(A) = sub(B) U {A}. If B sub(A), we say B is a subformula of A. If B sub(A) but B A, we say B is a proper subformula

of A. If is a set of wffs, define sub() = U A sub(A)Ex: Find subformulas of A = ((p \/ (q /\ ~r)) -> (q \/ s)).Ex: What is the relationship between sub(A) and I-sub(A) ?

Propositional Logic: syntax

Transparency No. 3.1-11

Tree representation of wffs

Examples: (x + 3) / (2 + 1) * y ((p \/ q) /\ ~ ( ~q /\ r))

Propositional Logic: syntax

Transparency No. 3.1-12

(x + 3) / (2 + 1) *y

(x+3)/(2+1) y

(x+3) 2+1

x 3 2 1

parse tree for arithmetic expression

*

/ y

+ +

x 3 2 1

Propositional Logic: syntax

Transparency No. 3.1-13

(p \/ q) /\ ~ ( ~q /\ r)

(p \/ q) ~ ( ~q /\ r)

p (~q /\ r)q

~q r

q

Formation tree for the formula (p\/q)/\~(~q /\ r)

rootleafinternal node(immediate)predecessor(immediate)successordegree, branch [factor]n-ary treepathdepth (of a tree)level (of a node)

Propositional Logic: syntax

Transparency No. 3.1-14

Assign addresses (id codes) to nodes of a tree

(p \/ q) /\ ~ ( ~q /\ r)

(p \/ q) ~ ( ~q /\ r)

p (~q /\ r)q

~q r

q

0 1

00 0110

100 101

1000

Propositional Logic: syntax

Transparency No. 3.1-15

Formal definition of a Tree [domain]

define [n] =def {0,1,…, n-1}.

[n]* =def {0,1,…,n-1}* be the set of all n-digit strings.Any subset D of [n-1]* is a tree [domain] iff

1. D, which is the root (address) of the tree. 2. for all string x and digit i < n, xi D implies xj D for all j

< i. 3. for all string x, and for all prefix y of x, x D implies y D. note: Tree domains can be infinite sets.

Some definitions: depth(D) = max{ |x| | x D }; degree(x) = |{i | xi D}|; level(x) = |x|. arity(D) = branching(D) = max{ degree(x) | x D}. Arity(D) < 3 => binary tree domain. leaf(x) iff ?, root(x) iff ? internal(x) iff ?

Propositional Logic: syntax

Transparency No. 3.1-16

Two natural ordering on tree domains (nodes)

prefix ordering: (partial order) x,y: two nodes (or equivalently, strings) of a tree.

x <p y iff x is a proper prefix of y.

iff x is a proper predecessor of y

iff y is a proper successor of x. lexicographical ordering: (total order)

x,y: two nodes (or equivalently, strings) on a tree. x <L y iff either

1. x <p y or

2. x = z a u and y = z b v with a < b.

Note: <L corresponds to Preorder traversal of the tree. I.e.,

x <L y iff X will be traversed before y in preorder traversal of the tree.

Propositional Logic: syntax

Transparency No. 3.1-17

Some more definitions about tree domains

D: a tree domain. A path of D is a possibly infinite sequence of nodes x1, x2,

…xn, s.t. xi+1 is an immediate successor of xi for all i = 1,2,… A branch of D is a miximal path of D.Exercise: Every branch of a tree must begins at the root nod

e.

Theorem 1.4: (Konig’s lemma): If a finitely branching tree T is infinite, it has an infinite path.

pf: An infinite path x0,x1,x2,… is generated as follows:

1. let x0 = . let n = 0.

2. since xn has infinitely many successors and has only finitely many immediate successors, it must has one child which has infinitely many success

ors. let xn+1 be any such child. 3. increase n by 1, goto 2. Obviously the procedure never terminates and we can generate an infinite

path.

Propositional Logic: syntax

Transparency No. 3.1-18

subtrees and operations on trees

D: a tree domain, x : a node (place, address) of D S: a subset of D, is said to be a subtree [domain] of D at pl

ace x iff S = {y | xy D }. S is a subtree domain of D iff S ia a subtree domain of D at

some place of D. notation:

D: a tree domain, x : a node of D =>

D|x is the subtree of D rooted at place x.

example: if D is binary then left subtree of D = D|0

right subtree of D = D|1 = {x | 1x D}.

lsubtree(x) = D|x0, rsubtree(x) = D|x1.

Propositional Logic: syntax

Transparency No. 3.1-19

Operations on trees

1. substitution: D: a tree, S: a tree, x a non-root place ==>

D[x<-S] is the resulting tree obtained by substituting S for the subtree of D rooted at x, i.e.,

D[x <- S} = D - {x’y | y D|x} U {x’z | z S}, where x is the immediate predecessor of x.

2. appending: D: a tree, S: a tree, x a leaf ==> D[x/S] is the tree obtained by appending S to x [ as the uni

que immediate subtree of D, i.e.

D[x/S] = D U {xy | y in S}.

3. join: D[x:S] = D U {xy | y in S - {} }

Propositional Logic: syntax

Transparency No. 3.1-20

unlabeled trees and labeled trees

An unlabeled tree is (or can be represented as ) a tree domain.

A labeled tree is a tree in which every node is associated with a label, which can be anything of interest.

: a nonempty (label) set.

An n-ary -tree is a function T : DT --> , where

DT is a tree domain with arity < n+1.

Example: A formula tree is a Binary Wff-tree T:DT-> Wff where DT

is a binary tree domain.

Propositional Logic: syntax

Transparency No. 3.1-21

Formation trees for wffs Def 2.2: A formation tree is a finite binary wff-tree T:DT-> Wff, whose nodes

are labeled with wffs. the labeling satisfies the following conditions: for all node d in DT, 1. T(d) = p is an atom => d is a leaf. 2. T(d) = (A @ B), => d has two immediate successors d0 and d1 and T(d0) = A and T(d1) = B. 3. T(d) = ~A => d has one immediate successor d0 and

T(d0) = A. A formation tree for a wff A is a formation tree TA with TA() = A.Def2.5: 1. depth of a wff: depth(A) = depth of the formation tree for A.

2. support(A) = the set of atoms appearing in A.

Exercise: give an inductive definition for the depth and support of a wffExample: What is the formation tree for (~(A/\B)->C) ?Theorem 2.4: Every wff has a unique formation tree for it.pf: left as an exercise.

Def: For each wff A, let its formation tree be the unique tree TA: D

A-> sub(A) with TA() = A.

Propositional Logic: syntax

Transparency No. 3.1-22

Occurrence and subformulas

Each subformula B of a wff A may occur many times: Ex: In A = ( p /\ q) \/ (~p -> (p /\ q)), the subformula (p /\ q) occurs twice, one at place 0 and on

e at 11 at the formation tree TA for A. (i.e., TA(1)=TA(11) = (p /\ q)

p occurs ? times, and ~p occurs ? time. Definition: A: a wff, B: a wff formula.

A subformula occurrence of B in A is a subtree rooted at place x in the formation tree TA for A s.t. TA(x) = B. Namely we can identify a subformula occurrence as a subtree of A.

Sometimes we may need to distinguish between subformulas and occurrences of subformulas.

Propositional Logic: syntax

Transparency No. 3.1-23