Short summary of 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
int c; if(a==0) c=0; if(((b==0)&&(d!=0))||(a!=0)) c=1; System.out.println(c);contains:
Will this program compile?
int c; if(a==0) c=0; if(((b==0)&&(d!=0))||(a!=0)) c=1; System.out.println(c);
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!
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
Examples:
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)
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
What can we do in propositional logic?
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:
Definition:
Example: (¬x ∨ y ∨ z) ∧ (x ∨ ¬z)
Set notation: omit ∧ by writing the set of clauses:
{¬x ∨ y ∨ z, x ∨ ¬z}
Two methods:
works my "moving" connectives
if a connective is not in the right place:
¬((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:
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…)
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
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:
in this case, the result is the conjunction of:
result looks bigger (after converting ≡), but…
conversion increase size only linearly
no repeating doubling-size step, as in the first conversion
second conversion does not preserve equivalence, but almost
apart from the new variables, models are the same