# Struggling with Symbolics matrix multiplication

**URL:** https://discourse.julialang.org/t/struggling-with-symbolics-matrix-multiplication/137476
**Category:** General Usage
**Tags:** question
**Created:** [June 6, 2026, 8:40pm UTC](https://discourse.julialang.org/t/struggling-with-symbolics-matrix-multiplication/137476 "2026-06-06T20:40:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ea42gh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ea42gh/32/12000_2.png) [@ea42gh](https://discourse.julialang.org/u/ea42gh)
#### Post date: [June 6, 2026, 8:40pm UTC](https://discourse.julialang.org/t/struggling-with-symbolics-matrix-multiplication/137476/1 "2026-06-06T20:40:32Z")

</div>

Newbie Symbolics question.

I have two matrices with element type Int  
L = [1 0 0 0; -3 1 0 0; 2 3 1 0; -2 3 -2 1]  
D = [1 0 0 0; 0 2 0 0; 0 0 1 0; 0 0 0 2]

Forming the product G = Num.(L) \* sqrt( Num.(D) ) yields  
G = Num[sqrt(1) 0 0 0; -3sqrt(1) sqrt(2) 0 0; 2sqrt(1) 3sqrt(2) sqrt(1) 0; -2sqrt(1) 3sqrt(2) -2sqrt(1) sqrt(2)]

with the result that G\*G’ promotes sqrt(2)\*sqrt(2) to a float 2.0,  
as opposed to sqrt(Num(2))\*sqrt(Num(2)) = Num(2)

How do I avoid this promotion to float? I would hope to get  
G\*G’ = Num[1 -3 2 -2; -3 11 0 12; 2 0 23 12; -2 12 12 28]

---

<div class="post-metadata">

### Author: ![ea42gh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ea42gh/32/12000_2.png) [@ea42gh](https://discourse.julialang.org/u/ea42gh)
#### Post date: [June 7, 2026, 6:19pm UTC](https://discourse.julialang.org/t/struggling-with-symbolics-matrix-multiplication/137476/2 "2026-06-07T18:19:35Z")

</div>

Simplified the example too much: D should be the diagonal of matrix D.

The only workaround I have found is to use variables for the square roots, and substitute the actual values after each computation…

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [June 8, 2026, 1:02pm UTC](https://discourse.julialang.org/t/struggling-with-symbolics-matrix-multiplication/137476/3 "2026-06-08T13:02:47Z")

</div>

Unfortunately this is deep in `Num` operations: `sqrt(Num(2)) * sqrt(Num(2)) === Num(2.0)`. That’s not a general eagerness to simplify `Num` scalars e.g. `sqrt(Num(2))*sqrt(Num(18))` does not simplify at all to `Num(6.0)`. I’m pretty sure [rule rewriting](https://symbolicutils.juliasymbolics.org/rewrite/#rule-based_rewriting) of subexpressions can’t change how Julia operations are implemented. I couldn’t quickly find a Github issue along these lines, so I don’t know what the developers’ opinions on this are.

---

<div class="post-metadata">

### Author: ![sablonl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sablonl/32/217805_2.png) [@sablonl](https://discourse.julialang.org/u/sablonl)
#### Post date: [June 8, 2026, 1:36pm UTC](https://discourse.julialang.org/t/struggling-with-symbolics-matrix-multiplication/137476/4 "2026-06-08T13:36:04Z")

</div>

There is [Expansion of sqrt for integers · Issue #1875 · JuliaSymbolics/Symbolics.jl · GitHub](https://github.com/JuliaSymbolics/Symbolics.jl/issues/1875)
