1. math:gcd is incorrect

The manual:

62.7.7 GCD
include std/math.e
namespace math

public function gcd (atom p, atom q)

Returns the greater common divisor of to atoms

Parameters:
p : one of the atoms to consider
q : the other atom.

Returns:
A positive atom, without a fractional part, evenly dividing both
parameters, and is the greatest value with those properties.

Comments:
Signs are ignored. Atoms are rounded down to integers.
Any zero parameter causes 0 to be returned.
....

Evidence:

	include std/math.e 
	? gcd(0, 48) 
 
	returns 0 

This is simply wrong.

GCD (0, 48) = 48

1. By definition a greatest common divisor could not be 0.
Division by 0 is undefined (and 1/0 != INF).

2. 0 is divisible by 48.

Pseudocode GCD (from Knuth pp.319-20)
quoted in Wikipedia article on GCD algorithm

	function gcd(a, b) 
	   while b != 0 
	      t := b 
	      b := a mod b 
	      a := t 
	   return a 

Note: formally gcd(0, 0) is undefined and should be an
error just as much as division by zero is an error.

Theorem 2.1 Given any two integers a and b, not both zero,
there is a unique integer d, called their greatest common
divisor, with these properties: 1: d | a and d | b;
2: if d1 | a and d1 | b then d1 | d;
3: d > 0.

WJ Leveque Fundamentals of Number Theory p.31

new topic     » topic index » view message » categorize

2. Re: math:gcd is incorrect

bill said...

The manual:

   Any zero parameter causes 0 to be returned. 

...

This is simply wrong.

Agreed. This is a mistake. I'll submit a ticket for it. In future, this function will return a value greater than zero when we have a GCD, and 0 when the input values cannot have a GCD (eg. gcd(0,0))

In general, gcd(0, X) will return floor(abs(X))

new topic     » goto parent     » topic index » view message » categorize

3. Re: math:gcd is incorrect

bill said...

The manual:

62.7.7 GCD
Any zero parameter causes 0 to be returned.
This is simply wrong.

GCD (0, 48) = 48

Agreed. GCD(0, 48) is the same as GCD(48, 0) which is 48.

I'll take a stab at fixing this.

bill said...

(and 1/0 != INF).

Agreed. The limit of 1/x becomes arbiturarily large as x approaches 0, but that's different from stating that 1/0 is equal to infinity.

bill said...

Division by 0 is undefined

Except in trivial rings and wheel groups...

bill said...

Note: formally gcd(0, 0) is undefined and should be an
error just as much as division by zero is an error.

Technically, this is correct. Sometimes GCD(0, 0) is explicitly considered being equal to zero for similiar reasons that 0^0 is considered equal to 1.

new topic     » goto parent     » topic index » view message » categorize

4. Re: math:gcd is incorrect

Note: formally gcd(0, 0) is undefined and should be an
error just as much as division by zero is an error.

Technically, this is correct. Sometimes GCD(0, 0) is
explicitly considered being equal to zero for similar
reasons that 0^0 is considered equal to 1.

The situations are not similar.

1. 0^0 is def = 1 because lim x->0 x^x = 1 and x^x is continuous  
   on all real x != 0 
2. GCD is a divisor: by definition 0 is not a divisor 
3. Normalisation: Q(0,0) = 0: Q(x,y) = (x/gcd(x,y), y/gcd(x,y)) 
new topic     » goto parent     » topic index » view message » categorize

5. Re: math:gcd is incorrect

said...

Technically, this is correct. Sometimes GCD(0, 0) is
explicitly considered being equal to zero for similar
reasons that 0^0 is considered equal to 1.

bill said...

The situations are not similar.

They are in the sense that in both cases the functions are redefined by mathematicians such that they return a value.

bill said...

2. GCD is a divisor: by definition 0 is not a divisor

Well, division is the inverse of multiplication. It's true that it's common to define division (at least in basic arthimetic) excluding zero as a divisor, this leads arthimetic to be incomplete.

Alternatively, you could allow division by zero, but then you'd have contradictions. This seems like a deal-breaker, and it is most of the time, but probability works pretty well in spite of it. For example, the probability of hitting a smaller area within a larger one (e.g. hitting the 1-square inch bulls eye of a much larger dart board) is the area of the smaller divided by the area of the larger. However, the probability of hitting a single point overall in the larger area is zero, so if you attempt to compute the probability of hitting the larger area (out of the entire larger area, so larger area / larger area or P(1) )by summing up the probability of hitting any individual point, this infinite summation will lead you to a probability of 0% instead of 100%!

Back to division by zero. 1 / 0 = some imaginary number z, but then 0 * z would equal 0 and not 1, leading to a contradiction.

Even worse, 0 / 0 could equal any number. After all, 0 * z = 0, so 0 / 0 = z, but 0 * 1 = 0, so 0 / 0 = 1, and 0 * 0 = 0, so 0 / 0 = 0, 0 * i = 0, so 0 / 0 = i, etc. This makes 0 / 0 indeterminate.

bill said...
1. 0^0 is def = 1 because lim x->0 x^x = 1 and x^x is continuous  
   on all real x != 0 

So? x to the power of x is not continuous when x equals 0, and the limit of a value is different from the value.

Additionally, the limit of 0 to the power of x as x approaches 0 is 0. This gives a different answer than your formula, which means the value of 0 to the power of 0 is indeterminate.

0 to the power of 0 is itself indeterminate. One way to define power of zero is like this:

x^0 = x^-1 * x^1 

Of course, by definition

x^-1 = 1/(x^1) 

This gives

x^1 / x^1 = x/x 

When x is not equal to zero, it's obvious that this is equal to one. But when x is equal to zero, then this ends up as 0/0 which is indeterminate as discussed above.

