Talk:Square root algorithms: Difference between revisions

Content deleted Content added
minor grammar errors - replaced "has me published" by
Update archiving templates after a page move (Report bot issues)
 
(35 intermediate revisions by 21 users not shown)
Line 1:
{{User:MiszaBot/config
| algo = old(90d360d)
| archive = Talk:MethodsSquare ofroot computing square rootsalgorithms/Archive %(counter)d
| counter = 1
| maxarchivesize = 150K
| archiveheader = {{Automatic archive navigator}}
| minthreadstoarchive = 12
| minthreadsleft = 45
}}
{{WikiProject banner shell|class=C|
{{WikiProject Mathematics|importance= low}}
}}
{{Maths rating|class= Start|importance= low|field= analysis}}
{{archive box|auto=long}}
 
Line 27 ⟶ 29:
That cryptic constant is actually a composite of three bitfields, and twiddling it requires some understanding of what those fields are. It would be clearer, but a few more operations, to do that line as a pair of bitfield extract/inserts. But we're saving divides in the subsequent iterations, so the extra 1-cycle operations are a wash.
 
== Undefined behaviour ==
== "nearest perfect square" in Bakhshali method? ==
 
The examples using unions are invalid C, as they invoke undefined behaviour. An easy solution that is probably even clearer for the purpose of example code would be to use memcpy, e.g.
 
float f;
uint32_t u;
memcpy (&u, &f, sizeof (u));
 
[[Special:Contributions/37.49.68.13|37.49.68.13]] ([[User talk:37.49.68.13|talk]]) 13:08, 1 April 2022 (UTC)
 
:Type punning with unions is undefined in C++, but not in C. This is a topic of much confusion.
:The following is pulled from a footnote around section 6.5.2.3 of the C17 standard:
:"If the member used to read the contents of a union object is not the same as the member last used to store a value in the object, the appropriate part of the object representation of the value is reinterpreted as an object representation in the new type as described in 6.2.6 (a process sometimes called “type punning”). This might be a trap representation."
:This basically says, 'you may use a union to reinterpret the bits of one type into another but we're not going to promise that the new interpretation will be valid'
:I will say that the C code in this article is rather clunky and may benefit from a bitfield to separate the different sections of the float representation so it is easier to read and understand, but I will have to flatly disagree with you that <code>memcpy() </code>is more appropriate than a union in this code snippet. [[User:WillisHershey|WillisHershey]] ([[User talk:WillisHershey|talk]]) 17:24, 25 September 2023 (UTC)
 
== Lucas sequence method - original research? ==
 
I could not find any relevant research papers on the use of Lucas sequences for computing real square roots.
The example in the Bakhshali method has me confused. The initial guess is said to be "''x''<sub>0</sub><sup>2</sup> be the initial approximation to ''S''." The example uses <math>S = 125348</math>, and chooses <math> x_0 = 600 </math>. How can that be? <math>600^2 = 360000</math> and there are many perfect squares closer to ''S'', like 400 or 350.
The closest I found is
 
G. Adj and F. Rodríguez-Henríquez, "Square Root Computation over Even Extension Fields," in IEEE Transactions on Computers, vol. 63, no. 11, pp. 2829-2841, Nov. 2014, doi: 10.1109/TC.2013.145.
How is the initial guess ''really'' meant to be chosen? Unfortunately, the material here (in particular, this example) isn't well-referenced enough to explain how 600 meets the criteria given in the article. -- [[User:Mikeblas|Mikeblas]] ([[User talk:Mikeblas|talk]]) 21:06, 26 February 2020 (UTC)
 
which is concerned with square roots in finite fields and uses a different algorithm.
:The method does not require the initial guess to be the closest perfect square. This was only used to obtain a bound on the error. The 600 value is obtained in the above section on scalar estimates and was used as the initial guess in the previous example. --[[User:Wcherowi|Bill Cherowitzo ]] ([[User talk:Wcherowi|talk]]) 23:27, 26 February 2020 (UTC)
Should this paragraph be removed as original research?
Or it could also simply be made much shorter, by avoiding to repeat the properties of Lucas sequences. [[User:BlueRavel|BlueRavel]] ([[User talk:BlueRavel|talk]]) 23:27, 3 December 2023 (UTC)
 
