# Formal Methods 101: Induction

Introduction:

Induction is a mathematical technique used to prove a property of a system.

Intuitively, you can think of induction as a way of proving that all dominos will fall. If we know that the first domino falls, and we know that this domino causes the next domino to fall, we are assured that all dominos will fall.

Induction involves 4 steps:

1. Base Case: Proof that a property holds for the base case (or state).
2. Inductive Hyposysis: Assume that the property holds for a latter case (or state) satisfies the assumptions of a base case (i.e. assume symbolic base case).
3. Inductive Step: Perform an inductive step (i.e. symbolic transition to the next state).
4. Proof Step: Prove that a property holds after the inductive step (i.e. after the symbolic transition.)

Classic Example:

We will now explore a classic example. We will prove that the following formula holds out to N natural numbers; that is the sum of n natural numbers equals P(n).

• Step 1 – Base Case:
• Test the base case, n=0.
• The base case is proven true.
• Step 2 – Inductive Hypothesis:
• Assume P(n) holds for a latter case, n = k | n ∈ , which has the same properties as the base case. (i.e. symbolic base case)
• Step 3 – Inductive Step:
• Perform an inductive step by testing n = k+1. (i.e. symbolic execution from k to k+1)
• Equation for P(k+1):
• Left Hand Side:
• Right Hand Side:
• Step 4 – Proof Step:
• Check if the property, P(n), still holds.
• Simplify Left-Hand Side:
• Rewrite Right-Hand Side by Definition:
• Rewrite Right Hand Side:
• Step 1:
• Step 2:
• Step 3:
• Set Left Hand Side equal to Right Hand Side
• Proof Complete: We have proved that for all n, P(n) holds

Types of Induction:

• Weak Induction (or Simple Induction):
• The classical example above was an example of weak induction; that is, we only assume a single base case (and therefore, symbolic base case) and an inductive step.
• In natural language this is read: The property holds in the initial state and for all future states, if the property holds for some state, it holds for the next state; therefore, the property holds for all states.
• Strong Induction(or Complete Induction, or K-Induction) :
• Complete induction is when you make the property easier to prove by inductive strengthening the base case (and therefore, symbolic base case), also known as the inductive hypothesis.
• In natural language this is read: The property holds in the initial state and for all future states, if the property holds for some amount of states, it holds for the next state; therefore, the property holds for all states.
• K-Induction can be looked at from a different syntactic lense:
• Consider the following set of equivalent formulas:
• 1-Induction:
• 2-Induction:
• K-Induction:
• K-Induction (simplified):

Induction for Extended-State Machines:

• Induction may be applied to extended-state machines to prove invariant properties about systems.
• Consider the following extended-state machine. This system is made up of two states, four transitions, one variable of type int, and one variable representing the current state (i.e. S1 or S2). The system initially states in the state S1 with variable x equal to 0. In the next transition (step), if x is less than 0, the system transitions to state S2 and increments x by one. While in state S2, the system increments x by one each transition (step) until x is greater than 9. When x is greater than 9, the system transitions back to state S1 and resets x to 0.
• Consider the following property that we wish to prove is invariant by induction:
• That is, x can never be greater than 9. This is known as a static invariant; which is a property that is unchanging throughout the life of the system.
• If the invariant can be proven by induction then we call this an inductive invariant. Note: there are invariants that cannot be proven by induction.
• Notices how this extened-state machine can be written as the following SMT formula:
• Note: x’ & state’ stand for the value of the x & state variables after the next transition.
• We will now join this property to this SMT formula by an implication operator; indicating that where this system SMT formula is satisfied, the property is always satisfied.

We will now attempt to prove this invariant via induction.

• Step 1 – Base Case:
• Test the base case (i.e. the initial value), x = 0 & state = S1.
• Simplify…
• The base case is proven true.
• Step 2 – Inductive Hypothesis:
• Assume the property holds for a latter case, x = k (where )
• Step 3 – Inductive Step:
• Perform and inductive step by testing n = k+1. (i.e. symbolic execution from k to k+1)
• Step 4 – Proof Step:
• Check if the implication, , still holds.
• In order to do this, we much check is holds for the two cases: the case when and the case when . Note: only one of these can be true at one point time, and one of them must always be true.
• Case 1:
• Since k+1 is less than 9, the highest k could be is 7.
• Case 2:
• Because , and our assumption from our inductive hypothesis is that where k is an integer, we can conclude that . Therefore, k must equal 8.
• Proof Complete: We have proved that for all states the property is held. Since we have proven by induction, we call the property an inductive invariant of the system.