# How to find and count the points that are elements of $\{(x,y)\in\mathbb{Z}^2:x^2+y^2\le16 \wedge |y|\gt x\}$?

I am given the following set:

$\qquad \{(x,y)\in\mathbb{R}^2:x^2+y^2\le16 \wedge |y|\gt x\}$

I want find and count the number of points in this set that have integer coordinates.

I drew this to help me visualize the problem. ClearAll["Global*"];
Plot[{y /. Solve[x^2 + y^2 == 16, y], x, -x}, {x, -5, 5},
PlotStyle -> {Solid, Dashed, Dashed},
AspectRatio -> 1,
PlotRange -> {{-5, 5}, {-5, 5}},
PlotTheme -> "Detailed",
GridLines -> {{-4, -3, -2, -1, 0, 1, 2, 3, 4}, {-4, -3, -2, -1, 0, 1, 2, 3, 4}}]


I want to mark all of those points which are inside the set red as well as count them.

What should I do?

Just solve it:

sol = Solve[x^2 + y^2 <= 16 && Abs[y] > x, {x, y}, Integers];


Get how many:

Length@sol


Make the points (set point size or use Disk if you want bigger):

gr = Graphics[{Red, Point[{x, y}] /. sol}];


Then show them together:

Show[{Plot[{y /. Solve[x^2 + y^2 == 16, y], x, -x}, {x, -5, 5},
PlotStyle -> {Solid, Dashed, Dashed}, AspectRatio -> 1,
PlotRange -> {{-5, 5}, {-5, 5}}, PlotTheme -> "Detailed",
GridLines -> {{-4, -3, -2, -1, 0, 1, 2, 3, 4}, {-4, -3, -2, -1, 0,
1, 2, 3, 4}}], gr}]


Here is one way to do it.

grid = Catenate @ CoordinateBoundsArray[{{-4, 4}, {-4, 4}}];
belongsQ[{x_, y_}] := x^2 + y^2 <= 16 && Abs[y] > x
pts = Pick[grid, belongsQ /@ grid];
Length[pts]


34

Plot[{y /. Solve[x^2 + y^2 == 16, y], x, -x}, {x, -5, 5},
PlotStyle -> {Automatic, Dashed, Dashed},
AspectRatio -> 1,
PlotRange -> {{-5, 5}, {-5, 5}},
PlotTheme -> "Detailed",
PlotLegends -> False,
GridLines -> {{-4, -3, -2, -1, 0, 1, 2, 3, 4}, {-4, -3, -2, -1, 0, 1, 2, 3, 4}},
Epilog -> {Red, AbsolutePointSize, Point[pts]}] • Was Epilog intended to do only things like this ?
– AHB
Jan 11, 2017 at 12:00
• @AHB. It is certainly much used to do things like this, but I would not say "only". Jan 11, 2017 at 16:18
plot1 = Plot[{y /. Solve[x^2 + y^2 == 16, y], x, -x}, {x, -5, 5},
PlotStyle -> {Automatic, Dashed, Dashed}, AspectRatio -> 1,
PlotRange -> {{-5, 5}, {-5, 5}}, PlotTheme -> "Detailed",
GridLines -> {{-4, -3, -2, -1, 0, 1, 2, 3, 4}, {-4, -3, -2, -1, 0,
1, 2, 3, 4}}]


This shot works:

pts = {x, y} /. FindInstance[x^2 + y^2 <= 16 && Abs[y] > x, {x, y}, Integers, 100]
(* 100 was chosen big enough to have all points found *)

plot2 = ListPlot[pts, PlotStyle -> {Red, PointSize[Large]}];

Show[plot1, plot2] Length@pts
`

34