From b5197cbd54a3d1dc2bbe9eefc818b06d9b15c734 Mon Sep 17 00:00:00 2001 From: fanasina Date: Wed, 6 May 2026 21:55:54 +0200 Subject: [PATCH] update: try reverse transpositiongit status --- onedimensiontensor.tex | 390 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 385 insertions(+), 5 deletions(-) diff --git a/onedimensiontensor.tex b/onedimensiontensor.tex index 3432d60..73bda4f 100644 --- a/onedimensiontensor.tex +++ b/onedimensiontensor.tex @@ -36,14 +36,20 @@ \newtheorem{definition}{Definition}[section] \begin{document} -\section{Goal: Write any tensor as vector !!} - +\section{Write any tensor of any order as vector or tensor of order one !!} +Let +$\mathbb{K}$ a field( for e.g $\mathbb{R}$ ), we will construct $\mathbb{K}^{d_1\times\cdots\times d_k}\simeq \mathbb{K}^{d_1\cdots d_k}$ such that $d_1,\ldots,d_k\in\mathbb{N}^*$. +\begin{definition} +A tensor is a collection of elements + its dimensions define the size of the collection + its order is the number of different dimensions +\end{definition} +In linear algebra, we have the unfolding \begin{definition} A dimension of a tensor $T$ is a vector $d\in \left(\mathbb{N}^*\right)^k$ $(k<\infty)$. We have $$T=(a)_d=(a)_{d_1,\ldots,d_k} =({\alpha}_{i_1,\ldots,i_k}^{\{k\}})_{0\le i_10$ is the order.\\ The size of the Tensor is $d_1 \times \cdots \times d_k=\prod_{i=1}^kd_i$ @@ -55,7 +61,7 @@ We can write $$T\in \mathbb{K}^{d_1 \times d_2 \times \cdots \times d_k}$$ \section{Bijection} -For a given $d_1,\ldots,d_k\in \mathbb{N}^*$, there exists a bijective application between a set of tensor order 1 of size $n=d_1\cdot d_2 \cdots d_k$ $\mathbb{K}^{d_1\times d_2 \times \cdots \times d_k}$ and the set of tensor of order $k$ of the size $n= d_1\cdot d_2 \cdots d_k$ $\mathbb{K}^{d_1\times d_2 \times \cdots \times d_k}$. +For a given $d_1,\ldots,d_k\in \mathbb{N}^*$, there exists a bijective application between a set of tensor order 1 of size $n=d_1\cdot d_2 \cdots d_k$ $\mathbb{K}^{n}$ and the set of tensor of order $k$ of the size $n= d_1\cdot d_2 \cdots d_k$ $\mathbb{K}^{d_1\times d_2 \times \cdots \times d_k}$. Little endian $$ @@ -263,8 +269,380 @@ $$ The most advantage is computation, only one loop to browse all tensor elements! If we can compute in parallele, as we know the size and it is on a line, each threads or compute units available can have the same number of elements to compute! +\section{Transposition} +By definition, the transposition of a tensor $T_{\alpha}^{\{k\}}\in\mathbb{R}^{d_{1}\times\cdots\times d_{k}}$ is $T_{\beta}^{\{k\}}\in\mathbb{R}^{b_{1}\times \cdots\times b_{k}}$ and $T_{\alpha}^{\{1\}}\in\mathbb{R}^{d_{1}\cdots d_{k}}$ and $T_{\beta}^{\{1\}}\in\mathbb{R}^{b_{k}\cdots b_{1}}$ such that : $b_j=d_{k-j+1}$ + +$\alpha_{\left(i_1, i_2,\ldots, i_{k}\right)_k} = \beta_{\left(i_{k},\ldots,i_2,i_1\right)_k} $ + +in one dim representation (little endian) we have + +\begin{align*} + \alpha_{\left(i_1, i_2,\ldots, i_{k}\right)_k} &= \alpha_{\left(\sum_{j=1}^k i_j \prod_{l=1}^{j-1}d_l \right)_1} \\ + \beta_{\left(t_{1},\ldots,t_{k}\right)_k} &= \beta_{\left( \sum_{j=1}^k t_j \prod_{l=1}^{j-1}b_l\right)_1} +\end{align*} +here $t_j=i_{k-j+1}$ and $b_j=d_{k-j+1}$ so we have + +\begin{align*} + \alpha_{\left(i_1, i_2,\ldots, i_{k}\right)_k} &= \alpha_{\left(\sum_{j=1}^k i_j \prod_{l=1}^{j-1}d_l \right)_1} \\ + &=\beta_{\left(t_{1},\ldots,t_{k}\right)_k} \\ + &= \beta_{\left( \sum_{j=1}^k t_j \prod_{l=1}^{j-1}b_l\right)_1}\\ + & t_j=i_{k-j+1}\text{ and }b_j=d_{k-j+1}\\ + &= \beta_{\left( \sum_{j=1}^k i_{k-j+1} \prod_{l=1}^{j-1}d_{k-l+1}\right)_1}\\ + &\text{we pose }t=k-j+1 \text{ so } j=k-t+1 \\ + &\text{if }j=1 \Rightarrow t=k \text{ and } j=k \Rightarrow t=1 \\ + &= \beta_{\left( \sum_{t=k}^{1} i_{t} \prod_{l=1}^{k-t+1-1}d_{k-l+1}\right)_1}\\ + &= \beta_{\left( \sum_{t=1}^{k} i_{t} \prod_{l=1}^{k-t}d_{k-l+1}\right)_1}\\ + & \text{ we pose }s=k-l+1 \text{ and }l=k-s+1 \\ + &\text{if }l=1 \Rightarrow s=k \text{ and } l=k-t \Rightarrow s=k-(k-t)+1=t+1 \\ + &= \beta_{\left( \sum_{t=1}^{k} i_{t} \prod_{s=k}^{t+1}d_{s}\right)_1}\\ +\end{align*} + + + +\section{Transposition} +By definition, the transposition of a tensor $T_{\alpha}^{\{k\}}\in\mathbb{R}^{d_{1}\times\cdots\times d_{k}}$ is $T_{\beta}^{\{k\}}\in\mathbb{R}^{d_{k}\times d_{k-1}\cdots\times d_{1}}$ and $T_{\alpha}^{\{1\}}\in\mathbb{R}^{d_{1}\cdots d_{k}}$ and $T_{\beta}^{\{1\}}\in\mathbb{R}^{d_{k}\cdots d_{1}}$ such that + +$\alpha_{\left(i_1, i_2,\ldots, i_{k}\right)_k} = \beta_{\left(i_{k},\ldots,i_2,i_1\right)_k} $ + +So, if little endian + + +\begin{align*} +\alpha_{\left(\sum_{j=1}^{k} i_j \prod_{l=1}^{j-1}d_j \right)_1} &= \beta_{\left(\sum_{j=k}^{1} i_j \prod_{l=k}^{j+1}d_j \right)_1}\\ +&= \beta_{\left(\sum_{j=1}^{k} i_j \prod_{l=j+1}^{k}d_j \right)_1}\\ +\end{align*} + +Let $l=\sum_{j=1}^{k} i_j \prod_{l=1}^{j-1}d_j$ corresponds $m=\sum_{j=1}^{k} i_j \prod_{l=j+1}^{k}d_j$ + +Suppose $i_1 \prod_{l=1}^{k}d_j + \end{align*} + + \begin{align*} + m'-m &=\sum_{j=3}^k i_j \prod_{l=j+1}^{k}d_l + i_2 \prod_{l=3}^k d_l + \prod_{l=3}^k d_l \\ +&-\left( (d_1-1)\prod_{l=2}^k d_l + i_2\prod_{l=3}d_l +\sum_{j=3}i_j\prod_{l=j+1}d_l \right)\\ +&=\sum_{j=3}^k i_j \prod_{l=j+1}^{k}d_l + i_2 \prod_{l=3}^k d_l + \prod_{l=3}^k d_l \\ +&-\left( \prod_{l=1}^k d_l-\prod_{l=2}^k d_l + i_2\prod_{l=3}d_l +\sum_{j=3}i_j\prod_{l=j+1}d_l \right)\\ +&= \prod_{l=3}^k d_l -\left( \prod_{l=1}^k d_l-\prod_{l=2}^k d_l \right)\\ +&= \prod_{l=3}^k d_l + \prod_{l=2}^k d_l - \prod_{l=1}^k d_l + \end{align*} + +If $i_1=d_1-1$ and $i_2=d_2-1$ in $m$ so +\begin{align*} +m'&=\left(i_1+1\right)\prod_{l=2}^{k}d_j+ \sum_{j=2}^{k} i_j \prod_{l=j+1}^{k}d_j\\ +&=\prod_{l=2}^{k}d_j + i_1 \prod_{l=2}^{k}d_j+ \sum_{j=2}^{k} i_j \prod_{l=j+1}^{k}d_j\\ +&=\prod_{l=2}^{k}d_j + \sum_{j=1}^{k} i_j \prod_{l=j+1}^{k}d_j\\ +&=\prod_{l=2}^{k}d_j + m\\ +&=\prod_{l=2}^{k}d_j + (d_1-1)\prod_{j=2}^kd_j+(d_2-1)\prod_{j=3}^kd_j + \sum_{j=3}^{k} i_j \prod_{l=j+1}^{k}d_j\\ +&=\prod_{l=2}^{k}d_j + \prod_{j=1}^kd_j -\prod_{j=2}^kd_j+ \prod_{j=2}^kd_j -\prod_{j=3}^kd_j + \sum_{j=3}^{k} i_j \prod_{l=j+1}^{k}d_j\\ +&=\prod_{l=2}^{k}d_j + \prod_{j=1}^kd_j -\prod_{j=3}^kd_j + \sum_{j=3}^{k} i_j \prod_{l=j+1}^{k}d_j\\ +&=\prod_{l=2}^{k}d_j + \prod_{j=1}^kd_j -\prod_{j=3}^kd_j + i_3 \prod_{l=4}^{k}d_j+ \sum_{j=4}^{k} i_j \prod_{l=j+1}^{k}d_j\\ +&> \prod_{j=1}^kd_j\\ +\end{align*} +\begin{align*} + m'-m &= \prod_{l=2}^{k}d_j \\ + \end{align*} + + + +\begin{align*} +m''&= (i_3+1) \prod_{l=4}^{k}d_j + \sum_{j=4}^{k} i_j \prod_{l=j+1}^{k}d_j\\ +\end{align*} +\begin{align*} +m''-m &= (i_3+1) \prod_{l=4}^{k}d_j + \sum_{j=4}^{k} i_j \prod_{l=j+1}^{k}d_j - \left((d_1-1)\prod_{l=2}^k d_l + (d_2-1)\prod_{l=3}^kd_l + i_3 \prod_{l=4}^kd_l + \sum_{j=4}^k i_j \prod_{l=j+1}^kd_l \right) \\ +m''-m &= \prod_{l=4}^{k}d_j - \left((d_1-1)\prod_{l=2}^k d_l + (d_2-1)\prod_{l=3}^kd_l \right) \\ +m''-m &= \prod_{l=4}^{k}d_j - \left(\prod_{l=1}^k d_l-\prod_{l=2}^k d_l + \prod_{l=2}^k d_l-\prod_{l=3}^kd_l \right) \\ +m''-m &= \prod_{l=4}^{k}d_j - \left(\prod_{l=1}^k d_l-\prod_{l=3}^kd_l \right) \\ +m''-m &= \prod_{l=3}^kd_l + \prod_{l=4}^{k}d_j - \prod_{l=1}^k d_l \\ +\end{align*} + + +if $i_1=d_1-1$, $i_2=d_2-1$, $i_3=d_3-1$ +\begin{align*} + m+\prod_{l=3}^kd_l + \prod_{l=4}^{k}d_j - \prod_{l=1}^k d_l &= \left( (d_1-1)\prod_{l=2}^kd_l+(d_2-1)\prod_{l=3}^kd_l+(d_3-1)\prod_{l=4}^kd_l +\sum_{j=4}^k i_j\prod_{l=j+1}d_l \right) \\& +\prod_{l=3}^kd_l+ \prod_{l=4}^{k}d_j - \prod_{l=1}^k d_l\\ + \end{align*} +\begin{align*} + m+\prod_{l=3}^kd_l + \prod_{l=4}^{k}d_j - \prod_{l=1}^k d_l &= \left( (d_1-1)\prod_{l=2}^kd_l+(d_2-1)\prod_{l=3}^kd_l+(d_3-1)\prod_{l=4}^kd_l +\sum_{j=4}^k i_j\prod_{l=j+1}d_l \right) \\& +\prod_{l=3}^kd_l+ \prod_{l=4}^{k}d_j - \prod_{l=1}^k d_l\\ + &= \left(\prod_{l=1}^kd_l-\prod_{l=2}^kd_l+ \prod_{l=2}^kd_l-\prod_{l=3}^kd_l+\prod_{l=3}^kd_l-\prod_{l=4}^kd_l +\sum_{j=4}^k i_j\prod_{l=j+1}d_l \right) \\& + \prod_{l=3}^kd_l+ \prod_{l=4}^{k}d_j - \prod_{l=1}^k d_l\\ + &= \left(\prod_{l=1}^kd_l-\prod_{l=4}^kd_l +\sum_{j=4}^k i_j\prod_{l=j+1}d_l \right) \\& + \prod_{l=3}^kd_l+ \prod_{l=4}^{k}d_j - \prod_{l=1}^k d_l\\ + &= \sum_{j=4}^k i_j\prod_{l=j+1}d_l + \prod_{l=3}^kd_l\\ + &= \sum_{j=4}^k i_j\prod_{l=j+1}d_l + <\prod_{l=3}^kd_l\\ +\end{align*} + + +\begin{align*} + l+1&=\sum_{j=1}^k i_j\prod_{l=1}^{j-1}d_l +1\\ + &= 1+(d_1-1) + (d_2-1)d_1 + (d_3-1)d_1 d_2+i_4d_1d_2d_3 +\sum_{j=5}^k i_j\prod_{l=1}^{j-1}d_l\\ + &= d_1 + d_2-d_1 + d_1d_2d_3-d_1 d_2+i_4d_1d_2d_3 +\sum_{j=5}^k i_j\prod_{l=1}^{j-1}d_l\\ + &= (i_4+1)d_1d_2d_3 +\sum_{j=5}i_j\prod_{l=1}^{j-1}d_l\\ +\end{align*} + +corresponds to +\begin{align*} + m' &= (i_4+1)\prod_{l=5}^kd_l + \sum_{j=5}i_j\prod_{l=j+1}^kd_l\\ + &= i_4\prod_{l=5}^kd_l +\prod_{l=5}^kd_l + \sum_{j=5}i_j\prod_{l=j+1}^kd_l\\ +\end{align*} +\begin{align*} + m'-m &= i_4\prod_{l=5}^kd_l +\prod_{l=5}^kd_l + \sum_{j=5}i_j\prod_{l=j+1}^kd_l\\ + & -\left( (d_1-1)\prod_{l=2}^kd_l + (d_2-1)\prod_{l=3}^kd_l+(d_3-1)\prod_{l=4}^kd_l+i_4\prod_{l=5}^kd_l+\sum_{j=5}^ki_j\prod_{l=j+1}^k d_l \right)\\ +&= i_4\prod_{l=5}^kd_l +\prod_{l=5}^kd_l + \sum_{j=5}i_j\prod_{l=j+1}^kd_l\\ + & -\left( \prod_{l=1}^kd_l-\prod_{l=2}^kd_l + \prod_{l=2}^kd_l-\prod_{l=3}^kd_l+\prod_{l=3}^kd_l-\prod_{l=4}^kd_l+i_4\prod_{l=5}^kd_l+\sum_{j=5}^ki_j\prod_{l=j+1}^k d_l \right)\\ + &= \prod_{l=5}^kd_l + \prod_{l=4}^kd_l - \prod_{l=1}^kd_l + \end{align*} + + \section{Transposition backward} + + $l=\sum_{j=1}^ki_j\prod_{l=1}^{j-1}d_l$ corresponds to $m=\sum_{j=1}^ki'_j\prod_{l=1}^{j-1}d'_l$ such that + \begin{align*} + d'_l&=d_{k-l+1} \\ + i'_j&=d'_{j}-i_{k-j+1} -1\\ + &=d_{k-j+1}-i_{k-j+1}-1 \\ + \end{align*} + + \begin{align*} + m&=\sum_{j=1}^ki'_j\prod_{l=1}^{j-1}d'_l\\ + &=\sum_{j=1}^k\left(d_{k-j+1}-i_{k-j+1}-1\right)\prod_{l=1}^{j-1}d_{k-l+1}\\ +&t=k-j+1 \Rightarrow j=k-t+1\\ +&j=1 \Rightarrow t=k\\ +&j=k \Rightarrow t=1\\ + m&=\sum_{t=k}^1\left(d_{t}-i_{t}-1\right)\prod_{l=1}^{k-t+1-1}d_{k-l+1}\\ + m&=\sum_{t=1}^k\left(d_{t}-i_{t}-1\right)\prod_{l=1}^{k-t}d_{k-l+1}\\ +&s=k-l+1 \Rightarrow l=k-s+1\\ +&l=1 \Rightarrow s=k\\ +&l=k-t \Rightarrow s=k-(k-t)+1=t+1\\ + m&=\sum_{t=1}^k\left(d_{t}-i_{t}-1\right)\prod_{s=k}^{t+1}d_{s}\\ + m&=\sum_{t=1}^k\left(d_{t}-i_{t}-1\right)\prod_{s=t+1}^{k}d_{s}\\ + \end{align*} +if $i_1 \prod_{l=3}^k d_l -1 -\prod_{l=2}^k d_l \ge m-\prod_{l=2}^k d_l &\ge \prod_{s=4}d_s - \prod_{l=2}^k d_l \\ +(d_1-1)\prod_{l=2}^k+\prod_{l=3}^k d_l \ge m +(d_1-1)\prod_{l=2}^k -1 &\ge (d_1-1)\prod_{l=2}^k+ \prod_{s=4}d_s \\ +% (1-d_2)\prod_{l=3}^k d_l \ge m-\prod_{l=2}^k d_l &\ge \prod_{s=4}d_s - \prod_{l=2}^k d_l \\ +% (1-d_2)\prod_{l=3}^k d_l \ge m-\prod_{l=2}^k d_l &\ge \prod_{s=4}d_s - \prod_{s=3}d_s + \prod_{s=3}d_s - \prod_{l=2}^k d_l \\ +% (1-d_2)\prod_{l=3}^k d_l \ge m-\prod_{l=2}^k d_l &\ge (1-d_3)\prod_{s=4}d_s + (1-d_2) \prod_{s=3}d_s \\ +\end{align*} + + + + + + + + + + + + Perhaps, it's a little endian rewrite in big endian + + +For any $i\in \mathbb{N} , i