bazele matematice ale calculatoarelor

8
Propositional logic, MFCS -2010, Mihaiela Lupea rii I Lwt LI Propositional logic 1. Syntax Logical propositions are rnodels of propositional assertions from natural language, whicl can bg "true" or "false" . Zp =Var _proposwConnectivesu{(,y} - alphabet - Var _propos : {p,, pr,...} - a set of propositional variables - Connectives = {-(negation), n (conjunction), v (clisjunction),-+ (implication),<,+ (equivatence)) ; The logical connectives are from the natural language, and their priority in the decreasinS order is the one provided above. Fr: the set of well formed formulas built using the propositional variables and thr connectives.(ex: (.p -+ -q) n(r v q <+ p) n s ) 2. Semantics of propositional logic o the aim of the semantics is to give a meaning (to assign a truth value) to the propositional formulas. o the semantic domain is the set of truth values: lF (fatse), T (true)|,which satisSi the relatioflst -F =7,-T = F . New connectives J ("nand"), J("nor"), @ ("xor,) can be defined. They have the definitions: pI q:= -(p rrq), p I q:=-(pv q), p@q ::-(p <,> q) The semantics of the connectives is provided by the following truth tables: p q -p P^q pvq p-+q peq pIq pIq p@q T T F T T T I tr F F T F F a T F F T F T F T T F T T F T F T F F T F F T T T T Remarks: - A conjunction is true only when all its components are true. - A disjunction is false only when all its components are false. - The implication p -) 4 is false only when the hypothesispis true and the conclusion a is false ("true" can't imply "false"). - The equivalence p e q is true whenp and q have the same truth value.

Upload: bogdan-maier

Post on 16-Apr-2015

364 views

Category:

Documents


1 download

DESCRIPTION

bmc UBB course

TRANSCRIPT

Page 1: Bazele matematice ale calculatoarelor

Propositional logic, MFCS -2010, Mihaiela Lupearii ILwt LI

Propositional logic

1. Syntax

Logical propositions are rnodels of propositional assertions from natural language, whicl

can bg "true" or "false" .

Zp =Var _proposwConnectivesu{(,y} - alphabet

- Var _propos : {p,, pr,...} - a set of propositional variables

- Connectives = {-(negation), n (conjunction), v (clisjunction),-+ (implication),<,+ (equivatence)) ;

The logical connectives are from the natural language, and their priority in the decreasinS

order is the one provided above.

Fr: the set of well formed formulas built using the propositional variables and thr

connectives.(ex: (.p -+ -q) n(r v q <+ p) n s )

2. Semantics of propositional logic

o the aim of the semantics is to give a meaning (to assign a truth value) to the

propositional formulas.

o the semantic domain is the set of truth values: lF (fatse), T (true)|,which satisSi

the relatioflst -F =7,-T = F .

New connectives J ("nand"), J("nor"), @ ("xor,) can be defined.

They have the definitions:pI q:= -(p rrq), p I q:=-(pv q), p@q ::-(p <,> q)

The semantics of the connectives is provided by the following truth tables:

p q -p P^q pvq p-+q peq pIq pIq p@qT T F T T T I tr F FT F F a T F F T F TF T T F T T F T F TF F T F F T T T T

Remarks:

- A conjunction is true only when all its components are true.

- A disjunction is false only when all its components are false.

- The implication p -) 4 is false only when the hypothesispis true and the conclusion a

is false ("true" can't imply "false").

- The equivalence p e q is true whenp and q have the same truth value.

Page 2: Bazele matematice ale calculatoarelor

Propositional logic, MFCS -2010, Mihaiela Lupea

Definition L: An interpretation of a formula Ll(h,p2,...,pn)eFP is a function

i : {pt, p2,..., p} --> {F ,T} that can be extended to ; : Fp -+ {F,T} using the relations:

i(-P) = -i(P) i(P n q) = i(P) ni(q)

i(p" q)=i(Dv i(q) i(p -+ q)=i(p) ->i(q)

i(P <+ q) = i(P) <> i(q)

Interpretations assign truth values to propositional variables and using the semantics of

the connectives evaluate formulas assigning to them truth values.

The truth table of a propositional formula U(h,p2,...,p)eFp corresponds to the

evaluation of the formula in all its 2n interpretations.

Definition 2 (semantic concePts)Let u (py, p2,..., p )be a propositional formula.

1. An interpretation i which evaluates the formula (J as true is called a model for U.

i:{p1,...,pn} -+ {2,tr} such thati(L\:T.

2. An interpretation i which evaluates the formula U as false is called an anti-model fot

U. i : {p1,..., p n\ -+ {7, F} such that i((D:F .

3. A formula U is called consistent (sutisfiable) if it has a model:

1i : {p1,..., pr\ + {T,F} such that r((I):T '

4. The formula tl is called volid (tautology) and we use the notation: l: U, if U is

evaluated as true in all interpretations: Yi :{p1,..., Pn\ + {T,F\,i(U) =7. All

interpretations of IJ are models for U.

I The formuta U is called inconsistent if U does not have any model, [/ is evaluated as

false in all interpretations: Vi : {p1,..., pn\ -+ {T,F\, i(U) : F'

6. The formuta tl is called contingent if tl is consistent, but is not valid'

Remarks:

o If the truth table of U contains only "T", then U is a tautology.

o If the truth table of U contains only "F", then U is an inconsistent formula.

o For a propositional formula, its models conespond to the interpretations (the table

rows) in which the formula is evaluated as true and its anti-models correspond to the

interpretations (the table rows) in which the formula is evaluated as false' ]7--

Page 3: Bazele matematice ale calculatoarelor

Propositional logic, MFCS -2010, Mihaiela Lupea

The logicul consequence notion is a generalization of the taatologynotion:

Definition 3: The formula v(h,pz,...,pn)e Fp is a rogicar consequence ofthe formuliU(pt,pz,..,pn)eFp, notation: u l: v, if vi:Fp-+{T,F)such that i(U):T, we havri(v):T.

Definition 4: The fomulas U(pt,p2,...,pn)eFp and, V(pt,p2,...,pn)eFp are logicoltlequivalent, notation: Ll = V , if they have identical truth tables.

Remark: "l:" and " = " are metasymbols used to express logical relations betweenformulas.

Example 1: Build the truth tables for the formulas:

U(p,q,r) = (-pv q) n(r v p), V(p,q,r) = (_p nr)v (q r,.r)v (q n p),

W(p,q,r) =@l Gp nd)v r gi Z(p,q,r) = p n((_Qv r) I q) .

p a r - PvQ rvp U(p,q,r) v(p,q ,r) w(p,q,r) Z(p,q,r)r1 T T T T T T T T ri2 T T F T T T T T trIJ T F T F T F tr T Fi4 T tr T T F F T

ii

tF

t5 F T T T T T Tr6

i7

F T F T F F F FF F T T T T T T F

i8 F F F T T F F T F

- We remark that only the interpretations il, 12, i5 and i7 evaluate as true the fbrmulauQt,c1,r), thus these are all the models of u. The formula uis contingent.

' i1 :{p,q,r}->{T,F} , ilQ):T, il(q):T, il(r):T and i1(U):Til:{p,q,r}-t{T,F} , |SQ):F, i5(q):T, i5(r):T and i5(U):T

- The formula W(p,q,r) is a tautology, all its 8 interpretations are also its models.- The formula Z(p,q,r) is inconsistent, it is evaluated as false in all its g interpretations.- tl : Z, because (J and Vhave identical truth tables.

- U l= -Pv Q, because in all interpretations (i 1,12,i5,17) which evaluate the formula U as

true, the formula -p v Q is also evaluated as true.

Page 4: Bazele matematice ale calculatoarelor

Propositional logic, MFCS -2010, Mihaiela Lupea

Logical equivalences:

. Simplification laws:

--LJ =[J and u -+U =T(J n-(J = F and (J v -(J =TTr,U=L/ and FvU=UU +T=T and (J-+F=-(lT ,+u =U and F -+U =TU<+T=U and LJ<>F=-(JIJ@T:-U ANd U@F=UU<+U=T and U@U=F

o Idempotency laws:

UnU=UUvU=U

o Absorption laws:

U n(UvV)=UU v (U nV)=U

o Distribution laws:

LI r,(V v Z): (U nV)v (U n Z)Uv(V ^Z):(UvV)n(LIvZ). Definition of the connectives

U-+V:-[JvVU -+V =U <> (U nV)

U <+V -(U -+V) n(V -+rJ)U <+V:(UvV)-->(U r,V)(JvV =-(-U n-V)UvV=-(J-+V_u =t_l t U(Jvv=(Lttu)t(rIr)LJvV =(U I'nI(tt Itt)

l. {- , n};s.{}};

Comutativity laws:

UnV=VnUUvV=VvU

DeMorgan laws:

-(UnV)=-(Jv-V--.(U v V) =--(J n-VAssociativity laws:

(u nV) n Z =(l n(V n Z)({J vV)v Z =U v (V v Z)

LI -+ V = -(U n-V)U +V=V<>QrvV)Lr @V = -((J --> V) v - (V -+ U)

U nV = -(-U v -V)U ,",V = -(LI -+ -V)-U =U {U(Jr,V=(UIqI(rtIr.r)(JnV=(UInT(UTtr)

sets ofconnectives such that all the other connectives can beThe following sets are minimalexpressed using them.

2. {-,v}; 3. {-, +}; +. {t};6. {O, n}; 7. {@, v}; 8. {@, +};

The principle of duality: For every logical equivalence (J =Zcontaining only tht

connectives r,A,V,t,.t,<+,8 there is another local equivalence (J'=V', where LI',V'ar<

formulas obtained from Il Vby interchanging the connectives (r.,t), (t,J),(<+,8) anc

the truth values (7, F).We can remark that some of the above laws are pairs of duul logical equivalences.

Dual connectives: ( n.v ) . ( t. J ;.1 *,o ). Dual truth values: (T,F). q

Page 5: Bazele matematice ale calculatoarelor

Propositional logic, MFCS -2010, Mihaiela Lupea

The following definitions show that

its elements from the semantic point

a set of formulas is considered as the conjunction ofof view:

Definition 5:

- The set {ur,Uz,...,Un} is called consistent if the formula u1 n u2 n ... n IJ, isconsistent: li : Fp -+ {T ,F} such that i(IJ 1n IJ2 n . . . n Un ):T.- The set {Ul,Uz,".,Un} is called inconsistent if the formula Ur ntJzn..AlJn isinconsistent: Vi : Fp -+ {7, F}, i(U1 nUz n...n(} ) = p.

- The formula V is a togical consequence of the set {Ul,U2,...,Un} of formulas, notation:fJr,fJz,...,Un l: V, if Vi:Fp -+{T,F} such that i(U1n IJzn...nUn):T, we have i(V):T.The formulas rJt,IJz,...,Un are called premises, hypotheses, facts, and V is calledconclusion.

Theorem 1: Let (Jt,(J2,...,U,,U,V bepropositional formulas.

. l: U if and only tf _t/ is inconsistent.

' u l: v if and onry tf l: U -+ v if and onry if {ry ,--v) is inconsistent.

U =V if and only tf l= j <+V .

U1,U2,...,U ,l: V if and only tf l= Ut ^Uz n...n[J, -+ V if and only i/ the set

{(J1,U 2,...,U r, -Z} is inconsistent.

Theorem 2: Let S = {Ur ,(J2,...,U,}be a set of propositional formulas.

1. ff,sis a consistent set, then vy, 1< j <n,s -{(J.,} is a consistent set.

2. rf s is a consistent set and v is a valid formula, then ^s w {v} is consistent.

3. If ,s is an inconsistent set, then yv e Fr, s v {v}is inconsistent.

4' If'sis an inconsistent set and uris valid, where 1< i <n,then.9-{ui } is inconsistent.

t,

Page 6: Bazele matematice ale calculatoarelor

Propositional logic, MFCS -2010, Mihaiela Lupea

3. Normal forms in propositional logic

Aim: to transform a formula into another equivalent formula having a cerlain character o

"normal" or "canonical" form.

Definition 6:

1. A literal is a propositional variable or its negation (ex: p,-Q,r).

2. A clause is a disjunction of a finite number of literals (ex: p,-pv q,rv qvs).

3. A cube is a conjunction of a finite number of literals (ex q,p A-Q,r ns n p).

4. The empty clause, denoted by n, is the clause without any literal and it is the onll

inconsistent clause.

5. A formula is in disjunctive normal form (DNF), if it is written as a disjunctior

of cubes: v!=, (nq1-riu) , where l, are literals.

Ex: p - DNF with one cube

p Y -Q v r - DNF with three cubes

p ^q - DNF with one cube

pv (q n r) v (-p ^rr A s) -DNF with 3 cubes

6. A formula is in conjunctive normal form (CNF), if it is written as a conjunctior

of clauses : ,r','=, (v'l'-,/u ) , where l, are literals.

Ex: p - CNF with one clause

pv -Q v r - CNF with one clause

p ^q - CNF with two clauses

' p ^(q

v r) n(-p v -r v s) - CNF with 3 clauses

Properfy: Let { 1,12...,1n } be a set of literals. The following sentences are equivalent:

a) The clause vir l, is a tautology;

b) The cube n','.1, is inconsistent;

c) The set {1t,12...,1,} of literals contains at least one pair of opposite literals

li, j e {1,..,r} such that l, = --1, "

Ex: - the clause IJ: pv qv r v -p is a tautology (U =D, p,-p are opposite literals

- the cube Y: p Aq Ar n:p iS an inconsistent formula (V=F)

It

Page 7: Bazele matematice ale calculatoarelor

Propositional logic, MFCS _2010, Mihaiela Lupea

Theorem 3:

Every propositional formula admits an equivalent cNF and an equivalent DNFNorma I iz at ion a lgo r ithm ;

on the initial formula we apply transformations which preserve the logical equivalence:stepl: The formulas of " x -) y " type are replaced by the equivalent Lorm__x v y .

The formulas of " X qs y " type are replaced by the equivalent forn(Jvy)n(-yvX).Step2:- DeMorgan laws are applied::) the negation will be only in front of

propositional variables

- Multiple negations are eliminated by the reduction rule: ____x : xStep3: The distribution laws are applied.

Theorem 4:1' A forrnula in cNF is a tautology if and only if all its clauses are tautologies.2' A formula in DNF is inconsist*t irand oniy if all its cubes are inconsistent.

Remarks

- The first part of the above theorem provides a direct method to prove that aformula is atautology.

- DNF of a propositional formula provides all the models of that formula, finding all theinterpretations that evaluate, the cubes as true.- cNF of a propositional formula provides all the anti-models of that formula, finding allthe interpretations that evaluate, one by one, the clauses as false.

Dual concepts: clause-cube, DNF_CNF.

Example 2: write the equivalent cNF of A2 (the second axiom of propositional logic).A2:((u + (v ) z)) + ((u +'t/) + ((_/ + z)): (replace _> from inside formulas)

= ((u -+ (-- It v z)) -+ ((- U v v) -+ (--u v z)): (replace the main connective _> )

='-([J +(-It v Z))v((-U vV)+ (- U v Z))=(replace both -) connectives)

= -(--U v --v v Z)v (--(-- u v v)v --(I v z) :(application ofDeMorgan laws): (U nV r', -Z)v (U n-V)v -(J v Z ___ DNF with 4 cubes

(application of distribution laws): (U v U v -U v Z) n(U v -V v -(J v Z) n(V v U v _U v Z) n

'^'(v v -v v -(J v z) n (-Z v (J v -(J v Z) n (-Z v -v v -Lr v z) --- cNF with 6 clauses

which are tautologies.Thus, according to the previous theorem, the formula A2 is a tautology . l

Page 8: Bazele matematice ale calculatoarelor

Propositional logic, MFCS -2010, Mihaiela Lupea

Example 3: Write the equivalent DNF of the formula: X:-A1:--(U -+ (t/ +U))

X:--(U +(V )U)) =-,(-Uv(--VvtJ)): Un'-(-Vvu))=U nV n'-U

We have obtained CNF (with 3 clauses) and DNF (with one cube).

DNF contains an inconsistent cube. thus X is an inconsistent formula and A1

tautology.

Example 4: Write the equivalent DNF of the formula: X: (.p ^q

-) r) -+ (p -+ r) nq

We apply the normahzatron algorithm:

X:(p ^q

-) r) -+ (p+ r)n Q = -(p ^q -+ r)v (p -+ r) nq :

: -(-(p ^q)v r)v (-pvr)n q = (p nq n-r)v (-pv r) xq :

=(p ^q n-r)v (-p nq)v (r nq) --- DNF with 3 cubes

The models of X are the interpretations that evaluate one by one the cubes of DNF as true.

Cube: p AQ A-r

i1 :{p,q,r}->{T,F}, i1(p):T, i1(q):T, i1(r):F

Cube: -p Q

12 : {p,q,r} -> { T,F }, i2(p):F, i2(q):T, l2(r):T

i3 : {p,q,r}->{T,F}, i3(p):F, i3(q):T, i3(r):F

Cube: r n q

i4:{p,q,r}->{T,F}, i4(p):T, i4(q):T, i4(r):T

i5 : {p,q,r}*>{T,F}, i5(p):F, i5(q):T, i5(r):T

We remark that r2:i5. The models of X are the interpretations:i1,i2,i3,i4.

,All the other four interpretations evaluate the formula X as false.

We will transform the DNF of X to its CNF, using distribution laws:

DNF(X): (p nq n-r) v (-p ^q)v

(r nq):

=(pv -pv r) ^(pv -pv Q) n(pv qv r) ^(pv qy q) ^

n(q v -pv r) ^(qv -pv Q) n(qv qv r) ^(qv qv q) ^

n(-r y -py r) n(-rv -pv q) n(-rv qv r) n(-r v qv q):

=T nT ^(pv qv r) ^(pv q) n(qy -py r) n(qv -p) n(qv r) nq n

nT n (-r v -pv Q) nT n (-r v q):- q

We have applied the absorption law: a n(av b): a and a nT = a

is

+,v