#10112: random_prime  does not handle erroneous input gracefully - it hangs
-----------------------------+----------------------------------------------
   Reporter:  drkirkby       |       Owner:  was       
       Type:  defect         |      Status:  new       
   Priority:  major          |   Milestone:  sage-4.6.1
  Component:  number theory  |    Keywords:            
     Author:                 |    Upstream:  N/A       
   Reviewer:                 |      Merged:            
Work_issues:                 |  
-----------------------------+----------------------------------------------
 As noted at #10111 and

 http://groups.google.com/group/sage-
 devel/browse_thread/thread/6e8d6f28c915830d?hl=en

 {{{random_prime()}}} is not well documented.

 But {{{random_prime()}}} is also broken for some erroneous input. Programs
 should always handle poor input properly, which is the case of Sage
 probably means generating an error message.

 {{{
 sage: random_prime(0,True,-1) # Hangs
 sage: random_prime(0,False,-1) # Hangs
 sage: random_prime(1,0,-23) # Hangs
 sage: random_prime(-12,0,-12) # Hangs
 sage: random_prime(0, proof=False, lbound=-12) # Hangs
 }}}

 Having a negative lower bound can cause the function to hang, but this is
 not always the case, as the example below shows. Here an error message is
 generated.

 {{{
 sage: random_prime(-12,0,-4)
 ---------------------------------------------------------------------------
 ValueError                                Traceback (most recent call
 last)

 /export/home/drkirkby/sage-4.6.alpha3/<ipython console> in <module>()

 /export/home/drkirkby/sage-4.6.alpha3/local/lib/python2.6/site-
 packages/sage/rings/arith.pyc in random_prime(n, proof, lbound)
    1144     n = ZZ(n)
    1145     if n < lbound:
 -> 1146         raise ValueError, "n must be greater than lbound:
 %s"%(lbound)
    1147     elif n == 2:
    1148         return ZZ(n)

 ValueError: n must be greater than lbound: -4
 }}}

 Dave

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10112>
Sage <http://www.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