I'm currently writing a library for exterior algebra on manifolds and need to define the Hodge star operator. In particular, the Hodge star maps a k-form on an n-dimensional manifold to an n-k-form. Is there any use-case which disagrees with โ being a unary operator? If not and it's a quick fix, could fulfilling this request be part of the 0.5 release?
You can call the function form of *, which accepts a single argument, by enclosing it in parentheses
julia> (*)(1)
1
We are talking about \star right?
What does work for \star is, like what @simonbyrne said for *, using it as a function.
julia> โ(x)=2*x
โ (generic function with 1 method)
julia> โ(4)
8
I'm fine with letting \star be both unary and binary, but from a syntax perspective people may prefer to have it behave like *
What about making unary * syntax for unsafe_load? (Joking. That would be terrible.)
On a more relevant note, how about making \bigcup, \bigcap, \prod, \sum, \bigvee, and \bigwedge unary? These symbols (โ โ โ โ โ โ) are fairly commonly used unary in mathematics.
@TotalVerb, I think @JeffBezanson's perspective from way back was that \cup would be a binary operator and \bigcup (etc.) would just be an identifier name, so you can basically use it as a unary operator but you have to add parens.
now we can pass comprehensions in functions, these should be reduction operators, i.e. \bigcup (foo(i) for i in X)
I can get behind aliases like
const โ = sum
const โ = prod
โ(x) = reduce(โง, x) # all?
โ(x) = reduce(โจ, x) # any?
โ(x) = reduce(union, x)
โ(x) = reduce(intersect, x)
though the empty case is troublesome, as usual.
wrt sets, Union( โ
, โ
) is Union( โ
) is (โ
) which I am free to write this way () # math, not as a tuple
similarly Intersection, so how about
โ(x) = reduce(union, x)
โ(x) = reduce(intersect, x)
โ() = Void()
โ() = Void()
# and if it is useful to cover reducing over an empty collection, here are two
const emptyTuple = ()
const zeroElements = []
โ(emptyTuple) = emptyTuple
โ(emptyTuple) = emptyTuple
โ(zeroElements) = zeroElements
โ(zeroElements) = zeroElements
Fixed in #31604
Most helpful comment
now we can pass comprehensions in functions, these should be reduction operators, i.e.
\bigcup (foo(i) for i in X)