Converting float to algebraic number - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Converting float to algebraic number (/thread-7769.html) |
Converting float to algebraic number - Han - 02-14-2017 03:03 PM Useless trivia for the day... Let \( n \) be in decimal representation. To find an (\( a + \sqrt{b} \))-approximation of \( n \), i.e. find integers \(a\) and \( b \) such that \( n = a+ \sqrt{b} \), we can use the following simple idea. Since \( (n-a)^2 = b \), we simply check whether any of the values among \[ n^2, (n-1)^2, (n-2)^2, \dotsm, (n-\lfloor n \rfloor)^2 \] are integers. Code: export algn(x) Example: X:=1+8^.5; algn(X); // -----> { 1, 8 } representing \( 1 + \sqrt{8} \) RE: Converting float to algebraic number - parisse - 02-14-2017 04:56 PM If a and b are not too large, there is a more general algorithm that works for (a+b*sqrt(c))/d: find the continued fraction expansion and detect periodicity. |