




'''simple docstring'''
from __future__ import annotations
def 				snake_case_  (   a__		:	Any    ,a__		:	int    ,a__		:	Dict			):



    """simple docstring"""




    assert n > 1 and a > 0 and greatest_common_divisor(a__    ,a__			) == 1
    ((__lowercase)				,(__lowercase)				,(__lowercase))							=						extended_gcd(a__    ,a__			)  # Implemented below
    __lowercase							=						(b * s) % n
    return x
def 				snake_case_  (   a__		:	Optional[Any]    ,a__		:	int			):



    """simple docstring"""




    ((__lowercase)				,(__lowercase))							=						extended_euclid(a__    ,a__			)  # Implemented below
    if b < 0:
        __lowercase							=						(b % n + n) % n
    return b
def 				snake_case_  (   a__		:	List[str]    ,a__		:	Tuple    ,a__		:	List[str]			):



    """simple docstring"""




    __lowercase							=						invert_modulo(a__    ,a__			)
    __lowercase							=						(b * s) % n
    return x
def 				snake_case_  (   a__		:	List[Any]    ,a__		:	List[Any]			):



    """simple docstring"""




    assert a >= 0 and b >= 0

    if b == 0:
        __lowercase				,__lowercase				,__lowercase							=						a, 1, 0
    else:
        ((__lowercase)				,(__lowercase)				,(__lowercase))							=						extended_gcd(a__    ,a % b			)
        __lowercase							=						q
        __lowercase							=						p - q * (a // b)

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

    return (d, x, y)
def 				snake_case_  (   a__		:	Any    ,a__		:	List[str]			):



    """simple docstring"""




    if b == 0:
        return (1, 0)
    ((__lowercase)				,(__lowercase))							=						extended_euclid(a__    ,a % b			)
    __lowercase							=						a // b
    return (y, x - k * y)
def 				snake_case_  (   a__		:	int    ,a__		:	int			):



    """simple docstring"""




    if a < b:
        __lowercase				,__lowercase							=						b, a

    while a % b != 0:
        __lowercase				,__lowercase							=						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}}}""")