janhardo

695 Reputation

12 Badges

11 years, 39 days

MaplePrimes Activity


These are replies submitted by janhardo

@janhardo 

restart;
BitMod:= (N::posint, n::posint)->
local B:= Bits:-Split(N, n);
    `if`(nops(B) < 2, `if`(ilog2(N+1) = n, 0, N), thisproc(add(B), n))
:
(*---
Check whether (2^p-1) is prime by Lucas-Lehmer algorithm.
-----*)
IsMersennePrimeExponent:= proc(p::And(prime, Not(2)))
local s:= 4;
    to p-2 do s:= BitMod(`*`(s,s), p) - 2 od;
    evalb(s=0)
end proc;
IsMersennePrimeExponent(2):= true
:
Typesetting:-mprintslash([(IsMersennePrimeExponent := proc (p::And(prime,Not(2)
)) local s; s := 4;  to p-2 do s := BitMod(`*`(s,s),p)-2; end do; evalb(s = 0);
end proc)],[proc (p::And(prime,Not(2))) local s; s := 4;  to p-2 do s := BitMod
(`*`(s,s),p)-2; end do; evalb(s = 0); end proc])

CodeTools:-Usage(IsMersennePrimeExponent(2));
memory used=0.77KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns, gc time=0ns
true

CodeTools:-Usage(IsMersennePrimeExponent(44497));
memory used=2.58GiB, alloc change=-4.81MiB, cpu time=3.73s, real time=3.73s, gc time=171.88ms
true


#This Mersenne prime was discovered by computer in 1979:
CodeTools:-Usage(IsMersennePrime(44497));
memory used=2.65GiB, alloc change=0 bytes, 
cpu time=10.58s, real time=12.60s, gc time=6.48s

                              true
-----------------------------------------------------------------
The second procedure seems to be much faster ....
-------------------------------------------------------------------
CodeTools:-Usage(IsMersennePrimeExponent(110503));
memory used=15.73GiB, alloc change=0 bytes, cpu time=25.58s, real time=25.62s, gc time=609.38ms
true


;
The first million Mersenne exponent found on 3 sept 1996 : 1,257,787, second : see calculation
How long does it take 

CodeTools:-Usage(IsMersennePrimeExponent(1398269));
memory used=4.30TiB, alloc change=0 bytes, cpu time=92.42m, real time=92.44m, gc time=61.94s
true

CodeTools:-Usage(IsMersennePrimeExponent(2976221));
memory used=19.62TiB, alloc change=27.47MiB, cpu time=7.38h, real time=7.39h, gc time=6.09m
true

-----------------------------------------------------------

2^2,976,221 -1  Mersenne prime took 7.38 h
How big the number is, as expression of a power of 10 ?
Interesting is the latest known Mersenne prime as power of 10. 

@janhardo 

Good news ..your estimation :
-------------------------------------------------------------------------------------------------

I predict that your prime 1398269 would take 4 hours 12 minutes on my computer, an Intel Core I-7 @ 2.7 GHz. Extra processors have little effect on this (but can be used to process multiple primes simultaneously).

--------------------------------------------------------------------------------------------------

It takes about 1 1/2 hour on my computer ! ..wow ( a fast motherboard )

CodeTools:-Usage(IsMersennePrimeExponent(1398269));
memory used=4.30TiB, alloc change=0 bytes, cpu time=92.42m, real time=92.44m, gc time=61.94s
true
There is a list of primes for 1000 billione  List of prime numbers up to 1000000000000 (free.fr)
Its 10^9  numbers ,compare this with say 2^(10^6) numbers 

 

@Carl Love 

Your improved procedure IsMersennePrimeExponent()  has now becomes much faster !
Prime 110503 :real time=25.62 s 
I am calculating now the 1398269 prime : how long does it take? 

Suppose you do have the fastest prime test algorithm possible, then there is the question : where lies the greatest primenumber on the numberline?  
82,589,933 (Mersenne prime)     2^ 85,589,933 - 1  =  prime number.(but not always)
This the largest primenumber known now on the numberline.
For Pi(X) (generally , how many primes are there less than any given number X ?)
What could be a strategy to seek further for a bigger prime?
for 10^8 =100 million , there are 5,761,455 primes (quess?) and prime number 88,589,933 is one of them

I do see that for this number segment : 1000 numbers, in old studymaterial 10^7-1000  to 10^7 on the numberline there are 53 primenumbers to find.
The number of primes goes from  0-1000 = 168 from steps of 1000 numbers to  10^7-1000- 10^7 = 53  
The 1000 number segment where (2^82,589,933-1 ) in is positioned : how many primes are here in to find? 

Meanwhile now ,the computer is calculating further for prime 1,398,269 : how long does it take ? 
Its going to the 3 hours now ...

@janhardo 

Tried the Mersenne prime , but memory allocation error from Maple. 

21,398,269-

This is the first in the green table on internet. 

Using  amd 6 core 5 serie 1600 CPU ( a slow one)  and 16 Mb memory.
( i made always myself a computersystem )

Is there a quess how much memory is needed for the prime calculation?

@Carl Love 

Amazing...thanks , don't tell me that we find now  the largest primenumber now with Maple..
I will make some calculations with it and look how far it goes 

see List of known Mersenne prime numbers - PrimeNet

I am interested in the Riemann hypothese and want to know more about advanced mathematics  
Someone who has made something out of the primes :

Is This the Most Maple Prime Post Ever on MaplePrimes? - MaplePrimes

@acer 
Thanks

I do see a basic do loop example here what not difficult now to understand is

@Carl Love 

Thanks
Well, still no idea why this is assignment operators are introduced in Maple, but that question cannot maybe easy  be answered?

@Carl Love

