
import unittest

from transformers.testing_utils import CaptureStdout
from transformers.tools.python_interpreter import evaluate


def 				__A(lowerCAmelCase			)		->					Optional[int]:

		"""simple docstring"""






		return x + 2







class 							lowerCAmelCase__   ( unittest.TestCase						):

						def 			A_					(      self					)       ->   List[str]:


								'''simple docstring'''

								_UpperCamelCase         =						"""x = 3"""
								_UpperCamelCase         =						{}
								_UpperCamelCase         =						evaluate(A_							,				{}							,				state=A_					)
								assert result == 3
								self.assertDictEqual(A_							,				{"""x""": 3}					)

								_UpperCamelCase         =						"""x = y"""
								_UpperCamelCase         =						{"""y""": 5}
								_UpperCamelCase         =						evaluate(A_							,				{}							,				state=A_					)
								# evaluate returns the value of the last assignment.
								assert result == 5
								self.assertDictEqual(A_							,				{"""x""": 5, """y""": 5}					)

						def 			A_					(      self					)       ->   Tuple:


								'''simple docstring'''

								_UpperCamelCase         =						"""y = add_two(x)"""
								_UpperCamelCase         =						{"""x""": 3}
								_UpperCamelCase         =						evaluate(A_							,				{"""add_two""": add_two}							,				state=A_					)
								assert result == 5
								self.assertDictEqual(A_							,				{"""x""": 3, """y""": 5}					)

								# Won't work without the tool
								with CaptureStdout() as out:
										_UpperCamelCase         =						evaluate(A_							,				{}							,				state=A_					)
								assert result is None
								assert "tried to execute add_two" in out.out

						def 			A_					(      self					)       ->   Optional[int]:


								'''simple docstring'''

								_UpperCamelCase         =						"""x = 3"""
								_UpperCamelCase         =						{}
								_UpperCamelCase         =						evaluate(A_							,				{}							,				state=A_					)
								assert result == 3
								self.assertDictEqual(A_							,				{"""x""": 3}					)

						def 			A_					(      self					)       ->   Dict:


								'''simple docstring'''

								_UpperCamelCase         =						"""test_dict = {'x': x, 'y': add_two(x)}"""
								_UpperCamelCase         =						{"""x""": 3}
								_UpperCamelCase         =						evaluate(A_							,				{"""add_two""": add_two}							,				state=A_					)
								self.assertDictEqual(A_							,				{"""x""": 3, """y""": 5}					)
								self.assertDictEqual(A_							,				{"""x""": 3, """test_dict""": {"""x""": 3, """y""": 5}}					)

						def 			A_					(      self					)       ->   Tuple:


								'''simple docstring'''

								_UpperCamelCase         =						"""x = 3\ny = 5"""
								_UpperCamelCase         =						{}
								_UpperCamelCase         =						evaluate(A_							,				{}							,				state=A_					)
								# evaluate returns the value of the last assignment.
								assert result == 5
								self.assertDictEqual(A_							,				{"""x""": 3, """y""": 5}					)

						def 			A_					(      self					)       ->   int:


								'''simple docstring'''

								_UpperCamelCase         =						"""text = f'This is x: {x}.'"""
								_UpperCamelCase         =						{"""x""": 3}
								_UpperCamelCase         =						evaluate(A_							,				{}							,				state=A_					)
								# evaluate returns the value of the last assignment.
								assert result == "This is x: 3."
								self.assertDictEqual(A_							,				{"""x""": 3, """text""": """This is x: 3."""}					)

						def 			A_					(      self					)       ->   List[str]:


								'''simple docstring'''

								_UpperCamelCase         =						"""if x <= 3:\n    y = 2\nelse:\n    y = 5"""
								_UpperCamelCase         =						{"""x""": 3}
								_UpperCamelCase         =						evaluate(A_							,				{}							,				state=A_					)
								# evaluate returns the value of the last assignment.
								assert result == 2
								self.assertDictEqual(A_							,				{"""x""": 3, """y""": 2}					)

								_UpperCamelCase         =						{"""x""": 8}
								_UpperCamelCase         =						evaluate(A_							,				{}							,				state=A_					)
								# evaluate returns the value of the last assignment.
								assert result == 5
								self.assertDictEqual(A_							,				{"""x""": 8, """y""": 5}					)

						def 			A_					(      self					)       ->   Tuple:


								'''simple docstring'''

								_UpperCamelCase         =						"""test_list = [x, add_two(x)]"""
								_UpperCamelCase         =						{"""x""": 3}
								_UpperCamelCase         =						evaluate(A_							,				{"""add_two""": add_two}							,				state=A_					)
								self.assertListEqual(A_							,				[3, 5]					)
								self.assertDictEqual(A_							,				{"""x""": 3, """test_list""": [3, 5]}					)

						def 			A_					(      self					)       ->   Optional[Any]:


								'''simple docstring'''

								_UpperCamelCase         =						"""y = x"""
								_UpperCamelCase         =						{"""x""": 3}
								_UpperCamelCase         =						evaluate(A_							,				{}							,				state=A_					)
								assert result == 3
								self.assertDictEqual(A_							,				{"""x""": 3, """y""": 3}					)

						def 			A_					(      self					)       ->   List[str]:


								'''simple docstring'''

								_UpperCamelCase         =						"""test_list = [x, add_two(x)]\ntest_list[1]"""
								_UpperCamelCase         =						{"""x""": 3}
								_UpperCamelCase         =						evaluate(A_							,				{"""add_two""": add_two}							,				state=A_					)
								assert result == 5
								self.assertDictEqual(A_							,				{"""x""": 3, """test_list""": [3, 5]}					)

								_UpperCamelCase         =						"""test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"""
								_UpperCamelCase         =						{"""x""": 3}
								_UpperCamelCase         =						evaluate(A_							,				{"""add_two""": add_two}							,				state=A_					)
								assert result == 5
								self.assertDictEqual(A_							,				{"""x""": 3, """test_dict""": {"""x""": 3, """y""": 5}}					)







						def 			A_					(      self					)       ->   Optional[int]:


								'''simple docstring'''

								_UpperCamelCase         =						"""x = 0\nfor i in range(3):\n    x = i"""
								_UpperCamelCase         =						{}
								_UpperCamelCase         =						evaluate(A_							,				{"""range""": range}							,				state=A_					)
								assert result == 2
								self.assertDictEqual(A_							,				{"""x""": 2, """i""": 2}					)







"""simple docstring"""




from collections.abc import Callable





def       a_ (	lowercase__ :Callable[[float], float],			lowercase__ :float,			lowercase__ :float     ):
			__lowerCamelCase          =      a
			__lowerCamelCase          =      b
			if function(lowercase__     ) == 0:  # one of the a or b is a root for the function
						return a
			elif function(lowercase__     ) == 0:
						return b
			elif (
			    function(lowercase__     ) * function(lowercase__     ) > 0
			):  # if none of these are root and they are both positive or negative,
						# then this algorithm can't find the root
						raise ValueError("""could not find root in given interval."""     )
			else:
						__lowerCamelCase          =      start + (end - start) / 2.0
						while abs(start - mid     ) > 10**-7:  # until precisely equals to 10^-7
									if function(lowercase__     ) == 0:
												return mid
									elif function(lowercase__     ) * function(lowercase__     ) < 0:
												__lowerCamelCase          =      mid
									else:
												__lowerCamelCase          =      mid
									__lowerCamelCase          =      start + (end - start) / 2.0
						return mid





def       a_ (	lowercase__ :float     ):
			return x**3 - 2 * x - 5


if __name__ == "__main__":
					print(bisection(f, 1, 1_0_0_0))

					import doctest

					doctest.testmod()




