Ticket #7377: trac_7377-fastcalculus_p2.patch
File trac_7377-fastcalculus_p2.patch, 22.3 KB (added by , 10 years ago) |
---|
-
sage/calculus/calculus.py
# HG changeset patch # User Jean-Pierre Flori <flori@enst.fr> # Date 1297786300 -3600 # Node ID 5bff07b42baf278a7f8154e66e8f3d849eb60561 # Parent 1160d58a0f0abf2904a1e73853937277832a2c5c # Parent 3b1d2675ab7a1e4ede566e5b0e9938e74fcce16c Let calculus use the maxima_lib instance and implement some preliminary diff -r 1160d58a0f0a -r 5bff07b42baf sage/calculus/calculus.py
a b 386 386 f1 387 387 """ 388 388 maxima = sage.interfaces.maxima_lib.maxima 389 #maxima = Maxima(init_code = ['display2d:false', 'domain: complex', 390 # 'keepfloat: true', 'load(to_poly_solver)', 'load(simplify_sum)'], 391 # script_subdirectory=None) 389 392 390 393 ######################################################## 391 394 def symbolic_sum(expression, v, a, b, algorithm='maxima'): … … 529 532 raise ValueError, "summation limits must not depend on the summation variable" 530 533 531 534 if algorithm == 'maxima': 532 sum = "'sum(%s, %s, %s, %s)" % tuple([repr(expr._maxima_()) for expr in (expression, v, a, b)])533 535 try: 534 result = maxima.simplify_sum(sum) 535 result = result.ratsimp() 536 return expression.parent()(result) 536 return maxima.sr_sum(expression,v,a,b) 537 537 except TypeError, error: 538 538 s = str(error) 539 539 if "divergent" in s or 'Pole encountered' in s: … … 1101 1101 1102 1102 if algorithm == 'maxima': 1103 1103 if dir is None: 1104 l = ex._maxima_().limit(v, a)1104 l = maxima.sr_limit(ex, v, a) 1105 1105 elif dir in ['plus', '+', 'right', 'above']: 1106 1106 if dir == 'above': 1107 1107 from sage.misc.misc import deprecation 1108 1108 deprecation("the keyword 'above' is deprecated. Please use 'right' or '+' instead.", 'Sage version 4.6') 1109 l = ex._maxima_().limit(v, a, 'plus')1109 l = maxima.sr_limit(ex, v, a, 'plus') 1110 1110 elif dir in ['minus', '-', 'left', 'below']: 1111 1111 if dir == 'below': 1112 1112 from sage.misc.misc import deprecation 1113 1113 deprecation("the keyword 'below' is deprecated. Please use 'left' or '-' instead.", 'Sage version 4.6') 1114 l = ex._maxima_().limit(v, a, 'minus')1114 l = maxima.sr_limit(ex, v, a, 'minus') 1115 1115 elif algorithm == 'maxima_taylor': 1116 1116 if dir is None: 1117 l = ex._maxima_().tlimit(v, a)1117 l = maxima.sr_tlimit(ex, v, a) 1118 1118 elif dir == 'plus' or dir == 'above' or dir == 'from_right': 1119 l = ex._maxima_().tlimit(v, a, 'plus')1119 l = maxima.sr_tlimit(ex, v, a, 'plus') 1120 1120 elif dir == 'minus' or dir == 'below' or dir == 'from_left': 1121 l = ex._maxima_().tlimit(v, a, 'minus')1121 l = maxima.sr_tlimit(ex, v, a, 'minus') 1122 1122 elif algorithm == 'sympy': 1123 1123 if dir is None: 1124 1124 import sympy … … 1126 1126 else: 1127 1127 raise NotImplementedError, "sympy does not support one-sided limits" 1128 1128 1129 return l.sage()1129 #return l.sage() 1130 1130 return ex.parent()(l) 1131 1131 1132 1132 # lim is alias for limit -
sage/interfaces/maxima.py
diff -r 1160d58a0f0a -r 5bff07b42baf sage/interfaces/maxima.py
a b 1011 1011 """ 1012 1012 return maxima_version() 1013 1013 1014 ##some helper functions to wrap tha calculus use of the maxima interface. 1015 ##these routines expect arguments living in the symbolic ring and return something 1016 ##that is hopefully coercible into the symbolic ring again. 1014 1017 1018 def sr_integral(self,*args): 1019 return args[0]._maxima_().integrate(*args[1:]) 1020 1021 def sr_sum(self,expression,v,a,b): 1022 sum = "'sum(%s, %s, %s, %s)" % tuple([repr(expr._maxima_()) for expr in (expression, v, a, b)]) 1023 result = self.simplify_sum(sum) 1024 result = result.ratsimp() 1025 return expression.parent()(result) 1026 1027 def sr_limit(self,ex,*args): 1028 return ex._maxima_().limit(*args) 1029 1030 def sr_tlimit(self,ex,*args): 1031 return ex._maxima_().tlimit(*args) 1032 1015 1033 ## def display2d(self, flag=True): 1016 1034 ## """ 1017 1035 ## Set the flag that determines whether Maxima objects are … … 1077 1095 def __doctest_cleanup(): 1078 1096 import sage.interfaces.quit 1079 1097 sage.interfaces.quit.expect_quitall() 1080 1081 -
sage/interfaces/maxima_lib.py
diff -r 1160d58a0f0a -r 5bff07b42baf sage/interfaces/maxima_lib.py
a b 423 423 sage: var('Ax,Bx,By') 424 424 (Ax, Bx, By) 425 425 sage: t = -Ax*sin(sqrt(Ax^2)/2)/(sqrt(Ax^2)*sqrt(By^2 + Bx^2)) 426 sage: t.limit(Ax=0, 426 sage: t.limit(Ax=0,dir='+') 427 427 0 428 428 429 429 A long complicated input expression:: … … 470 470 import sage.server.support 471 471 472 472 import maxima_abstract 473 from maxima_abstract import MaximaFunctionElement, MaximaExpectFunction, Maxima Element, MaximaFunction, maxima_console473 from maxima_abstract import MaximaFunctionElement, MaximaExpectFunction, MaximaFunction, maxima_console 474 474 475 475 # The Maxima "apropos" command, e.g., apropos(det) gives a list 476 476 # of all identifiers that begin in a certain way. This could … … 485 485 ecl_eval("(in-package :maxima)") 486 486 ecl_eval("(setq $nolabels t))") 487 487 ecl_eval("(defvar *MAXIMA-LANG-SUBDIR* NIL)") 488 ecl_eval("(set-locale-subdir)") 488 489 ecl_eval("(set-pathnames)") 489 490 ecl_eval("(defun add-lineinfo (x) x)") 490 491 ecl_eval("""(defun retrieve (msg flag &aux (print? nil))(error (concatenate 'string "Maxima asks:" (meval (list '($string) msg)))))""") 491 492 ecl_eval('(defparameter *dev-null* (make-two-way-stream (make-concatenated-stream) (make-broadcast-stream)))') 492 493 ecl_eval('(defun principal nil (error "Divergent Integral"))') 493 494 495 ecl_eval("(setf $errormsg nil)") 496 494 497 maxima_eval=ecl_eval(""" 495 (defun maxima-eval( form ) 496 (let ((result (catch 'macsyma-quit (cons 'maxima_eval (meval form))))) 497 ;(princ (list "result=" result)) 498 ;(terpri) 499 ;(princ (list "$error=" $error)) 500 ;(terpri) 501 (cond 502 ((and (consp result) (eq (car result) 'maxima_eval)) (cdr result)) 503 ((eq result 'maxima-error) (error (cadr $error))) 504 (t (error (concatenate 'string "Maxima condition. result:" (princ-to-string result) "$error:" (princ-to-string $error)))) 505 ) 498 (defun maxima-eval( form ) 499 (let ((result (catch 'macsyma-quit (cons 'maxima_eval (meval form))))) 500 ;(princ (list "result=" result)) 501 ;(terpri) 502 ;(princ (list "$error=" $error)) 503 ;(terpri) 504 (cond 505 ((and (consp result) (eq (car result) 'maxima_eval)) (cdr result)) 506 ((eq result 'maxima-error) 507 (let ((the-jig (process-error-argl (cddr $error)))) 508 (mapc #'set (car the-jig) (cadr the-jig)) 509 (error (concatenate 'string "Error executing code in Maxima: " 510 (with-output-to-string (stream) 511 (apply #'mformat stream (cadr $error) (caddr the-jig))))) 512 )) 513 (t 514 (let ((the-jig (process-error-argl (cddr $error)))) 515 (mapc #'set (car the-jig) (cadr the-jig)) 516 (error (concatenate 'string "Maxima condition. result:" (princ-to-string result) "$error:" 517 (with-output-to-string (stream) 518 (apply #'mformat stream (cadr $error) (caddr the-jig))))) 519 )) 506 520 ) 507 521 ) 522 ) 508 523 """) 509 524 510 525 #ecl_eval('(defun ask-evod (x even-odd)(error "Maxima asks a question"))') … … 527 542 528 543 maxprint=EclObject("$STRING") 529 544 meval=EclObject("MEVAL") 545 msetq=EclObject("MSETQ") 546 mlist=EclObject("MLIST") 547 mequal=EclObject("MEQUAL") 548 cadadr=EclObject("CADADR") 549 550 max_integrate=EclObject("$INTEGRATE") 551 max_sum=EclObject("$SUM") 552 max_simplify_sum=EclObject("$SIMPLIFY_SUM") 553 max_ratsimp=EclObject("$RATSIMP") 554 max_limit=EclObject("$LIMIT") 555 max_tlimit=EclObject("$TLIMIT") 556 max_plus=EclObject("$PLUS") 557 max_minus=EclObject("$MINUS") 558 max_use_grobner=EclObject("$USE_GROBNER") 559 max_to_poly_solve=EclObject("$TO_POLY_SOLVE") 530 560 531 561 def max_to_string(s): 532 562 return meval(EclObject([[maxprint],s])).python()[1:-1] … … 582 612 for l in init_code: 583 613 ecl_eval("#$%s$"%l) 584 614 ecl_eval("(setf *standard-output* original-standard-output)") 615 616 def _coerce_from_special_method(self, x): 617 if isinstance(x, EclObject): 618 return MaximaElement(self,self._create(x)) 619 else: 620 return maxima_abstract.Maxima._coerce_from_special_method(self,x) 621 585 622 586 623 def _function_class(self): 587 624 """ … … 605 642 sage: m.is_running() 606 643 True 607 644 """ 608 ecl_eval(r"(defun tex-derivative (x l r) (tex (if $derivabbrev (tex-dabbrev x) (tex-d x '\partial)) l r lop rop ))") 609 645 # ecl_eval(r"(defun tex-derivative (x l r) (tex (if $derivabbrev (tex-dabbrev x) (tex-d x '\partial)) l r lop rop ))") 646 pass 647 610 648 def __reduce__(self): 611 649 """ 612 650 EXAMPLES:: … … 627 665 sage: integrate(1/(x^3 *(a+b*x)^(1/3)),x) 628 666 Traceback (most recent call last): 629 667 ... 630 TypeError: Computation failed since Maxima requested additional constraints (try the command 'assume(a>0)' before integral or limit evaluation, for example): 631 Is a positive or negative? 668 RuntimeError: ECL says: Maxima asks:... 632 669 sage: assume(a>0) 633 670 sage: integrate(1/(x^3 *(a+b*x)^(1/3)),x) 634 671 2/9*sqrt(3)*b^2*arctan(1/3*(2*(b*x + a)^(1/3) + a^(1/3))*sqrt(3)/a^(1/3))/a^(7/3) + 2/9*b^2*log((b*x + a)^(1/3) - a^(1/3))/a^(7/3) - 1/9*b^2*log((b*x + a)^(2/3) + (b*x + a)^(1/3)*a^(1/3) + a^(2/3))/a^(7/3) + 1/6*(4*(b*x + a)^(5/3)*b^2 - 7*(b*x + a)^(2/3)*a*b^2)/((b*x + a)^2*a^2 - 2*(b*x + a)*a^3 + a^4) … … 637 674 sage: integral(x^n,x) 638 675 Traceback (most recent call last): 639 676 ... 640 TypeError: Computation failed since Maxima requested additional constraints (try the command 'assume(n+1>0)' before integral or limit evaluation, for example): 641 Is n+1 zero or nonzero? 677 RuntimeError: ECL says: Maxima asks:... 642 678 sage: assume(n+1>0) 643 679 sage: integral(x^n,x) 644 680 x^(n + 1)/(n + 1) … … 690 726 691 727 def _eval_line(self, line, allow_use_file=False, 692 728 wait_for_prompt=True, reformat=True, error_check=True): 693 return max_to_string(maxima_eval("#$%s$"%line)) 694 729 result = '' 730 while line: 731 ind_dollar=line.find("$") 732 ind_semi=line.find(";") 733 if ind_dollar == -1 or (ind_semi >=0 and ind_dollar > ind_semi): 734 if ind_semi == -1: 735 statement = line 736 line = '' 737 else: 738 statement = line[:ind_semi] 739 line = line[ind_semi+1:] 740 if statement: result = ((result + '\n') if result else '')+ max_to_string(maxima_eval("#$%s$"%statement)) 741 else: 742 statement = line[:ind_dollar] 743 line = line[ind_dollar+1:] 744 if statement: _ = max_to_string(maxima_eval("#$%s$"%statement)) 745 return result 695 746 696 747 def _synchronize(self): 697 748 """ … … 939 990 """ 940 991 s = self._eval_line('%s;'%var) 941 992 return s 942 993 994 def _create(self, value, name=None): 995 name = self._next_var_name() if name is None else name 996 if isinstance(value,EclObject): 997 maxima_eval([[msetq],cadadr("#$%s$#$"%name),value]) 998 else: 999 self.set(name, value) 1000 return name 1001 943 1002 def version(self): 944 1003 """ 945 1004 Return the version of Maxima that Sage includes. … … 951 1010 """ 952 1011 return maxima_version() 953 1012 1013 ##some helper functions to wrap tha calculus use of the maxima interface. 1014 ##these routines expect arguments living in the symbolic ring and return something 1015 ##that is hopefully coercible into the symbolic ring again. 1016 1017 def sr_integral(self,*args): 1018 try: 1019 return max_to_sr(maxima_eval(([max_integrate],[sr_to_max(SR(a)) for a in args]))) 1020 except RuntimeError, error: 1021 s = str(error) 1022 if "Divergent" in s or "divergent" in s: 1023 raise ValueError, "Integral is divergent." 1024 else: 1025 raise error 1026 1027 def sr_sum(self,*args): 1028 try: 1029 return max_to_sr(maxima_eval([[max_ratsimp],[[max_simplify_sum],([max_sum],[sr_to_max(SR(a)) for a in args])]])); 1030 except RuntimeError, error: 1031 s = str(error) 1032 if "divergent" in s: 1033 raise ValueError, "Sum is divergent." 1034 else: 1035 raise error 1036 1037 def sr_limit(self,expr,v,a,dir=None): 1038 L=[sr_to_max(SR(a)) for a in [expr,v,a]] 1039 if dir == "plus": 1040 L.append(max_plus) 1041 elif dir == "minus": 1042 L.append(max_minus) 1043 return max_to_sr(maxima_eval(([max_limit],L))) 1044 1045 def sr_tlimit(self,expr,v,a,dir=None): 1046 L=[sr_to_max(SR(a)) for a in [expr,v,a]] 1047 if dir == "plus": 1048 L.append(max_plus) 1049 elif dir == "minus": 1050 L.append(max_minus) 1051 return max_to_sr(maxima_eval(([max_tlimit],L))) 954 1052 955 1053 ## def display2d(self, flag=True): 956 1054 ## """ … … 974 1072 ## """ 975 1073 ## self._display2d = bool(flag) 976 1074 1075 class MaximaElement(maxima_abstract.MaximaElement): 1076 """ 1077 """ 1078 def ecl(self): 1079 try: 1080 return self._ecl 1081 except AttributeError: 1082 self._ecl=maxima_eval("#$%s$"%self._name) 1083 return self._ecl 1084 1085 def to_poly_solve(self,vars,options=""): 1086 if options.find("use_grobner=true") != -1: 1087 cmd=EclObject([[max_to_poly_solve], self.ecl(), sr_to_max(vars), 1088 [[mequal],max_use_grobner,True]]) 1089 else: 1090 cmd=EclObject([[max_to_poly_solve], self.ecl(), sr_to_max(vars)]) 1091 return self.parent()(maxima_eval(cmd)) 1092 977 1093 def is_MaximaElement(x): 978 1094 """ 979 1095 Returns True if x is of type MaximaElement. … … 1018 1134 sage.interfaces.quit.expect_quitall() 1019 1135 1020 1136 1137 import sage.symbolic.expression 1138 from sage.symbolic.ring import SR 1139 1140 import sage.symbolic.expression 1141 import sage.functions.trig 1142 import sage.functions.log 1143 import sage.functions.other 1144 import sage.symbolic.integration.integral 1145 1146 car=EclObject("car") 1147 cdr=EclObject("cdr") 1148 caar=EclObject("caar") 1149 cadr=EclObject("cadr") 1150 cddr=EclObject("cddr") 1151 caddr=EclObject("caddr") 1152 caaadr=EclObject("caaadr") 1153 cadadr=EclObject("cadadr") 1154 meval=EclObject("meval") 1155 NIL=EclObject("NIL") 1156 ratdisrep=EclObject("ratdisrep") 1157 1158 sage_op_dict={} 1159 1160 sage_op_dict = { 1161 sage.symbolic.expression.operator.abs : "MABS", 1162 sage.symbolic.expression.operator.add : "MPLUS", 1163 sage.symbolic.expression.operator.div : "MQUOTIENT", 1164 sage.symbolic.expression.operator.eq : "MEQUAL", 1165 sage.symbolic.expression.operator.ge : "MGEQP", 1166 sage.symbolic.expression.operator.gt : "MGREATERP", 1167 sage.symbolic.expression.operator.le : "MLEQP", 1168 sage.symbolic.expression.operator.lt : "MLESSP", 1169 sage.symbolic.expression.operator.mul : "MTIMES", 1170 sage.symbolic.expression.operator.ne : "MNOTEQUAL", 1171 sage.symbolic.expression.operator.neg : "MMINUS", 1172 sage.symbolic.expression.operator.pow : "MEXPT", 1173 sage.symbolic.expression.operator.or_ : "MOR", 1174 sage.symbolic.expression.operator.and_ : "MAND", 1175 sage.functions.trig.acos : "%ACOS", 1176 sage.functions.trig.acot : "%ACOT", 1177 sage.functions.trig.acsc : "%ACSC", 1178 sage.functions.trig.asec : "%ASEC", 1179 sage.functions.trig.asin : "%ASIN", 1180 sage.functions.trig.atan : "%ATAN", 1181 sage.functions.trig.cos : "%COS", 1182 sage.functions.trig.cot : "%COT", 1183 sage.functions.trig.csc : "%CSC", 1184 sage.functions.trig.sec : "%SEC", 1185 sage.functions.trig.sin : "%SIN", 1186 sage.functions.trig.tan : "%TAN", 1187 sage.functions.log.exp : "%EXP", 1188 sage.functions.log.ln : "%LOG", 1189 sage.functions.log.log : "%LOG", 1190 sage.functions.other.factorial : "MFACTORIAL", 1191 sage.functions.other.erf : "%ERF", 1192 sage.functions.other.gamma_inc : "%GAMMA_INCOMPLETE" 1193 } 1194 1195 #we compile the dictionary 1196 sage_op_dict = dict([(k,EclObject(sage_op_dict[k])) for k in sage_op_dict]) 1197 max_op_dict = dict([(sage_op_dict[k],k) for k in sage_op_dict]) 1198 def add_vararg(*args): 1199 S=0 1200 for a in args: 1201 S=S+a 1202 return S 1203 1204 def mul_vararg(*args): 1205 P=1 1206 for a in args: 1207 P=P*a 1208 return P 1209 1210 def sage_rat(x,y): 1211 return x/y 1212 1213 mplus=EclObject("MPLUS") 1214 mtimes=EclObject("MTIMES") 1215 rat=EclObject("RAT") 1216 max_i=EclObject("$%I") 1217 max_op_dict[mplus]=add_vararg 1218 max_op_dict[mtimes]=mul_vararg 1219 max_op_dict[rat]=sage_rat 1220 mqapply=EclObject("MQAPPLY") 1221 max_li=EclObject("$LI") 1222 max_psi=EclObject("$PSI") 1223 max_array=EclObject("ARRAY") 1224 max_gamma_incomplete=sage_op_dict[sage.functions.other.gamma_inc] 1225 1226 def mrat_to_sage(expr): 1227 r""" 1228 Convert a maxima MRAT expression to Sage SR 1229 1230 Maxima has an optimised representation for multivariate rational expressions. 1231 The easiest way to translate those to SR is by first asking maxima to give 1232 the generic representation of the object. That is what RATDISREP does in 1233 maxima. 1234 """ 1235 return max_to_sr(meval(EclObject([[ratdisrep],expr]))) 1236 1237 def mqapply_to_sage(expr): 1238 r""" 1239 Special conversion rule for MQAPPLY expressions 1240 """ 1241 if caaadr(expr) == max_li: 1242 return sage.functions.log.polylog(max_to_sr(cadadr(expr)),max_to_sr(caddr(expr))) 1243 if caaadr(expr) == max_psi: 1244 return sage.functions.other.psi(max_to_sr(cadadr(expr)),max_to_sr(caddr(expr))) 1245 else: 1246 op=max_to_sr(cadr(expr)) 1247 max_args=cddr(expr) 1248 args=[max_to_sr(a) for a in max_args] 1249 return op(*args) 1250 1251 def dummy_integrate(expr): 1252 r""" 1253 we would like to simply tie maxima's integrate to sage.calculus.calculus.dummy_integrate, but we're being imported there so to avoid circularity we define it here. 1254 """ 1255 args=[max_to_sr(a) for a in cdr(expr)] 1256 if len(args) == 4 : 1257 return sage.symbolic.integration.integral.definite_integral(*args, hold=True) 1258 else: 1259 return sage.symbolic.integration.integral.indefinite_integral(*args, hold=True) 1260 1261 special_max_to_sage={ 1262 EclObject("MRAT") : mrat_to_sage, 1263 EclObject("MQAPPLY") : mqapply_to_sage, 1264 EclObject("%INTEGRATE") : dummy_integrate 1265 } 1266 1267 special_sage_to_max={ 1268 sage.functions.log.polylog : lambda N,X : [[mqapply],[[max_li, max_array],N],X], 1269 sage.functions.other.psi1 : lambda X : [[mqapply],[[max_psi, max_array],0],X], 1270 sage.functions.other.psi2 : lambda N,X : [[mqapply],[[max_psi, max_array],N],X], 1271 sage.functions.other.Ei : lambda X : [[max_gamma_incomplete], 0, X] 1272 } 1273 1274 sage_sym_dict={} 1275 max_sym_dict={} 1276 1277 def pyobject_to_max(obj): 1278 if isinstance(obj,sage.rings.rational.Rational): 1279 return EclObject(obj) if (obj.denom().is_one()) else EclObject([[rat], obj.numer(),obj.denom()]) 1280 elif isinstance(obj,sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic) and obj.parent().defining_polynomial().list() == [1,0,1]: 1281 re, im = obj.list() 1282 return EclObject([[mplus], pyobject_to_max(re), [[mtimes], pyobject_to_max(im), max_i]]) 1283 1284 return EclObject(obj) 1285 1286 def sr_to_max(expr): 1287 r""" 1288 """ 1289 global sage_op_dict, max_op_dict 1290 global sage_sym_dict, max_sym_dict 1291 if isinstance(expr,list) or isinstance(expr,tuple): 1292 return EclObject(([mlist],[sr_to_max(e) for e in expr])) 1293 op = expr.operator() 1294 if op: 1295 if (op in special_sage_to_max): 1296 return EclObject(special_sage_to_max[op](*[sr_to_max(o) for o in expr.operands()])) 1297 elif not (op in sage_op_dict): 1298 op_max=caar(maxima(expr).ecl()) 1299 sage_op_dict[op]=op_max 1300 max_op_dict[op_max]=op 1301 return EclObject(([sage_op_dict[op]], 1302 [sr_to_max(o) for o in expr.operands()])) 1303 elif expr._is_symbol() or expr._is_constant(): 1304 if not expr in sage_sym_dict: 1305 sym_max=maxima(expr).ecl() 1306 sage_sym_dict[expr]=sym_max 1307 max_sym_dict[sym_max]=expr 1308 return sage_sym_dict[expr] 1309 else: 1310 try: 1311 return pyobject_to_max(expr.pyobject()) 1312 except TypeError: 1313 return maxima(expr).ecl() 1314 1315 def max_to_sr(expr): 1316 if expr.consp(): 1317 op_max=caar(expr) 1318 if op_max in special_max_to_sage: 1319 return special_max_to_sage[op_max](expr) 1320 if not(op_max in max_op_dict): 1321 sage_expr=SR(maxima(expr)) 1322 max_op_dict[op_max]=sage_expr.operator() 1323 sage_op_dict[sage_expr.operator()]=op_max 1324 op=max_op_dict[op_max] 1325 max_args=cdr(expr) 1326 args=[ max_to_sr(a) for a in max_args] 1327 return op(*args) 1328 elif expr.symbolp(): 1329 if not(expr in max_sym_dict): 1330 sage_symbol=SR(maxima(expr)) 1331 sage_sym_dict[sage_symbol]=expr 1332 max_sym_dict[expr]=sage_symbol 1333 return max_sym_dict[expr] 1334 else: 1335 return expr.python() 1336 -
sage/symbolic/integration/external.py
diff -r 1160d58a0f0a -r 5bff07b42baf sage/symbolic/integration/external.py
a b 12 12 sage: maxima_integrator(f(x), x) 13 13 integrate(f(x), x) 14 14 """ 15 from sage.calculus.calculus import maxima 15 16 if not isinstance(expression, Expression): 16 17 expression = SR(expression) 17 18 if a is None: 18 result = expression._maxima_().integrate(v)19 result = maxima.sr_integral(expression,v) 19 20 else: 20 21 try: 21 result = expression._maxima_().integrate(v, a, b)22 result = maxima.sr_integral(expression, v, a, b) 22 23 except TypeError, error: 23 24 s = str(error) 24 25 if "divergent" in s or 'Principal Value' in s: 25 26 raise ValueError, "Integral is divergent." 26 27 else: 27 28 raise 28 return result .sage()29 return result 29 30 30 31 def sympy_integrator(expression, v, a=None, b=None): 31 32 """