Issue 3086 in sympy: round() function overrides built-in

2 views
Skip to first unread message

sy...@googlecode.com

unread,
Feb 18, 2012, 3:50:12 AM2/18/12
to sympy-...@googlegroups.com
Status: Accepted
Owner: ----
CC: smi...@gmail.com
Labels: Type-Defect Priority-Critical

New issue 3086 by asme...@gmail.com: round() function overrides built-in
http://code.google.com/p/sympy/issues/detail?id=3086

See https://github.com/sympy/sympy/pull/998. The recently (since the last
release) added round() function needs to be renamed, as it overrides the
built-in round(), which we decided a while back was a bad idea.

Round() is probably a good replacement.

sy...@googlecode.com

unread,
Feb 18, 2012, 6:48:54 AM2/18/12
to sympy-...@googlegroups.com

Comment #1 on issue 3086 by smi...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

Unlike __int__ there is not way to keep the same name for round, so I made
it to default quickly to python's built-in. The time difference is < 3%. Is
this significant enough to warrant having to use a different name?

>>> from sympy.functions.elementary.miscellaneous import _pyround
>>> from timeit import timeit
>>> timeit('_pyround(randint(1,1000000))','from
>>> sympy.functions.elementary.misc
llaneous import _pyround\nfrom random import randint')
2.8012628194217446
>>> timeit('round(randint(1,1000000))','from
>>> sympy.functions.elementary.miscell
neous import _pyround\nfrom random import randint')
2.8702862158276918

(If the name change is deemed necessary, I would prefer a non-caps name
like `rounded` since, unlike Abs, it isn't a class.)

sy...@googlecode.com

unread,
Feb 18, 2012, 7:29:05 AM2/18/12
to sympy-...@googlegroups.com
Updates:
Cc: -smi...@gmail.com

Comment #2 on issue 3086 by smi...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

Which discussion are you referring to, btw. I recall discussion about int,
was it?

sy...@googlecode.com

unread,
Feb 18, 2012, 7:33:06 AM2/18/12
to sympy-...@googlegroups.com

Comment #3 on issue 3086 by smi...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

Or perhaps it was sum. We decided to go with summation for that routine.
But it has a much greater overhead than round in terms of figuring out if
the arbitrary number of args are python objects or sympy objects whereas
round only has a single argument to consider.

sy...@googlecode.com

unread,
Feb 18, 2012, 3:44:40 PM2/18/12
to sympy-...@googlegroups.com
Updates:
Cc: Ronan.L...@gmail.com

Comment #4 on issue 3086 by asme...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

See issue 1376 and issue 1727. The issue was with sum and abs.

sy...@googlecode.com

unread,
Feb 18, 2012, 3:48:40 PM2/18/12
to sympy-...@googlegroups.com

Comment #5 on issue 3086 by asme...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

The argument there had nothing to do with overhead. It was all about making
the API clean.

sy...@googlecode.com

unread,
Feb 20, 2012, 8:10:30 PM2/20/12
to sympy-...@googlegroups.com

Comment #6 on issue 3086 by Ronan.L...@gmail.com: round() function
overrides built-in
http://code.google.com/p/sympy/issues/detail?id=3086

Actually, I don't understand what this new round() does, apart from
sympifying the result of __builtin__.round(). In any case, it doesn't
behave like a sympy Function, so it's misleading to have it inside
sympy.functions.

sy...@googlecode.com

unread,
Feb 23, 2012, 1:13:05 PM2/23/12
to sympy-...@googlegroups.com

Comment #7 on issue 3086 by smi...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

> The argument there had nothing to do with overhead.

Regarding overhead, see our brief discussion about point 4 at
http://code.google.com/p/sympy/issues/detail?id=1727#c13

> I don't understand what this new round() does

Compare:
>>> __builtins__.round(pi**100)
5.1878483143196132e+49
>>> round(pi**100)
51878483143196131920862615246303013562686760680406.

Perhaps it could be made the round *method*?

sy...@googlecode.com

unread,
Feb 29, 2012, 6:46:52 AM2/29/12
to sympy-...@googlegroups.com

Comment #8 on issue 3086 by papriwal...@gmail.com: round() function
overrides built-in
http://code.google.com/p/sympy/issues/detail?id=3086

it could be made roundoff()

sy...@googlecode.com

unread,
Feb 29, 2012, 10:51:55 AM2/29/12
to sympy-...@googlegroups.com

Comment #9 on issue 3086 by smi...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

I think the most compelling reason to change the name is that whereas our
override of int returns an int, our round currently returns a sympy Float.
We just need to agree on a new name. Suggestions so far:

roundoff(expr)
expr.round()
rounded(expr)

/c

sy...@googlecode.com

unread,
Mar 1, 2012, 12:25:35 AM3/1/12
to sympy-...@googlegroups.com

Comment #10 on issue 3086 by papriwal...@gmail.com: round() function
overrides built-in
http://code.google.com/p/sympy/issues/detail?id=3086

sticking to round will not be a good option .. rather go with either
roundoff(expr) or rounded(expr) .

sy...@googlecode.com

unread,
Mar 1, 2012, 12:50:42 AM3/1/12
to sympy-...@googlegroups.com

Comment #11 on issue 3086 by smi...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

Do you mean that you would not be in favor of using a round method?

sy...@googlecode.com

unread,
Mar 1, 2012, 1:05:46 AM3/1/12
to sympy-...@googlegroups.com

Comment #12 on issue 3086 by papriwal...@gmail.com: round() function
overrides built-in
http://code.google.com/p/sympy/issues/detail?id=3086

no i mean using round for the above function will not be a good option ..
as it will override with already present round function (in python).

sy...@googlecode.com

unread,
Mar 1, 2012, 4:12:25 AM3/1/12
to sympy-...@googlegroups.com

Comment #13 on issue 3086 by asme...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

A round() method would be reasonable, I think, as it doesn't work on
non-Number objects anyway.

Unless you want to make it potentially work symbolically. In that case,
Round() would be OK.

sy...@googlecode.com

unread,
Mar 1, 2012, 6:59:21 AM3/1/12
to sympy-...@googlegroups.com

Comment #14 on issue 3086 by papriwal...@gmail.com: round() function
overrides built-in
http://code.google.com/p/sympy/issues/detail?id=3086

agree with asme...@gmail.com , unless we make it work symbolically , then
only there is a need of name change else it is fine .. and on the other
hand there is no need to keep this function inside sympy.functions ..

sy...@googlecode.com

unread,
Mar 1, 2012, 8:05:43 AM3/1/12
to sympy-...@googlegroups.com

Comment #15 on issue 3086 by papriwal...@gmail.com: round() function
overrides built-in
http://code.google.com/p/sympy/issues/detail?id=3086

hey guys, i saw one thing that
>>> round(3.14j)
>>> cant convert complex into float (error)

moreover

>>> round(3.14j+7*sin(exp(2)))
>>> Symbolic value , cant compute

but matlab provides the allows the above computations

http://www.mathworks.in/help/toolbox/mupad/stdlib/round.html

please see to it .. we can work to develop a symbolic rounding off
function ..

sy...@googlecode.com

unread,
Mar 1, 2012, 12:34:40 PM3/1/12
to sympy-...@googlegroups.com

Comment #16 on issue 3086 by smi...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

It took me a moment to find it...but when the number is complex, they just
round the two parts. This makes sense, I think.

>>> [round(a) for a in S(3.14j+7*sin(exp(2))).as_real_imag()]
[6., 3.]
>>> _[0] + I*_[1]
6.0 + 3.0*I

Aaron:


> it doesn't work on non-Number objects anyway.

You must mean non-numeric, b/c

>>> round(sqrt(2) + 3, 3)
4.414


sy...@googlecode.com

unread,
Mar 3, 2012, 7:38:06 AM3/3/12
to sympy-...@googlegroups.com

Comment #17 on issue 3086 by papriwal...@gmail.com: round() function
overrides built-in
http://code.google.com/p/sympy/issues/detail?id=3086

@smichr ... i think we can make this adjustment say ...
round(3.14j+6.86) gives 7+3j in sympy console ... what say ...

sy...@googlecode.com

unread,
Mar 4, 2012, 3:38:59 PM3/4/12
to sympy-...@googlegroups.com

Comment #18 on issue 3086 by asme...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

> You must mean non-numeric, b/c

Ah yes. I always forget the scope of the Number class. So I guess it will
have to be a method of Expr if we go that route.

sy...@googlecode.com

unread,
Mar 15, 2012, 5:22:10 AM3/15/12
to sympy-...@googlegroups.com

Comment #19 on issue 3086 by papriwal...@gmail.com: round() function
overrides built-in
http://code.google.com/p/sympy/issues/detail?id=3086

what u mean by scope of NUmber Class .

sy...@googlecode.com

unread,
Mar 15, 2012, 5:32:24 AM3/15/12
to sympy-...@googlegroups.com

Comment #20 on issue 3086 by smi...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

There is a sympy object, Number, from which Float, Integer, Rational and
+/-Infinity derive. Things which evaluate to a Number are not necessarily
Numbers themselves, e.g. `sqrt(3) + 2` is an Add object, not within the
scope of (not an instance of) Number.

>>> sqrt(3).is_number
True
>>> sqrt(3).is_Number
False


sy...@googlecode.com

unread,
Mar 15, 2012, 6:39:00 AM3/15/12
to sympy-...@googlegroups.com
Updates:
Labels: NeedsReview smichr

Comment #21 on issue 3086 by smi...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

https://github.com/sympy/sympy/pull/1124

sy...@googlecode.com

unread,
Mar 15, 2012, 6:43:02 AM3/15/12
to sympy-...@googlegroups.com

Comment #22 on issue 3086 by smi...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

each part of a complex number is now rounded (but how it is printed is
still an issue):

>>> (pi+2*I*E).round()
3.0 + 5.0*I
>>> (pi).round()
3.

sy...@googlecode.com

unread,
Mar 17, 2012, 8:33:45 PM3/17/12
to sympy-...@googlegroups.com
Updates:
Status: Fixed

Comment #23 on issue 3086 by smi...@gmail.com: round() function overrides
built-in
http://code.google.com/p/sympy/issues/detail?id=3086

(No comment was entered for this change.)

Reply all
Reply to author
Forward
0 new messages