#C2.txt Help2:=proc(): print(` LD(p), RG(n,p), Clique(G,k) `):end: with(combinat): LD:=proc(p) local a,b,ra: a:=numer(p): b:=denom(p): ra:=rand(1..b)(): if ra<=a then true: else false: fi: end: #RG(n,p): a random graph on {1,...n} wih prob. of each edge being p (independently) 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 LD(p) then E:=E union {{i,j}}: fi: od: od: [n,E]: end: #Cliques(G,k): inputs a graph [n,E] and a pos. integer k, outputs the set of all triples k-clique #contained G Cliques:=proc(G,k) local S,i,c,C,E,n: n:=G[1]: E:=G[2]: C:=choose({seq(i,i=1..n)},k): #S is the set of k-cliques S:={}: for c in C do if choose(c,2) minus E={} then S:=S union {c}: fi: od: S: end: ######FROM C1.txt #C1.txt: Jan. 23, 2025 Exp Math (Dr. Z.) Help1:=proc(): print(`Graphs(n), Tri(G) , TotTri(G) `): end: with(combinat): #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: ######End FROM C1.txt