# Negate \`a in b\`?

**URL:** <https://discourse.julialang.org/t/negate-a-in-b/86963>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [September 8, 2022, 8:23pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963 "2022-09-08T20:23:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![SodAlmighty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sodalmighty/32/42450_2.png) [@SodAlmighty](https://discourse.julialang.org/u/SodAlmighty)\
**Post date:** [September 8, 2022, 8:23pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963/1 "2022-09-08T20:23:05Z")

</div>

The opposite of `a in b` seems to be `!(a in b)` which looks clunky to me. I would prefer something like `a not in b`, but that doesn’t work.

Seems to me that a general rule would work well:

```julia
x not op y ≣ !(x op y)

```

Is there some way to achieve this?

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [September 8, 2022, 8:25pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963/2 "2022-09-08T20:25:41Z")

</div>

`\notin` expands to `∉`, such as `a ∉ b`.

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [September 8, 2022, 8:25pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963/3 "2022-09-08T20:25:42Z")

</div>

` a in b` can be written as `a ∈ b` with the mathematical symbol `∈`. And the opposite of that, `∉` is available as an operator too, so you can do `a ∉ b` for `!(a in b)`.

`∈` can be typed with `\in<TAB>`, `∉` with `\notin<TAB>` in the REPL.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [September 8, 2022, 8:33pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963/4 "2022-09-08T20:33:06Z")

</div>

Related issue: [! for infix operators · Issue #25512 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/25512)

---

<div class="post-metadata">

**Author:** ![SodAlmighty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sodalmighty/32/42450_2.png) [@SodAlmighty](https://discourse.julialang.org/u/SodAlmighty)\
**Post date:** [September 8, 2022, 8:33pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963/5 "2022-09-08T20:33:25Z")

</div>

Oooh, interesting. I shall give that a try.

It would be helpful if all such operators were “aliased” to normal words that one could type on a keyboard, however. I don’t know about you, but I don’t have a `∉` key on mine 😉

What we need, I feel, is a way to create infix aliases or functions. Something like:

```julia
infix notin = ∉

```

Or even better, the ability to create our own infix operators.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [September 8, 2022, 8:37pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963/6 "2022-09-08T20:37:22Z")

</div>

> [@SodAlmighty](#):
>
> I don’t know about you, but I don’t have a `∉` key on mine

You can type it on a normal keyboard in a Julia REPL or VS Code by typing `\notin` and pressing TAB.

---

<div class="post-metadata">

**Author:** ![SodAlmighty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sodalmighty/32/42450_2.png) [@SodAlmighty](https://discourse.julialang.org/u/SodAlmighty)\
**Post date:** [September 8, 2022, 8:43pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963/7 "2022-09-08T20:43:19Z")

</div>

But not in Atom.

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [September 8, 2022, 9:14pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963/8 "2022-09-08T21:14:16Z")

</div>

The way to do this with infix operators is either `a \notin<tab> b` or `!(a in b)`. But if you’re willing to give up infix, you can use the function form `!in(a,b)`.

---

<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 8, 2022, 9:49pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963/9 "2022-09-08T21:49:00Z")

</div>

> [@SodAlmighty](#):
>
> But not in Atom.

There are [plugins for Atom](https://atom.io/packages/latex-completions) and for all other popular editors nowadays to do LaTeX-like tab completion of Unicode math symbols.

---

<div class="post-metadata">

**Author:** ![SodAlmighty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sodalmighty/32/42450_2.png) [@SodAlmighty](https://discourse.julialang.org/u/SodAlmighty)\
**Post date:** [September 8, 2022, 10:00pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963/10 "2022-09-08T22:00:35Z")

</div>

@stevengj I did not know that! This will come in very handy.

Thank you all for your help.

---

<div class="post-metadata">

**Author:** ![LeePhillips](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leephillips/32/205514_2.png) [@LeePhillips](https://discourse.julialang.org/u/LeePhillips)\
**Post date:** [September 10, 2022, 3:27pm UTC](https://discourse.julialang.org/t/negate-a-in-b/86963/11 "2022-09-10T15:27:30Z")

</div>

You can create your own infix operators. I have an example in [New features coming in Julia 1.7 [LWN.net]](https://lwn.net/Articles/871486/).
