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


Groups > comp.lang.python > #46650

RE: Short-circuit Logic

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!npeer03.iad.highwinds-media.com!feed-me.highwinds-media.com!cyclone03.ams2.highwinds-media.com!news.highwinds-media.com!voer-me.highwinds-media.com!eweka.nl!lightspeed.eweka.nl!194.109.133.83.MISMATCH!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <carlosnepomuceno@outlook.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.045
X-Spam-Evidence '*H*': 0.91; '*S*': 0.00; 'operator': 0.03; 'subsequent': 0.05; '(especially': 0.07; 'creator': 0.09; 'here?': 0.09; 'logic': 0.09; 'measure': 0.09; 'neighborhood': 0.09; '\xe2\x80\x94': 0.09; 'question.': 0.14; "wouldn't": 0.14; '[1].': 0.16; 'carpenter': 0.16; 'comparison"': 0.16; 'comparison.': 0.16; 'considers': 0.16; 'length.': 0.16; 'lengths': 0.16; 'next.': 0.16; 'numbers).': 0.16; 'reminded': 0.16; 'sharp': 0.16; 'skipping': 0.16; 'index': 0.16; 'wrote:': 0.18; 'pieces': 0.19; '>>>': 0.22; 'programming': 0.22; '+0000': 0.22; 'to:name:python- list@python.org': 0.22; '31,': 0.24; 'received:65.55.116': 0.24; 'paul': 0.24; 'looks': 0.24; 'compare': 0.26; 'second': 0.26; 'pass': 0.26; 'least': 0.26; 'defined': 0.27; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'skip:- 40': 0.29; 'chris': 0.29; '[1]': 0.29; 'generally': 0.29; 'points': 0.29; '[2]': 0.30; 'absolute': 0.30; 'relative': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'asked': 0.31; 'membership': 0.31; 'went': 0.31; 'comparison': 0.31; 'consequence': 0.31; 'context,': 0.31; "d'aprano": 0.31; 'equality': 0.31; 'exceptions': 0.31; 'extensively': 0.31; 'piece': 0.31; 'steven': 0.31; 'languages': 0.32; "we're": 0.32; 'says': 0.33; 'url:python': 0.33; 'beginning': 0.33; 'fri,': 0.33; 'date:': 0.34; 'knows': 0.35; 'case,': 0.35; 'equal': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'representing': 0.36; 'url:listinfo': 0.36; 'next': 0.36; "i'll": 0.36; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'two': 0.37; 'email addr:python.org': 0.37; 'easily': 0.37; 'richard': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'rather': 0.38; 'subject:': 0.39; 'quote': 0.39; 'use.': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'according': 0.40; 'url:mail': 0.40; 'read': 0.60; 'skip:\xc2 10': 0.60; 'most': 0.60; 'mentioned': 0.61; 'numbers': 0.61; 'first': 0.61; 'here:': 0.62; 'times': 0.62; 'show': 0.63; 're:': 0.63; 'story': 0.63; 'real': 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'email name:python-list': 0.65; 'talking': 0.65; 'within': 0.65; 'benefit': 0.68; 'advantages': 0.68; 'continuous': 0.68; 'nobody': 0.68; 'default': 0.69; '8bit%:100': 0.72; 'applying': 0.72; 'url:htm': 0.73; 'audience': 0.74; 'cut': 0.74; 'about?': 0.84; 'again?': 0.84; 'berry': 0.84; 'fuck': 0.84; 'glass': 0.84; 'tolerant': 0.84; 'true!': 0.84; 'don\xe2\x80\x99t': 0.91; 'thing,': 0.91; '2013': 0.98
X-TMN [dCfudNFNqQJmxtbwE2hw7J00g6wIIZkU]
X-Originating-Email [carlosnepomuceno@outlook.com]
From Carlos Nepomuceno <carlosnepomuceno@outlook.com>
To "python-list@python.org" <python-list@python.org>
Subject RE: Short-circuit Logic
Date Sat, 1 Jun 2013 10:23:25 +0300
Importance Normal
In-Reply-To <51a86319$0$29966$c3e8da3$5496439d@news.astraweb.com>
References <51a86319$0$29966$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
MIME-Version 1.0
X-OriginalArrivalTime 01 Jun 2013 07:23:26.0104 (UTC) FILETIME=[E8058980:01CE5E98]
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2520.1370071413.3114.python-list@python.org> (permalink)
Lines 77
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1370071413 news.xs4all.nl 15932 [2001:888:2000:d::a6]:47526
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 11147
Xref csiph.com comp.lang.python:46650

Show key headers only | View raw


