# Issetequal behavior with duplicate elements

**URL:** <https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [July 10, 2019, 8:32pm UTC](https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238 "2019-07-10T20:32:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pearlzli](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@pearlzli](https://discourse.julialang.org/u/pearlzli)\
**Post date:** [July 10, 2019, 8:32pm UTC](https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238/1 "2019-07-10T20:32:38Z")

</div>

The `issetequal` docstring says that `issetequal(a, b)` is equivalent to `a ⊆ b && b ⊆ a`, but I found this isn’t the case when there are duplicate elements. In v1.0.0:

```julia
julia> a = [1,2,3];

julia> b = [1,1,2,3];

julia> a ⊆ b && b ⊆ a
true

julia> issetequal(a, b)
false

```

Is this the intended behavior?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [July 10, 2019, 8:58pm UTC](https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238/2 "2019-07-10T20:58:06Z")

</div>

Good catch. The implementation assumes there are no duplicates, as it is just:

```julia
issetequal(l, r) = length(l) == length(r) && l ⊆ r

```

Can you file an issue on GitHub? At the very least the documentation should mention this

---

<div class="post-metadata">

**Author:** ![pearlzli](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@pearlzli](https://discourse.julialang.org/u/pearlzli)\
**Post date:** [July 10, 2019, 9:15pm UTC](https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238/3 "2019-07-10T21:15:48Z")

</div>

Have done - thanks!  
[https://github.com/JuliaLang/julia/issues/32550](https://github.com/JuliaLang/julia/issues/32550)

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [July 10, 2019, 9:35pm UTC](https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238/4 "2019-07-10T21:35:25Z")

</div>

The _name_ of the function, `issetequal(a,b)` kind of indicates that `a` and `b` should be sets. Indeed,

```julia
julia> a = Set([1,2,3])
Set([2, 3, 1])

julia> b = Set([1,1,2,3])
Set([2, 3, 1])

julia> issetequal(a,b)
true

```

So an alternative question is: should the function respond with `true`/`false` with other argument types, e.g., vectors (in original question), tuples, etc.? Or should the function give an error message if the arguments are not sets?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 11, 2019, 5:59am UTC](https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238/5 "2019-07-11T05:59:14Z")

</div>

> [@BLI](#):
>
> should the function respond with `true` / `false` with other argument types

My understanding was that it treats other collections implicitly as sets (eg equivalent to calling `Set(...)` on the arguments).

But looking at the docs I am not sure why I think this, perhaps it could be documented? (or I read this ages ago and I just cannot find it 😉)

---

<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:** [July 11, 2019, 4:54pm UTC](https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238/6 "2019-07-11T16:54:17Z")

</div>

There are quite a few set operations that work correctly for non-sets, eg setdiff, union, intersect. So it’s not unreasonable to expect this to work correctly as well, especially given that it doesn’t throw a no method error.

---

<div class="post-metadata">

**Author:** ![Jean\_Michel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jean_michel/32/8282_2.png) [@Jean\_Michel](https://discourse.julialang.org/u/Jean_Michel)\
**Post date:** [July 11, 2019, 5:05pm UTC](https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238/7 "2019-07-11T17:05:09Z")

</div>

If the arguments are sets, should not `issetequal(a,b)` be the same as `a==b`? Thus, if it was restricted to sets, `issetequal` would be useless…

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [July 11, 2019, 8:14pm UTC](https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238/8 "2019-07-11T20:14:56Z")

</div>

> [@Jean\_Michel](#):
>
> Thus, if it was restricted to sets, `issetequal` would be useless…

Perhaps. But do you then say that `issetequal(a,b) == isequal(Set(a),Set(b))` (or rather: should be like that)? If so, perhaps `issetequal()` is not an essential function?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 12, 2019, 5:26am UTC](https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238/9 "2019-07-12T05:26:40Z")

</div>

> [@BLI](#):
>
> If so, perhaps `issetequal()` is not an essential function?

I don’t know what essential means in this context, but building a `Set` may be a cost that one can avoid.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [July 12, 2019, 7:12pm UTC](https://discourse.julialang.org/t/issetequal-behavior-with-duplicate-elements/26238/10 "2019-07-12T19:12:54Z")

</div>

That is, of course, a valid argument.
