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