sum and Substitute
Hi
why Ds (like D ) does not give a numerical value ?
fs_d=r"!n \triangleq n! \sum_{i = 0}^{n}\frac{(-1)^i}{i!}"
#https://en.wikipedia.org/wiki/Derangement
forget()
var('n,l')
assume(l, 'integer')
assume(l>0)
assume(l, 'integer')
assume(n, 'integer')
assume(n>l)
assume(n, 'integer')
# Derangement
D=function('D')(n,l)
Dn=function('Dn')(n,l)
Dn=factorial(n)*sum(((-1)^l/factorial(l)),l,0,n)
D=factorial(7)*sum(((-1)^l/factorial(l)),l,0,7)
Ds=Dn.substitute({n:7})
show(LatexExpr(fs_d))
show('D : ',D)
show('Ds : ',Ds)