Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79071
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <torriem+gmail@torriefamily.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.015 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'broken': 0.04; 'logic': 0.09; 'lost.': 0.09; 'statements': 0.09; 'subject:while': 0.09; '"if"': 0.16; 'assembler': 0.16; 'block.': 0.16; 'clauses': 0.16; 'curious:': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'jumps': 0.16; 'opposite': 0.16; 'statements,': 0.16; 'zero,': 0.16; 'wrote:': 0.18; '(not': 0.18; 'variable': 0.18; 'pieces': 0.19; 'command': 0.22; '>>>': 0.22; 'header:User- Agent:1': 0.23; 'instead.': 0.24; 'lets': 0.24; 'mon,': 0.24; 'looks': 0.24; '(or': 0.24; 'compare': 0.26; 'right.': 0.26; 'second': 0.26; 'asking': 0.27; 'gets': 0.27; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'bigger': 0.30; 'easier': 0.31; 'usually': 0.31; '13,': 0.31; '>>>>': 0.31; 'asks': 0.31; "d'aprano": 0.31; 'equivalent.': 0.31; 'steven': 0.31; 'guess': 0.33; 'monday,': 0.33; 'not.': 0.33; 'test': 0.35; 'but': 0.35; 'combination': 0.36; 'should': 0.36; 'positive': 0.37; 'two': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'middle': 0.60; 'negative': 0.60; 'hope': 0.61; 'entire': 0.61; 'course': 0.61; 'first': 0.61; 'name': 0.63; 'day.': 0.63; 'more': 0.64; 'different': 0.65; 'reverse': 0.68; 'overall': 0.69; '"not': 0.84; '+1100': 0.84; 'x):': 0.84; '(pdt)': 0.91; 'eliminates': 0.91 |
| X-Virus-Scanned | amavisd-new at torriefamily.org |
| Date | Mon, 13 Oct 2014 16:08:36 -0600 |
| From | Michael Torrie <torriem@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: while loop - multiple condition |
| References | <loom.20141012T190458-947@post.gmane.org> <CAPTjJmrPgTdysCnLcbMqYFiGGwg-wV_mjfw16Kt15_zuv_624g@mail.gmail.com> <loom.20141012T191849-946@post.gmane.org> <CAPTjJmouQsm_9ccqdtmJ3kmd4SqmmOqk3OVdS4mngeHaVT2S6w@mail.gmail.com> <loom.20141012T195709-937@post.gmane.org> <mailman.14798.1413137019.18130.python-list@python.org> <878uklcd3r.fsf@elektro.pacujo.net> <mailman.14805.1413146405.18130.python-list@python.org> <543b0706$0$13005$c3e8da3$5496439d@news.astraweb.com> <20141013091248.1ffd94a0@rg.highlandtechnology.com> <ee40ce93-38e0-47ca-b41a-b76c9f84c8c4@googlegroups.com> <20141013094308.7d4ea20c@rg.highlandtechnology.com> <1b9fa5ce-45da-4aa8-a849-394a033e1c9d@googlegroups.com> |
| In-Reply-To | <1b9fa5ce-45da-4aa8-a849-394a033e1c9d@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| 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.14837.1413238130.18130.python-list@python.org> (permalink) |
| Lines | 68 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1413238130 news.xs4all.nl 2907 [2001:888:2000:d::a6]:33054 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:79071 |
Show key headers only | View raw
On 10/13/2014 11:12 AM, Rustom Mody wrote: > On Monday, October 13, 2014 10:13:20 PM UTC+5:30, Rob Gaddi wrote: >> On Mon, 13 Oct 2014 09:26:57 -0700 (PDT) >> Rustom Mody wrote: > >>> On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote: >>>> On Mon, 13 Oct 2014 09:56:02 +1100 >>>> Steven D'Aprano wrote: >>>>> When you have multiple clauses in the condition, it's easier to reason about >>>>> them if you write the clauses as positive statements rather than negative >>>>> statements, that is, "something is true" rather than "something is not >>>>> true", and then use `not` to reverse it if you want to loop *until* the >>>>> overall condition is true. >>>> I was just explaining this concept to a young pup the other day. De >>>> Morgan's lets you say that (not (p and q)) == ((not p) or (not q)), but >>>> the positive logic flavor is substantially less error-prone. People >>>> are fundamentally not as good at thinking about inverted logic. >>> Curious: Which of >>> - (not (p and q)) >>> - ((not p) or (not q)) >>> is more positive (less negative)?? > >> The first is asking you to compare positive conditions (p and q) and >> negate the entire thing (NAND). The second asks you to think about >> the combination of two different "not true" pieces of logic >> (OR of two inverted inputs). The first is pretty straightforward, and >> I usually see people get it right. The second gets screwed up as often >> as not. > >> And of course, any combination of ands and ors should be broken into >> multiple statements with a descriptive variable name in the middle or >> all hope is lost. > > Yeah I guess 2 nots is one more than one! > > However (to my eyes) > while i < N and a[i] != X: > > looks less negative than > > while not (i==N or a[i] == X): > > [Of course i < N is not identical to i != N ] Right it should have been not (i >= N or a[i] == X) to be equivalent. In assembler it's often best to reverse the condition and then use the opposite jump mnemonic. IE, if the test is to see if a number not zero, use the jump if zero command instead. Often it reduces the number of jumps required and eliminates the need to jump over the body of the "if" block. if a != 0 then jump to bigger jump to end bigger: blah blah end: vs if a == 0 then jump to end blah blah end:
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: while loop - multiple condition Chris Angelico <rosuav@gmail.com> - 2014-10-13 05:03 +1100
Re: while loop - multiple condition Marko Rauhamaa <marko@pacujo.net> - 2014-10-12 22:16 +0300
Re: while loop - multiple condition Chris Angelico <rosuav@gmail.com> - 2014-10-13 06:22 +1100
Re: while loop - multiple condition Tim Chase <python.list@tim.thechases.com> - 2014-10-12 15:42 -0500
Re: while loop - multiple condition Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-13 09:56 +1100
Re: while loop - multiple condition Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-13 09:12 -0700
Re: while loop - multiple condition Rustom Mody <rustompmody@gmail.com> - 2014-10-13 09:26 -0700
Re: while loop - multiple condition Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-10-13 09:43 -0700
Re: while loop - multiple condition Rustom Mody <rustompmody@gmail.com> - 2014-10-13 10:12 -0700
Re: while loop - multiple condition Michael Torrie <torriem@gmail.com> - 2014-10-13 16:08 -0600
Re: while loop - multiple condition wxjmfauth@gmail.com - 2014-10-13 23:34 -0700
Re: while loop - multiple condition giacomo boffi <pecore@pascolo.net> - 2014-10-15 01:04 +0200
Re: while loop - multiple condition Chris Angelico <rosuav@gmail.com> - 2014-10-15 10:16 +1100
csiph-web