From Jason Turner

[rand.dist.samp]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp2l10q0lp/{from.md → to.md} +77 -90
tmp/tmp2l10q0lp/{from.md → to.md} RENAMED
@@ -2,20 +2,17 @@
2
 
3
  ##### Class template `discrete_distribution` <a id="rand.dist.samp.discrete">[[rand.dist.samp.discrete]]</a>
4
 
5
  A `discrete_distribution` random number distribution produces random
6
  integers i, 0 ≤ i < n, distributed according to the discrete probability
7
- function $$%
8
- P(i\,|\,p_0,\ldots,p_{n-1})
9
- = p_i
10
- \; \mbox{.}$$
11
 
12
  Unless specified otherwise, the distribution parameters are calculated
13
- as: $p_k = {w_k / S} \; \mbox{ for } k = 0, \ldots, n\!-\!1$ , in which
14
- the values wₖ, commonly known as the *weights* , shall be non-negative,
15
- non-NaN, and non-infinity. Moreover, the following relation shall hold:
16
- 0 < S = w₀ + + wₙ₋₁.
17
 
18
  ``` cpp
19
  template<class IntType = int>
20
  class discrete_distribution {
21
  public:
@@ -61,15 +58,18 @@ p₀ = 1.
61
  ``` cpp
62
  template<class InputIterator>
63
  discrete_distribution(InputIterator firstW, InputIterator lastW);
64
  ```
65
 
66
- *Requires:* `InputIterator` shall satisfy the requirements of an input
67
- iterator ([[input.iterators]]). Moreover,
68
- `iterator_traits<InputIterator>::value_type` shall denote a type that is
69
- convertible to `double`. If `firstW == lastW`, let n = 1 and w₀ = 1.
70
- Otherwise, [`firstW`, `lastW`) shall form a sequence w of length n > 0.
 
 
 
71
 
72
  *Effects:* Constructs a `discrete_distribution` object with
73
  probabilities given by the formula above.
74
 
75
  ``` cpp
@@ -81,22 +81,22 @@ discrete_distribution(initializer_list<double> wl);
81
  ``` cpp
82
  template<class UnaryOperation>
83
  discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
84
  ```
85
 
86
- *Requires:* Each instance of type `UnaryOperation` shall be a function
87
- object ([[function.objects]]) whose return type shall be convertible to
88
- `double`. Moreover, `double` shall be convertible to the type of
89
- `UnaryOperation`’s sole parameter. If `nw` = 0, let n = 1, otherwise let
90
- n = `nw`. The relation 0 < δ = (`xmax` - `xmin`) / n shall hold.
91
 
92
  *Effects:* Constructs a `discrete_distribution` object with
93
  probabilities given by the formula above, using the following values: If
94
  `nw` = 0, let w₀ = 1. Otherwise, let wₖ = `fw`(`xmin` + k ⋅ δ + δ / 2)
95
  for k = 0, …, n - 1.
96
 
97
- *Complexity:* The number of invocations of `fw` shall not exceed n.
98
 
99
  ``` cpp
100
  vector<double> probabilities() const;
101
  ```
102
 
@@ -107,27 +107,21 @@ k = 0, …, n-1.
107
  ##### Class template `piecewise_constant_distribution` <a id="rand.dist.samp.pconst">[[rand.dist.samp.pconst]]</a>
108
 
109
  A `piecewise_constant_distribution` random number distribution produces
110
  random numbers x, b₀ ≤ x < bₙ, uniformly distributed over each
111
  subinterval [ bᵢ, bᵢ₊₁ ) according to the probability density function
112
- $$%
113
- p(x\,|\,b_0,\ldots,b_n,\;\rho_0,\ldots,\rho_{n-1})
114
- = \rho_i
115
- \; \mbox{,}
116
- \mbox{ for } b_i \le x < b_{i+1}
117
- \; \mbox{.}$$
118
 
119
  The n + 1 distribution parameters bᵢ, also known as this distribution’s
