Getting rid of bitwise operators in Python 3?

R

richyjsm

The `operator.pow()` is just the function for ``**``, it lacks the
optional third argument of the built in `pow()`.

Ciao,
Marc 'BlackJack' Rintsch

But does the three-argument version of pow() really belong in the
core? Who uses it? It seems very much like a specialist's function
to me: certainly it wouldn't be out of place in the standard library
somewhere (perhaps a cryptography or number theory module), but in its
three argument form it has to be one of the least used core functions.

Richard
 
S

Steven D'Aprano

On that subject, I'd suggest that the pow() builtin (not the ** operator
- just the pow() function) should also be a candidate for removal...

Help on built-in function pow in module __builtin__:

pow(...)
pow(x, y[, z]) -> number

With two arguments, equivalent to x**y. With three arguments,
equivalent to (x**y) % z, but may be more efficient (e.g. for longs).


Everybody forgets that pow can take three arguments, except of course for
those who use that functionality and would be mighty peeved if it went
away.
 
R

richyjsm

Everybody forgets that pow can take three arguments, except of course for
those who use that functionality and would be mighty peeved if it went
away.

And who is it who uses this functionality? It's useful in elementary
number theory, sure, but I'd argue that if there are going to be
number theoretical functions in the core then there are other things,
like gcd(), that are far more deserving of inclusion. It comes up in
the RSA cryptosystem, but if you're using Python's pow for this then
you're surely only writing a toy RSA implementation, perhaps for
educational purposes(?). Neither of these seem like compelling
arguments to have pow in the core.

Richard
 
G

George Sakkis

Well, if people are going to take the suggestion this personally, maybe
that's reason enough not to bother.

Carl Banks

If you want to push it further, one argument could be along the lines
of "ok, apparently bit fiddling is important for some classes of
problems but so are regular expressions. Are bit operations so
frequent and/or important to grant them around a dozen of operators
while there are none for regexps ?"

George
 
P

Paul Rubin

And who is it who uses this functionality?

I use it but I agree it's easy to implement given the underlying
bignum arithmetic.
It's useful in elementary number theory, sure, but I'd argue that if
there are going to be number theoretical functions in the core then
there are other things, like gcd(), that are far more deserving of
inclusion.

Certainly xgcd should be in the math library or somewhere similar.
It comes up in the RSA cryptosystem, but if you're using
Python's pow for this then you're surely only writing a toy RSA
implementation, perhaps for educational purposes(?).

Not necessarily. See for example http://trevp.net/tlslite
 
R

richyjsm

Certainly xgcd should be in the math library or somewhere similar.

It does feel odd to have modular exponentiation in the core but no
other number-theoretic stuff in core+libraries. Perhaps a proposal on
python-ideas is in order... Though it's not clear what else would be
useful; primality testing and factoring are obvious candidates, but I
don't much fancy writing an MPQS factorization algorithm in Python.
Well okay, I take that back---I wouldn't mind *writing* it; I just
wouldn't expect to get much speed from *running* it. Miller-Rabin
probabilistic primality testing would be easy to implement though.

Anyway, I'm getting way off-topic here... sorry.
Not necessarily. See for example http://trevp.net/tlslite

Interesting. Thanks for the link.

Richard
 
P

Paul Rubin

Well okay, I take that back---I wouldn't mind *writing* it; I just
wouldn't expect to get much speed from *running* it.

I don't see why not. It's just the basic Python long arithmetic which
is coded in C. I tested it against gmpy (carefully written asm code
and tuned algorithms) and gmpy's modexp was around 4x faster, but
Python's is plenty fast enough for many purposes. The 4x ratio is
certainly lower than the usual ratio between Python code and C code.
 
P

Paddy

Well, if people are going to take the suggestion this personally, maybe
that's reason enough not to bother.

Carl Banks

Carl, don't snipe. You asked and received many answers from personal
viewpoints.
Tally and move on. - Paddy.
 
M

mensanator

It does feel odd to have modular exponentiation in the core but no
other number-theoretic stuff in core+libraries. Perhaps a proposal on
python-ideas is in order... Though it's not clear what else would be
useful;

Greatest Common Denominator
Least Common Multiple
Modular Inverse
Linear Congruence

(all found in gmpy)
primality testing

Also in gmpy.
and factoring

Alas, not in gmpy. I work around that by using a
custom version I made of factor.exe from the MIRACL
library. Which, alas, doesn't work quite right and
which I would think is beyond my ability to fix.
But this can be fixed in the Python program I use
to capture the factors.
 
C

c d saunter

: arguments and dicts, which are lot more versatile. Another major use,
: talking to hardware, is not something oft done in Python either.

Are you sure? I've been doing lots of exactly that for 4 years, and
I'm not the only one round here... Python makes an excellent language for
talking to hardware.

cds
 
D

[david]

But does the three-argument version of pow() really belong in the
core? Who uses it?

It was a common cryptographic operation.

The two-argument version is used by the same
person who wrote the semi-colon at the end of
every line of the code I'm working with.

Personally, I'm sorry that 'and' and 'or' weren't
chosen for the bitwise operators: I'd happily give
up 'and' and 'or' for logic operations.

[david]
 
A

Anurag

Anyone with me here? (I know the deadline for P3 PEPs has passed; this
is just talk.)

Not many people are bit-fiddling these days. One of the main uses of bit
fields is flags, but that's not often done in Python because of keyword
arguments and dicts, which are lot more versatile. Another major use,
talking to hardware, is not something oft done in Python either.
Actually I think many people are not using many operators now
days..lets remove them all
e.g. I searched one of my downloder script and it doesn't have '+'
operator
lets remove it!

-Anurag
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,172
Latest member
NFTPRrAgenncy
Top