                                          1–65, 2024




                                                                        Safely Learning Dynamical Systems

                                          Amir Ali Ahmadi                                                                        AAA @ PRINCETON . EDU
                                          Abraar Chaudhry                                                                        AZC @ PRINCETON . EDU
                                          Princeton University
                                          Vikas Sindhwani                                                                   SINDHWANI @ GOOGLE . COM
                                          Stephen Tu                                                                        STEPHENTU @ GOOGLE . COM
arXiv:2305.12284v2 [math.OC] 8 Jun 2024




                                          Robotics at Google, New York


                                                                                                   Abstract
                                               A fundamental challenge in learning an unknown dynamical system is to reduce model uncertainty
                                               by making measurements while maintaining safety. In this work, we formulate a mathematical
                                               definition of what it means to safely learn a dynamical system by sequentially deciding where to
                                               initialize the next trajectory. In our framework, the state of the system is required to stay within a
                                               safety region for a horizon of T time steps under the action of all dynamical systems that (i) belong
                                               to a given initial uncertainty set, and (ii) are consistent with the information gathered so far.
                                                    For our first set of results, we consider the setting of safely learning a linear dynamical system
                                               involving n states. For the case T = 1, we present a linear programming-based algorithm that
                                               either safely recovers the true dynamics from at most n trajectories, or certifies that safe learning
                                               is impossible. For T = 2, we give a semidefinite representation of the set of safe initial conditions
                                               and show that ⌈n/2⌉ trajectories generically suffice for safe learning. For T = ∞, we provide
                                               semidefinite representable inner approximations of the set of safe initial conditions and show that
                                               one trajectory generically suffices for safe learning. Finally, we extend a number of our results to
                                               the cases where the initial uncertainty set contains sparse, low-rank, or permutation matrices, or
                                               when the dynamical system involves a control input.
                                                    Our second set of results concerns the problem of safely learning a general class of nonlinear
                                               dynamical systems. For the case T = 1, we give a second-order cone programming based represen-
                                               tation of the set of safe initial conditions. For T = ∞, we provide semidefinite representable inner
                                               approximations to the set of safe initial conditions. We show how one can safely collect trajectories
                                               and fit a polynomial model of the nonlinear dynamics that is consistent with the initial uncertainty
                                               set and best agrees with the observations. We also present extensions of some of our results to the
                                               cases where the measurements are noisy or the dynamical system involves disturbances.
                                               Keywords: learning dynamical systems, safe learning, uncertainty quantification, robust optimiza-
                                               tion, conic optimization


                                          1. Problem Formulation and Outline of Contributions
                                          In many applications such as robotics, autonomous systems, and safety-critical control, one needs to
                                          learn a model of a dynamical system by observing a small set of its trajectories in a safe manner. This
                                          model can serve as a tool for making predictions about unobserved trajectories of the system. It can
                                          also be used for accomplishing downstream control objectives. Often, an important challenge during
                                          the initial stages of learning is that deploying even a conservative learning strategy on a real world
                                          system, such as a robot, is fraught with risk. How should the robot be “set loose” (i.e., initialized)
                                          in the real world so that our uncertainty about its dynamics is reduced, but with guarantees that
                                          the robot will remain safe (e.g., it does not exit a pre-specified region in state space)? How much
                                          more aggressive can our learning strategy get “on the fly” as uncertainty is reduced? This interplay


                                          © 2024 A.A. Ahmadi, A. Chaudhry, V. Sindhwani & S. Tu.
                                           S AFE L EARNING




(a) The safety region in blue; one safe and two (b) After safely observing one trajectory, uncer-
    potentially unsafe initialization points given  tainty reduces and a previously unsafe initial-
    uncertainty over dynamics                       ization point becomes safe to query


                  Figure 1: A conceptual illustration of the safe learning problem.


between safety and uncertainty while learning dynamical systems is the central theme of this paper.
We propose a mathematical formulation that captures the essence of this interplay and study the
optimization problems that arise from the formulation in several settings.
     Before we present the mathematical framework of this paper, let us provide some conceptual
intuition with Figure 1. In this figure, the blue parallelogram represents the boundary of a safety
region in which the trajectory of the dynamical system we wish to learn must stay throughout the
learning process. In Figure 1(a), we draw three points as examples of possible initializations of
this dynamical system. If we choose one of these points and observe the resulting trajectory of
the system, we can use our observations to learn more about the system parameters. The safety
constraint in this context means we must ensure the trajectory remains in the safety region up to a
given horizon. If we truly knew nothing about the dynamics, then this task would be impossible
since for any initialization, we could imagine some dynamics which would quickly take us out of
the safety region. If we suppose, however, that we have some initial information on the system, we
can find sets representing the possible trajectories of all systems consistent with our information.
For our three candidate points, these sets are drawn in orange. We should not initialize the system at
either of the two red points since the system may take their associated trajectories outside the safety
region. The green point is “safe” to initialize from since its trajectory must stay in the safety region
despite our uncertainty over the dynamics.
     In Figure 1(b), we imagine having safely observed a trajectory up to our given horizon initialized
at the green point from Figure 1(a). We can use the information from this trajectory (drawn in
black) to learn more about the system and reduce our uncertainty over its potential trajectories. This
is represented by the orange sets being smaller than previously. With this narrowed uncertainty, a


                                                   2
                                            S AFE L EARNING




previously unsafe initialization point now becomes safe to query as denoted by the green color in
Figure 1(b). Given this certification, we could then initialize the system at the green point, observe
a new trajectory, and continue learning more about the system.
    We now describe the safe learning problem more formally. The central object of our mathemat-
ical framework is a discrete-time dynamical system

                                             xt+1 = f⋆ (xt ),                                         (1)

where f⋆ : Rn → Rn is an unknown map. This could be either a naturally arising autonomous
system, or a closed-loop control system with a fixed feedback policy. Our interest is in the problem
of safe data acquisition for estimating the unknown map f⋆ from a collection of length-T trajectories
{ϕf⋆ ,T (xj )}m
              j=1 , where ϕf,T (x) := (x, f (x), . . . , f
                                                           (T ) (x)).

    In our setting, we are given as input a set S ⊂ Rn , called the safety region, in which the state
should remain throughout the learning process. We say that an initial state x is T -step safe under a
map f : Rn → Rn if f (i) (x) ∈ S for all i = 0, . . . , T . We define S T (f ) ⊆ S to be the set of states
that are T -step safe under f . In order to safely learn f⋆ , we require that measurements are made
only at points in S T (f⋆ ). Obviously, if we make no assumptions about f⋆ , this task is impossible.
We assume, therefore, that the map f⋆ belongs to a set of dynamics U0 , which we call the initial
uncertainty set. As experience is gathered, the uncertainty over f⋆ decreases. Let us denote the
uncertainty set after we have observed k trajectories {ϕf⋆ ,T (xj )}kj=1 by,

                       Uk := {f ∈ U0 | ϕf,T (xj ) = ϕf⋆ ,T (xj ) , j = 1, . . . , k}.

Observe that Uk+1 ⊆ Uk for all k. For a nonnegative integer k, define
                                              \
                                      SkT :=      S T (f ) ,
                                                  f ∈Uk

the set of points that are T -step safe under all dynamics consistent with the initial uncertainty set and
the data after observing k trajectories. We refer to the set SkT as the T -step safe set (the dependence
on k is implicit). Note that SkT ⊆ Sk+1 T   for all k. A primary goal of this paper is to characterize the
       T
sets Sk as feasible regions of tractable optimization problems. In certain settings where an exact
tractable characterization is not possible, our goal would be to find tractable inner approximations of
these sets. For robustness reasons, we would like these inner approximations to be full-dimensional
so that safe queries to the system can be made while tolerating perturbations which may arise during
implementation.
    A secondary goal of this paper is to provide algorithms for what we define as the T -step safe
learning problem. Fix a scalar ε̄ > 0 and a norm ||.|| on Rn . Given a safety region S ⊂ Rn and
an initial uncertainty set U0 , the T -step safe learning problem (up to accuracy ε̄ and with respect to
norm ||.||) is to sequentially choose vectors x1 , . . . , xm , for some nonnegative integer m, such that:
                                                T ,
   1. (Safety) for each k = 1, . . . , m, xk ∈ Sk−1

   2. (Learning) supf ∈Um ,x∈S T (f⋆ ) ∥f (x) − f⋆ (x)∥ ≤ ε̄.

If for a given T , no such sequence of vectors x1 , . . . , xm exists (for any m), we say that T -step
safe learning is impossible. Note that if T -step safe learning is possible, then T ′ -step safe learning
is also possible for any T ′ < T . Moreover, since the highest rate of safe information assimilation

                                                     3
                                            S AFE L EARNING




is achieved when T = 1, to prove that safe learning is impossible for any T , it is necessary and
sufficient to prove its impossibility for T = 1.
    In many situations, the choice of the sequence of {x1 , . . . , xm } that achieves T -step safe learn-
ing may not be unique. We further suppose that for a function c : Rn 7→ R that takes nonnegative
values over S, initializing the unknown system at a state x ∈ S comes at a cost of c(x). In such
a setting, we are interested in safelyP learning the dynamical system at minimum total initialization
cost. Ideally, we wish to minimize m      k=1 c(xk ) over sequences {x1 , . . . , xm } that satisfy the safe
learning conditions 1 and 2 above. However, such an optimization problem cannot be solved without
knowing the action of the true dynamics f⋆ on the initialization points {xk } ahead of time. Hence,
a natural online algorithm is to sequentially solve the following greedy optimization problem

                                                min c(x) ,                                              (2)
                                                 T
                                              x∈Sk−1


whose optimal solution gives the next cheapest T -step safe initialization point xk , given information
gathered before time k. A byproduct of our primary goal of characterizing the sets SkT tractably is
efficient algorithms for solving the optimization problem (2).
Contributions. In this paper, we derive tractable conic programs that exactly characterize or inner
approximate T -step safe sets (for any k) for both linear systems and a general class of nonlinear
systems in the extreme cases when T = 1 and T = ∞. For linear systems, we also address the case
when T = 2, and provide algorithms for solving the exact (i.e., ε̄ = 0) T -step safe learning problem
when T = 1, 2, ∞. Throughout the paper, we assume that the safety region S is a polyhedron.
      More specifically, for linear systems, we give an exact linear programming-based characteriza-
tion of the one-step safe set when U0 is a polytope, and an exact semidefinite programming-based
characterization of the two-step safe set when U0 is an ellipsoid. Based on the former characteri-
zation, we present a linear programming-based algorithm that either learns the unknown dynamics
by making at most n one-step safe queries, or certifies the impossibility of safe learning (for any
T ). This results demonstrates that safety requirements do not hinder the possibility to identify an
n-dimensional system in n steps. In the case of T = 2, we show that under mild assumptions,
⌈ n2 ⌉ trajectories (whose initializations are computed by semidefinite programming) suffice for safe
learning. Roughly speaking, these algorithms sequentially solve (2) and add appropriate safe pertur-
bations to ensure that the remaining uncertainty Uk is shrinking. When T = ∞, under the assump-
tion that U0 is a compact subset of Schur-stable matrices, we present a sum of squares hierarchy of
semidefinite programs that provide full-dimensional inner approximations of the infinite-step safe
set. Under mild assumptions, we show that a single trajectory randomly initialized from our inner
approximation suffices for safe learning. Finally, we extend some of our results for one-step safe
learning to the case where more specialized side information is available, as well as to systems in-
volving an affine control law. More specifically, we give an exact linear/semidefinite programming-
based characterization of the set of one-step safe points of a linear system in the case where the
governing matrix is known to be sparse, low-rank, or a permutation matrix. We also define a notion
of controlled safe learning and show that this property can again be checked by linear programming.
      Turning to nonlinear systems, we consider the case when the dynamics in (1) consists of a linear
term plus a nonlinear function with bounded growth. When T = 1, we give an exact second-order
cone programming-based representation of the safe set when the uncertainty around the linear dy-
namics is represented by a polyhedron. When T = ∞, we provide a hierarchy of semidefinite


                                                     4
                                           S AFE L EARNING




representable inner approximations to the infinite-step safe set. Under the assumption that the non-
linear function growth is relatively small compared to the uncertainty around the linear part of the
dynamics, we prove that our hierarchy provides a full-dimensional inner approximation. By using
our safe set representations, we show how one can safely collect trajectories to refine uncertainty
regarding the linear term of the dynamics and fit a polynomial model of the nonlinear dynamics that
is consistent with the initial uncertainty set and best agrees with the observations.
     Finally, we show how some of our tractable conic programming formulations of the T -step safe
sets can be extended to the cases when the dynamical system has disturbances or the measurements
are noisy. For T = 1, both for linear and nonlinear systems, we can tolerate both bounded measure-
ment noise and bounded disturbances and still given a exact characterization of the one-step safe
set. For T = ∞, both for linear and nonlinear systems, we can tolerate bounded measurement noise
and still give tractable inner approximations of the infinite-step safe set.
Outline. In Section 2, we cover the relevant literature around safe learning and control. Section 3,
Section 4, and Section 5 present our results and algorithms for safely learning linear systems when
T = 1, 2, ∞, respectively. Section 6 and Section 7 contain our results for nonlinear systems when
T = 1 and T = ∞, respectively. In Section 8, we present our results on initial uncertainty sets
containing sparse, low-rank, and permutation matrices. In Section 9, we define a notion of controlled
safe learning and present an efficient algorithm for checking this property. Future directions for
research are presented in Section 10, including extensions to continuous-time systems. Omitted
proofs of some technical statements can be found in Appendix A.

2. Related Work
The idea of using conic and robust optimization techniques for verifying various properties of a
known dynamical system has been the focus of much research in the control and optimization com-
munities (Parrilo, 2000; Lasserre, 2010; Boyd et al., 1994; Blekherman et al., 2013). Our work
borrows some of these techniques to instead learn a dynamical system from data subject to cer-
tain safety constraints. Learning dynamical systems from data is an important problem in the field
of system identification; see, e.g., Åström and Eykhoff (1971); Antoulas (2005); Keesman (2011);
Brunton and Kutz (2019), and references therein. This continues to be an active area of research,
even for linear systems; see, e.g., the recent paper Bakshi et al. (2023).
    The problem of additionally accounting for safety constraints during system identification has
recently gained attention; see, e.g., Brunke et al. (2021) for an excellent survey of this growing
research field. Here, we highlight a few of the key technical tools used: Gaussian process models
(Akametalu et al., 2014; Berkenkamp and Schoellig, 2015; Berkenkamp et al., 2017), control barrier
functions (Cheng et al., 2019; Taylor et al., 2020; Luo et al., 2021), set invariance and uncertainty
propagation (Artstein and Raković, 2008; Gurriet et al., 2019; Koller et al., 2019), “safety critics” in
reinforcement learning (Zhang et al., 2020; Bharadhwaj et al., 2021), and backup controllers (Man-
nucci et al., 2018; Wabersich and Zeilinger, 2021).
    We highlight two related works for safely learning linear dynamical systems that, similar to our
work, rely on optimization formulations to ensure safety. The first is the work of Dean et al. (2019),
which uses convex programming methods to approximate the solution to a finite-time horizon linear-
quadratic optimal control problem with both model uncertainty and state/action constraints. They
provide convex optimization based sufficient conditions for existence of a control law that keeps a
given initial condition safe up to a certain time horizon despite uncertainty and disturbance in the

                                                   5
                                           S AFE L EARNING




dynamics. However, their approach requires the initial condition to be fixed and does not character-
ize the set of initial conditions for which there exists a control law ensuring safety (which would be
the right generalization of our work to the controlled case; see Section 9). Indeed, one can check
that if both the control law and the initial condition are decision variables, then the formulation of
Dean et al. (2019) is no longer convex. By contrast, our work focuses on autonomous systems and
characterizes the set of initial conditions that remain safe despite uncertainty in the dynamics. Our
characterizations are exact for time horizons T = 1 and T = 2 and are in state space, while the sets
provided by Dean et al. (2019) are in control space and in general conservative. For T = 1, our
exact characterization of safe sets extends to cases including bounded disturbances in the dynamics
and noise in the measurements (even for nonlinear systems). Our results for T = 1 also extend
to the problem of controlled safe learning of linear control affine systems; see Section 9. In addi-
tion, the work in Dean et al. (2019) does not provide an implementable algorithm for handling the
case when T = ∞ since the size of their convex programs grow with the horizon length T . Also,
that work does not use information on the fly for learning dynamics, which could be necessary for
safe learning (see Section 3.6). We note that follow-up work (Chen et al., 2021, 2022) provides
better heuristics for constructing inner approximations to the set of safe controls, but again these
approximations are not exact.
     The second related paper is that of Lu et al. (2017). In this work, the authors address the problem
of “one-step safety” and “trajectory safety” in a probabilistic framework. While similar sounding
to our problem setup, in their work the initial condition is again fixed and the question of either
characterizing or inner approximating the T -step safety sets S0T is not addressed. Furthermore,
the proposed algorithm in the T -step setting requires a separate computation to check safety for
every time step t ∈ {1, . . . , T }, and hence, similar to Dean et al. (2019), cannot be implemented
in the T = ∞ setting. The algorithm also requires checking safety for each coordinate of the state
separately and relies on nonconvex optimization without optimality guarantees.
     We would like to also highlight some papers on the topic of learning to stabilize dynamical
systems, which has recently gained attention. The work of Dean et al. (2020) studies linear sys-
tems with noise and shows how to learn a stabilizing controller efficiently, both with respect to the
number of required samples and cost. The work of Werner and Peherstorfer (2023) shows that one
can stabilize linear noiseless systems with less data than would be necessary to learn the system pa-
rameters exactly. The work of Guo et al. (2022) shows how to search for stabilizing controllers and
associated Lyapunov functions for all continuous-time polynomial systems that are consistent with
collected data. In a follow-up paper, Bisoffi et al. (2022) use Petersen’s lemma to further develop
the method and prove a necessary and sufficient condition for data-driven stabilization of linear sys-
tems. All these methods lead to stabilized systems wherein the state will remain bounded, however
they do not consider explicit safety constraints. In another follow-up paper, Luppi et al. (2021)
incorporate safety constraints into the framework of Guo et al. (2022) and Bisoffi et al. (2022) and
show how to find approximations of the continuous time analogue of Sk∞ . This work is concerned
with stabilization of polynomial vector fields and is focused on the T = ∞ case. The approach is
specific to data observation models which lead to “matrix ellipsoidal” uncertainty sets (see Bisoffi
et al. (2022) for a definition) and does not consider the problems of trajectory initialization and its
cost. The work is instead focused on the design of controllers which produce invariant subsets of
the safety region that are defined as sublevel sets of polynomials. By contrast, the invariant sets that
our work produces (for a different class of nonlinear dynamics) are semidefinite representable and
hence can be optimized over efficiently.


                                                   6
                                            S AFE L EARNING




    We end by noting that our work has some conceptual connections to the literature on experiment
design (see, e.g., Pukelsheim, 2006; De Castro et al., 2019). However, this literature typically does
not consider dynamical systems or notions of safety.
    A much shorter version of this work containing preliminary results on one-step and two-step
safe learning has appeared in Ahmadi et al. (2021).

3. One-Step Safe Learning of Linear Systems
In this section, we focus on characterizing one-step safe learning for linear systems. Here, the state
evolves according to
                                            xt+1 = A⋆ xt ,                                         (3)
where A⋆ is an unknown n × n matrix. We assume we know that A⋆ belongs to a set U0 ⊂ Rn×n
that represents our prior knowledge of A⋆ . In this section, we take U0 to be a polyhedron; i.e.,
                              n                                             o
                        U0 = A ∈ Rn×n | Tr(VjT A) ≤ vj j = 1, . . . , s                           (4)

for some matrices V1 , . . . , Vs ∈ Rn×n and scalars v1 , . . . , vs ∈ R. We also work with a polyhedral
representation of the safety region S; i.e.,
                                     n                                     o
                                S = x ∈ R n | hTi x ≤ bi i = 1, . . . , r                            (5)

for some vectors h1 , . . . , hr ∈ Rn and some scalars b1 , . . . , br ∈ R. We assume that initializing
the system at a point x ∈ Rn comes at a cost cT x, for some given vector c ∈ Rn . In practice,
initialization costs are nonnegative. Since the set S is often compact in applications, one can add a
constant term to cT x to ensure this requirement without changing any of our optimization problems.
We ignore this constant term in our formulations and examples. Our algorithms tractably extend to
any semidefinite-representable cost function (see Ben-Tal and Nemirovski (2001) for a definition)
c : Rn 7→ R by replacing the objective function with a new variable β and adding the constraint
c(x) ≤ β.
     We start by finding the minimum cost point that is one-step safe under all valid dynamics, i.e.,
a point x ∈ S such that Ax ∈ S for all A ∈ U0 . Once this is done, we gain further information by
observing the action y = A⋆ x of system (3) on our point x, which further constrains the uncertainty
set U0 . We then repeat this procedure with the updated uncertainty set to find the next minimum
cost one-step safe point. More generally, after collecting k measurements, our uncertainty in the
dynamics reduces to the set
                            Uk = {A ∈ U0 | Axj = yj        j = 1, . . . , k}.                       (6)
Hence, the problem of finding the next cheapest one-step safe initialization point (i.e., the version
of (2) for this specific case) becomes:
                                     min     cT x
                                     x∈Rn
                                       s.t. x ∈ S                                                   (7)
                                             Ax ∈ S     ∀A ∈ Uk .
    In Section 3.1, we show that problem (7) can be efficiently solved. We then use (7) as a subrou-
tine in a one-step safe learning algorithm which we present in Section 3.2.

                                                    7
                                                 S AFE L EARNING




3.1. Reformulation via Duality
In this subsection, we reformulate problem (7) as a linear program. To do this, we introduce auxil-
                (i)          (i)
iary variables µj ∈ R and ηℓ ∈ Rn for i = 1, . . . , r, j = 1, . . . , s, and ℓ = 1, . . . , k.
Proposition 1 The feasible set of problem (7) is the projection to x-space of the feasible set of the
following linear program:
                        min     cT x
                        x,µ,η

                         s.t. hT
                               i x ≤ bi          i = 1, . . . , r
                                k                   s
                                           (i)               (i)
                                X                   X
                                       yℓT ηℓ +           µj vj ≤ bi            i = 1, . . . , r
                                 ℓ=1                j=1
                                                                                                                       (8)
                                          k                        s
                                                      (i)T                (i)
                                          X                        X
                                xhT
                                  i =            xℓ η ℓ      +           µj VjT      i = 1, . . . , r
                                          ℓ=1                      j=1

                                µ(i) ≥ 0 i = 1, . . . , r.
In particular, the optimal values of (7) and (8) are the same and the optimal solutions of (7) are the
optimal solutions of (8) projected to x-space.
Proof Using the definitions of S and U0 , let us first rewrite (7) as a bilevel program:
              min cT x
                x
                s.t. hT
                      i x ≤ bi     i = 1, . . . , r
                                                                                                                       (9)
                                                  hT
                                                                     
                       maxA                        i Ax
                      s.t.            Tr(VjT A) ≤ vj j = 1, . . . , s ≤ bi                       i = 1, . . . , r.
                                         Axℓ = yℓ ℓ = 1, . . . , k
 We proceed by taking the dual of the r inner programs, treating the x variable as fixed. By intro-
                         (i)    (i)
ducing dual variables µj and ηℓ for i = 1, . . . , r, j = 1, . . . , s, and ℓ = 1, . . . , k, and by invoking
strong duality of linear programming, we have

                                                                            T η (i) +         (i)
                                                                                     Pk  Ps                 
                    hT

 maxA                i Ax                    minµ(i) ,η(i)                  y
                                                                        ℓ=1 ℓ ℓ               µ
                                                                                           j=1 j j  v
 s.t.          T
           Tr(Vj A) ≤ vj j = 1, . . . , s = 
                                                                        Pk           (i)T   Ps        (i) T 
                                                                xhT
                                            
                                               s.t.              i  =          x
                                                                           ℓ=1 ℓ ℓ η      +   j=1 µj Vj
                                                                                                            
             Axℓ = yℓ ℓ = 1, . . . , k                                             (i)
                                                                                 µ ≥0
                                                                                                         (10)
 for i = 1, . . . , r. Thus by replacing the inner problem of (9) with the right-hand side of (10), the
