parece que funciona

This commit is contained in:
carlos alquezar 2022-04-07 12:52:21 +02:00
parent c88a275df8
commit 7dbf5344c0
2 changed files with 40 additions and 12 deletions

27
aplK.py
View File

@ -3,7 +3,7 @@ from sage.structure.parent import Parent
from sage.structure.element import Element from sage.structure.element import Element
from sage.structure.richcmp import rich_to_bool, op_EQ, op_NE, op_LT, op_LE, op_GT, op_GE from sage.structure.richcmp import rich_to_bool, op_EQ, op_NE, op_LT, op_LE, op_GT, op_GE
from sage.rings.polynomial.polydict import ETuple from sage.rings.polynomial.polydict import ETuple
import copy from copy import deepcopy
class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation): class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation):
""" """
@ -235,7 +235,7 @@ class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation):
n = len(exp)//2 n = len(exp)//2
if (exp[n+idx]==0): if (exp[n+idx]==0):
raise IndexError("It is not possible to get a primitive using the given idx.") raise IndexError("It is not possible to get a primitive using the given idx.")
primitive = list(copy.deepcopy(exp)) primitive = list(deepcopy(exp))
primitive[n+idx] = 0 primitive[n+idx] = 0
primitive[idx] += 1 primitive[idx] += 1
new_coef = coef/primitive[idx] new_coef = coef/primitive[idx]
@ -454,7 +454,7 @@ class SimplicialAplN(AplN, UniqueRepresentation):
graded_part = apl(0) graded_part = apl(0)
for i in reversed(indexes): for i in reversed(indexes):
t = t_gens[i] t = t_gens[i]
y_prod = copy.deepcopy(y_gens) y_prod = deepcopy(y_gens)
del y_prod[i] del y_prod[i]
y_prod = prod(y_prod) y_prod = prod(y_prod)
graded_part += ((-1)**i)*t*y_prod#((-1)**(simplex_dim+i))*t*y_prod graded_part += ((-1)**i)*t*y_prod#((-1)**(simplex_dim+i))*t*y_prod
@ -476,7 +476,7 @@ class SimplicialAplN(AplN, UniqueRepresentation):
n_vars = len(monomial) // 2 n_vars = len(monomial) // 2
combinations = [] combinations = []
for i in range(n_vars): for i in range(n_vars):
mono = list(copy.deepcopy(monomial)) mono = list(deepcopy(monomial))
if mono[n_vars+i]: if mono[n_vars+i]:
mono[i] += 1 mono[i] += 1
mono[n_vars+i] = 0 mono[n_vars+i] = 0
@ -486,7 +486,7 @@ class SimplicialAplN(AplN, UniqueRepresentation):
def _add_kernel_terms_to_primitive_basis(self, basis): def _add_kernel_terms_to_primitive_basis(self, basis):
new_elements = [] new_elements = []
for e in basis: for e in basis:
monomial = list(copy.deepcopy(e)) monomial = list(deepcopy(e))
n = len(e) // 2 n = len(e) // 2
monomial[:n] = n*[0] monomial[:n] = n*[0]
new_elements.append(tuple(monomial)) new_elements.append(tuple(monomial))
@ -673,9 +673,9 @@ class AlgebraAplK(UniqueRepresentation, Parent):
""" """
return [tuple(e) for e in Set(simplex).subsets(length)] return [tuple(e) for e in Set(simplex).subsets(length)]
def null_element(self): def zero(self):
""" """
Returns the null element of the algebra respect to the addition operation Returns the zero element of the algebra
""" """
values = {} values = {}
for i in range(self.K.dimension()+1): for i in range(self.K.dimension()+1):
@ -684,6 +684,19 @@ class AlgebraAplK(UniqueRepresentation, Parent):
values[tuple(f)]=s(0) values[tuple(f)]=s(0)
return self._element_constructor_(values) return self._element_constructor_(values)
def one(self):
"""
Returns the one element of the algebra
"""
values = {}
for i in range(self.K.dimension()+1):
s = SimplicialAlgebraplN(i)
for f in self.K._n_cells_sorted(i):
values[tuple(f)]=s(1)
return self._element_constructor_(values)
null_element = zero
def lift_cochain(self, cochain): def lift_cochain(self, cochain):
""" """
Returns an element of the algebra Apl(K) whose integral is the cochain given as input. Returns an element of the algebra Apl(K) whose integral is the cochain given as input.

View File

@ -1,18 +1,33 @@
def phi_polinomial(pol, model_morphism, A): def phi_polinomial(pol, model_morphism, A):
pol_keys = pol.dict().keys() pol_keys = pol.dict().keys()
gens = pol.parent().gens() m_gens = pol.parent().gens()[:-1]
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 = [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*prod([gen**e for gen,e in zip(aplkGens, exp)]) term = coef*A.one()
for i in range(len(exp)-1):
e = exp[i]
if e:
aGen = aplkGens[i]
# print()
# print("term antes")
# print(term)
# print("aGen**e")
# print(aGen**e)
term *= aGen**e
# print("term después")
# print(term)
#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()
@ -135,7 +150,7 @@ def surjective_step(A, M, phi, dim, names, degrees, differentials, cohomology_co
phi_n_map[new_var] = g[gen_key] phi_n_map[new_var] = g[gen_key]
correspondence_n_map[new_var] = cohomology_gens[gen_key] correspondence_n_map[new_var] = cohomology_gens[gen_key]
gca = GradedCommutativeAlgebra(QQ, names=new_names, degrees=new_degrees) gca = GradedCommutativeAlgebra(QQ, names=new_names, degrees=new_degrees)
new_M = update_cdga(gca, differentials) new_M = gca.cdg_algebra(differentials)
new_phi[dim] = phi_n_map new_phi[dim] = phi_n_map
new_correspondence[dim] = correspondence_n_map new_correspondence[dim] = correspondence_n_map
return [new_M, new_phi, new_names, new_degrees, new_correspondence] return [new_M, new_phi, new_names, new_degrees, new_correspondence]