Posts: 4,653
Threads: 1,496
Joined: Sep 2016
i am wondering if squaring is faster than multiply in Python's large int arithmetic. i know there is a way, that i cannot recall, to optimize multiplication of a number with itself, mathematically. this cannot be done when the two numbers are different. i'm curious if the big int logic includes this for the case of raising power by 2 making a**2 faster than a*b where b != a but b is nearly as big as a,
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,653
Threads: 1,496
Joined: Sep 2016
i'll take that as a "no".
actually i had a way to use squaring as an alternative to multiplying for an app. if squaring was faster, it would be worth doing things that way. apparently not. big int is faster in Pike. but I'll stay with Python.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,653
Threads: 1,496
Joined: Sep 2016
Oct-01-2018, 02:29 AM
(This post was last modified: Oct-01-2018, 02:29 AM by Skaperen.)
if anyone is considering optimizing CPython, they should at least look at adding a check in the raise power (**) code to check for x**2 and x**3 (int powers) and do x*x an x*x*x instead of doing it the logarithm way. i doubt it is doing logarithms for big int to int power since i am getting really big int answers with all the right digits.
1 2 3 4 5 6 7 8 9 10 11 |
lt1 / forums / home / forums 3 > py3
Python 3.5 . 2 (default, Nov 23 2017 , 16 : 37 : 01 )
[GCC 5.4 . 0 20160609 ] on linux
Type "help" , "copyright" , "credits" or "license" for more information.
>>> 2 * * 64
18446744073709551616
>>> 20000000000000000001
20000000000000000001
>>> 20000000000000000001 * * 3
8000000000000000001200000000000000000060000000000000000001
>>>
|
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,653
Threads: 1,496
Joined: Sep 2016
Oct-02-2018, 04:09 AM
(This post was last modified: Oct-02-2018, 04:15 AM by Skaperen.)
uint64 (in C) is limited to a maximum of 2**64-1. in C, you can still assign -1 to it an will get that largest possible value. gcc supports a 64 bit int on 32 bit architectures and a 128 bit int on 64 bit architectures. to go beyond that, use libgmp or switch to Python.
in C,
x > 0xffffffffffffU
would never be true for any possible x that is uint64.
if power takes more time than the equivalent multiply, especially for big int, then power must be doing something else or something more. maybe for small int it is using logarithms. for big powers, that is the fast way. maybe a good test would be to work out the power with logs, and compare that to straight powering.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,653
Threads: 1,496
Joined: Sep 2016
Oct-03-2018, 02:59 AM
(This post was last modified: Oct-03-2018, 03:00 AM by Skaperen.)
i think Python float is limited to 64 bits and hence has a type as CUDA might know them. a really big int would be some kind of array. i'm have no idea how you might need to pass data to CUDA from Python, much less tell CUDA what it is getting. are you going to be running some specific software there that might document this or are you expecting to run your own Python code on it?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.