
"""simple docstring"""







from sympy import diff, lambdify, symbols
from sympy.functions import *  # noqa: F403
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE = "x"							,    SCREAMING_SNAKE_CASE = 10**-10							,    SCREAMING_SNAKE_CASE = 1							,    )  ->     complex:







							"""simple docstring"""


							__snake_case     			=       symbols(__snake_case )
							__snake_case     			=       lambdify(__snake_case							,    __snake_case )
							__snake_case     			=       lambdify(__snake_case							,    diff(__snake_case							,    __snake_case ) )

							__snake_case     			=       starting_point

							while True:
														if diff_function(__snake_case ) != 0:
																					__snake_case     			=       prev_guess - multiplicity * func(__snake_case ) / diff_function(
																					    __snake_case )
														else:
																					raise ZeroDivisionError("Could not find root" ) from None

														# Precision is checked by comparing the difference of consecutive guesses
														if abs(next_guess - prev_guess ) < precision:
																					return next_guess

														__snake_case     			=       next_guess


# 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
		# Find fourth Root of 5
		print(F"""The root of x**4 - 5 = 0 is {newton_raphson('x**4 -5', 0.4 +5J)}""")

		# Find value of e
		print(
		    """The root of log(y) - 1 = 0 is """,
		    F"""{newton_raphson('log(y) - 1', 2, variable='y')}""",
		)

		# Exponential Roots
		print(
		    """The root of exp(x) - 1 = 0 is""",
		    F"""{newton_raphson('exp(x) - 1', 10, precision=0.005)}""",
		)

		# Find root of cos(x)
		print(F"""The root of cos(x) = 0 is {newton_raphson('cos(x)', 0)}""")


"""simple docstring"""







from heapq import heappop, heappush

import numpy as np
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    )  ->     tuple[float | int, list[tuple[int, int]]]:







							"""simple docstring"""


							__snake_case			,   __snake_case     			=       grid.shape
							__snake_case     			=       [-1, 1, 0, 0]
							__snake_case     			=       [0, 0, -1, 1]
							if allow_diagonal:
														dx += [-1, -1, 1, 1]
														dy += [-1, 1, -1, 1]

							__snake_case			,   __snake_case     			=       [(0, source)], set()
							__snake_case     			=       np.full((rows, cols)							,    np.inf )
							__snake_case     			=       0
							__snake_case     			=       np.empty((rows, cols)							,    dtype=SCREAMING_SNAKE_CASE )
							__snake_case     			=       None

							while queue:
														((__snake_case)			,   (__snake_case))     			=       heappop(SCREAMING_SNAKE_CASE )
														if (x, y) in visited:
																					continue
														visited.add((x, y) )

														if (x, y) == destination:
																					__snake_case     			=       []
																					while (x, y) != source:
																												path.append((x, y) )
																												__snake_case			,   __snake_case     			=       predecessors[x, y]
																					path.append(SCREAMING_SNAKE_CASE )  # add the source manually
																					path.reverse()
																					return matrix[destination], path

														for i in range(len(SCREAMING_SNAKE_CASE ) ):
																					__snake_case			,   __snake_case     			=       x + dx[i], y + dy[i]
																					if 0 <= nx < rows and 0 <= ny < cols:
																												__snake_case     			=       grid[nx][ny]
																												if next_node == 1 and matrix[nx, ny] > dist + 1:
																																			heappush(SCREAMING_SNAKE_CASE							,    (dist + 1, (nx, ny)) )
																																			__snake_case     			=       dist + 1
																																			__snake_case     			=       (x, y)

							return np.inf, []


if __name__ == "__main__":
		import doctest

		doctest.testmod()
