Skip to content

Commit

Permalink
Merge pull request #234 from HEPLean/NoDocs
Browse files Browse the repository at this point in the history
feat: No docs script
  • Loading branch information
jstoobysmith authored Nov 11, 2024
2 parents 91d639c + 63fcbf3 commit 1cb24f6
Show file tree
Hide file tree
Showing 15 changed files with 349 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:
- name: make list of informal proofs and lemmas
run : lake exe informal mkFile mkDot mkHTML

- name: make stats page
run : lake exe stats mkHTML

- name: Generate svg from dot
run : dot -Tsvg -o ./docs/graph.svg ./docs/InformalDot.dot

Expand Down
1 change: 1 addition & 0 deletions HepLean.lean
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import HepLean.Mathematics.LinearMaps
import HepLean.Mathematics.PiTensorProduct
import HepLean.Mathematics.SO3.Basic
import HepLean.Meta.AllFilePaths
import HepLean.Meta.Basic
import HepLean.Meta.Informal
import HepLean.Meta.TransverseTactics
import HepLean.SpaceTime.Basic
Expand Down
1 change: 1 addition & 0 deletions HepLean/AnomalyCancellation/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ instance chargesModule (χ : ACCSystemCharges) : Module ℚ χ.Charges :=
instance ChargesAddCommGroup (χ : ACCSystemCharges) : AddCommGroup χ.Charges :=
Module.addCommMonoidToAddCommGroup ℚ

/-- The module `χ.Charges` over `ℚ` is finite. -/
instance (χ : ACCSystemCharges) : Module.Finite ℚ χ.Charges :=
FiniteDimensional.finiteDimensional_pi ℚ

Expand Down
1 change: 1 addition & 0 deletions HepLean/AnomalyCancellation/GroupActions.lean
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ structure ACCSystemGroupAction (χ : ACCSystem) where

namespace ACCSystemGroupAction

/-- The given instance of a group on the `group` field of a `ACCSystemGroupAction`. -/
instance {χ : ACCSystem} (G : ACCSystemGroupAction χ) : Group G.group := G.groupInst

/-- The action of a group element on the vector space of linear solutions. -/
Expand Down
3 changes: 3 additions & 0 deletions HepLean/AnomalyCancellation/MSSMNu/OrthogY3B3/ToSols.lean
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace AnomalyFreePerp
and for the cube line to sit in the quad. -/
def LineEqProp (R : MSSMACC.AnomalyFreePerp) : Prop := α₁ R = 0 ∧ α₂ R = 0 ∧ α₃ R = 0

/-- The proposition `LineEqProp` is decidable. -/
instance (R : MSSMACC.AnomalyFreePerp) : Decidable (LineEqProp R) := instDecidableAnd

/-- A condition on `Sols` which we will show in `linEqPropSol_iff_proj_linEqProp` that is equivalent
Expand Down Expand Up @@ -79,6 +80,7 @@ entirely in the quadratic surface. -/
def InQuadProp (R : MSSMACC.AnomalyFreePerp) : Prop :=
quadBiLin R.val R.val = 0 ∧ quadBiLin Y₃.val R.val = 0 ∧ quadBiLin B₃.val R.val = 0

/-- The proposition `InQuadProp` is decidable. -/
instance (R : MSSMACC.AnomalyFreePerp) : Decidable (InQuadProp R) := instDecidableAnd

/-- A condition which is satisfied if the plane spanned by the solutions `R`, `Y₃` and `B₃`
Expand Down Expand Up @@ -124,6 +126,7 @@ def InCubeProp (R : MSSMACC.AnomalyFreePerp) : Prop :=
cubeTriLin R.val R.val R.val = 0 ∧ cubeTriLin R.val R.val B₃.val = 0
cubeTriLin R.val R.val Y₃.val = 0

/-- The proposition `InCubeProp` is decidable. -/
instance (R : MSSMACC.AnomalyFreePerp) : Decidable (InCubeProp R) := instDecidableAnd

/-- A condition which is satisfied if the plane spanned by the solutions `R`, `Y₃` and `B₃`
Expand Down
1 change: 1 addition & 0 deletions HepLean/AnomalyCancellation/MSSMNu/Permutations.lean
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ open BigOperators
@[simp]
def PermGroup := Fin 6 → Equiv.Perm (Fin 3)

