Safety Filter Design for Neural Network Systems via Convex Optimization
With the increase in data availability, it has been widely demonstrated that
neural networks (NN) can capture complex system dynamics precisely in a
data-driven manner. However, the architectural complexity and nonlinearity of
the NNs make it challenging to synthesize a provably safe controller. In this
work, we propose a novel safety filter that relies on convex optimization to
ensure safety for a NN system, subject to additive disturbances that are
capable of capturing modeling errors. Our approach leverages tools from NN
verification to over-approximate NN dynamics with a set of linear bounds,
followed by an application of robust linear MPC to search for controllers that
can guarantee robust constraint satisfaction. We demonstrate the efficacy of
the proposed framework numerically on a nonlinear pendulum system.
Shaoru Chen, Kong Yao Chee, Nikolai Matni, M. Ani Hsieh, George J. Pappas
# Safety Filter Design for Neural Network Systems via

###### Abstract

With the increase in data availability, it has been widely demonstrated that neural networks (NN) can capture complex system dynamics precisely in a data-driven manner. However, the architectural complexity and nonlinearity of the NNs make it challenging to synthesize a provably safe controller. In this work, we propose a novel safety filter that relies on convex optimization to ensure safety for a NN system, subject to additive disturbances that are capable of capturing modeling errors. Our approach leverages tools from NN verification to over-approximate NN dynamics with a set of linear bounds, followed by an application of robust linear MPC to search for controllers that can guarantee robust constraint satisfaction. We demonstrate the efficacy of the proposed framework numerically on a nonlinear pendulum system.

## I Introduction

With the rapid development in machine learning infrastructure, neural networks (NN) have been ubiquitously applied in the modeling of complex dynamical systems [1, 2]. Through a data collection and training procedure [3], NNs can capture accurate representations of the system dynamics even in challenging scenarios where high-speed aerodynamic effects [4, 5, 6] or contact-rich environments [7, 8] are present. Moreover, NNs can be easily updated online as more data is collected, making them suitable for online tasks or modeling changing environments. For example, NN dynamical systems are widely used in model-based reinforcement learning [9] and learning-based adaptive control [6].

However, applying NN dynamics brings about significant challenges in providing safety guarantees for the controlled system. Benefiting from the expressivity of NNs, we are meanwhile faced with the high nonlinearity and large scale of NNs since they are often overparameterized. The runtime assurance (RTA) [10] mechanism provides a practical and effective solution to guarantee the safety of complex dynamical systems by designing a safety filter that primarily focuses on enforcing safety constraints. Given a primary controller that aims to optimize performance, the safety filter monitors and modifies the output of the primary controller online to guarantee that only safe control inputs are applied. The safety filter allows the design of the safety and performance-based controllers to be decoupled and has found wide applications in safe learning-based control [11, 12, 13].

In this work, we focus on the design of a predictive safety filter (PSF) [14] for uncertain NN dynamics. The PSF essentially follows a model predictive control (MPC) formulation with the nonlinear dynamics and constraints encoded in an optimization problem. Different from MPC, the PSF is less complex to solve since it does not consider any performance objectives [14]. Compared with the alternative safety filter construction schemes through control barrier functions (CBF) [15, 16] or Hamilton-Jacobi (HJ) reachability analysis [17, 18], the PSF enjoys flexibility in handling dynamically changing NN models or model uncertainty bounds when updated online. We refer the interested readers to [14, Section 1 and 2] for a detailed discussion of the PSF, CBF, and HJ reachability-based safety filters.

**Contributions**: In this work, we consider uncertain NN dynamics subject to bounded additive disturbances, where the disturbances can encapsulate the errors between the learned NN dynamics and the true system. Despite being highly expressive, the considered uncertain NN dynamics requires solving a robust optimization problem involving NN dynamical constraints online in the PSF. To resolve this computational challenge, we propose to apply NN verification tools [19] to abstract the NN dynamics locally as a linear uncertain system, thereby reducing the original PSF problem into one that is amenable to robust linear MPC and convex optimization. In particular, we adapt the SLS (System Level Synthesis) MPC method [20] to solve the resulting robust MPC problem. A schematic of our pipeline is shown in Fig. 1. Soft constraints are used in robust linear MPC where slack variables denoting constraint violations are penalized. By applying a hierarchy of conservative function and model uncertainty approximations, we transform the original optimization problem into a convex one. A safety certificate for the uncertain NN dynamics over a finite horizon can then be provided when all slack variables are zero. Our contributions are summarized below.

1. Drawing tools from NN verification and robust linear MPC, we propose a novel predictive safety filter for uncertain NN dynamics through convex optimization. Importantly, the complexity of the convex optimization problem is independent of the NN size (i.e., width and depth of the NN).
2. Our PSF provides a safety certificate for the uncertain NN dynamics over a finite horizon when a certain numerical criterion is met by the convex optimization solutions.
### _Related works_

The problem of ensuring the safety of learning-based systems has received significant interest with a plethora of methods described in [21]. Directly related to our work is the PSF developed in [14], which monitors and modifies a given control input by solving a predictive control problem online to guarantee the safety of the system. This formulation has been extended to the SLS setting [22], applied to racing cars [12] and a soft-constrained variant is proposed in [23] to handle unexpected disturbances to the states. The PSF that we propose differs from those in the existing work in the following ways. First, we exploit the structure of the neural networks to extract linear bounds on the NN outputs using NN verification tools [19, 24], simplifying the PSF formulation for NN dynamics. Second, our proposed pipeline circumvents the need to solve a robust non-convex optimization problem, even with the consideration of additive disturbances within the uncertain dynamics, as typical for nonlinear variants of SLS [25]. Unlike existing work in predictive control of NN dynamics [2, 26, 27], our work considers robust control of uncertain NN dynamics with a focus on obtaining formal safety guarantees.

_Notation_: \([N]\) denotes the set \(\{0,1,\ldots,N\}\). \(\mathcal{B}_{p}(z,r)\) denotes the \(\ell_{p}\) ball centered at \(z\) with radius \(r\). We use \(x_{0:T}\) to denote the sequence \(\{x_{0},\ldots,x_{T}\}\). \(\mathbf{0}\) denotes a vector of all zeros, and its dimension can be inferred from context. For a vector \(d\in\mathbb{R}^{n}\), \(S=\text{diag}(d)\in\mathbb{R}^{n\times n}\) denotes a diagonal matrix with \(d\) being the diagonal vector. For a sequence of matrices \(S_{1},\cdots,S_{N}\), \(S=\text{blkdiag}(S_{1},\cdots,S_{N})\) denotes a block diagonal matrix whose diagonal blocks are \(S_{1},\cdots,S_{N}\) arranged in the order. We represent a linear, causal operator \(\mathbf{R}\) defined over a horizon \(T\) by the block-lower-triangular matrix

