Skip to content

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

Open

Description

@ArnoStrouwen

min is documented to "return the minimum of the arguments, with respect to isless", but for a Dual that ties in value it returns whichever argument comes first:

julia> using ForwardDiff

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

julia> isless(48.0, x)
true

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

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

Since #695, isless breaks a value tie on the partials, so 48.0 is the smaller argument here, but min(x, 48.0) returns x. min picks its argument by value only, so on a tie the result depends on argument order rather than on isless.

I ran into this through differentiating Interpolations.jl, whose linear extrapolation clamps with min and then bounds-checks the result with <=, so it throws a BoundsError under --check-bounds=yes when differentiating exactly at the last knot.

ForwardDiff 1.4.6, Julia 1.12.7.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions