Languages determined by the parity of the input length #
The first genuinely linear-time examples: scan the input, toggling a bit
each step, and write the answer once we hit a blank. Demonstrates a
textbook scan-style TM with an O(n) time bound, proved by induction on
the input.
Main definitions #
TM.evenLengthTM— 4-state scanning TM (start,even,odd,done).Language.evenLength— strings of even length.Language.oddLength— strings of odd length.
Main results #
evenLengthTM_reachesIn— halts in|x| + 2steps with1iff|x|is even.evenLength_in_DTIME,oddLength_in_DTIME— both inDTIME(n + 2).evenLength_mem_P,oddLength_mem_P— derived viaDTIME_mono/P_compl.oddLength_eq_compl_evenLength— explicit Boolean identity.
Control states of evenLengthTM.
- start : LengthParityPhase
- even : LengthParityPhase
- odd : LengthParityPhase
- done : LengthParityPhase
Instances For
@[implicit_reducible]
@[implicit_reducible]
Equations
- One or more equations did not get rendered due to their size.
Scanning TM that writes 1 if the input length is even, 0 otherwise.
Uses exactly 4 control states and halts in |x| + 2 steps on every input.
Equations
- One or more equations did not get rendered due to their size.
Instances For
evenLengthTM halts in |x| + 2 steps on every input, writing Γ.one
to output cell 1 iff |x| is even.
theorem
Complexity.evenLengthTM_decidesInTime :
TM.evenLengthTM.DecidesInTime Language.evenLength fun (n : ℕ) => n + 2
evenLengthTM decides evenLength in time n + 2.
evenLength ∈ DTIME(n + 2).