




"""simple docstring"""







import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
		import ctypes
		import msvcrt  # noqa






		class       SCREAMING_SNAKE_CASE__					(					ctypes.Structure					):
								_a    						=						[('size', ctypes.c_int), ('visible', ctypes.c_byte)]





def 							lowercase					()     ->  List[str]:


				'''simple docstring'''






				if os.name == "nt":
								lowerCAmelCase  =				CursorInfo()
								lowerCAmelCase  =				ctypes.windll.kernelaa.GetStdHandle(-11 )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(__SCREAMING_SNAKE_CASE      ,       ctypes.byref(__SCREAMING_SNAKE_CASE ) )
								lowerCAmelCase  =				False
								ctypes.windll.kernelaa.SetConsoleCursorInfo(__SCREAMING_SNAKE_CASE      ,       ctypes.byref(__SCREAMING_SNAKE_CASE ) )
				elif os.name == "posix":
								sys.stdout.write("""\033[?25l""" )
								sys.stdout.flush()





def 							lowercase					()     ->  Optional[int]:


				'''simple docstring'''






				if os.name == "nt":
								lowerCAmelCase  =				CursorInfo()
								lowerCAmelCase  =				ctypes.windll.kernelaa.GetStdHandle(-11 )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(__SCREAMING_SNAKE_CASE      ,       ctypes.byref(__SCREAMING_SNAKE_CASE ) )
								lowerCAmelCase  =				True
								ctypes.windll.kernelaa.SetConsoleCursorInfo(__SCREAMING_SNAKE_CASE      ,       ctypes.byref(__SCREAMING_SNAKE_CASE ) )
				elif os.name == "posix":
								sys.stdout.write("""\033[?25h""" )
								sys.stdout.flush()






@contextmanager
def 							lowercase					()     ->  List[Any]:


				'''simple docstring'''






				try:
								hide_cursor()
								yield
				finally:
								show_cursor()











"""simple docstring"""







from __future__ import annotations

from decimal import Decimal
from math import *  # noqa: F403

from sympy import diff





def 							lowercase					(snake_case__   : str      ,       snake_case__   : float | Decimal      ,       snake_case__   : float = 10**-10 )     ->  float:


				'''simple docstring'''






				lowerCAmelCase  =				a
				while True:
								lowerCAmelCase  =				Decimal(snake_case__ ) - (
								    Decimal(eval(snake_case__ ) ) / Decimal(eval(str(diff(snake_case__ ) ) ) )  # noqa: S307
								)
								# This number dictates the accuracy of the answer
								if abs(eval(snake_case__ ) ) < precision:  # noqa: S307
												return float(snake_case__ )


# Let's Execute
if __name__ == "__main__":
		# Find root of trigonometric function
		# Find value of pi
		print(f"""The root of sin(x) = 0 is {newton_raphson("sin(x)", 2)}""")
		# Find root of polynomial
		print(f"""The root of x**2 - 5*x + 2 = 0 is {newton_raphson("x**2 - 5*x + 2", 0.4)}""")
		# Find Square Root of 5
		print(f"""The root of log(x) - 1 = 0 is {newton_raphson("log(x) - 1", 2)}""")
		# Exponential Roots
		print(f"""The root of exp(x) - 1 = 0 is {newton_raphson("exp(x) - 1", 0)}""")





