File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -135,3 +135,38 @@ function substituter(pairs)
135
135
end
136
136
137
137
@deprecate substitute_expr! (expr,s) substitute (expr,s)
138
+
139
+ # Really bad solve for vars
140
+ function solve_for (eqs, vars)
141
+ @assert length (eqs) >= length (vars)
142
+ @assert all (iszero (eq. lhs) for eq in eqs)
143
+ neweqs = []
144
+ for (i, eq) in enumerate (eqs)
145
+ rhs = eq. rhs
146
+ if rhs. op == (- )
147
+ if any (isequal (rhs. args[1 ]), vars) && any (isequal (rhs. args[2 ]), vars)
148
+ push! (neweqs, rhs. args[1 ] ~ rhs. args[2 ]) # pick one?
149
+ @warn (" todo" )
150
+ elseif any (isequal (rhs. args[1 ]), vars)
151
+ push! (neweqs, rhs. args[1 ] ~ rhs. args[2 ])
152
+ elseif any (isequal (rhs. args[2 ]), vars)
153
+ push! (neweqs, rhs. args[2 ] ~ rhs. args[1 ])
154
+ else
155
+ @warn (" may require unimplemented solve" )
156
+ # error("todo 2")
157
+ push! (neweqs, eq)
158
+ end
159
+ elseif rhs. op == (+ )
160
+ eqs[i] = 0 ~ rhs. args[1 ] - (- rhs. args[2 ])
161
+ else
162
+ error (" todo" )
163
+ end
164
+ end
165
+ if length (neweqs) >= length (vars)
166
+ return neweqs
167
+ else
168
+ # substitute
169
+ eqs′ = Equation .(0 , substitute .(rhss (eqs), (Dict (lhss (neweqs) .=> rhss (neweqs),))))
170
+ solve_for (eqs′, vars)
171
+ end
172
+ end
You can’t perform that action at this time.
0 commit comments