[Python-Dev] PEP 572: Assignment Expressions
Tim Peters
tim.peters at gmail.com
Mon Apr 23 13:31:31 EDT 2018
[Sven R. Kunze <srkunze at mail.de>]
> What about
>
> diff = x - x_base
> if diff and gcd(diff, n) > 1:
> return gcd(diff, n)
>
> # or
>
> if (x - x_base) and gcd(x - x_base, n) > 1:
> return gcd(x - x_base, n)
>
>
> and have the interpreter handle the optimization, or apply an lru_cache? ;-)
Surely you're joking. This is math.gcd(), which is expensive for
multi-thousand bit integers, and the interpreter knows nothing about
it. Adding a cache of _any_ kind (LRU or otherwise) would make it
even slower (in the application, there's no reason to expect that x -
x_base will repeat a value before O(sqrt(n)) iterations, which itself
can be thousands of bits - a cache hit would be a miracle).
More information about the Python-Dev
mailing list