



import dataclasses
import enum
import functools
import math
import re

# The following script is adapted from the script of TaPas.
# Original: https://github.com/google-research/tapas/master/wikisql_utils.py
from typing import Any, List, Text


_lowercase	:   Optional[Any]    	="none"
_lowercase	:   Dict    	="none"

def 			lowerCAmelCase_  (						_lowercase       :     Union[str, Any]		,     _lowercase       :     List[Any])							-> Union[str, Any]:







			"""simple docstring"""
			a__     :		List[Any]		 =						value.split(_lowercase)
			return len(_lowercase) > 1 and any((len(_lowercase) == 3 for x in split))

def 			lowerCAmelCase_  (						_lowercase       :     Any)							-> List[Any]:







			"""simple docstring"""
			if isinstance(_lowercase		,     _lowercase):
						return value
			if isinstance(_lowercase		,     _lowercase):
						return float(_lowercase)
			if not isinstance(_lowercase		,     _lowercase):
						raise ValueError("""Argument value is not a string. Can't parse it as float""")
			a__     :		int		 =						value

			try:
						# Example: 1,000.7
						if "." in sanitized and "," in sanitized:
									return float(sanitized.replace(""","""		,     """"""))
						# 1,000
						if "," in sanitized and _split_thousands(""","""		,     _lowercase):
									return float(sanitized.replace(""","""		,     """"""))
						# 5,5556
						if "," in sanitized and sanitized.count(""",""") == 1 and not _split_thousands(""","""		,     _lowercase):
									return float(sanitized.replace(""","""		,     """."""))
						# 0.0.0.1
						if sanitized.count(""".""") > 1:
									return float(sanitized.replace("""."""		,     """"""))
						# 0,0,0,1
						if sanitized.count(""",""") > 1:
									return float(sanitized.replace(""","""		,     """"""))
						return float(_lowercase)
			except ValueError:
						# Avoid adding the sanitized value in the error message.
						raise ValueError("""Unable to convert value to float""")

def 			lowerCAmelCase_  (						_lowercase       :     Tuple)							-> Any:







			"""simple docstring"""
			if answer is None:
						return None
			try:
						a__     :		Dict		 =						convert_to_float(_lowercase)
						if isinstance(_lowercase		,     _lowercase) and math.isnan(_lowercase):
									return None
						return value
			except ValueError:
						return answer.lower()


_lowercase	:   Optional[int]    	={
    "text": lambda x: x,
    "real": convert_to_float,
}

class      snake_case__       (enum.Enum	):







						"""simple docstring"""




						__lowerCAmelCase  :Tuple			      =  0
						__lowerCAmelCase  :List[Any]			      =  1
						__lowerCAmelCase  :List[str]			      =  2
						__lowerCAmelCase  :List[Any]			      =  3
						__lowerCAmelCase  :Union[str, Any]			      =  4
						__lowerCAmelCase  :Optional[Any]			      =  5




class      snake_case__       (enum.Enum	):







						"""simple docstring"""




						__lowerCAmelCase  :Tuple			      =  0
						__lowerCAmelCase  :Dict			      =  1
						__lowerCAmelCase  :Any			      =  2




@dataclasses.dataclass
class      snake_case__       :







						"""simple docstring"""




						__lowerCAmelCase  :Text
						__lowerCAmelCase  :_Operator
						__lowerCAmelCase  :Any




_lowercase	:   Dict    	=re.compile(r"\w+|[^\w\s]+", re.UNICODE | re.MULTILINE | re.DOTALL)

def 			lowerCAmelCase_  (						_lowercase       :     Dict)							-> Optional[int]:







			"""simple docstring"""
			return list(_TOKENIZER.findall(x.lower()))

def 			lowerCAmelCase_  (						_lowercase       :     str		,     _lowercase       :     Optional[Any]		,     _lowercase       :     Any)							-> Any:







			"""simple docstring"""
			if operator == _Operator.EQUALS:
						return src == tgt
			elif operator == _Operator.GREATER:
						return src > tgt
			elif operator == _Operator.LESSER:
						return src < tgt
			raise ValueError(F'''Unknown operator: {operator}''')

def 			lowerCAmelCase_  (						_lowercase       :     Optional[int]		,     _lowercase       :     List[str]		,     _lowercase       :     Union[str, Any])							-> List[str]:







			"""simple docstring"""
			a__     :		Optional[int]		 =						table["""types"""]
			return _TYPE_CONVERTER[types[column]](_lowercase)

def 			lowerCAmelCase_  (						_lowercase       :     Union[str, Any])							-> Union[str, Any]:







			"""simple docstring"""
			return isinstance(_lowercase		,     _lowercase)

def 			lowerCAmelCase_  (						_lowercase       :     int		,     _lowercase       :     int		,     _lowercase       :     Any)							-> Optional[int]:







			"""simple docstring"""
			for cond in conditions:
						a__     :		Optional[Any]		 =						row[cond.column]

						a__     :		Optional[Any]		 =						_parse_value(_lowercase		,     cond.column		,     cond.cmp_value)

						if _is_string(_lowercase) and _is_string(_lowercase):
									a__     :		List[str]		 =						_normalize_for_match(_lowercase)
									a__     :		List[str]		 =						_normalize_for_match(_lowercase)

						if not isinstance(_lowercase		,     type(_lowercase)):
									raise ValueError("""Type difference {} != {}""".format(type(_lowercase)		,     type(_lowercase)))

						if not _compare(cond.operator		,     _lowercase		,     _lowercase):
									return False
			return True

