README.md (3524B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 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 # Lucas 22 23 > Compute the nth [Lucas number][lucas-number]. 24 25 <section class="intro"> 26 27 The [Lucas numbers][lucas-number] are the integer sequence 28 29 <!-- <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"> --> 30 31 <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"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/lucas/docs/img/equation_lucas_sequence.svg" alt="Lucas sequence"> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 The sequence is defined by the recurrence relation 39 40 <!-- <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"> --> 41 42 <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"> 43 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/lucas/docs/img/equation_lucas_recurrence_relation.svg" alt="Lucas sequence recurrence relation"> 44 <br> 45 </div> 46 47 <!-- </equation> --> 48 49 </section> 50 51 <!-- /.intro --> 52 53 <section class="usage"> 54 55 ## Usage 56 57 ```javascript 58 var lucas = require( '@stdlib/math/base/special/lucas' ); 59 ``` 60 61 #### lucas( n ) 62 63 Computes the nth [Lucas number][lucas-number]. 64 65 ```javascript 66 var v = lucas( 0 ); 67 // returns 2 68 69 v = lucas( 1 ); 70 // returns 1 71 72 v = lucas( 2 ); 73 // returns 3 74 75 v = lucas( 3 ); 76 // returns 4 77 78 v = lucas( 76 ); 79 // returns 7639424778862807 80 ``` 81 82 If `n > 76`, the function returns `NaN`, as larger [Lucas numbers][lucas-number] cannot be safely represented in [double-precision floating-point format][ieee754]. 83 84 ```javascript 85 var v = lucas( 77 ); 86 // returns NaN 87 ``` 88 89 If not provided a nonnegative integer value, the function returns `NaN`. 90 91 ```javascript 92 var v = lucas( 3.14 ); 93 // returns NaN 94 95 v = lucas( -1 ); 96 // returns NaN 97 ``` 98 99 If provided `NaN`, the function returns `NaN`. 100 101 ```javascript 102 var v = lucas( NaN ); 103 // returns NaN 104 ``` 105 106 </section> 107 108 <!-- /.usage --> 109 110 <section class="notes"> 111 112 </section> 113 114 <!-- /.notes --> 115 116 <section class="examples"> 117 118 ## Examples 119 120 <!-- eslint no-undef: "error" --> 121 122 ```javascript 123 var lucas = require( '@stdlib/math/base/special/lucas' ); 124 125 var v; 126 var i; 127 128 for ( i = 0; i < 77; i++ ) { 129 v = lucas( i ); 130 console.log( v ); 131 } 132 ``` 133 134 </section> 135 136 <!-- /.examples --> 137 138 <section class="links"> 139 140 [lucas-number]: https://en.wikipedia.org/wiki/Lucas_number 141 142 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 143 144 </section> 145 146 <!-- /.links -->