test_spence.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import numpy as np
  2. from numpy import sqrt, log, pi
  3. from scipy.special._testutils import FuncData
  4. from scipy.special import spence
  5. def test_consistency():
  6. # Make sure the implementation of spence for real arguments
  7. # agrees with the implementation of spence for imaginary arguments.
  8. x = np.logspace(-30, 300, 200)
  9. dataset = np.vstack((x + 0j, spence(x))).T
  10. FuncData(spence, dataset, 0, 1, rtol=1e-14).check()
  11. def test_special_points():
  12. # Check against known values of Spence's function.
  13. phi = (1 + sqrt(5))/2
  14. dataset = [(1, 0),
  15. (2, -pi**2/12),
  16. (0.5, pi**2/12 - log(2)**2/2),
  17. (0, pi**2/6),
  18. (-1, pi**2/4 - 1j*pi*log(2)),
  19. ((-1 + sqrt(5))/2, pi**2/15 - log(phi)**2),
  20. ((3 - sqrt(5))/2, pi**2/10 - log(phi)**2),
  21. (phi, -pi**2/15 + log(phi)**2/2),
  22. # Corrected from Zagier, "The Dilogarithm Function"
  23. ((3 + sqrt(5))/2, -pi**2/10 - log(phi)**2)]
  24. dataset = np.asarray(dataset)
  25. FuncData(spence, dataset, 0, 1, rtol=1e-14).check()