3
$\begingroup$

I have square matrix of size $n$ filled with the following values

$$ T(i,j) = \begin{cases} 1 & i=j \\ -1 & j=k(i) \\ 0 & \mbox{otherwise} \end{cases} $$

where $k(i)=\{ \ldots \}$ is vector of integers, each one $k(i)

Example with $n=4$ generated from $k=\{ 0, 1, 1, 3 \}$

$$ T = \begin{bmatrix} 1 & 0 & 0 & 0 \\ -1 & 1 & 0 & 0 \\ -1 & 0 & 1 & 0 \\ 0 & 0 & -1 & 1 \end{bmatrix} $$

Notice that for each row $i$ there is only one $-1$ at the $k(i)$ column.

Now I want to find a rule for any $n>1$ that would generate $B=$T^{-1} = \begin{bmatrix} 1 & & & \\ & 1 & & \mbox{all zeros} \\ & \ddots & 1 & \\ \mbox{zeros}& \mbox{or ones}& & 1 \end{bmatrix} $$

For the example $T$ above we have

$$ B=T^{-1} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 1 & 1 & 0 & 0 \\ 1 & 0 & 1 & 0 \\ 1 & 0 & 1 & 1 \end{bmatrix} $$

Please try to include step by step example for the $T$ value above.

Using matlab I initialize $T$ with the following code:

% Parent indices
k = [0,1,1,3]   % or [0,1,2,3], [0,1,1,1], [0,1,2,2], ...

% Construct adjacency matrix T
n = size(k,2);
T = eye(n);
for i=2:n
    T(i,k(i))=-1;
end

Edit 1

I tried the method of setting $(T^{-1})_{ij}=1$ if $j$ is a multiple of $k(i)$ and it didn't work. Here is the sample matlab code:

%Find B=inv(T)
B = eye(n);
for i=2:n
    for j=1:i-1
        for u=1:i-1
            if j==(k(i))^u
                B(i,j) = 1;
                break
            end
        end
    end
end

T=
     1     0     0     0
    -1     1     0     0
    -1     0     1     0
     0     0    -1     1

B=  
     1     0     0     0
     1     1     0     0
     1     0     1     0
     0     0     1     1
(not correct)

Edit 2 I tried the following matlab code

%Find B=inv(T)
B = eye(n);
for i=2:n
    for j=1:i-1
        B(i,j) = -T(i,k(i))*B(k(i),j);
    end
end

and it works it seems fine for cases where $k(i)

Edit 3

I have settled with

B=eye(n);
for i=2:n,
    j=k(i);
    while j>0,
        B(i,j)=1;
        j=k(j);
    end;
end

based on the answer & comments by user1551. Here is the test code for posterity:

% Size
n  = 15
% k=Parent indices
k = zeros(1,n);
for i=2:n
    k(1,i) = int32(1+rand*(i-2) )
end
% Assemble T
T = eye(n);
for i=2:n
    T(i,k(i))=-1;
end

% Generate B=inv(T) with various methods

if(B*T==eye(n)) 
    disp('CORRECT')
else
    disp('FAIL')
end
  • 0
    Explicit formula: $T^{-1}\left(i,j\right)$ is $1$ if $j$ has the form $k^u\left(i\right)$ for some nonnegative integer $u$ (where $k\left(0\right) := 0$), and is $0$ otherwise. The proof is easy (just multiply the two matrices).2017-01-13
  • 0
    In your code, "k(i)^u" should be "k^u(i)", though I don't know whether whatever language you are using knows this syntax. The point is to apply u times the map k to i.2017-01-15
  • 0
    @darijgrinberg added parens for clarity. Thanks.2017-01-15
  • 0
    @ja72 Your $T$ is lower triangular and you have stated clearly that $k(i)$k=[0,3,2,1]$? Anyway, given a legitimate vector $k$, you can generate $B$ as follows: `B=zeros(n,n);for i=1:n,j=i;while j>0,B(i,j)=1;j=k(j);end;end` – 2017-01-15
  • 0
    @user1551 - You are correct. I will fix the example code. Please add your code as an answer as I like it a lot.2017-01-15

