Open the simulator
if (a < b || (a >= b && c == d)) the same as if (a < b || c == d)? All three hide the same question: what follows from what. Propositional logic is the simplest tool for answering it, and the foundation of logic programming, software verification, digital circuits and a good part of artificial intelligence.
What you will learn
- Translate sentences from natural language into formulas, including the tricky ones (“only if”, “is necessary for”, “unless”).
- Read a formula using the precedence of the connectives and evaluate it under an interpretation.
- Classify formulas as valid, satisfiable or unsatisfiable, and sets of formulas as consistent or inconsistent.
- Decide whether an argument is valid with a truth table.
- Convert any formula into conjunctive normal form and clausal form.
- Prove an argument by resolution, deriving the empty clause.
How to use the simulator
The simulator’s interface is in Spanish. The table gives each control’s Spanish label.- With premises and a conclusion, the simulator says whether the argument is valid and, if it is not, gives a counterexample.
- With a single formula, it classifies it: valid, satisfiable or unsatisfiable.
- With several formulas and no conclusion, it says whether the set is consistent.
- Propositions are lowercase letters (
p,q,r,p1…). The constants true and false are writtenVandF, from the Spanish verdadero and falso.
Theory
Propositions and connectives
A proposition is the smallest piece of information that can be said to be true or false: “it is raining”, “John is a doctor”. Questions, exclamations and sentences whose truth depends on a variable (” is greater than 3”) are not propositions; the last ones belong to predicate logic. Propositions are combined with five connectives:Syntax and precedence
Well-formed formulas are built from the atomic ones (the propositions and the constants and ): if and are formulas, so are , , , and . To save brackets, connectives have a precedence, from highest to lowest: So reads . Between connectives of the same level, the leftmost one goes first: is . The simulator writes those brackets even when they are not needed, because the formula is hard to read without them.Semantics: interpretations and truth tables
An interpretation assigns true (V) or false (F) to each proposition. With different propositions there are interpretations. The value of a formula is computed with the tables of the connectives:Classifying formulas
Logical equivalence
Two formulas are equivalent, , if they have the same value under every interpretation, that is, if is valid. The most useful equivalences:Logical consequence: when an argument is valid
is a logical consequence of the premises , written , if every common model of the premises is also a model of . An argument is valid when its conclusion is a logical consequence of its premises. There are two equivalent ways to check it: The truth table uses Theorem I: look for the rows where every premise is true and check the conclusion. If it is false in any of them, that row is a counterexample and the argument is not valid. The method always works, but with propositions there are rows: with 10 there are already 1024.Conjunctive normal form and clausal form
A literal is a proposition or its negation; is its complement ( and ). A formula is in conjunctive normal form (CNF) if it is a conjunction of disjunctions of literals, such as . Each disjunction is a clause, and the set of clauses is the clausal form. The clause with no literals is the empty clause , which is unsatisfiable. Any formula can be converted to CNF in five steps, the same ones the simulator shows:Eliminate ↔
Eliminate →
Push negations inwards
Distribute ∨ over ∧
Simplify
Resolution
Resolution (Robinson, 1965) uses a single inference rule, which is very easy to automate: A pair of complementary literals is removed and what is left of the two clauses is joined: the result is the resolvent. It works because, if is false, has to be true, and if is true, has to be true; either way, holds. To prove an argument, you work by refutation, using Theorem II:- Convert the premises and the negation of the conclusion to clausal form.
- Resolve pairs of clauses and add the resolvents.
- If the empty clause appears, the set is inconsistent and the argument is valid.
- If every possible pair has been resolved without reaching , the set is consistent and the argument is not valid.
Worked examples
Example 1 · The umbrella, with a truth table
Example 1 · The umbrella, with a truth table
Example 2 · The umbrella, by resolution
Example 2 · The umbrella, by resolution
- (premise 1)
- (premise 2)
- (premise 2)
- (negated conclusion)
- , resolving 1 and 2 on
- , resolving 3 and 5 on
- , resolving 4 and 6 on
Example 3 · Clausal form with a biconditional
Example 3 · Clausal form with a biconditional
Example 4 · An invalid argument
Example 4 · An invalid argument
Example 5 · Classifying a formula
Example 5 · Classifying a formula
Try it in the simulator
Find the counterexample
Three methods, one result
The mirror principle
Consistent or not
Precedence matters
Common mistakes
- Translating “p only if q” as . It is .
- Thinking that is false when is false. It is only false when is true and is false.
- Confusing satisfiable with valid. A formula being true in some row does not make it a tautology.
- Forgetting to negate the conclusion before resolving. Resolving with instead of proves nothing.
- Resolving on two pairs at once. and do not give : each resolution step removes a single pair, and here any resolvent is a tautology.
- Distributing the wrong way. For CNF you distribute over , not over (that gives the disjunctive normal form).
Limitations
Propositional logic cannot talk about objects or their properties. “All men are mortal; Socrates is a man; therefore Socrates is mortal” is a valid argument that cannot be proved here: it needs the quantifiers (, ) of predicate logic. Besides, deciding whether a formula is satisfiable (the SAT problem) is NP-complete: no known method does it in polynomial time. Truth tables grow as and resolution can generate a huge number of clauses. The simulator draws tables of up to 7 propositions and stops at 3000 clauses. Even so, modern SAT solvers handle industrial problems with millions of variables.A bit of history
Aristotle studied syllogisms in the 4th century BC, but logic as a calculus starts with George Boole, who in 1854 treated propositions with the rules of algebra. Gottlob Frege gave the first complete formal system in 1879. In 1935 Gerhard Gentzen proposed natural deduction, which mimics how people reason, and in 1965 John Alan Robinson invented resolution, designed for machines to reason. It led to the Prolog language (1972), which runs programs by resolving Horn clauses.Frequently asked questions
What is the difference between ⊨ and ⊢?
What is the difference between ⊨ and ⊢?
Why does anything follow from inconsistent premises?
Why does anything follow from inconsistent premises?
What is a Horn clause?
What is a Horn clause?
Is this useful for simplifying conditions in a program?
Is this useful for simplifying conditions in a program?
a < b and = c == d, the condition a < b || (a >= b && c == d) is , which is equivalent to . Type into the simulator and you will see it is valid.How does it relate to Boolean algebra?
How does it relate to Boolean algebra?