----------------------------------------
> From: steve+comp.lang.python@pearwood.info
> Subject: Re: Short-circuit Logic
> Date: Fri, 31 May 2013 08:45:13 +0000
> To: python-list@python.org
>
> On Fri, 31 May 2013 17:09:01 +1000, Chris Angelico wrote:
>
>> On Fri, May 31, 2013 at 3:13 PM, Steven D'Aprano
>> <steve+comp.lang.python@pearwood.info> wrote:
>>> What makes you think that the commutative law is relevant here?
>>>
>>>
>> Equality should be commutative. If a == b, then b == a. Also, it's
>> generally understood that if a == c and b == c, then a == b, though
>> there are more exceptions to that (especially in loosely-typed
>> languages).
>
> Who is talking about equality? Did I just pass through the Looking Glass
> into Wonderland again? *wink*
>
> We're talking about *approximate equality*, which is not the same thing,
> despite the presence of the word "equality" in it. It is non-commutative,
> just like other comparisons like "less than" and "greater than or equal
> to". Nobody gets their knickers in a twist because the>= operator is non-
> commutative.

Approximately equality CAN be commutative! I have just showed you that in the beginning using the following criteria:

|v-u| <= ε*max(|u|,|v|)

Which is implemented as fpc_aeq():

def fpc_aeq(u,v,eps=sys.float_info.epsilon):
    au=abs(u)
    av=abs(v)
    return abs(v-u) <= (eps*(au if au>av else av))  # |v-u| <= ε*max(|u|,|v|)


> Approximate equality is not just non-commutative, it's also intransitive.
> I'm reminded of a story about Ken Iverson, the creator of APL. Iverson
> was a strong proponent of what he called "tolerant equality", and APL
> defined the = operator as a relative approximate equal, rather than the
> more familiar exactly-equal operator most programming languages use.
>
> In an early talk Ken was explaining the advantages of tolerant
> comparison. A member of the audience asked incredulously,
> “Surely you don’t mean that when A=B and B=C, A may not equal C?”
> Without skipping a beat, Ken replied, “Any carpenter knows that!”
> and went on to the next question. — Paul Berry

That's true! But it's a consequence of floating points (discretes representing a continuous set -- real numbers).
Out of context, as you put it, looks like approximate equality is non-commutative, but that's wrong.

Did you read the paper[1] you have suggested? Because SHARP APL in fact uses the same criteria I have mentioned and it supports it extensively to the point of applying it by default to many primitive functions, according to Lathwell[2] wich is reference 19 of [1].

"less than                  a<b
less than or equal          a≤b
equal                       a=b
greater than or equal       a≥b
greater than                a>b
not equal                   a≠b
floor                       ⌊a
ceiling                     ⌈a
membership                  a∊b
index of                    a⍳b"


I'll quote Lathwell. He called "tolerant comparison" what we are now calling "approximate equality".

"Tolerant comparison considers two numbers to be equal if they are within some neighborhood. The neighborhood has a radius of ⎕ct times the larger of the two in absolute value."

He says "larger of the two" which means "max(|u|,|v|)". So, you reference just reaffirms what TAOCP have demonstrated to be the best practice.

I really don't know what the fuck you are arguing about?

Can you show me at least one case where the commutative law wouldn't benefit the use of the approximate equality operator?

[1] http://www.jsoftware.com/papers/APLEvol.htm
[2] http://www.jsoftware.com/papers/satn23.htm