min-max problem (9) becomes a min-min problem. This min-min problem can be combined into a
single minimization problem and be written as problem (8). Indeed, if x is feasible to (9), for that
fixed x and for each i, there exist values of µ(i) and η (i) that attain the optimal value for (10) and
therefore the triple (x, µ, η) will be feasible to (8). Conversely, if some (x, µ, η) is feasible to (8),
it follows that x is feasible to (9). This is because for any fixed x and for each i, the optimal value
of the left-hand side of (10) is bounded from above by the objective value of the right-hand side
evaluated at any feasible µ(i) and η (i) .


                                                             8
                                                        S AFE L EARNING




Remark 2 We note that problem (8) can be modified so that one-step safety is achieved in the
presence of bounded disturbances. That is, suppose that the dynamics were governed by

                                                      xt+1 = A⋆ xt + wt ,

where wt represents some potentially adversarial disturbance and A⋆ ∈ U0 . We can still give an
exact linear programming-based characterization of the one-step safety set in the case when we
have ∥wt ∥ ≤ Wt , where ∥ · ∥ is any norm whose unit ball is a polytope and Wt is a given scalar.
For example, if ∥ · ∥ is the infinity norm, the set of one-step safe initialization points after observing
k measurements from the disturbed dynamics is the projection to x-space of the feasible set of the
following linear program:

           min         cT x
        x,µ,η + ,η −

                 s.t. hT
                       i x ≤ bi      i = 1, . . . , r
                       s                 k X
                                           n
                               (i)                    +(i)
                       X                 X
                              µj v j +               ηℓℓ′ (Wℓ + (yℓ )ℓ′ )
                       j=1               ℓ=1 ℓ′ =1
                                   k X
                                     n
                                             −(i)
                                   X
                               +            ηℓℓ′ (Wℓ − (yℓ )ℓ′ ) + Wk+1 ∥hi ∥1 ≤ bi   i = 1, . . . , r
                              ℓ=1 ℓ′ =1
                               s           k X   n                 k X   n
                                    (i) T            +(i)                    −(i)
                             X            X                       X
                         T                                   T
                       xhi =     µj Vj +            ηℓℓ′ xℓ eℓ′ −           ηℓℓ′ xℓ eT
                                                                                     ℓ′       i = 1, . . . , r
                             j=1          ℓ=1 ℓ′ =1               ℓ=1 ℓ′ =1
                                 +        −
                       µ ≥ 0,      η ≥ 0,        η ≥ 0,

where the input to the problem is the descriptions of S and U0 (hi , bi and Vj , vj ) and the mea-
                                                            (i)
surements (xℓ , yℓ ) and we have introduced dual variables µj for i = 1, . . . , r, j = 1, . . . , s and
 +(i)     −(i)
ηℓℓ′ , ηℓℓ′ for i = 1, . . . , r, ℓ = 1, . . . , k and ℓ′ = 1, . . . , n.

This is a special case of Theorem 26 which will be shown in Section 6.

Remark 3 We note that problem (8) can be modified so that one-step safety is achieved in the
presence of bounded measurement noise. That is, suppose that instead of directly observing yk =
A⋆ xk , we observe
                                     yk = A⋆ xk + zk ,
where zk represents the noise in the measurement and A⋆ ∈ U0 . We can still give an exact linear
programming-based characterization of the one-step safety set in the case when we have ∥zk ∥ ≤ Zk ,
where ∥ · ∥ is any norm whose unit ball is a polytope and Zk is a given scalar. For example, if ∥ · ∥ is
the infinity norm, the set of one-step safe initialization points after observing k noisy measurements




                                                               9
                                                            S AFE L EARNING




is the projection to x-space of the feasible set of the following linear program:
           min         cT x
        x,µ,η + ,η −

                 s.t. hT
                       i x ≤ bi          i = 1, . . . , r
                       s                     n
                                           k X
                               (i)                        +(i)
                       X                   X
                              µj v j +                   ηℓℓ′ (Zℓ + (yℓ )ℓ′ )
                       j=1                 ℓ=1 ℓ′ =1
                                     n
                                   k X
                                                  −(i)
                                   X
                               +                 ηℓℓ′ (Zℓ − (yℓ )ℓ′ ) ≤ bi        i = 1, . . . , r
                                     ℓ=1 ℓ′ =1
                                   s                       n
                                                         k X                           n
                                                                                     k X
                                          (i)                         +(i)                        −(i)
                                   X                     X                           X
                       xhT
                         i =             µj VjT +                    ηℓℓ′ xℓ eT
                                                                              ℓ′ −               ηℓℓ′ xℓ eT
                                                                                                          ℓ′   i = 1, . . . , r
                                   j=1                   ℓ=1 ℓ′ =1                   ℓ=1 ℓ′ =1
                                      +                  −
                       µ ≥ 0,         η ≥ 0,         η ≥0
where the input to the problem is the descriptions of S and U0 (hi , bi and Vj , vj ) and the mea-
                                                            (i)
surements (xℓ , yℓ ) and we have introduced dual variables µj for i = 1, . . . , r, j = 1, . . . , s and
 +(i)     −(i)
ηℓℓ′ , ηℓℓ′ for i = 1, . . . , r, ℓ = 1, . . . , k and ℓ′ = 1, . . . , n.
    We note that we can also exactly characterize one-step safety sets in the presence of both dis-
turbances and noisy measurements.

3.2. An Algorithm for One-Step Safe Learning
We start by giving a mathematical definition of (exact) safe learning specialized to the case of one-
step safety and linear dynamics. Recall the definition of the set Uk in (6).
Definition 4 (One-Step Safe Learning) We say that one-step safe learning is possible if for some
nonnegative integer m, we can sequentially choose vectors xk ∈ S, for k = 1, . . . , m, and observe
measurements yk = A⋆ xk such that:
   1. (Safety) for k = 1, . . . , m, we have Axk ∈ S                         ∀A ∈ Uk−1 ,
   2. (Learning) the set of matrices Um is a singleton.
    We now present our algorithm for checking the possibility of one-step safe learning (Algo-
rithm 1). The proof of correctness of Algorithm 1 is given in Theorem 8.

Remark 5 As Theorem 8 will demonstrate, the particular choice of the parameter ε ∈ (0, 1] in
the input to Algorithm 1 does not affect the detection of one-step safe learning by this algorithm.
However, a smaller ε leads to a lower cost of learning. Therefore, in practice, ε should be chosen
positive and as small as possible without causing the matrix X in line 25 to be ill conditioned.

    Algorithm 1 invokes two subroutines which we present next in Lemma 6 and Lemma 7.

Lemma 6 Let A ∈ Rm×n , B ∈ Rm×p , c ∈ Rm , and define the polyhedron
                                   P := {x ∈ Rn | ∃y ∈ Rp                    s.t. Ax + By ≤ c}.
The problem of checking if P is a singleton can be reduced to solving 2n linear programs.

                                                                      10
                                             S AFE L EARNING




     Algorithm 1: One-Step Safe Learning Algorithm
   Input : polyhedra S ⊂ Rn and U0 ⊂ Rn×n , cost vector c ∈ Rn , and a constant ε ∈ (0, 1].
   Output: A matrix A⋆ ∈ Rn×n or a declaration that one-step safe learning is impossible.
 1 for k = 0, . . . , n − 1 do
 2     Dk ← {(xj , yj ) | j = 1, . . . , k}
 3     Uk ← {A ∈ U0 | Axj = yj , j = 1, . . . , k}
 4     if Uk is a singleton (cf. Lemma 6) then
 5          return the single element in Uk as A⋆
 6     end
 7     Let x⋆k be the projection to x-space of an optimal solution to problem (8) with data Dk
 8     if x⋆k is linearly independent from {x1 , . . . , xk } then
 9          xk+1 ← x⋆k
10     else
11          Let Sk1 be the projection to x-space of the feasible region of problem (8) with data Dk
12          Compute a basis Bk ⊂ Sk1 of span(Sk1 ) (cf. Lemma 7)
13          for zj ∈ Bk do
14               if zj is linearly independent from {x1 , . . . , xk } then
15                    xk+1 ← (1 − ε)x⋆k + εzj
16                    break
17               end
18          end
19          if no zj ∈ Bk is linearly independent from {x1 , . . . , xk } then
20               return one-step safe learning is impossible
21          end
22     end
23     Observe yk+1 ← A⋆ xk+1
24 end
25 Define matrix X = [x1 , . . . , xn ]
26 Define matrix Y = [y1 , . . . , yn ]
27 return A⋆ = Y X −1




   Proof For each i = 1, . . . , n, maximize and minimize the i-th coordinate of x over P . It is
   straightforward to check that P is a singleton if and only if the optimal values of these two linear
   programs coincide for every i = 1, . . . , n.

   In the next lemma, the notation span(P ) denotes the set of all linear combinations of points in a set
   P ⊆ Rn (see the appendix for a proof of this lemma).

   Lemma 7 Let A ∈ Rm×n , B ∈ Rm×p , c ∈ Rm , and define the polyhedron

                            P := {x ∈ Rn | ∃y ∈ Rp       s.t. Ax + By ≤ c}.

   One can find a basis of span(P ) contained within P by solving at most 2n2 linear programs.

       Our next theorem is the main result of the section.

                                                    11
                                             S AFE L EARNING




Theorem 8 Given a safety region S ⊂ Rn and an uncertainty set U0 ⊂ Rn×n , one-step safe
learning is possible if and only if Algorithm 1 (with an arbitrary choice of c ∈ Rn and ε ∈ (0, 1])
returns a matrix.

Proof [“If”] By construction, the sequence of initialization points chosen by Algorithm 1 satisfies
the first condition of Definition 4, since the vectors x⋆k and zj are both contained in Sk1 and any
vector in Sk1 will remain in the safety region under the action of all matrices in Uk ; i.e. all matrices
in UA that are consistent with the measurements made so far. If Algorithm 1 terminates early at
line 5 for some iteration k, then clearly the uncertainty set Uk is a singleton. On the other hand,
if we reach line 27, then we must have n linearly independent initialization points {x1 , . . . , xn }.
From this, it is clear that the set {A ∈ U0 | Axj = yj , j = 1, . . . , n} = {A⋆ }.
     [“Only if”] Suppose Algorithm 1 chooses points {x1 , . . . , xm } where m < n and terminates
at line 20. Then it is clear from the algorithm that {x1 , . . . , xm } must form a basis of span(Sm   1)

and that Um is not a singleton. Take m̃ to be any nonnegative integer and {x̃1 , . . . , x̃m̃ } to be any
sequence that satisfies the first condition of Definition 4. For k = 1, . . . , m̃, let

                             Ũk = {A ∈ U0 | Ax̃j = A⋆ x̃j , j = 1, . . . , k} ,
                             S̃k1 = {x ∈ S | Ax ∈ S, ∀A ∈ Ũk } .

First we claim that x̃k ∈ Sm  1 for k = 1, . . . , m̃. We show this by induction. It is clear that x̃ ∈ S 1
                                                                                                       1   m
                  1
since x̃1 ∈ S0 and S0 ⊆ Sm 1     1 . Now we assume x̃ , . . . , x̃ ∈ S 1 and show that x̃                  1
                                                              1       k       m                    k+1 ∈ Sm .
Since {x1 , . . . , xm } forms a basis of span(Sm   1 ), it follows that for any matrix A, Ax = A x for
                                                                                                j      ⋆ j
j = 1, . . . , m implies Ax = A⋆ x for all x ∈ Sm      1 . In particular, for any matrix A, Ax = A x for
                                                                                                j      ⋆ j
j = 1, . . . , m implies Ax̃j = A⋆ x̃j for all j = 1, . . . , k. It follows that Um ⊆ Ũk and therefore,
S̃k1 ⊆ Sm1 . By the first condition of Definition 4, we must have x̃                1                      1
                                                                            k+1 ∈ S̃k , and thus, x̃k+1 ∈ Sm .
                                                                           1
This completes the inductive argument and shows that x̃k ∈ Sm for k = 1, . . . , m̃. From this,
it follows that Um ⊆ Ũm̃ . Recall that Um is not a singleton, thus Ũm̃ is not a singleton either.
Therefore, the sequence {x̃1 , . . . , x̃m̃ } does not satisfy the second condition of Definition 4.


Corollary 9 Given a safety region S ⊂ Rn and an uncertainty set U0 ⊂ Rn×n , if one-step safe
learning is possible, then it is possible with at most n measurements.

   Note that if A⋆ belongs to the interior of U0 , any algorithm needs at least n measurements in
order to learn A⋆ .

3.3. The Value of Exploiting Information on the Fly
In addition to detectingP the possibility of safe learning, Algorithm 1 attempts to minimize the overall
cost of learning (i.e., m           T
                             k=1 c xk ) by exploiting information gathered at every step. In order to
demonstrate the value of using information online, we construct Algorithm 2 which chooses n
initialization points x1 , . . . , xn ahead of time based solely on U0 and S. This algorithm succeeds
under the assumption that S01 contains a basis of Rn .
     As ε tends to zero, the cost of Algorithm 2 approaches ncT x⋆0 , where x⋆0 is a minimum cost
initialization point in S01 ; therefore, ncT x⋆0 serves as an upper bound on the cost incurred by Al-
gorithm 1. We note that ncT x⋆0 is also the minimum cost achievable by any one-step safe offline


                                                     12
                                                S AFE L EARNING




      Algorithm 2: Offline One-Step Safe Learning Algorithm
   Input : polyhedra S ⊂ Rn and U0 ⊂ Rn×n , cost vector c ∈ Rn , and a constant ε ∈ (0, 1].
   Output: A matrix A⋆ ∈ Rn×n or failure.
 1 if S01 does not contain a basis of Rn (cf. Lemma 7) then
 2      return failure
 3 end
 4 Compute a basis {z1 , . . . , zn } ⊂ S01 of Rn
 5 Let x⋆ 0 be the projection to x-space of an optimal solution to problem (8) with data D0
 6 Set xk = (1 − ε)x⋆   0 + εzk for k = 1, . . . , n
 7 Observe yk ← A⋆ xk for k = 1, . . . , n
 8 Define matrix X = [x1 , . . . , xn ]
 9 Define matrix Y = [y1 , . . . , yn ]
10 return A⋆ = Y X −1




  algorithm that takes n measurements, since all initialization points {xk } of such an algorithm must
  come from S01 .
      We refer the reader to Section 3.5 for a numerical example comparing Algorithm 1 and Algo-
  rithm 2, and to Section 3.6 for an example where exploiting online information is necessary for safe
  learning.

  3.4. A Lower Bound on the Cost of Safe Learning
  Consider a safety region S ⊂ Rn , an initial uncertainty set U0 ⊂ Rn×n , and an affine function
  c : S 7→ R+ . By assuming knowledge of the matrix A⋆ governing the true dynamics, we can
  express the minimum cost of safe learning (cf. the paragraph before Eq. (2)) over all possible (online
  or offline) algorithms as the optimal value of the following optimization problem:

                             m
                             X
               inf                 c(xk )
        m∈N,x1 ,...,xm ∈Rn
                             k=1
                      s.t. xk ∈ S       k = 1, . . . , m
                             Ax1 ∈ S        ∀A ∈ U0
                             Ax2 ∈ S        ∀A ∈ {A ∈ U0 | Ax1 = A⋆ x1 }                                   (11)
                             Ax3 ∈ S        ∀A ∈ {A ∈ U0 | Ax1 = A⋆ x1 ,            Ax2 = A⋆ x2 }
                                 ..
                                  .
                             Axm ∈ S        ∀A ∈ {A ∈ U0 | Axk = A⋆ xk             k = 1, . . . , m − 1}
                             {A ∈ U0 | Axk = A⋆ xk              k = 1, . . . , m} = {A⋆ }.

  For a fixed m ∈ N, and assuming knowledge of A⋆ , using a similar duality approach as in the
  proof of Proposition 1, the membership constraints in (11) can be written as bilinear constraints in
  x1 , . . . , xm and additional dual variables. It is unclear however if (11) can be solved tractably (even
  for fixed m). Accordingly, we use the following easily computable lower bound on the minimum


                                                           13
                                                 S AFE L EARNING




cost of safe learning for our numerical example in the next section. Suppose A⋆ is in the interior of
U0 . Let
                                  S 1 (A⋆ ) = {x ∈ S | A⋆ x ∈ S}
be the true one-step safety region of A⋆ . Suppose x⋆ is an optimal solution to the linear program
that minimizes c(x) over S 1 (A⋆ ). Since one-step safe learning requires at least n measurements,
we cannot achieve a cost lower than nc(x⋆ ).

3.5. Numerical Example of One-Step Safe Learning
We present a numerical example with n = 4. Here, we take U0 = {A ∈ R4×4 | |Aij | ≤ 4 ∀i, j},
S = {x ∈ R4 | ∥x∥∞ ≤ 1}, and c = (−1, −1, 0, 0)T . We choose the matrix A⋆ uniformly at
random among integer matrices in U0
                                                         
                                         2    1    4     2
                                       2 −3 −1 −2
                                A⋆ = −2 −3
                                                          .
                                                   1     0
                                         2    0 −2       2

In this example, Algorithm 1 takes four steps to safely recover A⋆ . The projection to the first two
dimensions of the four vectors that Algorithm 1 selects are plotted in Figure 2(a) (note that two of
the points are very close to each other). Because of the cost vector c, points higher and further to the
right in the plot have lower initialization cost. Also plotted in Figure 2(a) are the projections to the
first two dimensions of the sets Sk1 for k ∈ {0, 1, 2, 3} and of the set S 1 (A⋆ ), the true one-step safety
region of A⋆ . In Figure 2(b), we plot Uk (the remaining uncertainty after making k measurements)
for k ∈ {0, 1, 2, 3, 4}; we draw a two-dimensional projection of these sets of matrices by looking at
the trace and the sum of the entries of each matrix in the set. Note that U4 is a single point since we
have recovered the true dynamicsP4 after  the fourth measurement.
                                        T
     The cost of learning (i.e., i=1 ci xi ) for the offline algorithm (Algorithm 2) approaches −1 as
ε → 0. The cost of learning for Algorithm 1 (with ε = 0.01) is −1.6385. The lower bound on the
cost of learning is −2.2264 (cf. Section 3.4).1 We can see that the value of exploiting information
on the fly is significant.
     To show that the above trend is not specific to the example we chose, we repeat the procedure
for 100 randomly generated instances of this problem. We use the same sets S and U0 , we sample
the matrix A⋆ uniformly at random from integer matrices in U0 , and we sample the cost vector
c uniformly at random from the unit sphere. In all 100 examples, we learn the true system after
4 iterations as guaranteed by Corollary 9. The cost of learning for Algorithm 1 was on average
−1.2151 with a standard deviation of 0.4310. The cost of learning for Algorithm 2 was on average
−0.7717 with a standard deviation of 0.1038. The lower bound on the cost of learning was on
average −3.1792 with a standard deviation of 1.2243. The box plot in Figure 3 summarizes the
distribution of initialization costs for each iterate. For later iterates when more has been learned
about the system, lower cost initialization points are chosen by the online algorithm.
 1. Note that adding a constant to the objective function to make it nonnegative over S, would shift all of our bounds by
    the same amount.




                                                          14
                                         S AFE L EARNING




    0.5                                                60

                                                       40

                                                       20

      0                                                  0

                                                       -20

                                                       -40

                                                       -60
   -0.5
          -0.5                0             0.5                -10          0          10

                 (a) Sk1 grows with k.                        (b) Uk shrinks with k.


      Figure 2: One-step safe learning associated with the numerical example in Section 3.5.




Figure 3: Initialization cost of the iterates chosen by Algorithm 1 (the online algorithm) for the
          distribution of four-dimensional problems described at the end of Section 3.5. The ini-
          tialization cost for Algorithm 2 (the offline algorithm) would be 4cT x1 .




                                                  15
                                            S AFE L EARNING




3.6. Failure of Offline Learning
It is natural to ask if in every case that one-step safe learning is possible, whether it is also possible
with an offline algorithm (i.e., an algorithm that can only sample points from S01 ). In this subsection,
we show that this is not the case, demonstrating the necessity of exploiting information on the fly.
     Consider the following example with n = 2,
                                                             
                                     2×2 1 0                 2 1
                      U0 = A ∈ R                   ≤A≤                , S = [1, 3]2 ,
                                             0 1             1 2
                                          
                                      1 0
an arbitrary cost vector c, and A⋆ =        . It is straightforward to see that no offline algorithm
                                      1 1
can recover A⋆ . Indeed, one can check that (i) S01 = {(1, 1)T }, which does not contain a basis of
R2 , and (ii)                                             
                                                1 0       1 0
                               U1 = conv                ,
                                                0 2       1 1
which is not a singleton.
     By contrast, Algorithm 1 takes two steps to safely recover A⋆ , demonstrating that safe learning
is possible. Plotted in Figure 4(a) are the sets Sk1 for k ∈ {0, 1} and the set S 1 (A⋆ ), the true
one-step safety region of A⋆ . In Figure 4(b), we plot Uk (the remaining uncertainty after making k
measurements) for k ∈ {0, 1, 2}; we draw a two-dimensional projection of these sets of matrices
by plotting the trace and the sum of the entries of each matrix in the set. As noted previously, U1
is not a singleton as we cannot exactly recover A⋆ from measuring its action on the single point
in S01 . However, U2 is a singleton since we have recovered the true dynamics after the second
measurement. Thus, we see that the value of exploiting information on the fly is significant not just
in terms of cost, but in terms of the possibility of learning as well.

4. Two-Step Safe Learning of Linear Systems
In this section, we again focus on learning the linear dynamics in (3). However, unlike the previous
section, we are interested in making queries to the system that are two-step safe. An advantage of
this formulation is that we may have fewer system resets and can potentially learn the dynamics with
lower initialization cost. Moreover, it turns out that the robust optimization problem underlying the
two-step safe learning problem remains tractable in the setting where the initial uncertainty set is
an ellipsoid (in matrix space). We do not anticipate an exact tractable formulation of the T -step
safe learning problem for T ≥ 3. Our analysis of the T = 2 case (in addition to the limiting
cases of T = 1 and T = ∞) is mainly motivated by the aforementioned tractability reason (see
Theorem 10).
     We take the input to the two-step safe learning problem to be a polyhedral safety region S ⊂ Rn
given in the form of (5), an objective function representing initialization cost which for simplicity
we again take to be a linear function cT x, and an uncertainty set U0 ⊂ Rn×n to which the matrix
A⋆ belongs. We assume the set U0 is an ellipsoid; this means that there is a strictly convex quadratic
function q : Rn×n → R such that

                                   U0 = A ∈ Rn×n | q(A) ≤ 0 .
                                          




                                                   16
                                            S AFE L EARNING




      2                                                    6

                                                         5.5
   1.8
                                                           5

                                                         4.5
   1.6
                                                           4
   1.4                                                   3.5

                                                           3
   1.2
                                                         2.5
      1                                                    2

           1               1.5                 2               2       2.5      3       3.5       4

               (a) Sk1 grows with k.                               (b) Uk shrinks with k.


      Figure 4: One-step safe learning associated with the numerical example in Section 3.6.

An example of such an uncertainty set is U0 = {A ∈ Rn×n | ∥A − A0 ∥F ≤ γ}, where A0 is
a nominal matrix, γ is a positive scalar, and ∥ · ∥F denotes to the Frobenius norm. Having safely
collected k length-two trajectories {(xj , A⋆ xj , A2⋆ xj )}kj=1 , our uncertainty around A⋆ reduces to:

                   Uk = {A ∈ U0 | Axj = A⋆ xj , A2 xj = A2⋆ xj , j = 1, . . . , k}.                (12)

The optimization problem we would like to solve to find the next best two-step safe initialization
point (i.e., the version of (2) for this specific case) is the following:

                                       min cT x
                                        x
                                       s.t. x ∈ S
                                                                                                   (13)
                                            Ax ∈ S       ∀A ∈ Uk
                                            A2 x ∈ S     ∀A ∈ Uk .

   The feasible region of (13) is the set of two-step safe points with information available at step k
and is denoted, using our convention, by Sk2 .

4.1. Reformulation via the S-Lemma
In this subsection, we derive a tractable reformulation of problem (13), which as a consequence
results in an efficient semidefinite representation of the set Sk2 . Recall that n denotes the dimension
of the state and r denotes the number of facets of the polytopic safety set S.

Theorem 10 Problem (13) can be reformulated as a semidefinite program involving 3r scalar
inequalities and 2r positive semidefinite constraints on matrices of size at most (n2 + 1) × (n2 + 1).

                                                    17
                                            S AFE L EARNING




    Our proof makes use to the S-lemma (see, e.g., Pólik and Terlaky, 2007) which we recall next.

