I wasnt able to find any topic on this despite multiple searches. Apologies if this was already covered here.
Can anyone point me in the right direction for further research on the below topic:
I have played recently with the Fibonacci sequence and prime numbers. I have noticed that, at least for certain initial items in that sequence, if you mark all of the primes in the sequence (I did it for numbers: 2(odd prime),3,5,13,89,233,1597,28657) and check their place in the sequence, it also turns out to be a prime. I'm asssuming that 0 is the 0th item. To give some examples: for 2(odd prime) - which is the 3rd number of the sequence - 3 is also a prime, for 13 being 7th number of the sequence - 7 is also prime, for 233 - being 17th number of the sequence - 17 is also a prime. This seems to be true for all primes up to 17 item in the sequence, it then starts to diverge as 19th (19 being a prime) number of the sequence is 4181 which is not a prime.
To give a visual example:
item number Fib number
0 0
1 1
2 1
prime 3 2 prime !
not prm 4 3 prime
prime 5 5 prime !
6 8
prime 7 13 prime !
8 21
9 34
10 55
prime 11 89 prime !
12 144
prime 13 233 prime !
14 377
15 610
16 987
prime 17 1597 prime !
18 2584
prime 19 4181 not prime
20 6765
21 10946
22 17711
prime 23 28657 prime !
24 46368
25 75025
26 121393
27 196418
28 317811
prime 29 514229 prime !
30 832040
prime 31 1346269 not prime
32 2178309
33 3524578
34 5702887
35 9227465
36 14930352
prime 37 24157817 not prime
38 39088169
39 63245986
40 102334155
41 165580141
Despite there being certain numbers in the sequence which are primes but their sequence order number not being a prime and vice versa, it's still quite interesting to know why is there such a pattern and if it's true for majority of Fibonacci sequence numbers.
Again, apologies if this is something obvious.
TIA for any clarification on this!
You might want to look at A001605 and follow the links from there. The Online Encyclopedia of Integer Sequences is a fantastic resource for things like this.
I also discuss fibonacci primes at my blog.
You seem to be mixing two different thoughts here:
If I index the Fibonacci series with a prime, will I find a prime
there?
If I find a prime in the Fibonacci series, will its index be a
prime?
According to the Fibonacci Prime article in Wikipedia:
Except for the case n = 4, all Fibonacci primes have a prime index,
..., but not every prime is the index of a Fibonacci prime.
Which means 1 above doesn't hold, as you demonstrated with prime index 19, but 2 above always holds except for Fibonacci prime 3 whose Fibonacci index is 4.
To bring this back to programming, my Python code to reproduce your table (sorta):
def is_prime(n):
if n > 1 and n % 2 != 0 or n == 2:
for i in range(3, int(n ** 0.5) + 1, 2):
if n % i == 0:
break
else:
return n
return '*' * len(str(n))
print('n', 'f', sep='\t')
f, p, n = 0, 1, 0
while True:
print(is_prime(n), is_prime(f), sep='\t')
f, p, n = f + p, f, n + 1
OUTPUT
n f
* *
* *
2 *
3 2
* 3
5 5
* *
7 13
* **
* **
** **
11 89
** ***
13 233
** ***
** ***
** ***
17 1597
** ****
19 ****
** ****
** *****
** *****
23 28657
** *****
** *****
** ******
** ******
** ******
29 514229
** ******
31 *******
** *******
** *******
** *******
** *******
** ********
37 ********
** ********
** ********
** *********
41 *********
** *********
43 433494437
** *********
** **********
** **********
47 2971215073
** **********
** **********
** ***********
** ***********
** ***********
53 ***********
** ***********
** ************
** ************
** ************
** ************
59 ************
** *************
61 *************
** *************
** *************
** **************
** **************
** **************
67 **************
** **************
** ***************
** ***************
71 ***************
** ***************
73 ***************
** ****************
** ****************
** ****************
** ****************
** ****************
79 *****************
** *****************
** *****************
** *****************
83 99194853094755497
** ******************
** ******************
** ******************
** ******************
** *******************
89 *******************
** *******************
** *******************
** *******************
** ********************
Related
I'm solving a MILP problem with CPLEX called from Julia JuMP package.
In CPLEX log the number of solutions is displayed to be more than 3000, but there is the parameter CPXPARAM_MIP_Limits_Solutions set to 55, so the solver should return when the number of solution is more than 55.
The explosion of the number of solution causes an out of memory error, therefore the Linux kernel kills the process.
This is the log:
CPXPARAM_Emphasis_Memory 1
CPXPARAM_Emphasis_MIP 2
CPXPARAM_MIP_Limits_Solutions 55
CPXPARAM_TimeLimit 60
Warning: Non-integral bounds for integer variables rounded.
2 of 3 MIP starts provided solutions.
MIP start 'm1' defined initial solution with objective 0.0000.
Warning: Non-integral bounds for integer variables rounded.
Tried aggregator 2 times.
MIP Presolve eliminated 12094 rows and 182224 columns.
MIP Presolve added 26 rows and 0 columns.
MIP Presolve modified 17428 coefficients.
Aggregator did 1 substitutions.
Reduced MIP has 5863 rows, 4313 columns, and 28322 nonzeros.
Reduced MIP has 4132 binaries, 175 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.35 sec. (311.81 ticks)
Probing fixed 3059 vars, tightened 200 bounds.
Probing changed sense of 57 constraints.
Probing time = 0.45 sec. (324.14 ticks)
Cover probing fixed 0 vars, tightened 286 bounds.
Tried aggregator 2 times.
MIP Presolve eliminated 4435 rows and 3257 columns.
MIP Presolve modified 923 coefficients.
Aggregator did 2 substitutions.
Reduced MIP has 1426 rows, 1054 columns, and 7403 nonzeros.
Reduced MIP has 929 binaries, 122 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.02 sec. (19.58 ticks)
Probing time = 0.03 sec. (18.90 ticks)
Tried aggregator 1 time.
MIP Presolve eliminated 5 rows and 3 columns.
MIP Presolve modified 1 coefficients.
Reduced MIP has 1421 rows, 1051 columns, and 7378 nonzeros.
Reduced MIP has 927 binaries, 121 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.01 sec. (7.48 ticks)
Probing time = 0.08 sec. (52.47 ticks)
Clique table members: 6451.
MIP emphasis: optimality.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 32 threads.
Root relaxation solution time = 0.02 sec. (14.70 ticks)
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
* 0+ 0 0.0000 -106269.5431 ---
0 0 -463.9717 61 0.0000 -463.9717 480 ---
0 0 -454.9015 109 0.0000 Cuts: 86 537 ---
0 0 -434.5372 112 0.0000 Cuts: 87 592 ---
0 0 -426.6747 113 0.0000 Cuts: 97 622 ---
0 0 -418.6204 136 0.0000 Cuts: 62 660 ---
0 0 -413.7867 132 0.0000 Cuts: 55 698 ---
0 0 -409.6387 140 0.0000 Cuts: 16 721 ---
0 0 -407.9923 135 0.0000 Cuts: 39 739 ---
0 0 -407.0012 148 0.0000 Cuts: 34 760 ---
0 0 -406.3034 149 0.0000 Cuts: 11 775 ---
0 0 -405.7757 134 0.0000 Cuts: 17 784 ---
0 0 -405.4831 148 0.0000 Cuts: 59 804 ---
0 2 -405.4831 145 0.0000 -118.6877 804 ---
Elapsed time = 2.12 sec. (1148.70 ticks, tree = 0.02 MB, solutions = 2)
* 282 17 integral 0 0.0000 -118.6877 3889 ---
6415 1365 -0.0974 1 0.0000 -0.1947 20809 ---
11118 1933 -348.8038 138 0.0000 -0.1947 37285 ---
* 11185 11 integral 0 0.0000 -0.1947 37522 ---
* 11206 16 integral 0 -0.0000 -0.1947 37594 ---
12049 384 -0.0974 1 -0.0000 -0.1947 39994 ---
13976 1504 -0.0974 1 -0.0000 -0.1947 44560 ---
15081 1894 -0.0974 1 -0.0000 -0.1947 47408 ---
16098 2205 -0.0000 0 -0.0000 -0.1947 49781 ---
17468 2844 -0.0974 1 -0.0000 -0.1947 52969 ---
18578 3322 -0.0000 0 -0.0000 -0.1947 56013 ---
19990 1939 -0.0000 0 -0.0000 -0.1947 61970 ---
Elapsed time = 14.88 sec. (4728.96 ticks, tree = 2.14 MB, solutions = 3127)
21354 555 cutoff -0.0000 -0.1947 67537 ---
26500 824 -0.0974 1 -0.0000 -0.1431 79682 ---
Killed
Version:
CPLEX 12.9.0
Julia 1.2.0
JuMP 0.20.1
Edit:
CPXPARAM_MIP_Limits_Solutions parameter controls the maximum number of incumbent solution to be found before stopping the optimization. However this number is not enough to control the number of solutions that the solver keeps in memory, because there may be the case when there are multiple solutions that are equivalent in terms of their value of the objective function, and in this case they just count for one solution for CPXPARAM_MIP_Limits_Solutions purpose. Therefore, to avoid memory consumption caused by solutions stored by the solver the right parameter is CPXPARAM_MIP_Pool_Capacity (that controls the number of solutions explored by the solver) that I set to 0 (because I was not interested in getting back all the solutions explored by CPLEX, but just the best one).
After this configuration the program terminated its run without being killed by the kernel.
The number of solutions is very likely not the reason for the out-of-memory error. It's the size of the branch-and-bound tree and the number of nodes that need to be stored and processed. You should try limiting the number of threads that are used to reduce the memory footprint.
Furthermore, there aren't that many proper solutions found. For every new incumbent you see a marker (* or H) at the beginning of the respective line, e.g.,
* 282 17 integral 0 0.0000 -118.6877 3889 ---
6415 1365 -0.0974 1 0.0000 -0.1947 20809 ---
11118 1933 -348.8038 138 0.0000 -0.1947 37285 ---
* 11185 11 integral 0 0.0000 -0.1947 37522 ---
* 11206 16 integral 0 -0.0000 -0.1947 37594 ---
12049 384 -0.0974 1 -0.0000 -0.1947 39994 ---
I don't know what the number of solutions reported in the log refers to. Probably these are additional solutions that do not improve the objective.
Please note the description of the parameter CPXPARAM_MIP_Limits_Solutions in the CPLEX docu:
Sets the number of MIP solutions to be found before stopping.
This integer solution limit does not apply to the populate procedure, which generates solutions to store in the solution pool. For a limit on the number of solutions generated by populate, see the populate limit parameter: maximum number of solutions generated for solution pool by populate.
You may want to check the CPXPARAM_MIP_Limits_Populate parameter as well.
just looking for an easy way to run trig functions in SAS without having to manually correct in each calculation. Below is what I am working with.
I am running this in SAS 9 probably, the SAS Studio Student Module but this is a general SAS question.
I have manually created a variable, 'rad' in the 'calc' data step to deal with this but it adds a step of complexity that I would like to avoid.
I am asking whether there is a system setting, alternate trig function or ... ? that would change the calculation from:
bh_x = cos(rad*bh_a)*bh_l ;
to:
bh_x = cos(bh_a)*bh_l ;
so I don't have to manually convert my angle in degrees to radians for the trig function to work.
Thanks to anyone reading this and putting any mental effort to the solution!
Tim
data spec ;
length
b2h_a 8
b2h_l 8
b2h_l_e 8
bike $ 8
name $ 16
;
input
bike $
name $
bh_a
bh_l
ht_a
spcr
st_h
st_a
st_l
hb_r
hb_a
;
datalines ;
srcn (0,0) 0 0 67 0 0 0 0 0 0
srcn c 41 658 71.5 27 40 25 120 100 13
srcn ne_27_n13 41 658 71.5 27 40 27 127 100 13
srcn ne_15_0 41 658 71.5 15 40 27 127 100 0
srcn ne_5_0 41 658 71.5 5 40 27 127 100 0
srcn ne_2_n9 41 658 71.5 2 40 27 127 100 9
srcn ne_5_10 41 658 71.5 5 40 27 127 100 -10
srcn ne_10_rf10 41 658 71.5 10 40 27 127 20 -10
srcn max 41 658 90 250 0 0 250 0 0
;
run ;
data calc ;
set spec ;
pi=constant('pi') ;
rad=pi/180 ;
bh_x = cos(rad*bh_a)*bh_l ;
bh_y = sin(rad*bh_a)*bh_l ;
sr_x = (cos(rad*ht_a)*(spcr+st_h/2))*-1 ;
sr_y = sin(rad*ht_a)*(spcr+st_h/2);
st_x = cos(rad*(90-ht_a+st_a))*st_l ;
st_y = sin(rad*(90-ht_a+st_a))*st_l ;
hb_x = cos(rad*(90-hb_a))*hb_r*-1 ;
hb_y = sin(rad*(90-hb_a))*hb_r ;
hd_x = bh_x + sr_x + st_x + hb_x ;
hd_y = bh_y + sr_y + st_y + hb_y ;
if hd_x=0 then do ;
b2h_a=0 ;
b2h_l=0 ;
end ;
else do ;
b2h_a = atan(hd_y/hd_x)/rad ;
b2h_l = hd_y/sin(b2h_a*rad) ;
end ;
b2h_l_e = b2h_l/25.4 ;
drop pi rad ;
format
b2h_a 5.
b2h_l 5.
b2h_l_e 5.
bh_a 5.
bh_l 5.
ht_a 5.
spcr 5.
st_h 5.
st_a 5.
st_l 5.
hb_r 5.
hb_a 5.
bh_x 5.
bh_y 5.
sr_x 5.
sr_y 5.
st_x 5.
st_y 5.
hb_x 5.
hb_y 5.
hd_x 5.
hd_y 5.
b2h_a 5.
b2h_l 5.
b2h_l_e 5.1
;
run ;
There are no trig functions in SAS that accept DEGREE or GRADIAN arguments. You always need to convert from your data's angular measurement system to RADIAN.
You can write a macro to perform the conversion. Example:
%macro cosD(theta);
%* theta is angle in degrees;
%* emit data step source code that performs conversion from degrees to radians;
cos(&theta*constant('PI')/180)
%mend;
In use:
data calc ;
set spec ;
bh_x = %cosD(bh_a) * bh_l ;
You could convert the angular data to radians during the step where input occurs and then not have to worry about it again.
The following code ( specifically as.matrix ) fails only when opening very large libsvm files. It works fine on smaller files
rawmforCluster=read.matrix.csr(filePath)
sparseforCluster=rawmforCluster$x
str(sparseforCluster)
sparseMatrixforCluster=as.matrix(sparseforCluster)
The structure of sparseforCluster is
Formal class 'matrix.csr' [package "SparseM"] with 4 slots
..# ra : num [1:4860285] 1 1 2 1 1 1 1 1 1 1 ...
..# ja : int [1:4860285] 77 668 716 1086 1202 1306 1527 2184 2545 2729 ...
..# ia : int [1:659095] 1 18 25 26 31 36 52 59 67 72 ...
..# dimension: int [1:2] 659094 3778
The error I get is
Error in double(nrow * ncol) : vector size cannot be NA In addition:
Warning message: In nrow * ncol : NAs produced by integer overflow
Question
How do I coerce the data into a matrix or (second best) a data.table?
(or should I be seeking another solution?)
Update
I have found that the standard solution is to reduce the size of the matrix by removing sparse (low frequency) terms. This is not an option in my case as some low frequency terms may be highly relevant to some subsets.
I have also read about the bigmemory package. However, this does not seem to work with matrix.csr
I have two mathematical formulae that needed to be created as R functions and then run them on my data.
First of all let me show you the head of my data, which I named it "data_1"
sex age seca1 chad1 DL alog1 dig1 scifirst1 crimetech1
1 F 20 1754 1750 175 95 95 432 429
2 F 19 1594 1596 158 56 55 420 417
3 F 20 1556 1558 156 74 72 435 437
4 F 18 1648 1640 167 67 65 431 434
5 F 19 1780 1780 178 99 67 433 431
6 F 19 1610 1620 165 56 54 423 425
Now lets look at the formulae and my attempts to create the functions on r :
1)The 1st formula (f1):
The first formula (can be accessed through this link):
This is what I did to create the first formula:
f1 <- function(x, y) {sqrt(sum((x - y) ^ 2) / 2 / length(x))}
As I need to run f1 on data_1$alog1 vs data_1$dig1... here's what I did:
f1(data_1$alog1, data_1$dig1)
which gives: 4.3
Now the question is: have I created the function correctly? and is it supposed to be giving me only one value?
2)The 2nd formula (f2):
The second function is to create a mathematical formula in which the first function is substituted. Here is the formula --> (follow this link):
"f1" that appears in red in the second formula, is supposed to be the first function created (1st formula).
Next, here is what I did to implement the 2nd formula:
f2 <- function(x, y){(f1 / ((x + y) / 2)) * 100}
but then, when I run it on data_1$alog1 vs data_1$dig1 to calculate the coefficient of variation of the error for these data, I get:
> f2(data_1$alog1, data_1$dig1)
Error in f1/((x + y)/2) : non-numeric argument to binary operator
Could anyone please comment on the steps performed to create the functions and the way I run the functions on "alog1 vs dig1"?
If x is a vector, then sum(x) is a scalar. To get cumulative sums, use cumsum(x):
f1 <- function(x, y) {sqrt(cumsum((x - y) ^ 2) / 2 / length(x))}
f1(data_1$alog1, data_1$dig1)
which returns
[1] 0.0000000 0.2886751 0.6454972 0.8660254 9.2781104 9.2960565
instead of simply returning the last value.
In the second function definition, you are forgetting that f1 is a function of (x, y):
f2 <- function(x, y) {f1(x, y) / ((x + y) / 2) * 100}
f2(data_1$alog1, data_1$dig1)
[1] 0.0000000 0.5201354 0.8842428 1.3121597 11.1784463 16.9019209
I am solving an example problem, RSA algorithm
I have been given two prime numbers 7 and 11. Let's say p=7 and q=11
I have to calculate the decryption key, d, for some encryption key, e.
Firstly I calculated n=p*q which implies that n=77.
Suppose that e=13,
to calculate d I used the formula d*e = 1 mod fi,
where fi=(p-1)(q-1), and so fi=60
The final equation becomes 13*d = 1 mod fi
According to some solved example
d is calculated to be 37, how is this result obtained?
Any help would be appreciated.
i think this is what you are looking for
Verifying the answer is easy, finding it in the first place, a little more work.
Verification:
13 * 37 = 481
481 = 8 * 60 + 1
Hence if you divide 13 * 37 by 60 you have remainder 1.
Alternate answers:
Any integer of the form (37 + 60 k) where k is any integer is also a solution. (97, -23, etc.)
To find the solution you can proceed as follows:
Solve:
13 d = 1 + 60 k
mod 13:
0 = 1 + 8k (mod 13)
8k = -1 (mod 13)
Add 13's until a multiple of 8 is found:
8k = 12 or 25 or 38 or 51 or 64 .... aha a multiple of 8!
k = 64 / 8 = 8
Substitute k = 8 back into 13 d = 1 + 60 k
13 d = 1 + 8 * 60 = 481
481 /13 = 37
and that is the answer.
Use the extended Euclidean algorithm to compute integers x and y such that
13*x+60*y=1
Then x is the answer you're looking for, mod 60.