\[\mathbf{R}=\begin{bmatrix}R^{0,0}&&&\\ R^{1,1}&R^{1,0}&&\\ \vdots&\ddots&\ddots&\\ R^{T,T}&\cdots&R^{T,1}&R^{T,0}\end{bmatrix} \tag{1}\]

where \(R^{i,j}\in\mathbb{R}^{p\times q}\) is a matrix of compatible dimension. The set of such matrices is denoted by \(\mathcal{L}_{TV}^{T,p\times q}\) and the superscript \(T\) or \(p\times q\) will be dropped when it is clear from the context.

## II Problem Formulation

Consider the following discrete-time nonlinear system,

\[x(k+1)=Ax(k)+Bu(k)+f\left(x(k),u(k)\right)+w(k), \tag{2}\]

where the vectors \(x(k)\in\mathbb{R}^{n_{x}}\) and \(u(k)\in\mathbb{R}^{n_{u}}\) are the state and control input. The vector \(w(k)\in\mathbb{R}^{n_{x}}\) denotes the additive disturbances that can account for unknown effects from the environment or unmodeled dynamics. We assume that \(w(k)\) is norm-bounded, _i.e._, \(w(k)\in\mathcal{W}:=\{w\mid\|w\|_{\infty}\leq\sigma_{w}\}\). The system consists of a set of linear dynamics characterized by the matrices \(A\) and \(B\) and a set of nonlinear dynamics, \(f(x(k),u(k))\). Specifically, these nonlinear dynamics are given by a NN \(f:\mathbb{R}^{n_{x}+n_{u}}\mapsto\mathbb{R}^{n_{x}}\) with an arbitrary architecture. While we discuss our proposed approach taking into account a general formulation of dynamics in (2), the approach allows the matrices \(A\) and \(B\) to be zero and has the flexibility to account for time-varying dynamics \((A(k),B(k))\). The system (2) is required to satisfy the following constraints,

\[x(k)\in\mathcal{X},\quad u(k)\in\mathcal{U}, \tag{3}\]

where \(\mathcal{X}\subset\mathbb{R}^{n_{x}}\) and \(\mathcal{U}\subset\mathbb{R}^{n_{u}}\) are polytopes. The state \(x(k)\) and input \(u(k)\) are considered _safe_ if they satisfy constraints (3).

### _Predictive safety filter_

We assume a primary controller \(\pi(x)\) which aims to complete a task or achieve high performance is given for system (2). Following the runtime assurance scheme, the primary controller \(\pi(x)\) is not guaranteed to be safe since its design may be decoupled from the safety requirements. To ensure constraint satisfaction of the closed-loop system, we aim to design a predictive safety filter that monitors and modifies the control input \(\pi(x(k))\) given by the primary controller in a minimally invasive manner online. This is achieved by solving the following robust optimization problem at each time step \(k\),

\[\begin{split}\underset{u_{0:T-1}}{\text{minimize}}& \|u_{0}-\pi(x(k))\|_{2}^{2}\\ \text{subject to}& x_{t+1}=Ax_{t}+Bu_{t}+f(x_{t},u_{t})+w_{t},\\ & x_{t}\in\mathcal{X},u_{t}\in\mathcal{U},\forall w_{t}\in \mathcal{W},\quad t\in[T],\\ & x_{0}=x(k),\end{split} \tag{4}\]

where the vectors \(x_{t},\,u_{t}\) denote the predicted states and inputs over the horizon \(T\), with \(x(k)\) representing the current state of the system. We denote Problem (4) as the PSF problem and the sequence \(u_{0:T-1}^{*}\) as the optimal solution of Problem (4). When applied, the control inputs \(u_{0:T-1}^{*}\) can guarantee the safety of the system for the next \(T\) steps. In practice, the PSF problem (4) is solved recursively at each time step \(k\), and the first optimal control input \(u_{0}^{*}\) is applied to the system, analogous to an MPC scheme.

Fig. 1: Pipeline of the proposed predictive safety filter for uncertain NN systems.
### _Challenges with the predictive safety filter_

While the solution to Problem (4) is able to provide safety guarantees, solving Problem (4) is a challenging task. Some potential issues include

1. it is well known in robust MPC that searching over open-loop control sequences \(u_{0:T-1}\) can be overly conservative [28],
2. the presence of the NN dynamics \(f(x,u)\) makes solving the PSF computationally challenging,
3. the safety certificate of the solution \(u_{0:T-1}^{*}\) is not available until convergence is reached, and
4. without the availability of a robust forward invariant set, attempting to solve the PSF may result in infeasibility.

To handle all the aforementioned issues, we combine NN verification tools [19] and robust MPC [20]. Our solution consists of two steps. First, we generate local linear bounds for the NN dynamics \(f(x,u)\) using tools from NN verification. Next, we apply robust linear MPC to synthesize a state feedback control policy that guarantees robust constraint satisfaction for the system. This combined procedure provides a powerful simplification of the PSF problem and resolves issues (i) to (iii). To address the issue (iv), we introduce soft constraints in our formulation. This provides formal safety guarantees for the system when the slack variables are zero. We describe these two steps in Sections III and IV, respectively. Section V demonstrates our method numerically, and Section VI concludes the paper.

**Remark 1**: _To ensure the safety constraints are satisfied at all times or guarantee recursive feasibility of the PSF (4), a local forward invariant set for the nonlinear system (2) is required, which is generally challenging to find. In this work, we do not assume the availability of such a forward invariant set and use slack variables as numerical certificates of safety. We leave the synthesis of the forward invariant terminal set for NN dynamics and its integration into the PSF as part of our future work._

## III Neural network verification bounds

In this section, we demonstrate how tools from NN verification can be utilized to over-approximate the NN dynamics with a linear time-varying (LTV) representation. This enables us to conservatively transform the PSF problem into a robust convex optimization problem, which is simpler to solve.

Given a bounded input set, the linear relaxation-based perturbation analysis (LiRPA) [19] is an efficient method to synthesize linear lower and upper bounds for the outputs of a NN with a general architecture. The bounds computed from this method are described in the following theorem.

**Theorem 1**: _(rephrasing [24, Theorem 3.2]) Given a NN \(f(z):\mathbb{R}^{n_{0}}\mapsto\mathbb{R}^{n_{L}}\), there exist two explicit linear functions \(f_{U}:\mathbb{R}^{n_{0}}\mapsto\mathbb{R}^{n_{L}}\) and \(f_{L}:\mathbb{R}^{n_{0}}\mapsto\mathbb{R}^{n_{L}}\) such that for all \(z\in\mathcal{B}_{p}(z_{0},r)\), we have_

\[f_{L}(z)=A_{L}z+b_{L}\leq f(z)\leq A_{U}z+b_{U}=f_{U}(z), \tag{5}\]

_where the inequalities are applied component-wise._

