#7580: bugs in infinite polynomial ring
-----------------------+----------------------------------------------------
   Reporter:  was      |       Owner:  SimonKing
       Type:  defect   |      Status:  new      
   Priority:  major    |   Milestone:  sage-4.3 
  Component:  algebra  |    Keywords:           
Work_issues:           |      Author:           
   Upstream:  N/A      |    Reviewer:           
     Merged:           |  
-----------------------+----------------------------------------------------

Comment(by SimonKing):

 Here is one example why I chose to use regular expressions.

 Often I have to find out what variables (i.e., generator and shift) occur
 in what power in the leading monomial of a polynomial. So:
 {{{
 # Create a polynomial ring
 # (the typical underlying finite polynomial ring of a densely
 #  implemented InfinitePolynomialRing)
 sage: Vars = ['x_'+str(n) for n in range(50)]+['y'+str(n) for n in
 range(50)]
 sage: R = PolynomialRing(QQ,Vars)
 # Create a big random element
 sage: p = R.random_element()
 sage: p *= R.random_element()
 sage: p *= R.random_element()
 sage: p *= R.random_element()
 sage: p *= R.random_element()
 }}}

 The generic approach to get the exponents of the variables in the leading
 monomial is, of course, the method {{{exponents()}}}. We need to associate
 the exponent with the variable, so, let's zip two lists:
 {{{
 sage: zip(Vars,p.lm().exponents()[0])
 [('x_0', 0),
  ('x_1', 2),
  ('x_2', 0),
  ('x_3', 0),
  ('x_4', 0),
  ('x_5', 0),
  ('x_6', 0),
 ...
 }}}
 It is a long list, and we still did not separate the generator name from
 the shift.

 Now, do essentially the same with regular expressions:
 {{{
 sage: import re
 sage: RE = re.compile('([a-zA-Z0-9]+)_([0-9]+)\^?([0-9]*)')
 sage: RE.findall(str(p.lm()))
 [('x', '1', '2'),
  ('x', '13', '2'),
  ('x', '16', ''),
  ('x', '23', ''),
  ('x', '45', '')]
 }}}

 The list is much shorter, and moreover generator names and shifts are
 already told apart. This is actually the typical situation for elements of
 Infinite Polynomial Rings in dense implementation: Only few variables from
 the underlying finite polynomial ring appear in the leading monomial.

 And I guess this is why the regular expression is faster:
 {{{
 sage: timeit('L = RE.findall(str(p.lm()))')
 625 loops, best of 3: 23.8 µs per loop
 sage: timeit('L = zip(Vars,p.lm().exponents()[0])')
 625 loops, best of 3: 40.5 µs per loop
 }}}

 IIRC, in a very early stage of my implementation, I did use
 {{{exponents()}}}. But it soon turned out that it was too slow for Gröbner
 basis computations.

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