mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Math > Number Theory Discussion Group

Reply
 
Thread Tools
Old 2021-11-03, 17:34   #12
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

397510 Posts
Default

Quote:
Originally Posted by bhelmes View Post

calling function is
mpz_mod_mp (m_A, m_A, Mp);

The result is not the same (I replaced it with a mpz_mod)

Where is the logical error ?
You call with mpz_mod_mp (m_A, m_A, Mp); Are the variables in the call initialized?
paulunderwood is offline   Reply With Quote
Old 2021-11-03, 17:39   #13
bhelmes
 
bhelmes's Avatar
 
Mar 2016

3·53 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
You call with mpz_mod_mp (m_A, m_A, Mp); Are the variables in the call initialized?
yes, otherwise the program would not run.
bhelmes is offline   Reply With Quote
Old 2021-11-03, 17:44   #14
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

1111100001112 Posts
Default

Quote:
Originally Posted by bhelmes View Post
I had some problems to use the function, described before, mpz_mod_Mp


void mpz_mod_mp (mpz_t r, mpz_t a, mp_bitcnt_t p)
{
mpz_t res;
mpz_init (res);

// assumed that r is initialized and a is expendable
do
{
mpz_fdiv_r_2exp (res, a, p);
mpz_fdiv_q_2exp (a, a, p);
mpz_add (res, res, a);
} while (mpz_sizeinbase (res,2) > p);

mpz_set (r, res);
mpz_clear (res);
}


calling function is
mpz_mod_mp (m_A, m_A, Mp);

The result is not the same (I replaced it with a mpz_mod)

Where is the logical error ?

You call with Mp but the argument is p. This could be the reason for the error.

Last fiddled with by paulunderwood on 2021-11-03 at 17:52
paulunderwood is offline   Reply With Quote
Old 2021-11-03, 17:52   #15
bhelmes
 
bhelmes's Avatar
 
Mar 2016

3·53 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
You call with Mp but the parameter is p. This could be the reason for the error.

nice stroke, Mp was uint64, p was mp_bitcnt_t.
I replaced the mp_bitcnt_t by uint64 and the results are correct.
Thanks a lot.


bhelmes is offline   Reply With Quote
Old 2021-11-13, 19:11   #16
bhelmes
 
bhelmes's Avatar
 
Mar 2016

3×53 Posts
Default

A peaceful and pleasant day for you,

there is a bug in the function, and I have no idea, where the reason is:


void mpz_mod_mp (mpz_t r, mpz_t a, uint64 p)
{
mpz_t res_1, res_2;
mpz_init (res_1);
mpz_init (res_2);

// 1. Calculation
mpz_mod (res_1, a, f);

// 2. Calculation
mp_bitcnt_t mp=mp_bitcnt_t(p);

// assumed that r is initialized and a is expendable
if (mpz_cmp_ui (a, 0)==0)
{
mpz_set_ui (res_2, 0);
}
else
{
do
{
mpz_fdiv_r_2exp (res_2, a, mp);
mpz_fdiv_q_2exp (a, a, mp);
mpz_add (res_2, res_2, a);
} while (mpz_sizeinbase (res_2,2) > mp);
}

// Compairison
if (mpz_cmp (res_1, res_2)!=0)
{
mpz_out_str (stdout, 10, a);
cout << endl;
mpz_out_str (stdout, 10, res_1);
cout << endl;
mpz_out_str (stdout, 10, res_2);
cout << endl;

exit (1);
}

mpz_set (r, res_2);
mpz_clear (res_1);
mpz_clear (res_2);
}



The error appears if a=0 and the output is
0
10584739298409185657387898722659423897260
89430325577680987480245132687307139815991


If you have an idea, where the error is,
I will be glad.
bhelmes is offline   Reply With Quote
Old 2021-11-13, 19:24   #17
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

F8716 Posts
Default

Quote:
Originally Posted by bhelmes View Post
there is a bug in the function, and I have no idea, where the reason is:


void mpz_mod_mp (mpz_t r, mpz_t a, uint64 p)

<snip>
// 2. Calculation
mp_bitcnt_t mp=mp_bitcnt_t(p);
<snip>
It usual for p to be a prime and Mp to be the corresponding Mersenne number. If you have passed in p then why do you need Mp?

What is f?

Last fiddled with by paulunderwood on 2021-11-13 at 19:32
paulunderwood is offline   Reply With Quote
Old 2021-11-13, 19:44   #18
bhelmes
 
