1

I need to find the value different to 0 when evaluating

Fibonacci[x,2]mod(8417525)=0

How can I set up that with an iterative process, trying subsequent natural numbers till it finds the target value?

I'm quite new, so sorry if it's just a banal question.

Thanks

user967210
  • 245
  • 1
  • 8
  • Welcome to the Mathematica Stack Exchange. Please include Mathematica code that you have tried so far. You can copy from your notebook's input cell and paste into the edit window where a braces icon { } can be used to format code. Could you include a simple example (with say x=2) and a smaller Mod value that has a known result? – Syed Feb 21 '22 at 11:31
  • Thanks for your comment, till now I just tried Table[Fibonacci[x,2]mod(8417525)=0,{x,a,b}] with various intervals [a,b], and just tried to find if for any of those value is "True". I just want to try an iterative process that stop when the mod is 0 and gives me the corresponding x value – user967210 Feb 21 '22 at 11:46
  • Mathematica function Fibonacci[n,x] provides the polynomials. Please show your code ( "Table[Fibonacci[x,2]mod(8417525)=0,{x,a,b}]" doesn't evaluate ) . – Ulrich Neumann Feb 21 '22 at 11:50
  • Your syntax for Fibonacci polynomial is wrong. Should be Fibonacci[n,x] as stated above. First type in FindInstance, hover over it, click the I and study the examples. Go down the examples to Scope/Integer domain and study those. Then study the construct for example: FindInstance[Mod[Fibonacci[3,x],8417525,x,Integers] – josh Feb 21 '22 at 12:37
  • Well no, because I want to find the right Fibonacci Polynomial of (x-1) degree, such that when I insert 2 as a value I will get the number P and taking P mod(8417525) I will get 0. That's why I thought about a cycle over the naturals that will stop when the Mod will be 0, meaning I will get the right degree of the polynomial – user967210 Feb 21 '22 at 12:51
  • @user967210: Ok sorry. I mis-understood. – josh Feb 21 '22 at 13:19

3 Answers3

3
$Version

(* "13.0.1 for Mac OS X x86 (64-bit) (January 28, 2022)" *)

Clear["Global`*"]

x = 1; While[Mod[Fibonacci[x, 2], 8417525] != 0, x++]; x

(* 127380 *)

Verifying,

Mod[Fibonacci[x, 2], 8417525]

(* 0 *)

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
3

Here are a couple of approaches which speed the solution dramatically for large indices.

The following code answers the question with a straight-forward While loop (@BobHanlon) giving the solution $n=127380$. Running this on a fresh kernel requires 31 s on my machine.

Block[{n = 1},
   AbsoluteTiming[ While[Mod[Fibonacci[n, 2], 8417525] != 0, n++]; n]
]

{31.7111, 127380}

FibPoly2Mod[n,m] finds Mod[Fibonacci[n,2],m], by using the recursion matrix $\{\{0,1\},\{1,2\}\}$ and code similar to FibonacciMod in this question.

FibPoly2Mod[n_, m_] :=
   Block[{b = {{0, 1}, {1, 2}}, d = IntegerDigits[n, 2]},
      Do[
         b = If[d[[i]] == 0, Mod[b . b, m], 
         Mod[b . b . {{0, 1}, {1, 2}}, m]],
         {i, 2, Length[d]}];
      b[[1, 2]]
   ]

For large indices, FibPoly2Mod[n,m] is much faster than Mod[Fibonacci[n,2],m].

For Fibonacci numbers, the Pisano period $k[m]$ of Mod[Fibonacci[n],m] is the LCM of the periods of the prime powers in the modulus $m$. That is, $k[m]={\rm LCM}[k[p_ 1^{e_ 1}],k[p_ 2^{e_ 2}],...,k[p_j^{e_j}]]$, where $m=p_ 1^{e_ 1}p_ 2^{e_ 2}...p_j^{e_j}$.

Therefore, I conjecture that the period of Mod[Fibonacci[n,x],m] equals the least common multiple of the periods of the prime powers making up the modulus $m$.

FibPoly2Mod0[m_Integer] :=
   Block[{p, f, n},
      p = FactorInteger[m];
      f = Table[
         n = 1;
         While[FibPoly2Mod[n, p[[i, 1]]^p[[i, 2]]] != 0, n++];
         n,
         {i, 1, Length[p]}];
      LCM @@ f
   ]

The code takes only 0.03 s, compared with 31 s for the While loop.

RepeatedTiming[FibPoly2Mod0[8417525], 10]

{0.0294806, 127380}

My tests so far suggest the conjecture is true...

KennyColnago
  • 15,209
  • 26
  • 62
1

Shorter:

NestWhile[#+1&,1,Mod[Fibonacci[#,2],8417525]!=0&]

enter image description here

AsukaMinato
  • 9,758
  • 1
  • 14
  • 40