diff --git a/aplK.py b/aplK.py index 3d63e2a..04c3578 100644 --- a/aplK.py +++ b/aplK.py @@ -145,7 +145,8 @@ class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation): """ Return "True" if "self" is homogeneous and "False" otherwise. """ - + if self.is_zero(): + return True degrees = set([k[0] for k in self.homogeneous_parts()]) return len(degrees) == 1 @@ -153,8 +154,10 @@ class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation): """ Return the total degree of this element. """ - - degrees = set([k[0] for k in self.homogeneous_parts()]) + homParts = self.homogeneous_parts() + if not homParts: # the polynomial is equal to zero + return self.parent().n + degrees = set([k[0] for k in homParts]) return max(degrees) def homogeneous_part(self, degree): @@ -748,9 +751,10 @@ class AlgebraAplK(UniqueRepresentation, Parent): def _faces_of_length(self, simplex, length): """ - Returns all faces of dimension 'length' for a given simplex + Returns all faces of dimension 'length' for a given simplex 's' """ - return [tuple(e) for e in Set(simplex).subsets(length)] + return [tuple(l) for l in list(powerset(simplex)) if len(l)==length] + #return [tuple(e) for e in Set(simplex).subsets(length)] @cached_function def zero(self): @@ -802,12 +806,12 @@ class AlgebraAplK(UniqueRepresentation, Parent): k) == n+1] # keys of the n-simplices for k in keys: simplicial_structure[k] = values[k] + \ - self._propagate(cochain, k) + self._propagate(cochain, k, values) # print(simplicial_structure) return AlgebraAplK.Element(self, simplicial_structure) - def _propagate(self, cochain, simplex): + def _propagate(self, cochain, simplex, values): """ Returns the part of the polynomial assigned to 'simplex' related to the propagation of the simplicial information of its faces @@ -815,21 +819,25 @@ class AlgebraAplK(UniqueRepresentation, Parent): dim = len(simplex)-1 apl = SimplicialAlgebraplN(dim) propagation = apl(0) + S = Simplex(simplex) for n in reversed(range(dim)): faces = self._faces_of_length(simplex, n+1) apl = SimplicialAlgebraplN(n) # we propagate the polynomial (y_1...y_n) - pol = apl(prod(apl.gens()[n+2:])) - dict_set_keys = {c:set(c) for c in cochain.keys()} - for f in faces: #CUIDADO AQUÍ CON CÓMO ESTÁN ORDENADOS LOS IDENTIFICADORES DE LOS SIMPLICES + #pol = apl(prod(apl.gens()[n+2:])) + dict_set_keys = {c:set(c) for c in values.keys()} + for f in faces: #CUIDADO AQUÍ CON CÓMO ESTÁN ORDENADOS LOS IDENTIFICADORES DE LOS SIMPLICES if set(f) in dict_set_keys.values(): + #print("Dim "+str(n), "cochain: ",cochain[f],"pol: ", pol, flush=True) + pol = values[f] face = [k for k, v in dict_set_keys.items() if v == set(f)][0] # get_keys_from_value(dict, value) - value = cochain[face] + #value = cochain[face] face_indexes = [simplex.index(i) for i in face] #print("dim: ",n," pol: ",pol," face_idx: ",face_indexes) - propagation += value * \ - ((1) ** ((n * (n-1)) // 2)) * factorial(n) * \ - pol.propagate(face_indexes, dim) + #propagation += value * \ + # ((1) ** ((n * (n-1)) // 2)) * factorial(n) * \ + # pol.propagate(face_indexes, dim) + propagation += pol.propagate(face_indexes, dim) return propagation @cached_function @@ -1059,7 +1067,7 @@ class AlgebraAplK(UniqueRepresentation, Parent): #print("face: " + str(f),"simplex: " + str(simplex),"sFace: " + str(self.elements[sFace]), "aFace: " + str(aFace)) if(self.elements[sFace] != aFace): raise ValueError("the assignation is not valid") - print("Check ok", flush=True) + #print("Check ok", flush=True) return True def differential(self):