Following this definition, 0 to the power of 0 can be argued to be anything (e.g. 0, 1, i, -264, etc...), the same way 0/0 is.

The real reason that 0 to the power of 0 is considered as equal to 1 is because it is useful to do so as it simplifies things like the binomial theorem by removing special cases.

Likewise, and to quote Wikipedia,

said...

It is useful to define gcd(0, 0) = 0 and lcm(0, 0) = 0 because then the natural numbers become a complete distributive lattice with gcd as meet and lcm as join operation. This extension of the definition is also compatible with the generalization for commutative rings given below.

bill said...

3. Normalisation: Q(0,0) = 0: Q(x,y) = (x/gcd(x,y), y/gcd(x,y))

By normalization, are you refering to normalized vectors, normalization property, or statistical normalization? None of these seem to fit.

Perhaps you mean something like "to make the function seem normal, as applies to common sense, by replacing its undefined and indeterminate cases with values that seem to make sense, according to common sense".

In that case, I'm fine with your definition, but I'd argue:

Normalization: POW(0,0) = 1: POW(x,x) = x^x 

new topic     » goto parent     » topic index » view message » categorize

6. Re: math:gcd is incorrect

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.

new topic     » goto parent     » topic index » view message » categorize

7. Re: math:gcd is incorrect

EUWX 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.

Just interested. Where did the above info come from ?.

Selgor

new topic     » goto parent     » topic index » view message » categorize

8. Re: math:gcd is incorrect

Selgor said...
EUWX 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.

Just interested. Where did the above info come from ?.

Selgor

http://www.jsoftware.com/papers/eem/0div0a.htm

0/1..... =1 is NOT the preferred interpretation. I therefore specifically prefixed my statement with "I like the following". There is also a reference in ancient Eastern mathematics about 0/0 being 1, but I can't find it right now.

new topic     » goto parent     » topic index » view message » categorize

9. Re: math:gcd is incorrect

At the level of writing a division algorithm for a computer language, it is the slowest compared to add, subtract, or multiply.
It is therefore handled thusly:

If Left_Arg = Right_Arg, then return 1 and exit.
If Right_Arg = 0, then return sign of Left_Arg on infinity symbol and exit.

Proceed normally with division.

new topic     » goto parent     » topic index » view message » categorize

10. Re: math:gcd is incorrect

Is EUWX a troll, an APL has been, or just Somebody making things up?

This is do it fast, DO IT WRONG.

new topic     » goto parent     » topic index » view message » categorize

11. Re: math:gcd is incorrect

EUWX is saying

'Because I prefer ...'

Because I prefer 0/0 = 1

I prefer it when: 
 
 0 * 2     0      
 _____  =  _  =  1 * 2 = 2 
 
   0       0              
    
and  0 * 2  = 0 
              _  = 1   
 
	      0  

Should any person take notice of him?

new topic     » goto parent     » topic index » view message » categorize

12. Re: math:gcd is incorrect

I don't know exactly what you mean by "a troll".
You mentioned "APL has been".
I discovered that there is a current APL standard
ISO/IEC 13751 Extended APL
A commercial version of APL is available but costs a lot of money. However, it is free for students
http://www.microapl.co.uk/apl/
I also discovered that there is a company jsoftware, which has a version based on these standards
http://www.jsoftware.com/
A quick look it suggests it is a free download. I haven't tried it.

I am not sure how many institutions use Euphoria
The following are a few of the corporate and academic institutions that use J:

Cognos · Bayesian Enhanced Strategic Trading · Fax Focus, Inc. · Hewlett Packard · Intel · Korea Telecom · Luen Thai · Maple Partners · Microsoft · Niagara Mohawk Power · Nikko Securities · Novell · Okada Denki Co. Ltd. · Pivotal Technologies · Syngenesis, Inc.

Duke University · Harvard School of Public Health · Keio University · Lafayette College · Penn State University · Rochester Institute of Technology · Thompson Rivers University · Trinity University · University of Alberta · UCLA · University of Florida · University of Haifa · University of Houston · University of Iowa · University of Massachusetts (Amherst) · University of Wisconsin

There is conference on 24th July, 2012 in Toronto on J software - if costs $1200 to attend.

There is also a long standing statistical package written in APL called SPSS by IBM. It looks to me like a very sophisticated statistics package
http://www-01.ibm.com/software/analytics/spss/products/statistics/advanced-statistics/

There is at totally free version of APL called NARS APL, which is said to be fully compliant of the ISO/IEC 13751 Extended APL standards. You can download and use it on your desktop and test out whatever you want to test. There is a Editor too. It is a Windows software
http://www.nars2000.org/
Even if you can't create the APL symbols you can still use it comfortably.

I am currently working on an application and trying to use wxEuphoria, and till yesterday, I had good help from some people here. I thought I had made a deep math related comment, which has a large amount of discussion on the Internet from math and computing experts.

Thanks for your sarcasm that lead me to discover all the above on APL, and I will now try and look at APL to see if I can do my project in that language.

new topic     » goto parent     » topic index » view message » categorize

13. Re: math:gcd is incorrect

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.

new topic     » goto parent     » topic index » view message » categorize

14. Re: math:gcd is incorrect

I simply said "I prefer 0/0 = 1"
Rightly or wrongly, that's what I was taught in grade 3 of school.
Many years later, in a computer class we had a discussion and we were told to adopt (rightly or wrongly) whatever attitude we chose to adopt.
When I saw the discussion, I googled and found many similar discussion of 0/0, and I quoted one.

I am not interested in relative merits of one language against another, nor do I want to prove or disprove anything you have to say regarding the result of infinity divided by infinity. You mentioned a language called APL and I researched and gave you the result of the validity of APL, and it surprised me too. For that also I have to thank Google.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu