PrepStack · Markdown HTML

Explicit simulation / state machine

Geometry, sweep, simulation, and parsing · HTML

Formal shape

state_{t+1}=F(state_t,input_t); output comes from state or transition; repetition of a complete deterministic finite state repeats the future.

Recognition signals

False friends

SignalWhy it is different
A direct aggregate formula existsIf steps commute or have a closed form, literal simulation may time out.
Recorded state omits history that affects the futureIf equal recorded states can diverge later, the state is not sufficient.

Core invariant

At loop entry, state completely describes the real process configuration, and one transition is definitionally equivalent to one rule step.

State, transition, and processing order

ItemDefinition
StateOnly future-relevant fields such as position, direction, mode, and counters; optionally seen[state]=(step,metric).
TransitionRead the old state and input, apply mutually exclusive rule priority, and fast-forward only after a complete state repeats.
Frontier / orderstep separates an exactly executed prefix from the remaining suffix; fast-forward skips only whole identical cycles.

Python skeleton

def run_machine(initial, steps, transition):
    state = initial
    seen = {}
    t = 0
    while t < steps:
        if state in seen:
            cycle = t - seen[state]
            if cycle:
                jump = (steps - t) // cycle
                if jump:
                    t += jump * cycle
                    continue
        else:
            seen[state] = t
        state = transition(state)
        t += 1
    return state

Correctness sketch

  1. The initial state matches the real initial configuration.
  2. If the current state is correct, an equivalent transition produces the correct next state.
  3. Induction proves every explicitly executed prefix.
  4. A deterministic system returning to the same complete state has the same future, so whole-cycle jumps preserve the final state.

Complexity

TimeSpaceParameters
O(T) directly; cycle acceleration often O(S) for finite stateO(1) directly or O(S) with seenT requested steps and S reachable states

Edge cases

Error patterns

PatternWhy it fails / fix
In-place synchronous updatesCompute all new fields from the old snapshot.
Cycle detection on incomplete stateOmitted direction or phase causes invalid jumps.
Jumping past the remainderOnly complete cycles may be skipped.

Selection and exclusion rules

RelationTemplateBoundary
finite-state complementStack-based state simulationUse enum states for flat phases and frame stacks for nesting.
optimization-branch contrastFinite-state-machine DPUpgrade to DP when several reachable modes aggregate an optimum or count; deterministic single-successor processes need only simulation

Original micro-example

PartDetail
ResultThe length-two cycle 1↔3 enables fast-forwarding.
ScenarioStates follow 0→1→3→1 for ten steps.
WalkthroughOn revisiting complete state 1, the future is fixed; only the final step-count remainder needs explicit execution.

Recall prompts

My notes