Commit 8366e51
Fold abs where the sign of its argument is known (#881)
|x| is x for a non-negative real x and -x for a negative one, which is the definition of
the function rather than an identity carrying a side condition. It was applied only where
the argument was a Number node, so an argument whose *value* is a known real kept its abs:
abs(-sqrt(6)) and abs(-pi) came back exactly as written.
That is visible in answers built out of radicals. (2x^2 - 3 > 0) and (x > 0) solved to
(abs(-sqrt(6)) / 2; +oo) and now solves to (sqrt(6) / 2; +oo) -- the endpoint was always
the same number, printed in a form that read as unfinished work. The Solvers wiki page
shows the old output and wants updating with the release; docsamples reports it as its one
output mismatch until then.
The sign is read off Evaled, so nothing is assumed about a symbol -- abs(-a) is left alone
-- and an argument off the real line declines rather than being guessed at. sqrt(-4)
evaluates to 2i, whose absolute value is 2, which is neither the argument nor its
negation; a rule reading "negative, therefore negate" would be wrong there. Non-finite
values decline too.
#881 also asks for |-x| = |x| for a symbolic x, which is unconditionally sound and is not
here. Measured why: sgn(-a) does not normalise to -sgn(a), so rewriting abs(-a) to abs(a)
on its own breaks the pairing that gives sgn(-a) * abs(-a) -> -a. It wants the odd
symmetry of sgn alongside it.
Suite 6320 passed; casbench 117/119 with 0 wrong; rootcheck 596/596; simpsweep
10463/10463; propcheck 0 failures; crashcheck 1652 cases with 0 crashes.
boundcheck reports 46 shapes rewritten and 6 disagreements both with this change and on
the commit before it, measured separately, so it adds none. The report committed in the
workspace said four, and was stale rather than better: two of the six are abs(sgn(x)) and
sgn(abs(x)), each simplifying to 1 where both are 0 at x = 0. Those are wrong answers in
master, not here, and get their own issue.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent d8bfcd5 commit 8366e51
3 files changed
Lines changed: 90 additions & 0 deletions
File tree
- Sources
- AngouriMath/Functions/Evaluation/Evaluation.Continuous
- Tests/UnitTests/Common
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
349 | 350 | | |
350 | 351 | | |
351 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
352 | 382 | | |
353 | 383 | | |
354 | 384 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
448 | 448 | | |
449 | 449 | | |
450 | 450 | | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
451 | 469 | | |
452 | 470 | | |
453 | 471 | | |
| |||
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
699 | 699 | | |
700 | 700 | | |
701 | 701 | | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
702 | 744 | | |
703 | 745 | | |
0 commit comments