: {{ping|BlueRavel}} I have searched, and I too failed to find any relevant source for this. It was posted into the article in 2009 without any explanation, by an editor who has never made any other substantial contribution, just one other very small edit. It looks as though it may well be original research, but whether it is or not, it is unsourced, so I have removed it. [[User:JBW|JBW]] ([[User talk:JBW|talk]]) 21:54, 5 December 2023 (UTC)
The article referenced [https://simplycurious.blog/2018/06/05/bucking-down-to-the-bakhshali-manuscript/ here] makes clear, by numerical example, that the initial guess does not need to be near the closest perfect square. <!-- Template:Unsigned --><span class="autosigned" style="font-size:85%;">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:Sramakrishna123|Sramakrishna123]] ([[User talk:Sramakrishna123#top|talk]] • [[Special:Contributions/Sramakrishna123|contribs]]) 22:10, 19 December 2020 (UTC)</span> <!--Autosigned by SineBot-->
 
== Merge "Approximations that depend on the floating point representation" into "Initial estimate" ==
== Square Root algorithm in 1965 Friden EC-132 Electronic Calculator ==
 
I believe the section "Approximations that depend on the floating point representation" should be merged into "Initial estimate", since it is a special case of "Binary estimates". Merging would clear up the fact that the floating point trick gives an initial rough approximation, which is then typically iteratively improved.
Early electronic calculator square root algorithms:
* https://www.oldcalculatormuseum.com/friden132.html
* https://www.oldcalculatormuseum.com/d-f132svcsqr.pdf
* https://docs.google.com/viewer?url=patentimages.storage.googleapis.com/pdfs/US3526760.pdf <!-- Template:Unsigned IP --><small class="autosigned">—&nbsp;Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/98.164.14.157|98.164.14.157]] ([[User talk:98.164.14.157#top|talk]]) 15:16, 6 October 2020 (UTC)</small> <!--Autosigned by SineBot-->
 
I also believe the "Initial estimate" section should appear after the section on Heron's method, as the reader is likely more interested in the general idea of iterative refinement than in the details of how to obtain a good initial estimate in all possible ways.
== Erroneous introduction ==
 
Additionally, in my opinion the entirety of the article could benefit from some trimming/rewriting, as many sections contain redundant information, unnecessary details, and awkward formulations. [[User:BlueRavel|BlueRavel]] ([[User talk:BlueRavel|talk]]) 14:54, 4 December 2023 (UTC)
The first paragraph of the article is this:
 
:: Your proposition makes sense to me, and I dont necessarily disagree. That said though, as a pure mathematician, I am uninclined to blur the lines between programmatical issues and mathematical problems. I think maintaining a distinction is appropriate. An analysis of the pure mathematical problem of initial estimation in these abstract reiterative processes is a decidedly distinct discussion from considerations in this programming language, or that programming language, or this architecture, or that architecture. The former is future-proofed, the latter is not. [[User:CogitoErgoCogitoSum|CogitoErgoCogitoSum]] ([[User talk:CogitoErgoCogitoSum|talk]]) 21:09, 11 February 2024 (UTC)
"'''''Methods of computing square roots''' are numerical analysis algorithms for finding the principal, or non-negative, [[square root]] (usually denoted {{sqrt|''S''}}, {{radic|''S''|2}}, or S<sup>1/2</sup>) of a real number. Arithmetically, it means given S, a procedure for finding a number which when multiplied by itself, yields S; algebraically, it means a procedure for finding the non-negative root of the equation x<sup>2</sup> - S = 0; geometrically, it means given the area of a square, a procedure for constructing a side of the square.''"
 
== Useful addition?? ==
I do not know much about numerical analysis. But I do know that this is totally misleading!
Not sure if its useful, but I have found that, in general, <math>\sqrt{x+2} \approx \frac{x+1}{\sqrt{x}}</math>, and if {{math|''x''{{=}}''n''{{sup|''2''}}}} we get <math>\sqrt{n^2+2} \approx n + \frac{1}{n}</math>.
 
Similarly <math>\sqrt{x+4} \approx \frac{x+2}{\sqrt{x}}</math>.
A "method for computing a square root" of a number does '''not''' mean a method for *finding* the square root of that number.
 
I sometimes use this for quick pencil and paper calculations, if Im close enough to a convenient value.
Instead, it means a method for '''approximating''' the square root of the number, usually to various degrees of accuracy.
 
Not sure if this is a known or established property, proven, bounded, or if its already in the article in some alternative capacity, or if its even appropriate for this article. I do know the taylor series approximation with two terms connects these expressions.
The distinction is '''essential''' to understanding what a "method for computing a square root" means. So the article should not mislead readers with an erroneous first paragraph.[[Special:Contributions/66.37.241.35|66.37.241.35]] ([[User talk:66.37.241.35|talk]]) 16:39, 7 October 2020 (UTC)
[[User:CogitoErgoCogitoSum|CogitoErgoCogitoSum]] ([[User talk:CogitoErgoCogitoSum|talk]]) 21:05, 11 February 2024 (UTC)
: There is nothing special about 2 and 4: <math>\sqrt{x+2c} \approx \frac{x+c}{\sqrt{x}}</math> provided that c is small compared to x. This is, in fact, just the first two terms of the series given in the article under the section heading "Taylor series". [[User:JBW|JBW]] ([[User talk:JBW|talk]]) 01:45, 13 February 2024 (UTC)
 
: I don't think they are useful. In the first, you have replaced a square root and an addition with a square root, an addition, and a division to get an approximate answer. [[User:Bubba73|Bubba73]] <sup>[[User talk:Bubba73|You talkin' to me?]]</sup> 08:02, 13 February 2024 (UTC)
:Is this not dealt with adequately in the second paragraph? [[User:JRSpriggs|JRSpriggs]] ([[User talk:JRSpriggs|talk]]) 17:05, 7 October 2020 (UTC)