Lemma 11 (S-lemma) For two quadratics functions qa and qb , if there exists a point x̄ such that
qa (x̄) < 0, then the implication

                                     ∀x, [qa (x) ≤ 0 ⇒ qb (x) ≤ 0]

holds if and only if there exists a scalar λ ≥ 0 such that

                                      λqa (x) − qb (x) ≥ 0 ∀x.

Proof [of Theorem 10] Note that the set of equations

                            Axj = A⋆ xj ,     A2 xj = A2⋆ xj         j = 1, . . . , k

in the definition of Uk in (12) is equivalent to the set of linear equations

                         Axj = A⋆ xj ,      A(A⋆ xj ) = A2⋆ xj            j = 1, . . . , k.          (14)

If there is only one matrix in U0 that satisfies all of the equality constraints in (14) (a condition that
can be checked via a simple modification of Lemma 6), then we have found A⋆ and (13) becomes
a linear program. Therefore, let us assume that more than one matrix in U0 satisfies the constraints
in (14). In order to apply the S-lemma, we need to remove these equality constraints, a task that we
accomplish via variable elimination. Let n̂ be the dimension of the affine subspace of matrices that
satisfy the constraints in (14) and let Â ∈ Rn×n be an arbitrary member of this affine subspace. Let
A1 , . . . , An̂ ∈ Rn×n be a basis of the subspace

                      {A ∈ Rn×n | Axj = 0,         A(A⋆ xj ) = 0 j = 1, . . . , k}.

Consider an affine function g : Rn̂ → Rn×n defined as follows:
                                                         n̂
                                                         X
                                         g(â) := Â +         âi Ai .
                                                         i=1

The function g has the properties that it is injective and that for each A that satisfies the equality
constraints, there must be a vector â such that A = g(â). In other words, the function g is simply
parametrizing the affine subspace of matrices that satisfy the equality constraints. Now we can
reformulate (13) as:
                            min cT x
                              x
                              s.t. x ∈ S
                                                                                                     (15)
                                    g(â)x ∈ S     ∀â s.t. q(g(â)) ≤ 0
                                    g(â)2 x ∈ S   ∀â s.t. q(g(â)) ≤ 0.
Let q̂ := q ◦ g. Since q is a strictly convex quadratic function and g is an injective affine map,
q̂ is also a strictly convex quadratic function. Since we are under the assumption that there are
multiple matrices in U0 that satisfy the equality constraints, there must be a vector ā ∈ Rn̂ such that



                                                    18
                                                S AFE L EARNING




q̂(ā) < 0. To see this, take ā1 ̸= ā2 such that q̂(ā1 ), q̂(ā2 ) ≤ 0. It follows from strict convexity of q̂
that q̂( 21 (ā1 + ā2 )) < 0. Using the definition of S, problem (15) can be rewritten as:

                           min cT x
                               x
                               s.t. hT
                                     i x ≤ bi     i = 1, . . . , r
                                                  hT
                                                             
                                     maxâ           i g(â)x ≤ b                                           (16)
                                                                   i i = 1, . . . , r
                                       s.t.       q̂(â) ≤ 0
                                                  hT        2
                                                               
                                     maxâ           i g(â) x ≤ b
                                                                    i i = 1, . . . , r.
                                       s.t.        q̂(â) ≤ 0

Let q1,i (â; x) = hT                                 T      2
                    i g(â)x − bi and q2,i (â; x) = hi g(â) x − bi . We consider these functions
as quadratic functions of â parametrized by x. Note that the coefficients of q1,i and q2,i depend
affinely on x. Using logical implications, problem (16) can be rewritten as:

                         min cT x
                           x
                          s.t. hT
                                i x ≤ bi        i = 1, . . . , r                                            (17)
                                   ∀â, [q̂(â) ≤ 0 ⇒ q1,i (â; x) ≤ 0]     i = 1, . . . , r
                                   ∀â, [q̂(â) ≤ 0 ⇒ q2,i (â; x) ≤ 0]     i = 1, . . . , r.

Now we use the S-lemma to reformulate an implication between quadratic inequalities as a con-
straint on the global nonnegativity of a quadratic function. Note that as we have already argued
for the existence of a vector ā such that q̂(ā) < 0, the condition of the S-lemma is satisfied. After
introducing variables λ1,i and λ2,i for i = 1, . . . , r, we apply the S-lemma 2r times to reformulate
(17) as the following program:

                           min cT x
                           x,λ

                            s.t. hT
                                  i x ≤ bi        i = 1, . . . , r
                                    λ1,i q̂(â) − q1,i (â; x) ≥ 0   ∀â   i = 1, . . . , r                 (18)
                                    λ2,i q̂(â) − q2,i (â; x) ≥ 0   ∀â   i = 1, . . . , r
                                    λ1,i ≥ 0,     λ2,i ≥ 0 i = 1, . . . , r.

It is a standard procedure to convert the constraint that a quadratic function of N variables is globally
nonnegative into a semidefinite constraint on a matrix of size (N + 1) × (N + 1). Note that the
coefficients of q1,i and q2,i depend affinely on x; this results in linear matrix inequalities when (18)
is converted into a semidefinite program.


4.2. Number of Two-Step Trajectories Needed for Learning
In Section 3, we established that when one-step safe learning is possible, it can be done with at most
n trajectories of length one (see Corollary 9). It is natural to ask how many trajectories might be
required in the case of two-step safe learning. We show that generically, ⌈ n2 ⌉ two-step trajectories
suffice for learning.


                                                         19
                                           S AFE L EARNING




    Given m two-step trajectories, let X = [x1 , . . . , xm ] be a matrix whose columns are the vectors
where our trajectories are initialized. Since our trajectories are of length two, we will observe
Y (1) := A⋆ X and Y (2) := A2⋆ X. We can write these measurements as the following linear system
in A:
                                     A[X, Y (1) ] = [Y (1) , Y (2) ].                              (19)
From this, it is clear that A will be uniquely identifiable if the matrix [X, Y (1) ] has rank n. This is
only possible if [X, Y (1) ] has at least n columns; in particular, this requires that m ≥ ⌈ n2 ⌉. This
suggests that we may be able to learn A with only ⌈ n2 ⌉ trajectories if we choose X correctly. Un-
fortunately, it is possible that no matter how we choose X, we may need more than ⌈ n2 ⌉ trajectories
in order to make [X, Y (1) ] have rank n. This can be seen for example if A is the zero matrix or
the identity matrix. Despite this, we can design an algorithm (Algorithm 3) for which ⌈ n2 ⌉ trajecto-
ries suffice generically to make the matrix [X, Y (1) ] have rank n, and hence for learning A⋆ . Our
algorithm relies on the following lemma as a subroutine (see the appendix for a proof).

Lemma 12 If S02 is full-dimensional, one can solve 2n semidefinite programs to find 2n vectors
in S02 whose convex hull is full-dimensional (if S02 is not full-dimensional, the same process will
prove that it is not full-dimensional). These semidefinite programs have the same variables and
constraints as the program from Theorem 10, and in addition, at most n linear constraints.

Our algorithm for two-step safe learning is Algorithm 3. We can prove the following theorem about
it.

Theorem 13 Suppose S02 is full-dimensional. For any matrix A⋆ outside of a Lebesgue measure
zero set in Rn×n , Algorithm 3 almost surely succeeds in safe learning using only ⌈ n2 ⌉ trajectories.

   The proof of Theorem 13 relies on the following proposition whose proof can be found in the
appendix.

Proposition 14 Let λn denote the Lebesgue measure on Rn . Let {δt }m         t=1 be a finite sequence of
mutually independent random variables in Rn . Suppose that for each t, the law of δt is absolutely
continuous with respect to λn . Let {ft }m−1
                                           t=1 be any sequence of functions mapping R
                                                                                              n×t to Rn .
                                                                                     nm
Define z1 = δ1 and zt = ft−1 (z1 , ..., zt−1 ) + δt for t = 2, . . . , m. For every λ null-set N , we
have P((z1 , ..., zm ) ∈ N ) = 0.

Proof [of Theorem 13] First observe that by the convexity of Sk2 (i.e., the feasible set of (13)), every
initialization point chosen by Algorithm 3 is two-step safe.
     Assume for simplicity that n is even and let m = ⌈ n2 ⌉. Consider the set

                          V := {[A, X] ∈ Rn×(n+m) | det(Z(A, X)) = 0},

where Z(A, X) ∈ Rn×n is the first n columns of [X, AX]. As a zero-set of a polynomial, V is
either all of Rn×(n+m) or has Lebesgue measure zero. It is not all of Rn×(n+m) since, defining Is
to be the s × s identity matrix, we can take
                                                             
                                         Im              0    0
                                  X=         , A=
                                          0         I⌊ n2 ⌋   0


                                                   20
                                                     S AFE L EARNING




     Algorithm 3: Two-Step Safe Learning Algorithm
   Require: S02 full-dimensional
   Input : polyhedron S ⊂ Rn , ellipsoid U0 ⊂ Rn×n , cost vector c ∈ Rn , and a constant
              ε ∈ (0, 1].
   Output : A matrix A⋆ ∈ Rn×n .
 1 Compute 2n vectors z1 , . . . , z2n ∈ S02 such that conv{z1 , . . . , z2n } is full-dimensional (cf.
    Lemma 12)
                    n
 2 Define m = ⌈ 2 ⌉
 3 for k = 0, . . . , m − 1 do
                                     (1)     (1)   (2)
 4     Uk ← {A ∈ U0 | Axj = yj , Ayj = yj               j = 1, . . . , k}
 5                          2
       if Uk is a singleton then
 6         return the single element in Uk as A⋆
 7     end
 8     Let x⋆k be an optimal solution to problem (13) with the set Uk (cf. Theorem 10)
 9     Pick a random vector λ ∈ R2n from the 2n-dimensional simplex3
       xk+1 ← (1 − ε)x⋆k + ε 2n
                                 P
10                                  i=1 λi zi
                     (1)                  (2)            (1)
11    Observe yk+1 ← A⋆ xk+1 , yk+1 ← A⋆ yk+1
12 end
13 Define matrix X = [x1 , . . . , xm ]
                             (1)        (1)
14 Define matrix Y (1) = [y1 , . . . , ym ]
                             (2)        (2)
15 Define matrix Y (2) = [y1 , . . . , ym ]
16 return A⋆ = [Y (1) , Y (2) ][X, Y (1) ]T ([X, Y (1) ][X, Y (1) ]T )−1



     and observe that
                                           det(Z(A, X)) = det(In ) = 1 ̸= 0.
     Therefore V must have Lebesgue measure zero. Since the Lebesgue measure on Rn×(n+m) is the
     completion of the product measure of the the Lebesgue measures of Rn×n and Rn×m , we have that
     for almost every A, the set

                                         VA := {X ∈ Rn×m | Z(A, X) = 0}

     has Lebesgue measure zero. Thus there must exist a set A ⊂ Rn×n of Lebesgue measure zero such
     that if A ∈/ A, then VA has Lebesgue measure zero.
         Supposing A⋆ ∈    / A, we now apply Proposition 14 to the points x1 , . . . , xm produced by Al-
     gorithm 3. Assume that the algorithm does not return at Line 6, otherwise there is nothing to
     prove. Notice that for some choice of functions f1 , . . . , fP             n×t → Rn , we can write for
                                                                        m−1 : R
                                                                          2n
     k = 2, . . . , m, xk = fk−1 (x⋆0 , . . . , x⋆k−1 ) + δk with δk = ε i=1 λi zi . It is clear that the law of δk
     is absolutely continuous with respect to the Lebesgue measure on Rn since conv({z1 , . . . , z2n }) is
     full-dimensional. Hence, letting X ∈ Rn×m be the matrix with x1 , ..., xm as columns, by Proposi-
     tion 14, P(X ∈ VA⋆ ) = 0. Therefore, almost surely, we have det(Z(A⋆ , X)) ̸= 0. This proves that
      2. The same approach as the proof of Lemma 6 can be used to perform this check.
      3. Any distribution on the simplex that is absolutely continuous with respect to the Lebesgue measure would work, for
         example, the uniform distribution.


                                                               21
                                                  S AFE L EARNING




                                                                7
      0.1
                                                                6

                                                                5
    0.05
                                                                4

                                                                3
        0
                                                                2

                                                                1
   -0.05
                                                                0

                                                                -1
     -0.1
                                                                -2
            -0.1      -0.05      0         0.05      0.1             0       1          2      3    4

                   (a) Sk2 grows with k.                                   (b) Uk shrinks with k.


      Figure 5: Two-step safe learning associated with the numerical example in Section 4.3.


[X, Y (1) ] almost surely has rank n and hence

                           [Y (1) , Y (2) ][X, Y (1) ]T ([X, Y (1) ][X, Y (1) ]T )−1 = A⋆ .




4.3. Numerical Example
We present a numerical example of two-step safe learning, again with n = 4. Here we choose a
nominal matrix                                                  
                                   2.25     0.75     4.25    1.75
                                 2.25 −3.25 −1.25 −2.25
                          A0 = −2.00 −2.75
                                                                 
                                                     1.25    0.00
                                   1.75 −0.25 −2.00          2.00
and let U0 = {A ∈ R4×4 | ∥A − A0 ∥F ≤ 1}. We let S = {x ∈ R4 | |xi | ≤ 1, i = 1, . . . , 4} and
c = (−1, 0, 0, 0)T . We choose the true matrix A⋆ to be the same matrix used in Section 3.5 (which
belongs to U0 ).
     In this example, with Algorithm 3, we learn the true matrix A⋆ by choosing two initialization
points that are each two-step safe. In other words, Algorithm 3 chooses x1 ∈ R4 , observes A⋆ x1 and
A2⋆ x1 , then chooses x2 ∈ R4 , and observes A⋆ x2 and A2⋆ x2 . We can verify that we have recovered
A⋆ if the vectors {x1 , A⋆ x1 , x2 , A⋆ x2 } are linearly independent, which is the case. The projection
to the first two dimensions of the two initialization points x1 and x2 are plotted in Figure 5(a).



                                                           22
                                            S AFE L EARNING




Because of the cost vector c, points further to the right in the plot have lower initialization cost.
Also plotted are the projections to the first two dimensions of the sets

                              S02 = {x ∈ S | Ax ∈ S, A2 x ∈ S         ∀A ∈ U0 },
                              S12 = {x ∈ S | Ax ∈ S, A2 x ∈ S         ∀A ∈ U1 },
                          2
                        S (A⋆ ) = {x ∈ S | A⋆ x ∈ S, A2⋆ x ∈ S}.

The sets S02 and S01 are the projections to x-space of the feasible regions of our two semidefinite
programs (cf. Theorem 10). The set S 2 (A⋆ ) is the true two-step safety region of A⋆ . In Figure 5(b),
we plot Uk (the remaining uncertainty after observing k trajectories of length two) for k ∈ {0, 1, 2};
we draw a two-dimensional projection of these sets of matrices by looking at the trace and the sum
of the entries of each matrix in the set. Note that U2 is a single point since we have recovered the
true dynamics after observing the second trajectory. The cost of learning (i.e., cT x1 + cT x2 ) is
−0.1493.
     We can construct an analogue of the offline Algorithm 2 by only making measurements from
S0 . This approach would first pick the optimal point in S02 (i.e., x1 ), and then another vector in S02
  2

close to x1 , but linearly independent from it. The cost of learning for this offline approach would
be 2cT x1 = −0.1099. Finally, we can again find a lower bound on the cost of learning of any
algorithm that chooses two two-step safe initialization points by assuming we know A⋆ ahead of
time and optimizing cT x over S 2 (A⋆ ); in this example, the lower bound is −0.2097. Here, again,
we see that by using information on the fly, we can succeed at safe learning at a considerably lower
cost than the offline approach.

5. Infinite-Step Safe Learning of Linear Systems
In contrast to the previous two sections, in this section we consider the problem of safely learning
the linear dynamical system in (3) from trajectories of unbounded length. This means that we are
constrained to initializing the system at points whose entire future trajectories are guaranteed to
remain in a specified safety region.
    More formally, in the infinite-step safe learning problem, we have as input a polyhedral safety
region S ⊂ Rn given in the form (5), an objective function representing initialization cost which for
simplicity we take to be a linear function cT x, and a polyhedral uncertainty set U0 ⊂ Rn×n , given
in the form (4), to which the matrix A⋆ governing the true dynamics belongs. Having collected k
safe trajectories {(xℓ , A⋆ xℓ , A2⋆ xℓ , . . .)}kℓ=1 , our uncertainty around A⋆ reduces to

         Uk = {A ∈ U0 | Axℓ = A⋆ xℓ , A2 xℓ = A2⋆ xℓ , . . . , An xℓ = An⋆ xℓ , ℓ = 1, . . . , k}.

Note that in the definition of Uk , information contained in the tail of the trajectories, beyond step
n, is discarded. This is because of the following proposition, which we prove in the appendix using
the Cayley-Hamilton theorem.

Proposition 15 Let A⋆ ∈ Rn . For any vector x ∈ Rn and integer k ≥ n, we have

                      {A ∈ Rn×n | Ax = A⋆ x, A2 x = A2⋆ x, . . . , Ak x = Ak⋆ x}
                    ={A ∈ Rn×n | Ax = A⋆ x, A2 x = A2⋆ x, . . . , An x = An⋆ x}.


                                                    23
                                                S AFE L EARNING




    Given the sets S, Uk , and the vector c, the optimization problem we would like to solve to find
the next best infinite-step safe initialization point (i.e., the version of (2) for this specific case) is the
following:
                              min cT x
                                  x
                                  s.t. x ∈ S                                                                     (20)
                                          t
                                        Ax∈S          ∀A ∈ Uk ,      t = 1, 2, . . . .
    In keeping with the naming conventions of this work, we refer to the feasible region of (20) as
Sk∞ ; if U0 is a single matrix A, we call this set S ∞ (A).
    Unlike problems (7) and (13), which as we showed admit a reformulation as tractable conic
programs, problem (20) is in general intractable. In fact, even when the set U0 is a singleton,
deciding if a given vector x is feasible to (20) is NP-hard (Ahmadi and Günlük, 2024, Theorem
2.1). Therefore, our aim in this section is to find tractable inner approximations to the feasible
region of (20).
    We now describe our assumptions on (20) and their implications. We assume that our safety
region S is compact, as this is typically the case in most applications. It is also natural to require
S0∞ to be full-dimensional, as otherwise the implementation of a safe initialization would be impos-
sible in presence of arbitrarily small quantization error and/or physical perturbations. Under these
assumptions, we can make the following conclusions.

Proposition 16 Suppose that S is compact and S0∞ is full-dimensional. Then, U0 is bounded4 and
contains only matrices with spectral radius5 less than or equal to one.

Proof Suppose for the sake of contradiction that U0 is unbounded. Because U0 is a convex set,
there must exist a matrix A0 ∈ U0 and a nonzero matrix D ∈ Rn×n such that A0 + λD ∈ U0 for
all λ ≥ 0. Since D ̸= 0, the nullspace of D is not full-dimensional and therefore S0∞ cannot be
contained within it. Therefore there exists a vector x ∈ S0∞ such that Dx ̸= 0. Now observe that
(A0 + λD)x = A0 x + λDx ∈ S for every λ ≥ 0, which contradicts the compactness of S.
    To prove that U0 only contains matrices with spectral radius at most 1, suppose for the sake
of contradiction that there exists a matrix Ā ∈ U0 with an eigenvalue λ ∈ C satisfying |λ| > 1.
Because the spectral radius is dominated by the operator norm, we have that for every nonnegative
integer k, ∥Āk ∥ ≥ ρ(Āk ) ≥ |λ|k . Let R be a nonnegative scalar large enough such that x ∈ S
implies ∥x∥ ≤ R. Let g ∈ Rn be a random vector with each entry an independent standard normal.
First, we claim that P(g ∈ S0∞ ) = 0. Let U Σk V T be the singular value decomposition of Āk , with
the largest singular value placed on the first entry of Σk . By the rotational invariance of Gaussian
random vectors, ∥Āk g∥ has the same distribution as ∥Σk g∥. Therefore, letting g1 denote the first
 4. As the proof demonstrates, the claim that U0 is bounded holds even under the weaker requirement that S is compact
    and S01 is full-dimensional.
 5. Recall that the spectral radius of a square matrix A is defined as ρ(A) := maxi |λi (A)|, where λi (A) is the i-th
    eigenvalue of A.




                                                         24
                                          S AFE L EARNING




entry of the random vector g, we have

                         P(g ∈ S0∞ ) ≤ P(∥Āk g∥ ≤ R      ∀k ≥ 0)
                                                  k
                                      ≤ inf P(∥Ā g∥ ≤ R)
                                        k≥0
                                      = inf P(∥Σk g∥ ≤ R)
                                        k≥0
                                      ≤ inf P(∥Σk ∥|g1 | ≤ R)
                                        k≥0

                                      ≤ inf P(|λ|k |g1 | ≤ R)
                                        k≥0

                                      = inf P(|g1 | ≤ R|λ|−k )
                                        k≥0
                                                 Z R|λ|−k
                                             1
                                      = inf √             exp(−s2 /2) ds
                                        k≥0   2π −R|λ|−k
                                            r
                                              2
                                      ≤ inf     R|λ|−k = 0.
                                        k≥0   π
Since S0∞ is full-dimensional, its Lebesgue measure is positive. Furthermore, we showed that the
Gaussian measure of S0∞ is zero. Since the Lebesgue measure is absolutely continuous with respect
to the Gaussian measure, this is a contradiction.

    In view of Proposition 16, if we want S0∞ to be full-dimensional, we must assume that each
matrix in U0 has spectral radius less than or equal to one. We make the slightly stronger assumption
that U0 only contains matrices with spectral radius less than one. (Recall that a matrix with spectral
radius less than one is called stable or Schur stable.) Under this assumption, for the set S0∞ to
be nonempty, we need the origin to be in our safety region S (as otherwise, all initial conditions
would converge to the origin under (3) and eventually leave S). We work with the slightly stronger
assumption that the origin belongs to the interior of S. Under this assumption, our representation of
the polytope S in (5) can be simplified (after potential rescaling) to:
                                  n                                     o
                             S = x ∈ R n | hT   i x ≤ 1 i = 1, . . . , r .                       (21)

   Before we state the main theorem of this section, we need to recall some basic definitions. Let
Sm×m denote the space of m × m real-valued symmetric matrices.       We say that a matrix-valued
function M : Rn → Sm×m is a polynomial matrix if each entry Mij is a polynomial.

Definition 17 (SOS Polynomial and SOS Matrix) A polynomial p : Rn → R is said P        to be a sum
of squares (SOS) if there exist some polynomials q1 , . . . , qr : R 7→ R such that p = ri=1 qi2 . A
                                                                    n

polynomial matrix M : Rn → Sm×m is said to be a sum of squares matrix (SOS matrix) if the
scalar-valued polynomial y T M (x)y in the n + m variables (x, y) is SOS.

     We can now present our main theorem of this section, which enables us to find infinite-step safe
initialization points. Our arguments thus far justify the assumptions that this theorem places on the
uncertainty set Uk .



                                                 25
                                                    S AFE L EARNING




Theorem 18 Let the polyhedron S ⊆ Rn be as in (21), and the polyhedron U0 ⊆ Rn×n be as
in (4). For t = 0, . . . , n and ℓ = 1, . . . , k, let yt,ℓ ∈ Rn be the tth vector in the ℓth observed
trajectory; i.e., y0,ℓ is the trajectory’s initialization and yt,ℓ = At y0,ℓ . Let {ep }np=1 be the canonical
basis vectors of Rn . For an even integer d, let S̃k,d∞ be the projection to x-space of the feasible region

