From 7dbf5344c008213f1f3587fb88742ff361a34341 Mon Sep 17 00:00:00 2001 From: carlos alquezar Date: Thu, 7 Apr 2022 12:52:21 +0200 Subject: [PATCH] parece que funciona --- aplK.py | 27 ++++++++++++++++++++------- minimalModel.py | 25 ++++++++++++++++++++----- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/aplK.py b/aplK.py index 8de1933..229af84 100644 --- a/aplK.py +++ b/aplK.py @@ -3,7 +3,7 @@ from sage.structure.parent import Parent 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.rings.polynomial.polydict import ETuple -import copy +from copy import deepcopy class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation): """ @@ -235,7 +235,7 @@ class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation): n = len(exp)//2 if (exp[n+idx]==0): 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[idx] += 1 new_coef = coef/primitive[idx] @@ -454,7 +454,7 @@ class SimplicialAplN(AplN, UniqueRepresentation): graded_part = apl(0) for i in reversed(indexes): t = t_gens[i] - y_prod = copy.deepcopy(y_gens) + y_prod = deepcopy(y_gens) del y_prod[i] y_prod = prod(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 combinations = [] for i in range(n_vars): - mono = list(copy.deepcopy(monomial)) + mono = list(deepcopy(monomial)) if mono[n_vars+i]: mono[i] += 1 mono[n_vars+i] = 0 @@ -486,7 +486,7 @@ class SimplicialAplN(AplN, UniqueRepresentation): def _add_kernel_terms_to_primitive_basis(self, basis): new_elements = [] for e in basis: - monomial = list(copy.deepcopy(e)) + monomial = list(deepcopy(e)) n = len(e) // 2 monomial[:n] = n*[0] new_elements.append(tuple(monomial)) @@ -673,9 +673,9 @@ class AlgebraAplK(UniqueRepresentation, Parent): """ 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 = {} for i in range(self.K.dimension()+1): @@ -683,6 +683,19 @@ class AlgebraAplK(UniqueRepresentation, Parent): for f in self.K._n_cells_sorted(i): values[tuple(f)]=s(0) 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): """ diff --git a/minimalModel.py b/minimalModel.py index d3b2043..3944a19 100644 --- a/minimalModel.py +++ b/minimalModel.py @@ -1,18 +1,33 @@ def phi_polinomial(pol, model_morphism, A): - pol_keys = pol.dict().keys() - 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 = pol.parent().gens()[:-1] + #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] aplkElement = A.null_element() for exp in pol.dict().keys(): coef = pol.dict()[exp] # 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 return aplkElement + def get_ker_elements(sullivan_model, model_morphism, A, dim): # Get the basis of Hm 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] correspondence_n_map[new_var] = cohomology_gens[gen_key] 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_correspondence[dim] = correspondence_n_map return [new_M, new_phi, new_names, new_degrees, new_correspondence]