




"""simple docstring"""




import importlib.metadata
import subprocess
import sys







def       __UpperCAmelCase      (				__UpperCamelCase = False					):
			__lowercase	:       int				=   False
			if "IPython" in sys.modules:
						__lowercase	:       str				=   '''google.colab''' in str(sys.modules['''IPython'''].get_ipython()					)

			if in_colab:
						if upgrade:
									__lowercase	:       Tuple				=   ['''pip''', '''install''', '''-U''', '''torch''']
									subprocess.run(__UpperCamelCase					,							check=__UpperCamelCase					)
						# get the current version of torch
						__lowercase	:       int				=   importlib.metadata.version('''torch'''					)
						__lowercase	:       Any				=   torch_version[: torch_version.rindex('''.'''					)]
						__lowercase	:       List[Any]				=   f"""https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl"""
						__lowercase	:       Optional[Any]				=   ['''pip''', '''install''', xla_wheel]
						subprocess.run(__UpperCamelCase					,							check=__UpperCamelCase					)
			else:
						raise RuntimeError('''`install_xla` utility works only on google colab.'''					)









"""simple docstring"""




a_            =   1_0_0_0







def       __UpperCAmelCase      (				__UpperCamelCase					):
			return x * x







def       __UpperCAmelCase      (				__UpperCamelCase					,							__UpperCamelCase					,							__UpperCamelCase					,							__UpperCamelCase = 4					):
			assert callable(
			    __UpperCamelCase					), f"""the function(object) passed should be callable your input : {function}"""
			assert isinstance(__UpperCamelCase					,							(float, int)					), f"""a should be float or integer your input : {a}"""
			assert isinstance(function(__UpperCamelCase					)					,							(float, int)					), (
			    "the function should return integer or float return type of your function, "
			    f"""{type(__UpperCamelCase					)}"""
			)
			assert isinstance(__UpperCamelCase					,							(float, int)					), f"""b should be float or integer your input : {b}"""
			assert (
			    isinstance(__UpperCamelCase					,							__UpperCamelCase					) and precision > 0
			), f"""precision should be positive integer your input : {precision}"""

			# just applying the formula of simpson for approximate integration written in
			# mentioned article in first comment of this file and above this function

			__lowercase	:       Optional[Any]				=   (b - a) / N_STEPS
			__lowercase	:       Optional[int]				=   function(__UpperCamelCase					) + function(__UpperCamelCase					)

			for i in range(1					,							__UpperCamelCase					):
						__lowercase	:       Union[str, Any]				=   a + h * i
						result += function(__UpperCamelCase					) * (4 if i % 2 else 2)

			result *= h / 3
			return round(__UpperCamelCase					,							__UpperCamelCase					)


if __name__ == "__main__":
			import doctest

			doctest.testmod()



