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$
1
  • $\begingroup$ Like Select[pts, PrimeQ[Apply[Times, #] + 1] &]? $\endgroup$ Commented May 17, 2017 at 13:35

1 Answer 1

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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