def 			lowerCAmelCase_  (						_lowercase       :     Dict		,     _lowercase       :     Optional[int]		,     _lowercase       :     Union[str, Any])							-> List[str]:







			"""simple docstring"""
			if not answer_coordinates:
						if aggregation_op == _Aggregation.COUNT:
									return 0.0
						else:
									return EMPTY_ANSWER_AGG

    # Count can support non numeric answers.
			if aggregation_op == _Aggregation.COUNT:
						return float(len(_lowercase))

			# If we have just one answer, if float returns it or try a conversion.
			a__     :		List[Any]		 =						[table["""rows"""][i][j] for (i, j) in answer_coordinates]
			if len(_lowercase) == 1:
						try:
									return convert_to_float(values[0])
						except ValueError as e:
									if aggregation_op != _Aggregation.NONE:
												raise e

			if aggregation_op == _Aggregation.NONE:
						return None

			# Other aggregation only support numeric values. Bail out if we have strings.
			if not all((isinstance(_lowercase		,     (int, float)) for v in values)):
						return None

			if aggregation_op == _Aggregation.SUM:
						return float(sum(_lowercase))
			elif aggregation_op == _Aggregation.AVERAGE:
						return sum(_lowercase) / len(_lowercase)
			else:
						raise ValueError(F'''Unknown aggregation: {aggregation_op}''')

def 			lowerCAmelCase_  (						_lowercase       :     Optional[int]		,     _lowercase       :     Optional[Any])							-> List[str]:







			"""simple docstring"""
			a__     :		List[Any]		 =						sql_query["""agg"""]
			if aggregation_op_index >= 3:
						a__     :		Any		 =						_Aggregation(_lowercase)
			else:
						a__     :		int		 =						_Aggregation.NONE

			a__     :		Any		 =						sql_query["""sel"""]
			a__     :		List[str]		 =						[
			    _Condition(_lowercase		,     _Operator(_lowercase)		,     _lowercase)
			    for column, operator, cmp_value in zip(
			        sql_query["""conds"""]["""column_index"""]		,     sql_query["""conds"""]["""operator_index"""]		,     sql_query["""conds"""]["""condition"""])
			]

			a__     :		Optional[Any]		 =						[]
			for row in range(len(table["""rows"""])):
						if _respect_conditions(_lowercase		,     table["""rows"""][row]		,     _lowercase):
									indices.append((row, target_column))

			if not indices:
						return [], aggregation_op

			if len(_lowercase) == 1:
						return indices, aggregation_op

			# Parsing of MIN/MAX.
			if aggregation_op_index in (1, 2):
						a__     :		Optional[int]		 =						{2: min, 1: max}
						a__     :		Union[str, Any]		 =						[(table["""rows"""][i][j], index) for index, (i, j) in enumerate(_lowercase)]
						a__     :		List[Any]		 =						functools.reduce(operators[sql_query["""agg"""]]		,     _lowercase)

						a__     :		str		 =						[indices[reduced[1]]]
						return ret, _Aggregation.NONE

			return indices, aggregation_op

def 			lowerCAmelCase_  (						_lowercase       :     Tuple		,     _lowercase       :     Dict		,     _lowercase       :     Union[str, Any])							-> Optional[int]:







			"""simple docstring"""
			if float_answer is not None:
						return [str(_lowercase)]
			return [str(table["""real_rows"""][r][c]) for r, c in answer_coordinates]





def 			lowerCAmelCase_  (						_lowercase       :     int		,     _lowercase       :     int)							-> List:







			"""simple docstring"""
			a__ ,		a__     :		str		 =						_get_answer_coordinates(_lowercase		,     _lowercase)
			a__     :		List[str]		 =						_get_float_answer(_lowercase		,     _lowercase		,     _lowercase)
			a__     :		Optional[Any]		 =						_get_answer_text(_lowercase		,     _lowercase		,     _lowercase)
			# keep the original data the same with TaPas
			if len(_lowercase) == 0:
						a__     :		List[str]		 =						[EMPTY_ANSWER]
			return answer_text









from collections.abc import Callable

_lowercase	:   int    	=Callable[[float], float]  # type alias for a real -> real function

def 			lowerCAmelCase_  (						_lowercase       :     RealFunc		,     _lowercase       :     RealFunc		,     _lowercase       :     int		,     )							-> float:







			"""simple docstring"""
			a__     :		Optional[int]		 =						float(_lowercase)
			while True:
						try:
									a__     :		Union[str, Any]		 =						prev_guess - function(_lowercase) / derivative(_lowercase)
						except ZeroDivisionError:
									raise ZeroDivisionError("""Could not find root""") from None
						if abs(prev_guess - next_guess) < 10**-5:
									return next_guess
						a__     :		Optional[Any]		 =						next_guess

def 			lowerCAmelCase_  (						_lowercase       :     float)							-> float:







			"""simple docstring"""
			return (x**3) - (2 * x) - 5

def 			lowerCAmelCase_  (						_lowercase       :     float)							-> float:







			"""simple docstring"""
			return 3 * (x**2) - 2


if __name__ == "__main__":
		print(newton(f, fa, 3))




