Derive a D-finite equation for a rational period integral.
Requirements: ore_algebra package
# Define function to help with latex typesetting
def le(s): return LatexExpr(s)
# Introduce our domains for computations, and define f
S.<t> = QQ['t']
R.<x> = S.fraction_field()['x']
# Our goal is to determine a differential equation for the integral
f = -x^2-t+x
F = 1/f
show("G(t) =", le("\\int_{|x|=1/2}"), F, le("dx"))
# We do this by relating F to
show(le("\\frac{dF}{dt} = "), diff(F,t).factor())
# Since the derivative has a higher exponent in the denominator, we use the Euclidean algorithm to write
r,a,b = f.xgcd(diff(f,x))
show(le("1 = A \\cdot f + B \\cdot \\frac{df}{dx}"), " where A = ", SR(a), " and B = ", SR(b))
# Thus, we see
show(le("\\frac{dF}{dt} = 1 \\cdot \\frac{dF}{dt} = \\left(A\\cdot f + B \\frac{df}{dx}\\right)"), diff(F,t).factor())
# Note the chain rule implies that for any function B(x)
show(le("\\frac{d}{dx}\\frac{B(x)}{f(x)} = - \\frac{df}{dx}\\frac{B(x)}{f(x)^2} + \\frac{1}{f(x)}\\frac{dB}{dx}"))
# Thus, we have the relation
show(diff(F,t).factor() , le(" = "), SR(-a/f - diff(b,x)/f), " + ", le("\\frac{d}{dx}"), -SR(b/f).factor())
Clearing the factor of $(4t-1)$ from the denominator gives the relation [ (4t-1) \frac{d}{dt}F(x,t) + 2F(t) = \frac{d}{dx}\left(\frac{1-2x}{f(x,t)}\right) ]
# This relation is easily verified
simplify((4*t-1)*diff(F,t) + 2*F - diff((1-2*x)*F,x))
0
# Integrating with respect to x kills the right-hand side
var('θ')
var('t'); assume(t<1/4, sqrt(1-4*t)-1>0)
integral(diff((1-2*x)*F,x).subs(x=exp(I*θ)/2)*exp(I*θ)*I/2,θ,-pi,pi)
0
# Thus, we have the following differential equation
show(le("(4t-1) G'(t) + 2G(t) = 0"))
# And initial condition
show(le("G(0) = "), integral(((1-2*x)*F(t=0)).subs(x=exp(I*θ)/2)*exp(I*θ)*I/2,θ,-pi,pi)/2/pi/I)
# We can solve this differential equation to get G(t)
var('T')
g = function('g')(T)
assume(0<T,T<1/4)
gf = desolve((4*T-1)*diff(g,T) + 2*g, g, [0,1]).simplify_full()
gf
1/sqrt(-4*T + 1)
# This is the generating function of the general binomial coefficients
print([k for [k,n] in gf.series(T,10).coefficients()])
[binomial(2*k,k) for k in range(10)]
[1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620]
[1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620]