120
- *interval boundaries* , shall satisfy the relation bᵢ < bᵢ₊₁ for
121
- i = 0, …, n-1. Unless specified otherwise, the remaining n distribution
122
- parameters are calculated as: $$%
123
- \rho_k = \;
124
- \frac{w_k}{S \cdot (b_{k+1}-b_k)}
125
- \; \mbox{ for } k = 0, \ldots, n\!-\!1,$$ in which the values wₖ,
126
- commonly known as the *weights* , shall be non-negative, non-NaN, and
127
- non-infinity. Moreover, the following relation shall hold:
128
- 0 < S = w₀ + ⋯ + wₙ₋₁.
129
 
130
  ``` cpp
131
  template<class RealType = double>
132
  class piecewise_constant_distribution {
133
  public:
@@ -175,59 +169,60 @@ n = 1, ρ₀ = 1, b₀ = 0, and b₁ = 1.
175
  template<class InputIteratorB, class InputIteratorW>
176
  piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
177
  InputIteratorW firstW);
178
  ```
179
 
180
- *Requires:* `InputIteratorB` and `InputIteratorW` shall each satisfy the
181
- requirements of an input iterator
182
- (Table  [[tab:iterator.input.requirements]]) type. Moreover,
183
- `iterator_traits<InputIteratorB>::value_type` and
184
- `iterator_traits<InputIteratorW>::value_type` shall each denote a type
185
- that is convertible to `double`. If `firstB == lastB` or
186
- `++firstB == lastB`, let n = 1, w₀ = 1, b₀ = 0, and b₁ = 1. Otherwise,
187
- [`firstB`, `lastB`) shall form a sequence b of length n+1, the length of
188
- the sequence w starting from `firstW` shall be at least n, and any wₖ
189
- for k n shall be ignored by the distribution.
 
 
 
190
 
191
  *Effects:* Constructs a `piecewise_constant_distribution` object with
192
  parameters as specified above.
193
 
194
  ``` cpp
195
  template<class UnaryOperation>
196
  piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);
197
  ```
198
 
199
- *Requires:* Each instance of type `UnaryOperation` shall be a function
200
- object ([[function.objects]]) whose return type shall be convertible to
201
- `double`. Moreover, `double` shall be convertible to the type of
202
- `UnaryOperation`’s sole parameter.
203
 
204
  *Effects:* Constructs a `piecewise_constant_distribution` object with
205
  parameters taken or calculated from the following values: If
206
  `bl.size()` < 2, let n = 1, w₀ = 1, b₀ = 0, and b₁ = 1. Otherwise, let
207
  [`bl.begin()`, `bl.end()`) form a sequence b₀, …, bₙ, and let
208
  wₖ = `fw`((bₖ₊₁ + bₖ) / 2) for k = 0, …, n - 1.
209
 
210
- *Complexity:* The number of invocations of `fw` shall not exceed n.
211
 
212
  ``` cpp
213
  template<class UnaryOperation>
214
  piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
215
  ```
216
 
217
- *Requires:* Each instance of type `UnaryOperation` shall be a function
218
- object ([[function.objects]]) whose return type shall be convertible to
219
- `double`. Moreover, `double` shall be convertible to the type of
220
- `UnaryOperation`’s sole parameter. If `nw` = 0, let n = 1, otherwise let
221
- n = `nw`. The relation 0 < δ = (`xmax` - `xmin`) / n shall hold.
222
 
223
  *Effects:* Constructs a `piecewise_constant_distribution` object with
224
  parameters taken or calculated from the following values: Let
225
  bₖ = `xmin` + k ⋅ δ for k = 0, …, n, and wₖ = `fw`(bₖ + δ / 2) for
226
  k = 0, …, n - 1.
227
 
228
- *Complexity:* The number of invocations of `fw` shall not exceed n.
229
 
230
  ``` cpp
231
  vector<result_type> intervals() const;
232
  ```
233
 
@@ -245,29 +240,24 @@ k = 0, …, n-1.
245
 
