Complex floor: Difference between revisions
m (Text replacement - "</source>" to "</syntaxhighlight>") |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
In this article, an ''integer'' refers to a [[wikipedia:Gaussian integer|Gaussian integer]], a complex number whose real and imaginary parts are integers. | In this article, an ''integer'' refers to a [[wikipedia:Gaussian integer|Gaussian integer]], a complex number whose real and imaginary parts are integers. | ||
In code fragments, < | In code fragments, <syntaxhighlight lang=apl inline>re</syntaxhighlight> and <syntaxhighlight lang=apl inline>im</syntaxhighlight> 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 <syntaxhighlight lang=apl inline>9○</syntaxhighlight> and <syntaxhighlight lang=apl inline>11○</syntaxhighlight>. | ||
== Concept == | == Concept == | ||
Line 15: | Line 15: | ||
:# ''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. | :# ''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. | :# ''Integrity''. The floor of a number is an integer. | ||
:# ''Convexity''. If < | :# ''Convexity''. If <syntaxhighlight lang=apl inline>g</syntaxhighlight> is the floor of the numbers <syntaxhighlight lang=apl inline>z</syntaxhighlight> and <syntaxhighlight lang=apl inline>w</syntaxhighlight>, then it is also the floor of all numbers on the line segment between <syntaxhighlight lang=apl inline>z</syntaxhighlight> and <syntaxhighlight lang=apl inline>w</syntaxhighlight>. | ||
:# ''Integer Translation''. For < | :# ''Integer Translation''. For <syntaxhighlight lang=apl inline>c</syntaxhighlight> a complex integer, <syntaxhighlight lang=apl inline>(c+⌊z) = ⌊(c+z)</syntaxhighlight>. | ||
:# ''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, < | :# ''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, <syntaxhighlight lang=apl inline>(re⌊z)≤re⌈z</syntaxhighlight> and <syntaxhighlight lang=apl inline>(im⌊z)≤im⌈z</syntaxhighlight>. | ||
Then he proposed a shape on the complex plane that satisfies all seven requirements: a rectangle of width < | Then he proposed a shape on the complex plane that satisfies all seven requirements: a rectangle of width <syntaxhighlight lang=apl inline>√2</syntaxhighlight> and height <syntaxhighlight lang=apl inline>√÷2</syntaxhighlight>, rotated 45 degrees clockwise so that the midpoint of the bottom side is placed on an integer <syntaxhighlight lang=apl inline>b</syntaxhighlight>, and the top two corners are placed on <syntaxhighlight lang=apl inline>b+0j1</syntaxhighlight> and <syntaxhighlight lang=apl inline>b+1</syntaxhighlight> respectively. The following is the APL model by McDonnell, rewritten using [[dfn]]s: | ||
< | <syntaxhighlight lang=apl> | ||
Floor←{ | Floor←{ | ||
r←re ⍵ | r←re ⍵ | ||
Line 32: | Line 32: | ||
b+0j1 | b+0j1 | ||
} | } | ||
</ | </syntaxhighlight> | ||
== Application to other primitives == | == Application to other primitives == | ||
[[Ceiling]] < | [[Ceiling]] <syntaxhighlight lang=apl inline>⌈x</syntaxhighlight> was extended via the property <syntaxhighlight lang=apl inline>(⌈x) = -⌊-x</syntaxhighlight>. | ||
[[Residue]] < | [[Residue]] <syntaxhighlight lang=apl inline>x|y</syntaxhighlight> was extended by the definition <syntaxhighlight lang=apl inline>(w|z) = z-w×⌊z÷w+w=0</syntaxhighlight>. The property of Fractionality ensures that the residue is always smaller in [[magnitude]] than the divisor. | ||
[[GCD]] < | [[GCD]] <syntaxhighlight lang=apl inline>x∨y</syntaxhighlight> 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: | ||
< | <syntaxhighlight lang=apl> | ||
GCD←{ | GCD←{ | ||
0=⍺|⍵:⍺ | 0=⍺|⍵:⍺ | ||
(⍺|⍵)∇⍺ | (⍺|⍵)∇⍺ | ||
} | } | ||
</ | </syntaxhighlight> | ||
[[LCM]] < | [[LCM]] <syntaxhighlight lang=apl inline>x∧y</syntaxhighlight> was extended by using the property <syntaxhighlight lang=apl inline>(x∧y) = x×y÷x∨y</syntaxhighlight>. | ||
== References == | == References == | ||
<references/> | <references/> | ||
{{APL features}} | {{APL features}}[[Category:Scalar monadic functions]] |
Latest revision as of 22:14, 10 September 2022
Complex Floor is a domain extension for the built-in function Floor to accept complex numbers. It was originally designed by Eugene McDonnell[1] 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, re
and im
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 9○
and 11○
.
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
g
is the floor of the numbersz
andw
, then it is also the floor of all numbers on the line segment betweenz
andw
. - Integer Translation. For
c
a complex integer,(c+⌊z) = ⌊(c+z)
. - 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,
(re⌊z)≤re⌈z
and(im⌊z)≤im⌈z
.
Then he proposed a shape on the complex plane that satisfies all seven requirements: a rectangle of width √2
and height √÷2
, rotated 45 degrees clockwise so that the midpoint of the bottom side is placed on an integer b
, and the top two corners are placed on b+0j1
and b+1
respectively. The following is the APL model by McDonnell, rewritten using dfns:
Floor←{ r←re ⍵ i←im ⍵ b←(⌊r)+0j1×⌊i x←1|r y←1|i 1>x+y: b x≥y: b+1 b+0j1 }
Application to other primitives
Ceiling ⌈x
was extended via the property (⌈x) = -⌊-x
.
Residue x|y
was extended by the definition (w|z) = z-w×⌊z÷w+w=0
. The property of Fractionality ensures that the residue is always smaller in magnitude than the divisor.
GCD x∨y
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:
GCD←{ 0=⍺|⍵:⍺ (⍺|⍵)∇⍺ }
LCM x∧y
was extended by using the property (x∧y) = x×y÷x∨y
.
References
- ↑ McDonnell, Eugene. "Complex Floor".
APL features [edit] | |
---|---|
Built-ins | Primitives (functions, operators) ∙ Quad name |
Array model | Shape ∙ Rank ∙ Depth ∙ Bound ∙ Index (Indexing) ∙ Axis ∙ Ravel ∙ Ravel order ∙ Element ∙ Scalar ∙ Vector ∙ Matrix ∙ Simple scalar ∙ Simple array ∙ Nested array ∙ Cell ∙ Major cell ∙ Subarray ∙ Empty array ∙ Prototype |
Data types | Number (Boolean, Complex number) ∙ Character (String) ∙ Box ∙ Namespace ∙ Function array |
Concepts and paradigms | Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity element ∙ Complex floor ∙ Array ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ Glyph ∙ Leading axis theory ∙ Major cell search ∙ First-class function |
Errors | LIMIT ERROR ∙ RANK ERROR ∙ SYNTAX ERROR ∙ DOMAIN ERROR ∙ LENGTH ERROR ∙ INDEX ERROR ∙ VALUE ERROR ∙ EVOLUTION ERROR |