OK, I give up. Especially since anyone who agrees with me can just In[895]:= Unprotect[GCD]; GCD[a_, b_] /; a/b ∉ Rationals = 0; In[896]:= GCD[1/6, 1/9] Out[896]= 1/18 In[897]:= {GCD[π, 1], GCD[1, π]} Out[897]= {0, 0} In[908]:= GCD[E,π] Out[908]= GCD[E, π] In[909]:= GCD[Sqrt[2], π] Out[909]= 0 Mma is surprisingly accommodating this way. E.g., Unprotect[Numerator, Denominator]; Numerator[ComplexInfinity] = 1; Denominator[ComplexInfinity] = 0; Off[Power::infy] Then if In[903]:= Clear[mediant]; mediant[a__] := Divide @@ (Plus @@ # & /@ {Numerator[{a}], Denominator[{a}]}) E.g., In[904]:= mediant[a/b, c/d, e/f] Out[904]= (a + c + e)/(b + d + f) you can In[907]:= mediant[0, 1/0] Out[907]= 1 which is acutally useful for Farey interpolation. --rwg
Hmm, this apparently presumes that the input fractions are reduced. 'Cause if say 2 divides both a and b, and we input (a/2)/(b/2) instead of a/b, this would output (a/2 + c + e)/(b/2 + d + f) -- not the same thing. --Dan On 2013-11-29, at 11:44 AM, Bill Gosper wrote:
In[904]:= mediant[a/b, c/d, e/f]
Out[904]= (a + c + e)/(b + d + f)
On Fri, Nov 29, 2013 at 11:44 AM, Bill Gosper <billgosper@gmail.com> wrote:
OK, I give up. Especially since anyone who agrees with me can just In[895]:= Unprotect[GCD]; GCD[a_, b_] /; a/b ∉ Rationals = 0;
In[896]:= GCD[1/6, 1/9]
Out[896]= 1/18
In[897]:= {GCD[π, 1], GCD[1, π]}
Out[897]= {0, 0}
In[908]:= GCD[E,π]
Out[908]= GCD[E, π]
In[909]:= GCD[Sqrt[2], π]
Out[909]= 0
[...]
ARGH! In[952]:= GCD[1198 - 197*I, 1147 + 398*I] Out[952]= 0 <Hasty retreat> In[953]:= Unprotect[GCD]; Clear[GCD]; GCD[1198 - 197*I, 1147 + 398*I] Out[953]= 16 + 19 I OK, how about Unprotect[GCD]; GCD[a_, b_] /; a/b \[NotElement] Rationals && a/b \[Element] Reals =0; In[1006]:= GCD[1198 + 197*I, 1147 + 398*I] Out[1006]= 25 + 42 I In[1007]:= GCD[1/6, 1/9] Out[1007]= 1/18 In[1008]:= GCD[E, 1] Out[1008]= 0 This time fer shure. --rwg
On 01/12/2013 05:06, Bill Gosper wrote:
ARGH!
In[952]:= GCD[1198 - 197*I, 1147 + 398*I]
Out[952]= 0 <Hasty retreat> ... Unprotect[GCD]; GCD[a_, b_] /; a/b \[NotElement] Rationals && a/b \[Element] Reals =0; In[1006]:= GCD[1198 + 197*I, 1147 + 398*I] ... This time fer shure. --rwg
So you don't want gcd(1, i pi) = 0? -- g
Julian just sent me a very annoying message, ALL UPPERCASE, and consistently placing e before i. Don't tell me that I'm being hypersensitive just because the message is only seven characters long: GCD[E,I]? Furthermore, his subtle exposure of my hypocrisy is ABSOLUTELY IRRELEVANT. My proposed diddle leaves GCD[E,I] unchanged. But it should be 0. Kosher GCD already extends to Gaussian rationals: In[1023]:= GCD[1/(1198 + 197*I), 1/(1147 + 398*I)] Out[1023]= 42/1474013 + (25 I)/1474013 In[1024]:= {1/(1198 + 197*I), 1/(1147 + 398*I)}/% Out[1024]= {19 - 16 I, 16 - 19 I} This follows, modulo powers of I, from extending Euclid's algorithm by defining Floor, Round, etc, to simply treat real and imaginary parts separately: In[1020]:= NestList[ Simplify[{#2, #1 - #2*Round[#1/#2]} & @@ #] &, {1/(1198 + 197*I), 1/(1147 + 398*I)}, 4] Out[1020]= {{1198/1474013 - (197 I)/1474013, 1147/1474013 - (398 I)/1474013}, {1147/1474013 - (398 I)/1474013, 51/1474013 + (201 I)/1474013}, {51/1474013 + (201 I)/ 1474013, -(59/1474013) - (92 I)/1474013}, {-(59/1474013) - (92 I)/ 1474013, 25/1474013 - (42 I)/1474013}, {25/1474013 - (42 I)/1474013, 0}} (This is consistent with my proposal for the reals.) Giving it E and I: In[1017]:= NestList[ Simplify[{#2, #1 - #2*Round[#1/#2]} & @@ #] &, {E, I}, 9] Out[1017]= {{E, I}, {I, -3 + E}, {-3 + E, I (-11 + 4 E)}, {I (-11 + 4 E), 19 - 7 E}, {19 - 7 E, I (-106 + 39 E)}, {I (-106 + 39 E), -193 + 71 E}, {-193 + 71 E, I (-1457 + 536 E)}, {I (-1457 + 536 E), 2721 - 1001 E}, {2721 - 1001 E, I (-25946 + 9545 E)}, {I (-25946 + 9545 E), -49171 + 18089 E}} In[1018]:= N[%] Out[1018]= {{2.71828, 0. + 1. I}, {0. + 1. I, -0.281718}, {-0.281718, 0. - 0.126873 I}, {0. - 0.126873 I, -0.0279728}, {-0.0279728, 0. + 0.0129913 I}, {0. + 0.0129913 I, -0.00199018}, {-0.00199018, 0. - 0.000939946 I}, {0. - 0.000939946 I, -0.000110288}, {-0.000110288, 0. + 0.0000526416 I}, {0. + 0.0000526416 I, -5.00433*10^-6}} resolutely seeking to vanish, as claimed. --rwg I "sent" this last night and it never went. Meanwhile, Gareth had the same thought: So you don't want gcd(1, i pi) = 0? -- g On Sat, Nov 30, 2013 at 9:06 PM, Bill Gosper <billgosper@gmail.com> wrote:
On Fri, Nov 29, 2013 at 11:44 AM, Bill Gosper <billgosper@gmail.com>wrote:
OK, I give up. Especially since anyone who agrees with me can just In[895]:= Unprotect[GCD]; GCD[a_, b_] /; a/b ∉ Rationals = 0;
In[896]:= GCD[1/6, 1/9]
Out[896]= 1/18
In[897]:= {GCD[π, 1], GCD[1, π]}
Out[897]= {0, 0}
In[908]:= GCD[E,π]
Out[908]= GCD[E, π]
In[909]:= GCD[Sqrt[2], π]
Out[909]= 0
[...]
ARGH!
In[952]:= GCD[1198 - 197*I, 1147 + 398*I]
Out[952]= 0 <Hasty retreat>
In[953]:= Unprotect[GCD]; Clear[GCD]; GCD[1198 - 197*I, 1147 + 398*I]
Out[953]= 16 + 19 I
OK, how about Unprotect[GCD]; GCD[a_, b_] /; a/b \[NotElement] Rationals && a/b \[Element] Reals =0; In[1006]:= GCD[1198 + 197*I, 1147 + 398*I]
Out[1006]= 25 + 42 I
In[1007]:= GCD[1/6, 1/9]
Out[1007]= 1/18
In[1008]:= GCD[E, 1]
Out[1008]= 0
This time fer shure. --rwg
GCD is really an operation on the lattice of ideals, and the Euclidean algorithm is merely a calculational device that is sometimes helpful. Rings such as Z[i], Z[(1+√-3)/2], Z[√2], and the other quadratic PIDs may be easy to handle. But in the general case, the GCD is nonprincipal, and there are things like Z[roots of monic irreducible quintic]. Question for the algebraic number theory experts: Does every nonprincipal ideal become principal in some extension of the ring? And if so, does the representation of this ideal as (some algebraic integer) remain the same as the ring is further extended, and all the way to the ring of all algebraic integers? A mathematically proper GCD is probably far too messy to justify the effort to put it into code. As for GCD(1,π), it is an ideal containing 1, and the only correct ring theoretic value, if you insist on a number, is 1. On the other hand, GCD(e,π) is the ideal (e,π) whatever the containing ring. I just cannot envision a situation where the GCD is zero. I'd say the best way to handle a recalcitrant GCD is to return it unevaluated. -- Gene
________________________________ From: Bill Gosper <billgosper@gmail.com> To: math-fun@mailman.xmission.com Sent: Saturday, November 30, 2013 9:06 PM Subject: Re: [math-fun] GCD[1,π]
On Fri, Nov 29, 2013 at 11:44 AM, Bill Gosper <billgosper@gmail.com> wrote:
OK, I give up. Especially since anyone who agrees with me can just In[895]:= Unprotect[GCD]; GCD[a_, b_] /; a/b ∉ Rationals = 0;
In[896]:= GCD[1/6, 1/9]
Out[896]= 1/18
In[897]:= {GCD[π, 1], GCD[1, π]}
Out[897]= {0, 0}
In[908]:= GCD[E,π]
Out[908]= GCD[E, π]
In[909]:= GCD[Sqrt[2], π]
Out[909]= 0
[...]
ARGH!
In[952]:= GCD[1198 - 197*I, 1147 + 398*I]
Out[952]= 0 <Hasty retreat>
In[953]:= Unprotect[GCD]; Clear[GCD]; GCD[1198 - 197*I, 1147 + 398*I]
Out[953]= 16 + 19 I
OK, how about Unprotect[GCD]; GCD[a_, b_] /; a/b \[NotElement] Rationals && a/b \[Element] Reals =0; In[1006]:= GCD[1198 + 197*I, 1147 + 398*I]
Out[1006]= 25 + 42 I
In[1007]:= GCD[1/6, 1/9]
Out[1007]= 1/18
In[1008]:= GCD[E, 1]
Out[1008]= 0
This time fer shure. --rwg
_______________________________________________ math-fun mailing list math-fun@mailman.xmission.com http://mailman.xmission.com/cgi-bin/mailman/listinfo/math-fun
participants (4)
-
Bill Gosper -
Dan Asimov -
Eugene Salamin -
Gareth McCaughan