#13836: Fix variable dependence in PiecewisePolynomial
----------------------------------------------+-----------------------------
       Reporter:  christiankuper              |         Owner:  burcin       
           Type:  defect                      |        Status:  needs_review 
       Priority:  major                       |     Milestone:  sage-5.9     
      Component:  symbolics                   |    Resolution:               
       Keywords:  Piecewise, critical_points  |   Work issues:               
Report Upstream:  N/A                         |     Reviewers:  Burcin Erocal
        Authors:  Andrew Fleckenstein         |     Merged in:               
   Dependencies:                              |      Stopgaps:               
----------------------------------------------+-----------------------------
Changes (by afleckenstein):

  * status:  needs_work => needs_review


Old description:

> When using the example in the documentation of the function the following
> results are displayed for critical points:
>
> {{{
> sage: R.<x> = QQ[]
> sage: f1 = x^0
> sage: f2 = 10*x - x^2
> sage: f3 = 3*x^4 - 156*x^3 + 3036*x^2 - 26208*x
> sage: f = Piecewise([[(0,3),f1],[(3,10),f2],[(10,20),f3]])
> sage: f.critical_points()
> [5.0, 12.000000000000124, 12.999999999999725, 14.000000000000151]
> }}}
>
> When doing the same with y instead of x as a variable an empty list is
> returned as a result:
>
> {{{
> sage: R.<y> = QQ[]
> sage: f1 = y^0
> sage: f2 = 10*y - y^2
> sage: f3 = 3*y^4 - 156*y^3 + 3036*y^2 - 26208*y
> sage: f = Piecewise([[(0,3),f1],[(3,10),f2],[(10,20),f3]])
> sage: f.critical_points()
> []
> }}}
>
> This behavior does not change even if y is explicitly defined as the
> variable:
>
> {{{
> sage: f = Piecewise([[(0,3),f1],[(3,10),f2],[(10,20),f3]],y)
> sage: f.critical_points()
> []
> }}}
>
> A variable besides default_variable() is also used (to varying effects)
> in the functions trapezoid(), derivative(), tangent_line() and
> convolution(). The fourier series functions that find coefficients use a
> variable other than default_variable() in the code, but it doesn't affect
> output, and probably doesn't need to be changed. However, the
> _fourier_series_helper() function probably should be changed.
> {{{
> sage: y = var('y')
> sage: f(y) = y^2
> sage: f = Piecewise([[(-1, 1),f]])
> sage: f._fourier_series_helper(3, 1, lambda n: 1)
> -4*cos(pi*x)/pi^2 + cos(2*pi*x)/pi^2 + 1/3
> }}}
>
> It should be possible to obtain consistent results no matter what the
> name of the variable is.
>
> Reviewers: The final patch is trac_13836_piecewise_var_fix.patch. This is
> the only patch that needs to be reviewed, all other patches were works in
> progress.
>
> Apply :
>     * [attachment:trac_13836_piecewise_var_fix.patch]
>     * [attachment:trac_13836-rev.patch]

New description:

 When using the example in the documentation of the function the following
 results are displayed for critical points:

 {{{
 sage: R.<x> = QQ[]
 sage: f1 = x^0
 sage: f2 = 10*x - x^2
 sage: f3 = 3*x^4 - 156*x^3 + 3036*x^2 - 26208*x
 sage: f = Piecewise([[(0,3),f1],[(3,10),f2],[(10,20),f3]])
 sage: f.critical_points()
 [5.0, 12.000000000000124, 12.999999999999725, 14.000000000000151]
 }}}

 When doing the same with y instead of x as a variable an empty list is
 returned as a result:

 {{{
 sage: R.<y> = QQ[]
 sage: f1 = y^0
 sage: f2 = 10*y - y^2
 sage: f3 = 3*y^4 - 156*y^3 + 3036*y^2 - 26208*y
 sage: f = Piecewise([[(0,3),f1],[(3,10),f2],[(10,20),f3]])
 sage: f.critical_points()
 []
 }}}

 This behavior does not change even if y is explicitly defined as the
 variable:

 {{{
 sage: f = Piecewise([[(0,3),f1],[(3,10),f2],[(10,20),f3]],y)
 sage: f.critical_points()
 []
 }}}

 A variable besides default_variable() is also used (to varying effects) in
 the functions trapezoid(), derivative(), tangent_line() and convolution().
 The fourier series functions that find coefficients use a variable other
 than default_variable() in the code, but it doesn't affect output, and
 probably doesn't need to be changed. However, the _fourier_series_helper()
 function probably should be changed.
 {{{
 sage: y = var('y')
 sage: f(y) = y^2
 sage: f = Piecewise([[(-1, 1),f]])
 sage: f._fourier_series_helper(3, 1, lambda n: 1)
 -4*cos(pi*x)/pi^2 + cos(2*pi*x)/pi^2 + 1/3
 }}}

 It should be possible to obtain consistent results no matter what the name
 of the variable is.

 Reviewers: The final patch is trac_13836_piecewise_var_fix.patch. This is
 the only patch that needs to be reviewed, all other patches were works in
 progress.

 Apply :
     * [attachment:trac_13836_piecewise_var_fix.patch]
     * [attachment:trac_13836-rev-commit.patch]

--

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