[SciPy-Dev] Code review for trapz update

fizyxnrd fizyxnrd at gmail.com
Tue Mar 10 19:23:55 EDT 2015


Nathaniel Smith <njs <at> pobox.com> writes:

> 
> 
> On Mar 10, 2015 1:22 PM, "fizyxnrd" <fizyxnrd <at> gmail.com> wrote:
> >
> > Eric Moore <ewm <at> redtetrahedron.org> writes:
> > > This equivalence is false.  For instance both of these results are
> > correct.  Would they still be with your changes?
> > > In [46]: x = np.exp(1j*np.pi*np.linspace(0,1,100))
> > >
> > > In [47]: z = 1/x
> > >
> > > In [48]: np.trapz(z, x)
> > > Out[48]: (1.3244509217643717e-18+3.1410654163086975j)
> > >
> > > In [49]: np.trapz(z[::-1], x[::-1])
> > > Out[49]: (-1.3244509217643594e-18-3.1410654163086971j)
> >
> > These results would still be correct.  In the first case, the user
> > simply specifies that they wish to know $Z(x) - Z(0) = \int_0^x 
z(x')
> > dx'$, while in the second case, they specify that they are looking 
for
> > Z(0) - Z(x) = \int_x^0 z(x') dx' = -\int_0^x z(x') dx'$.
> > I'm asserting that the two should be completely equivalent, and that 
the
> > user recognize that the endpoints in the first instance are 1 and -1
> > ($\theta \elem [0, \pi]$), while in the latter case the endpoints 
are -1
> > and 1 ($\theta \elem [\pi, 0]$).  Thus $\int_0^x z(x)$ is given by
> > np.trapz(z, x) and $\int_x^0 z(x)$ is given by -np.trapz(z, x).
> >
> > This modification treats the area under the curve as independent of
> > path, and asks the user to use path endpoints to determine what 
should
> > be done with that quantity.
> Look again at the example: here the path is a two-dimensional arc in 
the complex plane. Ian Henricksen's message gives an even more refined 
version of the same example, where the arc is a circle with the same 
start and end points. Nonetheless, it matters whether you traverse the 
circle clockwise or anti-clockwise.
> These are real cases where your proposed change just cannot be 
applied, because the integral really does depend on all the points in 
the path, not just the start and end. I understand where you're coming 
from, but, well, mathematics has spoken .
> -n
> 
> 
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev <at> scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
> 

It appears that there is more use for the current form than I have come 
across with my adventures in positive-definite quantities.  Is there 
room for a keyword e.g., unsorted ( so that the call is trapz(y, x=None, 
dx = 1.0, axis=-1, unsorted=False) where if unsorted is set to True, the 
data is automatically sorted before integration?


More information about the SciPy-Dev mailing list