Logic for Computer Science/Propositional Logic
Propositional LogicEdit
Propositional logic is a good vehicle to introduce basic properties of logic. It does not provide means to determine the validity (truth or false) of atomic statements. Instead, it allows you to evaluate the validity of compound statements given the validity of its atomic components.
For example, consider the following:
- I like Pat or I like Joe.
- If I like Pat then I like Joe.
- Do I like Joe?
Accept as facts the first two statements, noting that the use of "or" here is not exclusive and thus could really be thought of as saying "I like Pat, or I like Joe, or I like them both". Do these statements imply that "I like Joe" is true? Try to convince yourself that "I like Joe" is true, and consider another line of reasoning:
- Pigs can fly or fish can sing.
- If pigs can fly then fish can sing.
- Can fish sing?
We can see that the answer is yes in both cases. The above two sets of statements can be both abstracted as follows:
- ?
Here, we are concerned about the logical reasoning itself, and not the statements. Thus, instead of working with pigs or Pats, we simply write s or s. We begin our study first with the syntax of propositional logic: that is, we describe the elements in our language of logic and how they are written. We then describe the semantics of these symbols: that is, what the symbols mean.
SyntaxEdit
The syntax of propositional logic is composed of propositional symbols, logical connectives, and parenthesis. Rules govern how these elements can be written together. First, we treat propositional symbols merely as a set of some symbols, for our purposes we'll use letters of the Roman and Greek alphabets, and refer to the set of all symbols as :
- Propositional symbols: A set of some symbols. For example
Second, we have the logical connectives:
- Logical connectives:
Note that these are not the minimal required set; they can be equivalently represented only using the single connective NOR (not-or) or NAND (not-and) as is used at the lowest level in computer hardware. Finally, we use parenthesis to denote expressions (later on we make parenthesis optional):
- Parentheses:
An expression is a string of propositional symbols, parenthesis, and logical connectives.
The expressions we consider are called formulas. The set of formulas is the smallest set of expressions such that:
- If then
- ,
- ,
- , and
- .
Another way to define formulas is as the language defined by the following context-free grammar (with start symbol ):
- , where stands for any propositional symbol
Fact 1 (Unique Readability): The above context free grammar is unambiguous.
SemanticsEdit
The function of a formula is to create meanings of statements given meanings of atomic statements. The semantics of a formula with propositional symbols is a mapping associating to each truth assignment to a truth value (0 or 1) for . (The truth values true and false can be used instead of 1 or 0, respectively, as well as the abbreviations T and F.)
The semantics are well defined due to Fact 1 (seen just above).
One way to specify semantics of a logical connective is via a truth table:
0 0 0 0 1 0 1 0 0 1 1 1
Can one always find a formula that implements any given semantics? Yes, any truth table is realized by a formula. The formula can be found as follows. "Represent" the rows where with conjunctions of the true proposition symbols and negations of the false ones. Finally write the disjunction of the results.
For example,
Conjunctions (true values only) 0 0 1 0 1 0 1 0 1 1 1 0
Corollary: Every formula is equivalent to a disjunction of conjunctions of propositional symbols or negation of propositional symbols (DNF).
Dual of DNF is CNF.
To get in CNF:
- Describe cases when is false.
- Note that is true when is false. Hence, negate using DeMorgan's laws.
There are cases when DNF (resp. CNF) is exponentially larger than the original formula. For example, for the equivalent DNF is exponential in size.
Does each truth table have a polynomial size formula implementing it? More precisely, does there exist such that every truth table with propositional symbols has a form of size ? Answer: no.
Proof: Assume there exists such . The number of truth tables for propositional symbols is . The number of formulas of size is ( propositional symbols, 4 connectives and parentheses.) Clearly, , for sufficiently large .
[TODO: exposition to explain what these definitions are and provide their context]
- Satisfaction: Satisfaction of a formula by a truth assignment . Notation: ( is true for ).
- Implication: A set of formulas implies . Notation: . implies if and only if every truth assignment that satisfies also satisfies .
Formula Classes of Special InterestEdit
- – the set of formulas that are always true (also known as tautologies). For example, are valid formulas.
- – the set of formulas that are never true (unsatisfiable).
- In between: - the set of formulas for which there exists a satisfying assignment (not unsatisfiable).
Note. .
Claim:
Claim: is NP-complete.
Proof:
- : guess a satisfying assignment, then verify that the formula is true (a satisfying assignment is a certificate).
- Hardness. graph 3-coloring (there also exists a direct proof). We reduce 3-coloring to . Let be a graph with nodes . We use propositional variables to indicate that vertex is colored with green, red, or blue. Construct as follows:
Claim: .
It is also possible to prove that directly
Claim: .
Horn ClausesEdit
Special case for which SAT is in polynomial time. Example:
A Horn clause is a disjunction of literals of which at most one is positive. There are two kinds of possible Horn clauses:
- clause has 1 positive literal
- , or
- no positive literal
Claim: For every set of Horn formulas, checking whether is satisfiable is in .
Proof Idea: Let be the subset of containing only clauses of type 1, and the subset of containing clauses of type 2. Note first that is satisfiable. To obtain a minimum satisfying assignment , start with literals from single-literal clauses and crank the rules. It now remains to check consistency of with the clauses in . To do this, it is enough to check that for each clause in , is not true for all of .
Example: Consider the set of Horn clauses:
The set of clauses of type 1 consists of the first 5 clauses, and consists of the last clause. Note that can also be written as:
The minimum satisfying assignment for is obtained as follows:
- start with
- use the first implication to infer
- use the second implication to infer
Thus, the minimum satisfying assignment makes true. This contradicts , which states that must be false. Thus, is not satisfiable.
Deductive SystemsEdit
A deductive system is a mechanism for proving new statements from given statements.
Let be a set of known valid statements (propositional formulas). In a deductive system, there are two components: inference rules and proofs.
- Inference rules
- An inference rule indicates that if certain set of statements (formulas) is true, then a given statement must be true. An inference rule is denoted as .
- Example (modus ponens):
- Proofs
A proof of from is sequence of formulas such that and for all
- Each formula , or
- There are a subset of formulas , such that is an inference rule.
If has a proof from using inference rule we write .
Properties:
- Soundness: If then (i.e., all provable sentences are true). This property is fundamental for the correctness of the deductive system.
- Completeness: If then (i.e., all true sentences are provable). This is a desirable property in deductive systems.
Natural DeductionEdit
Natural deduction is a collection of inference rules. Let denote contradiction, falsity. The following are the inference rules of natural deduction:
Rule (13) allows us to prove valid statements of the form "If then " even if we don't know the truth value of the statement (i.e., is not in the set of known valid statements). Indeed, for this rule, we start assuming is valid. If we can conclude is valid in a world where are valid, then we conclude that the relation is true, and we "release" the assumption is valid.
We now show how to apply the above inference rules.
Example: De Morgan's Law for negated or-expressions says:
Proof: By rule if we can prove and we can infer the desired result.
To prove the first direction, we use rule 13 and assume the hypothesis . Then
- (assumed)
- (assumed)
- (by rule 11)
- (by rule 5)
- (by rule 14)
- (assumed)
- (by rule 11)
- (by rule 5)
- (by rule 14)
- (by rule 1)
- (by rule 13)
We now prove the second direction.
- (assumed)
- (by rule 2)
- (by rule 3)
- (assumed)
- (assumed)
- (by rule 5)
- (by rule 16)
- (assumed)
- (by rule 14)
- (by rule 13)
Proof of Pierce's Law:
- (assumed) (1*)
- (assumed)
- (assumed)
- (by rule 5)
- (by rule 7)
- (by rule 13)
- (by assumption (1*) and rule 4)
- (by rule 5)
- (assumed)
- (by rule 14)
- (by rule 13)
Fact 2: Natural deduction is sound.
To show that natural deduction is also complete we need to introduce propositional resolution.
Propositional ResolutionEdit
Resolution is another procedure for checking validity of statements. It involves clauses, formulas and a single resolution rule.
Some terminology:
- Clause
- A clause is a propositional formula composed by disjunction of literals. For example . It is usually denoted as the set of literals, e.g. .
- The empty clause, denoted as an open box " ", is the disjunction of no literals. It is always false.
- Formula
- A set of clauses, each of them satisfiable. For example, represents the CNF formula .
- The empty formula, denoted as , is the set that contains no clauses. It is always true.
- Resolution Rule
- It is a rule that, given two clauses (containing some literal ) and (containing some literal ), allows to infer a new clause, called the resolvent of and (with respect to ).
A proof system for resolution contains a single resolution rule, where the resolvent is defined as follows. Assume and are clauses such that and , then
The smallest set of clauses containing and closed under resolution is denoted .
Example: If and , then .
It is possible to show that the resolution rule, as defined, computes a clause that can be inferred using natural deduction.
Claim: Let and be any two clauses such that and . Then .
In order to prove the validity of a statement , we will prove the negated statement is unsatisfiable. To prove unsatisfiability of a formula , we need to define the resolution refutation of the formula :
The resolution refutation tree of the formula is a tree rooted at the empty clause, where every leaf is a clause in and each internal node is computed as the resolvent of the two corresponding children.
Notice that clauses of can appear repeated as leaves. From above claim we can conclude that:
Claim: If there exists a resolution refutation tree for formula , then , that is, is unsatisfiable.
Example: The formula
has the following resolution refutation tree:
The order in which clauses are selected to compute the resolvent matters when computing the resolution refutation tree, as the following example shows: Consider the formula
Even though a resolution refutation tree may exist for , order is important when trying to build the tree. Below are two different resolution refutation trees, but only one is successful:
Properties of Propositional ResolutionEdit
Soundness: Propositional resolution is sound, that is, if there exists a resolution refutation tree for a given formula , then must be unsatisfiable.
Theorem: For any formula , if , then .
Completeness: Propositional resolution is complete, that is, if a given formula is unsatisfiable, then has a resolution refutation tree.
Theorem: For any formula , if , then .
Proof: By induction on the number of variables in .
Basis: We have one variable, say . All possible clauses of are and . If is unsatisfiable then both clauses occur, and therefore .
Induction step: Suppose the hypothesis is true for formulas with less than variables. Let be a formula with variables. Suppose ; we will show is satisfiable. Let be a variable of . Then either or (if both hold then immediately).
Assume . We define the formula as containing all clauses that do not contain and where the literal has been removed from each clause (in other words, is equivalent to the formula resulting from setting true).
Formally,
- .
First, notice that
and thus,
- .
Also, since we have that . By the induction hypothesis, is satisfiable. Then is satisfiable by an extension of the satisfying assignment of with equal true. The case is analogous.
Completeness of Natural DeductionEdit
Theorem: Let be the set of inference rules of Natural Deduction. If then .
The idea behind the proof of completeness of natural deduction is as follows. Suppose is valid (then is unsatisfiable). We then show there exists a resolution refutation for and then by applying the contradiction rule (rule 15):
we conclude can be inferred.
Proof: (Sketch) Given a formula valid under , we perform the following steps:
- Prove that is equivalent to some , where is in CNF.
- Prove that , for all .
- By completeness of resolution, if is unsatisfiable then . Therefore, and for some literal . This implies .
- Conclude that and therefore is valid.
Step (1) can be easily done by repeated application of De Morgan's laws. Step (2) can be proven using natural deduction. Finally, step (3) can be proven by induction on the number of steps to obtain . Clearly, each step can be simulated using natural deduction.
It is very likely that any algorithm for propositional resolution will take very long on the worst case (recall that checking validity of a formula is co-NP complete).
Linear Resolution and PROLOGEdit
Linear resolution is a particular resolution strategy that always resolves the most recent resolvent with a clause. The resolution refutation tree so obtained is therefore linear. It is possible to prove that, if the set of clauses are Horn clauses, there exists a linear resolution strategy for any formula. That is, linear resolution is complete for the set of Horn clauses.
The language PROLOG uses resolution on a set of Horn clauses. Each clause is called a program clause. Moreover, clauses composed by a single literal are called facts. A clause with a single negated literal is called a query. The table below shows a comparison of the different notations. In PROLOG, to query a statement , the idea is to negate the statement ( ) and to perform resolution with the set of known true statements. If a resolution refutation tree is found, the statement is implied by the program.
Example: An example of linear resolution for the formula
is shown here: