Benutzer Diskussion:Yoyo/factordb
Factordb is a repository for integer factorizations that are used in many areas: aliquot sequences, homeprime sequences, the Cunningham project, odd perfect number research, and many others. By factoring numbers in the database, all of these areas benefit.
Some tools to factor composites needed in factordb.
Inhalt
yafu.pl
Takes composites (beginning with 70 digits) from factordb which needs to be factored. yafu.pl downloads a random composite and runs yafu to factor it. Afterwards the factors are reported back to the factordb.
preconditions
You need:
- Perl
- the yafu binary
- optional: gnfs binaries, which is faster for composites with more than 95 digits than the build in siqs method and which can use multiple cores.
- optional: gmp-ecm binary which can than use multiple cores
source
#!/usr/bin/perl use warnings; use strict; use LWP::Simple; my %total; while(1){ print "get composites\n"; my $rand=int(rand(100)); my $contents = get("http://factordb.com/listtype.php?t=3&mindig=10&perpage=1&start=$rand&download=1"); if (!defined $contents or $contents =~ /[a-z]/ ){ print "$contents\n"; print "Error, no composites fetched\n"; sleep(10); } else { my @composites=split(/\s/, $contents); foreach my $composite (@composites) { print "Factoring ".length($composite)." digits: $composite\n"; my @results; open(YAFU, "./yafu \"factor($composite)\" -threads 8|") or die "Couldn't start yafu!"; while (<YAFU>) { print "$_"; chomp; if (/^[CP].*? = (\d+)/) { push( @results, $1 ); print "*****\n"; } } close(YAFU); if ( scalar(@results) > 0 ) { print "===========================================================================\n"; print "report factors\n"; my $url="http://factordb.com/report.php?report=".$composite."%3D".join('*',@results); #print "$url\n"; $contents=get($url); #print "$contents\n"; my $nofactors = ($contents =~ s/Does not divide//g); my $already_known = ($contents =~ s/Factor already known//g); my $added = ($contents =~ s/Factor added//g); my $small = ($contents =~ s/Small factor//g); $total{'nofactors'} += $nofactors; $total{'already_known'} += $already_known; $total{'added'} += $added; $total{'small'} += $small; print "\tNew factors added: " . ($added ? $added : 0) . " / $total{'added'}\n"; print "\tFactors already known: " . ($already_known ? $already_known : 0) . " / $total{'already_known'}\n"; print "\tSmall factors: " . ($small ? $small : 0) . " / $total{'small'}\n"; print "\tErrors (does not divide): " . ($nofactors ? $nofactors : 0) . " / $total{'nofactors'}\n"; print "===========================================================================\n"; }else { print "Error, no result found\n"; sleep(60); } } } } die;
ali.pl
Is a helper tool which drives Aliquot Sequences in factordb.
USAGE: ali.pl <sequence> <max composite length> <threads>
It fetches the last index for the given <sequence> and checks if there is a composite left. If the composite has more than <max composite length> digits it continues with the next sequence. Otherwise it runs yafu for this composites and reports the given factors into the factordb. Afterwards it again fetches the last index for this sequence and continues. Yafu is started with parallel <threads>.
preconditions
You need:
- Perl
- the yafu binary
- optional: gnfs binaries, which is faster for composites with more than 95 digits than the build in siqs method and which can use multiple cores.
- optional: gmp-ecm binary which can than use multiple cores
links
- sequence state: https://www.rechenkraft.net/aliquot/AllSeq.html
- list of open sequences [1]
source
#!/usr/bin/perl -w use warnings; use strict; use LWP::Simple; use LWP::UserAgent; sub usage() { print "$0 <sequence> <max composite length> <threads>\n"; } if ($#ARGV != 2) { usage; exit } my $seq=shift; my $maxlength=shift; my $yafuthreads=shift; my $user="YOURuser"; my $password="YOURpw"; # login to factordb my $ua = LWP::UserAgent->new(); $ua->cookie_jar( {} ); my $response = $ua->post("http://factordb.com/login.php", { 'user' => $user, 'pass' => $password, 'dlogin' => "Login" } ); while(1){ print "get last sequence id for sequence $seq\n"; $response = $ua->get("http://factordb.com/sequences.php?se=1&eff=2&aq=$seq&action=last&fr=0&to=100"); my $contents = $response->decoded_content(); my $found = ($contents =~ s/.*Unchecked//ms); if ($found < 1) {print "no unchecked number found\n"; $seq++; die;}; # no unchecked number # remove the end $contents =~ s/<\/table>.*//ms; my @content = split(/\n/, $contents); # get id my $id = $content[1]; $id =~ s/.*>(\d+)<.*/$1/; # get length my $len = $content[2]; $len =~ s/^[^>]*>(\d*).*/$1/; print "Sequence: $seq ID: $id Digits: $len\n"; # get composite id my $index = $content[3]; $index =~ s/.*index.php\?id=(\d*).*/$1/; print "get composite, index $index\n"; $response = $ua->get("http://factordb.com/index.php?showid=$index"); my $composite = $response->decoded_content(); if (!defined($composite)) {die "could not fetch composite\n";}; $composite =~ s/.*Number<\/td>(.*?)<\/td>.*/$1/ms; $composite =~ s/<br>//gms; $composite =~ s/\x0a//gms; $composite =~ s/\x0d//gms; $composite =~ s/<.*>//gms; print "C".length($composite)." $composite\n"; if (length($composite) > $maxlength) {print "composite has more than $maxlength digits\n"; $seq++; next;}; # factor it my @results; open(YAFU, "./yafu \"factor($composite)\" -threads $yafuthreads|") or die "Couldn't start yafu!"; while (<YAFU>) { print "$_"; chomp; if (/^[CP].*? = (\d+)/) { push( @results, $1 ); print "*****\n"; } } close(YAFU); if ( scalar(@results) > 0 ) { # login again $response = $ua->post("http://factordb.com/login.php", { 'user' => $user, 'pass' => $password, 'dlogin' => "Login" } ); print "===========================================================================\n"; print "report factors\n"; my $url="http://factordb.com/report.php?report=".$composite."%3D".join('*',@results); #print "$url\n"; $response = $ua->get($url); $contents = $response->decoded_content(); #print "$contents\n"; my $nofactors = ($contents =~ s/Does not divide//g); my $already_known = ($contents =~ s/Factor already known//g); my $added = ($contents =~ s/Factor added//g); my $small = ($contents =~ s/Small factor//g); print "\tNew factors added: " . ($added ? $added : 0) . "\n"; print "\tFactors already known: " . ($already_known ? $already_known : 0) . "\n"; print "\tSmall factors: " . ($small ? $small : 0) . "\n"; print "\tErrors (does not divide): " . ($nofactors ? $nofactors : 0) . "\n"; print "===========================================================================\n"; }else { print "Error, no result found\n"; $seq++; sleep(2); } }
helper tools
tool | download |
---|---|
Perl | Windows |
yafu | Windows, Linux |
gmp-ecm | Windows |