of the following optimization problem:


                              min                       cT x                                            (22)
              x,Q,Mj ,Mtℓp ,M̂j ,M̂tℓp ,σij ,σitℓp ,ε
                                                                      s
                                                                      X
             s.t.    Q(A) − AQ(A)AT = εI + M0 (A) +                         Mj (A)(vj − Tr(VjT A))     (22a)
                                                                      j=1
                       k X
                     n X
                     X   n
                 +                   Mtℓp (A)eT
                                              p (Ayt−1,ℓ − yt,ℓ ) ∀A ∈ R
                                                                         n×n

                     t=1 ℓ=1 p=1
                                                    s
                                                    X
             1 − hT
                  i Q(A)hi = σi0 (A) +                    σij (A)(vj − Tr(VjT A))                      (22b)
                                                    j=1
                       k X
                     n X
                     X   n
                 +                   σitℓp (A)eT
                                               p (Ayt−1,ℓ − yt,ℓ )      i = 1, . . . , r   ∀A ∈ Rn×n
                     t=1 ℓ=1 p=1
                                   s
               Q(A) x                X
                        = M̂ 0 (A) +   M̂j (A)(vj − Tr(VjT A))                                         (22c)
                xT  1
                                                 j=1
                       k X
                     n X
                     X   n
                 +                   M̂tℓp (A)eT
                                               p (Ayt−1,ℓ − yt,ℓ ) ∀A ∈ R
                                                                          n×n

                     t=1 ℓ=1 p=1

             ε > 0,                                                                                    (22d)

    • where Q(A), Mj (A) are n × n SOS matrices with degree at most d for j = 0, . . . , s,

    • Mtℓp (A) are n×n symmetric polynomial matrices with degree at most d for t = 1, . . . , n, ℓ =
      1, . . . , k, p = 1, . . . , n,

    • M̂j (A) are (n + 1) × (n + 1) SOS matrices with degree at most d for j = 0, . . . , s,

    • M̂tℓp (A) are (n + 1) × (n + 1) symmetric polynomial matrices with degree at most d for
      t = 1, . . . , n, ℓ = 1, . . . , k, p = 1, . . . , n,

    • σij (A) are SOS polynomials with degree at most d for i = 1, . . . , r, j = 0, . . . , s,

    • and σitℓp (A) are polynomials with degree at most d for i = 1, . . . , r, t = 1, . . . , n, ℓ =
      1, . . . , k, p = 1, . . . , n.

    Then,

  (i) The program (22) can be reformulated as a semidefinite program of size polynomial in the
      size of the input (S,U0 , {yt,ℓ } and c).


                                                               26
                                          S AFE L EARNING




                 ∞ ⊆ S ∞ (i.e, any vector x feasible to this semidefinite program is infinite-step
  (ii) We have S̃k,d  k
       safe).

 (iii) Furthermore, if Uk is compact and contains only stable matrices, then, for large enough d,
                 ∞ is full-dimensional.
       the set S̃k,d

In words, Theorem 18 allows us to optimize the initialization cost over semidefinite representable
subsets of the set of infinite-step safe points. While the theorem guarantees full-dimensionality
of these subsets for large d, in our experience, small values of d suffice for safe learning; see
Section 5.5. We present the proof of this theorem in Section 5.3 after we review some results
building up to it in Sections 5.1 and 5.2.

Remark 19 We note that problem (22) can be modified so that infinite-step safety is achieved in
the presence of bounded measurement noise. That is, suppose that instead of directly observing
yt,ℓ = A⋆ yt−1,ℓ , we observe
                                     ŷt,ℓ = yt,ℓ + zt,ℓ ,
where zt,ℓ represents the noise in the measurement and A⋆ ∈ U0 . We can still give an SOS
programming-based inner approximation of the infinite-step safety set in the case when we have
∥zt,ℓ ∥ ≤ Zt,ℓ , where ∥ · ∥ is, e.g., any polynomial norm (see Ahmadi et al. (2019) for a definition)
or any norm whose unit ball is a polytope, and Zt,ℓ is a given scalar. To see this, observe that the
vectors ŷt,ℓ will satisfy
                                     ŷt,ℓ = A⋆ (ŷt−1,ℓ − zt−1,ℓ ) + zt,ℓ .
Now for example, if ∥ · ∥ is the Euclidean norm, and if we have maxA∈Uk ∥A∥ ≤ Mk for some
constant Mk (computed, e.g., by a semidefinite relaxation), we can derive the following inequality:

                            ∥ŷt,ℓ − A⋆ ŷt−1,ℓ ∥ ≤ ∥A⋆ ∥∥zt−1,ℓ ∥ + ∥zt,ℓ ∥
                                                ≤ Mk Zt−1,ℓ + Zt,ℓ .

We can then adapt the methodology of Theorem 18 by multiplying the SOS matrices and polynomials
in semidefinite program (22) by the polynomials
                       n                                                  o
                         A 7→ (Mk Zt−1,ℓ + Zt,ℓ )2 − ∥ŷt,ℓ − Aŷt−1,ℓ ∥2
                                                                               t,ℓ

instead of {A 7→ eT p (Ayt−1,ℓ − yt,ℓ )}t,ℓ,p . For this modified SOS program, claims (i) and (ii) of
Theorem 18 hold, and claim (iii) holds under the slightly stronger assumption that U0 is compact.
    We note that in the case of noisy measurements, Proposition 15 does not apply anymore and it
may be useful to use more than n measurements from a trajectory.

5.1. Review of a Result from Ahmadi and Günlük (2024)
The basis of (22) comes from the approach of Ahmadi and Günlük (2024). Let the safety set S
be as in (21). For a single stable matrix A, this approach can be used to compute tractable inner
approximations of S ∞ (A).
    Recall that a matrix P ∈ Sn×n is positive definite (resp. positive semidefinite) if for every
nonzero vector x ∈ Rn we have that xT P x > 0 (resp. xT P x ≥ 0); we indicate such a matrix
with the notation P ≻ 0 (resp. P ⪰ 0). Furthermore, we use the notation P ≻ Q (resp. P ⪰ Q)

                                                  27
                                           S AFE L EARNING




if we have that P − Q is positive definite (resp. positive semidefinite). Consider the following
semidefinite program:

                                  min         cT x
                              x∈Rn ,Q∈Sn×n

                                        s.t. Q ≻ 0
                                              Q ⪰ AQAT                                             (23)
                                              hT
                                               i Qhi ≤ 1         i = 1, . . . , r
                                                           
                                                  Q       x
                                                              ⪰ 0.
                                                  xT      1
 The following lemma is a special case of Theorem 2.11 from Ahmadi and Günlük (2024). The
proof carries some intuition behind the construction of (22) and therefore we include it here.
Lemma 20 Let S ⊂ Rn be as in (21) and A ∈ Rn×n . Let S̃ ∞ (A) be the projection to x-space of
the feasible region of (23). We have S̃ ∞ (A) ⊆ S ∞ (A).
Proof Let E := {x | xT Q−1 x ≤ 1}; first we show that the constraints hTi Qhi ≤ 1 for i = 1, . . . , r
imply the set inclusion E ⊆ S. For a set T ⊆ R , we define its polar T ◦ as T ◦ := {y | y T x ≤
                                                  n

1, ∀x ∈ T }. One can check that E ⊆ S if and only if S ◦ ⊆ E ◦ , S ◦ = conv({hi }ri=1 ), and
E ◦ = {x | xT Qx ≤ 1}. Thus, for each i, the constraint hT                       ◦
                                                         i Qhi ≤ 1 implies hi ∈ E . By convexity,
                 ◦     ◦
it follows that S ⊆ E and therefore E ⊆ S as desired.                 
                                                                 Q x
     Note that by the Schur complement lemma, the constraint T            ⪰ 0 implies that x ∈ E.
                                                                x    1
Thus, x is in the safety region. To show that the trajectory remains safe for all time it suffices
to show that the set E is invariant under the dynamics, i.e. that if x̄ is in E, then so is Ax̄.
Fix an arbitrary point x̄ ∈ E. By two applications of the Schur complement lemma, the con-
straint Q ⪰ AQAT is equivalent to Q−1 ⪰ AT Q−1 A. This linear matrix inequality implies that
x̄T Q−1 x̄ ≥ x̄T AT Q−1 Ax̄. Thus, we have (Ax̄)T Q−1 (Ax̄) ≤ x̄T Q−1 x̄ ≤ 1, and hence Ax̄ ∈ E
as desired.

The approach of Ahmadi and Günlük (2024) and its extensions lead to infinite-safe sets for dynamics
governed by a single matrix, or a group of matrices where the “joint spectral radius” is less than one.
Our Theorem 18 extends their approach to the case where each individual matrix in Uk is stable,
which is a weaker condition than the joint spectral radius of the matrices in Uk being less than one.
This is the relevant setting for us which is not covered by Ahmadi and Günlük (2024).
    We also note that the approach of Ahmadi and Günlük (2024) gives a hierarchy of inner approx-
imations to S ∞ (A). However, the first level of the hierarchy is sufficient for our goal of finding
full-dimensional inner approximations.

5.2. Review of Putinar’s Positivstellensatz
In this subsection, we briefly review Putinar’s Positivstellensatz and its matrix generalization due to
Scherer and Hol which, when combined with Lemma 20, help us approximate the feasible region
of (20) with semidefinite programs. These theorems involve SOS polynomials and matrices (cf.
Definition 17), and our interest in them stems from the following well-known fact: the constraint
that an unknown polynomial or a polynomial matrix of a given degree be SOS and satisfy a set of
affine inequalities can be cast as an semidefinite program of tractable size; see, e.g., Parrilo (2000).

                                                     28
                                           S AFE L EARNING




Definition 21 (Archimedian Property) We say that a set of n-variate polynomials G = {g1 , . . . , gm }
satisfies the Archimedian property if there exists a scalar R and SOS polynomials σ0 , σ1 , . . . , σm
such that
                             Xn                  Xm
                         2        2
                       R −       xi = σ0 (x) +       σj (x)gj (x) ∀x ∈ Rn .
                              i=1                j=1

   Note that the Archimedian property implies that the set

                          K(G) := {x ∈ Rn | gi (x) ≥ 0 i = 1, . . . , m}                         (24)

is compact. Furthermore, it is known that if g1 , . . . , gm are affine polynomials and if K(G) is
compact, then G satisfies the Archimedian property (see, e.g., Laurent, 2009). Note that if we let
G = {A 7→ vj − Tr(VjT A)}sj=1 , then U0 from (4) equals K(G) and G satisfies the Archimedian
property.

Theorem 22 (Putinar’s Positivstellensatz (Putinar, 1993)) Let G = {g1 , . . . , gm } be a set of n-
variate polynomials satisfying the Archimedian property and let K(G) be as in (24). For any poly-
nomial p : Rn → R, we have p(x) > 0 for all x ∈ K(G) if and only if there exists a positive scalar
ε and SOS polynomials σ0 , σ1 , . . . , σm such that
                                               m
                                               X
                         p(x) = ε + σ0 (x) +         σj (x)gj (x) ∀x ∈ Rn .
                                               j=1

Theorem 23 (Matrix Putinar’s Positivstellensatz (Scherer and Hol, 2006)) Let G = {g1 , . . . , gm }
be a set of n-variate polynomials satisfying the Archimedian property and let K(G) be as in (24).
For any polynomial matrix M : Rn → Sr×r , we have M (x) ≻ 0 for all x ∈ K(G) if and only if
there exists a positive scalar ε and SOS matrices S0 , S1 , . . . , Sm such that
                                                 m
                                                 X
                        M (x) = εI + S0 (x) +          Sj (x)gj (x)   ∀x ∈ Rn .
                                                 j=1


5.3. Proof of Theorem 18
In addition to Theorems 22 and 23, the proof of claim (iii) in Theorem 18 also relies on the following
technical lemma.

Lemma 24 Let U ⊂ Rn×n be a compact set of matrices. Then, every matrix A ∈ U is stable if
and only if there exists a n × n SOS matrix P : Rn×n 7→ Sn×n such that

   1. P (A) ≻ 0 ∀A ∈ U ,

   2. P (A) − AT P (A)A ≻ 0         ∀A ∈ U .

Proof [“If”] It is straightforward to check that the conditions imply that for any matrix A ∈ U , the
positive definite Lyapunov function VA (x) = xT P (A)x satisfies VA (Ax) < V (x) for all x ̸= 0.
The stability of A then follows from Lyapunov’s stability theorem; see, e.g., (Żak, 2003, Theorem
4.3).


                                                 29
                                               S AFE L EARNING




    [“Only if”] For a positive integer N , let the SOS matrix PN : Rn×n → Sn×n be defined as
follows:
                                                XN
                                    PN (A) =        (Ak )T (Ak ).
                                                    k=0

Clearly we have PN (A) ≻ 0 for each matrix A ∈ U since each summand is positive semidefinite
and the zeroth summand is the identity matrix. We claim that for sufficiently large N , PN (A) will
satisfy PN (A) − AT PN (A)A ≻ 0 for all A ∈ U . Observe

                           PN (A) − AT PN (A)A = I − (AN +1 )T (AN +1 ).

To show that PN (A) − AT PN (A)A ≻ 0 for each A ∈ U , we prove

                                     ∥(AN +1 )T (AN +1 )∥ < 1    ∀A ∈ U.

For a matrix B, let ∥B∥∞ := maxij |Bij |. Define the scalars R, M as

                                    R := max ρ(A),     M := max ∥A∥∞ .
                                         A∈U                    A∈U

Since each matrix A ∈ U is stable and U is compact, R < 1. Since U is compact, M < ∞. Now
fix a matrix A ∈ U and write A = QT Q−1 , where Q ∈ Cn×n is unitary and T ∈ Cn×n is upper
triangular (this “Schur decomposition” always exists). Observe that ∥AN ∥ = ∥T N ∥. We can bound
the norm of powers of a triangular matrix as follows (see Corollary 3.15 of Dowler (2013)):

                                √ n−1
                                   X n − 1N 
                                N
                          ∥T ∥ ≤ n              ∥T ∥j∞ ρ(T )N −j .
                                        j    j
                                           j=0

In particular, we have

                 √ n−1
                    X n − 1N 
                                  j N −j  √ n−1
                                             X n − 1
              N
           ∥A ∥ ≤ n              M R     ≤ n           N j M j RN −j .                                (25)
                         j    j                   j
                          j=0                                         j=0

Inequality (25) implies that limN →∞ ∥AN ∥ = 0. Therefore, we can choose N large enough such
that
                               ∥(AN +1 )T (AN +1 )∥ ≤ ∥AN +1 ∥2 < 1.



     We are now able to present the proof of the main result of this section.
Proof [of Theorem 18]
     (i) Recall that for any fixed degree d, the SOS constraints in (22) can be reformulated as semidef-
inite programming constraints of size polynomial in n; see, e.g., Parrilo (2000). The constraints in
(22a), (22b), (22c) can be imposed by coefficient matching via a number of linear equations bounded
by a polynomial function of     the size of the input (S, U0 , {yt,ℓ }). The constraint that ε > 0 can be
                                ε 1
rewritten as the constraint             ⪰ 0 for a new variable δ. Therefore, for any fixed degree d, (22)
                                1 δ
is a semidefinite program of size polynomial in the size of the input (S, U0 , {yt,ℓ }, c).

                                                     30
                                            S AFE L EARNING




   (ii) Let (x, Q, Mj , Mtℓp , M̂j , M̂tℓp , σij , σitℓp , ε) be feasible to (22). It is straightforward to
check that for every A ∈ Uk , the tuple (x, Q(A)) satisfies the following constraints

                                      Q(A) ≻ 0
                                      Q(A) ⪰ AQ(A)AT
                                      hT
                                       i Q(A)hi ≤ 1 i = 1, . . . , r
                                                                                                      (26)
                                               
                                       Q(A) x
                                                  ⪰ 0.
                                         xT   1

Therefore, by Lemma 20, we have x ∈ S̃ ∞ (A) ⊆ S ∞ (A) for every A ∈ Uk . Hence,
                                        \
                                  x∈        S ∞ (A) = Sk∞ .
                                            A∈Uk

                    ∞ ⊆ S∞.
This implies that S̃k,d    k
   (iii) Suppose that Uk is compact and contains only stable matrices. It follows that the set

                                         UkT := {AT | A ∈ Uk }

is also compact and contains only stable matrices. By Lemma 24 applied to UkT , there exists an SOS
matrix P (A) which satisfies

                                   P (A) ≻ 0 ∀A ∈ U0T
                                   P (A) ≻ AT P (A)A         ∀A ∈ U0T .

Now by defining Q(A) := P (AT ), we observe that

                                   Q(A) ≻ 0       ∀A ∈ U0
                                   Q(A) ≻ AQ(A)AT            ∀A ∈ U0 .

     Analogously to how we derived linear constraints in (14), we can rewrite the description of Uk
as
                    Uk = {A ∈ U0 | Ayt−1,ℓ = yt,ℓ , t = 1, . . . , n, ℓ = 1, . . . , k}.
Since Uk is a compact polyhedron, the Archimedian property is satisfied for the polynomials {A 7→
vj − Tr(VjT A)} and {A 7→ ±eT    p (Ayt−1,ℓ − yt,ℓ )}. By Theorem 23, since Q(A) − AQ(A)A ≻ 0
                                                                                              T
                                                                                 ±
for every A ∈ Uk , there exists a positive scalar ε and SOS matrices Mj (A) and Mtℓp (A) that satisfy
                                                    s
                                                    X
          Q(A) − AQ(A)AT =εI + M0 (A) +                   Mj (A)(vj − Tr(VjT A))
                                                    j=1
                                        k X
                                      n X
                                      X   n
                                                     +
                                  +                 Mtℓp (A)eT
                                                             p (Ayt−1,ℓ − yt,ℓ )
                                      t=1 ℓ=1 p=1
                                        k X
                                      n X
                                      X   n
                                                     −
                                  −                 Mtℓp (A)eT
                                                             p (Ayt−1,ℓ − yt,ℓ )    ∀A ∈ Rn×n .
                                      t=1 ℓ=1 p=1



                                                     31
                                               S AFE L EARNING



                         +            −
By letting Mtℓp (A) = Mtℓp  (A) − Mtℓp   (A), we can satisfy (22a).
    Now observe that for each i ∈ {1, . . . , r}, the function A → hT  i Q(A)hi is continuous. There-
fore, since Uk is compact, there exists a positive scalar α satisfying

                                            max           hT
                                                           i Q(A)hi < α.
                                       i∈{1,...,r},A∈Uk

Observe that the tuple (ε/α, Q(A)/α, Mj (A)/α, Mtℓp /α) still satisfies (22a), (22d), and the SOS
constraints. Furthermore, for each i ∈ {1, . . . , r}, 1 − α−1 hT
                                                                i Q(A)hi > 0 for all A ∈ Uk . There-
fore, by Theorem 22, and by a similar argument as in the case of constraint (22a), there exist SOS
polynomials σij (A) and polynomials σitℓp (A) satisfying (22b).
    Since Q(A)/α is a continuous function of A and since Q(A)/α is positive definite for each A
in the compact set Uk , there exists a scalar β > 0 such that Q(A)/α ≻ βI for all A ∈ Uk . Then,
we have                                              
                                 Q(A)/α − βI 0
                                                    1 ≻ 0 ∀A ∈ Uk .
                                        0           2
It follows from Theorem 23, and by a similar argument as in the case of constraint (22a), that there
exist some SOS matrices M̂j (A) and symmetric polynomial matrices M̂tℓp (A) satisfying
                                               s
             Q(A)/α − βI    0                    X
                            1       =M̂0 (A) +         M̂j (A)(vj − Tr(VjT A))
                  0         2                    j=1
                                            k X
                                          n X
                                          X   n
                                      +                 M̂tℓp (A)eT
                                                                  p (Ayt−1,ℓ − yt,ℓ ) ∀A ∈ R
                                                                                             n×n
                                                                                                 .
                                          t=1 ℓ=1 p=1
                                                                                       
                                                           q
                                                                1                 βI x
Observe that for any x ∈ Rn satisfying ∥x∥ ≤                   2β , we have               ⪰ 0. Therefore, A 7→
                                                                                  xT 12
              
          βI x
M̂0 (A) + T 1 is still an SOS matrix of the same degree as M̂0 (A). Hence, for any x satisfying
          x  2
       q
         1
∥x∥ ≤ 2β , we have that the tuple
                                                                                          
                                          βI x
           x, Q/α, Mj /α, Mtℓp /α, M̂0 + T 1 , M̂1 , . . . , M̂s , M̂tℓp , σij , σitℓp , ε/α
                                         x   2

is feasible to (22) for some degree d large enough.



5.4. Number of Trajectories Needed to Learn
In Corollary 9, we established that we need no more than n one-step trajectories to safely learn the
matrix A⋆ ∈ Rn×n governing the true linear dynamical system of interest. Then in Theorem 13, we
proved that generically, it is possible to safely learn A⋆ using only ⌈ n2 ⌉ trajectories of length two.
We now show that generically, we can safely learn A⋆ from a single trajectory of length n.




                                                          32
                                                S AFE L EARNING




Theorem 25 There exists a set A ⊂ Rn×n of Lebesgue measure zero such that if A⋆ ∈     / A, then by
observing a single trajectory of length n initialized at random6 from any full-dimensional infinite-
                                      ∞ defined in Theorem 18 for large enough d), we will almost
