Langlib

Langlib.Automata.Turing.Equivalence.GrammarToTM.MembershipComputability

Computability of the Grammar Membership Test #

This file establishes that the grammarTest function is Computable₂.

Key results #

Structure #

  1. Primcodable instances for symbol and grule
  2. Primrec lemmas for symbol constructors and grule field projections
  3. primrec_applyRuleAtapplyRuleAt is primitive recursive
  4. computable_extractTerminalsextractTerminals is computable
  5. primrec_applyRuleSeq_step / computable_applyRuleSeq — rule sequence application
  6. grammarTest_computable₂ — the final result

Primcodable instances #

noncomputable def symbolEquiv (T N : Type) :
symbol T N T N
Equations
  • One or more equations did not get rendered due to their size.
Instances For
    noncomputable def gruleEquiv (T N : Type) :
    grule T N List (symbol T N) × N × List (symbol T N) × List (symbol T N)
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      noncomputable instance grulePrimcodable {T N : Type} [Primcodable T] [Primcodable N] :
      Equations

      Symbol constructors are primrec #

      theorem primrec_symbol_casesOn {T N σ : Type} [Primcodable T] [Primcodable N] [Primcodable σ] {α : Type} [Primcodable α] {f : αsymbol T N} {g : αTσ} {h : αNσ} (hf : Primrec f) (hg : Primrec₂ g) (hh : Primrec₂ h) :
      Primrec fun (a : α) => match f a with | symbol.terminal t => g a t | symbol.nonterminal n => h a n

      Case analysis on symbol is primrec.

      grule field projections are primrec #

      theorem primrec_grule_inputL {T N : Type} [Primcodable T] [Primcodable N] :
      Primrec fun (r : grule T N) => r.input_L
      theorem primrec_grule_inputN {T N : Type} [Primcodable T] [Primcodable N] :
      Primrec fun (r : grule T N) => r.input_N
      theorem primrec_grule_inputR {T N : Type} [Primcodable T] [Primcodable N] :
      Primrec fun (r : grule T N) => r.input_R

      applyRuleAt is primrec #

      theorem primrec_applyRuleAt {T : Type} [DecidableEq T] {N : Type} [DecidableEq N] [Primcodable T] [Primcodable N] :
      Primrec fun (args : grule T N × List (symbol T N) × ) => applyRuleAt args.1 args.2.1 args.2.2

      extractTerminals is computable #

      applyRuleSeq with fixed args is computable #

      theorem primrec_applyRuleSeq_step {T : Type} [DecidableEq T] {N : Type} [DecidableEq N] [Primcodable T] [Primcodable N] (rules : List (grule T N)) :
      Primrec fun (p : Option (List (symbol T N)) × × ) => match p.1 with | none => none | some sf => match rules[p.2.1]? with | none => none | some r => applyRuleAt r sf p.2.2
      theorem computable_applyRuleSeq {T : Type} [DecidableEq T] {N : Type} [DecidableEq N] [Primcodable T] [Primcodable N] (rules : List (grule T N)) (init : List (symbol T N)) :
      Computable fun (seq : List ( × )) => applyRuleSeq rules init seq

      Main result #