[Python-Dev] PEP 572: Assignment Expressions (original) (raw)
Tim Peters tim.peters at gmail.com
Mon Apr 23 13:31:31 EDT 2018
- Previous message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Next message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Sven R. Kunze <srkunze at mail.de>]
What about
diff = x - xbase if diff and gcd(diff, n) > 1: return gcd(diff, n) # or if (x - xbase) and gcd(x - xbase, n) > 1: return gcd(x - xbase, n)
and have the interpreter handle the optimization, or apply an lrucache? ;-)
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).
- Previous message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Next message (by thread): [Python-Dev] PEP 572: Assignment Expressions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]