I want to make it suitable for more variables, as shown below:
In[44]:= TermString[term_Plus] :=
StringRiffle[
ToString@*InputForm /@ SortBy[List @@ term, FreeQ[x | y | z|t|u|v]],
" + "];
CoordinatesString[coords : {_, _, _}] :=
StringRiffle[TermString /@ coords, {"{", ", ", "}"}]
CoordinatesString[{1/4 - y, 1/4 - z, 1/4 - x}]
CoordinatesString[{1/4 - y, 1/4 - z, 1/4 - x, 2-t}]
CoordinatesString[{1/4 - y, 1/4 - z, 1/4 - x, 1/2-t,2/3+u}]
CoordinatesString[{1/4 - y, 1/4 - z, 1/4 - x, 1/2-t,2/3+u,4/5+v}]
Out[46]= "{-y + 1/4, -z + 1/4, -x + 1/4}"
During evaluation of In[46]:= StringRiffle::string: String expected at position 2 in StringRiffle[{-y + 1/4,-z + 1/4,-x + 1/4,-t + 2},{{,, ,, ,}}].
Out[47]= StringRiffle[{"-y + 1/4", "-z + 1/4", "-x + 1/4",
"-t + 2"}, {"{", ", ", ", ", "}"}]
Out[48]= CoordinatesString[{1/4 - y, 1/4 - z, 1/4 - x, 1/2 - t,
2/3 + u}]
Out[49]= CoordinatesString[{1/4 - y, 1/4 - z, 1/4 - x, 1/2 - t,
2/3 + u, 4/5 + v}]
It seems that the following method works well:
In[171]:= {{1/4 - y, 1/4 - z, 1/4 - x,1/2-t},{1/4 - y, 1/4 - z, 1/4 - x,1/2-t,3/4+u,5/6+v}}
(ToString[#[[2]],InputForm]<>"+"<>ToString[#[[1]],InputForm]&/@List@@@#)&/@%//StringRiffle[#,","]&//StringReplace[#,{"("->"",")"->"","},"->"\n","{"->"","}"->""}]&
Out[171]= {{1/4 - y, 1/4 - z, 1/4 - x, 1/2 - t}, {1/4 - y, 1/4 - z,
1/4 - x, 1/2 - t, 3/4 + u, 5/6 + v}}
Out[172]= "-y+1/4, -z+1/4, -x+1/4, -t+1/2
-y+1/4, -z+1/4, -x+1/4, -t+1/2, u+3/4, v+5/6"
However, when I further tried it on my actual data, I still didn't get the expected results:
gensFindGroup//ClearAll;
gensFindGroup[{m__?MatrixQ} | m__?MatrixQ]:=Block[{gens,dim,vec,vars,x,y,z,t,u,v,gensop},
gens={m};
dim=Dimensions[gens][[2]]-1;
vars = {x, y, z, t, u, v};
vec = Append[Take[vars, dim], 1];
(*vec = {x, y, z, t, u, v}[[;; dim]]~Join~{1}*)
(*Table[(i[[1;;3,1;;3]] . Transpose[{{x,y,z}}] + i[[1;;3,4]])//Transpose,{i,gens}]//ArrayFlatten[#,1]&//ToString[#,InputForm]&//StringReplace[#,{"("->"",")"->""}]&;*)
(*Plus@@{ArrayFlatten[#[[1;;3,1;;3]] . Transpose[{{x,y,z}}],1],#[[1;;3,4]]}&/@gens// InputForm // ToString //StringReplace[#,{"("->"",")"->""}]&*)
gensop=Map[Dot[#, vec] &, gens[[All, 1 ;; dim]], {-2}];
(ToString[#[[2]],InputForm]<>"+"<>ToString[#[[1]],InputForm]&/@List@@@#)&/@gensop//StringRiffle[#,","]&//StringReplace[#,{"("->"",")"->"","},"->"\n","{"->"","}"->""}]&
]
In[318]:= "gensSGc2false:=[[[0,-1,0,1/4],[0,0,-1,1/4],[-1,0,0,1/4],[0,0,0,1]],[[-1,2,-1,-3/8],[-3/2,3/2,-1/2,-1/16],[-1/2,3/2,-3/2,-17/16],[0,0,0,1]]]"//StringReplace[#,{"["->"{","]"->"}"}]&//ToExpression
gensSGc2false//gensFindGroup
Out[319]= "-y+1/4, -z+1/4, -x+1/4
-x+-3/8, -3*x/2+-1/16, -1/2*x+-17/16"
The expected results should be as follows:
-y + 1/4, -z + 1/4, -x + 1/4
-x + 2*y - z -3/8, - 3*x/2 + 3*y/2 - z/2 -1/16, - x/2 + 3*y/2 - 3*z/2 -17/16