INAIO Guide Stage 1 4Sequences and Recurrences
4.4 Iterative state updates
Reframe a recurrence as repeated updates to the state containing everything needed for the next step.
In Module 4.3, we used starting values and a rule to build each new value from earlier ones. We are doing the same thing here. The change is what we carry from one step to the next: instead of keeping only one number, we can keep several related values together as a state and update that whole state at once. Applying the rule again and again is called iteration.
This framing is useful when the next step needs more than one piece of information. A simulation may track several populations; an algorithm may track a position and a remaining resource. Putting the needed values together makes each update clear, repeatable, and easier to check. This is intermediate work built on the previous module. The OpenStax introduction to recursive sequences reviews the one-number version.
A basic idea: keep the needed values together
The staircase example in Module 4.3 used : the next count needs the two latest counts. Keep those two counts as one state, . The recurrence can now be written as an update of the pair:
The first entry becomes the old second entry; the second entry becomes the sum of the old two. This is the previous recurrence in a different form. The state is a snapshot of what the rule needs now, and the update produces the next snapshot. We no longer have to look back through the whole history for the two values.
For the animation, choose the starting state . The updates give , then , then , then . This uses the same pair rule as the staircase count but different starting values. Both new entries must use the same old pair. If you replace first and use that new to calculate , you have changed the rule.
The animation follows this pair for four updates. Use Next to see which values feed the next round.
A quick tour of update questions
A state contains everything the rule needs at time . An update has the form ; the initial state makes the sequence determined. This is the same shape as from Module 4.3, but can hold a pair or several values. A one-number counter is also a state, with just one entry. Before calculating, ask:
| Question | Why it matters |
|---|---|
| What is in the state? | Missing information makes the next step ambiguous. |
| Are updates simultaneous? | A newly changed value may give the wrong next state. |
| What stays invariant? | A conserved total can catch an arithmetic error. |
| When do we stop? | A resource may run out or a target may be reached. |
For a simulation, write a short table with columns for , old state, and new state. If an action requires a condition such as energy , test it before applying that action. A bound such as may be a rule that stops the process, not just a fact to check afterwards.
An invariant is a quantity that the update preserves. For example, transferring one unit from to changes to but leaves unchanged. Finding an invariant can make a long iteration easier to verify.
Application 1: a robot's energy
A robot starts with energy units. A move requires at least units, uses , and then a charger returns units. How many moves can it complete?
- Set the state and rule. . If , then .
- Check before each move. From it reaches , then , then .
- Stop. At , it cannot pay the next move's upfront cost of . It completes three moves.
The final energy is positive, but that alone does not permit another move.
Application 2: generating neighbouring counts
Start with and update simultaneously by . What is the state after four updates?
- Record each old pair. .
- Count updates, not states. The start is time , so the fifth pair shown is the state at time .
- Check the last transition. From old , new and new .
This pair update produces neighbouring Fibonacci counts. Its purpose here is the update discipline: calculate from the old pair, then replace both entries together.
Resources
| Source | Title | Why read it |
|---|---|---|
| OpenStax | Sequences and their notations | Begin with recursive sequences before tracking several state values. |
Finished this module? Mark it done.
Comments
Stuck on something, spotted a mistake, or found a resource that helped you? Tell us below.
Loading comments