


from math import factorial



class    UpperCAmelCase_	:
       '''simple docstring'''






       def __init__(     self ,					__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              UpperCamelCase    :	Dict   	=		real
              if isinstance(__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						):
                     UpperCamelCase    :	Union[str, Any]   	=		[1] * rank
              else:
                     UpperCamelCase    :	List[str]   	=		rank






       def __repr__(     self						):




              """simple docstring"""




              return (
                  f"""{self.real}+"""
                  f"""{"+".join(str(__SCREAMING_SNAKE_CASE						)+"E"+str(n+1						)for n,dual in enumerate(self.duals						)						)}"""
              )






       def  _lowercase   (     self						):




              """simple docstring"""




              UpperCamelCase    :	Tuple   	=		self.duals.copy()
              while cur[-1] == 0:
                     cur.pop(-1						)
              return Dual(self.real ,					__SCREAMING_SNAKE_CASE						)






       def __add__(     self ,					__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              if not isinstance(__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						):
                     return Dual(self.real + other ,					self.duals						)
              UpperCamelCase    :	List[str]   	=		self.duals.copy()
              UpperCamelCase    :	Any   	=		other.duals.copy()
              if len(__SCREAMING_SNAKE_CASE						) > len(__SCREAMING_SNAKE_CASE						):
                     o_dual.extend([1] * (len(__SCREAMING_SNAKE_CASE						) - len(__SCREAMING_SNAKE_CASE						))						)
              elif len(__SCREAMING_SNAKE_CASE						) < len(__SCREAMING_SNAKE_CASE						):
                     s_dual.extend([1] * (len(__SCREAMING_SNAKE_CASE						) - len(__SCREAMING_SNAKE_CASE						))						)
              UpperCamelCase    :	Union[str, Any]   	=		[]
              for i in range(len(__SCREAMING_SNAKE_CASE						)						):
                     new_duals.append(s_dual[i] + o_dual[i]						)
              return Dual(self.real + other.real ,					__SCREAMING_SNAKE_CASE						)

       __UpperCamelCase      :     Dict							=					__add__






       def __sub__(     self ,					__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              return self + other * -1






       def __mul__(     self ,					__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              if not isinstance(__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						):
                     UpperCamelCase    :	int   	=		[]
                     for i in self.duals:
                            new_duals.append(i * other						)
                     return Dual(self.real * other ,					__SCREAMING_SNAKE_CASE						)
              UpperCamelCase    :	Optional[Any]   	=		[0] * (len(self.duals						) + len(other.duals						) + 1)
              for i, item in enumerate(self.duals						):
                     for j, jtem in enumerate(other.duals						):
                            new_duals[i + j + 1] += item * jtem
              for k in range(len(self.duals						)						):
                     new_duals[k] += self.duals[k] * other.real
              for index in range(len(other.duals						)						):
                     new_duals[index] += other.duals[index] * self.real
              return Dual(self.real * other.real ,					__SCREAMING_SNAKE_CASE						)

       __UpperCamelCase      :     str							=					__mul__






       def __truediv__(     self ,					__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              if not isinstance(__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						):
                     UpperCamelCase    :	List[str]   	=		[]
                     for i in self.duals:
                            new_duals.append(i / other						)
                     return Dual(self.real / other ,					__SCREAMING_SNAKE_CASE						)
              raise ValueError






       def __floordiv__(     self ,					__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              if not isinstance(__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						):
                     UpperCamelCase    :	int   	=		[]
                     for i in self.duals:
                            new_duals.append(i // other						)
                     return Dual(self.real // other ,					__SCREAMING_SNAKE_CASE						)
              raise ValueError






       def __pow__(     self ,					__SCREAMING_SNAKE_CASE						):




              """simple docstring"""




              if n < 0 or isinstance(__SCREAMING_SNAKE_CASE ,					__SCREAMING_SNAKE_CASE						):
                     raise ValueError('''power must be a positive integer'''						)
              if n == 0:
                     return 1
              if n == 1:
                     return self
              UpperCamelCase    :	Optional[Any]   	=		self
              for _ in range(n - 1						):
                     x *= self
              return x




def      a	(							SCREAMING_SNAKE_CASE_      :		Optional[Any]							,			SCREAMING_SNAKE_CASE_      :		Dict							,			SCREAMING_SNAKE_CASE_      :		Tuple       ):






       """simple docstring"""





       if not callable(SCREAMING_SNAKE_CASE_       ):
              raise ValueError('''differentiate() requires a function as input for func'''       )
       if not isinstance(SCREAMING_SNAKE_CASE_							,			(float, int)       ):
              raise ValueError('''differentiate() requires a float as input for position'''       )
       if not isinstance(SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_       ):
              raise ValueError('''differentiate() requires an int as input for order'''       )
       UpperCamelCase    :	str   	=		Dual(SCREAMING_SNAKE_CASE_							,			1       )
       UpperCamelCase    :	List[str]   	=		func(SCREAMING_SNAKE_CASE_       )
       if order == 0:
              return result.real
       return result.duals[order - 1] * factorial(SCREAMING_SNAKE_CASE_       )


if __name__ == "__main__":
  import doctest

  doctest.testmod()


  def      a	(							SCREAMING_SNAKE_CASE_      :		Optional[int]       ):






         """simple docstring"""





         return y**2 * y**4
  print(differentiate(f, 9, 2))





def      a	(							SCREAMING_SNAKE_CASE_      :		int							,			SCREAMING_SNAKE_CASE_      :		int       ):






       """simple docstring"""





       if a < 0 or b < 0:
              raise ValueError('''the value of both inputs must be positive'''       )
       UpperCamelCase    :	int   	=		str(bin(SCREAMING_SNAKE_CASE_       )       )[2:]  # remove the leading "0b"
       UpperCamelCase    :	List[str]   	=		str(bin(SCREAMING_SNAKE_CASE_       )       )[2:]
       UpperCamelCase    :	Tuple   	=		max(len(SCREAMING_SNAKE_CASE_       )							,			len(SCREAMING_SNAKE_CASE_       )       )
       return "0b" + "".join(
           str(int('''1''' in (char_a, char_b)       )       )
           for char_a, char_b in zip(a_binary.zfill(SCREAMING_SNAKE_CASE_       )							,			b_binary.zfill(SCREAMING_SNAKE_CASE_       )       )       )


if __name__ == "__main__":
  import doctest

  doctest.testmod()

