Reconcile one variable in the expression e=0, given const.
(e: dict[str, float], const: str)
| 130 | |
| 131 | |
| 132 | def recon(e: dict[str, float], const: str) -> tuple[str, dict[str, float]]: |
| 133 | """Reconcile one variable in the expression e=0, given const.""" |
| 134 | e = strip(e) |
| 135 | if len(e) == 0: # pylint: disable=g-explicit-length-test |
| 136 | return None |
| 137 | |
| 138 | v0 = None |
| 139 | for v in e: |
| 140 | if v != const: |
| 141 | v0 = v |
| 142 | break |
| 143 | if v0 is None: |
| 144 | return v0 |
| 145 | |
| 146 | c0 = e.pop(v0) |
| 147 | return v0, {v: -c / c0 for v, c in e.items()} |
| 148 | |
| 149 | |
| 150 | def replace( |