import math as m




def 				_snake_case     (       lowerCAmelCase							:       Any       ,			lowerCAmelCase							:       Tuple       ,			lowerCAmelCase							:       List[Any]=0.001     ):
			"""simple docstring"""







			return (f(a + h     ) - f(a - h     )) / (2 * h)




def 				_snake_case     (       lowerCAmelCase							:       Tuple       ,			lowerCAmelCase							:       Tuple=0       ,			lowerCAmelCase							:       Union[str, Any]=1_0_0       ,			lowerCAmelCase							:       List[str]=0.0001       ,			lowerCAmelCase							:       str=1E-6       ,			lowerCAmelCase							:       Optional[Any]=False     ):
			"""simple docstring"""







			SCREAMING_SNAKE_CASE_  :		Union[str, Any]    				=   xa  # set the initial guess
			SCREAMING_SNAKE_CASE_  :		int    				=   [a]
			SCREAMING_SNAKE_CASE_  :		Any    				=   abs(f(lowerCAmelCase     )     )
			SCREAMING_SNAKE_CASE_  :		Any    				=   lambda lowerCAmelCase     : calc_derivative(lowerCAmelCase       ,			lowerCAmelCase       ,			h=lowerCAmelCase     )  # noqa: E731  Derivative of f(x)
			for _ in range(lowerCAmelCase     ):
						if fa(lowerCAmelCase     ) == 0:
									raise ValueError("No converging solution found"     )
						SCREAMING_SNAKE_CASE_  :		List[Any]    				=   a - f(lowerCAmelCase     ) / fa(lowerCAmelCase     )  # Calculate the next estimate
						if logsteps:
									steps.append(lowerCAmelCase     )
						if error < maxerror:
									break
			else:
						raise ValueError("Iteration limit reached, no converging solution found"     )
			if logsteps:
						# If logstep is true, then log intermediate steps
						return a, error, steps
			return a, error


if __name__ == "__main__":
		from matplotlib import pyplot as plt

		__lowerCamelCase :     Any          =  lambda x: m.tanh(x) ** 2 - m.exp(3 * x)  # noqa: E731
		__lowerCamelCase :     Tuple          =  newton_raphson(
		    f, xa=10, maxiter=10_00, step=1E-6, logsteps=True
		)
		plt.plot([abs(f(x)) for x in steps])
		plt.xlabel('''step''')
		plt.ylabel('''error''')
		plt.show()
		print(f'''solution = {{{solution:f}}}, error = {{{error:f}}}''')

__lowerCamelCase :     List[Any]          =  {hex(i)[2:]: i for i in range(16)}  # Use [:2] to strip off the leading '0x'




def 				_snake_case     (       lowerCAmelCase							:       str     ):
		"""simple docstring"""







		SCREAMING_SNAKE_CASE_  :		Optional[Any]    				=   hex_string.strip().lower()
		if not hex_string:
				raise ValueError("Empty string was passed to the function"     )
		SCREAMING_SNAKE_CASE_  :		str    				=   hex_string[0] == "-"
		if is_negative:
				SCREAMING_SNAKE_CASE_  :		Optional[int]    				=   hex_string[1:]
		if not all(char in hex_table for char in hex_string     ):
				raise ValueError("Non-hexadecimal value was passed to the function"     )
		SCREAMING_SNAKE_CASE_  :		List[Any]    				=   0
		for char in hex_string:
				SCREAMING_SNAKE_CASE_  :		Tuple    				=   1_6 * decimal_number + hex_table[char]
		return -decimal_number if is_negative else decimal_number


if __name__ == "__main__":
		from doctest import testmod

		testmod()
