with(networks): DegG:=proc(_G) local _i,_D,_N,_M; _M:=adjacency(_G); _N:=LinearAlgebra[RowDimension](convert(_M,Matrix)): _D:=Matrix(_N,_N,0); for _i from 1 to _N do _D[_i,_i]:=add(_M[_i,_j],_j=1.._N); od: return _D; end proc: LapG:=proc(_G) return adjacency(_G)-DegG(_G); end proc: SNF:=proc(_G) local _N,_SF; _N:=LinearAlgebra[RowDimension](convert(adjacency(_G),Matrix)): _SF:=linalg[ismith](LapG(_G)); return [seq(_SF[_i,_i],_i=1.._N)]; end proc: fSNF:=proc(_G) return ifactor(SNF(_G)); end proc: oSNF:=proc(_G) local ords,i,j,_list,_n; _list:=SNF(_G); _n:=LinearAlgebra[RowDimension](convert(adjacency(_G),Matrix)): j:=1: for i from 1 to _n do #print(_list,_list[i]); if (_list[i] <> 0 and _list[i]<> 1) then ords[j]:=_list[i]: j:=j+1: fi: od: if j=1 then ords[1]:=0: fi; return convert(ords,list); end proc: ofSNF:=proc(_G) return ifactor(oSNF(_G)); end proc: LabelIt:=proc(_G,_labels) local _n; _n:=LinearAlgebra[RowDimension](convert(adjacency(_G),Matrix)); return graph(_labels,subs({seq(i=_labels[i],i=1.._n)},ends(_G))); end proc: UnLabel:=proc(_G) local _n; _n:=LinearAlgebra[RowDimension](convert(adjacency(_G),Matrix)); return graph({seq(i,i=1.._n)},subs({seq(v[i]=i,i=1.._n)},ends(_G))); end proc: gdunion:=proc(_list) local _i,_nextLab,_LGraphs,_numGs,_numVs,_totVs,_ansa; _numGs:=LinearAlgebra[ColumnDimension](convert(_list,Matrix)); _totVs:=0: for _i from 1 to _numGs do _numVs[_i]:=LinearAlgebra[RowDimension](convert(adjacency(_list[_i]),Matrix)): _LGraphs[_i]:=LabelIt(_list[_i],[seq(v[j],j=_totVs+1.._totVs+_numVs[_i])]); _totVs:=_totVs+_numVs[_i]; od: _ansa:=_LGraphs[1]; for _i from 2 to _numGs do _ansa:=gunion(_ansa,_LGraphs[_i]); od; return( UnLabel(_ansa)); end proc: NPath:=proc(_N) return delete({_N+2},cycle(_N+2)); end proc: KRho:=proc(_n,_subbie) local biggie; if( _n >= LinearAlgebra[RowDimension](incidence(_subbie)) ) then biggie:=complete(_n): return complement(graph({seq(i,i=1.._n)},ends(_subbie)),biggie); else print(cat("Must take complement in larger complete graph. Received K_", _n,", but subgraph has ", LinearAlgebra[RowDimension](incidence(_subbie)), " vertices!")); return graph({1},[1,1]): fi: end proc: ModPath:=proc(_A,_M, _N) local i, paf,first,last; paf:={}: first:=-1: for i from 1 to _N-_M do if (i mod _M = _A mod _M ) then if ( first = -1 ) then first:=i; fi; paf:=paf union {{i,i+_M}}; last:=i+_M; fi; od: if( first mod _M = last mod _M ) then paf:=paf union {{first,last}} fi; return graph({seq(j,j=1.._N)},paf); end proc: ParPath:=proc(_N) return gunion(ModPath(1,2,_N),ModPath(2,2,_N)); end proc: SkipN:=proc(_M,_N) local paf, i, j, ModN; ModN:=x->piecewise((x-_N*trunc(x/_N))<>0,x-_N*trunc(x/_N) mod _N,_N): paf:={}; for i from 1 to _N do paf:=paf union {{i ,ModN(i+_M)},{i ,ModN(i-_M)}}; od; return graph({seq(i,i=1.._N)},paf); end proc: DisPaths:=proc(_list) return DisjointPaths(_list); end proc: DisjointPaths:=proc(_list) local _numGs; _numGs:=LinearAlgebra[ColumnDimension](convert(_list,Matrix)); return gdunion([seq(NPath(_list[i]),i=1.._numGs)]); end proc: LineGraph:=proc(_G) local i,Vset, Eset; Eset:={}: Vset:=ends(_G): for i from 1 to LinearAlgebra[RowDimension](incidence(_G)) do Eset:=Eset union combinat[choose](ends(incident(i,_G),_G),2); od; return graph(Vset,Eset); end proc: print("Added Commands: LapG, DegG, SNF, fSNF, oSNF, ofSNF, gdunion, NPath, ModPath, ParPath, DisPaths, SkipN, KRho, LineGraph");