2 Answers 2

3

Let $T^{-1}=B$. Forward substitution gives $B_{i\ast}=e_i^T+B_{k(i)\ast}$. That is, the $i$-th row of $B$ is basically identical to the $k(i)$-th row, except that $b_{ii}$ is also equal to $1$. Put it another way, $$ b_{ij}=\begin{cases} 1&\text{ if } j\in\left\{i,\,k(i),\,k^2(i),\ldots,\,k^{i-1}(i)\right\},\\ 0&\text{ otherwise}. \end{cases} $$

  • 0
    Is there a formal name for $e_i$, a vector of zeros except the _i_-th element being 1?2017-01-15
  • 0
    I tried this method (also mentioned in the comments) but it doesn't work out. See edited question for my try.2017-01-15
  • 0
    @ja72 Not one I've heard of, but $e_i$ is just the $i$-th vector in the standard basis of $\mathbb R^n$.2017-01-15
  • 0
    More importantly the name for the subspace $n_i$ which contains all the element vectors of $\mathbb R^n$ _except_ $e_i$?2017-01-15
  • 0
    @ja72 I'm not aware of any name for that.2017-01-15
  • 0
    You comment helped me the most, so please add the algo to the answer for future visitors.2017-01-15
1

Recall the general matrix multiplication formula:

$\left[\begin{array}{lcr}1&0&0\\a&1&0\\b&c&1\end{array}\right] \left[\begin{array}{lcr}1&0&0\\\alpha&1&0\\\beta&\gamma&1\end{array}\right] =\left[\begin{array}{lcr}1&0&0\\0&1&0\\0&0&1\end{array}\right] $ requires $\left\{\begin{array}{c}\alpha=-a,\\\beta=-b-\alpha c,\\ \gamma=-c\end{array}\right\}$

Similar recursive formulas hold for higher-dimensional arrays. So to figure out your $\alpha,\beta,\gamma$, you need only to plug them into the formulas like this. The fact that only one of each row will be -1, and the rest will be 0's allow for a simple formulation of your recursive formula:

$A^{-1}_{i,j}=-A_{i,k(i)}A^{-1}_{k(i),j}$

which you can start by filling out from the top.

For your example:

$T^{-1}_{21}=-T_{2,k(2)}T^{-1}_{k(1),1}=-T_{21}T^{-1}_{11}=--1\cdot 1=1$

$T^{-1}_{31}=-T_{31}T^{-1}_{11}=--1\cdot 1 = 1$

$T^{-1}_{32}=-T_{31}T^{-1}_{12}=--1\cdot 0 = 0$

$T^{-1}_{41}=-T_{43}T^{-1}_{31}=--1\cdot 1 = 1$

$T^{-1}_{42}=-T_{43}T^{-1}_{32}=--1\cdot 0 = 0$

$T^{-1}_{43}=-T_{43}T^{-1}_{33}=--1\cdot 1 = 1$

Note that at each step, you already know the value of $T^{-1}_{ij}$ by the time you need it (the first case being $T^{-1}_{11}=1$ because it's on the diagonal.

  • 0
    In the end I want a computer algorithm, and not something that I match coefficients by hand. Can you show and example with $n=4$ like I have in the question?2017-01-13
  • 0
    Sure, this can be programmed into a recursive computer algorithm. Just start with the top row, and go down, and any cross-references should be resolved by the time you get there. OK, I'll demo.2017-01-13
  • 0
    Per the example, shouldn't the rule be $A^{-1}_{i,j}=-A_{i,k(i)}A^{-1}_{k(j),j}$? you wrote $A^{-1}_{i,j}=-A_{i,k(i)}A^{-1}_{k(i),j}$. In the example you reference $k(1)$ and $k(2)$ index in the first line, but the rule only references $k(i)$.2017-01-13
  • 0
    Please correct the example. $k(1)=0$ always, and in your example you have ${T^{-1}}_{k(1),1}$ which is undefined.2017-01-15