Areas Reasoning and proof Heuristics of discovery Example
The backward search for 5 liters with jugs of 4 and 6 liters
Example
With a jug of exactly liters, a jug of exactly liters and unlimited water, can we get exactly liters in one jug? The moves are as in measuring 6 liters with jugs of 4 and 9 liters: fill a jug, empty a jug, or pour one jug into the other until the first is empty or the second is full. A state is a pair of the amounts in the small and the large jug, and the start is . We try working backwards and see where it misleads.
- The goal is . A full large jug holds liters, so we could pour liter out of a full large jug.
- A pour moves exactly liter into the small jug when the small jug holds liters, so the new goal is .
- A pour from the large jug into an empty small jug stops at liters or when the large jug is empty. So one way to get is to pour a large jug that holds liters into the empty small jug, and the new goal is .
- To get we could pour liters out of a full large jug, so the small jug must hold liter, and the new goal is .
- To get , either the large jug holds liter and is poured into the empty small jug, or a full small jug pours liters into a large jug that holds . Each new goal asks again for an odd amount.
The backward chain moves among the goals " liter", " liters" and " liters", and it never reaches the start . So working backwards gives no plan. It also gives no proof that no plan exists, because a cleverer backward step might have been missed.
An invariant settles the question.
- We claim that in every state that can be reached from , both amounts are even.
- The start has both amounts even.
- Filling a jug puts or liters in it, and emptying a jug leaves , all even.
- A pour moves either all the water of the first jug, or , or the free space of the second jug, or . If and are even, each of these amounts is even, so both amounts stay even.
- By induction on the number of moves, the claim holds in every reachable state.
- The goal needs liters in a jug, and is odd, so no sequence of moves reaches the goal.
Remarks
The example shows a limit of working backwards: it can find a plan, but a failure to find one proves nothing. To show that a goal cannot be reached, we need an argument about all states at once, such as a parity argument.
The invariant also explains why the backward chain kept asking for odd amounts. A computer search over all pairs confirms that only of them can be reached, and each has both amounts even. In general, with jugs of and liters, the large jug can hold exactly the multiples of from up to its size. For jugs of and liters, , so the large jug can hold , , or liters.
Going deeper
For a student
We compare two ways to treat a goal that may be impossible. A backward search lists the states that lead to the goal, and if it is complete and runs out of new states, it proves impossibility, but a search by hand is seldom complete. An invariant is one property, here "both amounts are even", that holds at the start, survives each move, and fails at the goal. For jugs of and liters and the goal of liters, the invariant "both amounts are multiples of " works in the same way, since is not a multiple of .
This is the typical use: when working backwards keeps returning to the same kind of goal, look for a quantity that every move preserves. Watch out: a short backward search that fails is not a proof, because a missed move could open a path.
Reading path
To understand this page from the ground up, read these 63 pages in order. The foundations come first. The path takes the proofs Proof of unique readability by counting brackets, Proof of the double negation law by a truth table.
- Alphabet concept
- Arity concept
- Boolean function concept
- Congruence modulo n concept
- Countermodel concept
- Effectively decidable set concept
- Formal language concept
- Function concept
- Induction on well-formed formulas concept
- Mathematical statement definition
- Natural numbers object
- Proposition concept
- Propositional letter concept
- Set concept
- String concept
- Tuple concept
- Signature concept
- Logical connective definition
- Connectives in mathematical language concept
- Conjunction definition
- Disjunction definition
- Material implication definition
- Principle of bivalence concept
- Predicate concept
- Conditional statements concept
- Biconditional definition
- Term concept
- Negation concept
- Negation definition
- Atomic formula concept
- Quantifiers in mathematical writing concept
- Truth table concept
- Material implication concept
- Conjunction concept
- Disjunction concept
- Negating mathematical statements concept
- Tautology concept
- Biconditional concept
- Universal quantifier concept
- Logical equivalence concept
- Logical connective concept
- Existential quantifier concept
- Well-formed formula concept
- Proof of the double negation law by a truth table proof
- Propositional formula definition
- Propositional formula concept
- Double negation law statement
- Formal system concept
- Proof of unique readability by counting brackets proof
- Unique readability theorem statement
- Truth valuation concept
- Logical consequence concept
- Rule of inference concept
- Modus ponens concept
- Mathematical proof concept
- Deductive, inductive and abductive reasoning concept
- Proof by contradiction concept
- Mathematical induction concept
- Heuristics in mathematics concept
- Invariants concept
- Parity arguments concept
- Working backwards concept
- The backward search for 5 liters with jugs of 4 and 6 liters example
Further reading
- Web https://en.wikipedia.org/wiki/Water_pouring_puzzle, lead section
About this page
| Tag | 33P1SJW98J |
|---|---|
| URI | m2://33P1SJW98J |
| Kind | example |
| Writing | W0 stub |
| MSC | 00A35, 00A08 |
| Not an instance of | Working backwards (note: working backwards from 5 liters produces only states with an odd amount and never reaches the start, but it cannot show by itself that no plan exists; an invariant proves the impossibility.) |
| Part of | Heuristics of discovery |
| Uses | Working backwards, Invariants, Parity arguments |
| Changed | 23 November 2026, first written 17 November 2026 |
Markdown · JSON · Edit on GitHub
What this page needs for W1
- an inventory row: the row of the inventory that the node accounts for (0 of 1)
The writing levels say how complete the text of a page is. They do not measure its truth.
History
Each change to this page, from its provenance log. A change by an agent names its run.
| Date | Change | Field | By |
|---|---|---|---|
| 2026-11-17 | add | the whole node | tamnd |
| 2026-11-23 | change | the section Example | tamnd |
| 2026-11-23 | change | the explanation L1 | tamnd |
| 2026-11-23 | change | the explanation L2 | tamnd |
| 2026-11-23 | change | the section Remarks | tamnd |
| 2026-11-23 | change | the field name | tamnd |
| 2026-11-23 | change | the field not_instance_of | tamnd |
What links here
No page links to this page yet.