How to resolve the algorithm Lucas-Lehmer test step by step in the Bracmat programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Lucas-Lehmer test step by step in the Bracmat programming language

Table of Contents

Problem Statement

Lucas-Lehmer Test: for

p

{\displaystyle p}

an odd prime, the Mersenne number

2

p

− 1

{\displaystyle 2^{p}-1}

is prime if and only if

2

p

− 1

{\displaystyle 2^{p}-1}

divides

S ( p − 1 )

{\displaystyle S(p-1)}

where

S ( n + 1 )

( S ( n )

)

2

− 2

{\displaystyle S(n+1)=(S(n))^{2}-2}

, and

S ( 1 )

4

{\displaystyle S(1)=4}

.

Calculate all Mersenne primes up to the implementation's maximum precision, or the 47th Mersenne prime   (whichever comes first).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Lucas-Lehmer test step by step in the Bracmat programming language

Source code in the bracmat programming language

  ( clk$:?t0:?now
  & ( time
    =   ( print
        =   
          .   put
            $ ( str
              $ ( div$(!arg,1)
                  ","
                  (   div$(mod$(!arg*100,100),1):?arg
                    & !arg:<10
                    & 0
                  | 
                  )
                  !arg
                  " "
                )
              )
        )
      & -1*!now+(clk$:?now):?SEC
      & print$!SEC
      & print$(!now+-1*!t0)
      & put$"s: "
    )
  & 3:?exponent
  &   whl
    ' ( !exponent:~>12000
      & (   !exponent^(!exponent^-1):!exponent^%
          & 4:?s
          & 2^!exponent+-1:?n
          & 0:?i
          &   whl
            ' ( 1+!i:?i
              & !exponent+-2:~
              & mod$(!s^2+-2.!n):?s
              )
          & (   !s:0
              & !time
              & out$(str$(M !exponent " is PRIME!"))
            | 
            )
        | 
        )
      & 1+!exponent:?exponent
      )
  & done
  );

  

You may also check:How to resolve the algorithm Accumulator factory step by step in the ActionScript programming language
You may also check:How to resolve the algorithm Dinesman's multiple-dwelling problem step by step in the C programming language
You may also check:How to resolve the algorithm Rep-string step by step in the Clojure programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the SNUSP programming language
You may also check:How to resolve the algorithm Generate Chess960 starting position step by step in the Common Lisp programming language