Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make isless, <, >, <=, and >= consistent with == and isequal #695

Merged
merged 2 commits into from
Jul 28, 2024

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.

@devmotion devmotion merged commit a286920 into master Jul 28, 2024
4 checks passed
@KristofferC KristofferC deleted the dw/isless branch July 29, 2024 10:11
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.

2 participants