Return a, b such that a * symbol + b == self. If self is not linear with respect to symbol, raise RuntimeError.
(self, symbol)
| 772 | return found |
| 773 | |
| 774 | def linear_solve(self, symbol): |
| 775 | """Return a, b such that a * symbol + b == self. |
| 776 | |
| 777 | If self is not linear with respect to symbol, raise RuntimeError. |
| 778 | """ |
| 779 | b = self.substitute({symbol: as_number(0)}) |
| 780 | ax = self - b |
| 781 | a = ax.substitute({symbol: as_number(1)}) |
| 782 | |
| 783 | zero, _ = as_numer_denom(a * symbol - ax) |
| 784 | |
| 785 | if zero != as_number(0): |
| 786 | raise RuntimeError(f'not a {symbol}-linear equation:' |
| 787 | f' {a} * {symbol} + {b} == {self}') |
| 788 | return a, b |
| 789 | |
| 790 | |
| 791 | def normalize(obj): |