test_identify.py 692 B

12345678910111213141516171819
  1. from mpmath import *
  2. def test_pslq():
  3. mp.dps = 15
  4. assert pslq([3*pi+4*e/7, pi, e, log(2)]) == [7, -21, -4, 0]
  5. assert pslq([4.9999999999999991, 1]) == [1, -5]
  6. assert pslq([2,1]) == [1, -2]
  7. def test_identify():
  8. mp.dps = 20
  9. assert identify(zeta(4), ['log(2)', 'pi**4']) == '((1/90)*pi**4)'
  10. mp.dps = 15
  11. assert identify(exp(5)) == 'exp(5)'
  12. assert identify(exp(4)) == 'exp(4)'
  13. assert identify(log(5)) == 'log(5)'
  14. assert identify(exp(3*pi), ['pi']) == 'exp((3*pi))'
  15. assert identify(3, full=True) == ['3', '3', '1/(1/3)', 'sqrt(9)',
  16. '1/sqrt((1/9))', '(sqrt(12)/2)**2', '1/(sqrt(12)/6)**2']
  17. assert identify(pi+1, {'a':+pi}) == '(1 + 1*a)'