X-Received: by 10.183.11.76 with SMTP id eg12mr2400108obd.47.1413268495848; Mon, 13 Oct 2014 23:34:55 -0700 (PDT) X-Received: by 10.140.20.108 with SMTP id 99mr6510qgi.15.1413268494741; Mon, 13 Oct 2014 23:34:54 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!uq10no10318527igb.0!news-out.google.com!i10ni86qaf.0!nntp.google.com!s7no2586309qap.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Mon, 13 Oct 2014 23:34:54 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2a02:120b:c3cc:5710:3501:744c:f571:1bcf; posting-account=ung4FAoAAAC46zhHJ0Nsnuox7M5gDvs_ NNTP-Posting-Host: 2a02:120b:c3cc:5710:3501:744c:f571:1bcf References: <878uklcd3r.fsf@elektro.pacujo.net> <543b0706$0$13005$c3e8da3$5496439d@news.astraweb.com> <20141013091248.1ffd94a0@rg.highlandtechnology.com> <20141013094308.7d4ea20c@rg.highlandtechnology.com> <1b9fa5ce-45da-4aa8-a849-394a033e1c9d@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4359ed6d-b92f-4dde-8564-0742898b70a8@googlegroups.com> Subject: Re: while loop - multiple condition From: wxjmfauth@gmail.com Injection-Date: Tue, 14 Oct 2014 06:34:55 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 5106 X-Received-Body-CRC: 1229433621 Xref: csiph.com comp.lang.python:79079 Le mardi 14 octobre 2014 00:09:08 UTC+2, Michael Torrie a =E9crit=A0: > On 10/13/2014 11:12 AM, Rustom Mody wrote: >=20 > > On Monday, October 13, 2014 10:13:20 PM UTC+5:30, Rob Gaddi wrote: >=20 > >> On Mon, 13 Oct 2014 09:26:57 -0700 (PDT) >=20 > >> Rustom Mody wrote: >=20 > >=20 >=20 > >>> On Monday, October 13, 2014 9:43:03 PM UTC+5:30, Rob Gaddi wrote: >=20 > >>>> On Mon, 13 Oct 2014 09:56:02 +1100 >=20 > >>>> Steven D'Aprano wrote: >=20 > >>>>> When you have multiple clauses in the condition, it's easier to rea= son about >=20 > >>>>> them if you write the clauses as positive statements rather than ne= gative >=20 > >>>>> statements, that is, "something is true" rather than "something is = not >=20 > >>>>> true", and then use `not` to reverse it if you want to loop *until*= the >=20 > >>>>> overall condition is true. >=20 > >>>> I was just explaining this concept to a young pup the other day. De >=20 > >>>> Morgan's lets you say that (not (p and q)) =3D=3D ((not p) or (not q= )), but >=20 > >>>> the positive logic flavor is substantially less error-prone. People >=20 > >>>> are fundamentally not as good at thinking about inverted logic. >=20 > >>> Curious: Which of >=20 > >>> - (not (p and q)) >=20 > >>> - ((not p) or (not q)) >=20 > >>> is more positive (less negative)?? >=20 > >=20 >=20 > >> The first is asking you to compare positive conditions (p and q) and >=20 > >> negate the entire thing (NAND). The second asks you to think about >=20 > >> the combination of two different "not true" pieces of logic >=20 > >> (OR of two inverted inputs). The first is pretty straightforward, and >=20 > >> I usually see people get it right. The second gets screwed up as ofte= n >=20 > >> as not. >=20 > >=20 >=20 > >> And of course, any combination of ands and ors should be broken into >=20 > >> multiple statements with a descriptive variable name in the middle or >=20 > >> all hope is lost. >=20 > >=20 >=20 > > Yeah I guess 2 nots is one more than one! >=20 > >=20 >=20 > > However (to my eyes) >=20 > > while i < N and a[i] !=3D X: >=20 > >=20 >=20 > > looks less negative than >=20 > >=20 >=20 > > while not (i=3D=3DN or a[i] =3D=3D X): >=20 > >=20 >=20 > > [Of course i < N is not identical to i !=3D N ] >=20 >=20 >=20 > Right it should have been not (i >=3D N or a[i] =3D=3D X) to be equivalen= t. >=20 >=20 >=20 > In assembler it's often best to reverse the condition and then use the >=20 > opposite jump mnemonic. IE, if the test is to see if a number not zero, >=20 > use the jump if zero command instead. Often it reduces the number of >=20 > jumps required and eliminates the need to jump over the body of the "if" >=20 > block. >=20 >=20 >=20 > if a !=3D 0 then jump to bigger >=20 > jump to end >=20 > bigger: >=20 > blah >=20 > blah >=20 > end: >=20 >=20 >=20 > vs >=20 >=20 >=20 > if a =3D=3D 0 then jump to end >=20 > blah >=20 > blah >=20 > end: On the side of logic. Nothing can beat this mathematical absurdity (in the logical sense of the term) called Flexible String Representation. Simply unbelievable. jmf