/-- The type `PermGroup` has a group instances derived from the group instance of it's target. -/
@[simp]
instance : Group PermGroup := Pi.group

Expand Down
1 change: 1 addition & 0 deletions HepLean/AnomalyCancellation/PureU1/BasisLinear.lean
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ noncomputable
def asBasis : Basis (Fin n) ℚ ((PureU1 n.succ).LinSols) where
repr := coordinateMap

/-- The module over `ℚ` defined by linear solutions to the pure `U(1)` ACCs is finite. -/
instance : Module.Finite ℚ ((PureU1 n.succ).LinSols) :=
Module.Finite.of_basis asBasis

Expand Down
1 change: 1 addition & 0 deletions HepLean/AnomalyCancellation/PureU1/Permutations.lean
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace PureU1
@[simp]
def PermGroup (n : ℕ) := Equiv.Perm (Fin n)

/-- The type `PermGroup n` inherits the instance of a group from `Equiv.Perm`. -/
instance {n : ℕ} : Group (PermGroup n) := Equiv.Perm.permGroup

section Charges
Expand Down
2 changes: 2 additions & 0 deletions HepLean/AnomalyCancellation/SM/Permutations.lean
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def PermGroup (n : ℕ) := ∀ (_ : Fin 5), Equiv.Perm (Fin n)

variable {n : ℕ}

/-- The type `PermGroup n` inherits the instance of a group from it's
target space `Equiv.Perm`. -/
@[simp]
instance : Group (PermGroup n) := Pi.group

Expand Down
1 change: 1 addition & 0 deletions HepLean/FlavorPhysics/CKMMatrix/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ scoped[CKMMatrix] notation (name := ts_element) "[" V "]ts" => V.1 2 1
/-- The `tb`th element of the CKM matrix. -/
scoped[CKMMatrix] notation (name := tb_element) "[" V "]tb" => V.1 2 2

/-- The setoid of CKM matrices defined by phase shifts of fermions. -/
instance CKMMatrixSetoid : Setoid CKMMatrix := ⟨PhaseShiftRelation, phaseShiftRelation_equiv⟩

/-- The matrix obtained from `V` by shifting the phases of the fermions. -/
Expand Down
1 change: 1 addition & 0 deletions HepLean/Lorentz/ComplexTensor/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ instance {n : ℕ} {c : Fin n → complexLorentzTensor.C} :
instance {n : ℕ} {c : Fin n → complexLorentzTensor.C} :
Fintype (OverColor.mk c).left := Fin.fintype n

