Why was primality test thought to be NP?
$begingroup$
To check if $n$ is prime, one only need to try dividing $n$ by numbers up to $sqrt{n}$, meaning that the complexity would be $O(sqrt{n})$. In my opinion, $O(sqrt{n}) < O(n)$ so this simple algorithm is already P. But why did people think that primality test is NP, and were surprised by the AKS primality test?
complexity-theory time-complexity np
$endgroup$
add a comment |
$begingroup$
To check if $n$ is prime, one only need to try dividing $n$ by numbers up to $sqrt{n}$, meaning that the complexity would be $O(sqrt{n})$. In my opinion, $O(sqrt{n}) < O(n)$ so this simple algorithm is already P. But why did people think that primality test is NP, and were surprised by the AKS primality test?
complexity-theory time-complexity np
$endgroup$
2
$begingroup$
Possible duplicate of Primality testing: Why is dividing a number $n$ by every integer between 2 and $sqrt{n}$ an inefficient test?
$endgroup$
– David Richerby
1 hour ago
4
$begingroup$
If something is in P then it is automatically in NP. You seem to be using "NP" as shorthand for either "NP - P" or "NP-complete".
$endgroup$
– John Coleman
1 hour ago
add a comment |
$begingroup$
To check if $n$ is prime, one only need to try dividing $n$ by numbers up to $sqrt{n}$, meaning that the complexity would be $O(sqrt{n})$. In my opinion, $O(sqrt{n}) < O(n)$ so this simple algorithm is already P. But why did people think that primality test is NP, and were surprised by the AKS primality test?
complexity-theory time-complexity np
$endgroup$
To check if $n$ is prime, one only need to try dividing $n$ by numbers up to $sqrt{n}$, meaning that the complexity would be $O(sqrt{n})$. In my opinion, $O(sqrt{n}) < O(n)$ so this simple algorithm is already P. But why did people think that primality test is NP, and were surprised by the AKS primality test?
complexity-theory time-complexity np
complexity-theory time-complexity np
edited 1 hour ago
David Richerby
71k16109199
71k16109199
asked 5 hours ago
DimenDimen
364
364
2
$begingroup$
Possible duplicate of Primality testing: Why is dividing a number $n$ by every integer between 2 and $sqrt{n}$ an inefficient test?
$endgroup$
– David Richerby
1 hour ago
4
$begingroup$
If something is in P then it is automatically in NP. You seem to be using "NP" as shorthand for either "NP - P" or "NP-complete".
$endgroup$
– John Coleman
1 hour ago
add a comment |
2
$begingroup$
Possible duplicate of Primality testing: Why is dividing a number $n$ by every integer between 2 and $sqrt{n}$ an inefficient test?
$endgroup$
– David Richerby
1 hour ago
4
$begingroup$
If something is in P then it is automatically in NP. You seem to be using "NP" as shorthand for either "NP - P" or "NP-complete".
$endgroup$
– John Coleman
1 hour ago
2
2
$begingroup$
Possible duplicate of Primality testing: Why is dividing a number $n$ by every integer between 2 and $sqrt{n}$ an inefficient test?
$endgroup$
– David Richerby
1 hour ago
$begingroup$
Possible duplicate of Primality testing: Why is dividing a number $n$ by every integer between 2 and $sqrt{n}$ an inefficient test?
$endgroup$
– David Richerby
1 hour ago
4
4
$begingroup$
If something is in P then it is automatically in NP. You seem to be using "NP" as shorthand for either "NP - P" or "NP-complete".
$endgroup$
– John Coleman
1 hour ago
$begingroup$
If something is in P then it is automatically in NP. You seem to be using "NP" as shorthand for either "NP - P" or "NP-complete".
$endgroup$
– John Coleman
1 hour ago
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
To start, any decision problem with a witness verifiable for a "yes" answer in polynomial time is in NP.
$bullet$ The problem 'Is $p$ composite?' has a witness $k$, and it can be tested in polynomial time whether $k$ divides $p$, therefore is in NP.
$bullet$ The problem 'Is $p$ prime?' has a polynomial certificate (which can be found here), therefore is also in NP.
Now, your complexity analysis is not correct. If your input is a number $p$, then the input size is $log (p)$, since you need $log(p)$ bits to represent it. Therefore, $n=log(p)$ and $sqrt{p}=frac{1}{2} log(p)$ bits. So the time required (in respect to $n$) checking all the numbers up to $sqrt{p}$ will be $2^{frac{1}{2}n}$, and is in fact exponential in terms on input size $n$.
The question "Where exactly does the Primality problem lie" has been answered in the link here
$endgroup$
1
$begingroup$
"Is p composite" is obviously in NP, because you can bring a witness easily. "Is p prime" is in NP, but not obviously at all - there is a quite deep theorem that every prime p has a short prove of being prime, which I think involves complete factorisations of p+1 and/or p-1.
$endgroup$
– gnasher729
2 hours ago
$begingroup$
@gnasher729 thank you for spotting it! I edited it in.
$endgroup$
– lox
1 hour ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "419"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcs.stackexchange.com%2fquestions%2f108598%2fwhy-was-primality-test-thought-to-be-np%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
To start, any decision problem with a witness verifiable for a "yes" answer in polynomial time is in NP.
$bullet$ The problem 'Is $p$ composite?' has a witness $k$, and it can be tested in polynomial time whether $k$ divides $p$, therefore is in NP.
$bullet$ The problem 'Is $p$ prime?' has a polynomial certificate (which can be found here), therefore is also in NP.
Now, your complexity analysis is not correct. If your input is a number $p$, then the input size is $log (p)$, since you need $log(p)$ bits to represent it. Therefore, $n=log(p)$ and $sqrt{p}=frac{1}{2} log(p)$ bits. So the time required (in respect to $n$) checking all the numbers up to $sqrt{p}$ will be $2^{frac{1}{2}n}$, and is in fact exponential in terms on input size $n$.
The question "Where exactly does the Primality problem lie" has been answered in the link here
$endgroup$
1
$begingroup$
"Is p composite" is obviously in NP, because you can bring a witness easily. "Is p prime" is in NP, but not obviously at all - there is a quite deep theorem that every prime p has a short prove of being prime, which I think involves complete factorisations of p+1 and/or p-1.
$endgroup$
– gnasher729
2 hours ago
$begingroup$
@gnasher729 thank you for spotting it! I edited it in.
$endgroup$
– lox
1 hour ago
add a comment |
$begingroup$
To start, any decision problem with a witness verifiable for a "yes" answer in polynomial time is in NP.
$bullet$ The problem 'Is $p$ composite?' has a witness $k$, and it can be tested in polynomial time whether $k$ divides $p$, therefore is in NP.
$bullet$ The problem 'Is $p$ prime?' has a polynomial certificate (which can be found here), therefore is also in NP.
Now, your complexity analysis is not correct. If your input is a number $p$, then the input size is $log (p)$, since you need $log(p)$ bits to represent it. Therefore, $n=log(p)$ and $sqrt{p}=frac{1}{2} log(p)$ bits. So the time required (in respect to $n$) checking all the numbers up to $sqrt{p}$ will be $2^{frac{1}{2}n}$, and is in fact exponential in terms on input size $n$.
The question "Where exactly does the Primality problem lie" has been answered in the link here
$endgroup$
1
$begingroup$
"Is p composite" is obviously in NP, because you can bring a witness easily. "Is p prime" is in NP, but not obviously at all - there is a quite deep theorem that every prime p has a short prove of being prime, which I think involves complete factorisations of p+1 and/or p-1.
$endgroup$
– gnasher729
2 hours ago
$begingroup$
@gnasher729 thank you for spotting it! I edited it in.
$endgroup$
– lox
1 hour ago
add a comment |
$begingroup$
To start, any decision problem with a witness verifiable for a "yes" answer in polynomial time is in NP.
$bullet$ The problem 'Is $p$ composite?' has a witness $k$, and it can be tested in polynomial time whether $k$ divides $p$, therefore is in NP.
$bullet$ The problem 'Is $p$ prime?' has a polynomial certificate (which can be found here), therefore is also in NP.
Now, your complexity analysis is not correct. If your input is a number $p$, then the input size is $log (p)$, since you need $log(p)$ bits to represent it. Therefore, $n=log(p)$ and $sqrt{p}=frac{1}{2} log(p)$ bits. So the time required (in respect to $n$) checking all the numbers up to $sqrt{p}$ will be $2^{frac{1}{2}n}$, and is in fact exponential in terms on input size $n$.
The question "Where exactly does the Primality problem lie" has been answered in the link here
$endgroup$
To start, any decision problem with a witness verifiable for a "yes" answer in polynomial time is in NP.
$bullet$ The problem 'Is $p$ composite?' has a witness $k$, and it can be tested in polynomial time whether $k$ divides $p$, therefore is in NP.
$bullet$ The problem 'Is $p$ prime?' has a polynomial certificate (which can be found here), therefore is also in NP.
Now, your complexity analysis is not correct. If your input is a number $p$, then the input size is $log (p)$, since you need $log(p)$ bits to represent it. Therefore, $n=log(p)$ and $sqrt{p}=frac{1}{2} log(p)$ bits. So the time required (in respect to $n$) checking all the numbers up to $sqrt{p}$ will be $2^{frac{1}{2}n}$, and is in fact exponential in terms on input size $n$.
The question "Where exactly does the Primality problem lie" has been answered in the link here
edited 17 mins ago
answered 4 hours ago
loxlox
611110
611110
1
$begingroup$
"Is p composite" is obviously in NP, because you can bring a witness easily. "Is p prime" is in NP, but not obviously at all - there is a quite deep theorem that every prime p has a short prove of being prime, which I think involves complete factorisations of p+1 and/or p-1.
$endgroup$
– gnasher729
2 hours ago
$begingroup$
@gnasher729 thank you for spotting it! I edited it in.
$endgroup$
– lox
1 hour ago
add a comment |
1
$begingroup$
"Is p composite" is obviously in NP, because you can bring a witness easily. "Is p prime" is in NP, but not obviously at all - there is a quite deep theorem that every prime p has a short prove of being prime, which I think involves complete factorisations of p+1 and/or p-1.
$endgroup$
– gnasher729
2 hours ago
$begingroup$
@gnasher729 thank you for spotting it! I edited it in.
$endgroup$
– lox
1 hour ago
1
1
$begingroup$
"Is p composite" is obviously in NP, because you can bring a witness easily. "Is p prime" is in NP, but not obviously at all - there is a quite deep theorem that every prime p has a short prove of being prime, which I think involves complete factorisations of p+1 and/or p-1.
$endgroup$
– gnasher729
2 hours ago
$begingroup$
"Is p composite" is obviously in NP, because you can bring a witness easily. "Is p prime" is in NP, but not obviously at all - there is a quite deep theorem that every prime p has a short prove of being prime, which I think involves complete factorisations of p+1 and/or p-1.
$endgroup$
– gnasher729
2 hours ago
$begingroup$
@gnasher729 thank you for spotting it! I edited it in.
$endgroup$
– lox
1 hour ago
$begingroup$
@gnasher729 thank you for spotting it! I edited it in.
$endgroup$
– lox
1 hour ago
add a comment |
Thanks for contributing an answer to Computer Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcs.stackexchange.com%2fquestions%2f108598%2fwhy-was-primality-test-thought-to-be-np%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
$begingroup$
Possible duplicate of Primality testing: Why is dividing a number $n$ by every integer between 2 and $sqrt{n}$ an inefficient test?
$endgroup$
– David Richerby
1 hour ago
4
$begingroup$
If something is in P then it is automatically in NP. You seem to be using "NP" as shorthand for either "NP - P" or "NP-complete".
$endgroup$
– John Coleman
1 hour ago