![]() |
|
|
#199 | |
|
Aug 2006
10111010110112 Posts |
Quote:
Let's see... how to go about generating a random semiprime. Suppose we want one in the range (a, b] with b - a large compared to log^2 b and b/a small. There are So if the range is (2^99, 2^100] then we want to give 2 weight 1/2, 3 weight 1/3, ..., and 1125899906842597 weight 1/1125899906842597. (I'm going to ignore issues about choosing toward the end of the range here.) The total weight is going to be about M + log log sqrt b.* So generate a random number uniformly at random up to that total, subtract M, and exponentiate twice, choosing a prime around there. Then generate the other factor as appropriate. * Dusart's recent preprint gives reasonably tight bounds on this. Pity, though, I don't know of a correcting term, because there certainly seems to be one. |
|
|
|
|
|
|
#200 |
|
May 2010
Prime hunting commission.
32208 Posts |
Alternatively, you could just multiply two random primes together. No need for much math work on generating a set of random primes to multiply together to form a semiprime.
Wait.. disregard the above. Last fiddled with by 3.14159 on 2010-08-11 at 01:29 |
|
|
|
|
|
#201 | |
|
Aug 2006
3·1,993 Posts |
Quote:
But I thought you were looking at strong pseudoprimes, not Fermat pseudoprimes. In that case "Average case error estimates for the strong probable prime test" is probably more appropriate, though I don't remember if they define an analogue for P(x). |
|
|
|
|
|
|
#202 | |||
|
Aug 2006
3×1,993 Posts |
Quote:
Quote:
Quote:
I suggest breaking the task down into simple parts and working on them separately. That way you won't get discouraged by the difficulty of the whole task -- and you can have something that you can finish in an hour rather than in a lifetime. |
|||
|
|
|
|
|
#203 |
|
"Forget I exist"
Jul 2009
Dumbassville
100000110000002 Posts |
lets say it was on the same computer all together we have:
1) read the problem to the script 2) decipher the meaning of the problem 3) output a code that does what the problem needs. the main one when it's on one computer is 2) decipher the meaning of the problem. example if the problem is read as: find all primes from x upto/until/to n the key words/phrasings I see are 1)find - suggest to most I think that they may not necessarily want to have them printed to them but to get them for further use (though printing is a further use in one sense) 2)all primes-means they don't want any missed. 3)from-shows us there's a range involved and that that range may be anywhere on the number line (so we can just assume 1 in this case). 4)x-our lower limit if it's odd if not it's x+1 (except when x = 2) that is our lower limit. 5) upto/until/to- these all mean in the positive direction last i checked. 6) n-our upper bound. so generically they want: Code:
forprime(p=x,n,do something else/likely print()) Code:
for(p=x,n,if(isprime(p),do something else/likely print())) Last fiddled with by science_man_88 on 2010-08-11 at 02:07 |
|
|
|
|
|
#204 |
|
Aug 2006
597910 Posts |
Agreed, 2 does seem the hardest. 1 is easy.
So why don't you focus on #3. It's not completely trivial, but unlike #2 it isn't a lifetime research project.
|
|
|
|
|
|
#205 | |
|
"Forget I exist"
Jul 2009
Dumbassville
100000110000002 Posts |
Quote:
I used the words to decipher the meaning and in doing so I was able to give possible codes. |
|
|
|
|
|
|
#206 |
|
Aug 2006
10111010110112 Posts |
OK, here's my program for generating random semiprimes. It's not perfect, but it gives reasonable results I think. And the speed should be fast even when working with large numbers.
If you need higher-quality results, you'd want correction factors for M when generating p and a different method entirely for selecting q. The first takes mathematical knowledge and programmer time to implement, but wouldn't make the program run much more slowly at all; the second takes little time to implement (< 10 minutes) but would cause the program to run perhaps ~100 times more slowly at large numbers. Code:
rsp(b,flag=0)={
if(b<7,
if(b<3, error("No semiprimes with fewer than 3 bits"));
if(type(b) != "t_INT", error("Bad type in rsp"));
my(n);
if(b==3,n=[4,6]);
if(b==4,n=[9,10,14,15]);
if(b==5,n=[21,22,25,26]);
if(b==6,n=[33,34,35,38,39,46,49,51,55,57,58,62]);
n=n[random(#n)+1];
return(if(flag,factor(n),n))
);
\\ Choose the small prime as 2 with probability 1/2, 3 with probability 1/3, etc.
my(M=.261497212847642783755,weight=log(b*log(2)/2)+M,r=random(round(weight << 64))*1.>>64,p=precprime(exp(exp(r-M))),q);
q=2^b\p;
q=nextprime(q\2+random(q\2));
if(p > q,
b = p;
p = q;
q = b;
);
if(flag,
if(p==q,
matrix(1,2,i,j,if(j==1,p,2))
,
[p,1;q,1]
)
,
p*q
)
};
addhelp(rsp, "rsp(b, {flag=0}): Generates a random b-bit semiprime. If flag is nonzero, returns the factorization of the number.");
|
|
|
|
|
|
#207 |
|
Aug 2006
3·1,993 Posts |
It doesn't have to. Suppose your program works like this:
Code:
foo(name, description)={
\\ stuff goes here that figures out what the user wants
if (userDesire == 1,
print("forprime(p="start","stop","func");")
return;
);
if (userDesire == 2,
print("isprime("start");")
return;
);
if (userDesire == 3,
error("i'm afraid I can't do that, Dave.")
);
error("Bad user desire code")
};
|
|
|
|
|
|
#208 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
interesting idea...
dictionary for step 2 with different wordings leading to a main math word that they describe. that math word can be linked to specific codes to help put it in practice. |
|
|
|
|
|
#209 | |
|
Aug 2006
597910 Posts |
Quote:
|
|
|
|
|
![]() |
| Thread Tools | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why do I sometimes see all the <> formatting commands when I quote or edit? | cheesehead | Forum Feedback | 3 | 2013-05-25 12:56 |
| Passing commands to PARI on Windows | James Heinrich | Software | 2 | 2012-05-13 19:19 |
| Ubiquity commands | Mini-Geek | Aliquot Sequences | 1 | 2009-09-22 19:33 |
| 64-bit Pari? | CRGreathouse | Software | 2 | 2009-03-13 04:22 |
| Are these commands correct? | jasong | Linux | 2 | 2007-10-18 23:40 |