/usr/share/pyshared/sympy/parsing/maxima.py is in python-sympy 0.7.1.rc1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import re
from sympy import sympify, Sum, product, sin, cos
class MaximaHelpers:
def maxima_expand(expr):
return expr.expand()
def maxima_float(expr):
return expr.evalf()
def maxima_trigexpand(expr):
return expr.expand(trig=True)
def maxima_sum(a1, a2, a3, a4):
return Sum(a1, (a2, a3, a4)).doit()
def maxima_product(a1,a2,a3,a4):
return product(a1, (a2,a3,a4))
def maxima_csc(expr):
return 1/sin(expr)
def maxima_sec(expr):
return 1/cos(expr)
sub_dict = {
'pi' : re.compile('%pi'),
'E' : re.compile('%e'),
'I' : re.compile('%i'),
'**': re.compile('\^'),
'oo': re.compile(r'\binf\b'),
'-oo': re.compile(r'\bminf\b'),
"'-'" : re.compile(r'\bminus\b'),
'maxima_expand' : re.compile(r'\bexpand\b'),
'maxima_float' : re.compile(r'\bfloat\b'),
'maxima_trigexpand' : re.compile(r'\btrigexpand'),
'maxima_sum' : re.compile(r'\bsum\b'),
'maxima_product' : re.compile(r'\bproduct\b'),
'cancel' : re.compile(r'\bratsimp\b'),
'maxima_csc' : re.compile(r'\bcsc\b'),
'maxima_sec' : re.compile(r'\bsec\b')
}
var_name = re.compile('^\s*(\w+)\s*:')
def parse_maxima(str, globals=None, name_dict={}):
str = str.strip()
str = str.rstrip('; ')
for k,v in sub_dict.items():
str = v.sub(k, str)
assign_var = None
var_match = var_name.search(str)
if var_match:
assign_var = var_match.group(1)
str = str[var_match.end():].strip()
dct = MaximaHelpers.__dict__.copy()
dct.update(name_dict)
obj = sympify(str, locals= dct)
if assign_var and globals:
globals[assign_var] = obj
return obj
|