Broadcast operator for mathjs functions?
- Dominant language
- JavaScript
- Stars
- 15.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
There is a standard meaning for the Gamma function applied to a square matrix (see https://arxiv.org/abs/1806.10554), which is not the Gamma function applied componentwise, like the current behavior of `gamma(M)` in mathjs. Also, the componentwise application already has another very short expression, namely `map(M, gamma)`.
To avoid potential confusion, should the current matrix interpretation of `gamma(M)` as componentwise application be eliminated, requiring the use of `map(M, gamma)`? That way, no one would accidentally call `gamma` on a square matrix thinking they were getting the usual matrix gamma function. (And if anyone ever chose to implement the usual matrix gamma, it could either be overloaded onto the gamma symbol, or called `gammam` by analogy with `expm`.)
In fact, the analogy with `exp` is very strong. The usual mathematical meaning of "exp" of a (square) matrix is not componentwise exponentiation, but rather the matrix exponential. Clearly a specific decision was made to call that operation `expm` in mathjs, and I am not suggesting that decision be revisited. But I would suggest that the componentwise meaning of `exp(M)` be disabled and the documentation of `exp` be revised to point to `expm` for the matrix exponential and `map(M, exp)` for componentwise exponentiation. Again, the motivation here is to avoid the potential confusion of someone calling `exp(M)` thinking they were getting `expm(M)`.
Failing that, I'd suggest amplifying the documentation of exp to make it more prominent that `exp(M)` is not the matrix exponential.
In any case, perhaps it would be good to make a decision at least on whether `gamma` should continue to apply componentwise to matrices before acting on PR #2416 (which is the proximate cause of my looking into the semantics of `gamma` and raising this issue).
Contributor guide
Assessment
This issue has not been assessed yet.