README.md (5228B)
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 # iterLucasSeq 22 23 > Create an iterator which generates a [Lucas 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 [Lucas numbers][lucas-number] are the integer sequence 30 31 <!-- <equation class="equation" label="eq:lucas_sequence" align="center" raw="2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, \ldots" alt="Lucas 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:lucas_sequence"> 34 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@aa77a2f6e76d2e9da5b49bffa45ee5167d6c16e1/lib/node_modules/@stdlib/math/iter/sequences/lucas/docs/img/equation_lucas_sequence.svg" alt="Lucas 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:lucas_recurrence_relation" align="center" raw="L_n = \begin{cases}2 & \textrm{if}\ n = 0\\1 & \textrm{if}\ n = 1\\L_{n-1} + L_{n-2} & \textrm{if}\ n > 1\end{cases}" alt="Lucas sequence recurrence relation"> --> 43 44 <div class="equation" align="center" data-raw-text="L_n = \begin{cases}2 & \textrm{if}\ n = 0\\1 & \textrm{if}\ n = 1\\L_{n-1} + L_{n-2} & \textrm{if}\ n > 1\end{cases}" data-equation="eq:lucas_recurrence_relation"> 45 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@aa77a2f6e76d2e9da5b49bffa45ee5167d6c16e1/lib/node_modules/@stdlib/math/iter/sequences/lucas/docs/img/equation_lucas_recurrence_relation.svg" alt="Lucas sequence recurrence relation"> 46 <br> 47 </div> 48 49 <!-- </equation> --> 50 51 </section> 52 53 <!-- /.intro --> 54 55 <!-- Package usage documentation. --> 56 57 <section class="usage"> 58 59 ## Usage 60 61 ```javascript 62 var iterLucasSeq = require( '@stdlib/math/iter/sequences/lucas' ); 63 ``` 64 65 #### iterLucasSeq( \[options] ) 66 67 Returns an iterator which generates a [Lucas sequence][lucas-number]. 68 69 ```javascript 70 var it = iterLucasSeq(); 71 // returns <Object> 72 73 var v = it.next().value; 74 // returns 2 75 76 v = it.next().value; 77 // returns 1 78 79 v = it.next().value; 80 // returns 3 81 82 // ... 83 ``` 84 85 The returned iterator protocol-compliant object has the following properties: 86 87 - **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. 88 - **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. 89 90 The function supports the following `options`: 91 92 - **iter**: number of iterations. Default: `77`. 93 94 The returned iterator can only generate the first `77` [Lucas numbers][lucas-number], as larger [Lucas 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. 95 96 ```javascript 97 var opts = { 98 'iter': 2 99 }; 100 var it = iterLucasSeq( opts ); 101 // returns <Object> 102 103 var v = it.next().value; 104 // returns 2 105 106 v = it.next().value; 107 // returns 1 108 109 var bool = it.next().done; 110 // returns true 111 ``` 112 113 </section> 114 115 <!-- /.usage --> 116 117 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 118 119 <section class="notes"> 120 121 ## Notes 122 123 - If an environment supports `Symbol.iterator`, the returned iterator is iterable. 124 125 </section> 126 127 <!-- /.notes --> 128 129 <!-- Package usage examples. --> 130 131 <section class="examples"> 132 133 ## Examples 134 135 <!-- eslint no-undef: "error" --> 136 137 ```javascript 138 var iterLucasSeq = require( '@stdlib/math/iter/sequences/lucas' ); 139 140 // Create an iterator: 141 var it = iterLucasSeq(); 142 143 // Perform manual iteration... 144 var v; 145 while ( true ) { 146 v = it.next(); 147 if ( v.done ) { 148 break; 149 } 150 console.log( v.value ); 151 } 152 ``` 153 154 </section> 155 156 <!-- /.examples --> 157 158 <!-- 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. --> 159 160 <section class="references"> 161 162 </section> 163 164 <!-- /.references --> 165 166 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 167 168 <section class="links"> 169 170 [lucas-number]: https://en.wikipedia.org/wiki/Lucas_number 171 172 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 173 174 </section> 175 176 <!-- /.links -->