New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented Quadratic residue function #736
Conversation
There are compile errors. You can test locally by running |
c9c3697
to
ca73632
Compare
@isuruf Compiler errors fixed and it passes the one test I set. I'll add more tests. By that time you can review the rest of the code. |
ce36e32
to
7991983
Compare
7991983
to
20a9dc9
Compare
bed19fe
to
13ca5ac
Compare
You got a test failure on Appveyor:
Can you look into that? Is that a bug in your code? |
@@ -169,6 +169,9 @@ bool powermod(const Ptr<RCP<const Integer>> &powm, const RCP<const Integer> &a, | |||
//! All solutions to x**s == a**r mod m where b = r / s. Return false if none exists. | |||
void powermod_list(std::vector<RCP<const Integer>> &pows, const RCP<const Integer> &a, | |||
const RCP<const Number> &b, const RCP<const Integer> &m); | |||
|
|||
//! Finds all Quadratic Residue of a Positive Integer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Residue -> Residues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected.
To see if it works I changed all of the |
@certik Its working with mpz_class. But I still don't beleive it was an |
You were using |
@isuruf But |
@CodeMaxx, the compiler is free to inline
You are right about overflow though, for 100, it is not possible to overflow. |
@CodeMaxx Let us know if you need more help. |
@Sumith1896 I'm having some trouble using |
return false; | ||
|
||
RCP<const Integer> x; | ||
const RCP<const Integer> a1 = integer(a_final); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take care of tabs and spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is spaces. Is there an inconsistency anywhere?
Got it.
Can you add tests for the second function? |
3a6b147
to
e76fc7e
Compare
I'll add tests by tomorrow. |
@@ -1194,6 +1194,23 @@ bool _nthroot_mod1(std::vector<RCP<const Integer>> &roots, const integer_class & | |||
return true; | |||
} | |||
|
|||
// Checks if Solution for x**n == a mod p**k exists where a != 0 mod p and p is an odd prime. | |||
bool is_nthroot_mod1(const integer_class &a, const integer_class &n, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to _is_nthroot_mod1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functions not declared in the header files have names starting from _
. Is that a symengine convention ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
return is_nthroot_mod1(a, n, p, k); | ||
} | ||
} else { | ||
integer_class _a; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this from wikipedia
In general, to determine if a quadratic congruence with composite modulus is solvable use the following theorem:[37]
Let n > 1, and gcd(a,n) =1. Then x2 ≡ a (mod n) is solvable if and only if:
The Legendre symbol \left(\frac{a}{p}\right)=1 for all odd prime divisors p of n.
a ≡ 1 (mod 4) if 4|n, but 8 does not divide n; a ≡ 1 (mod 8) if 8|n.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore that
@CodeMaxx, since the code is generic for |
@isuruf Do you mean two functions? ( |
Or just |
@isuruf So code is not generic for |
@isuruf Can review this. |
*/ | ||
{ | ||
if (mod->as_mpz() <= 0) { | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mod
can be negative
@CodeMaxx, I'm sorry I didn't see this message for review. I left a few comments. When you are done ping me. |
@isuruf Ping |
|
||
bool is_nth_residue(const RCP<const Integer> &a, const RCP<const Integer> &n, const RCP<const Integer> &mod) | ||
/* | ||
Returns true if ``a`` (mod ``mod``) is in the set of squares mod ``mod``, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set of nth powers
+1 to merge when tests pass |
@isuruf ping |
@isuruf @Sumith1896 Could you please review this?