Cartesian product of sets

I have two types of sets, one of them is a list of points of the form $\{t_{k}\}$ and the other one is an interval of the form $[a,b]$. And my custom set consists of these type of sets and I need to plot its Cartesian product. As an example, say my set is $A=[0,1]\cup\{2,3,4,5\}$, I need to plot $A\times A$. If I have only list of points, then I have no problem but when intervals come in to play, I don't have a very good idea. I need help at this point.

Try the following:

For example, $A=[0,1]\cup\{2,3,4\}\cup[5,7]$.

points = {2, 3, 4};
intervals = {{0, 1}, {5, 7}};

Graphics[{Lighter@Blue, Point@Tuples[points, 2],
Rectangle @@ Transpose[#] & /@ Tuples[intervals, 2],
Line[{{{#1, #2[[1]]}, {#1, #2[[2]]}}, {{#2[[1]], #1}, {#2[[2]], #1}}}] & @@@
Tuples[{points, intervals}]}, Axes -> True]


The disadvantage of the considered method is different width of lines and points. Adjusting the PointSize and Thickness does not help.

Let us consider another method and $A=[0,1]\cup\{3/2,4/3,\dots,(n+1)/n,\ldots\}$.

points = Table[(n + 1)/n, {n, 2, 30}];
intervals = {{0, Min[points]}};


I use Min[points] instead of 1 to remove the gap between interval and finite number of points.

min = Min[points, intervals] - 0.01;
max = Max[points, intervals] + 0.01;
size = 1000;
thickness = 2;
data = ConstantArray[0, size];
scale = Round@Rescale[#, {min, max}, {1, size}] &;


Here 0.01 is a small space around the data, size is the size of partitioning, and thickness measured in the integers units.

(data[[scale[#1] ;; scale[#2]]] = 1) & @@@ intervals;
(data[[scale[#] - thickness ;; scale[#] + thickness]] = 1) & /@ points;
img = ColorNegate@Image@Outer[Times, data, data, 1 - {0.33, 0.33, 1}];


Here {0.33, 0.33, 1} is color (light blue).

Graphics[{Texture[img],
Polygon[{{min, min}, {min, max}, {max, max}, {max, min}},
VertexTextureCoordinates -> {{0, 1}, {0, 0}, {1, 0}, {1, 1}}]},
Axes -> True]


• How can we make width of lines and dots same size? Also, what would you suggest for $A=[0,1]\cup\{3/2,4/3,\cdots,(n+1)/n,\cdots\}$? – bkarpuz Sep 24 '13 at 21:04
• @bkarpuz It is the interesting question. See my update. – ybeltukov Sep 24 '13 at 23:04
• I got the idea for filling the gap between the interval and the "cut" sequence. How about we use another set $B$ to fill the gap and take Cartesian product of $A\cup B$. For instance $B=\{1,31/30\}$ as a filler interval? But it seems that setting the size of the points and the width of the lines is the main issue. – bkarpuz Sep 25 '13 at 5:57