diff --git a/ext/SymbolicsForwardDiffExt.jl b/ext/SymbolicsForwardDiffExt.jl index 480fc83f5..9882bec12 100644 --- a/ext/SymbolicsForwardDiffExt.jl +++ b/ext/SymbolicsForwardDiffExt.jl @@ -103,6 +103,25 @@ function binary_dual_definition(M, f, Ts) return expr end +##################### +# Generic Functions # +##################### + +# Predicates # +#------------# + +for pred in [:isequal, :(==)] + @eval begin + @define_binary_dual_op( + Base.$(pred), + $(pred)(value(x), value(y)) && $(pred)(partials(x), partials(y)), + $(pred)(value(x), y) && iszero(partials(x)), + $(pred)(x, value(y)) && iszero(partials(y)), + $AMBIGUOUS_TYPES + ) + end +end + ################################### # General Mathematical Operations # ################################### diff --git a/test/forwarddiff_symbolic_dual_ops.jl b/test/forwarddiff_symbolic_dual_ops.jl index 1b89c79e6..e132f9a50 100644 --- a/test/forwarddiff_symbolic_dual_ops.jl +++ b/test/forwarddiff_symbolic_dual_ops.jl @@ -107,3 +107,10 @@ for f ∈ (hypot, muladd) end # fma is not defined for Symbolics.Num + +# https://github.com/JuliaSymbolics/Symbolics.jl/issues/1246 +@testset "isequal type ambiguity" begin + @variables z + y(x) = isequal(z, x) ? 0 : x + @test ForwardDiff.derivative(y, 0) == 1 # expect ∂(x)/∂x +end