Halting of a drawn partial recursive code

Lax624099.CodeHalting · concepts/Lax624099/CodeHalting.lean · lax-624099

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural Language Statement

    Definition

    An instance is the syntax tree of a partial recursive code of Mathlib, drawn with one element per node: a node carries one of the eight constructor marks, zero, successor, left, right, pair, composition, primitive recursion and unbounded search, its children are given by two binary relations, and one node is marked as the root. A node decodes to a code by recursion on the code: it carries the code's constructor mark and its children decode to the constructor's arguments. CODEHALT is the decision problem of the structures isomorphic to one whose root decodes to a code that halts on input zero.

    Concept map
    7 concepts; 19 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Mathlib.Computability.PartrecCode
    2import Mathlib.ModelTheory.Semantics
    3import Mathlib.ModelTheory.Complexity
    4import Mathlib.Tactic.FinCases
    5import Lax904597.Classes
    6import Lax624099.Problems
    7
    8/-!
    9---
    10title: Halting of a drawn partial recursive code
    11type: definition
    12---
    13An instance is the syntax tree of a partial recursive code of Mathlib,
    14drawn with one element per node: a node carries one of the eight constructor
    15marks, zero, successor, left, right, pair, composition, primitive recursion
    16and unbounded search, its children are given by two binary relations, and
    17one node is marked as the root. A node decodes to a code by recursion on the
    18code: it carries the code's constructor mark and its children decode to the
    19constructor's arguments. CODEHALT is the decision problem of the structures
    20isomorphic to one whose root decodes to a code that halts on input zero.
    21-/
    22
    23namespace Lax624099.CodeHalting
    24
    25open FirstOrder
    26
    27open FirstOrder.Language
    28
    29/-- Relation symbols of code instances. -/
    30inductive codeRel : ℕ → Type
    31 /-- `croot n`: `n` is the root of the syntax tree. -/
    32 | croot : codeRel 1
    33 /-- `czero n`: `n` draws the constructor `zero`. -/
    34 | czero : codeRel 1
    35 /-- `csucc n`: `n` draws the constructor `succ`. -/
    36 | csucc : codeRel 1
    37 /-- `cleft n`: `n` draws the constructor `left`. -/
    38 | cleft : codeRel 1
    39 /-- `cright n`: `n` draws the constructor `right`. -/
    40 | cright : codeRel 1
    41 /-- `cpair n`: `n` draws the constructor `pair`. -/
    42 | cpair : codeRel 1
    43 /-- `ccomp n`: `n` draws the constructor `comp`. -/
    44 | ccomp : codeRel 1
    45 /-- `cprec n`: `n` draws the constructor `prec`. -/
    46 | cprec : codeRel 1
    47 /-- `crfind n`: `n` draws the constructor `rfind'`. -/
    48 | crfind : codeRel 1
    49 /-- `carg1 n m`: `m` is the first child of `n`. -/
    50 | carg1 : codeRel 2
    51 /-- `carg2 n m`: `m` is the second child of `n`. -/
    52 | carg2 : codeRel 2
    53 deriving DecidableEq
    54
    55/-- The relational language of code instances: the eight constructor marks,
    56the mark of the root, and the two child relations. -/
    57def code : Language :=
    58 ⟨fun _ => Empty, codeRel⟩
    59
    60instance instIsRelationalCode : IsRelational code :=
    61 fun _ => ⟨fun f => Empty.elim f⟩
    62
    63/-- The root symbol. -/
    64abbrev cRoot : code.Relations 1 := .croot
    65
    66/-- The `zero` symbol. -/
    67abbrev cZero : code.Relations 1 := .czero
    68
    69/-- The `succ` symbol. -/
    70abbrev cSucc : code.Relations 1 := .csucc
    71
    72/-- The `left` symbol. -/
    73abbrev cLeft : code.Relations 1 := .cleft
    74
    75/-- The `right` symbol. -/
    76abbrev cRight : code.Relations 1 := .cright
    77
    78/-- The `pair` symbol. -/
    79abbrev cPair : code.Relations 1 := .cpair
    80
    81/-- The `comp` symbol. -/
    82abbrev cComp : code.Relations 1 := .ccomp
    83
    84/-- The `prec` symbol. -/
    85abbrev cPrec : code.Relations 1 := .cprec
    86
    87/-- The `rfind'` symbol. -/
    88abbrev cRfind : code.Relations 1 := .crfind
    89
    90/-- The first-child symbol. -/
    91abbrev cArg1 : code.Relations 2 := .carg1
    92
    93/-- The second-child symbol. -/
    94abbrev cArg2 : code.Relations 2 := .carg2
    95
    96open FirstOrder
    97
    98open Language Structure
    99
    100section Shorthands
    101
    102variable {A : Type} [code.Structure A]
    103
    104/-- Being the root. -/
    105def CRoot (a : A) : Prop := RelMap cRoot ![a]
    106
    107/-- Drawing the constructor `zero`. -/
    108def CZero (a : A) : Prop := RelMap cZero ![a]
    109
    110/-- Drawing the constructor `succ`. -/
    111def CSucc (a : A) : Prop := RelMap cSucc ![a]
    112
    113/-- Drawing the constructor `left`. -/
    114def CLeft (a : A) : Prop := RelMap cLeft ![a]
    115
    116/-- Drawing the constructor `right`. -/
    117def CRight (a : A) : Prop := RelMap cRight ![a]
    118
    119/-- Drawing the constructor `pair`. -/
    120def CPair (a : A) : Prop := RelMap cPair ![a]
    121
    122/-- Drawing the constructor `comp`. -/
    123def CComp (a : A) : Prop := RelMap cComp ![a]
    124
    125/-- Drawing the constructor `prec`. -/
    126def CPrec (a : A) : Prop := RelMap cPrec ![a]
    127
    128/-- Drawing the constructor `rfind'`. -/
    129def CRfind (a : A) : Prop := RelMap cRfind ![a]
    130
    131/-- Being the first child. -/
    132def CArg1 (a b : A) : Prop := RelMap cArg1 ![a, b]
    133
    134/-- Being the second child. -/
    135def CArg2 (a b : A) : Prop := RelMap cArg2 ![a, b]
    136
    137end Shorthands
    138
    139section Decode
    140
    141variable {A : Type} [code.Structure A]
    142
    143/-- **The node `n` draws the code `c`.** A recursion on the code: the mark of
    144the node must be the constructor's, and its children must draw the
    145constructor's arguments. -/
    146def DecodesTo (n : A) : Nat.Partrec.Code → Prop
    147 | .zero => CZero n
    148 | .succ => CSucc n
    149 | .left => CLeft n
    150 | .right => CRight n
    151 | .pair cf cg =>
    152 CPair n ∧ ∃ a b, CArg1 n a ∧ CArg2 n b ∧ DecodesTo a cf ∧ DecodesTo b cg
    153 | .comp cf cg =>
    154 CComp n ∧ ∃ a b, CArg1 n a ∧ CArg2 n b ∧ DecodesTo a cf ∧ DecodesTo b cg
    155 | .prec cf cg =>
    156 CPrec n ∧ ∃ a b, CArg1 n a ∧ CArg2 n b ∧ DecodesTo a cf ∧ DecodesTo b cg
    157 | .rfind' cf => CRfind n ∧ ∃ a, CArg1 n a ∧ DecodesTo a cf
    158
    159end Decode
    160
    161open Lax904597.Problems Lax624099.Problems
    162
    163/-- The root of the instance draws a code halting on `0`. -/
    164def CodeHaltsOn (A : Type) [code.Structure A] : Prop :=
    165 ∃ (n : A) (c : Nat.Partrec.Code), CRoot n ∧ DecodesTo n c ∧ (Nat.Partrec.Code.eval c 0).Dom
    166
    167/-- CODEHALT: does the partial recursive code drawn in the instance halt on
    168`0`? -/
    169def CODEHALT : DecisionProblem code :=
    170 DecisionProblem.ofPred CodeHaltsOn
    171
    172end Lax624099.CodeHalting
    173

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…