Ticket #7682: trac-7682-realfield-printing-options.4.patch

File trac-7682-realfield-printing-options.4.patch, 34.2 KB (added by jason, 11 years ago)

rebase to 4.4.1, fix startup bug, apply only this patch

  • sage/calculus/calculus.py

    # HG changeset patch
    # User Jason Grout <jason-sage@creativetrax.com>
    # Date 1273860324 18000
    # Node ID 79fb58cb32e3a87535a38ec5218abbbe44ca2e8c
    # Parent  5a5ad42d94c6af432eaa895fcc70137c49fa156d
    [mq]: realfield--printing.patch
    
    diff -r 5a5ad42d94c6 -r 79fb58cb32e3 sage/calculus/calculus.py
    a b  
    846846                            elif epsilon and error < epsilon:
    847847                                return g
    848848                            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'))
    850850
    851851        if algorithm is not None:
    852852            raise ValueError, "Could not find minimal polynomial (%s bits, degree %s)." % (bits, degree)
     
    15051505    search = sci_not.search(s)
    15061506    while not search is None:
    15071507        (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)
    15091509        s = s.replace(s[start:end], r)
    15101510        search = sci_not.search(s)
    15111511     
  • sage/calculus/desolvers.py

    diff -r 5a5ad42d94c6 -r 79fb58cb32e3 sage/calculus/desolvers.py
    a b  
    740740
    741741    ::
    742742
    743         sage: RR = RealField(sci_not=0, prec=4, rnd='RNDU')
     743        sage: RR = RealField(prec=4, rnd='RNDU', print_options={'scientific_notation': 0})
    744744        sage: x,y = PolynomialRing(RR,2,"xy").gens()
    745745        sage: eulers_method(5*x+y-5,0,1,1/2,1,method="None")
    746746        [[0, 1], [1/2, -1.0], [1, -2.7], [3/2, -4.0]]
    747747
    748748    ::
    749749
    750         sage: RR = RealField(sci_not=0, prec=4, rnd='RNDU')
     750        sage: RR = RealField(prec=4, rnd='RNDU', print_options={'scientific_notation': 0})
    751751        sage: x,y=PolynomialRing(RR,2,"xy").gens()
    752752        sage: eulers_method(5*x+y-5,0,1,1/2,1)
    753753             x                    y                  h*f(x,y)
     
    832832
    833833    ::
    834834
    835         sage: RR = RealField(sci_not=0, prec=4, rnd='RNDU')
     835        sage: RR = RealField(prec=4, rnd='RNDU', print_options={'scientific_notation': 0})
    836836        sage: t,x,y=PolynomialRing(RR,3,"txy").gens()
    837837        sage: f = x+y+t; g = x-y
    838838        sage: eulers_method_2x2(f,g, 0, 0, 0, 1/3, 1)
     
    847847    convert to a system: `y_1' = y_2`, `y_1(0)=1`; `y_2' =
    848848    \\frac{y_1-y_2}{1+t^2}`, `y_2(0)=-1`.::
    849849
    850          sage: RR = RealField(sci_not=0, prec=4, rnd='RNDU')
     850         sage: RR = RealField(prec=4, rnd='RNDU', print_options={'scientific_notation': 0})
    851851         sage: t, x, y=PolynomialRing(RR,3,"txy").gens()
    852852         sage: f = y; g = (x-y)/(1+t^2)
    853853         sage: eulers_method_2x2(f,g, 0, 1, -1, 1/4, 1)
  • sage/misc/explain_pickle.py

    diff -r 5a5ad42d94c6 -r 79fb58cb32e3 sage/misc/explain_pickle.py
    a b  
    210210        {('a', 'b'):[1r, 2r]}
    211211        sage: explain_pickle(dumps(RR(pi)), in_current_sage=True)
    212212        from sage.rings.real_mpfr import __create__RealNumber_version0
    213         from sage.rings.real_mpfr import __create__RealField_version0
    214         __create__RealNumber_version0(__create__RealField_version0(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)
    215215        sage: s = 'hi'
    216216        sage: explain_pickle(dumps((s, s)))
    217217        ('hi', 'hi')
  • sage/rings/real_interval_field.py

    diff -r 5a5ad42d94c6 -r 79fb58cb32e3 sage/rings/real_interval_field.py
    a b  
    1212    return isinstance(x, RealIntervalFieldElementClass)
    1313
    1414def __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)
    1617
    1718def __reduce__RealIntervalFieldElement(parent, x, base=10):
    1819    return RealIntervalFieldElementClass(parent, x, base=base)
  • sage/rings/real_mpfi.pxd

    diff -r 5a5ad42d94c6 -r 79fb58cb32e3 sage/rings/real_mpfi.pxd
    a b  
    1818
    1919cdef class RealIntervalField_class(sage.rings.ring.Field):
    2020    cdef int __prec
    21     cdef bint sci_not
     21    cdef object print_options
    2222    # Cache RealField instances for the lower, upper, and middle bounds.
    2323    # These have the same precision as the interval field;
    2424    # __lower_field rounds down, __upper_field rounds up.
  • sage/rings/real_mpfi.pyx

    diff -r 5a5ad42d94c6 -r 79fb58cb32e3 sage/rings/real_mpfi.pyx
    a b  
    198198
    199199cimport real_mpfr
    200200from real_mpfr cimport RealField_class, RealNumber
    201 from real_mpfr import RealField
     201from real_mpfr import RealField, sci_not_deprecation
    202202import real_mpfr
    203203
    204204import operator
     
    227227printing_style = 'question'
    228228printing_error_digits = 0
    229229
     230_PRINT_OPTIONS = {'skip_zeroes': False, 'truncate': True, 'scientific_notation': 'extreme',
     231                  'style': 'question', 'error_digits': 0}
     232
     233
    230234#*****************************************************************************
    231235#
    232236#       Real Field
     
    237241
    238242RealIntervalField_cache = {}
    239243
    240 def RealIntervalField(prec=53, sci_not=False):
     244def RealIntervalField(prec=53, scientific_notation=None, print_options={},sci_not=None):
    241245    r"""
    242246    Construct a RealIntervalField_class, with caching.
    243247
     
    249253       mpfr_prec_min() and mpfr_prec_max(). In the current
    250254       implementation, mpfr_prec_min() is equal to 2.
    251255
    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;
    254264
    255265    EXAMPLES::
    256266
    257267        sage: RealIntervalField()
    258268        Real Interval Field with 53 bits of precision
    259         sage: RealIntervalField(200, sci_not=True)
     269        sage: RealIntervalField(200, scientific_notation=True)
    260270        Real Interval Field with 200 bits of precision
    261271        sage: RealIntervalField(53) is RIF
    262272        True
     
    268278    See the documentation for :class:`RealIntervalField_class` for many more
    269279    examples.
    270280    """
     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()))
    271290    try:
    272         return RealIntervalField_cache[prec, sci_not]
     291        return RealIntervalField_cache[prec, print_cached]
    273292    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)
    275294        return R
    276295
    277296cdef class RealIntervalField_class(sage.rings.ring.Field):
    278297    """
    279     RealIntervalField(prec, sci_not):
     298    RealIntervalField(prec, scientific_notation):
    280299   
    281300    INPUT:
    282301   
     
    288307       implementation, mpfr_prec_min() is equal to 2.
    289308   
    290309   
    291     -  ``sci_not`` - (default: False) whether or not to display using
     310    -  ``scientific_notation`` - (default: False) whether or not to display using
    292311       scientific notation
    293312   
    294313    EXAMPLES::
     
    412431   
    413432    Some examples with a real interval field of higher precision::
    414433   
    415         sage: R = RealIntervalField(100)
     434        sage: R = RealIntervalField(100); R
    416435        sage: R(3)
    417436        3
    418437        sage: R(R(3))
     
    434453        True
    435454        sage: TestSuite(RIF).run()
    436455    """
    437 
    438     def __init__(self, int prec=53, int sci_not=0):
     456    def __init__(self, int prec=53, scientific_notation=None, print_options=None, sci_not=None):
    439457        if prec < MPFR_PREC_MIN or prec > MPFR_PREC_MAX:
    440458            raise ValueError, "prec (=%s) must be >= %s and <= %s."%(
    441459                prec, MPFR_PREC_MIN, MPFR_PREC_MAX)
    442460        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")
     461
     462        if sci_not is not None:
     463            from sage.misc.misc import deprecation
     464            deprecation("The sci_not keyword is deprecated.  Use scientific_notation instead.")
     465            scientific_notation=sci_not
     466       
     467        self.print_options=_PRINT_OPTIONS.copy()
     468        if scientific_notation is not None:
     469            self.print_options['scientific_notation']=scientific_notation
     470
     471        realfield_print_options={}
     472        for key in real_mpfr._PRINT_OPTIONS:
     473            if key in self.print_options:
     474                realfield_print_options[key]=self.print_options[key]
     475
     476        self.__lower_field = RealField(prec=prec, rnd="RNDD",
     477                                                   print_options=realfield_print_options)
     478        self.__middle_field = RealField(prec=prec, rnd="RNDN",
     479                                                    print_options=realfield_print_options)
     480        self.__upper_field = RealField(prec=prec, rnd="RNDU",
     481                                                   print_options=realfield_print_options)
     482
    447483        from sage.categories.fields import Fields
    448484        ParentWithGens.__init__(self, self, tuple([]), False, category = Fields())
    449485
     
    464500        elif rnd == "RNDU":
    465501            return self._upper_field()
    466502        else:
    467             return RealField(self.__prec, self.sci_not, "RNDZ")
     503            return RealField(prec=self.__prec, rnd="RNDZ",
     504                                         print_options=self.print_options)
    468505
    469506    cdef RealIntervalFieldElement _new(self):
    470507        """
     
    585622        from sage.categories.pushout import CompletionFunctor
    586623        return (CompletionFunctor(sage.rings.infinity.Infinity,
    587624                                  self.prec(),
    588                                   {'sci_not': self.scientific_notation(), 'type': 'Interval'}),
     625                                  {'print_options': self.print_options, 'type': 'Interval'}),
    589626               sage.rings.rational_field.QQ)
    590627
    591628    cdef _coerce_c_impl(self, x):
     
    640677            False
    641678            sage: RealIntervalField(10) == RealIntervalField(10)
    642679            True
    643             sage: RealIntervalField(10,sci_not=True) == RealIntervalField(10,sci_not=False)
     680            sage: RealIntervalField(10,scientific_notation=True) == RealIntervalField(10,scientific_notation=False)
    644681            True
    645682            sage: RealIntervalField(10) == IntegerRing()
    646683            False
     
    657694        """
    658695        EXAMPLES::
    659696       
    660             sage: R = RealIntervalField(sci_not=1, prec=200)
     697            sage: R = RealIntervalField(scientific_notation=1, prec=200)
    661698            sage: loads(dumps(R)) == R
    662699            True
    663700        """
    664         return __create__RealIntervalField_version0, (self.__prec, self.sci_not)
     701        return __create__RealIntervalField_version1, (self.__prec, self.print_options)
    665702
    666703    def random_element(self, *args):
    667704        """
     
    883920       
    884921        -  ``status`` - (bool -) optional flag
    885922        """
     923        from sage.misc.misc import deprecation
    886924        if status is None:
    887             return self.sci_not
     925            deprecation("scientific_notation() is deprecated.  Use self.print_options['scientific_notation'] instead")
     926            return self.print_options['scientific_notation']
    888927        else:
    889             self.sci_not = status
     928            deprecation("scientific_notation() is deprecated.  Use self.print_options['scientific_notation']=value instead")
     929            self.print_options['scientific_notation'] = status
    890930       
    891931    def zeta(self, n=2):
    892932        """
     
    10611101            sage: a = RIF(5,5.5)
    10621102            sage: cmp(loads(dumps(a)), a)
    10631103            0       
    1064             sage: R = RealIntervalField(sci_not=1, prec=200)
     1104            sage: R = RealIntervalField(scientific_notation=1, prec=200)
    10651105            sage: b = R('393.39203845902384098234098230948209384028340')
    10661106            sage: cmp(loads(dumps(b)), b)
    10671107            0
     
    12031243        """
    12041244        return self._parent
    12051245
    1206     # MPFR had an elaborate "truncation" scheme to avoid printing
    1207     # inaccurate-looking results; this has been removed for MPFI,
     1246    # RealField had an elaborate "truncation" scheme to avoid printing
     1247    # inaccurate-looking results; this has been removed for RealIntervalField,
    12081248    # because I think it's less confusing to get such results than to
    12091249    # see [0.333 .. 0.333] for an interval with unequal left and right
    12101250    # sides.
    1211     def str(self, int base=10, style=None, no_sci=None, e=None, error_digits=None):
     1251    def str(self, int base=10, style=None, no_sci=None, e=None, error_digits=None,scientific_notation=None):
    12121252        r"""
    12131253        INPUT:
    12141254       
     
    13541394            '[2.1851851851851851 .. 2.1851851851851856]'
    13551395            sage: a.str(16)
    13561396            '2.2f684bda12f69?'
    1357             sage: a.str(no_sci=False)
     1397            sage: a.str(scientific_notation='always')
    13581398            '2.185185185185186?e0'
    13591399            sage: pi_appr = RIF(pi, 22/7)
    13601400            sage: pi_appr.str(style='brackets')
     
    13921432            else:
    13931433                return "[.. NaN ..]"
    13941434       
     1435
     1436        if no_sci is not None:
     1437            from sage.misc.misc import deprecation
     1438            deprecated_option = {True: 'extreme', False: 'always'}
     1439            deprecation("The no_sci keyword is deprecated.  Use scientific_notation=%r instead."%deprecated_option[no_sci])
     1440            scientific_notation=deprecated_option[no_sci]
     1441        if scientific_notation not in [None, 'always','extreme']:
     1442            raise ValueError, "scientific_notation must be one of 'always', 'extreme', or 'never'."
     1443        elif scientific_notation is None:
     1444            scientific_notation = (<RealIntervalField_class>self._parent).print_options.get('scientific_notation',_PRINT_OPTIONS['scientific_notation'])
     1445       
     1446
     1447
    13951448        if e is None:
    13961449            if base > 10:
    13971450                e = '@'
     
    14071460            style = 'brackets'
    14081461
    14091462        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)
     1463            t1 = self.lower().str(base=base, scientific_notation=scientific_notation, e=e, truncate=False)
     1464            t2 = self.upper().str(base=base, scientific_notation=scientific_notation, e=e, truncate=False)
    14121465
    14131466            return "[%s .. %s]"%(t1, t2)
    14141467       
    14151468        elif style == 'question':
    1416             if no_sci == False:
     1469            if scientific_notation=='always':
    14171470                prefer_sci = True
     1471            elif scientific_notation=='extreme':
     1472                prefer_sci = False
    14181473            else:
    1419                 prefer_sci = False
     1474                raise ValueError, "scientific_notation must be 'always' or 'extreme'"
    14201475            return self._str_question_style(base, error_digits, e, prefer_sci)
    14211476
    14221477        else:
     
    41694224
    41704225
    41714226#### pickle functions
     4227def __create__RealIntervalField_version1(prec, print_options):
     4228    return RealIntervalField(prec=prec, print_options=print_options)
     4229
    41724230def __create__RealIntervalField_version0(prec, sci_not):
    4173     return RealIntervalField(prec, sci_not)
     4231    print_options={'scientific_notation': sci_not}
     4232    return RealIntervalField(prec=prec, print_options=print_options)
    41744233
    41754234## Keep all old versions!!!
    41764235def __create__RealIntervalFieldElement_version0(parent, x, base=10):
  • sage/rings/real_mpfr.pxd

    diff -r 5a5ad42d94c6 -r 79fb58cb32e3 sage/rings/real_mpfr.pxd
    a b  
    1616
    1717cdef class RealField_class(sage.rings.ring.Field):
    1818    cdef int __prec
    19     cdef bint sci_not
     19    cdef object print_options
    2020    cdef mpfr_rnd_t rnd
    2121    cdef object rnd_str
    2222    cdef RealNumber _new(self)
  • sage/rings/real_mpfr.pyx

    diff -r 5a5ad42d94c6 -r 79fb58cb32e3 sage/rings/real_mpfr.pyx
    a b  
    2424
    2525- Robert Bradshaw (2009-09): decimal literals, optimizations
    2626
     27- Jason Grout (2010-01): unified printing option defaults
     28
    2729This is a binding for the MPFR arbitrary-precision floating point
    2830library.
    2931
     
    205207
    206208_rounding_modes = ['RNDN', 'RNDZ', 'RNDU', 'RNDD']
    207209
     210_PRINT_OPTIONS = {'skip_zeroes': False, 'truncate': True, 'scientific_notation': 'extreme'}
     211
     212# Remove sci_not_deprecation when removing the sci_not deprecation warnings
     213sci_not_deprecation = {0: 'extreme', False: 'extreme', 1: 'always', True: 'always'}
     214
    208215cdef object RealField_cache = weakref.WeakValueDictionary()
    209216
    210 def RealField(int prec=53, int sci_not=0, rnd="RNDN"):
     217def RealField(int prec=53, scientific_notation=None, rnd="RNDN", truncate=None,skip_zeroes=None, print_options=None, sci_not=None):
    211218    """
    212     RealField(prec, sci_not, rnd):
     219    RealField(prec, scientific_notation, rnd):
    213220   
    214221    INPUT:
    215222   
     
    221228       implementation, mpfr_prec_min() is equal to 2.
    222229   
    223230   
    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;
    227239   
    228240    -  ``rnd`` - (string) the rounding mode
    229241
     
    237249
    238250      - 'RNDU' - round towards plus infinity
    239251   
     252    - ``sci_not`` - deprecated.  See ``scientific_notation``.
     253
    240254    EXAMPLES::
    241255   
    242256        sage: RealField(10)
     
    263277       numbers (double type in C), except the default exponent range
    264278       is much wider and subnormal numbers are not implemented.'
    265279    """
     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()))
    266297    try:
    267         return RealField_cache[prec, sci_not, rnd]
     298        return RealField_cache[prec, rnd, print_cached]
    268299    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)
    270301        return R
    271302
    272303cdef class RealField_class(sage.rings.ring.Field):
     
    282313    details.
    283314    """
    284315
    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
    286323        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
    287335        cdef RealNumber rn
    288336        if prec < MPFR_PREC_MIN or prec > MY_MPFR_PREC_MAX:
    289337            raise ValueError, "prec (=%s) must be >= %s and <= %s."%(
     
    291339        self.__prec = prec
    292340        if not isinstance(rnd, str):
    293341            raise TypeError, "rnd must be a string"
    294         self.sci_not = sci_not
     342        self.print_options=print_options
    295343        n = _rounding_modes.index(rnd)
    296344        if n == -1:
    297345            raise ValueError, "rnd (=%s) must be one of RNDN, RNDZ, RNDU, or RNDD"%rnd
     
    536584       
    537585        ::
    538586       
    539             sage: RealField(10,sci_not=True) == RealField(10,sci_not=False)
     587            sage: RealField(10,scientific_notation='always') == RealField(10,scientific_notation='extreme')
    540588            True
    541589            sage: RealField(10) == IntegerRing()
    542590            False
    543591       
    544592        ::
    545593       
    546             sage: RS = RealField(sci_not=True)
     594            sage: RS = RealField(scientific_notation='always')
    547595            sage: RR == RS
    548596            True
    549             sage: RS.scientific_notation(False)
     597            sage: RS.print_options['scientific_notation']='extreme'
    550598            sage: RR == RS
    551599            True
    552600        """
     
    554602            return -1
    555603        cdef RealField_class _other
    556604        _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:
    559606            return 0
    560607        return 1
    561608
     
    565612
    566613        EXAMPLES::
    567614       
    568             sage: R = RealField(sci_not=1, prec=200, rnd='RNDU')
     615            sage: R = RealField(scientific_notation='always', prec=200, rnd='RNDU')
    569616            sage: loads(dumps(R)) == R
    570617            True
    571618        """
    572         return __create__RealField_version0, (self.__prec, self.sci_not, self.rnd_str)
     619        return __create__RealField_version1, (self.__prec, self.rnd_str, self.print_options)
    573620       
    574621    def construction(self):
    575622        """
     
    591638        from sage.categories.pushout import CompletionFunctor
    592639        return (CompletionFunctor(sage.rings.infinity.Infinity,
    593640                                  self.prec(),
    594                                   {'sci_not': self.scientific_notation(), 'rnd': self.rounding_mode()}),
     641                                  {'rnd': self.rounding_mode(),'print_options': self.print_options}),
    595642               sage.rings.rational_field.QQ)
    596643
    597644    def gen(self, i=0):
     
    813860        if prec == self.__prec:
    814861            return self
    815862        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)
    817865   
    818866    # int mpfr_const_pi (mpfr_t rop, mp_rnd_t rnd)
    819867    def pi(self):
     
    10061054
    10071055    def scientific_notation(self, status=None):
    10081056        """
     1057        .. warning:: Deprecated.  See :meth:`printing_options` for
     1058           this functionality.
     1059       
    10091060        Set or return the scientific notation printing flag. If this flag
    10101061        is True then real numbers with this space as parent print using
    10111062        scientific notation.
     
    10131064        INPUT:
    10141065           
    10151066        -  ``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
    10171076        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'
    10191079        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
    10221108    def zeta(self, n=2):
    10231109        """
    10241110        Return an `n`-th root of unity in the real field, if one
     
    12631349        """
    12641350        EXAMPLES::
    12651351       
    1266             sage: R = RealField(sci_not=1, prec=200, rnd='RNDU')
     1352            sage: R = RealField(scientific_notation='always', prec=200, rnd='RNDU')
    12671353            sage: b = R('393.39203845902384098234098230948209384028340')
    12681354            sage: loads(dumps(b)) == b
    12691355            True
     
    12801366            sage: loads(dumps(b)) == b
    12811367            True
    12821368        """
    1283         s = self.str(32, no_sci=False, e='@')
     1369        s = self.str(32, scientific_notation='always', e='@')
    12841370        return (__create__RealNumber_version0, (self._parent, s, 32))
    12851371
    12861372    def  __dealloc__(self):
     
    13211407            sage: s1 == RR(gp(s1))
    13221408            True
    13231409        """
    1324         return self.str(10, no_sci=True, truncate=False)
     1410        return self.str(10, scientific_notation='extreme', truncate=False)
    13251411
    13261412    def _sage_input_(self, sib, coerced):
    13271413        r"""
     
    15221608        """
    15231609        return self._parent
    15241610
    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):
    15261612        """
    15271613        INPUT:
    15281614       
    15291615       
    15301616        -  ``base`` - base for output
    15311617       
    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.
    15371628
    15381629        -  ``e`` - symbol used in scientific notation; defaults to 'e' for
    15391630           base=10, and '@' otherwise
     
    15511642            '20.333333333333332'
    15521643            sage: a.str(2)
    15531644            '10100.010101010101010101010101010101010101010101010101'
    1554             sage: a.str(no_sci=False)
     1645            sage: a.str(scientific_notation='always')
    15551646            '2.03333333333333e1'       
    1556             sage: a.str(16, no_sci=False)
     1647            sage: a.str(16, scientific_notation='always')
    15571648            '1.4555555555555@1'
    15581649            sage: b = 2.0^99
    15591650            sage: b.str()
    15601651            '6.33825300114115e29'
    1561             sage: b.str(no_sci=False)
     1652            sage: b.str(scientific_notation='always')
    15621653            '6.33825300114115e29'
    1563             sage: b.str(no_sci=True)
     1654            sage: b.str(scientific_notation='extreme')
    15641655            '6.33825300114115e29'
    15651656            sage: c = 2.0^100
    15661657            sage: c.str()
    15671658            '1.26765060022823e30'
    1568             sage: c.str(no_sci=False)
     1659            sage: c.str(scientific_notation='always')
    15691660            '1.26765060022823e30'
    1570             sage: c.str(no_sci=True)
     1661            sage: c.str(scientific_notation='extreme')
    15711662            '1.26765060022823e30'
    1572             sage: c.str(no_sci=2)
     1663            sage: c.str(scientific_notation='never')
    15731664            '1267650600228230000000000000000.'
    15741665            sage: 0.5^53
    15751666            1.11022302462516e-16
     
    15881679        """
    15891680        if base < 2 or base > 36:
    15901681            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           
    15911691        if mpfr_nan_p(self.value):
    15921692            if base >= 24:
    15931693                return "@NaN@"
     
    16051705            else:
    16061706                e = 'e'
    16071707
     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
    16081714        cdef char *s
    16091715        cdef mp_exp_t exponent
    16101716
     
    16511757        if t[0] == "-":
    16521758            digits = digits - 1
    16531759
    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':
    16611765            if t[0] == "-":
    16621766                return "-%s.%s%s%s"%(t[1:2], t[2:], e, exponent-1)
    16631767            return "%s.%s%s%s"%(t[0], t[1:], e, exponent-1)
     
    49695073
    49705074
    49715075# here because this imports the other two real fields
    4972 def create_RealField(prec=53, type="MPFR", rnd="RNDN", sci_not=0):
     5076def 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    """
    49735092    if type == "RDF":
    49745093        return RDF
    49755094    elif type == "RQDF":
     
    49775096        return RQDF
    49785097    elif type == "Interval":
    49795098        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)
    49815100    elif type == "RLF":
    49825101        from real_lazy import RLF
    49835102        return RLF
    49845103    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)
    49865105
    49875106
    49885107def is_RealField(x):
     
    50175136    """
    50185137    return PY_TYPE_CHECK(x, RealNumber)
    50195138
     5139def __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
    50205151def __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)
    50225166
    50235167def __create__RealNumber_version0(parent, x, base=10):
    50245168    """