# Status of exp and sqrt

#1

Now that exp. and sqrt. exist, will expm and sqrtm be deprecated and replaced by exp and sqrt on matrices? Is the answer no because it would be too error-prone?

#2

The `expm` and `sqrtm` functions are matrix operations, not elementwise operations. I expect theyâll be sticking around.

#3

Edit: Below is likely not what OP meant.

To be explicit:

``````julia> A = rand(2,2)
2Ă2 Array{Float64,2}:
0.0692582  0.167208
0.223925   0.360005

julia> expm(A'A)
2Ă2 Array{Float64,2}:
1.06113  0.10272
0.10272  1.17547

julia> exp.(A'A)
2Ă2 Array{Float64,2}:
1.05648  1.09658
1.09658  1.17065

julia> expm(A'A) â exp.(A'A)
false
``````

#4

But having `exp.` to mean elementwise operations, wouldnât it be correct for `exp` to mean matrix exponentiation (although possibly against all other languages)?

#5

Ah, that makes more sense. Hm, I think that would perhaps be error prone. On the other hand, it might enable generic code that will both work with matrices and scalars?

#6

Some prior discussion here: https://github.com/JuliaLang/julia/issues/5840#issuecomment-237077416

#7

Thanks. Sorry for being unclear. Yes, I meant using exp for matrix exponentiation

#8

Yes, exponential integrators, integration factor methods, and exponential time differencing methods would be nicer to write with this. You can get around this with a simple `if <: AbstractArray`, but if `exp` âjust workedâ then the code would be much nicer. So thereâs at least a use case in DiffEqs (that I ran into quite recently).

#9

It sounds tempting, but then what about fast vectorised versions of `exp` etc, see e.g. AppleAccelerate.jl

Also note that `expm` and `sqrtm` can be applied to scalars, so the canonical way to write exponential integrators would probably be to use `expm` from the start?

#10

They can overload `broadcast` and `broadcast!`

#11

I did not know thatâŚ you make a great point sir.

#12

Interesting- then maybe this could be a nice (if not crucial) change.

#13

I think all these types of functions should work on matrices, on the guiding principal that if a Taylor (or similar) expansion works for both `Number` and square `Matrix`, then why wouldnât the same function apply to both?? Julia is meant to support generic mathematical programming, after allâŚ

#14

But then `expm` is merely a superset of `exp`?

#15

Not really. Exp applied to a matrix is not the same as expm.

#16

@cortner If the element-wise `exp([1., 2.])` becomes deprecated, then `expm` will be a superset of `exp`.

#17

I guess you are right then - I am still thinking 0.5; maybe another argument in favour deprecating `expm`

#18

IMHO it would be confusing for new users. People will frequently expect `exp(::AbstractMatrix)` to apply `exp` to each entry in the matrix. Better keep separate functions.

#19

At least while only a subset of functions have a âproperâ matrix version, distinguishing the latter is a reasonable alternative, even if it comes at the cost of elegance.

Conversely, `expm` should only be merged to `exp` when `cos(::AbstractMatrix)` and similar throw an error.

#20

So 0.7 then (when the deprecations are removed)?