Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
21ed7bd
chore: bump mathlib to e06eff5, fix breaking changes (#848)
mathlib-nightly-testing[bot] Aug 31, 2026
daedb5e
chore: document two heavy grind uses (#850)
jessealama Sep 1, 2026
aeb2e41
chore(LTS/MapHom): golf mapHom_mTr proof (#849)
jessealama Sep 1, 2026
bba5e73
chore(HML/LogicalEquivalence): golf to remove `mergeWithGrind` opt (#…
jessealama Sep 1, 2026
e4a29c2
Any function between finite types is computable in constant time and …
crei Sep 2, 2026
ff00e3f
Any function between finite types is computable in constant time and …
crei Sep 2, 2026
5330b08
Add two examples.
crei Sep 3, 2026
bc1122a
Merge remote-tracking branch 'self/tm_finite' into tm_finite
crei Sep 3, 2026
1927c42
Update wording.
crei Sep 3, 2026
eae0622
Extend result to "almost constant" functions.
crei Sep 4, 2026
e4c6bfb
feat(Turing): while/loop combinators, plumbing and encoding requirements
crei Sep 5, 2026
fa21954
feat(Turing): prove the loop combinator
crei Sep 5, 2026
ecd9e67
feat(Turing): factor the conditional through the recursor of `Bool`
crei Sep 8, 2026
3f5e73c
feat(Turing): the generic constructor of a non-recursive inductive type
crei Sep 8, 2026
fd2051a
feat(Turing): requirements on a pair encoding, as complexities only
crei Sep 8, 2026
2449092
test(Turing): a type with two constructors of arity two
crei Sep 8, 2026
552f510
refactor(Turing): make the finite case analysis the primitive
crei Sep 8, 2026
b20a39c
refactor(Turing): one bound for the scrutinee and every branch
crei Sep 8, 2026
3860f30
docs(Turing): note that `_match`'s `f` is inferred from the goal
crei Sep 8, 2026
1af43a7
test(Turing): destructuring matches, with and without junk
crei Sep 8, 2026
0a461cc
test(Turing): match on `Span` itself rather than on a computed scrutinee
crei Sep 8, 2026
9413495
feat(Turing): `_match` needs a finite range, not a finite scrutinee type
crei Sep 8, 2026
2b60af8
refactor(Turing): plumbing postconditions as vector equalities
crei Sep 8, 2026
e76bda0
refactor(Turing): extract the loop proof's reusable parts
crei Sep 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cslib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,23 @@ public import Cslib.Computability.Languages.OmegaLanguage
public import Cslib.Computability.Languages.OmegaRegularLanguage
public import Cslib.Computability.Languages.RegularLanguage
public import Cslib.Computability.Languages.SafetyLiveness
public import Cslib.Computability.Machines.Turing.MultiTape.Combinators.AlmostConstant
public import Cslib.Computability.Machines.Turing.MultiTape.Combinators.Comp
public import Cslib.Computability.Machines.Turing.MultiTape.Combinators.Concat
public import Cslib.Computability.Machines.Turing.MultiTape.Combinators.Ite
public import Cslib.Computability.Machines.Turing.MultiTape.Combinators.Loop
public import Cslib.Computability.Machines.Turing.MultiTape.Combinators.Tuple
public import Cslib.Computability.Machines.Turing.MultiTape.Combinators.While
public import Cslib.Computability.Machines.Turing.MultiTape.Deterministic
public import Cslib.Computability.Machines.Turing.MultiTape.Encodings.Option
public import Cslib.Computability.Machines.Turing.MultiTape.Encodings.Pair
public import Cslib.Computability.Machines.Turing.MultiTape.Plumbing.Basic
public import Cslib.Computability.Machines.Turing.MultiTape.Plumbing.Clean
public import Cslib.Computability.Machines.Turing.MultiTape.Plumbing.LiftTapes
public import Cslib.Computability.Machines.Turing.MultiTape.Plumbing.OnTape
public import Cslib.Computability.Machines.Turing.MultiTape.Plumbing.Sequential
public import Cslib.Computability.Machines.Turing.MultiTape.Plumbing.TapeContents
public import Cslib.Computability.Machines.Turing.MultiTape.Plumbing.Words
public import Cslib.Computability.Machines.Turing.MultiTape.TapeLemmas
public import Cslib.Computability.Machines.Turing.SingleTape.Defs
public import Cslib.Computability.Machines.Turing.SingleTape.Deterministic
Expand Down
1 change: 0 additions & 1 deletion Cslib/Computability/Languages/OmegaRegularLanguage.lean
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public import Cslib.Computability.Automata.NA.Sum
public import Cslib.Computability.Languages.Congruences.BuchiCongruence
public import Cslib.Computability.Languages.ExampleEventuallyZero
public import Mathlib.SetTheory.Cardinal.NatCard
public import Mathlib.Data.Finite.Sigma
public import Mathlib.Logic.Equiv.Fin.Basic

/-!
Expand Down
2 changes: 1 addition & 1 deletion Cslib/Computability/Languages/RegularLanguage.lean
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public import Cslib.Computability.Automata.NA.ToDA
public import Cslib.Computability.Automata.DA.ToNA
public import Mathlib.Computability.DFA
public import Mathlib.Computability.RegularExpressions
public import Mathlib.Data.Finite.Sum
public import Mathlib.Basic.Finite.Sum
public import Mathlib.Data.Set.Card

/-!
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/-
Copyright (c) 2026 Christian Reitwiessner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christian Reitwiessner
-/

module

public import Cslib.Computability.Machines.Turing.MultiTape.Deterministic

/-!
# Complexity of composed functions

If `f` and `g` are computable, then so is `g ∘ f`. The machine runs the machine for `f` with its
output diverted onto a work tape, and then runs the machine for `g` with that tape as its input
tape.

Note that the intermediate result has to be stored on a work tape: the output tape is append-only
and cannot be read back. Its length therefore enters both the time and the space bound, and it is
not bounded by the space used by the machine for `f`, since a machine can produce an output much
longer than the space it uses.

Recoding the input or the output of a computation is the special case where one of the two
functions is the identity.

## Main results

* `Turing.MultiTapeTM.computableInTimeAndSpace_comp`: the complexity of a composition.
-/

@[expose] public section

namespace Turing.MultiTapeTM

variable {α β γ : Type*}

/-- **Complexity of the identity.** A machine can copy its input to its output one symbol at a
time, so the identity is computable in linear time and zero space, relative to any encoding.

Together with `computableInTimeAndSpace_comp` this is what recodes a value from one encoding to
another, and what copies the input of a machine onto a work tape. -/
public theorem computableInTimeAndSpace_id {enc : α ↪ List Bool} :
∃ c, ComputableInTimeAndSpace (id : α → α) enc enc
(fun a => c * ((enc a).length + 1)) (fun _ => 0) :=
sorry

/-- **Complexity of a composition.** The bounds are those of the two machines, plus the length of
the encoded intermediate result, which has to be written to and read from a work tape. -/
public theorem computableInTimeAndSpace_comp {f : α → β} {g : β → γ}
{encA : α ↪ List Bool} {encB : β ↪ List Bool} {encC : γ ↪ List Bool}
{tf sf : α → ℕ} {tg sg : β → ℕ}
(hf : ComputableInTimeAndSpace f encA encB tf sf)
(hg : ComputableInTimeAndSpace g encB encC tg sg) :
∃ c, ComputableInTimeAndSpace (fun a => g (f a)) encA encC
(fun a => c * (tf a + tg (f a) + (encB (f a)).length + 1))
(fun a => c * (sf a + sg (f a) + (encB (f a)).length + 1)) :=
sorry

end Turing.MultiTapeTM
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/-
Copyright (c) 2026 Christian Reitwiessner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christian Reitwiessner
-/

module

public import Cslib.Computability.Machines.Turing.MultiTape.Deterministic

/-!
# Complexity of a concatenation of two functions

If `f` and `g` are computable, then so is any function whose encoded result is the encoded result
of `f` followed by the encoded result of `g`. The bounds are the sums of the two bounds, plus one
rewind of the input tape in time and a constant in space.

The machine runs the machine for `f`, rewinds the input head, and runs the machine for `g` on fresh
work tapes. The intermediate results are never stored: both machines write straight to the output
tape, which is append-only, so their outputs end up concatenated. The rewind is what lets the
second machine read the same input as the first, and it is the reason the input length appears in
the time bound.

This is the introduction rule of a finite product, dual to the case analysis of
`Cslib.Computability.Machines.Turing.MultiTape.Combinators.Ite`, which is the elimination rule of a
finite coproduct. Both are irreducibly machine-level for the same reason: they need the input to be
presented twice, once to each of the two computations.

Note that only the *syntactic* factorisation of the encoding is required. Producing a pair asks
nothing of the encoding beyond `henc`, whereas consuming one — reading a component back out —
is a genuine computability requirement on the encoding, of the kind
`Cslib.Computability.Machines.Turing.MultiTape.Encodings.Option` collects.

## Main results

* `Turing.MultiTapeTM.computableInTimeAndSpace_concat`: the complexity of a concatenation.
* `Turing.MultiTapeTM.computableInTimeAndSpace_pair`: the special case of a pair.
-/

@[expose] public section

namespace Turing.MultiTapeTM

variable {α β γ δ : Type*}

/-- **Complexity of a concatenation.** If `f` and `g` are computable and the encoded result of `h`
is the encoded result of `f` followed by the encoded result of `g`, then `h` is computable in the
sum of the two times plus the length of the input, and in the sum of the two spaces plus a
constant.

The result is stated for an arbitrary `h` with the assumption that its encoding factors as the
concatenation, rather than for a fixed pairing, so that it covers whatever the caller happens to be
encoding — a pair, a tuple, a constructor of an inductive type — and the caller is the one who has
to know that the concatenation of the two encodings is again injective. -/
public theorem computableInTimeAndSpace_concat
{f : α → β} {g : α → γ} {h : α → δ}
{encIn : α ↪ List Bool} {encB : β ↪ List Bool} {encC : γ ↪ List Bool} {encD : δ ↪ List Bool}
{tf sf tg sg : α → ℕ}
(henc : ∀ x, encD (h x) = encB (f x) ++ encC (g x))
(hf : ComputableInTimeAndSpace f encIn encB tf sf)
(hg : ComputableInTimeAndSpace g encIn encC tg sg) :
∃ c, ComputableInTimeAndSpace h encIn encD
(fun x => tf x + tg x + (encIn x).length + 2)
(fun x => sf x + sg x + c) :=
sorry

/-- **Complexity of computing a pair.** The special case of `computableInTimeAndSpace_concat` in
which the two results are packed into a pair, encoded by concatenating the two encodings. It is up
to the caller to provide such an encoding; this needs the encoding of the first component to
determine where it ends. -/
public theorem computableInTimeAndSpace_pair
{f : α → β} {g : α → γ}
{encIn : α ↪ List Bool} {encB : β ↪ List Bool} {encC : γ ↪ List Bool}
{encPair : β × γ ↪ List Bool} {tf sf tg sg : α → ℕ}
(henc : ∀ p : β × γ, encPair p = encB p.1 ++ encC p.2)
(hf : ComputableInTimeAndSpace f encIn encB tf sf)
(hg : ComputableInTimeAndSpace g encIn encC tg sg) :
∃ c, ComputableInTimeAndSpace (fun x => (f x, g x)) encIn encPair
(fun x => tf x + tg x + (encIn x).length + 2)
(fun x => sf x + sg x + c) :=
computableInTimeAndSpace_concat (fun x => henc (f x, g x)) hf hg

end Turing.MultiTapeTM
Loading
Loading