bhelmes's Avatar
 
Mar 2016

3·53 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
It usual for p to be a prime and Mp to be the corresponding Mersenne number. If you have passed in p then why do you need Mp?
I need for the function mpz_fdiv_r_2exp the variable as mp_bitcnt_t, therefore I made a change from uint_64 to mp_bitcnt_t

Quote:
Originally Posted by paulunderwood View Post
What is f?
f is Mp as mpz_t variable

But why is res_1 and res_2 not equal 0 ?
In other cases res_1 and res_2 are the same.
bhelmes is offline   Reply With Quote
Old 2021-11-13, 19:51   #19
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

3·52·53 Posts
Default

Quote:
Originally Posted by bhelmes View Post
I need for the function mpz_fdiv_r_2exp the variable as mp_bitcnt_t, therefore I made a change from uint_64 to mp_bitcnt_t
Without checking the manual that may well be the case, but mpz_sizeinbase returns an int?
paulunderwood is offline   Reply With Quote
Old 2021-11-13, 20:01   #20
bhelmes
 
bhelmes's Avatar
 
Mar 2016

3×53 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
Without checking the manual that may well be the case, but mpz_sizeinbase returns an int?

for a=0 the loop with mpz_sizeinbase is not entered.
bhelmes is offline   Reply With Quote
Old 2021-11-13, 20:08   #21
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

3·52·53 Posts
Default

Quote:
Originally Posted by bhelmes View Post

f is Mp as mpz_t variable
can you output p and f in that function for us to see?
paulunderwood is offline   Reply With Quote
Old 2021-11-13, 20:18   #22
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

3·52·53 Posts
Default

Quote:
Originally Posted by bhelmes View Post
f is Mp as mpz_t variable
Has it been initialized?
paulunderwood is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Factorial modulo a prime axn Computer Science & Computational Number Theory 66 2011-09-01 21:55
modulo operation for polynomials? smslca Math 3 2011-04-18 17:18
Order of 3 modulo a Mersenne prime T.Rex Math 7 2009-03-13 10:46
N! modulo for large N Cyclamen Persicum Math 2 2003-12-10 10:52
The modulo operation, how is it computed? eepiccolo Math 7 2003-01-08 03:07

All times are UTC. The time now is 16:58.


Mon Jan 17 16:58:03 UTC 2022 up 178 days, 11:27, 0 users, load averages: 1.32, 1.28, 1.25

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.

≠ ± ∓ ÷ × · − √ ‰ ⊗ ⊕ ⊖ ⊘ ⊙ ≤ ≥ ≦ ≧ ≨ ≩ ≺ ≻ ≼ ≽ ⊏ ⊐ ⊑ ⊒ ² ³ °
∠ ∟ ° ≅ ~ ‖ ⟂ ⫛
≡ ≜ ≈ ∝ ∞ ≪ ≫ ⌊⌋ ⌈⌉ ∘ ∏ ∐ ∑ ∧ ∨ ∩ ∪ ⨀ ⊕ ⊗ 𝖕 𝖖 𝖗 ⊲ ⊳
∅ ∖ ∁ ↦ ↣ ∩ ∪ ⊆ ⊂ ⊄ ⊊ ⊇ ⊃ ⊅ ⊋ ⊖ ∈ ∉ ∋ ∌ ℕ ℤ ℚ ℝ ℂ ℵ ℶ ℷ ℸ 𝓟
¬ ∨ ∧ ⊕ → ← ⇒ ⇐ ⇔ ∀ ∃ ∄ ∴ ∵ ⊤ ⊥ ⊢ ⊨ ⫤ ⊣ … ⋯ ⋮ ⋰ ⋱
∫ ∬ ∭ ∮ ∯ ∰ ∇ ∆ δ ∂ ℱ ℒ ℓ
𝛢𝛼 𝛣𝛽 𝛤𝛾 𝛥𝛿 𝛦𝜀𝜖 𝛧𝜁 𝛨𝜂 𝛩𝜃𝜗 𝛪𝜄 𝛫𝜅 𝛬𝜆 𝛭𝜇 𝛮𝜈 𝛯𝜉 𝛰𝜊 𝛱𝜋 𝛲𝜌 𝛴𝜎 𝛵𝜏 𝛶𝜐 𝛷𝜙𝜑 𝛸𝜒 𝛹𝜓 𝛺𝜔