{'fraction_non_alphanumeric': 0.03973632559345258, 'fraction_numerical': 0.012331963115209421, 'mean_word_length': 4.195075028857253, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Piecewise linear approximations of the standard normal first order loss function

The first order loss function and its complementary function are extensively used in practical settings. When the random variable of interest is normally distributed, the first order loss function can be easily expressed in terms of the standard normal cumulative distribution and probability density function. However, the standard normal cumulative distribution does not admit a closed form solution and cannot be easily linearised. Several works in the literature discuss approximations for either the standard normal cumulative distribution or the first order loss function and their inverse. However, a comprehensive study on piecewise linear upper and lower bounds for the first order loss function is still missing. In this work, we initially summarise a number of distribution independent results for the first order loss function and its complementary function. We then extend this discussion by focusing first on random variable featuring a symmetric distribution, and then on normally distributed random variables. For the latter, we develop effective piecewise linear upper and lower bounds that can be immediately embedded in MILP models. These linearisations rely on constant parameters that are independent of the mean and standard deviation of the normal distribution of interest. We finally discuss how to compute optimal linearisation parameters that minimise the maximum approximation error.


Introduction
Consider a random variable ω and a scalar variable x. The first order loss function is defined as where E denotes the expected value. The complementary first order loss function is defined as The first order loss function and its complementary function play a key role in several application domains. In inventory control [10] it is often used to express expected inventory holding or shortage costs, as well as service level measures such as the widely adopted "fill rate", also known as β service level [1], p. 94. In finance the first order loss function may be employed to capture risk measures such as the so-called "conditional value at risk" (see e.g. [8]) . These examples illustrate possible applications of this function. Of course, the applicability of this function goes beyond inventory theory and finance. Despite its importance, to the best of our knowledge a comprehensive analysis of results concerning the first order loss function seems to be missing in the literature. In Section 2, we first summarise a number of distribution independent results for the first order loss function and its complementary function. We then focus on symmetric distributions and on normal distributions; for these we discuss ad-hoc results in Section 3.
According to one of these results, the first order loss function can be expressed in terms of the cumulative distribution function of the random variable under scrutiny. Depending on the probability distribution adopted, integrating this function may constitute a challenging task. For instance, if the random variable is normally distributed, no closed formulation exists for its cumulative distribution function. Several approximations have been proposed in the literature, see e.g. [12,9,11,3,7,4], which can be employed to approximate the first order loss function. However, these approximations are generally nonlinear and cannot be easily embedded in mixed integer linear programming (MILP) models.
In Section 4 and 5, we introduce piecewise linear lower and upper bounds for the first order loss function and its complementary function for the case of normally distributed random variables. These bounds are based on standard bounding techniques from stochastic programming, i.e. Jensen's lower bound and Edmundson-Madansky upper bound [6], p. 167-168. The bounds can be readily used in MILP models and do not require instance dependent tabulations. Our linearisation strategy is based on standard optimal linearisation coefficients computed in such a way as to minimise the maximum approximation error, i.e. according to a minimax approach. Optimal coefficients for approximations comprising from two to eleven segments will be presented in Table 1; these can be reused to approximate the loss function associated with any normally distributed random variable.

The first order loss function and its complementary function
Consider a continuous random variable ω with support over R, probability density function g ω (x) : R → (0, 1) and cumulative distribution function G ω (x) : R → (0, 1). The first order loss function can be rewritten as The complementary first order loss function can be rewritten as Lemma 1. The first order loss function L(x, ω) can also be expressed as Proof.
is a well-known integration by parts that proceeds as follows. Let and take the limit since b → ∞. The product term in the integration by parts formula converges to x(1 − G ω (x)) as b → ∞. We therefore take the limit to obtain the identity and by substituting ∞ x tg ω (t) dt with this expression we obtain The following well-known lemma is introduced, together with its proof, for completeness.
Lemma 2. The complementary first order loss function L(x, ω) can also be expressed as Proof.
There is a close relationship between the first order loss function and the complementary first order loss function.
Lemma 3. The first order loss function L(x, ω) can also be expressed as Proof.
Because of the relation discussed in Lemma 3, in what follows without loss of generality most of the results will be presented for the complementary first order loss function.
Another known result for the first order loss function and its complementary function is their convexity, which we present next. Proof. We shall prove the result for L(x, ω).
and d 2 dx 2 L(x, ω) = g ω (x). Since g ω (x) is nonnegative the result follows immediately; furthermore, the proof for L(x, ω) follows from Lemma 3 and from the fact that −x is convex.
For a random variable ω with symmetric probability density function, we introduce the following results. Proof.
Lemma 6. If the probability density function of ω is symmetric about a mean valueω, then and Proof. Follows immediately from Lemma 3 and Lemma 5.
The results presented so far are easily extended to the case in which the random variable is discrete. In the following section we present results for the case in which the random variable is normally distributed.

The first order loss function for a normally distributed random variable
Let ζ be a normally distributed random variable with mean µ and standard deviation σ. Recall that the Normal probability density function is defined as No closed form expression exists for the cumulative distribution function Let φ(x) be the standard Normal probability density function and Φ(x) the respective cumulative distribution function. We next present three known results for a normally distributed random variable: a standardisation result in Lemma 7, and two closed form expressions for the computation of the loss function and of its complementary function in Lemmas 8 and 9.
Lemma 7. The complementary first order loss function of ζ can be expressed in terms of the standard Normal cumulative distribution function as where Z is a standard Normal random variable.
Proof. Recall that the complementary first order loss function is defined as We change the upper integration limit to = σ = σ Lemma 8. The complementary first order loss function L(x, ζ) can be rewritten in closed form as Proof. Integrate by parts Eq. 28 and observe that From Lemma 3 the first order loss function of ζ can be expressed as Recall that an alternative expression is obtained via Lemma 1, From Lemma 3 and Lemma 8 we obtain the closed form expression Lemma 9. The first order loss function L(x, ζ) can be rewritten in closed form as Proof. Integrate by parts Eq. 32 and observe that Furthermore, since the Normal distribution is symmetric, both Lemma 5 and Lemma 6 hold.

Jensen's lower bound for the standard normal first order loss function
We introduce a well-known inequality from stochastic programming [6], p. 167.

Jensen's lower bound
Theorem 1 (Jensen's inequality). Consider a random variable ω with support Ω and a function f (x, s), which for a fixed x is convex for all s ∈ Ω, then Proof. [2], p. 140.
Common discrete lower bounding approximations in stochastic programming are extensions of Jensen's inequality. The usual strategy is to find a low cardinality discrete set of realisations representing a good approximation of the true underling distribution. [2], p. 288, discuss one of these discrete lower bounding approximations which consists in partitioning the support Ω into a number of disjoint regions, Jensen's bound is then applied in each of these regions.
Theorem 3. Given a random variable ω Jensen's bound (Theorem 1) is applicable to the first order loss function L(x, ω) and its complementary function L(x, ω).
Proof. Follows immediately from Lemma 4.
Having established this result, we must then decide how to partition the support ω in order to obtain a good bound. In fact, to generate good lower bounds, it is necessary to carefully select the partition of the support ω. The optimal partitioning strategy will depend, of course, on the probability distribution of the random variable ω.

Minimax discrete lower bounding approximation
We discuss a minimax strategy for generating discrete lower bounding approximations of the (complementary) first order loss function. In this strategy, we partition the support ω into a predefined number of regions N in order to minimise the maximum approximation error.
Consider a random variable ω and the associated complementary first order loss function assume that the support Ω of ω is partitioned into N disjoint subregions Ω 1 , . . . , Ω N .
Lemma 10. For the (complementary) first order loss function the lower bound presented in Theorem 2 is a piecewise linear function with N + 1 segments.
Proof. Consider the bound presented in Theorem 2 and let f (x, ω) = max(x − ω, 0), this function is equivalent to The proof for the first order loss function follows a similar reasoning.
which is the equation of the tangent line to L(x, ω) at a given point b, that is The very same reasoning can be easily applied to the first order loss function.
Lemma 12. The maximum approximation error between L lb (x, ω) and L(x, ω) will be attained at a breakpoint.
Proof. By recalling that L(x, ω) is convex (Lemma 4), since L lb (x, ω) is piecewise linear (Lemma 10) and each segment of L lb (x, ω) is tangent to L(x, ω) (Lemma 11), it follows that the maximum error will be attained at a breakpoint. Proof. The approximation errors for x → −∞ and x → ∞ are both 0; since we have N+1 segments, we only have N breakpoints to check.
We first show that (→) if Ω 1 , . . . , Ω N is an optimal partition of the support Ω of ω under a minimax strategy, then approximation errors at breakpoints are all equal.
A first observation that follows immediately from Lemma 12 is that, if the slope of segment L i+1 lb (x, ω) remains unchanged, and the breakpoint between L i lb (x, ω) and L i+1 lb (x, ω) moves towards the point at which L i+1 lb (x, ω) is tangent to L(x, ω), the error at such breakpoint decreases.
If one changes the size of region Ω i so that the upper limit becomes b i + ∆, then E[ω|Ω i ] will increase if ∆ > 0, or will decrease if ∆ < 0. This immediately follows from the definition of E[ω|Ω i ]. Therefore, the breakpoint between segment i and segment i+1, which occurs at E[ω|Ω i ], will move accordingly. However, the slope of segment i + 1, which we recall is equal to G ω (b i+1 ), depends uniquely on the upper limit of the region Ω i+1 , b i+1 , and is not affected by a change in the upper limit of region Ω i . Therefore, the error at the breakpoint between segment i and segment i + 1 will decrease if ∆ > 0, or will increase if ∆ < 0. Now, assume that Ω 1 , . . . , Ω N is an optimal partition of the support Ω of ω and approximation errors at breakpoints are not all equal. Furthermore, assume that the maximum approximation error occurs at breakpoint i. By increasing the size of the region Ω i , i.e. by setting the upper limit to b i + ∆, where ∆ > 0, it is possible to decrease the maximum error until it becomes equal to the error at breakpoint k, where k ∈ {1, . . . , i − 1}. The procedure can be repeated until all approximation errors are equal.
Second, we show that (←) if approximation errors at breakpoints are all equal, then Ω 1 , . . . , Ω N is an optimal partition of the support Ω of ω under a minimax strategy.
If approximation errors at breakpoints are all equal and we change the size of region Ω i by setting the upper limit to b i + ∆, where ∆ > 0, then the approximation error at breakpoint i − 1 will increase; conversely, if ∆ < 0, then the approximation error at breakpoint i + 1 will increase. By using this last result it is possible to derive a set of equations that can be solved for computing an optimal partitioning. Let us consider the error e i at breakpoint i, this can be expressed as where Ω i = [a i , b i ]. Since we have N breakpoints to check, we must solve a system comprising the following N − 1 equations e 1 = e i for i = 2, . . . , N.
under the following restrictions The system therefore involves N − 1 variables, each of which identifies the boundary between two disjoint regions Ω i and Ω i+1 .
Theorem 5. Assume that the probability density function of ω is symmetric about a mean valueω. Then, under a minimax strategy, if Ω 1 , . . . , Ω N is an optimal partition of the support Ω of ω, breakpoints will be symmetric aboutω.
Proof. This follows from Lemma 6 and Theorem 4.
In this case, by exploiting the symmetry of the piecewise linear approximation, an optimal partitioning can be derived by solving a smaller system comprising ⌈N/2⌉ equations, where N is the number of regions Ω i and ⌈x⌉ rounds x to the next integer value.
Unfortunately, equations in the above system are nonlinear and do not admit a closed form solution in the general case.

Normal distribution
We will next discuss the system of equations that leads to an optimal partitioning for the case of a standard Normal random variable Z. This partitioning leads to a piecewise linear approximation that is, in fact, easily extended to the general case of a normally distributed variable ζ with mean µ and standard deviation σ via Lemma 7. This equation suggests that the error of this approximation is independent of µ and proportional to σ.
To express the conditional expectation E[Z|Ω i ] we proceed as follows: let To solve the above system of non-linear equations we will exploit the close connections between finding a local minimum and solving a set of nonlinear equations. In particular, we will use the Gauss-Newton method to find a partition Ω 1 , . . . , Ω N of the support of Z that minimises the following sum of squares This minimisation problem can be solved by software packages such as Mathematica (see NMinimize).

Numerical examples
The classical Jensen's bound for the complementary first order loss function of a standard Normal random variable Z is show in Fig. 1. This is obtained by considering a degenerate partition of the support of Z comprising only a single region Ω 1 = [−∞, ∞]. In practice, we simply replace Z by its expected value, i.e. zero. Therefore we simply have L lb = max(x, 0). The maximum error of this piecewise linear approximation occurs for x = 0 and it is equal to 1/ √ 2π. If we split the support of Z into four regions (Fig. 2), the solution to the system of nonlinear equations prescribes to split Ω at b 1 = −0.886942, b 2 = 0, b 3 = 0.886942. The maximum error is 0.0339052 and it is observed at x ∈ {±1.43535, ±0.415223}. In Table 1 we report parameters of L lb (x, Z) with up to eleven segments. In Fig. 3 we present the approximation error of L lb (x, Z) with up to eleven segments.    In Fig. 4 we exploited Lemma 7 to obtain the five-segment piecewise Jensen's bound for L(x, ζ), where ζ is a normally distributed random variable with mean µ = 20 and standard deviation σ = 5. The maximum error is σ0.0339052 and it is observed at x ∈ {σ(±1.43535) + µ, σ(±0.415223) + µ}.

A piecewise linear upper bound
Without loss of generality we shall introduce the bound for the complementary first order loss function. Consider a random variable ω with support Ω. From Lemma 4, L(x, ω) is convex in x regardless of the distribution of ω. Given an interval [a, b] ∈ R, it is possible to construct an upper bound by exploiting the very same definition of convexity, that is by constructing a straight line L ub (x, ω) between the two points (a, L(a, ω)) and (b , L(b, ω)). The slope (α) and the intercept (β) of this line can be easily computed The upper bound is then We can improve the quality of this bound by partitioning the domain R of L(x, ω) into N disjoint regions D i = [a i , b i ], i = 1, . . . , N . The selected regions must be all compact and adjacent. Because of the convexity of L(x, ω) the bound can be then applied to each of these regions considered separately. However, since L(x, ω) is defined over R, it is not possible to guarantee a complete covering of the domain by using compact regions. We must therefore add two extreme it is easy to derive equations for the lines associated with these two extra regions. In particular, we associate with D 0 a horizontal line with slope α = 0 and intercept β = L(a 1 , ω), and with D N +1 a line with slope α = 1 and intercept β Also in this case, we must then decide how to partition the domain R into N + 2 intervals D 0 , . . . , D N +1 to obtain a tight bound. Once more, the optimal partitioning strategy will depend on the probability distribution of the random variable ω.

Minimax piecewise linear upper bound
We discuss a minimax strategy for generating a piecewise linear upper bound of the (complementary) first order loss function L(x, ω). In this strategy, we partition of the domain R of x into a predefined number of regions N + 2 in order to minimise the maximum approximation error. Note that, since this domain is not compact, one needs at least two regions to derive a piecewise linear upper bound.
Consider a random variable ω and the associated complementary first order loss function assume that the domain R of x is partitioned into N + 2 disjoint adjacent subregions Let L i ub (x, ω) be the linear segment of L ub (x, ω) over D i , for i = 0, . . . , N + 1.
Lemma 13. Consider L i ub (x, ω), where i = 1, . . . , N ; the maximum approximation error between L i ub (x, ω) and L(x, ω) will be attained for Proof. The idea here is to derive a line that is tangent to L(x, ω) and that has a slope equal to that of the i-th linear segment of L ub (x, ω). We have already discussed in Lemma 11 that the equation of the tangent to L(x, ω) at a given pointx i is The slope G ω (x i ) only depends onx i . To find a tangent with a slope equal to that of the i-th linear segment of L ub (x, ω), we simply let and invert the cumulative distribution function.
Note that the maximum approximation error for the linear segment over D 0 is L(a 1 , ω) and the maximum approximation error for the linear segment over D N +1 is L(b N , ω) − b N . This can be inferred from the fact that L(x, ω) monotonically approaches 0 for x → −∞ and x for x → ∞. Theorem 6. D 0 , . . . , D N +1 is an optimal partition under a minimax strategy, if and only if the maximum approximation error between L(x, ω) and each linear segment of L ub (x, ω) is the same.
Proof. The proof of this theorem can be obtained from Lemma 13 and from Theorem 4. In particular, the key insight needed to understand this result is the following. In Theorem 4 we showed that the approximation errors at breakpoints for the piecewise linear lower bound presented are all equal to each other and also equal to the maximum approximation error; furthermore, in Lemma 11 we showed that the i-th piecewise linear segment of this lower bound agrees with the original function at point b i , where Ω i = [a i , b i ] is the i-th partition of the support of Z, for i = 1, . . . , N . Since the first order loss function is convex and we know the maximum approximation error, by shifting up the piecewise linear lower bound by a value equal to the maximum approximation error we immediately obtain a piecewise linear upper bound comprising N + 1 segments. This upper bound agrees with the original function at E[Z|Ω i ], for i = 1, . . . , N . The maximum approximation error will be attained at those points in which the lower bound was tangent to the original function, that is a 1 , b 1 , b 2 , . . . , b N . By using a reasoning similar to the one developed for Theorem 4, it is possible to show that, if we increase or decrease at least one E[Z|Ω i ], the maximum approximation error can only increase.
By using this result it is possible to derive a set of equations that can be solved for computing an optimal partitioning. Let us consider the maximum approximation error e i associated with the i-th linear segment of L ub (x, ω), this can be expressed as where i = 1, . . . , N ; furthermore e 0 = L(a 1 , ω) and e N +1 = L(b N , ω) − b N . Since we have N + 2 segments to check, we must solve a system comprising the following N + 1 equations e 0 = e i for i = 1, . . . , N + 1 under the following restrictions The system involves N + 1 variables, each of which identifies the boundary between two disjoint adjacent regions D i and D i+1 .
Theorem 7. Assume that the probability density function of ω is symmetric about a mean valueω. Then, under a minimax strategy, if D 0 , . . . , D N +1 is an optimal partition of the domain, breakpoints will be symmetric about the mean valueω.
Proof. This follows from Lemma 6 and Theorem 6.
In this case, by exploiting the symmetry of the piecewise linear approximation, an optimal partitioning can be derived by solving a smaller system comprising ⌈(N + 1)/2⌉ equations, where N + 2 is the number of regions D i and ⌈x⌉ rounds x to the next integer value.
As in the case of Jensen's bound, equations in the above system are nonlinear and do not admit a closed form solution in the general case. For sake of completeness, we will briefly discuss next how to derive the system of nonlinear equations for the case of a standard normal random variable Z. However, one should note that in practice, by exploiting the properties illustrated in the proof of Theorem 6, one does not need to solve a new system of nonlinear equations to derive the piecewise linear upper bound. All information needed, i.e. maximum approximation error at breakpoints and locations of the breakpoint, are in fact immediately available as soon as the system of equation presented for the piecewise linear lower bound is solved ( Table 1).
The upper bound presented is closely related to a well-known inequality from stochastic programming, see e.g. [6], p. 168, [5], p. 316, and [2], pp. 291-293. As pointed out in [6], p. 168, Edmundson-Madanski's upper bound can be seen as a bound where the original distribution is replaced by a two point distribution and the problem itself is unchanged, or it can be viewed as a bound where the distribution is left unchanged and the original function is replaced by a linear affine function represented by a straight line. The above discussion clearly demonstrates the dual nature of this upper bound.

Normal distribution
We will next discuss the system of equations that leads to an optimal partitioning for the case of a standard Normal random variable Z. This partitioning leads to a piecewise linear approximation that is, in fact, easily extended to the general case of a normally distributed variable ζ with mean µ and standard deviation σ via Lemma 7. Also for this second approximation this equation suggests that the error is independent of µ and proportional to σ.
Consider a partitioning for the domain of x in L(x, ω) into N + 2 adjacent regions Also in this case, we shall use Lemma 8 for expressing L(x, Z), and we will exploit the close connections between finding a local minimum and solving a set of nonlinear equations. We will therefore use the Gauss-Newton method to minimize the following sum of squares This minimisation problem can be solved by software packages such as Mathematica (see NMinimize).

Numerical examples
A two-segment piecewise linear upper bound for the complementary first order loss function of a standard Normal random variable Z is shown in Fig. 5. This bound has been obtained, under the minimax criterion previously described, by considering a single breakpoint in the domain, i.e. x = 0. Of course, the maximum error of this piecewise linear approximation occurs for x = ±∞ and it is equal to 1/ √ 2π. It is easy to observe that this upper bound can be obtained by adding to the classical Jensen's lower bound presented in Fig. 1 a constant value equal to its maximum approximation error, i.e. 1/ √ 2π. We next present a more interesting case, in which the domain has been split into five regions (Fig. 6). Breakpoints are positioned at x ∈ {±1.43535, ±0.415223}. These were the locations at which the maximum error, i.e. 0.0339052, was observed in Fig.  2. Also in this case, the five-segment piecewise linear upper bound can be obtained by adding to the five-segment piecewise Jensen's lower bound a value equal to its maximum approximation error.
Finally, in Fig. 7, we show an example in which we exploited Lemma 7 to obtain, from the approximation presented in Fig. 6, the five-segment piecewise linear upper bound for L(x, ζ), where ζ is a normally distributed random variable with mean µ = 20 and standard deviation σ = 5. The maximum error is σ0.0339052 and it is observed at x ∈ {±∞, σ(±0.886942) + µ, µ}.

Conclusions
We summarised a number of distribution independent results for the first order loss function and its complementary function. We then focused on symmetric distributions and on normal distributions; for these we discussed ad-hoc results. To the best of our knowledge a comprehensive analysis of results concerning the first order loss function seems to be missing in the literature. The first contribution of this work was to fill this gap in the literature. Based on the results discussed, we developed effective piecewise linear approximation strategies based on a minimax framework. This is the second contribution of our work. More specifically, we developed piecewise linear upper and lower bounds for the first order loss function and its complementary function. These bounds rely on constant parameters that are independent of the means and standard deviation of the normal distribution considered. We discussed how to compute optimal parameters that minimise the maximum approximation error and we also provided a table with pre-computed optimal parameters for piecewise bound with up to eleven segments. These bounds can be easily embedded in existing MILP models.