Open oppressionslayer opened 4 years ago
Please use ``` to format your code (see https://guides.github.com/features/mastering-markdown/). Otherwise it removes the indentation and isn't readable.
ok, i added those
At second look this isn't faster, but the code is more concise. I'll post again if i find a faster method
I updated the orignal post with a faster algorithm and updated the description. This is just to show that a refactor can lead to faster results using a shortcut in a base 10 to 16 relationship of repeating trailing numbers. Something you may or may not be interested in, but maybe the performance gains are so i wanted to share
I see that trailing
is used in a number of other functions like perfect_power
and some prime testing routines. Does this lead to a measurable speed up in any of those?
@haru-44 , you already made changes. Should this issue be closed?
I think it is good to close. Essentially, I think small_trailing
implements this suggestion.
Most definitely!
On Tue, Sep 19, 2023, 7:41 AM haru-44 @.***> wrote:
I think it is good to close. Essentially, I think small_trailing implements this suggestion.
— Reply to this email directly, view it on GitHub https://github.com/sympy/sympy/issues/20014#issuecomment-1725469484, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI35AJHMKQPDEQN7MFJULMTX3GOG3ANCNFSM4QOSTXMA . You are receiving this because you modified the open/close state.Message ID: @.***>
I discovered a much faster method to get the shifted value of trailing by using powers of two math to get the same result. The speeds are 1.5x to 3x faster for larger numbers and only 3x slower in 1 in 15 cases, so an overall performance increase:
Code for quick testing:
Results:
This is just a suggestion, as the math is faster and code is more concise and the code is more accurate in terms of the math used to determine the result. Feel free to ignore if you don't need these speed increase. This is just a suggestion. There is slight difference in usage as mine does the shift operation with a division in the trailing algorithm. This is a different approach to the problem, as it uses shortcuts of a base 10 to 16 relationship of repeating numbers in that base 10 to 16 relationship. Instead of the Stein Algorithm, i used sympy's algorithm for cases of 1 Again, just a suggestion and some support for it's use if you would like the speed increase, feel free to use. It is slower 1 in 15 tries ,but i think the performance gain 1.5x to 3x of the other 15 numbers outweighs the 3x slower of the 1 in 15.
In the case someone wants to build the powers of two path down a number that's over a million digits long, the performance enhancements may be helpful. I used the algorithm above to build that for A Million Random Digits from the RAND corporation and it finished rather quickly.