# Equality of two \`AbstractArray\`s

**URL:** https://discourse.julialang.org/t/equality-of-two-abstractarray-s/2256
**Category:** General Usage
**Created:** [February 23, 2017, 7:18pm UTC](https://discourse.julialang.org/t/equality-of-two-abstractarray-s/2256 "2017-02-23T19:18:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![gasagna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gasagna/32/1275_2.png) [@gasagna](https://discourse.julialang.org/u/gasagna)
#### Post date: [February 23, 2017, 7:18pm UTC](https://discourse.julialang.org/t/equality-of-two-abstractarray-s/2256/1 "2017-02-23T19:18:02Z")

</div>

Hi,

Quick question: for `x= [1, 2, 3]`, why is that

```julia
julia> x == 1:3
false

```

but

```julia
julia> x == collect(1:3)
true

```

?

This is on

```julia
Julia Version 0.5.1-pre+33
Commit 20d401c (2017-01-29 21:00 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin15.6.0)
  CPU: Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  BLAS: libgfortblas
  LAPACK: liblapack
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, haswell)

```

Doing `@edit x == 1:3` results in this call in `abstractarray.jl`

```julia
function (==)(A::AbstractArray, B::AbstractArray)
    if indices(A) != indices(B)
        return false
    end
    if isa(A,Range) != isa(B,Range)
        return false
    end
    for (a, b) in zip(A, B)
        if !(a == b)
            return false
        end
    end
    return true
end

```

Now we have that

```julia
indices(x) == indices(1:3)

```

but

````julia
isa(x,Range) != isa(1:3,Range)``` 

returns `true` and so 

```x == 1:3```

has to be false.

Why has this decision been made?

Thanks!

Davide
````

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [February 23, 2017, 7:27pm UTC](https://discourse.julialang.org/t/equality-of-two-abstractarray-s/2256/2 "2017-02-23T19:27:54Z")

</div>

This is something we’d like to change. See: [https://github.com/JuliaLang/julia/issues/16364](https://github.com/JuliaLang/julia/issues/16364)

TL/DR: Equality and hashing must correspond with each other. For ranges, there’s a O(1) shortcut for hashing: just hash the start, step and length together. But this makes that hash different from the hash of the equivalent `Array`… and as such, they must compare as different.

---

<div class="post-metadata">

### Author: ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)
#### Post date: [February 24, 2017, 3:25am UTC](https://discourse.julialang.org/t/equality-of-two-abstractarray-s/2256/3 "2017-02-24T03:25:19Z")

</div>

> and as such, they must compare as different.

Isn’t there a special `isequal` operation for this?

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [February 24, 2017, 4:26pm UTC](https://discourse.julialang.org/t/equality-of-two-abstractarray-s/2256/4 "2017-02-24T16:26:42Z")

</div>

Yes, but `==` and `isequal` agree except for floating-point numbers.
