Re: QQ random_matrix()

61 views
Skip to first unread message

Kenneth Lin

unread,
May 14, 2013, 9:06:11 PM5/14/13
to sage-...@googlegroups.com
Has anyone taken a look at this or know what's wrong? Just wanted to bump this once if anyone missed it

Rob Beezer

unread,
May 15, 2013, 12:39:08 AM5/15/13
to sage-...@googlegroups.com
The zeros problem is known:

http://trac.sagemath.org/sage_trac/ticket/11968

I could be responsible for some of this - but not all, as the documentation was in even worse shape before I attacked it.  I might be able to revist some of this soon, but not immediately.

Rob

On Thursday, May 9, 2013 8:17:30 PM UTC-7, Kenneth Lin wrote:
Hey everyone,

So I'm not sure if I discovered two bugs in random_matrix or if I'm reading the documentation wrong. Firstly, in the documentation, it says:

   Random integer matrices.  With no arguments, the majority of the
   entries are -1 and 1, never zero, and rarely "large."
      sage: random_matrix(ZZ, 5, 5)
      [ -8   2   0   0   1]
      [ -1   2   1 -95  -1]
      [ -2 -12   0   0   1]
      [ -1   1  -1  -2  -1]
      [  4  -4  -6   5   0]

Now, it appears that there are 0's in the matrix produced. This also happens when I run the exact function above. Is this a bug in the documentation or the function?

Secondly, the documentation says this about random matrices in rational fields:

   Random rational matrices.  Now "num_bound" and "den_bound" control
   the generation of random elements, by specifying limits on the
   absolute value of numerators and denominators (respectively).
   Entries will be positive and negative (map the absolute value
   function through the entries to get all positive values), and zeros
   are avoided unless the density is set.  If either the numerator or
   denominator bound (or both) is not used, then the values default to
   the distribution for ZZ described above that is most frequently
   positive or negative one.


However, when I run <code>random_matrix(QQ, 10, 10)</code>, it appears all the numbers are either 0, 1, 2, -1, -2, 1/2, and -1/2. This doesn't seem to be the "most frequently positive or negative one" distribution, but instead the "uniform" one for integers. I could imagine it being such that two numbers every time with the uniform distribution as the numerator and denominator and the two are divided. Could anyone else verify this behavior?

Thanks

Kenneth Lin

unread,
May 19, 2013, 4:40:55 AM5/19/13
to sage-...@googlegroups.com
Ah, I see. Can you tell me what the intended behavior should be? I was hoping I could help out somewhere, but I'd need to know what should be intended in both the documentation and the function. Also, do you know anything about the function's behavior on QQ?

Rob Beezer

unread,
May 20, 2013, 7:01:05 PM5/20/13
to sage-...@googlegroups.com
Generally, it would be best to review the code for intent and test the output to see if the intent is realized. The documentation should then reflect this.

Changing behavior would require a stronger rationale, such as bug you might discover when reviewing code and output.

Feel free to cc me if you write a patch.

Rob

Kenneth Lin

unread,
May 21, 2013, 4:54:15 AM5/21/13
to sage-...@googlegroups.com
Will do. I have a few other things on hand right now though but I'll definitely get to it eventually. In the meantime, anyone else feel free to review this.
Reply all
Reply to author
Forward
0 new messages