From 480c2e834f1271d72b974cf6d7d4e6b78e35b40e Mon Sep 17 00:00:00 2001
From: schillic <git@christianschilling.net>
Date: Fri, 10 Jan 2025 17:08:21 +0100
Subject: [PATCH 1/3] fix typo 'homogenization'

---
 docs/src/lib/systems.md                                  | 2 +-
 docs/src/man/systems.md                                  | 2 +-
 src/Continuous/{homogeneization.jl => homogenization.jl} | 8 ++++----
 src/ReachabilityAnalysis.jl                              | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
 rename src/Continuous/{homogeneization.jl => homogenization.jl} (92%)

diff --git a/docs/src/lib/systems.md b/docs/src/lib/systems.md
index ca9eebf18a..36959e8537 100644
--- a/docs/src/lib/systems.md
+++ b/docs/src/lib/systems.md
@@ -24,7 +24,7 @@ normalize(::InitialValueProblem)
 ReachabilityAnalysis.add_dimension
 ```
 
-## Homogeneization
+## Homogenization
 
 ```@docs
 homogenize
diff --git a/docs/src/man/systems.md b/docs/src/man/systems.md
index 23498e040b..c7acf608c1 100644
--- a/docs/src/man/systems.md
+++ b/docs/src/man/systems.md
@@ -74,7 +74,7 @@ in `MathematicalSystems.jl` for additional details in second order ODEs types.
 
 ## Normalization
 
-## Homogeneization
+## Homogenization
 
 ## Nonlinear systems
 
diff --git a/src/Continuous/homogeneization.jl b/src/Continuous/homogenization.jl
similarity index 92%
rename from src/Continuous/homogeneization.jl
rename to src/Continuous/homogenization.jl
index 7c76e30cba..5a08d417ee 100644
--- a/src/Continuous/homogeneization.jl
+++ b/src/Continuous/homogenization.jl
@@ -1,5 +1,5 @@
 # ====================================================
-# Homogeneization of linear systems
+# Homogenization of linear systems
 # ====================================================
 
 # no-op