step safe set (for example, the set S̃0,d
surely safely learn A⋆ .

Proof Consider the set

                   V := {[A, x] ∈ Rn×(n+1) | det([x, Ax, A2 x, . . . , An−1 x]) = 0}.

This is the zero-set of a polynomial, therefore it is either the entire space or has Lebesgue measure
zero. It is not the entire space since we can take A to be the matrix with ones on its first subdiagonal
and zeros elsewhere and x to be the vector with one as its first entry and zeros elsewhere. With A
and x defined this way, we have

                            det([x, Ax, A2 x, . . . , An−1 x]) = det(I) = 1 ̸= 0.

Therefore, V must have Lebesgue measure zero. Since the Lebesgue measure on Rn×(n+1) is the
completion of the product measure of the Lebesgue measures of Rn×n and Rn , we have that for
almost every A, the set

                         VA := {x ∈ Rn | det([x, Ax, A2 x, . . . , An−1 x]) = 0}

has Lebesgue measure zero. Thus, there must exist a set A ⊂ Rn×n of Lebesgue measure zero such
          / A, then VA has Lebesgue measure zero. Now assume that A⋆ ∈
that if A ∈                                                                     / A and let x be the initial-
ization of our observed trajectory. Because x is sampled at random6 from a full-dimensional infinite-
step safe set, we have P(x ̸∈ VA⋆ ) = 1. When x ̸∈ VA⋆ , we have det([x, A⋆ x, A2⋆ x, . . . , A⋆n−1 x]) is
nonzero, and therefore [x, A⋆ x, A2⋆ x, . . . , An−1
                                                 ⋆   x] is invertible. Since we observe [A⋆ x, A2⋆ x, . . . , An⋆ x],
we can now recover A⋆ by solving a linear system

                         A⋆ [x, A⋆ x, A2⋆ x, . . . , A⋆n−1 x] = [A⋆ x, A2⋆ x, . . . , An⋆ x]
                                                                                         −1
                    ⇒ A⋆ = [A⋆ x, A2⋆ x, . . . , An⋆ x] [x, A⋆ x, A2⋆ x, . . . , A⋆n−1 x]    .




5.5. Numerical Examples
In this section, we present two numerical examples of infinite-step safe learning.

5.5.1. I NNER AND O UTER A PPROXIMATIONS OF THE I NFINITE -S TEP S AFE S ET
In our first example, we take n = 2,
                                                                                
                            2×2              1                                 9
              U0 = A ∈ R        A1,1 = A2,2 = , A1,2 , A2,1 ≥ 0, A1,2 + A2,1 =     ,
                                             2                                 5
 6. Any distribution that is absolutely continuous with respect to the Lebesgue measure would work; for example, the
    uniform distribution.



                                                         33
                                          S AFE L EARNING




and                                                
                                          1  1       1 
                              S = x ∈ R2 −1 0  x ≤ 1 .
                                           0 −1       1
                                                       

One can check that every matrix in U0 is stable, though there are products of matrices in U0 that
have spectral radius greater than one and hence the techniques of Ahmadi and Günlük (2024) do not
apply. We solve the semidefinite program (22) with degree d = 4 (in this example, the semidefinite
                                                                ∞ , and S̃ ∞ (A) for various matrices
program with d = 2 is infeasible). In Figure 6(a), we plot S, S̃0,4
A in U0 . We also plot S̄0∞ which is the intersection of S 10 (A) for various matrices A in U0 ; in
particular, S̄0∞ is an outer approximation of S0∞ . This outer approximation is not too much larger
       ∞ , our inner approximation of S ∞ .
than S̃0,4                               0
    In this example, we also observe that
                                                 \
                                           ∞
                                        S̃0,4 =      S̃ ∞ (A).
                                                A∈U0

                                                     ∞ ⊆             ∞
                                                            T
From the proof of Theorem 18, we have that S̃0,d              A∈U0 S̃ (A) for all d. Therefore, this
example shows not only that d = 4 is high enough to get a full-dimensional inner approximation of
S0∞ , but also that d = 4 is sufficient to get the largest possible infinite-step safe set based on our
approach.

5.5.2. C OMPARING O NE , T WO , AND I NFINITE - STEP S AFETY
In our second example, we take n = 2,
                                                                           
                                                   1 .5
                       U0 = A ∈ Rn×n           A−                     ≤ 0.1       ,
                                                  −.5 .5          F
                                                                                       
                                                                               1.05 .5
and the same safety region S as in the previous example. We take A⋆ =                     ∈ U0 and
                                                                                −.5 .5
the initialization cost function to be given by the affine function c(x) = (−1, 0)T x + 3, which is
nonnegative over S.
    Since the initial uncertainty set U0 is not polyhedral, we replace the linear programs in Algo-
rithm 1 for one-step safe learning with semidefinite programs. This is done by taking (13), discard-
ing the two-step constraint, and then converting the resulting problem to a semidefinite program by
the same method as in Theorem 10. Our algorithm then learns A⋆ with two one-step safe trajectories
with a total initialization cost of 3.1489.
    For two-step safe learning, we use Algorithm 3. We learn A⋆ with one two-step safe trajectory
with an initialization cost of 1.9252.
    For infinite-step safe learning, we adapt the method of Theorem 18 to the non-polyhedral set U0
by multiplying the SOS matrices and polynomials in semidefinite program (22) by the polynomial
                                  (                             2)
                                            2            1 .5
                                    A 7→ 0.1 − A −
                                                        −.5 .5 F

instead of {A 7→ vj − Tr(VjT A)}sj=1 . We learn A⋆ with one infinite-step safe trajectory with an
initialization cost of 2.0080.

                                                  34
                                             S AFE L EARNING




    In this example, we see that two-step learning incurs the lowest total initialization cost. This is
because a single two-step safe trajectory is sufficient for learning A⋆ . Therefore, the initialization
cost is incurred once as opposed to twice for one-step safe learning. Additionally, requiring two-
step safety is less restrictive than requiring infinite-step safety resulting in lower cost compared to
infinite-step safe learning.
                                                   ∞ and the initialization points chosen by each algorithm.
    In Figure 6(b), we plot S, S01 , S11 , S02 , S̃0,2
We observe the inclusion relationships S̃0,2      ∞ ⊆ S 2 ⊆ S 1 ⊆ S as expected. Note that S 1 and S 2
                                                         0       0                                 0       0
are exact characterizations of the one-step and two-step safety sets, respectively, while S̃0,2      ∞ is an

inner approximation of S0∞ , the true infinite-step safety set. Since S̃0,2  ∞ is not much smaller than S 2 ,
                                                                                                          0
                           ∞
which is a superset of S0 , we see that our semidefinite representable set S̃0,d      ∞ with d = 2 closely

approximates the true infinite-step safety set S0∞ .
    To show that the above trend is not specific to the example we chose, we repeat the procedure
for 100 randomly generated instances of this problem. We use the same sets S and U0 , we sample
the matrix A⋆ uniformly at random from U0 , and we sample the cost vector c uniformly at random
from the unit sphere. In all 100 examples, we learn the true system after two one-step trajectories
as guaranteed by Corollary 9, or with a single trajectory of length two (or longer) as suggested by
Theorem 13 (or Theorem 25). The cost of one-step learning was on average 3.5324 with a standard
deviation of 0.5907. The cost of two-step learning was on average 1.9484 with a standard deviation
of 0.1963. The cost of infinite-step learning was on average 2.0246 with a standard deviation of
0.1746. The box plot in Figure 7 summarizes the distribution of initialization costs for each version.
Here, the initialization cost of infinite-step safe learning is slightly higher than that of two-step safe
learning. Observe that since S0∞ ⊆ S02 , and since a two-dimensional system can be learned with
a single two-step trajectory, the cost of two-step safe learning here will never be worse than that
of infinite-step safe learning. While S02 ⊆ S01 , the cost of one-step safe learning is higher in these
examples since initialization cost is paid twice.

6. One-Step Safe Learning of Nonlinear Systems
In this section, we turn our attention to the problem of safely learning a dynamical system of the
form xt+1 = f⋆ (xt ), where
                                         f⋆ (x) = A⋆ x + g⋆ (x),                                        (27)
for some matrix A⋆ ∈ Rn×n and some possibly nonlinear map g⋆ : Rn → Rn . We take our safety
region S ⊂ Rn to be the same as (5). Our initial knowledge about A⋆ , g⋆ is membership in the sets
                            n                                              o
                    U0,A := A ∈ Rn×n | Tr(VjT A) ≤ vj j = 1, . . . , s ,
                       U0,g := {g : Rn → Rn | ∥g(x)∥∞ ≤ γ∥x∥dp             ∀x ∈ S}.
Here, p ≥ 1 is either +∞ or a rational number, γ is a given positive constant, and d is a given
nonnegative integer. The use of the ∥ · ∥∞ on g in the definition of U0,g simplifies some of the
following analysis, though an extension to other semidefinite representable norms is possible. Here
the parameter d represents the growth rate of the nonlinearity; a larger value of d corresponds to a
nonlinearity that can grow faster away from the origin. Note that by taking d = 0, e.g., our model
of uncertainty captures any map f which is bounded on S. Again for simplicity, we assume a linear
initialization cost cT x for some vector c ∈ Rn .

                                                     35
                                           S AFE L EARNING




      2                                                    2

    1.5                                                 1.5

      1                                                    1

    0.5                                                 0.5

      0                                                    0

   -0.5                                                 -0.5

      -1                                                  -1

           -1          0           1           2               -1          0           1           2

(a) Inner approximation of the infinite-step safety (b) One-step and two-step safety sets and an in-
    set of a linear system associated with the ex-      ner approximation of the infinite-step safety
    ample in Section 5.5.1.                             set associated with the example in Sec-
                                                        tion 5.5.2.

    Figure 6: Infinite-step safe learning associated with the numerical examples in Section 5.5.




Figure 7: Total initialization cost of one, two, and infinite-step safe learning for the distribution of
          two-dimensional problems described at the end of Section 5.5.2.




                                                   36
                                             S AFE L EARNING




    Our goal in this section is to demonstrate how to safely collect one-step safe trajectories for (27)
at minimum cost. By doing so, we reduce our uncertainty on A⋆ and are able to fit a parametric
model to g that respects the constraints in U0,g . Having collected k safe measurements {(xj , yj )}kj=1
with yj = f⋆ (xj ), we can reduce our uncertainty around A⋆ as follows:

                      Uk,A = {A ∈ U0 | ∥Axj − yj ∥∞ ≤ γ∥xj ∥dp           j = 1, . . . , k}.

The optimization problem to find the next cheapest one-step safe initialization point (i.e., the version
of (2) for this specific case) is then:

                 min cT x
                  x
                  s.t. x ∈ S                                                                            (28)
                        f (x) ∈ S    ∀ f ∈ {x 7→ Ax + g(x) | A ∈ Uk,A , g ∈ U0,g }.

We show next that an exact reformulation of this problem can be solved in an efficient manner.

6.1. Reformulation as a Second-Order Cone Program
Our main result of this section is to derive a tractable reformulation of problem (28).

Theorem 26 Problem (28) can be reformulated as a second-order cone program.

Proof We start by rewriting problem (28) using the definition of S:

            min cT x
             x
             s.t. hT
                   i x ≤ bi i = 1, . . . , r
                                           hT
                                                               
                    maxA,g                   i (Ax + g(x))                                              (29)
                   s.t.        Tr(VjT A) ≤ vj j = 1, . . . , s 
                                                                 ≤ bi
                                                                                   i = 1, . . . , r.
                               ∥g(x)∥∞ ≤ γ∥x∥dp ∀x ∈ S 
                                    Axℓ + g(xℓ ) = yℓ     ℓ = 1, . . . , k

 Note that in the inner maximization problem in (29), the variable x is fixed. We claim that if
x ̸∈ {x1 , . . . , xk }, then

                      hT
                                               
  maxA,g               i (Ax + g(x))
  s.t.        Tr(VjT A) ≤ vj j = 1, . . . , s 
                                                                                (30)
              ∥g(x)∥∞ ≤ γ∥x∥dp ∀x ∈ S 
             Axℓ + g(xℓ ) = yℓ ℓ = 1, . . . , k
                              hT                                     hT
                                                                                
         maxA,g                i Ax                 maxA,g            i g(x)
         s.t.         Tr(VjT A) ≤ vj ∀j           s.t.      Tr(VjT A) ≤ vj ∀j   
       =                                        +                               .
                    Axℓ + g(xℓ ) = yℓ ∀ℓ                  Axℓ + g(xℓ ) = yℓ ∀ℓ 
                  ∥g(x)∥∞ ≤ γ∥x∥dp ∀x ∈ S                  ∥g(x)∥∞ ≤ γ∥x∥dp ∀x ∈ S

 It is clear that the left-hand side is upper bounded by the right-hand side. To show the reverse in-
equality, let (A1 , g1 ) (resp. (A2 , g2 )) be feasible to the first (resp. second) problem on the right-hand



                                                     37
                                                     S AFE L EARNING




side (if any of these of these problems is infeasible, then the inequality we are after is immediate).
Now let
                                       (
                                        g2 (x)       if x ̸∈ {x1 , . . . , xk }
                             ĝ2 (x) =
                                        yℓ − A1 xℓ if x = xℓ .

 It is straightforward to check that the pair (A1 , ĝ2 ) is feasible to the left-hand side of (30), therefore
proving (30).
      We now focus on reformulating each term on the right-hand side of (30), again under the as-
sumption that x ̸∈ {x1 , . . . , xk }. Using the constraint on g, the first term can be rewritten as
follows:
                            max hT    i Ax
                                  A
                                  s.t. Tr(VjT A) ≤ vj               j = 1, . . . , s                                     (31)
                                        ∥Axℓ − yℓ ∥∞ ≤ γ∥xℓ ∥dp                ℓ = 1, . . . , k.
Note that (31) is a linear program as it is equivalent to:

                   max hT
                        i Ax
                     A
                     s.t. Tr(VjT A) ≤ vj             j = 1, . . . , s
                                                                                                                         (32)
                            (Axℓ − yℓ )ℓ′ ≤ γ∥xℓ ∥dp             ℓ = 1, . . . , k       ℓ′ = 1, . . . , n
                             − (Axℓ − yℓ )ℓ′ ≤ γ∥xℓ ∥dp                ℓ = 1, . . . , k     ℓ′ = 1, . . . , n.

Here, the notation (Axℓ − yℓ )ℓ′ represents the ℓ′ -th coordinate of the vector (Axℓ − yℓ ). Following
the same approach as in Section 3, we proceed by taking the dual of this linear program. For
                                                                     +       −
j = 1, . . . , s, ℓ = 1, . . . , k, and ℓ′ = 1, . . . , n, let µj , ηℓℓ ′ , ηℓℓ′ ∈ R be dual variables. The dual of

problem (32) reads:
                  s
                  X                 n
                                  k X
                                  X                                              n
                                                                               k X
                                                                               X
                                               +           d                                 −           d
       min              µj vj +               ηℓℓ ′ (γ∥xℓ ∥p + (yℓ )ℓ′ ) +                  ηℓℓ ′ (γ∥xℓ ∥p − (yℓ )ℓ′ )
     µ,η + ,η −
                  j=1             ℓ=1 ℓ′ =1                                    ℓ=1 ℓ′ =1
                           s
                           X                    n
                                              k X
                                              X                           k X
                                                                          X n                                            (33)
                                                           +                            −
           s.t.   xhT
                    i =        µj VjT +                   ηℓℓ      T
                                                             ′ xℓ eℓ′ −                ηℓℓ      T
                                                                                          ′ xℓ eℓ′
                           j=1                ℓ=1 ℓ′ =1                   ℓ=1 ℓ′ =1
                              +                −
                  µ ≥ 0,     η ≥ 0,           η ≥ 0,

where eℓ′ is the l-th coordinate vector. Now we turn our attention to the second term on the right-
hand side of (30). After eliminating the irrelevant constraints, the problem can be rewritten as:

                                              max hT
                                                   i g(x)
                                                 g
                                                                                                                         (34)
                                                s.t. ∥g(x)∥∞ ≤ γ∥x∥dp .

Recall that the dual norm of ∥·∥∞ is ∥·∥1 . Therefore, the optimal value of this optimization problem
is simply γ∥hi ∥1 · ∥x∥dp .



                                                               38
                                                    S AFE L EARNING




    Now consider the optimization problem:

      min         cT x
   x,µ,η + ,η −

           s.t. hT
                 i x ≤ bi        i = 1, . . . , r
                  s                  n
                                   k X
                          (i)                   +(i)
                  X                X
                         µj vj +               ηℓℓ′ (γ∥xℓ ∥dp + (yℓ )ℓ′ )
                  j=1              ℓ=1 ℓ′ =1
                             k X
                               n                                                                              (35)
                                        −(i)
                             X
                         +            ηℓℓ′ (γ∥xℓ ∥dp − (yℓ )ℓ′ ) + γ∥hi ∥1 · ∥x∥dp ≤ bi    i = 1, . . . , r
                         ℓ=1 ℓ′ =1
                          s             k X   n                     k X   n
                               (i) T               +(i)                       −(i)
                        X              X                           X
                  xhT
                    i =     µ  j  Vj +           η ℓℓ′  x ℓ eT
                                                             ℓ ′ −           ηℓℓ′ xℓ eT
                                                                                      ℓ′   i = 1, . . . , r
                        j=1            ℓ=1 ℓ′ =1                   ℓ=1 ℓ′ =1
                            +          −
                  µ ≥ 0,        η ≥ 0,      η ≥ 0.

If d = 0, or if d = 1 and p ∈ {1, +∞}, then (35) is a linear program. Otherwise, the rationality of p
ensures that ∥x∥dp is second-order cone representable (see Ben-Tal and Nemirovski, 2001, Sect. 2.3;
Lobo et al., 1998, Sect. 2.5). This means that (35) is indeed a second-order cone program.
     Let F ⊂ Rn denote the projection of the feasible set of (35) to x-space. We claim that the feasi-
ble set of (28) equals F ∪ {x1 , . . . , xk }. Indeed, since the vectors xk are one-step safe initialization
points, we have that xk ∈ S and yk ∈ S. This implies that xk is feasible to (28). Furthermore, for
x ∈ F \ {x1 , . . . , xk }, we have shown that x satisfies the constraints of (29) if and only if x satisfies
the constraints of (35).
     Therefore, optimizing an objective function over the feasible set of (28) is equivalent to opti-
mizing the same objective function over F ∪ {x1 , . . . , xk }.


Remark 27 We note that problem (35) can be modified so that one-step safety is achieved in the
presence of bounded disturbances. That is, suppose that the dynamics were governed by

                                           xt+1 = A⋆ xt + g⋆ (xt ) + wt ,

where wt represents some potentially adversarial disturbance, A⋆ ∈ U0,A , and g⋆ ∈ U0,g . We can
still give an exact second-order cone programming-based characterization of the one-step safety set
in the case when we have ∥wt ∥ ≤ Wt , where ∥ · ∥ is any norm whose unit ball is a polytope and
Wt is a given scalar. For example, if ∥ · ∥ is the infinity norm, the set of one-step safe initialization
points after observing k measurements from the disturbed dynamics is the projection to x-space of




                                                            39
                                                                   S AFE L EARNING




the feasible set of the following second-order cone program:

   min           cT x
x,µ,η + ,η −

        s.t. hT
              i x ≤ bi              i = 1, . . . , r
                  s                      n
                                       k X
                         (i)                           +(i)
                  X                    X
                        µj v j +                      ηℓℓ′ (γ∥xℓ ∥dp + Wℓ + (yℓ )ℓ′ )
                  j=1                  ℓ=1 ℓ′ =1
                               n
                             k X
                                               −(i)
                             X
                         +                   ηℓℓ′ (γ∥xℓ ∥dp + Wℓ − (yℓ )ℓ′ ) + γ∥hi ∥1 · ∥x∥dp + Wk+1 ∥hi ∥1 ≤ bi                          i = 1, . . . , r
                               ℓ=1 ℓ′ =1
                                                        n
                                                      k X                            n
                                                                                   k X
                                       (i)                          +(i)                        −(i)
                             X                        X                            X
                 xhT
                   i =             µj VjT +                        ηℓℓ′ xℓ eT
                                                                            ℓ′ −               ηℓℓ′ xℓ eT
                                                                                                        ℓ′   i = 1, . . . , r
                               j                      ℓ=1 ℓ′ =1                    ℓ=1 ℓ′ =1
                                                      −
                 µ ≥ 0,         η + ≥ 0,            η ≥0

where the input to the problem is the descriptions of S and U0 (hi , bi and Vj , vj ) and the mea-
                                                            (i)
surements (xℓ , yℓ ) and we have introduced dual variables µj for i = 1, . . . , r, j = 1, . . . , s and
 +(i)     −(i)
ηℓℓ′ , ηℓℓ′ for i = 1, . . . , r, ℓ = 1, . . . , k and ℓ′ = 1, . . . , n.

Remark 28 We note that problem (35) can be modified so that one-step safety is achieved in the
presence of bounded measurement noise. That is, suppose that instead of directly observing yk =
A⋆ xk + g⋆ (xk ), we observe
                                yk = A⋆ xk + g⋆ (xk ) + zk ,
where zk represents the noise in the measurement, A⋆ ∈ U0,A , and g⋆ ∈ U0,g . We can still give
an exact second-order cone programming-based characterization of the one-step safety set in the
case when we have ∥zk ∥ ≤ Zk , where ∥ · ∥ is any norm whose unit ball is a polytope and Zk is a
given scalar. For example, if ∥ · ∥ is the infinity norm, the set of one-step safe initialization points
after observing k noisy measurements is the projection to x-space of the feasible set of the following
second-order cone program:

        min        cT x
   x,µ,η + ,η −

           s.t. hT
                 i x ≤ bi                i = 1, . . . , r
                    s                          n
                                             k X
                           (i)                              +(i)
                    X                        X
                          µj v j +                         ηℓℓ′ (γ∥xℓ ∥dp + Zℓ + (yℓ )ℓ′ )
                    j=1                      ℓ=1 ℓ′ =1
                                     n
                                   k X
                                                    −(i)
                                   X
                               +                   ηℓℓ′ (γ∥xℓ ∥dp + Zℓ − (yℓ )ℓ′ ) + γ∥hi ∥1 · ∥x∥dp ≤ bi               i = 1, . . . , r
                                   ℓ=1 ℓ′ =1
                                                             n
                                                           k X                           n
                                                                                       k X
                                             (i)                        +(i)                        −(i)
                                   X                       X                           X
                   xhT
                     i =                µj VjT +                       ηℓℓ′ xℓ eT
                                                                                ℓ′ −               ηℓℓ′ xℓ eT
                                                                                                            ℓ′   i = 1, . . . , r
                                   j                       ℓ=1 ℓ′ =1                   ℓ=1 ℓ′ =1
                   µ ≥ 0,           η + ≥ 0,           η− ≥ 0



                                                                           40
                                                 S AFE L EARNING




where the input to the problem is the descriptions of S and U0 (hi , bi and Vj , vj ) and the mea-
                                                            (i)
surements (xℓ , yℓ ) and we have introduced dual variables µj for i = 1, . . . , r, j = 1, . . . , s and
 +(i)    −(i)
ηℓℓ′ , ηℓℓ′ for i = 1, . . . , r, ℓ = 1, . . . , k and ℓ′ = 1, . . . , n.

    We note that we can also exactly characterize one-step safety sets in the presence of both dis-
turbances and noisy measurements.

6.2. Numerical Example
We present a numerical example with n = 4. We take

                        S = {x ∈ R4 | |xi | ≤ 1, i = 1, . . . , 4},
                    U0,A = {A ∈ R4×4 | −4 ≤ Aij ≤ 8, i = 1, . . . , 4, j = 1, . . . , 4},
                    U0,g = {g : R4 → R4 | ∥g(x)∥∞ ≤ γ                ∀x ∈ S}.

In Figure 8(a), we plot S01 (the one-step safety region without any measurements) projected to the
first two dimensions of x for γ ∈ {0, 0.4, 0.8}. As expected, larger values of γ result in smaller
one-step safety regions.
     For our next experiment, we choose the matrix A⋆ in (27) to be the same matrix used in the
example in Section 3.5. We let γ = 0.1, and
                                                                           T
                     γ
                                        q
                          2                4     4          2         2
            g⋆ (x) =     x2 − x3 x4 ,     x1 + x3 , x3 sin (x1 ), sin (x2 )    ∈ U0,g .
                     2
    Since the true system is not linear, we cannot hope to learn the dynamics in n steps as we did
in the linear case. We instead pick 30 one-step safe points x1 , . . . , x30 (by sequentially solving the
second-order cone program from Theorem 26) and observe yk = f⋆ (xk ) for each k = 1, . . . , 30.
In order to encourage exploration of the state space, we optimize in random directions in every
iteration (instead of optimizing the same cost function throughout the process). In Figure 8(b), we
plot Sk1 (the one-step safety region after k measurements) projected to the first two dimensions of x
for k = 0, . . . , 30. Note that Sk1 is the projection of the feasible set of (35) to x-space. We also plot
the projection of Sγ1 (A⋆ ), which we define as the set of one-step safe points if we knew A⋆ , but not
g⋆
                          Sγ1 (A⋆ ) := {x ∈ S | A⋆ x + g(x) ∈ S ∀g ∈ U0,g }.
Note that this set is an outer approximation to Sk1 . Here we see that Sk1 comes close to Sγ1 (A⋆ )
already in thirty iterations.
    Finally, we undertake the task of learning the unknown nonlinear dynamics. We only use in-
formation from our first 8 data points in order to make the fitting task more challenging. We fit a
function of the form
                                        fˆ(x) = Âx + ĝ(x),
where Â ∈ R4×4 and each entry of ĝ : R4 → R4 is a homogeneous quadratic function of x. Our
regression is done by minimizing the least-squares loss function
                                                    8
                                                    X
                                          L(fˆ) =         ∥fˆ(xk ) − yk ∥2 .
                                                    k=1


                                                          41
                                            S AFE L EARNING




                                                               0.5

      0.1


    0.05


        0                                                         0


   -0.05


     -0.1


   -0.15                                                       -0.5
               -0.1            0           0.1                    -0.5               0            0.5

            (a) Dependence of S01 on γ.                                  (b) Sk1 grows with k.


Figure 8: One-step safe learning of a nonlinear system associated with the example in Section 6.2.


We train two models. The first model, fˆls , minimizes the least-squares loss with no constraints.
The second model, fˆSOS , minimizes the least-squares loss subject to the constraints that Â ∈ U0,A ,
∥Âxk − yk ∥∞ ≤ γ for k = 1, . . . , 8, and ĝ ∈ U0,g . The constraint that ĝ ∈ U0,g is imposed via
sum of squares constraints (see, e.g., Parrilo, 2000; Ahmadi and El Khadir, 2023 for details). More
specifically, we require that for j = 1, . . . , 4,
                                                  r
                      γ ± ĝj (x) = σ0j,± (x) +         σij,± (x)(bi − hT
                                                  X
                                                                        i x)   ∀x ∈ R4 .
                                                  i=1

Here, ĝj (x) is the j-th entry of the vector ĝ(x), and the functions σij,± , for i = 0, . . . , r and
j = 1, . . . , 4, are sum of squares quadratic functions of x. These constraints can be imposed by
semidefinite programming.
    We sample test points z1 , . . . , z1000 uniformly at random in S in order to estimate the general-
ization error. The root-mean-square error (RMSE) is computed as
                                             v
                                             u 1 1000
                                             u
                                                     X
                                        ˆ
                             RMSE(f ) = t                 ∥fˆ(zi ) − f⋆ (zi )∥2 .
                                                1000
                                                         j=1


The RMSE(fˆSOS ) of the constrained model is 0.0851 and the RMSE(fˆls ) of the unconstrained
model is 0.2567. We see that imposing prior knowledge with sum of squares constraints results in a
significantly better fit.




                                                        42
                                            S AFE L EARNING




7. Infinite-Step Safe Learning of Nonlinear Systems
In our final technical section, we consider the problem of safely learning a dynamical system of the
same form as in Section 6, i.e.,
                                        xt+1 = A⋆ xt + g⋆ (xt )                                (36)
involving some matrix A⋆ ∈ Rn×n and some possibly nonlinear map g⋆ : Rn → Rn . We take
the safety region S ⊂ Rn to be the same as (5). We take our initial knowledge about A⋆ , g⋆ to be
membership in the following sets:
                             n                                           o
                     U0,A := A ∈ Rn×n | Tr(VjT A) ≤ vj j = 1, . . . , s ,
                        U0,g := {g : Rn → Rn | ∥g(x)∥ ≤ γ∥x∥           ∀x ∈ S},

where γ is a given nonnegative constant. In the definition of U0,g , it is convenient to use the ℓ2
norm because of some technical reasons that will become clear in the proofs of the statements in
this section. Again for simplicity, we assume that for some vector c ∈ Rn , initializing the system at
a point x ∈ S comes at the cost cT x.
    Just as in Section 5, the notion of safety in this section is that of infinite-step safety; i.e., we can
only initialize the system at points whose entire trajectory will remain in S under all dynamical sys-
tems consistent with the information at hand. By observing these trajectories, we can safely reduce
our uncertainty on A⋆ and fit a parametric model to g⋆ that respects the constraints in U0,g (in the
same way that we did in Section 6). Unlike the setting of infinite-step safe learning of linear systems
(Section 5), it might be useful to observe trajectories of length greater than n. Assuming there is
some limitation on memory, it is sensible to truncate each trajectory after some time. Suppose that
we have collected k trajectories and that the ℓth trajectory is of length nℓ . Let yt,ℓ ∈ Rn be the
tth observed vector in the ℓth trajectory with y0,ℓ being the trajectory’s initialization. With these
observations, we can reduce our uncertainty around A⋆ as follows:

           Uk,A = {A ∈ U0 | ∥Ayt−1,ℓ − yt,ℓ ∥ ≤ γ∥yt−1,ℓ ∥ t = 1, . . . , nℓ       ℓ = 1, . . . , k}.

Since U0,g contains the zero map (i.e., one possibility for the unknown dynamics is xt+1 = Axt for
some matrix A ∈ U0,A ), the problem considered in this section is at least as hard as that of Section 5.
Therefore, we make the same assumptions as Section 5 to have a full-dimensional infinite-step
safety set. In particular, we assume that the origin is in the interior of S, which means that S
can be described as (21), and that all matrices in U0,A are stable. Having collected k infinite-step
safe trajectories, the optimization problem we are interested in solving to find the next cheapest
infinite-step safe initialization point is:

     min cT x
       x
       s.t. x ∈ S                                                                                       (37)
              f t (x) ∈ S   ∀ f ∈ {x 7→ Ax + g(x) | A ∈ Uk,A , g ∈ U0,g }        t = 1, 2, . . . .

In keeping with the naming conventions of this work, we refer to the feasible region of (37) as Sk∞ ,
and if U0,A is a single matrix A, we call it Sγ∞ (A). We can now present the main theorem of this
section, which enables us to find infinite-step safe initialization points (i.e., the version of (2) for
this specific case).

                                                    43
                                                       S AFE L EARNING




Theorem 29 Let the polyhedron S ⊆ Rn be as in (21), and the polyhedron U0,A ⊆ Rn×n be as
in (4). For ℓ = 1, . . . , k and t = 0, . . . , nℓ , let yt,ℓ be the tth vector in the ℓth observed trajectory.
For an even integer d, let S̃k,d∞ be the projection to x-space of the feasible region of the following

optimization problem:


                min                       cT x                                                                (38)
x,Q,Mj ,Mtℓ ,M̂j ,M̂tℓ ,σij ,σitℓ ,ε,λ
                                                                  s
             Q(A) − AQ(A)AT −AQ(A)
                                       2    
                                         γ I 0                    X
s.t.                                − λ          = εI + M 0 (A) +   Mj (A)(vj − Tr(VjT A))
                −Q(A)AT     −Q(A)         0 −I
                                                                                            j=1
                                                                                                             (38a)
                          nℓ
                        k X
                        X
                    +              Mtℓ (A)(γ 2 ∥yt−1,ℓ ∥2 − ∥Ayt−1,ℓ − yt,ℓ ∥2 ) ∀A ∈ Rn×n
                        ℓ=1 t=1
                                         s
                                         X
1 − hT
     i Q(A)hi = σi0 (A) +                      σij (A)(vj − Tr(VjT A))                                       (38b)
                                         j=1
                          nℓ
                        k X
                        X
                    +              σitℓ (A)(γ 2 ∥yt−1,ℓ ∥2 − ∥Ayt−1,ℓ − yt,ℓ ∥2 )   i = 1, . . . , r   ∀A ∈ Rn×n
                        ℓ=1 t=1
                                   s
    Q(A) x              X
           = M̂ 0 (A) +   M̂j (A)(vj − Tr(VjT A))                                                            (38c)
     xT  1
                                   j=1
                          nℓ
                        k X
                        X
                    +              M̂tℓ (A)(γ 2 ∥yt−1,ℓ ∥2 − ∥Ayt−1,ℓ − yt,ℓ ∥2 ) ∀A ∈ Rn×n
                        ℓ=1 t=1
ε>0                                                                                                          (38d)
λ ≥ 0,                                                                                                       (38e)

       • where Q(A) is an n × n SOS matrix with degree at most d,

       • Mj (A) are 2n × 2n SOS matrices with degree at most d for j = 0, . . . , s,

       • Mtℓ (A) are 2n × 2n SOS matrices with degree at most d for ℓ = 1, . . . , k, t = 1, . . . , nℓ ,

       • M̂j (A) are (n + 1) × (n + 1) SOS matrices with degree at most d for j = 0, . . . , s,

       • M̂tℓ (A) are (n + 1) × (n + 1) SOS matrices with degree at most d for ℓ = 1, . . . , k, t =
         1, . . . , nℓ ,

       • σij (A) are SOS polynomials with degree at most d for i = 1, . . . , r, j = 0, . . . , s,

       • and σitℓ (A) are SOS polynomials with degree at most d for i = 1, . . . , r, ℓ = 1, . . . , k, t =
         1, . . . , nℓ .
       Then,
    (i) The program (38) can be reformulated as a semidefinite program of size polynomial in the
        size of the input (S, U0 , {yt,ℓ }, c, γ).

                                                              44
                                            S AFE L EARNING




                 ∞ ⊆ S ∞ (i.e, any vector x feasible to this semidefinite program is infinite-step
  (ii) We have S̃k,d  k
       safe).

 (iii) Furthermore, if U0,A is compact and contains only stable matrices, and if γ is smaller than
                                                                                        ∞ is full-
       some positive threshold depending on U0,A , then, for large enough d, the set S̃k,d
       dimensional.

In words, Theorem 29 allows us to optimize the initialization cost over semidefinite representable
subsets of the set of points which are infinite-step safe under all nonlinear dynamics consistent
with information at hand. While the theorem guarantees full-dimensionality of these subsets for
sufficiently small γ and large d, in our experience, even when γ is relatively large, small values of d
suffice for safe learning; see Section 6.2.

Remark 30 We note that problem (38) can be modified so that infinite-step safety is achieved in
the presence of bounded measurement noise. That is, suppose that instead of directly observing
yt,ℓ = A⋆ yt−1,ℓ + g⋆ (yt−1,ℓ ), we observe

                                            ŷt,ℓ = yt,ℓ + zt,ℓ ,

where zt,ℓ represents the noise in the measurement, A⋆ ∈ U0,A , and g⋆ ∈ U0,g . We can still give
an SOS programming-based inner approximation of the infinite-step safety set in the case when
we have ∥zt,ℓ ∥ ≤ Zt,ℓ , where ∥ · ∥ is, e.g., any polynomial norm (see Ahmadi et al. (2019) for a
definition) or any norm whose unit ball is a polytope, and Zt,ℓ is a given scalar. To see this, observe
that the vectors ŷt,ℓ will satisfy

                           ŷt,ℓ = A⋆ (ŷt−1,ℓ − zt−1,ℓ ) + g⋆ (yt−1,ℓ ) + zt,ℓ .

Now for example, if ∥ · ∥ is the Euclidean norm, and if we have maxA∈Uk,A ∥A∥ ≤ Mk for some
constant Mk (computed, e.g., by a semidefinite relaxation), we can derive the following inequality:

                   ∥ŷt,ℓ − A⋆ ŷt−1,ℓ ∥ ≤ ∥A⋆ ∥∥zt−1,ℓ ∥ + ∥g⋆ (yt−1,ℓ )∥ + ∥zt,ℓ ∥
                                       ≤ Mk Zt−1,ℓ + γ∥yt−1,ℓ ∥ + Zt,ℓ
                                       ≤ Mk Zt−1,ℓ + γ(∥ŷt−1,ℓ ∥ + Zt−1,ℓ ) + Zt,ℓ .

   We can then adapt the methodology of Theorem 29 by multiplying the SOS matrices and poly-
nomials in semidefinite program (38) by the polynomials
           n                                                                            o
             A 7→ (Mk Zt−1,ℓ + γ(∥ŷt−1,ℓ ∥ + Zt−1,ℓ ) + Zt,ℓ )2 − ∥ŷt,ℓ − Aŷt−1,ℓ ∥2
                                                                                         t,ℓ

instead of {A 7→ γ 2 ∥yt−1,ℓ ∥2 − ∥Ayt−1,ℓ − yt,ℓ ∥2 }t,ℓ . For this modified SOS program, all claims of
Theorem 29 hold.




                                                     45
                                            S AFE L EARNING




   Before we present a proof of Theorem 29, we introduce a “nonlinear version” of (23), which
applies to the case of a fixed matrix A:

                           min           cT x
                    x∈Rn ,Q∈Sn×n ,λ∈R

                                   s.t. Q ≻ 0
                                         Q − AQAT −AQ
                                                          2    
                                                            γ I 0
                                                        ⪰λ
                                           −QAT   −Q         0 −I
                                                                                                  (39)
                                         hT
                                          i Qhi ≤ 1 i = 1, . . . , r
                                               
                                           Q x
                                                  ⪰0
                                          xT 1
                                         λ ≥ 0.

We now prove a nonlinear version of Lemma 20. Recall the definition of the set Sγ∞ (A) from the
paragraph after (37).

Lemma 31 Let S̃γ∞ (A) be the projection to x-space of the feasible region of (39). Then, we have
S̃γ∞ (A) ⊆ Sγ∞ (A).

Proof Let x, Q, and λ be feasible to (39). As in the proof of Lemma 20, the constraints hT  i Qhi ≤ 1,
i = 1, . . . , r, imply
                                      {x | xT Q−1 x ≤ 1} ⊆ S,
                           
                        Q x
and the constraint T          ⪰ 0 implies xT Q−1 x ≤ 1. Thus x is in the safety region S. To show
                        x 1
that the trajectory remains safe for all time, it suffices to show that the set {x | xT Q−1 x ≤ 1} is
invariant under all valid dynamics, i.e., for any vector x̄ in this set and any vector g(x̄) satisfying
∥g(x̄)∥ ≤ γ∥x̄∥, the vector Ax̄ + g(x̄) is also in the set.
    Let B ∈ Rn×n be an arbitrary matrix and let ∥B∥ denote its spectral norm. We first claim that
if ∥B∥ ≤ γ, then (A + B)T Q−1 (A + B) ⪯ Q−1 . Fix an arbitrary vector x̂ and let ŷ = B T x̂. By
the bound on the spectral norm of B, we have ∥ŷ∥ ≤ γ∥x̂∥. By the second linear matrix inequality
in (39), we have
                    T                      T  2
                         Q − AQAT −AQ x̂
                                                       
                    x̂                        x̂   γ I 0   x̂
                               T          ≥λ                  .
                    ŷ     −QA    −Q   ŷ     ŷ    0 −I ŷ

Rearranging, we have

                 x̂T Qx̂ − (x̂T AQAT x̂ + 2x̂T AQŷ + ŷ T Qŷ) ≥ λ(γ 2 x̂T x̂ − ŷ T ŷ).

Since λ ≥ 0 and ∥ŷ∥ ≤ γ∥x̂∥, we have x̂T Qx̂ ≥ x̂T AQAT x̂ + 2x̂T AQŷ + ŷ T Qŷ, which implies

                                 x̂T (A + B)Q(A + B)T x̂ ≤ x̂T Qx̂.

This is equivalent to the claimed linear matrix inequality by two applications of the Schur comple-
ment lemma.


                                                    46
                                              S AFE L EARNING




   Now we show invariance of the set {x | xT Q−1 x ≤ 1} under all valid dynamics. Let x̄ be
                                                            T
any vector such that x̄T Q−1 x̄ ≤ 1, and let Bx̄ := g(x̄)x̄
                                                     ∥x̄∥2
                                                              . From the definition of U0,g , we have
∥Bx̄ ∥ ≤ γ. By the claim we established above, we have x̄T (A + Bx̄ )T Q−1 (A + Bx̄ )x̄ ≤ x̄T Q−1 x̄.
Since (A + Bx̄ )x̄ = Ax̄ + g(x̄), it follows that
                                       T
                            Ax̄ + g(x̄) Q−1 Ax̄ + g(x̄) ≤ x̄T Q−1 x̄ ≤ 1.
                                                       


Thus, Ax̄ + g(x̄) is in the set {x | xT Q−1 x ≤ 1} as desired.

We can now present the proof of the main result of this section.
Proof [Proof of Theorem 29]
    (i) We make a similar argument as in the proof of (i) in Theorem 18. Recall that for any fixed
degree d, the SOS constraints can be reformulated as semidefinite programming constraints of size
polynomial in n. The “∀A” constraints can be imposed by coefficient matching via a number of
linear equations bounded by a polynomial function of the sizeof the input (S, U0,A , {yt,ℓ }, c, γ).
                                                                            ε 1
The constraint that ε > 0 can be rewritten as the constraint                        ⪰ 0 for a new variable δ.
                                                                            1 δ
Therefore, for any fixed degree d, (22) is a semidefinite program of size polynomial in the size of
the input (S, U0,A , {yt,ℓ }, c, γ).
    (ii) Let (x, Q, Mj , Mtℓ , M̂j , M̂tℓ , σij , σitℓ , ε, λ) be feasible to (38). Then, it is straightforward
to check that for every A ∈ Uk,A , the tuple (x, Q(A), λ) satisfies the following constraints:

                          Q(A) ≻ 0
                            Q(A) − AQ(A)AT −AQ(A)
                                                     2    
                                                       γ I 0
                                                   ⪰λ
                               −Q(A)AT     −Q(A)        0 −I
                                                                                                          (40)
                          hT
                           i Q(A)hi ≤ 1 i = 1, . . . , r
                                   
                            Q(A) x
                                      ⪰ 0,
                             xT   1

and therefore, by Lemma 31, we have x ∈ S̃γ∞ (A) ⊆ Sγ∞ (A). Hence,
                                               \
                                        x∈            Sγ∞ (A) = Sk∞ ,
                                             A∈Uk,A

                ∞ ⊆ S∞.
implying that S̃k,d    k
    (iii) Suppose that U0,A is compact and contains only stable matrices. By Lemma 24 and the
arguments in the beginning of the proof of (iii) in Theorem 18, we can find an SOS matrix Q̂(A)
satisfying

                                    Q̂(A) ≻ 0     ∀A ∈ U0,A
                                    Q̂(A) ≻ AQ̂(A)AT         ∀A ∈ U0,A .

In particular, there must be a positive constant δ such that Q̂(A)−AQ̂(A)AT ⪰ δI for all A ∈ U0,A .
Let λ̂ := 1 + maxA∈U0,A ∥Q̂(A)AT (Q̂(A) − AQ̂(A)AT − 2δ I)−1 AQ̂(A) + Q̂(A)∥, and take γ to


                                                      47
                                               S AFE L EARNING



                               q
                                  δ
be a positive scalar less than 2λ   . By the Schur complement lemma and the fact that 2δ > λ̂γ 2 , it
follows that for every A ∈ U0,A ,
                                               δ
              Q̂(A) − AQ̂(A)AT −AQ̂(A)
                                                                        2       
                                                    2 I     0             γ I 0
                                                ⪰                   ≻ λ̂             .
                   −Q̂(A)AT           −Q̂(A)         0 −(λ̂ − 1)I          0 −I

Since Uk,A is compact, there exists a scalar α > 0 satisfying maxi∈{1,...,r},A∈Uk,A hT
                                                                                     i Q̂(A)hi < α.
Let us define Q := Q̂/α and λ := λ̂/α. Since Q(A) ≻ 0 for all A ∈ Uk,A , we can find a scalar
                  Q(A) − βI 0
β > 0 such that                1 ≻ 0 for all A ∈ Uk,A . Summarizing, so far we have:
                      0        2

      Q(A) − AQ(A)AT −AQ(A)
                                             2       
                                               γ I 0
                                         −  λ             ≻ 0 ∀A ∈ Uk,A
           −Q(A)AT           −Q(A)              0 −I
                                              1 − hT
                                                   i Q(A)hi > 0 ∀A ∈ Uk,A i = 1, . . . , r              (41)
                                                          
                                             Q(A) − βI 0
                                                         1 ≻ 0 ∀A ∈ Uk,A .
                                                 0       2

Since U0,A is a bounded polyhedron, the set of inequalities that define it (i.e., {A → vj −Tr(VjT A)}sj=1 )
satisfy the Archimedian property. Consider the following set of polynomials:
                                                   nℓ
                                                 k [
                                                 [
        G := {A → vj − Tr(VjT A)}sj=1 ∪                 {A → γ 2 ∥yt−1,ℓ ∥2 − ∥Ayt−1,ℓ − yt,ℓ ∥2 }.
                                                ℓ=1 t=1

As a superset of a set satisfying the Archimedian property, this set also satisfies the Archimedian
property. By applying Theorem 22 and Theorem 23 to (41), we can conclude the existence of SOS
matrices, Mj , Mtℓ , M̂j , M̂tℓ , and SOS polynomials, σij , σitℓ of some degree d, and a positive scalar
ε satisfying (38a), (38b), (38d), and the following:
                                         s
        Q(A) − βI 0                        X
                       1    = M̂   0 (A) +   M̂j (A)(vj − Tr(VjT A))
             0         2                  j=1
                                nℓ
                              k X
                              X
                          +             M̂tℓ (A)(γ 2 ∥yt−1,ℓ ∥2 − ∥Ayt−1,ℓ − yt,ℓ ∥2 ) ∀A ∈ Rn×n .
                              ℓ=1 t=1
                                                                 
                                          q
                                               1        βI x
Note that for any x satisfying ∥x∥ ≤          2β , we have that ⪰ 0. Therefore,
                                                        xT 12
                                                          
                                                     βI x
                                     A 7→ M̂0 (A) + T 1
                                                    x    2
                                                                                                 q
                                                                                                       1
is still an SOS matrix of the same degree as M̂0 (A). Hence, for any x satisfying ∥x∥ ≤               2β , we
have that the tuple
                                                                                 
                                                βI x
                    x, Q, Mj , Mtℓ , M̂0 (A) + T 1 , M̂j , M̂tℓ , σij , σitℓ , ε, λ
                                               x    2

is feasible to (38).


                                                      48
                                           S AFE L EARNING




                                2

                              1.5

                                1

                              0.5

                                0

                             -0.5

                               -1

                                    -1           0           1            2


                                                                               ∞ for four different
Figure 9: The numerical example in Section 7.1: the safety set S, the sets S̃0,4
                                     ∞                                       ∞
          values of γ, and the set S̄0 , which is an outer approximation to S0 for any value of γ.



7.1. Numerical Example
We present a numerical example with n = 2. Here we take S and U0,A to be the same as S and U0
in Section 5.5.1. We solve the semidefinite program in (38) with degree d = 4 (the program with
d = 2 is infeasible). In Figure 7.1, we plot the safety region S, and our semidefinite programming
based inner approximations S̃0,4∞ of the infinite-step safe set S ∞ for γ = 0, 0.02, 0.04, 0.06. We also
                                                                  0
             ∞
plot a set S̄0 , which is the same outer approximation of S0∞ as in Section 5.5.1. Note that S̄0∞ is an
outer approximation of S0∞ for any value of γ.
    For γ = 0.06, our semidefinite program is infeasible and therefore we can only certify that
the origin is infinite-step safe. This is intended behavior since for γ = 0.06, the     true infinite-
                                                                              0.5 0.45
step safe set is just the origin. To see why, observe that if A⋆ =                         ∈ U0,A , and
                                                                             0.45 0.5
                                                                          
                                                              0.555 0.45
g⋆ (x) = 0.055 ∗ x ∈ U0,g , then we have f⋆ (x) =                            x which is unstable since
                                                              0.45 0.555
                  
     0.555 0.45
ρ                        > 1. This means that the true infinite-step safe set is not full-dimensional
      0.45 0.555
(see Preposition 16). By slightly perturbing g⋆ within U0,g , we can obtain another valid unstable
linear map fˆ whose lower-dimensional stable subspace is different than that of f⋆ . Therefore, when
γ = 0.06, the true infinite-step safe set is indeed just the origin.
    For γ = 0.02 or 0.04 for example, and for any nonlinear system of the type (36), with A⋆ ∈ U0,A
and g⋆ ∈ U0,g , we can choose initialization points within our full-dimensional sets S̃0,4 ∞ and safely

observe their trajectories. Having safely collected trajectory data, following the same exact proce-
dure as in Section 6.2, we can narrow the uncertainty on the linear part of the dynamics and use



                                                     49
                                                 S AFE L EARNING




semidefinite programming to fit a polynomial map to the nonlinear part of the dynamics in such a
way that the information in U0,g is respected and the error on the observations is minimized.

8. Safe Learning with Specialized Side Information
In previous sections, the initial information we assumed on the matrix A⋆ ∈ Rn×n governing the
linear part of an unknown dynamical system was in terms of membership to an initial uncertainty
set U0 ⊂ Rn×n which took the form of a polyhedron or an ellipsoid. Such uncertainty sets already
capture natural side information such as being close to a nominal matrix in 1, 2, ∞ norm, having a
banded structure, or being sparse with a known support. In this section, we give three examples of
more specialized side information for which we can still exactly characterize the T -step safe set of a
linear system for T = 1 (or higher in special cases) as the feasible set of a tractable conic program.
Extensions of this research direction to other types of side information, different time horizons, and
nonlinear systems is left for future research.
     Throughout this section, we work with a polyhedral safety region S ⊂ Rn given in the form of
(5), and for simplicity, a linear objective function cT x representing initialization cost. Our goal is to
provide a tractable reformulation of the following optimization problem

                                          min      cT x
                                          x∈Rn
                                            s.t. x ∈ S                                                           (42)
                                                   Ax ∈ S       ∀A ∈ U0 ,

for three different classes of sets U0 .

8.1. Sparse Matrices with Unknown Support
Suppose that we know that the matrix A⋆ governing the linear dynamics in (3) has bounded entries
of which only a limited number are nonzero. We can then represent our initial uncertainty set as

                               U0 = {A ∈ Rn×n | ∥A∥0 ≤ k, ∥A∥∞ ≤ M },                                            (43)

where k ∈ N and M ≥ 0 are given constants and ∥A∥0 (resp. ∥A∥∞ ) denotes the number of
nonzeros (resp. the largest entry in absolute value) of the matrix A.7 In the following theorem, we
establish that problem (42) has an exact linear programming reformulation. We introduce auxiliary
variables η +(i) , η −(i) , β (i) ∈ Rn×n , and α(i) ∈ R for i = 1, . . . , r.
 7. Note that merely assuming that ∥A∥0 ≤ k cannot lead to safe learning. Indeed, if the safety region S is compact, no
    nonzero point can be one-step safe with regards to this information even when k=1.




                                                          50
                                                         S AFE L EARNING




Theorem 32 The feasible set of problem (42) with U0 as in (43) is the projection to x-space of the
feasible set of the following linear program:
                             min                  cT x
                  x,η +(i) ,η −(i) ,β (i) ,α(i)

                                          s.t. hT
                                                i x ≤ bi            i = 1, . . . , r
                                                              (i)
                                                  M Tr(Jβ ) + M kα(i) ≤ bi                      i = 1, . . . , r
                                                                                                                   (44)
                                                  xhT
                                                    i =η
                                                         +(i)
                                                              − η −(i)             i = 1, . . . , r
                                                  η +(i) + η −(i) = β (i) + α(i) J              i = 1, . . . , r
                                                  η +(i) , η −(i) , β (i) ≥ 0, α(i) ≥ 0 i = 1, . . . , r,
where J ∈ Rn×n is the matrix of all ones. In particular, the optimal values of (42) and (44) are the
same and the optimal solutions of (42) are the optimal solutions of (44) projected to x-space.
Before we prove this theorem, we characterize the convex hull of the set U0 with the following
standard lemma. We recall our notation conv(Ω) to denote the convex hull of a set Ω ⊆ Rn .
Lemma 33 For all n, k ∈ N and all M ≥ 0, we have:
         conv({x ∈ Rn | ∥x∥0 ≤ k, ∥x∥∞ ≤ M }) = {x ∈ Rn | ∥x∥1 ≤ M k, ∥x∥∞ ≤ M }.
Proof [Proof of Theorem 32] We first write (42) as the bilevel program:
                                min cT x
                                  x
                                  s.t. hT
                                        i x ≤ bi           i = 1, . . . , r                                        (45)
                                                             hT
                                                                    
                                        maxA                  i Ax       ≤ bi          i = 1, . . . , r.
                                          s.t.              A ∈ U0
Observe that in the inner problems, the objective function A 7→ hT
                                                                 i Ax is a linear function of the
variable A. From this and Lemma 33, we have
                                                                             hT
                                                                                      
                     T
                                               T
                                                              maxA            i Ax
         maxA       hi Ax       maxA            hi Ax
                             =                              =  s.t.     ∥A∥1 ≤ M k  .
          s.t.     A ∈ U0        s.t.      A ∈ conv(U0 )
                                                                          ∥A∥∞ ≤ M
Introducing a new variable Ā ∈ Rn×n , we rewrite this latter problem as a linear program:
                                                                     hT
                                                                               
                                                 maxA,Ā              i Ax
                                 hT
                                          
                   maxA           i Ax          s.t.            −Ā ≤ A ≤ Ā 
                  s.t.       ∥A∥1 ≤ M k  =                                   .
                                                               Tr(J Ā) ≤ M k 
                              ∥A∥∞ ≤ M
                                                                   Ā ≤ M J
We proceed by taking the dual of the inner problems, treating the x variable as fixed. By introducing
dual variables η +(i) , η −(i) , β (i) ∈ Rn×n , and α(i) ∈ R for i = 1, . . . , r, and by invoking strong
duality of linear programming, we have
                                                                         M Tr(Jβ (i) ) + M kα(i)
                                                                                                             
 
   maxA,Ā              hT  Ax                       min
                          i                η +(i) ,η −(i) ,β (i) ,α(i)
  s.t.           − Ā  ≤   A   ≤   Ā                                                   +(i) − η −(i)
                                                                                                             
                                      =           s.t.                   xhT  i =η                        (46)
                                                                                                             
                 Tr(J Ā) ≤ M k                                      η +(i)  +η   −(i)       (i)
                                                                                            =β +α J     (i)
                     Ā ≤ M J                                          η +(i) , η −(i) , β (i) ≥ 0, α(i) ≥ 0

                                                                51
                                                 S AFE L EARNING




for i = 1, . . . , r. Thus by replacing the inner problems of (45) with the right-hand side of (46), the
min-max problem (45) becomes a min-min problem. This min-min problem can be combined into a
single minimization problem and be written as problem (44). Indeed, if x is feasible to (45), for that
fixed x and for each i, there exist values of η +(i) , η −(i) , β (i) , α(i) that attain the optimal value for
(46) and therefore the tuple (x, η +(i) , η −(i) , β (i) , α(i) ) will be feasible to (44). Conversely, if some
(x, η +(i) , η −(i) , β (i) , α(i) ) is feasible to (44), it follows that x is feasible to (45). This is because for
any fixed x and for each i, the optimal value of the left-hand side of (46) is bounded from above by
the objective value of the right-hand side evaluated at any feasible (x, η +(i) , η −(i) , β (i) , α(i) ).


8.2. Low-Rank Matrices
Suppose that we know that the matrix A⋆ governing the linear dynamics in (3) has bounded spectral
norm and is low rank. We can then write the initial uncertainty set as

                                U0 = {A ∈ Rn×n | rk(A) ≤ k, ∥A∥ ≤ M },                                           (47)

where k ∈ N and M ≥ 0 are given and rk(A) (resp. ∥A∥) denotes the rank (resp. spectral norm) of
the matrix A.8 In the following theorem, we establish that problem (42) has an exact semidefinite
                                                               (i) (i)           (i)
programming reformulation. We introduce auxiliary variables η1 , η3 ∈ Sn×n , η2 ∈ Rn×n and
α(i) ∈ R for i = 1, . . . , r.

Theorem 34 The feasible set of problem (42) with U0 as in (47) is the projection to x-space of the
feasible set of the following semidefinite program:

                       min            cT x
                   (i) (i) (i)
                x,η1 ,η2 ,η3 ,α(i)

                               s.t. hT
                                     i x ≤ bi       i = 1, . . . , r
                                             (i)      (i)
                                      M Tr(η1 ) + Tr(η3 ) + α(i) M k ≤ bi i = 1, . . . , r
                                      "
                                                          (i)
                                                                    #                                            (48)
                                            α(i) I    2η2 + xhT   i
                                         (i)T                         ⪰ 0 i = 1, . . . , r
                                       2η2 + hi xT         α(i) I
                                      "             #
                                           (i)  (i)
                                         η1    η2
                                          (i)T  (i) ⪰ 0 i = 1, . . . , r,
                                        η2     η3

where I denotes the n × n identity matrix. In particular, the optimal values of (42) and (48) are the
same and the optimal solutions of (42) are the optimal solutions of (48) projected to x-space.

Before we prove this theorem, we recall a result that characterizes the convex hull of U0 . We use
the notation ∥A∥∗ to denote the nuclear norm of the matrix A, i.e., the sum of its singular values.

Lemma 35 (Hiriart-Urruty and Le (2012)) For all n, k ∈ N and all M ≥ 0, we have:

      conv({A ∈ Rn×n | rk(A) ≤ k, ∥A∥ ≤ M }) = {A ∈ Rn×n | ∥A∥∗ ≤ M k, ∥A∥ ≤ M }.
 8. Note that merely assuming that A is low rank cannot lead to safe learning. Indeed, for any two vectors, x, y ∈ Rn ,
                                     yxT
    with x ̸= 0, the rank-one matrix ∥x∥2 takes x to y; thus, a rank-one matrix can take any nonzero point to an unsafe
    point in just one step.


                                                         52
                                                 S AFE L EARNING




Proof [Proof of Theorem 34] We first write (42) as the bilevel program:

                              min cT x
                                x
                               s.t. hT
                                     i x ≤ bi       i = 1, . . . , r                                              (49)
                                                      hT
                                                             
                                      maxA             i Ax       ≤ bi   i = 1, . . . , r.
                                       s.t.          A ∈ U0

Observe that in the inner problems, the objective function A 7→ hT
                                                                 i Ax is a linear function of the
variable A. From this and Lemma 35, we have

                                                                             hT
                                                                                      
                                                               maxA            i Ax
                    hT                            T Ax
                                                       
         maxA         i Ax      max   A         h i
                             =                              =  s.t.     ∥A∥∗ ≤ M k  .
          s.t.     A ∈ U0        s.t.      A ∈ conv(U0 )
                                                                           ∥A∥ ≤ M

Introducing new variables W1 , W2 ∈ Sn×n , we rewrite this latter problem as a semidefinite pro-
gram:

                                                                   hT
                                                                                    
                                         max                        i Ax
                                       A,W1 ,W2                        
                         T
                                                            W1 A
                                                                                     
            maxA         hi Ax
                                                                                    
                                       s.t.                     T        ⪰  0       
           s.t.      ∥A∥∗ ≤ M k  = 
                                                             A      W2              .
                                                                                     
                                                    1
                       ∥A∥ ≤ M
                                      
                                                   2 (Tr(W  1 ) + Tr(W 2 )) ≤ M k 
                                                                                     
                                                             MI A                   
                                                                  T       ⪰0
                                                               A      I

We proceed by taking the dual of the inner problems, treating the x variable as fixed. By introducing
                   (i) (i)               (i)
dual variables η1 , η3 ∈ Sn×n , η2 ∈ Rn×n , and α(i) ∈ R for i = 1, . . . , r, we claim that
                                                                                   (i)            (i)
                                                                                                                           
                             hT                                                                                  (i) M k

    max                       i Ax                           min           M  Tr(η   1   )  +  Tr(η 3   ) +    α
A,W1 ,W2                                           (i) (i) (i)
                                                       η1 ,η2 ,η3 ,α(i)                                                    
                       W  1    A                                     "
                                                                                   (i)              (i)           T
                                                                                                                     #     
 s.t.                     T W        ⪰  0          
                                                                                 α     I         2η 2    +   xh   i
                                                                                                                           
                        A                                  s.t.                                                      ⪰ 0
                                                                                                                           
                                2               =                         (i)T            T          (i) I
                                                                                                                           
             1
                (Tr(W     ) + Tr(W      )) ≤ M k                           2η 2     +   h i x         α                    
                       1          2
                                                
             2                                                                    "
                                                                                           (i)    (i)
                                                                                                      #                    
                        MI A                                                             η1      η2
                                                                                                                       
                                     ⪰0                                                   (i)T    (i)    ⪰    0            
                         AT I                                                          η2        η3
                                                                                                                    (50)
for i = 1, . . . , r. By taking A to be the zero matrix and W1 and W2 to be small enough positive
multiples of the identity matrix, we observe that the problem on the left hand side of (50) is strictly
                                     (i)                        (i)     (i)
feasible. Similarly, by taking η2 to be the zero matrix, η1 and η3 to be identity matrices, and α(i)
sufficiently large, we observe that the problem on the right hand side of (50) is strictly feasible. Thus,
the equality in (50) follows from strong duality of semidefinite programming (see, e.g., (Lovász,
2003, Theorem 6.3.4)). Thus, by replacing the inner problems of (49) with the right-hand side
of (50), the min-max problem (49) becomes a min-min problem. This min-min problem can be
combined into a single minimization problem and be written as problem (48). Indeed, if x is feasible
                                                                    (i) (i) (i)
to (49), for that fixed x and for each i, there exist values of η1 , η2 , η3 , α(i) that attain the optimal
                                                 (i) (i) (i)
value for (50) and therefore the tuple (x, η1 , η2 , η3 , α(i) ) will be feasible to (48). Conversely, if


                                                          53
                                                 S AFE L EARNING



           (i)   (i)   (i)
some (x, η1 , η2 , η3 , α(i) ) is feasible to (48), it follows that x is feasible to (49). This is because
for any fixed x and for each i, the optimal value of the left-hand side of (50) is bounded from above
                                                                                 (i) (i) (i)
by the objective value of the right-hand side evaluated at any feasible (x, η1 , η2 , η3 , α(i) ).


Remark 36 In the special case when M ≤ 1, the projection to x-space of the feasible set of the
semidefinite program in (48) is not only an exact characterization of the one-step safe set, but also
of the T -step safe set for any T (including T = ∞). This follows from the fact that

                                             A ∈ U0 ⇒ At ∈ U0      ∀t,

as the spectral norm is submultiplicative and rk(At ) ≤ rk(A).

8.3. Permutation Matrices
Suppose that we know that the matrix A⋆ governing the linear dynamics in (3) acts on a vector by
permuting its entries. In other words,

                              U0 = {A ∈ Rn×n | A is a permutation matrix},                           (51)

where we recall that a permutation matrix is a binary square matrix with each row and each column
containing exactly one nonzero entry. While there are n! matrices in U0 , the following theorem
establishes that problem (42) has an exact reformulation as a linear problem of polynomial size.
The proof of this theorem invokes the fact that conv(U0 ) is the set of n × n doubly stochastic
matrices (Birkhoff, 1946). We introduce auxiliary variables u(i) , w(i) ∈ Rn for i = 1, . . . , r.

Theorem 37 (follows from Theorem 3.8 of Ahmadi and Günlük (2024)) The feasible set of prob-
lem (42) with U0 as in (51) is the projection to x-space of the feasible set of the following linear
program:
                         min       cT x
                             x,u(i) ,w(i)

                                     s.t. 1T u(i) + 1T w(i) ≤ bi     i = 1, . . . , r                (52)

                                            u(i) 1T + 1w(i)T ≥ xhT
                                                                 i      i = 1, . . . , r,
where 1 denotes the n-dimensional vector of all ones. In particular, the optimal values of (42) and
(52) are the same and the optimal solutions of (42) are the optimal solutions of (52) projected to
x-space.

Remark 38 The projection to x-space of the feasible set (52) is not only an exact characterization
of the one-step safe set, but also for the T -step safe set for any T (including T = ∞). This follows
from the fact that
                                        A ∈ U0 ⇒ At ∈ U0 ∀t
since the permutation matrices form a group closed under matrix multiplication.

   We remark that more generally, whenever a tractable conic programming based description of
conv(U0 ) is available, one can invoke conic programming strong duality theory to get a tractable
characterization of the one-step safe set.

                                                       54
                                                   S AFE L EARNING




9. Controlled Safe Learning
In this section, we extend our mathematical framework for safe learning to a setting where in ad-
dition to choosing the initialization point to the dynamics, we can also choose a control input. We
present generalizations of our previous results to the case of linear control affine dynamics and time
horizon T = 1. Extensions to other settings is left for future work.
    Consider the linear control affine dynamical system

                                               xt+1 = A⋆ xt + B⋆ ut ,

defined by the matrices A⋆ ∈ Rn×n and B⋆ ∈ Rn×n̄ , where xt ∈ Rn (resp. ut ∈ Rn̄ ) is the state
(resp. control input) at time t. Suppose we have a safety region in x-space again called S ⊂ Rn and
defined as the polyhedron in (5). In addition, suppose we have a set of admissible controls C ⊆ Rn̄
defined as
                              C = {u ∈ Rn̄ | h̄Ti u ≤ b̄i i = 1, . . . , r̄}.

The matrices A⋆ and B⋆ are unknown, but respectively belong to initial uncertainty sets U0,A ⊂ Rn×n
and U0,B ⊂ Rn×n̄ . Let us again assume a polyhedral form for these sets:

                           U0,A = {A ∈ Rn×n | Tr(VjT A) ≤ vj                 j = 1, . . . , s}
                                               n×n̄
                           U0,B = {B ∈ R              | Tr(V̄jT B) ≤ v̄j     j = 1, . . . , s̄},

where V1 , . . . , Vs ∈ Rn×n , V̄1 , . . . , V̄s̄ ∈ Rn×n̄ , and v1 , . . . , vs , v̄1 , . . . , v̄s̄ ∈ R are given. Suppose
that we have collected k measurements from the true system in the form of tuples (xℓ , uℓ , yℓ ) such
that yℓ = A⋆ xℓ + B⋆ uℓ for ℓ = 1, . . . , k. Our updated uncertainty set Uk is then the set of pairs of
matrices which agree with our initial information and our k measurements; i.e.,

     Uk = (A, B) ∈ Rn×n × Rn×n̄ A ∈ U0,A , B ∈ U0,B , yℓ = Axℓ + Buℓ ℓ = 1, . . . , k .
            

We may also define Uk,A (resp. Uk,B ) to be the projection to A-space (resp. B-space) of Uk . With
this updated information, we can then define the one-step controlled safe set as

                      CSk1 = {x ∈ Rn | ∃u ∈ C s.t. ∀(A, B) ∈ Uk , Ax + Bu ∈ S}.

Now we can formalize what it means to safely learn in the controlled case, analogously to Defini-
tion 4.
Definition 39 (One-Step Controlled Safe Learning) We say that one-step controlled safe learn-
ing is possible if for some nonnegative integer m, we can sequentially choose vectors xk ∈ S and
uk ∈ C, for k = 1, . . . , m, and observe measurements yk = A⋆ xk + B⋆ uk such that:
   1. (Safety) for k = 1, . . . , m, we have Axk + Buk ∈ S                  ∀(A, B) ∈ Uk−1 ,

   2. (Learning) the sets of matrices Um,A and Um,B are singletons.
Note that by the safety requirement, each chosen initialization point xk must lie in CSk−1    1 . One

can define T -step controlled safe learning analogously. Just as in the autonomous case, we note
that controlled safe learning is possible for some T if and only if it is possible for T =1. Therefore,
the reader can note that our Corollary 41 below provides an efficient algorithm for checking the
possibility of controlled safe learning.

                                                            55
                                                      S AFE L EARNING




    We model initialization (resp. control) cost for simplicity with a linear function cT x (resp. c̄T u)
for some given vector c ∈ Rn (resp. c̄ ∈ Rn̄ ). The following problem finds the next cheapest pair
of initialization point and control which ensure one-step safety:
                                     min
                                     n
                                                    cT x + c̄T u
                                x∈R   ,u∈Rn̄

                                           s.t. x ∈ S                                                                 (53)
                                                    u∈C
                                                    Ax + Bu ∈ S                  ∀(A, B) ∈ Uk .
    Similarly as in Proposition 1, we can show that the feasible region of (53) is the projection to
(x, u)-space of the feasible region of the following linear program, where we have added auxiliary
           (i)                                                 (i)
variables µj ∈ R for i = 1, . . . , r, j = 1, . . . , s, and µ̄j ∈ R for i = 1, . . . , r̄, j = 1, . . . , s̄, and
 (i)
ηℓ ∈ Rn for i = 1, . . . , r, ℓ = 1, . . . , k.
Proposition 40 The feasible set of problem (53) is the projection to (x, u)-space of the feasible set
of the following linear program:
                    min        cT x + c̄T u
                  x,u,µ,µ̄,η

                        s.t. hT
                              i x ≤ bi            i = 1, . . . , r
                               h̄T
                                 i u ≤ b̄i        i = 1, . . . , r̄
                               k                     s                     s̄
                                           (i)                (i)                 (i)
                               X                     X                     X
                                     yℓT ηℓ +              µj vj +               µ̄j v̄j ≤ bi      i = 1, . . . , r
                               ℓ=1                   j=1                   j=1
                                        k                           s                                                 (54)
                                                       (i)T                (i)
                                        X                           X
                               xhT
                                 i =              xℓ η ℓ      +           µj VjT        i = 1, . . . , r
                                        ℓ=1                         j=1
                                        k                           s̄
                                                       (i)T                (i)
                                        X                           X
                               uhT
                                 i =              uℓ ηℓ       +           µ̄j V̄jT      i = 1, . . . , r
                                        ℓ=1                         j=1

                               µ(i) ≥ 0          i = 1, . . . , r
                               µ̄(i) ≥ 0         i = 1, . . . , r.
In particular, the optimal values of (53) and (54) are the same and the optimal solutions of (53) are
the optimal solutions of (54) projected to (x, u)-space.
    We omit the proof of this proposition as it is very similar to the proof of Proposition 1, with
its main ingredient being strong duality of linear programming. Our final two corollaries give the
controlled analogues of Theorem 8 and Corollary 9. The proofs are similar and hence omitted.
Corollary 41 Given a safety region S ⊂ Rn , a set of admissible controls C ⊆ Rn̄ , and uncertainty
sets U0,A ⊂ Rn×n and U0,B ⊂ Rn×n̄ , one-step controlled safe learning (see Definition 39) is
possible if and only if Algorithm 1 with the input tuple
                                                                              
                              A B         (n+n̄)×(n+n̄)
                  S × C,              ∈R                A ∈ U0,A , B ∈ U0,B , c, ε
                              0 I
(with an arbitrary choice of c ∈ Rn+n̄ and ε ∈ (0, 1]) returns a matrix.

                                                                    56
                                                S AFE L EARNING




Corollary 42 Given a safety region S ⊂ Rn , a set of admissable controls C ⊆ Rn̄ , and uncertainty
sets U0,A ⊂ Rn×n and U0,B ⊂ Rn×n̄ , if one-step controlled safe learning is possible, then it is
possible with at most n + n̄ measurements.

10. Future Research Directions
Besides extending the results of this paper to time horizons T other than 1, 2, ∞, the results of
Section 8 to other types of side information, and the results of Section 9 on controlled safe learning
beyond the one-step linear control affine case, we list some potential directions for future research
below:

    • We addressed the settings of noisy measurements for time horizon T = 1, ∞, and distur-
      bances in the dynamics for T = 1. Can we extend the treatment of noisy measurements to
      T = 2? Can we extend the treatment of disturbed dynamics to T = 2, ∞? It would also
      be interesting to consider distributional assumptions on noise or disturbances and devise a
      statistical analysis of the resulting safe learning problem.

    • Can one bound the suboptimality of our greedy online algorithm for minimizing the cost of
      safe learning against the idealized minimum cost of safe learning (cf. the paragraph above
      Eq. (2) and e.g., problem (11))? How would this bound depend on the input parameters S,
      U0 , T , and the true dynamics f⋆ ? Furthermore, since it is not clear if any possible algorithm
      can achieve the idealized minimum cost of safe learning for every f⋆ ∈ U0 , one could instead
      consider comparing to the best valid algorithm for safe learning that achieves the lowest
      worst-case (minimax) cost over all f⋆ ∈ U0 . How would the greedy algorithm compare to
      this minimax optimal algorithm?

    • In Sections 6 and 7, we studied systems which consist of a linear term plus a nonlinear term
      with bounded growth. While this description is fairly general, further specialization to prac-
      tical nonlinear systems, such as piecewise affine systems or systems parameterized with a
      known set of basis functions, could potentially allow one to safely recover the nonlinear part
      of the dynamics.9

    • In Sections 5 and 7, we approximated infinite-step safe sets by deriving semidefinite programs
      whose size depend on the maximum allowed degree of certain SOS polynomials and matri-
      ces. While we found small degrees to suffice empirically, it would be interesting to bound,
      for some class of problem instances, the degree one must choose in order for the proposed ap-
      proximation to the safe sets to be full-dimensional (assuming the true set is full-dimensional).

    • While in this paper we focused on discrete-time systems, our mathematical framework for
      safe learning also applies to continuous-time systems. Extending our results to the continuous-
      time setting would broaden the scope of our work and capture problems in control theory or
      physics that are modelled with ordinary or partial differential equations. Unlike the discrete-
      time setting, where every time horizon is a different case to study, in continuous-time, there
 9. Under suitable growth assumptions, one could apply the results in Section 6 (resp. Section 7) to derive inner ap-
    proximations of the one (resp. infinite) step safe set of e.g. a piecewise affine system. However, by specializing
    the description of the system, it may be possible to derive less conservative inner approximations (or even exact
    characterizations).


                                                         57
                                          S AFE L EARNING




      would essentially only be two cases: either the time horizon T is finite or infinite. Another dif-
      ference is that for many parametric classes of continuous-time dynamical systems such as lin-
      ear or polynomial systems, an infinitesimally small noiseless observation of a single generic
      trajectory suffices for learning the system. Therefore, one must assume a discretized access to
      the trajectory for the sequential learning problem to be nontrivial. Despite these distinctions,
      the concepts behind our paradigm carry over to continuous time; e.g., safety sets would still
      grow and uncertainty sets would still shrink as more information is gathered. We suspect that
      in the continuous-time case, the analysis would likely be much more focused on the behavior
      of the system on the boundary of the safety region, since unsafe trajectories must exit the
      safety region through its boundary. We suspect that the literature on maximal invariant sets
      and peak estimation for continuous-time dynamical systems would be relevant to extending
      our algorithms and theory to continuous time; see, e.g., Blanchini (1999); Nagumo (1942);
      Korda et al. (2014); Bell et al. (2010); Miller and Sznaier (2023) and references therein.

Acknowledgments
We would like to thank two anonymous referees whose comments have greatly improved our
manuscript. AAA and AC were partially supported by the MURI award of the AFOSR, the DARPA
Young Faculty Award, the CAREER Award of the NSF, the Google Faculty Award, the Innovation
Award of the School of Engineering and Applied Sciences at Princeton University, and the Sloan
Fellowship.

References
Amir Ali Ahmadi and Bachir El Khadir. Learning dynamical systems with side information. SIAM
 Review, 65(1):183–223, 2023.

Amir Ali Ahmadi and Oktay Günlük. Robust-to-dynamics optimization. To appear in Mathematics
 of Operations Research, 2024. Available at arXiv:1805.03682.

Amir Ali Ahmadi, Etienne de Klerk, and Georgina Hall. Polynomial norms. SIAM Journal on
 Optimization, 29(1):399–422, 2019.

Amir Ali Ahmadi, Abraar Chaudhry, Vikas Sindhwani, and Stephen Tu. Safely learning dynamical
 systems from short trajectories. In Proceedings of the 3rd Conference on Learning for Dynamics
 and Control, volume 144 of Proceedings of Machine Learning Research, pages 498–509. PMLR,
 2021.

Anayo K. Akametalu, Jaime F. Fisac, Jeremy H. Gillula, Shahab Kaynama, Melanie N. Zeilinger,
  and Claire J. Tomlin. Reachability-based safe learning with Gaussian processes. In 53rd IEEE
  Conference on Decision and Control, 2014.

Athanasios C. Antoulas. Approximation of Large-Scale Dynamical Systems. Society for Industrial
  and Applied Mathematics, 2005.

Zvi Artstein and Saša V. Raković. Feedback and invariance under uncertainty via set-iterates. Au-
  tomatica, 44(2):520–525, 2008.


                                                  58
                                         S AFE L EARNING




Karl Johan Åström and Peter Eykhoff. System identification—a survey. Automatica, 7(2):123–162,
  1971.

Ainesh Bakshi, Allen Liu, Ankur Moitra, and Morris Yau. A new approach to learning linear
  dynamical systems. In Proceedings of the 55th Annual ACM Symposium on Theory of Computing,
  page 335–348. Association for Computing Machinery, 2023.

Paul C. Bell, Jean-Charles Delvenne, Raphaël M. Jungers, and Vincent D. Blondel. The continuous
  skolem-pisot problem. Theoretical Computer Science, 411(40):3625–3634, 2010. ISSN 0304-
  3975.

Aharon Ben-Tal and Arkadi Nemirovski. Lectures on Modern Convex Optimization. Society for
  Industrial and Applied Mathematics, 2001.

Felix Berkenkamp and Angela P. Schoellig. Safe and robust learning control with Gaussian pro-
  cesses. In 2015 European Control Conference (ECC), 2015.

Felix Berkenkamp, Matteo Turchetta, Angela P. Schoellig, and Andreas Krause. Safe model-based
  reinforcement learning with stability guarantees. In Neural Information Processing Systems,
  2017.

Homanga Bharadhwaj, Aviral Kumar, Nicholas Rhinehart, Sergey Levine, Florian Shkurti, and Ani-
  mesh Garg. Conservative safety critics for exploration. In International Conference on Learning
  Representations, 2021.

G. Birkhoff. Tres Observaciones Sobre el Algebra Lineal. Univ. Nac. Tucuman, Ser. A, 5:147–154,
  1946.

Andrea Bisoffi, Claudio De Persis, and Pietro Tesi. Data-driven control via Petersen’s lemma.
  Automatica, 145:110537, 2022. ISSN 0005-1098.

Franco Blanchini. Set invariance in control. Automatica, 35(11):1747–1767, 1999.

Grigoriy Blekherman, Pablo A. Parrilo, and Rekha Thomas. Semidefinite Optimization and Convex
  Algebraic Geometry. SIAM Series on Optimization, 2013.

Stephen Boyd, Laurent El Ghaoui, Eric Feron, and Venkataramanan Balakrishnan. Linear Matrix
  Inequalities In System And Control Theory. SIAM, 1994.

Lukas Brunke, Melissa Greeff, Adam W. Hall, Zhaocong Yuan, Siqi Zhou, Jacopo Panerati, and
  Angela P. Schoellig. Safe learning in robotics: From learning-based control to safe reinforcement
  learning. Annual Reviews of Control, Robotics, and Autonomous Systems, 2021.

Steven L. Brunton and J. Nathan Kutz. Data-Driven Science and Engineering: Machine learning,
  Dynamical Systems, and Control. Cambridge University Press, 2019.

Shaoru Chen, Nikolai Matni, Manfred Morari, and Victor M. Preciado. System level synthesis-
  based robust model predictive control through convex inner approximation. arXiv:2111.05509,
  2021.



                                                59
                                         S AFE L EARNING




Shaoru Chen, Victor M. Preciado, Manfred Morari, and Nikolai Matni. Robust model predictive
  control with polytopic model uncertainty through system level synthesis. arXiv:2203.11375,
  2022.
Richard Cheng, Gábor Orosz, Richard M. Murray, and Joel W. Burdick. End-to-end safe reinforce-
  ment learning through barrier functions for safety-critical continuous control tasks. In Proceed-
  ings of the Thirty-Third AAAI Conference on Artificial Intelligence and Thirty-First Innovative
  Applications of Artificial Intelligence Conference and Ninth AAAI Symposium on Educational
  Advances in Artificial Intelligence, 2019.
Yohann De Castro, Fabrice Gamboa, Didier Henrion, Roxana Hess, and Jean-Bernard Lasserre.
  Approximate optimal designs for multivariate polynomial regression. Ann. Statist., 47(1):127–
  155, 2019.
Sarah Dean, Stephen Tu, Nikolai Matni, and Benjamin Recht. Safely learning to control the con-
  strained linear quadratic regulator. In Proceedings of the American Control Conference, 2019.
Sarah Dean, Horia Mania, Nikolai Matni, Benjamin Recht, and Stephen Tu. On the sample com-
  plexity of the linear quadratic regulator. Foundations of Computational Mathematics, 20(4):
  633–679, 2020. ISSN 1615-3383.
Daniel Ammon Dowler. Bounding the norm of matrix powers. In BYU ScholarsArchive, 2013.
Gerald B. Folland. Real Analysis: Modern Techniques and Their Applications. Wiley, 1999.
Meichen Guo, Claudio De Persis, and Pietro Tesi. Data-driven stabilization of nonlinear polynomial
 systems with noisy data. IEEE Transactions on Automatic Control, 67(8):4210–4217, 2022.
Thomas Gurriet, Mark Mote, Andrew Singletary, Eric Feron, and Aaron D. Ames. A scalable
  controlled set invariance framework with practical safety guarantees. In Proceedings of the 58th
  IEEE Conference on Decision and Control, 2019.
Jean-Baptiste Hiriart-Urruty and Hai Yen Le. Convexifying the set of matrices of bounded rank:
  applications to the quasiconvexification and convexification of the rank function. Optimization
  Letters, 6(5):841–849, 2012.
Karel J. Keesman. System Identification: An Introduction, volume 2. Springer, 2011.
Torsten Koller, Felix Berkenkamp, Matteo Turchetta, Joschka Boedecker, and Andreas Krause.
  Learning-based model predictive control for safe exploration and reinforcement learning.
  arXiv:1906.12189, 2019.
Milan Korda, Didier Henrion, and Colin N. Jones. Convex computation of the maximum controlled
 invariant set for polynomial control systems. SIAM Journal on Control and Optimization, 52(5):
 2944–2969, 2014.
Jean Bernard Lasserre. Moments, Positive Polynomials And Their Applications, volume 1. World
  Scientific, 2010.
Monique Laurent. Sums of Squares, Moment Matrices and Optimization Over Polynomials, pages
 157–270. Springer New York, New York, NY, 2009. ISBN 978-0-387-09686-5.

                                                60
                                         S AFE L EARNING




Miguel Sousa Lobo, Lieven Vandenberghe, Stephen Boyd, and Hervé Lebret. Applications of
 second-order cone programming. Linear Algebra and its Applications, 284(1):193–228, 1998.

L. Lovász. Semidefinite Programs and Combinatorial Optimization, pages 137–194. Springer,
  2003.

Tyler Lu, Martin Zinkevich, Craig Boutilier, Binz Roy, and Dale Schuurmans. Safe exploration for
  identifying linear systems via robust optimization. arXiv:1711.11165, 2017.

Wenhao Luo, Wen Sun, and Ashish Kapoor. No-regret safe learning for online nonlinear control
 with control barrier functions. In ICRA Workshop on Safe Robot Control with Learned Motion
 and Environment Models, 2021.

Alessandro Luppi, Andrea Bisoffi, Claudio De Persis, and Pietro Tesi. Data-driven design of safe
  control for polynomial systems. arXiv:2112.12664, 2021.

Tommaso Mannucci, Erik-Jan van Kampen, Cornelis de Visser, and Qiping Chu. Safe exploration
  algorithms for reinforcement learning controllers. IEEE Transactions on Neural Networks and
  Learning Systems, 29(4):1069–1081, 2018.

Jared Miller and Mario Sznaier. Bounding the Distance to Unsafe Sets with Convex Optimization.
   IEEE Transactions on Automatic Control, 2023.

Mitio Nagumo. Über die Lage der Integralkurven gewöhnlicher Differentialgleichungen. Proceed-
 ings of the Physico-Mathematical Society of Japan., 24:551–559, 1942.

Pablo Parrilo. Structured semidefinite programs and semialgebraic geometry methods in robustness
  and optimization. PhD thesis, California Institute of Technology, 2000.

Friedrich Pukelsheim. Optimal Design of Experiments. Society for Industrial and Applied Mathe-
  matics, 2006.

Mihai Putinar. Positive polynomials on compact semi-algebraic sets. Indiana University Mathe-
 matics Journal, 42(3):969–984, 1993.

Imre Pólik and Tamás Terlaky. A survey of the S-lemma. SIAM Review, 49(3):371–418, 2007.

Carsten W. Scherer and Camile W. J. Hol. Matrix sum-of-squares relaxations for robust semi-
  definite programs. Math. Program., 107(1–2):189–211, 2006.

Andrew Taylor, Andrew Singletary, Yisong Yue, and Aaron Ames. Learning for safety-critical
  control with control barrier functions. In Proceedings of the 2nd Conference on Learning for
  Dynamics and Control, 2020.

Kim Peter Wabersich and Melanie N. Zeilinger. A predictive safety filter for learning-based control
  of constrained nonlinear dynamical systems. Automatica, 129:109597, 2021.

Steffen W. R. Werner and Benjamin Peherstorfer. On the sample complexity of stabilizing linear
  dynamical systems from data. Foundations of Computational Mathematics, 2023. ISSN 1615-
  3383.


                                                61
                                              S AFE L EARNING




Stanislaw H. Żak. Systems and Control. Oxford Series in Electrical and Computer Engineering.
  Oxford University Press, 2003.

Jesse Zhang, Brian Cheung, Chelsea Finn, Sergey Levine, and Dinesh Jayaraman. Cautious adapta-
  tion for reinforcement learning in safety-critical settings. In Proceedings of the 37th International
  Conference on Machine Learning, Proceedings of Machine Learning Research, 2020.


Appendix A. (Omitted Proofs)
A.1. Proof of Lemma 7
Proof We form the desired basis {ei } iteratively and with an inductive argument. Let e1 be any
nonzero vector in P (existence of such a vector can be checked by the argument in the proof of
Lemma 6); if there is no such vector, we return the empty set. Let {e1 , . . . , ek } be a linearly
independent set in P . We will either find an additional linearly independent vector ek+1 ∈ P , or
show that the dimension of the span of P is k. Let x, x+ , and x− be variables in Rn , y + and y −
be variables in Rp , and λ+ and λ− be variables in R. Consider the following linear programming
feasibility problem:
                                     eTi x = 0 i = 1, . . . , k
                                           x = x+ − x−
                                           Ax+ + By + ≤ λ+ c
                                                                                                            (55)
                                           Ax− + By − ≤ λ− c
                                           λ+ ≥ 0
                                           λ− ≥ 0.
Let F ⊆ Rn be the projection to x-space of the feasible region of this problem. We claim that
F = {0} if and only if the dimension of span(P ) is k. Moreover, if there is solution to (55) with
                                                                                                            +
x ̸= 0, then there is also a solution (x, x± , y ± , λ± ) where λ+ , λ− ̸= 0. In this case, either λx+ or
x+
λ+
     can be taken as ek+1 .
     Suppose first that the dimension span(P ) is at least k +1; then there is a vector x̃ ∈ span(P ) that
is linearly independent from {e1 , . . . , ek }. By subtracting the projection of x̃ to span({e1 , . . . , ek }),
we will find a nonzero vector x ∈ span(P ) that is orthogonal to the vectors e1 , . . . , ek . We claim
this vector x is feasible to (55) for some choice of (x± , y ± , λ± ). Indeed, since x ∈ span(P ), then
                                                        r
                                                        X
                                                x=            λ j xj ,
                                                        j=1

for some vectors x1 , . . . , xr ∈ P and some nonzero scalars λ1 , . . . , λr . For each j, as xj ∈ P , there
exists a vector yj such that Axj + Byj ≤ c. Let J denote the set of indices j such that λj > 0. It is
easy to check that the assignment
                                               X          X          X
                           (x+ , y + , λ+ ) = (  λ j xj ,   λ j yj ,   λj ) ,
                                              j∈J             j∈J            j∈J
                                                 X                   X                   X                  (56)
                             −    −   −
                          (x , y , λ ) = (−             λ j xj , −          λ j yj , −          λj )
                                                 j ∈J
                                                   /                 j ∈J
                                                                       /                 j ∈J
                                                                                           /


                                                         62
                                              S AFE L EARNING




satisfies system (55). Hence, we have shown that if F = {0} then the dimension of span(P ) is k.
    To see the converse implication, suppose x ̸= 0, and that the tuple (x, x± , y ± , λ± ) is feasible to
system (55). Without loss of generality we assume λ± ≥ 1; if not, we replace the tuple with

                                       (x, x± + x̂, y ± + ŷ, λ± + 1),                                     (57)
                                                                                  +         +
where x̂ and ŷ are any vectors satisfying Ax̂ + B ŷ ≤ c. Then, since A λx+ + B λy + ≤ c, the vector
x+                                    −
λ+
     ∈ P . By the same argument, λx− ∈ P . It follows from the orthogonality constraint of (55) that
                              +       −
at least one of the vectors λx+ and λx− is linearly independent from {e1 , . . . , ek } and can be taken as
ek+1 , also proving that the dimension of span(P ) is at least k + 1.
     Note that the condition F = {0} can be checked by solving 2n linear programs (cf. the proof
of Lemma 6); if F ̸= {0}, then at least one of these 2n linear programs will return a tuple
(x, x± , y ± , λ± ) where x ̸= 0. We then transform this tuple via (57) to ensure that both λ+ , λ− ̸= 0
(we can take x̂ = e1 and ŷ to be any vector such that Ae1 + B ŷ ≤ c). Since we cannot have more
than n linearly independent vectors in span(P ), this procedure is repeated at most n times.


A.2. Proof of Lemma 12
Proof Let ei ∈ Rn be the i-th canonical basis vector. We construct 2n points {x±                     ±
                                                                                        1 , . . . , xn } using
the following iterative procedure.
    To construct x±                                                    + −1
                    1 , we first solve (13) with c = ±e1 and set x1 , x1 to be optimal solutions for
+e1 , −e1 , respectively. Now to construct x±             ±            ±
                                               k+1 given x1 , . . . , xk , we solve (13) with c = ±ek+1
                                                        eT x+ +eT x−
and with the additional constraints that eT     i x =
                                                         i i
                                                             2
                                                               i i
                                                                   for each i = 1, . . . , k; call the resulting
                 ±                                     ±
optimal points xk+1 . By Theorem 10, every xk , for k = 1, . . . , n is the solution to a semidefinite
program.
    We now prove that conv(x±                 ±                                     2
                                 1 , . . . , xn ) is a full-dimensional subset of S0 . For a vector x ∈ R
                                                                                                               n

and a positive scalar r, let B(x, r) represent the closed ℓ2 ball centered at x of radius r. Let x0 and
r0 be such that B(x0 , r0 ) ⊆ S02 ; such a point exists by the assumption that S02 is full-dimensional.
    We first show by induction that for each k = 0, . . . , n, there exist some xk and rk > 0 such
                                       eT x+ +eT x−
that B(xk , rk ) ⊆ S02 and eT
                            i xk =
                                    i i
                                        2
                                          i i
                                              for each i = 1, . . . , k. The base case k = 0 holds by
assumption. Assume for k < n we have such an xk and rk > 0, and let us show the corresponding
statement for k + 1. By the properties assumed of xk and rk , and by the definition of x±k+1 , we have
      +                             −                                                +            −
 T              T               T           T                                   T
ek+1 xk+1 ≤ ek+1 xk −rk and ek+1 xk+1 ≥ ek+1 xk +rk . Therefore, we have ek+1 xk+1 < eT      k+1 xk+1 .
                                             eT   x+    +eT    x−
Assume without loss of generality that k+1 k+1 2 k+1 k+1 ≤ eT
                                                            k+1 xk (if the inequality is reversed,
                 −
swap x+
      k+1 with x k+1 ). Let λ ∈ [0, 1) be such that
                              +           −
                        eT           T
                         k+1 xk+1 + ek+1 xk+1          +
                                              = λeT                  T
                                                  k+1 xk+1 + (1 − λ)ek+1 xk .
                                  2
Now we define xk+1 := λx+
                        k+1 + (1 − λ)xk and rk+1 = (1 − λ)rk . It is clear by this definition
                                                      eT x+ +eT x−
that xk+1 satisfies the constraints eT
                                     i xk+1 =
                                              i i
                                                  2
                                                    i i
                                                        for each i = 1, . . . , k since it is a convex
                              +
combination of the vectors xk+1 and xk which also satisfy those constraints. It is also clear by the
                                         +          −
                                   eT          T
                                    k+1 xk+1 +ek+1 xk+1
choice of λ that xk+1 satisfies              2          = eT                 2
                                                           k+1 xk+1 . Since S0 is a convex set and since


                                                        63
                                                S AFE L EARNING




we have x+         2                     2                   2                              +
            k+1 ∈ S0 and B(xk , rk ) ⊆ S0 , it follows that S0 contains the convex hull of xk+1 and
                                                                                           2
B(xk , rk ). Observe that B(xk+1 , rk+1 ) lies inside this convex hull and therefore also S0 , by the
following Minkowski arithmetic:

                   conv({x+                       +
                          k+1 }, B(xk , rk )) ⊇ λxk+1 + (1 − λ)B(xk , rk )
                                                  = λx+
                                                      k+1 + B((1 − λ)xk , (1 − λ)rk )
                                                  = B(λx+
                                                        k+1 + (1 − λ)xk , (1 − λ)rk )
                                                  = B(xk+1 , rk+1 ).

This establishes the statement for k + 1 and concludes the inductive argument.
   Thus, for each k = 0, . . . , n, there exist some xk and rk > 0 such that B(xk , rk ) ⊆ S02 and
         eT x+ +eT x−                                                 +    T −
eT
 i xk =
         i i
             2
               i i
                   for each i = 1, . . . , k. It now follows that eT
                                                                   k xk < ek xk for each k = 1, . . . , n.
                                                      +     −                  +     T −
Let T be the n × n matrix whose i-th column is xi − xi . Then Tii = eT      i xi − ei xi ̸= 0, and for
                                  +      T −            eT x+ +eT x−
k > i we have Tik = 0 since eT i xk = ei xk =
                                                   i i
                                                       2
                                                         i i
                                                             . Therefore T is invertible, because it is
a lower triangular with nonzero entries on its diagonal. Define
                                                  n
                                                  X 1               −
                                         xc :=               (x+
                                                               i + xi )
                                                        2n
                                                  i=1

and the set
                                                            1
                                   M := {xc + u | ∥T −1 u∥∞ ≤ }.
                                                           2n
Observe that M is full-dimensional. To conclude the proof, we show that M ⊆ conv({x±  n
                                                                                   i }i=1 ).
Indeed, for any xc + u ∈ M ,
                                   n                            n
                                   X 1               −
                                                                X
                                                                               −1
                        xc + u =              (x+
                                                i + xi ) + T           ei eT
                                                                           i T    u
                                         2n
                                   i=1                           i=1
                                n
                                X    1                    1
                              =   (    + eT
                                          i T
                                              −1
                                                 u)x+
                                                    i +(    − eT
                                                               i T
                                                                   −1
                                                                      u)x−
                                                                         i
                                    2n                   2n
                                   i=1
                              ∈ conv({x±  n
                                       i }i=1 ).

    Note that if S02 is not full-dimensional, the points {x±  n
                                                           i }i=1 supplied by this algorithm would
         T  +     T  −
satisfy ek xk = ek xk for at least one k = 1, . . . , n.


A.3. Proof of Proposition 14
Proof We proceed by induction. For the base case, let N1 be an arbitrary λn null-set. We clearly
have P(z1 ∈ N1 ) = P(δ1 ∈ N1 ) = 0 by the absolute continuity of the law of δ1 w.r.t. λn .
    For the inductive hypothesis, let k be an integer satisfying 1 ≤ k ≤ m − 1. Suppose that for
every λnk null-set Nk , we have P((z1 , . . . , zk ) ∈ Nk ) = 0. Now let Nk+1 be an arbitrary λn(k+1)
null-set. For any z̄1:k ∈ Rn×k , define the slice Nk+1 (z̄1:k ) = {z̄k+1 ∈ Rn | (z̄1:k , z̄k+1 ) ∈ Nk+1 }.
Next, define the set:
          0
         Nk+1 = {z̄1:k ∈ Rn×k | Nk+1 (z̄1:k ) is λn -measurable and λn (Nk+1 (z̄1:k )) = 0}.


                                                        64
                                                   S AFE L EARNING




By the Fubini-Tonelli theorem for complete measures (see e.g. Theorem 2.39 of Folland (1999)),
 0
Nk+1                                0 )c ) = 0. Abbreviating z
      is λnk -measurable and λnk ((Nk+1                       1:k = (z1 , . . . , zk ),

                                                                         0
 P((z1 , . . . , zk+1 ) ∈ Nk+1 ) = P({(z1:k , zk+1 ) ∈ Nk+1 } ∩ {z1:k ∈ Nk+1 })
                                                                                0
                                       + P({(z1:k , zk+1 ) ∈ Nk+1 } ∩ {z1:k ∈ (Nk+1 )c })
                                                                        0                   0
                                ≤ P({(z1:k , zk+1 ) ∈ Nk+1 } ∩ {z1:k ∈ Nk+1 }) + P(z1:k ∈ (Nk+1 )c )
                                (a)                                     0
                                = P({(z1:k , zk+1 ) ∈ Nk+1 } ∩ {z1:k ∈ Nk+1 })
                                                                     0
                                = P({zk+1 ∈ Nk+1 (z1:k )} ∩ {z1:k ∈ Nk+1 })
                                                                                  0
                                = P({δk+1 ∈ Nk+1 (z1:k ) − fk (z1:k )} ∩ {z1:k ∈ Nk+1 })
                                (b)
                                = 0.

Above, (a) follows by the inductive hypothesis and the fact that (Nk+1       0 )c is a λnk null-set. Fur-

thermore, (b) follows since when z1:k ∈ Nk+1 0 , then N                       n
                                                            k+1 (z1:k ) is a λ null-set, and hence by the
                           n                                       n
translation invariance of λ , Nk+1 (z1:k ) − fk (z1:k ) is also a λ null-set. Therefore, by the absolute
continuity of the law of δk+1 w.r.t. λn and the independence of δk+1 from δ1 , . . . , δk ,
                                               0
  P(δk+1 ∈ Nk+1 (z1:k ) − fk (z1:k ) | z1:k ∈ Nk+1 ) = Pδk+1 (δk+1 ∈ Nk+1 (z1:k ) − fk (z1:k )) = 0.




A.4. Proof of Proposition 15
Proof It is sufficient to show that for each integer k satisfying k ≥ n,
                      Ax = A⋆ x, A2 x = A2⋆ x, . . . , An x = An⋆ x ⇒ Ak x = Ak⋆ x.
                                                                  

Clearly this statement holds for k = n. We now assume the statement holds for some k ≥ n and
show that it also holds for k + 1. By the Cayley-Hamilton theorem, we have
                                           Ak⋆ ∈ span(I, . . . , An−1
                                                                  ⋆   )
and from this it follows that
                                        Ak⋆ x ∈ span(x, . . . , A⋆n−1 x).
                                                                              Pn−1
Therefore, there exist scalars λi , i = 0, . . . , n − 1, such that Ak⋆ x =            i
                                                                               i=0 λi A⋆ x. Now we have:
                                (a)
            Ak+1 x = AAk x = AAk⋆ x
                        n−1
                                    ! n−1               n−1               n−1
                        X              X            (b) X             (c) X
                   =A       λi Ai⋆ x =    λi AAi⋆ x =       λi Ai+1 x =       λi Ai+1
                                                                                  ⋆ x
                            i=0                     i=0              i=0             i=0
                             n−1
                                               !
                             X
                     = A⋆           λi Ai⋆ x       = A⋆ Ak⋆ x = Ak+1
                                                                 ⋆ x,
                              i=0

where (a) follows from the inductive hypothesis and (b) and (c) follow from the assumption that
Ai x = Ai⋆ x for i = 1, . . . , n.



                                                          65
