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.

66 lines
2.2 KiB

6 months ago
  1. from sympy.parsing.mathematica import mathematica
  2. from sympy.core.sympify import sympify
  3. def test_mathematica():
  4. d = {
  5. '- 6x': '-6*x',
  6. 'Sin[x]^2': 'sin(x)**2',
  7. '2(x-1)': '2*(x-1)',
  8. '3y+8': '3*y+8',
  9. 'ArcSin[2x+9(4-x)^2]/x': 'asin(2*x+9*(4-x)**2)/x',
  10. 'x+y': 'x+y',
  11. '355/113': '355/113',
  12. '2.718281828': '2.718281828',
  13. 'Sin[12]': 'sin(12)',
  14. 'Exp[Log[4]]': 'exp(log(4))',
  15. '(x+1)(x+3)': '(x+1)*(x+3)',
  16. 'Cos[ArcCos[3.6]]': 'cos(acos(3.6))',
  17. 'Cos[x]==Sin[y]': 'cos(x)==sin(y)',
  18. '2*Sin[x+y]': '2*sin(x+y)',
  19. 'Sin[x]+Cos[y]': 'sin(x)+cos(y)',
  20. 'Sin[Cos[x]]': 'sin(cos(x))',
  21. '2*Sqrt[x+y]': '2*sqrt(x+y)', # Test case from the issue 4259
  22. '+Sqrt[2]': 'sqrt(2)',
  23. '-Sqrt[2]': '-sqrt(2)',
  24. '-1/Sqrt[2]': '-1/sqrt(2)',
  25. '-(1/Sqrt[3])': '-(1/sqrt(3))',
  26. '1/(2*Sqrt[5])': '1/(2*sqrt(5))',
  27. 'Mod[5,3]': 'Mod(5,3)',
  28. '-Mod[5,3]': '-Mod(5,3)',
  29. '(x+1)y': '(x+1)*y',
  30. 'x(y+1)': 'x*(y+1)',
  31. 'Sin[x]Cos[y]': 'sin(x)*cos(y)',
  32. 'Sin[x]**2Cos[y]**2': 'sin(x)**2*cos(y)**2',
  33. 'Cos[x]^2(1 - Cos[y]^2)': 'cos(x)**2*(1-cos(y)**2)',
  34. 'x y': 'x*y',
  35. '2 x': '2*x',
  36. 'x 8': 'x*8',
  37. '2 8': '2*8',
  38. '1 2 3': '1*2*3',
  39. ' - 2 * Sqrt[ 2 3 * ( 1 + 5 ) ] ': '-2*sqrt(2*3*(1+5))',
  40. 'Log[2,4]': 'log(4,2)',
  41. 'Log[Log[2,4],4]': 'log(4,log(4,2))',
  42. 'Exp[Sqrt[2]^2Log[2, 8]]': 'exp(sqrt(2)**2*log(8,2))',
  43. 'ArcSin[Cos[0]]': 'asin(cos(0))',
  44. 'Log2[16]': 'log(16,2)',
  45. 'Max[1,-2,3,-4]': 'Max(1,-2,3,-4)',
  46. 'Min[1,-2,3]': 'Min(1,-2,3)',
  47. 'Exp[I Pi/2]': 'exp(I*pi/2)',
  48. 'ArcTan[x,y]': 'atan2(y,x)',
  49. 'Pochhammer[x,y]': 'rf(x,y)',
  50. 'ExpIntegralEi[x]': 'Ei(x)',
  51. 'SinIntegral[x]': 'Si(x)',
  52. 'CosIntegral[x]': 'Ci(x)',
  53. 'AiryAi[x]': 'airyai(x)',
  54. 'AiryAiPrime[5]': 'airyaiprime(5)',
  55. 'AiryBi[x]' :'airybi(x)',
  56. 'AiryBiPrime[7]' :'airybiprime(7)',
  57. 'LogIntegral[4]':' li(4)',
  58. 'PrimePi[7]': 'primepi(7)',
  59. 'Prime[5]': 'prime(5)',
  60. 'PrimeQ[5]': 'isprime(5)'
  61. }
  62. for e in d:
  63. assert mathematica(e) == sympify(d[e])