The primes of Fibonacci sequence: behavior and visualization​
​by Daniel Carvalho
I was a little bored, and suddenly this idea to check how the primes in the Fibonacci sequence behave...
Lets check this out!
First check a definition about it with Wikipedia data
WikipediaData["Fibonacci prime"]//StringTake[#,205]&
Out[]=
A Fibonacci prime is a Fibonacci number that is prime, a type of integer sequence prime.The first Fibonacci primes are (sequence A005478 in the OEIS):​2, 3, 5, 13, 89, 233, 1597, 28657, 514229, 433494437
WordCloud[DeleteStopwords[WikipediaData["Fibonacci prime"]]]
Out[]=
WordCloud[DeleteStopwords[WikipediaData["Fibonacci"]]]
Out[]=
WordCloud[DeleteStopwords[WikipediaData["Prime number"]]]
Out[]=
​
First take a look at the 1,000 Fibonacci that are prime, highlighting them in red in a simple list...
well the Fibonacci numbers quicky grows as crazy...
try it yourself without the Take function at postfix to see all the values...
If[PrimeQ[#],Style[#,Red,Bold],#]&/@Table[Fibonacci[s],{s,0,1000}]//Take[#,100]&
Out[]=
{0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170,1836311903,2971215073,4807526976,7778742049,12586269025,20365011074,32951280099,53316291173,86267571272,139583862445,225851433717,365435296162,591286729879,956722026041,1548008755920,2504730781961,4052739537881,6557470319842,10610209857723,17167680177565,27777890035288,44945570212853,72723460248141,117669030460994,190392490709135,308061521170129,498454011879264,806515533049393,1304969544928657,2111485077978050,3416454622906707,5527939700884757,8944394323791464,14472334024676221,23416728348467685,37889062373143906,61305790721611591,99194853094755497,160500643816367088,259695496911122585,420196140727489673,679891637638612258,1100087778366101931,1779979416004714189,2880067194370816120,4660046610375530309,7540113804746346429,12200160415121876738,19740274219868223167,31940434634990099905,51680708854858323072,83621143489848422977,135301852344706746049,218922995834555169026}
Lets select just the Fibonacci primes and view it in a bar chart...
It is better to use log in order to view all the numbers graphically...
Select[Table[Fibonacci[s],{s,0,1000}],PrimeQ]​​BarChart[%,ColorFunctionHue,PlotLabel"Prime fibonacci"]​​BarChart[Log[%%],ColorFunctionHue,PlotLabel"Prime fibonacci (log)"]
Out[]=
{2,3,5,13,89,233,1597,28657,514229,433494437,2971215073,99194853094755497,1066340417491710595814572169,19134702400093278081449423917,475420437734698220747368027166749382927701417016557193662268716376935476241,529892711006095621792039556787784670197112759029534506620905162834769955134424689676262369,1387277127804783827114186103186246392258450358171783690079918032136025225954602593712568353,3061719992484545030554313848083717208111285432353738497131674799321571238149015933442805665949,10597999265301490732599643671505003412515860435409421932560009680142974347195483140293254396195769876129909,36684474316080978061473613646275630451100586901195229815270242868417768061193560857904335017879540515228143777781065869,96041200618922553823942883360924865026104917411877067816822264789029014378308478864192589084185254331637646183008074629}
Out[]=
Out[]=
Lets go deep and spy primes in the 10,000 first Fibonacci values
BarChart[​​Log[Select[Table[Fibonacci[s],{s,0,10000}],PrimeQ]]​​,ColorFunctionHue,PlotLabel"Prime fibonacci (log)"]
Out[]=
Lets check the distance between those prime Fibonacci numbers with a new function
In[]:=
distance[v_List]:=#〚2〛-#〚1〛&/@Partition[Riffle[Most[v],Rest[v]],2]
Testing the function, it sums consecutive values in the given list
Append[Range[10],20]​​distance[%]
Out[]=
{1,2,3,4,5,6,7,8,9,10,20}
Out[]=
{1,1,1,1,1,1,1,1,1,10}
To view something interesting we need to Log it, facing the values grows fast!
ListPlot[Log[distance[Select[Table[Fibonacci[s],{s,0,1000}],PrimeQ]]],FillingAxis]
Out[]=
ListPlot[Log[distance[Select[Table[Fibonacci[s],{s,0,10000}],PrimeQ]]],FillingAxis]
Out[]=
Lets save the primes in the 10k first Fibonacci numbers in a variable and in a file, because it takes time to be calculated...
In[]:=
fibprime=Select[Table[Fibonacci[s],{s,0,10000}],PrimeQ];
Export["fibprime.tsv",fibprime]
Out[]=
fibprime.tsv
We can save it on Wolfram Cloud too, it is more fashion! Local files are old school!!
CloudPut[fibprime,"fibprime"]
Out[]=
CloudObject[
https://www.wolframcloud.com/obj/dcarvalho/fibprime
]
We can use CloudGet to get the data back latter
In[]:=
fibprime=CloudGet["fibprime"];
distance[Table[Fibonacci[n],{n,0,100,1}]]
Out[]=
{1,0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170,1836311903,2971215073,4807526976,7778742049,12586269025,20365011074,32951280099,53316291173,86267571272,139583862445,225851433717,365435296162,591286729879,956722026041,1548008755920,2504730781961,4052739537881,6557470319842,10610209857723,17167680177565,27777890035288,44945570212853,72723460248141,117669030460994,190392490709135,308061521170129,498454011879264,806515533049393,1304969544928657,2111485077978050,3416454622906707,5527939700884757,8944394323791464,14472334024676221,23416728348467685,37889062373143906,61305790721611591,99194853094755497,160500643816367088,259695496911122585,420196140727489673,679891637638612258,1100087778366101931,1779979416004714189,2880067194370816120,4660046610375530309,7540113804746346429,12200160415121876738,19740274219868223167,31940434634990099905,51680708854858323072,83621143489848422977,135301852344706746049}
Check how many primes we have at the first 10k Fibonacci numbers
Length[fibprime]
Out[]=
26
View the last and biggest one
Last[fibprime]
Out[]=
1056597787330886165607283376335772947912004036112564579874375352759594439245750115025661751635771858498604063538249919150521910143408974582829038241321765899686974372065892543538158617334073268472725275364083905833609186070912661512269116100758775431451837305406774829615930445817607326150685658795315867111693264823732004839656664575237111288179099232440466298431582104527085532877031549603964884101691956585163355851591142327980744624330187879064855304798755771686797051547007947771882372952667893427143690224381067780291488291525844107323034231967453469607389798265139480514915570754010362634536063309050925069684058402883158793747384557423242752292859137029927002634958591300831686286270148295738141642265185159474092374071727835227879093337721218970960045114467179521256582820857644478939615872693259767625051656784436320536214888099246970935202477840794020001804824934094322942647313245015464146235410381690956788503264561405618174143168558794485590593621905074843445469861525661965245856307816345300556329589695975628440616169746340959867964538987362157854244708043842221402221963277716301052548247805899502717820052033072255313071657586884240821681100976940998736672322113547366478126078861119513619044370696083360828601809924884717575519821133956492114471403028698547136465705828789219477311237793325673906241774008541206351713780742201285265869533452824000524673440422889327800328362335547519511501666197619108063285902418799306753187272256356221431103854880105596403020095508495581348319107302916061047962850483220408241536724453572645136434687510278707999281526171375525625955687762398910760113471086947693290849443284396138463694877303972778628913002680531451135439058230938508307644282628222440206903725318897236157720164030865445790151149151226995439617177019234605884244198267136453281188424540649497573644414770526808655328967088370380579677911448765589873573311772376689968432217235625731351030824652263016860210144187956704470629348157475577780655133842312690878825193342235991049335995169792504550670357
Uau! How many digits are there at this big Fibonacci prime integer??
IntegerLength[Last[fibprime]]
Out[]=
2023
Wha is the size of all the numbers in this list?
IntegerLength/@fibprime
Out[]=
{1,1,1,2,2,3,4,5,6,9,10,17,28,29,75,90,91,94,107,119,119,621,987,1126,1946,2023}
Lets see those 20 Fibonacci prime numbers as binary
ArrayPlot[IntegerDigits[#,2]&/@fibprime〚;;20〛,FrameNone]
Out[]=
Lets see the first 1k Fibonacci numbers as binary pattern
ArrayPlot[IntegerDigits[#,2]&/@Table[Fibonacci[n],{n,0,1000,1}],FrameNone]
Out[]=
The same view padding left with 400 first numbers, we can notes gliders and randomness
ArrayPlot[PadLeft[IntegerDigits[#,2]&/@Table[Fibonacci[n],{n,0,400,1}]],FrameNone,ColorRules{0Yellow,1Orange}]
Out[]=
I published a function called SeguenceGraph where we can view a graph of a series, lets try with this big number
ResourceFunction["SequenceGraph"][IntegerDigits[Last[fibprime]]]
Out[]=
We can see it for all the Fibonacci primes we have
In[]:=
Manipulate[ResourceFunction["SequenceGraph"][IntegerDigits[fibprime〚n〛],PlotLabeln],{{n,14},1,Length[fibprime],1},SaveDefinitionsTrue]
Out[]=
​
n
OK, now we can check how those Fibonacci primes fits the Benford’s Law
Get the first digits
Map[First[IntegerDigits[#]]&,fibprime]
Out[]=
{2,3,5,1,8,2,1,2,5,4,2,9,1,1,4,5,1,3,1,3,9,3,5,2,3,1}
View the list
BarChart[%,ColorFunctionHue,ChartLabels%]
Out[]=
Now count the occurrence of the first digits values
Tally[Flatten[First[IntegerDigits[#]]&/@fibprime]]​​PieChart[%〚All,2〛,ChartLabels%〚All,1〛]
Out[]=
{{2,5},{3,5},{5,4},{1,7},{8,1},{4,2},{9,2}}
Out[]=
I think we need more data to validate Benford’s Law here
Play around with numbers is fun!!
What did you do when you get bored??!!
I like to do some data science style tinkering with Wolfram Language!
​
Please add your suggestions about how to view the Fibonacci primes
References:
​
https://mathworld.wolfram.com/BenfordsLaw.html
https://mathworld.wolfram.com/FibonacciNumber.html
https://mathworld.wolfram.com/PrimeNumber.html
https://resources.wolframcloud.com/FunctionRepository/resources/SequenceGraph/
https://en.wikipedia.org/wiki/Fibonacci_prime
​