





"""simple docstring"""




from __future__ import annotations





def        a_				(							_lowercase       ,						_lowercase       ,						_lowercase   ):
						assert n > 1 and a > 0 and greatest_common_divisor(_lowercase       ,						_lowercase   ) == 1
						((_UpperCamelCase)   ,							(_UpperCamelCase)   ,							(_UpperCamelCase))			:					Union[str, Any]     =    extended_gcd(_lowercase       ,						_lowercase   )  # Implemented below
						_UpperCamelCase			:					Optional[Any]     =    (b * s) % n
						return x





def        a_				(							_lowercase       ,						_lowercase   ):
						((_UpperCamelCase)   ,							(_UpperCamelCase))			:					int     =    extended_euclid(_lowercase       ,						_lowercase   )  # Implemented below
						if b < 0:
												_UpperCamelCase			:					Any     =    (b % n + n) % n
						return b





def        a_				(							_lowercase       ,						_lowercase       ,						_lowercase   ):
						_UpperCamelCase			:					Optional[Any]     =    invert_modulo(_lowercase       ,						_lowercase   )
						_UpperCamelCase			:					int     =    (b * s) % n
						return x





def        a_				(							_lowercase       ,						_lowercase   ):
						assert a >= 0 and b >= 0

						if b == 0:
												_UpperCamelCase   ,							_UpperCamelCase   ,							_UpperCamelCase			:					int     =    a, 1, 0
						else:
												((_UpperCamelCase)   ,							(_UpperCamelCase)   ,							(_UpperCamelCase))			:					Any     =    extended_gcd(_lowercase       ,						a % b   )
												_UpperCamelCase			:					List[Any]     =    q
												_UpperCamelCase			:					Tuple     =    p - q * (a // b)

						assert a % d == 0 and b % d == 0
						assert d == a * x + b * y

						return (d, x, y)





def        a_				(							_lowercase       ,						_lowercase   ):
						if b == 0:
												return (1, 0)
						((_UpperCamelCase)   ,							(_UpperCamelCase))			:					int     =    extended_euclid(_lowercase       ,						a % b   )
						_UpperCamelCase			:					Any     =    a // b
						return (y, x - k * y)





def        a_				(							_lowercase       ,						_lowercase   ):
						if a < b:
												_UpperCamelCase   ,							_UpperCamelCase			:					Tuple     =    b, a

						while a % b != 0:
												_UpperCamelCase   ,							_UpperCamelCase			:					Any     =    b, a % b

						return b


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

						testmod(name="""modular_division""", verbose=True)
						testmod(name="""modular_division2""", verbose=True)
						testmod(name="""invert_modulo""", verbose=True)
						testmod(name="""extended_gcd""", verbose=True)
						testmod(name="""extended_euclid""", verbose=True)
						testmod(name="""greatest_common_divisor""", verbose=True)







import math as m







def   lowerCamelCase(      a__		,a__		,a__=0.001):
				return (f(a + h) - f(a - h)) / (2 * h)







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

							snake_case_  :	Tuple							  =							lambda x: m.tanh(x) ** 2 - m.exp(3 * x)  # noqa: E731
							snake_case_  , snake_case_  , snake_case_  :	str							  =							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}}}""")