Coq-BB5 Formal Verification Project

repository·main·Indexed 18 days ago

https://github.com/ccz181078/coq-bb5

A formal verification project using the Coq proof assistant to prove specific Busy Beaver values. The repository includes proofs for BB(2)=6, BB(2,3)=38, and BB(2,4)=3,932,964, utilizing Tree Normal Form (TNF) enumeration and a pipeline of deciders (Loops, n-gram CPS, and RepWL). It requires Coq v8.20.1 and provides OCaml extraction scripts to export verified enumeration results to CSV files.

Tokens
14.4K
Snippets
38
Records
75
Agent score
60%

What's inside Coq-BB5

  1. Overview of the BB(5) = 47,176,870 proof

    main

    This project provides a Coq proof verifying that the Busy Beaver number for 5 states, $BB(5)$, is exactly $47,176,870$. This represents the maximum number of steps a halting 5-state Turing machine can perform starting from an all-0 tape.

    The proof works by enumerating 5-state Turing machines and using deciders to determine if each machine halts or not, and ensuring that any halting machine does so within the $47,176,870$ step limit.

  2. Overview of Coq-BB5

    main
    Coq-BB5 is a formal verification project that uses the Coq proof assistant (version v8.20.1) to prove theorems regarding Busy Beaver values. It provides formal proofs for several key results, including the determination of BB(5) and BB(2,4), as well as confirmations of previously known values like BB(4), BB(3), BB(2), and BB(2,3).
  3. Overview of Coq-BB5 proofs

    main

    Coq-BB5 is a repository containing Coq proofs (compatible with Coq v8.20.1) regarding Busy Beaver values. It provides formal verification for several Busy Beaver results, including original proofs for BB(5) and BB(2,4), and confirmations of previously known results for BB(4), BB(3), BB(2), and BB(2,3).

    Note that for previously known results, the Coq proofs confirm the values but do not attempt to reproduce the original historical proofs.

  4. Access the full BusyCoq repository

    main
    The files in this directory represent a partial snapshot of the BusyCoq repository (specifically at commit 333695b79707189d49f5e560a55c3ab8dda1cdc6). For the complete repository and original context, refer to the official BusyCoq repository on GitHub.
  5. Understand the proof structure of Coq-BB5

    main

    The proofs in this repository follow a hierarchical structure based on complexity:

    1. BB(5) Proof: This is the most general proof. It contains the full suite of techniques used in the project.
    2. Other Proofs: All other proofs (e.g., BB(4), BB(3), etc.) use only subsets of the techniques found in the BB(5) proof. They follow a structure that is a simplified version of the BB(5) proof structure, specifically modeled after the BB(4) proof structure.

    For detailed information on the specific proof structure of BB(5), refer to the CoqBB5/BB5/README.md file.

  6. How BusyCoq is used in Coq-BB5

    main

    To prove that BB(5) = 47,176,870, Coq-BB5 utilizes the busycoq library. Specifically, busycoq is used to prove that certain 5-state 2-symbol Turing machines, referred to as Sporadic Machines, do not halt.

    The BusyCoq/ directory in this repository contains a partial snapshot of the busycoq library, including only the specific proofs required for the CoqBB5/BB5/ proofs.

  7. Understand the TNF Tree structure and parallelization strategy

    main

    The proof is parallelized by splitting the TNF tree into several subtrees, each contained in a separate Coq file. The original root represents completely undefined Turing machines and has 8 children.

    To optimize proof search, you can leverage symmetry: the four roots using direction L do not need to be searched directly; instead, their computation can be symmetrized to use direction R.

    Root Distribution:

    • TNF_Root_1.v: explores 0RA---_------_------_------_------
    • TNF_Root_2.v: explores 1RA---_------_------_------_------
    • TNF_Root_3.v: explores 0RB---_------_------_------_------
    • TNF_Root_4.v: explores 1RB---_------_------_------_------. This root is further expanded into 12 children located in the TNF_Root_4/ subfolder.

    Leaf Nodes: Files in the TNF_Root_4/ directory marked with _leaf (e.g., TNF_Root_4/TNF_Root_4_3_leaf.v) represent nonhalting children of root_4. These are terminal nodes in the overall TNF tree and do not yield additional subtrees.

  8. Understand the Skelet17 tape representation (level 2 behavior)

    main

    At level 2 of the proof, the tape configuration is abstracted using the lower function.

    lower [a[0]; a[1]; ...; a[l-1]] represents a tape containing 10 repeaters separated by 1s, with the head positioned at the right. Specifically, it represents: 10^a[l-1] ... 1 10^a[1] 1 10^a[0] <C.

    Key list operations used in this representation:

    • a++b: List concatenation.
    • a::b: Prepending element a to list b (concatenation of a single element).
    • <C: Indicates the head position/state context.
  9. Understand the BB(4) Proof Structure and Deciders

    main

    The proof for BB(4) = 107 works by enumerating 4-state Turing machines in Tree Normal Form (TNF) and passing them through a pipeline of deciders.

    Core Components

    • Statement & Theorem: BB4_Statement.v contains the main definitions and theorem, while BB4_Theorem.v is the entry point.
    • TNF Enumeration: BB4_TNF_Enumeration.v implements the algorithm that visits machines in a tree structure. It ignores machines whose first head move is Left (due to symmetry) but includes both machines starting with 0 and 1 to simplify the proof.
    • Decider Pipeline: Machines are processed by a subset of the BB(5) pipeline (defined in BB4_Deciders_Pipeline.v):
      1. Loops: ../BB5/Deciders/Decider_Loop.v
      2. n-gram Closed Position Set (n-gram CPS): ../BB5/Deciders/Decider_NGramCPS.v
      3. Repeated Word List (RepWL): ../BB5/Deciders/Decider_RepWL.v

    Each decider is implemented and proven correct in Coq, ensuring that if they output HALT or NONHALT, the result is mathematically sound.

  10. Understand the Decider abstractions in Coq-BB5

    main

    In this project, Deciders are algorithms designed to determine whether a given Turing Machine (TM) halts or not when starting from an all-0 tape.

    Core Concepts

    • Turing Machine (TM) Model: A TM is defined by the type $St \to \Sigma \to ((St \times {-1, +1} \times \Sigma) + {\bot})$. Given a current state and input, it returns the next state, head movement direction, and output. The symbol $\bot$ indicates the machine halts at the next step.
    • ExecState: Represents the state of the machine after some steps, encoded as $St \times (\mathbb{Z} \to \Sigma)$, which captures the current state and the entire tape content.
  11. Understand the WF1 and WF2 Configuration Types

    main

    The system uses two inductive types, WF1 and WF2, to track the valid configuration states of the counter. This ensures that certain invalid states (like a list containing only even numbers in specific positions) are unreachable.

    • WF1: A basic configuration where all elements in the list (except potentially the last) are non-zero.
    • WF2: A more complex configuration used during specific transitions. It requires elements to be even, a specific odd element y, and non-zero elements in the remainder of the list zs, ending with [O; O].

    Transitions between WF1 and WF2 are managed by the pre-conditions of the Increment, Halve, Zero, and Overflow operations to maintain system invariants.

    Inductive WF1: (nat*(list nat))->Prop :=
    | WF1_intro x xs y:
      Forall Nonzero xs ->
      WF1 (x,xs ++ [y]).
    
    Inductive WF2: (nat*(list nat))->Prop :=
    | WF2_intro x xs y zs:
      Forall Nonzero xs ->
      Forall Even xs ->
      Odd y ->
      Forall Nonzero zs ->
      WF2 (x,xs ++ y :: zs ++ [O; O])
  12. Understand the BB(2)=6 Proof Structure

    main

    The proof follows a specific logical structure involving Tree Normal Form (TNF) enumeration and a pipeline of deciders:

    1. TNF Enumeration

    The proof enumerates 2-state machines in Tree Normal Form (TNF). The algorithm (BB2_TNF_Enumeration.v) works as follows:

    • If a machine halts (meets an undefined transition), the algorithm visits a new subtree of machines representing all possible ways to fill that undefined transition.
    • If a machine does not halt, it is treated as a leaf in the TNF tree.
    • The enumeration ignores machines whose first head move is Left (due to symmetry) but includes machines starting by writing either 0 or 1 to maintain a simpler proof.

    2. Decider Pipeline

    Each enumerated machine is passed through a pipeline of deciders (BB2_Deciders_Pipeline.v) to determine if it halts or not. The deciders are programmed and proven correct in Coq. The pipeline for BB(2) includes:

    • Loops: See ../BB5/Deciders/Decider_Loop.v.
    • n-gram Closed Position Set (n-gram CPS): See ../BB5/Deciders/Decider_NGramCPS.v.

    3. Key Files

    • BB2_Statement.v: Contains main definitions and the BB(2) = 6 theorem statement.
    • BB2_Theorem.v: The entry point of the proof.
    • BB2_Deciders_Generic.v: Defines the IDs for the deciders.