> The intransitivity of [tolerant] equality is well known in
> practical situations and can be easily demonstrated by sawing
> several pieces of wood of equal length. In one case, use the
> first piece to measure subsequent lengths; in the second case,
> use the last piece cut to measure the next. Compare the lengths
> of the two final pieces.
> — Richard Lathwell, APL Comparison Tolerance, APL76, 1976
>
> See also here:
>
> http://www.jsoftware.com/papers/APLEvol.htm
>
> (search for "fuzz" or "tolerance".
>
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list 		 	   		  

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


Thread

Short-circuit Logic Ahmed Abdulshafy <abdulshafy@gmail.com> - 2013-05-26 04:11 -0700
  Re: Short-circuit Logic Roy Smith <roy@panix.com> - 2013-05-26 07:38 -0400
  Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-26 12:13 +0000
    Re: Short-circuit Logic Ahmed Abdulshafy <abdulshafy@gmail.com> - 2013-05-27 13:11 -0700
      Re: Short-circuit Logic Nobody <nobody@nowhere.com> - 2013-05-28 01:10 +0100
        Re: Short-circuit Logic Ahmed Abdulshafy <abdulshafy@gmail.com> - 2013-05-28 01:39 -0700
          RE: Short-circuit Logic Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-28 12:32 +0300
          Re: Short-circuit Logic Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-05-28 12:45 +0100
          Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-28 13:51 +0000
            Re: Short-circuit Logic Grant Edwards <invalid@invalid.invalid> - 2013-05-28 15:14 +0000
              Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-28 15:55 +0000
      Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-28 13:48 +0000
        Re: Short-circuit Logic Chris Angelico <rosuav@gmail.com> - 2013-05-29 00:01 +1000
        Re: Short-circuit Logic Ahmed Abdulshafy <abdulshafy@gmail.com> - 2013-05-29 07:27 -0700
          Re: Short-circuit Logic Chris Angelico <rosuav@gmail.com> - 2013-05-30 00:32 +1000
          Re: Short-circuit Logic rusi <rustompmody@gmail.com> - 2013-05-29 07:33 -0700
            Re: Short-circuit Logic Ian Kelly <ian.g.kelly@gmail.com> - 2013-05-29 10:50 -0600
              Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-30 02:28 +0000
                Re: Short-circuit Logic Chris Angelico <rosuav@gmail.com> - 2013-05-30 13:45 +1000
                Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-30 05:42 +0000
                Re: Short-circuit Logic Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-05-30 10:22 +0300
                Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-30 08:29 +0000
                Re: Short-circuit Logic Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-05-30 12:07 +0300
                Re: Short-circuit Logic Nobody <nobody@nowhere.com> - 2013-05-30 23:55 +0100
                Re: Short-circuit Logic Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-30 19:31 -0400
                Re: Short-circuit Logic Stefan Drees <stefan@drees.name> - 2013-05-31 17:34 +0200
                Re: Short-circuit Logic Roy Smith <roy@panix.com> - 2013-05-30 08:48 -0400
                Re: Short-circuit Logic Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-30 19:38 -0400
                Re: Short-circuit Logic Nobody <nobody@nowhere.com> - 2013-05-31 02:10 +0100
                Re: Short-circuit Logic Roy Smith <roy@panix.com> - 2013-05-30 21:21 -0400
                Re: Short-circuit Logic Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-30 21:57 -0400
                Re: Short-circuit Logic Michael Torrie <torriem@gmail.com> - 2013-05-30 21:33 -0600
                RE: Short-circuit Logic Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-31 03:03 +0300
                Re: Short-circuit Logic Chris Angelico <rosuav@gmail.com> - 2013-05-30 18:29 +1000
                RE: Short-circuit Logic Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-31 00:03 +0300
                Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-31 05:13 +0000
                RE: Short-circuit Logic Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-31 09:42 +0300
                Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-31 08:11 +0000
                Re: Short-circuit Logic Chris Angelico <rosuav@gmail.com> - 2013-05-31 17:09 +1000
                Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-31 08:45 +0000
                Re: Short-circuit Logic Roy Smith <roy@panix.com> - 2013-05-31 09:20 -0400
                RE: Short-circuit Logic Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-01 10:23 +0300
                Re: Short-circuit Logic 88888 Dihedral <dihedral88888@gmail.com> - 2013-05-30 20:11 -0700
            Re: Short-circuit Logic Dave Angel <davea@davea.name> - 2013-05-29 20:23 -0400
              Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-30 05:20 +0000
          Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-30 05:10 +0000
            Re: Short-circuit Logic Chris Angelico <rosuav@gmail.com> - 2013-05-30 15:22 +1000
              Re: Short-circuit Logic Roy Smith <roy@panix.com> - 2013-05-30 08:40 -0400
                Re: Short-circuit Logic Chris Angelico <rosuav@gmail.com> - 2013-05-30 22:58 +1000
                Re: Short-circuit Logic rusi <rustompmody@gmail.com> - 2013-05-30 09:58 -0700
                Re: Short-circuit Logic Chris Angelico <rosuav@gmail.com> - 2013-05-31 03:23 +1000
                Re: Short-circuit Logic Rick Johnson <rantingrickjohnson@gmail.com> - 2013-05-30 17:13 -0700
                Re: Short-circuit Logic Chris Angelico <rosuav@gmail.com> - 2013-05-31 12:29 +1000
                Re: Short-circuit Logic Ethan Furman <ethan@stoneleaf.us> - 2013-05-30 08:02 -0700
                Re: Short-circuit Logic Chris Angelico <rosuav@gmail.com> - 2013-05-31 01:56 +1000
                Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-30 16:40 +0000
                Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-30 19:22 +0000
                Re: Short-circuit Logic Chris Angelico <rosuav@gmail.com> - 2013-05-31 07:46 +1000
                Re: Short-circuit Logic Ethan Furman <ethan@stoneleaf.us> - 2013-05-30 09:30 -0700
              Re: Short-circuit Logic Neil Cerutti <neilc@norwich.edu> - 2013-05-30 19:30 +0000
                Re: Short-circuit Logic Ian Kelly <ian.g.kelly@gmail.com> - 2013-05-30 13:49 -0600
  Re: Short-circuit Logic Terry Jan Reedy <tjreedy@udel.edu> - 2013-05-26 16:19 -0400
    Re: Short-circuit Logic Roy Smith <roy@panix.com> - 2013-05-26 16:22 -0400
      Re: Short-circuit Logic Terry Jan Reedy <tjreedy@udel.edu> - 2013-05-26 17:28 -0400
      Re: Short-circuit Logic Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-27 00:40 +0000
        Re: Short-circuit Logic Cameron Simpson <cs@zip.com.au> - 2013-05-27 11:57 +1000
        Re: Short-circuit Logic rusi <rustompmody@gmail.com> - 2013-05-26 21:44 -0700
        Re: Short-circuit Logic Vito De Tullio <vito.detullio@gmail.com> - 2013-05-27 06:59 +0200
  Re: Short-circuit Logic Nobody <nobody@nowhere.com> - 2013-05-27 18:52 +0100
  Re: Short-circuit Logic Ahmed Abdulshafy <abdulshafy@gmail.com> - 2013-05-27 13:08 -0700
    Re: Short-circuit Logic Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-05-27 21:36 -0400

csiph-web