# Product of a scalar with Symmetric is not symmetric (while Symmetric times scalar is)

**URL:** <https://discourse.julialang.org/t/product-of-a-scalar-with-symmetric-is-not-symmetric-while-symmetric-times-scalar-is/15555>\
**Category:** General Usage\
**Created:** [September 27, 2018, 12:25pm UTC](https://discourse.julialang.org/t/product-of-a-scalar-with-symmetric-is-not-symmetric-while-symmetric-times-scalar-is/15555 "2018-09-27T12:25:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [September 27, 2018, 12:25pm UTC](https://discourse.julialang.org/t/product-of-a-scalar-with-symmetric-is-not-symmetric-while-symmetric-times-scalar-is/15555/1 "2018-09-27T12:25:14Z")

</div>

```julia
julia> using LinearAlgebra
julia> A = Symmetric(rand(4,4))
4×4 Symmetric{Float64,Array{Float64,2}}:
 0.0410142 0.31574 0.0784682 0.649851
 0.31574 0.315311 0.908595 0.376246
 0.0784682 0.908595 0.758999 0.965215
 0.649851 0.376246 0.965215 0.13525
julia> A*2.0
4×4 Symmetric{Float64,Array{Float64,2}}:
 0.0820284 0.631481 0.156936 1.2997
 0.631481 0.630623 1.81719 0.752492
 0.156936 1.81719 1.518 1.93043
 1.2997 0.752492 1.93043 0.270501
julia> 2.0*A
4×4 Array{Float64,2}:
 0.0820284 0.631481 0.156936 1.2997
 0.631481 0.630623 1.81719 0.752492
 0.156936 1.81719 1.518 1.93043
 1.2997 0.752492 1.93043 0.270501

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [September 27, 2018, 12:33pm UTC](https://discourse.julialang.org/t/product-of-a-scalar-with-symmetric-is-not-symmetric-while-symmetric-times-scalar-is/15555/2 "2018-09-27T12:33:03Z")

</div>

Can you open an issue at the JuliaLang/julia repo on GitHub and link to this thread?  
The problematic lines are [julia/symmetric.jl at da964d6178c5b22e9dc4b1dd8489f052f4b73e94 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/blob/da964d6178c5b22e9dc4b1dd8489f052f4b73e94/stdlib/LinearAlgebra/src/symmetric.jl#L443-L448) which should probably be updated as

```diff
diff --git a/stdlib/LinearAlgebra/src/symmetric.jl b/stdlib/LinearAlgebra/src/symmetric.jl
index b5f6204..d8aad50 100644
--- a/stdlib/LinearAlgebra/src/symmetric.jl
+++ b/stdlib/LinearAlgebra/src/symmetric.jl
@@ -442,9 +442,9 @@ mul!(C::StridedMatrix{T}, A::StridedMatrix{T}, B::Hermitian{T,<:StridedMatrix})
 
 for T in (:Symmetric, :Hermitian), op in (:*, :/)
     # Deal with an ambiguous case
- @eval ($op)(A::$T, x::Bool) = ($T)(($op)(A.data, x), sym_uplo(A.uplo))
+ @eval ($op)(A::$T, x::Bool) = broadcast($op, A, x)
     S = T == :Hermitian ? :Real : :Number
- @eval ($op)(A::$T, x::$S) = ($T)(($op)(A.data, x), sym_uplo(A.uplo))
+ @eval ($op)(A::$T, x::$S) = broadcast($op, A, x)
 end
 
 function factorize(A::HermOrSym{T}) where T

```

---

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [September 27, 2018, 12:40pm UTC](https://discourse.julialang.org/t/product-of-a-scalar-with-symmetric-is-not-symmetric-while-symmetric-times-scalar-is/15555/3 "2018-09-27T12:40:51Z")

</div>

Done! Also noticed that the addition between symmetric matrices was not working.

[EDIT :] link to Github issue [https://github.com/JuliaLang/julia/issues/29392](https://github.com/JuliaLang/julia/issues/29392)

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [September 27, 2018, 12:46pm UTC](https://discourse.julialang.org/t/product-of-a-scalar-with-symmetric-is-not-symmetric-while-symmetric-times-scalar-is/15555/4 "2018-09-27T12:46:04Z")

</div>

> [@theogf](#):
>
> Also noticed that the addition between symmetric matrices was not working.

You mean that the result is not of type `Symmetric`? See [Adding (SymTri)Diagonal, Symmetric or Hermitian matrices together · Issue #22550 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/22550)

---

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [September 27, 2018, 1:01pm UTC](https://discourse.julialang.org/t/product-of-a-scalar-with-symmetric-is-not-symmetric-while-symmetric-times-scalar-is/15555/5 "2018-09-27T13:01:26Z")

</div>

Yes exactly!
