0
|
1411 Views
|
3 Replies
|
7 Total Likes
View groups...
Share

# Unexpected output from Reduce?

Posted 7 months ago
 In[86]:= Reduce[NextPrime[x] - x == 2 && 0 < x < 20 && PrimeQ[x], x \[Element] Integers] Out[86]= False In[87]:= Reduce[NextPrime[x] - x == 2 && 0 < x < 20, x \[Element] Integers] Out[87]= x == 3 || x == 5 || x == 9 || x == 11 || x == 15 || x == 17  why Out[86]=False ? I expect Out[86]= x == 3 || x == 5 ||x == 11 ||x == 17 
3 Replies
Sort By:
Posted 7 months ago
 Gianluca, your are simply too fast - and with the better solution! Best regards -- Henrik
Posted 7 months ago
 Well, some non-obvious things here (at least as far as I could find out): PrimeQ[x] gets evaluated immediately to False, before any number can be even tried; Reduce[] seems to expect a system of equations and inequalities only; So - here is my approach: primeQ[x_?NumericQ] := PrimeQ[x] Reduce[NextPrime[x] - x == 2 && 0 < x < 20 && primeQ[x] == True, x \[Element] Integers] 
Posted 7 months ago
 I suppose it is because PrimeQ is meant as a test for numbers. When given a symbol, such as in PrimeQ[x], it gives False.I would use Element[x, Primes], which remains unevaluated when x is a symbol.