Update aplK.py
This commit is contained in:
parent
ea2139bc66
commit
16316bb3da
36
aplK.py
36
aplK.py
@ -145,7 +145,8 @@ class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation):
|
|||||||
"""
|
"""
|
||||||
Return "True" if "self" is homogeneous and "False" otherwise.
|
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()])
|
degrees = set([k[0] for k in self.homogeneous_parts()])
|
||||||
return len(degrees) == 1
|
return len(degrees) == 1
|
||||||
|
|
||||||
@ -153,8 +154,10 @@ class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation):
|
|||||||
"""
|
"""
|
||||||
Return the total degree of this element.
|
Return the total degree of this element.
|
||||||
"""
|
"""
|
||||||
|
homParts = self.homogeneous_parts()
|
||||||
degrees = set([k[0] for k in 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)
|
return max(degrees)
|
||||||
|
|
||||||
def homogeneous_part(self, degree):
|
def homogeneous_part(self, degree):
|
||||||
@ -748,9 +751,10 @@ class AlgebraAplK(UniqueRepresentation, Parent):
|
|||||||
|
|
||||||
def _faces_of_length(self, simplex, length):
|
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
|
@cached_function
|
||||||
def zero(self):
|
def zero(self):
|
||||||
@ -802,12 +806,12 @@ class AlgebraAplK(UniqueRepresentation, Parent):
|
|||||||
k) == n+1] # keys of the n-simplices
|
k) == n+1] # keys of the n-simplices
|
||||||
for k in keys:
|
for k in keys:
|
||||||
simplicial_structure[k] = values[k] + \
|
simplicial_structure[k] = values[k] + \
|
||||||
self._propagate(cochain, k)
|
self._propagate(cochain, k, values)
|
||||||
# print(simplicial_structure)
|
# print(simplicial_structure)
|
||||||
|
|
||||||
return AlgebraAplK.Element(self, 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
|
Returns the part of the polynomial assigned to 'simplex' related to the
|
||||||
propagation of the simplicial information of its faces
|
propagation of the simplicial information of its faces
|
||||||
@ -815,21 +819,25 @@ class AlgebraAplK(UniqueRepresentation, Parent):
|
|||||||
dim = len(simplex)-1
|
dim = len(simplex)-1
|
||||||
apl = SimplicialAlgebraplN(dim)
|
apl = SimplicialAlgebraplN(dim)
|
||||||
propagation = apl(0)
|
propagation = apl(0)
|
||||||
|
S = Simplex(simplex)
|
||||||
for n in reversed(range(dim)):
|
for n in reversed(range(dim)):
|
||||||
faces = self._faces_of_length(simplex, n+1)
|
faces = self._faces_of_length(simplex, n+1)
|
||||||
apl = SimplicialAlgebraplN(n)
|
apl = SimplicialAlgebraplN(n)
|
||||||
# we propagate the polynomial (y_1...y_n)
|
# we propagate the polynomial (y_1...y_n)
|
||||||
pol = apl(prod(apl.gens()[n+2:]))
|
#pol = apl(prod(apl.gens()[n+2:]))
|
||||||
dict_set_keys = {c:set(c) for c in cochain.keys()}
|
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
|
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():
|
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)
|
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]
|
face_indexes = [simplex.index(i) for i in face]
|
||||||
#print("dim: ",n," pol: ",pol," face_idx: ",face_indexes)
|
#print("dim: ",n," pol: ",pol," face_idx: ",face_indexes)
|
||||||
propagation += value * \
|
#propagation += value * \
|
||||||
((1) ** ((n * (n-1)) // 2)) * factorial(n) * \
|
# ((1) ** ((n * (n-1)) // 2)) * factorial(n) * \
|
||||||
pol.propagate(face_indexes, dim)
|
# pol.propagate(face_indexes, dim)
|
||||||
|
propagation += pol.propagate(face_indexes, dim)
|
||||||
return propagation
|
return propagation
|
||||||
|
|
||||||
@cached_function
|
@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))
|
#print("face: " + str(f),"simplex: " + str(simplex),"sFace: " + str(self.elements[sFace]), "aFace: " + str(aFace))
|
||||||
if(self.elements[sFace] != aFace):
|
if(self.elements[sFace] != aFace):
|
||||||
raise ValueError("the assignation is not valid")
|
raise ValueError("the assignation is not valid")
|
||||||
print("Check ok", flush=True)
|
#print("Check ok", flush=True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def differential(self):
|
def differential(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user