#6870: [with third patch, needs review] 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):

 Replying to [comment:8 hgranath]:
 > I really have no idea what to do. So assume we have something like
 >
 > {{{
 > if isinstance(x,Expression):
 > }}}
 >
 > then what to do? We have no idea at this point if x happens to be
 something
 > like SR(10**7) or n+1, and we will not know until we try x=ZZ(x). If
 > that try should fail, it is already too late to avoid the time penalty
 > that is the point of this discussion.

 Understood; I think I didn't catch what the salient point was in your
 earlier comment, but now I do, and I agree that there is no easy way
 around it.  My apologies.

 Here is my last idea.  I think that the .pyobject() method of Expression
 can catch this - because it returns an error for anything which is not a
 bare coefficient:
 {{{
 sage: def h():
     try:
         a.pyobject()
         return ZZ(a)
     except:
             return a
 sage: a = n+1
 sage: h()
 n + 1
 sage: timeit('h()')
 625 loops, best of 3: 5.98 µs per loop
 sage: a = SR(10^7)
 sage: timeit('h()')
 625 loops, best of 3: 1.89 µs per loop
 }}}
 The docstring confirms this performs as advertised.  If that doesn't speed
 things up, then I guess it's not possible :(

 So if that doesn't work, your original solution stands as a definite
 improvement, with the changes you noted - put the rational check inside
 the already existing not isinstance(m, int etc.) check, before trying m =
 ZZ(m), do the floating point fix where you have it.  Oh yeah, be sure to
 add doctests for the SR(10**7) etc.

 Because in the long run, we should have more correct cases, I think.  If
 someone notices a really bad slowdown, we will have to write a very fast
 symbolic binomial or something.  But all of these are an improvement on
 before.  Thanks for all of it!

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6870#comment:9>
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