fixed bug in minimalmodel.py (phi_polinomial)

This commit is contained in:
carlos alquezar 2023-01-16 17:37:53 +01:00
parent 7dbf5344c0
commit 446eceb01b
2 changed files with 15 additions and 63 deletions

32
aplK.py
View File

@ -854,13 +854,14 @@ class AlgebraAplK(UniqueRepresentation, Parent):
def __init__(self, parent, values): def __init__(self, parent, values):
Element.__init__(self,parent) Element.__init__(self,parent)
self.elements = self._reduce(values) self.elements = self._reduce(values)
self.check() #self.check()
def _repr_(self): def _repr_(self):
""" """
Return the base string representation of ``self``. Return the base string representation of ``self``.
""" """
return str(self.elements) return str({a:b for a,b in self.elements.items() if not b.is_zero()})
#return str(self.elements)
def dimension(self): def dimension(self):
""" """
@ -1209,6 +1210,8 @@ class AlgebraAplK(UniqueRepresentation, Parent):
offsets = self._get_offsets_matrix(p_basis) offsets = self._get_offsets_matrix(p_basis)
len_row = sum([len(l) for l in p_basis.values()]) len_row = sum([len(l) for l in p_basis.values()])
M = zero_matrix(QQ,1, len_row) M = zero_matrix(QQ,1, len_row)
S = self.parent().simplicialComplex()
dim = S.dimension()
min_dim = self.degree() min_dim = self.degree()
for n in reversed(range(min_dim,dim+1)): for n in reversed(range(min_dim,dim+1)):
for simplex in S._n_cells_sorted(n): for simplex in S._n_cells_sorted(n):
@ -1257,6 +1260,7 @@ class AlgebraAplK(UniqueRepresentation, Parent):
nrows = face_matrix.nrows() nrows = face_matrix.nrows()
v = vector(QQ, list(v_dif)+nrows*[0]) v = vector(QQ, list(v_dif)+nrows*[0])
M = diff_matrix.stack(face_matrix) M = diff_matrix.stack(face_matrix)
print("Matrix size: ",M.nrows(),M.ncols())
sol = M.solve_right(v) sol = M.solve_right(v)
return self._get_solution(sol, p_basis) return self._get_solution(sol, p_basis)
@ -1276,27 +1280,3 @@ class MorphismFromQQToAplK(Morphism):
params[tuple(c)]=s(x) params[tuple(c)]=s(x)
A = AlgebraAplK(S) A = AlgebraAplK(S)
return AlgebraAplK.Element(A, params) return AlgebraAplK.Element(A, params)
#############################################
# TEST
print("TEST AlgebraAplK")
S = SimplicialComplex([[0,1,2]],is_mutable=False)
A = AlgebraAplK(S)
print("Test check if the assignation is valid")
s0 = SimplicialAlgebraplN(0)
s0.inject_variables()
p0 = s0(2)
p1 = s0(1)
p2 = s0(3)
s1 = SimplicialAlgebraplN(1)
s1.inject_variables()
p01 = 2*t0+t1
p02 = 2*t0+3*t1
p12 = t0+3*t1
s2 = SimplicialAlgebraplN(2)
s2.inject_variables()
p012 = 2-t1+t2
values = {(0,): p0, (1,): p1, (2,): p2, (0,1): p01, (0,2): p02, (1,2): p12, (0,1,2): p012}
e1 = A._element_constructor_(values)
e1
#############################################

View File

@ -1,33 +1,22 @@
def phi_polinomial(pol, model_morphism, A): def phi_polinomial(pol, model_morphism, A):
pol_keys = pol.dict().keys() #pol_keys = pol.dict().keys()
m_gens = pol.parent().gens()[:-1] m_gens = pol.parent().gens()
#m_gens = [g for g,e in zip(gens,sum([vector(k) for k in pol_keys])) if e] #m_gens = [g for g,e in zip(gens,sum([vector(k) for k in pol_keys])) if e]
aplkGens = [model_morphism[g.degree()][str(g)] for g in m_gens] aplkGens = {g:model_morphism[g.degree()][str(g)] for g in m_gens}
aplkElement = A.null_element() aplkElement = A.null_element()
for exp in pol.dict().keys(): for exp in pol.dict().keys():
coef = pol.dict()[exp] coef = pol.dict()[exp]
# To-Do: check if exp and aplkGens are sorted in the same way # To-Do: check if exp and aplkGens are sorted in the same way
term = coef*A.one() term = coef*A.one()
for i in range(len(exp)-1): for i in range(len(exp)):
e = exp[i] e = exp[i]
if e: if e:
aGen = aplkGens[i] aGen = aplkGens[m_gens[i]]
# print()
# print("term antes")
# print(term)
# print("aGen**e")
# print(aGen**e)
term *= aGen**e term *= aGen**e
# print("term después")
# print(term)
#term = coef*prod([gen^e for (gen,e) in zip(aplkGens, exp)]) #term = coef*prod([gen^e for (gen,e) in zip(aplkGens, exp)])
aplkElement += term aplkElement += term
return aplkElement return aplkElement
def get_ker_elements(sullivan_model, model_morphism, A, dim): def get_ker_elements(sullivan_model, model_morphism, A, dim):
# Get the basis of Hm # Get the basis of Hm
hm_basis = sullivan_model.cohomology(dim).basis() hm_basis = sullivan_model.cohomology(dim).basis()
@ -84,9 +73,6 @@ def injectivity_step(M, phi, check_dim, names,
gca = GradedCommutativeAlgebra(QQ, names=new_names, degrees=new_degrees) gca = GradedCommutativeAlgebra(QQ, names=new_names, degrees=new_degrees)
gen = gca.gens_dict()[new_gen] gen = gca.gens_dict()[new_gen]
aplkElement = phi_polinomial(kerElement, phi, A) aplkElement = phi_polinomial(kerElement, phi, A)
print(aplkElement)
print(aplkElement.is_zero())
print(aplkElement == A.null_element())
if aplkElement == A.null_element(): if aplkElement == A.null_element():
preimage = A.null_element() preimage = A.null_element()
else: else:
@ -198,6 +184,8 @@ def minimal_model(S, max_depth=5, max_dim=5):
else: else:
dim = first_dim + 1 dim = first_dim + 1
for i in range(dim, max_dim): for i in range(dim, max_dim):
print("phi")
print(phi)
[M, phi, names, degrees, cohomology_correspondence] = surjective_step(A, M, phi, i, names, degrees, [M, phi, names, degrees, cohomology_correspondence] = surjective_step(A, M, phi, i, names, degrees,
differentials, cohomology_correspondence) differentials, cohomology_correspondence)
[M, phi, names, degrees, differentials, limit] = injectivity_step(M, phi, i+1, names, [M, phi, names, degrees, differentials, limit] = injectivity_step(M, phi, i+1, names,
@ -207,19 +195,3 @@ def minimal_model(S, max_depth=5, max_dim=5):
break break
return [M, phi, cohomology_correspondence] return [M, phi, cohomology_correspondence]
#######################################################
# TESTS
S1 = simplicial_complexes.Sphere(2)
S2 = simplicial_complexes.Sphere(2)
S = S1.wedge(S2, is_mutable=False)
#######################################################
#S = simplicial_complexes.ComplexProjectivePlane()
#######################################################
# S = simplicial_complexes.BrucknerGrunbaumSphere()
#######################################################
# S = simplicial_complexes.ProjectivePlane().wedge(simplicial_complexes.Sphere(2), is_mutable=False)
#######################################################
[sullivan_model, model_morphism, cohomology_correspondence] = minimal_model(S, max_depth=5, max_dim=10)
sullivan_model