1

I am a farmer / novice number theory researcher. I happened to discover some years back a pattern that emerged in the distribution of the prime numbers that related the number of primes to the operation of 300 Fibonacci-like sequences. Well, as a person who has always used pen and paper I was at a loss when it came to converting my methods into computer code (so I hired a programmer to implement my code in Perl). That code worked but it was not the process that I now need; I wish to ask a community of programmers what they think is the best approach to making this (Python) code work. Also, as a researcher I am not overly concerned with people appropriating this code for their own uses - I would just like to see what you do with it!

The results generated by the Perl program were published in the AT&T Online Encyclopedia of Integer Sequences. https://oeis.org/search?q=helkenberg&language=english&go=Search

The program below is my recent effort but I cannot for the life of me figure out how to get certain parts of the code to work.

For instance (from the larger program below),

print"""THIS CODE WILL NOT COMPILE (example p*q = 29*73)
print [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90 #example 23
print [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90 #example 215

z(0) = [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90
z(1) = [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90
#This defines a new process, a Fibonacci-like sequence:

a = z(1) - z(0) #example (192=215-23)
g = 180 #think the unit circle, clock cycles

m_0 = a + g #example 192+180 = 372

z(2) = m_0 + z(1) #example 587 = 372 + 215

m_1 = m_0 + g #example 552 = 372 + 180

z(3) = z(2)+ m_1 #example 1139 = 587 + 552

m_2 = m_1 + g #example 732 = 552 + 180

z(4) = z(3) + m_2 #example 1871 = 1139 + 732

I am teaching myself how to code and I cannot for the life of me figure out how to implement this!!!

Lastly, I need to use those values (of the z term) to solve an equation of the form:

0 = r - [(((90*n))+29)*y) + z_n]
0 = r - [(((90*n))+73)*y) + z_n]

where the z term is used for both 29 and 73 (as an example)

Here is what I have so far.

print    "1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139"

variable = raw_input('copy and paste the above number')

#This valuable function reduces an arbitrarily large number to the SUM OF ITS DIGITS
new_variable = sum(map(int, str(variable)))
print new_variable

next_step = sum(map(int, str(new_variable)))
print next_step

new_step = sum(map(int, str(next_step)))

print "The digital root of our test number is", new_step, "A fine answer."

if int(new_step) > 9:
print "We cannot have a two digit digital root!Enter the sum of those two numbers here!"

newest_data = raw_input ('>enter the digital root here')

#newest_data = raw_input ()

if new_step == 3:
print "This number is divisible by 3."
if new_step == 6:
print "This number is divisible by 3."
if new_step == 9:
print "This number is divisible by 3 and 9."

if newest_data == 3:
print "This number is divisible by 3."
if newest_data == 6:
print "This number is divisible by 3."
if newest_data == 9:
print "This number is divisible by 3 and 9."

print "What is the last digit of our number?"
last_digit = raw_input("Last digit here")

print last_digit

if int(last_digit) == 0:
print "This number is divisible by 2 and 5."
if int(last_digit) == 2:
print "This number is divisible by 2."
if int(last_digit) == 4:
print "This number is divisible by 2."
if int(last_digit) == 6:
print "This number is divisible by 2."
if int(last_digit) == 8:
print "This number is divisible by 2."

digital_root = int(new_step)
new_digit = int(last_digit)

if digital_root == 1 and new_digit == 1:
print "your primitive is 91"

elif digital_root == 1 and new_digit == 3:
print "your primitive is 73"

elif digital_root == 1 and new_digit == 7:
print "your primitive is 37"

elif digital_root == 1 and new_digit == 9:
print "your primitive is 19"

elif digital_root == 2 and new_digit == 1:
print "your primitive is 11"

elif digital_root == 2 and new_digit == 3:
print "your primitive is 73"

elif digital_root == 2 and new_digit == 7:
print "your primitive is 47"

elif digital_root == 2 and new_digit == 9:
print "your primitive is 29"

elif digital_root == 4 and new_digit == 1:
print "your primitive is 31"

elif digital_root == 4 and new_digit == 3:
print "your primitive is 13"

elif digital_root == 4 and new_digit == 7:
print "your primitive is 67"

elif digital_root == 4 and new_digit == 9:
print "your primitive is 49"

elif digital_root == 5 and new_digit == 1:
print "your primitive is 41"

elif digital_root == 5 and new_digit == 3:
print "your primitive is 23"

elif digital_root == 5 and new_digit == 7:
print "your primitive is 77"

elif digital_root == 5 and new_digit == 9:
print "your primitive is 59"

elif digital_root == 7 and new_digit == 1:
print "your primitive is 61"

elif digital_root == 7 and new_digit == 3:
print "your primitive is 43"

elif digital_root == 7 and new_digit == 7:
print "your primitive is 7"

elif digital_root == 7 and new_digit == 9:
print "your primitive is 79"

elif digital_root == 8 and new_digit == 1:
print "your primitive is 71"

elif digital_root == 8 and new_digit == 3:
print "your primitive is 53"

elif digital_root == 8 and new_digit == 7:
print "your primitive is 17"

elif digital_root == 8 and new_digit == 9:
print "your primitive is 89"


primitive = raw_input("enter primitive here")
new_value = int(variable) - int(primitive)
stored_data = new_value/90

print "this is our new number, the position of our test number in a dr,ld index.", stored_data

print "This number above is our test number (r)."

tuple = [73,91,19,37,11,23,29,77,47,59,83,41,13,61,31,43,49,7, 67,79,17,89,53,71]

print tuple
print " the example is based on 29*73"
p = raw_input("p from tuple (to be defined)") # example 29
q = raw_input("q associated with p") #example 73

#def make_incrementor (n): return lambda x: x + n
#cannot figure this one out
#notice x_0 and then x_1:
print"""THIS CODE WILL NOT COMPILE (example p*q = 29*73)
print [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90 #example 23
print [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90 #example 215

z(0) = [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90
z(1) = [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90

#This defines a new process, a Fibonacci-like sequence:

a = z(1) - z(0) #example (192=215-23)
g = 180 #think the unit circle, clock cycles

m_0 = a + g #example 192+180 = 372

z(2) = m_0 + z(1) #example 587 = 372 + 215

m_1 = m_0 + g #example 552 = 372 + 180

z(3) = z(2)+ m_1 #example 1139 = 587 + 552

m_2 = m_1 + g #example 732 = 552 + 180

z(4) = z(3) + m_2 #example 1871 = 1139 + 732

"""

print "seed values for sequence z = [23, 215]"
print "set of z terms [23, 215, 587, 1139, 1871,.....] "


print "notice the last-digit pattern for the z term means that every term of z will end  in a [3, 5, 7, 9, 1], in that order, but also IN A POWER SERIES. Also notice that our test number (r) ends with the last digit 8. So prior to computing w, we know that none of the solutions represented by z (where z = r) are possible."

print """
there are 24 equations (posed as alternatives):

r = stored_data test number, RSA-100 clock position
print "RSA-100 = 19 +     (90*16917833643583704005951315312584860330200756832904229873976761050890255147321698862822226118800068)"
Startng at 19 degrees, RSA100 is 169..... 1/4 rotations from the 0 position on the clock face.

#special case: where r-z = 0, factor found.

0 = r - [(((90*n))+19)*y) + z_n]
0 = [(((r-z_n)/y)-19)]/x - 90]

0 = r - [(((90*n)+91)*y) + z_n]
0 = [(((r-z_n)/y)-91)]/n - 90]

0 = r - [(((90*n)+37)*y) + z_n]
0 = [(((n-z_n)/y)-37)]/n - 90]

