feat(Computability): Plan for complexity theory
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- 説明が足りない
- 活発さ
- 活発
- 領域
- tooling
調査の方向性
まず、repository にある既存の 1-TM の定義と提案されている k-TM の作業を確認し、ここで説明されている機械モデルおよびシミュレーションと比較してください。この issue は範囲が限定されたタスクというより、広範な計画提案です。完了には、スコープと、形式化する具体的なモデル、シミュレーション、または定理について合意する必要があります。
索引モデルが issue の本文から書いたものです。
説明
In my opinion, we currently have two major blockers to make progress on complexity theory in CSLib:
The first is that we do not have consensus about how to define space and time.
While this is a very important point, I think the details of it are not too relevant once we have established multiple machine models and theorems about how simulations between them translate time and space bounds.
So because of that, I think it is more important to define multiple models of more and more expressive machines and their own definitions of time and space consumption.
Textbooks on complexity often start with defining different machine models and show how they can simulate each other, but then actual proofs are usually done "in prose", assuming some arbitrary pseudo-code language and requiring from the reader to translate the resource bounds in their head.
Of course we cannot use pseudo-code, and this is the second blocker: We need a useful high-level machine model with a definition of time and space plus theorems how these resource bounds translate between the models. If we more or less agree about the path to take, we can start working on theorems in parallel instead of everyone waiting until we agree on the very first step.
This issue is a proposal about such a sequence of machine models and also contains some early theorems we can start on formalizing, once we have it.
Machine Models
The Machines
Multiple stages of progressively more complicated and expressive machines which are still well enough related to Turing machines with respect to resource consumption.
1) Single-Tape Turing Machine: 1-TM
Already defined in the repository. Might need some tweaks with respect to space.
We need to decide which restriction to adopt to allow sub-linear space, or just not use it for sub-linear space.
Also non-determinism is unclear.
2) Multi-Tape Turing Machine: k-TM
Existing pull request. Does not define space consumption. Will need special input and output tapes, also oracle tapes and path tapes (for nondeterminism and alternation, see below).
Non-determinism unclear.
3) Function-free RTM
As an abstraction on top of k-TMs I would propose a simple "functional" language.
The main feature of that language is that it makes an expressivity step towards functional languages but defines a resource consumption model that allows it to be easily simulated by a k-TM.
I have worked quite some time on different iterations of such a language in my private fork but defining this latest iteration, writing a program that simulates a 1-TM (exactly as defined in cslib) in a universal way and proving its semantic correctness took me just a few days.
Because of that, I think this language is useful enough to be considered.
It processes the following data type which can be used to represent almost any lean type in an obvious way:
inductive Data where l : List Data → Data
Programs are defined as follows with a sketch of the semantics in comments - each "AST node" returns a value of type Data.
inductive Prog where
| var (id : ℕ) -- returns the contents of variable `id`
| empty -- returns `Data.l []`
| cons (h t : Prog) -- computes `cons` on the result of `h` and `t`
/-- models "match v with | Data.l [] => em | Data.l hd :: tl => cs hd tl (introduces new vars) -/
| elim (v em cs : Prog)
/-- models "if x == y then the_ else else_" -/
| ifEq (x y then_ else_ : Prog)
/-- models "list.foldl body init" -/
| fold (body init list : Prog)
/-- models a potentially unbounded loop -/
| while_ (init body : Prog)
The time and space consumption is as what would be expected from simulating the program on a k-TM such that each AST node has its own tape containing the result of evaluation, plus some auxiliary tapes for some operations like fold. For most operations, the space consumption is the max of the space consumption of the "inner" programs plus the size of the output. For time it is similar, just that we use + instead of max. For fold and while_, tapes from earlier iterations are re-used, so the space usage is the max over all iterations.
The advantage of this model is that termination is guaranteed as long as there is no while loop.
Furthermore, we can have generic theorems like "if the 'body' part of a 'fold' has linear complexity and its output is bounded by a constant, then 'fold' has linear complexity" and similar.
And of course, it is easy to simulate on a k-TM.
4) Functional RTM
Extend Prog by closures and function application, introducing functions as first-class citizens roughly as follows:
inductive FProg where
-- var, empty, cons, ... similar to Prog plus
-- function definition, taking one variable, but also allow environment capture.
| fn (body : FProg) : FProg
-- function applycation.
| apply (f arg : FProg) : FProg
This extensions allows recursion, a feature that makes some proofs much easier (for example Savitch's theorem), but there are also many proofs that can be done using the function-free RTM alone.
I have not yet fully specced-out this extension.
5) Sub-Linear-Space Modifier
Neither the RTM nor the FRTM allow sub-linear space usage. They also make it difficult to define oracle tapes, nondeterminism for space or other extensions of multi-tape Turing machines.
There is a similar problem for single-tape Turing machines, but that could be overcome.
I would propose to overcome all of these in a unified way instead: Define a "machine modifier" that can extend any machine with a way to run in sub-linear-space, allow oracle access, nondeterminism and other "features".
So the goal is that this modifier takes an arbitrary machine model that "compatible" with a k-TM above linear space and returns a machine model that is compatible also below linear space.
For a machine model Machine, assume we have
Computes : Machine → (List Bool) → (List Bool) → ℕ → ℕ → Prop
such that Computes m x y t s means that machine m on input x outputs y and uses time t and space s.
On top of this we define something like ComputesModified, which keeps on running a machine of type Machine and supplies the current input symbol to it, expecting it to output a four-tuple of: termination flag, input head movement, optional output bit,
state to forward.
The time usage of the modified machine is the sum of the times spent in the inner machine and the space usage is the max over all iterations.
This models a multi-tape Turing machine with read-only input tape and write-only output tape but allowing a machine of any type as the control of that machine.
It does not matter if the inner machine can only model linear space and above since the space usage is taken relative to the input size, but the inner machine is never supplied with the "full input" at once.
Of course this has to be proven equivalent to a "ground truth" complexity measure with bounds on the translation. If that "ground truth" is the k-TM, then this should follow more or less directly from the general equivalence.
Formally (please excuse any bugs, enc is an encoding function),
inductive ComputesModified'
(m : Machine) (input : List Bool) (output : List Bool) (t : ℕ) (s : ℕ)
(inputPos : ℕ) (state : List Bool) : Prop
| noOut -- inner machine does not terminate, does not output anything, but moves head
(h1 : Computes m (enc (input[inputPos]?, state)) (enc (false, move, none, state')) t1 s1)
(h_move : -1 ≤ move ∧ move ≤ 1 ∧ 0 ≤ inputPos + move ∧ inputPos + move ≤ input.length)
(h2 : ComputesModified' m input output t2 s2 (inputPos + move) state') :
ComputesModified' m input output (t1 + t2) (max s1 s2) inputPos state
| out -- inner machine does not terminate, outputs one bit, moves head
(h1 : Computes m (enc (input[inputPos]?, state)) (enc (false, move, some o, state')) t1 s1) :
(h_move : -1 ≤ move ∧ move ≤ 1 ∧ 0 ≤ inputPos + move ∧ inputPos + move ≤ input.length)
(h2 : ComputesModified' m input output' t2 s2 (inputPos + move) state') :
ComputesModified' m input (o :: output') (t1 + t2) (max s1 s2) inputPos state
| term -- inner machine terminates
(h1 : Computes m (enc (input[inputPos]?, state)) (enc (true, 0, none, state')) t1 s1) :
ComputesModified' m input [] t1 s1 inputPos state
def ComputesModified (m : Machine) (x : List Bool) (y : List Bool) (t : ℕ) (s : ℕ) : Prop :=
ComputesModified' m x y t s 0 []
Further extensions:
In addition to the input being "fed" to the machine, we could feed one bit of a binary "path" string on every iteration. This would be equivalent to a read-only-no-move-left tape and could allow us to model non-determinism also for space-bounded machines correctly and even alternation for both space and time. Similarly, we could model oracles where the output of the machine contains the optional oracle question and the answer is either fed bit-by-bit to the inner machine (if it is more than one bit) like the input tape contents or as a full word.
The advantage of this model is that we could use the full expressive power of the functional RTM but still make it "look like" a Turing machine, and we could put this extension on any machine model where we know how its resource model translates.
Simulations
Note that two machine models are considered to be "compatible" if the simulation has a linear space overhead and a polynomial time overhead. Of course, lower time overhead is still better, but does not matter for most theorems.
1) 1-TM -> Function-free RTM
(read: 1-TM simulated by a Function-free RTM)
Done in my fork, is a more-or-less obvious translation of the definition of the 1-TM to RTM.
Should be easy to extend to k-TM.
2) Function-free RTM -> k-TM
Data is encoded as parenthesized expressions, i.e. enc (Data.l []) = "()".
One tape for each AST node plus some aux tapes for elim, fold and while. The most complicated part is skipping one element of Data in elim and fold. This is done by counting the nesting depth in unary on a helper tape, if it reaches zero again, we are at the end of the element.
Both time and space overhead should be linear.
3) k-TM -> 1-TM
Should be the standard textbook simulation that extends the alphabet such that there are multiple tracks on the tape with markers for the head. Each step, we traverse the full tape to read the symbols and perform write and head movement actions, resulting in quadratic time overhead and linear space overhead. There might be more efficient simulations, but this is probably OK for now.
4) Function-free RTM -> Functional RTM
Obvious, it is a subset.
5) Functional RTM -> Function-free RTM
Defunctionalize, simulate using an operator and a result stack.
The resource consumption of Functional RTM is not yet defined, so I'm pretty sure we should be able to achieve linear overhead with the simulation.
First Actual Theorems
Once we have a sequence of expressive machine models, we can finally start proving some theorems.
There is the approach of Blum where we don't even need explicit machine models, but just assumptions that certain functions are computable, which could also be an option.
Trivial Inclusions
DTIME(t) ⊆ DSPACE(O(t)) - should be easy once we have defined DTIME and DSPACE
DSPACE(s) ⊆ DTIME(2^O(s)) - count the number of configurations of a k-TM with bounded space
Hierarchy Theorems
This should be easy already with Function-Free RTM. I did the simulation 1-TM -> Function-free RTMb in a way that it can uniformly simulate a 1-TM, i.e. the 1-TM is part of the input.
We need to extend it to track the space and time usage during simulation and of course negate the output.
Gap Theorem
Also not too much more complicated than hierarchy theorems. Complications are mostly on the argumentation side, not the algorithm side.
Cook-Levin
SAT ∈ NP should be easy to show conceptually. It depends on how we define NP, it's easy to show in the "polynomial verifier" setting. Showing this equivalent to the k-TM with "path" tape or in the "Modified Machine" model should also not be too hard. It might be a more difficult with a version of a TM that uses a "multi-valued transition function".
The other part has been done by Maximilian, albeit for the Mathlib version of the Turing machine.
I'm not sure how difficult this is to adapt.
Relationship to Non-Machine Classes
REG = DSPACE(O(1))
(or even DSPACE(s) for s ∈ o(log log n))
REG ⊆ DSPACE(O(1)) should be easy with the "Modified Machine" model above. The "inner" machine just executes the automaton, always moves right and stores the automaton state in state. It outputs 0 / 1 upon reaching the first blank symbol.
DSPACE(O(1)) ⊆ REG - should also follow from the "Modified Machine" model plus pumping lemma.
Savitch's Theorem
Savitch's theorem (nondeterministic space is in quadratric deterministic space) relies on showing that s-t-connectivity in graphs can be solved in quadratic logarithmic space in the number of vertices. The algorithm "guesses" the "mid-point" by iterating through all possible nodes and then calling itself recursively twice.
This is rather difficult to implement on Turing machines or even function-free RTMs. But on RTMs with functions, it should be doable. Note that we need recursive function calls and loops that iterate over all vertices such that they only store the current vertex number as an index.
I don't think this is easy to do using recursion (unless we add tail recursion into the cost model), but fortunately, we have the while loop from function-free RTM, that just does this easily.
- 主要言語
- Lean
- スター
- 847
- フォーク
- 234
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 49
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
leanprover/cslib のほかの issue
-
`listFullBeta_cons_r` should rename to `listFullBeta_concat_r`対応中かも @lengyijun が 134 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
leanprover/cslib#784 ·
メンテナーはふだん 1 日以内に返信
-
logic
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
leanprover/cslib#74 ·
メンテナーはふだん 1 日以内に返信
-
dependency-incompatibility
難易度 3/5 半日 初心者へのやさしさ 45/100
leanprover/cslib#1271 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
leanprover/cslib#1262 ·
メンテナーはふだん 1 日以内に返信
-
BetaAt.appR doesn't require LC N, weakening BetaAt.lc_r, not consistent with FullBeta対応中かも @Digger-Rockwell が 5 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
leanprover/cslib#1243 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
leanprover/cslib の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
sindresorhus/eslint-plugin-unicorn#4045 ·
メンテナーはふだん 1 日以内に返信
-
`simp environment new` creates rsync/CentOS unconditionally, so the rsync skeleton cannot ship itオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
simp/rubygem-simp-cli#244 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Automattic/blocks-engine#7459 ·
メンテナーはふだん 1 日以内に返信
-
vote-tally: date_order_mismatches compares ISO dates as text, so UTC offsets are misread対応中かも @leninworld が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
bucharitesh/qrdx#852 ·