@@ -9,7 +9,7 @@ homogenize(sys::LCS{N,MT}) where {N,MT<:AbstractMatrix{N}} = sys
 """
     homogenize(ivp::IVP{CLCCS{N,MT,IdentityMultiple{N},XT,ConstantInput{SI}},ST}) where {N, MT<:AbstractMatrix{N}, XT<:LazySet{N}, SI<:Singleton{N}, ST<:LazySet{N}}
 
-Transform an inhomogeneous linear initial-value problem into an homogeneous one
+Transform an inhomogeneous linear initial-value problem into a homogeneous one
 by introducing auxiliary state variables.
 
 ### Input
@@ -23,7 +23,7 @@ Homogeneous initial-value problem.
 ### Notes
 
 This function transforms the canonical initial-value problem ``x' = Ax + u``,
-``x ∈ X`` with ``u(0) ∈ U = {u}`` (a singleton) into an homogeneous problem
+``x ∈ X`` with ``u(0) ∈ U = {u}`` (a singleton) into a homogeneous problem
 without inputs ``y' = Â * y``, ``y ∈ Y``.
 """
 function homogenize(ivp::IVP{CLCCS{N,MT,IdentityMultiple{N},XT,ConstantInput{SI}},ST}) where {N,
@@ -49,7 +49,7 @@ end
 """
     homogenize(sys::SOACS)
 
-Transform an inhomogeneous second order system into an homogeneous one
+Transform an inhomogeneous second order system into a homogeneous one
 by introducing auxiliary state variables.
 
 ### Input
diff --git a/src/ReachabilityAnalysis.jl b/src/ReachabilityAnalysis.jl
index 32020eb042..273d50f9e6 100644
--- a/src/ReachabilityAnalysis.jl
+++ b/src/ReachabilityAnalysis.jl
@@ -27,7 +27,7 @@ include("Flowpipes/solutions.jl")
 # ===========================================================
 include("Continuous/fields.jl")
 include("Continuous/normalization.jl")
-include("Continuous/homogeneization.jl")
+include("Continuous/homogenization.jl")
 include("Continuous/linearization.jl")
 
 # ===========================================================

From b5e884021acd9d867a1b2e7430a472a268a55dff Mon Sep 17 00:00:00 2001
From: schillic <git@christianschilling.net>
Date: Fri, 10 Jan 2025 19:29:19 +0100
Subject: [PATCH 2/3] test homogenization

---
 test/algorithms/BOX.jl | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/test/algorithms/BOX.jl b/test/algorithms/BOX.jl
index 315d9e5071..13e216570a 100644
--- a/test/algorithms/BOX.jl
+++ b/test/algorithms/BOX.jl
@@ -6,7 +6,6 @@
     # continuous algorithm
     sol = solve(ivp; tspan=tspan, alg=alg)
     @test isa(sol.alg, BOX)
-    @test setrep(sol) <: Hyperrectangle
     @test setrep(sol) == Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}
     @test dim(sol) == 1
     # discrete algorithm
@@ -15,6 +14,18 @@
     NSTEPS = 500
     fp_d = ReachabilityAnalysis.post(alg, ivp_discr, NSTEPS)
 
+    # homogenization
+    A = hcat(state_matrix(ivp))
+    X = stateset(ivp)
+    X0 = initial_state(ivp)
+    B = Id(1, 1.0)  # TODO implement for different multiple
+    U = ConstantInput(Singleton([0.0]))
+    ivp2 = @ivp(ConstrainedLinearControlContinuousSystem(A, B, X, U), X(0) ∈ X0)
+    sol2 = solve(ivp2; tspan=(0.0, 1.0), alg=alg, homogenize=true)
+    @test isa(sol2.alg, BOX)
+    @test setrep(sol2) == Hyperrectangle{Float64,Array{Float64,1},Array{Float64,1}}
+    @test dim(sol2) == 2
+
     # higher-dimensional homogeneous
     ivp, tspan = linear5D_homog()
     sol = solve(ivp; tspan=tspan, alg=BOX(; δ=0.01))

From 8f08ae2bdd565bce8787a82722b9e0972c2cb19c Mon Sep 17 00:00:00 2001
From: schillic <git@christianschilling.net>
Date: Fri, 10 Jan 2025 19:30:10 +0100
Subject: [PATCH 3/3] fix homogenization

---
 src/Continuous/homogenization.jl | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/Continuous/homogenization.jl b/src/Continuous/homogenization.jl
index 5a08d417ee..6a63f63817 100644
--- a/src/Continuous/homogenization.jl
+++ b/src/Continuous/homogenization.jl
@@ -2,12 +2,15 @@
 # Homogenization of linear systems
 # ====================================================
 
+using ..DiscretizationModule: next_set
+
 # no-op
 homogenize(ivp::IVP{LCS{N,MT},ST}) where {N,MT<:AbstractMatrix{N},ST} = ivp
 homogenize(sys::LCS{N,MT}) where {N,MT<:AbstractMatrix{N}} = sys
 
 """
-    homogenize(ivp::IVP{CLCCS{N,MT,IdentityMultiple{N},XT,ConstantInput{SI}},ST}) where {N, MT<:AbstractMatrix{N}, XT<:LazySet{N}, SI<:Singleton{N}, ST<:LazySet{N}}
+    homogenize(ivp::IVP{<:CLCCS{N,MTA,MTB,XT,UT},ST}) where {N, MTA<:AbstractMatrix{N},
+        MTB<:IdentityMultiple{N}, XT<:LazySet{N}, UT<:ConstantInput{<:Singleton{N}}, ST<:LazySet{N}}
 
 Transform an inhomogeneous linear initial-value problem into a homogeneous one
 by introducing auxiliary state variables.
@@ -26,22 +29,27 @@ This function transforms the canonical initial-value problem ``x' = Ax + u``,
 ``x ∈ X`` with ``u(0) ∈ U = {u}`` (a singleton) into a homogeneous problem
 without inputs ``y' = Â * y``, ``y ∈ Y``.
 """
-function homogenize(ivp::IVP{CLCCS{N,MT,IdentityMultiple{N},XT,ConstantInput{SI}},ST}) where {N,
-                                                                                              MT<:AbstractMatrix{N},
-                                                                                              XT<:LazySet{N},
-                                                                                              SI<:Singleton{N},
-                                                                                              ST<:LazySet{N}}
+function homogenize(ivp::IVP{<:CLCCS{N,MTA,MTB,XT,UT},ST}) where {N,
+                                                                  MTA<:AbstractMatrix{N},
+                                                                  MTB<:IdentityMultiple{N},
+                                                                  XT<:LazySet{N},
+                                                                  UT<:ConstantInput{<:Singleton{N}},
+                                                                  ST<:LazySet{N}}
     # homogenized state matrix
+    B = input_matrix(ivp)
+    @assert isone(B.M.λ) "input matrix should be normalized"
     U = ReachabilityAnalysis.next_set(inputset(ivp))
     A = state_matrix(ivp)
     Â = _homogenize_state_matrix(A, U)
 
-    # homogenized input set
+    # homogenized initial set
     X0 = initial_state(ivp)
     Y0 = _homogenize_initial_state(X0)
 
+    # homogenized state constraint
     X = stateset(ivp)
     Y = _homogenize_stateset(X)
+
     ivph = IVP(CLCS(Â, Y), Y0)
     return ivph
 end