m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.7 KiB

6 months ago
  1. from sympy.core.function import (diff, expand_func)
  2. from sympy.core.numbers import I
  3. from sympy.core.symbol import (Dummy, symbols)
  4. from sympy.functions.elementary.complexes import conjugate
  5. from sympy.functions.special.beta_functions import (beta, betainc, betainc_regularized)
  6. from sympy.functions.special.gamma_functions import gamma
  7. from sympy.functions.special.hyper import hyper
  8. from sympy.integrals.integrals import Integral
  9. from sympy.functions.special.gamma_functions import polygamma
  10. from sympy.core.function import ArgumentIndexError
  11. from sympy.core.expr import unchanged
  12. from sympy.testing.pytest import raises
  13. def test_beta():
  14. x, y = symbols('x y')
  15. t = Dummy('t')
  16. assert unchanged(beta, x, y)
  17. assert beta(5, -3).is_real == True
  18. assert beta(3, y).is_real is None
  19. assert expand_func(beta(x, y)) == gamma(x)*gamma(y)/gamma(x + y)
  20. assert expand_func(beta(x, y) - beta(y, x)) == 0 # Symmetric
  21. assert expand_func(beta(x, y)) == expand_func(beta(x, y + 1) + beta(x + 1, y)).simplify()
  22. assert diff(beta(x, y), x) == beta(x, y)*(polygamma(0, x) - polygamma(0, x + y))
  23. assert diff(beta(x, y), y) == beta(x, y)*(polygamma(0, y) - polygamma(0, x + y))
  24. assert conjugate(beta(x, y)) == beta(conjugate(x), conjugate(y))
  25. raises(ArgumentIndexError, lambda: beta(x, y).fdiff(3))
  26. assert beta(x, y).rewrite(gamma) == gamma(x)*gamma(y)/gamma(x + y)
  27. assert beta(x).rewrite(gamma) == gamma(x)**2/gamma(2*x)
  28. assert beta(x, y).rewrite(Integral).dummy_eq(Integral(t**(x - 1) * (1 - t)**(y - 1), (t, 0, 1)))
  29. def test_betainc():
  30. a, b, x1, x2 = symbols('a b x1 x2')
  31. assert unchanged(betainc, a, b, x1, x2)
  32. assert unchanged(betainc, a, b, 0, x1)
  33. assert betainc(1, 2, 0, -5).is_real == True
  34. assert betainc(1, 2, 0, x2).is_real is None
  35. assert conjugate(betainc(I, 2, 3 - I, 1 + 4*I)) == betainc(-I, 2, 3 + I, 1 - 4*I)
  36. assert betainc(a, b, 0, 1).rewrite(Integral).dummy_eq(beta(a, b).rewrite(Integral))
  37. assert betainc(1, 2, 0, x2).rewrite(hyper) == x2*hyper((1, -1), (2,), x2)
  38. assert betainc(1, 2, 3, 3).evalf() == 0
  39. def test_betainc_regularized():
  40. a, b, x1, x2 = symbols('a b x1 x2')
  41. assert unchanged(betainc_regularized, a, b, x1, x2)
  42. assert unchanged(betainc_regularized, a, b, 0, x1)
  43. assert betainc_regularized(3, 5, 0, -1).is_real == True
  44. assert betainc_regularized(3, 5, 0, x2).is_real is None
  45. assert conjugate(betainc_regularized(3*I, 1, 2 + I, 1 + 2*I)) == betainc_regularized(-3*I, 1, 2 - I, 1 - 2*I)
  46. assert betainc_regularized(a, b, 0, 1).rewrite(Integral) == 1
  47. assert betainc_regularized(1, 2, x1, x2).rewrite(hyper) == 2*x2*hyper((1, -1), (2,), x2) - 2*x1*hyper((1, -1), (2,), x1)
  48. assert betainc_regularized(4, 1, 5, 5).evalf() == 0