mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Blogorrhea > EdH

Reply
 
Thread Tools
Old 2020-11-21, 17:12   #1
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

1101011101112 Posts
Default How I Create a Colab Session That Factors factordb Small Composites with PARI/GP

(Note: I expect to keep the first post of each of these "How I..." threads up-to-date with the latest version. Please read the rest of each thread to see what may have led to the current set of instructions.)

I will take the liberty of expecting readers to already be somewhat familiar with Google's Colaboratory sessions. There are several threads already on Colab and these should be reviewed by interested readers:

Google Colaboratory Notebook?
GPU72 Notebook Integration...
Notebook Instance Reverse SSH and HTTP Tunnels.
Colab question

I do not, as of yet, have a github account, so I have not created an upload of this to github. Others may feel free to do so, if desired.

The following is a manner to retrieve small composites from factordb.com and factor out small primes by TF using PARI/GP. This does not totally factor all composites that are encountered. Although it can be used with larger composites, it is not to be considered effective, unless those composites are comprised of many small primes.

When run, this session retrieves composites of a chosen size from factordb, factors out small primes and submits the factors back to the db.

To use Colab, you need a Gmail account and will be required to log into that account to run a session.

On to the specifics:

Open a Google Colaboratory session.
Sign in with your Google/Gmail account info.
Choose New Python3 notebook:
Code:
Menu->File->New Python3 notebook (or within popup)
Click Connect to start a session.
Edit title from Untitled... to whatever you like.
Paste the following into the Codeblock:
Code:
#########################################################
### This Colaboratory session is designed to retrieve ###
### small composites from factordb.com and factor them ##
### using PARI/GP.  The factors are then sent back to ###
### factordb.                                         ###
###                                                   ###
### To adjust the number of composites to retrieve as ###
### well as the size to retrive, change the variables ###
### totalrun and digitsize.   The size of the random  ###
### number to be used to help avoid collisions (1000) ###
### can also be changed, as well as the offset (10).  ###
#########################################################

!apt install pari-gp
!echo '#!/bin/bash/' >dbW.sh
!echo '' >>dbW.sh
!echo 'digitsize=20' >>dbW.sh
!echo 'totalrun=50' >>dbW.sh
!echo '' >>dbW.sh
!echo 'printf "\nFactoring $totalrun composites:\n\n"' >>dbW.sh
!echo 'for ((n=0;n<totalrun;n++))' >>dbW.sh
!echo '  do' >>dbW.sh
!echo '    startt=$SECONDS' >>dbW.sh
!echo '    randomnumber=$(echo $((10 + RANDOM % 1000)))' >>dbW.sh
!echo '    wget "http://factordb.com/listtype.php?t=3&mindig=${digitsize}&perpage=1&start=$randomnumber&download=1" -q -O dbTemp' >>dbW.sh
!echo '    exec <"dbTemp"' >>dbW.sh
!echo '      read composite in' >>dbW.sh
!echo '    if [[ $composite =~ ^[0-9]+$ ]]' >>dbW.sh
!echo '      then' >>dbW.sh
!echo '        ccount=0' >>dbW.sh
!echo '        echo "Composite $((${n}+1)) of $totalrun is $composite <${#composite}>"' >>dbW.sh
!echo '        temp=$(echo "factor($composite, 10^9)" | gp -f -q)' >>dbW.sh
!echo '        temp=$(echo "${temp//\n/}" | xargs)' >>dbW.sh
!echo '        temp=$(echo "${temp// 1]/}")' >>dbW.sh
!echo '        temp=$(echo "${temp//]/}")' >>dbW.sh
!echo '        temp=$(echo "${temp//[/*}")' >>dbW.sh
!echo '        temp=$(echo "${temp// /}")' >>dbW.sh
!echo '        printf "Factors are ${temp:1} <$((${SECONDS}-${startt}))s>\n\n"' >>dbW.sh
!echo '        returnfactors=${composite}%3D${temp:1}' >>dbW.sh
!echo '        wget "http://factordb.com/report.php?report=$returnfactors" -q -O dbSuccess' >>dbW.sh
!echo '      else' >>dbW.sh
!echo '        let ccount=${ccount}+1' >>dbW.sh
!echo '        printf "Non-number found (${composite})! Pausing briefly. . .\n\n"' >>dbW.sh
!echo '        if [ $ccount -gt 4 ]' >>dbW.sh
!echo '          then' >>dbW.sh
!echo '            sleep 590' >>dbW.sh
!echo '        fi' >>dbW.sh
!echo '        sleep 10' >>dbW.sh
!echo '    fi' >>dbW.sh
!echo '  done' >>dbW.sh
!echo 'echo "Total time for $n composites was $SECONDS seconds."' >>dbW.sh
!echo 'rm dbTemp' >>dbW.sh
!bash dbW.sh
Click on the Run cell icon or use CTRL-Enter.

The first time this is run, PARI/GP will be installed prior to writing the script to a file and running it. Subsequent runs within the same session check that PARI/GP is installed and then continue.

The current default is to process fifty, 20 digit composites and stop. The factors are sent to the db automatically, so no other manual intervention is needed. To change the number of composites to work on for each run, edit the totalrun variable. To change the size of the composites to work on edit the digitsize variable. Choosing a size doesn't guarantee work on that size. It is only the minimum size to retrieve. This script will work with the smallest size available starting with the digitsize value.

Eventually, I hope to add a more detailed description of all the code.

Last fiddled with by EdH on 2020-11-21 at 17:20
EdH is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Factoring small composites hansl FactorDB 54 2020-11-25 23:31
How I Create a Colab Session That Factors factordb Comps with the GPU branch of GMP-ECM and msieve EdH EdH 0 2019-12-07 19:51
How I Create a Colab Session That Factors factordb Composites with the GPU branch of GMP-ECM EdH EdH 0 2019-12-04 01:49
How I Create a Colab Session That Factors factordb Composites with YAFU EdH EdH 12 2019-11-11 17:44
Cunningham Table Composites in FactorDB Batalov Cunningham Tables 15 2011-07-30 03:43

All times are UTC. The time now is 19:05.

Thu Nov 26 19:05:51 UTC 2020 up 77 days, 16:16, 3 users, load averages: 1.34, 1.40, 1.46

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

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.