#6870: [with second patch, needs work] Bug in binomial
------------------------------+---------------------------------------------
 Reporter:  hgranath          |       Owner:  somebody  
     Type:  defect            |      Status:  new       
 Priority:  minor             |   Milestone:  sage-4.1.2
Component:  basic arithmetic  |    Keywords:  binomial  
 Reviewer:                    |      Author:            
   Merged:                    |  
------------------------------+---------------------------------------------

Comment(by kcrisman):

 Maybe this?
 {{{
 sage: var('n')
 n
 sage: a = n+1
 sage: from sage.symbolic.expression import Expression
 sage: isinstance(a,Expression)
 True
 sage: def g():
 ....:     isinstance(a,Expression)
 ....:
 sage: timeit('g()')
 625 loops, best of 3: 573 ns per loop
 sage: a=SR(10**7)
 sage: timeit('g()')
 625 loops, best of 3: 595 ns per loop
 sage: timeit('f()')
 625 loops, best of 3: 1.59 µs per loop
 }}}
 You can still use try: ZZ(x), it just makes sense to check type first,
 since it adds only nanoseconds, and then if someone is silly enough to use
 SR(10**7) instead of 10**7, they'll have to pay the microsecond penalty.
 I jest a little, but I think you should try something like this to see if
 it would work.  If not, the first patch is probably better than allowing
 rational things to get through.  You could also add a check for rationals
 instead:
 {{{
 sage: from sage.rings.rational import Rational
 sage: def g():
 ....:     isinstance(a,Rational)
 ....:
 sage: timeit('g()')
 625 loops, best of 3: 1.23 µs per loop
 sage: a = 10**7-1/1
 sage: type(a)
 <type 'sage.rings.rational.Rational'>
 sage: timeit('g()')
 625 loops, best of 3: 570 ns per loop
 }}}
 So even if a isn't rational, you lose very little time by checking that
 before you coerce.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6870#comment:5>
Sage <http://sagemath.org/>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to