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
17
aplK.py
17
aplK.py
@ -29,7 +29,7 @@ class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation):
|
||||
- ``differential`` -- a differential
|
||||
"""
|
||||
|
||||
self.n = len(A._names)//2-1
|
||||
self.n = len(A._names) // 2 - 1
|
||||
DifferentialGCAlgebra_multigraded.__init__(self, A, differential)
|
||||
self.t_relation = sum(self.gens()[:self.n+1])-1
|
||||
self.y_relation = sum(self.gens()[self.n+1:])
|
||||
@ -147,7 +147,7 @@ class AplN(DifferentialGCAlgebra_multigraded, UniqueRepresentation):
|
||||
denominator += e
|
||||
coef = pol.dict()[k]
|
||||
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
|
||||
|
||||
def _get_term(self, coef, exp, gens):
|
||||
@ -378,6 +378,7 @@ class SimplicialAplN(AplN, UniqueRepresentation):
|
||||
|
||||
return self.face_morphism(i)(self)
|
||||
|
||||
@cached_method
|
||||
def degeneration_morphism(self,j):
|
||||
""""
|
||||
|
||||
@ -472,7 +473,7 @@ class SimplicialAplN(AplN, UniqueRepresentation):
|
||||
Example:
|
||||
|
||||
"""
|
||||
n_vars = len(monomial)/2
|
||||
n_vars = len(monomial) // 2
|
||||
combinations = []
|
||||
for i in range(n_vars):
|
||||
mono = list(copy.deepcopy(monomial))
|
||||
@ -486,7 +487,7 @@ class SimplicialAplN(AplN, UniqueRepresentation):
|
||||
new_elements = []
|
||||
for e in basis:
|
||||
monomial = list(copy.deepcopy(e))
|
||||
n = len(e)/2
|
||||
n = len(e) // 2
|
||||
monomial[:n] = n*[0]
|
||||
new_elements.append(tuple(monomial))
|
||||
return new_elements
|
||||
@ -505,7 +506,7 @@ class SimplicialAplN(AplN, UniqueRepresentation):
|
||||
terms = []
|
||||
apl = self.parent()
|
||||
for b in basis:
|
||||
dim = len(monomial)/2-1
|
||||
dim = len(monomial)//2 - 1
|
||||
terms.append(self._get_term(1, b, apl.gens()))
|
||||
terms.sort(reverse=False)
|
||||
return terms
|
||||
@ -696,7 +697,7 @@ class AlgebraAplK(UniqueRepresentation, Parent):
|
||||
max_dim = dim
|
||||
apl = SimplicialAlgebraplN(dim)
|
||||
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:
|
||||
values[k]= apl(cochain[k])
|
||||
|
||||
@ -726,7 +727,7 @@ class AlgebraAplK(UniqueRepresentation, Parent):
|
||||
value = cochain[f]
|
||||
face_indexes = [simplex.index(i) for i in f]
|
||||
#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
|
||||
|
||||
def cohomology_gens(self,degree):
|
||||
@ -1029,7 +1030,7 @@ class AlgebraAplK(UniqueRepresentation, Parent):
|
||||
for k in self.elements.keys():
|
||||
dim = len(k)-1
|
||||
# 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
|
||||
|
||||
def _face_basis(self, basis, face_idx):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user