#18935: Finite field linear function to polynomial
-------------------------------------+-------------------------------------
       Reporter:  tgagne             |        Owner:
           Type:  enhancement        |       Status:  needs_work
       Priority:  minor              |    Milestone:  sage-6.10
      Component:  finite rings       |   Resolution:
       Keywords:  finite field,      |    Merged in:
  polynomial                         |    Reviewers:  Vincent Delecroix
        Authors:  Thomas Gagne       |  Work issues:
Report Upstream:  N/A                |       Commit:
         Branch:                     |  1608ecbe6702539fdbcbfef4f6b27dbe39d275dc
  u/tgagne/finite_field_matrix_to_polynomial|     Stopgaps:
   Dependencies:  #18714             |
-------------------------------------+-------------------------------------
Changes (by vdelecroix):

 * status:  needs_review => needs_work
 * reviewer:   => Vincent Delecroix
 * milestone:  sage-6.8 => sage-6.10


Comment:

 Why `base_matrix_to_polynomial` and not simply `matrix_to_polynomial`?

 `poly(el)` is simpler than `poly.subs(x=el)`

 This test is really bad
 {{{
 not all([matrix[i,j] in self.base_ring() for i in range(n) for j in
 range(n)])
 }}}
 You have several better options
 - {{{matrix.base_ring() == self}}}
 - {{{matrix = matrix.change_ring(self)}}} (this might make an unneeded
 copy)

 If `var` is already an element of a polynomial ring then you should not
 recreate another one. In particular, I might want to work over QQ[x,y] and
 obtain a polynomial in the variable x in this specific ring. I would
 simply do
 {{{
 if isinstance(var, str):
     from sage.rings.polynomial.polynomial_ring import polygen
     var = polygen(self)
 }}}

 If the matrix is sparse you are doing a lot of unwanted computations. I
 would actually separate
 {{{
 if matrix.is_sparse():
     entries = matrix.nonzero_positions()
 else:
     entries = ((i,j) for i in range(n) for j in range(n))

 for i,j in entries:
     # do the looping
 }}}
 And add a test with a huge matrix with very few coefficients like
 {{{
 sage: M = matrix(GF(3,4), 1000, sparse=True)
 sage: M[0,3] = 1
 }}}

 The operation `gen**i` is actually very fast. So I would avoid computing
 the list `basis` and replace `basis[i]` with `gen**i`

 You should not compute a list and then make a sum of elements. Do
 everything at once
 {{{
 s = 0
 for i in range(10):
     s += 1
 }}}
 is much better than
 {{{
 l = []
 for i in range(10):
     l.append(i)
 s = sum(l)
 }}}

--
Ticket URL: <http://trac.sagemath.org/ticket/18935#comment:5>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to