test_spence.py 1.1 KB

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