Skip to content

isequal for BasicSymbolic should consider metadata #665

@bowenszhu

Description

@bowenszhu

The current implementation of Base.isequal for BasicSymbolic objects doesn't take into account potential metadata differences. This can lead to situations where two symbolically equivalent expressions with different metadata are considered equal, which might not be the desired behavior.

function Base.isequal(a::BasicSymbolic{T}, b::BasicSymbolic{S}) where {T,S}
a === b && return true
E = exprtype(a)
E === exprtype(b) || return false
T === S || return false
return _isequal(a, b, E)::Bool
end
function _isequal(a, b, E)
if E === SYM
nameof(a) === nameof(b)
elseif E === ADD || E === MUL
coeff_isequal(a.coeff, b.coeff) && isequal(a.dict, b.dict)
elseif E === DIV
isequal(a.num, b.num) && isequal(a.den, b.den)
elseif E === POW
isequal(a.exp, b.exp) && isequal(a.base, b.base)
elseif E === TERM
a1 = arguments(a)
a2 = arguments(b)
isequal(operation(a), operation(b)) && _allarequal(a1, a2)
else
error_on_type()
end
end

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