time-to-botec

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

README.md (5737B)


      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 # iterFactorialsSeq
     22 
     23 > Create an iterator which generates a sequence of [factorials][oeis-a000142].
     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 [factorial][factorial-function] function may be defined as the product
     30 
     31 <!-- <equation class="equation" label="eq:factorial_function" align="center" raw="n! = \prod_{k=1}^n k" alt="Factorial function definition"> -->
     32 
     33 <div class="equation" align="center" data-raw-text="n! = \prod_{k=1}^n k" data-equation="eq:factorial_function">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@aa77a2f6e76d2e9da5b49bffa45ee5167d6c16e1/lib/node_modules/@stdlib/math/iter/sequences/factorials/docs/img/equation_factorial_function.svg" alt="Factorial function definition">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 or according to the recurrence relation
     41 
     42 <!-- <equation class="equation" label="eq:factorial_recurrence_relation" align="center" raw="n! = \begin{cases}1 & \textrm{if } n = 0,\\(n-1)! \times n & \textrm{if } n > 1\end{cases}" alt="Factorial function recurrence relation"> -->
     43 
     44 <div class="equation" align="center" data-raw-text="n! = \begin{cases}1 &amp; \textrm{if } n = 0,\\(n-1)! \times n &amp; \textrm{if } n &gt; 1\end{cases}" data-equation="eq:factorial_recurrence_relation">
     45     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@aa77a2f6e76d2e9da5b49bffa45ee5167d6c16e1/lib/node_modules/@stdlib/math/iter/sequences/factorials/docs/img/equation_factorial_recurrence_relation.svg" alt="Factorial function recurrence relation">
     46     <br>
     47 </div>
     48 
     49 <!-- </equation> -->
     50 
     51 Following the convention for an [empty product][empty-product], in all definitions,
     52 
     53 <!-- <equation class="equation" label="eq:zero_factorial" align="center" raw="0! = 1" alt="Zero factorial"> -->
     54 
     55 <div class="equation" align="center" data-raw-text="0! = 1" data-equation="eq:zero_factorial">
     56     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@aa77a2f6e76d2e9da5b49bffa45ee5167d6c16e1/lib/node_modules/@stdlib/math/iter/sequences/factorials/docs/img/equation_zero_factorial.svg" alt="Zero factorial">
     57     <br>
     58 </div>
     59 
     60 <!-- </equation> -->
     61 
     62 </section>
     63 
     64 <!-- /.intro -->
     65 
     66 <!-- Package usage documentation. -->
     67 
     68 <section class="usage">
     69 
     70 ## Usage
     71 
     72 ```javascript
     73 var iterFactorialsSeq = require( '@stdlib/math/iter/sequences/factorials' );
     74 ```
     75 
     76 #### iterFactorialsSeq( \[options] )
     77 
     78 Returns an iterator which generates a sequence of factorials.
     79 
     80 ```javascript
     81 var it = iterFactorialsSeq();
     82 // returns <Object>
     83 
     84 var v = it.next().value;
     85 // returns 1
     86 
     87 v = it.next().value;
     88 // returns 1
     89 
     90 v = it.next().value;
     91 // returns 2
     92 
     93 v = it.next().value;
     94 // returns 6
     95 
     96 v = it.next().value;
     97 // returns 24
     98 
     99 // ...
    100 ```
    101 
    102 The returned iterator protocol-compliant object has the following properties:
    103 
    104 -   **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.
    105 -   **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object.
    106 
    107 The function supports the following `options`:
    108 
    109 -   **iter**: number of iterations. Default: `1e308`.
    110 
    111 By default, the function returns an infinite iterator (i.e., an iterator which never ends). To limit the number of iterations, set the `iter` option.
    112 
    113 ```javascript
    114 var opts = {
    115     'iter': 2
    116 };
    117 var it = iterFactorialsSeq( opts );
    118 // returns <Object>
    119 
    120 var v = it.next().value;
    121 // returns 1
    122 
    123 v = it.next().value;
    124 // returns 1
    125 
    126 var bool = it.next().done;
    127 // returns true
    128 ```
    129 
    130 </section>
    131 
    132 <!-- /.usage -->
    133 
    134 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    135 
    136 <section class="notes">
    137 
    138 ## Notes
    139 
    140 -   If an environment supports `Symbol.iterator`, the returned iterator is iterable.
    141 
    142 </section>
    143 
    144 <!-- /.notes -->
    145 
    146 <!-- Package usage examples. -->
    147 
    148 <section class="examples">
    149 
    150 ## Examples
    151 
    152 <!-- eslint no-undef: "error" -->
    153 
    154 ```javascript
    155 var iterFactorialsSeq = require( '@stdlib/math/iter/sequences/factorials' );
    156 
    157 // Create an iterator:
    158 var opts = {
    159     'iter': 100
    160 };
    161 var it = iterFactorialsSeq( opts );
    162 
    163 // Perform manual iteration...
    164 var v;
    165 while ( true ) {
    166     v = it.next();
    167     if ( v.done ) {
    168         break;
    169     }
    170     console.log( v.value );
    171 }
    172 ```
    173 
    174 </section>
    175 
    176 <!-- /.examples -->
    177 
    178 <!-- 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. -->
    179 
    180 <section class="references">
    181 
    182 </section>
    183 
    184 <!-- /.references -->
    185 
    186 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    187 
    188 <section class="links">
    189 
    190 [oeis-a000142]: https://oeis.org/A000142
    191 
    192 [factorial-function]: https://en.wikipedia.org/wiki/Factorial
    193 
    194 [empty-product]: https://en.wikipedia.org/wiki/Empty_product
    195 
    196 </section>
    197 
    198 <!-- /.links -->