Convert numbers to Fraction when possible. Args: num: A numeric value. Returns: A Fraction if the input is Rational, otherwise the original value.
(
num: int | float | Fraction,
)
| 55 | |
| 56 | @staticmethod |
| 57 | def _rationalize_if_possible( |
| 58 | num: int | float | Fraction, |
| 59 | ) -> Fraction | float: |
| 60 | """Convert numbers to Fraction when possible. |
| 61 | |
| 62 | Args: |
| 63 | num: A numeric value. |
| 64 | |
| 65 | Returns: |
| 66 | A Fraction if the input is Rational, otherwise the original value. |
| 67 | """ |
| 68 | if isinstance(num, Rational): |
| 69 | res = Fraction(num, 1) |
| 70 | return Fraction(res.numerator, res.denominator) |
| 71 | else: |
| 72 | return num |
| 73 | |
| 74 | def equal_upto_scalar(self, other: object) -> bool: |
| 75 | """Check if other is a monomial equivalent to self up to scalar multiple. |
no outgoing calls
no test coverage detected