time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (5610B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2020 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # iterTriangularSeq
     22 
     23 > Create an iterator which generates a sequence of [triangular numbers][oeis-a000217].
     24 
     25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
     26 
     27 <section class="intro">
     28 
     29 The [triangular numbers][triangular-number] are the integer sequence
     30 
     31 <!-- <equation class="equation" label="eq:triangular_numbers_sequence" align="center" raw="0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, \ldots" alt="Triangular number sequence"> -->
     32 
     33 <div class="equation" align="center" data-raw-text="0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, \ldots" data-equation="eq:triangular_numbers_sequence">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@7000a1b5cd08bb73f2dfe04976524042ab3b580d/lib/node_modules/@stdlib/math/iter/sequences/triangular/docs/img/equation_triangular_numbers_sequence.svg" alt="Triangular number sequence">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 starting at the 0th [triangular number][triangular-number].
     41 
     42 [Triangular numbers][triangular-number] are given by the following explicit formulas
     43 
     44 <!-- <equation class="equation" label="eq:triangular_numbers" align="center" raw="T_n = \sum_{i=1}^{n} i = 1 + 2 + 3 + \ldots + n = \frac{n(n+1)}{2} = \binom{n+1}{2}" alt="Triangular number formulas"> -->
     45 
     46 <div class="equation" align="center" data-raw-text="T_n = \sum_{i=1}^{n} i = 1 + 2 + 3 + \ldots + n = \frac{n(n+1)}{2} = \binom{n+1}{2}" data-equation="eq:triangular_numbers">
     47     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@7000a1b5cd08bb73f2dfe04976524042ab3b580d/lib/node_modules/@stdlib/math/iter/sequences/triangular/docs/img/equation_triangular_numbers.svg" alt="Triangular number formulas">
     48     <br>
     49 </div>
     50 
     51 <!-- </equation> -->
     52 
     53 where the last formula corresponds to a [binomial coefficient][@stdlib/math/base/special/binomcoef], representing the number of distinct pairs that can be selected from `n+1` items.
     54 
     55 </section>
     56 
     57 <!-- /.intro -->
     58 
     59 <!-- Package usage documentation. -->
     60 
     61 <section class="usage">
     62 
     63 ## Usage
     64 
     65 ```javascript
     66 var iterTriangularSeq = require( '@stdlib/math/iter/sequences/triangular' );
     67 ```
     68 
     69 #### iterTriangularSeq( \[options] )
     70 
     71 Returns an iterator which generates a sequence of [triangular numbers][triangular-number].
     72 
     73 ```javascript
     74 var it = iterTriangularSeq();
     75 // returns <Object>
     76 
     77 var v = it.next().value;
     78 // returns 0
     79 
     80 v = it.next().value;
     81 // returns 1
     82 
     83 v = it.next().value;
     84 // returns 3
     85 
     86 v = it.next().value;
     87 // returns 6
     88 
     89 v = it.next().value;
     90 // returns 10
     91 
     92 // ...
     93 ```
     94 
     95 The returned iterator protocol-compliant object has the following properties:
     96 
     97 -   **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished.
     98 -   **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object.
     99 
    100 The function supports the following `options`:
    101 
    102 -   **iter**: number of iterations. Default: `134217727`.
    103 
    104 By default, the function returns a finite iterator to avoid exceeding the maximum safe double-precision floating-point integer. To adjust the number of iterations, set the `iter` option.
    105 
    106 ```javascript
    107 var opts = {
    108     'iter': 2
    109 };
    110 var it = iterTriangularSeq( opts );
    111 // returns <Object>
    112 
    113 var v = it.next().value;
    114 // returns 0
    115 
    116 v = it.next().value;
    117 // returns 1
    118 
    119 var bool = it.next().done;
    120 // returns true
    121 ```
    122 
    123 </section>
    124 
    125 <!-- /.usage -->
    126 
    127 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    128 
    129 <section class="notes">
    130 
    131 ## Notes
    132 
    133 -   If an environment supports `Symbol.iterator`, the returned iterator is iterable.
    134 
    135 </section>
    136 
    137 <!-- /.notes -->
    138 
    139 <!-- Package usage examples. -->
    140 
    141 <section class="examples">
    142 
    143 ## Examples
    144 
    145 <!-- eslint no-undef: "error" -->
    146 
    147 ```javascript
    148 var iterTriangularSeq = require( '@stdlib/math/iter/sequences/triangular' );
    149 
    150 // Create an iterator:
    151 var opts = {
    152     'iter': 100
    153 };
    154 var it = iterTriangularSeq( opts );
    155 
    156 // Perform manual iteration...
    157 var v;
    158 while ( true ) {
    159     v = it.next();
    160     if ( v.done ) {
    161         break;
    162     }
    163     console.log( v.value );
    164 }
    165 ```
    166 
    167 </section>
    168 
    169 <!-- /.examples -->
    170 
    171 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    172 
    173 <section class="references">
    174 
    175 </section>
    176 
    177 <!-- /.references -->
    178 
    179 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    180 
    181 <section class="links">
    182 
    183 [oeis-a000217]: https://oeis.org/A000217
    184 
    185 [triangular-number]: https://en.wikipedia.org/wiki/Triangular_number
    186 
    187 [@stdlib/math/base/special/binomcoef]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/binomcoef
    188 
    189 </section>
    190 
    191 <!-- /.links -->