Skip to content

Commit

Permalink
Rename 'Real' to 'Float' (see issue #1721).
Browse files Browse the repository at this point in the history
This makes it clear that there is a fundamental difference between
infinitely precise, symbolically described real numbers like pi or
atan(1/7), and floating-point numbers.
  • Loading branch information
rlamy authored and smichr committed May 24, 2011
1 parent 78899b4 commit abe1c49
Show file tree
Hide file tree
Showing 86 changed files with 337 additions and 338 deletions.
4 changes: 2 additions & 2 deletions doc/src/gotchas.txt
Expand Up @@ -278,10 +278,10 @@ to a Python expression. Use the :func:`sympify` function, or just
6.2000000000000002
>>> type(6.2)
<type 'float'>
>>> S(6.2) # SymPy Real has no such problems because of arbitrary precision.
>>> S(6.2) # SymPy Float has no such problems because of arbitrary precision.
6.20000000000000
>>> type(S(6.2))
<class 'sympy.core.numbers.Real'>
<class 'sympy.core.numbers.Float'>

If you include numbers in a SymPy expression, they will be sympified
automatically, but there is one gotcha you should be aware of. If you
Expand Down
4 changes: 2 additions & 2 deletions doc/src/guide.txt
Expand Up @@ -114,8 +114,8 @@ Basics

All symbolic things are implemented using subclasses of the ``Basic`` class.
First, you need to create symbols using ``Symbol("x")`` or numbers using
``Integer(5)`` or ``Real(34.3)``. Then you construct the expression using any
class from SymPy. For example ``Add(Symbol("a"),Symbol("b"))`` gives an
``Integer(5)`` or ``Float(34.3)``. Then you construct the expression using any
class from SymPy. For example ``Add(Symbol("a"), Symbol("b"))`` gives an
instance of the ``Add`` class. You can call all methods, which the particular
class supports.

Expand Down
14 changes: 7 additions & 7 deletions doc/src/modules/evalf.txt
Expand Up @@ -75,22 +75,22 @@ significantly speed up computations such as the one above.
Floating-point numbers
----------------------

Floating-point numbers in SymPy are instances of the class ``Real``. A ``Real``
Floating-point numbers in SymPy are instances of the class ``Float``. A ``Float``
can be created with a custom precision as second argument:

>>> Real(0.1)
>>> Float(0.1)
0.100000000000000
>>> Real(0.1, 10)
>>> Float(0.1, 10)
0.1000000000
>>> Real(0.1, 30)
>>> Float(0.1, 30)
0.100000000000000005551115123126


As the last example shows, Python floats are only accurate to about 15 digits as
inputs. To create a ``Real`` from a high-precision decimal number, it is better
inputs. To create a ``Float`` from a high-precision decimal number, it is better
to pass a string or ``evalf`` a ``Rational``:

>>> Real('0.1', 30)
>>> Float('0.1', 30)
0.100000000000000000000000000000
>>> Rational(1,10).evalf(30)
0.100000000000000000000000000000
Expand Down Expand Up @@ -357,7 +357,7 @@ and a minimum numerical tolerance. Here are some elementary examples:

Here are several more advanced examples:

>>> nsimplify(Real('0.130198866629986772369127970337',30), [pi, E])
>>> nsimplify(Float('0.130198866629986772369127970337',30), [pi, E])
1
----------
5*pi
Expand Down
2 changes: 1 addition & 1 deletion doc/src/tutorial.txt
Expand Up @@ -123,7 +123,7 @@ Documentation can be found at http://www.sympy.org
Using SymPy as a calculator
---------------------------

Sympy has three built-in numeric types: Real, Rational and Integer.
Sympy has three built-in numeric types: Float, Rational and Integer.

The Rational class represents a rational number as a pair of two Integers: the numerator and the denominator, so Rational(1,2) represents 1/2, Rational(5,2) 5/2 and so on.

Expand Down
2 changes: 1 addition & 1 deletion examples/beginner/substitution.py
Expand Up @@ -20,7 +20,7 @@ def main():
pprint(e.subs(sympy.cos(x), y).subs(y, x**2))

e = 1/sympy.log(x)
e = e.subs(x, sympy.Real("2.71828"))
e = e.subs(x, sympy.Float("2.71828"))
print '\n'
pprint(e)
print '\n'
Expand Down
4 changes: 2 additions & 2 deletions examples/intermediate/sample.py
Expand Up @@ -6,7 +6,7 @@
"""

from numpy import repeat, arange, empty, ndarray, array
from sympy import Symbol, Basic, Real, Rational, I, sympify
from sympy import Symbol, Basic, Rational, I, sympify

def sample2d(f, x_args):
"""
Expand Down Expand Up @@ -52,7 +52,7 @@ def sample3d(f, x_args, y_args):
try:
f = sympify(f)
except:
raise ValueError("f could not be interpretted as a SymPy function")
raise ValueError("f could not be interpreted as a SymPy function")
try:
x, x_min, x_max, x_n = x_args
y, y_min, y_max, y_n = y_args
Expand Down
4 changes: 2 additions & 2 deletions sympy/assumptions/handlers/ntheory.py
Expand Up @@ -58,7 +58,7 @@ def Rational(expr, assumptions):
return False

@staticmethod
def Real(expr, assumptions):
def Float(expr, assumptions):
return AskPrimeHandler._number(expr, assumptions)

@staticmethod
Expand Down Expand Up @@ -167,7 +167,7 @@ def Rational(expr, assumptions):
return False

@staticmethod
def Real(expr, assumptions):
def Float(expr, assumptions):
return expr % 2 == 0

@staticmethod
Expand Down
6 changes: 3 additions & 3 deletions sympy/assumptions/handlers/sets.py
Expand Up @@ -73,7 +73,7 @@ def Rational(expr, assumptions):
return False

@staticmethod
def Real(expr, assumptions):
def Float(expr, assumptions):
return int(expr) == expr

@staticmethod
Expand Down Expand Up @@ -138,7 +138,7 @@ def Rational(expr, assumptions):
return True

@staticmethod
def Real(expr, assumptions):
def Float(expr, assumptions):
# it's finite-precission
return True

Expand Down Expand Up @@ -240,7 +240,7 @@ def Rational(expr, assumptions):
return True

@staticmethod
def Real(expr, assumptions):
def Float(expr, assumptions):
return True

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion sympy/concrete/tests/test_sums_products.py
@@ -1,4 +1,4 @@
from sympy import (S, Symbol, Sum, oo, Real, Rational, summation, pi, cos,
from sympy import (S, Symbol, Sum, oo, Float, Rational, summation, pi, cos,
zeta, exp, log, factorial, sqrt, E, sympify, binomial, harmonic, Catalan,
EulerGamma, Function, Integral, Product, product, nan, diff, Derivative)
from sympy.concrete.summations import telescopic
Expand Down
2 changes: 1 addition & 1 deletion sympy/core/__init__.py
Expand Up @@ -7,7 +7,7 @@
from singleton import S
from expr import Expr, AtomicExpr
from symbol import Symbol, Wild, Dummy, symbols, var, Pure
from numbers import Number, Real, Rational, Integer, NumberSymbol,\
from numbers import Number, Float, Rational, Integer, NumberSymbol,\
RealNumber, igcd, ilcm, seterr, E, I, nan, oo, pi, zoo
from power import Pow, integer_nthroot
from mul import Mul
Expand Down
2 changes: 1 addition & 1 deletion sympy/core/basic.py
Expand Up @@ -59,7 +59,7 @@ class Basic(AssumeMeths):
is_Mul = False
is_Pow = False
is_Number = False
is_Real = False
is_Float = False
is_Rational = False
is_Integer = False
is_NumberSymbol = False
Expand Down
2 changes: 1 addition & 1 deletion sympy/core/cache.py
Expand Up @@ -275,7 +275,7 @@ class Memoizer_nocache(Memoizer):

def __call__(self, func):
# XXX I would be happy just to return func, but we need to provide
# argument convertion, and it is really needed for e.g. Real("0.5")
# argument convertion, and it is really needed for e.g. Float("0.5")
@wraps(func)
def wrapper(*args, **kw_args):
kw_items = tuple(kw_args.items())
Expand Down
2 changes: 1 addition & 1 deletion sympy/core/core.py
Expand Up @@ -9,7 +9,7 @@
# singleton numbers
'Zero', 'One','Half','Infinity','NaN','NegativeOne','NegativeInfinity',
# numbers
'Integer','Rational','Real',
'Integer','Rational','Float',
# singleton symbols
'Exp1','Pi','ImaginaryUnit',
# symbols
Expand Down
16 changes: 8 additions & 8 deletions sympy/core/evalf.py
Expand Up @@ -617,7 +617,7 @@ def evalf_piecewise(expr, prec, options):
if hasattr(expr,'func'):
return evalf(expr, prec, options)
if type(expr) == float:
return evalf(C.Real(expr), prec, options)
return evalf(C.Float(expr), prec, options)
if type(expr) == int:
return evalf(C.Integer(expr), prec, options)

Expand Down Expand Up @@ -866,7 +866,7 @@ def evalf_sum(expr, prec, options):
return v, None, min(prec, delta), None
except NotImplementedError:
# Euler-Maclaurin summation for general series
eps = C.Real(2.0)**(-prec)
eps = C.Float(2.0)**(-prec)
for i in range(1, 5):
m = n = 2**i * prec
s, err = expr.euler_maclaurin(m=m, n=n, eps=eps, \
Expand Down Expand Up @@ -911,7 +911,7 @@ def _create_evalf_table():
evalf_table = {
C.Symbol : evalf_symbol,
C.Dummy : evalf_symbol,
C.Real : lambda x, prec, options: (x._mpf_, None, prec, None),
C.Float : lambda x, prec, options: (x._mpf_, None, prec, None),
C.Rational : lambda x, prec, options: (from_rational(x.p, x.q, prec), None, prec, None),
C.Integer : lambda x, prec, options: (from_int(x.p, prec), None, prec, None),
C.Zero : lambda x, prec, options: (None, None, prec, None),
Expand Down Expand Up @@ -1035,13 +1035,13 @@ def evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None,
if re:
p = max(min(prec, re_acc), 1)
#re = mpf_pos(re, p, round_nearest)
re = C.Real._new(re, p)
re = C.Float._new(re, p)
else:
re = S.Zero
if im:
p = max(min(prec, im_acc), 1)
#im = mpf_pos(im, p, round_nearest)
im = C.Real._new(im, p)
im = C.Float._new(im, p)
return re + im*S.ImaginaryUnit
else:
return re
Expand All @@ -1066,19 +1066,19 @@ def _to_mpmath(self, prec, allow_ints=True):
v = self._eval_evalf(prec)
if v is None:
raise ValueError(errmsg)
if v.is_Real:
if v.is_Float:
return make_mpf(v._mpf_)
# Number + Number*I is also fine
re, im = v.as_real_imag()
if allow_ints and re.is_Integer:
re = from_int(re.p)
elif re.is_Real:
elif re.is_Float:
re = re._mpf_
else:
raise ValueError(errmsg)
if allow_ints and im.is_Integer:
im = from_int(im.p)
elif im.is_Real:
elif im.is_Float:
im = im._mpf_
else:
raise ValueError(errmsg)
Expand Down
14 changes: 7 additions & 7 deletions sympy/core/expr.py
Expand Up @@ -106,11 +106,11 @@ def __ge__(self, other):
@staticmethod
def _from_mpmath(x, prec):
if hasattr(x, "_mpf_"):
return C.Real._new(x._mpf_, prec)
return C.Float._new(x._mpf_, prec)
elif hasattr(x, "_mpc_"):
re, im = x._mpc_
re = C.Real._new(re, prec)
im = C.Real._new(im, prec)*S.ImaginaryUnit
re = C.Float._new(re, prec)
im = C.Float._new(im, prec)*S.ImaginaryUnit
return re+im
else:
raise TypeError("expected mpmath number (mpf or mpc)")
Expand Down Expand Up @@ -1052,8 +1052,8 @@ def extract_multiplicatively(self, c):
return None
else:
return quotient
elif self.is_Real:
if not quotient.is_Real:
elif self.is_Float:
if not quotient.is_Float:
return None
elif self.is_positive and quotient.is_negative:
return None
Expand Down Expand Up @@ -1141,8 +1141,8 @@ def extract_additively(self, c):
return None
else:
return sub
elif self.is_Real:
if not sub.is_Real:
elif self.is_Float:
if not sub.is_Float:
return None
elif self.is_positive and sub.is_negative:
return None
Expand Down
6 changes: 3 additions & 3 deletions sympy/core/function.py
Expand Up @@ -178,12 +178,12 @@ def _should_evalf(cls, arg):
ARG is a floating point number.
This function is used by __new__.
"""
if arg.is_Real:
if arg.is_Float:
return True
if not arg.is_Add:
return False
re, im = arg.as_real_imag()
return re.is_Real or im.is_Real
return re.is_Float or im.is_Float

@property
def is_commutative(self):
Expand All @@ -207,7 +207,7 @@ def _eval_evalf(self, prec):
func = getattr(mpmath, fname)
except (AttributeError, KeyError):
try:
return C.Real(self._imp_(*self.args), prec)
return C.Float(self._imp_(*self.args), prec)
except (AttributeError, TypeError):
return

Expand Down
2 changes: 1 addition & 1 deletion sympy/core/mul.py
Expand Up @@ -741,7 +741,7 @@ def _combine_inverse(lhs, rhs):
if lhs == rhs:
return S.One
def check(l, r):
if l.is_Real and r.is_comparable:
if l.is_Float and r.is_comparable:
return Add(l, 0) == Add(r.evalf(), 0)
return False
if check(lhs, rhs) or check(rhs, lhs):
Expand Down

0 comments on commit abe1c49

Please sign in to comment.