Skip to content

Make min/max on Dual consistent with isless - #869

Open
devmotion wants to merge 1 commit into
masterfrom
dmw/minmax-isless
Open

devmotion wants to merge 1 commit into
masterfrom
dmw/minmax-isless

Conversation

@devmotion

Copy link
Copy Markdown
Member

Fixes #868.

min/max on Dual were generated from DiffRules. Those rules choose the partials by value only, so on a tie in value the result depended on the argument order rather than on isless, which breaks ties on the partials since #695:

julia> x = ForwardDiff.Dual(48.0, 1.0);

julia> min(x, 48.0), min(48.0, x)  # before
(Dual{Nothing}(48.0,1.0), Dual{Nothing}(48.0,0.0))

julia> min(x, 48.0), min(48.0, x)  # after
(Dual{Nothing}(48.0,0.0), Dual{Nothing}(48.0,0.0))

No DiffRules rule can express this tie-breaking, since a rule only sees the values. So this PR stops generating min/max from DiffRules and defines them in terms of isless. Like min/max on floats, they propagate NaN values. Mixed Dual/Real arguments are promoted by Base's min(::Real, ::Real).

🤖 Generated with Claude Code

`min`/`max` were generated from DiffRules, which choose the partials by
value only. On ties in value the result depended on the argument order
rather than `isless`, which breaks ties on the partials since #695.

Fixes #868.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.10%. Comparing base (37a61e1) to head (5875780).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #869      +/-   ##
==========================================
- Coverage   91.17%   91.10%   -0.08%     
==========================================
  Files          11       11              
  Lines        1077     1079       +2     
==========================================
+ Hits          982      983       +1     
- Misses         95       96       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

min does not return the minimum with respect to isless when values tie

1 participant