246
  ##### Class template `piecewise_linear_distribution` <a id="rand.dist.samp.plinear">[[rand.dist.samp.plinear]]</a>
247
 
248
  A `piecewise_linear_distribution` random number distribution produces
249
  random numbers x, b₀ ≤ x < bₙ, distributed over each subinterval
250
- [ bᵢ, bᵢ₊₁ ) according to the probability density function $$%
251
- p(x\,|\,b_0,\ldots,b_n,\;\rho_0,\ldots,\rho_n)
252
- = \rho_i \cdot {\frac{b_{i+1} - x}{b_{i+1} - b_i}}
253
  + \rho_{i+1} \cdot {\frac{x - b_i}{b_{i+1} - b_i}}
254
- \; \mbox{,}
255
- \mbox{ for } b_i \le x < b_{i+1}
256
- \; \mbox{.}$$
257
 
258
  The n + 1 distribution parameters bᵢ, also known as this distribution’s
259
  *interval boundaries* , shall satisfy the relation bᵢ < bᵢ₊₁ for
260
  i = 0, …, n - 1. Unless specified otherwise, the remaining n + 1
261
- distribution parameters are calculated as
262
- $\rho_k = {w_k / S} \; \mbox{ for } k = 0, \ldots, n$, in which the
263
- values wₖ, commonly known as the *weights at boundaries* , shall be
264
- non-negative, non-NaN, and non-infinity. Moreover, the following
265
- relation shall hold: $$%
266
- 0 < S = \frac{1}{2}
267
- \cdot \sum_{k=0}^{n-1} (w_k + w_{k+1}) \cdot (b_{k+1} - b_k)
268
- \; \mbox{.}$$
269
 
270
  ``` cpp
271
  template<class RealType = double>
272
  class piecewise_linear_distribution {
273
  public:
@@ -314,58 +304,55 @@ n = 1, ρ₀ = ρ₁ = 1, b₀ = 0, and b₁ = 1.
314
  template<class InputIteratorB, class InputIteratorW>
315
  piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
316
  InputIteratorW firstW);
317
  ```
318
 
319
- *Requires:* `InputIteratorB` and `InputIteratorW` shall each satisfy the
320
- requirements of an input iterator
321
- (Table  [[tab:iterator.input.requirements]]) type. Moreover,
322
- `iterator_traits<InputIteratorB>::value_type` and
323
- `iterator_traits<InputIteratorW>::value_type` shall each denote a type
324
- that is convertible to `double`. If `firstB == lastB` or
325
- `++firstB == lastB`, let n = 1, ρ₀ = ρ₁ = 1, b₀ = 0, and b = 1.
326
- Otherwise, [`firstB`, `lastB`) shall form a sequence b of length n+1,
327
- the length of the sequence w starting from `firstW` shall be at least
328
- n+1, and any wₖ for k ≥ n+1 shall be ignored by the distribution.
329
 
330
  *Effects:* Constructs a `piecewise_linear_distribution` object with
331
  parameters as specified above.
332
 
333
  ``` cpp
334
  template<class UnaryOperation>
335
  piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw);
336
  ```
337
 
338
- *Requires:* Each instance of type `UnaryOperation` shall be a function
339
- object ([[function.objects]]) whose return type shall be convertible to
340
- `double`. Moreover, `double` shall be convertible to the type of
341
- `UnaryOperation`’s sole parameter.
342
 
343
  *Effects:* Constructs a `piecewise_linear_distribution` object with
344
  parameters taken or calculated from the following values: If
345
  `bl.size()` < 2, let n = 1, ρ₀ = ρ₁ = 1, b₀ = 0, and b₁ = 1. Otherwise,
346
  let [`bl.begin(),` `bl.end()`) form a sequence b₀, …, bₙ, and let
347
  wₖ = `fw`(bₖ) for k = 0, …, n.
348
 
349
- *Complexity:* The number of invocations of `fw` shall not exceed n+1.
350
 
351
  ``` cpp
352
  template<class UnaryOperation>
353
  piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
354
  ```
