Complex floor

Complex Floor is a domain extension for the built-in function Floor to accept complex numbers. It was originally designed by Eugene McDonnell in order to provide domain extensions to ceiling, residue, GCD, and LCM, which all depend on the definition of Floor. This extension is currently implemented in Dyalog APL, J, and NARS2000.

Terminology
In this article, an integer refers to a Gaussian integer, a complex number whose real and imaginary parts are integers.

In code fragments,  and   refer to functions that return the real and imaginary part of the given complex number respectively. They are available as a part of Circular, namely  and.

Concept
McDonnell focused on a few specific uses of Floor: calculating the quotient and remainder between two numbers, and calculating the GCD via the Euclidean algorithm. In order to achieve this, he proposed seven requirements:


 * Existence. Every number has a floor.
 * Uniqueness. Every number has only one floor.
 * Fractionality. The magnitude of the difference of a number and its floor shall be less than one. This property must be satisfied to guarantee that remainders are less in magnitude than divisors. It may be called the fundamental property of the floor function.
 * Integrity. The floor of a number is an integer.
 * Convexity. If  is the floor of the numbers   and , then it is also the floor of all numbers on the line segment between   and.
 * Integer Translation. For  a complex integer,.
 * Compatability. The complex floor function is compatible with the real floor function. Furthermore, its action on purely imaginary numbers is similar to the action of the real floor function on real numbers. In particular,  and.

Then he proposed a shape on the complex plane that satisfies all seven requirements: a rectangle of width  and height , rotated 45 degrees clockwise so that the midpoint of the bottom side is placed on an integer  , and the top two corners are placed on   and   respectively. The following is the APL model by McDonnell, rewritten using dfns:

Application to other primitives
Ceiling  was extended via the property.

Residue  was extended by the definition. The property of Fractionality ensures that the residue is always smaller in magnitude than the divisor.

GCD  was extended by using the Euclidean algorithm, which is guaranteed to terminate for any pair of complex numbers, again due to Fractionality. The following is the APL model for complex GCD, again using dfns:

LCM  was extended by using the property.