log then Newton solution in Speedy category for Super Root by
from math import log
x = 10
a = log(number)
while abs(x**x - number) >= 0.001:
x = x - (x*log(x) - a) / (log(x) + 1)
# We solve x*log(x) = log(a) instead of x**x = a,
# where x*log(x) = log(x**x).
# f(x) = x*log(x) - a
# f'(x) = log(x) + 1
# This code achieve good performance.
# I have not done yet the selection of the initial value.
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
def check_result(function, number):
result = function(number)
if not isinstance(result, (int, float)):
print("The result should be a float or an integer.")
p = result ** result
if number - 0.001 < p < number + 0.001:
assert check_result(super_root, 4), "Square"
assert check_result(super_root, 9), "Cube"
assert check_result(super_root, 81), "Eighty one"
July 4, 2014