pivots[A_]:=Flatten[FirstPosition[1]/@Transpose[A]]

pMatrix[n_]:=Table[
Which[i==2&&j==1||i==1&&j==2,-1/2,
i==j&&i>2,1,
True,0],{i, n},{j,n}]

gramMatrix[W_]:=Simplify[Transpose[W].pMatrix[Length[W]].W]

linearRelationsMatrix[G_]:=RowReduce[G][[1;;MatrixRank[G]]]//Transpose

linearRelations[L_]:=Select[
Table[Equal[(Subscript[b, i]),L[[i]].Table[(Subscript[b, i]),{i,pivots[L]}]],{i,Length[L]}],Not[BooleanQ[#]]&]

linearRelationsFromW=linearRelations@*linearRelationsMatrix@*gramMatrix;

inverseLinearRelations[G_]:=Table[If[i==#,1,0],{i,Length[G[[1]]]}]&/@Flatten[FirstPosition[#,1]&/@(RowReduce[G]//Select[Not[AllTrue[#,#==0&]]&])]

quadraticFormMatrix[G_,L_]:=Inverse[Table[G[[i, j]],{i,pivots[L]},{j,pivots[L]}]]

quadraticForm[Q_,L_]:=Module[{v=Table[(Subscript[b, i]),{i,pivots[L]}]},Simplify[v.Q.v==0]]

quadform[W_]:=Module[{G=gramMatrix[W]},Module[{L=linearRelationsMatrix[G]},quadraticForm[quadraticFormMatrix[G,L],L]]]

quadformFromG[G_]:=Module[{L=linearRelationsMatrix[G]},quadraticForm[quadraticFormMatrix[G,L],L]]

graphFromG[G_]:=PlanarGraph[AdjacencyGraph[If[#==-1,1,0]&/@#&/@G,VertexLabels->"Name"]]

nextCandidate[s_,t_,adj_]:=Block[{length,pos},length=Length[adj];
pos=Mod[Position[adj,s][[1,1]]+1,length,1];
{t,adj[[pos]]}];

FindFace[g_?PlanarGraphQ]:=Block[{emb},emb=GraphEmbedding[g,"PlanarEmbedding"];
FindFace[g,emb]];

FindFace[g_?PlanarGraphQ,emb_]:=Block[{m,orderings,pAdj,rightF,s,t,initial,face},m=AdjacencyMatrix[g];
Table[pAdj[v]=SortBy[Pick[VertexList[g],m[[v]],1],ArcTan@@(emb[[v]]-emb[[#]])&],{v,VertexList[g]}];
rightF[_]:=False;
Reap[Table[If[!rightF[e],s=e[[1]];
t=e[[2]];
initial=s;
face={s};
While[t=!=initial,rightF[UndirectedEdge[s,t]]=True;
{s,t}=nextCandidate[s,t,pAdj[t]];
face=Join[face,{s}];];
Sow[face];],{e,EdgeList[g]}]][[2,1]]]

findGenerators[faces_,vertices_,G_]:=Table[Block[{face,otherVertex,verticesOnFace,allVertices,Gp,P,Gnew,L,Q,Qform,sol1,sol2,sols,coeff,coeffTable,small,Li,P2},
face=faces[[i]];
verticesOnFace=Sort[RandomSample[face,3]];
otherVertex=RandomChoice[Select[vertices,Not[MemberQ[face,#]]&]];
allVertices=Append[verticesOnFace,otherVertex];
P=Transpose[IdentityMatrix[Length[vertices]][[#]]&/@DeleteDuplicates[Join[allVertices,vertices]]];
Gnew=Transpose[P].G.P;
L=linearRelationsMatrix[Gnew];
Gp=Table[G[[i,j]],{i,allVertices},{j,allVertices}];
Q=Inverse[Gp];
Qform=(#.Q.#&[Table[(Subscript[b, j]),{j,allVertices}]])==0;
sols=Expand[FullSimplify[Total[#[[1]][[2]]&/@Solve[Qform,(Subscript[b, otherVertex])]]]];
coeff=Table[sols/.Table[(Subscript[b, i])->If[i==curr,1,0],{i,allVertices}],{curr,allVertices}];
small=IdentityMatrix[Length[allVertices]];
small[[-1]]=Table[If[j==4,-1,If[MemberQ[verticesOnFace,allVertices[[j]]],coeff[[j]],0]],{j,Length[allVertices]}];
Li=Table[Table[If[j==k,1,0],{j,Length[vertices]}],{k,allVertices}];
P2=Table[If[j==k,1,0],{j,Length[vertices]},{k,DeleteDuplicates[Join[allVertices,vertices]]}];
P2.L.small.Li
],{i,Length[faces]}]

findGeneratorsN[faces_,vertices_,G_]:=Table[Block[{face,otherVertex,verticesOnFace,allVertices,Gp,P,Gnew,L,Q,Qform,sol1,sol2,sols,coeff,coeffTable,small,Li,P2},
face=faces[[i]];
verticesOnFace=Sort[RandomSample[face,3]];
otherVertex=RandomChoice[Select[vertices,Not[MemberQ[face,#]]&]];
allVertices=Append[verticesOnFace,otherVertex];
P=Transpose[IdentityMatrix[Length[vertices]][[#]]&/@DeleteDuplicates[Join[allVertices,vertices]]];
Gnew=Transpose[P].G.P;
L=linearRelationsMatrix[Gnew];
Gp=Table[G[[i,j]],{i,allVertices},{j,allVertices}];
Q=Inverse[Gp];
Qform=(#.Q.#&[Table[(Subscript[b, j]),{j,allVertices}]])==0;
sols=Expand[FullSimplify[Total[#[[1]][[2]]&/@NSolve[Qform,(Subscript[b, otherVertex])]]]];
coeff=Table[sols/.Table[(Subscript[b, i])->If[i==curr,1,0],{i,allVertices}],{curr,allVertices}];
small=IdentityMatrix[Length[allVertices]];
small[[-1]]=Table[If[j==4,-1,If[MemberQ[verticesOnFace,allVertices[[j]]],coeff[[j]],0]],{j,Length[allVertices]}];
Li=Table[Table[If[j==k,1,0],{j,Length[vertices]}],{k,allVertices}];
P2=Table[If[j==k,1,0],{j,Length[vertices]},{k,DeleteDuplicates[Join[allVertices,vertices]]}];
P2.L.small.Li
],{i,Length[faces]}]

findGeneratorsFromG[G_]:=findGeneratorsN[FindFace[PlanarGraph[AdjacencyGraph[If[#==-1,1,0]&/@#&/@G,VertexLabels->"Name"]]],Range[Length[G]],G]

search[generators_,current_,lastgen_,upperBound_,faces_]:=Block[{totals,invalid},
invalid[σ_,face_]:=σ==lastgen||AllTrue[Delete[σ.current,{#}&/@face],#>upperBound&];
totals[i_]:=If[invalid[generators[[i]],faces[[i]]],0,
Length[current]-Length[faces[[i]]]-Length[Select[Delete[current,{#}&/@faces[[i]]],#>upperBound&]]+search[generators,generators[[i]].current,generators[[i]],upperBound,faces]];
Total[totals/@Range[Length[generators]]]]

$RecursionLimit=16384

fractalDimensionFromG[G_,max_,delta_,root_]:=Block[{xs,ys,data,graph,faces,sigmas,nlm,params},
xs=Range[delta,max,delta];
graph=graphFromG[G];
faces=FindFace[graph];
sigmas=findGeneratorsFromG[G];
ys=search[sigmas,root,{},#,faces]+Length[root]&/@xs;
data={xs[[#]],ys[[#]]}&/@Range[Length[ys]];
nlm=NonlinearModelFit[data,a (x^b),{a,b},x];
params=nlm["BestFitParameters"];
Print[nlm["RSquared"]];
b/.params
]

pyramidG[n_]:=Table[Which[i==0&&j==0,1,i==0||j==0,-1,True,1-((2((Sin[((Abs[i-j]π)/n)])^2))/((Sin[(π/n)])^2))],{i,0,n},{j,0,n}]

pyramidG[5]//Simplify//MatrixForm

pyramidFractalDimension[n_,max_,delta_]:=fractalDimensionFromG[N[pyramidG[n]],max,delta,N[Table[If[i==n+1,-1,((Sec[(π/n)]+Tan[(π/n)])/(Tan[(π/n)]))],{i,n+1}]]]

G={{1,-8-3 Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),3 (-2-Sqrt[5]),-2-Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],3 (-2-Sqrt[5]),-1,-1,-1,-5-2 Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5]},{-8-3 Sqrt[5],1,-5-2 Sqrt[5],-5-2 Sqrt[5],-1,-1,-5-2 Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],-1,3 (-2-Sqrt[5]),3 (-2-Sqrt[5]),3 (-2-Sqrt[5]),-2-Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],-2-Sqrt[5]},{-2-Sqrt[5],-5-2 Sqrt[5],1,3 (-2-Sqrt[5]),-2-Sqrt[5],3 (-2-Sqrt[5]),-1,-5-2 Sqrt[5],-2-Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],-1,-5-2 Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),-1,-8-3 Sqrt[5]},{-2-Sqrt[5],-5-2 Sqrt[5],3 (-2-Sqrt[5]),1,3 (-2-Sqrt[5]),-2-Sqrt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5-2 Sqrt[5],-1,-5-2 Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),-2-Sqrt[5],1,-5-2 Sqrt[5],-1},{-5-2 Sqrt[5],-2-Sqrt[5],-1,-8-3 Sqrt[5],-1,-5-2 Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),-2-Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),-5-2 Sqrt[5],-1,-5-2 Sqrt[5],1,3 (-2-Sqrt[5])},{-5-2 Sqrt[5],-2-Sqrt[5],-8-3 Sqrt[5],-1,-5-2 Sqrt[5],-1,3 (-2-Sqrt[5]),-2-Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),-2-Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],-1,3 (-2-Sqrt[5]),1}}

fractalDimensionFromG[G,1000,20,{-1,2,2,4,4,7}]

faces-1

faces=FindFace[PlanarGraph[AdjacencyGraph[If[#==-1,1,0]&/@#&/@G,VertexLabels->"Name"]]]

sigmas=findGeneratorsFromG[G]

(search[sigmas,{-1,2,2,4,4,7},{},#,faces]+6)&/@Range[10]

2

(*Timing[pyramidFractalDimension[11,100000,10000]]*)

G={{1,-8-3 Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),3 (-2-Sqrt[5]),-2-Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],3 (-2-Sqrt[5]),-1,-1,-1,-5-2 Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5]},{-8-3 Sqrt[5],1,-5-2 Sqrt[5],-5-2 Sqrt[5],-1,-1,-5-2 Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],-2-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[5]),3 (-2-Sqrt[5]),-5-2 Sqrt[5],-5-2 Sqrt[5]},{-5-2 Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),-2-Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],-8-3 Sqrt[5],-1,-2-Sqrt[5],-5-2 Sqrt[5],3 (-2-Sqrt[5]),-1,-2-Sqrt[5],-5-2 Sqrt[5],3 (-2-Sqrt[5]),1,-2-Sqrt[5],-1,-5-2 Sqrt[5]},{-5-2 Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),-2-Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-8-3 Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-1,3 (-2-Sqrt[5]),-5-2 Sqrt[5],-1,-5-2 Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),-2-Sqrt[5],1,-5-2 Sqrt[5],-1},{-5-2 Sqrt[5],-2-Sqrt[5],-1,-8-3 Sqrt[5],-1,-5-2 Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),-2-Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),-5-2 Sqrt[5],-1,-5-2 Sqrt[5],1,3 (-2-Sqrt[5])},{-5-2 Sqrt[5],-2-Sqrt[5],-8-3 Sqrt[5],-1,-5-2 Sqrt[5],-1,3 (-2-Sqrt[5]),-2-Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-5-2 Sqrt[5],-2-Sqrt[5],-2-Sqrt[5],3 (-2-Sqrt[5]),-2-Sqrt[5],-5-2 Sqrt[5],-5-2 Sqrt[5],-1,3 (-2-Sqrt[5]),1}}

root={1.6838616297871791`,3.5522063477126107`,0.5291610914079277`,3.5522063477126107`,1.6838616297871791`,3.5522063477126107`,-0.18448308813825243`,1.6838616297871791`,3.5522063477126107`,4.706906886091862`,0.5291610914079277`,1.6838616297871791`,4.706906886091862`,1.6838616297871791`,3.5522063477126107`,0.5291610914079277`,3.5522063477126107`,5.420551065638042`,1.6838616297871791`,4.706906886091862`};

(*fractalDimensionFromG[G,10000,100,root]*)

W=({{0, 0, 0, -1}, {2, 0, 0, 1}, {0, 3, 0, 1}, {2, 3, (Sqrt[3]), 2}});

P=({{0, -1/2, 0, 0}, {-1/2, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}});

G=({{1, -1, -1, -2}, {-1, 1, -2, -1}, {-1, -2, 1, -1}, {-2, -1, -1, 1}});

W.P.Transpose[W]//MatrixForm

v=Table[(Subscript[b, i]),{i,4}]

eq=Simplify[v.Inverse[G].v]==0

Total[Solve[eq,(Subscript[b, 4])]/.{(Subscript[b, 4])->x_}->x]

sigmas={
({{-1, 2, 2, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}),({{1, 0, 0, 0}, {2, -1, 0, 2}, {0, 0, 1, 0}, {0, 0, 0, 1}}),({{1, 0, 0, 0}, {0, 1, 0, 0}, {2, 0, -1, 2}, {0, 0, 0, 1}}),({{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 2, 2, -1}})
};

faces={{2,3,4},{1,3,4},{1,2,4},{1,2,3}};

root={-2,4,5,9};

Total[sigmas[[1]].v]

eq/.{(Subscript[b, 1])->-2,(Subscript[b, 2])->4,(Subscript[b, 3])->5}//Simplify

(*search[sigmas,N[root],-1,20]*)

sigmas={
({{-1, 2, 2, 2}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}),({{1, 0, 0, 0}, {2, -1, 2, 2}, {0, 0, 1, 0}, {0, 0, 0, 1}}),({{1, 0, 0, 0}, {0, 1, 0, 0}, {2, 2, -1, 2}, {0, 0, 0, 1}}),({{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {2, 2, 2, -1}})
};
faces={{2,3,4},{1,3,4},{1,2,4},{1,2,3}};
root={-6,11,14,23};
Timing[search[sigmas,N[root],{},2000,faces]+Length[root]]

G=({{1, -1, -1, -1}, {-1, 1, -1, -1}, {-1, -1, 1, -1}, {-1, -1, -1, 1}})

fractalDimensionFromG[G,1000,100,root]

sigmas[[1]].root

sigmas[[2]].sigmas[[3]].sigmas[[2]].root//Total

Total[root]

Total[sigmas[[4]].sigmas[[3]].sigmas[[4]].root]

(*search[generators_,current_,lastgen_,upperBound_]:=
Total[Table[If[(generators[[i]].current)[[i]]≥upperBound||Total[generators[[i]].current]≤Total[current],0,1+search[generators,generators[[i]].current,i,upperBound]],{i,4}]]*)

sigmas[[3]].root

(*search[sigmas,N[root],{},10,faces]*)

(*max=100;
delta=10;
xs=Range[1,max,delta];
ys=search[sigmas,N[root],-1,#]+Length[root]&/@xs;
data={xs[[#]],ys[[#]]}&/@Range[Length[ys]];
nlm=NonlinearModelFit[data,a (x^b),{a,b},x];
params=nlm["BestFitParameters"];
b/.params*)

nlm["RSquared"]

G=pyramidG[4]//Simplify

sigmas=findGeneratorsFromG[G]

FindFace[graphFromG[G]]-1

root={-0.5131807550506294`,1.2389279387920946`,1.2389279387920946`,1.2389279387920946`,1.2389279387920946`}

sigmas[[1]].root