JuliaSymbolics/Symbolics.jl

Hash function for `Arr` does not consider array structure and size

Opened this issue · 1 comments

Currently, the hash function for Arr only considers its value field.

Symbolics.jl/src/arrays.jl

Lines 495 to 499 in 1da13fd

@symbolic_wrap struct Arr{T,N} <: AbstractArray{T, N}
value
end
Base.hash(x::Arr, u::UInt) = hash(unwrap(x), u)

This means that two Arr objects with identical symbolic elements but different array structures and sizes will have the same hash value.

For example, the following code snippet demonstrates this issue:

using Symbolics

a1 = only(@variables a[1:5])
a2 = only(@variables a[1:4, 1:6])
a3 = only(@variables a)

h1 = hash(a1)
h2 = hash(a2)
h3 = hash(a3)

h1 == h2 == h3 # This returns true, but we expect it to be false

Yeah it seems to me that should hash differently.