# Ticket #2347: 2347-6.patch

File 2347-6.patch, 5.2 KB (added by robertwb, 14 years ago)
• ## sage/calculus/calculus.py

```# HG changeset patch
# Date 1207901491 25200
# Node ID dd1dddfd7b4f0e59db8030450a53bb88920f045e
# Parent  cec740e603143f0ee77011ab1fee03377497ae06
Cleanup all uses of sage_eval in calculus, all doctests pass.

diff -r cec740e60314 -r dd1dddfd7b4f sage/calculus/calculus.py```
 a import sage.numerical.optimize # separate from the default system-wide version. maxima = Maxima(init_code = ['display2d:false; domain: complex; keepfloat: true']) from sage.misc.parser import Parser, LookupNameMaker from sage.misc.parser import Parser from sage.calculus.equations import SymbolicEquation from sage.rings.real_mpfr import RealNumber def symbolic_expression_from_maxima_stri #r = maxima._eval_line('listofvars(_tmp_);')[1:-1] s = maxima._eval_line('_tmp_;') formal_functions = maxima_tick.findall(s) if len(formal_functions) > 0: for X in formal_functions: def symbolic_expression_from_maxima_stri # evaluation of maxima code are assumed pre-simplified is_simplified = True return symbolic_expression_from_string(s, syms, accept_sequence=True) last_msg = '' while True: try: w = sage_eval(s, syms) except NameError, msg: if msg == last_msg: raise NameError, msg msg = str(msg) last_msg = msg i = msg.find("'") j = msg.rfind("'") nm = msg[i+1:j] res = re.match('.*' + nm + '\s*\(.*\)', s) if res: syms[nm] = function(nm) else: syms[nm] = var(nm) else: break if isinstance(w, (list, tuple)): return w else: x = SR(w) return x except SyntaxError: raise TypeError, "unable to make sense of Maxima expression '%s' in SAGE"%s finally: def _find_var(name): return SR(sage.all.__dict__[name]) except KeyError: return var(name) def _find_func(name): try: func = (_augmented_syms or _syms)[name] if not isinstance(func, (SymbolicConstant, SymbolicVariable)): return func except KeyError: pass try: func = SR(sage.all.__dict__[name]) if not isinstance(func, (SymbolicConstant, SymbolicVariable)): return func except KeyError: return function(name) SR_parser = Parser(make_int      = lambda x: SymbolicConstant(Integer(x)), make_float    = lambda x: SymbolicConstant(create_RealNumber(x)), make_var      = _find_var, make_function = LookupNameMaker(_syms, function)) make_function = _find_func) def symbolic_expression_from_string(s, syms=None, accept_sequence=False): parse_func = SR_parser.parse_sequence if accept_sequence else SR_parser.parse_expression
• ## sage/calculus/equations.py

`diff -r cec740e60314 -r dd1dddfd7b4f sage/calculus/equations.py`
 a _assumptions = [] from sage.structure.sage_object import SageObject from sage.structure.sequence    import Sequence from sage.misc.sage_eval        import sage_eval from calculus                   import maxima class SymbolicEquation(SageObject): if len(X) == 0: return X, [] else: return X, sage_eval(P.get('multiplicities')) return X, [int(e) for e in str(P.get('multiplicities'))[1:-1].split(',')] else: return X
• ## sage/rings/rational.pyx

`diff -r cec740e60314 -r dd1dddfd7b4f sage/rings/rational.pyx`
 a cdef class Rational(sage.structure.eleme sage: (2/3)^(x^n + y^n + z^n) 3^(-z^n - y^n - x^n)*2^(z^n + y^n + x^n) sage: (-7/11)^(tan(x)+exp(x)) 11^(-tan(x) - e^x)*-7^(tan(x) + e^x) 11^(-tan(x) - e^x)*(-7)^(tan(x) + e^x) sage: (2/3)^(3/4) 2^(3/4)/3^(3/4) sage: (-1/3)^0
• ## sage/rings/real_double.pyx

`diff -r cec740e60314 -r dd1dddfd7b4f sage/rings/real_double.pyx`
 a cdef class RealDoubleElement(FieldElemen Symbolic examples: sage: x, y = var('x,y') sage: RDF('-2.3')^(x+y^3+sin(x)) -2.30000000000000^(y^3 + sin(x) + x) (-2.30000000000000)^(y^3 + sin(x) + x) sage: RDF('-2.3')^x -2.30000000000000^x (-2.30000000000000)^x """ cdef RealDoubleElement base, exp if PY_TYPE_CHECK(self, RealDoubleElement):