Documentation

Complexitylib.Classes.P.Cobham.Internal.TakeLen

Truncating to the length of a leading block — proof internals #

takeLen (pair c y) = y.take |c|: the leading self-delimiting block acts as a ruler and the verbatim suffix is truncated to its length. Carrying a width bound as a string rather than as a number is what keeps an iterated FP step function polynomial-time — each iteration truncates its state to the ruler, so no intermediate value can grow beyond it.

The transducer takeLenTM has one work tape: scan parses the leading block two symbols at a time, writing one unary mark per payload bit; rewind returns the work head to cell one; copy emits one input symbol per remaining mark. Malformed input halts with empty output, matching unpair? = none.

Main results #

The function computed by the scanner #

The remaining output of the truncation scanner when k payload bits of the leading block have already been counted and w is the unread part of the input: the suffix truncated to the total ruler length, and nothing at all when the block framing is broken.

Equations
Instances For

    Truncate the verbatim suffix of a pair to the length of its leading block.

    Equations
    Instances For
      @[simp]

      Reaching the separator ends the ruler: the suffix is truncated to k.

      theorem Complexity.takeLenAux_double (k : ) (b : Bool) (z : List Bool) :
      takeLenAux k (b :: b :: z) = takeLenAux (k + 1) z

      A doubled payload bit lengthens the ruler by one.

      @[simp]

      A broken doubling halts the scan with no output.

      On a genuine pair the leading block is the ruler.

      Control states of takeLenTM.

      • skip : TakePhase

        Move every head off the left-end marker.

      • scanA : TakePhase

        Read the first symbol of a doubled payload bit.

      • scanB0 : TakePhase

        The first symbol of the pair was 0.

      • scanB1 : TakePhase

        The first symbol of the pair was 1.

      • rew : TakePhase

        Rewind the work head to cell one.

      • copy : TakePhase

        Emit one input symbol per remaining mark.

      • done : TakePhase

        Halt.

      Instances For
        @[implicit_reducible]
        Equations
        @[implicit_reducible]
        Equations
        • One or more equations did not get rendered due to their size.

        The truncation scanner. Parses the leading self-delimiting block into |c| unary marks on its work tape, then copies that many input symbols to the output. Computes takeLen.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          Correctness of the scanner #

          takeLenTM computes takeLen in 3 · |p| + 6 steps.

          Internal proof that ruler-truncation is in FP.