220 11603 <8c420393-c2ac-45a1-8b3b-4b0029894bc0@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Proposal. Generators of numeric sequences: the
 steps class template
Date: Sat, 28 Jun 2014 13:06:28 -0700 (PDT)
Lines: 157
Approved: news@gmane.org
Message-ID: <8c420393-c2ac-45a1-8b3b-4b0029894bc0@isocpp.org>
References: <8aec4acb-2eea-4288-b215-81e828cd0b42@isocpp.org>
 <lon1rr$nrk$1@ger.gmane.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_1353_24319980.1403985989215"
X-Trace: ger.gmane.org 1403985998 25552 80.91.229.3 (28 Jun 2014 20:06:38 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 28 Jun 2014 20:06:38 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDC55PNFRYGRBRWAXSOQKGQEIHANWLI@isocpp.org Sat Jun 28 22:06:33 2014
Return-path: <std-proposals+bncBDC55PNFRYGRBRWAXSOQKGQEIHANWLI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f200.google.com ([209.85.214.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDC55PNFRYGRBRWAXSOQKGQEIHANWLI@isocpp.org>)
	id 1X0ytL-0000fV-Lh
	for gclcip-std-proposals@m.gmane.org; Sat, 28 Jun 2014 22:06:31 +0200
Original-Received: by mail-ob0-f200.google.com with SMTP id wm4sf38496706obc.7
        for <gclcip-std-proposals@m.gmane.org>; Sat, 28 Jun 2014 13:06:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=QsX2BEx5JhRLZiSkxHouhfPz32NPHB2GRA25WKsMrbU=;
        b=EEASuEUT876FDynlEy8wOxXNV+XCe99tXisOCNxKBVoUgCsh0mARH5TitXxBnpksED
         zZIFLjqWAI4dKVfTFEHdBBoWeZdFeHYLOUip72PJ4/DxzrRAj69uClFUiw4L0Z0qcKYc
         bYYFqCydRRGchW8IM/XwOP6R4wpdoDW9Mm+7NrwhiCQ1hD1ZkMup4FTHJ7L50iHaC3kl
         YnPj/GA/NYTN/rcK6TsOBMU1ynspek9h9ZCBEO91cSJtTKPnuHzBwj1xC8vUxLzHGhR8
         gnmpLAHhodzEEC2VQmoL8ZRU97srPT6zdr8zVpKrDSQgg8RFGhBhiHA5VMEA3ZnMs70t
         aPsQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=QsX2BEx5JhRLZiSkxHouhfPz32NPHB2GRA25WKsMrbU=;
        b=HDtYIriOZJkqoqm44Vi9VYaI5bHNI1HeU0OJjKktkqASAjDhgJisgflM2cVkLjIrS/
         EVyiJj5c6Yx3jCaN+pJsHpPz9fgSikWFAQYlZgrSkNC45lYOxM5Zy+sXt5D14iQ9yKNs
         7n1phezWxnLXv1PFo8gKPHlWkCVQwcz3CWfwBX95eD1ATXyrIper9asbh2q7Z+/fX5l1
         k+O82+gyvGDiRFPbf27PMhPH0hWsx5C18MXogwrup0MLTSE5sBLFye0/rv6I8g1QjZX2
         apbAhhpxi2K1c9qS/vPWhxaBPdUESo7n1VwtYmkHryQW0yi4hFQHxV23m+VGn/YMjqWR
         mB7g==
X-Gm-Message-State: ALoCoQksS0mEEHBgy4a83BvWpDcMvebwkRklooAu3k3rMy+7af50ETAOzigci8pwkkade8b5ZOs2
X-Received: by 10.182.209.37 with SMTP id mj5mr17391598obc.7.1403985990733;
        Sat, 28 Jun 2014 13:06:30 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.50.80 with SMTP id r74ls980822qga.71.gmail; Sat, 28 Jun
 2014 13:06:30 -0700 (PDT)
X-Received: by 10.140.94.38 with SMTP id f35mr678qge.9.1403985990034;
        Sat, 28 Jun 2014 13:06:30 -0700 (PDT)
In-Reply-To: <lon1rr$nrk$1@ger.gmane.org>
X-Original-Sender: mikhailsemenov1957@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:11603
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11603>

------=_Part_1353_24319980.1403985989215
Content-Type: text/plain; charset=UTF-8

Jim. I was thinking about something like that:
make_table(a,b,N, upper_bound_included)
make_table(f,a,b,N, upper_bound_included)
I probably should add them to the proposal.

On Saturday, June 28, 2014 8:15:13 PM UTC+1, Jim Porter wrote:

> On 6/28/2014 10:50 AM, Mikhail Semenov wrote: 
> > https://dl.dropboxusercontent.com/u/35715999/steps_template.htm 
>
> In this, you describe ways to use std::steps with floating point values, 
> which requires some special handling to stop the iteration if you're 
> within epsilon of the endpoint. However, for the floating point case, 
> I'd really recommend using something more like NumPy's linspace, which 
> takes, a start, a stop, and a *number of samples*. 
>
> Supposing we had a function like template <typename T> std::linspace(T 
> start, T stop, size_t num, include_endpoint = true) and a corresponding 
> std::make_linspace, this is how you could write your integrate function: 
>
>    double integrate( 
>      std::function<double(double)> f, double a, double b, int N 
>    ) { 
>      double h = (b - a) / N; 
>      double h2 = h * 0.5; 
>      double sum = 0.0; 
>
>      for(auto x : std::make_linspace(a + h2, b - h2, N)) { 
>        sum += f(x); 
>      } 
>
>      return sum * h; 
>    } 
>
> This allows you to avoid worrying about how to define epsilon so that 
> you're guaranteed to get the number of steps you expect. The extra 
> complexity for the user is minimal, and makes it clearer that you expect 
> N steps. If you cared less about efficiency, you could make the loop 
> look even simpler: 
>
>      for(auto x : std::make_linspace(a, b, N, false)) { 
>        sum += f(x + h2); 
>      } 
>
> Even with the epsilon calculation for std::steps, I'd still be worried 
> about using it if I expected a particular number of iteration steps, and 
> if that number were quite large. std::linspace would have no such trouble. 
>
> - Jim 
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_1353_24319980.1403985989215
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Jim. I was thinking about something like that:</div><=
div>make_table(a,b,N, upper_bound_included)</div><div>make_table(f,a,b,N, u=
pper_bound_included)</div><div>I probably should add them to the proposal.<=
br><br>On Saturday, June 28, 2014 8:15:13 PM UTC+1, Jim Porter wrote:</div>=
<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; paddi=
ng-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px=
; border-left-style: solid;">On 6/28/2014 10:50 AM, Mikhail Semenov wrote:
<br>&gt; <a onmousedown=3D"this.href=3D'https://www.google.com/url?q\75http=
s%3A%2F%2Fdl.dropboxusercontent.com%2Fu%2F35715999%2Fsteps_template.htm\46s=
a\75D\46sntz\0751\46usg\75AFQjCNEHsERzK0q4Gj_XECN3wdBJ4bEutA';return true;"=
 onclick=3D"this.href=3D'https://www.google.com/url?q\75https%3A%2F%2Fdl.dr=
opboxusercontent.com%2Fu%2F35715999%2Fsteps_template.htm\46sa\75D\46sntz\07=
51\46usg\75AFQjCNEHsERzK0q4Gj_XECN3wdBJ4bEutA';return true;" href=3D"https:=
//dl.dropboxusercontent.com/u/35715999/steps_template.htm" target=3D"_blank=
">https://dl.dropboxusercontent.<wbr>com/u/35715999/steps_template.<wbr>htm=
</a>
<br>
<br>In this, you describe ways to use std::steps with floating point values=
,=20
<br>which requires some special handling to stop the iteration if you're=20
<br>within epsilon of the endpoint. However, for the floating point case,=
=20
<br>I'd really recommend using something more like NumPy's linspace, which=
=20
<br>takes, a start, a stop, and a *number of samples*.
<br>
<br>Supposing we had a function like template &lt;typename T&gt; std::linsp=
ace(T=20
<br>start, T stop, size_t num, include_endpoint =3D true) and a correspondi=
ng=20
<br>std::make_linspace, this is how you could write your integrate function=
:
<br>
<br>&nbsp; &nbsp;double integrate(
<br>&nbsp; &nbsp; &nbsp;std::function&lt;double(double)&gt; f, double a, do=
uble b, int N
<br>&nbsp; &nbsp;) {
<br>&nbsp; &nbsp; &nbsp;double h =3D (b - a) / N;
<br>&nbsp; &nbsp; &nbsp;double h2 =3D h * 0.5;
<br>&nbsp; &nbsp; &nbsp;double sum =3D 0.0;
<br>
<br>&nbsp; &nbsp; &nbsp;for(auto x : std::make_linspace(a + h2, b - h2, N))=
 {
<br>&nbsp; &nbsp; &nbsp; &nbsp;sum +=3D f(x);
<br>&nbsp; &nbsp; &nbsp;}
<br>
<br>&nbsp; &nbsp; &nbsp;return sum * h;
<br>&nbsp; &nbsp;}
<br>
<br>This allows you to avoid worrying about how to define epsilon so that=
=20
<br>you're guaranteed to get the number of steps you expect. The extra=20
<br>complexity for the user is minimal, and makes it clearer that you expec=
t=20
<br>N steps. If you cared less about efficiency, you could make the loop=20
<br>look even simpler:
<br>
<br>&nbsp; &nbsp; &nbsp;for(auto x : std::make_linspace(a, b, N, false)) {
<br>&nbsp; &nbsp; &nbsp; &nbsp;sum +=3D f(x + h2);
<br>&nbsp; &nbsp; &nbsp;}
<br>
<br>Even with the epsilon calculation for std::steps, I'd still be worried=
=20
<br>about using it if I expected a particular number of iteration steps, an=
d=20
<br>if that number were quite large. std::linspace would have no such troub=
le.
<br>
<br>- Jim
<br>
<br></blockquote></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1353_24319980.1403985989215--

.
