Does ⎕CT tolerance apply to complex numbers in nested arrays?
0 reputation · 04 Feb 2022, 18:49 UTC
0 reputation · 04 Feb 2022, 18:49 UTC
Determine whether comparison tolerance ⎕CT applies to complex numbers nested inside arrays, and whether enclosing primitives such as match (≡) and find (⍳) propagate that tolerance to complex leaf elements.
⎕CT is well established for floating-point equality, with a default commonly near 1E-14 in Dyalog APL and implementation-specific elsewhere. Vendor references do not uniformly specify complex-number tolerance or its behavior inside nested arrays. As a result, expressions such as comparing 1+1E-15j to 1, or matching nested arrays containing complex values, may return different booleans across interpreters.
Does ⎕CT affect equality of complex scalars such as 1+1E-15j and 1? When ≡ or ⍳ compares nested arrays, does tolerance apply to complex leaf elements? Which implementations document this behavior, and where is it left unspecified?
34775 reputation · 05 Feb 2022, 02:32 UTC
In Dyalog APL (version 14.0 and later) the comparison tolerance ⎕CT does apply to complex numbers, and when primitives such as match (≡) or find (⍳) compare nested arrays the tolerance is used for each leaf complex element. In many other APL implementations the behavior is either unspecified or treats complex equality as exact, so tolerance may not affect complex numbers.
Because the APL2 standard does not explicitly mention complex numbers in the definition of ⎕CT, some interpreters either leave the behavior undefined or implement complex equality as an exact test (or apply ⎕CT separately to real and imaginary parts). This leads to variation across vendors.
⎕CT←1E-14.a←1+1E-15j and b←1.a≡b; a result of 1 indicates tolerance is active for complex numbers.X←(a 2) (3 b) and Y←(1 2) (3 1).X≡Y; a result of 1 shows tolerance propagated to the leaf complex elements.⎕CT←0 (exact comparison) to confirm the same expressions return 0.If you are using an APL other than Dyalog, consult its language reference for the "Comparison tolerance" section to see whether complex numbers are mentioned.
To give a definitive recommendation, please specify which APL interpreter you are using (e.g., Dyalog, GNU APL, NARS2000, APLX, etc.).
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.