Function Repository Resource:

ComplexRange

Source Notebook

Generate a range of complex numbers

Contributed by: Daniele Gregori

ResourceFunction["ComplexRange"][z1]

generates a rectangular range between 0 and the complex number z1.

ResourceFunction["ComplexRange"][{z1}]

generates a linear range between 0 and the complex number z1.

ResourceFunction["ComplexRange"][z1,z2]

generates a rectangular range between the complex numbers z1 and z2.

ResourceFunction["ComplexRange"][{z1,z2}]

generates a linear range between the complex numbers z1 and z2.

ResourceFunction["ComplexRange"][z1,z2,z3]

generates a rectangular range between the complex numbers z1 and z2, with real and imaginary steps Re[z3] and Im[z3] respectively.

ResourceFunction["ComplexRange"][z1,z2,{Δzre,Δzim}]

generates a rectangular range between the complex numbers z1 and z2, with real and imaginary steps Δzre and Δzim respectively.

ResourceFunction["ComplexRange"][{z1,z2},z3]

generates a linear range between the complex numbers z1 and z2, with real and imaginary steps Re[z3] and Im[z3] respectively.

ResourceFunction["ComplexRange"][{z1,z2},{Δzre,Δzim}]

generates a linear range between the complex numbers z1 and z2, with real and imaginary steps Δzre and Δzim respectively.

Details and Options

ResourceFunction["ComplexRange"] generalizes Range to complex numbers.
ResourceFunction["ComplexRange"] requires as first and second argument two complex numbers, spanning a range between their minimum and maximum real and imaginary parts.
A step size may optionally be given as either a complex number or a list of real numbers. By default, the imaginary part is incremented first, throughout its range, with the real part fixed; then the real part is incremented and the process is iterated until the end of the real part's range.
ResourceFunction["ComplexRange"] accepts the following options:
"IncrementFirst"Imincrement first the real or imaginary part
"FareyRange"Falsecreate a complex generalization of the Farey range

Examples

Basic Examples (2) 

Create a linear range between two complex numbers:

In[1]:=
ResourceFunction["ComplexRange"][{1 + 1 I, 6 + 6 I}]
Out[1]=

Visualize it in the complex plane:

In[2]:=
ComplexListPlot@%
Out[2]=

Create a rectangular range between two complex numbers:

In[3]:=
ResourceFunction["ComplexRange"][-2 - 2 I, 2 + 2 I]
Out[3]=

Visualize it in the complex plane:

In[4]:=
ComplexListPlot@%
Out[4]=

Scope (5) 

Create a rectangular range between 0 and a given complex number:

In[5]:=
ResourceFunction["ComplexRange"][4 + 2 I]
Out[5]=

Visualize it in the complex plane:

In[6]:=
ComplexListPlot@%
Out[6]=

The range can be in any quadrant of the complex plane:

In[7]:=
ResourceFunction["ComplexRange"][-3 - 3 I, 0]
Out[7]=
In[8]:=
ComplexListPlot@%
Out[8]=

The step subdivisions can be specified as a complex number:

In[9]:=
ResourceFunction["ComplexRange"][-2 - I, 1 + I, 1 + 1/2 I]
Out[9]=
In[10]:=
ComplexListPlot@%
Out[10]=

Alternatively, the third argument can be a list of the real and imaginary steps:

In[11]:=
ResourceFunction["ComplexRange"][-2 - I, 1 + I, {1, 1/2}]
Out[11]=
In[12]:=
% == ResourceFunction["ComplexRange"][-2 - I, 1 + I, 1 + 1/2 I]
Out[12]=

It is also possible to create a linear range, by wrapping the first two arguments in a list:

In[13]:=
ResourceFunction["ComplexRange"][{0, 3 + 4 I}, 1/3 + 1/2 I]
Out[13]=
In[14]:=
ComplexListPlot@%
Out[14]=

Options (6) 

IncrementFirst (3) 

By default, the imaginary part is incremented first:

In[15]:=
ResourceFunction["ComplexRange"][2 + 2 I]
Out[15]=

To increment first the real part, use the option "IncrementFirst" Re:

In[16]:=
ResourceFunction["ComplexRange"][2 + 2 I, "IncrementFirst" -> Re]
Out[16]=

Of course, their Union is the same:

In[17]:=
Union[%] == Union[%%]
Out[17]=

FareyRange (3) 

It is possible to specify a special range, namely the complex generalization of the resource function FareyRange:

In[18]:=
ResourceFunction["ComplexRange"][{-3/2 - 3/2 I, 3/2 + 3/2 I}, {3, 3}, "FareyRange" -> True]
Out[18]=
In[19]:=
ComplexListPlot@%
Out[19]=

The third argument is then the third argument of the resource function FareyRange, possibly different for the real and imaginary parts:

In[20]:=
ResourceFunction["ComplexRange"][-1 - I, 1 + I, {4, 3}, "FareyRange" -> True]
Out[20]=
In[21]:=
ComplexListPlot@%
Out[21]=

If the third argument is not a list of integers, a failure is returned:

In[22]:=
ResourceFunction["ComplexRange"][-1 - I, 1 + I, {1/3, 1/3}, "FareyRange" -> True]
Out[22]=

Properties and Relations (3) 

ComplexRange[z1,z2,z3] can be realized by combining Range and Outer. That is, ComplexRange[z1,z2,z3] is equivalent to Flatten@Outer[#1+ⅈ#2&,Range[Re[z1],Re[z2],Re[z3]],Range[Im[z1],Im[z2],Im[z3]]]:

In[23]:=
ResourceFunction["ComplexRange"][-1 - I, 1 + I, 1/2 + I]
Out[23]=
In[24]:=
Flatten@Outer[#1 + I #2 &, Range[-1, 1, 1/2], Range[-1, 1]]
Out[24]=
In[25]:=
% == %%
Out[25]=

ComplexRange[z1,z2,z3] can be also realized by combining Range and Tuples. That is, ComplexRange[z1,z2,z3] is equivalent to Plus@@@Tuples[{Range[Re[z1],Re[z2],Re[z3],Range[Im[z1],Im[z2],Im[z3]]}]:

In[26]:=
ResourceFunction["ComplexRange"][-1 - I, 1 + I, 1/2 + I]
Out[26]=
In[27]:=
Plus @@@ Tuples[{Range[-1, 1, 1/2], I Range[-1, 1, 1]}]
Out[27]=
In[28]:=
% == %%
Out[28]=

ComplexRange[z1,z2,z3] can be also realized through CoordinateBoundsArray. That is, ComplexRange[z1,z2,z3] is equivalent to Plus@@@MapAt[# ⅈ&,Flatten[CoordinateBoundsArray[{{Re[z1],Re[z2]},{Im[z1],Im[z2]}},{Re[z3],Im[z3]}],1],{All,2}]:

In[29]:=
ResourceFunction["ComplexRange"][-1 - I, 1 + I, 1/2 + I]
Out[29]=
In[30]:=
Plus @@@ MapAt[# I &, Flatten[CoordinateBoundsArray[{{-1, 1}, {-1, 1}}, {1/2, 1}], 1], {All, 2}]
Out[30]=
In[31]:=
% == %%
Out[31]=

Neat Examples (1) 

Draw simple and beautiful geometrical point patterns:

In[32]:=
ComplexListPlot[
 {ResourceFunction["ComplexRange"][-3 - 3 I, 3 + 3 I, {3, 3}, "FareyRange" -> True],
  ResourceFunction["ComplexRange"][-3 - 3 I, 3 + 3 I],
  ResourceFunction["ComplexRange"][-5/2 - 5/2 I, 5/2 + 5/2 I],
  ResourceFunction["ComplexRange"][-3 - 3 I, 3 + 3 I, {1/2, 1/2}]},
 PlotMarkers ->
  {{Automatic, Small}, {Automatic, Small}, {Automatic, Medium}, {Automatic, Tiny}},
 Background -> Black, ImageSize -> Large]
Out[32]=

Publisher

Daniele Gregori

Version History

  • 1.0.0 – 28 May 2025

Related Resources

Author Notes

The development of this function benefitted from suggestions by the Wolfram review team.

License Information