Ticket #7682: trac-7682-realfield-printing-options.5.patch
File trac-7682-realfield-printing-options.5.patch, 34.3 KB (added by , 11 years ago) |
---|
-
sage/calculus/calculus.py
# HG changeset patch # User Jason Grout <jason-sage@creativetrax.com> # Date 1273864581 18000 # Node ID 388db1e1d12f027e3291302e8f2b5a95c06660bc # Parent 5a5ad42d94c6af432eaa895fcc70137c49fa156d [mq]: realfield--printing.patch diff -r 5a5ad42d94c6 -r 388db1e1d12f sage/calculus/calculus.py
a b 846 846 elif epsilon and error < epsilon: 847 847 return g 848 848 elif algorithm is not None: 849 raise NotImplementedError, "Could not prove minimal polynomial %s (epsilon %s)" % (g, RR(error).str( no_sci=False))849 raise NotImplementedError, "Could not prove minimal polynomial %s (epsilon %s)" % (g, RR(error).str(scientific_notation='always')) 850 850 851 851 if algorithm is not None: 852 852 raise ValueError, "Could not find minimal polynomial (%s bits, degree %s)." % (bits, degree) … … 1505 1505 search = sci_not.search(s) 1506 1506 while not search is None: 1507 1507 (start, end) = search.span() 1508 r = create_RealNumber(s[start:end]).str( no_sci=2, truncate=True)1508 r = create_RealNumber(s[start:end]).str(scientific_notation='never', truncate=True) 1509 1509 s = s.replace(s[start:end], r) 1510 1510 search = sci_not.search(s) 1511 1511 -
sage/calculus/desolvers.py
diff -r 5a5ad42d94c6 -r 388db1e1d12f sage/calculus/desolvers.py
a b 740 740 741 741 :: 742 742 743 sage: RR = RealField( sci_not=0, prec=4, rnd='RNDU')743 sage: RR = RealField(prec=4, rnd='RNDU', print_options={'scientific_notation': 0}) 744 744 sage: x,y = PolynomialRing(RR,2,"xy").gens() 745 745 sage: eulers_method(5*x+y-5,0,1,1/2,1,method="None") 746 746 [[0, 1], [1/2, -1.0], [1, -2.7], [3/2, -4.0]] 747 747 748 748 :: 749 749 750 sage: RR = RealField( sci_not=0, prec=4, rnd='RNDU')750 sage: RR = RealField(prec=4, rnd='RNDU', print_options={'scientific_notation': 0}) 751 751 sage: x,y=PolynomialRing(RR,2,"xy").gens() 752 752 sage: eulers_method(5*x+y-5,0,1,1/2,1) 753 753 x y h*f(x,y) … … 832 832 833 833 :: 834 834 835 sage: RR = RealField( sci_not=0, prec=4, rnd='RNDU')835 sage: RR = RealField(prec=4, rnd='RNDU', print_options={'scientific_notation': 0}) 836 836 sage: t,x,y=PolynomialRing(RR,3,"txy").gens() 837 837 sage: f = x+y+t; g = x-y 838 838 sage: eulers_method_2x2(f,g, 0, 0, 0, 1/3, 1) … … 847 847 convert to a system: `y_1' = y_2`, `y_1(0)=1`; `y_2' = 848 848 \\frac{y_1-y_2}{1+t^2}`, `y_2(0)=-1`.:: 849 849 850 sage: RR = RealField( sci_not=0, prec=4, rnd='RNDU')850 sage: RR = RealField(prec=4, rnd='RNDU', print_options={'scientific_notation': 0}) 851 851 sage: t, x, y=PolynomialRing(RR,3,"txy").gens() 852 852 sage: f = y; g = (x-y)/(1+t^2) 853 853 sage: eulers_method_2x2(f,g, 0, 1, -1, 1/4, 1) -
sage/misc/explain_pickle.py
diff -r 5a5ad42d94c6 -r 388db1e1d12f sage/misc/explain_pickle.py
a b 210 210 {('a', 'b'):[1r, 2r]} 211 211 sage: explain_pickle(dumps(RR(pi)), in_current_sage=True) 212 212 from sage.rings.real_mpfr import __create__RealNumber_version0 213 from sage.rings.real_mpfr import __create__RealField_version 0214 __create__RealNumber_version0(__create__RealField_version 0(53r, False, 'RNDN'), '3.4gvml245kc0@0', 32r)213 from sage.rings.real_mpfr import __create__RealField_version1 214 __create__RealNumber_version0(__create__RealField_version1(53r, 'RNDN', {'scientific_notation':'extreme', 'skip_zeroes':False, 'truncate':True}), '3.4gvml245kc0@0', 32r) 215 215 sage: s = 'hi' 216 216 sage: explain_pickle(dumps((s, s))) 217 217 ('hi', 'hi') -
sage/rings/real_interval_field.py
diff -r 5a5ad42d94c6 -r 388db1e1d12f sage/rings/real_interval_field.py
a b 12 12 return isinstance(x, RealIntervalFieldElementClass) 13 13 14 14 def __reduce__RealIntervalField(prec, sci_not): 15 return RealIntervalField(prec, sci_not) 15 print_options={'scientific_notation': sci_not} 16 return RealIntervalField(prec=prec, print_options=print_options) 16 17 17 18 def __reduce__RealIntervalFieldElement(parent, x, base=10): 18 19 return RealIntervalFieldElementClass(parent, x, base=base) -
sage/rings/real_mpfi.pxd
diff -r 5a5ad42d94c6 -r 388db1e1d12f sage/rings/real_mpfi.pxd
a b 18 18 19 19 cdef class RealIntervalField_class(sage.rings.ring.Field): 20 20 cdef int __prec 21 cdef bint sci_not21 cdef object print_options 22 22 # Cache RealField instances for the lower, upper, and middle bounds. 23 23 # These have the same precision as the interval field; 24 24 # __lower_field rounds down, __upper_field rounds up. -
sage/rings/real_mpfi.pyx
diff -r 5a5ad42d94c6 -r 388db1e1d12f sage/rings/real_mpfi.pyx
a b 198 198 199 199 cimport real_mpfr 200 200 from real_mpfr cimport RealField_class, RealNumber 201 from real_mpfr import RealField 201 from real_mpfr import RealField, sci_not_deprecation 202 202 import real_mpfr 203 203 204 204 import operator … … 227 227 printing_style = 'question' 228 228 printing_error_digits = 0 229 229 230 _PRINT_OPTIONS = {'skip_zeroes': False, 'truncate': True, 'scientific_notation': 'extreme', 231 'style': 'question', 'error_digits': 0} 232 233 230 234 #***************************************************************************** 231 235 # 232 236 # Real Field … … 237 241 238 242 RealIntervalField_cache = {} 239 243 240 def RealIntervalField(prec=53, sci _not=False):244 def RealIntervalField(prec=53, scientific_notation=None, print_options={},sci_not=None): 241 245 r""" 242 246 Construct a RealIntervalField_class, with caching. 243 247 … … 249 253 mpfr_prec_min() and mpfr_prec_max(). In the current 250 254 implementation, mpfr_prec_min() is equal to 2. 251 255 252 - ``sci_not`` - (default: False) whether or not to display using 253 scientific notation 256 - ``scientific_notation`` 257 258 - 'never' - never print using scientific notation; 259 260 - 'extreme' (default) - print using scientific notation only for very 261 large or very small numbers; 262 263 - 'always' - always print with scientific notation; 254 264 255 265 EXAMPLES:: 256 266 257 267 sage: RealIntervalField() 258 268 Real Interval Field with 53 bits of precision 259 sage: RealIntervalField(200, sci _not=True)269 sage: RealIntervalField(200, scientific_notation=True) 260 270 Real Interval Field with 200 bits of precision 261 271 sage: RealIntervalField(53) is RIF 262 272 True … … 268 278 See the documentation for :class:`RealIntervalField_class` for many more 269 279 examples. 270 280 """ 281 printing=_PRINT_OPTIONS.copy() 282 printing.update(print_options) 283 if sci_not is not None: 284 from sage.misc.misc import deprecation 285 deprecation("The sci_not keyword is deprecated. Use print_options={'scientific_notation': %r} instead."%sci_not_deprecation[sci_not]) 286 scientific_notation=sci_not_deprecation[sci_not] 287 if scientific_notation is not None: 288 printing['scientific_notation']=scientific_notation 289 print_cached=tuple(sorted(printing.items())) 271 290 try: 272 return RealIntervalField_cache[prec, sci_not]291 return RealIntervalField_cache[prec, print_cached] 273 292 except KeyError: 274 RealIntervalField_cache[prec, sci_not] = R = RealIntervalField_class(prec,sci_not)293 RealIntervalField_cache[prec, print_cached] = R = RealIntervalField_class(prec=prec, print_options=printing, sci_not=sci_not) 275 294 return R 276 295 277 296 cdef class RealIntervalField_class(sage.rings.ring.Field): 278 297 """ 279 RealIntervalField(prec, sci _not):298 RealIntervalField(prec, scientific_notation): 280 299 281 300 INPUT: 282 301 … … 288 307 implementation, mpfr_prec_min() is equal to 2. 289 308 290 309 291 - ``sci _not`` - (default: False) whether or not to display using310 - ``scientific_notation`` - (default: False) whether or not to display using 292 311 scientific notation 293 312 294 313 EXAMPLES:: … … 412 431 413 432 Some examples with a real interval field of higher precision:: 414 433 415 sage: R = RealIntervalField(100) 434 sage: R = RealIntervalField(100); R 435 Real Interval Field with 100 bits of precision 416 436 sage: R(3) 417 437 3 418 438 sage: R(R(3)) … … 434 454 True 435 455 sage: TestSuite(RIF).run() 436 456 """ 437 438 def __init__(self, int prec=53, int sci_not=0): 457 def __init__(self, int prec=53, scientific_notation=None, print_options=None, sci_not=None): 439 458 if prec < MPFR_PREC_MIN or prec > MPFR_PREC_MAX: 440 459 raise ValueError, "prec (=%s) must be >= %s and <= %s."%( 441 460 prec, MPFR_PREC_MIN, MPFR_PREC_MAX) 442 461 self.__prec = prec 443 self.sci_not = sci_not 444 self.__lower_field = RealField(prec, sci_not, "RNDD") 445 self.__middle_field = RealField(prec, sci_not, "RNDN") 446 self.__upper_field = RealField(prec, sci_not, "RNDU") 462 463 if sci_not is not None: 464 from sage.misc.misc import deprecation 465 deprecation("The sci_not keyword is deprecated. Use scientific_notation instead.") 466 scientific_notation=sci_not 467 468 self.print_options=_PRINT_OPTIONS.copy() 469 if scientific_notation is not None: 470 self.print_options['scientific_notation']=scientific_notation 471 472 realfield_print_options={} 473 for key in real_mpfr._PRINT_OPTIONS: 474 if key in self.print_options: 475 realfield_print_options[key]=self.print_options[key] 476 477 self.__lower_field = RealField(prec=prec, rnd="RNDD", 478 print_options=realfield_print_options) 479 self.__middle_field = RealField(prec=prec, rnd="RNDN", 480 print_options=realfield_print_options) 481 self.__upper_field = RealField(prec=prec, rnd="RNDU", 482 print_options=realfield_print_options) 483 447 484 from sage.categories.fields import Fields 448 485 ParentWithGens.__init__(self, self, tuple([]), False, category = Fields()) 449 486 … … 464 501 elif rnd == "RNDU": 465 502 return self._upper_field() 466 503 else: 467 return RealField(self.__prec, self.sci_not, "RNDZ") 504 return RealField(prec=self.__prec, rnd="RNDZ", 505 print_options=self.print_options) 468 506 469 507 cdef RealIntervalFieldElement _new(self): 470 508 """ … … 585 623 from sage.categories.pushout import CompletionFunctor 586 624 return (CompletionFunctor(sage.rings.infinity.Infinity, 587 625 self.prec(), 588 {' sci_not': self.scientific_notation(), 'type': 'Interval'}),626 {'print_options': self.print_options, 'type': 'Interval'}), 589 627 sage.rings.rational_field.QQ) 590 628 591 629 cdef _coerce_c_impl(self, x): … … 640 678 False 641 679 sage: RealIntervalField(10) == RealIntervalField(10) 642 680 True 643 sage: RealIntervalField(10,sci _not=True) == RealIntervalField(10,sci_not=False)681 sage: RealIntervalField(10,scientific_notation=True) == RealIntervalField(10,scientific_notation=False) 644 682 True 645 683 sage: RealIntervalField(10) == IntegerRing() 646 684 False … … 657 695 """ 658 696 EXAMPLES:: 659 697 660 sage: R = RealIntervalField(sci _not=1, prec=200)698 sage: R = RealIntervalField(scientific_notation=1, prec=200) 661 699 sage: loads(dumps(R)) == R 662 700 True 663 701 """ 664 return __create__RealIntervalField_version 0, (self.__prec, self.sci_not)702 return __create__RealIntervalField_version1, (self.__prec, self.print_options) 665 703 666 704 def random_element(self, *args): 667 705 """ … … 883 921 884 922 - ``status`` - (bool -) optional flag 885 923 """ 924 from sage.misc.misc import deprecation 886 925 if status is None: 887 return self.sci_not 926 deprecation("scientific_notation() is deprecated. Use self.print_options['scientific_notation'] instead") 927 return self.print_options['scientific_notation'] 888 928 else: 889 self.sci_not = status 929 deprecation("scientific_notation() is deprecated. Use self.print_options['scientific_notation']=value instead") 930 self.print_options['scientific_notation'] = status 890 931 891 932 def zeta(self, n=2): 892 933 """ … … 1061 1102 sage: a = RIF(5,5.5) 1062 1103 sage: cmp(loads(dumps(a)), a) 1063 1104 0 1064 sage: R = RealIntervalField(sci _not=1, prec=200)1105 sage: R = RealIntervalField(scientific_notation=1, prec=200) 1065 1106 sage: b = R('393.39203845902384098234098230948209384028340') 1066 1107 sage: cmp(loads(dumps(b)), b) 1067 1108 0 … … 1203 1244 """ 1204 1245 return self._parent 1205 1246 1206 # MPFRhad an elaborate "truncation" scheme to avoid printing1207 # inaccurate-looking results; this has been removed for MPFI,1247 # RealField had an elaborate "truncation" scheme to avoid printing 1248 # inaccurate-looking results; this has been removed for RealIntervalField, 1208 1249 # because I think it's less confusing to get such results than to 1209 1250 # see [0.333 .. 0.333] for an interval with unequal left and right 1210 1251 # sides. 1211 def str(self, int base=10, style=None, no_sci=None, e=None, error_digits=None ):1252 def str(self, int base=10, style=None, no_sci=None, e=None, error_digits=None,scientific_notation=None): 1212 1253 r""" 1213 1254 INPUT: 1214 1255 … … 1354 1395 '[2.1851851851851851 .. 2.1851851851851856]' 1355 1396 sage: a.str(16) 1356 1397 '2.2f684bda12f69?' 1357 sage: a.str( no_sci=False)1398 sage: a.str(scientific_notation='always') 1358 1399 '2.185185185185186?e0' 1359 1400 sage: pi_appr = RIF(pi, 22/7) 1360 1401 sage: pi_appr.str(style='brackets') … … 1392 1433 else: 1393 1434 return "[.. NaN ..]" 1394 1435 1436 1437 if no_sci is not None: 1438 from sage.misc.misc import deprecation 1439 deprecated_option = {True: 'extreme', False: 'always'} 1440 deprecation("The no_sci keyword is deprecated. Use scientific_notation=%r instead."%deprecated_option[no_sci]) 1441 scientific_notation=deprecated_option[no_sci] 1442 if scientific_notation not in [None, 'always','extreme']: 1443 raise ValueError, "scientific_notation must be one of 'always', 'extreme', or 'never'." 1444 elif scientific_notation is None: 1445 scientific_notation = (<RealIntervalField_class>self._parent).print_options.get('scientific_notation',_PRINT_OPTIONS['scientific_notation']) 1446 1447 1448 1395 1449 if e is None: 1396 1450 if base > 10: 1397 1451 e = '@' … … 1407 1461 style = 'brackets' 1408 1462 1409 1463 if style == 'brackets': 1410 t1 = self.lower().str(base=base, no_sci=no_sci, e=e, truncate=False)1411 t2 = self.upper().str(base=base, no_sci=no_sci, e=e, truncate=False)1464 t1 = self.lower().str(base=base, scientific_notation=scientific_notation, e=e, truncate=False) 1465 t2 = self.upper().str(base=base, scientific_notation=scientific_notation, e=e, truncate=False) 1412 1466 1413 1467 return "[%s .. %s]"%(t1, t2) 1414 1468 1415 1469 elif style == 'question': 1416 if no_sci == False:1470 if scientific_notation=='always': 1417 1471 prefer_sci = True 1472 elif scientific_notation=='extreme': 1473 prefer_sci = False 1418 1474 else: 1419 prefer_sci = False1475 raise ValueError, "scientific_notation must be 'always' or 'extreme'" 1420 1476 return self._str_question_style(base, error_digits, e, prefer_sci) 1421 1477 1422 1478 else: … … 4169 4225 4170 4226 4171 4227 #### pickle functions 4228 def __create__RealIntervalField_version1(prec, print_options): 4229 return RealIntervalField(prec=prec, print_options=print_options) 4230 4172 4231 def __create__RealIntervalField_version0(prec, sci_not): 4173 return RealIntervalField(prec, sci_not) 4232 print_options={'scientific_notation': sci_not} 4233 return RealIntervalField(prec=prec, print_options=print_options) 4174 4234 4175 4235 ## Keep all old versions!!! 4176 4236 def __create__RealIntervalFieldElement_version0(parent, x, base=10): -
sage/rings/real_mpfr.pxd
diff -r 5a5ad42d94c6 -r 388db1e1d12f sage/rings/real_mpfr.pxd
a b 16 16 17 17 cdef class RealField_class(sage.rings.ring.Field): 18 18 cdef int __prec 19 cdef bint sci_not19 cdef object print_options 20 20 cdef mpfr_rnd_t rnd 21 21 cdef object rnd_str 22 22 cdef RealNumber _new(self) -
sage/rings/real_mpfr.pyx
diff -r 5a5ad42d94c6 -r 388db1e1d12f sage/rings/real_mpfr.pyx
a b 24 24 25 25 - Robert Bradshaw (2009-09): decimal literals, optimizations 26 26 27 - Jason Grout (2010-01): unified printing option defaults 28 27 29 This is a binding for the MPFR arbitrary-precision floating point 28 30 library. 29 31 … … 205 207 206 208 _rounding_modes = ['RNDN', 'RNDZ', 'RNDU', 'RNDD'] 207 209 210 _PRINT_OPTIONS = {'skip_zeroes': False, 'truncate': True, 'scientific_notation': 'extreme'} 211 212 # Remove sci_not_deprecation when removing the sci_not deprecation warnings 213 sci_not_deprecation = {0: 'extreme', False: 'extreme', 1: 'always', True: 'always'} 214 208 215 cdef object RealField_cache = weakref.WeakValueDictionary() 209 216 210 def RealField(int prec=53, int sci_not=0, rnd="RNDN"):217 def RealField(int prec=53, scientific_notation=None, rnd="RNDN", truncate=None,skip_zeroes=None, print_options=None, sci_not=None): 211 218 """ 212 RealField(prec, sci _not, rnd):219 RealField(prec, scientific_notation, rnd): 213 220 214 221 INPUT: 215 222 … … 221 228 implementation, mpfr_prec_min() is equal to 2. 222 229 223 230 224 - ``sci_not`` - (default: False) if True, always display using 225 scientific notation; if False, display using scientific notation 226 only for very large or very small numbers 231 - ``scientific_notation`` 232 233 - 'never' - never print using scientific notation; 234 235 - 'extreme' (default) - print using scientific notation only for 236 very large or very small numbers; 237 238 - 'always' - always print with scientific notation; 227 239 228 240 - ``rnd`` - (string) the rounding mode 229 241 … … 237 249 238 250 - 'RNDU' - round towards plus infinity 239 251 252 - ``sci_not`` - deprecated. See ``scientific_notation``. 253 240 254 EXAMPLES:: 241 255 242 256 sage: RealField(10) … … 263 277 numbers (double type in C), except the default exponent range 264 278 is much wider and subnormal numbers are not implemented.' 265 279 """ 280 printing=_PRINT_OPTIONS.copy() 281 if print_options is not None: 282 printing.update(print_options) 283 if sci_not is not None: 284 from sage.misc.misc import deprecation 285 deprecation("The sci_not keyword is deprecated. Use scientific_notation=%r instead."%sci_not_deprecation[sci_not], 'Sage 4.3.2') 286 scientific_notation=sci_not_deprecation[sci_not] 287 if scientific_notation is not None: 288 if scientific_notation not in ['always', 'extreme', 'never']: 289 raise ValueError, "scientific_notation must be one of 'always', 'extreme', or 'never' (was %r)"%scientific_notation 290 printing['scientific_notation']=scientific_notation 291 if truncate is not None: 292 printing['truncate']=truncate 293 if skip_zeroes is not None: 294 printing['skip_zeroes']=skip_zeroes 295 296 print_cached=tuple(sorted(printing.items())) 266 297 try: 267 return RealField_cache[prec, sci_not, rnd]298 return RealField_cache[prec, rnd, print_cached] 268 299 except KeyError: 269 RealField_cache[prec, sci_not, rnd] = R = RealField_class(prec=prec, sci_not=sci_not, rnd=rnd)300 RealField_cache[prec, rnd, print_cached] = R = RealField_class(prec=prec, rnd=rnd, print_options=printing) 270 301 return R 271 302 272 303 cdef class RealField_class(sage.rings.ring.Field): … … 282 313 details. 283 314 """ 284 315 285 def __init__(self, int prec=53, int sci_not=0, rnd="RNDN"): 316 def __init__(self, int prec=53, scientific_notation=None, rnd="RNDN", print_options=None, sci_not=None): 317 318 if sci_not is not None: 319 from sage.misc.misc import deprecation 320 deprecation("The sci_not keyword is deprecated. Use print_options={'scientific_notation': %r} instead."%sci_not_deprecation[sci_not], 'Sage 4.3.1') 321 scientific_notation=sci_not_deprecation[sci_not] 322 286 323 global MY_MPFR_PREC_MAX 324 if print_options is None: 325 print_options={} 326 if 'scientific_notation' in print_options: 327 if scientific_notation is None: 328 scientific_notation = print_options['scientific_notation'] 329 else: 330 print_options['scientific_notation']=scientific_notation 331 else: 332 if scientific_notation is not None: 333 print_options['scientific_notation']=scientific_notation 334 287 335 cdef RealNumber rn 288 336 if prec < MPFR_PREC_MIN or prec > MY_MPFR_PREC_MAX: 289 337 raise ValueError, "prec (=%s) must be >= %s and <= %s."%( … … 291 339 self.__prec = prec 292 340 if not isinstance(rnd, str): 293 341 raise TypeError, "rnd must be a string" 294 self. sci_not = sci_not342 self.print_options=print_options 295 343 n = _rounding_modes.index(rnd) 296 344 if n == -1: 297 345 raise ValueError, "rnd (=%s) must be one of RNDN, RNDZ, RNDU, or RNDD"%rnd … … 536 584 537 585 :: 538 586 539 sage: RealField(10,sci _not=True) == RealField(10,sci_not=False)587 sage: RealField(10,scientific_notation='always') == RealField(10,scientific_notation='extreme') 540 588 True 541 589 sage: RealField(10) == IntegerRing() 542 590 False 543 591 544 592 :: 545 593 546 sage: RS = RealField(sci _not=True)594 sage: RS = RealField(scientific_notation='always') 547 595 sage: RR == RS 548 596 True 549 sage: RS. scientific_notation(False)597 sage: RS.print_options['scientific_notation']='extreme' 550 598 sage: RR == RS 551 599 True 552 600 """ … … 554 602 return -1 555 603 cdef RealField_class _other 556 604 _other = other # to access C structure 557 if self.__prec == _other.__prec and self.rnd == _other.rnd: \ 558 #and self.sci_not == _other.sci_not: 605 if self.__prec == _other.__prec and self.rnd == _other.rnd: 559 606 return 0 560 607 return 1 561 608 … … 565 612 566 613 EXAMPLES:: 567 614 568 sage: R = RealField(sci _not=1, prec=200, rnd='RNDU')615 sage: R = RealField(scientific_notation='always', prec=200, rnd='RNDU') 569 616 sage: loads(dumps(R)) == R 570 617 True 571 618 """ 572 return __create__RealField_version 0, (self.__prec, self.sci_not, self.rnd_str)619 return __create__RealField_version1, (self.__prec, self.rnd_str, self.print_options) 573 620 574 621 def construction(self): 575 622 """ … … 591 638 from sage.categories.pushout import CompletionFunctor 592 639 return (CompletionFunctor(sage.rings.infinity.Infinity, 593 640 self.prec(), 594 {' sci_not': self.scientific_notation(), 'rnd': self.rounding_mode()}),641 {'rnd': self.rounding_mode(),'print_options': self.print_options}), 595 642 sage.rings.rational_field.QQ) 596 643 597 644 def gen(self, i=0): … … 813 860 if prec == self.__prec: 814 861 return self 815 862 else: 816 return RealField(prec, self.sci_not, _rounding_modes[self.rnd]) 863 return RealField(prec, rnd=_rounding_modes[self.rnd], 864 print_options=self.print_options) 817 865 818 866 # int mpfr_const_pi (mpfr_t rop, mp_rnd_t rnd) 819 867 def pi(self): … … 1006 1054 1007 1055 def scientific_notation(self, status=None): 1008 1056 """ 1057 .. warning:: Deprecated. See :meth:`printing_options` for 1058 this functionality. 1059 1009 1060 Set or return the scientific notation printing flag. If this flag 1010 1061 is True then real numbers with this space as parent print using 1011 1062 scientific notation. … … 1013 1064 INPUT: 1014 1065 1015 1066 - ``status`` - (bool -) optional flag 1016 """ 1067 1068 EXAMPLES:: 1069 1070 sage: RR.scientific_notation() 1071 doctest:1172: DeprecationWarning: (Since Sage 4.3.1) scientific_notation() is deprecated. Use self.print_options['scientific_notation'] 1072 True 1073 1074 """ 1075 from sage.misc.misc import deprecation 1017 1076 if status is None: 1018 return self.sci_not 1077 deprecation("scientific_notation() is deprecated. Use self.print_options['scientific_notation']", 'Sage 4.3.1') 1078 return self.print_options.get('scientific_notation',_PRINT_OPTIONS['scientific_notation'])!='always' 1019 1079 else: 1020 self.sci_not = status 1021 1080 deprecation("scientific_notation() is deprecated. Use self.print_options['scientific_notation']=value instead", 'Sage 4.3.1') 1081 if status is True: 1082 self.print_options['scientific_notation'] = 'always' 1083 else: 1084 self.print_options['scientific_notation'] = 'extreme' 1085 1086 1087 1088 property print_options: 1089 """ 1090 Options for printing a real number. 1091 """ 1092 def __get__(self): 1093 """ 1094 Get the printing options. 1095 """ 1096 return self.print_options 1097 def __set__(self,newval): 1098 """ 1099 Set the printing options. 1100 """ 1101 self.print_options=newval 1102 def __del__(self): 1103 """ 1104 Reset the printing options to be empty. 1105 """ 1106 self.print_options={} 1107 1022 1108 def zeta(self, n=2): 1023 1109 """ 1024 1110 Return an `n`-th root of unity in the real field, if one … … 1263 1349 """ 1264 1350 EXAMPLES:: 1265 1351 1266 sage: R = RealField(sci _not=1, prec=200, rnd='RNDU')1352 sage: R = RealField(scientific_notation='always', prec=200, rnd='RNDU') 1267 1353 sage: b = R('393.39203845902384098234098230948209384028340') 1268 1354 sage: loads(dumps(b)) == b 1269 1355 True … … 1280 1366 sage: loads(dumps(b)) == b 1281 1367 True 1282 1368 """ 1283 s = self.str(32, no_sci=False, e='@')1369 s = self.str(32, scientific_notation='always', e='@') 1284 1370 return (__create__RealNumber_version0, (self._parent, s, 32)) 1285 1371 1286 1372 def __dealloc__(self): … … 1321 1407 sage: s1 == RR(gp(s1)) 1322 1408 True 1323 1409 """ 1324 return self.str(10, no_sci=True, truncate=False)1410 return self.str(10, scientific_notation='extreme', truncate=False) 1325 1411 1326 1412 def _sage_input_(self, sib, coerced): 1327 1413 r""" … … 1522 1608 """ 1523 1609 return self._parent 1524 1610 1525 def str(self, int base=10, no_sci=None, e=None, int truncate=1, bint skip_zeroes=0):1611 def str(self, int base=10, no_sci=None, e=None, truncate=None, skip_zeroes=None,scientific_notation=None): 1526 1612 """ 1527 1613 INPUT: 1528 1614 1529 1615 1530 1616 - ``base`` - base for output 1531 1617 1532 - ``no_sci`` - if 2, never print using scientific 1533 notation; if 1 or True, print using scientific notation only for 1534 very large or very small numbers; if 0 or False always print with 1535 scientific notation; if None (the default), print how the parent 1536 prints. 1618 - ``scientific_notation`` - (default: None) 1619 1620 - 'never' - never print using scientific notation; 1621 1622 - 'extreme' - print using scientific notation only for very 1623 large or very small numbers; 1624 1625 - 'always' - always print with scientific notation; 1626 1627 - None (default) - print how the parent prints. 1537 1628 1538 1629 - ``e`` - symbol used in scientific notation; defaults to 'e' for 1539 1630 base=10, and '@' otherwise … … 1551 1642 '20.333333333333332' 1552 1643 sage: a.str(2) 1553 1644 '10100.010101010101010101010101010101010101010101010101' 1554 sage: a.str( no_sci=False)1645 sage: a.str(scientific_notation='always') 1555 1646 '2.03333333333333e1' 1556 sage: a.str(16, no_sci=False)1647 sage: a.str(16, scientific_notation='always') 1557 1648 '1.4555555555555@1' 1558 1649 sage: b = 2.0^99 1559 1650 sage: b.str() 1560 1651 '6.33825300114115e29' 1561 sage: b.str( no_sci=False)1652 sage: b.str(scientific_notation='always') 1562 1653 '6.33825300114115e29' 1563 sage: b.str( no_sci=True)1654 sage: b.str(scientific_notation='extreme') 1564 1655 '6.33825300114115e29' 1565 1656 sage: c = 2.0^100 1566 1657 sage: c.str() 1567 1658 '1.26765060022823e30' 1568 sage: c.str( no_sci=False)1659 sage: c.str(scientific_notation='always') 1569 1660 '1.26765060022823e30' 1570 sage: c.str( no_sci=True)1661 sage: c.str(scientific_notation='extreme') 1571 1662 '1.26765060022823e30' 1572 sage: c.str( no_sci=2)1663 sage: c.str(scientific_notation='never') 1573 1664 '1267650600228230000000000000000.' 1574 1665 sage: 0.5^53 1575 1666 1.11022302462516e-16 … … 1588 1679 """ 1589 1680 if base < 2 or base > 36: 1590 1681 raise ValueError, "the base (=%s) must be between 2 and 36"%base 1682 1683 if no_sci is not None: 1684 from sage.misc.misc import deprecation 1685 deprecated_option = {0: 'always', 1: 'extreme', 2: 'never'} 1686 deprecation("The no_sci keyword is deprecated. Use scientific_notation=%r instead."%deprecated_option[no_sci]) 1687 scientific_notation=deprecated_option[no_sci] 1688 if scientific_notation not in [None, 'always','extreme','never']: 1689 raise ValueError, "scientific_notation must be one of 'always', 'extreme', or 'never'." 1690 1591 1691 if mpfr_nan_p(self.value): 1592 1692 if base >= 24: 1593 1693 return "@NaN@" … … 1605 1705 else: 1606 1706 e = 'e' 1607 1707 1708 if skip_zeroes is None: 1709 skip_zeroes = (<RealField_class>self._parent).print_options.get('skip_zeroes',_PRINT_OPTIONS['skip_zeroes']) 1710 1711 if truncate is None: 1712 truncate = (<RealField_class>self._parent).print_options.get('truncate',_PRINT_OPTIONS['truncate']) 1713 1608 1714 cdef char *s 1609 1715 cdef mp_exp_t exponent 1610 1716 … … 1651 1757 if t[0] == "-": 1652 1758 digits = digits - 1 1653 1759 1654 if no_sci is None: 1655 no_sci = not (<RealField_class>self._parent).sci_not 1656 1657 if no_sci is True and ( abs(exponent-1) >=6 ): 1658 no_sci = False 1659 1660 if no_sci==False: 1760 if scientific_notation is None: 1761 scientific_notation = (<RealField_class>self._parent).print_options.get('scientific_notation',_PRINT_OPTIONS['scientific_notation']) 1762 1763 if (scientific_notation=='extreme' and ( abs(exponent-1) >=6 )) \ 1764 or scientific_notation=='always': 1661 1765 if t[0] == "-": 1662 1766 return "-%s.%s%s%s"%(t[1:2], t[2:], e, exponent-1) 1663 1767 return "%s.%s%s%s"%(t[0], t[1:], e, exponent-1) … … 4969 5073 4970 5074 4971 5075 # here because this imports the other two real fields 4972 def create_RealField(prec=53, type="MPFR", rnd="RNDN", sci_not=0): 5076 def create_RealField(prec=53, type="MPFR", rnd="RNDN", scientific_notation=None, print_options={},sci_not=None): 5077 """ 5078 A generic constructor that returns the appropriate real field. 5079 5080 INPUTS: 5081 5082 - ``type`` 5083 5084 - ``MPFR`` - A real field with precision ``prec`` and the 5085 specified printing options. 5086 - ``RDF`` - A real field with double precision 5087 - ``RQDF`` - A real field with quad double precision 5088 - ``RLF`` - A real lazy field 5089 - ``Interval`` - A real interval field with ``prec`` precision 5090 and the specified printing options 5091 """ 4973 5092 if type == "RDF": 4974 5093 return RDF 4975 5094 elif type == "RQDF": … … 4977 5096 return RQDF 4978 5097 elif type == "Interval": 4979 5098 from real_mpfi import RealIntervalField 4980 return RealIntervalField(prec ,sci_not)5099 return RealIntervalField(prec=prec, scientific_notation=scientific_notation, print_options=print_options, sci_not=sci_not) 4981 5100 elif type == "RLF": 4982 5101 from real_lazy import RLF 4983 5102 return RLF 4984 5103 else: 4985 return RealField(prec , sci_not, rnd)5104 return RealField(prec=prec, scientific_notation=scientific_notation, rnd=rnd, print_options=print_options, sci_not=sci_not) 4986 5105 4987 5106 4988 5107 def is_RealField(x): … … 5017 5136 """ 5018 5137 return PY_TYPE_CHECK(x, RealNumber) 5019 5138 5139 def __create__RealField_version1(prec, rnd, print_options): 5140 """ 5141 Return a real field with precision ``prec``, rounding ``rnd``, and 5142 print options ``print_options``. 5143 5144 EXAMPLES:: 5145 5146 sage: sage.rings.real_mpfr.__create__RealField_version1(50, 'RNDD',{}) 5147 Real Field with 50 bits of precision and rounding RNDD 5148 """ 5149 return RealField(prec=prec, rnd=rnd, print_options=print_options) 5150 5020 5151 def __create__RealField_version0(prec, sci_not, rnd): 5021 return RealField(prec, sci_not, rnd) 5152 """ 5153 Return a real field with precision ``prec``, rounding ``rnd``, and 5154 the specified scientific notation setting. 5155 5156 EXAMPLES:: 5157 5158 sage: sage.rings.real_mpfr.__create__RealField_version1(50, 'RNDD',{}) 5159 Real Field with 50 bits of precision and rounding RNDD 5160 sage: R=sage.rings.real_mpfr.__create__RealField_version0(50, True, 'RNDD') 5161 sage: R.print_options 5162 {'scientific_notation': 'always', 'skip_zeroes': False, 'truncate': True} 5163 """ 5164 print_options={'scientific_notation':sci_not_deprecation[sci_not]} 5165 return RealField(prec=prec, rnd=rnd, print_options=print_options) 5022 5166 5023 5167 def __create__RealNumber_version0(parent, x, base=10): 5024 5168 """