Propositional logic

Short summary of propositional logic


Propositional logic

a formal way for representing complex statements that can be true or false

complex=statements that can be expressed in terms of a number of facts that can be true or false

representing statements + reasoning about them


Boolean formulae in Java

int c;
if(a==0)
  c=0;
if(((b==0)&&(d!=0))||(a!=0))
  c=1;
System.out.println(c);
contains:

Example of use of logic

Will this program compile?

int c;
if(a==0)
  c=0;
if(((b==0)&&(d!=0))||(a!=0))
  c=1;
System.out.println(c);

Example: initialization

int c;
if(a==0)
  c=0;
if(((b==0)&&(d!=0))||(a!=0))
  c=1;
System.out.println(c);

Compiler refuses to compile

Error: Variable c may not have been initialized

Meaning: c is only initialized within if conditional instructions; conditions might be false

May be false as far as the compiler knows!


Example: unsatisfiability of conditions

Compiler just assumes that every conditions could be false

In this case:

No way to make both a==0 and (((b==0)&&(d!=0))||(a!=0)) false at the same time


Uses of logic


Syntax

Examples:


Variables

Variables can be only true or false

Every elementary condition like a==0 is expressed by a variable, like x

No way to express what x means, just that it is a condition (something that can be true or false)


Semantics

Interpretation = evaluation of the variables

An interpretation I tells the value (true or false) of each variable

Example: I = {x=true, y=false, z=false}

Example: I' = {x=false, y=false, z=true}

Evaluation: I ⊨ F means that F is true when the variables have the values of I

If I ⊨ F, we say that I is a model of F


Reasoning

What can we do in propositional logic?


How about the example Java program?

int c;
if(a==0)
  c=0;
if(((b==0)&&(d!=0))||(a!=0))
  c=1;
System.out.println(c);

c is always initialized if (a==0)&&(((b==0)&&(d!=0))||(a!=0)) is always true

Propositional logic does not work with integers: express a==0, b==0 and d==0 by x, y and z, respectively

Is x ∧ ((y ∧ ¬z) ∨ ¬x) always true?

(yes)

not much useful in practice (just an example)

Other problems can be expressed in propositional logic:


CNF form

Definition:

Example: (¬x ∨ y ∨ z) ∧ (x ∨ ¬z)

Set notation: omit ∧ by writing the set of clauses:

{¬x ∨ y ∨ z, x ∨ ¬z}


CNF: examples


CNF: conversion

Two methods:


Equivalent conversion

works my "moving" connectives

if a connective is not in the right place:

¬
use De Morgan's laws:
  1. ¬(A∧B)=¬A∨¬B
  2. ¬(A∨B)=¬A∧¬B
and
use distributivity:
  1. A∧(B∨C)=(A∧B)∨(A∧C)
  2. A∨(B∧C)=(A∨B)∧(A∨C)

Equivalent conversion: example

¬((x∧y)∧(z∨¬(¬x∨(z∧y))))
= ¬(x∧y)∨¬(z∨¬(¬x∨(z∧y)))
= (¬x∨¬y)∨(¬z∧¬¬(¬x∨(z∧y)))
= ¬x∨¬y∨(¬z∧(¬x∨(z∧y)))
= (¬x∨¬y∨¬z) ∧ (¬x∨¬y∨¬x∨(z∧y))
= (¬x∨¬y∨¬z) ∧ ((¬x∨¬y∨¬x∨z) ∧ (¬x∨¬y∨¬x∨y))
= (¬x∨¬y∨¬z) ∧ (¬x∨¬y∨¬x∨z) ∧ (¬x∨¬y∨¬x∨y)

policy:


Equivalent conversion: size

in the example, slight increase in formula size

in general: may be exponential

(x1∧x2) ∨ (x3∧x4) ∨ (x5∧x6) ∨…∨ (xn-1∧xn)
= ( x1 ∨ (x3∧x4) ∨ (x5∧x6) ∨…∨ (xn-1∧xn) ) ∧ ( x2 ∨ (x3∧x4) ∨ (x5∧x6) ∨…∨ (xn-1∧xn) )
= repeat for x3∧x4 in both subformulae
= same for x5∧x6 in all four subformulae
=

every distribution doubles (more or less) the size of the formula

result is exponential in the number of variables
(all possible disjunctions that contains either x1 or x2 and either x3 or x4 and…)


Equisatisfiable conversion

employs the connective

A≡B = (A→B)∧(B→A)

can be expressed in terms of , and ¬

x≡(y∧z) = (x→y)∧(x→z)∧((y∧z)→x) = (¬x∨y)∧(¬x∨z)∧(¬y∨¬z∨x)
x≡(y∨z) = (x→(y∨z))∧((y∨z)→x) = (¬x∨y∨z)∧(¬y∨x)∧(¬z∨x)

conversion only needed for these two formulae


Equisatisfiable conversion: example

first push negation to literals (does not increase size)

as above (passages omitted)

¬((x∧y)∧(z∨¬(¬x∨(z∧y))))
= ¬x∨¬y∨(¬z∧(¬x∨(z∧y)))

for each subformula (apart literals), define a variable

x1 ¬z∧(¬x∨(z∧y))
x2 ¬x∨(z∧y)
x3 z∧y

resulting formula is obtained by:

  1. conjoin the original formulae and these three
  2. in all of them, replace each topmost subformula with its new variable

in this case, the result is the conjunction of:


Equisatisfiable conversion: size

result looks bigger (after converting ), but…

conversion increase size only linearly

no repeating doubling-size step, as in the first conversion


Equivalence?

second conversion does not preserve equivalence, but almost

apart from the new variables, models are the same