Skip to content

feat(Foundations/Data): Function view for Turing tapes#499

Open
crei wants to merge 3 commits intoleanprover:mainfrom
crei:tapes_as_functions
Open

feat(Foundations/Data): Function view for Turing tapes#499
crei wants to merge 3 commits intoleanprover:mainfrom
crei:tapes_as_functions

Conversation

@crei
Copy link
Copy Markdown

@crei crei commented Apr 18, 2026

The central addition in this PR is BiTape.get: it allows (integer) index-based access to the Turing tape cells.

In addition, adds several lemmas that make it easier to work with BiTapes by viewing them as functions ℤ → Option Symbol. A sequence of moves and writes translates into a sequence of Function.update and thus maps everything into a domain that simp and grind can already nicely work with.

@BoltonBailey
Copy link
Copy Markdown
Contributor

Seems like a good addition! My only comment is: Should we add tags like @[ext] or grind = to some of these to improve integration with tactics?

Copy link
Copy Markdown
Collaborator

@chenson2018 chenson2018 left a comment

Choose a reason for hiding this comment

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

This looks straightforward, thanks! Just some style questions.

Comment thread Cslib/Foundations/Data/BiTape.lean Outdated
obtain ⟨head₂, left₂, right₂⟩ := t₂
have h_head : head₁ = head₂ := by simpa [get] using h_get_eq 0
have h_right : right₁ = right₂ := by
apply StackTape.ext_get
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.

Should StackTape.ext_get and this theorem have ext attributes?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

After adding the attributes to StackTape.ext and StackTape.ext_get, I can use ext1 p here, but how can I be sure that the ext tactic uses StackTape.ext_get instead of StackTape.ext?

Comment thread Cslib/Foundations/Data/BiTape.lean Outdated
Comment thread Cslib/Foundations/Data/BiTape.lean Outdated
apply StackTape.ext_get
intro p
simpa [get] using h_get_eq (Int.negSucc p)
simp only [h_head, h_left, h_right]
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.

No need to squeeze terminal simp. Can also just be grind if you prefer.

Comment thread Cslib/Foundations/Data/BiTape.lean Outdated
Comment thread Cslib/Foundations/Data/BiTape.lean Outdated
Comment thread Cslib/Foundations/Data/BiTape.lean Outdated
cases d with
| none => simp
| some d =>
cases d <;> simp [move, show p + (-1 : ℤ) = p - 1 from by omega]
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.

I'm not a fan of nested simp and grind. Here it seems particularly not needed because you can write

Suggested change
cases d <;> simp [move, show p + (-1 : ℤ) = p - 1 from by omega]
cases d
· grind [move, get_move_left]
· grind [move, get_move_right]

maybe some of these should be simp/grind =?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It seems that grind [move] solves the whole thing just after the unfold commands - maybe also because I added some more annotations.

Comment thread Cslib/Foundations/Data/BiTape.lean Outdated
Comment thread Cslib/Foundations/Data/BiTape.lean Outdated
@chenson2018 chenson2018 self-assigned this Apr 18, 2026
@chenson2018 chenson2018 changed the title feat(Foundations/Data): Function view for Turing tapes. feat(Foundations/Data): Function view for Turing tapes Apr 18, 2026
crei and others added 2 commits April 20, 2026 11:38
Co-authored-by: Chris Henson <46805207+chenson2018@users.noreply.github.com>
@crei crei requested a review from chenson2018 April 21, 2026 08:58
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.

3 participants