Automated theorem proving: search and checked certificates
自动定理证明
Build a finite resolution prover, independently check its evidence, and distinguish logic from truth of assumptions.
automated-theorem-provingA problem to solve
Suppose it is raining, and rain implies that the ground is wet. A proof of wetness is short. A large theorem may require a long search, but checking a proposed sequence of valid inference steps can be a separate task. Automated theorem proving benefits from that separation: let a search procedure try ideas, then check exactly what it claims to have established.
This chapter builds a tiny propositional refutation prover and an independent certificate checker. It operates on clauses supplied by the caller. It is not a parser for arbitrary mathematics or a reimplementation of Lean.
Definitions and guarantees
A literal is an atom or its negation; a clause is a disjunction of literals. The input is a conjunction of clauses. Integers encode atoms, and changing the sign negates them. An empty clause is false, whereas an empty collection of clauses is true.
To establish a goal from assumptions , refute their conjunction with the negated goal:
Resolution eliminates one selected complementary pair:
It does not remove every complementary pair at once. Resolving with on leaves , a tautology, not an empty clause. Removing both pairs would falsely refute a satisfiable formula. Robinson’s original work establishes the resolution approach in a richer first-order setting; the program here uses only its propositional special case. A Machine-Oriented Logic Based on the Resolution Principle
A certificate records two earlier clause indices, one pivot and the claimed result. The checker recomputes the result and accepts only if an empty clause is genuinely present. Sound inference makes the conclusion follow from the supplied assumptions; it does not establish that the assumptions describe the world correctly.
Modern proof assistants combine a richer logical foundation with automation. The 2021 Lean4 system description discusses extensibility and a relatively small trusted kernel. This motivates checking proof artifacts separately from a complex search procedure, but the small Python checker below is ordinary tested software, not a formally verified trusted kernel. The Lean4 Theorem Prover and Programming Language — system description
A minimal implementation
The search adds new non-tautological resolvents until it finds a contradiction or saturates. With atoms there are at most distinct non-tautological clauses, because each atom can be absent, positive or negative. If counts initial and added clauses, the simple pair search costs elementary work and stores literals. The exponential clause space is the practical limit.
def normalise(clauses):
result = []
atoms = set()
for clause in clauses:
values = list(clause)
if any(type(x) is not int or x == 0 for x in values):
raise ValueError("literals must be nonzero integers")
result.append(frozenset(values))
atoms.update(abs(x) for x in values)
if len(atoms) > 6:
raise ValueError("teaching limit: at most six propositional atoms")
return result
def prove_unsat(clauses):
known = normalise(clauses)
seen = set(known)
steps = []
if frozenset() in seen:
return True, steps
i = 0
while i < len(known):
for j in range(i):
for pivot in sorted(known[i]):
if -pivot not in known[j]:
continue
resolvent = (known[i] - {pivot}) | (known[j] - {-pivot})
if any(-x in resolvent for x in resolvent) or resolvent in seen:
continue
steps.append((i, j, pivot, tuple(sorted(resolvent))))
known.append(resolvent)
seen.add(resolvent)
if not resolvent:
return True, steps
i += 1
return False, steps
def verify(clauses, steps):
# This checker does not call the search procedure.
try:
known = normalise(clauses)
for row in steps:
if len(row) != 4:
return False
i, j, pivot, claimed = row
if type(i) is not int or type(j) is not int or type(pivot) is not int:
return False
if not (0 <= i < len(known) and 0 <= j < len(known)):
return False
left, right = known[i], known[j]
if pivot not in left or -pivot not in right:
return False
expected = frozenset(x for x in left if x != pivot)
expected = expected.union(x for x in right if x != -pivot)
derived = normalise([claimed])[0]
if derived != expected:
return False
known.append(derived)
return any(not clause for clause in known)
except (TypeError, ValueError):
return False
if __name__ == "__main__":
# 1: rain; 2: wet. Last clause negates the proposed goal.
clauses = [{1}, {-1, 2}, {-2}]
unsat, proof = prove_unsat(clauses)
print("refuted:", unsat, "steps:", len(proof))
print("certificate accepted:", verify(clauses, proof))
forged = [(0, 1, 1, ())]
print("forged empty clause:", verify([{1, 2}, {-1, -2}], forged))
print("satisfiable input:", not prove_unsat([{1, 2}, {-1, 2}])[0])
refuted: True steps: 3
certificate accepted: True
forged empty clause: False
satisfiable input: True
The example adds “not wet” to the two assumptions and obtains a contradiction, so wetness follows from those assumptions. The forged certificate tries to remove two complementary pairs and is rejected. No certificate needs to trust the order in which the search discovered its steps; it must still reference earlier available clauses correctly.
For this finite propositional closure, saturation without contradiction establishes satisfiability. A timeout before saturation would not. The function has no timeout-result shortcut and rejects more than six atoms to keep the teaching search small. The boolean result must not be interpreted using the same termination guarantee for general first-order problems.
Limits and alternatives
First-order reasoning introduces variables, quantifiers, unification and possibly infinitely many terms. A complete refutation procedure with suitable preprocessing and fair search can find a refutation when one exists, yet may run forever when none exists. Do not confuse completeness of an inference method with a decision procedure that always terminates.
A proof also depends on the formalization. An inconsistent assumption set entails every goal in classical logic, and proving a mistranslated statement does not prove the intended statement. Record axioms, definitions and any admitted results when inspecting a real proof development.
Production systems use stronger search strategies and representations, including SAT/SMT procedures, first-order provers and interactive tactics. Their guarantees depend on the logic, solver mode and evidence returned. The toy checker illustrates an auditable boundary, but it still needs tests and its own correctness argument.
Exercises with answers
1. What is the difference between an empty clause and no clauses?
An empty clause is false; a conjunction with no clauses is true.
2. Resolve p or q with not-p or not-q using p.
The result is q or not-q, not a contradiction.
3. Does a search timeout prove satisfiability?
No. The finite example needs complete saturation; a timeout has not established it.
4. Does accepting a proof establish that its assumptions are true in reality?
No. It establishes a consequence relative to the supplied formal assumptions.
Research and next steps
Read Robinson for resolution’s logical basis and the Lean system paper for the relationship between an extensible prover and checking infrastructure. Keep propositional search, first-order reasoning and proof-assistant kernels distinct.
Continue with resolution, first-order logic and SAT solving.
Make a prediction, then check
What remains after resolving the two complementary-pair clauses on p?
Learning objectives
- Distinguish proof search, certificate validation and assumption correctness.
- Explain finite propositional saturation versus first-order semidecision.
Prerequisites & connections
Explore related knowledge →References
- A Machine-Oriented Logic Based on the Resolution Principle
J. A. Robinson · 1965 - The Lean 4 Theorem Prover and Programming Language — system description
Leonardo de Moura; Sebastian Ullrich · 2021
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-07 · Codex single-AI-author technical check: bounded primary-source passages, explicit finite models, executed programs, independent mathematical/exhaustive references, input boundaries and bilingual alignment. Not independent human or second-agent review; no full-system research reproduction claimed.
- Single-agent authored technical review; runnable example, exact or literal reference checks, explicit assumptions and matching bilingual equations/exercises. Automated execution and rendering results recorded separately.
- Verified7 tests including all512 CNFs over two atoms against independent truth tables; rejected double-pivot forged empty clauses, forward references and bad literals. Corrected search complexity to O(C²n²) elementary work before freezing.
- Compared both locale arguments, definitions, assumptions, formulas, code, results and all four exercises. Original finite teaching programs; no published system or research benchmark reproduction claimed. Catalogue IDs corrected before freezing.
- Complete bilingual prose and corresponding exercises promoted with formal status and SHA binding. Algorithm tests read formal MDX; historical essays claim no executable program or computational tests.
- Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
Source locations checked:
- A Machine-Oriented Logic Based on the Resolution Principle · Reuse original resolution inference/refutation framework; program limited to finite propositional clauses, not full first-order implementation.
- The Lean 4 Theorem Prover and Programming Language — system description · Read physical1–2 introduction and physical9 conclusion on extensibility and trusted kernel; no Lean execution claimed.
Related topics