Linear time and space, and encodings of pairs, options and lists #
Tidy computability (Turing.MultiTapeTM.ComputableTidilyInTimeAndSpace) is relative to encodings of
values as words. Tidy computability in linear time and space is closed under composition, case
distinctions, concatenation of encoded values and pairing, and contains constant functions and the
functions computed by finite-state transducers.
This file also states, as classes indexed by the encodings, what is required of encodings of pairs, options and lists: their basic operations are tidily computable in linear time and space, and pairing, which builds a value from a common input, preserves tidy computability. Theorems take these classes as instance arguments, so they hold for every encoding with the required capabilities.
Main definitions #
Turing.MultiTapeTM.encBool: the encodingb ↦ [b]ofBool. Case distinctions (Turing.MultiTapeTM.ComputableTidilyInTimeAndSpace.ite) accept any encoding ofBool, so the choice matters only up to a constant.Turing.MultiTapeTM.ComputableTidilyInLinearTimeAndSpace: tidy computability in linear time and space, up to a constant.Turing.MultiTapeTM.PairEncoding enc₁ enc₂ enc:encencodes pairs compatibly withenc₁andenc₂.Turing.MultiTapeTM.OptionEncoding enc₁ enc:encencodes options compatibly withenc₁, withnoneencoded by the empty word.Turing.MultiTapeTM.ListEncoding enc₁ enc:encencodes lists compatibly withenc₁.
Main results #
Turing.MultiTapeTM.ComputableTidilyInTimeAndSpace.of_enc_eq: reuse identical encoded outputs with the same machine and exact time and space bounds.Turing.MultiTapeTM.ComputableTidilyInLinearTimeAndSpace.comp,.ite,.append,.pair: closure properties of linear time and space.Turing.MultiTapeTM.ComputableTidilyInLinearTimeAndSpace.const: constant functions.Turing.MultiTapeTM.Transducer.computableTidilyInLinearTimeAndSpace: functions computed by finite-state transducers.Turing.MultiTapeTM.PairEncoding.pair_mono: pairing functions computable within different bounds.
Reuse the same machine when the new function emits the same encoded output word. The time and space bounds are unchanged; no encoding conversion is performed.
Closure properties of linear time and space #
Compositions of functions tidily computable in linear time and space.
A function tidily computable in linear time and space on all inputs is so on the inputs
satisfying p.
Case distinctions of functions tidily computable in linear time and space, each branch on the inputs where it is taken.
Functions whose encoded value is the encoded input.
A function whose encoded value is the concatenation of the encoded values of two functions tidily computable in linear time and space.
A function computed by a transducer with finitely many states is tidily computable in linear time and space.
Encodings of pairs, options and lists #
enc encodes pairs compatibly with enc₁ and enc₂.
- pair {γ : Type u} {encIn : γ ↪ List Bool} {f : γ → α} {g : γ → β} {t s : γ → ℕ} : ComputableTidilyInTimeAndSpace f encIn enc₁ t s → ComputableTidilyInTimeAndSpace g encIn enc₂ t s → ∃ (c : ℕ), ComputableTidilyInTimeAndSpace (fun (x : γ) => (f x, g x)) encIn enc (fun (x : γ) => c * (t x + 1)) fun (x : γ) => c * (s x + (enc (f x, g x)).length + 1)
Pairing is a combinator: functions
fandgtidily computable from a common input within common bounds combine intofun x => (f x, g x), within a constant factor of those bounds, plus space for the encoded pair. Different bounds are covered byTuring.MultiTapeTM.PairEncoding.pair_mono. - fst : ComputableTidilyInLinearTimeAndSpace Prod.fst enc enc₁
The first projection is tidily computable in linear time and space.
- snd : ComputableTidilyInLinearTimeAndSpace Prod.snd enc enc₂
The second projection is tidily computable in linear time and space.
Instances
enc encodes options compatibly with enc₁: none is encoded by the empty word.
noneis encoded by the empty word.- some : ComputableTidilyInLinearTimeAndSpace Option.some enc₁ enc
someis tidily computable in linear time and space. - getD (d : α) : ComputableTidilyInLinearTimeAndSpace (fun (o : Option α) => o.getD d) enc enc₁
Option.getDis tidily computable in linear time and space.
Instances
enc encodes lists compatibly with enc₁.
- headD (d : α) : ComputableTidilyInLinearTimeAndSpace (fun (l : List α) => l.headD d) enc enc₁
List.headDis tidily computable in linear time and space. - tail : ComputableTidilyInLinearTimeAndSpace List.tail enc enc
List.tailis tidily computable in linear time and space. - isEmpty : ComputableTidilyInLinearTimeAndSpace List.isEmpty enc encBool
Testing a list for emptiness is tidily computable in linear time and space.
Instances
Pairing functions tidily computable within different bounds.
Pairing functions tidily computable in linear time and space.