On Sat, Oct 9, 2010 at 11:59 AM, David Kirkby <david.kir...@onetel.net> wrote: > I beg to differ ~John - to me it is *very* confusing to me, but then > I've not used Sage much.
It is because you aren't familiar with Python and its conventions. > It's not obvious to me if random_prime() is called with two > arguments, whether the second argument is the lower bound, or the > proof. How am I supposed to know? If you call it with with only positional arguments then it uses the order that is in the function definition. > Neither is it obvious to me if the 'proof' should be one of "None", > "bool" or "False". This is right in the docstring. > * This returns a prime between 20 and 123, so I might reasonably > expect that the second argument is the lower bound and not the proof. > > sage: random_prime(123,20) > 109 Incorrect. > * But this returns a prime under 123, so I might conclude the second > argument is taken to be the proof When you call it like that, the second argument is the proof keyword. > sage: random_prime(123,bool) > 29 Nope. When bool is written in the docstring, it means to pass in either True or False -- not the bool type. > sage: random_prime(123,None) > 59 This is the same as "random_prime(123), > sage: random_prime(123,False) > 83 Usually, you'd write this random_prime(123, proof=False) > * I don't have a ******* clue what this is doing! > > sage: random_prime(123,2000) > 3 > > Is 2000 the lower bound? The proof? 2000 is what you're passing in as the proof parameter. Since bool(2000) is True, this is equivalent to random_prime(123, proof=True). > I had a thought. Clearly the fact this generates random data can cause > issues with doctesting. But we could avoid that by suitable choice or > the range This is handled by setting the random seed. > Since I can't work out what the Sage one is doing, I'll use a couple > of examples from Mathematica using RandomPrime[] which I feel is > better documented. > > http://reference.wolfram.com/mathematica/ref/RandomPrime.html > > In[8]:= RandomPrime[{10000000,10000900}] > > Out[8]= 10000871 > > In[9]:= RandomPrime[{10000000,10000900}] > > Out[9]= 10000103 If you want this, you'd do random_prime(10000900, lbound=10000000) --Mike -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org