Re: [sage-devel] PolynomialRing().random_element() returns 0 rather often.

2023-12-30 Thread Maxime Bombar

On 12/30/23 13:43, Georgi Guninski wrote:

Just FYI:

def testquotient2():
 set_random_seed(1);p=next_prime(10**120);Kx=Integers(p)['x']
 l=[Kx.random_element() for _ in range(100)]
 return l.count(0)
testquotient2()
27


Hi,

this is because PolynomialRing().random_element() takes an optional 
argument degree which should either be an integer greater or equal to 
-1, or an ordered pair of such integers which defines an integer range 
in which the degree is selected uniformly at random. By convention, 
degree -1 yields the 0 polynomial, degree 0 yields a constant non zero 
and so on.


By default, this argument is set to (-1, 2), which means that which 25% 
probability, degree -1 will be selected, and this is exactly what you 
observe with your experiment. But you can set degree to whatever suits 
you better, e.g. starting with 0 instead of -1 to avoid the 0 polynomial.


For more information:

https://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/polynomial_ring.html#sage.rings.polynomial.polynomial_ring.PolynomialRing_general.random_element 



Best,

--
Maxime

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/401e78b2-baf4-4209-b9e1-1eec1e05e61f%40inria.fr.


[sage-devel] PolynomialRing().random_element() returns 0 rather often.

2023-12-30 Thread Georgi Guninski
Just FYI:

def testquotient2():
set_random_seed(1);p=next_prime(10**120);Kx=Integers(p)['x']
l=[Kx.random_element() for _ in range(100)]
return l.count(0)
testquotient2()
27

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/CAGUWgD_eXb%2BJi_CVBCC5_Q%3DiYhg0A%3DKnvZZCAbG9Fv-NKYSL7A%40mail.gmail.com.