355
 
356
- *Requires:* Each instance of type `UnaryOperation` shall be a function
357
- object ([[function.objects]]) whose return type shall be convertible to
358
- `double`. Moreover, `double` shall be convertible to the type of
359
- `UnaryOperation`’s sole parameter. If `nw` = 0, let n = 1, otherwise let
360
- n = `nw`. The relation 0 < δ = (`xmax` - `xmin`) / n shall hold.
361
 
362
  *Effects:* Constructs a `piecewise_linear_distribution` object with
363
  parameters taken or calculated from the following values: Let
364
  bₖ = `xmin` + k ⋅ δ for k = 0, …, n, and wₖ = `fw`(bₖ) for k = 0, …, n.
365
 
366
- *Complexity:* The number of invocations of `fw` shall not exceed n+1.
367
 
368
  ``` cpp
369
  vector<result_type> intervals() const;
370
  ```
371
 
 
2
 
3
  ##### Class template `discrete_distribution` <a id="rand.dist.samp.discrete">[[rand.dist.samp.discrete]]</a>
4
 
5
  A `discrete_distribution` random number distribution produces random
6
  integers i, 0 ≤ i < n, distributed according to the discrete probability
7
+ function $$P(i \,|\, p_0, \dotsc, p_{n-1}) = p_i \text{ .}$$
 
 
 
8
 
9
  Unless specified otherwise, the distribution parameters are calculated
10
+ as: pₖ = {wₖ / S} for k = 0, , n - 1, in which the values wₖ, commonly
11
+ known as the *weights* , shall be non-negative, non-NaN, and
12
+ non-infinity. Moreover, the following relation shall hold:
13
+ $0 < S = w_0 + \dotsb + w_{n - 1}$.
14
 
15
  ``` cpp
16
  template<class IntType = int>
17
  class discrete_distribution {
18
  public:
 
58
  ``` cpp
59
  template<class InputIterator>
60
  discrete_distribution(InputIterator firstW, InputIterator lastW);
61
  ```
62
 
63
+ *Mandates:*
64
+ `is_convertible_v<iterator_traits<InputIterator>::value_type, double>`
65
+ is `true`.
66
+
67
+ *Preconditions:* `InputIterator` meets the *Cpp17InputIterator*
68
+ requirements [[input.iterators]]. If `firstW == lastW`, let n = 1 and
69
+ w₀ = 1. Otherwise, [`firstW`, `lastW`) forms a sequence w of length
70
+ n > 0.
71
 
72
  *Effects:* Constructs a `discrete_distribution` object with
73
  probabilities given by the formula above.
74
 
75
  ``` cpp
 
81
  ``` cpp
82
  template<class UnaryOperation>
83
  discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
84
  ```
85
 
86
+ *Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
87
+ `true`.
88
+
89
+ *Preconditions:* If `nw` = 0, let n = 1, otherwise let n = `nw`. The
90
+ relation 0 < δ = (`xmax` - `xmin`) / n holds.
91
 
92
  *Effects:* Constructs a `discrete_distribution` object with
93
  probabilities given by the formula above, using the following values: If
94
  `nw` = 0, let w₀ = 1. Otherwise, let wₖ = `fw`(`xmin` + k ⋅ δ + δ / 2)
95
  for k = 0, …, n - 1.
96
 
97
+ *Complexity:* The number of invocations of `fw` does not exceed n.
98
 
99
  ``` cpp
100
  vector<double> probabilities() const;
101
  ```
102
 
 
107
  ##### Class template `piecewise_constant_distribution` <a id="rand.dist.samp.pconst">[[rand.dist.samp.pconst]]</a>
108
 
109
  A `piecewise_constant_distribution` random number distribution produces
110
  random numbers x, b₀ ≤ x < bₙ, uniformly distributed over each
111
  subinterval [ bᵢ, bᵢ₊₁ ) according to the probability density function
