


import math as m
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case  ,		__snake_case=0.0_01		)  ->    Optional[int]:







	"""simple docstring"""


	return (f(a + h		) - f(a - h		)) / (2 * h)
def        UpperCAmelCase_      (							__snake_case  ,		__snake_case=0  ,		__snake_case=100  ,		__snake_case=0.00_01  ,		__snake_case=1e-6  ,		__snake_case=False		)  ->    Any:







	"""simple docstring"""


	_lowercase							   =xa  # set the initial guess
	_lowercase							   =[a]
	_lowercase							   =abs(f(__snake_case		)		)
	_lowercase							   =lambda __snake_case		: calc_derivative(__snake_case  ,		__snake_case  ,		h=__snake_case		)  # noqa: E731  Derivative of f(x)
	for _ in range(__snake_case		):
		if fa(__snake_case		) == 0:
			raise ValueError('''No converging solution found'''		)
		_lowercase							   =a - f(__snake_case		) / fa(__snake_case		)  # Calculate the next estimate
		if logsteps:
			steps.append(__snake_case		)
		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

		UpperCAmelCase__     			=							lambda x: m.tanh(x) ** 2 - m.exp(3 * x)  # noqa: E731
		UpperCAmelCase__			,UpperCAmelCase__			,UpperCAmelCase__     			=							newton_raphson(
		    f, xa=10, maxiter=1000, 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}}}''')





def        UpperCAmelCase_      (							__snake_case		)  ->    bool:







 """simple docstring"""


 if not isinstance(__snake_case  ,		__snake_case		):
  _lowercase							   =F"Input value of [number={number}] must be an integer"
  raise TypeError(__snake_case		)
 if number < 0 or number % 2 == 1:
  return False
 _lowercase							   =int(number**0.5		)
 return number == number_sqrt * (number_sqrt + 1)


if __name__ == "__main__":
  import doctest

  doctest.testmod()

