Investigating branches of the logarithm.
Requirements: ore_algebra package
# Define the rings of differential and shift operators
from ore_algebra import *
Ind.<n> = PolynomialRing(QQ); Shift.<Sn> = OreAlgebra(Ind)
Pols.<z> = PolynomialRing(QQ); Diff.<Dz> = OreAlgebra(Pols)
# Any branch of the natural logarithm satisfies the D-finite equation
diff = z*Dz^2 + Dz
# As for the last example on algebraic roots, we can start with a fixed value of the logarithm at a fixed point
# and locally compute branches of the logarithm using numeric analytic continuation. Here we start with log(1)=0
# and approximate log(2). The initial conditions are the first two series coefficients of log(z) at z=1.
diff.numerical_solution(ini=[0,1], path=[1, 2], eps=1e-100)
[0.693147180559945309417232121458176568075500134360255254120680009493393621969694715605863326996418687542 +/- 5.34e-103]
# This approximates the "usual" (principal branch) value of log(2)
log(2).n(333)
0.693147180559945309417232121458176568075500134360255254120680009493393621969694715605863326996418688
# We can continue this branch in a circle around the origin
diff.numerical_solution(ini=[0,1], path=[1, I, -1, -I, 1], eps=1e-100)
[+/- 1.72e-106] + [6.283185307179586476925286766559005768394338798750211641949889184615632812572417997256069650684234135964 +/- 5.31e-103]*I
# This is an approximation to 2*pi*I
(2*pi*I).n(333)
6.28318530717958647692528676655900576839433879875021164194988918461563281257241799725606965068423414*I
# Unlike algebraic roots, continually circling the origin just keeps adding 2*pi*I -- we never return to the original branch
circle = [1, I, -1, -I]
print(diff.numerical_solution(ini=[0,1], path=circle + [1], eps=1e-100)) # circle once
print(diff.numerical_solution(ini=[0,1], path=2*circle + [1], eps=1e-100)) # circle twice
print(diff.numerical_solution(ini=[0,1], path=3*circle + [1], eps=1e-100)) # circle thrice
print(diff.numerical_solution(ini=[0,1], path=4*circle + [1], eps=1e-100)) # circle four times
[+/- 1.72e-106] + [6.283185307179586476925286766559005768394338798750211641949889184615632812572417997256069650684234135964 +/- 5.31e-103]*I [+/- 8.00e-105] + [12.566370614359172953850573533118011536788677597500423283899778369231265625144835994512139301368468271928 +/- 7.34e-103]*I [+/- 3.26e-103] + [18.84955592153875943077586029967701730518301639625063492584966755384689843771725399176820895205270240789 +/- 3.86e-102]*I [+/- 1.32e-101] + [25.1327412287183459077011470662360230735773551950008465677995567384625312502896719890242786027369365439 +/- 5.66e-101]*I