112
+ $$p(x \,|\, b_0, \dotsc, b_n, \; \rho_0, \dotsc, \rho_{n-1}) = \rho_i
113
+ \text{ , for $b_i \le x < b_{i+1}$.}$$
 
 
 
 
114
 
115
  The n + 1 distribution parameters bᵢ, also known as this distribution’s
116
+ *interval boundaries* , shall satisfy the relation $b_i < b_{i + 1}$ for
117
+ i = 0, …, n - 1. Unless specified otherwise, the remaining n
118
+ distribution parameters are calculated as:
119
+ $$\rho_k = \frac{w_k}{S \cdot (b_{k+1}-b_k)} \text{ for } k = 0, \dotsc, n - 1 \text{ ,}$$
120
+ in which the values wₖ, commonly known as the *weights* , shall be
121
+ non-negative, non-NaN, and non-infinity. Moreover, the following
122
+ relation shall hold: 0 < S = w₀ + + wₙ₋₁.
 
 
123
 
124
  ``` cpp
125
  template<class RealType = double>
126
  class piecewise_constant_distribution {
127
  public:
 
169
  template<class InputIteratorB, class InputIteratorW>
170
  piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
171
  InputIteratorW firstW);
172
  ```
173
 
174
+ *Mandates:* Both of
175
+
176
+ - `is_convertible_v<iterator_traits<InputIteratorB>::value_type, double>`
177
+ - `is_convertible_v<iterator_traits<InputIteratorW>::value_type, double>`
178
+
179
+ are `true`.
180
+
181
+ *Preconditions:* `InputIteratorB` and `InputIteratorW` each meet the
182
+ *Cpp17InputIterator* requirements [[input.iterators]]. If
183
+ `firstB == lastB` or `++firstB == lastB`, let n = 1, w₀ = 1, b₀ = 0, and
184
+ b₁ = 1. Otherwise, [`firstB`, `lastB`) forms a sequence b of length n+1,
185
+ the length of the sequence w starting from `firstW` is at least n, and
186
+ any wₖ for k ≥ n are ignored by the distribution.
187
 
188
  *Effects:* Constructs a `piecewise_constant_distribution` object with
189
  parameters as specified above.
190
 
191
  ``` cpp
192
  template<class UnaryOperation>
193
  piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);
194
  ```
195
 
196
+ *Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
197
+ `true`.
 
 
198
 
199
  *Effects:* Constructs a `piecewise_constant_distribution` object with
200
  parameters taken or calculated from the following values: If
201
  `bl.size()` < 2, let n = 1, w₀ = 1, b₀ = 0, and b₁ = 1. Otherwise, let
202
  [`bl.begin()`, `bl.end()`) form a sequence b₀, …, bₙ, and let
203
  wₖ = `fw`((bₖ₊₁ + bₖ) / 2) for k = 0, …, n - 1.
204
 
205
+ *Complexity:* The number of invocations of `fw` does not exceed n.
206
 
207
  ``` cpp
208
  template<class UnaryOperation>
209
  piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
210
  ```
211
 
212
+ *Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
213
+ `true`.
214
+
215
+ *Preconditions:* If `nw` = 0, let n = 1, otherwise let n = `nw`. The
216
+ relation 0 < δ = (`xmax` - `xmin`) / n holds.
217
 
218
  *Effects:* Constructs a `piecewise_constant_distribution` object with
219
  parameters taken or calculated from the following values: Let
220
  bₖ = `xmin` + k ⋅ δ for k = 0, …, n, and wₖ = `fw`(bₖ + δ / 2) for
221
  k = 0, …, n - 1.
222
 
223
+ *Complexity:* The number of invocations of `fw` does not exceed n.
224
 
225
  ``` cpp
226
  vector<result_type> intervals() const;
227
  ```
228
 
 
240
 
241
  ##### Class template `piecewise_linear_distribution` <a id="rand.dist.samp.plinear">[[rand.dist.samp.plinear]]</a>
242
 
243
  A `piecewise_linear_distribution` random number distribution produces
