Commit 84c3abd
fix(simplify): Improve collection of nonconstant like terms (#2384)
The key is that the rule-matching engine is optimized for finding matches
on the lefts of terms, but the central term-collection rule
`n1*n3 + n2*n3 -> (n1+n2)*n3` was written with the key common term rightmost.
Reversing this rule to `n3*n1 + n3*n2 -> n3*(n1+n2)` therefore does most
of the work of improving like-term collection. It also better corresponds
to typical mathematical presentation: common terms tend to be pulled out
to the left in common practice.
Floating constants to the right of a product initially (before they are
moved back to the left for human-preferred output) and ensuring that
negations are subsumed into constants whenever possible did the rest.
Also, rule context was not being propagated into the simplification
engine; this commit corrects that.
Resolves #1179.
Resolves #1290.
Co-authored-by: Jos de Jong <[email protected]>1 parent 7beac55 commit 84c3abd
File tree
2 files changed
+22
-10
lines changed- src/function/algebra
- test/unit-tests/function/algebra
2 files changed
+22
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
| 288 | + | |
| 289 | + | |
288 | 290 | | |
289 | | - | |
290 | | - | |
| 291 | + | |
| 292 | + | |
291 | 293 | | |
292 | 294 | | |
293 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
294 | 302 | | |
295 | 303 | | |
296 | 304 | | |
| |||
302 | 310 | | |
303 | 311 | | |
304 | 312 | | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
310 | 316 | | |
311 | 317 | | |
312 | 318 | | |
313 | 319 | | |
314 | 320 | | |
315 | | - | |
| 321 | + | |
316 | 322 | | |
317 | 323 | | |
318 | 324 | | |
| |||
376 | 382 | | |
377 | 383 | | |
378 | 384 | | |
379 | | - | |
| 385 | + | |
380 | 386 | | |
381 | 387 | | |
382 | 388 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
235 | 240 | | |
236 | 241 | | |
237 | 242 | | |
| |||
246 | 251 | | |
247 | 252 | | |
248 | 253 | | |
| 254 | + | |
249 | 255 | | |
250 | 256 | | |
251 | 257 | | |
| |||
0 commit comments