Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

As a computer, I find your faith in technology amusing.


devel / comp.lang.python / Re: xor operator

SubjectAuthor
o Re: xor operatorDom Grigonis

1
Re: xor operator

<mailman.235.1699923631.3828.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24455&group=comp.lang.python#24455

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!paganini.bofh.team!2.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: dom.grig...@gmail.com (Dom Grigonis)
Newsgroups: comp.lang.python
Subject: Re: xor operator
Date: Tue, 14 Nov 2023 03:00:26 +0200
Lines: 63
Message-ID: <mailman.235.1699923631.3828.python-list@python.org>
References: <2624DD04-097A-48B1-9F05-C6EF30F4C82D@gmail.com>
<6552a859.020a0220.8cb14.012f@mx.google.com>
<78B43ECD-2EFC-4CDF-99C4-DC310F0B26DE@gmail.com>
<CAPTjJmr+AthCgZWkkehL3i=wCywGG+ShUiBcKtkhZxYdFgy+ow@mail.gmail.com>
<FCFD8802-9FE9-48E0-B453-F9C22121EDF9@gmail.com>
<2f915cf1-c8ca-4db4-87a7-4597d5209b71@wichmann.us>
<50B86B3F-4EE9-4570-A650-691554F8E71F@gmail.com>
Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\))
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de jMDi/IVpeT30RlUylA62gQKNmeX/Bkls68Y2A3PUvUkQ==
Cancel-Lock: sha1:bpBnO2K/1rEBNIBeEIww40/cRUA= sha256:jfIrHi77W0GifQ3g/ACXxxVR11x87li+2Co6a6UbijQ=
Return-Path: <dom.grigonis@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=Gq2utogf;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; 'fairly':
0.05; 'is.': 0.05; 'thing.': 0.07; 'python.': 0.08; 'cc:addr
:python-list': 0.09; 'didn\xe2\x80\x99t': 0.09; 'mechanism': 0.09;
'perspective': 0.09; 'situations': 0.09; 'those.': 0.09;
'url:mailman': 0.15; 'anything,': 0.16; 'cc:name:python': 0.16;
'forums': 0.16; 'mats': 0.16; 'mean.': 0.16; 'nodes': 0.16;
'perhaps,': 0.16; 'received:apple': 0.16;
'received:smtpclient.apple': 0.16; 'similar,': 0.16; 'slow': 0.16;
'somewhat': 0.16; 'terribly': 0.16; 'to:name:mats wichmann': 0.16;
'useful.': 0.16; 'wichmann': 0.16; 'wrote:': 0.16; 'problem':
0.16; 'python': 0.16; 'reached': 0.17; 'message-id:@gmail.com':
0.18; 'hardware': 0.19; 'cc:addr:python.org': 0.20; 'views': 0.23;
'url-ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'url:listinfo': 0.25; 'cc:2**0': 0.25; 'url-ip:188.166/16': 0.25;
'clicked': 0.26; 'bit': 0.27; 'function': 0.27; 'folks': 0.28;
'email addr:python.org&gt;': 0.28; 'suggest': 0.28; 'seem': 0.31;
'url-ip:188/8': 0.31; 'think': 0.32; 'question': 0.32;
'encountered': 0.32; 'false,': 0.32; 'here,': 0.32; 'manner.':
0.32; 'python-list': 0.32; 'but': 0.32; 'there': 0.33;
'particular': 0.33; 'same': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'complex': 0.35; 'one.': 0.35;
'yes,': 0.35; 'from:addr:gmail.com': 0.35; 'cases': 0.36;
'processes': 0.36; 'people': 0.36; 'those': 0.36; 'using': 0.37;
"it's": 0.37; 'way': 0.38; 'could': 0.38; 'means': 0.38; 'two':
0.39; 'added': 0.39; 'least': 0.39; 'single': 0.39; 'use': 0.39;
'case.': 0.40; 'people,': 0.40; 'something': 0.40; 'want': 0.40;
'provide': 0.60; 'here': 0.62; 'true': 0.63; 'great': 0.63;
'once': 0.63; 'skip:b 20': 0.63; 'experience': 0.64; 'clear':
0.64; 'less': 0.65; 'bad': 0.67; 'times': 0.69; 'took': 0.69;
'interesting': 0.71; 'combination': 0.76; 'dead': 0.81;
'combinations': 0.84; 'dom': 0.84; 'dozen': 0.84; 'email name:&lt
;python-list': 0.84; 'received:88': 0.84; 'trick,': 0.84;
'positive': 0.86; 'convey': 0.91; 'me:': 0.91; 'number.': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1699923628; x=1700528428; darn=python.org;
h=references:to:cc:in-reply-to:date:subject:mime-version:message-id
:from:from:to:cc:subject:date:message-id:reply-to;
bh=7NeIFJgru4NUPLr0miewbN+vtf3Q4x2ezqokHvcu/PQ=;
b=Gq2utogf6zAS70sijDL8khspt8HIiteOLvmclpxRafrZiNoEVmV/x1lCXkbTwZr5d9
8RacECvxn0Wey6kTi4H8RnEaN9TMQyWteGwQb3mpd/Sq2lRlKDRbwLVa1p8v62im1O2A
eNVFqDMxB+lL9bZyQLwTVgzkEomD11iK25p/el1O2IVPCmdkfJVUc9tMBEemUgTbjYX6
NcuWgZXVVgWJvUt3KIqwX3fLnBxxnJUS2HD1tjE0c3okcAe0olMlQm5JyQK2efWZCKaW
+L/iI0cXv2aoZmiQjQniCCo4w7Zzs71/NSgSiq7F7DSH3Y8XSz3szGd2TkbD47z8oduR
KAnQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1699923628; x=1700528428;
h=references:to:cc:in-reply-to:date:subject:mime-version:message-id
:from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=7NeIFJgru4NUPLr0miewbN+vtf3Q4x2ezqokHvcu/PQ=;
b=AdBtx8q/cTuqh8ZN67VAo7bQvL1ZOOuOcUSSuL9XGxt9HLcaSlkVM3Ny6GCIR03xU4
p7x8i4oMe/Imp3ZTqS2rlpXt9pfeP36X6FuIcJwjPo4x1OtvnDP46nDwik5HcRODePfl
1LSjPnAFlWWzLpUqSSrWKz0NlvICX1spp5tlZoV0M+ov/u0+jEnHj2pI8wGeCkcMbamK
FEQuqHNgfk2HRkPk02d4/rNh49m3jRAHT3vZ5rc4q7UV0URpNCZaJJzi8PPGro83rKE3
jPxBNWeuUFGgFE5KS6K0MHUWoczX1+r07NlYIDC/xxXCfvVS0JBl774YuZt2oamWOBOE
fi7Q==
X-Gm-Message-State: AOJu0YyoXq6LMLdfxUvj7TO2QBNYpNUwKwNLgi8d3IKClUK2CtxH5g85
5yyzJiSbBC8dTkDJ4Nl5Tl/xiIqxgos=
X-Google-Smtp-Source: AGHT+IFp8hZdvT/axtBd/CD4cdIApiZLSNIUjRyjCTAc0bHPPJtoBR2wLxSCZJ9pluimfvhp1RZt3A==
X-Received: by 2002:a05:6512:239f:b0:50a:756c:dfc3 with SMTP id
c31-20020a056512239f00b0050a756cdfc3mr6707462lfv.3.1699923628038;
Mon, 13 Nov 2023 17:00:28 -0800 (PST)
In-Reply-To: <2f915cf1-c8ca-4db4-87a7-4597d5209b71@wichmann.us>
X-Mailer: Apple Mail (2.3654.120.0.1.15)
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <50B86B3F-4EE9-4570-A650-691554F8E71F@gmail.com>
X-Mailman-Original-References: <2624DD04-097A-48B1-9F05-C6EF30F4C82D@gmail.com>
<6552a859.020a0220.8cb14.012f@mx.google.com>
<78B43ECD-2EFC-4CDF-99C4-DC310F0B26DE@gmail.com>
<CAPTjJmr+AthCgZWkkehL3i=wCywGG+ShUiBcKtkhZxYdFgy+ow@mail.gmail.com>
<FCFD8802-9FE9-48E0-B453-F9C22121EDF9@gmail.com>
<2f915cf1-c8ca-4db4-87a7-4597d5209b71@wichmann.us>
 by: Dom Grigonis - Tue, 14 Nov 2023 01:00 UTC

