Generatore di Cartan NxN

Listing all the necessary off-diagonal elements

funzioneSemplice[x_,y_]:=Sqrt[x*y]

Tan[ArcTan["2."]]

funzioneComplicata[x_, y_] := Module[{variabilelocale,variabilelocale2},
variabilelocale=x^2+y^2;
variabilelocale2=ArcTan[variabilelocale];
Sqrt[variabilelocale]
]

n=3
ul=Table[ToString[i]<>ToString[j],{i,1,n},{j,1,i-1}]
MatrixForm[%]
dr=Table[ToString[j]<>ToString[i],{i,1,n},{j,1,i-1}]
MatrixForm[%]
Unset[n]

I can transform each of them into a basis-element in a 6D vector
21 -> 1
31 -> 2
32 -> 3
...

Join[{a,b},{c,d}]

ul
Select[{ul},{}≠#&]
(Sin[#])&

(#>0) &

f[x_]:=Sin[x]

ModuleFunctionExample[n_]:=Module[{ul,dr},
ul=Table[ToString[i]<>ToString[j],{i,1,n},{j,1,i-1}];
dr=Table[ToString[j]<>ToString[i],{i,1,n},{j,1,i-1}];
Select[Join[ul,dr],{}≠#&]//Flatten
]

ModuleFunctionExample[2]

ModuleFunctionExample[3]

The complete set of N-dim vectors  (there a a lot! (4^N)) can be generated with Outer

4^6

n^2-n/.n->4

4^12

The dimensionality of this approach grows very fast, so it should not be very extensible

TensorProduct, Outer and Apply

Tr[{a,b,c}]

Tr[{a, b, c},Times]

Tr[{a, b, c},f]

TensorProduct[{a,b,c,d},{a,b,c,d}]

Outer[f,{a,b,c,d},{a,b,c,d}]

Outer[List, {a, b, c, d},{a, b, c, d}, {a, b, c, d}]

Table[{i,j},{i,{-3,-2,-1,0}},{j,{-3,-2,-1,0}}]

TensorProduct[{a,b,c,d},{a,b,c,d},{a,b,c,d}]

Outer[Times,{a,b,c,d},{a,b,c,d},{a,b,c,d}]

An extensible multiplication: The Outer function

In principle I could get this via the Outer function applied to two lists

Outer[f,{α,β,γ},{a,b,c}]

For instance I can apply the function f=Plus

Outer[Plus,{α,β,γ},{a,b,c}]

m=4
Join[{Plus}, Table[{a, b, c},m]]
Unset[m]

Outer@@{Plus,{α,β,γ},{a,b,c}}

Interestingly I can use Outer on more than 2 lists

Outer[f,{α,β,γ},{a,b,c},{s,t,u}]

Apply and the list of Arguments

@

Through the use of Apply (or @@) I can construct the argument of the general Outer

Here is what Apply (or @@) does

Apply[Plus,{a,b,c}]

Plus@@{a,b,c}

n=3
Apply[f, Table[i,{i,1,n}]]
Unset[n]

n = 3
operation={f}
operand=Table[Table[a,4], {i, 1, n}]
args=Join[operation,operand]
Apply[Outer,args ]
Unset[n]

To obtain the same thins as above I can do

Outer@@{f,{α,β,γ},{a,b,c},{s,t,u}}

Outer@@{Plus,{α,β,γ},{a,b,c},{s,t,u}}

Interestingly the argument of @@ can be constructed with Join

Join[{a},{b}]

Join[{f},{{α,β,γ},{a,b,c},{s,t,u}}]

Outer@@Join[{f},{{α,β,γ},{a,b,c},{s,t,u}}]

If I want I can now construct the “list of lists”  with Table

Table[{a,b,c,d},4]

Outer@@Join[{f},Table[{a,b,c},3]]

k=6
Outer@@Join[{f},Table[{a,b,c},k]]
Unset[k]

Generation of the (very redundant!) set of N-ples ( N=n(n-1)=2, 6, 12, ...)

Outer@@Join[{f},Table[{0,-1,-2,-3},2]]

Then I can Imagine to filter them assuming each pair is an i<->j exchange symmetric pair on which I can check the (Subscript[M, ij])(Subscript[M, ji])  conditions

I can do that through the function Partition

Partition[{a,b,c,d,e,f,g,h,i,j,k,l},2]
Partition[{a,b,c,d,e,f,g,h,i,j,k,l},3]
Partition[{a,b,c,d,e,f,g,h,i,j,k,l},4]

Let us first develop a function that recognises the invalid Mij Mji pairs.

ValidIJForCartan[Mij_,Mji_]:=(Mij==0&&Mji==0)||(Mij*Mji<4&&Mij!=0&&Mji!=0)

ValidIJForCartan[0,0]
ValidIJForCartan[0,-1]
ValidIJForCartan[0,-2]
ValidIJForCartan[-3,-1]
ValidIJForCartan[-3,-2]
ValidIJForCartan[-1,-2]

ValidIJForCartan[{0,0}]

{0,0}//FullForm

ListToSequence[l_]:=l/.List->Sequence

ValidIJForCartan[ListToSequence[{0,0}]]

ValidIJForCartan@@{0,0}

Outer@@Join[{ValidIJForCartan},Table[{0,-1,-2,-3},2]]

PrintValidIJForCartan[Mij_,Mji_]:=If[ValidIJForCartan[Mij,Mji],Sort[{Mij,Mji}],{}]

PrintValidIJForCartanList[pair_]:=If[ValidIJForCartan[ListToSequence[pair]],Sort[pair],Null]

PrintValidIJForCartan[0,0]
PrintValidIJForCartan[0,-1]
PrintValidIJForCartan[-2,-1]

PrintValidIJForCartanList[{0,0}]
PrintValidIJForCartanList[{0,-1}]
PrintValidIJForCartanList[{-2,-1}]

Outer@@Join[{PrintValidIJForCartan},Table[{0,-1,-2,-3},2]]

If I apply it to 2-dim lists I can get already all the allowed off-diagonals of the 2x2 Cartan matrices

Outer@@Join[{f},Table[{0,-1,-2,-3},2]]
%//.f->PrintValidIJForCartan
Sort[Flatten[%,1]]
DeleteDuplicates[%]

To apply the check for Mij Mji to a n(n-1)-dim vector I have to apply it to a pair-partitioned list

Let us start with a short list first ...

Partition[{a,b,c,d},2]

I can test each pair with Map

Map[PrintValidIJForCartanList,Partition[{a,b,c,d},2]]
%/.{a->0,b->0,c->-1,d->-2}
%%/.{a->0,b->0,c->-3,d->-2}

Now I can make a function that tests the whole list and if the output is equal to the input (all pairs are valid) it returns the list

ValidSequenceofMIJForCartan[list_]:=If[Map[PrintValidIJForCartanList,Partition[list,2]]==Partition[list,2],list,{},{}]

ValidSequenceofMIJForCartan[{0,0,-2,-2}]
ValidSequenceofMIJForCartan[{0,0,-1,-2}]
ValidSequenceofMIJForCartan[{0,0,-2,-1}]

Outer@@Join[{List},Table[{0,-1,-2,-3},6]];
Flatten[%];
Partition[%,6];
Map[ValidSequenceofMIJForCartan,%];
Select[%,{}≠#&]
Length[%]

Not all the 64 are truly valid, not all are even inequivalent. More checks would be needed to eliminate them.

Construct the Matrix directly as sum of valid blocks

Instead of considering the 6 elements of a 3x3 matrix as independent I can say that they are 3 pairs. Each of which can assume one of the 4 valid values that I found for the 2x2 exercise
{ {0,0}, {-1,-1}, {-2,-1},{-3,-1} }

There are n(n-1)/2 pairs, each can take only 4 values. Hence I have intermediate steps with the Sqrt[] of the number of attempts that I make in the other way.

Table[Power[4,n(n-1)],{n,2,5}]

Table[Power[4,n(n-1)/2],{n,2,5}]

This is better but I still will stop at 4x4, because 5x5 needs 1M attempts, which is silly.

To really do better I may try to get the NxN by the extension of the (N-1) x (N-1). This requires adding N-1 pairs to the valid ones found at the NxN level.

Table[Row[{ToString[n->n+1]<>": ",Power[4,n(n-1)/2*(n-1)]}],{n,2,5}]

If all the matrices obtain at N-1 were to be kept this would give even worse divergence of workload, but it may work ok if at each step I can eliminate the majority of the resulting matrices either by equivalence, or triviality, ...

A more matrix-based approach

Outer[Plus,Tuples[{{a,b},{x,y},{w,q}}]]

Outer[Plus,{a,b},{x,y},{w,q}]
Flatten[%]

n=3;
Table[Normal[SparseArray[{{i,j}->k},n]],{i,1,n},{j,i+1,n},{k,-3,0}];
eMatrixes=Flatten[%,1]
MatrixForm[eMatrixes]
Unset[n]

eMatrixes//Length
DeleteDuplicates[Map[Length,eMatrixes]]

Table[Table[ToString[i]<>"+"<>ToString[j],{i,1,3}],{j,1,3}]