Hi Fred,
could you please run the attached debug version of ComplexCell.cc?
I am getting:
5J3 | 4J¯1
⎕CT is: 1e-13
modulus (A) is: (5,3)
A=0 is: (0,0)
A+A=0 is: (5,3)
B÷A+A=0 is: (0.5,-0.5)
⌊B÷A+A=0 is: (1,-1)
A×⌊B÷A+A=0 is: (8,-2)
B-A×⌊B÷A+A=0 is: (-4,1)
¯4J1
The above printout are the intermediate results of the following
computation
in bif_resudue():
// // op Z
before Z after
new (Z) IntCell(0); // Z←0 any 0
Z->bif_equal(Z, A); // Z←A=Z
0 A=0
Z->bif_add(Z, A); // Z←A+Z
A=0 A+A=0
Z->bif_divide(Z, this); // Z←B÷Z
A+A=0 B÷A+A=0
Z->bif_floor(Z); // Z←⌊Z
B÷A+A=0 ⌊B÷A+A=0
Z->bif_multiply(Z, A); // Z←A×Z
⌊B÷A+A=0 A×⌊B÷A+A=0
Z->bif_subtract(Z, this); // Z←A-Z
A×⌊B÷A+A=0 B-A×⌊B÷A+A=0
which I believe is a faithful (apart from errors)
implementation of Z←B-A×⌊B÷A+A=0
as given in the McDonnell paper.
The key issue are probably the following out put lines:
B÷A+A=0 is:
(0.5,-0.5)
⌊B÷A+A=0 is: (1,-1)
Best Regards,
/// Jürgen
On 06/24/2017 01:48 AM, Frederick Pitts
wrote:
Hello Jürgen,
This is a followup to my previous email.
I
have found that if I replace | and ⌊ invocations in the test
code with residue AND floor (¨ needed with floor) functions
(see below) from Eugene McDonnell's article, the idempotency
and complete residue system count tests are successful.
∇g ←
floor z
r
← 9 ○ z
i
← 11 ○ z
b
← ( ⌊ r ) + 0J1 × ⌊ i
x
← 1 ∣ r
y
← 1 ∣ i
→
( 1 ≤ x + y ) / L0
g
← b
→
0
L0:
→
( x < y ) / L1
g
← b + 1
→
0
L1:
g
← b + 0J1
∇
∇ r ← w residue z
r ← z - w × floor
z ÷ w + w = 0
∇
Maybe a faithful implementation of both these function in
Gnu APL is required.
Regards,
Fred
On Fri, 2017-06-23 at 21:58 +0200, Juergen Sauermann wrote:
Hi,
please disregard my comment on bif_floor() below.
The proper line should be this (note the -
instead of +):
if (D < 1.0 -
Workspace::get_CT()) return zv(Z, fr, fi);
With that
change my testcases (which contain the examples of both
the ISO standard and
the IBM language reference) are now properly working
again. Fixed in SVN 970.
/// Jürgen
On 06/23/2017 09:02 PM, Juergen
Sauermann wrote:
Hi Frederick,
I suppose that this is caused by a rounding error just
before the complex floor.
I have attached a debug version of ComplexCell.cc
that prints every partial result of the computation.
If I run it then I get:
5J3
| 14J5
modulus (A) is: (5,3)
A=0 is: (0,0)
A+A=0 is: (5,3)
B÷A+A=0 is: (2.5,-0.5)
⌊B÷A+A=0 is: (3,-1)
A×⌊B÷A+A=0 is: (18,4)
B-A×⌊B÷A+A=0 is: (-4,1)
¯4J1
However if I use a slightly smaller B (kind of
simulating a rounding error) then I get:
5J3
| 14J4.999999999
modulus (A) is: (5,3)
A=0 is: (0,0)
A+A=0 is: (5,3)
B÷A+A=0 is: (2.4999999999118,-0.50000000014706)
⌊B÷A+A=0 is: (2,-1)
A×⌊B÷A+A=0 is: (13,1)
B-A×⌊B÷A+A=0 is: (1,3.999999999)
1J3.999999999
I suppose that is what happens on your machine but not on
mine.
You may also want to try out the following. In ComplexCell::bif_floor()
around line 231 ff it says:
// ISO:
if D is tolerantly less than 1 return fr + 0J1×fi
// IBM: if D is less than 1 return
fr + 0J1×fi
// However, ISO examples follow IBM (and so do
we)
//
// if (D < 1.0 + Workspace::get_CT()) return
zv(Z, fr, fi); // ISO
if (D < 1.0) return zv(Z, fr, fi); //
IBM and examples in ISO
If you uncomment the first if statement then you get the
ISO variant of bif_floor() while otherwise you
get the IBM variant (which is also the one described in
the McDonnel paper). It could be that the ISO variant
works better for the bif_residue() function, but
it causes problems in other places. If uncommenting the if
line should fix your problem, then I can create two
variants of bif_floor(): one for bif_residue()
and one
for the rest.
Best Regards,
Jürgen Sauermann
On 06/23/2017 07:31 PM,
Frederick Pitts wrote:
Hello Jürgen,
SVN 969 on my platform (Fedora 25, Intel(R)
Core(TM) i7-6700 CPU)
5J3
| 14J5 1J4 ¯4J1
gives
1J4 ¯4J1 ¯4J1
not
¯1J4 ¯4J1 ¯4J1
Regards,
Fred
On Fri, 2017-06-23 at 17:38 +0200, Juergen
Sauermann wrote:
Hi,
I have changed A∣B to literally follow the
paper pointed out by Jay.
The complex floor itself was already implemented
like described in the paper,
but A∣B was not.
Now (SVN 969) the complex A∣B is
computed as
Z←B-A×⌊B÷A+A=0
without any attempts to improve the performance of
the operation.
The result in the 5J3 modulus are now the
same as in IBM APL2 (and I suppose also in J)
5J3 ∣ 14J5 1J4 ¯4J1
¯4J1 ¯4J1 ¯4J1
I hope this finally fixed it. Thanks a lot to all
that helped fixing this bug.
/// Jürgen
On 06/23/2017 09:34 AM,
Jay Foad wrote:
I urge you to read Eugene
McDonnell's Complex
Floor, which also discusses Residue. I
believe the design he comes up with in this
paper was adopted more or less verbatim in APL.
Also bear in mind that Floor and Residue in APL
have to work well on all complex numbers, not just the
Gaussian integers.
Jay.
|