#14685: error in the computing of the approximate order in LazyPowerSeries
------------------------------------------------------------+---------------
       Reporter:  MatthieuDien                              |         Owner:  
sage-combinat
           Type:  defect                                    |        Status:  
new          
       Priority:  major                                     |     Milestone:  
sage-5.10    
      Component:  combinatorics                             |    Resolution:    
           
       Keywords:  LazyPowerSeries aorder approximate order  |   Work issues:    
           
Report Upstream:  N/A                                       |     Reviewers:    
           
        Authors:                                            |     Merged in:    
           
   Dependencies:                                            |      Stopgaps:    
           
------------------------------------------------------------+---------------
Description changed by MatthieuDien:

Old description:

> Hi,
>
> I found a bug in the LazyPowerSeries class of package combinat.
> There is mistake in the computing of the approximate order of a serie.
> A demonstration of the bug :
> {{{
> sage: R = LazyPowerSeriesRing(QQ)
> sage: B = R([0,0,0,1,0])
> sage: B.aorder
> 0
> sage: B.coefficients(10)
> [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
> sage: B.aorder
> 1
> }}}
>
> Here, a patch :
> {{{
> diff --git a/sage/combinat/species/series.py
> b/sage/combinat/species/series.py
> --- a/sage/combinat/species/series.py
> +++ b/sage/combinat/species/series.py
> @@ -631,6 +631,7 @@
>                          self.aorder += 1
>                          ao += 1
>                      else:
> +                        self.order = ao
>                          break
>
>              #Try to recognize the zero series
> @@ -643,8 +644,17 @@
>                      self.order  = inf
>                      return
>
> -            if ao < n:
> -                self.order = ao
> +            if self.order == unk:
> +                while ao < n:
> +                    if self._stream[ao] == 0:
> +                        self.aorder += 1
> +                        ao += 1
> +                    else:
> +                        self.order = ao
> +                        break
> +
> +            # if ao < n:
> +            #     self.order = ao
>

>          if hasattr(self, '_reference') and self._reference is not None:
> }}}
>
> I commited it with the number 18037 on the mercurial server
>
> It's my first patch, sorry if i did a mistake.

New description:

 Hi,

 I found a bug in the LazyPowerSeries class of package combinat.
 There is mistake in the computing of the approximate order of a serie.
 A demonstration of the bug :
 {{{
 sage: R = LazyPowerSeriesRing(QQ)
 sage: B = R([0,0,0,1,0])
 sage: B.aorder
 0
 sage: B.coefficients(10)
 [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
 sage: B.aorder
 1
 }}}
 The good result should be 3 and not 1 (the order of the series B = x^3 is
 3 not 1 )

 Here, a patch which fix that:
 {{{
 --- series_old.py       2013-06-08 13:48:40.490566975 +0200
 +++ series.py   2013-06-08 14:00:41.903399503 +0200
 @@ -624,17 +624,17 @@
              c = self._stream
              n = c.number_computed()

 +            while ao < n:
 +                if self._stream[ao] == 0:
 +                    self.aorder += 1
 +                    ao += 1
 +                else:
 +                    self.order = ao
 +                    break

 -            if ao == 0 and n > 0:
 -                while ao < n:
 -                    if self._stream[ao] == 0:
 -                        self.aorder += 1
 -                        ao += 1
 -                    else:
 -                        break

              #Try to recognize the zero series
 -            if ao == n:
 +            if ao == n and n > 0:
                  #For non-constant series, we cannot do anything
                  if not c.is_constant():
                      return
 @@ -642,11 +642,7 @@
                      self.aorder = inf
                      self.order  = inf
                      return
 -
 -            if ao < n:
 -                self.order = ao
 -
 -
 +
          if hasattr(self, '_reference') and self._reference is not None:
              self._reference._copy(self)
 }}}
 The bug is that the aorder is computed one time and never updated. This is
 because the order was assigned the first time then the condition
 self.order != unk becomes false and the update never comes.

 After the patch, we obtain :
 {{{
 sage: R = LazyPowerSeriesRing(QQ)
 sage: B = R([0,0,0,1,0])
 sage: B.aorder
 0
 sage: B.coefficients(10)
 [0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
 sage: B.aorder
 3
 }}}

 What we expected.


 PS : Thanks you for the commment, I tried to answer.

--

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14685#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 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to