![]() |
|
|
#23 | ||
|
∂2ω=0
Sep 2002
República de California
1163910 Posts |
Quote:
The revised function, assuming no mathlib loaded or mathlib loaded and scale=0: Quote:
But hey, what is trial without its necessary-for-learning partner, error? Last fiddled with by ewmayer on 2017-10-14 at 03:24 |
||
|
|
|
|
|
#24 |
|
Sep 2002
Database er0rr
3,739 Posts |
Computing 2^r is the slow thing and that could be done 3 times. Given such a worst case, how does it compare with your recursive divide and conquer function?
|
|
|
|
|
|
#25 | |
|
∂2ω=0
Sep 2002
República de California
103×113 Posts |
Quote:
Having btiwise functions bits() and reverse() allowed me to compare RL and LR binary powering algos ... the latter runs in ~60% the time of the former for a typical scenario: for a base-3 PRP test of the ~thousand-decimal-digit m-prime M3217, RL needs ~60 sec, LR needs ~30 (this is best-case for LR because nearly every exponent bit = 1; for quasirandom exponents LR typically needs 2/3 r=the runtime of RL). Basic gcd and egcd also work. May play with extended factoring functionality (p-1, later ecm and possibly qs) next, but first a deeper look at the NT-for-bc link you provided over the weekend. |
|
|
|
|
|
|
#26 |
|
Bamboozled!
"𒉺𒌌𒇷𒆷𒀭"
May 2003
Down not across
10,753 Posts |
How many systems around here do not have Perl installed? AFAIK it runs on almost everything and is an essential part of the system for anything which is even vaguely Unix-like.
Ernst: if you have Perl just use it. It's so much more flexible than bc. |
|
|
|
|
|
#27 | |
|
Sep 2002
Database er0rr
72338 Posts |
Quote:
Last fiddled with by paulunderwood on 2017-10-14 at 21:57 |
|
|
|
|
|
|
#28 |
|
∂2ω=0
Sep 2002
República de California
2D7716 Posts |
Paul, of course Perl is much better suited for such stuff, but permit me my little exercise in getting-a-really-dumb-dog-to-perform-some-new-tricks-ery - it's a nice bit of fun for times when I need a break from my usual serious coding work but still wish to keep my brain in code/algo-focused mode.
By way of somewhat-answering the question I posed in the OP, bc's limited programming functionality forces one to resort to kludgery in order to support any kind of reasonable const-array-init, but it's not too bad for some common kinds of inits. For example, in my C codebase I have a utility function to generate a table of all odd primes up to some bound, whocse current limit is 2^32. Said function uses a simple mod-3,5 sieve and feeds the resulting candidates to a Fermat 2-PRP routine. That needs an auxiliary table of known Fermat base-2 pseudoprimes, of which there are 9366 < 2^32 not divisible by 3 or 5. So let's say we want to code similar in bc, restricting ourselves to prime < 10^8. We can do this by taking our C-code array-init for the Fermat base-2 pseudoprimes, excerpting the entries < 10^8, reverse-sorting them, left-0-padding all entries to 8 decimal digits, concatenating the results them into a long decimal string, and feeding same to a loop which does repeated mod-and-div-by-10^8 to init our array. The yuuge decimal string is not particularly fuglier than the big comma-separated table used in the C-code's array init, and the repeated-div loop needs just a few seconds to run. The associated small-primes-init code needed ~60 sec on my Core2 macbook to generate the first 65536 odd primes, which is of course really slow, but not egregious to support such basic-foundation operations in bc. Code attached. |
|
|
|
|
|
#29 |
|
Sep 2009
2×1,039 Posts |
Another reason for avoiding bc is that it's a lot slower than GMP. I've just updated my script searching for algebraic factors of number in factordb to work out what the number evaluates to with pexpr (sample program shipped with GMP) instead of bc and it's dramatically faster.
Code:
time pexpr '(74^16820-1)/1791051738450034974183457153894994534200971751588579164486402699442174091407878519893290614801' >/dev/null real 0m0.017s user 0m0.012s sys 0m0.004s Code:
echo '(74^16820-1)/1791051738450034974183457153894994534200971751588579164486402699442174091407878519893290614801' | time -p bc >/dev/null real 0.17 user 0.16 sys 0.00 Chris |
|
|
|
|
|
#30 |
|
∂2ω=0
Sep 2002
República de California
1163910 Posts |
I would never recommend bc based on speed, but it has the advantage that you don't need to download/install it. I.e. if I want to play around with some not-huge bignum calculations on any of my posix boxes, "it's just there". I've had numerous build/install fails with gmp under various versions of macos in the past, an issue that is quite common if you're an OS-upgrade-Luddite like me, who likes his macOS 10.6.8 because it was the last version of said OS before Apple succumbed to featuritis and turned its subseqent versions into iOS-driven bloatware. (I have a backup macbook running 10.7.5 and the few times I've used it I've wante to tear my hair out, it's so bloody ^!%&$ slow).
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Array vs Hash Table vs Map for QS | Sam Kennedy | Programming | 1 | 2012-12-25 23:25 |
| Init.d Script for MPrime | CrashM | Software | 0 | 2012-05-18 01:01 |
| array of bits | Citrix | Programming | 2 | 2005-08-21 20:06 |
| Ubasic Array question | rn0dal | Programming | 6 | 2004-09-15 14:57 |