/-- The equality of two maps in `OverColor C` from objects based on `Fin _` is decidable. -/
instance {n m : ℕ} {c : Fin n → complexLorentzTensor.C}
{c1 : Fin m → complexLorentzTensor.C} (σ σ' : OverColor.mk c ⟶ OverColor.mk c1) :
Decidable (σ = σ') :=
Expand Down
193 changes: 193 additions & 0 deletions HepLean/Meta/Basic.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/-
Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved.
Released under Apache 2.0 license.
Authors: Joseph Tooby-Smith
-/
import Batteries.Lean.HashSet
import Lean
import Mathlib.Lean.Expr.Basic
import Mathlib.Lean.CoreM
import ImportGraph.RequiredModules
import HepLean.Meta.Informal
/-!
## Basic Lean meta programming commands
-/

namespace HepLean
open Lean System Meta

/-!
## Imports
-/

/-- Gets all imports within HepLean. -/
def allImports : IO (Array Import) := do
initSearchPath (← findSysroot)
let mods : Name := `HepLean
let imp : Import := {module := mods}
let mFile ← findOLean imp.module
unless (← mFile.pathExists) do
throw <| IO.userError s!"object file '{mFile}' of module {imp.module} does not exist"
let (hepLeanMod, _) ← readModuleData mFile
let imports := hepLeanMod.imports.filter (fun c => c.module ≠ `Init)
return imports

/-- Number of files within HepLean. -/
def noImports : IO Nat := do
let imports ← allImports
pure imports.size

/-- Gets all constants from an import. -/
def Imports.getConsts (imp : Import) : IO (Array ConstantInfo) := do
let mFile ← findOLean imp.module
let (modData, _) ← readModuleData mFile
pure modData.constants

/-- Gets all user defined constants from an import. -/
def Imports.getUserConsts (imp : Import) : MetaM (Array ConstantInfo) := do
let env ← getEnv
let x := (← Imports.getConsts imp).filter (fun c => ¬ c.name.isInternal)
let x := x.filter (fun c => ¬ Lean.isCasesOnRecursor env c.name)
let x := x.filter (fun c => ¬ Lean.isRecOnRecursor env c.name)
let x := x.filter (fun c => ¬ Lean.isNoConfusion env c.name)
let x := x.filter (fun c => ¬ Lean.isBRecOnRecursor env c.name)
let x := x.filter (fun c => ¬ Lean.isAuxRecursorWithSuffix env c.name Lean.binductionOnSuffix)
let x := x.filter (fun c => ¬ Lean.isAuxRecursorWithSuffix env c.name Lean.belowSuffix)
let x := x.filter (fun c => ¬ Lean.isAuxRecursorWithSuffix env c.name Lean.ibelowSuffix)
/- Removing syntax category declarations. -/
let x := x.filter (fun c => ¬ c.name.toString = "Informal.informalAssignment.quot" )
let x := x.filter (fun c => ¬ c.name.toString = "TensorTree.indexExpr.quot" )
let x := x.filter (fun c => ¬ c.name.toString = "TensorTree.tensorExpr.quot" )
pure x

/-- Lines from import. -/
def Imports.getLines (imp : Import) : IO (Array String) := do
let filePath := (mkFilePath (imp.module.toString.split (· == '.'))).addExtension "lean"
let lines ← IO.FS.lines filePath
return lines

/-!
## Name
-/


/-- Turns a name into a Lean file. -/
def Name.toFile (c : Name) : MetaM String := do
return s!"./{c.toString.replace "." "/" ++ ".lean"}"

/-- Given a name, returns the line number. -/
def Name.lineNumber (c : Name) : MetaM Nat := do
match ← findDeclarationRanges? c with
| some decl => pure decl.range.pos.line
| none => panic! s!"{c} is a declaration without position"

/-- Returns the location of a name. -/
def Name.location (c : Name) : MetaM String := do
let env ← getEnv
let x := env.getModuleFor? c
match x with
| some decl => pure ((← Name.toFile decl) ++ ":" ++ toString (← Name.lineNumber c) ++ " "
++ c.toString)
| none => panic! s!"{c} is a declaration without position"

/-- Determines if a name has a location. -/
def Name.hasPos (c : Name) : MetaM Bool := do
match ← findDeclarationRanges? c with
| some _ => pure true
| none => pure false

/-- Determines if a name has a doc string. -/
def Name.hasDocString (c : Name) : MetaM Bool := do
let env ← getEnv
let doc ← Lean.findDocString? env c
match doc with
| some _ => pure true
| none => pure false

/-- Number of definitions. -/
def noDefs : MetaM Nat := do
let imports ← allImports
let x ← imports.mapM Imports.getUserConsts
let x := x.flatten
let x := x.filter (fun c => c.isDef)
let x ← x.filterM (fun c => (Name.hasPos c.name))
pure x.toList.length

/-- Number of definitions. -/
def noLemmas : MetaM Nat := do
let imports ← allImports
let x ← imports.mapM Imports.getUserConsts
let x := x.flatten
let x := x.filter (fun c => ¬ c.isDef)
let x ← x.filterM (fun c => (Name.hasPos c.name))
pure x.toList.length

/-- Number of definitions without a doc-string. -/
def noDefsNoDocString : MetaM Nat := do
let imports ← allImports
let x ← imports.mapM Imports.getUserConsts
let x := x.flatten
let x := x.filter (fun c => c.isDef)
let x ← x.filterM (fun c => (Name.hasPos c.name))
let x ← x.filterM (fun c => do
return Bool.not (← (Name.hasDocString c.name)))
pure x.toList.length

/-- Number of definitions without a doc-string. -/
def noLemmasNoDocString : MetaM Nat := do
let imports ← allImports
let x ← imports.mapM Imports.getUserConsts
let x := x.flatten
let x := x.filter (fun c => ¬ c.isDef)
let x ← x.filterM (fun c => (Name.hasPos c.name))
let x ← x.filterM (fun c => do
return Bool.not (← (Name.hasDocString c.name)))
pure x.toList.length

/-- The number of lines in HepLean. -/
def noLines : IO Nat := do
let imports ← HepLean.allImports
let x ← imports.mapM HepLean.Imports.getLines
let x := x.flatten
pure x.toList.length

/-- The number of informal lemmas in HepLean. -/
def noInformalLemmas : MetaM Nat := do
let imports ← allImports
let x ← imports.mapM Imports.getUserConsts
let x := x.flatten
let x := x.filter (Informal.isInformal)
let x := x.filter (Informal.isInformalLemma)
pure x.toList.length

/-- The number of informal definitions in HepLean. -/
def noInformalDefs : MetaM Nat := do
let imports ← allImports
let x ← imports.mapM Imports.getUserConsts
let x := x.flatten
let x := x.filter (Informal.isInformal)
let x := x.filter (Informal.isInformalDef)
pure x.toList.length

/-- The number of TODO items. -/
def noTODOs : IO Nat := do
let imports ← HepLean.allImports
let x ← imports.mapM HepLean.Imports.getLines
let x := x.flatten
let x := x.filter fun l => l.startsWith "/-! TODO:"
pure x.size

/-- The number of files with a TODO item. -/
def noFilesWithTODOs : IO Nat := do
let imports ← HepLean.allImports
let x ← imports.mapM HepLean.Imports.getLines
let x := x.filter (fun M => M.any fun l => l.startsWith "/-! TODO:")
pure x.size

end HepLean
4 changes: 4 additions & 0 deletions lakefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ srcDir = "scripts"
name = "free_simps"
srcDir = "scripts/MetaPrograms"

[[lean_exe]]
name = "no_docs"
srcDir = "scripts/MetaPrograms"

[[lean_exe]]
name = "informal"
supportInterpreter = true
Expand Down
44 changes: 44 additions & 0 deletions scripts/MetaPrograms/no_docs.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/-
Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved.
Released under Apache 2.0 license.
Authors: Joseph Tooby-Smith
-/
import HepLean.Meta.Basic
/-!
# Extracting commands with no doc strings.
-/

open Lean System Meta HepLean

def Imports.NoDocStringDef (imp : Import) : MetaM UInt32 := do
let x := (← Imports.getUserConsts imp).filter (fun c => c.isDef)
let x ← x.filterM (fun c => do
return Bool.not (← (Name.hasDocString c.name)))
let y ← x.filterM (fun c => Name.hasPos c.name)
let loc ← y.mapM (fun c => (Name.location c.name))
if loc.toList.length > 0 then
IO.println "\n"
IO.println s!"Module {imp.module} has the following definitions without doc strings:"
IO.println (String.intercalate "\n" loc.toList)
pure 0

def Imports.NoDocStringLemma (imp : Import) : MetaM UInt32 := do
let x := (← Imports.getUserConsts imp).filter (fun c => ¬ c.isDef)
let x ← x.filterM (fun c => do
return Bool.not (← (Name.hasDocString c.name)))
let y ← x.filterM (fun c => Name.hasPos c.name)
let loc ← y.mapM (fun c => (Name.location c.name))
if loc.toList.length > 0 then
IO.println "\n"
IO.println s!"Module {imp.module} has the following lemmas without doc strings:"
IO.println (String.intercalate "\n" loc.toList)
pure 0

unsafe def main (args : List String) : IO UInt32 := do
let imports ← allImports
let _ ← CoreM.withImportModules #[`HepLean] (imports.mapM Imports.NoDocStringDef).run'
if "--lemmas" ∈ args then
let _ ← CoreM.withImportModules #[`HepLean] (imports.mapM Imports.NoDocStringLemma).run'
pure 0
Loading

0 comments on commit 1cb24f6

Please sign in to comment.