Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69495

Re: Code style query: multiple assignments in if/elif tree

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.034
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'forgive': 0.05; 'say,': 0.05; 'great.': 0.07; 'subject:query': 0.07; 'assuming': 0.09; 'correct,': 0.09; 'curve': 0.09; 'integral': 0.09; 'mixed': 0.09; '(just': 0.16; '0.2': 0.16; 'calculus,': 0.16; 'curve.': 0.16; 'incorrect': 0.16; 'jumped': 0.16; 'losing': 0.16; 'segment': 0.16; 'those,': 0.16; 'triangle': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'version.': 0.19; 'error': 0.23; 'stopping': 0.24; 'subject:Code': 0.24; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'points': 0.29; 'reaches': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'constant': 0.31; 'guess': 0.33; 'actual': 0.34; 'beyond': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'error.': 0.37; 'so,': 0.37; 'two': 0.37; 'area': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'easy': 0.60; 'ian': 0.60; "you'll": 0.62; 'myself': 0.63; 'connecting': 0.64; 'more': 0.64; 'distance': 0.65; 'modeling': 0.65; 'within': 0.65; 'between': 0.67; 'stated': 0.69; 'safe': 0.72; 'upper': 0.74; 'bounding': 0.84; 'maths': 0.84; 'one).': 0.84; 'points,': 0.84; 'traveled': 0.84; 'distance.': 0.91; 'increases': 0.91; 'average': 0.93; 'picture': 0.97
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=9J6imTW2GmDtMYZ0Qeoew7cf3yHq6OwLm+vk5L7QNug=; b=H1AEAPTSidiv4egSx/dr48u9ggp3sKMuyCp/hG9MGwjkJU4ZBtkmsJD6AApcTIGvh2 jaOPW31TBCAQEgFwzu89oPCVLqqf+HkdGR4lCy5SuMJLQd8EZzCpj59hlp7qp47h15iq nFn4gYYcnmEp0RowO9zMQvlFqia53Qw6H/SS8Ev1lCyZ4AU007+hs7qGIo3K9T3kZ2Kg ZEliLHPhp/vHB7xh/mctxWqGxcso+tfW4aJ40KiUZSEafOn6IZ0RdbbSCQMF8XocQs0F E9K3KylZ3CQClgrQ0uXUBaKyabM64H7eqJeq4CRL5fuoRlqmv9X44HkGO0amZJ1DiY8U rWjA==
X-Received by 10.68.134.198 with SMTP id pm6mr26186745pbb.9.1396342563990; Tue, 01 Apr 2014 01:56:03 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <CAPTjJmrX3gSb_EXZJVOFuUzUK61pP+7t7vNxPpdoYroG+fFqHA@mail.gmail.com>
References <mailman.8744.1396276875.18130.python-list@python.org> <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <CAPTjJmoqdHtbyTKLf0b6c5Xy8Wx_NQVvFenB-S0hE3dHO15uzA@mail.gmail.com> <CALwzidmEqc45K49c3agMzRzpAtEqejGF2svpPOZXg5X6dbBnGw@mail.gmail.com> <CAPTjJmrX3gSb_EXZJVOFuUzUK61pP+7t7vNxPpdoYroG+fFqHA@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 1 Apr 2014 02:55:23 -0600
Subject Re: Code style query: multiple assignments in if/elif tree
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.8788.1396342572.18130.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1396342572 news.xs4all.nl 2969 [2001:888:2000:d::a6]:49723
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:69495

Show key headers only | View raw


On Tue, Apr 1, 2014 at 12:55 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Tue, Apr 1, 2014 at 5:13 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>> Then your computation is incorrect and will systematically
>> underestimate the stopping distance.  Assuming for simplicity that the
>> acceleration actually increases linearly until it reaches maximum,
>> picture the velocity graph between, say, t=0 and t=1s.  You are
>> modeling it as a straight line segment.  However, it would actually be
>> part of a quadratic curve connecting the same points, convex upwards.
>> The line segment is short-cutting the curve between the two points.
>> The distance traveled is the integral of the curve, and it is easy to
>> see that the integral of the line segment is less than the integral of
>> the actual curve.
>
> .... great.
>
> Okay. I never studied calculus, so this is beyond my expertise. Is
> this going to make a majorly significant difference to the end result?
> If so, I guess the code's going to have to be a whole lot more
> sophisticated, which means I need to learn a whole lot more maths in
> order to write it. And I'm still trying to find time to get familiar
> with systemd (having jumped on the Upstart bandwagon and now find
> myself backing a losing horse, if you'll forgive a mixed metaphor) and
> Cython (just need an excuse for that one).

Assuming the stated acceleration averages are correct, we can put an
upper bound on the error.  Draw a rectangle bounding the two
consecutive points on the velocity graph.  Given that the actual
velocity decreases monotonically (which should be a safe assumption),
that curve must be contained within this rectangle.  Given that the
deceleration also increases monotonically, we can also say that the
curve must be contained within the upper triangle of that rectangle,
as bisected by the straight line segment of the constant average
acceleration version.  The area of this triangle is 1s * 0.2 m/s / 2 =
0.1m.  The area of the same triangle between t=1s and t=2s is 1s *
0.425 m/s / 2= 0.2125 m.  Summing those, the upper bound for the error
is only 0.3125 m.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 01:33 +1100
  Re: Code style query: multiple assignments in if/elif tree Marko Rauhamaa <marko@pacujo.net> - 2014-03-31 18:40 +0300
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 03:03 +1100
      Re: Code style query: multiple assignments in if/elif tree Rustom Mody <rustompmody@gmail.com> - 2014-03-31 09:20 -0700
        Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 03:29 +1100
          Re: Code style query: multiple assignments in if/elif tree "Rhodri James" <rhodri@wildebst.org.uk> - 2014-03-31 21:31 +0100
    Re: Code style query: multiple assignments in if/elif tree Ned Batchelder <ned@nedbatchelder.com> - 2014-03-31 17:42 -0400
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 09:50 +1100
    Re: Code style query: multiple assignments in if/elif tree Ben Finney <ben+python@benfinney.id.au> - 2014-04-01 09:57 +1100
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 10:12 +1100
      Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-01 00:57 +0000
    Re: Code style query: multiple assignments in if/elif tree Ethan Furman <ethan@stoneleaf.us> - 2014-03-31 17:30 -0700
  Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 04:26 +0000
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 16:01 +1100
      Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 07:20 +0000
        Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:35 +1100
          Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 08:07 +0000
            Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 19:12 +1100
        Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:18 -0600
        Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:24 -0600
    Re: Code style query: multiple assignments in if/elif tree Rustom Mody <rustompmody@gmail.com> - 2014-03-31 22:45 -0700
      Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 02:05 -0400
      Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:28 -0600
    Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:13 -0600
    Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 02:24 -0400
    Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:39 -0600
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 17:55 +1100
      Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 07:29 +0000
        Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:49 +1100
        Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:29 -0600
        Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 19:56 +1100
    Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:21 -0400
    Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:26 +1100
    Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:34 -0400
    Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:39 -0400
    Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:46 -0400
    Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:55 -0600

csiph-web