1
$\begingroup$

I understand how to make lists with the Select function and NestList, but these are only for one dimensional lists. Is it possible to make lists of all points that satisfy a constraint? For example, all points {x,y} that satisfy PrimeQ[x*y+1]==True.

Sorry if this is really amateur, I only recently started Mathematica and I'm trying to teach myself the functions.

$\endgroup$
2
$\begingroup$

There are many ways to do this. I will show one with SparseArray.

matrix = SparseArray[{x_, y_} /; PrimeQ[x y + 1] -> 1, {100, 100}]

Now try these:

MatrixPlot[matrix]

ArrayRules[matrix]

Keys@Most@ArrayRules[matrix]

The last one just gives a list of {x,y} pairs.

| improve this answer | |
$\endgroup$
  • $\begingroup$ f@x is just alternative notation for f[x]. $\endgroup$ – Szabolcs May 17 '17 at 13:38
  • $\begingroup$ What does the ->1 mean? $\endgroup$ – volcanrb May 17 '17 at 14:40
  • $\begingroup$ @volcanrb , You might be interested in this thread. $\endgroup$ – N.J.Evans May 17 '17 at 15:15
  • $\begingroup$ @volcanrb It depends on the context. For this use, look up SparseArray. $\endgroup$ – Szabolcs May 17 '17 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.