def QuadraticBernoulliNumber(k, d): r""" Compute `k`-th Bernoulli number for the primitive quadratic character associated to `\chi(x) = \left(\frac{d}{x}\right)`. EXAMPLES: Let us create a list of some odd negative fundamental discriminants:: sage: test_set = [d for d in range(-163, -3, 4) if is_fundamental_discriminant(d)] In general, we have `B_{1, \chi_d} = -2 h/w` for odd negative fundamental discriminants:: sage: all(QuadraticBernoulliNumber(1, d) == -len(BinaryQF_reduced_representatives(d)) for d in test_set) True REFERENCES: - [Iwa1972]_, pp 7-16. """ # Ensure the character is primitive d1 = fundamental_discriminant(d) f = abs(d1) # Make the (usual) k-th Bernoulli polynomial x = PolynomialRing(QQ, 'x').gen() bp = bernoulli_polynomial(x, k) # Make the k-th quadratic Bernoulli number total = sum([kronecker_symbol(d1, i) * bp(i / f) for i in range(f)]) total *= (f**(k - 1)) return total
def QuadraticBernoulliNumber(k, d): r""" Compute k-th Bernoulli number for the primitive quadratic character associated to `\chi(x) = \left(\frac{d}{x}\right)`. Reference: Iwasawa's "Lectures on p-adic L-functions", pp7-16. EXAMPLES:: sage: ## Makes a set of odd fund discriminants < -3 sage: Fund_odd_test_set = [D for D in range(-163, -3, 4) if is_fundamental_discriminant(D)] sage: ## In general, we have B_{1, \chi_d} = -2h/w for odd fund disc < 0 sage: for D in Fund_odd_test_set: ... if len(BinaryQF_reduced_representatives(D)) != -QuadraticBernoulliNumber(1, D): ... print "Oops! There is an error at D = ", D """ ## Ensure the character is primitive d1 = fundamental_discriminant(d) f = abs(d1) ## Make the (usual) k-th Bernoulli polynomial x = PolynomialRing(QQ, 'x').gen() bp = bernoulli_polynomial(x, k) ## Make the k-th quadratic Bernoulli number total = sum([kronecker_symbol(d1, i) * bp(i/f) for i in range(f)]) total *= (f ** (k-1)) return total
def QuadraticBernoulliNumber(k, d): r""" Compute `k`-th Bernoulli number for the primitive quadratic character associated to `\chi(x) = \left(\frac{d}{x}\right)`. EXAMPLES: Let us create a list of some odd negative fundamental discriminants:: sage: test_set = [d for d in range(-163, -3, 4) if is_fundamental_discriminant(d)] In general, we have `B_{1, \chi_d} = -2 h/w` for odd negative fundamental discriminants:: sage: all(QuadraticBernoulliNumber(1, d) == -len(BinaryQF_reduced_representatives(d)) for d in test_set) True REFERENCES: - [Iwa1972]_, pp 7-16. """ # Ensure the character is primitive d1 = fundamental_discriminant(d) f = abs(d1) # Make the (usual) k-th Bernoulli polynomial x = PolynomialRing(QQ, 'x').gen() bp = bernoulli_polynomial(x, k) # Make the k-th quadratic Bernoulli number total = sum([kronecker_symbol(d1, i) * bp(i/f) for i in range(f)]) total *= (f ** (k-1)) return total
def QuadraticBernoulliNumber(k, d): r""" Compute k-th Bernoulli number for the primitive quadratic character associated to `\chi(x) = \left(\frac{d}{x}\right)`. Reference: Iwasawa's "Lectures on p-adic L-functions", pp7-16. EXAMPLES:: sage: ## Makes a set of odd fund discriminants < -3 sage: Fund_odd_test_set = [D for D in range(-163, -3, 4) if is_fundamental_discriminant(D)] sage: ## In general, we have B_{1, \chi_d} = -2h/w for odd fund disc < 0 sage: for D in Fund_odd_test_set: ... if len(BinaryQF_reduced_representatives(D)) != -QuadraticBernoulliNumber(1, D): ... print "Oops! There is an error at D = ", D """ ## Ensure the character is primitive d1 = fundamental_discriminant(d) f = abs(d1) ## Make the (usual) k-th Bernoulli polynomial x = PolynomialRing(QQ, 'x').gen() bp = bernoulli_polynomial(x, k) ## Make the k-th quadratic Bernoulli number total = sum([kronecker_symbol(d1, i) * bp(i / f) for i in range(f)]) total *= (f**(k - 1)) return total
def _eval_(self, s, x): r""" TESTS:: sage: hurwitz_zeta(x, 1) zeta(x) sage: hurwitz_zeta(4, 3) 1/90*pi^4 - 17/16 sage: hurwitz_zeta(-4, x) -1/5*x^5 + 1/2*x^4 - 1/3*x^3 + 1/30*x sage: hurwitz_zeta(3, 0.5) 8.41439832211716 """ if x == 1: return zeta(s) if s in ZZ and s > 1: return ((-1)**s) * psi(s - 1, x) / factorial(s - 1) elif s in ZZ and s < 0: return -bernoulli_polynomial(x, -s + 1) / (-s + 1) else: return
def _eval_(self, s, x): r""" TESTS:: sage: hurwitz_zeta(x, 1) zeta(x) sage: hurwitz_zeta(4, 3) 1/90*pi^4 - 17/16 sage: hurwitz_zeta(-4, x) -1/5*x^5 + 1/2*x^4 - 1/3*x^3 + 1/30*x sage: hurwitz_zeta(3, 0.5) 8.41439832211716 """ if x == 1: return zeta(s) if s in ZZ and s > 1: return ((-1) ** s) * psi(s - 1, x) / factorial(s - 1) elif s in ZZ and s < 0: return -bernoulli_polynomial(x, -s + 1) / (-s + 1) else: return
def _eval_(self, s, x): r""" TESTS:: sage: hurwitz_zeta(x, 1) zeta(x) sage: hurwitz_zeta(4, 3) 1/90*pi^4 - 17/16 sage: hurwitz_zeta(-4, x) -1/5*x^5 + 1/2*x^4 - 1/3*x^3 + 1/30*x sage: hurwitz_zeta(3, 0.5) 8.41439832211716 """ co = get_coercion_model().canonical_coercion(s, x)[0] if is_inexact(co) and not isinstance(co, Expression): return self._evalf_(s, x, parent=parent(co)) if x == 1: return zeta(s) if s in ZZ and s > 1: return ((-1)**s) * psi(s - 1, x) / factorial(s - 1) elif s in ZZ and s < 0: return -bernoulli_polynomial(x, -s + 1) / (-s + 1) else: return
def _eval_(self, s, x): r""" TESTS:: sage: hurwitz_zeta(x, 1) zeta(x) sage: hurwitz_zeta(4, 3) 1/90*pi^4 - 17/16 sage: hurwitz_zeta(-4, x) -1/5*x^5 + 1/2*x^4 - 1/3*x^3 + 1/30*x sage: hurwitz_zeta(3, 0.5) 8.41439832211716 """ co = get_coercion_model().canonical_coercion(s, x)[0] if is_inexact(co) and not isinstance(co, Expression): return self._evalf_(s, x, parent=parent(co)) if x == 1: return zeta(s) if s in ZZ and s > 1: return ((-1) ** s) * psi(s - 1, x) / factorial(s - 1) elif s in ZZ and s < 0: return -bernoulli_polynomial(x, -s + 1) / (-s + 1) else: return