Julia: define βŠ‡ analogous to βŠ†

Created on 20 Apr 2017  Β·  23Comments  Β·  Source: JuliaLang/julia

Discovered that this operator is undefined by default, since βŠ† is, it should also be defined. We should probably take a pass through all defined operators that have a naturally symmetric pair and make sure that they have the appropriate definitions.

good first issue help wanted

Most helpful comment

And perhaps you get tired of writing reverse(<), and want a short name for it. If only there were a standard symbol for that.

All 23 comments

Does it make sense to define βŠ‡ if you can get the same thing with βŠ† and a reverse order? Blah blah blah properly factored functions blah blah blah

As much as it makes sense to have > even though you could write everything with <.

Isn't there an issue for lowering things like EXPR1 βŠ‡ EXPR2 to let x = EXPR1, y = EXPR2; y βŠ† x; end; or perhaps I'm misremembering?

As much as it makes sense to have > even though you could write everything with <

Does it?

Isn't there an issue for lowering things like EXPR1 βŠ‡ EXPR2 to let x = EXPR1, y = EXPR2; y βŠ† x; end; or perhaps I'm misremembering?

This would be an alternative general solution.

Does it?

Are you proposing that we get rid of the > operator?

Well it's something I've pondered, anyway

Not being able to write a > b would be really annoying. It would be better to do the lowering thing where a > b is lowered to the moral equivalent of b < a.

I wrote the definition for βŠ‡, βŠ‰, βŠ‹ before your comments, so might as well share it here even if the general solution suggested above seems nicer than having

βŠ‡(l, r) = issubset(r, l)
βŠ‰(l::Set, r::Set) = !βŠ‡(l, r)
βŠ‹(l::Set, r::Set) = <(r, l)

for each operator with a mirrored counterpart.

If it helps, I can put up the WIP PR for βŠ‡, βŠ‰, βŠ‹ in a bit, once the tests finish running. /edit: see link below.

You can't do this with lowering if you want to have both < and > available as first-class functions. We already have the definition >(x, y) = y < x, along with a note that new types should implement <.

This isn't a matter of proper code factoring, just notational convenience.

One could always make > a shorthand for (args...)->(<)(reverse(args)...) everywhere – then it would be possible to use it as a first-class object as well, but then you might as well just provide that as a default definition and let people provide a new definition of the want.

That definition wouldn't have a splatting penalty?

notational convenience

I'm not too invested here, but I can't think of an example where > is more convenient than <

pop!(A) > pop!(A)?

Clever. Though I'm not sure that's the clearest way to write that code.

last_one = pop!(A)
second_to_last_one = pop!(A)
second_to_last_one < last_one

At risk of taking this question too seriously, sort(x, lt = <) vs. sort(x, lt = >) ?

sort(x, lt = <, rev = true)?

Or even:

reverse(f) = (a, b) -> f(b, a)
sort(x, lt = reverse(<) )

And perhaps you get tired of writing reverse(<), and want a short name for it. If only there were a standard symbol for that.

If only there were a standard symbol for that.

⇄(<) ?

Certainly everything can be expressed with just <. Similarly, we can express all control flow constructs with gotos. Minimalism is not the end goal, just a sometimes-useful heuristic. People like to use both < and > in mathematical notation, and we're interested in making it easy to just transcribe mathematics in a way that matches the original text – excluding > does not help that.

Julia enables and eases communication of computational ideas among humans; imo, pair accordingly.

Closed by #21469

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arshpreetsingh picture arshpreetsingh  Β·  3Comments

tkoolen picture tkoolen  Β·  3Comments

omus picture omus  Β·  3Comments

TotalVerb picture TotalVerb  Β·  3Comments

yurivish picture yurivish  Β·  3Comments