I agree, from perspective of standard `all` and `any` use cases this does not seem very useful.

However, in my experience it has its usages. E.g.:
* If sum(map(bool, iterable) [> | <] n can be useful. Counting dead processes and similar, optimisation problems where need to re-initialise if less than certain number of nodes reached certain threshold.
* If sum(map(bool, iterable) [== | !=] n is an edge case. Can’t even think of an example
* Finally, it would be a convenient shorthand for `bool(a) ^ bool(b)`

I sometimes think that there is also a case when certain function is not in one’s mind he doesn’t see the usefulness, but sometimes the sheer knowledge of its existence can twist certain situations in a positive manner.

What about an alternative, which does seem more useful:

def count_compare(iterable, n):
return np.sign(sum(map(bool, iterable)) - n)

print(count_compare([False, False, False], 1))
As I am here, I will dare to ask if there is no way that `sign` function is going to be added to `math` or `builtins`. `np.sign` does the trick, but it is very slow to be used on a single number. And yes, I know that `copysign` exists, it just doesn’t do the same thing.

DG

> On 14 Nov 2023, at 02:33, Mats Wichmann via Python-list <python-list@python.org> wrote:
>
> On 11/13/23 16:24, Dom Grigonis via Python-list wrote:
>> I am not arguing that it is a generalised xor.
>> I don’t want anything, I am just gauging if it is specialised or if there is a need for it. So just thought could suggest it as I have encountered such need several times already.
>> It is fairly clear by now that it is not a common one given it took some time to even convey what I mean. Bad naming didn’t help ofc, but if it was something that is needed I think it would have clicked much faster.
>
> There are things that If You Need Them You Know, and If You Do Not You Do Not Understand - and you seem to have found one. The problem is that forums like this are not a statistically great sampling mechanism - a few dozen people, perhaps, chime in on many topics; there are millions of people using Python. Still, the folks here like to think they're at least somewhat representative :)
>
> Hardware and software people may have somewhat different views of xor, so *maybe* the topic title added a bit to the muddle. To me (one of those millions), any/all falsy, any/all truthy have some interest, and Python does provide those. Once you get into How Many True question - whether that's the odd-is-true, even-is-false model, or the bail-after-X-truthy-values model, it's not terribly interesting to me: once it gets more complex than an all/any decision, I need to check for particular combinations specifically. Two-of-six means nothing to me until I know which combination of two it is.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor