mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   PARI/GP (https://www.mersenneforum.org/forumdisplay.php?f=155)
-   -   IntegerExponent Equivalent in Pari-GP (https://www.mersenneforum.org/showthread.php?t=21198)

Dubslow 2016-05-24 13:15

[QUOTE=CRGreathouse;434758]It uses it (or rather, it uses software which itself relies on GMP) to do correctly-rounded constant-folding and the like, as I recall.[/QUOTE]

Hmmm... and that requires arbitrary precision arithmetic? If I define a constant with 100 decimals, does gcc truly record all 100? I suppose it has to if you're using GMP yourself...?

(Edit: This post falls firmly into the "edification by posting a stupid answer" category :smile:)

xilman 2016-05-24 16:04

[QUOTE=a1call;434712]Thank you for all the replies.
The following probably belongs to it's own thread, but I rather not mess up the board.

I am trying to come up with uses other than Number-Theory for "arbitrary precision math operations". The only things I can think of would be astronomical and calendar calculations. Perhaps it could be used for subatomic calculations if they somehow warrant extreme precision.

* Are there any other real world applications anyone can think of?

Thanks in advance.[/QUOTE]There are a number of situations in numerical analysis where the computations are extremely ill-behaved. To oversimplify greatly, it is sometimes necessary to compute two large and almost equal numbers separately and then subtract one from the other to compute the solution required.

CRGreathouse 2016-05-24 16:09

[QUOTE=Dubslow;434760]Hmmm... and that requires arbitrary precision arithmetic?[/QUOTE]

It can. Consider taking the sine of a large number near an integer multiple of [$]\pi.[/$]

gcc does other mathematical heavy lifting in its optimization phase (e.g., Graphite), but I don't know if GMP is used, directly or indirectly.

xilman 2016-05-24 16:14

[QUOTE=xilman;434775]There are a number of situations in numerical analysis where the computations are extremely ill-behaved. To oversimplify greatly, it is sometimes necessary to compute two large and almost equal numbers separately and then subtract one from the other to compute the solution required.[/QUOTE]A variant on this crops up in computational chemistry, a field in which I have some interest. Molecular spectroscopists can often measure energy separations to 8 significant digits (separations of several eV measured to an accuracy of 10[SUP]-7[/SUP] eV) which doesn't sound very much, not much more than standard single precision.

However, the levels themselves may be 10[SUP]5[/SUP]eV below the energy of the starting state of infinitely separated nuclei and electrons, so the precision required is now (5 - (-7)) = 12 digits for a useful answer. Standard double precision fp is barely adequate, even if the equations to be solved are well-behaved. Often they are not.

science_man_88 2016-05-25 19:43

I think a1call should be looking at the pari commands thread:

[url]http://mersenneforum.org/showthread.php?t=13636[/url] ( yes there's a lot of me being stupid and it's now 27 pages in even on 97 posts per page but at least some of it may be worth looking at)

CRGreathouse 2016-05-25 20:42

Also the mercifully short replacement thread
[url]http://www.mersenneforum.org/showthread.php?p=422544[/url]

a1call 2016-05-25 20:52

[QUOTE=CRGreathouse;434834]Also the mercifully short replacement thread
[url]http://www.mersenneforum.org/showthread.php?p=422544[/url][/QUOTE]

Thank you for all the replies and suggestions.
I'd be reluctant to post my simpleton/numerous inquiries in a thread like that. A bulletin-board has limited value as a reference resource unless it Is part of a Search-Engine [URL="https://en.wikipedia.org/wiki/Search_engine_results_page"]SERP[/URL]. Accordingly, it doesn't really matter where the thread is as long as it is indexed by google.

science_man_88 2016-05-25 21:18

[QUOTE=CRGreathouse;434834]Also the mercifully short replacement thread
[url]http://www.mersenneforum.org/showthread.php?p=422544[/url][/QUOTE]

if only i was good at doing tricks most things I do are just playing around.

CRGreathouse 2016-05-25 21:19

Short posts are nice when you want to read them rather than just search them, though. :smile:

science_man_88 2016-05-25 22:13

[QUOTE=CRGreathouse;434839]Short posts are nice when you want to read them rather than just search them, though. :smile:[/QUOTE]

yeah but I have too many things to say at times yet nothing of substance, one of the best rule I've learned on this forum is know your data you can make a crappy version of a script to print all the squares up to a number say 1 billion in over 2 minutes or you can use things you know about the squares and eliminate the checks and print all up to 100 billion in under 21 seconds .

CRGreathouse 2016-05-26 01:39

Well, the whole purpose of the thread was to share the kinds of tricks that let people like me do things like that! :smile:

Let me give a silly example. Suppose you wanted to build a list of all the numbers up to a billion that (1) were one more than a square and (2) were prime. You could write tests for each of these conditions, and then test them over each of those numbers:
[code]isOneMoreThanASquare(n)=issquare(n-1)
addhelp(isOneMoreThanASquare, "isOneMoreThanASquare(n): Returns 1 if n-1 is a square and 0 otherwise.")

\\isprime already exists

v=List();
for(n=1, 10^9, if(isOneMoreThanASquare(n) && isprime(n), listput(v, n)));
v=Vec(v); \\ converts from a list to a vector
#v \\ the number of terms found[/code]

But since you can iterate over both types of number, you might consider
[code]forprime(n=2, 10^9, if(isOneMoreThanASquare(n), listput(v, n)))[/code]
or
[code]for(k=1,sqrtint(10^9-1), n=k^2+1; if(isprime(n), listput(v, n)));[/code]

Stop to think about this for a moment -- don't try these yet. Which would work better, and why? Can you find a general rule about finding sequences with two particular properties (when you can loop over and test for membership of both)?

If you can, compare the expected time for these two approaches. Once you do, as a follow-up question, what can you do to make this code more efficient, by using the parity of primes greater than 2? How much of a difference does this make compared to choosing the better of the two methods?


All times are UTC. The time now is 06:54.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.