Thanks for the explanation of the do loop where you started with on this thread.
Complicated ...at first sight

The other loop examples seems to be easier to understand, but still left room for me to ask some  question about the innerworking of the loop in a procedure.
Let me first try to understand the do loop hereunder and then go again to another explanation of the do loop from you. 

-----------------------------------------------------------------------------

@janhardo From closely reading your loop attempts, I see that you're really struggling with it. Here's a simple straightforward procedure with a loop to sum the elements of a list of arbitrary length:
-----------------------------------------------------------------------------

SumList:= proc(L::list)
local S:= 0, i;
    for i to nops(L) do
        S:= S + L[i]
    od;
    S
end proc;

-------------------------------------------------------------------------------
Please study this thoroughly and let me know if you have any questions.
----------------------------------------------------------------------------

Indeed i am struggling with SumList procedure ( in general with do loops now) to add a list of  2 numbers 1,2  with outcome 3 
L::list   = input parameter L in procedureand  must be a list as datatype
L:=[1,2]  

local S:= 0, i;  local variables S and  i used in procedure
S is sum of list L and i is index varialble of do loop.

I is a index variable in the do loop : don't know if this i starts on 0 or 1 ?

ops(L) is the number of elements in the list : here two in L:=[1,2] 
So i cannot start on 0 ( there is no 0 th element in List L ), there is 1, and 2

Don't know why i should use this : S:= S + L[i]  and why not S:=L[i]  ?
od; is a shortcut for:  end do 
S  stands here alone  only for ? 

Let me see how i get this little  procedure working in Maple

@Carl Love 

The task was:
a) Sum all numbers in a list 
b) Calculate n! , where  n is positive integer 

Try to follow again from the start solutions and following the other writings

a)

SumList:= proc(L::{list, set})
local r:= 0, x;
    for x in L do r+= x od;
    r
end proc:

b)

Factorial:= (n::nonnegint)-> local r:= 1, k:= 0; do r*= ++k until k>=n;

 r+  is  summing up by 1 for a integer number (natural numbers)?

-----------------------------------------------------------------------------

@acer 

I found my earlier stored worksheet back as reference and make some notes.
I remember some rootfinding commands ( student-calculus package ) for a function and this  ..

************************************************************************************
As far as I can tell the author of your book prefers using loops and Arrays, even for things which seq and map would make somewhat simpler
*********************************************************************************.
So i keep this in mind for if i start possible again with new procedural programming

@acer 

Thanks

So not using anymore a array , but Array instead with a capital then.
But in my old examples of programing procedures you advise to program the procedure on a another way and don't use array as datatype here ? ( in 2020) 
Probably (for sure) was it a easier way of programming the procedure as you did.  
Unfortanely i did not focus on this other way of programming  and went on wit the exercises, but they became hard to solve with more advanced calculus ( series ), so i stopped.  

I am still curiuos and maybe i can make a overhaul of the already made exercises and see there..

@Mac Dude 

If you are really after learning how to write procedures in Maple, there is no better resource than the Programming Guide. Sections 1.4 and 6 are relevant here. I do not understand your assertion that questions have no answers, maybe because I do not know your questions.
========================================================================

In the past here on maple primes forum , i tried to learn  program procedures by using a book, but the used programming in this book seems to be obselote as @Acer forummember pointed out to me.
Now i must find out what the present procedure programming approach is again..probably it has to do by using what datastructure ?
In this book they use array's a lot and it should be beter to use another datastructure in Maple?

I must reread the old post again

@tomleslie 
Thanks
There is not a formula known (yet), what can predicts a next coming Mersenne prime.(as the Merssene formula shows) 
The prime numbers are endless, but not for Mersenne primes. ( how to proof this this ..)

Suppose there was a formula, then the whole problem of finding the largest prime number is solved.

Left over..

- Stronger caculation capacity computer
- Optimal algoritme for finding Mersenne primes
- seek strategy 

On 19 sept1983 the largest prime number was  2^132.049  -1   ~40.000 digits

Its about 1 sec for 919,142  prime p , but if you search in steps you need less seeking time ? 
132.049/ 919,142 = 2.39 min, but the calculation becomes larger and larger by increasing number. 
fascinating: GIMPS - The Math - PrimeNet (mersenne.org)

@tomleslie 

Thanks,
Interesting programming.

I looked at the GIMPS (great internet Mersenneprime search)

If you do want to use the program GIMP : 

The Most importantly, you will need a lot of patience. Roughly speaking it will take about a month to run a single primality test – visit the benchmark page for a more accurate estimate on your computer.

Seems to be revolving about the Mersenne numbers formula: there are primes in the formula what gives a prime number and some do not .
What is a Mersenne number in the sieve programming ? :  Mn= 2^n-1 
M3 (mersenne number 3) is 7 ..is a prime
M11 = 2047 =23 . 89 is not prime

So if the procedure shows what are Mersenne numbers, then we can calculate how much time Maple  needs for finding the Mersenne primes ?
But easier is  probably to use the Mersenne formula directly?
Mersenne Prime Discovery - 2^82589933-1 is Prime!

Using this in the procedure of the sieve :

Lucas–Lehmer primality test - Wikipedia  ( Lucas–Lehmer test that applies only to Mersenne numbers )

Only 50 Mersenne prime  numbers are till now found yet and because i do want to know more as hobby of the Riemann hypothesis about the distribution of the prime numbers

@Mac Dude 

Thanks,

I am wondering why there no included answers for the exercises in the Maple programming guide..or do i miss something?
Yes, the question is how to start programming this sieve in Maple

There are some interesting answers to study .. 
Let me find the biggest prime in the world and there are enough of them. .:-)  

First 46 47 48 49 50 51 52 Last Page 48 of 73