Physlib

Physlib.Meta.Sorry

Meta results regarding `sorry` and `pseudo` attributions

i. Overview

The purpose of this module is to collect all results which depend on the `sorryAx` axiom and the `Lean.ofReduceBool` axiom, and check that these results are correctly attributed `sorryful` and `pseudo` respectively.

ii. Key results

- `sorryfulPseudoTest` : A test that all results attributed `sorryful` depend on the `sorryAx` axiom and vice versa, and all results attributed `pseudo` depend on the `Lean.ofReduceBool` axiom and vice versa.

iii. Table of contents

- A. Collectings results depending on `sorryAx` and `Lean.ofReduceBool` - A.1. The state information to be collected - A.2. The monad for collecting names - A.3. The collection function - A.4. Given an array updating the state with all names depending on axioms - A.5. Given an array getting all names depending on axioms - A.6. Getting all names depending on axioms from all user defined constants - B. Collecting all names attributed `sorryful` and `pseudo` - C. Testing the `sorryful` and `pseudo` attributions are correctly applied

iv. References

Some of the code here is adapted from from the file: `Lean.Util.CollectAxioms` copyright (c) 2020 Microsoft Corporation. Authored by Leonardo de Moura.

A. Collectings results depending on `sorryAx` and `Lean.ofReduceBool`

A.1. The state information to be collected

A.2. The monad for collecting names

A.3. The collection function

A.4. Given an array updating the state with all names depending on axioms

A.5. Given an array getting all names depending on axioms

A.6. Getting all names depending on axioms from all user defined constants

B. Collecting all names attributed `sorryful` and `pseudo`

C. Testing the `sorryful` and `pseudo` attributions are correctly applied

8 declarations

abbrev

Monad MM for collecting axiom-dependent results

The monad MM is defined as M:=ReaderT(Environment,StateM(State))M := \text{ReaderT}(\text{Environment}, \text{StateM}(\text{State})). It provides a computational context that combines read-only access to the Lean Environment\text{Environment} with a mutable State\text{State} for the purpose of traversing and collecting the names of constants that depend on the axioms sorryAx\texttt{sorryAx} (representing "sorry" proofs) and Lean.ofReduceBool\texttt{Lean.ofReduceBool} (representing pseudo-definitions).

definition

Update Monad MM with Axiom Dependencies of Name cc

Given a Lean name cc and a set of names representing its ancestors in the dependency graph, parents\text{parents}, the function updates the state within the monad MM by determining if the constant cc or its dependencies rely on the axioms sorryAx\texttt{sorryAx} (indicating "sorry" proofs) or Lean.ofReduceBool\texttt{Lean.ofReduceBool} (indicating pseudo-definitions).

definition

Update Monad MM with Axiom Dependencies for Array cc

Given an array of Lean names cc, the function iterates through each name xcx \in c and applies the collect\texttt{collect} function with an empty set of ancestor names. This operation updates the internal state of the monad MM by identifying whether the constants corresponding to the names in cc and their recursive dependencies rely on the axioms sorryAx\texttt{sorryAx} (representing "sorry" proofs) or Lean.ofReduceBool\texttt{Lean.ofReduceBool} (representing pseudo-definitions).

definition

Collect `sorryAx` and `ofReduceBool` dependencies for cc

Given an array of names cc, this function identifies all constants in the dependency closure of cc that rely on the sorryAx\texttt{sorryAx} or Lean.ofReduceBool\texttt{Lean.ofReduceBool} axioms. It returns a pair of arrays (A,B)(A, B) in the `CoreM` monad, where AA contains the names of results depending on sorryAx\texttt{sorryAx} (representing "sorry" proofs) and BB contains the names of results depending on Lean.ofReduceBool\texttt{Lean.ofReduceBool} (representing pseudo-definitions).

definition

All user-defined constants with sorryAx\texttt{sorryAx} or Lean.ofReduceBool\texttt{Lean.ofReduceBool} dependencies

This function, operating within the Lean core environment monad (CoreM\text{CoreM}), identifies all user-defined constants in the current environment that depend on either the sorryAx\texttt{sorryAx} or Lean.ofReduceBool\texttt{Lean.ofReduceBool} axioms. It returns a pair of arrays (A,B)(A, B), where AA is the collection of names of constants whose definitions or proofs rely on the sorryAx\texttt{sorryAx} axiom (indicating the presence of sorry\texttt{sorry}), and BB is the collection of names of constants relying on the Lean.ofReduceBool\texttt{Lean.ofReduceBool} axiom (indicating pseudo-definitions).

definition

Names attributed `sorryful`

The computation retrieves and returns an array containing all names nn in the current environment that have been explicitly marked with the `sorryful` attribute.

definition

Array of all names attributed as `pseudo`

Within the context of the Lean core environment monad (CoreM\text{CoreM}), this function retrieves an array of all constant identifiers (names) that have been assigned the `pseudo` attribute.

definition

Consistency test for `sorryful` and `pseudo` attributes

Within the meta-programming monad (MetaM\text{MetaM}), this procedure verifies the consistency of the `sorryful` and `pseudo` attributes for all user-defined constants in the environment. Specifically, it checks that a constant is attributed `sorryful` if and only if its definition or proof depends on the `sorryAx` axiom. Simultaneously, it verifies that a constant is attributed `pseudo` if and only if it depends on the `Lean.ofReduceBool` axiom (typically associated with `native_decide`). If any discrepancies are found—either a constant possessing an attribute without the corresponding dependency or a constant having the dependency without the attribute—the function terminates with a detailed error message listing the inconsistent identifiers. Otherwise, it prints a success message indicating that the metadata is correctly applied.