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.
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.)
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?
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.
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.
The argument there had nothing to do with overhead. It was all about making
the API clean.
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.
> 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*?
it could be made roundoff()
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
sticking to round will not be a good option .. rather go with either
roundoff(expr) or rounded(expr) .
Do you mean that you would not be in favor of using a round method?
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).
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.
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 ..
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 ..
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
@smichr ... i think we can make this adjustment say ...
round(3.14j+6.86) gives 7+3j in sympy console ... what say ...
> 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.
what u mean by scope of NUmber Class .
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
Comment #21 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.
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.)