# When does exp(A) == exp.(A)?

**URL:** <https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369>\
**Category:** Offtopic\
**Tags:** linearalgebra\
**Created:** [May 16, 2021, 1:59pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369 "2021-05-16T13:59:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [May 16, 2021, 1:59pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/1 "2021-05-16T13:59:23Z")

</div>

> [@Why does Julia require a . for broadcasting?](https://discourse.julialang.org/t/why-does-julia-require-a-for-broadcasting/61180/3):
>
> It is not equal generally to the exponential of each element of the matrix

Is it ever the case that `exp(A) == exp.(A)` apart from when `A` is 1x1?

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [May 16, 2021, 2:27pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/2 "2021-05-16T14:27:53Z")

</div>

Diagonal 😉

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [May 16, 2021, 2:29pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/3 "2021-05-16T14:29:07Z")

</div>

Umm no: `exp(::Diagonal) ` is diagonal but `exp(0)= 1`:

```julia
julia> exp.(I(2))
2×2 Matrix{Float64}:
 2.71828 1.0
 1.0 2.71828

julia> exp(I(2))
2×2 Diagonal{Float64, Vector{Float64}}:
 2.71828 ⋅ 
  ⋅ 2.71828

```

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [May 16, 2021, 2:46pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/4 "2021-05-16T14:46:30Z")

</div>

… maybe I shouldn’t post before coffee …

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [May 16, 2021, 3:44pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/5 "2021-05-16T15:44:56Z")

</div>

> [@dlfivefifty](#):
>
> Is it ever the case that `exp(A) == exp.(A)` apart from when `A` is 1x1?

You can get arbitrarily close by just making `A` a matrix of larger and larger negative numbers.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [May 16, 2021, 5:08pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/6 "2021-05-16T17:08:22Z")

</div>

> You can get arbitrarily close by just making A a matrix of larger and larger negative numbers.

You need to be more precise about how you want to approach the negative infinity. With e.g. equal entries this is nowhere on the road to zeros:

```julia
julia> exp([-10000 -10000;-10000 -10000])
2×2 Matrix{Float64}:
  0.5 -0.5
 -0.5 0.5

```

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [May 16, 2021, 5:12pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/7 "2021-05-16T17:12:16Z")

</div>

Good point.

```julia
julia> using Optim

julia> sol = optimize(ones(2,2), BFGS()) do A
           norm(exp(A) - exp.(A))
       end
 * Status: success

 * Candidate solution
    Final objective value: 0.000000e+00

 * Found with
    Algorithm: BFGS

 * Convergence measures
    |x - x'| = 5.47e+04 ≰ 0.0e+00
    |x - x'|/|x'| = 1.00e+00 ≰ 0.0e+00
    |f(x) - f(x')| = 2.55e-02 ≰ 0.0e+00
    |f(x) - f(x')|/|f(x')| = Inf ≰ 0.0e+00
    |g(x)| = 0.00e+00 ≤ 1.0e-08

 * Work counters
    Seconds run: 1 (vs limit Inf)
    Iterations: 5
    f(x) calls: 23
    ∇f(x) calls: 23

julia> sol.minimizer
2×2 Matrix{Float64}:
 -54762.4 -53084.3
 -53084.3 -54762.4

julia> exp.(sol.minimizer)
2×2 Matrix{Float64}:
 0.0 0.0
 0.0 0.0

julia> exp(sol.minimizer)
2×2 Matrix{Float64}:
  0.0 -0.0
 -0.0 0.0

```

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [May 16, 2021, 8:01pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/8 "2021-05-16T20:01:23Z")

</div>

Stefan gutel tweeted me

[https://mathoverflow.net/questions/237454/can-the-matrix-exponential-be-equal-to-the-elementwise-exponential](https://mathoverflow.net/questions/237454/can-the-matrix-exponential-be-equal-to-the-elementwise-exponential)

Which had an example

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 16, 2021, 8:29pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/9 "2021-05-16T20:29:38Z")

</div>

Is there a way to get logarithms of negative numbers without having to write `+ 0im` all the time:

```julia
A = [log(-4/3+0im) log(-2+0im) log(-2+0im);
     log(-2+0im) log(-4/3+0im) log(-2+0im);
     log(-2+0im) log(-2+0im) log(-4/3+0im)]

julia> norm(exp(A) - exp.(A)) < 1e-12
true

```

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [May 16, 2021, 8:36pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/10 "2021-05-16T20:36:24Z")

</div>

How about

```julia
julia> A = log.(Complex[-4//3 -2 -2
                        -2 -4//3 -2
                        -2 -2 -4//3])
3×3 Matrix{ComplexF64}:
 0.287682+3.14159im 0.693147+3.14159im 0.693147+3.14159im
 0.693147+3.14159im 0.287682+3.14159im 0.693147+3.14159im
 0.693147+3.14159im 0.693147+3.14159im 0.287682+3.14159im

julia> exp(A) ≈ exp.(A)
true

```

?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 16, 2021, 8:56pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/11 "2021-05-16T20:56:28Z")

</div>

Great, thanks 🙂

_ **NB:** _ _Is there any point in this case in defining rational numbers (`4//3`) given that the logarithms and exponentiation should convert then to floats?_

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [May 16, 2021, 9:27pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/12 "2021-05-16T21:27:04Z")

</div>

> [@rafael.guerra](#):
>
> _ **NB:** _ _Is there any point in this case in defining rational numbers ( `4//3` ) given that the logarithms and exponentiation should convert then to floats?_

Not really, no.

---

<div class="post-metadata">

**Author:** ![puerco-errante](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/puerco-errante/32/19468_2.png) [@puerco-errante](https://discourse.julialang.org/u/puerco-errante)\
**Post date:** [May 18, 2021, 7:05am UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/13 "2021-05-18T07:05:21Z")

</div>

My first thought was also Diagonal, and I also haven’t had my coffee yet 😛

---

<div class="post-metadata">

**Author:** ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)\
**Post date:** [May 18, 2021, 2:23pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/14 "2021-05-18T14:23:19Z")

</div>

With a matrix A that is _strictly_ positive definite e^{tA} \rightarrow 0 as t \rightarrow -\infty. So as you see, tA is negative definite with negative entries 🙂

Nilpotent matrices should provide plenty of examples; the entries solving equations of the messy type e^{a\_{ij}} = polynomial(a\_{11},a\_{12},\dots,a\_{nn}).

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [May 18, 2021, 6:23pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/15 "2021-05-18T18:23:38Z")

</div>

> [@raminammour](#):
>
> With a matrix A that is _strictly_ positive definite e^{tA} \rightarrow 0 as t \rightarrow -\infty. So as you see, tA is negative definite with negative entries

Not every positive definite matrix has all positive entries though.

> [@](#):
>
> Nilpotent matrices should provide plenty of examples

Examples of what?

---

<div class="post-metadata">

**Author:** ![raminammour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raminammour/32/13572_2.png) [@raminammour](https://discourse.julialang.org/u/raminammour)\
**Post date:** [May 18, 2021, 6:47pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/16 "2021-05-18T18:47:19Z")

</div>

Which is why I specified, negative definite (not semi-definite) matrix with **negative** entries.

Examples of matrices satisfying `exp.(A) == exp(A)`.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [May 18, 2021, 7:00pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/17 "2021-05-18T19:00:00Z")

</div>

Very unlikely nilpotent helps since zero is not an example

---

<div class="post-metadata">

**Author:** ![Wei\_Yang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wei_yang/32/23951_2.png) [@Wei\_Yang](https://discourse.julialang.org/u/Wei_Yang)\
**Post date:** [May 18, 2021, 7:14pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/18 "2021-05-18T19:14:08Z")

</div>

Theorem 1 of the following paper gave a complete characterization of the solutions.

> **[1509.00241.pdf](https://arxiv.org/pdf/1509.00241.pdf)**
>
> 90.53 KB

ADDED: **But the problem in the paper is not really what we are discussing here** , notice that the zero-th term is missing, in the following definitions from the paper.  
p(A)=c\_{m} A^{m}+c\_{m-1} A^{m-1}+\cdots+c\_{1} A   
p^{H}(A)=c\_{m} A^{(m)}+c\_{m-1} A^{(m-1)}+\cdots+c\_{1} A

😥 It will be nice if someone can provided a large family of solutions to our problem here.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [May 18, 2021, 7:44pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/19 "2021-05-18T19:44:48Z")

</div>

At the moment there is only one example which is complex… I’m curious if there’s a real example

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [May 18, 2021, 8:06pm UTC](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369/20 "2021-05-18T20:06:01Z")

</div>

If matrix A has invertible eigenvector matrix M with corresponding eigenvalues \lambda\_1,\ldots,\lambda\_n, then

\exp(A)\cdot M = M\cdot \mathrm{diag}(e^\lambda\_1,\ldots,e^\lambda\_n)

Here, \mathrm{diag}(e^{\lambda\_1},\ldots,e^{\lambda\_n}) \neq \exp.(\Lambda) where \Lambda = \mathrm{diag}(\lambda\_1,\ldots,\lambda\_n) — \mathrm{diag} (e^{\lambda\_1},\ldots,e^{\lambda\_n}) has zeros outside of the diagonal, while \exp.(\Lambda) has unity outside of the diagonal.

More generally,

\exp(A) = \sum\_{i=0}^\infty\frac{1}{i!}A^i

[Next page](https://discourse.julialang.org/t/when-does-exp-a-exp-a/61369.md?page=2)
