Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Complexity.InSpace.Cases

Case analysis within linear work space #

Case analysis on a tagged sum or option preserves space linear in the encoded input. The implementations reuse the native case combinators, forgetting their time bounds.

theorem Turing.MultiTapeTM.ComputableInSpace.sumElimSnd {π α β ε : Type} {encP : π ↪ List Bool} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encE : ε ↪ List Bool} {f : π × α → ε} {g : π × β → ε} (hf : ComputableInSpace f (encPair encP encA) encE fun (p : π × α) => ((encPair encP encA) p).length) (hg : ComputableInSpace g (encPair encP encB) encE fun (p : π × β) => ((encPair encP encB) p).length) :
ComputableInSpace (fun (p : π × (α ⊕ β)) => Sum.elim (fun (a : α) => f (p.1, a)) (fun (b : β) => g (p.1, b)) p.2) (encPair encP (encSum encA encB)) encE fun (p : π × (α ⊕ β)) => ((encPair encP (encSum encA encB)) p).length

Linear-space branches give linear-space case analysis on the second component.

theorem Turing.MultiTapeTM.ComputableInSpace.optionElimSnd {π α ε : Type} {encP : π ↪ List Bool} {encA : α ↪ List Bool} {encE : ε ↪ List Bool} {f : π → ε} {g : π × α → ε} (hf : ComputableInSpace f encP encE fun (p : π) => (encP p).length) (hg : ComputableInSpace g (encPair encP encA) encE fun (p : π × α) => ((encPair encP encA) p).length) :
ComputableInSpace (fun (p : π × Option α) => p.2.elim (f p.1) fun (a : α) => g (p.1, a)) (encPair encP (encOption encA)) encE fun (p : π × Option α) => ((encPair encP (encOption encA)) p).length

Inspecting an option and running its selected linear-space branch uses linear space.

theorem Turing.MultiTapeTM.ComputableInSpace.optionElim {α ε : Type} {encA : α ↪ List Bool} {encE : ε ↪ List Bool} (fallback : ε) {g : α → ε} (hg : ComputableInSpace g encA encE fun (a : α) => (encA a).length) :
ComputableInSpace (fun (s : Option α) => s.elim fallback g) (encOption encA) encE fun (s : Option α) => ((encOption encA) s).length

Linear-space case analysis on an option without an auxiliary parameter.

theorem Turing.MultiTapeTM.ComputableInSpace.sumElimFst {π α β ε : Type} {encP : π ↪ List Bool} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encE : ε ↪ List Bool} {f : α × π → ε} {g : β × π → ε} (hf : ComputableInSpace f (encPair encA encP) encE fun (p : α × π) => ((encPair encA encP) p).length) (hg : ComputableInSpace g (encPair encB encP) encE fun (p : β × π) => ((encPair encB encP) p).length) :
ComputableInSpace (fun (p : (α ⊕ β) × π) => Sum.elim (fun (a : α) => f (a, p.2)) (fun (b : β) => g (b, p.2)) p.1) (encPair (encSum encA encB) encP) encE fun (p : (α ⊕ β) × π) => ((encPair (encSum encA encB) encP) p).length

Case analysis on the first component preserves a shared second parameter.

theorem Turing.MultiTapeTM.ComputableInSpace.sumElim {α β ε : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encE : ε ↪ List Bool} {f : α → ε} {g : β → ε} (hf : ComputableInSpace f encA encE fun (a : α) => (encA a).length) (hg : ComputableInSpace g encB encE fun (b : β) => (encB b).length) :
ComputableInSpace (Sum.elim f g) (encSum encA encB) encE fun (s : α ⊕ β) => ((encSum encA encB) s).length

Linear-space case analysis without an auxiliary parameter.