Zulip Chat Archive

Stream: new members

Topic: Help: Notation for Turing Machines from transition table


Thomas Vigouroux (Aug 27 2024 at 08:22):

Hi,
I would like to implement an notation for Turing machine that mimics this notation: https://wiki.bbchallenge.org/wiki/Turing_machine#Standard_text_format

I don't know if this is possible or if anyone had experience implementing similar notations. I am fine learning how to handle elaboration and stuff like that by the way, but would greatly appreciate any guidance.

My formalisation of Turing machines is there by the way: https://git.sr.ht/~vigoux/busybeaver/tree/master/item/Busybeaver/Basic.lean#L69

Martin Dvořák (Aug 27 2024 at 10:22):

Are you interested in parsing
image.png
to a docs#TuringMachine term?

Or do you also want to use the notation
image.png
for describing the computation?

Thomas Vigouroux (Aug 27 2024 at 10:27):

I'd say both

Martin Dvořák (Aug 27 2024 at 12:18):

Regarding the latter notation, would writing something like ⟨[0, 0, 0], A, 0, [0, 0, 0]⟩ be good enough?
Or do you actually want to require single-character identifiers, no delimiters, and so on?

Thomas Vigouroux (Aug 27 2024 at 12:18):

For this I already have a notation actually, which resembles this

Thomas Vigouroux (Aug 27 2024 at 12:19):

And I think it is fine writing them like this

Thomas Vigouroux (Aug 27 2024 at 12:19):

Or at least, we can postpone such considerations to later

Thomas Vigouroux (Aug 27 2024 at 12:19):

Thanks for your time by the way !

Thomas Vigouroux (Aug 30 2024 at 09:45):

I am trying to have this working but I am stuck, here is my current implementation:

/-
Parsing machines in standard format for convenience.
-/
import Busybeaver.Basic

open Lean Elab

declare_syntax_cat dir

syntax "L": dir
syntax "R": dir

def elabDir : Syntax  MetaM Expr
  -- `mkAppM` creates an `Expr.app`, given the function `Name` and the args
  -- `mkNatLit` creates an `Expr` from a `Nat`
  | `(dir | L) => Meta.mkAppM ``Turing.Dir.left #[]
  | `(dir | R) => Meta.mkAppM ``Turing.Dir.right #[]
  | _ => throwUnsupportedSyntax

declare_syntax_cat symbol
syntax num : symbol

declare_syntax_cat label
syntax "A" : label
syntax "B" : label
syntax "C" : label
syntax "D" : label
syntax "E" : label
syntax "F" : label

declare_syntax_cat stmt
syntax symbol dir label: stmt
syntax "...": stmt

def elabStmt : Syntax  MetaM Expr
  -- `mkAppM` creates an `Expr.app`, given the function `Name` and the args
  -- `mkNatLit` creates an `Expr` from a `Nat`
  | `(stmt | ...) => Meta.mkAppM ``TM.Stmt.halt #[]
  | `(stmt | $S:symbol $D:dir $L:label ) => do dbg_trace "stmt"; throwUnsupportedSyntax
  | _ => throwUnsupportedSyntax

elab "test_elab " l:stmt : term => elabStmt l

#reduce test_elab ...

Last updated: May 02 2025 at 03:31 UTC