JuliaReach / MathematicalSystems.jl

Systems definitions in Julia

Home Page:https://juliareach.github.io/MathematicalSystems.jl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exact and approximate system equality should not look at the type parameters

schillic opened this issue · comments

I would argue that the following two systems should be exactly and approximately equal.

julia> A = [1.0 1; 1 -1]
2×2 Matrix{Float64}:
 1.0   1.0
 1.0  -1.0

julia> B = [1 1; 1 -1]
2×2 Matrix{Int64}:
 1   1
 1  -1

julia> sA = LinearDiscreteSystem(A)
LinearDiscreteSystem{Float64, Matrix{Float64}}([1.0 1.0; 1.0 -1.0])

julia> sB = LinearDiscreteSystem(B)
LinearDiscreteSystem{Int64, Matrix{Int64}}([1 1; 1 -1])

julia> sA  sB
false

julia> sA == sB
false

The reason for the false is that we first compare the types, which include all type parameters, and LinearDiscreteSystem{Float64, Matrix{Float64}} != LinearDiscreteSystem{Int64, Matrix{Int64}} because Float64 != Int:

function Base.isapprox(sys1::AbstractSystem, sys2::AbstractSystem; kwargs...)
if typeof(sys1) != typeof(sys2)
return false
end

I would thus suggest to replace this check with the (probably intended) check of the ground type.