0 = r - [(((90*n)+73)*y) + z_n]
0 = [(((r-z_n)/y)-73)]/n - 90]

0 = r - [(((90*n)+11)*y) + z_n]
0 = [(((r-z_n)/y)-11)]/n - 90]

0 = r - [(((90*n)+59)*y) + z_n]
0 = [(((r-z_n)/y)-59)]/n - 90]

0 = r - [(((90*n)+29)*y) + z_n]
0 = [(((r-z_n)/y)-29)]/x - 90]

0 = r - [(((90*n)+41)*y) + z_n]
0 = [(((r-z_n)/y)-41)]/n - 90]

0 = r - [(((90*n)+47)*y) + z_n]
0 = [(((r-z_n)/y)-47)]/n - 90]

0 = r - [(((90*n)+77)*y) + z_n]
0 = [(((r-z_n)/y)-77)]/n - 90]

0 = r - [(((90*n)+83)*y) + z_n]
0 = [(((r-z_n)/y)-83)]/n - 90]

0 = r - [(((90*n)+23)*y) + z_n]
0 = [(((r-z_n)/y)-83)]/n - 90]

0 = r - [(((90*n)+13)*y) + z_n]
0 = [(((r-z_n)/y)-13)]/n - 90]

0 = r - [(((90*n)+43)*y) + z_n]
0 = [(((r-z_n)/y)-43)]/n - 90]

