Hi
If I would like to generate my own symbolic math function : general_falling_factorial(x, j, n) . What I should add and modify in the code below ?
j,n=var('j,n')
N=11
show(LatexExpr(r"B_n=\sum_{j=1}^{n+1}\frac{(-1)^{j-1}}{j}{n+1\choose j}\sum_{i=0}^{j-1}(i|j)_n"))
show(LatexExpr(r"\text{with }\, \,(i|j)_n:=i(i-j)\cdots(i-(n-1)j)= \
\text{general_falling_factorial() is not the falling_factorial() SageMath Function} \
\, = \, "),falling_factorial(x, n))
print "https://math.stackexchange.com/questions/497616/is-there-an-explicit-formula-for-the-bernoulli-numbers-that-doesnt-implicitly-r"
print "http://youngp.people.cofc.edu/factbern.pdf"
show(LatexExpr(r"B_n=\sum_{j=1}^{n+1}\frac{(-1)^{j-1}}{j}{n+1\choose j}\sum_{i=0}^{j-1}(i|j)_n"))
show(LatexExpr(r"\text{with }\, \,(i|j)_n:=i(i-j)\cdots(i-(n-1)j)"))
def general_falling_factorial_latex(self, x,j,n):
return '{' + '('+str(i) + ' | ' + str(j) + ')'+'}_{' + str(n) + '}'
general_falling_factorial = function('general_falling_factorial', nargs=3, print_latex_func=general_falling_factorial_latex)
def general_falling_factorial(x, j, n):
r""" to fill up """
from sage.symbolic.expression import Expression
from sage.structure.coerce import py_scalar_to_element
x = py_scalar_to_element(x)
j = py_scalar_to_element(j)
n = py_scalar_to_element(n)
if ((isinstance(j, Integer) or
(isinstance(j, Expression) and
j.is_integer())) and j >= 0) and \
((isinstance(n, Integer) or
(isinstance(n, Expression) and
n.is_integer())) and n >= 0) :
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
def bernoulliExplicit(N) :
bernoulliSL=[]
for n in range(0,N) :
bernoulliSLt=[]
for j in range (1,n+2):
#show("j : ",j)
bernoulliSLt.append((((-1)^(j-1)/j) *(factorial(n+1))/((factorial(j)*(factorial((n+1-j))))))* \
sum([general_falling_factorial(i,j,n) for i in range(0,j)]))
bernoulliSL.append(sum(bernoulliSLt))
return bernoulliSL
show("Explicit Bernoulli List : ",bernoulliExplicit(N))
bernoulliL=[]
for i in range(0,N) :
bernoulliL.append(bernoulli(i))
show("SageMath Bernoulli List : ",bernoulliL)