sicp.io
1.3.3 · Fixed-point search

A transformation can produce its own next guess.

Repeatedly applying one transformation turns its output into the next input, while an explicit step count makes the stopping rule observable.

Guiding question

What does it mean to search for a value that a transformation leaves unchanged?

  • Treat a transformation as a procedure value
  • Carry each transformed result into the next iteration
  • Use a fixed count as an explicit stopping rule
  • Inspect successive guesses for the selected starting value

A fixed point of f is a value x for which f(x) equals x. The transformation x ↦ 1 + 1/x has the golden ratio as a fixed point, so applying it repeatedly from 1.0 produces guesses that move around that value.

fixed-point does not hide its stopping decision inside an unobserved tolerance. It accepts the transformation, current guess, and remaining count as its complete state. The history version records the same handoff so the alternating guesses remain visible.

SICP code283 of 1,048,576 UTF-8 bytes
Examples
Result
Output
Value
Diagnostic
Execution trace0 / 0 events
    Programs run in the browser with their result and execution trace.
    Expected result

    The first program returns 1.6180257510729614 after twelve transformations. The second returns (1.0 2.0 1.5 1.6666666666666665 1.6 1.625 1.6153846153846154).

    Trace focus

    Follow improve as an ordinary procedure value, then watch each returned number become the next guess while remaining decreases. The complete execution traces record every step of the selected runs under fixed runtime limits.

    Try it yourself

    Change the program and compare the result.

    Change the first program from twelve transformations to eight. Predict whether the result lies above or below the twelve-step value before running.

    Show hint

    The guesses alternate around the fixed point, so keep track of whether the count is even or odd.

    Complete this lesson

    0 of 18 lessons complete in this chapter0%