Make sure computing half is an integer, and caching method
In some cases taking half of an integer results in a fractional type (even if it represents an integer number). This causes problems with indices, so this change uses division with quotient and remainder instead. Also, it caches the degeneration morphism, which is expensive to create.
This commit is contained in:
parent
2c2d2aeac0
commit
71cb7aef68
15
aplK.py
15
aplK.py
@ -147,7 +147,7 @@ class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation):
|
|||||||
denominator += e
|
denominator += e
|
||||||
coef = pol.dict()[k]
|
coef = pol.dict()[k]
|
||||||
result += coef*numerator/factorial(denominator)
|
result += coef*numerator/factorial(denominator)
|
||||||
#return ((-1)**(apl.n*(apl.n-1)/2))*result
|
#return ((-1) ** ((apl.n*(apl.n-1)) // 2)) * result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _get_term(self, coef, exp, gens):
|
def _get_term(self, coef, exp, gens):
|
||||||
@ -378,6 +378,7 @@ class SimplicialAplN(AplN, UniqueRepresentation):
|
|||||||
|
|
||||||
return self.face_morphism(i)(self)
|
return self.face_morphism(i)(self)
|
||||||
|
|
||||||
|
@cached_method
|
||||||
def degeneration_morphism(self,j):
|
def degeneration_morphism(self,j):
|
||||||
""""
|
""""
|
||||||
|
|
||||||
@ -472,7 +473,7 @@ class SimplicialAplN(AplN, UniqueRepresentation):
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
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(copy.deepcopy(monomial))
|
||||||
@ -486,7 +487,7 @@ class SimplicialAplN(AplN, UniqueRepresentation):
|
|||||||
new_elements = []
|
new_elements = []
|
||||||
for e in basis:
|
for e in basis:
|
||||||
monomial = list(copy.deepcopy(e))
|
monomial = list(copy.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))
|
||||||
return new_elements
|
return new_elements
|
||||||
@ -505,7 +506,7 @@ class SimplicialAplN(AplN, UniqueRepresentation):
|
|||||||
terms = []
|
terms = []
|
||||||
apl = self.parent()
|
apl = self.parent()
|
||||||
for b in basis:
|
for b in basis:
|
||||||
dim = len(monomial)/2-1
|
dim = len(monomial)//2 - 1
|
||||||
terms.append(self._get_term(1, b, apl.gens()))
|
terms.append(self._get_term(1, b, apl.gens()))
|
||||||
terms.sort(reverse=False)
|
terms.sort(reverse=False)
|
||||||
return terms
|
return terms
|
||||||
@ -696,7 +697,7 @@ class AlgebraAplK(UniqueRepresentation, Parent):
|
|||||||
max_dim = dim
|
max_dim = dim
|
||||||
apl = SimplicialAlgebraplN(dim)
|
apl = SimplicialAlgebraplN(dim)
|
||||||
if dim>0:
|
if dim>0:
|
||||||
values[k] = ((-1)**(dim*(dim-1)/2))*apl.integrand(cochain[k])
|
values[k] = ((-1) ** ((dim * (dim-1)) // 2)) * apl.integrand(cochain[k])
|
||||||
else:
|
else:
|
||||||
values[k]= apl(cochain[k])
|
values[k]= apl(cochain[k])
|
||||||
|
|
||||||
@ -726,7 +727,7 @@ class AlgebraAplK(UniqueRepresentation, Parent):
|
|||||||
value = cochain[f]
|
value = cochain[f]
|
||||||
face_indexes = [simplex.index(i) for i in f]
|
face_indexes = [simplex.index(i) for i in f]
|
||||||
#print("dim: ",n," pol: ",pol," face_idx: ",face_indexes," dim: ", n)
|
#print("dim: ",n," pol: ",pol," face_idx: ",face_indexes," dim: ", n)
|
||||||
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)
|
||||||
return propagation
|
return propagation
|
||||||
|
|
||||||
def cohomology_gens(self,degree):
|
def cohomology_gens(self,degree):
|
||||||
@ -1029,7 +1030,7 @@ class AlgebraAplK(UniqueRepresentation, Parent):
|
|||||||
for k in self.elements.keys():
|
for k in self.elements.keys():
|
||||||
dim = len(k)-1
|
dim = len(k)-1
|
||||||
# the sign is due to stoke's theorem
|
# the sign is due to stoke's theorem
|
||||||
cochain[k] = ((-1)**(dim*(dim-1)/2))*self.elements[k].integral()
|
cochain[k] = ((-1) ** ((dim * (dim-1)) // 2)) * self.elements[k].integral()
|
||||||
return cochain
|
return cochain
|
||||||
|
|
||||||
def _face_basis(self, basis, face_idx):
|
def _face_basis(self, basis, face_idx):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user