Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear and educational solution in Clear category for Super Root by rafal.pawlowski
from math import log,exp
from scipy.special import lambertw
"""
x**x = a
x*log(x)=log(a)
e**log(x)*log(x)=log(a)
lambertw(e**log(x)*log(x))=lambertw(log(a)), lambertw is an inverse function of f(x)=x*e^x
log(x)=lambertw(log(a))
x=e**lambert(log(a))
"""
def super_root(number):
return exp(lambertw(log(number)))
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.")
return False
p = result ** result
if number - 0.001 < p < number + 0.001:
return True
return False
assert check_result(super_root, 4), "Square"
assert check_result(super_root, 9), "Cube"
assert check_result(super_root, 81), "Eighty one"
Nov. 19, 2017