Advertisement
NLinker

Sympy session

Dec 30th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | None | 0 0
  1. ~/tmp ❯❯❯ conda activate torch1
  2. (torch1) ~/tmp ❯❯❯ python
  3.  
  4. >>> from sympy import *
  5. >>> x = Symbol('x')
  6. >>> y = Symbol('y')
  7. >>> (x + y)**2
  8. (x + y)**2
  9. >>> ((x + y)**2).expand()
  10. x**2 + 2*x*y + y**2
  11. >>>
  12. >>> from sympy.interactive import printing
  13. >>> printing.init_printing(use_latex=True)
  14. >>>
  15. >>>
  16. >>> ((x + y)**2).expand()
  17.  2            2
  18. x  + 2⋅x⋅y + y
  19. >>> init_printing()
  20. >>>
  21. >>>
  22. >>> ((x + y)**2).expand()
  23.  2            2
  24. x  + 2⋅x⋅y + y
  25. >>> a = Integral(cos(x)*exp(x), x)
  26. >>> Eq(a, a.doit())
  27. ⌠                 x           x      
  28. ⎮  x             ℯ ⋅sin(x)   ℯ ⋅cos(x)
  29. ⎮ ℯ ⋅cos(x) dx = ───────── + ─────────
  30. ⌡                    2           2    
  31. >>>
  32. >>>
  33. >>> (sqrt(2-x) + sqrt(2+x)).factor()
  34.   ________     _______
  35. ╲╱ -x + 2  + ╲╱ x + 2
  36. >>> (-x) + sqrt(2+x)).factor()
  37. KeyboardInterrupt
  38. >>> (4 + 2*sqrt(2-x)*sqrt(2+x)).factor()
  39.   ⎛  ________   _______    ⎞
  40. 2⋅⎝╲╱ -x + 2 ⋅╲╱ x + 2  + 2
  41. >>> (4 - x + x + 2*sqrt(2-x)*sqrt(2+x)).factor()
  42.   ⎛  ________   _______    ⎞
  43. 2⋅⎝╲╱ -x + 2 ⋅╲╱ x + 2  + 2
  44. >>> (x**2 + 2*x + 1).factor()
  45.        2
  46. (x + 1)
  47. >>> (x**3 - sqrt(2-x)**3).factor()
  48.  3       ________       ________
  49. x  + x⋅╲╱ -x + 2  - 2⋅╲╱ -x + 2
  50. >>> (x**3 - sqrt(2-x)**3).expand
  51. <bound method Expr.expand of x**3 - (-x + 2)**(3/2)>
  52. >>> (x**3 - sqrt(2-x)**3).expand()
  53.  3       ________       ________
  54. x  + x⋅╲╱ -x + 2  - 2⋅╲╱ -x + 2
  55. >>> factor(sqrt(2-x) + sqrt(2+x))
  56.   ________     _______
  57. ╲╱ -x + 2  + ╲╱ x + 2
  58. >>>
  59. >>>
  60. >>> (x**3 - 8*y**6).factor()
  61. ⎛       2⎞ ⎛ 2        2      4
  62. ⎝x - 2⋅y ⎠⋅⎝x  + 2⋅x⋅y  + 4⋅y ⎠
  63. >>>
  64. >>>
  65. >>> (x^4 - 1).factor()
  66. Traceback (most recent call last):
  67.   File "<stdin>", line 1, in <module>
  68. AttributeError: 'Not' object has no attribute 'factor'
  69. >>> (x**4 - 1).factor()
  70.                 ⎛ 2    ⎞
  71. (x - 1)(x + 1)⋅⎝x  + 1
  72. >>> (2*x**3 + x**2*y-6*x*y-3*y**2)
  73.    3    2                2
  74. 2⋅x  + x ⋅y - 6⋅x⋅y - 3⋅y
  75. >>> (2*x**3 + x**2*y-6*x*y-3*y**2).factor()
  76.           ⎛ 2      ⎞
  77. (2⋅x + y)⋅⎝x  - 3⋅y⎠
  78. >>>
  79. >>>
  80. >>> x2 = x**2
  81. >>> (x2 + 6*x - 7).factor()
  82. (x - 1)(x + 7)
  83. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement