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.

--
Hamish Ivey-Law
PhD student,
Institut de Mathématiques de Luminy, Université de la Méditerranée,
and
School of Mathematics and Statistics, University of Sydney.
--~--~---------~--~----~------------~-------~--~----~
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