Infix function notation for `setdiff`

I’m looking for suggestions for an infix function for Base.setdiff. I’ve seen $\setminus$ () used, but that’s not a valid identifier character probably because it’s often indistinguishable from backslash (\) (Ah yes: https://github.com/JuliaLang/julia/issues/30506)

I don’t want to pun on the division operation.

The only idea I have is $\ominus$ (). Another possibility is defining a wrapper type Complement, specialize on intersect, and allow writing A ∩ ¬B. Any others?

You could use (typed -\hat<TAB>).

julia> -̂(A, B) = Base.setdiff(A, B)
-̂ (generic function with 1 method)

julia> Set([1,2,3,4]) -̂ Set([1, 4])
Set{Int64} with 2 elements:
  2
  3

Note however that this character won’t show up well on many displays.

I thought \ was the standard notation for this, but setdiff([1 2; 3 4], [4,5]) and [1 2; 3 4] \ [4,5] already mean different things.

Currently ¬ doesn’t parse as infix. But ~ does, and has no two-argument methods. Not sure I’ve seen either used, but the set operation is pronounced “A not B” right?

Or -ₛ (-\_s<TAB>), which I’m guessing has more widespread font support.

I would recommend defining such synonyms as constants rather than as new functions:

const -ₛ = setdiff

That way, online help (?-ₛ) and other things specialized for setdiff will continue to work.

2 Likes

Thanks for the suggestion. No program (browser or terminal) I’ve tried so far has been able to render it, unfortunately. It’s http://unicode.scarfboy.com/?s=000209b for others who don’t have it rendering either.

That’s a subscript s, which also doesn’t seem to work anywhere for me. Superscript s works better for me, so you could do const \ˢ = setdiff except that this is a pain to type!