PhysLean/scripts/MetaPrograms/notes.lean

296 lines
13 KiB
Text
Raw Normal View History

2024-12-04 13:37:23 +00:00
/-
Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved.
Released under Apache 2.0 license.
Authors: Joseph Tooby-Smith
-/
import HepLean.Meta.Basic
2025-01-23 06:31:11 +00:00
import HepLean.Meta.Remark.Properties
2024-12-04 13:37:23 +00:00
import HepLean.Meta.Notes.ToHTML
2025-02-03 12:04:24 +00:00
import Mathlib.Lean.CoreM
2025-02-06 10:06:05 +00:00
import HepLean
2024-12-04 13:37:23 +00:00
/-!
# Extracting notes from Lean files
-/
open Lean System Meta HepLean
2025-02-06 10:06:05 +00:00
inductive NameStatus
| complete : NameStatus
| incomplete : NameStatus
instance : ToString NameStatus where
toString
| NameStatus.complete => "complete"
| NameStatus.incomplete => "incomplete"
2025-01-23 06:31:11 +00:00
inductive NotePart
| h1 : String → NotePart
| h2 : String → NotePart
| p : String → NotePart
2025-02-06 10:06:05 +00:00
| name : Name → NameStatus → NotePart
2025-02-03 15:59:25 +00:00
| warning : String → NotePart
2025-01-22 10:32:39 +00:00
2025-01-23 10:46:50 +00:00
structure DeclInfo where
line : Nat
fileName : Name
name : Name
2025-02-06 10:06:05 +00:00
status : NameStatus
2025-01-23 10:46:50 +00:00
declString : String
docString : String
2025-02-07 13:16:01 +00:00
isDef : Bool
2025-01-23 06:31:11 +00:00
2025-02-06 10:06:05 +00:00
def DeclInfo.ofName (n : Name) (ns : NameStatus): MetaM DeclInfo := do
2025-01-23 10:46:50 +00:00
let line ← Name.lineNumber n
let fileName ← Name.fileName n
let declString ← Name.getDeclStringNoDoc n
2025-01-23 10:46:50 +00:00
let docString ← Name.getDocString n
2025-02-07 13:16:01 +00:00
let constInfo ← getConstInfo n
let isDef := constInfo.isDef Lean.isStructure (← getEnv) n constInfo.isInductive
2025-01-23 10:46:50 +00:00
pure {
line := line,
fileName := fileName,
name := n,
2025-02-06 10:06:05 +00:00
status := ns,
2025-01-23 10:46:50 +00:00
declString := declString,
2025-02-07 13:16:01 +00:00
docString := docString,
isDef := isDef}
2025-01-23 06:31:11 +00:00
2025-01-23 14:18:02 +00:00
def DeclInfo.toYML (d : DeclInfo) : MetaM String := do
2025-01-23 10:46:50 +00:00
let declStringIndent := d.declString.replace "\n" "\n "
2025-01-23 14:18:02 +00:00
let docStringIndent := d.docString.replace "\n" "\n "
2025-02-03 12:04:24 +00:00
let link := Name.toGitHubLink d.fileName d.line
2025-01-23 14:18:02 +00:00
return s!"
2025-01-23 10:46:50 +00:00
- type: name
name: {d.name}
line: {d.line}
fileName: {d.fileName}
2025-02-06 10:06:05 +00:00
status: \"{d.status}\"
2025-01-23 14:18:02 +00:00
link: \"{link}\"
2025-02-07 13:16:01 +00:00
isDef: {d.isDef}
2025-01-23 14:18:02 +00:00
docString: |
{docStringIndent}
2025-01-23 10:46:50 +00:00
declString: |
{declStringIndent}"
2025-02-07 14:09:12 +00:00
/-- In `(List String) × Nat × Nat` the first `Nat` is section number, the second `Nat`
is subsection number, and the third `Nat` is defn. or lemma number.
Definitions and lemmas etc are done by section not subsection. -/
def NotePart.toYMLM : ((List String) × Nat × Nat × Nat) → NotePart →
MetaM ((List String) × Nat × Nat × Nat)
2025-01-23 10:46:50 +00:00
| x, NotePart.h1 s =>
let newString := s!"
2025-01-23 06:31:11 +00:00
- type: h1
2025-01-23 10:46:50 +00:00
sectionNo: {x.2.1.succ}
2025-01-23 06:31:11 +00:00
content: \"{s}\""
2025-02-07 14:09:12 +00:00
return ⟨x.1 ++ [newString], ⟨Nat.succ x.2.1, 0, 0⟩⟩
2025-01-23 10:46:50 +00:00
| x, NotePart.h2 s =>
let newString := s!"
2025-01-23 06:31:11 +00:00
- type: h2
2025-02-07 14:09:12 +00:00
sectionNo: \"{x.2.1}.{x.2.2.1.succ}\"
2025-01-23 06:31:11 +00:00
content: \"{s}\""
2025-02-07 14:09:12 +00:00
return ⟨x.1 ++ [newString], ⟨x.2.1, Nat.succ x.2.2.1, x.2.2.2⟩⟩
2025-01-23 10:46:50 +00:00
| x, NotePart.p s =>
let newString := s!"
2025-01-23 06:31:11 +00:00
- type: p
content: \"{s}\""
2025-01-23 10:46:50 +00:00
return ⟨x.1 ++ [newString], x.2⟩
2025-02-03 15:59:25 +00:00
| x, NotePart.warning s =>
let newString := s!"
- type: warning
content: \"{s}\""
return ⟨x.1 ++ [newString], x.2⟩
2025-02-06 10:06:05 +00:00
| x, NotePart.name n s => do
2025-01-23 06:31:11 +00:00
match (← RemarkInfo.IsRemark n) with
| true =>
let remarkInfo ← RemarkInfo.getRemarkInfo n
let content := remarkInfo.content
let contentIndent := content.replace "\n" "\n "
let shortName := remarkInfo.name.toString
2025-01-23 10:46:50 +00:00
let newString := s!"
2025-01-23 06:31:11 +00:00
- type: remark
name: \"{shortName}\"
2025-02-06 10:06:05 +00:00
status : \"{s}\"
2025-02-03 12:04:24 +00:00
link: \"{Name.toGitHubLink remarkInfo.fileName remarkInfo.line}\"
2025-01-23 06:31:11 +00:00
content: |
{contentIndent}"
2025-01-23 10:46:50 +00:00
return ⟨x.1 ++ [newString], x.2⟩
2025-01-23 06:31:11 +00:00
| false =>
2025-02-06 10:06:05 +00:00
let newString ← (← DeclInfo.ofName n s).toYML
2025-02-07 14:09:12 +00:00
let newString := newString ++ s!"\n declNo: \"{x.2.1}.{x.2.2.2.succ}\""
return ⟨x.1 ++ [newString], ⟨x.2.1, x.2.2.1, Nat.succ x.2.2.2⟩⟩
2025-01-23 06:31:11 +00:00
structure Note where
title : String
/-- The curators of the note are the people who put the note together.
This may not conicide with the original authors of the material. -/
curators : List String
parts : List NotePart
def Note.toYML : Note → MetaM String
2025-01-23 10:46:50 +00:00
| ⟨title, curators, parts⟩ => do
let parts ← parts.foldlM NotePart.toYMLM ([], ⟨0, 0⟩)
return s!"
2025-01-23 06:31:11 +00:00
title: \"{title}\"
2025-01-23 10:46:50 +00:00
curators: {String.intercalate "," curators}
2025-01-23 06:31:11 +00:00
parts:
2025-01-23 10:46:50 +00:00
{String.intercalate "\n" parts.1}"
2025-01-23 06:31:11 +00:00
def perturbationTheory : Note where
title := "Proof of Wick's theorem"
curators := ["Joseph Tooby-Smith"]
parts := [
2025-01-23 10:46:50 +00:00
.h1 "Introduction",
2025-02-06 10:06:05 +00:00
.name `FieldSpecification.wicks_theorem_context .incomplete,
2025-02-10 10:21:57 +00:00
.p "In this note we walk through the important parts of the proof of the three versions of
Wick's theorem for field operators containing carrying both fermionic and bosonic statitics,
2025-02-07 13:16:01 +00:00
as it appears in HepLean. Not every lemma or definition is covered here.
The aim is to give just enough that the story can be understood.",
2025-02-10 10:21:57 +00:00
.p "
Before proceeding with the steps in the proof, we review some basic terminology
related to Lean and type theory. The most important notion is that of a type.
We don't give any formal definition here, except to say that a type `T`, like a set, has
elements `x` which we say are of type `T` and write `x : T`. Examples of types include,
the type of natural numbers ``, the type of real numbers ``, the type of numbers
`0, …, n-1` denoted `Fin n`. Given two types `T` and `S`, we can form the product type `T × S`,
and the function type `T → S`.
Types form the foundation of Lean and the theory behind them will be used both explicitly and
implicitly throughout this note.",
2025-02-03 15:59:25 +00:00
.h1 "Field operators",
2025-01-23 10:46:50 +00:00
.h2 "Field statistics",
2025-02-06 10:06:05 +00:00
.name ``FieldStatistic .complete,
.name ``FieldStatistic.instCommGroup .complete,
.name ``FieldStatistic.exchangeSign .complete,
2025-01-23 10:46:50 +00:00
.h2 "Field specifications",
2025-02-06 10:06:05 +00:00
.name ``FieldSpecification .complete,
2025-02-03 15:59:25 +00:00
.h2 "Field operators",
2025-02-06 10:06:05 +00:00
.name ``FieldSpecification.FieldOp .complete,
.name ``FieldSpecification.fieldOpStatistic .complete,
.name ``CreateAnnihilate .complete,
.name ``FieldSpecification.CrAnFieldOp .complete,
2025-02-10 10:21:57 +00:00
.name ``FieldSpecification.crAnFieldOpToCreateAnnihilate .complete,
2025-02-06 10:06:05 +00:00
.name ``FieldSpecification.crAnStatistics .complete,
.name `FieldSpecification.notation_remark .complete,
2025-02-03 15:59:25 +00:00
.h2 "Field-operator free algebra",
2025-02-06 10:47:34 +00:00
.name ``FieldSpecification.FieldOpFreeAlgebra .complete,
.name `FieldSpecification.FieldOpFreeAlgebra.naming_convention .complete,
.name ``FieldSpecification.FieldOpFreeAlgebra.ofCrAnOpF .complete,
2025-02-06 12:38:05 +00:00
.name ``FieldSpecification.FieldOpFreeAlgebra.universality .complete,
2025-02-06 10:47:34 +00:00
.name ``FieldSpecification.FieldOpFreeAlgebra.ofCrAnListF .complete,
.name ``FieldSpecification.FieldOpFreeAlgebra.ofFieldOpF .complete,
.name ``FieldSpecification.FieldOpFreeAlgebra.ofFieldOpListF .complete,
.name `FieldSpecification.FieldOpFreeAlgebra.notation_drop .complete,
.name ``FieldSpecification.FieldOpFreeAlgebra.fieldOpFreeAlgebraGrade .complete,
.name ``FieldSpecification.FieldOpFreeAlgebra.superCommuteF .complete,
.name ``FieldSpecification.FieldOpFreeAlgebra.superCommuteF_ofCrAnListF_ofCrAnListF_eq_sum .complete,
2025-02-03 15:59:25 +00:00
.h2 "Field-operator algebra",
2025-02-06 13:06:51 +00:00
.name ``FieldSpecification.FieldOpAlgebra .complete,
.name ``FieldSpecification.FieldOpAlgebra.ι .complete,
.name ``FieldSpecification.FieldOpAlgebra.universality .complete,
.name ``FieldSpecification.FieldOpAlgebra.ofCrAnOp .complete,
.name ``FieldSpecification.FieldOpAlgebra.ofCrAnList .complete,
.name ``FieldSpecification.FieldOpAlgebra.ofFieldOp .complete,
.name ``FieldSpecification.FieldOpAlgebra.ofCrAnList .complete,
.name `FieldSpecification.FieldOpAlgebra.notation_drop .complete,
.name ``FieldSpecification.FieldOpAlgebra.anPart .complete,
.name ``FieldSpecification.FieldOpAlgebra.crPart .complete,
.name ``FieldSpecification.FieldOpAlgebra.ofFieldOp_eq_crPart_add_anPart .complete,
.name ``FieldSpecification.FieldOpAlgebra.fieldOpAlgebraGrade .complete,
.name ``FieldSpecification.FieldOpAlgebra.superCommute .complete,
2025-02-03 15:59:25 +00:00
.h1 "Time ordering",
2025-02-06 13:28:52 +00:00
.name ``FieldSpecification.crAnTimeOrderRel .complete,
.name ``FieldSpecification.crAnTimeOrderList .complete,
.name ``FieldSpecification.crAnTimeOrderSign .complete,
.name ``FieldSpecification.FieldOpFreeAlgebra.timeOrderF .complete,
.name ``FieldSpecification.FieldOpAlgebra.timeOrder .complete,
.name ``FieldSpecification.FieldOpAlgebra.timeOrder_eq_maxTimeField_mul_finset .complete,
2025-02-07 09:56:37 +00:00
.name ``FieldSpecification.FieldOpAlgebra.timeOrder_timeOrder_mid .complete,
2025-02-03 15:59:25 +00:00
.h1 "Normal ordering",
2025-02-06 14:10:45 +00:00
.name ``FieldSpecification.normalOrderRel .complete,
.name ``FieldSpecification.normalOrderList .complete,
.name ``FieldSpecification.normalOrderSign .complete,
.name ``FieldSpecification.normalOrderSign_eraseIdx .complete,
.name ``FieldSpecification.FieldOpFreeAlgebra.normalOrderF .complete,
.name ``FieldSpecification.FieldOpAlgebra.normalOrder .complete,
2025-02-07 06:58:41 +00:00
.name ``FieldSpecification.FieldOpAlgebra.normalOrder_superCommute_eq_zero .complete,
2025-02-06 14:10:45 +00:00
.name ``FieldSpecification.FieldOpAlgebra.ofCrAnOp_superCommute_normalOrder_ofCrAnList_sum .complete,
.name ``FieldSpecification.FieldOpAlgebra.ofFieldOp_mul_normalOrder_ofFieldOpList_eq_sum .complete,
2025-01-23 14:18:02 +00:00
.h1 "Wick Contractions",
2025-02-03 15:59:25 +00:00
.h2 "Definition",
2025-02-07 06:58:41 +00:00
.name ``WickContraction .complete,
2025-02-10 10:21:57 +00:00
.name ``WickContraction.mem_three .complete,
.name ``WickContraction.mem_four .complete,
2025-02-07 06:58:41 +00:00
.name `WickContraction.contraction_notation .complete,
.name ``WickContraction.GradingCompliant .complete,
.h2 "Aside: Cardinality",
2025-02-07 06:58:41 +00:00
.name ``WickContraction.card_eq_cardFun .complete,
.h2 "Uncontracted elements",
.name ``WickContraction.uncontracted .complete,
.name ``WickContraction.uncontractedListGet .complete,
2025-02-03 15:59:25 +00:00
.h2 "Constructors",
2025-02-07 06:58:41 +00:00
.name ``WickContraction.insertAndContract .complete,
2025-02-07 09:56:37 +00:00
.name ``WickContraction.insertLift_sum .complete,
2025-02-07 06:58:41 +00:00
.name ``WickContraction.join .complete,
2025-02-03 15:59:25 +00:00
.h2 "Sign",
2025-02-07 06:58:41 +00:00
.name ``WickContraction.sign .complete,
.name ``WickContraction.join_sign .complete,
.name ``WickContraction.sign_insert_none .complete,
.name ``WickContraction.sign_insert_none_zero .complete,
.name ``WickContraction.sign_insert_some_of_not_lt .complete,
.name ``WickContraction.sign_insert_some_of_lt .complete,
.name ``WickContraction.sign_insert_some_zero .complete,
.h2 "Normal order",
2025-02-07 06:58:41 +00:00
.name ``FieldSpecification.FieldOpAlgebra.normalOrder_uncontracted_none .complete,
.name ``FieldSpecification.FieldOpAlgebra.normalOrder_uncontracted_some .complete,
2025-02-07 09:56:37 +00:00
.h1 "Static Wicks theorem",
.h2 "Static contractions",
.name ``WickContraction.staticContract .complete,
.name ``WickContraction.staticContract_insert_none .complete,
.name ``WickContraction.staticContract_insert_some .complete,
2025-02-10 10:21:57 +00:00
.h2 "Static Wick terms",
2025-02-07 09:56:37 +00:00
.name ``WickContraction.staticWickTerm .complete,
.name ``WickContraction.staticWickTerm_empty_nil .complete,
.name ``WickContraction.staticWickTerm_insert_zero_none .complete,
.name ``WickContraction.staticWickTerm_insert_zero_some .complete,
.name ``WickContraction.mul_staticWickTerm_eq_sum .complete,
.h2 "The Static Wicks theorem",
.name ``FieldSpecification.FieldOpAlgebra.static_wick_theorem .complete,
.h1 "Wick's theorem",
.h2 "Time contractions",
.name ``FieldSpecification.FieldOpAlgebra.timeContract .complete,
.name ``FieldSpecification.FieldOpAlgebra.timeContract_of_timeOrderRel .complete,
.name ``FieldSpecification.FieldOpAlgebra.timeContract_of_not_timeOrderRel_expand .complete,
.name ``FieldSpecification.FieldOpAlgebra.timeContract_mem_center .complete,
.name ``WickContraction.timeContract .complete,
.name ``WickContraction.timeContract_insert_none .complete,
.name ``WickContraction.timeContract_insert_some_of_not_lt .complete,
.name ``WickContraction.timeContract_insert_some_of_lt .complete,
.name ``WickContraction.join_sign_timeContract .complete,
.h2 "Wick terms",
.name ``WickContraction.wickTerm .complete,
.name ``WickContraction.wickTerm_empty_nil .complete,
.name ``WickContraction.wickTerm_insert_none .complete,
.name ``WickContraction.wickTerm_insert_some .complete,
.name ``WickContraction.mul_wickTerm_eq_sum .complete,
.h2 "Wick's theorem",
.name ``FieldSpecification.wicks_theorem .complete,
.h1 "Normal-ordered Wick's theorem",
.name ``WickContraction.EqTimeOnly.timeOrder_staticContract_of_not_mem .complete,
.name ``WickContraction.EqTimeOnly.staticContract_eq_timeContract_of_eqTimeOnly .complete,
.name ``WickContraction.EqTimeOnly.timeOrder_timeContract_mul_of_eqTimeOnly_left .complete,
.name ``FieldSpecification.FieldOpAlgebra.timeOrder_ofFieldOpList_eqTimeOnly .complete,
.name ``FieldSpecification.FieldOpAlgebra.normalOrder_timeOrder_ofFieldOpList_eq_eqTimeOnly_empty .complete,
.name ``FieldSpecification.FieldOpAlgebra.timeOrder_haveEqTime_split .complete,
.name ``FieldSpecification.FieldOpAlgebra.wicks_theorem_normal_order .complete
2025-02-04 14:56:38 +00:00
]
2024-12-04 13:37:23 +00:00
2024-12-05 06:23:10 +00:00
unsafe def main (_ : List String) : IO UInt32 := do
2024-12-04 13:37:23 +00:00
initSearchPath (← findSysroot)
2025-01-23 06:31:11 +00:00
let ymlString ← CoreM.withImportModules #[`HepLean] (perturbationTheory.toYML).run'
let fileOut : System.FilePath := {toString := "./docs/_data/perturbationTheory.yml"}
IO.println (s!"YML file made.")
IO.FS.writeFile fileOut ymlString
2024-12-04 13:37:23 +00:00
pure 0