Re: math:gcd is incorrect
- Posted by bill May 10, 2012
- 1554 views
I apologise for being so sharp.
I wasn't being personal.
What I was trying to point out is not that Eu is
superior to APL. I don't believe that. I do
believe that Eu4 has faults. Eu is weakly typed.
I am interested in Eu as a scripting language not
for serious programming.
"APL has been" was unnecessarily dismissive.
What I said:
1 Using 0/0 = 1 can lead to major inconsistencies
- such as 1 = 2 - depending on evaluation order.
From what I have seen APL gets away with 0/0 = 1
because it uses a fixed eveluation order
(right to left) unless brackets intervene. Also
it does not respect precedence for operators.
You said:
I like the following understanding.
x divided by 0 ...... (plus or minus) infinity if x is not 0
0 divided by 0 ...... is 1 because anything divided by itself
results in 1.
You gave no indication of understanding the consequences of such definitions.
We have numbers/symbols +inf -inf
Division by zero is an error/inf unless it is zero / zero
when it is fine. Reduction of equation have to be done in a fixed order.
Question: If anything / anything = 1 then does inf / inf = 1?
That, I considered trolling.
You followed up with a reference to an APL paper and a
comment on machine division. And the killingly funny
source for 0/0 = 1 ancient middle eastern philosophy.
The original discussion was about GCD and particularly that
GCD(0,4) is 4 not 0 as in the Euphoria Maths library.
GCD(0,0) is undefined because there is no uniquely defined
common divisor.
GCD(0,0) is defined as 1 or 0
- 0 because it is common,
- 1 because it is a divisor.
Knuth gives GCD code which would give GCD(0,0) = 0.
Lattice theory would require GCD(0,0) = 1, LCM(0,0) = 0
Neither is convincing.
Defining GCD(0,0) = 1 is useful in that 1 is a divisor.
My initial thought was to disqualify GCD(0,0) but
rethinking I would go with 1. (pace Knuth)
Again, I apologise for being offensive.