README.md (6098B)
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 # iterSquaredTriangularSeq 22 23 > Create an iterator which generates a sequence of [squared triangular numbers][oeis-a000537]. 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 [squared triangular numbers][squared-triangular-number] are the integer sequence 30 31 <!-- <equation class="equation" label="eq:squared_triangular_numbers_sequence" align="center" raw="0, 1, 9, 36, 100, 225, 441, 784, 1296, 2025, 3025, 4356, \ldots" alt="Triangular number sequence"> --> 32 33 <div class="equation" align="center" data-raw-text="0, 1, 9, 36, 100, 225, 441, 784, 1296, 2025, 3025, 4356, \ldots" data-equation="eq:squared_triangular_numbers_sequence"> 34 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@ffa1a1acab2d2c9973d3ad22a5dfc25afd86767a/lib/node_modules/@stdlib/math/iter/sequences/squared-triangular/docs/img/equation_squared_triangular_numbers_sequence.svg" alt="Triangular number sequence"> 35 <br> 36 </div> 37 38 <!-- </equation> --> 39 40 starting at the 0th [squared triangular number][squared-triangular-number]. 41 42 [Triangular numbers][@stdlib/math/iter/sequences/triangular] 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@ffa1a1acab2d2c9973d3ad22a5dfc25afd86767a/lib/node_modules/@stdlib/math/iter/sequences/squared-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 The nth [squared triangular number][squared-triangular-number] is the nth [triangular number][@stdlib/math/iter/sequences/triangular] squared. 56 57 </section> 58 59 <!-- /.intro --> 60 61 <!-- Package usage documentation. --> 62 63 <section class="usage"> 64 65 ## Usage 66 67 ```javascript 68 var iterSquaredTriangularSeq = require( '@stdlib/math/iter/sequences/squared-triangular' ); 69 ``` 70 71 #### iterSquaredTriangularSeq( \[options] ) 72 73 Returns an iterator which generates a sequence of [squared triangular numbers][squared-triangular-number]. 74 75 ```javascript 76 var it = iterSquaredTriangularSeq(); 77 // returns <Object> 78 79 var v = it.next().value; 80 // returns 0 81 82 v = it.next().value; 83 // returns 1 84 85 v = it.next().value; 86 // returns 9 87 88 v = it.next().value; 89 // returns 36 90 91 v = it.next().value; 92 // returns 100 93 94 // ... 95 ``` 96 97 The returned iterator protocol-compliant object has the following properties: 98 99 - **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. 100 - **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object. 101 102 The function supports the following `options`: 103 104 - **iter**: number of iterations. Default: `11585`. 105 106 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. 107 108 ```javascript 109 var opts = { 110 'iter': 2 111 }; 112 var it = iterSquaredTriangularSeq( opts ); 113 // returns <Object> 114 115 var v = it.next().value; 116 // returns 0 117 118 v = it.next().value; 119 // returns 1 120 121 var bool = it.next().done; 122 // returns true 123 ``` 124 125 </section> 126 127 <!-- /.usage --> 128 129 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 130 131 <section class="notes"> 132 133 ## Notes 134 135 - If an environment supports `Symbol.iterator`, the returned iterator is iterable. 136 137 </section> 138 139 <!-- /.notes --> 140 141 <!-- Package usage examples. --> 142 143 <section class="examples"> 144 145 ## Examples 146 147 <!-- eslint no-undef: "error" --> 148 149 ```javascript 150 var iterSquaredTriangularSeq = require( '@stdlib/math/iter/sequences/squared-triangular' ); 151 152 // Create an iterator: 153 var opts = { 154 'iter': 100 155 }; 156 var it = iterSquaredTriangularSeq( opts ); 157 158 // Perform manual iteration... 159 var v; 160 while ( true ) { 161 v = it.next(); 162 if ( v.done ) { 163 break; 164 } 165 console.log( v.value ); 166 } 167 ``` 168 169 </section> 170 171 <!-- /.examples --> 172 173 <!-- 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. --> 174 175 <section class="references"> 176 177 </section> 178 179 <!-- /.references --> 180 181 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 182 183 <section class="links"> 184 185 [oeis-a000537]: https://oeis.org/A000537 186 187 [squared-triangular-number]: https://en.wikipedia.org/wiki/Squared_triangular_number 188 189 [@stdlib/math/iter/sequences/triangular]: https://www.npmjs.com/package/@stdlib/math/tree/main/iter/sequences/triangular 190 191 [@stdlib/math/base/special/binomcoef]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/binomcoef 192 193 </section> 194 195 <!-- /.links -->