Compute the multiplicative inverse of this monomial. Returns: The inverse Monomial. Raises: ValueError: If the coefficient is zero.
(self)
| 167 | ).clean() |
| 168 | |
| 169 | def inverse(self) -> Monomial: |
| 170 | """Compute the multiplicative inverse of this monomial. |
| 171 | |
| 172 | Returns: |
| 173 | The inverse Monomial. |
| 174 | |
| 175 | Raises: |
| 176 | ValueError: If the coefficient is zero. |
| 177 | """ |
| 178 | mono = {i: self.variables[i] for i in self.variables if self.variables[i] != 0} |
| 179 | for i in mono: |
| 180 | mono[i] *= -1 |
| 181 | if self.coeff == 0: |
| 182 | raise ValueError("Coefficient must not be 0.") |
| 183 | return Monomial(mono, Monomial._rationalize_if_possible(1 / self.coeff)).clean() |
| 184 | |
| 185 | def __truediv__(self, other: int | float | Fraction) -> Monomial: |
| 186 | """Divide this monomial by another monomial or scalar. |