November 26, 2013
On Monday, 25 November 2013 at 08:18:43 UTC, Joseph Rushton Wakeling wrote:
> But if you just think of 0 as a number, then
>
> 0 * lim{x --> inf} x
>              = lim{x --> inf} (0 * x)

This is where your argument falls apart, as mathematically, you can't do that unless lim{x --> inf} x is well-defined.

See also: http://en.wikipedia.org/wiki/Riemann_sphere

David

November 26, 2013
On 11/26/13 3:22 AM, Joseph Rushton Wakeling wrote:
> So, as other people have suggested, really the only thing we can
> reasonably do is to define a separate Imaginary type

I agree. Let's move forward with this.

Thanks,

Andrei
November 26, 2013
On 26/11/13 17:11, David Nadlinger wrote:
> On Monday, 25 November 2013 at 08:18:43 UTC, Joseph Rushton Wakeling wrote:
>> But if you just think of 0 as a number, then
>>
>> 0 * lim{x --> inf} x
>>              = lim{x --> inf} (0 * x)
>
> This is where your argument falls apart, as mathematically, you can't do that
> unless lim{x --> inf} x is well-defined.

I was using a very lazy shorthand there, I'm glad someone thought to call me on it.  Can we take it as read that I was basically thinking of a sequence {x_n} such that for every K there is an N such that for n > N, x_n > K ... ? :-)

And then you have

    0 * lim{n --> inf} x_n = ... etc.

The fun stuff must surely arrive when you want to show this kind of stuff in the context of real numbers being defined as equivalence classes of infinite sequences of rationals, à la Cauchy ...

> See also: http://en.wikipedia.org/wiki/Riemann_sphere

I don't recall ever actually studying the Riemann sphere, which really seems to me like a gap in my education :-\

November 26, 2013
On 11/26/13 7:13 AM, Dmitry Olshansky wrote:
> 26-Nov-2013 09:06, Daniel Murphy пишет:
>> "Dmitry Olshansky" <dmitry.olsh@gmail.com> wrote in message
>> news:l6tfm8$2hnj$1@digitalmars.com...
>>>>
>>>
>>> Can't it just check for the real part being exactly zero and special-
>>> case
>>> multiplication for that?
>>>
>>
>> There is no such thing as exactly zero in floating point.  Only -0 and
>> +0.
>
> Well, let it be magnitude, "exactly" implies as good zero test as we
> need. I'm still of the opinion that a few predictable branches like
> `if(rhs.re.isZero)` won't kill it.
>
> Regardless, the point is that built-ins hardly help here at all as you
> may just as well get an "exactly" 0+1i for some complex computation, and
> the result won't suddenly change type to i{real,double,float}.

I think the problem is we currently don't have a means to distinguish between two cases:

(a) "There is no real part here at all"

(b) "There is a real part that happens to be zero, or really as close to zero as it can ever get in a discrete representation"

It seems the two cases behave differently in a few corner cases, and that is reasonable.


Andrei

November 26, 2013
On Tuesday, 26 November 2013 at 16:30:30 UTC, Joseph Rushton Wakeling wrote:
> On 26/11/13 17:11, David Nadlinger wrote:
>> On Monday, 25 November 2013 at 08:18:43 UTC, Joseph Rushton Wakeling wrote:
>>> But if you just think of 0 as a number, then
>>>
>>> 0 * lim{x --> inf} x
>>>             = lim{x --> inf} (0 * x)
>>
>> This is where your argument falls apart, as mathematically, you can't do that
>> unless lim{x --> inf} x is well-defined.
>
> I was using a very lazy shorthand there, I'm glad someone thought to call me on it.  Can we take it as read that I was basically thinking of a sequence {x_n} such that for every K there is an N such that for n > N, x_n > K ... ? :-)
>
> And then you have
>
>     0 * lim{n --> inf} x_n = ... etc.

x_n = n actually fulfils that property, and I think most people would understand the limit notation for real numbers exactly the way you intended.

But that was not my point. To be able to write "lim{n --> inf} x_n" in a meaningful way (and consequently »pull in« the multiplication), a (or as it turns out, the) limit must exist in the metric space you are working in.

If your metric space contains ∞, and it has the property that 0 . ∞ = 0, then your argument is correct. But such a symbol ∞ does not exist in the real numbers.

I guess it might help to think back to your first university-level analysis courses, where I'm sure these distinctions were discussed many times in proofs concerning the existence of limits, e.g. integrability of certain functions, …

>> See also: http://en.wikipedia.org/wiki/Riemann_sphere
>
> I don't recall ever actually studying the Riemann sphere, which really seems to me like a gap in my education :-\

Well, the reason I bring this up is that what the »right« behavior is all comes down to the definition of your numerical system.

IEEE 754 includes infinity as an actual value, contrary to the usual definition of real numbers in mathematics. However, it also distinguishes between +∞ and -∞, so it can't model the Riemann sphere, which is one of the most straightforward ways to perform the extension of the complex plane with a concept infinity in mathematics.

David
November 26, 2013
On 2013-11-26 12:55:26 +0000, Joseph Rushton Wakeling said:

> Sounds very cool.  What kind of stuff will you be working on?

Who knows.  Haven't even finished my apps yet.  The deadline is in a couple weeks :)

November 27, 2013
On 26/11/13 22:11, David Nadlinger wrote:
> x_n = n actually fulfils that property, and I think most people would understand
> the limit notation for real numbers exactly the way you intended.
>
> But that was not my point. To be able to write "lim{n --> inf} x_n" in a
> meaningful way (and consequently »pull in« the multiplication), a (or as it
> turns out, the) limit must exist in the metric space you are working in.
>
> If your metric space contains ∞, and it has the property that 0 . ∞ = 0, then
> your argument is correct. But such a symbol ∞ does not exist in the real numbers.
>
> I guess it might help to think back to your first university-level analysis
> courses, where I'm sure these distinctions were discussed many times in proofs
> concerning the existence of limits, e.g. integrability of certain functions, …

Well, it has been 12+ years ... :-P  Still, it's very, very annoying when one misplaces fundamental stuff like that.  Thank you for reminding me :-)

Now I need to dust off my copy of "What is Mathematics?" ...

> Well, the reason I bring this up is that what the »right« behavior is all comes
> down to the definition of your numerical system.
>
> IEEE 754 includes infinity as an actual value, contrary to the usual definition
> of real numbers in mathematics. However, it also distinguishes between +∞ and
> -∞, so it can't model the Riemann sphere, which is one of the most
> straightforward ways to perform the extension of the complex plane with a
> concept infinity in mathematics.

I'm sure you've heard that old anecdote of the professor back in the 1950s, or was it the 1920s, who, on hearing a student say "infinity", said: "I won't have bad language in class!" :-)

November 27, 2013
On 2013-11-27 09:14:04 +0000, Joseph Rushton Wakeling said:

> I'm sure you've heard that old anecdote of the professor back in the 1950s, or was it the 1920s, who, on hearing a student say "infinity", said: "I won't have bad language in class!" :-)

Yes.  I think that's part of the reason 0 • inf = NaN in IEEE.   The values are taken to be limits of unknown functions.  Thus 0 * inf is uncalculable without knowing those functions.   There is no such thing as the value infinity.

November 27, 2013
On 26/11/13 17:28, Andrei Alexandrescu wrote:
> On 11/26/13 3:22 AM, Joseph Rushton Wakeling wrote:
>> So, as other people have suggested, really the only thing we can
>> reasonably do is to define a separate Imaginary type
>
> I agree. Let's move forward with this.

I've started work, code is here:
https://github.com/WebDrake/phobos/tree/imaginary

Feedback, forks/pull requests, etc. welcome.
November 28, 2013
On Wed, Nov 27, 2013 at 11:29:55PM +0100, Joseph Rushton Wakeling wrote:
> On 26/11/13 17:28, Andrei Alexandrescu wrote:
> >On 11/26/13 3:22 AM, Joseph Rushton Wakeling wrote:
> >>So, as other people have suggested, really the only thing we can reasonably do is to define a separate Imaginary type
> >
> >I agree. Let's move forward with this.
> 
> I've started work, code is here: https://github.com/WebDrake/phobos/tree/imaginary
> 
> Feedback, forks/pull requests, etc. welcome.

For the benefit of others:

If you already have a Phobos fork on github, forking this repo won't do anything. What you need to do in that case is to add this repo as a remote, then fetch the 'imaginary' branch and check it out, like this:

	# Add this repo as a new remote named 'webdrake'
	git remote add webdrake https://github.com/WebDrake/phobos.git

	# Fetch the branch named 'imaginary' into webdrake/imaginary
	git fetch webdrake imaginary

	# Checkout the fetched branch into a local branch named
	# 'imaginary' (you can name this whatever you like, it doesn't
	# matter)
	git checkout -b imaginary webdrake/imaginary

Now you can review / edit the code, push to origin (github), and then submit pull requests (make sure to target the WebDrake repo when submitting the pull, since otherwise it will go to Phobos master by default, which is probably not what you want).


T

-- 
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan