linear algebra.c
// expand indexes array of N elements to  N+2 elements
expand indexes array of N elements to  N+2 elements
expand indexes array of N elements to N + 2 elements
int TensorExpandArray(int *I, int N, int i, int j, int k) {
    int *I1, i1 = min(i,j), j1 = max(i,j);
    I1 = malloc((N+2)*sizeof(int));
    for (int l = 0; l < i1; l++) {
        I1[l] = I[l];
    }
    I1[i1] = k;
    for (int l = i1+1; l < j1; l++) {
        I1[l] = I[l-1];
    }
    I1[j1] = k;
    for (int l = j1+1; l < N+2; l++) {
        I1[l] = I[l-2];
    }
    I = realloc(I, (N+2)*sizeof(int));
    for (int l = 0; l < N+2; l++) {
        I[l] = I1[l];
    }
    free(I1);
    return 0;
}
int TensorExpandArray ( int * I , int N , int i , int j , int k ) { int * I1 , i1 = min ( i , j ) , j1 = max ( i , j ) ; I1 = malloc ( ( N + 2 ) * sizeof ( int ) ) ; for ( int l = 0 ; l < i1 ; l ++ ) { I1 [ l ] = I [ l ] ; } I1 [ i1 ] = k ; for ( int l = i1 + 1 ; l < j1 ; l ++ ) { I1 [ l ] = I [ l - 1 ] ; } I1 [ j1 ] = k ; for ( int l = j1 + 1 ; l < N + 2 ; l ++ ) { I1 [ l ] = I [ l - 2 ] ; } I = realloc ( I , ( N + 2 ) * sizeof ( int ) ) ; for ( int l = 0 ; l < N + 2 ; l ++ ) { I [ l ] = I1 [ l ] ; } free ( I1 ) ; return 0 ; }
expand indexes array of N elements to  N+2 elements
expand indexes array of N elements to N + 2 elements
/*
        expand indexes array of N elements to  N+2 elements
        insert int 'k' in positions 'i' and 'j' in array I
    */ // make new array to join old and new indexes // copy to old array with new indexes