diff --git a/HepLean/BeyondTheStandardModel/GeorgiGlashow/Basic.lean b/HepLean/BeyondTheStandardModel/GeorgiGlashow/Basic.lean index 382c70b..695ce7b 100644 --- a/HepLean/BeyondTheStandardModel/GeorgiGlashow/Basic.lean +++ b/HepLean/BeyondTheStandardModel/GeorgiGlashow/Basic.lean @@ -17,27 +17,30 @@ This file currently contains informal-results about the Georgi-Glashow group. namespace GeorgiGlashow +/-- The gauge group of the Georgi-Glashow model, i.e., `SU(5)`. -/ informal_definition GaugeGroupI where - math :≈ "The group `SU(5)`." - physics :≈ "The gauge group of the Georgi-Glashow model." + deps := [] +/-- The homomorphism of the Standard Model gauge group into the Georgi-Glashow gauge group, i.e., +the group homomorphism `SU(3) × SU(2) × U(1) → SU(5)` taking `(h, g, α)` to +`blockdiag (α ^ 3 g, α ^ (-2) h)`. + +See page 34 of https://math.ucr.edu/home/baez/guts.pdf +-/ informal_definition inclSM where - physics :≈ "The homomorphism of the Standard Model gauge group into the - Georgi-Glashow gauge group." - math :≈ "The group homomorphism `SU(3) x SU(2) x U(1) -> SU(5)` - taking (h, g, α) to (blockdiag (α ^ 3 g, α ^ (-2) h)." - ref :≈ "Page 34 of https://math.ucr.edu/home/baez/guts.pdf" - deps :≈ [``GaugeGroupI, ``StandardModel.GaugeGroupI] + deps := [``GaugeGroupI, ``StandardModel.GaugeGroupI] +/-- The kernel of the map `inclSM` is equal to the subgroup `StandardModel.gaugeGroupℤ₆SubGroup`. + +See page 34 of https://math.ucr.edu/home/baez/guts.pdf +-/ informal_lemma inclSM_ker where - math :≈ "The kernel of the map ``inclSM is equal to the subgroup - ``StandardModel.gaugeGroupℤ₆SubGroup." - ref :≈ "Page 34 of https://math.ucr.edu/home/baez/guts.pdf" - deps :≈ [``inclSM, ``StandardModel.gaugeGroupℤ₆SubGroup] + deps := [``inclSM, ``StandardModel.gaugeGroupℤ₆SubGroup] +/-- The group embedding from `StandardModel.GaugeGroupℤ₆` to `GaugeGroupI` induced by `inclSM` by +quotienting by the kernal `inclSM_ker`. +-/ informal_definition embedSMℤ₆ where - math :≈ "The group embedding from ``StandardModel.GaugeGroupℤ₆ to ``GaugeGroupI - induced by ``inclSM by quotienting by the kernal ``inclSM_ker." - deps :≈ [``inclSM, ``StandardModel.GaugeGroupℤ₆, ``GaugeGroupI, ``inclSM_ker] + deps := [``inclSM, ``StandardModel.GaugeGroupℤ₆, ``GaugeGroupI, ``inclSM_ker] end GeorgiGlashow diff --git a/HepLean/BeyondTheStandardModel/PatiSalam/Basic.lean b/HepLean/BeyondTheStandardModel/PatiSalam/Basic.lean index 8ee2bb3..6cb7c9e 100644 --- a/HepLean/BeyondTheStandardModel/PatiSalam/Basic.lean +++ b/HepLean/BeyondTheStandardModel/PatiSalam/Basic.lean @@ -22,54 +22,62 @@ namespace PatiSalam -/ +/-- The gauge group of the Pati-Salam model (unquotiented by ℤ₂), i.e., `SU(4) × SU(2) × SU(2)`. -/ informal_definition GaugeGroupI where - math :≈ "The group `SU(4) x SU(2) x SU(2)`." - physics :≈ "The gauge group of the Pati-Salam model (unquotiented by ℤ₂)." + deps := [] +/-- The homomorphism of the Standard Model gauge group into the Pati-Salam gauge group, i.e., the +group homomorphism `SU(3) × SU(2) × U(1) → SU(4) × SU(2) × SU(2)` taking `(h, g, α)` to +`(blockdiag (α h, α ^ (-3)), g, diag (α ^ 3, α ^(-3))`. + +See page 54 of https://math.ucr.edu/home/baez/guts.pdf +-/ informal_definition inclSM where - physics :≈ "The homomorphism of the Standard Model gauge group into the Pati-Salam gauge group." - math :≈ "The group homomorphism `SU(3) x SU(2) x U(1) -> SU(4) x SU(2) x SU(2)` - taking (h, g, α) to (blockdiag (α h, α ^ (-3)), g, diag(α ^ (3), α ^(-3)))." - ref :≈ "Page 54 of https://math.ucr.edu/home/baez/guts.pdf" - deps :≈ [``GaugeGroupI, ``StandardModel.GaugeGroupI] + deps := [``GaugeGroupI, ``StandardModel.GaugeGroupI] +/-- The kernel of the map `inclSM` is equal to the subgroup `StandardModel.gaugeGroupℤ₃SubGroup`. + +See footnote 10 of https://arxiv.org/pdf/2201.07245 +-/ informal_lemma inclSM_ker where - math :≈ "The kernel of the map ``inclSM is equal to the subgroup - ``StandardModel.gaugeGroupℤ₃SubGroup." - ref :≈ "Footnote 10 of https://arxiv.org/pdf/2201.07245" - deps :≈ [``inclSM, ``StandardModel.gaugeGroupℤ₃SubGroup] + deps := [``inclSM, ``StandardModel.gaugeGroupℤ₃SubGroup] +/-- The group embedding from `StandardModel.GaugeGroupℤ₃` to `GaugeGroupI` induced by `inclSM` by +quotienting by the kernal `inclSM_ker`. +-/ informal_definition embedSMℤ₃ where - math :≈ "The group embedding from ``StandardModel.GaugeGroupℤ₃ to ``GaugeGroupI - induced by ``inclSM by quotienting by the kernal ``inclSM_ker." - deps :≈ [``inclSM, ``StandardModel.GaugeGroupℤ₃, ``GaugeGroupI, ``inclSM_ker] + deps := [``inclSM, ``StandardModel.GaugeGroupℤ₃, ``GaugeGroupI, ``inclSM_ker] +/-- The equivalence between `GaugeGroupI` and `Spin(6) × Spin(4)`. -/ informal_definition gaugeGroupISpinEquiv where - math :≈ "The equivalence between `GaugeGroupI` and `Spin(6) × Spin(4)`." - deps :≈ [``GaugeGroupI] + deps := [``GaugeGroupI] +/-- The ℤ₂-subgroup of the un-quotiented gauge group which acts trivially on all particles in the +standard model, i.e., the ℤ₂-subgroup of `GaugeGroupI` with the non-trivial element `(-1, -1, -1)`. + +See https://math.ucr.edu/home/baez/guts.pdf +-/ informal_definition gaugeGroupℤ₂SubGroup where - physics :≈ "The ℤ₂-subgroup of the un-quotiented gauge group which acts trivially on - all particles in the standard model." - math :≈ "The ℤ₂-subgroup of ``GaugeGroupI with the non-trivial element (-1, -1, -1)." - ref :≈ "https://math.ucr.edu/home/baez/guts.pdf" - deps :≈ [``GaugeGroupI] + deps := [``GaugeGroupI] +/-- The gauge group of the Pati-Salam model with a ℤ₂ quotient, i.e., the quotient of `GaugeGroupI` +by the ℤ₂-subgroup `gaugeGroupℤ₂SubGroup`. + +See https://math.ucr.edu/home/baez/guts.pdf +-/ informal_definition GaugeGroupℤ₂ where - physics :≈ "The gauge group of the Pati-Salam model with a ℤ₂ quotient." - math :≈ "The quotient of ``GaugeGroupI by the ℤ₂-subgroup `gaugeGroupℤ₂SubGroup`." - ref :≈ "https://math.ucr.edu/home/baez/guts.pdf" - deps :≈ [``GaugeGroupI, ``gaugeGroupℤ₂SubGroup] + deps := [``GaugeGroupI, ``gaugeGroupℤ₂SubGroup] +/-- The group `StandardModel.gaugeGroupℤ₆SubGroup` under the homomorphism `embedSM` factors through +the subgroup `gaugeGroupℤ₂SubGroup`. +-/ informal_lemma sm_ℤ₆_factor_through_gaugeGroupℤ₂SubGroup where - math :≈ "The group ``StandardModel.gaugeGroupℤ₆SubGroup under the homomorphism ``embedSM factors - through the subgroup ``gaugeGroupℤ₂SubGroup." - deps :≈ [``inclSM, ``StandardModel.gaugeGroupℤ₆SubGroup, ``gaugeGroupℤ₂SubGroup] + deps := [``inclSM, ``StandardModel.gaugeGroupℤ₆SubGroup, ``gaugeGroupℤ₂SubGroup] +/-- The group homomorphism from `StandardModel.GaugeGroupℤ₆` to `GaugeGroupℤ₂` induced by `embedSM`. +-/ informal_definition embedSMℤ₆Toℤ₂ where - math :≈ "The group homomorphism from ``StandardModel.GaugeGroupℤ₆ to ``GaugeGroupℤ₂ - induced by ``embedSM." - deps :≈ [``inclSM, ``StandardModel.GaugeGroupℤ₆, ``GaugeGroupℤ₂, + deps := [``inclSM, ``StandardModel.GaugeGroupℤ₆, ``GaugeGroupℤ₂, ``sm_ℤ₆_factor_through_gaugeGroupℤ₂SubGroup] end PatiSalam diff --git a/HepLean/BeyondTheStandardModel/Spin10/Basic.lean b/HepLean/BeyondTheStandardModel/Spin10/Basic.lean index a57d7c9..c44a80a 100644 --- a/HepLean/BeyondTheStandardModel/Spin10/Basic.lean +++ b/HepLean/BeyondTheStandardModel/Spin10/Basic.lean @@ -16,37 +16,42 @@ is Spin(10). namespace Spin10Model +/-- The gauge group of the Spin(10) model, i.e., the group `Spin(10)`. -/ informal_definition GaugeGroupI where - math :≈ "The group `Spin(10)`." - physics :≈ "The gauge group of the Spin(10) model (aka SO(10)-model.)" + deps := [] +/-- The inclusion of the Pati-Salam gauge group into Spin(10), i.e., the lift of the embedding +`SO(6) × SO(4) → SO(10)` to universal covers, giving a homomorphism `Spin(6) × Spin(4) → Spin(10)`. +Precomposed with the isomorphism, `PatiSalam.gaugeGroupISpinEquiv`, between `SU(4) × SU(2) × SU(2)` +and `Spin(6) × Spin(4)`. + +See page 56 of https://math.ucr.edu/home/baez/guts.pdf +-/ informal_definition inclPatiSalam where - physics :≈ "The inclusion of the Pati-Salam gauge group into Spin(10)." - math :≈ "The lift of the embedding `SO(6) x SO(4) → SO(10)` to universal covers, - giving a homomorphism `Spin(6) x Spin(4) → Spin(10)`. Precomposed with the isomorphism, - ``PatiSalam.gaugeGroupISpinEquiv, between `SU(4) x SU(2) x SU(2)` and `Spin(6) x Spin(4)`." - ref :≈ "Page 56 of https://math.ucr.edu/home/baez/guts.pdf" - deps :≈ [``GaugeGroupI, ``PatiSalam.GaugeGroupI, ``PatiSalam.gaugeGroupISpinEquiv] + deps := [``GaugeGroupI, ``PatiSalam.GaugeGroupI, ``PatiSalam.gaugeGroupISpinEquiv] +/-- The inclusion of the Standard Model gauge group into Spin(10), i.e., the compoisiton of +`embedPatiSalam` and `PatiSalam.inclSM`. + +See page 56 of https://math.ucr.edu/home/baez/guts.pdf +-/ informal_definition inclSM where - physics :≈ "The inclusion of the Standard Model gauge group into Spin(10)." - math :≈ "The compoisiton of ``embedPatiSalam and ``PatiSalam.inclSM." - ref :≈ "Page 56 of https://math.ucr.edu/home/baez/guts.pdf" - deps :≈ [``inclPatiSalam, ``PatiSalam.inclSM] + deps := [``inclPatiSalam, ``PatiSalam.inclSM] +/-- The inclusion of the Georgi-Glashow gauge group into Spin(10), i.e., the Lie group homomorphism +from `SU(n) → Spin(2n)` discussed on page 46 of https://math.ucr.edu/home/baez/guts.pdf for `n = 5`. +-/ informal_definition inclGeorgiGlashow where - physics :≈ "The inclusion of the Georgi-Glashow gauge group into Spin(10)." - math :≈ "The Lie group homomorphism from SU(n) → Spin(2n) dicussed on page 46 of - https://math.ucr.edu/home/baez/guts.pdf for n = 5." - deps :≈ [``GaugeGroupI, ``GeorgiGlashow.GaugeGroupI] + deps := [``GaugeGroupI, ``GeorgiGlashow.GaugeGroupI] +/-- The inclusion of the Standard Model gauge group into Spin(10), i.e., the composition of +`inclGeorgiGlashow` and `GeorgiGlashow.inclSM`. +-/ informal_definition inclSMThruGeorgiGlashow where - physics :≈ "The inclusion of the Standard Model gauge group into Spin(10)." - math :≈ "The composition of ``inclGeorgiGlashow and ``GeorgiGlashow.inclSM." - deps :≈ [``inclGeorgiGlashow, ``GeorgiGlashow.inclSM] + deps := [``inclGeorgiGlashow, ``GeorgiGlashow.inclSM] +/-- The inclusion `inclSM` is equal to the inclusion `inclSMThruGeorgiGlashow`. -/ informal_lemma inclSM_eq_inclSMThruGeorgiGlashow where - math :≈ "The inclusion ``inclSM is equal to the inclusion ``inclSMThruGeorgiGlashow." - deps :≈ [``inclSM, ``inclSMThruGeorgiGlashow] + deps := [``inclSM, ``inclSMThruGeorgiGlashow] end Spin10Model diff --git a/HepLean/BeyondTheStandardModel/TwoHDM/GaugeOrbits.lean b/HepLean/BeyondTheStandardModel/TwoHDM/GaugeOrbits.lean index 63c4453..aff69e8 100644 --- a/HepLean/BeyondTheStandardModel/TwoHDM/GaugeOrbits.lean +++ b/HepLean/BeyondTheStandardModel/TwoHDM/GaugeOrbits.lean @@ -84,17 +84,19 @@ lemma prodMatrix_smooth (Φ1 Φ2 : HiggsField) : simpa only [prodMatrix, Fin.zero_eta, Fin.isValue, of_apply, cons_val', cons_val_zero, empty_val', cons_val_fin_one] using smooth_innerProd _ _ +/-- The map `prodMatrix` is invariant under the simultanous action of `gaugeAction` on the two Higgs +fields. -/ informal_lemma prodMatrix_invariant where - math :≈ "The map ``prodMatrix is invariant under the simultanous action of ``gaugeAction - on the two Higgs fields." - deps :≈ [``prodMatrix, ``gaugeAction] + deps := [``prodMatrix, ``gaugeAction] +/-- Given any smooth map `f` from spacetime to 2-by-2 complex matrices landing on positive +semi-definite matrices, there exist smooth Higgs fields `Φ1` and `Φ2` such that `f` is equal to +`prodMatrix Φ1 Φ2`. + +See https://arxiv.org/pdf/hep-ph/0605184 +-/ informal_lemma prodMatrix_to_higgsField where - math :≈ "Given any smooth map ``f from spacetime to 2 x 2 complex matrices landing on positive - semi-definite matrices, there exist smooth Higgs fields ``Φ1 and ``Φ2 such that - ``f is equal to ``prodMatrix Φ1 Φ2." - deps :≈ [``prodMatrix, ``HiggsField, ``prodMatrix_smooth] - ref :≈ "https://arxiv.org/pdf/hep-ph/0605184" + deps := [``prodMatrix, ``HiggsField, ``prodMatrix_smooth] end end TwoHDM diff --git a/HepLean/Lorentz/ComplexTensor/Bispinors/Basic.lean b/HepLean/Lorentz/ComplexTensor/Bispinors/Basic.lean index af0cde5..1a1dd2f 100644 --- a/HepLean/Lorentz/ComplexTensor/Bispinors/Basic.lean +++ b/HepLean/Lorentz/ComplexTensor/Bispinors/Basic.lean @@ -80,15 +80,19 @@ lemma tensorNode_coBispinorDown (p : complexCo) : -/ -informal_lemma contrBispinorUp_eq_metric_contr_contrBispinorDown where - math :≈ "{contrBispinorUp p | α β = εL | α α' ⊗ εR | β β'⊗ contrBispinorDown p | α' β' }ᵀ" - proof :≈ "Expand `contrBispinorDown` and use fact that metrics contract to the identity." - deps :≈ [``contrBispinorUp, ``contrBispinorDown, ``leftMetric, ``rightMetric] +/-- `{contrBispinorUp p | α β = εL | α α' ⊗ εR | β β'⊗ contrBispinorDown p | α' β' }ᵀ`. +Proof: expand `contrBispinorDown` and use fact that metrics contract to the identity. +-/ +informal_lemma contrBispinorUp_eq_metric_contr_contrBispinorDown where + deps := [``contrBispinorUp, ``contrBispinorDown, ``leftMetric, ``rightMetric] + +/-- `{coBispinorUp p | α β = εL | α α' ⊗ εR | β β'⊗ coBispinorDown p | α' β' }ᵀ`. + +proof: expand `coBispinorDown` and use fact that metrics contract to the identity. +-/ informal_lemma coBispinorUp_eq_metric_contr_coBispinorDown where - math :≈ "{coBispinorUp p | α β = εL | α α' ⊗ εR | β β'⊗ coBispinorDown p | α' β' }ᵀ" - proof :≈ "Expand `coBispinorDown` and use fact that metrics contract to the identity." - deps :≈ [``coBispinorUp, ``coBispinorDown, ``leftMetric, ``rightMetric] + deps := [``coBispinorUp, ``coBispinorDown, ``leftMetric, ``rightMetric] lemma contrBispinorDown_expand (p : complexContr) : {contrBispinorDown p | α β}ᵀ.tensor = diff --git a/HepLean/Lorentz/ComplexTensor/Metrics/Lemmas.lean b/HepLean/Lorentz/ComplexTensor/Metrics/Lemmas.lean index dea01b0..ca848d0 100644 --- a/HepLean/Lorentz/ComplexTensor/Metrics/Lemmas.lean +++ b/HepLean/Lorentz/ComplexTensor/Metrics/Lemmas.lean @@ -31,29 +31,29 @@ namespace complexLorentzTensor -/ +/-- The covariant metric is symmetric `{η' | μ ν = η' | ν μ}ᵀ`. -/ informal_lemma coMetric_symm where - math :≈ "The covariant metric is symmetric {η' | μ ν = η' | ν μ}ᵀ" - deps :≈ [``coMetric] + deps := [``coMetric] +/-- The contravariant metric is symmetric `{η | μ ν = η | ν μ}ᵀ`. -/ informal_lemma contrMetric_symm where - math :≈ "The contravariant metric is symmetric {η | μ ν = η | ν μ}ᵀ" - deps :≈ [``contrMetric] + deps := [``contrMetric] +/-- The left metric is antisymmetric `{εL | α α' = - εL | α' α}ᵀ`. -/ informal_lemma leftMetric_antisymm where - math :≈ "The left metric is antisymmetric {εL | α α' = - εL | α' α}ᵀ" - deps :≈ [``leftMetric] + deps := [``leftMetric] +/-- The right metric is antisymmetric `{εR | β β' = - εR | β' β}ᵀ`. -/ informal_lemma rightMetric_antisymm where - math :≈ "The right metric is antisymmetric {εR | β β' = - εR | β' β}ᵀ" - deps :≈ [``rightMetric] + deps := [``rightMetric] +/-- The alt-left metric is antisymmetric `{εL' | α α' = - εL' | α' α}ᵀ`. -/ informal_lemma altLeftMetric_antisymm where - math :≈ "The alt-left metric is antisymmetric {εL' | α α' = - εL' | α' α}ᵀ" - deps :≈ [``altLeftMetric] + deps := [``altLeftMetric] +/-- The alt-right metric is antisymmetric `{εR' | β β' = - εR' | β' β}ᵀ`. -/ informal_lemma altRightMetric_antisymm where - math :≈ "The alt-right metric is antisymmetric {εR' | β β' = - εR' | β' β}ᵀ" - deps :≈ [``altRightMetric] + deps := [``altRightMetric] /-! @@ -61,35 +61,41 @@ informal_lemma altRightMetric_antisymm where -/ +/-- The contraction of the covariant metric with the contravariant metric is the unit +`{η' | μ ρ ⊗ η | ρ ν = δ' | μ ν}ᵀ`. +-/ informal_lemma coMetric_contr_contrMetric where - math :≈ "The contraction of the covariant metric with the contravariant metric is the unit - {η' | μ ρ ⊗ η | ρ ν = δ' | μ ν}ᵀ" - deps :≈ [``coMetric, ``contrMetric, ``coContrUnit] + deps := [``coMetric, ``contrMetric, ``coContrUnit] +/-- The contraction of the contravariant metric with the covariant metric is the unit +`{η | μ ρ ⊗ η' | ρ ν = δ | μ ν}ᵀ`. +-/ informal_lemma contrMetric_contr_coMetric where - math :≈ "The contraction of the contravariant metric with the covariant metric is the unit - {η | μ ρ ⊗ η' | ρ ν = δ | μ ν}ᵀ" - deps :≈ [``contrMetric, ``coMetric, ``contrCoUnit] + deps := [``contrMetric, ``coMetric, ``contrCoUnit] +/-- The contraction of the left metric with the alt-left metric is the unit +`{εL | α β ⊗ εL' | β γ = δL | α γ}ᵀ`. +-/ informal_lemma leftMetric_contr_altLeftMetric where - math :≈ "The contraction of the left metric with the alt-left metric is the unit - {εL | α β ⊗ εL' | β γ = δL | α γ}ᵀ" - deps :≈ [``leftMetric, ``altLeftMetric, ``leftAltLeftUnit] + deps := [``leftMetric, ``altLeftMetric, ``leftAltLeftUnit] +/-- The contraction of the right metric with the alt-right metric is the unit +`{εR | α β ⊗ εR' | β γ = δR | α γ}ᵀ`. +-/ informal_lemma rightMetric_contr_altRightMetric where - math :≈ "The contraction of the right metric with the alt-right metric is the unit - {εR | α β ⊗ εR' | β γ = δR | α γ}ᵀ" - deps :≈ [``rightMetric, ``altRightMetric, ``rightAltRightUnit] + deps := [``rightMetric, ``altRightMetric, ``rightAltRightUnit] +/-- The contraction of the alt-left metric with the left metric is the unit +`{εL' | α β ⊗ εL | β γ = δL' | α γ}ᵀ`. +-/ informal_lemma altLeftMetric_contr_leftMetric where - math :≈ "The contraction of the alt-left metric with the left metric is the unit - {εL' | α β ⊗ εL | β γ = δL' | α γ}ᵀ" - deps :≈ [``altLeftMetric, ``leftMetric, ``altLeftLeftUnit] + deps := [``altLeftMetric, ``leftMetric, ``altLeftLeftUnit] +/-- The contraction of the alt-right metric with the right metric is the unit +`{εR' | α β ⊗ εR | β γ = δR' | α γ}ᵀ`. +-/ informal_lemma altRightMetric_contr_rightMetric where - math :≈ "The contraction of the alt-right metric with the right metric is the unit - {εR' | α β ⊗ εR | β γ = δR' | α γ}ᵀ" - deps :≈ [``altRightMetric, ``rightMetric, ``altRightRightUnit] + deps := [``altRightMetric, ``rightMetric, ``altRightRightUnit] /-! diff --git a/HepLean/Lorentz/ComplexTensor/Units/Symm.lean b/HepLean/Lorentz/ComplexTensor/Units/Symm.lean index 541a097..a58aef7 100644 --- a/HepLean/Lorentz/ComplexTensor/Units/Symm.lean +++ b/HepLean/Lorentz/ComplexTensor/Units/Symm.lean @@ -31,32 +31,32 @@ namespace complexLorentzTensor -/ +/-- Swapping indices of `coContrUnit` returns `contrCoUnit`: `{δ' | μ ν = δ | ν μ}ᵀ`. -/ informal_lemma coContrUnit_symm where - math :≈ "Swapping indices of coContrUnit returns contrCoUnit, i.e. {δ' | μ ν = δ | ν μ}.ᵀ" - deps :≈ [``coContrUnit, ``contrCoUnit] + deps := [``coContrUnit, ``contrCoUnit] +/-- Swapping indices of `contrCoUnit` returns `coContrUnit`: `{δ | μ ν = δ' | ν μ}ᵀ`. -/ informal_lemma contrCoUnit_symm where - math :≈ "Swapping indices of contrCoUnit returns coContrUnit, i.e. {δ | μ ν = δ' | ν μ}ᵀ" - deps :≈ [``contrCoUnit, ``coContrUnit] + deps := [``contrCoUnit, ``coContrUnit] +/-- Swapping indices of `altLeftLeftUnit` returns `leftAltLeftUnit`: `{δL' | α α' = δL | α' α}ᵀ`. -/ informal_lemma altLeftLeftUnit_symm where - math :≈ "Swapping indices of altLeftLeftUnit returns leftAltLeftUnit, i.e. - {δL' | α α' = δL | α' α}ᵀ" - deps :≈ [``altLeftLeftUnit, ``leftAltLeftUnit] + deps := [``altLeftLeftUnit, ``leftAltLeftUnit] +/-- Swapping indices of `leftAltLeftUnit` returns `altLeftLeftUnit`: `{δL | α α' = δL' | α' α}ᵀ`. -/ informal_lemma leftAltLeftUnit_symm where - math :≈ "Swapping indices of leftAltLeftUnit returns altLeftLeftUnit, i.e. - {δL | α α' = δL' | α' α}ᵀ" - deps :≈ [``leftAltLeftUnit, ``altLeftLeftUnit] + deps := [``leftAltLeftUnit, ``altLeftLeftUnit] +/-- Swapping indices of `altRightRightUnit` returns `rightAltRightUnit`: +`{δR' | β β' = δR | β' β}ᵀ`. +-/ informal_lemma altRightRightUnit_symm where - math :≈ "Swapping indices of altRightRightUnit returns rightAltRightUnit, i.e. - {δR' | β β' = δR | β' β}ᵀ" - deps :≈ [``altRightRightUnit, ``rightAltRightUnit] + deps := [``altRightRightUnit, ``rightAltRightUnit] +/-- Swapping indices of `rightAltRightUnit` returns `altRightRightUnit`: +`{δR | β β' = δR' | β' β}ᵀ`. +-/ informal_lemma rightAltRightUnit_symm where - math :≈ "Swapping indices of rightAltRightUnit returns altRightRightUnit, i.e. - {δR | β β' = δR' | β' β}ᵀ" - deps :≈ [``rightAltRightUnit, ``altRightRightUnit] + deps := [``rightAltRightUnit, ``altRightRightUnit] end complexLorentzTensor diff --git a/HepLean/Lorentz/Group/Restricted.lean b/HepLean/Lorentz/Group/Restricted.lean index 7a806b6..082db08 100644 --- a/HepLean/Lorentz/Group/Restricted.lean +++ b/HepLean/Lorentz/Group/Restricted.lean @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Tooby-Smith -/ import HepLean.Lorentz.Group.Orthochronous +import HepLean.Meta.Informal.Basic /-! # The Restricted Lorentz Group @@ -16,17 +17,10 @@ TODO "Prove that every member of the restricted Lorentz group is TODO "Prove restricted Lorentz group equivalent to connected component of identity of the Lorentz group." -noncomputable section - -open Matrix -open Complex -open ComplexConjugate - namespace LorentzGroup +/-- The subgroup of the Lorentz group consisting of elements which are proper and orthochronous. -/ informal_definition Restricted where - math :≈ "The subgroup of the Lorentz group consisting of elements which - are proper and orthochronous." - deps :≈ [``LorentzGroup, ``IsProper, ``IsOrthochronous] + deps := [``LorentzGroup, ``IsProper, ``IsOrthochronous] end LorentzGroup diff --git a/HepLean/Lorentz/RealVector/Modules.lean b/HepLean/Lorentz/RealVector/Modules.lean index 2652df7..bc38c7c 100644 --- a/HepLean/Lorentz/RealVector/Modules.lean +++ b/HepLean/Lorentz/RealVector/Modules.lean @@ -3,7 +3,6 @@ Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Tooby-Smith -/ -import HepLean.Meta.Informal.Basic import HepLean.Lorentz.PauliMatrices.SelfAdjoint /-! diff --git a/HepLean/Lorentz/SL2C/Basic.lean b/HepLean/Lorentz/SL2C/Basic.lean index 58df051..8152aef 100644 --- a/HepLean/Lorentz/SL2C/Basic.lean +++ b/HepLean/Lorentz/SL2C/Basic.lean @@ -307,9 +307,9 @@ lemma toLorentzGroup_det_one (M : SL(2, ℂ)) : det (toLorentzGroup M).val = 1 : _ = M.val.det := congrArg det h.symm _ = 1 := M.property +/-- The homomorphism from `SL(2, ℂ)` to the restricted Lorentz group. -/ informal_lemma toRestrictedLorentzGroup where - math :≈ "The homomorphism from `SL(2, ℂ)` to the restricted Lorentz group." - deps :≈ [``toLorentzGroup, ``toLorentzGroup_det_one, ``toLorentzGroup_isOrthochronous, + deps := [``toLorentzGroup, ``toLorentzGroup_det_one, ``toLorentzGroup_isOrthochronous, ``LorentzGroup.Restricted] TODO "Define homomorphism from `SL(2, ℂ)` to the restricted Lorentz group." diff --git a/HepLean/Lorentz/Weyl/Basic.lean b/HepLean/Lorentz/Weyl/Basic.lean index 218b820..6c04b99 100644 --- a/HepLean/Lorentz/Weyl/Basic.lean +++ b/HepLean/Lorentz/Weyl/Basic.lean @@ -284,15 +284,17 @@ lemma leftHandedAltEquiv_inv_hom_apply (ψ : altLeftHanded) : leftHandedAltEquiv.inv.hom ψ = LeftHandedModule.toFin2ℂEquiv.symm (!![0, -1; 1, 0] *ᵥ ψ.toFin2ℂ) := rfl +/-- The linear equivalence between `rightHandedWeyl` and `altRightHandedWeyl` given by multiplying +an element of `rightHandedWeyl` by the matrix `εᵃ⁰ᵃ¹ = !![0, 1; -1, 0]]`. +-/ informal_definition rightHandedWeylAltEquiv where - math :≈ "The linear equiv between rightHandedWeyl and altRightHandedWeyl given - by multiplying an element of rightHandedWeyl by the matrix `εᵃ⁰ᵃ¹ = !![0, 1; -1, 0]]`" - deps :≈ [``rightHanded, ``altRightHanded] + deps := [``rightHanded, ``altRightHanded] +/-- The linear equivalence `rightHandedWeylAltEquiv` is equivariant with respect to the action of +`SL(2,C)` on `rightHandedWeyl` and `altRightHandedWeyl`. +-/ informal_lemma rightHandedWeylAltEquiv_equivariant where - math :≈ "The linear equiv rightHandedWeylAltEquiv is equivariant with respect to the - action of SL(2,C) on rightHandedWeyl and altRightHandedWeyl." - deps :≈ [``rightHandedWeylAltEquiv] + deps := [``rightHandedWeylAltEquiv] end diff --git a/HepLean/Meta/AllFilePaths.lean b/HepLean/Meta/AllFilePaths.lean index 9c26efe..d27cdd8 100644 --- a/HepLean/Meta/AllFilePaths.lean +++ b/HepLean/Meta/AllFilePaths.lean @@ -3,7 +3,6 @@ Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved. Released under Apache 2.0 license. Authors: Joseph Tooby-Smith -/ -import Lean import HepLean.Meta.TODO.Basic /-! @@ -11,7 +10,7 @@ import HepLean.Meta.TODO.Basic -/ -open Lean Elab System +open System TODO "Make this definition more functional in style. In other words, remove the for loop." diff --git a/HepLean/Meta/Basic.lean b/HepLean/Meta/Basic.lean index 7e2bf36..3fc53fd 100644 --- a/HepLean/Meta/Basic.lean +++ b/HepLean/Meta/Basic.lean @@ -3,19 +3,23 @@ Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved. Released under Apache 2.0 license. Authors: Joseph Tooby-Smith -/ -import Batteries.Lean.HashSet import Mathlib.Lean.Expr.Basic -import Mathlib.Lean.CoreM import ImportGraph.RequiredModules -import HepLean.Meta.Informal.Basic /-! ## Basic Lean meta programming commands -/ -namespace HepLean -open Lean System Meta +/-- The size of a flattened array of arrays. -/ +def Array.flatSize {α} : Array (Array α) → Nat := + foldl (init := 0) fun sizeAcc as => sizeAcc + as.size + +/-- The size of a flattened array of arrays after applying an element-wise filter. -/ +def Array.flatFilterSizeM {α m} [Monad m] (p : α → m Bool) : Array (Array α) → m Nat := + foldlM (init := 0) fun sizeAcc as => return sizeAcc + (← as.filterM p).size + +open Lean /-! @@ -24,194 +28,166 @@ open Lean System Meta -/ /-- Gets all imports within HepLean. -/ -def allImports : IO (Array Import) := do +def HepLean.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 mods := `HepLean + let mFile ← findOLean mods + unless ← mFile.pathExists do + throw <| IO.userError s!"object file '{mFile}' of module {mods} does not exist" let (hepLeanMod, _) ← readModuleData mFile - let imports := hepLeanMod.imports.filter (fun c => c.module ≠ `Init) - return imports + hepLeanMod.imports.filterM fun c => return c.module != `Init /-- Number of files within HepLean. -/ -def noImports : IO Nat := do +def HepLean.noImports : IO Nat := do let imports ← allImports - pure imports.size + return imports.size /-- Gets all constants from an import. -/ -def Imports.getConsts (imp : Import) : IO (Array ConstantInfo) := do +def HepLean.Imports.getConsts (imp : Import) : IO (Array ConstantInfo) := do let mFile ← findOLean imp.module let (modData, _) ← readModuleData mFile - pure modData.constants + return modData.constants /-- Gets all user defined constants from an import. -/ -def Imports.getUserConsts (imp : Import) : MetaM (Array ConstantInfo) := do +def HepLean.Imports.getUserConsts (imp : Import) : CoreM (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 + let consts ← Imports.getConsts imp + consts.filterM fun c => + let name := c.name + return !name.isInternal + && !isCasesOnRecursor env name + && !isRecOnRecursor env name + && !isNoConfusion env name + && !isBRecOnRecursor env name + && !isAuxRecursorWithSuffix env name binductionOnSuffix + && !isAuxRecursorWithSuffix env name belowSuffix + && !isAuxRecursorWithSuffix env name ibelowSuffix + /- Removing syntax category declarations. -/ + && name.toString != "TensorTree.indexExpr.quot" + && name.toString != "TensorTree.tensorExpr.quot" + +/-- Turns a name into a system file path. -/ +def Lean.Name.toFilePath (c : Name) : System.FilePath := + System.mkFilePath (c.toString.splitOn ".") |>.addExtension "lean" /-- 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 +def HepLean.Imports.getLines (imp : Import) : IO (Array String) := do + IO.FS.lines imp.module.toFilePath +namespace Lean.Name /-! ## Name -/ +variable {m} [Monad m] [MonadEnv m] [MonadLiftT BaseIO m] + /-- Turns a name into a Lean file. -/ -def Name.toFile (c : Name) : MetaM String := do - return s!"./{c.toString.replace "." "/" ++ ".lean"}" +def toRelativeFilePath (c : Name) : System.FilePath := + System.FilePath.join "." c.toFilePath /-- Turns a name, which represents a module, into a link to github. -/ -def Name.toGitHubLink (c : Name) (l : Nat := 0) : MetaM String := do - let headerLink := "https://github.com/HEPLean/HepLean/blob/master/" - let filePart := (c.toString.replace "." "/") ++ ".lean" - let linePart := "#L" ++ toString l - return headerLink ++ filePart ++ linePart +def toGitHubLink (c : Name) (line : Nat) : String := + s!"https://github.com/HEPLean/HepLean/blob/master/{c.toFilePath}#L{line}" /-- Given a name, returns the line number. -/ -def Name.lineNumber (c : Name) : MetaM Nat := do +def lineNumber (c : Name) : m Nat := do match ← findDeclarationRanges? c with - | some decl => pure decl.range.pos.line + | some decl => return decl.range.pos.line | none => panic! s!"{c} is a declaration without position" /-- Given a name, returns the file name corresponding to that declaration. -/ -def Name.fileName (c : Name) : MetaM Name := do +def fileName (c : Name) : m Name := do let env ← getEnv - let x := env.getModuleFor? c - match x with - | some c => pure c + match env.getModuleFor? c with + | some decl => return decl | none => panic! s!"{c} is a declaration without position" /-- Returns the location of a name. -/ -def Name.location (c : Name) : MetaM String := do +def location (c : Name) : m 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) + match env.getModuleFor? c with + | some decl => return s!"{decl.toRelativeFilePath}:{← c.lineNumber} {c}" | 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 +def hasPos (c : Name) : m Bool := do + let ranges? ← findDeclarationRanges? c + return ranges?.isSome /-- Determines if a name has a doc string. -/ -def Name.hasDocString (c : Name) : MetaM Bool := do +def hasDocString (c : Name) : CoreM Bool := do let env ← getEnv - let doc ← Lean.findDocString? env c - match doc with - | some _ => pure true - | none => pure false + let doc? ← findDocString? env c + return doc?.isSome /-- The doc string from a name. -/ -def Name.getDocString (c : Name) : MetaM String := do +def getDocString (c : Name) : CoreM String := do let env ← getEnv - let doc ← Lean.findDocString? env c - match doc with - | some doc => pure doc - | none => pure "" + let doc? ← findDocString? env c + return doc?.getD "" /-- Given a name, returns the source code defining that name. -/ -def Name.getDeclString (name : Name) : MetaM String := do +def getDeclString (name : Name) : CoreM String := do let env ← getEnv - let decl ← findDeclarationRanges? name - match decl with - | some decl => - let startLine := decl.range.pos - let endLine := decl.range.endPos - let fileName? := env.getModuleFor? name - match fileName? with + match ← findDeclarationRanges? name with + | some { range := { pos, endPos, .. }, .. } => + match env.getModuleFor? name with | some fileName => - let fileContent ← IO.FS.readFile { toString := (← Name.toFile fileName)} + let fileContent ← IO.FS.readFile fileName.toRelativeFilePath let fileMap := fileContent.toFileMap - let startPos := fileMap.ofPosition startLine - let endPos := fileMap.ofPosition endLine - let text := fileMap.source.extract startPos endPos - pure text - | none => - pure "" - | none => pure "" + return fileMap.source.extract (fileMap.ofPosition pos) (fileMap.ofPosition endPos) + | none => return "" + | none => return "" + +end Lean.Name + +namespace HepLean /-- 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 +def noDefs : CoreM Nat := do + let imports ← HepLean.allImports + let x ← imports.mapM HepLean.Imports.getUserConsts + x.flatFilterSizeM fun c => return c.isDef && (← c.name.hasPos) /-- 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 +def noLemmas : CoreM Nat := do + let imports ← HepLean.allImports + let x ← imports.mapM HepLean.Imports.getUserConsts + x.flatFilterSizeM fun c => return !c.isDef && (← c.name.hasPos) /-- 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 +def noDefsNoDocString : CoreM Nat := do + let imports ← HepLean.allImports + let x ← imports.mapM HepLean.Imports.getUserConsts + x.flatFilterSizeM fun c => + return c.isDef && (← c.name.hasPos) && !(← c.name.hasDocString) /-- 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 +def noLemmasNoDocString : CoreM Nat := do + let imports ← HepLean.allImports + let x ← imports.mapM HepLean.Imports.getUserConsts + x.flatFilterSizeM fun c => + return !c.isDef && (← c.name.hasPos) && !(← c.name.hasDocString) /-- 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 + return x.flatSize /-- 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 + x.flatFilterSizeM fun l => return l.startsWith "TODO " /-- 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 + let x := x.filter fun bs => bs.any fun l => l.startsWith "TODO " + return x.size end HepLean diff --git a/HepLean/Meta/Informal/Basic.lean b/HepLean/Meta/Informal/Basic.lean index 027f72c..414630c 100644 --- a/HepLean/Meta/Informal/Basic.lean +++ b/HepLean/Meta/Informal/Basic.lean @@ -3,245 +3,57 @@ Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved. Released under Apache 2.0 license. Authors: Joseph Tooby-Smith -/ -import Lean -import HepLean.Meta.TODO.Basic +import Lean.Parser.Term /-! ## Informal definitions and lemmas -This file contains the necessary structures that must be imported into a file -for it to contain informal definitions and lemmas. +This file contains the necessary structures that must be imported into a file for it to contain +informal definitions and lemmas. Everything else about informal definitions and lemmas are in the `Informal.Post` module. -/ -open Lean Elab System - -TODO "Can likely make this a bona-fide command." /-- The structure representing an informal definition. -/ structure InformalDefinition where - /-- The name of the informal definition. This is autogenerated. -/ - name : Name - /-- The mathematical description of the definition. -/ - math : String - /-- The physics description of the definition. -/ - physics : String - /-- References. -/ - ref : String /-- The names of top-level commands we expect this definition to depend on. -/ - dependencies : List Name + deps : List Lean.Name -/-- The structure representing an informal proof. -/ +/-- The structure representing an informal lemma. -/ structure InformalLemma where - /-- The name of the informal lemma. This is autogenerated. -/ - name : Name - /-- The mathematical description of the lemma. -/ - math : String - /-- The physics description of the lemma. -/ - physics : String - /-- A description of the proof. -/ - proof : String - /-- References. -/ - ref : String /-- The names of top-level commands we expect this lemma to depend on. -/ - dependencies : List Name + deps : List Lean.Name namespace Informal -/-- The Parser.Category we will use for assignments. -/ -declare_syntax_cat informalAssignment - -/-- The syntax describing an informal assignment of `ident` to a string. -/ -syntax (name := informalAssignment) ident ":≈" str : informalAssignment - -/-- The syntax describing an informal assignment of `ident` to a list. -/ -syntax (name := informalAssignmentDeps) ident ":≈" "[" sepBy(term, ",") "]" : informalAssignment - /-! ## Syntax +Using macros for syntax rewriting works better with the language server compared to +`Lake.DSL.LeanLibDecl`. Hovering over any definition of `informal_definition` or `informal_lemma` +gives a proper type hint like any proper definition using `def` whereas definitions of `lake_lib` +and `lake_exe` don't show docstrings and infer the type `Lean.Name`. + -/ -/-- The syntax for the command informal_definition. -/ -syntax (name := informal_definition) "informal_definition " ident - " where " (colGt informalAssignment)* : command -/-- An informal definition is a definition which is not type checked, and is written - as a string literal. It can be used to plan out sections for future formalization, or to - include results which the formalization is not immediately known. - Each informal definition must included a - `math :≈ "..."` - entry, but can also include the following entries - `physics :≈ "..."`, `ref :≈ "..."`, and `deps :≈ [...]`. -/ -macro "informal_definition " name:ident " where " assignments:informalAssignment* : command => do - let mut math_def? : Option (TSyntax `term) := none - let mut physics_def? : Option (TSyntax `term) := none - let mut ref_def? : Option (TSyntax `term) := none - let mut dep_def? : Option (TSyntax `term) := none - for assignment in assignments do - match assignment with - | `(informalAssignment| physics :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for physics" - physics_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignment| math :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for math" - math_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignment| ref :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for ref" - ref_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignmentDeps| deps :≈ [$deps,*]) => - dep_def? := some (← `([$deps,*])) - | _ => Macro.throwError "invalid assignment syntax in informal_definition" - unless math_def?.isSome do - Macro.throwError "A 'math' assignments is required" - `( -/-- An informal definition. -/ -def $name : InformalDefinition := { - name := $(Lean.quote name.getId), - physics := $(physics_def?.getD (← `("No physics description provided"))), - math := $(math_def?.getD (panic! "math not assigned")), - ref := $(ref_def?.getD (← `("No references provided"))), - dependencies := $(dep_def?.getD (← `([]))) - }) +open Lean.Parser.Term -/-- The syntax for the command informal_definition. -/ -syntax (name := informal_definition_note) "informal_definition_note " ident - " where " (colGt informalAssignment)* : command +/-- A placeholder for definitions to be formalized in the future. Docstrings of informal definitions +should outline its mathematical or physical content and specify useful references. Use the attribute +`note_attr_informal` from `HepLean.Meta.Notes.Basic` to mark the informal definition as a note. +-/ +macro (name := informalDefinitionDecl) +doc?:(docComment)? attrs?:(attributes)? "informal_definition " name:ident body:declVal : command => + `($[$doc?]? $[$attrs?]? def $name : InformalDefinition $body:declVal) -/-- An informal definition is a definition which is not type checked, and is written - as a string literal. It can be used to plan out sections for future formalization, or to - include results which the formalization is not immediately known. - Each informal definition must included a - `math :≈ "..."` - entry, but can also include the following entries - `physics :≈ "..."`, `ref :≈ "..."`, and `deps :≈ [...]`. -/ -macro "informal_definition_note " name:ident " where " assignments:informalAssignment* : - command => do - let mut math_def? : Option (TSyntax `term) := none - let mut physics_def? : Option (TSyntax `term) := none - let mut ref_def? : Option (TSyntax `term) := none - let mut dep_def? : Option (TSyntax `term) := none - for assignment in assignments do - match assignment with - | `(informalAssignment| physics :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for physics" - physics_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignment| math :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for math" - math_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignment| ref :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for ref" - ref_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignmentDeps| deps :≈ [$deps,*]) => - dep_def? := some (← `([$deps,*])) - | _ => Macro.throwError "invalid assignment syntax in informal_definition" - unless math_def?.isSome do - Macro.throwError "A 'math' assignments is required" - `( -/-- An informal definition. -/ -@[note_attr_informal] -def $name : InformalDefinition := { - name := $(Lean.quote name.getId), - physics := $(physics_def?.getD (← `("No physics description provided"))), - math := $(math_def?.getD (panic! "math not assigned")), - ref := $(ref_def?.getD (← `("No references provided"))), - dependencies := $(dep_def?.getD (← `([]))) - }) - -/-- The syntax for the command `informal_lemma`. -/ -syntax (name := informal_lemma) "informal_lemma " ident " where " - (colGt informalAssignment)* : command - -/-- An informal lemma is a lemma which is not type checked, and is written - as a string literal. It can be used to plan out sections for future formalization, or to - include results which the formalization is not immediately known. - Every informal lemma must included a - `math :≈ "..."` - entry, but can also include the following entries - `physics :≈ "..."`, `proof :≈ "..."`, `ref :≈ "..."`, and `deps :≈ [...]`. -/ -macro "informal_lemma " name:ident " where " assignments:informalAssignment* : command => do - let mut math_def? : Option (TSyntax `term) := none - let mut physics_def? : Option (TSyntax `term) := none - let mut proof_def? : Option (TSyntax `term) := none - let mut ref_def? : Option (TSyntax `term) := none - let mut dep_def? : Option (TSyntax `term) := none - for assignment in assignments do - match assignment with - | `(informalAssignment| physics :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for physics" - physics_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignment| math :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for math" - math_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignment| proof :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for proof" - proof_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignment| ref :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for ref" - ref_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignmentDeps| deps :≈ [$deps,*]) => - dep_def? := some (← `([$deps,*])) - | _ => Macro.throwError "invalid assignment syntax" - unless math_def?.isSome do - Macro.throwError "A 'math' assignments is required" - `( -/-- An informal lemma. -/ -def $name : InformalLemma := { - name := $(Lean.quote name.getId), - physics := $(physics_def?.getD (← `("No physics description provided"))), - math := $(math_def?.getD (panic! "math not assigned")), - proof := $(proof_def?.getD (← `("No proof description provided"))), - ref := $(ref_def?.getD (← `("No references provided"))), - dependencies := $(dep_def?.getD (← `([]))) - }) - -/-- The syntax for the command `informal_lemma`. -/ -syntax (name := informal_lemma_note) "informal_lemma_note " ident " where " - (colGt informalAssignment)* : command - -/-- An informal lemma is a lemma which is not type checked, and is written - as a string literal. It can be used to plan out sections for future formalization, or to - include results which the formalization is not immediately known. - Every informal lemma must included a - `math :≈ "..."` - entry, but can also include the following entries - `physics :≈ "..."`, `proof :≈ "..."`, `ref :≈ "..."`, and `deps :≈ [...]`. -/ -macro "informal_lemma_note " name:ident " where " assignments:informalAssignment* : command => do - let mut math_def? : Option (TSyntax `term) := none - let mut physics_def? : Option (TSyntax `term) := none - let mut proof_def? : Option (TSyntax `term) := none - let mut ref_def? : Option (TSyntax `term) := none - let mut dep_def? : Option (TSyntax `term) := none - for assignment in assignments do - match assignment with - | `(informalAssignment| physics :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for physics" - physics_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignment| math :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for math" - math_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignment| proof :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for proof" - proof_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignment| ref :≈ $val:str) => - let some strVal := val.raw.isStrLit? | Macro.throwError "Expected string literal for ref" - ref_def? := some (← `($(Lean.quote strVal))) - | `(informalAssignmentDeps| deps :≈ [$deps,*]) => - dep_def? := some (← `([$deps,*])) - | _ => Macro.throwError "invalid assignment syntax" - unless math_def?.isSome do - Macro.throwError "A 'math' assignments is required" - `( -/-- An informal lemma. -/ -@[note_attr_informal] -def $name : InformalLemma := { - name := $(Lean.quote name.getId), - physics := $(physics_def?.getD (← `("No physics description provided"))), - math := $(math_def?.getD (panic! "math not assigned")), - proof := $(proof_def?.getD (← `("No proof description provided"))), - ref := $(ref_def?.getD (← `("No references provided"))), - dependencies := $(dep_def?.getD (← `([]))) - }) +/-- A placeholder for lemmas to be formalized in the future. Docstrings of informal lemmas +should outline its mathematical or physical content and specify useful references. Use the attribute +`note_attr_informal` from `HepLean.Meta.Notes.Basic` to mark the informal definition as a note. +-/ +macro (name := informalLemmaDecl) +doc?:(docComment)? attrs?:(attributes)? "informal_lemma " name:ident body:declVal : command => + `($[$doc?]? $[$attrs?]? def $name : InformalLemma $body:declVal) end Informal diff --git a/HepLean/Meta/Informal/Post.lean b/HepLean/Meta/Informal/Post.lean index 80103e8..8504395 100644 --- a/HepLean/Meta/Informal/Post.lean +++ b/HepLean/Meta/Informal/Post.lean @@ -4,74 +4,61 @@ Released under Apache 2.0 license. Authors: Joseph Tooby-Smith -/ import HepLean.Meta.Basic +import HepLean.Meta.Informal.Basic /-! ## Informal definitions and lemmas -/ -open Lean Elab System +open Lean namespace Informal /-- Is true if and only if a `ConstantInfo` corresponds to an `InformalLemma` or a `InformalDefinition`. -/ -def isInformal (c : ConstantInfo) : Bool := - match c with - | ConstantInfo.defnInfo c => - if c.type.isAppOf ``InformalDefinition ∨ c.type.isAppOf ``InformalLemma then true else false +def isInformal : ConstantInfo → Bool + | .defnInfo c => c.type.isConstOf ``InformalDefinition ∨ c.type.isConstOf ``InformalLemma | _ => false /-- Is true if and only if a `ConstantInfo` corresponds to an `InformalLemma`. -/ -def isInformalLemma (c : ConstantInfo) : Bool := - match c with - | ConstantInfo.defnInfo c => - if c.type.isAppOf ``InformalLemma then true else false +def isInformalLemma : ConstantInfo → Bool + | .defnInfo c => c.type.isConstOf ``InformalLemma | _ => false /-- Is true if and only if a `ConstantInfo` corresponds to an `InformalDefinition`. -/ -def isInformalDef (c : ConstantInfo) : Bool := - match c with - | ConstantInfo.defnInfo c => - if c.type.isAppOf ``InformalDefinition then true else false +def isInformalDef : ConstantInfo → Bool + | .defnInfo c => c.type.isConstOf ``InformalDefinition | _ => false /-- Takes a `ConstantInfo` corresponding to a `InformalLemma` and returns the corresponding `InformalLemma`. -/ -unsafe def constantInfoToInformalLemma (c : ConstantInfo) : MetaM InformalLemma := do +unsafe def constantInfoToInformalLemma (c : ConstantInfo) : CoreM InformalLemma := do match c with - | ConstantInfo.defnInfo c => - Lean.Meta.evalExpr' InformalLemma ``InformalLemma c.value + | .defnInfo c => evalConstCheck InformalLemma ``InformalLemma c.name | _ => panic! "Passed constantInfoToInformalLemma a `ConstantInfo` that is not a `InformalLemma`" /-- Takes a `ConstantInfo` corresponding to a `InformalDefinition` and returns the corresponding `InformalDefinition`. -/ -unsafe def constantInfoToInformalDefinition (c : ConstantInfo) : MetaM InformalDefinition := do +unsafe def constantInfoToInformalDefinition (c : ConstantInfo) : CoreM InformalDefinition := do match c with - | ConstantInfo.defnInfo c => - Lean.Meta.evalExpr' InformalDefinition ``InformalDefinition c.value - | _ => panic! "Passed constantInfoToInformalDefinition a - `ConstantInfo` that is not a `InformalDefinition`" + | .defnInfo c => evalConstCheck InformalDefinition ``InformalDefinition c.name + | _ => panic! + "Passed constantInfoToInformalDefinition a `ConstantInfo` that is not a `InformalDefinition`" end Informal namespace HepLean /-- The number of informal lemmas in HepLean. -/ -def noInformalLemmas : MetaM Nat := do +def noInformalLemmas : CoreM 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 + x.flatFilterSizeM fun c => return Informal.isInformalLemma c /-- The number of informal definitions in HepLean. -/ -def noInformalDefs : MetaM Nat := do +def noInformalDefs : CoreM 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 + x.flatFilterSizeM fun c => return Informal.isInformalDef c end HepLean diff --git a/HepLean/Meta/Notes/Basic.lean b/HepLean/Meta/Notes/Basic.lean index 3626475..321a86d 100644 --- a/HepLean/Meta/Notes/Basic.lean +++ b/HepLean/Meta/Notes/Basic.lean @@ -3,10 +3,7 @@ Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved. Released under Apache 2.0 license. Authors: Joseph Tooby-Smith -/ -import Batteries.Lean.HashSet import Mathlib.Lean.Expr.Basic -import Mathlib.Lean.CoreM -import ImportGraph.RequiredModules /-! ## Underlying structure for notes @@ -24,7 +21,7 @@ Other results relating to notes are in other files. -/ namespace HepLean -open Lean System Meta +open Lean /-- The information from a `note ...` command. To be used in a note file-/ structure NoteInfo where diff --git a/HepLean/Meta/Notes/HTMLNote.lean b/HepLean/Meta/Notes/HTMLNote.lean index 807e9e0..3f08699 100644 --- a/HepLean/Meta/Notes/HTMLNote.lean +++ b/HepLean/Meta/Notes/HTMLNote.lean @@ -3,8 +3,9 @@ Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved. Released under Apache 2.0 license. Authors: Joseph Tooby-Smith -/ -import HepLean.Meta.Notes.NoteFile +-- import DocGen4.Output.DocString import HepLean.Meta.Informal.Post +import HepLean.Meta.Notes.NoteFile /-! ## Turns a delaration into a html note structure. @@ -12,7 +13,7 @@ import HepLean.Meta.Informal.Post -/ namespace HepLean -open Lean System Meta +open Lean /-- A `HTMLNote` is a structure containing the html information from individual contributions (commands, informal commands, note ..) etc. to a note file. -/ @@ -25,47 +26,52 @@ structure HTMLNote where line : Nat /-- Converts a note infor into a HTMLNote. -/ -def HTMLNote.ofNodeInfo (ni : NoteInfo) : MetaM HTMLNote := do - let line := ni.line - let decl := ni.content - let fileName := ni.fileName - pure { content := decl, fileName := fileName, line := line } +def HTMLNote.ofNodeInfo (ni : NoteInfo) : HTMLNote := + { ni with } /-- An formal definition or lemma to html for a note. -/ -def HTMLNote.ofFormal (name : Name) : MetaM HTMLNote := do - let line ← Name.lineNumber name - let decl ← Name.getDeclString name - let fileName ← Name.fileName name - let webAddress : String ← Name.toGitHubLink fileName line - let content := - "
"
- ++ decl ++
- "
{← name.getDeclString}
+