Logic and Constraint Reasoning
Logic and Propositional Inference
Why logic is useful
Consider the constraints
and
Adding the equations eliminates X2:
so X1=7. A search algorithm could try possible values for both variables until it found a satisfying assignment, but algebra uses the equations’ structure to reach the answer directly. This illustrates a broader idea: inference can exploit structure in a problem to derive answers more efficiently than searching through possibilities.
Logic provides a formal way to represent facts and derive consequences from them. It is especially valuable when a system needs to combine information and answer questions by reasoning, rather than relying only on superficial patterns.
Logic among modeling approaches
A general AI workflow connects modeling, inference, and learning:
Modeling represents a problem in a form an algorithm can use.
Inference uses a model to answer a question.
Learning uses data or experience to construct or improve a model.
Different modeling approaches lead to different kinds of inference:
State-based models represent states as nodes and actions as transitions. Search problems seek paths, while Markov decision processes and games seek policies or strategies.
Variable-based models represent variables and constraints or factors over those variables. Constraint satisfaction problems seek assignments that satisfy constraints, and Bayesian networks support probabilistic queries.
Logic-based models represent information using formulas and derive consequences using inference rules.
Logic is highly expressive: a short formula can describe many possible situations at once. Its traditional limitations are that classical logic is deterministic, so it does not naturally represent uncertainty, and rule-based knowledge can be difficult to acquire from large amounts of data. Probability and machine learning address these limitations in different ways. The central strength of logic remains its ability to express complex relationships precisely and compactly.
Languages, syntax, semantics, and inference
Natural language is expressive but can be ambiguous. For example:
A dime is better than a nickel.
A nickel is better than a penny.
Therefore, a dime is better than a penny.
This reasoning appears valid because “better than” is being used consistently. But consider:
A penny is better than nothing.
Nothing is better than world peace.
Therefore, a penny is better than world peace.
The words “nothing” and “better” can be interpreted in different ways, so the conclusion does not follow reliably. Formal languages help prevent this kind of ambiguity.
A logical language is formal, because its valid expressions are precisely defined, and declarative, because its expressions state what is the case rather than specifying a sequence of actions to perform.
A logic has three essential components:
Syntax specifies which expressions are grammatically valid.
Semantics specifies what those expressions mean.
Inference rules specify how to derive new expressions from existing ones while preserving meaning.
Syntax and semantics are distinct. The expressions 2+3 and 3+2 have different syntax but the same meaning in ordinary arithmetic. Conversely, the expression 3/2 has the same syntax in different arithmetic systems, but it can have different meanings: integer division may yield 1, while real-number division yields 1.5.
A precise account of a language requires both its syntax and its semantics. The symbols alone do not determine what an expression means.
Propositional logic: syntax
Propositional logic is built from propositional symbols, also called atomic formulas. Each symbol represents a statement that can be true or false. Examples include A, B, and C, or named propositions such as Rain.
Logical connectives combine formulas:
Negation: ¬F, meaning “not F”
Conjunction: F∧G, meaning “F and G”
Disjunction: F∨G, meaning “F or G”
Implication: F→G, meaning “if F, then G”
Biconditional: F↔G, meaning that F and G have the same truth value
Formulas are defined recursively:
Every propositional symbol is a formula.
If F and G are formulas, then ¬F, F∧G, F∨G, F→G, and F↔G are formulas.
For example, A, ¬A, and ¬B→C are formulas. The expression A¬B is not a formula because it has no connective between its parts. The expression A+B is also not a formula in propositional logic because + is not one of its logical connectives.
The connectives are initially just symbols with syntactic rules. Their meanings are supplied by semantics.
Propositional logic: semantics
Models and possible worlds
A model in propositional logic is a complete assignment of truth values to all propositional symbols under consideration. A model can also be viewed as a possible world: it specifies which propositions are true and which are false.
With three symbols, such as A, B, and C, there are 23=8 possible models. One model might assign A=1, B=0, and C=0, where 1 means true and 0 means false.
Interpretation function
The interpretation function evaluates a formula in a model. It returns true if the formula is true under that assignment and false otherwise. For a propositional symbol, evaluation is a lookup in the model. More complex formulas are evaluated recursively from their parts.
The standard truth conditions for the connectives are:
¬F is true exactly when F is false.
F∧G is true exactly when both F and G are true.
F∨G is true when at least one of F and G is true.
F→G is false only when F is true and G is false. Equivalently, it is true when F is false or G is true.
F↔G is true when F and G have the same truth value.
These truth conditions define the semantics of propositional logic. They do not depend on an informal guess about what a connective “ought” to mean.
Formulas as sets of models
A useful way to understand a formula is as the set of all models in which it is true. Write Mod(F) for the set of models satisfying F.
For example, Rain∨Wet is true in every model where it is raining, where it is wet, or where both are true. It excludes only the model where neither is true.
Thus, asserting a formula narrows the possible worlds under consideration. A statement such as “there is a water bottle on the table” rules out every world in which there is no water bottle on the table.
A single formula can represent a large set of worlds. This compact representation is one source of logic’s expressive power.
Knowledge bases and their models
A knowledge base, written KB, is a set of formulas representing the information currently known about the world. Its models are the worlds in which all its formulas are true:
A model of a knowledge base must satisfy every formula in it. If a new formula F is added, the resulting possible worlds are the intersection of the old possibilities with those satisfying F:
Adding information can only leave the possible-world set unchanged or shrink it. If the new information is incompatible with what is already known, the intersection becomes empty.
Example
Suppose a knowledge base contains Rain and Rain→Wet. Its models must make both formulas true. Since Rain must be true and rain implies wet, the models of the knowledge base must also make Wet true.
Relationships between a knowledge base and a formula
When a formula F is compared with a knowledge base KB, three cases are important.
Entailment
The knowledge base entails F, written
when every model of the knowledge base is also a model of F:
In that case, adding F does not narrow the possible-world set: the knowledge base already guarantees it.
For example, if the knowledge base says Rain∨Snow and also says Snow, then it entails Rain∨Snow. The disjunction was already guaranteed.
Contradiction
The knowledge base contradicts F when no model satisfies both:
Adding F would leave the knowledge base with no possible models. For example, a knowledge base that entails Snow contradicts ¬Snow.
Contradiction can also be expressed as entailment of the negation:
Contingency
The relationship is contingent when the formula is compatible with the knowledge base but is not already guaranteed by it. The intersection is nonempty but is smaller than the original set of models:
For instance, if the knowledge base entails Rain but says nothing about Snow, then learning Snow adds information without creating a contradiction.
Answering and telling
These relationships support two basic operations for a reasoning system:
Tell: When a new formula is supplied, the system can report that it already followed from its knowledge, that it conflicts with its knowledge, or that it adds new information.
Ask: For a yes-or-no question F, the system can answer:
Yes if KB⊨F.
No if KB⊨¬F.
Unknown if neither F nor ¬F is entailed.
A logical “yes” or “no” is conclusive relative to the knowledge base. If the answer is unknown, the system lacks enough information to determine the truth of the question.
Connection to probabilistic inference
A knowledge base identifies a set of possible worlds, while a Bayesian network assigns probabilities to worlds. This gives a probabilistic analogue of logical reasoning.
Treat the models of KB as an event. Then the probability of F given the knowledge base can be written as
provided P(KB)>0.
The numerator is the probability mass of worlds satisfying both F and the knowledge base; the denominator is the probability mass of worlds satisfying the knowledge base. A probability of 1 corresponds to certainty under the distribution, while a probability of 0 corresponds to impossibility under it. Unlike purely logical entailment, probabilistic reasoning can express degrees of confidence, such as a probability of 0.9.
This connection assumes that a probability distribution over the relevant assignments is available. Learning that distribution is a separate problem from performing inference with it.
Satisfiability and model checking
A knowledge base is satisfiable if it has at least one model:
A knowledge base with no models is unsatisfiable: its formulas cannot all be true at once.
Satisfiability provides a way to test entailment and contradiction using at most two checks:
Check whether KB∪{¬F} is satisfiable.
If it is unsatisfiable, then KB⊨F.
If it is satisfiable, check whether KB∪{F} is satisfiable.
If that is unsatisfiable, then the knowledge base contradicts F.
If it is satisfiable, the relationship is contingent.
The first test works because KB⊨F exactly when there is no possible model satisfying both KB and ¬F.
SAT as a constraint satisfaction problem
For propositional logic, satisfiability is the classical SAT problem. It can be viewed as a constraint satisfaction problem:
Propositional symbols become variables.
Formulas become constraints.
A satisfying assignment is a model of the knowledge base.
A satisfiability algorithm returns “satisfiable” if it finds an assignment satisfying every formula, and “unsatisfiable” if no such assignment exists.
Algorithms
DPLL is a SAT algorithm based on backtracking search and pruning. It uses the structure of the formulas to avoid exploring some assignments.
WalkSAT is a randomized local-search algorithm. It searches through assignments, making changes intended to increase the number of satisfied clauses.
The general task of checking whether a model satisfying a knowledge base exists is called model checking.
Inference rules and derivations
Instead of reasoning over sets of models, a system can manipulate formulas directly using inference rules.
A rule has premises and a conclusion. If the premises are available in the knowledge base, the rule permits the system to add its conclusion.
Modus ponens
Modus ponens says that from P and P→Q, one may derive Q:
For example, from Rain and Rain→Wet, the system derives Wet.
Inference rules can be applied repeatedly:
Select formulas from the knowledge base.
Find a rule whose premises match those formulas.
Add the rule’s conclusion to the knowledge base.
Continue until no rule produces a new formula.
A derivation operates on the syntax of formulas. Write KB⊢F to mean that F can be mechanically derived from KB using a specified set of inference rules. This differs from KB⊨F, which is a semantic claim about all models of the knowledge base.
For example, from Rain, Rain→Wet, and Wet→Slippery, repeated applications of modus ponens derive Wet and then Slippery. These rules do not, by themselves, derive every formula that is semantically implied by the knowledge base.
Soundness and completeness
These properties describe how well a set of inference rules relates derivation to semantic truth.
Soundness
A rule system is sound if it never derives a formula that is not entailed by the knowledge base:
Sound rules produce only valid conclusions. Modus ponens is sound: whenever both P and P→Q are true, Q must be true.
A rule that inferred Rain from Wet and Rain→Wet would be unsound. It is possible for it to be wet without raining, so those premises do not guarantee rain.
Completeness
A rule system is complete if it can derive every formula that is semantically entailed by the knowledge base:
A system can be sound but incomplete: every conclusion it produces may be correct, yet it may fail to produce some correct conclusions.
Modus ponens is not complete for unrestricted propositional logic. Suppose the knowledge base contains Rain and (Rain∨Snow)→Wet. The knowledge base entails Wet, because rain makes the antecedent true. But ordinary modus ponens does not match the disjunctive antecedent with the single premise Rain, so it cannot derive wet in this case.
Soundness is essential because unsound rules generate false conclusions. Completeness is also desirable, because an incomplete system can miss valid conclusions. More powerful inference rules can improve completeness; for example, resolution can handle general propositional formulas.
Horn clauses and generalized modus ponens
A restricted class of formulas called Horn clauses allows modus-ponens-style reasoning to be both sound and complete for atomic queries.
Definite clauses
A definite clause has the form
where each Pi and Q is a propositional symbol. It says that if all the premises P1,…,Pk hold, then Q holds.
For example,
says that rain and snow together imply traffic. Facts such as Rain can be treated as definite clauses with no premises.
The conclusion of a definite clause must be a single propositional symbol. A formula such as
is not a definite clause because its conclusion is a disjunction.
Horn clauses
A Horn clause is either a definite clause or a goal clause, which has the form
A goal clause states that the combination of premises is forbidden. In standard clause form, a Horn clause contains at most one positive literal.
Generalized modus ponens
For definite clauses, modus ponens generalizes to several premises:
For example, from Wet, Weekday, and Wet∧Weekday→Traffic, the system derives Traffic.
For a knowledge base consisting of Horn clauses, repeated generalized modus ponens is sound and complete for determining whether an atomic proposition is entailed. In other words, if a Horn knowledge base semantically entails an atomic proposition, this inference procedure can derive it.
Example of Horn-clause inference
Suppose the knowledge base contains:
Rain
Rain→Wet
Wet∧Weekday→Traffic
Weekday
To answer whether there is traffic:
From Rain and Rain→Wet, derive Wet.
From Wet, Weekday, and Wet∧Weekday→Traffic, derive Traffic.
The procedure builds up propositions known to be true. It does not need to branch between alternatives.
This restriction explains why Horn clauses work well with modus ponens. If a rule concludes Traffic∨Peaceful, the system cannot safely add either proposition individually: one or the other may be true, but the rule does not say which. More general inference procedures are needed to reason with such disjunctions.
A conclusion containing a conjunction can be split into separate rules. For example, A→(B∧C) is equivalent to having both A→B and A→C, each of which is a definite clause.
Key distinctions
Syntax determines which formulas are valid; semantics determines what they mean.
A model is a complete truth assignment; a formula denotes the models in which it is true.
A knowledge base restricts possible worlds to those satisfying all its formulas.
Entailment means a formula is true in every model of the knowledge base; contradiction means it is true in none of them; contingency means it is true in some but not all.
Satisfiability asks whether at least one model exists. It can be used to answer entailment and contradiction queries.
Derivation uses inference rules to manipulate formulas syntactically; entailment is a semantic relationship between formulas and models.
Soundness means rules derive only valid conclusions; completeness means they can derive all valid conclusions.
Generalized modus ponens is complete for atomic queries over Horn-clause knowledge bases, while unrestricted propositional logic requires more powerful inference methods.

Ask anything
We've read this whole study set, so questions about it get the best answers.