The areas / V08. Multilinear algebra and forms
Mathlib.Data.Holor
61 declarations. Mathlib docs · Source
Basic properties of holors
Holors are indexed collections of tensor coefficients. Confusingly, they are often called tensors in physics and in the neural network community.
A holor is simply a multidimensional array of values. The size of a
holor is specified by a List ℕ, whose length is called the dimension
of the holor.
The tensor product of x₁ : Holor α ds₁ and x₂ : Holor α ds₂ is the
holor given by (x₁ ⊗ x₂) (i₁ ++ i₂) = x₁ i₁ * x₂ i₂. A holor is "of
rank at most 1" if it is a tensor product of one-dimensional holors.
The CP rank of a holor x is the smallest N such that x is the sum
of N holors of rank at most 1.
Based on the tensor library found in https://www.isa-afp.org/entries/Deep_Learning.html
References
ctor Holor.CPRankMax.below.zero E0 #
∀ {α : Type} [inst : Mul α] [inst_1 : AddMonoid α]
{motive : (a : ℕ) → {ds : List ℕ} → (a_1 : Holor α ds) → Holor.CPRankMax a a_1 → Prop} {ds : List ℕ},
Holor.CPRankMax.below ⋯
ctor Holor.CPRankMax1.below.cons E0 #
∀ {α : Type} [inst : Mul α] {motive : {ds : List ℕ} → (a : Holor α ds) → a.CPRankMax1 → Prop} {d : ℕ} {ds : List ℕ}
(x : Holor α [d]) (y : Holor α ds) (a : y.CPRankMax1),
Holor.CPRankMax1.below a → motive y a → Holor.CPRankMax1.below ⋯
ctor Holor.CPRankMax.below.succ E0 #
∀ {α : Type} [inst : Mul α] [inst_1 : AddMonoid α]
{motive : (a : ℕ) → {ds : List ℕ} → (a_1 : Holor α ds) → Holor.CPRankMax a a_1 → Prop} (n : ℕ) {ds : List ℕ}
(x y : Holor α ds) (a : x.CPRankMax1) (a_1 : Holor.CPRankMax n y),
Holor.CPRankMax.below a_1 → motive n y a_1 → Holor.CPRankMax.below ⋯
theorem Holor.slice.congr_simp E1 #
∀ {α : Type} {d : ℕ} {ds : List ℕ} (x x_1 : Holor α (d :: ds)),
x = x_1 →
∀ (i i_1 : ℕ) (e_i : i = i_1) (h : i < d) (a a_1 : HolorIndex ds), a = a_1 → x.slice i h a = x_1.slice i_1 ⋯ a_1
ctor Holor.CPRankMax1.below.nil E0 #
∀ {α : Type} [inst : Mul α] {motive : {ds : List ℕ} → (a : Holor α ds) → a.CPRankMax1 → Prop} (x : Holor α []),
Holor.CPRankMax1.below ⋯
def HolorIndex E1 #
List ℕ → Type
HolorIndex ds is the type of valid index tuples used to identify an entry of a holor
of dimensions ds.
def HolorIndex.take E1 #
{ds₂ ds₁ : List ℕ} → HolorIndex (ds₁ ++ ds₂) → HolorIndex ds₁
Take the first elements of a HolorIndex.
def HolorIndex.drop E1 #
{ds₂ ds₁ : List ℕ} → HolorIndex (ds₁ ++ ds₂) → HolorIndex ds₂
Drop the first elements of a HolorIndex.
theorem HolorIndex.cast_type E1 #
∀ {ds₁ ds₂ : List ℕ} (is : List ℕ) (eq : ds₁ = ds₂) (h : List.Forall₂ (fun x1 x2 ↦ x1 < x2) is ds₁),
↑(cast ⋯ ⟨is, h⟩) = is
def HolorIndex.assocRight E1 #
{ds₁ ds₂ ds₃ : List ℕ} → HolorIndex (ds₁ ++ ds₂ ++ ds₃) → HolorIndex (ds₁ ++ (ds₂ ++ ds₃))
Right associator for HolorIndex
def HolorIndex.assocLeft E1 #
{ds₁ ds₂ ds₃ : List ℕ} → HolorIndex (ds₁ ++ (ds₂ ++ ds₃)) → HolorIndex (ds₁ ++ ds₂ ++ ds₃)
Left associator for HolorIndex
theorem HolorIndex.take_take E1 #
∀ {ds₁ ds₂ ds₃ : List ℕ} (t : HolorIndex (ds₁ ++ ds₂ ++ ds₃)), t.assocRight.take = t.take.take
theorem HolorIndex.drop_take E1 #
∀ {ds₁ ds₂ ds₃ : List ℕ} (t : HolorIndex (ds₁ ++ ds₂ ++ ds₃)), t.assocRight.drop.take = t.take.drop
theorem HolorIndex.drop_drop E1 #
∀ {ds₁ ds₂ ds₃ : List ℕ} (t : HolorIndex (ds₁ ++ ds₂ ++ ds₃)), t.assocRight.drop.drop = t.drop
def Holor E1 #
Type u → List ℕ → Type u
Holor (indexed collections of tensor coefficients)
instance Holor.instInhabited E0 #
{α : Type} → {ds : List ℕ} → [Inhabited α] → Inhabited (Holor α ds)
instance Holor.instZero E0 #
{α : Type} → {ds : List ℕ} → [Zero α] → Zero (Holor α ds)
instance Holor.instAdd E0 #
{α : Type} → {ds : List ℕ} → [Add α] → Add (Holor α ds)
instance Holor.instNeg E0 #
{α : Type} → {ds : List ℕ} → [Neg α] → Neg (Holor α ds)
instance Holor.instAddSemigroup E0 #
{α : Type} → {ds : List ℕ} → [AddSemigroup α] → AddSemigroup (Holor α ds)
instance Holor.instAddCommSemigroup E0 #
{α : Type} → {ds : List ℕ} → [AddCommSemigroup α] → AddCommSemigroup (Holor α ds)
instance Holor.instAddMonoid E0 #
{α : Type} → {ds : List ℕ} → [AddMonoid α] → AddMonoid (Holor α ds)
instance Holor.instAddCommMonoid E0 #
{α : Type} → {ds : List ℕ} → [AddCommMonoid α] → AddCommMonoid (Holor α ds)
instance Holor.instAddGroup E0 #
{α : Type} → {ds : List ℕ} → [AddGroup α] → AddGroup (Holor α ds)
instance Holor.instAddCommGroup E0 #
{α : Type} → {ds : List ℕ} → [AddCommGroup α] → AddCommGroup (Holor α ds)
instance Holor.instSMulOfMul E0 #
{α : Type} → {ds : List ℕ} → [Mul α] → SMul α (Holor α ds)
instance Holor.instModule E0 #
{α : Type} → {ds : List ℕ} → [inst : Semiring α] → Module α (Holor α ds)
def Holor.mul E1 #
{α : Type} → {ds₁ ds₂ : List ℕ} → [Mul α] → Holor α ds₁ → Holor α ds₂ → Holor α (ds₁ ++ ds₂)
The tensor product of two holors.
theorem Holor.cast_type E1 #
∀ {α : Type} {ds₁ ds₂ : List ℕ} (eq : ds₁ = ds₂) (a : Holor α ds₁), cast ⋯ a = fun t ↦ a (cast ⋯ t)
def Holor.assocRight E1 #
{α : Type} → {ds₁ ds₂ ds₃ : List ℕ} → Holor α (ds₁ ++ ds₂ ++ ds₃) → Holor α (ds₁ ++ (ds₂ ++ ds₃))
Right associator for Holor
def Holor.assocLeft E1 #
{α : Type} → {ds₁ ds₂ ds₃ : List ℕ} → Holor α (ds₁ ++ (ds₂ ++ ds₃)) → Holor α (ds₁ ++ ds₂ ++ ds₃)
Left associator for Holor
theorem Holor.mul_assoc0 E1 #
∀ {α : Type} {ds₁ ds₂ ds₃ : List ℕ} [inst : Semigroup α] (x : Holor α ds₁) (y : Holor α ds₂) (z : Holor α ds₃),
(x.mul y).mul z = (x.mul (y.mul z)).assocLeft
theorem Holor.mul_assoc E1 #
∀ {α : Type} {ds₁ ds₂ ds₃ : List ℕ} [inst : Semigroup α] (x : Holor α ds₁) (y : Holor α ds₂) (z : Holor α ds₃),
(x.mul y).mul z ≍ x.mul (y.mul z)
theorem Holor.mul_left_distrib E1 #
∀ {α : Type} {ds₁ ds₂ : List ℕ} [inst : Distrib α] (x : Holor α ds₁) (y z : Holor α ds₂),
x.mul (y + z) = x.mul y + x.mul z
theorem Holor.mul_right_distrib E1 #
∀ {α : Type} {ds₁ ds₂ : List ℕ} [inst : Distrib α] (x y : Holor α ds₁) (z : Holor α ds₂),
(x + y).mul z = x.mul z + y.mul z
theorem Holor.zero_mul E0 #
∀ {ds₁ ds₂ : List ℕ} {α : Type} [inst : MulZeroClass α] (x : Holor α ds₂), Holor.mul 0 x = 0
theorem Holor.mul_zero E0 #
∀ {ds₁ ds₂ : List ℕ} {α : Type} [inst : MulZeroClass α] (x : Holor α ds₁), x.mul 0 = 0
theorem Holor.mul_scalar_mul E1 #
∀ {α : Type} {ds : List ℕ} [inst : Mul α] (x : Holor α []) (y : Holor α ds), x.mul y = x ⟨[], ⋯⟩ • y
def Holor.slice E1 #
{α : Type} → {d : ℕ} → {ds : List ℕ} → Holor α (d :: ds) → (i : ℕ) → i < d → Holor α ds
A slice is a subholor consisting of all entries with initial index i.
def Holor.unitVec E1 #
{α : Type} → [Monoid α] → [AddMonoid α] → (d : ℕ) → ℕ → Holor α [d]
The 1-dimensional "unit" holor with 1 in the jth position.
theorem Holor.holor_index_cons_decomp E1 #
∀ {d : ℕ} {ds : List ℕ} (p : HolorIndex (d :: ds) → Prop) (t : HolorIndex (d :: ds)),
(∀ (i : ℕ) (is : List ℕ) (h : ↑t = i :: is), p ⟨i :: is, ⋯⟩) → p t
theorem Holor.slice_eq E0 #
∀ {α : Type} {d : ℕ} {ds : List ℕ} (x y : Holor α (d :: ds)), x.slice = y.slice → x = y
Two holors are equal if all their slices are equal.
theorem Holor.slice_unitVec_mul E1 #
∀ {α : Type} {d : ℕ} {ds : List ℕ} [inst : Semiring α] {i j : ℕ} (hid : i < d) (x : Holor α ds),
((Holor.unitVec d j).mul x).slice i hid = if i = j then x else 0
theorem Holor.slice_add E1 #
∀ {α : Type} {d : ℕ} {ds : List ℕ} [inst : Add α] (i : ℕ) (hid : i < d) (x y : Holor α (d :: ds)),
x.slice i hid + y.slice i hid = (x + y).slice i hid
theorem Holor.slice_zero E1 #
∀ {α : Type} {d : ℕ} {ds : List ℕ} [inst : Zero α] (i : ℕ) (hid : i < d), Holor.slice 0 i hid = 0
theorem Holor.slice_sum E1 #
∀ {α : Type} {d : ℕ} {ds : List ℕ} [inst : AddCommMonoid α] {β : Type} (i : ℕ) (hid : i < d) (s : Finset β)
(f : β → Holor α (d :: ds)), ∑ x ∈ s, (f x).slice i hid = (∑ x ∈ s, f x).slice i hid
theorem Holor.sum_unitVec_mul_slice E0 #
∀ {α : Type} {d : ℕ} {ds : List ℕ} [inst : Semiring α] (x : Holor α (d :: ds)),
∑ i ∈ (Finset.range d).attach, (Holor.unitVec d ↑i).mul (x.slice ↑i ⋯) = x
The original holor can be recovered from its slices by multiplying with unit vectors and summing up.
inductive Holor.CPRankMax1 E1 #
{α : Type} → [Mul α] → {ds : List ℕ} → Holor α ds → Prop
CPRankMax1 x means x has CP rank at most 1, that is,
it is the tensor product of 1-dimensional holors.
ctor Holor.CPRankMax1.nil E0 #
∀ {α : Type} [inst : Mul α] (x : Holor α []), x.CPRankMax1
ctor Holor.CPRankMax1.cons E0 #
∀ {α : Type} [inst : Mul α] {d : ℕ} {ds : List ℕ} (x : Holor α [d]) (y : Holor α ds),
y.CPRankMax1 → (x.mul y).CPRankMax1
inductive Holor.CPRankMax E1 #
{α : Type} → [Mul α] → [AddMonoid α] → ℕ → {ds : List ℕ} → Holor α ds → Prop
CPRankMax N x means x has CP rank at most N, that is,
it can be written as the sum of N holors of rank at most 1.
ctor Holor.CPRankMax.zero E0 #
∀ {α : Type} [inst : Mul α] [inst_1 : AddMonoid α] {ds : List ℕ}, Holor.CPRankMax 0 0
ctor Holor.CPRankMax.succ E0 #
∀ {α : Type} [inst : Mul α] [inst_1 : AddMonoid α] (n : ℕ) {ds : List ℕ} (x y : Holor α ds),
x.CPRankMax1 → Holor.CPRankMax n y → Holor.CPRankMax (n + 1) (x + y)
theorem Holor.cprankMax_nil E1 #
∀ {α : Type} [inst : Mul α] [inst_1 : AddMonoid α] (x : Holor α []), Holor.CPRankMax 1 x
theorem Holor.cprankMax_1 E1 #
∀ {α : Type} {ds : List ℕ} [inst : Mul α] [inst_1 : AddMonoid α] {x : Holor α ds}, x.CPRankMax1 → Holor.CPRankMax 1 x
theorem Holor.cprankMax_add E1 #
∀ {α : Type} {ds : List ℕ} [inst : Mul α] [inst_1 : AddMonoid α] {m n : ℕ} {x y : Holor α ds},
Holor.CPRankMax m x → Holor.CPRankMax n y → Holor.CPRankMax (m + n) (x + y)
theorem Holor.cprankMax_mul E1 #
∀ {α : Type} {d : ℕ} {ds : List ℕ} [inst : NonUnitalNonAssocSemiring α] (n : ℕ) (x : Holor α [d]) (y : Holor α ds),
Holor.CPRankMax n y → Holor.CPRankMax n (x.mul y)
theorem Holor.cprankMax_sum E1 #
∀ {α : Type} {ds : List ℕ} [inst : NonUnitalNonAssocSemiring α] {β : Type u_1} {n : ℕ} (s : Finset β)
(f : β → Holor α ds), (∀ x ∈ s, Holor.CPRankMax n (f x)) → Holor.CPRankMax (s.card * n) (∑ x ∈ s, f x)
theorem Holor.cprankMax_upper_bound E1 #
∀ {α : Type} [inst : Semiring α] {ds : List ℕ} (x : Holor α ds), Holor.CPRankMax ds.prod x
def Holor.cprank E1 #
{α : Type} → {ds : List ℕ} → [Ring α] → Holor α ds → ℕ
The CP rank of a holor x: the smallest N such that
x can be written as the sum of N holors of rank at most 1.
theorem Holor.cprank_upper_bound E1 #
∀ {α : Type} [inst : Ring α] {ds : List ℕ} (x : Holor α ds), x.cprank ≤ ds.prod