The parameters \(A_{L},A_{U},b_{L},b_{U}\) are derived from the weights, biases and activation functions of the NN. In this paper, we choose \(p:=\infty\) such that \(\mathcal{B}_{\infty}(z,r)\) is polyhedral. The bounds (5) are computed using closed-form updates with a computational complexity polynomial in the number of neurons [24]. This allows the method to scale well to deep networks. However, if the NN is deep or if the input domain \(\mathcal{B}_{\infty}(z,r)\) is large, the computed bounds tend to be loose. Motivated by this observation, we propose to extract a set of local linear bounds along a _reference trajectory_. Specifically, at every time step \(k\), we construct a reference trajectory given by the sequences of reference states \(\mathbf{\hat{x}}:=\hat{x}_{0:T}\) and control inputs \(\mathbf{\hat{u}}:=\hat{u}_{0:T-1}\) where

\[\begin{split}\hat{x}_{t+1}&=A\hat{x}_{t}+B\hat{u}_{ t}+f(\hat{x}_{t},\hat{u}_{t}),\quad t\in[T-1],\\ \hat{x}_{0}&=x(k).\end{split} \tag{6}\]

The reference control inputs \(\mathbf{\hat{u}}\) can be obtained, e.g., by rolling out the nominal NN dynamics following the primary policy \(\pi(\cdot)\). By denoting \(z_{t}:=[x_{t}^{\top}\;u_{t}^{\top}]^{\top}\), \(\hat{z}_{t}:=[\hat{x}_{t}^{\top}\;\hat{u}_{t}^{\top}]^{\top}\) and \(r_{t}\) to be the radius of the \(\ell_{\infty}\) ball around \(\hat{z}_{t}\), we apply Theorem 1 to get the following bounds for the NN dynamics along the reference trajectory,

\[\begin{bmatrix}\bar{G}_{t}^{x}&\bar{G}_{t}^{u}\end{bmatrix}z_{t}+\underline {g}_{t}\leq f(x_{t},u_{t})\leq\begin{bmatrix}\bar{G}_{t}^{x}&\bar{G}_{t}^{u} \end{bmatrix}z_{t}+\overline{g}_{t}, \tag{7}\]

for all \((x_{t},u_{t})\in\mathcal{B}_{\infty}(\hat{z}_{t},r_{t})\). In other words, the NN dynamics \(f(x_{t},u_{t})\) is over-approximated with a set of linear lower and upper bounds. The ball \(\mathcal{B}_{\infty}(\hat{z}_{t},r_{t})\) is referred to as the _trust region_ in which the bounds (7) are valid.

To reduce conservatism in the formulation of the filter within the robust MPC framework, we integrate the bounds into the linear dynamics of the system. Specifically, using the bounds in (7), we define

\[f_{d}(x_{t},u_{t}):=f(x_{t},u_{t})-\left(\tilde{A}_{t}x_{t}+\tilde{B}_{t}u_{t}+ \tilde{c}_{t}\right), \tag{8}\]

where

\[\tilde{A}_{t}:=\frac{\bar{G}_{t}^{x}+\bar{G}_{t}^{x}}{2},\;\tilde{B}_{t}:= \frac{\bar{G}_{t}^{u}+\bar{G}_{t}^{u}}{2},\;\tilde{c}_{t}:=\frac{\underline{g}_ {t}+\overline{g}_{t}}{2} \tag{9}\]

denote the means of the linear bounds.

**Corollary 1**: _Given the bounds in (7), for every \(z_{t}:=[x_{t}^{\top}\;u_{t}^{\top}]^{\top}\in\mathcal{B}_{\infty}(\hat{z}_{t},r _{t})\), the dynamics \(f_{d}(x_{t},u_{t})\) in (8) have the following bounds,_

\[\begin{bmatrix}\underline{D}_{t}^{x}&\underline{D}_{t}^{u}\end{bmatrix}z_{t}+ \underline{d}_{t}\leq f_{d}(x_{t},u_{t})\leq\begin{bmatrix}\bar{D}_{t}^{x}& \bar{D}_{t}^{u}\end{bmatrix}z_{t}+\overline{d}_{t}, \tag{10}\]

_where_

\[\underline{D}_{t}^{x}=\frac{\underline{G}_{t}^{x}-\bar{G}_{t}^{x}}{2}=-\bar{D}_ {t}^{x},\;\;\underline{D}_{t}^{u}=\frac{\underline{G}_{t}^{u}-\bar{G}_{t}^{u} }{2}=-\bar{D}_{t}^{u},\]

\[\underline{d}_{t}=\frac{\underline{g}_{t}-\overline{g}_{t}}{2}=-\overline{d}_{t}.\]

It is important to note that although the NN dynamics \(f(x_{t},u_{t})\) can have large values within the trust region \(\mathcal{B}_{\infty}(\hat{z}_{t},r_{t})\), the dynamics \(f_{d}(x_{t},u_{t})\) tends to be small in magnitude and can be treated as disturbances to the system. With the extraction of \(f_{d}(x_{t},u_{t})\), we obtain an LTV reformulation of the PSF problem, referred to as the _linear
_PSF_ problem,

\[\underset{u_{0:T-1}}{\text{minimize}} \|u_{0}-\pi(x(k))\|_{2}^{2}\] (11) subject to \[x_{t+1}=A_{t}x_{t}+B_{t}u_{t}+c_{t}+\Delta_{t}(x_{t},u_{t})+w_{t},\] \[(x_{t},u_{t})\in\mathcal{B}_{\infty}\left(\hat{z}_{t},r_{t} \right),\quad t\in[T-1],\] \[x_{t}\in\mathcal{X},\,u_{t}\in\mathcal{U},\quad t\in[T],\] \[\forall\Delta_{t}(\cdot)\in\mathcal{P}_{t},\,w_{t}\in\mathcal{W},\quad t\in[T],\] \[x_{0}=x(k),\]

where the means in (9) are merged into the linear dynamics of the system with the definition of the following time-varying system parameters 1,

Footnote 1: When a time-varying dynamics \((A(k),B(k))\) is considered in (2), we can replace \((A,B)\) by their time-varying counterparts in the definitions of \((A_{t},B_{t})\).

\[A_{t}:=A+\tilde{A}_{t},\,B_{t}:=B+\tilde{B}_{t},\,c_{t}:=\tilde{c}_{t}.\]

The uncertainty set \(\mathcal{P}_{t}\) is given as

