Skip to content

Conversation

@devmotion
Copy link
Member

Currently, the inequality operators for Duals are inconsistent with the definitions of == and isequal. In particular, isless violates the first requirement listed in its docstring:

If `isless(x, y)` is defined, then so is `isless(y, x)` and `isequal(x, y)`, and exactly one of those three yields true.

The PR fixes these inconsistencies.

@mcabbott
Copy link
Member

mcabbott commented Jun 15, 2024

To summarise what this does, tagged version is like so:

julia> using ForwardDiff: Dual

julia> pr(x, op, y) = println("x ", op, " y = ", op(x,y));

julia> pr.(Dual(1,1), (>,>=,==,<=,<), 1);  # like pr.(1.0, (>,>=,==,<=,<), 1.0);
x > y = false
x >= y = true
x == y = true
x <= y = true
x < y = false

(@v1.12) pkg> st ForwardDiff
Status `~/.julia/environments/v1.12/Project.toml`
  [f6369f11] ForwardDiff v0.10.36

master has instead this:

julia> pr.(Dual(1,1), (>,>=,==,<=,<), 1);
x > y = false
x >= y = true
x == y = false
x <= y = true
x < y = false

(jl_I2PrM4) pkg> st ForwardDiff
Status `/private/var/folders/yq/4p2zwd614y59gszh7y9ypyhh0000gn/T/jl_I2PrM4/Project.toml`
  [f6369f11] ForwardDiff v0.11.0-DEV `~/.julia/dev/ForwardDiff`

With this PR,

julia> pr.(Dual(1,1), (>,>=,==,<=,<), 1);  # like pr.(1.01, (>,>=,==,<=,<), 1.0);
x > y = true
x >= y = true
x == y = false
x <= y = false
x < y = false

julia> pr.(Dual(1,-1), (>,>=,==,<=,<), 1);  # like pr.(1-0.01, (>,>=,==,<=,<), 1.0);
x > y = false
x >= y = false
x == y = false
x <= y = true
x < y = true

(jl_FcBNXv) pkg> st ForwardDiff
Status `/private/var/folders/yq/4p2zwd614y59gszh7y9ypyhh0000gn/T/jl_FcBNXv/Project.toml`
  [f6369f11] ForwardDiff v0.11.0-DEV `https://github.com/JuliaDiff/ForwardDiff.jl#dw/isless`

A similar change was proposed in #377, and also discussed in #609. Probably this PR closes both of those.

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.

3 participants