Julia: Exterior algebra: `โ‹†` is not a unary operator

Created on 18 Jul 2016  ยท  9Comments  ยท  Source: JuliaLang/julia

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?

Most helpful comment

now we can pass comprehensions in functions, these should be reduction operators, i.e. \bigcup (foo(i) for i in X)

All 9 comments

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 believe the current unary operators are defined here.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yurivish picture yurivish  ยท  3Comments

iamed2 picture iamed2  ยท  3Comments

StefanKarpinski picture StefanKarpinski  ยท  3Comments

sbromberger picture sbromberger  ยท  3Comments

omus picture omus  ยท  3Comments