formal

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package formal builds the Lean package of the content repository and reads what it proves (spec 07).

Build runs lake build in the lean directory, then runs AlgoExtract (Extract.lean) with lake env lean. AlgoExtract writes one JSON line for each declaration in the namespace Algo to decls.jsonl. Check reads that file and reports each declaration that uses an axiom outside the policy of 07.5, and each name of a lean field that does not exist.

Index

Constants

This section is empty.

Variables

View Source
var Allowed = []string{"propext", "Classical.choice", "Quot.sound"}

Allowed are the axioms that a proof can use (spec 07.5). Each other axiom, such as sorryAx or Lean.ofReduceBool, fails the build.

View Source
var Kinds = map[string][]string{
	"model":   {"def"},
	"spec":    {"def", "inductive", "structure"},
	"correct": {"theorem"},
	"cost":    {"theorem"},
	"space":   {"theorem"},
}

Kinds are the kinds that each key of a lean field must name.

Functions

func Build

func Build(ctx context.Context, o Options) (string, error)

Build runs lake build and AlgoExtract, and returns the path of decls.jsonl.

func ClaimClass

func ClaimClass(bound string) string

ClaimClass returns the class of a front matter bound in the same normal form, such as "nlogn" for "Θ(n log n)". It returns "" when the bound is not of the form Θ(...), O(...) or Ω(...).

func ClassOf

func ClassOf(typ string) string

ClassOf returns the class of a class lemma in a normal form, such as "nlogn" for `f =O[Filter.atTop] fun n => ↑n * Real.log ↑n`. It returns "" when typ is not a class lemma.

func IsClassLemma

func IsClassLemma(typ string) bool

IsClassLemma tells if a type states an asymptotic class, such as `f =O[Filter.atTop] g`.

Types

type Decl

type Decl struct {
	Decl       string   `json:"decl"`
	Kind       string   `json:"kind"`
	Module     string   `json:"module"`
	Type       string   `json:"type"`
	TypeHash   string   `json:"type_hash"`
	Axioms     []string `json:"axioms"`
	Deps       []string `json:"deps"`
	Sorry      bool     `json:"sorry"`
	Computable bool     `json:"computable"`
	Doc        string   `json:"doc,omitempty"`
	Pos        *Pos     `json:"pos,omitempty"`
}

Decl is one line of decls.jsonl.

func (Decl) Disallowed

func (d Decl) Disallowed() []string

Disallowed returns the axioms of d that the policy does not permit.

type Decls

type Decls map[string]Decl

Decls maps each full name to its declaration.

func Load

func Load(path string) (Decls, error)

Load reads a decls.jsonl file.

type Finding

type Finding struct {
	// Rule is the audit rule of 07.15, such as L01 or L03.
	Rule string
	// Where is the declaration, or the node and its field.
	Where string
	Msg   string
}

Finding is one problem that Check finds.

func Check

func Check(c *node.Corpus, ds Decls) []Finding

Check reports each declaration that uses an axiom outside the policy (rule L03), and each name of a lean field that is not in ds or has the wrong kind (rule L01). The findings are in a stable order.

func CheckClaims

func CheckClaims(n *node.Node, ds Decls) []Finding

CheckClaims compares the time claims of a node that has lean.cost with the class lemmas of its module (rule L05). A claim with no class lemma of the same class is a finding. Space claims count only when lean.space is set.

func CheckNode

func CheckNode(n *node.Node, ds Decls) []Finding

CheckNode checks the names of the lean field of one node (rule L01).

func (Finding) String

func (f Finding) String() string

type Options

type Options struct {
	// Dir is the Lean package, the lean directory of the content repository.
	Dir string
	// Out is the directory for decls.jsonl and the copy of Extract.lean, such as build/lean.
	Out string
	// NoBuild skips lake build, when the package is built already.
	NoBuild bool
	// Wrap changes a command before it runs, for example to run it in a container. Nil runs it on the host.
	Wrap func(argv []string) []string
	// Log gets the output of lake.
	Log io.Writer
}

Options tell Build where the package is and how to run lake.

type Pos

type Pos struct {
	Line    int `json:"line"`
	EndLine int `json:"end_line"`
}

Pos is the line range of a declaration in its module.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL