| Hosted by CoCalc | Download
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) ]); #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #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() Pg = Set (G.vertices() + G.edges(labels=False)); Ph = Set (H.vertices() + H.edges(labels=False)); X = FiniteSetMaps(Pg, Ph); Z = Set(X) HomS = Set([]); for f in Z: s = True #Checking whether f is a graph morphism (vertices) for j in G.vertices(): if f(j)in H.vertices(): s=s and True else: s=s and False #Checking whether f is a graph morphism (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]) #We now display Hom(G, H) print("\n\n Hom(G, H) \n\n") for j in HomS: print j #Creating the Strict Homset 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]) #Displaying the Strict Homset print("\n\n HomSt(G, H) \n\n") for j in HomSt: print j