Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Complexity.PolyTime.Nat.Div

Division and remainder of unary counters #

A quotient/remainder loop scans the unary dividend and captures the divisor. One invariant proves its arithmetic specification and the linear bound on encoded intermediate states, including divisor zero. The fixed-divisor interface follows by composition.

Main results #

References #

The machine realization uses the invariant-based loop calculus in PolyTime.Iteration.

Compute both quotient and remainder with a runtime unary divisor. Division by zero returns (0, dividend), matching Lean's conventions. All intermediate counters have linear size.

Division by a fixed natural is a special case of runtime unary division.

Division of two unary counters, including divisor zero.

Remainder of two unary counters, including divisor zero.

theorem Turing.MultiTapeTM.ComputableInPolyTime.unary_div' {α : Type} {input : α ↪ List Bool} {left right : α → ℕ} (hleft : ComputableInPolyTime left input encUnary) (hright : ComputableInPolyTime right input encUnary) :
ComputableInPolyTime (fun (a : α) => left a / right a) input encUnary

Divide two computed unary naturals with the same full input context.

theorem Turing.MultiTapeTM.ComputableInPolyTime.unary_mod' {α : Type} {input : α ↪ List Bool} {left right : α → ℕ} (hleft : ComputableInPolyTime left input encUnary) (hright : ComputableInPolyTime right input encUnary) :
ComputableInPolyTime (fun (a : α) => left a % right a) input encUnary

Take the remainder of two computed unary naturals with the same full input context.

Compute both quotient and remainder with a runtime unary divisor. Division by zero returns (0, dividend), matching Lean's conventions. All intermediate counters have linear size.

Division by a fixed natural is a special case of runtime unary division.