(self, other: Union[int, float, Fraction, Monomial])
Add a given poylnomial to a copy of self.
Add a given poylnomial to a copy of self.
Add a given poylnomial to a copy of self .
def __add__(self, other: Union[int, float, Fraction, Monomial]):
        """
        Add a given poylnomial to a copy of self.

        """
        if isinstance(other, int) or isinstance(other, float) or isinstance(other, Fraction):
            return self.__add__(Monomial({}, Polynomial._rationalize_if_possible(other)))
        elif isinstance(other, Monomial):
            monos = {m.clone() for m in self.monomials}

            for _own_monos in monos:
                if _own_monos.equal_upto_scalar(other):
                    scalar = _own_monos.coeff
                    monos -= {_own_monos}
                    temp_variables = {i: other.variables[i] for i in other.variables}
                    monos |= {Monomial(temp_variables, Polynomial._rationalize_if_possible(scalar + other.coeff))}
                    return Polynomial([z for z in monos])

            monos |= {other.clone()}
            return Polynomial([z for z in monos])
        elif isinstance(other, Polynomial):
            temp = list(z for z in {m.clone() for m in self.all_monomials()})
        
            p = Polynomial(temp)
            for o in other.all_monomials():
                p = p.__add__(o.clone())
            return p
        else:
            raise ValueError('Can only add int, float, Fraction, Monomials, or Polynomials to Polynomials.')
def __add__ ( self , other : Union [ int , float , Fraction , Monomial ] ) : if isinstance ( other , int ) or isinstance ( other , float ) or isinstance ( other , Fraction ) : return self . __add__ ( Monomial ( { } , Polynomial . _rationalize_if_possible ( other ) ) ) elif isinstance ( other , Monomial ) : monos = { m . clone ( ) for m in self . monomials } for _own_monos in monos : if _own_monos . equal_upto_scalar ( other ) : scalar = _own_monos . coeff monos -= { _own_monos } temp_variables = { i : other . variables [ i ] for i in other . variables } monos |= { Monomial ( temp_variables , Polynomial . _rationalize_if_possible ( scalar + other . coeff ) ) } return Polynomial ( [ z for z in monos ] ) monos |= { other . clone ( ) } return Polynomial ( [ z for z in monos ] ) elif isinstance ( other , Polynomial ) : temp = list ( z for z in { m . clone ( ) for m in self . all_monomials ( ) } ) p = Polynomial ( temp ) for o in other . all_monomials ( ) : p = p . __add__ ( o . clone ( ) ) return p else : raise ValueError ( 'Can only add int, float, Fraction, Monomials, or Polynomials to Polynomials.' )