#11725: Generate random elements of the algebraic field
----------------------------+-----------------------------------------------
   Reporter:  rbeezer       |          Owner:  AlexGhitza   
       Type:  enhancement   |         Status:  needs_review 
   Priority:  minor         |      Milestone:  sage-4.7.2   
  Component:  algebra       |       Keywords:  random, QQbar
Work_issues:                |       Upstream:  N/A          
   Reviewer:  Simon Spicer  |         Author:  Rob Beezer   
     Merged:                |   Dependencies:               
----------------------------+-----------------------------------------------
Changes (by spice):

  * keywords:  => random, QQbar
  * reviewer:  => Simon Spicer


Old description:

> Random elements of QQbar default to the method implemented for the
> integers.  This patch creates algebraic numbers via roots of random
> polynomials with integer coefficients.
>
> Implementation notes:
>   1.  Degree 2 is the default so that some complex numbers are generated.
>   1.  Might create constant polynomials, so a monic term (of random
> degree) may be added.
>   1.  Could be some efficiencies to be gained by not creating all the
> roots and choosing just one, but this should be a good start.
>   1.  Real goal was random vectors over `QQbar`.  A doctest demonstrates
> how control of the integer coefficients can be passed from
> `random_vector()` to the `QQbar.random_element()` to
> `ZZ.random_element()`.
>
> '''Apply''':
>   1. [attachment:trac_11725-random-algebraic-numbers.patch]

New description:

 Random elements of QQbar default to the method implemented for the
 integers.  This patch creates algebraic numbers via roots of random
 polynomials with integer coefficients.

 Implementation notes:
   1.  Degree 2 is the default so that some complex numbers are generated.
   1.  Might create constant polynomials, so a monic term (of random
 degree) may be added.
   1.  Could be some efficiencies to be gained by not creating all the
 roots and choosing just one, but this should be a good start.
   1.  Real goal was random vectors over `QQbar`.  A doctest demonstrates
 how control of the integer coefficients can be passed from
 `random_vector()` to the `QQbar.random_element()` to
 `ZZ.random_element()`.

 '''Apply''':
   1. [attachment:trac_11725-random-algebraic-numbers2.patch]

--

Comment:

 Seems mostly fine to me. It would be easy to get bogged down as to what
 the default behaviour of {{{QQbar.random_element()}}} should be, but as
 implemented here this seems a reasonable first step. I did a test and
 found that with default parameters {{{QQbar.random_element()}}} returns
 zero about 15% of the time, nonzero real numbers about 60% of the time,
 and nonzero imaginary numbers about 7% of the time:
 {{{
 sage: L = []
 sage: for j in range(5000):
 ....:     L.append(QQbar.random_element())
 ....:
 sage: RDF(L.count(0))/len(L)
 0.133
 sage: C = [r.imag() == 0 and r != 0 for r in L]
 sage: RDF(C.count(True))/len(C)
 0.6194
 sage: D = [r.real() == 0 and r != 0 for r in L]
 sage: RDF(D.count(True))/len(D)
 0.066
 }}}

 The doctests all work and illustrate the new behaviour well. I fixed a few
 spelling errors, one grammatical error and added extra info in one other
 place:
 {{{
 - ``poly_degree`` - default: 2 - degree of the random
    polynomial over the integers that the algebraic number
    is a root of.
 }}}
 becomes
 {{{
 - ``poly_degree`` - default: 2 - degree of the random
     polynomial over the integers of which the returned
     algebraic number is a root.
 }}}
 And
 {{{
 For example if we do not include zero as a possible
 coefficient, there will never be a zero constant term, and
 thus never a zero root. ::
 }}}
 becomes
 {{{
 For example, current default behaviour of this method
 returns zero about 15% of the time; if we do not include zero as a
 possible coefficient, there will never be a zero constant term, and
 thus never a zero root. ::
 }}}

 I've uploaded the updated patch. These are trivial changes, but I suppose
 this should be re-reviewed before it can be given a positive review.

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