Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 64
import sys from sage.all import * #Graphs G and H G is the Domain, H is the coDomain. G = Graph([('a', 'b'),('b', 'c'), ('b', 'd')]) H = Graph([(1, 2), (2, 3) ]) ##DO NOT EDIT THESE 3 LINES Pg = Set (G.vertices() + G.edges(labels=False)); Ph = Set (H.vertices() + H.edges(labels=False)); X = FiniteSetMaps(Pg, Ph) ##DO NOT EDIT THE ABOVE 3 LINES f = X.from_dict({'a':1, 'b':2, 'c':3, 'd':3, ('a', 'b'):(1, 2), ('b', 'c'):(2, 3), ('b', 'd'):(2, 3)}); g = X.from_dict({'a':1, 'b':2, 'c':1, 'd':3, ('a', 'b'):(1, 2), ('b', 'c'):(1, 2), ('b', 'd'):(2, 3)}); #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #PLEASE DO NOT EDIT ANYTHING AFTER THIS LINE! #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! print("\n\n Graph G \n") G.show() print("\n\n Graph H \n\n") H.show() s = True #Checking whether f and g are graph morphisms (vertices) It seems like this only checks if f is a graph morphism rather than g. - Dr. C 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 print("\n\n Are f and g Graph Morphism? (T/F) \n\n"); s #Breaks the program if it is not a graph morphism if s == False: quit("Not a Morphism") #Eq is the equalizer graph Eq = Graph() #Creating the equalizer for j in G.vertices(): if f(j)==g(j): Eq.add_vertex(j) 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) 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 Graph CoEq \n\n") Coeq.show()