Eig3x3.Basic — types and the 3×3 vector/matrix vocabulary #
Core types (Vec3, Eigval3, Mat3, SymmMat3, Decomposition), the
public Float arithmetic vocabulary, typeclass instances for arithmetic
notation, and scoped unicode notation.
Usage #
Importing this module activates every typeclass instance (Add, Mul,
HSMul, Inv, …), so arithmetic on Vec3 and Mat3 works immediately
through Lean's core syntax. The Unicode operator glyphs are opt-in:
open scoped Eig3x3
Notation and Operators #
A Mathlib-consistent operator layer for vector/matrix algebra on Float,
with no Mathlib dependency. Precedences follow Lean core and Mathlib:
| Notation | Operation | Declaration | Convention source |
|---|---|---|---|
a + b | addition | infixl:65 | Lean core (HAdd.hAdd) |
a - b | subtraction | infixl:65 | Lean core (HSub.hSub) |
-a | negation | prefix | Lean core (Neg.neg) |
a * b | multiplication/action | infixl:70 | Lean core (HMul.hMul) |
a / s | scalar division | infixl:70 | Lean core (HDiv.hDiv) |
u ⊗ᵥ v | vector outer product | infixl:70 | (new; subscript family of ⬝ᵥ) |
u ⬝ᵥ v | vector dot product | infixl:72 | Mathlib Matrix.dotProduct |
A ⬝ₘ B | matrix Frobenius dot | infixl:72 | (family extension of ⬝ᵥ) |
s • v | scalar multiplication | infixr:73 | Lean core (HSMul.hSMul) |
u ⨯₃ v | cross product | infixl:74 | Mathlib crossProduct |
x ^ⁿ n | power (by fast Nat) | infixr:80 | (new; family of ^) |
A ⊙ B | Hadamard product | infixl:100 | Mathlib Matrix.hadamard |
|x| | absolute value | delimited | Mathlib |a| for abs |
‖v‖ | norm | delimited | Mathlib Norm.norm |
‖v‖² | squared norm | delimited | (Mathlib writes ‖x‖ ^ 2) |
Aᵀ | transpose | postfix:max | Mathlib Matrix.transpose |
A⁻¹ | inverse | postfix:max | Lean core (Inv.inv) |
Binding strength: + - (65) < * / (70) < ⬝ᵥ ⬝ₘ (72) < • (73) < ⨯₃ (74)
< ^ⁿ (80) < ⊙ (100); the postfixes ᵀ and ⁻¹ (1024) bind tightest.
Useful consequences:
u ⬝ᵥ v ⨯₃ wparses asu ⬝ᵥ (v ⨯₃ w)— the scalar triple product needs no parentheses.s • u ⨯₃ vparses ass • (u ⨯₃ v).u ⬝ᵥ u + v ⬝ᵥ vparses as(u ⬝ᵥ u) + (v ⬝ᵥ v).M⁻¹ᵀparses as(M⁻¹)ᵀ.
Important: ⬝ᵥ (72) binds tighter than * (70), so M * v ⬝ᵥ w parses as
M * (v ⬝ᵥ w) — write (M * v) ⬝ᵥ w instead.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Eig3x3.instReprVec3 = { reprPrec := Eig3x3.instReprVec3.repr }
General 3×3 matrix over Float, stored by columns. The primary matrix
this library produces is the eigenvector matrix Q, whose columns are
eigenvectors, matching conventional mathematics and NumPy/SciPy/PyTorch.
Instances For
Equations
- Eig3x3.instReprMat3 = { reprPrec := Eig3x3.instReprMat3.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Symmetric 3×3 matrix stored as its six independent entries.
Meant to be used as an input parameter type, not for matrix
math. Coerces one-way to Mat3 for matrix operations.
- a₀₀ : Float
Diagonal entry A₀₀.
- a₁₁ : Float
Diagonal entry A₁₁.
- a₂₂ : Float
Diagonal entry A₂₂.
- a₀₁ : Float
Off-diagonal entry A₀₁ = A₁₀.
- a₀₂ : Float
Off-diagonal entry A₀₂ = A₂₀.
- a₁₂ : Float
Off-diagonal entry A₁₂ = A₂₁.
Instances For
Equations
- Eig3x3.instReprSymmMat3 = { reprPrec := Eig3x3.instReprSymmMat3.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Ordered eigenvalues l₀ ≤ l₁ ≤ l₂.
Not meant to be used directly. A distinct return type so eigenvalue
ordering guarantees required by Eberly's algorithm [Ebe14] are carried
by the type. Coerces to Vec3 for vector operations. Coercion is one-way,
and ordering guarantees do not hold after coercion.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Eig3x3.instReprEigval3 = { reprPrec := Eig3x3.instReprEigval3.repr }
Equations
- Eig3x3.instReprDecomposition = { reprPrec := Eig3x3.instReprDecomposition.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Vec3 operations #
Outer product of two vectors, producing the rank-1 matrix u vᵀ.
Exposed as ⊗ᵥ. The columns are u scaled by the entries of v,
matching Mat3's column-major layout.
Instances For
Componentwise absolute value of a vector |v|.
Equations
- v.abs = Eig3x3.Vec3.map Float.abs v
Instances For
One-way coercion: ordered eigenvalues are a vector, but an arbitrary vector is not ordered eigenvalues.
Equations
Mat3 operations #
Row-minded constructor: build from three rows.
Equations
- Eig3x3.Mat3.ofRows r₀ r₁ r₂ = { c₀ := r₀, c₁ := r₁, c₂ := r₂ }.transpose
Instances For
Invert a 3×3 matrix via cofactor cross products: M⁻¹ = (1/det M) adj(M),
with adj(M) computed from cross products of the rows. Totalized like the
rest of the Float vocabulary: a singular M yields inf/NaN entries
rather than an error.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One-way coercion: a symmetric matrix is a matrix, but an arbitrary matrix is not symmetric.
Equations
Fast natural-number powers (^ⁿ) #
Power by repeated multiplication — adequate for the small exponents
(e.g. 2 or 3) that appear in characteristic-polynomial computations,
and computationally cheaper than Lean's C-accelerated pow call.
Equations
- Eig3x3.powNatSmall x 0 = 1.0
- Eig3x3.powNatSmall x n.succ = x * Eig3x3.powNatSmall x n
Instances For
Equations
- Eig3x3.instPowNatMat3 = { powNat := Eig3x3.Mat3.powSq }
Flexible compatibility with core's ^.
Equations
- Eig3x3.instPowMat3Nat = { pow := Eig3x3.Mat3.powSq }
Custom typeclasses behind the delimited/Hadamard notation #
Equations
- Eig3x3.instAbsFloat = { abs := Float.abs }
Equations
- Eig3x3.instAbsVec3 = { abs := Eig3x3.Vec3.abs }
Equations
- Eig3x3.instAbsMat3 = { abs := Eig3x3.Mat3.abs }
Euclidean norm for vectors, Frobenius norm for matrices.
- norm : α → Float
Euclidean (vector) or Frobenius (matrix) norm.
Instances
Equations
- Eig3x3.instNormVec3 = { norm := Eig3x3.Vec3.norm }
Equations
- Eig3x3.instNormMat3 = { norm := Eig3x3.Mat3.norm }
Squared norm: Euclidean for vectors, Frobenius for matrices.
- normSq : α → Float
Squared norm.
Instances
Equations
- Eig3x3.instNormSqVec3 = { normSq := Eig3x3.Vec3.normSq }
Equations
- Eig3x3.instNormSqMat3 = { normSq := Eig3x3.Mat3.normSq }
Hadamard (componentwise) product.
- hadamard : α → α → α
Componentwise (Hadamard) product.
Instances
Equations
- Eig3x3.instHadamardVec3 = { hadamard := Eig3x3.Vec3.hadamard }
Equations
- Eig3x3.instHadamardMat3 = { hadamard := Eig3x3.Mat3.hadamard }
Arithmetic instances (global: these are this package's own types) #
Equations
- Eig3x3.instAddVec3 = { add := Eig3x3.Vec3.add }
Equations
- Eig3x3.instNegVec3 = { neg := Eig3x3.Vec3.neg }
Equations
- Eig3x3.instSubVec3 = { sub := Eig3x3.Vec3.sub }
Equations
- Eig3x3.instHSMulFloatVec3 = { hSMul := fun (s : Float) (v : Eig3x3.Vec3) => v.scale s }
Equations
- Eig3x3.instHDivVec3Float = { hDiv := Eig3x3.Vec3.div }
Equations
- Eig3x3.instAddMat3 = { add := Eig3x3.Mat3.add }
Equations
- Eig3x3.instNegMat3 = { neg := Eig3x3.Mat3.neg }
Equations
- Eig3x3.instSubMat3 = { sub := Eig3x3.Mat3.sub }
Equations
- Eig3x3.instMulMat3 = { mul := Eig3x3.Mat3.mul }
Equations
- Eig3x3.instHMulMat3Vec3 = { hMul := Eig3x3.Mat3.mulVec }
Row-vector times matrix product vᵀ M without materializing the transpose.
Equations
- Eig3x3.instHMulVec3Mat3 = { hMul := fun (v : Eig3x3.Vec3) (M : Eig3x3.Mat3) => M.transposeMulVec v }
Equations
- Eig3x3.instHSMulFloatMat3 = { hSMul := fun (s : Float) (M : Eig3x3.Mat3) => M.scale s }
Equations
- Eig3x3.instHDivMat3Float = { hDiv := Eig3x3.Mat3.div }
Matrix inverse through Lean core's Inv class, so M⁻¹ just works.
Equations
- Eig3x3.instInvMat3 = { inv := Eig3x3.Mat3.inv }
Outer product producing the rank-1 matrix u vᵀ.
Type \otimes then \_v.
Equations
- Eig3x3.«term_⊗ᵥ_» = Lean.ParserDescr.trailingNode `Eig3x3.«term_⊗ᵥ_» 70 70 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⊗ᵥ ") (Lean.ParserDescr.cat `term 71))
Instances For
Vector dot product. Type \cdot then \_v (or \dot\_v).
Equations
- Eig3x3.«term_⬝ᵥ_» = Lean.ParserDescr.trailingNode `Eig3x3.«term_⬝ᵥ_» 72 72 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⬝ᵥ ") (Lean.ParserDescr.cat `term 73))
Instances For
Matrix Frobenius inner product. Type \cdot\_m.
Equations
- Eig3x3.«term_⬝ₘ_» = Lean.ParserDescr.trailingNode `Eig3x3.«term_⬝ₘ_» 72 72 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⬝ₘ ") (Lean.ParserDescr.cat `term 73))
Instances For
Cross product (⨯₃, U+2A2F). Type \crossproduct\_3.
Equations
- Eig3x3.«term_⨯₃_» = Lean.ParserDescr.trailingNode `Eig3x3.«term_⨯₃_» 74 74 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⨯₃ ") (Lean.ParserDescr.cat `term 75))
Instances For
Absolute value bars, whitespace-sensitive: the bars must hug the argument
(|v|, never | v |), so the leading bar will not be mistaken for | in
match, which is always followed by a space.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Fast natural-number exponent operator. Right-associative. Type ^\^n.
Equations
- Eig3x3.«term_^ⁿ_» = Lean.ParserDescr.trailingNode `Eig3x3.«term_^ⁿ_» 80 81 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ^ⁿ ") (Lean.ParserDescr.cat `term 80))
Instances For
Squared norm. Write it tight: ‖v‖², no space before the ².
Equations
- One or more equations did not get rendered due to their size.
Instances For
Hadamard (componentwise) product. Type \odot.
Equations
- Eig3x3.«term_⊙_» = Lean.ParserDescr.trailingNode `Eig3x3.«term_⊙_» 100 100 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⊙ ") (Lean.ParserDescr.cat `term 101))
Instances For
Transpose. Type \^T.
Equations
- Eig3x3.«term_ᵀ» = Lean.ParserDescr.trailingNode `Eig3x3.«term_ᵀ» 1024 1024 (Lean.ParserDescr.symbol "ᵀ")