<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>complex number divide by zero Archives - CenterSpace</title>
	<atom:link href="https://www.centerspace.net/tag/complex-number-divide-by-zero/feed" rel="self" type="application/rss+xml" />
	<link>https://www.centerspace.net/tag/complex-number-divide-by-zero</link>
	<description>.NET numerical class libraries</description>
	<lastBuildDate>Mon, 15 Feb 2010 18:06:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>
<site xmlns="com-wordpress:feed-additions:1">104092929</site>	<item>
		<title>Complex division by zero</title>
		<link>https://www.centerspace.net/complex-division-by-zero</link>
					<comments>https://www.centerspace.net/complex-division-by-zero#comments</comments>
		
		<dc:creator><![CDATA[Steve Sneller]]></dc:creator>
		<pubDate>Fri, 05 Dec 2008 18:31:31 +0000</pubDate>
				<category><![CDATA[Object-Oriented Numerics]]></category>
		<category><![CDATA[complex number divide by zero]]></category>
		<category><![CDATA[complex number division]]></category>
		<category><![CDATA[complex numbers]]></category>
		<category><![CDATA[computing with complex numbers]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=4</guid>

					<description><![CDATA[<p>An NMath customer submitted the following support question: I&#8217;m working on the primitives (NMathCoreShared.dll) and have found a rather odd &#8216;quirk&#8217; with complex division by zero: DoubleComplex aa = new DoubleComplex(0.0, 0.0); DoubleComplex bb = new DoubleComplex(5.2, -9.1); DoubleComplex cc = new DoubleComplex(); cc = bb/aa; Console.WriteLine(cc); // (NaN,NaN) double g = -5.0 / 0.0; [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/complex-division-by-zero">Complex division by zero</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>An NMath customer submitted the following support question:</p>
<blockquote><p>I&#8217;m working on the primitives (NMathCoreShared.dll) and have found a rather odd &#8216;quirk&#8217; with complex division by zero:</p>
<pre>DoubleComplex aa = new DoubleComplex(0.0, 0.0);
DoubleComplex bb = new DoubleComplex(5.2, -9.1);
DoubleComplex cc = new DoubleComplex();

cc = bb/aa;
Console.WriteLine(cc);  // (NaN,NaN)

double g = -5.0 / 0.0;
Console.WriteLine(g);   // -Infinity</pre>
<p>On my machine (Athlon FX), I get the value NaN back when I&#8217;m pretty sure it should be &#8216;Inf&#8217;?</p></blockquote>
<p>The code implementing complex division in the NMath complex number class does not check to see if the divisor is zero. It just applies the formula for complex division in terms of the operands&#8217; real and imaginary parts:</p>
<pre lang="eq.latex">\frac{a + bi}{c + di} = \frac{ac + bd}{c^2 + d^2} + i\frac{bc - ad}{c^2 + d^2}     (1)</pre>
<p>As you can see, when <em>c = d = 0 </em> both the real and imaginary components of the quotient take the form 0/0. Now the IEEE standard says that for real numbers <em>a/0</em>, <em>a</em> not equal to 0, should yield +∞ or -∞ where the sign depends on whether <em>a &gt; 0</em> or <em>a &lt; 0</em> and 0/0 should yield NaN (Not a Number). So a direct application of the formulas for division of complex number, without “special casing” the zero denominator case, will yield a result of (NaN, NaN).</p>
<p>One might be tempted to say “OK, that&#8217;s the end of that. (NaN, NaN) is obviously the correct behavior”. However, this does not set very well with intuition. If I have a fixed complex number <em>w</em> which is divided by another variable complex number <em>z</em>, it seems that as <em>z</em> gets smaller and smaller, the quotient should get bigger and bigger. There is a slight technicality here&#8211;there really is no notion of bigger and smaller for the complex number. That is, there is no ordering of the complex numbers that is consistent with its algebraic structure. In particular there is no notion of negative and positive complex numbers, so the concept of positive and negative infinity are not well defined. Let&#8217;s take a look at some theoretical stuff in the hopes it will help to guide our thinking.</p>
<p>Let&#8217;s start with something more familiar. What does it mean to divide a real number by zero? From a purely algebraic sense if <em>a</em> and <em>b</em> are two real numbers then the number <em>a ÷ b</em> is the solution to the equation <em>b * x = a</em>. When <em>b = 0</em> this equation has no solution and so the quotient is not defined (unless we extend the real numbers to include infinity and define algebraic operations that include infinity, but let&#8217;s not go there now as it isn&#8217;t really germane to our conversation). Where does infinity come in? Well, one can also look at the question from an analysis point of view, where one deals in functions and limits. With this perspective, given a real number <em>a</em> one defines a <em>division</em> function <em>f<sub>a</sub>(x) = a ÷ x</em>. This function is well defined for all <em>x</em> not equal to 0. But, analysis deals also with <em>limits</em>, and one would naturally ask what happens when <em>x</em> gets <em>close</em> to 0. The answer is as <em>x → 0, f<sub>a</sub> → ∞</em>. Formally, this means the following: Given any real number <em>M&gt;0</em>, there exists a corresponding real number <em>δ &gt; 0</em> such that |<em>fa </em>|<em> &gt; M</em> whenever |<em>x</em>|<em> &lt; δ</em>. Now, we can apply this definition to complex numbers since we have a notion of absolute value for complex numbers: if <em>z = a + ib</em> is a complex number, then the modulus of <em>z</em>, |<em>z</em>|, is defined as</p>
<pre lang="eq.latex">|z|=\sqrt{a^2 + b^2}</pre>
<p>That is it&#8217;s the euclidean distance from the point <em>z = (a,b)</em> to the origin in the complex plane. From this it is clear that as a complex number tends to zero, so must its real and imaginary parts. So as the denominator in equation (1) above tends to zero, so do its real and imaginary parts <em>c</em> and <em>d</em>. The fact that <em>c</em> and <em>d</em> are squared in the denominator of the real and imaginary parts of the quotient means that they will tend to zero faster than the their corresponding numerators and hence, using a L&#8217;Hôpital&#8217;s Rule based argument, or a straight <em>δ, M</em> based argument, we can see that both the real and imaginary parts of the quotient tend to infinity as the denominator tends towards zero. Whether it is positive or negative infinity is another question.</p>
<p>But enough theoretical talk. Let&#8217;s look at something concrete. Unlike C#, the standard C++ library includes a complex number class. What do they do when dividing by zero? Here&#8217;s the result I get with Microsoft&#8217;s C++ complex class:</p>
<p>Microsoft Visual C++ 15.0</p>
<pre>(1,1)/(0,0) = (1.#QNAN,1.#QNAN)
(0,0)/(0,0) = (1.#QNAN,1.#QNAN)
1/0 = 1.#INF
0/0 = -1.#IND</pre>
<p>Hmm. They seem to just apply the formulas and get 0/0 for the real and imaginary parts. How about the GNU C++ compiler?</p>
<p>g++ 4.3.2</p>
<pre>(1,1)/(0,0) = (inf,inf)
(0,0)/(0,0) = (nan,nan)
1/0 = inf
0/0 = nan</pre>
<p>Interesting. They return infinite real and imaginary parts. What&#8217;s more interesting is that the two compilers do not agree. And just for fun, here&#8217;s the result with the complex class included in Microsoft&#8217;s F# compiler:</p>
<p>F#</p>
<pre>(1,1)/(0,0) = NaNr+NaNi
(0,0)/(0,0) = NaNr+NaNi
1/0 = Infinity
0/0 = NaN</pre>
<p>No surprise here. At least Microsoft is consistent.</p>
<p>What does the GNU compiler do about positive and negative infinity in its results?</p>
<pre>(1,1)/(0,0) = (inf,inf)
(-1,-1)/(0,0) = (-inf,-inf)
(1,-1)/(0,0) = (inf,-inf)
(-1,1)/(0,0) = (-inf,inf)</pre>
<p>Apparently, they have adopted the convention that the sign of infinity in the real and imaginary parts of the quotient is the same as the signs of the real and imaginary parts of the numerator, respectively.</p>
<p>So, what should NMath do? On the one hand .NET is a Microsofty kind of thing, so maybe we should be consistent with their C++ implementation. On the other hand g++ is a widely distributed compiler and they seem to take the moral high road here. What would you do?</p>
<p>Steve</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/complex-division-by-zero">Complex division by zero</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/complex-division-by-zero/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4</post-id>	</item>
	</channel>
</rss>
