



"""simple docstring"""






import math as m






def 	snake_case__  (						__lowerCamelCase							:       Dict				,						__lowerCamelCase							:       Union[str, Any]				,						__lowerCamelCase							:       Tuple=0.0_01      ):
			"""simple docstring"""
			return (f(a + h      ) - f(a - h      )) / (2 * h)






def 	snake_case__  (						__lowerCamelCase							:       int				,						__lowerCamelCase							:       Union[str, Any]=0				,						__lowerCamelCase							:       Tuple=100				,						__lowerCamelCase							:       int=0.00_01				,						__lowerCamelCase							:       Tuple=1e-6				,						__lowerCamelCase							:       Union[str, Any]=False      ):
			"""simple docstring"""
			lowerCamelCase__						:						Tuple						      =xa  # set the initial guess
			lowerCamelCase__						:						Dict						      =[a]
			lowerCamelCase__						:						Any						      =abs(f(__lowerCamelCase      )      )
			lowerCamelCase__						:						Optional[int]						      =lambda __lowerCamelCase      : calc_derivative(__lowerCamelCase				,						__lowerCamelCase				,						h=__lowerCamelCase      )  # noqa: E731  Derivative of f(x)
			for _ in range(__lowerCamelCase      ):
						if fa(__lowerCamelCase      ) == 0:
									raise ValueError('''No converging solution found'''      )
						lowerCamelCase__						:						Tuple						      =a - f(__lowerCamelCase      ) / fa(__lowerCamelCase      )  # Calculate the next estimate
						if logsteps:
									steps.append(__lowerCamelCase      )
						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

		_lowercase					:					Optional[int] 		=		lambda x: m.tanh(x) ** 2 - m.exp(3 * x)  # noqa: E731
		_lowercase		,      _lowercase		,      _lowercase					:					Union[str, Any] 		=		newton_raphson(
		    f, xa=1_0, maxiter=1_0_0_0, 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}}}')











"""simple docstring"""




import os
import sys
import time

from . import transposition_cipher as trans_cipher





def 			a_							(				):
						_UpperCamelCase     :   Dict      =       '''Prehistoric Men.txt'''
						_UpperCamelCase     :   Optional[Any]      =       '''Output.txt'''
						_UpperCamelCase     :   Any      =       int(input('''Enter key: '''  )  )
						_UpperCamelCase     :   Optional[Any]      =       input('''Encrypt/Decrypt [e/d]: '''  )

						if not os.path.exists(_lowercase  ):
												print(F"""File {input_file} does not exist. Quitting..."""  )
												sys.exit()
						if os.path.exists(_lowercase  ):
												print(F"""Overwrite {output_file}? [y/n]"""  )
												_UpperCamelCase     :   Optional[int]      =       input('''> '''  )
												if not response.lower().startswith('''y'''  ):
																		sys.exit()

						_UpperCamelCase     :   List[str]      =       time.time()
						if mode.lower().startswith('''e'''  ):
												with open(_lowercase  ) as f:
																		_UpperCamelCase     :   Optional[int]      =       f.read()
												_UpperCamelCase     :   List[str]      =       trans_cipher.encrypt_message(_lowercase			,		_lowercase  )
						elif mode.lower().startswith('''d'''  ):
												with open(_lowercase  ) as f:
																		_UpperCamelCase     :   Dict      =       f.read()
												_UpperCamelCase     :   Any      =       trans_cipher.decrypt_message(_lowercase			,		_lowercase  )

						with open(_lowercase			,		'''w'''  ) as output_obj:
												output_obj.write(_lowercase  )

						_UpperCamelCase     :   List[str]      =       round(time.time() - start_time			,		2  )
						print(('''Done (''', total_time, '''seconds )''')  )


if __name__ == "__main__":
						main()



