Skip to content

feat(MultiTapeTM): Any function constant with finitely many exceptions is computable in constant time and space - #854

Open
crei wants to merge 6 commits into
leanprover:mainfrom
crei:tm_finite
Open

feat(MultiTapeTM): Any function constant with finitely many exceptions is computable in constant time and space#854
crei wants to merge 6 commits into
leanprover:mainfrom
crei:tm_finite

Conversation

@crei

@crei crei commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

This is a starting point of a Turing machine combinator library, it adds one of the leaves:

Any function that is constant with finitely many exceptions is computable in constant time and zero space, relative to any encoding. The same holds for any function with a finite domain.

This result captures many functions we want to compose later or with a combinator library: Any function on tuples of Bool, for example and "equality comparison with a constant". Together with a "fold" and "composition" combinators, this already allows us to evaluate CNFs or compute Nat.succ on binary encoded numbers.

The empty list has to be added explicitly for the case where `α` is empty: `finiteFunTM` uses
the elements of this set as its states while reading the input, so the set has to contain the
starting state `[]` even if there is no input to read. -/
noncomputable def encPrefixes (encIn : α ↪ List Bool) : Finset (List Bool) :=

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems a bit of a shame to make noncomputable;

@crei

crei commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

It turns out, almost the same machine can compute any function that is constant with a finite number of exceptions. There are two very important functions in this class: Equality and inequality comparison with a constant. This function is a building block in defining a "while" combinator, so I think it's worth it expanding the file.

@crei crei changed the title feat(MultiTapeTM): Any function between finite types is computable in constant time and space feat(MultiTapeTM): Any function constant with finitely many exceptions is computable in constant time and space Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants