<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/1.5.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Computing graphics</title>
	<link>http://bit-player.org/2008/computing-graphics</link>
	<description>An amateur's outlook on computation and mathematics.</description>
	<pubDate>Fri, 25 Jul 2008 16:44:58 +0000</pubDate>
	<generator>http://wordpress.org/?v=1.5.2</generator>

	<item>
 		<title>Comment on Computing graphics by: Barry Cipra</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1603</link>
		<pubDate>Fri, 01 Feb 2008 15:58:02 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1603</guid>
					<description>We're clearly both wrong in thinking it is (or isn't) a hyperbola, since Hewes and Seward say it's *an* hyperbola....

My underlying point, if I have one, is that while it's relatively easy to see how the logarithmic scales on the three lines and the fact that the V line is twice as far from the D line as it is from the d line come from the formula for the volume of the torus (by the way, 2.4674 is a good approximation to (355/226)^2....), and obvious that the curves for the riveted joints are hyperbolae, it's not at all obvious, to me at least, how and why the last two nomograms work.  I had to derive the parameterization you quoted from Hewes and Seward.  (I did so before my initial post, so I actually did know the curve to be a hyperbola.  It's worth noting that the equation is 
y = 1-x-1/(1+x)
so in particular, the hyperbola does not have a horizontal asymptote -- it curves back down to the right of the q-line and back up to the left of the point corresponding to z=-2.)  As for the cubic-equation nomogram, can you tell (without looking it up!) what family of curves is being used?

On a quasi-related matter, I've always wondered how well drawn these old diagrams are.  Having scanned them into your computer, you should be able to superimpose properly scaled computer-generated versions of the same curves, using appropriate equations (e.g., the parameterizations x=-z/(1+z), y=-z^2/(1+z), etc.) to see if the draftsman's drawing departs visibly from computer's presumably correct rendition.  Some discrepancies could, of course, be due to distortions created in the scanning procedure, but even that would be of interest.</description>
		<content:encoded><![CDATA[	<p>We&#8217;re clearly both wrong in thinking it is (or isn&#8217;t) a hyperbola, since Hewes and Seward say it&#8217;s *an* hyperbola&#8230;.</p>
	<p>My underlying point, if I have one, is that while it&#8217;s relatively easy to see how the logarithmic scales on the three lines and the fact that the V line is twice as far from the D line as it is from the d line come from the formula for the volume of the torus (by the way, 2.4674 is a good approximation to (355/226)^2&#8230;.), and obvious that the curves for the riveted joints are hyperbolae, it&#8217;s not at all obvious, to me at least, how and why the last two nomograms work.  I had to derive the parameterization you quoted from Hewes and Seward.  (I did so before my initial post, so I actually did know the curve to be a hyperbola.  It&#8217;s worth noting that the equation is<br />
y = 1-x-1/(1+x)<br />
so in particular, the hyperbola does not have a horizontal asymptote &#8212; it curves back down to the right of the q-line and back up to the left of the point corresponding to z=-2.)  As for the cubic-equation nomogram, can you tell (without looking it up!) what family of curves is being used?</p>
	<p>On a quasi-related matter, I&#8217;ve always wondered how well drawn these old diagrams are.  Having scanned them into your computer, you should be able to superimpose properly scaled computer-generated versions of the same curves, using appropriate equations (e.g., the parameterizations x=-z/(1+z), y=-z^2/(1+z), etc.) to see if the draftsman&#8217;s drawing departs visibly from computer&#8217;s presumably correct rendition.  Some discrepancies could, of course, be due to distortions created in the scanning procedure, but even that would be of interest.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Computing graphics by: brian</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1602</link>
		<pubDate>Fri, 01 Feb 2008 04:25:27 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1602</guid>
					<description>@ Barry Cipra: I know the curve must be a hyperbola because the book says it is, and any high school student can tell you that the book is never wrong. Here's the passage in Hewes and Seward (with inconsequential reformatting):

&quot;The equation of the three scales may for convenience be written as follows: x = –z/(1+z), y = –z^2/(1+z) ; x = –1, y = p ; x = 0, y = q. The scale for z is then graduated on an hyperbola with the asymptote x = –1. Figure 48 is the diagram. No scale factors are used but the unit on the horizontal axis is taken 100 times that on the vertical axis, as this convenient device is always available. The roots are read at the points where the straight line through the given values of p and q on their respective scales, cuts this hyperbola graduated with z.&quot;

I renew my question: If we look at this curve and assume it has some reasonably concise mathematical definition, what could it be other than a hyperbola? I can't think of another plausible candidate, but perhaps I'm missing something obvious.</description>
		<content:encoded><![CDATA[	<p>@ Barry Cipra: I know the curve must be a hyperbola because the book says it is, and any high school student can tell you that the book is never wrong. Here&#8217;s the passage in Hewes and Seward (with inconsequential reformatting):</p>
	<p>&#8220;The equation of the three scales may for convenience be written as follows: x = –z/(1+z), y = –z^2/(1+z) ; x = –1, y = p ; x = 0, y = q. The scale for z is then graduated on an hyperbola with the asymptote x = –1. Figure 48 is the diagram. No scale factors are used but the unit on the horizontal axis is taken 100 times that on the vertical axis, as this convenient device is always available. The roots are read at the points where the straight line through the given values of p and q on their respective scales, cuts this hyperbola graduated with z.&#8221;</p>
	<p>I renew my question: If we look at this curve and assume it has some reasonably concise mathematical definition, what could it be other than a hyperbola? I can&#8217;t think of another plausible candidate, but perhaps I&#8217;m missing something obvious.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Computing graphics by: brian</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1601</link>
		<pubDate>Fri, 01 Feb 2008 04:11:55 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1601</guid>
					<description>@ Carl Witty: I don't pretend to know what the Right Thing is. But if 0.5 is such a suspect value that you have to deliberately discard a bunch of perfectly good digits when you evaluate n(pi, digits=30) + 0.5, then I don't see how to justify the declaration 1/2==0.5. 

Of course there's also the irony that all this disputation began with a graphic device that provides an accuracy of no more than two decimal places. I'm sure Hewes and Seward would have been quite impressed by a method that gives an answer that begins to drift away from exactness in the 12th decimal place.</description>
		<content:encoded><![CDATA[	<p>@ Carl Witty: I don&#8217;t pretend to know what the Right Thing is. But if 0.5 is such a suspect value that you have to deliberately discard a bunch of perfectly good digits when you evaluate n(pi, digits=30) + 0.5, then I don&#8217;t see how to justify the declaration 1/2==0.5. </p>
	<p>Of course there&#8217;s also the irony that all this disputation began with a graphic device that provides an accuracy of no more than two decimal places. I&#8217;m sure Hewes and Seward would have been quite impressed by a method that gives an answer that begins to drift away from exactness in the 12th decimal place.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Computing graphics by: Barry Cipra</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1600</link>
		<pubDate>Fri, 01 Feb 2008 03:39:06 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1600</guid>
					<description>&quot;What makes you think it’s not?&quot;

What makes you think I think it's not?</description>
		<content:encoded><![CDATA[	<p>&#8220;What makes you think it’s not?&#8221;</p>
	<p>What makes you think I think it&#8217;s not?
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Computing graphics by: Carl Witty</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1599</link>
		<pubDate>Fri, 01 Feb 2008 02:09:22 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1599</guid>
					<description>I'm a beginner at this computer algebra stuff; I just happen to know a little bit about Sage (and a lot about this part of Sage).

I don't know if it's a good idea that (0.5 == 1/2) when they don't act the same.  I am pretty sure that it's a good idea that (2 == 4/2), even though they don't act exactly the same (in Sage, 2 is of type Integer, and 4/2 is of type Rational).

I do think it makes sense that multiplying floating-point numbers of different precisions should give a result of the lesser precision, and that multiplying a floating-point number by an integer should give a floating-point number of the same precision as the input.  I suppose an argument could be made for using a more complicated rule in the case of addition (if you have 1000 as a 10-bit float, and 1 as a 1-bit float, then it could make sense that their sum would be 1001 as a 10-bit float); but using the same rule for addition and multiplication makes things a lot simpler.

Mathematica actually seems to have roughly similar rules to Sage, based on the following experiments:

sage: n(pi, digits=30) + 1/2
3.64159265358979323846264338328
sage: n(pi, digits=30) + 0.5
3.64159265358979

In[1]:= N[Pi, 30] + 1/2
Out[1]= 3.64159265358979323846264338328
In[2]:= N[Pi, 30] + 0.5
Out[2]= 3.64159

We see that Mathematica defaults to using many fewer bits for the literal 0.5, but both systems treat 0.5 as being a limited-precision float, and 1/2 (in this context) as being essentially infinite precision.

Based on this experiment, I'm guessing that if you wrote the equivalent Newton's method code in Mathematica, you would get essentially the same result as in Sage, where a 0.5 would make the whole computation less precise.

If you invoke an explicit polynomial root-finder in Sage, then you do get the same results whether you use 0.5 or 1/2; this is because it coerces the coefficients to high precision floats at the start.

sage: z = polygen(RR)
sage: (z^3 + 4*z^2 - 4*z + 0.5).roots(ring=RealField(100))

[(-4.8466058702392431715989808960, 1),
 (0.14758497342621353660341004967, 1),
 (0.69902089681302963499557084630, 1)]
sage: (z^3 + 4*z^2 - 4*z + 1/2).roots(ring=RealField(100))

[(-4.8466058702392431715989808960, 1),
 (0.14758497342621353660341004967, 1),
 (0.69902089681302963499557084630, 1)]</description>
		<content:encoded><![CDATA[	<p>I&#8217;m a beginner at this computer algebra stuff; I just happen to know a little bit about Sage (and a lot about this part of Sage).</p>
	<p>I don&#8217;t know if it&#8217;s a good idea that (0.5 == 1/2) when they don&#8217;t act the same.  I am pretty sure that it&#8217;s a good idea that (2 == 4/2), even though they don&#8217;t act exactly the same (in Sage, 2 is of type Integer, and 4/2 is of type Rational).</p>
	<p>I do think it makes sense that multiplying floating-point numbers of different precisions should give a result of the lesser precision, and that multiplying a floating-point number by an integer should give a floating-point number of the same precision as the input.  I suppose an argument could be made for using a more complicated rule in the case of addition (if you have 1000 as a 10-bit float, and 1 as a 1-bit float, then it could make sense that their sum would be 1001 as a 10-bit float); but using the same rule for addition and multiplication makes things a lot simpler.</p>
	<p>Mathematica actually seems to have roughly similar rules to Sage, based on the following experiments:</p>
	<p>sage: n(pi, digits=30) + 1/2<br />
3.64159265358979323846264338328<br />
sage: n(pi, digits=30) + 0.5<br />
3.64159265358979</p>
	<p>In[1]:= N[Pi, 30] + 1/2<br />
Out[1]= 3.64159265358979323846264338328<br />
In[2]:= N[Pi, 30] + 0.5<br />
Out[2]= 3.64159</p>
	<p>We see that Mathematica defaults to using many fewer bits for the literal 0.5, but both systems treat 0.5 as being a limited-precision float, and 1/2 (in this context) as being essentially infinite precision.</p>
	<p>Based on this experiment, I&#8217;m guessing that if you wrote the equivalent Newton&#8217;s method code in Mathematica, you would get essentially the same result as in Sage, where a 0.5 would make the whole computation less precise.</p>
	<p>If you invoke an explicit polynomial root-finder in Sage, then you do get the same results whether you use 0.5 or 1/2; this is because it coerces the coefficients to high precision floats at the start.</p>
	<p>sage: z = polygen(RR)<br />
sage: (z^3 + 4*z^2 - 4*z + 0.5).roots(ring=RealField(100))</p>
	<p>[(-4.8466058702392431715989808960, 1),<br />
 (0.14758497342621353660341004967, 1),<br />
 (0.69902089681302963499557084630, 1)]<br />
sage: (z^3 + 4*z^2 - 4*z + 1/2).roots(ring=RealField(100))</p>
	<p>[(-4.8466058702392431715989808960, 1),<br />
 (0.14758497342621353660341004967, 1),<br />
 (0.69902089681302963499557084630, 1)]
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Computing graphics by: brian</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1598</link>
		<pubDate>Fri, 01 Feb 2008 00:33:30 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1598</guid>
					<description>I don't want to make trouble, and I know I'm in over my head, but....

If 0.5 and 1/2 aren't truly equal--if you can't substitute one for the other in all contexts--is it a good idea for (0.5 == 1/2) to claim they are equivalent?

More important, why *aren't* they equal? In 53 bits or any other floating-point representation, 0.5 and 1/2 both have an exact binary representation, namely 0.100.... 

I've just looked around at the way a few other systems deal with this issue. In both Common Lisp and Scheme (my home turf), (= 1/2 0.5) is true, but (= 1/10 0.1) is false (because decimal 1/10 has no exact finite representation in binary). In Mathematica, both of the corresponding expressions are true, which is also the case in Sage; these systems are evidently smart enough to figure out that the two notations refer to the same number. The difference is that Mathematica seems to be more consistent about treating the quantities as equals. Solving our little cubic equation in Mathematica gives the same (correct) result whether the constant term is expressed as 0.5 or 1/2.

What's going on in Sage that 0.5 and 1/2 are the same when I run a direct comparison but they behave differently in the context of the Newton's method algorithm?

Let me add one final point: It's just this sort of difficulty that makes me grateful I don't design highway bridges, or anything else that lives depend on.</description>
		<content:encoded><![CDATA[	<p>I don&#8217;t want to make trouble, and I know I&#8217;m in over my head, but&#8230;.</p>
	<p>If 0.5 and 1/2 aren&#8217;t truly equal&#8211;if you can&#8217;t substitute one for the other in all contexts&#8211;is it a good idea for (0.5 == 1/2) to claim they are equivalent?</p>
	<p>More important, why *aren&#8217;t* they equal? In 53 bits or any other floating-point representation, 0.5 and 1/2 both have an exact binary representation, namely 0.100&#8230;. </p>
	<p>I&#8217;ve just looked around at the way a few other systems deal with this issue. In both Common Lisp and Scheme (my home turf), (= 1/2 0.5) is true, but (= 1/10 0.1) is false (because decimal 1/10 has no exact finite representation in binary). In Mathematica, both of the corresponding expressions are true, which is also the case in Sage; these systems are evidently smart enough to figure out that the two notations refer to the same number. The difference is that Mathematica seems to be more consistent about treating the quantities as equals. Solving our little cubic equation in Mathematica gives the same (correct) result whether the constant term is expressed as 0.5 or 1/2.</p>
	<p>What&#8217;s going on in Sage that 0.5 and 1/2 are the same when I run a direct comparison but they behave differently in the context of the Newton&#8217;s method algorithm?</p>
	<p>Let me add one final point: It&#8217;s just this sort of difficulty that makes me grateful I don&#8217;t design highway bridges, or anything else that lives depend on.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Computing graphics by: Carl Witty</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1597</link>
		<pubDate>Thu, 31 Jan 2008 22:48:24 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1597</guid>
					<description>I had almost the same questions a few months ago...

The Sage coercion rules (for doing arithmetic and comparisons between values of different types) include the following:

1) In operations between different types, if one type is more precise than the other, the more precise value is coerced to the less precise type and then the operation is performed at the less precise type.  (This is similar to the rules for significant figures I learned in school.)

2) Floating-point literals default to 53-bit precision (the precision of an IEEE double-precision floating-point value) (unless the floating-point literal is specified with many digits; then it uses enough bits to account for all the given digits).

This root-finder tries to do everything in 80-bit precision, but it is &quot;poisoned&quot; by the 53-bit &quot;0.5&quot;.  So most of the arithmetic is actually done with 53-bit precision, which explains your inaccurate results.

The above rules also explain (0.5 == 1/2); the infinitely-precise 1/2 is coerced to a floating-point 0.5, and then the comparison says that the two values are equal.

These rules give results that are sometimes counter-intuitive (as you've seen), but usually they work well, and we haven't been able to come up with better rules.</description>
		<content:encoded><![CDATA[	<p>I had almost the same questions a few months ago&#8230;</p>
	<p>The Sage coercion rules (for doing arithmetic and comparisons between values of different types) include the following:</p>
	<p>1) In operations between different types, if one type is more precise than the other, the more precise value is coerced to the less precise type and then the operation is performed at the less precise type.  (This is similar to the rules for significant figures I learned in school.)</p>
	<p>2) Floating-point literals default to 53-bit precision (the precision of an IEEE double-precision floating-point value) (unless the floating-point literal is specified with many digits; then it uses enough bits to account for all the given digits).</p>
	<p>This root-finder tries to do everything in 80-bit precision, but it is &#8220;poisoned&#8221; by the 53-bit &#8220;0.5&#8243;.  So most of the arithmetic is actually done with 53-bit precision, which explains your inaccurate results.</p>
	<p>The above rules also explain (0.5 == 1/2); the infinitely-precise 1/2 is coerced to a floating-point 0.5, and then the comparison says that the two values are equal.</p>
	<p>These rules give results that are sometimes counter-intuitive (as you&#8217;ve seen), but usually they work well, and we haven&#8217;t been able to come up with better rules.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Computing graphics by: Jesse</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1596</link>
		<pubDate>Thu, 31 Jan 2008 22:47:51 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1596</guid>
					<description>Cool stuff.</description>
		<content:encoded><![CDATA[	<p>Cool stuff.
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Computing graphics by: brian</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1595</link>
		<pubDate>Thu, 31 Jan 2008 21:24:06 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1595</guid>
					<description>@ Carl Witty: When you pointed out the error, my first thought was that I must have been too lax in setting the tolerance of the algorithm, or something equally careless. But apparently that's not the problem.

The root-finder code comes from here: https://www.sagenb.org/home/pub/1500

And here is how I defined the polynomial we're trying to evaluate:

f(x) = x^3 + 4*x^2 - 4*x + 0.5

I'm still very much a Sage neophyte, and it took me a little while to sniff out what's wrong with that definition. The root-finder code returns correct results for *this* polynomial:

f(x) = x^3 + 4*x^2 - 4*x + 1/2

So it appears we have a simple case of inaccuracy introduced by floating-point truncation. What I don't understand, though, is that Sage tells me (0.5==1/2) returns True.

As I said, I'm a Sage newbie, so enlightenment is welcome!</description>
		<content:encoded><![CDATA[	<p>@ Carl Witty: When you pointed out the error, my first thought was that I must have been too lax in setting the tolerance of the algorithm, or something equally careless. But apparently that&#8217;s not the problem.</p>
	<p>The root-finder code comes from here: <a href='https://www.sagenb.org/home/pub/1500' rel='nofollow'>https://www.sagenb.org/home/pub/1500</a></p>
	<p>And here is how I defined the polynomial we&#8217;re trying to evaluate:</p>
	<p>f(x) = x^3 + 4*x^2 - 4*x + 0.5</p>
	<p>I&#8217;m still very much a Sage neophyte, and it took me a little while to sniff out what&#8217;s wrong with that definition. The root-finder code returns correct results for *this* polynomial:</p>
	<p>f(x) = x^3 + 4*x^2 - 4*x + 1/2</p>
	<p>So it appears we have a simple case of inaccuracy introduced by floating-point truncation. What I don&#8217;t understand, though, is that Sage tells me (0.5==1/2) returns True.</p>
	<p>As I said, I&#8217;m a Sage newbie, so enlightenment is welcome!
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Computing graphics by: Carl Witty</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1594</link>
		<pubDate>Thu, 31 Jan 2008 18:10:33 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1594</guid>
					<description>I'm curious how you got those roots, since only about half the digits are correct.  More-precise values (with all digits correct) for the three roots of this polynomial are: -4.84660587023924317159898089597, 0.147584973426213536603410049667, and 0.699020896813029634995570846304.

(As a Sage developer, I'm particularly curious, because if Sage gave you those wrong answers then that's a bug I want to fix.)</description>
		<content:encoded><![CDATA[	<p>I&#8217;m curious how you got those roots, since only about half the digits are correct.  More-precise values (with all digits correct) for the three roots of this polynomial are: -4.84660587023924317159898089597, 0.147584973426213536603410049667, and 0.699020896813029634995570846304.</p>
	<p>(As a Sage developer, I&#8217;m particularly curious, because if Sage gave you those wrong answers then that&#8217;s a bug I want to fix.)
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Computing graphics by: brian</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1593</link>
		<pubDate>Thu, 31 Jan 2008 17:10:27 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1593</guid>
					<description>What makes you think it's not? What are the alternatives?</description>
		<content:encoded><![CDATA[	<p>What makes you think it&#8217;s not? What are the alternatives?
</p>
]]></content:encoded>
				</item>
	<item>
 		<title>Comment on Computing graphics by: Barry Cipra</title>
		<link>http://bit-player.org/2008/computing-graphics#comment-1592</link>
		<pubDate>Thu, 31 Jan 2008 16:53:15 +0000</pubDate>
		<guid>http://bit-player.org/2008/computing-graphics#comment-1592</guid>
					<description>What makes you think the curve in the nomogram for the quadratic equation is a hyperbola?</description>
		<content:encoded><![CDATA[	<p>What makes you think the curve in the nomogram for the quadratic equation is a hyperbola?
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
