CoCalc Shared FilesRandom(Co)EqPublic.sagews
Author: Tien Chih
Views : 6
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()

#Creating the Part Sets for each graph

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;
v=i;
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==f(u) and z==f(v)) or (z==f(u) and z==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])

#Picking Random Morphisms

Homfg = FiniteEnumeratedSet(HomS)

f = Homfg.random_element()
print("\n\n Morphism f \n\n")
f
g = Homfg.random_element()
print("\n\n Morphism g \n\n")
g

#Eq is the equalizer graph

Eq = Graph()

#Creating the equalizer

for j in G.vertices():
if f(j)==g(j):

for j in G.edges(labels=False):
u=j
v=j
if f(j)==g(j) and j in Eq.vertices() and j in Eq.vertices():

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

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
for v in Coeq.vertices():
if e in v:
a = v
if e in v:
b = v

print("\n\n Graph Coeq \n\n")

Coeq.show()
{"ft_lang_label":"__label__en","ft_lang_prob":0.5368614,"math_prob":0.9974616,"size":2096,"snap":"2020-10-2020-16","text_gpt3_token_len":790,"char_repetition_ratio":0.1457935,"word_repetition_ratio":0.39884394,"special_character_ratio":0.39980915,"punctuation_ratio":0.15487571,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9959666,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-17T21:15:40Z\",\"WARC-Record-ID\":\"<urn:uuid:2044dc15-1c35-4ac5-9228-33ba51e90d0c>\",\"Content-Length\":\"33394\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7e414849-2b1a-458d-93e6-1421963c0aa1>\",\"WARC-Concurrent-To\":\"<urn:uuid:1d736294-bde6-498d-b4c8-6c5251851d17>\",\"WARC-IP-Address\":\"104.20.91.251\",\"WARC-Target-URI\":\"https://share.cocalc.com/share/b7e7e2af9f0166f139f869b4608da721ae34db06/Random(Co)EqPublic.sagews?viewer=share\",\"WARC-Payload-Digest\":\"sha1:NWF52RFS22MK7RMBPN4YH46UWBVCGMJH\",\"WARC-Block-Digest\":\"sha1:MC5TFEGWN4LK3GWJAA65FRZIF3UCNSB3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875143373.18_warc_CC-MAIN-20200217205657-20200217235657-00442.warc.gz\"}"}