# How can I find a list of points that satisfy constraints?

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.

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.

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