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

isequal for BasicSymbolic should consider metadata #665

Open
bowenszhu opened this issue Oct 25, 2024 · 0 comments · May be fixed by #669
Open

isequal for BasicSymbolic should consider metadata #665

bowenszhu opened this issue Oct 25, 2024 · 0 comments · May be fixed by #669

Comments

@bowenszhu
Copy link
Member

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

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 a pull request may close this issue.

1 participant