fact
stringlengths
19
8.26k
type
stringclasses
8 values
library
stringclasses
2 values
imports
listlengths
0
7
filename
stringclasses
397 values
symbolic_name
stringlengths
1
73
docstring
stringlengths
20
499
insertionSort_eq_insertionSortMin_cons {α : Type} (r : α → α → Prop) [DecidableRel r] [IsTotal α r] [IsTrans α r] (i : α) (l : List α) : List.insertionSort r (i :: l) = (insertionSortMin r i l) :: List.insertionSort r (insertionSortDropMinPos r i l) := by rw [insertionSortDropMinPos, ← eraseIdx_insertionSort_fin] conv_...
lemma
PhysLean
[ "import PhysLean.Mathematics.Fin", "import Mathlib.Data.Nat.Lattice" ]
PhysLean/Mathematics/List.lean
insertionSort_eq_insertionSortMin_cons
/-- The list remaining after dropping the element at the position determined by `insertionSortMinPos`. -/
optionEraseZ {I : Type} (l : List I) (a : I) (i : Option (Fin l.length)) : List I := match i with | none => a :: l | some i => List.eraseIdx l i @[simp]
def
PhysLean
[ "import PhysLean.Mathematics.Fin", "import Mathlib.Data.Nat.Lattice" ]
PhysLean/Mathematics/List.lean
optionEraseZ
/-- Optional erase of an element in a list, with addition for `none`. For `none` adds `a` to the front of the list, for `some i` removes the `i`th element of the list (does not add `a`). E.g. `optionEraseZ [0, 1, 2] 4 none = [4, 0, 1, 2]` and `optionEraseZ [0, 1, 2] 4 (some 1) = [0, 2]`. -/
optionEraseZ_some_length {I : Type} (l : List I) (a : I) (i : (Fin l.length)) : (optionEraseZ l a (some i)).length = l.length - 1 := by simp [optionEraseZ, List.length_eraseIdx]
lemma
PhysLean
[ "import PhysLean.Mathematics.Fin", "import Mathlib.Data.Nat.Lattice" ]
PhysLean/Mathematics/List.lean
optionEraseZ_some_length
/-- Optional erase of an element in a list, with addition for `none`. For `none` adds `a` to the front of the list, for `some i` removes the `i`th element of the list (does not add `a`). E.g. `optionEraseZ [0, 1, 2] 4 none = [4, 0, 1, 2]` and `optionEraseZ [0, 1, 2] 4 (some 1) = [0, 2]`. -/
optionEraseZ_ext {I : Type} {l l' : List I} {a a' : I} {i : Option (Fin l.length)} {i' : Option (Fin l'.length)} (hl : l = l') (ha : a = a') (hi : Option.map (Fin.cast (by rw [hl])) i = i') : optionEraseZ l a i = optionEraseZ l' a' i' := by subst hl subst ha cases hi congr simp
lemma
PhysLean
[ "import PhysLean.Mathematics.Fin", "import Mathlib.Data.Nat.Lattice" ]
PhysLean/Mathematics/List.lean
optionEraseZ_ext
null
mem_take_finrange : (n m : ℕ) → (a : Fin n) → a ∈ List.take m (List.finRange n) ↔ a.val < m | 0, m, a => Fin.elim0 a | n+1, 0, a => by simp | n +1, m + 1, ⟨0, h⟩ => by simp [List.finRange_succ] | n +1, m + 1, ⟨i + 1, h⟩ => by simp only [List.finRange_succ, List.take_succ_cons, List.mem_cons, Fin.ext_iff, Fin.val_zero, ...
lemma
PhysLean
[ "import PhysLean.Mathematics.Fin", "import Mathlib.Data.Nat.Lattice" ]
PhysLean/Mathematics/List.lean
mem_take_finrange
null
induction_tmul {f g : ((⨂[R] i : ι1, s1 i) ⊗[R] (⨂[R] i : ι2, s2 i)) →ₗ[R] M} (h : ∀ p q, f (PiTensorProduct.tprod R p ⊗ₜ[R] PiTensorProduct.tprod R q) = g (PiTensorProduct.tprod R p ⊗ₜ[R] PiTensorProduct.tprod R q)) : f = g := by ext exact h _ _
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
induction_tmul
null
induction_assoc {f g : ((⨂[R] i : ι1, s1 i) ⊗[R] (⨂[R] i : ι2, s2 i) ⊗[R] (⨂[R] i : ι3, s3 i)) →ₗ[R] M} (h : ∀ p q m, f (PiTensorProduct.tprod R p ⊗ₜ[R] PiTensorProduct.tprod R q ⊗ₜ[R] PiTensorProduct.tprod R m) = g (PiTensorProduct.tprod R p ⊗ₜ[R] PiTensorProduct.tprod R q ⊗ₜ[R] PiTensorProduct.tprod R m)) : f = g := ...
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
induction_assoc
null
induction_assoc' {f g : (((⨂[R] i : ι1, s1 i) ⊗[R] (⨂[R] i : ι2, s2 i)) ⊗[R] (⨂[R] i : ι3, s3 i)) →ₗ[R] M} (h : ∀ p q m, f ((PiTensorProduct.tprod R p ⊗ₜ[R] PiTensorProduct.tprod R q) ⊗ₜ[R] PiTensorProduct.tprod R m) = g ((PiTensorProduct.tprod R p ⊗ₜ[R] PiTensorProduct.tprod R q) ⊗ₜ[R] PiTensorProduct.tprod R m)) : f ...
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
induction_assoc'
null
induction_tmul_mod {f g : ((⨂[R] i : ι1, s1 i) ⊗[R] N) →ₗ[R] M} (h : ∀ p m, f (PiTensorProduct.tprod R p ⊗ₜ[R] m) = g (PiTensorProduct.tprod R p ⊗ₜ[R] m)) : f = g := by ext exact h _ _
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
induction_tmul_mod
null
induction_mod_tmul {f g : (N ⊗[R] (⨂[R] i : ι1, s1 i)) →ₗ[R] M} (h : ∀ m p, f (m ⊗ₜ[R] PiTensorProduct.tprod R p) = g (m ⊗ₜ[R] PiTensorProduct.tprod R p)) : f = g := by ext exact h _ _ /-! # Dependent type version of PiTensorProduct.tmulEquiv -/ /-- Given two maps `s1` and `s2` whose targets carry an instance of an add...
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
induction_mod_tmul
null
pureInl (f : (i : ι1 ⊕ ι2) → Sum.elim s1 s2 i) : (i : ι1) → s1 i := fun i => f (Sum.inl i) /-- Takes a map `(i : ι1 ⊕ ι2) → Sum.elim s1 s2 i` to the underlying map `(i : ι2) → s2 i `. -/
def
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
pureInl
/-- Takes a map `(i : ι1 ⊕ ι2) → Sum.elim s1 s2 i` to the underlying map `(i : ι1) → s1 i `. -/
pureInr (f : (i : ι1 ⊕ ι2) → Sum.elim s1 s2 i) : (i : ι2) → s2 i := fun i => f (Sum.inr i) section variable [DecidableEq (ι1 ⊕ ι2)] omit inst1 inst2
def
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
pureInr
/-- Takes a map `(i : ι1 ⊕ ι2) → Sum.elim s1 s2 i` to the underlying map `(i : ι2) → s2 i `. -/
pureInl_update_left [DecidableEq ι1] (f : (i : ι1 ⊕ ι2) → Sum.elim s1 s2 i) (x : ι1) (v1 : s1 x) : pureInl (Function.update f (Sum.inl x) v1) = Function.update (pureInl f) x v1 := by funext y simp only [pureInl, Function.update, Sum.inl.injEq, Sum.elim_inl] split · rename_i h subst h rfl · rfl
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
pureInl_update_left
/-- Takes a map `(i : ι1 ⊕ ι2) → Sum.elim s1 s2 i` to the underlying map `(i : ι2) → s2 i `. -/
pureInr_update_left (f : (i : ι1 ⊕ ι2) → Sum.elim s1 s2 i) (x : ι1) (v2 : s1 x) : pureInr (Function.update f (Sum.inl x) v2) = (pureInr f) := by funext y simp [pureInr, Function.update]
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
pureInr_update_left
null
pureInr_update_right [DecidableEq ι2] (f : (i : ι1 ⊕ ι2) → Sum.elim s1 s2 i) (x : ι2) (v2 : s2 x) : pureInr (Function.update f (Sum.inr x) v2) = Function.update (pureInr f) x v2 := by funext y simp only [pureInr, Function.update, Sum.inr.injEq, Sum.elim_inr] split · rename_i h subst h rfl · rfl
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
pureInr_update_right
null
pureInl_update_right (f : (i : ι1 ⊕ ι2) → Sum.elim s1 s2 i) (x : ι2) (v1 : s2 x) : pureInl (Function.update f (Sum.inr x) v1) = (pureInl f) := by funext y simp [pureInl, Function.update]
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
pureInl_update_right
null
domCoprod : MultilinearMap R (Sum.elim s1 s2) ((⨂[R] i : ι1, s1 i) ⊗[R] (⨂[R] i : ι2, s2 i)) where toFun f := (PiTensorProduct.tprod R (pureInl f)) ⊗ₜ (PiTensorProduct.tprod R (pureInr f)) map_update_add' f xy v1 v2 := by haveI : DecidableEq (ι1 ⊕ ι2) := inferInstance haveI : DecidableEq ι1 := @Function.Injective.decid...
def
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
domCoprod
/-- The multilinear map from `(Sum.elim s1 s2)` to `((⨂[R] i : ι1, s1 i) ⊗[R] ⨂[R] i : ι2, s2 i)` defined by splitting elements of `(Sum.elim s1 s2)` into two parts. -/
tmulSymm : (⨂[R] i : ι1 ⊕ ι2, (Sum.elim s1 s2) i) →ₗ[R] ((⨂[R] i : ι1, s1 i) ⊗[R] (⨂[R] i : ι2, s2 i)) := PiTensorProduct.lift domCoprod /-- Produces a map `(i : ι1 ⊕ ι2) → Sum.elim s1 s2 i` from a map `(i : ι1) → s1 i` and a map `q : (i : ι2) → s2 i`. -/
def
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
tmulSymm
/-- Expand `PiTensorProduct` on sums into a `TensorProduct` of two factors. -/
elimPureTensor (p : (i : ι1) → s1 i) (q : (i : ι2) → s2 i) : (i : ι1 ⊕ ι2) → Sum.elim s1 s2 i := fun x => match x with | Sum.inl x => p x | Sum.inr x => q x section variable [DecidableEq ι1] [DecidableEq ι2] omit inst1 inst2
def
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
elimPureTensor
/-- Produces a map `(i : ι1 ⊕ ι2) → Sum.elim s1 s2 i` from a map `(i : ι1) → s1 i` and a map `q : (i : ι2) → s2 i`. -/
elimPureTensor_update_right (p : (i : ι1) → s1 i) (q : (i : ι2) → s2 i) (y : ι2) (r : s2 y) : elimPureTensor p (Function.update q y r) = Function.update (elimPureTensor p q) (Sum.inr y) r := by funext x match x with | Sum.inl x => rfl | Sum.inr x => change Function.update q y r x = _ simp only [Function.update, Sum.inr...
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
elimPureTensor_update_right
/-- Produces a map `(i : ι1 ⊕ ι2) → Sum.elim s1 s2 i` from a map `(i : ι1) → s1 i` and a map `q : (i : ι2) → s2 i`. -/
elimPureTensor_update_left (p : (i : ι1) → s1 i) (q : (i : ι2) → s2 i) (x : ι1) (r : s1 x) : elimPureTensor (Function.update p x r) q = Function.update (elimPureTensor p q) (Sum.inl x) r := by funext y match y with | Sum.inl y => change (Function.update p x r) y = _ simp only [Function.update, Sum.inl.injEq, Sum.elim_i...
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
elimPureTensor_update_left
null
elimPureTensorMulLin : MultilinearMap R s1 (MultilinearMap R s2 (⨂[R] i : ι1 ⊕ ι2, (Sum.elim s1 s2) i)) where toFun p := { toFun := fun q => PiTensorProduct.tprod R (elimPureTensor p q) map_update_add' := fun m x v1 v2 => by haveI : DecidableEq ι2 := inferInstance haveI := Classical.decEq ι1 simp only [elimPureTensor_u...
def
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
elimPureTensorMulLin
/-- The multilinear map valued in multilinear maps defined by combining `(i : ι1) → s1 i` and `q : (i : ι2) → s2 i` into a PiTensorProduct. -/
tmul : ((⨂[R] i : ι1, s1 i) ⊗[R] (⨂[R] i : ι2, s2 i)) →ₗ[R] ⨂[R] i : ι1 ⊕ ι2, (Sum.elim s1 s2) i := TensorProduct.lift { toFun := fun a ↦ PiTensorProduct.lift <| PiTensorProduct.lift elimPureTensorMulLin a, map_add' := fun a b ↦ by simp map_smul' := fun r a ↦ by simp} /-- The equivalence formed by combining a `TensorPr...
def
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
tmul
/-- Collapse a `TensorProduct` of `PiTensorProduct` into a `PiTensorProduct`. -/
tmulEquiv : ((⨂[R] i : ι1, s1 i) ⊗[R] (⨂[R] i : ι2, s2 i)) ≃ₗ[R] ⨂[R] i : ι1 ⊕ ι2, (Sum.elim s1 s2) i := LinearEquiv.ofLinear tmul tmulSymm (by apply PiTensorProduct.ext apply MultilinearMap.ext intro p simp only [tmul, tmulSymm, domCoprod, LinearMap.compMultilinearMap_apply, LinearMap.coe_comp, Function.comp_apply, Pi...
def
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
tmulEquiv
/-- The equivalence formed by combining a `TensorProduct` into a `PiTensorProduct`. -/
tmulEquiv_tmul_tprod (p : (i : ι1) → s1 i) (q : (i : ι2) → s2 i) : tmulEquiv ((PiTensorProduct.tprod R) p ⊗ₜ[R] (PiTensorProduct.tprod R) q) = (PiTensorProduct.tprod R) (elimPureTensor p q) := by simp only [tmulEquiv, tmul, elimPureTensorMulLin, LinearEquiv.ofLinear_apply, lift.tmul, LinearMap.coe_mk, AddHom.coe_mk, Pi...
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.PiTensorProduct" ]
PhysLean/Mathematics/PiTensorProduct.lean
tmulEquiv_tmul_tprod
null
RatComplexNum where /-- The real part of a `RatComplexNum`. -/ fst : ℚ /-- The imaginary part of a `RatComplexNum`. -/ snd : ℚ namespace RatComplexNum @[ext]
structure
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
RatComplexNum
/-- Rational complex numbers. This type is mainly used when decidability is needed. -/
ext {x y : RatComplexNum} (h1 : x.1 = y.1) (h2 : x.2 = y.2) : x = y := by cases x cases y simp only at h1 h2 subst h1 h2 rfl /-- The equivalence as a type of `RatComplexNum` with `ℚ × ℚ`. -/
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
ext
/-- The imaginary part of a `RatComplexNum`. -/
equivToProd : RatComplexNum ≃ ℚ × ℚ where toFun := fun x => (x.1, x.2) invFun := fun x => ⟨x.1, x.2⟩ left_inv := by intro x cases x rfl right_inv := by intro x cases x rfl
def
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
equivToProd
/-- The equivalence as a type of `RatComplexNum` with `ℚ × ℚ`. -/
add_fst (x y : RatComplexNum) : (x + y).fst = x.fst + y.fst := rfl @[simp]
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
add_fst
/-- The equivalence as a type of `RatComplexNum` with `ℚ × ℚ`. -/
add_snd (x y : RatComplexNum) : (x + y).snd = x.snd + y.snd := rfl
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
add_snd
null
mul_fst (x y : RatComplexNum) : (x * y).fst = x.fst * y.fst - x.snd * y.snd := rfl @[simp]
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
mul_fst
null
mul_snd (x y : RatComplexNum) : (x * y).snd = x.fst * y.snd + x.snd * y.fst := rfl
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
mul_snd
null
one_fst : (1 : RatComplexNum).fst = 1 := rfl @[simp]
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
one_fst
null
one_snd : (1 : RatComplexNum).snd = 0 := rfl @[simp]
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
one_snd
null
zero_fst : (0 : RatComplexNum).fst = 0 := rfl @[simp]
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
zero_fst
null
zero_snd : (0 : RatComplexNum).snd = 0 := rfl open Complex /-- The inclusion of `RatComplexNum` into the complex numbers. -/
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
zero_snd
null
toComplexNum : RatComplexNum →+* ℂ where toFun := fun x => x.fst + x.snd * I map_one' := by simp map_add' a b := by simp only [add_fst, Rat.cast_add, add_snd] ring map_mul' a b := by simp only [mul_fst, Rat.cast_sub, Rat.cast_mul, mul_snd, Rat.cast_add] ring_nf simp only [I_sq, mul_neg, mul_one] ring map_zero' := by si...
def
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
toComplexNum
/-- The inclusion of `RatComplexNum` into the complex numbers. -/
I_mul_toComplexNum (a : RatComplexNum) : I * toComplexNum a = toComplexNum (⟨0, 1⟩ * a) := by simp only [toComplexNum, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, mul_fst, zero_mul, one_mul, zero_sub, Rat.cast_neg, mul_snd, zero_add] ring_nf simp only [I_sq, neg_mul, one_mul] ring
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
I_mul_toComplexNum
/-- The inclusion of `RatComplexNum` into the complex numbers. -/
ofNat_mul_toComplexNum (n : ℕ) (a : RatComplexNum) : n * toComplexNum a = toComplexNum (n * a) := by simp only [map_mul, map_natCast]
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
ofNat_mul_toComplexNum
null
toComplexNum_injective : Function.Injective toComplexNum := by intro a b ha simp only [toComplexNum, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk] at ha rw [Complex.ext_iff] at ha simp only [add_re, ratCast_re, mul_re, I_re, mul_zero, ratCast_im, I_im, mul_one, sub_self, add_zero, Rat.cast_inj, add_im, mul_im, zero_...
lemma
PhysLean
[ "import Mathlib.Analysis.Complex.Basic" ]
PhysLean/Mathematics/RatComplexNum.lean
toComplexNum_injective
null
Fin.subNat' (i : Fin (m + n)) (h : ¬ i < m) : Fin n := subNat m (Fin.cast (m.add_comm n) i) (Nat.ge_of_not_lt h) namespace Equiv /-- An alternative form of `Equiv.sumEquivSigmaBool` where `Bool.casesOn` is replaced by `cond`. -/
def
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
Fin.subNat'
/-- `subNat' i h` subtracts `m` from `i`. This is an alternative form of `Fin.subNat`. -/
sumEquivSigmalCond : Fin m ⊕ Fin n ≃ Σ b, cond b (Fin m) (Fin n) := calc Fin m ⊕ Fin n _ ≃ Fin n ⊕ Fin m := sumComm .. _ ≃ Σ b, bif b then (Fin m) else (Fin n) := sumEquivSigmaBool .. _ ≃ Σ b, cond b (Fin m) (Fin n) := sigmaCongrRight (fun | true | false => Equiv.refl _) /-- The composition of `finSumFinEquiv` and `Equ...
def
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
sumEquivSigmalCond
/-- An alternative form of `Equiv.sumEquivSigmaBool` where `Bool.casesOn` is replaced by `cond`. -/
finAddEquivSigmaCond : Fin (m + n) ≃ Σ b, cond b (Fin m) (Fin n) := finSumFinEquiv.symm.trans sumEquivSigmalCond variable {i : Fin (m + n)}
def
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
finAddEquivSigmaCond
/-- The composition of `finSumFinEquiv` and `Equiv.sumEquivSigmalCond` used by `LinearMap.SchurTriangulationAux.of`. -/
finAddEquivSigmaCond_true (h : i < m) : finAddEquivSigmaCond i = ⟨true, i, h⟩ := congrArg sumEquivSigmalCond <| finSumFinEquiv_symm_apply_castAdd ⟨i, h⟩
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
finAddEquivSigmaCond_true
/-- The composition of `finSumFinEquiv` and `Equiv.sumEquivSigmalCond` used by `LinearMap.SchurTriangulationAux.of`. -/
finAddEquivSigmaCond_false (h : ¬ i < m) : finAddEquivSigmaCond i = ⟨false, i.subNat' h⟩ := let j : Fin n := i.subNat' h calc finAddEquivSigmaCond i _ = finAddEquivSigmaCond (Fin.natAdd m j) := suffices m + (i - m) = i from congrArg _ (Fin.ext this.symm) Nat.add_sub_of_le (Nat.le_of_not_gt h) _ = ⟨false, i.subNat' h⟩ :...
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
finAddEquivSigmaCond_false
/-- The composition of `finSumFinEquiv` and `Equiv.sumEquivSigmalCond` used by `LinearMap.SchurTriangulationAux.of`. -/
IsUpperTriangular [LT n] [CommRing R] (A : Matrix n n R) := A.BlockTriangular id /-- The subtype of upper triangular matrices. -/
abbrev
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
IsUpperTriangular
/-- The property of a matrix being upper triangular. See also `Matrix.det_of_upperTriangular`. -/
UpperTriangular (n R) [LT n] [CommRing R] := { A : Matrix n n R // A.IsUpperTriangular }
abbrev
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
UpperTriangular
/-- The subtype of upper triangular matrices. -/
SchurTriangulationAux (f : Module.End 𝕜 E) where /-- The dimension of the inner product space `E`. -/ dim : ℕ hdim : Module.finrank 𝕜 E = dim /-- An orthonormal basis of `E` that induces an upper triangular form for `f`. -/ basis : OrthonormalBasis (Fin dim) 𝕜 E upperTriangular : (toMatrix basis.toBasis basis.toBasi...
structure
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
SchurTriangulationAux
/-- **Don't use this definition directly.** Instead, use `Matrix.schurTriangulationBasis`, `Matrix.schurTriangulationUnitary`, and `Matrix.schurTriangulation`. See also `LinearMap.SchurTriangulationAux.of` and `Matrix.schurTriangulationAux`. -/
SchurTriangulationAux.of [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [FiniteDimensional 𝕜 E] (f : Module.End 𝕜 E) : SchurTriangulationAux f := haveI : Decidable (Nontrivial E) := Classical.propDecidable _ if hE : Nontrivial E then let μ : f.Eigenvalues := default let V : Submodule 𝕜 E := f.eigenspace μ let W : S...
def
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
SchurTriangulationAux.of
/-- **Don't use this definition directly.** This is the key algorithm behind `Matrix.schur_triangulation`. -/
schurTriangulationAux : OrthonormalBasis n 𝕜 (EuclideanSpace 𝕜 n) × UpperTriangular n 𝕜 := let f := toEuclideanLin A let ⟨d, hd, b, hut⟩ := LinearMap.SchurTriangulationAux.of f let e : Fin d ≃o n := Fintype.orderIsoFinOfCardEq n (finrank_euclideanSpace.symm.trans hd) let b' := b.reindex e let B := LinearMap.toMatrix...
def
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
schurTriangulationAux
/-- This is `LinearMap.SchurTriangulationAux` adapted for matrices in the Euclidean space. -/
schurTriangulationBasis : OrthonormalBasis n 𝕜 (EuclideanSpace 𝕜 n) := A.schurTriangulationAux.1 /-- The unitary matrix that induces the upper triangular form `A.schurTriangulation` to which a matrix `A` over an algebraically closed field is unitarily similar. -/
def
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
schurTriangulationBasis
/-- The change of basis that induces the upper triangular form `A.schurTriangulation` of a matrix `A` over an algebraically closed field. -/
schurTriangulationUnitary : unitaryGroup n 𝕜 where val := (EuclideanSpace.basisFun n 𝕜).toBasis.toMatrix A.schurTriangulationBasis property := OrthonormalBasis.toMatrix_orthonormalBasis_mem_unitary .. /-- The upper triangular form induced by `A.schurTriangulationUnitary` to which a matrix `A` over an algebraically cl...
def
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
schurTriangulationUnitary
/-- The unitary matrix that induces the upper triangular form `A.schurTriangulation` to which a matrix `A` over an algebraically closed field is unitarily similar. -/
schurTriangulation : UpperTriangular n 𝕜 := A.schurTriangulationAux.2 /-- **Schur triangulation**, **Schur decomposition** for matrices over an algebraically closed field. In particular, a complex matrix can be converted to upper-triangular form by a change of basis. In other words, any complex matrix is unitarily sim...
def
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
schurTriangulation
/-- The upper triangular form induced by `A.schurTriangulationUnitary` to which a matrix `A` over an algebraically closed field is unitarily similar. -/
schur_triangulation : A = A.schurTriangulationUnitary * A.schurTriangulation * star A.schurTriangulationUnitary := let U := A.schurTriangulationUnitary have h : U * A.schurTriangulation.val = A * U := let b := A.schurTriangulationBasis.toBasis let c := (EuclideanSpace.basisFun n 𝕜).toBasis calc c.toMatrix b * LinearMa...
lemma
PhysLean
[ "import Mathlib.LinearAlgebra.Eigenspace.Triangularizable", "import Mathlib.Analysis.InnerProductSpace.Adjoint" ]
PhysLean/Mathematics/SchurTriangulation.lean
schur_triangulation
/-- **Schur triangulation**, **Schur decomposition** for matrices over an algebraically closed field. In particular, a complex matrix can be converted to upper-triangular form by a change of basis. In other words, any complex matrix is unitarily similar to an upper triangular matrix. -/
allFilePaths.go (prev : Array FilePath) (root : String) (path : FilePath) : IO (Array FilePath) := do let entries ← path.readDir let result ← entries.foldlM (init := prev) fun acc entry => do if ← entry.path.isDir then go acc (root ++ "/" ++ entry.fileName) entry.path else pure (acc.push (root ++ "/" ++ entry.fileName)...
def
PhysLean
[ "import PhysLean.Meta.TODO.Basic" ]
PhysLean/Meta/AllFilePaths.lean
allFilePaths.go
/-- The recursive function underlying `allFilePaths`. -/
allFilePaths : IO (Array FilePath) := do allFilePaths.go (#[] : Array FilePath) "./PhysLean" ("./PhysLean" : FilePath) /-- Gets an array of all module names in `PhysLean`. -/
def
PhysLean
[ "import PhysLean.Meta.TODO.Basic" ]
PhysLean/Meta/AllFilePaths.lean
allFilePaths
/-- Gets an array of all file paths in `PhysLean`. -/
allPhysLeanModules : IO (Array Lean.Name) := do let paths ← allFilePaths let moduleNames := paths.map fun path => let relativePath := path.toString.replace "./PhysLean/" "PhysLean." let noExt := relativePath.replace ".lean" "" let nameStr := noExt.replace "/" "." String.toName nameStr pure moduleNames
def
PhysLean
[ "import PhysLean.Meta.TODO.Basic" ]
PhysLean/Meta/AllFilePaths.lean
allPhysLeanModules
/-- Gets an array of all module names in `PhysLean`. -/
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
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
Array.flatSize
/-- The size of a flattened array of arrays. -/
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 /-! ## Imports -/ /-- Gets all imports within PhysLean. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
Array.flatFilterSizeM
/-- The size of a flattened array of arrays after applying an element-wise filter. -/
PhysLean.allImports : IO (Array Import) := do initSearchPath (← findSysroot) let mods := `PhysLean 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 hepLeanMod.imports.filterM fun c => return...
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
PhysLean.allImports
/-- Gets all imports within PhysLean. -/
PhysLean.noImports : IO Nat := do let imports ← allImports return imports.size /-- Gets all constants from an import. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
PhysLean.noImports
/-- Number of files within PhysLean. -/
PhysLean.Imports.getConsts (imp : Import) : IO (Array ConstantInfo) := do let mFile ← findOLean imp.module let (modData, _) ← readModuleData mFile return modData.constants /-- Gets all user defined constants from an import. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
PhysLean.Imports.getConsts
/-- Gets all constants from an import. -/
PhysLean.Imports.getUserConsts (imp : Import) : CoreM (Array ConstantInfo) := do let env ← getEnv 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 && ...
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
PhysLean.Imports.getUserConsts
/-- Gets all user defined constants from an import. -/
Lean.Name.toFilePath (c : Name) : System.FilePath := System.mkFilePath (c.toString.splitOn ".") |>.addExtension "lean" /-- Lines from import. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
Lean.Name.toFilePath
/-- Turns a name into a system file path. -/
PhysLean.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
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
PhysLean.Imports.getLines
/-- Lines from import. -/
toRelativeFilePath (c : Name) : System.FilePath := System.FilePath.join "." c.toFilePath /-- Turns a name, which represents a module, into a link to github. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
toRelativeFilePath
/-- Turns a name into a Lean file. -/
toGitHubLink (c : Name) (line : Nat) : String := s!"https://github.com/HEPLean/PhysLean/blob/master/{c.toFilePath}#L{line}" /-- Given a name, returns the line number. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
toGitHubLink
/-- Turns a name, which represents a module, into a link to github. -/
lineNumber (c : Name) : m Nat := do match ← findDeclarationRanges? c with | 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
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
lineNumber
/-- Given a name, returns the line number. -/
fileName (c : Name) : m Name := do let env ← getEnv 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
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
fileName
/-- Given a name, returns the file name corresponding to that declaration. -/
location (c : Name) : m String := do let env ← getEnv 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
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
location
/-- Returns the location of a name. -/
hasPos (c : Name) : m Bool := do let ranges? ← findDeclarationRanges? c return ranges?.isSome /-- Determines if a name has a doc string. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
hasPos
/-- Determines if a name has a location. -/
hasDocString (c : Name) : CoreM Bool := do let env ← getEnv let doc? ← findDocString? env c return doc?.isSome /-- The doc string from a name. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
hasDocString
/-- Determines if a name has a doc string. -/
getDocString (c : Name) : CoreM String := do let env ← getEnv let doc? ← findDocString? env c return doc?.getD "" /-- Given a name, returns the source code defining that name, including doc strings. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
getDocString
/-- The doc string from a name. -/
getDeclString (name : Name) : CoreM String := do let env ← getEnv match ← findDeclarationRanges? name with | some { range := { pos, endPos, .. }, .. } => match env.getModuleFor? name with | some fileName => let fileContent ← IO.FS.readFile fileName.toRelativeFilePath let fileMap := fileContent.toFileMap return (String....
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
getDeclString
/-- Given a name, returns the source code defining that name, including doc strings. -/
getDeclStringNoDoc (name : Name) : CoreM String := do let declarationString ← getDeclString name let headerLine (line : String) : Bool := line.startsWith "def " ∨ line.startsWith "lemma " ∨ line.startsWith "inductive " ∨ line.startsWith "structure " ∨ line.startsWith "theorem " ∨ line.startsWith "instance " ∨ line.star...
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
getDeclStringNoDoc
/-- Given a name, returns the source code defining that name, starting with the def ... or lemma... etc. -/
noDefs : CoreM Nat := do let imports ← PhysLean.allImports let x ← imports.mapM PhysLean.Imports.getUserConsts x.flatFilterSizeM fun c => return c.isDef && (← c.name.hasPos) /-- Number of definitions. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
noDefs
/-- Number of definitions. -/
noLemmas : CoreM Nat := do let imports ← PhysLean.allImports let x ← imports.mapM PhysLean.Imports.getUserConsts x.flatFilterSizeM fun c => return !c.isDef && (← c.name.hasPos) /-- All docstrings present in PhysLean. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
noLemmas
/-- Number of definitions. -/
allDocStrings : CoreM (Array String) := do let imports ← PhysLean.allImports let x ← imports.mapM PhysLean.Imports.getUserConsts let x' := x.flatten let docString ← x'.mapM fun c => Lean.Name.getDocString c.name return docString /-- Number of definitions without a doc-string. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
allDocStrings
/-- All docstrings present in PhysLean. -/
noDefsNoDocString : CoreM Nat := do let imports ← PhysLean.allImports let x ← imports.mapM PhysLean.Imports.getUserConsts x.flatFilterSizeM fun c => return c.isDef && (← c.name.hasPos) && !(← c.name.hasDocString) /-- Number of definitions without a doc-string. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
noDefsNoDocString
/-- Number of definitions without a doc-string. -/
noLemmasNoDocString : CoreM Nat := do let imports ← PhysLean.allImports let x ← imports.mapM PhysLean.Imports.getUserConsts x.flatFilterSizeM fun c => return !c.isDef && (← c.name.hasPos) && !(← c.name.hasDocString) /-- The number of lines in PhysLean. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
noLemmasNoDocString
/-- Number of definitions without a doc-string. -/
noLines : IO Nat := do let imports ← PhysLean.allImports let x ← imports.mapM PhysLean.Imports.getLines return x.flatSize /-- The number of TODO items. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
noLines
/-- The number of lines in PhysLean. -/
noTODOs : IO Nat := do let imports ← PhysLean.allImports let x ← imports.mapM PhysLean.Imports.getLines x.flatFilterSizeM fun l => return l.startsWith "TODO " /-- The number of files with a TODO item. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
noTODOs
/-- The number of TODO items. -/
noFilesWithTODOs : IO Nat := do let imports ← PhysLean.allImports let x ← imports.mapM PhysLean.Imports.getLines let x := x.filter fun bs => bs.any fun l => l.startsWith "TODO " return x.size /-- All user defined declarations. -/
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
noFilesWithTODOs
/-- The number of files with a TODO item. -/
allUserConsts : CoreM (Array ConstantInfo) := do let imports ← PhysLean.allImports return (← imports.flatMapM PhysLean.Imports.getUserConsts)
def
PhysLean
[ "import Mathlib.Lean.Expr.Basic", "import Lean.Elab.PreDefinition.Structural.BRecOn", "import ImportGraph.RequiredModules" ]
PhysLean/Meta/Basic.lean
allUserConsts
/-- All user defined declarations. -/
State where /-- The names which have already been visited as part of the state. -/ visited : NameSet := {} /-- The names which depend on the `sorryAx` axiom. -/ containsSorry : NameSet := {} /-- The names which depend on the `Lean.ofReduceBool` axiom. -/ containsOfReduceBool : NameSet := {} /-! ### A.2. The monad for c...
structure
PhysLean
[ "import PhysLean.Meta.Linters.Sorry" ]
PhysLean/Meta/Sorry.lean
State
/-- A structure used for collecting names of results dependent on the `sorryAx` axiom and the `Lean.ofReduceBool` axiom. -/
M := ReaderT Environment $ StateM State /-! ### A.3. The collection function -/ /-- Given a `c : Name` updating the monad `M` based on which results which `c` uses depend on the `sorryAx` axiom and the `Lean.ofReduceBool` axiom. -/
abbrev
PhysLean
[ "import PhysLean.Meta.Linters.Sorry" ]
PhysLean/Meta/Sorry.lean
M
/-- A monad used for collecting names of results dependent on the `sorryAx` axiom and the `Lean.ofReduceBool` axiom. -/
collect (c : Name) (parents : NameSet) : M Unit := do let collectExpr (e : Expr) : M Unit := e.getUsedConstants.forM fun x => collect x (parents.insert c) let s ← get if s.containsSorry.contains c then modify fun s => { s with containsSorry := s.containsSorry.append parents} if s.containsOfReduceBool.contains c then mo...
def
PhysLean
[ "import PhysLean.Meta.Linters.Sorry" ]
PhysLean/Meta/Sorry.lean
collect
/-- Given a `c : Name` updating the monad `M` based on which results which `c` uses depend on the `sorryAx` axiom and the `Lean.ofReduceBool` axiom. -/
allSorryPseudo (c : Array Name) : M Unit := do c.forM fun x => collect x {}
def
PhysLean
[ "import PhysLean.Meta.Linters.Sorry" ]
PhysLean/Meta/Sorry.lean
allSorryPseudo
/-- Given a `c : Array Name` updating the monad `M` based on which results depend on the `sorryAx` axiom and the `Lean.ofReduceBool` axiom. -/
collectSorryPseudo (c : Array Name) : CoreM (Array Name × Array Name) := do let env ← getEnv let (_, s) := ((CollectSorry.allSorryPseudo c).run env).run {} pure (s.containsSorry.toArray, s.containsOfReduceBool.toArray) /-! ### A.6. Getting all names depending on axioms from all user defined constants -/ /-- The axioms ...
def
PhysLean
[ "import PhysLean.Meta.Linters.Sorry" ]
PhysLean/Meta/Sorry.lean
collectSorryPseudo
/-- Given a `c : Array Name` the names of all results used to defined the results in `c` with the `sorryAx` axiom and the `Lean.ofReduceBool` axiom. -/
allWithSorryPseudo : CoreM (Array Name × Array Name) := do let x ← collectSorryPseudo ((← allUserConsts).map fun c => c.name) return x /-! ## B. Collecting all names attributed `sorryful` and `pseudo` -/ /-- All names which are attributed `sorryful`. -/
def
PhysLean
[ "import PhysLean.Meta.Linters.Sorry" ]
PhysLean/Meta/Sorry.lean
allWithSorryPseudo
/-- The axioms of a constant. -/
allSorryfulAttributed : CoreM (Array Name) := do let env ← getEnv let sorryfulInfos := (sorryfulExtension.getState env) return sorryfulInfos.map fun info => info.name /-- All names which are attributed `pseudo`. -/
def
PhysLean
[ "import PhysLean.Meta.Linters.Sorry" ]
PhysLean/Meta/Sorry.lean
allSorryfulAttributed
/-- All names which are attributed `sorryful`. -/
allPseudoAttributed : CoreM (Array Name) := do let env ← getEnv let pseudoInfos := (pseudoExtension.getState env) return pseudoInfos.map fun info => info.name /-! ## C. Testing the `sorryful` and `pseudo` attributions are correctly applied -/ /-- Checks whether all results attributed `sorryful` depend on the ```sorryAx...
def
PhysLean
[ "import PhysLean.Meta.Linters.Sorry" ]
PhysLean/Meta/Sorry.lean
allPseudoAttributed
/-- All names which are attributed `pseudo`. -/
sorryfulPseudoTest : MetaM Unit := do let (allWithSorry, allWithPseudo) ← PhysLean.allWithSorryPseudo let allConst ← PhysLean.allUserConsts let allConst := allConst.map fun c => c.name let allWithSorry := allWithSorry.filter fun n => n ∈ allConst let allWithPseudo := allWithPseudo.filter fun n => n ∈ allConst let sorry...
def
PhysLean
[ "import PhysLean.Meta.Linters.Sorry" ]
PhysLean/Meta/Sorry.lean
sorryfulPseudoTest
/-- Checks whether all results attributed `sorryful` depend on the ```sorryAx` axiom and vice versa. -/
processCommands : Frontend.FrontendM (List (Environment × InfoState)) := do /- Very roughly, `Frontend.FrontendM (List (Environment × InfoState))` is equivalent to `Frontend.Context → Frontend.state → List (Environment × InfoState)`. The `←get` here is returning the inputted value of `Frontend.state`, from which we get...
def
PhysLean
[ "import Lean", "import PhysLean.Meta.TODO.Basic" ]
PhysLean/Meta/TransverseTactics.lean
processCommands
/-- Takes in a file and returns the infostates of commands and the corresponding environment before the command is processed. -/
visitInfo (file : FilePath) (env : Environment) (visitTacticInfo : FilePath → ContextInfo → TacticInfo → MetaM Unit) (ci : ContextInfo) (info : Info) (acc : List (IO Unit)) : List (IO Unit) := match info with | .ofTacticInfo ti => (ci.runMetaM default (do setEnv env try visitTacticInfo file ci ti catch e => println! "c...
def
PhysLean
[ "import Lean", "import PhysLean.Meta.TODO.Basic" ]
PhysLean/Meta/TransverseTactics.lean
visitInfo
/-- Tests if a given `info` is `ofTacticInfo` and if so runs `visitTacticInfo`. -/
traverseForest (file : FilePath) (visitTacticInfo : FilePath → ContextInfo → TacticInfo → MetaM Unit) (steps : List (Environment × InfoState)) : List (IO Unit) := let t := steps.map fun (env, infoState) ↦ (infoState.trees.toList.map fun t ↦ (Lean.Elab.InfoTree.foldInfo (visitInfo file env visitTacticInfo) [] t).reverse...
def
PhysLean
[ "import Lean", "import PhysLean.Meta.TODO.Basic" ]
PhysLean/Meta/TransverseTactics.lean
traverseForest
/-- Applies `visitInfo` to each node of the info trees. -/
transverseTactics (file : FilePath) (visitTacticInfo : FilePath → ContextInfo → TacticInfo → MetaM Unit) : IO Unit := do initSearchPath (← findSysroot) /- This is equivalent to `(IO.FS.readFile file).bind (fun fileContent => do ...)`. -/ let fileContent ← IO.FS.readFile file enableInitializersExecution /- Get `Parser.I...
def
PhysLean
[ "import Lean", "import PhysLean.Meta.TODO.Basic" ]
PhysLean/Meta/TransverseTactics.lean
transverseTactics
/-- Applies `visitTacticInfo` to each tactic in a file. -/
ℏ : Subtype fun x : ℝ => 0 < x := ⟨1.054571817e-34, by norm_num⟩ /-- Planck's constant is positive. -/
def
PhysLean
[ "import Mathlib.Data.NNReal.Defs" ]
PhysLean/QuantumMechanics/PlanckConstant.lean
/-- The value of the reduced Planck's constant in units of J.s. -/
ℏ_pos : 0 < (ℏ : ℝ) := ℏ.2 /-- Planck's constant is non-negative. -/
lemma
PhysLean
[ "import Mathlib.Data.NNReal.Defs" ]
PhysLean/QuantumMechanics/PlanckConstant.lean
ℏ_pos
/-- Planck's constant is positive. -/
ℏ_nonneg : 0 ≤ (ℏ : ℝ) := le_of_lt ℏ.2 /-- Planck's constant is not equal to zero. -/
lemma
PhysLean
[ "import Mathlib.Data.NNReal.Defs" ]
PhysLean/QuantumMechanics/PlanckConstant.lean
ℏ_nonneg
/-- Planck's constant is non-negative. -/