On Monday 18 August 2008, Hamish Ivey-Law wrote:
> Hello,
>
> I found a bug that occurs when calling  random_element()  on a
> polynomial or power series ring over a Givaro finite field (the Givaro
> finite fields are used when the field is non-prime and has cardinality
> < 2^16).  The problem is that the polynomial ring assumes that its
> base ring's  random_element()  method takes arguments and it thus
> calls the base ring method like this:  R.random_element(*args,
> **kwds).  But the Givaro FF implementation of  random_element()  only
> takes a 'self' argument, and thus raises a TypeError if  args  is non-
> empty.  For example:
>
> --BEGIN--
> sage: P.<x> = PowerSeriesRing(GF(3^3, 'a'))
> sage: P.random_element(7)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call
> last)
>
> /Users/hlaw/sage/devel/<ipython console> in <module>()
>
> /Users/hlaw/sage/local/lib/python2.5/site-packages/sage/rings/
> power_series_ring.py in random_element(self, prec, bound)
>     544             1/15 + 19/17*t + 10/3*t^2 + 5/2*t^3 + 1/2*t^4 +
> O(t^5)
>     545         """
> --> 546         return self(self.__poly_ring.random_element(prec,
> bound), prec)
>     547
>     548     def __cmp__(self, other):
>
> /Users/hlaw/sage/local/lib/python2.5/site-packages/sage/rings/
> polynomial/polynomial_ring.py in random_element(self, degree, *args,
> **kwds)
>     770         """
>     771         R = self.base_ring()
> --> 772         return self([R.random_element(*args, **kwds) for _ in
> xrange(degree+1)])
>     773
>     774     def _monics_degree( self, of_degree ):
>
> TypeError: random_element() takes no arguments (1 given)
> --END--
>
> In this case, the problem occurs because the
> PowerSeriesRing_generic.random_element()  passes  bound  to
> PolynomialRing_general.random_element()  where it is placed in the
> args  parameter and subsequently given to
> FiniteField_givaro.random_element()  which is not expecting any
> arguments.
>
> I fixed this problem by adding  *args  and  **kwds  parameters to
> FiniteField_givaro.random_element():
>
> diff -r 717c10d9cd4a sage/rings/finite_field_givaro.pyx
> --- a/sage/rings/finite_field_givaro.pyx      Fri Jul 11 11:46:02 2008
> -0700
> +++ b/sage/rings/finite_field_givaro.pyx      Mon Aug 18 16:10:50 2008
> +0200
> @@ -358,7 +358,7 @@ cdef class FiniteField_givaro(FiniteFiel
>          else:
>              return True
>
> -    def random_element(FiniteField_givaro self):
> +    def random_element(FiniteField_givaro self, *args, **kwds):
>          """
>          Return a random element of self.
>
> Depending on your policy for the  random_element()  interface, this
> may or may not be the best way to fix the problem.  The diff above was
> against Sage 3.0.5, though I checked that this issue is still present
> in 3.1.1.
>
> Regards,
> Hamish.

Hi there,

I agree with your fix. However the problem is bigger than what you reported. 
We don't have a unified interface for random_element: Some methods expect 
parameters and some don't:

algebras/quaternion_algebra.py:    def random_element(self):
algebras/quaternion_order.py:    def random_element(self):
coding/linear_code.py:    def random_element(self):
combinat/cartesian_product.py:    def random_element(self):
combinat/choose_nk.py:    def random_element(self):
combinat/multichoose_nk.py:    def random_element(self):
combinat/permutation_nk.py:    def random_element(self):
combinat/permutation.py:    def random_element(self):
combinat/permutation.py:    def random_element(self):
combinat/permutation.py:    def random_element(self):
combinat/permutation.py:    def random_element(self):
combinat/split_nk.py:    def random_element(self):
combinat/subset.py:    def random_element(self):
combinat/subset.py:    def random_element(self):
combinat/tableau.py:    def random_element(self):
matrix/matrix_space.py:    def random_element(self, density=1, *args, **kwds):
modular/dirichlet.py:    def random_element(self):
modules/free_module.py:    def random_element(self, prob=1.0, **kwds):
rings/contfrac.py:    def random_element(self, num_bound=2, den_bound=2):
rings/extended_integer_ring.py:    def random_element(self, x=None, y=None):
rings/integer_mod_ring.py:    def random_element(self, bound=None):
....

So I'd suggest:
 - to open a trac ticket for the particular issue you have (if you don't have 
a Trac account yet, I can do that for you)
 - we open another Trac ticket with the task to 'fix' all the random_element 
methods by adding *args and **kwds.

Thoughts?
Martin

-- 
name: Martin Albrecht
_pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
_www: http://www.informatik.uni-bremen.de/~malb
_jab: [EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to