evalpoly.js (8028B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2019 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /* 20 * This script compiles modules for evaluating polynomial functions. If any polynomial coefficients change, this script should be rerun to update the compiled files. 21 */ 22 'use strict'; 23 24 // MODULES // 25 26 var resolve = require( 'path' ).resolve; 27 var writeFileSync = require( '@stdlib/fs/write-file' ).sync; 28 var licenseHeader = require( '@stdlib/_tools/licenses/header' ); 29 var compile = require( './../../../../base/tools/evalpoly-compile' ); 30 31 32 // VARIABLES // 33 34 // The tables below are from Fukushima, Toshio. 2009. "Fast computation of complete elliptic integrals and Jacobian elliptic functions." _Celestial Mechanics and Dynamical Astronomy_ 105 (4): 305. doi:[10.1007/s10569-009-9228-z](https://doi.org/10.1007/s10569-009-9228-z). 35 36 // Table 2 for expansion about x = 0.05: 37 var P1 = [ 38 1.591003453790792180, 39 0.416000743991786912, 40 0.245791514264103415, 41 0.179481482914906162, 42 0.144556057087555150, 43 0.123200993312427711, 44 0.108938811574293531, 45 0.098853409871592910, 46 0.091439629201749751, 47 0.085842591595413900, 48 0.081541118718303215 49 ]; 50 51 // Table 3 for expansion about 0.15: 52 var P2 = [ 53 1.635256732264579992, 54 0.471190626148732291, 55 0.309728410831499587, 56 0.252208311773135699, 57 0.226725623219684650, 58 0.215774446729585976, 59 0.213108771877348910, 60 0.216029124605188282, 61 0.223255831633057896, 62 0.234180501294209925, 63 0.248557682972264071, 64 0.266363809892617521 65 ]; 66 67 // Table 4 for expansion about 0.25: 68 var P3 = [ 69 1.685750354812596043, 70 0.541731848613280329, 71 0.401524438390690257, 72 0.369642473420889090, 73 0.376060715354583645, 74 0.405235887085125919, 75 0.453294381753999079, 76 0.520518947651184205, 77 0.609426039204995055, 78 0.724263522282908870, 79 0.871013847709812357, 80 1.057652872753547036 81 ]; 82 83 // Table 5 for expansion about 0.35: 84 var P4 = [ 85 1.744350597225613243, 86 0.634864275371935304, 87 0.539842564164445538, 88 0.571892705193787391, 89 0.670295136265406100, 90 0.832586590010977199, 91 1.073857448247933265, 92 1.422091460675497751, 93 1.920387183402304829, 94 2.632552548331654201, 95 3.652109747319039160, 96 5.115867135558865806, 97 7.224080007363877411 98 ]; 99 100 // Table 6 for expansion about 0.45: 101 var P5 = [ 102 1.813883936816982644, 103 0.763163245700557246, 104 0.761928605321595831, 105 0.951074653668427927, 106 1.315180671703161215, 107 1.928560693477410941, 108 2.937509342531378755, 109 4.594894405442878062, 110 7.330071221881720772, 111 11.87151259742530180, 112 19.45851374822937738, 113 32.20638657246426863, 114 53.73749198700554656, 115 90.27388602940998849 116 ]; 117 118 // Table 7 for expansion about 0.55: 119 var P6 = [ 120 1.898924910271553526, 121 0.950521794618244435, 122 1.151077589959015808, 123 1.750239106986300540, 124 2.952676812636875180, 125 5.285800396121450889, 126 9.832485716659979747, 127 18.78714868327559562, 128 36.61468615273698145, 129 72.45292395127771801, 130 145.1079577347069102, 131 293.4786396308497026, 132 598.3851815055010179, 133 1228.420013075863451, 134 2536.529755382764488 135 ]; 136 137 // Table 8 for expansion about 0.65: 138 var P7 = [ 139 2.007598398424376302, 140 1.248457231212347337, 141 1.926234657076479729, 142 3.751289640087587680, 143 8.119944554932045802, 144 18.66572130873555361, 145 44.60392484291437063, 146 109.5092054309498377, 147 274.2779548232413480, 148 697.5598008606326163, 149 1795.716014500247129, 150 4668.381716790389910, 151 12235.76246813664335, 152 32290.17809718320818, 153 85713.07608195964685, 154 228672.1890493117096, 155 612757.2711915852774 156 ]; 157 158 // Table 9 for expansion about 0.75: 159 var P8 = [ 160 2.156515647499643235, 161 1.791805641849463243, 162 3.826751287465713147, 163 10.38672468363797208, 164 31.40331405468070290, 165 100.9237039498695416, 166 337.3268282632272897, 167 1158.707930567827917, 168 4060.990742193632092, 169 14454.00184034344795, 170 52076.66107599404803, 171 189493.6591462156887, 172 695184.5762413896145, 173 2567994.048255284686, 174 9541921.966748386322, 175 35634927.44218076174, 176 133669298.4612040871, 177 503352186.6866284541, 178 1901975729.538660119, 179 7208915015.330103756 180 ]; 181 182 // Table 10 for expansion about 0.825: 183 var P9 = [ 184 2.318122621712510589, 185 2.616920150291232841, 186 7.897935075731355823, 187 30.50239715446672327, 188 131.4869365523528456, 189 602.9847637356491617, 190 2877.024617809972641, 191 14110.51991915180325, 192 70621.44088156540229, 193 358977.2665825309926, 194 1847238.263723971684, 195 9600515.416049214109, 196 50307677.08502366879, 197 265444188.6527127967, 198 1408862325.028702687, 199 7515687935.373774627 200 ]; 201 202 // Table 11 for expansion about 0.875: 203 var P10 = [ 204 2.473596173751343912, 205 3.727624244118099310, 206 15.60739303554930496, 207 84.12850842805887747, 208 506.9818197040613935, 209 3252.277058145123644, 210 21713.24241957434256, 211 149037.0451890932766, 212 1043999.331089990839, 213 7427974.817042038995, 214 53503839.67558661151, 215 389249886.9948708474, 216 2855288351.100810619, 217 21090077038.76684053, 218 156699833947.7902014, 219 1170222242422.439893, 220 8777948323668.937971, 221 66101242752484.95041, 222 499488053713388.7989, 223 37859743397240299.20 224 ]; 225 226 // Table 12 for Maclaurin expansion of Jacobi's nome, q, as a function of the elliptic parameter, m: 227 var P11 = [ 228 0.0, 229 1.0 / 16.0, 230 1.0 / 32.0, 231 21.0 / 1024.0, 232 31.0 / 2048.0, 233 6257.0 / 524288.0, 234 10293.0 / 1048576.0, 235 279025.0 / 33554432.0, 236 483127.0 / 67108864.0, 237 435506703.0 / 68719476736.0, 238 776957575.0 / 137438953472.0, 239 22417045555.0 / 4398046511104.0, 240 40784671953.0 / 8796093022208.0, 241 9569130097211.0 / 2251799813685248.0, 242 17652604545791.0 / 4503599627370496.0 243 ]; 244 245 // Talyor expansion of K(m) - E(m) for 0 <= m <= 0.1: 246 var P12 = [ 247 1.591003453790792180, 248 0.416000743991786912, 249 0.245791514264103415, 250 0.179481482914906162, 251 0.144556057087555150, 252 0.123200993312427711, 253 0.108938811574293531, 254 0.098853409871592910, 255 0.091439629201749751, 256 0.085842591595413900, 257 0.081541118718303215 258 ]; 259 260 // Header to add to output files: 261 var header = licenseHeader( 'Apache-2.0', 'js', { 262 'year': ( new Date() ).getFullYear(), 263 'copyright': 'The Stdlib Authors' 264 }); 265 header += '\n/* This is a generated file. Do not edit directly. */\n'; 266 267 268 // MAIN // 269 270 /** 271 * Main execution sequence. 272 * 273 * @private 274 */ 275 function main() { 276 var fpath; 277 var opts; 278 var str; 279 280 opts = { 281 'encoding': 'utf8' 282 }; 283 284 fpath = resolve( __dirname, '..', 'lib', 'poly_p1.js' ); 285 str = header + compile( P1 ); 286 writeFileSync( fpath, str, opts ); 287 288 fpath = resolve( __dirname, '..', 'lib', 'poly_p2.js' ); 289 str = header + compile( P2 ); 290 writeFileSync( fpath, str, opts ); 291 292 fpath = resolve( __dirname, '..', 'lib', 'poly_p3.js' ); 293 str = header + compile( P3 ); 294 writeFileSync( fpath, str, opts ); 295 296 fpath = resolve( __dirname, '..', 'lib', 'poly_p4.js' ); 297 str = header + compile( P4 ); 298 writeFileSync( fpath, str, opts ); 299 300 fpath = resolve( __dirname, '..', 'lib', 'poly_p5.js' ); 301 str = header + compile( P5 ); 302 writeFileSync( fpath, str, opts ); 303 304 fpath = resolve( __dirname, '..', 'lib', 'poly_p6.js' ); 305 str = header + compile( P6 ); 306 writeFileSync( fpath, str, opts ); 307 308 fpath = resolve( __dirname, '..', 'lib', 'poly_p7.js' ); 309 str = header + compile( P7 ); 310 writeFileSync( fpath, str, opts ); 311 312 fpath = resolve( __dirname, '..', 'lib', 'poly_p8.js' ); 313 str = header + compile( P8 ); 314 writeFileSync( fpath, str, opts ); 315 316 fpath = resolve( __dirname, '..', 'lib', 'poly_p9.js' ); 317 str = header + compile( P9 ); 318 writeFileSync( fpath, str, opts ); 319 320 fpath = resolve( __dirname, '..', 'lib', 'poly_p10.js' ); 321 str = header + compile( P10 ); 322 writeFileSync( fpath, str, opts ); 323 324 fpath = resolve( __dirname, '..', 'lib', 'poly_p11.js' ); 325 str = header + compile( P11 ); 326 writeFileSync( fpath, str, opts ); 327 328 fpath = resolve( __dirname, '..', 'lib', 'poly_p12.js' ); 329 str = header + compile( P12 ); 330 writeFileSync( fpath, str, opts ); 331 } 332 333 main();