Created
September 9, 2022 11:51
-
-
Save CodeDrome/a7c0ad88647094505cc66dad1b1d224c to your computer and use it in GitHub Desktop.
squarerootcalculations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import numpy as np | |
import squarerootestimates as sre | |
def babylonian_array(radicands, iterations): | |
estimates = sre.linear_2(radicands) | |
vfunc = np.vectorize(babylonian) | |
square_roots = vfunc(radicands, estimates, iterations) | |
return square_roots | |
def bakhshali_array(radicands, iterations): | |
estimates = sre.linear_2(radicands) | |
vfunc = np.vectorize(bakhshali) | |
square_roots = vfunc(radicands, estimates, iterations) | |
return square_roots | |
def exponential_identity_array(radicands): | |
vfunc = np.vectorize(exponential_identity) | |
square_roots = vfunc(radicands) | |
return square_roots | |
def babylonian(s, estimate, iterations): | |
sqrt = estimate | |
for i in range(0, iterations): | |
sqrt = (sqrt + s / sqrt) / 2 | |
return sqrt | |
def bakhshali(s, estimate, iterations): | |
sqrt = estimate | |
a = 0 | |
b = 0 | |
for i in range(0, iterations): | |
a = (s - sqrt**2) / (2 * sqrt) | |
b = sqrt + a | |
sqrt = b - (a**2 / (2 * b)) | |
return sqrt | |
def exponential_identity(n): | |
return math.e ** (0.5 * math.log(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment