#!/usr/local/bin/apl --script ⍝ Run with: ./MOD_TEST.apl ⍝ !!! This test is totally bogus because the residues produced by MODJ and ∣ for ⍝ a given modulo basis belong to different complete residue classes. !!! pwold ← ⎕pw ⎕pw ← 196 ∇ CONT "" ⍞ ← "Press enter to continue..." ⍞ "" ∇ ∇ EXIT "" ⍞ ← "Press enter to exit..." ⍞ ∇ ∇ z ← rcl LABEL tbl z ← ⍉ ⌽ ( ⌽ ⍉ ¯1 ⌽ tbl , 1 ⊃ rcl ) , ¯99J¯99, 2 ⊃ rcl ∇ ∇ z ← NORMJ m z ← m × + m ∇ ⍝ Truncate toward negative infinity. ⍝ This is an array function. ∇z ← ROUND x z ← ⌊ x ∇ ⍙J ← 0J1 ∇ z ← CMPLX a; m; n ( m n ) ← a z ← m + ⍙J × n ∇ ∇ z ← m CMPLX0 n z ← m + ⍙J × n ∇ ∇ z ← ROUNDJ m z ← CMPLX0 / ROUND 9 11 ○ m ∇ ⍝ Euclidean division algorithm for Gaussian integers. ⍝ DIVJ is a scalar function. ∇ z ← a DIVJ b; q → ( b ≠ 0J0 ) / L0 z ← 0 a → 0 L0: z ← q , a - b × q ← CMPLX ⌊ ( 9 11 ) ○ a ÷ b ∇ ⍝ Modulo function for Gaussian integers. A test replacement for current ⍝ gnu-apl ∣ function applied to Gaussian integers. ⍝ MODJ is a scalar function. ∇ z ← a MODJ b z ← ¯1 ↑ b DIVJ a ∇ ∇REPORT; n; r; c; rsd0; rsd1; bad; cnt; cl; clr ⍝ Test is performed on a grid of complex numbers ranging from ¯nJ¯n in the ⍝ lower left corner to nJn in the upper right corner. n ← 6 ⍝ 50 n2p1 ← 1 + 2 × n ⍝ r is a vector of Gaussian integer real parts r ← ( ¯1 - n ) + ⍳ n2p1 ⍝ c is a vector of all the required Gaussian integers generated from r. c ← , r ∘.+ 0J1 × r ⍝ rsd0 is matrix of residue's for all possible pairings of the elements of ⍝ c using MODJ. rsd0 ← , ⊃ c ∘.MODJ c ⍝ rsd1 is matrix of residue's for all possible pairings of the elements of c ⍝ using APL mod operator (∣). rsd1 ← , ⊃ c ∘.∣ c ⍝ colarg is a ( n2p1 ⋆ 2 ) ⋆ 2 vector composed of the c vector repeated ⍝ n2p1 ⋆ 3 times. colarg ← ( ( n2p1 ⋆ 2 ) ⋆ 2 ) ⍴ c ⍝ rowarg is a ( n2p1 ⋆ 2 ) ⋆ 2 vector composed of the c vector elements ⍝ repeated n2p1 ⋆ 2 times each. rowarg ← ( ( n2p1 ⋆ 2 ) ⍴ n2p1 ⋆ 2 ) / c " " ⍝ Compare rsd0 and rsd1 to determine if there are discrepancies. bad ← rsd0 ≠ rsd1 ⍝ Count the bad elements and return if cnt is zero. → ( 0 = cnt ← + / bad ) / 0 ⍝ Otherwise, generate a table of the arguments and differing results ' LA RA MODJ |' d ← cnt 1 ( d ⍴ bad / , rowarg ) , ( d ⍴ bad / , colarg ) , ( d ⍴ bad / rsd0 ) , d ⍴ bad / rsd1 ∇ REPORT "FINISHED"