Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 97
import sys from sage.all import * #Graphs G and H print("\n\n Graph G \n") G = Graph([('a', 'b'),('b', 'c'), ('d','a'), ('b', 'd')]); G.show() print("\n\n Graph H \n\n") H = Graph([(1, 2), (2, 3) ]); H.show() #Vertice and Edge Set of G and H print("\n\n Part Set of Graph G \n\n") Pg = Set (G.vertices() + G.edges(labels=False)); Pg print("\n\n Part Set of Graph H \n\n") Ph = Set (H.vertices() + H.edges(labels=False)); Ph X = FiniteSetMaps(Pg, Ph); X Z = Set(X) HomS = Set([]); for f in Z: s = True #Checking whether f and g are graph morphisms (vertices) for j in G.vertices(): if f(j)in H.vertices(): s=s and True else: s=s and False #Checking whether f and g are graph morphisms (edges) for i in G.edges(labels=False): u=i[0]; v=i[1]; if f(u)==f(v) and f(u)==f(i): s=s and True elif f(i)in H.edges(labels=False): z=f(i); if (z[0]==f(u) and z[1]==f(v)) or (z[1]==f(u) and z[0]==f(v)): s=s and True else: s=s and False else: s=s and False #Adds f to HomS if f is a morphism if s==True: HomS = HomS + Set([f]) #Shows every possible morphism #for j in HomS: # print j #HomSt = Set([]) #for g in HomS: # s = True # for v in G.edges(labels=false): # if g(v) in H.vertices(): # s = False # if s == True: # HomSt = HomSt + Set([g]) #HomSt Homfg = FiniteEnumeratedSet(HomS) f = Homfg.random_element(); f g = Homfg.random_element(); g #Prints the Product and Coproduct print("Grphs product of G and H") Prod = G.strong_product(H); Prod.show() print("Grphs co-product of G and H") Coprod = G.disjoint_union(H); Coprod.show() #Eq is the equalizer graph, Maybe change to Eq so we don't get confused with Coeq latter - Dr. C Eq = Graph() #Creating the equalizer print("\n\n Graph Eq V(Eq) \n\n") for j in G.vertices(): if f(j)==g(j): print(j) Eq.add_vertex(j) print("\n\n Graph Eq E(Eq) \n\n") for j in G.edges(labels=False): u=j[0] v=j[1] if f(j)==g(j) and j[0] in Eq.vertices() and j[1] in Eq.vertices(): Eq.add_edge(j) Eq.edges(labels=False) print("\n\n Graph Eq \n\n") Eq.show() #Coeq is the co-equalizer graph Coeq = Graph(multiedges=True, loops=True) Gdone = Set([]) Hdone = Set([]) for p in H.vertices(): if p not in Hdone: Gtemp=Set([]) Htemp=Set([p]) s = False while s == False: Gcheck=Gtemp Hcheck=Htemp for x in Pg: if f(x) in Htemp: Gtemp = Gtemp + Set([x]) if g(x) in Htemp: Gtemp = Gtemp + Set([x]) for p in Gtemp: Htemp = Htemp + Set([f(p), g(p)]) if (Gtemp == Gcheck) and (Htemp == Hcheck): s = True Gdone = Gdone + Gtemp Hdone = Hdone + Htemp Coeq.add_vertex(Htemp) for p in H.edges(labels=False): if p not in Hdone: Gtemp=Set([]) Htemp=Set([p]) s = False while s == False: Gcheck=Gtemp Hcheck=Htemp for x in Pg: if f(x) in Htemp: Gtemp = Gtemp + Set([x]) if g(x) in Htemp: Gtemp = Gtemp + Set([x]) for p in Gtemp: Htemp = Htemp + Set([f(p), g(p)]) if (Gtemp == Gcheck) and (Htemp == Hcheck): s = True Gdone = Gdone + Gtemp Hdone = Hdone + Htemp e=Htemp[0] for v in Coeq.vertices(): if e[0] in v: a = v if e[1] in v: b = v Coeq.add_edge(a, b, Htemp) print("\n\n Coequalizer \n\n") Coeq.show()
Graph G
Graph H
Part Set of Graph G {'a', 'c', 'b', 'd', ('b', 'c'), ('a', 'd'), ('a', 'b'), ('b', 'd')} Part Set of Graph H {(1, 2), 1, 2, 3, (2, 3)} Maps from {'a', 'c', 'b', 'd', ('b', 'c'), ('a', 'd'), ('a', 'b'), ('b', 'd')} to {(1, 2), 1, 2, 3, (2, 3)} map: a -> 2, c -> 1, b -> 2, d -> 3, ('b', 'c') -> (1, 2), ('a', 'd') -> (2, 3), ('a', 'b') -> 2, ('b', 'd') -> (2, 3) map: a -> 1, c -> 3, b -> 2, d -> 1, ('b', 'c') -> (2, 3), ('a', 'd') -> 1, ('a', 'b') -> (1, 2), ('b', 'd') -> (1, 2) Grphs product of G and H
Grphs co-product of G and H
Graph Eq V(Eq) b Graph Eq E(Eq) [] Graph Eq
Coequalizer
Coequalizer
map: a -> 1, c -> 3, b -> 2, d -> 1, ('b', 'c') -> (2, 3), ('a', 'd') -> 1, ('a', 'b') -> (1, 2), ('b', 'd') -> (1, 2) Grphs co-product of G and H
Graph Eq V(Eq) b Graph Eq E(Eq) [] Graph Eq
Coequalizer