KVSF5AFJEIMIYAC264OUAA56SGP5MFAUG3AECKOTUPIXPGULVFQQC QIVGMR6INKBVT5IFCO2UJJQEO4PVW3ZM7IDTCTCOKOX7VKG7UPFAC 6PTHERE26NXSC3ZXSI5UYKWTMPYZD4WMYFBJKZE3MRRTKC7MIU6QC X7SPUV4CXRX7D5KKL6UVGHC7JWRWCA4QAJVVQISE64UEU7GXJNRQC 567NUQ633R5ESTE2LWXVUGM7XEZGJ65IRKPOCDZJS3JE5RAMR5KAC DDNESFMD4LGNTDGTCW27FQPCOR5Y5MJWN2TWCSIRNBK6QGBITBRQC QCVDPRXH57UFLU4YV3P2I5RQZGCBUKROYUZHDWOCHL43KDYN7MPAC BGMT6NIKIDEGQ74DC4LPVBR7JCUYHHQBOZXHYXMO5F2UVEQ3N47QC B5T3HFKSQF3T4T6Z2KZOA5ZDMI6TVON7BS7KKB3EAGGYAS7RJPBAC UVN5HOW3H2OVESJ62UFNQNS6VXHI5TRV22HQ44EOYU42453SDD2QC KUEZAMEH2M3K6EDHWMYXQMHZ2QTTH4KBM5CO7A7EB64ABEWRE6WQC EIPHTX56WTRFBMBNA4VYMKK4L7GWHA4Q2AQ3BCG2ZGZB3DBRENBQC JCK77YLTPL6VV5ZOTMGUJSFZ5DNMS3MZGP5UQLXYW6WSMEK6GAQAC MQJMCLGFSBSFJ3JPCIHQSBZS4XZPGJI7NGGRASX5UVGJO6HES25AC \gls{koat}s analysis goal is to find tight upper bounds for \gls{pip} andpossibly non-probabilistic and non-deterministic integer programs that are aspecialization of the first. The analysis techniques used such as\gls{mprf},\todo{more} have their limits and cannot always find tight bounds forevery program, which motivates control-flow refinement in order to find anequivalent program to the original one, that opens the possibility for theanalysis to to find tighter bounds.Recall \ref{def:overallcomplexity}; the newly constructed refined program shallhave they have the same overall runtime complexity as the original program,which implies that complexity bounds found for the refined program are alsocomplexity bounds for the original one.Naturally the control-flow refinement will add and replace transitions andlocations, hence the runtime and size complexity per each transition won't bepreserved. However we will show, that each transition in the refined program isa copy of a transition in the original program, and that complexity of anoriginal transition is equal to the sum of its copies.The control-flow refinement presented in this thesis adapts the partialevaluation presented by \citeauthor{domenech2019arxiv}\cite{domenech2019arxiv}for \acrlong{pip}. The partial evaluation will be constructed in a similarway but explicitly taking probability and general transitions into account.The construction is done in three steps. First the single evaluation step(unfolding) of transitions in a probabilistic program is presented. Second, apossibly infinite evaluation tree is constructed that will finally be collapsedinto a finite evaluation graph by an abstraction layer.
\section{Program equivalence}\begin{definition}[Program equivalence]Given two PIP $P = (\V, L, \GT, l_0)$ and $P' = (\V, L', \GT', l_0)$are equivalent if and only if the following properties hold:\begin{enumerate}\item \todo{continue}\end{enumerate}\end{definition}
Afterwards we will show that the partial evaluation is sound for probabilisticinteger programs and prove that the overall expected runtime complexity(\cref{def:past}) is equally preserved as the overall (worst-case) runtimecomplexity (\cref{def:runtimebounds}).
described by a set of constraints (polyhedron).This approach is very similar to the computation of invariants, where the set ofpossible assignment each location in a given program is iteratively updated bypropagating the transition constraints throught the program until a fixpoint isfound. \todo{citation} However, during evaluation one starts at a specificconfiguration and \textit{unfolds} transitions recursively, without influencyneighboring paths. The result is a (possibly still infinite) tree, representingall possible runs.
described by a set of constraints. The resulting graph is called a\textit{partial evaluation graph}. It was formalized for \gls{chc} by\citeauthor{gallagher2019eptcs}. In this thesis the definitions are adapted tobetter fit the algorithm and the formalisms of \Glspl{pip}.
This tree was formalized as an evaluation tree for \gls{chc} by \todo{citation}.In this thesis the evaluation tree is defined for \Gls{pip} instead, giving theopportunity to explicitly handle costs, and probability and staying closer toKoAT's formalisms.
Given \gls{pip} $P$ with locations $L$, transitions $T$ and general transitions$G$. Versions are the vertices of the partial evaluation graph. They contain thelocation at each step of the evaluation and a representation of the possibleassignments at each step of the evaluation. Versions can contain justconstraints, but in order to guarantee a finite graph later on, they can alsocontain an value from an abstraction space (see \Sref{sec:abstraction_layer},not to be confused with the abstract domains).\begin{definition}[Version]\label{def:version}The set of \textit{constraint versions} is the set of tuples over thelocations $L$ from $P$ and constraints $\C$. The set of \textit{abstractversions} is the set of tuples over the locations $L$ from $P$ and somefinite abstraction space $A$. Since the set of locations and the abstractionspace are both finite, so are the abstract versions. The set of versions isthe union of constraint and abstract versions.\begin{equation}\vers = (\Loc \times \C) \union (\Loc \times A)\end{equation}For clarity sake, versions will be denoted with angles. The set notationwith curly braces is used for non-abstracted constraints like so $\langle l,\{\psi_1, \dots\}\rangle$ and the list notation with brackets is used forabstracted values like so $\langle l, [\psi_1, \dots]\rangle$.\end{definition}The edges of the partial evaluation graph are transitions $\T_{PE}$ analogouslydefined to Definition \ref{def:pip}, except that they connect versions and notlocations.
\begin{definition}[Evaluation Tree]
\begin{definition}[Partial Evaluation]A graph $G = (\vers, \T_{PE})$ is a \textit{partial evaluation} of a\gls{pip} $P$ when for every admissible path $c_0c_1\dots{}c_n \in \fpath$of P with $c_i = (l_i, s_i, t_i)$ and $t_i = (l_{i-1}, \tau_i, \eta_i, p_i,l_i)$ for all $i = 1, \dots, n$, there exists a path $v_0'v_1'\dots{}v_n'$in G with the following properties:\begin{enumerate}\item $v'_i = (\langle l_i, \varphi_i\rangle, t_i')$ with some $\varphi_i\in \C$ and $t_i' \in E(G)$,\item $t'_i = (\langle l_{i-i}, \varphi_{i-1}\rangle, p_i, \tau_i, \eta_i,\langle l_i, \varphi_i\rangle)$, and\item $s_i \models \varphi_i$\end{enumerate}\end{definition}A \Gls{pip} $P$ can be lifted to a trivial partial evaluation graph by replacingevery location $l \in L$ by the trivial version $\langle l,\textit{true}\rangle$. Obviously the lift of program is not useful for theanalysis, as it doesn't capture any interesting properties of the program,besides what is already known in the original program. In the following we willpresent a construction for a partial evaluation graph using unfolding andabstraction.The partial evaluation is done step-wise. On every step the next version$v' = \langle l', \phi'\rangle$ is computed by unfolding a transition $t \in \T$from the original \gls{pip} that starts in the same location $l \in \L$ as theversion $v = \langle l, \phi\rangle$. The resulting constraint $\phi'$ containsall states $s' \in \Sigma$ with $s' \models \phi'$ reachable via the transitionfrom a state in the source version, i.e. $\prSs((l, s, \_) \rightarrow (l',s',t))> 0$.The non-determinism is taken into account by the implicit existentialquantification of temporary variables in constraints. In contrast, theprobabilistic sampling is over-approximated with an non-probabilistic update$\tilde{\eta}: \PV \rightarrow Z[\V]$ and a constraint denoted as$\lfloor\eta\rceil$. The probabilistic distributions in the probabilistic update$\eta$ are replaced by fresh temporary variables that are then constraint by$\lfloor\eta\rceil$.\begin{definition}[Non-probabilistic overapproximation\label{def:nonprobapprox}]Let $\eta: \PV \rightarrow \Z[\V\union D]$ be a probabilistic updatefunction, with random distributions $D_1,\dots,D_n$ used within. A\textit{non-probabilistic over-approximation} is a pair $(\lfloor\eta\rceil,\tilde{\eta}) \in \C \times (\PV \rightarrow \Z[\V])$ where\begin{equation}\lfloor\eta\rceil = \LAnd_{x\in\PV} (x' = \eta(x)[D_i\backslash{}d_i])\land \LAnd_{i=1,\dots,n} \lfloor D_i \rceil \\\end{equation}\begin{equation}\tilde{\eta}(x) = x' \hspace{1cm} \text{for all } x\in\PV\end{equation}for some fresh temporary variables $x', d_i\in \TV$.
\begin{lemma}For any assignment $s\in\Sigma$, non-probabilistic update $\eta: \PV\rightarrow \Z[\V \union D]$, and values $k_i \in\text{supp}([\eta(x_i)](s))$, the assignment $s'(x_i)=k_i$ satisfies thenon-probabilistic over-approximation \todo{todo}\end{lemma}\begin{definition}[Unfolding constraints]Let $\varphi \in \C$ be a constraint and $t = (\_, \tau, \eta, \_, \_) \in\T$. An unfolding of $\varphi$ via $t$ is defined as follows.\begin{align}\unfold(\varphi, t) = \begin{cases}\eta(\varphi \Land \tau \Land \lfloor\eta\rceil)|_{\PV} & \text{if }\tilde{\eta}(\varphi \Land \tau \Land \lfloor\eta\rceil) \text{ isSAT}\\\textit{false} & \text{otherwise}\end{cases}\end{align}\end{definition}The exactness is relaxed in order to work with abstract domains. Instead, theresult of unfolding an abstract value equivalent to $c$ shall contain all valuesof the constraint unfolding but possibly more.Given an unfolding one can derive an unfolding operation $\unfold^*: \C \times\T \rightarrow 2^{\T_{PE}}$ that constructs a new transition between theversions copying the guard $\tau$, update $\eta$, and probability $p$ from theoriginal transition. Since unsatisfiable versions cannot be reached they areignored and no transition is created.\begin{align}\unfold^*(\varphi, (l, \tau, \eta, p, l')) = \begin{cases}\{(\langle l, \varphi\rangle, \tau, \eta, p, \langle l',\unfold(\varphi, t)\rangle \} & \unfold(\varphi, t) \text{ if is SAT} \\\{\} & \text{ otherwise}\end{cases}\end{align}The operation is overloaded with a set function $\unfold_P^*: \C \times \GT\rightarrow 2^{\T_{PE}}$ unfolding all transitions in a general transition.\begin{align}\unfold^*(\varphi, g) = \Union_{t \in g}\unfold^*(\varphi, t)\end{align}Again the operation is overloaded with a function $\unfold^* : \vers \rightarrow2^{\T_{PE}}$ unfolding all outgoing general transitions in the \gls{pip} $P$.\begin{align}\unfold^*(\langle l, \varphi\rangle) = \Union_{g \in \GT_{out}(l)} \unfold^*(\varphi, t)\end{align}\begin{example}\end{example}\begin{algorithm}\caption{$evaluate(P, G, v)$}\KwData{A PIP $P$, Graph $G$, and source version $\langle l, \varphi\rangle$}\KwResult{A Graph $G$}$N = \unfold^*(v)$\;\For{$t = (v, \tau, \eta, p, v') \in N $}{\If {$v' \not\in G$}{$G := G \union \{t\}$\;$G := evaluate(P, G, v')$\;}\Else {$G = G \union \{t\}$\;}}\Return {G}\end{algorithm}
\section{Partial evaluation of \gls{scc}s}During \gls{koat}s analysis the program is split into \glspl{scc}. Bounds arefound for every \gls{scc} separately and then composed into an overall bound atthe end. Control-flow refinement is only needed for those \glspl{scc} where theanalysis fails to find tight bounds. In practice, linear bounds are consideredtight enough, whereas polynomial and exponential complexity bounds warrantrefinement in hope for tighter bounds.The previously presented control-flow refinement starts at the start locationsand evaluates the whole program. The size of the refined program is limited bythe number of locations and transitions as well as the number of properties oneach abstracted location. The smaller the initial program, the faster thecontrol-flow, the refined program and subsequent analysis. Instead of evaluatingthe program, one can adapt the partial evaluate to only evaluate a single\gls{scc} of the program. This section presents the partial evaluation of an\gls{scc}.The result is again an entire program, where only transitions the \gls{scc}, andincoming and outgoing transitions to this \gls{scc} are changed.In a first step the program is copied as a whole, lifted to a trivial evaluationgraph and the \gls{scc}, and all incoming and outgoing transitions are removedfrom the copy.Then the evaluation algorithm is executed from every incoming transition, butwith the additional condition to backtrack after unfolding an exitingtransition. The new transitions are added into the copied evaluation graph andtherefore progress made by earlier evaluations of entry transitions can bereused, shortening the evaluation of succeeding incoming transitions.Finally, the evaluation graph is converted back to a \gls{pip} and returned asresult of the partial evaluation of the \gls{scc}.
\newcommand{\RB}[0]{\mathcal{RB}} % Runtime bound\newcommand{\SB}[0]{\mathcal{SB}} % Size bound\newcommand{\B}[0]{\mathcal{B}} %Bounds\newcommand{\Rt}[0]{\mathcal{R}} %Runtime\newcommand{\E}[0]{\mathbb{E}} % Expected\newcommand{\scheduler}[0]{\mathfrak{S}}\newcommand{\ESs}[0]{\mathbb{E}_{\scheduler,s_0}} % Expected\newcommand{\Prog}[0]{\mathcal{P}} % A PIP\newcommand{\GRV}[0]{\mathcal{GRV}} % General result variables\renewcommand{\S}[0]{\mathcal{S}} % grv variable\newcommand{\RBe}[0]{\mathcal{RB}_\E} % Expected Runtime bound\newcommand{\SBe}[0]{\mathcal{SB}_\E} % Expected Size bound
\newcommand{\unfold}[0]{\text{unfold}}\newcommand{\vers}[0]{\textbf{\textsf{Version}}}\newcommand{\pr}[0]{\textit{pr}}\newcommand{\prSs}[0]{\textit{pr}_{\scheduler, s_0}}\newcommand{\PrSs}[0]{\mathbb{P}_{\scheduler, s_0}}\newcommand{\G}[0]{\mathcal{G}}\newcommand{\Tin}[0]{\T_\text{in}}\newcommand{\Tout}[0]{\T_\text{out}}\newcommand{\GTin}[0]{{\mathcal{G}\mathcal{T}_\text{in}}}\newcommand{\GTout}[0]{{\mathcal{G}\mathcal{T}_\text{out}}}
constraint $\psi \in \L^{\leq}$ describes an closed affine half-space and everylinear strict inequality constraint $\psi \in \L^{\leq}$ describes an open
constraint $\psi \in \Lin^{\leq}$ describes an closed affine half-space and everylinear strict inequality constraint $\psi \in \Lin^{\leq}$ describes an open
\todo{define support, and constraints}
$\Z[\V\union D]$, is the set of integer polynomials containing variables $\V$ ordistributions. They behave exactly like normal polynomials except that thevalues of the distributions are sampled probabilistically instead of being givenas argument. As such we can define a function $[\cdot]: \Z[\V\union D]\rightarrow \Sigma \rightarrow \Z \rightarrow [0,1]$ that returns theprobability that the polynomial $f \in \Z[\V \union D]$ with a state $s \in\Sigma$ evaluates to a value $k\in\Z$ with a probability $[f](s)(k)$.The values of the variables are fixed by a syntactical substitution, where everyvariable $x_i\in\V$ is replaced by the value fixed in the assignment $s(x_i)$,we write $[x_i\backslash s(x_i)]$.The resulting polynomial $f[x_i\backslash s(x_i)]$ describes a random variable$[f](s)$ that takes a value at random depending only on the distributions $D_1,\dots, D_m$ within. The random variable has the following probabilitydistribution:\begin{align}[f](s)(k) &= \sum_{\substack{d_i \in \Z \\ i = 0,\dots,m}} D_1(d_1)\cdot D_2(d_2) \cdots D_m(d_m) \cdot \begin{cases}1, & \text{if } f[x_i \backslash s(x_i)][D_i\backslash d_i] = k \\0, & \text{otherwise}\end{cases}\\& = P([f](s) = k)\end{align}where $f[D_i\backslash d_i]$ is a syntactical substitution of every distribution$D_i$ by an integer value $d_i \in \Z$ for all $i = 1,\dots,m$.Under misuse of notation we write $f(s)$ to denote the unique value $v$ with$f(s)(v) = 1$, when it exists. \todo{check if actually used}The support of polynomial $f$ with an assignment $s$ is the set of values thatcan be achieved with the polynomial by sampling the random distributions.\begin{example}Consider the polynomial $f = x^2 + \textsc{Unif}(3,5)$ and the assignment$s(x) = 2$. $[f](s)$ is the random variable described by the polynomial $f[x/2]=2^2 + \textsc{Unif}(3,5)$.It can take three different values with the following probability\begin{equation}[f](s)(k) = \begin{cases}\frac{1}{3}, & \text{if } k \in \{7,8,9\}\\0, & \text{otherwise}\end{cases}\end{equation}\end{example}
\begin{definition}[Probabilistic Integer Program]\label{def:pip}$(\PV, L, \GT, l_0)$ is a probabilistic integer transition system where
\begin{definition}[Probabilistic Integer Program\cite{meyer2021tacas}]\label{def:pip}$(\PV, \Loc, \GT, l_0)$ is a probabilistic integer transition system where
\end{enumerate}\end{definition}\subsection{Probability space of a program\label{ssec:probabilityspace}}Before defining the semantics of a \gls{pip} a new special location $l_\bot$ isintroduced that will be used to indicate the termination of a program as well asa virtual transition $t_\bot$ and general transition $g_\bot = \{t_\bot\}$ withthe same purpose. Instead of just vaguely \enquote{terminating} a program takesthe transition $g_\bot$ to the location $l_\bot$ if and only if no othertransition is walkable. Since no normal transition leaves the location $l_\bot$the run loops indefinitely on the location $l_\bot$ after termination. Inaddition a new transition $t_\text{in}$ will be used for the start of theprogram.A state $s$ is a variable assignment for the variables of a program $s: \V\rightarrow \Z$. \Sigma is the set of all states. The set of configuration isdefined as $\confs = L \union \{l_\bot\} \times \T \union \{t_{\text{in}},t_\bot\} \times \Sigma$.Note that additionally to the location and state, the last transition taken tothe current location is captured as well. This won't be relevant for the partialevaluation but is important to define the probabilistic properties of a\gls{pip}.A run of the program is an \textit{infinite} sequence of configurations, and theset of all runs is defined as $\runs = \confs^\omega$. In contrast a finiteprefix is a finite sequence of configurations. The set of all finite prefixes isdefined as $\fpath = \confs^*$.\begin{rem}The set of configurations does not exclude invalid combinations oflocations and transitions, that is a configuration with a location that isnot the target of the incoming transition, or a state that is impossible toreach via the incoming transition. Conversely, the set of runs and finiteprefixes does not exclude invalid paths, e.g. two consecutive configurationsthat cannot be reached via the given transition, etc. The validity of a pathwill be described by a probability measure where invalid paths have a zeroprobability.\end{rem}For a \gls{pip} one can define a probability space $(\runs, \F, \PrSs)$, where theoutcomes of the probabilistic event are the runs on the program. Every distinctrun is measurable hence the $\sigma$-algebra $\F$ is defined to contain everyset ${r} \in \F$ for $r \in \runs$. The probability measure $\prSs$ describesthe probability of the given run for a scheduler $\scheduler$ and the inputgiven to the program as the initial state $s_0$. Formally the probability spaceis defined by a cylindrical construction expanding the length of finite prefixesup to infinity. For the detailed construction we'll refer to \cite{meyer20arxiv}.On any given configuration a scheduler resolves the non-determinism first. Theprobability measure will use the result of the scheduler instead of the previousconfiguration. The scheduler keeps the values of all program variables from theprevious configuration. It selects a general transition $g$ and a variableassignment $\tilde{s}$ satisfying the guard of the general transition. If nosuch transition is found of the program is already in the terminating state$l_\bot$ it takes the special transition $g_\bot$ indicating termination.\begin{definition}[Scheduler]\label{def:scheduler} \cite{meyer20arxiv}A function $\scheduler : \confs \rightarrow (\GT \uplus \{g_\bot\})$ is ascheduler if for every configuration $c = (l,t,s) \in \confs$,$\scheduler(c) = (g, s')$ implies:\begin{enumerate}\item \label{itm:scheduler1} $s'(x) = s(x)$ for all $x \in \PV$\item $l$ is the start location $l_g$ of the general transition $g$.\item \label{itm:scheduler3} $s' \models \tau_g$ for the guard $\tau_g$ of the generaltransition $g$.\item $g = g_\bot$ and $s' = s$, if $l=l_bot$, $t=t_\bot$, or no $g' \in\GT$ and $s'\in \Sigma$ satisfy \cref{itm:scheduler1} to\cref{itm:scheduler3}
Let $\scheduler$ be a scheduler and $s_0$ be an initial state. First, theprobability for a program to start at a configuration $c$ is 1 only for theconfiguration that has the initial state $s_0$ at the start location $l_0$coming from the initial transition $t_\text{in}$. All other configuration areinvalid starting configurations and get assigned a zero probability by theprobability measure $\prSs : \confs \rightarrow [0,1]$\begin{equation}\prSs(c) = \begin{cases}1 & \text{ if } c = (l_0, s_0, t_\text{in}) \\0 & \text{ otherwise}\end{cases}\end{equation}Lets say the program ran up to a configuration $c=(l,t,s)$. The schedulerresolves the non-deterministic sampling and branching to $\scheduler(c) = (g,\tilde{s})$. The probability for the event $c \rightarrow c'$ that $c'$ followsthe configuration $c$ with $c' = (l', t', s')$ and $t' = (l, p, \tau, \eta, l')\in g$ depends on three things: First the transition $t \in g$ is taken with theprobability $p$, second the probability that each program variables $x\in\PV$ isupdated to the value $s'(x)$ by the probabilistic update - recall definition\ref{def:polyindeterminates}, third that the temporary variables are sampled bythe scheduler equal to the target state. The result is the probability measure$\prSs: \confs^2 \rightarrow [0,1]$.\begin{align}\prSs(c \rightarrow c') = p \cdot \prod_{x\in\PV} [\eta(x)](\tilde{s})(s'(x))\cdot \prod_{u\in\V\backslash\PV} \delta_{\tilde{s}(u),s(u)},\end{align}with any $z_1, z_2 \in \Z$:\begin{equation}\delta_{z_1,z_2} = \begin{cases}1, & \text{if } z_1 = z_2 \\0, & \text{if } z_1 \neq z_2.\end{cases}\end{equation}Naturally for all other configurations $c'$, such as configuration that are notreachable by the given transition, or transitions that were not selected by thescheduler we define $\prSs(c \rightarrow c') = 0$.\begin{align}\prSs(f) = \prSs(c_0) \cdot \prod_{i=1}^n \prSs(c_{i-1} \rightarrow c_i)\end{align}By a cylindrical construction one gets the final probability measure for theinfinite runs $\PrSs : \runs \rightarrow [0,1]$ and the probability space$(\runs, \F, \PrSs)$.\begin{definition}[Admissible Run]\label{def:admissible}An finite prefix $f \in \fpath$ is \textit{admissible} if and only if$\prSs(f) > 0$. A run $c_0c_1\dots \in \runs$ is \textit{admissible} if andonly if every finite prefix $c_0\dots c_n \in\fpath$ is admissible.\end{definition}\begin{rem}An admissible run can very well have have a zero probability if theprobability of its prefixes approach zero for $n \rightarrow \inf$.\end{rem}\begin{definition}[Terminating Run]\label{def:termination}A run is is terminating if it is admissible and it has a finite prefixending in the location $l_\bot$.\end{definition}Because by definition only the terminating transition $t_\bot$ is admissiblewhen the program is in the terminal location $l_\bot$ and the followingconfiguration must again be in the terminal location $l_\bot$. A terminating runmust end with infinitely many repetitions of a terminating configuration$c_\bot=(l_\bot,t_\bot,s)$ for some assignment $s\in\Sigma$.\subsection{Bounds}The whole goal of \gls{koat}'s analysis is to find bounds. A bound is anexpression that describes the upper limit of a property of the program.\begin{definition}[Bounds\cite{meyer2021tacas}]\label{def:bounds}The set of bounds $\B$ is the smallest set with $\PV \union \R_{\geq 0}\subseteq \B$, and where $b_1,b_2 \in \B$ and $v\in \R_{\geq 1}$ imply $b_1 +b_2, b_1 \cdot b_2 \in \B$ and $v^{b_1} \in \B$.\end{definition}During analysis of classical integer programs, one is especially interested inruntime and size bounds. A runtime bound is an upper bound on the number ofvisits to a transition in the program over all admissible runs, whereas a sizebound describes the highest value of a program variable observed at atransition over all admissible runs. Because the values observed in a run arehighly dependent on the decisions made by the scheduler $\scheduler$, the boundswe take the supremum over all $\scheduler$. One can also picture the scheduleras an adversary that always takes the worst decision possible for runtime andsize-bounds.\begin{definition}[Runtime and Size Bounds\cite{meyer2021tacas}\label{def:runtimebounds}]$\RB: \T \rightarrow \B$ is a runtime bound and $\SB: \T \times \V\rightarrow \B$ is a size bound if for all transitions $t\in\T$, allvariables $x\in\V$, all schedulers $\scheduler$, and all states $s_0 \in\Sigma$, we have\begin{align*}&|s_0|(\RB(t)) \geq \sup \set{ |\set{i}{t_i =t}|}{f=(\_,t_0,\_)\dots(\_,t_n,\_), \prSs(f) > 0} \\&|s_0|(\SB(t, x)) \geq \sup \set{ |s(x)| }{f=\dots(\_,t,s), \prSs(f) >0}.\end{align*}\end{definition}In probabilistic programs not only the worst case is of interest, but also theprobable case. For example a program might run indefinitely in the worst casebut the worst-case has a probability approaching zero. The expected bounds aredefined using the expected value of random variables in the probability space$(\runs, \F, \PrSs)$ defined in \Sref{ssec:probabilityspace}. Moreover, recalldefinition \ref{def:expected_value}.\begin{definition}[Expected Runtime Complexity, \acrshort{past}\cite{meyer2021tacas}\label{def:past}]For $g \in \GT$ its runtime is the random variable $\Rt(g)$ where $R: \GT\rightarrow \runs \rightarrow \overline{\N}$ with \begin{equation}\Rt(g)((\_,t_0,\_)(\_,t_i,\_)\dots) = |\set{i}{t_i \in g}|. \end{equation}For a scheduler $\scheduler$ and starting state $s_0\in\Sigma$, the expectedruntime complexity of $g\in\GT$ is $\E_{\scheduler,s_0}(\Rt(g))$ and theexpected runtime complexity of $\Prog$ is $\sum_{g\in\GT}\E_{\scheduler,s_0}(\Rt(g)))$.If $\Prog$'s expected runtime complexity is finite for every scheduler$\scheduler$ and every initial state $s_0$, then $\Prog$ is called\acrfull{past}\end{definition}The expected size bound is defined similarly\begin{definition}[Expected SizeComplexity\cite{meyer2021tacas}\label{def:expectedcomplexity}]The set of general result variables is $\GRV = \set{(g,l,x)}{g\in\GT,x\in\PV, (\_,\_,\_,\_,l) \in g}$. The size of $\alpha = (g,l,x) \in \GRV$ isthe random variable $\S(\alpha)$ where $\S : \GRV \rightarrow (\runs\rightarrow \overline{N})$ with\begin{equation}\S(g,l,x)((l_0,t_0,s_0)(l_1,t_1,s_1)\dots) = \sup \set{|s_i(x)|}{l_i =l, t_i \in g}.\end{equation}For a scheduler $\scheduler$ and starting state $s_0$, the expected sizecomplexity of $\alpha \in \GRV$ is $\E_{\scheduler,s_0}(\S(\alpha))$.\end{definition}\begin{definition}[Expected Runtime and SizeBounds\cite{meyer2021tacas}\label{def:expectedbounds}]\phantom{ }\begin{itemize}\item $\RBe : \GT \rightarrow \B$ is an expected runtime bound if forall $g\in\GT$, all schedulers $\scheduler$, and all $s_0 \Sigma$, wehave $|s_0|(\RBe(g)) \geq \ESs(\Rt(g))$.\item $\SBe : \GRV \rightarrow \B$ is an expected size bound if forall $\alpha\in\GT$, all schedulers $\scheduler$, and all $s_0 \Sigma$, wehave $|s_0|(\SBe(g)) \geq \ESs(\S(g))$.\end{itemize}\end{definition}\begin{example}\end{example}\subsection{Costs}It is useful to add the notion of costs to a transition to reflect variablecomplexity of transitions. The accumulative costs of a run are the sum of costsfor each transition taken. Accumulative costs can simulated by an additionalprogram variable $\mathbf{c} \in \PV$ that is updated only by polynomials of theform $\eta(\mathbf{c}) = \mathbf{c} + c_t$, where $c_t \in\Z$ is the cost associated with the transition $t\in\T$.For a given size bound $\SB$ for the \gls{pip} $\Prog$ and a starting assignment$s_0$, the cost bound is defined as $|s_0|(\SB(t_\bot,\mathbf{c}))$, and givenan expected size bound $\SBe$, the expected cost bound is defined as$|s_0|\SBe(t_\bot, mathbf{c})$.\subsection{Graph operations}A \gls{pip} contains a directed graph with vertices $\L$ and edges $\T$. We willdefine some graph operations that will become useful during the thesis. The setof directed graphs over locations $\L$ and transitions $\T$ is denoted by $\G$.% The graph $G(P)$ denotes the graph contained within a \gls{pip} $P$ and is% defined as $G(P) = (L, \T)$. The following graph operations will be defined on% graphs only, but work equally well for \glspl{pip} by using the contained graph% operation first. However, the result might not be a valid integer program, per-se.A set of transitions $T \subseteq \T$ induces a sub-graph $G(T)$ in a program $P$,with $\G: 2^\T \rightarrow \G$. Similarly a set of locations $L \subseteq \Loc$induces a sub-graph $G(L)$ in $P$, with $G: 2^\Loc \rightarrow \G$.\begin{rem}The resulting graphs cannot allways be lifted to a valid \gls{pip}, sincecumulative probability of general transitions are not necessarily preserved.\end{rem}The operations $\Tin : \Loc \rightarrow 2^\T$, $\Tout : \Loc \rightarrow 2^\T$,$\GTin : \Loc \rightarrow 2^\GT$, and $\GTout: \Loc \rightarrow 2^\GT$ return theset of (general) transitions starting or ending in the given location.Adding a transition and possibly new locations therein to graph is denoted bythe plus operator $+: \G, \T \rightarrow \G$
\subsection{Semantics}\todo{open question regarding temporary variables}% the original definition alled states defining variables, but this let's% temporary variables carry-over to the next transition. Is this what we% want?Before defining the semantics of a \gls{pip} a new special location $l_\bot$ isintroduced that will be used to indicate the termination of a program as well asa virtual transition $t_\bot$ and general transition $gt_\bot = \{t_\bot\}$ withthe same purpose. Instead of just vaguely \enquote{terminating} a program takesthe transition $gt_\bot$ to the location $l_\bot$ if and only if no othertransition is walkable. Since no normal transition leaves the location $l_\bot$the run loops indefinitely on the location $l_\bot$ after termination. Inaddition a new transition $t_\text{in}$ will be used for the start of theprogram.A state $s$ is a variable assignment for the variables of a program $s: \V\rightarrow \Z$. \Sigma is the set of all states. The set of configuration isdefined as $\confs = L \union \{l_\bot\} \times \T \union \{t_{\text{in}},t_\bot\} \times \Sigma$.Note that additionally to the location and state, the last transition taken tothe current location is captured as well. This won't be relevant for the partialevaluation but is important to define the probabilistic properties of a\gls{pip}.A run of the program is an \textit{infinite} sequence of configurations, and theset of all runs is defined as $\runs = \confs^\omega$. In contrast a finiteprefix is a finite sequence of configurations. The set of all finite prefixes isdefined as $\fpath = \confs^*$.\begin{rem}The set of configurations does not exclude invalid combinations oflocations and transitions, that is a configuration with a location that isnot the target of the incoming transition, or a state that is impossible toreach via the incoming transition. Conversely, the set of runs and finiteprefixes does not exclude invalid paths, e.g. two consecutive configurationsthat cannot be reached via the given transition, etc. The validity of a pathwill be described by a probability measure where invalid paths have a zeroprobability.\end{rem}For a \gls{pip} one can define a $(\runs, \F, \textit{pr})$. The outcomes ofthe probabilistic event in this space are the runs on the program. Everydistinct run is measurable hence the $\sigma$-algebra $\F$ is defined to containevery set ${r} \in \F$ for $r \in \runs$. The probability measure $pr$ describesthe probability of the given runs. Formally the probability space is defined bya cylindrical construction \todo{elaborate}. Since the construction is ratherinvolved we will only sum up and the properties relevant to this thesis.First the probability of a run is separate from the non-determinism. So for allthe considerations the non determinism is assumed to be decided by a schedulerand the probability measure depends on the scheduler.The probability of specific run in the probability space is equal to theprobability that every transition in the run is taken. Naturally, invalidtransitions (either because they do not exist in the program, or because theguard is not satisfied) have a zero probability.The probability space will be used to define the semantics of a \gls{pip}\subsection{Notes about the probability measure}Probability that a variable $x$ takes the value $s(x)$ when taking thetransition $t$ from an (non-deterministically resolved) assignment $\tilde{s}$:\todo{redefine with polynomials over indeterminates}\begin{align}q_{\tilde{s},t,s(x)}(x)\end{align}(Trivial) probability that the temporary variables got assigned there expectedvalues, given a (non-deterministically resolved) assignment $\tilde{s}$ and theresulting assignment $s$\begin{align}\delta_{\tilde{s}(u),s(u)})\end{align}
Probability of a transition after a finite prefix: For $F = \dots (l', t', s') \in \fpath$, $(l, t,x) \in \confs$, $t = (l', p, \tau, \eta, l)$.\begin{align}pr_{\mathfrak{S},s_0}((l', t',s') \rightarrow (l, t, s)) :=pr_{\mathfrak{S},s_0}(f \rightarrow (l,t,s))= p \cdot \prod_{x\in\PV}q_{\tilde{s},t,s(x)}(x) \cdot \prod_{u \in \TV} \delta_{\tilde{s}(u),s(u)})\end{align}\begin{rem}The probability depends on the scheduler $\mathfrak{S}$ and the startingstate $s_0$.\end{rem}Probability of a finite prefix. For $f = c_0, \dots, c_n \in \fpath$:\begin{align}pr_{\mathfrak{S},s_0}(f) = pr_{\mathfrak{S},s_0}(c_0) \cdot \prod_{i=1}^n pr_{\mathfrak{A},s_0}(c_{i-1} \rightarrow c_i)\end{align}Cylindrical construction yields the unique probability measure$\mathbf{P}_{\mathfrak{S},s_0} : \F \rightarrow [0,1]$ for infinite runs\subsection{Runtime}\begin{comment}for a transition:- constant cost- most simple case cost = 1 for every transition- combining transitions and adding costs- costs depending on variablesfor a prefix:- finite sequence of configurations- runtime = sum of all costs over all steps in the prefix- probability = product over all transition probabilities in the prefix- legal prefix = non-zero probabilityfor a path:- infinite sequence of configurations- runtime = runtime of the largest non-zero probability prefix- prolegal paths = paths with a non-zerofor a program:- supremum over runtime of all paths\end{comment}\begin{definition}[Runtime of a run]\end{definition}\begin{definition}[Worst-case runtime of a Program]\end{definition}\begin{definition}[Expected runtime of a Program]\end{definition}
\newacronym{past}{PAST}{probably almost surely terminating}