SHARE
TWEET

Untitled

a guest Jun 16th, 2019 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. sys.path.append('/home/vagrant/.local/lib/python3.4/site-packages')
  3. from sympy import *
  4. from sympy.printing.mathml import mathml
  5.  
  6. print(mathml(sympify("y=4*x**3+3*x**2+2*x+1"),printer='presentation'))
  7. print(mathml(sympify("y=a*x**3+b*x**2+c*x+d"),printer='presentation'))
  8.      
  9. $ python test001.py
  10. Traceback (most recent call last):
  11.   File "/home/vagrant/.local/lib/python3.4/site-packages/sympy/core/sympify.py", line 368, in sympify
  12.     expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate)
  13.   File "/home/vagrant/.local/lib/python3.4/site-packages/sympy/parsing/sympy_parser.py", line 965, in parse_expr
  14.     return eval_expr(code, local_dict, global_dict)
  15.   File "/home/vagrant/.local/lib/python3.4/site-packages/sympy/parsing/sympy_parser.py", line 878, in eval_expr
  16.     code, global_dict, local_dict)  # take local objects in preference
  17.   File "<string>", line 1
  18.     Symbol ('y' )=Integer (4 )*Symbol ('x' )**Integer (3 )+Integer (3 )*Symbol ('x' )**Integer (2 )+Integer (2 )*Symbol ('x' )+Integer (1 )
  19.                  ^
  20. SyntaxError: invalid syntax
  21.  
  22. During handling of the above exception, another exception occurred:
  23.  
  24. Traceback (most recent call last):
  25.   File "test001.py", line 6, in <module>
  26.     print(mathml(sympify("y=4*x**3+3*x**2+2*x+1"),printer='presentation'))
  27.   File "/home/vagrant/.local/lib/python3.4/site-packages/sympy/core/sympify.py", line 370, in sympify
  28.     raise SympifyError('could not parse %r' % a, exc)
  29. sympy.core.sympify.SympifyError: Sympify of expression 'could not parse 'y=4*x**3+3*x**2+2*x+1'' failed, because of exception being raised:
  30. SyntaxError: invalid syntax (<string>, line 1)
  31. Error in sys.excepthook:
  32. Traceback (most recent call last):
  33.   File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
  34.     from apport.fileutils import likely_packaged, get_recent_crashes
  35.   File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
  36.     from apport.report import Report
  37.   File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
  38.     import apport.fileutils
  39.   File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
  40.     from apport.packaging_impl import impl as packaging
  41.   File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
  42.     import apt
  43.   File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
  44.     import apt_pkg
  45. ModuleNotFoundError: No module named 'apt_pkg'
  46.  
  47. Original exception was:
  48. Traceback (most recent call last):
  49.   File "/home/vagrant/.local/lib/python3.4/site-packages/sympy/core/sympify.py", line 368, in sympify
  50.     expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate)
  51.   File "/home/vagrant/.local/lib/python3.4/site-packages/sympy/parsing/sympy_parser.py", line 965, in parse_expr
  52.     return eval_expr(code, local_dict, global_dict)
  53.   File "/home/vagrant/.local/lib/python3.4/site-packages/sympy/parsing/sympy_parser.py", line 878, in eval_expr
  54.     code, global_dict, local_dict)  # take local objects in preference
  55.   File "<string>", line 1
  56.     Symbol ('y' )=Integer (4 )*Symbol ('x' )**Integer (3 )+Integer (3 )*Symbol ('x' )**Integer (2 )+Integer (2 )*Symbol ('x' )+Integer (1 )
  57.                  ^
  58. SyntaxError: invalid syntax
  59.  
  60. During handling of the above exception, another exception occurred:
  61.  
  62. Traceback (most recent call last):
  63.   File "test001.py", line 6, in <module>
  64.     print(mathml(sympify("y=4*x**3+3*x**2+2*x+1"),printer='presentation'))
  65.   File "/home/vagrant/.local/lib/python3.4/site-packages/sympy/core/sympify.py", line 370, in sympify
  66.     raise SympifyError('could not parse %r' % a, exc)
  67. sympy.core.sympify.SympifyError: Sympify of expression 'could not parse 'y=4*x**3+3*x**2+2*x+1'' failed, because of exception being raised:
  68. SyntaxError: invalid syntax (<string>, line 1)
  69.      
  70. <mi>y</mi><mo>=</mo><mn>4</mn><mo>&#x2061;<!--FUNCTION APPLICATION--></mo><msup><mi>x</mi><mn>3</mn></msup><mo>+</mo><mn>3</mn><mo>&#x2061;<!--FUNCTION APPLICATION--></mo><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mn>2</mn><mo>&#x2061;<!--FUNCTION APPLICATION--></mo><mi>x</mi><mo>+</mo><mn>1</mn>
  71.      
  72. <mi>y</mi><mo>=</mo><mi>a</mi><mo>&#x2061;<!--FUNCTION APPLICATION--></mo><msup><mi>x</mi><mn>3</mn></msup><mo>+</mo><mi>b</mi><mo>&#x2061;<!--FUNCTION APPLICATION--></mo><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>c</mi><mo>&#x2061;<!--FUNCTION APPLICATION--></mo><mi>x</mi><mo>+</mo><mi>d</mi>
  73.      
  74. Symbol ('y' )=Integer (4 )*Symbol ('x' )**Integer (3 )+Integer (3 )*Symbol ('x' )**Integer (2 )+Integer (2 )*Symbol ('x' )+Integer (1 )
  75.              ^
  76. SyntaxError: invalid syntax
  77.      
  78. map(sym.sympify, "y=4*x**3+3*x**2+2*x+1".split('='))
  79.      
  80. >>> sym.Eq(*map(sym.sympify, "y=4*x**3+3*x**2+2*x+1".split('=')))
  81. Eq(y, 4*x**3 + 3*x**2 + 2*x + 1)
  82.      
  83. import sys
  84. # sys.path.append('/home/vagrant/.local/lib/python3.4/site-packages')
  85. import sympy as sym
  86. from sympy.printing.mathml import mathml
  87.  
  88.  
  89. print(mathml(sym.Eq(*map(sym.sympify, "y=4*x**3+3*x**2+2*x+1".split('='))),printer='presentation'))
  90. print(mathml(sym.Eq(*map(sym.sympify, "y=a*x**3+b*x**2+c*x+d".split('='))),printer='presentation'))
  91.      
  92. <mrow><mi>y</mi><mo>=</mo><mrow><mrow><mn>4</mn><mo>&InvisibleTimes;</mo><msup><mi>x</mi><mn>3</mn></msup></mrow><mo>+</mo><mrow><mn>3</mn><mo>&InvisibleTimes;</mo><msup><mi>x</mi><mn>2</mn></msup></mrow><mo>+</mo><mrow><mn>2</mn><mo>&InvisibleTimes;</mo><mi>x</mi></mrow><mo>+</mo><mn>1</mn></mrow></mrow>
  93. <mrow><mi>y</mi><mo>=</mo><mrow><mrow><mi>a</mi><mo>&InvisibleTimes;</mo><msup><mi>x</mi><mn>3</mn></msup></mrow><mo>+</mo><mrow><mi>b</mi><mo>&InvisibleTimes;</mo><msup><mi>x</mi><mn>2</mn></msup></mrow><mo>+</mo><mrow><mi>c</mi><mo>&InvisibleTimes;</mo><mi>x</mi></mrow><mo>+</mo><mi>d</mi></mrow></mrow>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top