Basic properties of holors #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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 #
holor_index ds
is the type of valid index tuples used to identify an entry of a holor
of dimensions ds
.
Equations
- holor_index ds = {is // list.forall₂ has_lt.lt is ds}
Equations
- holor_index.assoc_right = cast holor_index.assoc_right._proof_1
Equations
- holor_index.assoc_left = cast holor_index.assoc_left._proof_1
Holor (indexed collections of tensor coefficients)
Equations
- holor α ds = (holor_index ds → α)
Equations
- holor.inhabited = {default := λ (t : holor_index ds), inhabited.default}
Equations
- holor.has_zero = {zero := λ (t : holor_index ds), 0}
Equations
- holor.has_add = {add := λ (x y : holor α ds) (t : holor_index ds), x t + y t}
Equations
- holor.has_neg = {neg := λ (a : holor α ds) (t : holor_index ds), -a t}
Equations
- holor.add_semigroup = {add := has_add.add holor.has_add, add_assoc := _}
Equations
- holor.add_comm_semigroup = {add := has_add.add holor.has_add, add_assoc := _, add_comm := _}
Equations
- holor.add_monoid = {add := has_add.add holor.has_add, add_assoc := _, zero := 0, zero_add := _, add_zero := _, nsmul := λ (n : ℕ) (x : holor α ds) (i : holor_index ds), n • x i, nsmul_zero' := _, nsmul_succ' := _}
Equations
- holor.add_comm_monoid = {add := has_add.add holor.has_add, add_assoc := _, zero := 0, zero_add := _, add_zero := _, nsmul := add_monoid.nsmul holor.add_monoid, nsmul_zero' := _, nsmul_succ' := _, add_comm := _}
Equations
- holor.add_group = {add := has_add.add holor.has_add, add_assoc := _, zero := 0, zero_add := _, add_zero := _, nsmul := add_monoid.nsmul holor.add_monoid, nsmul_zero' := _, nsmul_succ' := _, neg := λ (ᾰ : holor α ds), id (λ (ᾰ_1 : holor_index ds), add_group.neg (ᾰ ᾰ_1)), sub := λ (ᾰ ᾰ_1 : holor α ds), id (λ (ᾰ_2 : holor_index ds), add_group.sub (ᾰ ᾰ_2) (ᾰ_1 ᾰ_2)), sub_eq_add_neg := _, zsmul := λ (n : ℤ) (x : holor α ds) (i : holor_index ds), n • x i, zsmul_zero' := _, zsmul_succ' := _, zsmul_neg' := _, add_left_neg := _}
Equations
- holor.add_comm_group = {add := has_add.add holor.has_add, add_assoc := _, zero := 0, zero_add := _, add_zero := _, nsmul := add_monoid.nsmul holor.add_monoid, nsmul_zero' := _, nsmul_succ' := _, neg := λ (ᾰ : holor α ds), id (λ (ᾰ_1 : holor_index ds), add_comm_group.neg (ᾰ ᾰ_1)), sub := λ (ᾰ ᾰ_1 : holor α ds), id (λ (ᾰ_2 : holor_index ds), add_comm_group.sub (ᾰ ᾰ_2) (ᾰ_1 ᾰ_2)), sub_eq_add_neg := _, zsmul := sub_neg_monoid.zsmul (add_group.to_sub_neg_monoid (holor α ds)), zsmul_zero' := _, zsmul_succ' := _, zsmul_neg' := _, add_left_neg := _, add_comm := _}
Equations
- holor.has_smul = {smul := λ (a : α) (x : holor α ds) (t : holor_index ds), a * x t}
Equations
- holor.module = pi.module (holor_index ds) (λ (ᾰ : holor_index ds), α) α
The 1-dimensional "unit" holor with 1 in the j
th position.
Equations
- holor.unit_vec d j = λ (ti : holor_index [d]), ite (ti.val = [j]) 1 0
The original holor can be recovered from its slices by multiplying with unit vectors and summing up.
- nil : ∀ {α : Type} [_inst_1 : has_mul α] (x : holor α list.nil), x.cprank_max1
- cons : ∀ {α : Type} [_inst_1 : has_mul α] {d : ℕ} {ds : list ℕ} (x : holor α [d]) (y : holor α ds), y.cprank_max1 → (x.mul y).cprank_max1
cprank_max1 x
means x
has CP rank at most 1, that is,
it is the tensor product of 1-dimensional holors.
- zero : ∀ {α : Type} [_inst_1 : has_mul α] [_inst_2 : add_monoid α] {ds : list ℕ}, holor.cprank_max 0 0
- succ : ∀ {α : Type} [_inst_1 : has_mul α] [_inst_2 : add_monoid α] (n : ℕ) {ds : list ℕ} (x y : holor α ds), x.cprank_max1 → holor.cprank_max n y → holor.cprank_max (n + 1) (x + y)
cprank_max 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.