Square Root: Digit by Digit Algorithm
11-25-2022, 10:59 AM
Post: #5
 Thomas Klemm Senior Member Posts: 2,104 Joined: Dec 2013
RE: Square Root: Digit by Digit Algorithm
(11-25-2022 09:30 AM)brouhaha Wrote:  if there's a fixed-length field that specifies the length of the variable-length number, then there is an implementation limit, though it might be bigger than the amount of DRAM in existence.

As a playground I recommend to use an online Jupyter-Lab.
There mpmath is preinstalled.

Code:
from mpmath import *

The Naïve Way

Code:
mp.dps = 10 a = sqrt(2) b = log(a) a, b

(mpf('1.41421356237'), mpf('0.3465735902791'))

Code:
mp.dps = 100 a, b

(mpf('1.414213562369695864617824554443359375'),
mpf('0.3465735902791493572294712066650390625'))

First I was surprised but then I noticed: nah, that aren't 100 digits.

The Lazy Way

Using functions as numbers we can postpone the evaluation.

Code:
mp.dps = 10 a = lambda: sqrt(2) b = lambda: log(a()) a(), b()

(mpf('1.41421356237'), mpf('0.3465735902791'))

Code:
mp.dps = 100 a(), b()

(mpf('1.414213562373095048801688724209698078569671875376948073176679737990732478​462107038850387534327641572735'),
mpf('0.3465735902799726547086160607290882840377500671801276270603400047466968109​848473578029316634982093437698'))

The usage is rather clumsy but could be improved by wrapping these "lazy numbers" in a class.
Digits that have been calculated could be cached.

(11-25-2022 09:30 AM)brouhaha Wrote:  Egbert said "in current computers numbers can be expressed only to a limited number of digits", implying the possibility of computers in some other era (as opposed to "current") that can express numbers to an unlimited number of digits. I can't even begin to imagine how that could be done.

You enter 2 and press the √ button.
And then you die before reading all the digits.
 « Next Oldest | Next Newest »

 Messages In This Thread Square Root: Digit by Digit Algorithm - Thomas Klemm - 11-25-2022, 06:02 AM RE: Square Root: Digit by Digit Algorithm - brouhaha - 11-25-2022, 06:33 AM RE: Square Root: Digit by Digit Algorithm - Thomas Klemm - 11-25-2022, 07:51 AM RE: Square Root: Digit by Digit Algorithm - brouhaha - 11-25-2022, 09:30 AM RE: Square Root: Digit by Digit Algorithm - BruceH - 11-27-2022, 10:44 PM RE: Square Root: Digit by Digit Algorithm - Thomas Klemm - 11-25-2022 10:59 AM RE: Square Root: Digit by Digit Algorithm - Albert Chan - 11-25-2022, 02:28 PM RE: Square Root: Digit by Digit Algorithm - Thomas Klemm - 11-25-2022, 11:57 AM RE: Square Root: Digit by Digit Algorithm - ttw - 11-25-2022, 02:40 PM RE: Square Root: Digit by Digit Algorithm - Albert Chan - 11-25-2022, 03:48 PM RE: Square Root: Digit by Digit Algorithm - EdS2 - 11-25-2022, 05:31 PM RE: Square Root: Digit by Digit Algorithm - Thomas Klemm - 11-25-2022, 07:05 PM RE: Square Root: Digit by Digit Algorithm - Thomas Klemm - 11-26-2022, 01:15 PM RE: Square Root: Digit by Digit Algorithm - ttw - 11-27-2022, 07:34 PM

User(s) browsing this thread: 1 Guest(s)