Invariance Math Example 4

Follow the full solution, then compare it with the other examples linked below.

Example 4

medium
In a game, you start with the number 6. Each move you may subtract 1 or divide by 2 (if even). Show that the quantity n(mod3)n \pmod{3} is not always preserved and find an invariant that is preserved.

Solution

  1. 1
    Start: n=6n=6, 6(mod3)=06 \pmod{3}=0. Subtract 1: n=5n=5, 5(mod3)=25\pmod{3}=2. Parity of n(mod3)n\pmod{3} changed — not an invariant.
  2. 2
    Try: parity of nn. Start even (n=6n=6). Subtract 1 gives odd; divide by 2 gives 3 (odd). From odd, subtract 1 gives even; can't divide.
  3. 3
    Invariant found: the value nn is always a positive integer, and it strictly decreases toward 1 with each move (both operations reduce nn). The positivity of nn is preserved.

Answer

Invariant: n1 (positivity preserved); n(mod3) is not invariant\text{Invariant: } n \ge 1 \text{ (positivity preserved); } n\pmod{3} \text{ is not invariant}
Not every quantity is invariant. The process of testing candidates — and ruling them out — is how invariants are discovered. Strict decrease is a useful invariant for proving termination.

About Invariance

A property of a mathematical object that remains unchanged when the object undergoes a particular transformation or operation.

Learn more about Invariance →

More Invariance Examples