244
  random numbers x, b₀ ≤ x < bₙ, distributed over each subinterval
245
+ [bᵢ, bᵢ₊₁) according to the probability density function
246
+ $$p(x \,|\, b_0, \dotsc, b_n, \; \rho_0, \dotsc, \rho_n)
247
+ = \rho_{i} \cdot {\frac{b_{i+1} - x}{b_{i+1} - b_i}}
248
  + \rho_{i+1} \cdot {\frac{x - b_i}{b_{i+1} - b_i}}
249
+ \text{ , for $b_i \le x < b_{i+1}$.}$$
 
 
250
 
251
  The n + 1 distribution parameters bᵢ, also known as this distribution’s
252
  *interval boundaries* , shall satisfy the relation bᵢ < bᵢ₊₁ for
253
  i = 0, …, n - 1. Unless specified otherwise, the remaining n + 1
254
+ distribution parameters are calculated as ρₖ = {wₖ / S} for k = 0, …, n,
255
+ in which the values wₖ, commonly known as the *weights at boundaries* ,
256
+ shall be non-negative, non-NaN, and non-infinity. Moreover, the
257
+ following relation shall hold:
258
+ $$0 < S = \frac{1}{2} \cdot \sum_{k=0}^{n-1} (w_k + w_{k+1}) \cdot (b_{k+1} - b_k) \text{ .}$$
 
 
 
259
 
260
  ``` cpp
261
  template<class RealType = double>
262
  class piecewise_linear_distribution {
263
  public:
 
304
  template<class InputIteratorB, class InputIteratorW>
305
  piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
306
  InputIteratorW firstW);
307
  ```
308
 
309
+ *Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
310
+ `true`.
311
+
312
+ *Preconditions:* `InputIteratorB` and `InputIteratorW` each meet the
313
+ *Cpp17InputIterator* requirements [[input.iterators]]. If
314
+ `firstB == lastB` or `++firstB == lastB`, let n = 1, ρ₀ = ρ₁ = 1,
315
+ b₀ = 0, and b₁ = 1. Otherwise, [`firstB`, `lastB`) forms a sequence b of
316
+ length n+1, the length of the sequence w starting from `firstW` is at
317
+ least n+1, and any w for k n + 1 are ignored by the distribution.
 
318
 
319
  *Effects:* Constructs a `piecewise_linear_distribution` object with
320
  parameters as specified above.
321
 
322
  ``` cpp
323
  template<class UnaryOperation>
324
  piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw);
325
  ```
326
 
327
+ *Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
328
+ `true`.
 
 
329
 
330
  *Effects:* Constructs a `piecewise_linear_distribution` object with
331
  parameters taken or calculated from the following values: If
332
  `bl.size()` < 2, let n = 1, ρ₀ = ρ₁ = 1, b₀ = 0, and b₁ = 1. Otherwise,
333
  let [`bl.begin(),` `bl.end()`) form a sequence b₀, …, bₙ, and let
334
  wₖ = `fw`(bₖ) for k = 0, …, n.
335
 
336
+ *Complexity:* The number of invocations of `fw` does not exceed n+1.
337
 
338
  ``` cpp
339
  template<class UnaryOperation>
340
  piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
341
  ```
342
 
343
+ *Mandates:* `is_invocable_r_v<double, UnaryOperation&, double>` is
344
+ `true`.
345
+
346
+ *Preconditions:* If `nw` = 0, let n = 1, otherwise let n = `nw`. The
347
+ relation 0 < δ = (`xmax` - `xmin`) / n holds.
348
 
349
  *Effects:* Constructs a `piecewise_linear_distribution` object with
350
  parameters taken or calculated from the following values: Let
351
  bₖ = `xmin` + k ⋅ δ for k = 0, …, n, and wₖ = `fw`(bₖ) for k = 0, …, n.
352
 
353
+ *Complexity:* The number of invocations of `fw` does not exceed n+1.
354
 
355
  ``` cpp
356
  vector<result_type> intervals() const;
357
  ```
358