# Inverse of symbolic matrix

**URL:** <https://discourse.julialang.org/t/inverse-of-symbolic-matrix/85764>\
**Category:** Modelling & Simulations\
**Tags:** linearalgebra, symbolics\
**Created:** [August 15, 2022, 9:16am UTC](https://discourse.julialang.org/t/inverse-of-symbolic-matrix/85764 "2022-08-15T09:16:28Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![Johan-Gronqvist](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johan-gronqvist/32/29895_2.png) [@Johan-Gronqvist](https://discourse.julialang.org/u/Johan-Gronqvist)\
**Post date:** [August 18, 2022, 7:07am UTC](https://discourse.julialang.org/t/inverse-of-symbolic-matrix/85764/21 "2022-08-18T07:07:02Z")

</div>

There is an open issue related to this at [Rogue `true` in inverse of a matrix · Issue #64 · JuliaSymbolics/Symbolics.jl · GitHub](https://github.com/JuliaSymbolics/Symbolics.jl/issues/64)

I would appreciate if you could comment there on what the right solution is.

---

<div class="post-metadata">

**Author:** ![Andrew\_Swann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrew_swann/32/32106_2.png) [@Andrew\_Swann](https://discourse.julialang.org/u/Andrew_Swann)\
**Post date:** [August 18, 2022, 10:26am UTC](https://discourse.julialang.org/t/inverse-of-symbolic-matrix/85764/22 "2022-08-18T10:26:43Z")

</div>

Much appreciated. I don’t see that symbolics should just be working with integer coefficients, especially given some of the modelling applications. Implementing such a float method, doesn’t seem to be so straight forward, but I don’t have much julia experience. Perhaps what I am missing is more a simplification or expansion rule for (m_p)/(n_q) with m and n numbers.

---

<div class="post-metadata">

**Author:** ![Andrew\_Swann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrew_swann/32/32106_2.png) [@Andrew\_Swann](https://discourse.julialang.org/u/Andrew_Swann)\
**Post date:** [August 18, 2022, 10:28am UTC](https://discourse.julialang.org/t/inverse-of-symbolic-matrix/85764/23 "2022-08-18T10:28:43Z")

</div>

Incidentally

```julia
julia> true/2
0.5

```

rather than

```julia
1 // 2

```

so true is not having the desired effect here.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [August 18, 2022, 10:59am UTC](https://discourse.julialang.org/t/inverse-of-symbolic-matrix/85764/24 "2022-08-18T10:59:22Z")

</div>

I don’t find that strange at all, `true/2` is a division between two integers which Julia always promotes to a float

```julia
julia> true / 2
0.5

julia> 1 / 2
0.5

julia> 1.0 / 2
0.5

```

The OP asked about the use of `true` vs `1` or `1.0` in a symbolic expression, and the Julia type `Rational` is not really related to this. You could argue that `1/2` should always result in a `Rational` object, but that is not the path Julia or Symbolics.jl has taken. If you want to compute using rationals, you need to make that choice explicitly.

---

<div class="post-metadata">

**Author:** ![Andrew\_Swann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrew_swann/32/32106_2.png) [@Andrew\_Swann](https://discourse.julialang.org/u/Andrew_Swann)\
**Post date:** [August 18, 2022, 2:03pm UTC](https://discourse.julialang.org/t/inverse-of-symbolic-matrix/85764/25 "2022-08-18T14:03:19Z")

</div>

It sounds like I am missing some section of the Symbolics documentation. Could you please point to where this is explained. Typing help on Num in repl gives nearly no information.

---

<div class="post-metadata">

**Author:** ![josuagrw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josuagrw/32/1015_2.png) [@josuagrw](https://discourse.julialang.org/u/josuagrw)\
**Post date:** [August 18, 2022, 2:05pm UTC](https://discourse.julialang.org/t/inverse-of-symbolic-matrix/85764/26 "2022-08-18T14:05:18Z")

</div>

> [@Andrew\_Swann](#):
>
> I don’t see that symbolics should just be working with integer coefficients

If you use floating point numbers you will not encounter an integer overflow.

---

<div class="post-metadata">

**Author:** ![Andrew\_Swann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrew_swann/32/32106_2.png) [@Andrew\_Swann](https://discourse.julialang.org/u/Andrew_Swann)\
**Post date:** [August 19, 2022, 7:40am UTC](https://discourse.julialang.org/t/inverse-of-symbolic-matrix/85764/27 "2022-08-19T07:40:51Z")

</div>

For multiply by zero, what is wrong with either

```julia
multiply_by_zero(x) = zero(x)*x

```

or

```julia
multiply_by_zero(x) = zero(eltype(x))*x

```

depending whether we mean multiplication as elements of type x or as scalar multiplication?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [August 19, 2022, 9:32am UTC](https://discourse.julialang.org/t/inverse-of-symbolic-matrix/85764/28 "2022-08-19T09:32:52Z")

</div>

> [@Andrew\_Swann](#):
>
> what is wrong with either

Nothing is wrong with those, and they would probably be preferrable in most cases. They are not exactly equivalent though

```julia
julia> Inf*0.0
NaN

julia> Inf*false
0.0

```

`false` is a “strong zero”

[Previous page](https://discourse.julialang.org/t/inverse-of-symbolic-matrix/85764.md?page=1)
