time-to-botec

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

README.md (5755B)


      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 # iterNegaLucasSeq
     22 
     23 > Create an iterator which generates a [negaLucas sequence][lucas-number].
     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 [negaLucas numbers][lucas-number] are the integer sequence
     30 
     31 <!-- <equation class="equation" label="eq:negalucas_sequence" align="center" raw="2, -1, 3, -4, 7, -11, 18, -29, 47, -76, 123, -199, 322, \ldots" alt="NegaLucas sequence"> -->
     32 
     33 <div class="equation" align="center" data-raw-text="2, -1, 3, -4, 7, -11, 18, -29, 47, -76, 123, -199, 322, \ldots" data-equation="eq:negalucas_sequence">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@aa77a2f6e76d2e9da5b49bffa45ee5167d6c16e1/lib/node_modules/@stdlib/math/iter/sequences/negalucas/docs/img/equation_negalucas_sequence.svg" alt="NegaLucas sequence">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 The sequence is defined by the recurrence relation
     41 
     42 <!-- <equation class="equation" label="eq:negalucas_recurrence_relation" align="center" raw="L_{n-2} = L_{n} - L_{n-1}" alt="NegaLucas sequence recurrence relation"> -->
     43 
     44 <div class="equation" align="center" data-raw-text="L_{n-2} = L_{n} - L_{n-1}" data-equation="eq:negalucas_recurrence_relation">
     45     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@aa77a2f6e76d2e9da5b49bffa45ee5167d6c16e1/lib/node_modules/@stdlib/math/iter/sequences/negalucas/docs/img/equation_negalucas_recurrence_relation.svg" alt="NegaLucas sequence recurrence relation">
     46     <br>
     47 </div>
     48 
     49 <!-- </equation> -->
     50 
     51 which yields
     52 
     53 <!-- <equation class="equation" label="eq:negalucas_lucas" align="center" raw="L_{-n} = (-1)^{n} L_n" alt="NegaLucas relationship to Lucas numbers"> -->
     54 
     55 <div class="equation" align="center" data-raw-text="L_{-n} = (-1)^{n} L_n" data-equation="eq:negalucas_lucas">
     56     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@aa77a2f6e76d2e9da5b49bffa45ee5167d6c16e1/lib/node_modules/@stdlib/math/iter/sequences/negalucas/docs/img/equation_negalucas_lucas.svg" alt="NegaLucas relationship to Lucas numbers">
     57     <br>
     58 </div>
     59 
     60 <!-- </equation> -->
     61 
     62 with seed values `L_0 = 2` and `L_{-1} = -1`.
     63 
     64 </section>
     65 
     66 <!-- /.intro -->
     67 
     68 <!-- Package usage documentation. -->
     69 
     70 <section class="usage">
     71 
     72 ## Usage
     73 
     74 ```javascript
     75 var iterNegaLucasSeq = require( '@stdlib/math/iter/sequences/negalucas' );
     76 ```
     77 
     78 #### iterNegaLucasSeq( \[options] )
     79 
     80 Returns an iterator which generates a [negaLucas sequence][lucas-number].
     81 
     82 ```javascript
     83 var it = iterNegaLucasSeq();
     84 // returns <Object>
     85 
     86 var v = it.next().value;
     87 // returns 2
     88 
     89 v = it.next().value;
     90 // returns -1
     91 
     92 v = it.next().value;
     93 // returns 3
     94 
     95 // ...
     96 ```
     97 
     98 The returned iterator protocol-compliant object has the following properties:
     99 
    100 -   **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.
    101 -   **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object.
    102 
    103 The function supports the following `options`:
    104 
    105 -   **iter**: number of iterations. Default: `77`.
    106 
    107 The returned iterator can only generate the first `77` [negaLucas numbers][lucas-number], as larger [negaLucas numbers][lucas-number] cannot be safely represented in [double-precision floating-point format][ieee754]. By default, the function returns an iterator which generates all `77` numbers. To limit the number of iterations, set the `iter` option.
    108 
    109 ```javascript
    110 var opts = {
    111     'iter': 2
    112 };
    113 var it = iterNegaLucasSeq( opts );
    114 // returns <Object>
    115 
    116 var v = it.next().value;
    117 // returns 2
    118 
    119 v = it.next().value;
    120 // returns -1
    121 
    122 var bool = it.next().done;
    123 // returns true
    124 ```
    125 
    126 </section>
    127 
    128 <!-- /.usage -->
    129 
    130 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    131 
    132 <section class="notes">
    133 
    134 ## Notes
    135 
    136 -   If an environment supports `Symbol.iterator`, the returned iterator is iterable.
    137 
    138 </section>
    139 
    140 <!-- /.notes -->
    141 
    142 <!-- Package usage examples. -->
    143 
    144 <section class="examples">
    145 
    146 ## Examples
    147 
    148 <!-- eslint no-undef: "error" -->
    149 
    150 ```javascript
    151 var iterNegaLucasSeq = require( '@stdlib/math/iter/sequences/negalucas' );
    152 
    153 // Create an iterator:
    154 var it = iterNegaLucasSeq();
    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 [lucas-number]: https://en.wikipedia.org/wiki/Lucas_number
    184 
    185 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
    186 
    187 </section>
    188 
    189 <!-- /.links -->