Inverse of symbolic matrix

There is an open issue related to this at Rogue `true` in inverse of a matrix · Issue #64 · JuliaSymbolics/Symbolics.jl · GitHub

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

1 Like

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 (mp)/(nq) with m and n numbers.

Incidentally

julia> true/2
0.5

rather than

1 // 2

so true is not having the desired effect here.

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

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.

1 Like

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.

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

For multiply by zero, what is wrong with either

multiply_by_zero(x) = zero(x)*x

or

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

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

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

julia> Inf*0.0
NaN

julia> Inf*false
0.0

false is a “strong zero”

2 Likes