#C3.txt: Jan. 30, 2025 Help3:=proc(): print(`AM(G), Neis(G): CC(G,i), IsCo(G), NumCG(N), NumCGe(N,x) `):end: #NumCG(N): the first N terms of the number of connected labeled graphs NumCG:=proc(N) local f,z: f:=add(2^(binomial(i,2))*z^i/i!,i=0..N): f:=log(f): f:=taylor(f,z=0,N+1); [seq(i!*coeff(f,z,i),i=1..N)]: end: #NumCGe(N,x): the first N terms of the weight-enumerators of connected labeled graphs according to the number of edges NumCGe:=proc(N,x) local f,z: f:=add((1+x)^(binomial(i,2))*z^i/i!,i=0..N): f:=log(f): f:=taylor(f,z=0,N+1); expand([seq(i!*coeff(f,z,i),i=1..N)]): end: #Neis(G) The list of length n such that G[i] is the set iof neighbors of i Neis:=proc(G) local n,E,N,e,i: n:=G[1]: E:=G[2]: for i from 1 to n do N[i]:={}: od: for e in E do N[e[1]]:=N[e[1]] union {e[2]}: N[e[2]]:=N[e[2]] union {e[1]}: od: [seq(N[i],i=1..n)]: end: #CC(G,i): the connected component of vertex i in the graph G=[n,E] CC:=proc(G,i) local n,E,C1,C2,C3,N,c1: n:=G[1]: E:=G[2]: N:=Neis(G): C1:={i}: C2:= C1 union {seq(op(N[c1]),c1 in C1)}: while C1<>C2 do C3:= C2 union {seq(op(N[c1]),c1 in C2)}: C1:=C2: C2:=C3: od: C2: end: #IsCo(G): Is the graph G connected IsCo:=proc(G) local n,i: n:=G[1]: evalb(CC(G,1)={seq(i,i=1..n)}): end: #Code by Aurora Hively # AM(G): inputs a graph [n,E] and outputs the adjacency matrix, represented as a list of length n of lists of length n, # such that M[i][j]=1 if {i,j} belongs to E and 0 otherwise. # For example AM([2,{{1,2}}]); should output [[0,1],[1,0]] . AM := proc(G) local n,E,e,M: n := G[1]: E := G[2]: M := [[0$n]$n]: # initialize n x n matrix of all 0's for e in E do M[e[1]][e[2]]++: M[e[2]][e[1]]++: od: M: end: #old stuff #C2.txt: Jan. 27, 2025 Help2:=proc(): print(`LC(p), RG(n,p), Cliques(G,k) `):end: with(combinat): #LC(p): inputs a rational number between 0 and 1 and outputs true with prob. p LC:=proc(p) local a,b,ra: if not (type(p,fraction) and p>=0 and p<=1) then RETURN(FAIL): fi: a:=numer(p): b:=denom(p): ra:=rand(1..b)(): if ra<=a then true: else false: fi: end: RG:=proc(n,p) local E,i,j: E:={}: for i from 1 to n do for j from i+1 to n do if LC(p) then E:=E union {{i,j}}: fi: od: od: [n,E]: end: #Cliques(G,k): inputs a graph G and a pos. integer k outputs the set of #k-cliques Cliques:=proc(G,k) local n, E,S,i,c,C: n:=G[1]: E:=G[2]: S:={}: C:=choose({seq(i,i=1..n)},k): for c in C do if choose(c,2) minus E={} then S:=S union {c}: fi: od: S: end: ###From C1 #C1.txt: Jan. 23, 2025 Exp Math (Dr. Z.) Help1:=proc(): print(`Graphs(n), Tri(G) , TotTri(G) `): end: #An undirected graph is a set of vertices V and a set of edges #[V,E] and edge e={i,j} where i and j belong to V #Our vertices are labeled {1,2,...,n} #Our data structure is [n,E] where E is the set of edges [3,{{1,2},{1,3},{2,3}}]; #If there are n vertices how many (undirected) graphs there #Graphs(n): inputs a non-neg. integer and outputs the set of ALL #graphs on {1,...,n} Graphs:=proc(n) local i,j,S,E,s: E:={seq(seq({i,j},j=i+1..n), i=1..n)}; S:=powerset(E): {seq([n,s],s in S)}: end: #Tri(G): inputs a graph [n,E] and outputs the set of all triples {i,j,k} #such {{i,j},{i,k},{j,k}} is a subset of E Tri:=proc(G) local n,S,E,i,j,k: n:=G[1]: E:=G[2]: #S is the set of love triangles S:={}: for i from 1 to n do for j from i+1 to n do for k from j+1 to n do #if member({i,j},E) and member({i,k},E), and member({j,k},E) then if {{i,j},{i,k},{j,k}} minus E={} then S:=S union {{i,j,k}}: fi: od: od: od: S: end: #Comp(G): the complement of G=[n,E] Comp:=proc(G) local n,i,j,E: n:=G[1]: E:=G[2]: [n,{seq(seq({i,j},j=i+1..n), i=1..n)} minus E]: end: #Tot(G): the total number of love triangles and hate triangles TotTri:=proc(G) nops(Tri(G))+nops(Tri(Comp(G))): end: