Negate `a in b`?

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:

x not op y ≣ !(x op y)

Is there some way to achieve this?

1 Like

\notin expands to , such as a ∉ b.

2 Likes

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.

8 Likes

Related issue: ! for infix operators · Issue #25512 · JuliaLang/julia · GitHub

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 :wink:

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

infix notin = ∉

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

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

But not in Atom.

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).

There are plugins for Atom and for all other popular editors nowadays to do LaTeX-like tab completion of Unicode math symbols.

1 Like

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

Thank you all for your help.

You can create your own infix operators. I have an example in New features coming in Julia 1.7 [LWN.net].