# Pair of methods for symmetric operator by a single definition

**URL:** https://discourse.julialang.org/t/pair-of-methods-for-symmetric-operator-by-a-single-definition/132696
**Category:** General Usage
**Tags:** question
**Created:** [September 27, 2025, 10:05am UTC](https://discourse.julialang.org/t/pair-of-methods-for-symmetric-operator-by-a-single-definition/132696 "2025-09-27T10:05:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![DanimirD](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@DanimirD](https://discourse.julialang.org/u/DanimirD)
#### Post date: [September 27, 2025, 10:05am UTC](https://discourse.julialang.org/t/pair-of-methods-for-symmetric-operator-by-a-single-definition/132696/1 "2025-09-27T10:05:23Z")

</div>

Hi, I’ve been trying to familiarize myself with Julia lately and I finally stumbled upon a question to which I couldn’t find an answer yet, so I signed up to Discourse 🙂

First of all, thanks to everyone who contributed creating the enjoyable learning atmosphere around the Julia language!

And here goes my question:

```julia-auto
julia> struct myInt i::Int end

julia> Base.:(==)(int::Int, my::myInt) = int == my.i

julia> m = myInt(1)

julia> 1 == m
true

julia> m == 1
false

```

Is there a way to mark the definition of the `(==)`method as symmetric if you want to implement a symmetric operator? Then the compiler could create all permuted signatures of the method, instead of having to write them out by hand.

PS: Not using promotion mechanism on purpose here.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [September 27, 2025, 11:26am UTC](https://discourse.julialang.org/t/pair-of-methods-for-symmetric-operator-by-a-single-definition/132696/2 "2025-09-27T11:26:28Z")

</div>

> [@DanimirD](#):
>
> Is there a way to mark the definition of the `(==)`method as symmetric if you want to implement a symmetric operator?

No. Typically you just define (_update:_ fixed typo)

```julia-auto
Base.:(==)(my::myInt, int::Int) = int == my

```

(Alternatively, you [define a `promote_rule`](https://docs.julialang.org/en/v1/manual/conversion-and-promotion/#Defining-Promotion-Rules) to promote them both to `myInt`, and then define a single `==` rule for two `myInt`. Promotion rules _are_ automatically symmetrized.)

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [September 27, 2025, 11:41am UTC](https://discourse.julialang.org/t/pair-of-methods-for-symmetric-operator-by-a-single-definition/132696/3 "2025-09-27T11:41:06Z")

</div>

> [@stevengj](#):
>
> ```julia-auto
> Base.:(==)(my::myInt, int::Int) = int = my
> 
> ```

Nitpick, but presumably you meant `int == my`.