0 = r - [(((90*n)+31)*y) + z_n]
0 = [(((r-z_n)/y)-31)]/n - 90]

0 = r - [(((90*n)+79)*y) + z_n]
0 = [(((r-z_n)/y)-79)]/n - 90]

0 = r - [(((90*n)+49)*y) + z_n]
0 = [(((r-z_n)/y)-49)]/n - 90]

0 = r - [(((90*n)+61)*y) + z_n]
0 = [(((r-z_n)/y)-61)]/n - 90]

0 = r - [(((90*n)+67)*y) + z_n
0 = [(((r-z_n)/y)-67)]/n - 90]

0 = r - [(((90*n)+7)*y) + z_n]
0 = [(((r-z_n)/y)-7)]/n - 90]

0 = r - [(((90*n)+17)*y) + z_n]
0 = [(((r-z_n)/y)-17)]/n - 90]

0 = r - [(((90*n)+53)*y) + z_n]
0 = [(((r-z_n)/y)-53)]/n - 90]

0 = r - [(((90*n)+71)*y) + z_n]
0 = [(((r-z_n)/y)-71)]/n - 90]

0 = r - [(((90*n)+89)*y) + z_n]
0 = [(((r-z_n)/y)-89)]/n - 90]
"""



#Here is the OLD PROGRAM in Perl

#!/usr/bin/perl

use strict;
use warnings;

use Math::BigInt;
use POSIX;
use Getopt::Long;

my $rsa              = '';
my $p                = '';
my $q                = '';
my $digit_root_chart = '';

GetOptions(
'rsa|r=s'   => \$rsa,
'p=s'       => \$p,
'q=s'       => \$q,
'digit|d=i' => \$digit_root_chart,
) or die "Problem with command";

# /*
#  * General algorithm goes here.
#  *
#  */

my $length_of_semiprime = length($rsa);
my $digit_root          = &digit_root($rsa);

print "digit root: $digit_root\n";

$rsa = Math::BigInt->new($rsa);
print "rsa: $rsa\n";
my $new_rsa = $rsa->copy();
$new_rsa -=
  $digit_root_chart;  # need to figure out a way to tablize the digit root table
$new_rsa /= 90;
print "new_rsa: $new_rsa\n";

$p = Math::BigInt->new($p);
$q = Math::BigInt->new($q);
my $y = &first_two_calcs( $p, $q );
print "p = $p, q = $q\n";
&check_for_factor( $p, $q, $y );

$p += 90;
$q += 90;
my $z = &first_two_calcs( $p, $q );
print "p = $p, q = $q\n";
&check_for_factor( $p, $q, $z );

$p += 90;
$q += 90;
print "p = $p, q = $q\n";
my @r = &second_calcs( $y, $z );
$y = $r[0];
$z = $r[1];
&check_for_factor( $p, $q, $z );

while (1) {
   $p += 90;
   $q += 90;

my @t = &third_calc( $y, $z );
$y = $t[0];
$z = $t[1];

if ( $z <= $new_rsa ) {
    &check_for_factor( $p, $q, $z )
      if ( ( length($p) || length($q) ) >=
        ( ( $length_of_semiprime / 2 ) - 1 ) );
}
else {
    last;
}
}

# This sub() is used for the first two calculations
sub first_two_calcs {
my ( $p, $q ) = @_;
my $z = $p * $q;
my $x = $z / 9;

# if its a whole number we move along
if ( ( $z % 9 ) == 0 ) {
    print "($p * $q) / 9 = $x\n";
}
else {
    print "num doesn't div evenly: ($p * $q) / 9 = $x\n";
    $x = int( $x / 10 );
    print "new num: (($p * $q) / 9) / 10 = $x\n";
}
return $x;
}

# /*
#  * This sub() checks to see if it is a factor.
#  *
#  */
sub check_for_factor {
my ( $p, $q, $z ) = @_;

print "Check_for_factor(p = $p, q = $q, z = $z)\n";

for ( $p, $q ) {
    my $temp = $new_rsa - $z;
    my $y    = ( $temp / $_ );

    if ( ( $temp % $_ ) == 0 ) {
        print "\n******* factor found: $_ for $rsa *******\n";
        exit(0);
    }
    elsif ( ( int( $y / 10 ) ) == $new_rsa ) {
        print "\n******* factor found: $_ for $rsa *******\n";
        exit(0);
    }
    else {
        print "factor NOT found: ($new_rsa - $z) / $_ = $y\n";
    }
}
}

# This sub() is used for the rest of the calculations
sub second_calcs {
my ( $y, $z ) = @_;
my $j = $z - $y;
my $k = $j + 180;
my $l = $z + $k;

print "$z - $y = |$j|\n";
print "$j + 180 = $k\n";
print "$k + $z = $l\n";

return ( $k, $l );
}

sub third_calc {
my ( $y, $z ) = @_;

my $k = $y + 180;
my $l = $z + $k;

return ( $k, $l );
}

# /*
#  * This sub() calcs the digit root:
#  * example: $rsa = 12345
#  * 1 + 2 + 3 + 4 + 5 = 15 and 1 + 5 = 6 (digit root)
#  */
sub digit_root {
my $rsa = shift;

$rsa = Math::BigInt->new($rsa);

return ( 1 + ( ( $rsa - 1 ) % 9 ) );
}
Mat
  • 202,337
  • 40
  • 393
  • 406
  • `raw_input('copy and paste the above number')` -- wtf? – Fred Foo Feb 19 '12 at 14:48
  • @J. W. Helkenburg: I'm willing to help you with an implementation, if you can give me a clear description of the sequence. Trying to interpret your code, or anything named Perl is a waste of my time :) I can be found on #pygrafix at irc.freenode.org. – orlp Feb 19 '12 at 14:51
  • You hired a programmer to write THAT mess? – Joel Cornett Feb 19 '12 at 15:32
  • I allow people to copy and paste the "above number" as an example. You can enter any number you wish, but RSA-100 is my test number (since the factors are already known). – J. W. Helkenberg Feb 19 '12 at 15:34
  • Yeah, and it (the Perl program) is a mess isn't it! Lame - I would never have selected Perl if I had any foreknowledge of languages. It just happened by accident. – J. W. Helkenberg Feb 19 '12 at 15:37
  • x_0 and x_1 are not defined before the execution of the "This code will not compile" block. – Joel Cornett Feb 19 '12 at 15:43
  • Are x_0 and x_1 meant to be exogenous variables? – Joel Cornett Feb 19 '12 at 15:44
  • @ Joel Cornett: x_0 is the first step of a integer sequence, x_1 is the second step. But in the 24 equations, I need the step value to correspond to the z term. 0 = r - [(((90*n)+11)*y) + z_n] 0 = [(((r-z_n)/y)-11)]/n - 90] So x_0 = the value of z at the zeroth step. I need to solve for y (since x and z are known). I hope that makes sense. – J. W. Helkenberg Feb 19 '12 at 15:52
  • @ Joel Cornett: The value of x is simply the value of the step (not an outside value). So x=0 when z is in the first value, x=1 when z is at the second value, etc. I need to solve for y such that r - (equation) = 0. – J. W. Helkenberg Feb 19 '12 at 15:56
  • @J.W.Helkenberg: we can move this discussion to a more appropriate forum. If you want, you can google chat me at joel.cornett@gmail.com. – Joel Cornett Feb 19 '12 at 16:12

1 Answers1

0

I think the main issue with your code (the part that you label "THIS CODE WILL NOT COMPILE") is that you're using [square brackets] where you should be using parentheses. In python, unlike in mathematics, the square brackets denote a very specific data type called a list. You should replace your square brackets with regular parentheses.

print ((int(p) + 90*x_0) * int(q)+ 90*x_0))/90 #example 23 
print ((int(p) + 90*x_1) * (int(q)+90*x_1))/90 #example 215  
z(0) = ((int(p) + 90*x_0) * int(q)+ 90*x_0))/90 
z(1) = ((int(p) + 90*x_1) * (int(q)+90*x_1))/90 

Also, z(n) is going to give you problems. I'm not quite sure what z(0) is supposed to be programmatically. Unless z is a function however, you would probably want z to be a list of n elements. In which case you would access those elements with z[1], z[2], ... z[n].

That's probably not everything wrong, but it's a start. I recommend reading the python tutorial at python.org, and also looking at examples of python code to improve your understanding.

Joel Cornett
  • 24,192
  • 9
  • 66
  • 88
  • The code will not compile because it is pseudo-code and not Python. Here is something another user suggested. p = 29 q = 73 g = 180 # prevent re-calculation of previous terms by memoization z_results = { 0: int(((p + 90.0 * 0) * (q + 90.0 * 0)) / 90.0), 1: int(((p + 90.0 * 1) * (q + 90.0 * 1)) / 90.0), } def z(x): if x in z_results: return z_results[x] result = g + 2*z(x - 1) - z(x - 2) z_results[x] = result return result for i in range(20): print("%d: %d" % (i, z(i))) – J. W. Helkenberg Feb 20 '12 at 15:17