\[\mathcal{P}_{t}:=\begin{cases}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\! \!\!
MPC methods [30, 31, 32, 33], requires \(2^{n_{x}}\) vertices, (ii) applying SLS MPC requires merging the constant \(c_{t}\) into the lumped uncertainty \(\xi_{t}\) which causes the bounds on \(\mathbf{\xi}\) to be overly conservative. In the following subsections, we describe an extension to SLS MPC to address these two challenges.

### _Controller parameterization_

For the uncertain linear dynamics

\[x_{t+1}=A_{t}x_{t}+B_{t}u_{t}+c_{t}+\Delta_{t}(x_{t},u_{t})+w_{t} \tag{18}\]

stated in (11), we define \(\eta_{t}:=\Delta_{t}(x_{t},u_{t})+w_{t}\) as the lumped uncertainty. Instead of treating \(\xi_{t}=c_{t}+\eta_{t}\) in (13), we decompose (18) into a set of nominal and error dynamics.

First, in addition to (14), we concatenate these variables over the horizon \(T\),

\[\mathbf{\eta} :=[\mathbf{0}^{\top}~{}\eta_{0}^{\top}~{}\cdots~{}\eta_{T-1}^{\top}]^ {\top},~{}\mathbf{w}:=[\mathbf{0}^{\top}~{}w_{0}^{\top}~{}\cdots~{}w_{T-1}^{\top}]^ {\top}, \tag{19}\] \[\mathbf{c} :=[\mathbf{0}^{\top}c_{0}^{\top}~{}\cdots~{}c_{T-1}^{\top}]^{\top}, \quad\mathbf{\delta}_{x_{0}}:=[x_{0}^{\top}~{}\mathbf{0}^{\top}~{}\cdots~{}\mathbf{0}^{ \top}]^{\top}.\]

We define the nominal and error states \(\{\mathbf{h},\mathbf{x}_{e}\}\) and control inputs \(\{\mathbf{v},\mathbf{u}_{e}\}\) as

\[\mathbf{h} :=[h_{0}^{\top}~{}\cdots~{}h_{T}^{\top}]^{\top},~{}~{}\mathbf{v}:=[ v_{0}^{\top}~{}\cdots~{}v_{T}^{\top}]^{\top},\] \[\mathbf{x}_{e} :=[x_{e,0}^{\top}~{}\cdots~{}x_{e,T}^{\top}]^{\top}=\mathbf{x}- \mathbf{h},\] \[\mathbf{u}_{e} :=[u_{e,0}^{\top}~{}\cdots~{}u_{e,T}^{\top}]^{\top}=\mathbf{u}- \mathbf{v},\]

with the nominal and error dynamics as

\[\mathbf{h} =Z(\mathbf{A}\mathbf{h}+\mathbf{B}\mathbf{v})+\mathbf{c}+\mathbf{ \delta}_{x_{0}}, \tag{20a}\] \[\mathbf{x}_{e} =Z(\mathbf{A}\mathbf{x}_{e}+\mathbf{B}\mathbf{u}_{e})+\mathbf{\eta}. \tag{20b}\]

It is important to note that (20b) conforms with (13). A LTV state feedback controller \(\mathbf{K}\in\mathcal{L}_{TV}^{T,n_{x}\times n_{x}}\) is then applied to control the error states. The overall controller for (18) is given by \(\mathbf{u}=\mathbf{K}\mathbf{x}_{e}+\mathbf{v}=\mathbf{K}(\mathbf{x}-\mathbf{h })+\mathbf{v}\).

### _Lumped uncertainty over-approximation_

For the lumped uncertainty \(\mathbf{\eta}\), its dependence on \(\mathbf{x}\), \(\mathbf{u}\) and \(\mathbf{w}\) complicates the design of the robust controller. As in SLS MPC, the approach is to over-approximate \(\mathbf{\eta}\) by an independent, filtered virtual disturbance signal \(\mathbf{\Psi}\widetilde{\mathbf{w}}\), where \(\widetilde{\mathbf{w}}=[\mathbf{0}^{\top}~{}\widetilde{w}_{0}^{\top}~{}\cdots~{} \widetilde{w}_{T-1}^{\top}]^{\top},~{}\|\widetilde{w}_{t}\|_{\infty}\leq 1\). The matrix \(\mathbf{\Psi}\in\mathcal{L}_{TV}^{T,n_{x}\times n_{x}}\) is a filter operating on the finite-horizon virtual disturbance signal \(\widetilde{\mathbf{w}}\), with its diagonal blocks of \(\mathbf{\Psi}\) structured as \(\Psi^{0,0}=I,\Psi^{t,0}=\text{diag}(\psi_{t-1})\) with \(\psi_{t-1}\in\mathbb{R}^{n_{x}},\psi_{t-1}>0\), \(t=1,\ldots,T\).

We define \(\widetilde{\mathcal{W}}=\{\widetilde{\mathbf{w}}\mid\|\widetilde{w}_{t}\|_{ \infty}\leq 1,t\in[T-1]\}\) as the set of admissible virtual disturbances. Since \(\tilde{w}_{t}\) are unit norm-bounded, we tune the filter \(\mathbf{\Psi}\) to change the reachable set of \(\mathbf{\Psi}\widetilde{\mathbf{w}}\), defined as \(\mathcal{R}(\mathbf{\Psi}\widetilde{\mathbf{w}}):=\{\mathbf{\zeta}\mid\mathbf{\zeta}=\bm {\Psi}\widetilde{\mathbf{w}},\widetilde{\mathbf{w}}\in\widetilde{\mathcal{W}}\}\), \(\mathbf{\zeta}:=[\mathbf{0}^{\top}~{}\zeta_{0}^{\top}~{}\cdots~{}\zeta_{T-1}^{\top}]^ {\top}\).

Our goal is to find sufficient conditions on the control parameters \(\{\mathbf{K},\mathbf{h},\mathbf{v}\}\) and \(\mathbf{\Psi}\) such that the reachable set of \(\mathbf{\eta}\), denoted by \(\mathcal{R}\left(\mathbf{\eta};\mathbf{K},\mathbf{h},\mathbf{v}\right):=\{\mathbf{ \eta}\mid\eta_{t}=\Delta_{t}(x_{t},u_{t})+w_{t},\Delta_{t}\in\mathcal{P}_{t}, \,t\in[T-1]\}\), is a subset of the reachable set of \(\mathbf{\Psi}\widetilde{\mathbf{w}}\). The following proposition provides these sufficient conditions and the proof is given in Appendix A.

**Proposition 1**: _Let \(e_{i}\in\mathbb{R}^{n_{x}}\) denote the \(i\)-th standard basis for \(i=1,\ldots,n_{x}\) and \(y_{t}=[h_{t}^{\top}~{}v_{t}^{\top}]^{\top}\), \(\Phi^{t,t-i}:=\left[\Phi_{x}^{t,t-i\top}~{}\Phi_{u}^{t,t-i\top}\right]^{\top}\) for \(t\in[T-1]\). The following constraints:_

\[\left[I-Z\mathbf{A}\quad-Z\mathbf{B}\right]\begin{bmatrix}\mathbf{\Phi}_{x}\\ \mathbf{\Phi}_{u}\end{bmatrix}=\mathbf{\Psi},~{}\mathbf{\Phi}_{x},\mathbf{\Phi}_{u}\in\mathcal{ L}_{TV}^{T}, \tag{21}\]

_and_

\[\sigma_{w}+e_{i}^{\top}([\overline{D}_{0}^{x}~{}\overline{D}_{0}^{u}] y_{0}+\overline{d}_{0}) \leq\psi_{0,i}, \tag{22a}\] \[\sigma_{w}-e_{i}^{\top}\left([\overline{D}_{0}^{x}~{}\overline{D}_{0}^{u}] y_{0}+\underline{d}_{0}\right) \leq\psi_{0,i},\] (22b) \[\sigma_{w}+e_{i}^{\top}\Big{(}[\overline{D}_{t}^{x}~{}\overline{D}_ {t}^{u}]y_{t}+\overline{d}_{t}\Big{)}+\] \[\sum_{i=1}^{t}\Big{\|}e_{i}^{\top}\Big{(}[\overline{D}_{t}^{x}~{} \overline{D}_{t}^{u}]\Phi^{t,t-i}-\Psi^{t+1,t+1-i}\Big{)}\Big{\|}_{1}\leq\psi_{t,i},\] (22c) \[\sigma_{w}-e_{i}^{\top}\Big{(}[\overline{D}_{t}^{x}~{}\underline{D}_ {t}^{u}]y_{t}+\underline{d}_{t}\Big{)}+\] \[\sum_{i=1}^{t}\Big{\|}e_{i}^{\top}\Big{(}[\overline{D}_{t}^{x}~{} \underline{D}_{t}^{u}]\Phi^{t,t-i}-\Psi^{t+1,t+1-i}\Big{)}\Big{\|}_{1}\leq\psi_{t,i},\] (22d) \[i\in[n_{x}],\quad t=1,\cdots,T-1,\]

_guarantee that \(\mathcal{R}(\mathbf{\eta};\mathbf{K},\mathbf{h},\mathbf{v})\subseteq\mathcal{R}( \mathbf{\Psi}\widetilde{\mathbf{w}})\) holds._

### _Convex formulation of the linear PSF_

With the constraints (21) and (22), we have for any realization of \(\mathbf{\eta}\), there exists \(\widetilde{\mathbf{w}}\in\widetilde{\mathcal{W}}\) such that \(\mathbf{\eta}=\mathbf{\Psi}\widetilde{\mathbf{w}}\). Therefore, we can represent \(\mathbf{\eta}\) as \(\mathbf{\Psi}\widetilde{\mathbf{w}}\) and write the error dynamics (20b) as

\[\mathbf{x}_{e}=Z(\mathbf{A}\mathbf{x}_{e}+\mathbf{B}\mathbf{u}_{e})+\mathbf{\Psi} \widetilde{\mathbf{w}}. \tag{23}\]

By [20, Corollary 1], we have constraint (21) parameterizes all system responses \(\mathbf{x}_{e}=\mathbf{\Phi}_{x}\widetilde{\mathbf{w}},\mathbf{u}_{e}=\mathbf{\Phi}_{u }\widetilde{\mathbf{w}}\) of system (23) under the controller \(\mathbf{u}_{e}=\mathbf{K}\mathbf{x}_{e}\). Then, the closed-loop states and control inputs of system (18) are given by

\[\mathbf{x}=\mathbf{h}+\mathbf{\Phi}_{x}\widetilde{\mathbf{w}},\quad\mathbf{u}= \mathbf{v}+\mathbf{\Phi}_{u}\widetilde{\mathbf{w}}. \tag{24}\]

To
guarantee for the constraint with parameters \((a_{j}^{x},b_{j}^{x})\). Similarly, the input constraints can be tightened as

\[\begin{split} a_{k}^{u\top}v_{t}+\sum_{i=1}^{t}\left\|a_{k}^{u \top}\Phi_{u}^{t,t-i}\right\|_{{}_{1}}\leq b_{k}^{u}+\epsilon_{u,k}^{t},\quad \epsilon_{u,k}^{t}\geq 0,\,t\in[T],\\ k=1,\ldots,n_{\mathcal{U}},\end{split} \tag{27}\]

where \(n_{\mathcal{U}}\) denotes the number of linear inequalities defining \(\mathcal{U}\) and \((a_{k}^{u},b_{k}^{u})\) denotes the \(k\)-th set of linear constraint parameters in \(\mathcal{U}\). The trust region constraints \((x_{t},u_{t})\in\mathcal{B}_{\infty}\left(\hat{z}_{t},r_{t}\right)\) analogously can be tightened as

\[\begin{split} a_{j}^{\top}h_{t}+\sum_{i=1}^{t}\left\|a_{j}^{\top }\Phi_{x}^{t,t-i}\right\|_{{}_{1}}\leq b_{j}+\sigma_{x,j}^{t},\,\sigma_{x,j}^{ t}\geq 0,\\ a_{k}^{\top}v_{t}+\sum_{i=1}^{t}\left\|a_{k}^{\top}\Phi_{u}^{t, t-i}\right\|_{{}_{1}}\leq b_{k}+\sigma_{u,k}^{t},\,\sigma_{u,k}^{t}\geq 0,\\ j=1,\ldots,2n_{x},\,k=1,\ldots,2n_{u},\,t\in[T-1],\end{split} \tag{28}\]

where \((a_{j},b_{j})\) and \((a_{k},b_{k})\) are defined similarly for the state and input-related constraint parameters in \(\mathcal{B}_{\infty}\left(\hat{z}_{t},r_{t}\right)\).

Summarizing the results above, we propose a convex tightening of the linear PSF, which can be written as

\[\begin{split}\underset{\begin{subarray}{c}\mathbf{\Phi}_{x},\mathbf{ \Phi}_{u},\mathbf{\Psi}_{y},\mathbf{\mathrm{h}},\mathbf{\mathrm{v}},\\ \left\{\epsilon_{x}^{t},\epsilon_{u}^{t},\sigma_{x}^{t},\sigma_{u}^{t}\right\} \end{subarray}}{\text{minimize}}&\left\|u_{0}-\pi(x(k))\right\|_{ {}_{2}}^{2}+M_{\epsilon}\sum_{t=0}^{T}\left(\left\|\epsilon_{x}^{t}\right\|_{ {}_{1}}+\left\|\epsilon_{u}^{t}\right\|_{{}_{1}}\right)\\ &+M_{\sigma}\sum_{t=0}^{T-1}\left(\left\|\sigma_{x}^{t}\right\|_{ {}_{1}}+\left\|\sigma_{u}^{t}\right\|_{{}_{1}}\right)\end{split}\]

subject to \[\begin{split}&\text{\small over-approximation constraints \eqref{eq:constraintconstraintconstraint},}\\ &\text{\small soft state and input constraints \eqref{eq:constraintconstraintconstraint} and \eqref{eq:constraintconstraintconstraint},}\\ &\text{\small soft trust region constraints \eqref{eq:constraintconstraintconstraint},}\\ & x_{0}=x(k),\end{split}\] (29)

where \(M_{\epsilon},M_{\sigma}>0\) are chosen as large numbers. When a polyhedral robust forward invariant set is used as the terminal constraint, we can tighten it similarly as (26). All the constraints in Problem (29) are linear, making (29) a quadratic program. With the use of soft constraints, (29) is always feasible. If the slack variables \(\{\epsilon_{x}^{t},\epsilon_{u}^{t},\sigma_{x}^{t},\sigma_{u}^{t}\}\) in the solution are zero, we obtain a certificate that the system is safe for the next \(T\) steps under the state-feedback controller \(\mathbf{\mathrm{u}}=\mathbf{\mathrm{K}}(\mathbf{\mathrm{x}}-\mathbf{\mathrm{h}})+\mathbf{\mathrm{v}}\) with \(\mathbf{\mathrm{K}}=\mathbf{\Phi}_{u}\mathbf{\Phi}_{x}^{-1}\).

### _Trust region update_

Following the discussion on the trust regions in Section III, we describe a method to update the trust regions online. Starting with the reference trajectory given by the primary policy \(\pi(x)\), we propose to iteratively increase \(r_{t}\) and update the reference trajectory by applying the policy \(\mathbf{\mathrm{u}}=\mathbf{\mathrm{K}}(\mathbf{\mathrm{x}}-\mathbf{\mathrm{h}})+\mathbf{\mathrm{v}}\), synthesized in Section IV. We then pick the reference trajectory that gives the smallest slack variables and apply the corresponding control inputs to the system. Our framework is summarized in Algorithm 1.

**Input:** Current state \(x(k)\), horizon \(T\), number of iterations \(N\), initial reference trajectory \(\hat{z}_{0:T}\), reference control input \(\pi(x(k))\), initial trust region radius \(r_{0}>0\)

**Output:** Filtered control input \(u_{0}^{*}\), safety certificate safe_cert

```
1:At each time step \(k\),
2:Initialize:\(r_{t}\gets r_{0},\ t\in[T-1],\{\mathbf{\mathrm{K}}^{*},\mathbf{\mathrm{h}}^{*},\mathbf{ \mathrm{v}}^{*}\}\leftarrow\{\mathbf{0}\}\), \(\epsilon^{*}\leftarrow\infty\).
3:for\(\ell=1,\ldots,N\)do
4: Construct \(\mathcal{B}_{\infty}(\hat{z}_{t},r_{t})\) and \(\mathcal{P}_{t}\) with (7) and (10)
5: Solve (29) with \(x(k)\) to get \(\{\mathbf{\mathrm{K}},\mathbf{\mathrm{h}},\mathbf{\mathrm{v}}\}\)
6: Extract \(\epsilon_{max}:=\) max. value of slack variables
7:if\(\epsilon_{max}=0\)then
8: Set \(\{\mathbf{\mathrm{K}}^{*},\mathbf{\mathrm{h}}^{*},\mathbf{\mathrm{v}}^{*}\}\leftarrow\{\mathbf{ \mathrm{K}},\mathbf{\mathrm{h}},\mathbf{\mathrm{v}}\}\)
9: Set safe_cert \(\leftarrow\) True
10:else
11: Update \(\hat{z}_{0:T}\) with \(\mathbf{\mathrm{u}}=\mathbf{\mathrm{K}}(\mathbf{\mathrm{x}}-\mathbf{\mathrm{h}})+\mathbf{\mathrm{v}}\), as described in (6)
12: Update \(r_{t}\leftarrow\beta r_{t}\) for \(t\in[T-1]\) with \(\beta>1\).
13:if\(\epsilon_{max}\leq\epsilon^{*}\)then
14: Set \(\epsilon^{*}\leftarrow\epsilon_{max}\)
15: Set \(\{\mathbf{\mathrm{K}}^{*},\mathbf{\mathrm{h}}^{*},\mathbf{\mathrm{v}}^{*}\}\leftarrow\{\mathbf{ \mathrm{K}},\mathbf{\mathrm{h}},\mathbf{\mathrm{v}}\}\)
16: Set safe_cert \(\leftarrow\) False
17:Set \(u_{0}^{*}\gets v_{0}\), extracted from \(\{\mathbf{\mathrm{K}}^{*},\mathbf{\mathrm{h}}^{*},\mathbf{\mathrm{v}}^{*}\}\)
```

**Algorithm 1** Robust Linear MPC-based PSF

## V Numerical Example

To verify the efficacy of the proposed solution, we test it on a NN proxy of the nonlinear pendulum system 2. The pendulum consists of the following dynamics [34],

Footnote 2: Our codes are publicly available at [https://github.com/ShaorucChen/NN-System-PSF](https://github.com/ShaorucChen/NN-System-PSF).

\[\ddot{\theta}=\frac{3g\sin(\theta)}{2l}+\frac{3\tau}{ml^{2}}\,, \tag{30}\]

where \(\theta\) is the angle between the pendulum and the vertical, \(m\) and \(l\) are the mass and length of the pendulum, \(g\) is the gravitational force, and \(\tau\) is the external torque acting on the pendulum. The state and control input are defined as \(x:=[\theta\ \dot{\theta}]^{\top}\in\mathbb{R}^{2}\) and \(u:=\tau\in\mathbb{R}\). To obtain the linear dynamics in (2), the dynamics (30) are linearized about the origin and discretized with a sampling time of 0.05s to obtain the following dynamics,

\[x_{t+1}=\begin{bmatrix}1.0092&0.05015\\ 0.369&1.0092\end{bmatrix}x_{t}+\begin{bmatrix}0.00125\\ 0.05015\end{bmatrix}u_{t}. \tag{31}\]

Next, we train a NN \(f(x,u)\) to approximate the residual dynamics that are not captured by the linear dynamics in (31). We first collect data by simulating the nonlinear dynamics in (30) for a duration of 15s. The NN is then trained through a backpropagation procedure [3], using the mean squared errors between the predicted and true states as the loss function. The NN consists of 3 hidden layers with 64 neurons in each layer and uses the rectified linear unit (ReLU) as the activation function. Additive noise with
a maximum magnitude \(\sigma_{w}\) of \(\{0.05,0.1\}\) is injected into the states of the system. For the primary control policy, we consider an iterative linear quadratic regulator (iLQR) scheme [35] with the box-constrained heuristic [36]. This is implemented with the _mpc.pytorch_ library [37]. The box-constrained heuristic allows the system to adhere to the control constraints, but does not account for state constraints.

Four test cases are considered in our experiments. In each of these cases, the system is required to track a pair of reference angles \((\theta_{r,1},\,\theta_{r,2})\) sequentially, starting from an initial condition \(x_{0}\) and across a duration of 2s. The initial conditions and reference angles are given in Table I. We simulate each of these test cases under 4 control schemes - (i) a nominal iLQR framework, (ii) a soft-constrained iLQR framework (SC-iLQR), (iii) safe-filtered iLQR, where we apply the proposed safety filter to the nominal iLQR scheme, and (iv) safe-filtered SC-iLQR, where the safety filter is applied to SC-iLQR. For SC-iLQR, soft state constraints are incorporated into the cost function of the forward pass of the iLQR algorithm. Specifically, the function \(\phi(x)=\text{max}\{0,x\}\) is applied onto each of the constraints, which increases the cost function proportionally whenever the constraints are violated. In safe-filtered iLQR and SC-iLQR, the initial reference trajectories \(\hat{z}_{0:T}\) in Algorithm 1 were initialized by iLQR and SC-iLQR, respectively.

The state trajectories under these control schemes are plotted in Fig. 2 and the percentages of constraint violations are tabulated in Table II. These percentages are computed by taking the ratio between the number of points in which the states violate the constraints against the total number of points in the state trajectory. Since the nominal iLQR method does not account for state constraints, it results in the largest percentage of constraint violation. While the soft-constrained iLQR reduces the level of constraint violation, there are a number of instances where the constraints are violated, as depicted in Fig. 2. On the other hand, as shown in Table II, through the application of the safety filter to iLQR and SC-iLQR, no constraint violations are observed for the test cases. To illustrate the safety certificate obtained, we plot the slack variables that characterize the trust region and state and input constraints, together with the safety certificate for the third test case, under a maximum noise level \(\sigma_{w}=0.05\), in Fig. 3. The combination of Table II and Fig. 3 indicates that given the formulation in (29), the PSF may not give a numerical safety certificate even when the state trajectories are safe. Meanwhile, this proposed PSF can effectively encourage the system to behave safely by minimizing the conservative upper bounds on the constraint violation.

The statistics of the computational times of the control scheme, in this case the iLQR scheme, and the safety filter are depicted in Fig. 4. While introducing soft constraints increases the run times of the iLQR scheme, it has a significant effect on the run times of the safety filter, as observed in the right panel of Fig. 4. With the soft constraints added to the iLQR scheme, the state trajectories are closer to the boundaries of the constraint sets, without the activation of the safety filter. This allows the filter to find a solution that satisfies the constraints under a smaller number of iterations, which reduces computational time.

## VI Conclusion

We propose a convex optimization-based predictive safety filter for uncertain NN dynamical systems with the inclusion of additive disturbances. By utilizing tools from NN verification and robust linear MPC, our method requires solving a soft-constrained convex program online whose complexity

Fig. 3: **Top two panels**: Time histories of the slack variables for the trust region, state and input constraints. **Bottom panel**: Time histories of the safety certificate attained. The values of 1 and 0 denote True and False respectively.

Fig. 2: **Top panel**: Plots of the state trajectories under the 4 test cases. The initial and final states are marked with green and magenta circles. The state constraints are plotted with black dashed lines. **Bottom panel**: Zoomed-in plots of the state trajectories, around the boundaries where constraint violation potentially occurs.
is independent of the NN size. With our framework, formal safety guarantees, together with a robust state-feedback controller, are attained when the slack variables in the solution are all zero.

### _Proof of Proposition 1_

Showing that \(\mathcal{R}(\mathbf{\eta};\mathbf{K},\mathbf{h},\mathbf{v})\subseteq\mathcal{R}(\mathbf{ \Psi}\widetilde{\mathbf{w}})\) is equivalent to showing for every possible values of \(\mathbf{\eta}\), there exist \(\widetilde{\mathbf{w}}^{*}\in\widetilde{\mathcal{W}}\) such that \(\mathbf{\eta}=\mathbf{\Psi}\widetilde{\mathbf{w}}^{*}\). Following this perspective, the sufficient conditions in Proposition 1 can be derived inductively.

Initial caseAt \(t=0\), we have \(x_{0}=h_{0},u_{0}=v_{0}\), and

\[\Delta_{0}(x_{0},u_{0})\geq\begin{bmatrix}\underline{D}_{0}^{x}& \underline{D}_{0}^{u}\end{bmatrix}y_{0}+\underline{d}_{0}, \tag{32}\] \[\Delta_{0}(x_{0},u_{0})\leq\begin{bmatrix}\underline{D}_{0}^{x}& \underline{D}_{0}^{u}\end{bmatrix}y_{0}+\overline{d}_{0},\]

with \(y_{0}=[h_{0}^{\top}\ v_{0}^{\top}]^{\top}\). Note that \(\eta_{0}=\Delta_{0}(x_{0},u_{0})+w_{0}\). For \(\eta_{0}=\Psi^{1,0}\tilde{w}_{0}=\text{diag}(\psi_{0})\tilde{w}_{0}\) to have a solution \(\tilde{w}_{0}\) satisfying \(\|\tilde{w}_{0}\|_{\infty}\leq 1\) for all possible realization of the lumped uncertainty \(\eta_{0}\), it is both sufficient and necessary to have

\[\|\text{diag}(\psi_{0})^{-1}\eta_{0}\|_{\infty}\leq 1\Leftrightarrow\left\{ \begin{array}{l}e_{i}^{\top}\eta_{0}\leq\psi_{0,i},i\in[n_{x}],\\ -e_{i}^{\top}\eta_{0}\leq\psi_{0,i},i\in[n_{x}],\end{array}\right.\]

hold robustly for \(\eta_{0}\) where \(e_{i}\) denotes the \(i\)-th standard basis. Using the bounds in (32) and the fact that \(\|w_{0}\|_{\infty}\leq\sigma_{w}\), we have constraints (22a) and (22b) guarantee the robust feasibility of (33) for all possible values of \(\eta_{0}\). For any realization of \(\eta_{0}\), we denote the corresponding solution as \(\tilde{w}_{0}^{*}\) such that \(\eta_{0}=\text{diag}(\psi_{0})\tilde{w}_{0}^{*}\).

Induction stepFor a given controller \(\{\mathbf{K},\mathbf{h},\mathbf{v}\}\), consider an arbitrary realization of the lumped uncertainty \(\eta_{0:T}\). At time \(t\geq 1\), let \(\mathbf{\eta}_{0:t}:=[\mathbf{0}^{\top}\ \eta_{0}\ \cdots\ \eta_{t-1}^{\top}]^{\top}\) denote the truncation of \(\mathbf{\eta}\) consisting of the first \(t+1\) components of \(\mathbf{\eta}\), and \(\mathbf{\Psi}_{0:t}\in\mathcal{L}_{TV}^{t}\) denote the truncation of \(\mathbf{\Psi}\) up to the \(t+1\)-th row and column. The truncated vectors \(\mathbf{x}_{e,0:t},\mathbf{u}_{e,0:t}\) and matrices \(\mathbf{A}_{0:t},\mathbf{B}_{0:t}\) are defined similarly. Assume there exist \(\widetilde{\mathbf{w}}_{0:t}^{*}=[\mathbf{0}^{\top}\ \tilde{w}_{0}^{*\top}\ \cdots\ \tilde{w}_{t-1}^{\ast\top}]^{\top}\) such that \(\mathbf{\eta}_{0:t}=\mathbf{\Psi}_{0:t}\widetilde{\mathbf{w}}_{0:t}^{*}\). Next, we will show that under constraint (22) there exist \(\tilde{w}_{t}^{*}\) with \(\|\tilde{w}_{t}^{*}\|_{\infty}\leq 1\) such that

\[\eta_{t} =\sum_{i=1}^{t+1}\Psi^{t+1,t+1-i}\tilde{w}_{i-1}^{*} \tag{34}\] \[=\sum_{i=1}^{t}\Psi^{t+1,t+1-i}\tilde{w}_{i-1}^{*}+\text{diag}( \psi_{t})\tilde{w}_{t}^{*}\]

holds.

Since \(\mathbf{\eta}_{0:t}=\mathbf{\Psi}_{0:t}\widetilde{\mathbf{w}}_{0:t}^{*}\), the error dynamics (20b) up to time \(t\) can be written as

\[\mathbf{x}_{e,0:t}=Z(\mathbf{A}_{0:t}\mathbf{x}_{e,0:t}+\mathbf{B}_{0:t}) \mathbf{u}_{e,0:t}+\mathbf{\Psi}_{0:t}\widetilde{\mathbf{w}}_{0:t}^{*}. \tag{35}\]

According to [20, Corollary 1], the affine constraint (21) parameterizes all closed-loop system responses \(\mathbf{x}_{e,0:t}=\mathbf{\Phi}_{x,0:t}\widetilde{\mathbf{w}}_{0:t}^{*}\), \(\mathbf{u}_{e,0:t}=\mathbf{\Phi}_{u,0:t}\widetilde{\mathbf{w}}_{0:t}^{*}\) under the controller \(\mathbf{u}_{e,0:t}=\mathbf{K}_{0:t}\mathbf{x}_{e,0:t}\) where \(\mathbf{\Phi}_{x,0:t},\mathbf{\Phi}_{u,0:t},\mathbf{K}_{0:t}\in\mathcal{L}_{TV}^{t}\) are the corresponding truncation of \(\mathbf{\Phi}_{x},\mathbf{\Phi}_{u},\mathbf{K}\), respectively. Define \(y_{t}:=[h_{0}^{\top}\ v_{t}^{\top}]^{\top}\) and \(\Phi^{t,t-i}:=[\Phi_{x}^{t,t-i\top}\ \tilde{\Phi}_{u}^{t,t-i\top}]^{\top}\). It follows from (35) and the fact \(\mathbf{x}_{e,0:t}=\mathbf{\Phi}_{x,0:t}\widetilde{\mathbf{w}}_{0:t}^{*}\), \(\mathbf{u}_{e,0:t}=\mathbf{\Phi}_{u,0:t}\widetilde{\mathbf{w}}_{0:t}^{*}\) that the state \(x_{t}\) and control input \(u_{t}\) at time \(t\) under the policy \(\{\mathbf{K},\mathbf{h},\mathbf{v}\}\) are given by

\[\begin{bmatrix}x_{t}\\ u_{t}\end{bmatrix}=z_{t}+\sum_{i=1}^{t}\Phi^{t,t-i}\tilde{w}_{i-1}^{*}. \tag{36}\]

Correspondingly, the uncertainty \(\Delta_{t}(x_{t},u_{t})\) at time \(t\) are bounded by

\[\Delta_{t}(x_{t},u_{t}) \geq\begin{bmatrix}\underline{D}_{t}^{x}&\underline{D}_{t}^{u} \end{bmatrix}z_{t}+\underline{d}_{t} \tag{37}\] \[=\begin{bmatrix}\underline{D}_{t}^{x}&\underline{D}_{t}^{u}\end{bmatrix} \left(y_{t}+\sum_{i=1}^{t}\Phi^{t,t-i}\tilde{w}_{i-1}^{*}\right)+\underline{d}_{t},\] \[\Delta_{t}(x_{t},u_{t}) \leq\begin{bmatrix}\underline{D}_{t}^{x}&\overline{D}_{t}^{u} \end{bmatrix}z_{t}+\overline{d}_{t}\] \[=\begin{bmatrix}\underline{D}_{t}^{x}&\overline{D}_{t}^{u}\end{bmatrix} \left(y_{t}+\sum_{i=1}^{t}\Phi^{t,t-i}\tilde{w}_{i-1}^{*}\right)+\overline{d}_{t},\]

which is achieved by plugging (36) into the definition of \(\mathcal{P}_{t}\). Recall that \(\eta_{t}=\Delta_{t}(x_{t},u_{t})+w_{t}\). For

\[\eta_{t}=\sum_{i=1}^{t}\Psi^{t+1,t+1-i}\tilde{w}_{i-1}^{*}+\text{diag}(\psi_{t}) \tilde{w}_{t} \tag{38}\]

to have a solution \(\tilde{w}_{t}\) such that \(\|\tilde{w}_{t}\|_{\infty}\leq 1\), it is equivalent to require

\[e_{i}^{\top}\Big{(}\eta_{t}-\sum_{i=1}^{t}\Psi^{t+1,t+1-i}\tilde{w}_{i-1}^{*} \Big{)} \leq\psi_{t,i},i\in[n_{x}], \tag{39}\] \[-e_{i}^{\top}\Big{(}\eta_{t}-\sum_{i=1}^{t}\Psi^{t+1,t+1-i} \tilde{w}_{i-1}^{*}\Big{)} \leq\psi_{t,i},i\in[n_{x}],\]

Fig. 4: Statistics of the run times of the controller and the safety filter, under the four test methods.
hold. Since \(\Delta_{t}(x_{t},u_{t})\) is bounded by (37), \(\|\tilde{w}_{t}^{*}\|_{\infty}\leq 1\) for \(i\in[t-1]\) and \(\|w_{t}\|_{\infty}\leq\sigma_{w}\), we have constraints (22c) and (22d) are sufficient to guarantee the inequalities (39) hold. Then, we denote the solution of (38) as \(\tilde{w}_{t}^{*}\) for the given realization of \(\eta_{t}\). We repeat this process until \(t=T\) and in this way construct the virtual disturbance \(\widetilde{\mathbf{w}}^{*}\) such that \(\boldsymbol{\eta}=\boldsymbol{\Psi}\widetilde{\mathbf{w}}^{*}\). Since the realization of \(\boldsymbol{\eta}\) is chosen arbitrarily, we prove Proposition 1.
