1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | (function webpackUniversalModuleDefinition(root, factory) {
|
29 | if(typeof exports === 'object' && typeof module === 'object')
|
30 | module.exports = factory();
|
31 | else if(typeof define === 'function' && define.amd)
|
32 | define([], factory);
|
33 | else if(typeof exports === 'object')
|
34 | exports["math"] = factory();
|
35 | else
|
36 | root["math"] = factory();
|
37 | })(this, function() {
|
38 | return (function(modules) {
|
39 |
|
40 | var installedModules = {};
|
41 |
|
42 |
|
43 | function __webpack_require__(moduleId) {
|
44 |
|
45 |
|
46 | if(installedModules[moduleId]) {
|
47 | return installedModules[moduleId].exports;
|
48 | }
|
49 |
|
50 | var module = installedModules[moduleId] = {
|
51 | i: moduleId,
|
52 | l: false,
|
53 | exports: {}
|
54 | };
|
55 |
|
56 |
|
57 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
58 |
|
59 |
|
60 | module.l = true;
|
61 |
|
62 |
|
63 | return module.exports;
|
64 | }
|
65 |
|
66 |
|
67 |
|
68 | __webpack_require__.m = modules;
|
69 |
|
70 |
|
71 | __webpack_require__.c = installedModules;
|
72 |
|
73 |
|
74 | __webpack_require__.d = function(exports, name, getter) {
|
75 | if(!__webpack_require__.o(exports, name)) {
|
76 | Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
77 | }
|
78 | };
|
79 |
|
80 |
|
81 | __webpack_require__.r = function(exports) {
|
82 | if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
83 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
84 | }
|
85 | Object.defineProperty(exports, '__esModule', { value: true });
|
86 | };
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | __webpack_require__.t = function(value, mode) {
|
94 | if(mode & 1) value = __webpack_require__(value);
|
95 | if(mode & 8) return value;
|
96 | if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
97 | var ns = Object.create(null);
|
98 | __webpack_require__.r(ns);
|
99 | Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
100 | if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
101 | return ns;
|
102 | };
|
103 |
|
104 |
|
105 | __webpack_require__.n = function(module) {
|
106 | var getter = module && module.__esModule ?
|
107 | function getDefault() { return module['default']; } :
|
108 | function getModuleExports() { return module; };
|
109 | __webpack_require__.d(getter, 'a', getter);
|
110 | return getter;
|
111 | };
|
112 |
|
113 |
|
114 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
115 |
|
116 |
|
117 | __webpack_require__.p = "";
|
118 |
|
119 |
|
120 |
|
121 | return __webpack_require__(__webpack_require__.s = 161);
|
122 | })
|
123 |
|
124 | ([
|
125 |
|
126 | (function(module, exports, __webpack_require__) {
|
127 |
|
128 | "use strict";
|
129 |
|
130 |
|
131 | function factory(type, config, load, typed) {
|
132 | |
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | var matrix = typed('matrix', {
|
165 | '': function _() {
|
166 | return _create([]);
|
167 | },
|
168 | 'string': function string(format) {
|
169 | return _create([], format);
|
170 | },
|
171 | 'string, string': function stringString(format, datatype) {
|
172 | return _create([], format, datatype);
|
173 | },
|
174 | 'Array': function Array(data) {
|
175 | return _create(data);
|
176 | },
|
177 | 'Matrix': function Matrix(data) {
|
178 | return _create(data, data.storage());
|
179 | },
|
180 | 'Array | Matrix, string': _create,
|
181 | 'Array | Matrix, string, string': _create
|
182 | });
|
183 | matrix.toTex = {
|
184 | 0: '\\begin{bmatrix}\\end{bmatrix}',
|
185 | 1: "\\left(${args[0]}\\right)",
|
186 | 2: "\\left(${args[0]}\\right)"
|
187 | };
|
188 | return matrix;
|
189 | |
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 | function _create(data, format, datatype) {
|
199 |
|
200 | var M = type.Matrix.storage(format || 'default');
|
201 |
|
202 | return new M(data, datatype);
|
203 | }
|
204 | }
|
205 |
|
206 | exports.name = 'matrix';
|
207 | exports.factory = factory;
|
208 |
|
209 | }),
|
210 |
|
211 | (function(module, exports, __webpack_require__) {
|
212 |
|
213 | "use strict";
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 | module.exports = function deepMap(array, callback, skipZeros) {
|
229 | if (array && typeof array.map === 'function') {
|
230 |
|
231 | return array.map(function (x) {
|
232 | return deepMap(x, callback, skipZeros);
|
233 | });
|
234 | } else {
|
235 | return callback(array);
|
236 | }
|
237 | };
|
238 |
|
239 | }),
|
240 |
|
241 | (function(module, __webpack_exports__, __webpack_require__) {
|
242 |
|
243 | "use strict";
|
244 | __webpack_require__.r(__webpack_exports__);
|
245 | __webpack_require__.d(__webpack_exports__, "size", function() { return size; });
|
246 | __webpack_require__.d(__webpack_exports__, "validate", function() { return validate; });
|
247 | __webpack_require__.d(__webpack_exports__, "validateIndex", function() { return validateIndex; });
|
248 | __webpack_require__.d(__webpack_exports__, "resize", function() { return resize; });
|
249 | __webpack_require__.d(__webpack_exports__, "reshape", function() { return reshape; });
|
250 | __webpack_require__.d(__webpack_exports__, "squeeze", function() { return squeeze; });
|
251 | __webpack_require__.d(__webpack_exports__, "unsqueeze", function() { return unsqueeze; });
|
252 | __webpack_require__.d(__webpack_exports__, "flatten", function() { return flatten; });
|
253 | __webpack_require__.d(__webpack_exports__, "map", function() { return map; });
|
254 | __webpack_require__.d(__webpack_exports__, "forEach", function() { return forEach; });
|
255 | __webpack_require__.d(__webpack_exports__, "filter", function() { return filter; });
|
256 | __webpack_require__.d(__webpack_exports__, "filterRegExp", function() { return filterRegExp; });
|
257 | __webpack_require__.d(__webpack_exports__, "join", function() { return join; });
|
258 | __webpack_require__.d(__webpack_exports__, "identify", function() { return identify; });
|
259 | __webpack_require__.d(__webpack_exports__, "generalize", function() { return generalize; });
|
260 | var _number__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
|
261 | var _number__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(_number__WEBPACK_IMPORTED_MODULE_0__);
|
262 | var _string__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9);
|
263 | var _string__WEBPACK_IMPORTED_MODULE_1___default = __webpack_require__.n(_string__WEBPACK_IMPORTED_MODULE_1__);
|
264 | var _error_DimensionError__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
|
265 | var _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default = __webpack_require__.n(_error_DimensionError__WEBPACK_IMPORTED_MODULE_2__);
|
266 | var _error_IndexError__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(48);
|
267 | var _error_IndexError__WEBPACK_IMPORTED_MODULE_3___default = __webpack_require__.n(_error_IndexError__WEBPACK_IMPORTED_MODULE_3__);
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 | function size(x) {
|
283 | var s = [];
|
284 |
|
285 | while (Array.isArray(x)) {
|
286 | s.push(x.length);
|
287 | x = x[0];
|
288 | }
|
289 |
|
290 | return s;
|
291 | }
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 | function _validate(array, size, dim) {
|
303 | var i;
|
304 | var len = array.length;
|
305 |
|
306 | if (len !== size[dim]) {
|
307 | throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(len, size[dim]);
|
308 | }
|
309 |
|
310 | if (dim < size.length - 1) {
|
311 |
|
312 | var dimNext = dim + 1;
|
313 |
|
314 | for (i = 0; i < len; i++) {
|
315 | var child = array[i];
|
316 |
|
317 | if (!Array.isArray(child)) {
|
318 | throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(size.length - 1, size.length, '<');
|
319 | }
|
320 |
|
321 | _validate(array[i], size, dimNext);
|
322 | }
|
323 | } else {
|
324 |
|
325 | for (i = 0; i < len; i++) {
|
326 | if (Array.isArray(array[i])) {
|
327 | throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(size.length + 1, size.length, '>');
|
328 | }
|
329 | }
|
330 | }
|
331 | }
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 | function validate(array, size) {
|
342 | var isScalar = size.length === 0;
|
343 |
|
344 | if (isScalar) {
|
345 |
|
346 | if (Array.isArray(array)) {
|
347 | throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(array.length, 0);
|
348 | }
|
349 | } else {
|
350 |
|
351 | _validate(array, size, 0);
|
352 | }
|
353 | }
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 | function validateIndex(index, length) {
|
362 | if (!_number__WEBPACK_IMPORTED_MODULE_0___default.a.isNumber(index) || !_number__WEBPACK_IMPORTED_MODULE_0___default.a.isInteger(index)) {
|
363 | throw new TypeError('Index must be an integer (value: ' + index + ')');
|
364 | }
|
365 |
|
366 | if (index < 0 || typeof length === 'number' && index >= length) {
|
367 | throw new _error_IndexError__WEBPACK_IMPORTED_MODULE_3___default.a(index, length);
|
368 | }
|
369 | }
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 | function resize(array, size, defaultValue) {
|
382 |
|
383 |
|
384 | if (!Array.isArray(array) || !Array.isArray(size)) {
|
385 | throw new TypeError('Array expected');
|
386 | }
|
387 |
|
388 | if (size.length === 0) {
|
389 | throw new Error('Resizing to scalar is not supported');
|
390 | }
|
391 |
|
392 |
|
393 | size.forEach(function (value) {
|
394 | if (!_number__WEBPACK_IMPORTED_MODULE_0___default.a.isNumber(value) || !_number__WEBPACK_IMPORTED_MODULE_0___default.a.isInteger(value) || value < 0) {
|
395 | throw new TypeError('Invalid size, must contain positive integers ' + '(size: ' + _string__WEBPACK_IMPORTED_MODULE_1___default.a.format(size) + ')');
|
396 | }
|
397 | });
|
398 |
|
399 | var _defaultValue = defaultValue !== undefined ? defaultValue : 0;
|
400 |
|
401 | _resize(array, size, 0, _defaultValue);
|
402 |
|
403 | return array;
|
404 | }
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 | function _resize(array, size, dim, defaultValue) {
|
416 | var i;
|
417 | var elem;
|
418 | var oldLen = array.length;
|
419 | var newLen = size[dim];
|
420 | var minLen = Math.min(oldLen, newLen);
|
421 |
|
422 | array.length = newLen;
|
423 |
|
424 | if (dim < size.length - 1) {
|
425 |
|
426 | var dimNext = dim + 1;
|
427 |
|
428 | for (i = 0; i < minLen; i++) {
|
429 |
|
430 | elem = array[i];
|
431 |
|
432 | if (!Array.isArray(elem)) {
|
433 | elem = [elem];
|
434 |
|
435 | array[i] = elem;
|
436 | }
|
437 |
|
438 | _resize(elem, size, dimNext, defaultValue);
|
439 | }
|
440 |
|
441 |
|
442 | for (i = minLen; i < newLen; i++) {
|
443 |
|
444 | elem = [];
|
445 | array[i] = elem;
|
446 |
|
447 | _resize(elem, size, dimNext, defaultValue);
|
448 | }
|
449 | } else {
|
450 |
|
451 |
|
452 | for (i = 0; i < minLen; i++) {
|
453 | while (Array.isArray(array[i])) {
|
454 | array[i] = array[i][0];
|
455 | }
|
456 | }
|
457 |
|
458 |
|
459 | for (i = minLen; i < newLen; i++) {
|
460 | array[i] = defaultValue;
|
461 | }
|
462 | }
|
463 | }
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 | function reshape(array, sizes) {
|
477 | var flatArray = flatten(array);
|
478 | var newArray;
|
479 |
|
480 | function product(arr) {
|
481 | return arr.reduce(function (prev, curr) {
|
482 | return prev * curr;
|
483 | });
|
484 | }
|
485 |
|
486 | if (!Array.isArray(array) || !Array.isArray(sizes)) {
|
487 | throw new TypeError('Array expected');
|
488 | }
|
489 |
|
490 | if (sizes.length === 0) {
|
491 | throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(0, product(size(array)), '!=');
|
492 | }
|
493 |
|
494 | var totalSize = 1;
|
495 |
|
496 | for (var sizeIndex = 0; sizeIndex < sizes.length; sizeIndex++) {
|
497 | totalSize *= sizes[sizeIndex];
|
498 | }
|
499 |
|
500 | if (flatArray.length !== totalSize) {
|
501 | throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(product(sizes), product(size(array)), '!=');
|
502 | }
|
503 |
|
504 | try {
|
505 | newArray = _reshape(flatArray, sizes);
|
506 | } catch (e) {
|
507 | if (e instanceof _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a) {
|
508 | throw new _error_DimensionError__WEBPACK_IMPORTED_MODULE_2___default.a(product(sizes), product(size(array)), '!=');
|
509 | }
|
510 |
|
511 | throw e;
|
512 | }
|
513 |
|
514 | return newArray;
|
515 | }
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 | function _reshape(array, sizes) {
|
525 |
|
526 | var tmpArray = array;
|
527 | var tmpArray2;
|
528 |
|
529 | for (var sizeIndex = sizes.length - 1; sizeIndex > 0; sizeIndex--) {
|
530 | var size = sizes[sizeIndex];
|
531 | tmpArray2 = [];
|
532 |
|
533 | var length = tmpArray.length / size;
|
534 |
|
535 | for (var i = 0; i < length; i++) {
|
536 | tmpArray2.push(tmpArray.slice(i * size, (i + 1) * size));
|
537 | }
|
538 |
|
539 |
|
540 | tmpArray = tmpArray2;
|
541 | }
|
542 |
|
543 | return tmpArray;
|
544 | }
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 | function squeeze(array, arraySize) {
|
554 | var s = arraySize || size(array);
|
555 |
|
556 | while (Array.isArray(array) && array.length === 1) {
|
557 | array = array[0];
|
558 | s.shift();
|
559 | }
|
560 |
|
561 |
|
562 | var dims = s.length;
|
563 |
|
564 | while (s[dims - 1] === 1) {
|
565 | dims--;
|
566 | }
|
567 |
|
568 |
|
569 | if (dims < s.length) {
|
570 | array = _squeeze(array, dims, 0);
|
571 | s.length = dims;
|
572 | }
|
573 |
|
574 | return array;
|
575 | }
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 | function _squeeze(array, dims, dim) {
|
586 | var i, ii;
|
587 |
|
588 | if (dim < dims) {
|
589 | var next = dim + 1;
|
590 |
|
591 | for (i = 0, ii = array.length; i < ii; i++) {
|
592 | array[i] = _squeeze(array[i], dims, next);
|
593 | }
|
594 | } else {
|
595 | while (Array.isArray(array)) {
|
596 | array = array[0];
|
597 | }
|
598 | }
|
599 |
|
600 | return array;
|
601 | }
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 | function unsqueeze(array, dims, outer, arraySize) {
|
617 | var s = arraySize || size(array);
|
618 |
|
619 | if (outer) {
|
620 | for (var i = 0; i < outer; i++) {
|
621 | array = [array];
|
622 | s.unshift(1);
|
623 | }
|
624 | }
|
625 |
|
626 |
|
627 | array = _unsqueeze(array, dims, 0);
|
628 |
|
629 | while (s.length < dims) {
|
630 | s.push(1);
|
631 | }
|
632 |
|
633 | return array;
|
634 | }
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 | function _unsqueeze(array, dims, dim) {
|
645 | var i, ii;
|
646 |
|
647 | if (Array.isArray(array)) {
|
648 | var next = dim + 1;
|
649 |
|
650 | for (i = 0, ii = array.length; i < ii; i++) {
|
651 | array[i] = _unsqueeze(array[i], dims, next);
|
652 | }
|
653 | } else {
|
654 | for (var d = dim; d < dims; d++) {
|
655 | array = [array];
|
656 | }
|
657 | }
|
658 |
|
659 | return array;
|
660 | }
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 | function flatten(array) {
|
670 | if (!Array.isArray(array)) {
|
671 |
|
672 | return array;
|
673 | }
|
674 |
|
675 | var flat = [];
|
676 | array.forEach(function callback(value) {
|
677 | if (Array.isArray(value)) {
|
678 | value.forEach(callback);
|
679 | } else {
|
680 | flat.push(value);
|
681 | }
|
682 | });
|
683 | return flat;
|
684 | }
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 | function map(array, callback) {
|
692 | return Array.prototype.map.call(array, callback);
|
693 | }
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 | function forEach(array, callback) {
|
701 | Array.prototype.forEach.call(array, callback);
|
702 | }
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 | function filter(array, callback) {
|
710 | if (size(array).length !== 1) {
|
711 | throw new Error('Only one dimensional matrices supported');
|
712 | }
|
713 |
|
714 | return Array.prototype.filter.call(array, callback);
|
715 | }
|
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 | function filterRegExp(array, regexp) {
|
725 | if (size(array).length !== 1) {
|
726 | throw new Error('Only one dimensional matrices supported');
|
727 | }
|
728 |
|
729 | return Array.prototype.filter.call(array, function (entry) {
|
730 | return regexp.test(entry);
|
731 | });
|
732 | }
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 | function join(array, separator) {
|
740 | return Array.prototype.join.call(array, separator);
|
741 | }
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 | function identify(a) {
|
749 | if (!Array.isArray(a)) {
|
750 | throw new TypeError('Array input expected');
|
751 | }
|
752 |
|
753 | if (a.length === 0) {
|
754 | return a;
|
755 | }
|
756 |
|
757 | var b = [];
|
758 | var count = 0;
|
759 | b[0] = {
|
760 | value: a[0],
|
761 | identifier: 0
|
762 | };
|
763 |
|
764 | for (var i = 1; i < a.length; i++) {
|
765 | if (a[i] === a[i - 1]) {
|
766 | count++;
|
767 | } else {
|
768 | count = 0;
|
769 | }
|
770 |
|
771 | b.push({
|
772 | value: a[i],
|
773 | identifier: count
|
774 | });
|
775 | }
|
776 |
|
777 | return b;
|
778 | }
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 | function generalize(a) {
|
786 | if (!Array.isArray(a)) {
|
787 | throw new TypeError('Array input expected');
|
788 | }
|
789 |
|
790 | if (a.length === 0) {
|
791 | return a;
|
792 | }
|
793 |
|
794 | var b = [];
|
795 |
|
796 | for (var i = 0; i < a.length; i++) {
|
797 | b.push(a[i].value);
|
798 | }
|
799 |
|
800 | return b;
|
801 | }
|
802 |
|
803 | }),
|
804 |
|
805 | (function(module, exports, __webpack_require__) {
|
806 |
|
807 | "use strict";
|
808 |
|
809 |
|
810 | var objectUtils = __webpack_require__(5);
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 | exports.isNumber = function (value) {
|
823 | return typeof value === 'number';
|
824 | };
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 |
|
832 | exports.isInteger = function (value) {
|
833 | if (typeof value === 'boolean') {
|
834 | return true;
|
835 | }
|
836 |
|
837 | return isFinite(value) ? value === Math.round(value) : false;
|
838 | };
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 | exports.sign = Math.sign || function (x) {
|
847 | if (x > 0) {
|
848 | return 1;
|
849 | } else if (x < 0) {
|
850 | return -1;
|
851 | } else {
|
852 | return 0;
|
853 | }
|
854 | };
|
855 |
|
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 |
|
871 |
|
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 |
|
922 |
|
923 |
|
924 |
|
925 |
|
926 |
|
927 | exports.format = function (value, options) {
|
928 | if (typeof options === 'function') {
|
929 |
|
930 | return options(value);
|
931 | }
|
932 |
|
933 |
|
934 | if (value === Infinity) {
|
935 | return 'Infinity';
|
936 | } else if (value === -Infinity) {
|
937 | return '-Infinity';
|
938 | } else if (isNaN(value)) {
|
939 | return 'NaN';
|
940 | }
|
941 |
|
942 |
|
943 | var notation = 'auto';
|
944 | var precision;
|
945 |
|
946 | if (options) {
|
947 |
|
948 | if (options.notation) {
|
949 | notation = options.notation;
|
950 | }
|
951 |
|
952 |
|
953 | if (exports.isNumber(options)) {
|
954 | precision = options;
|
955 | } else if (exports.isNumber(options.precision)) {
|
956 | precision = options.precision;
|
957 | }
|
958 | }
|
959 |
|
960 |
|
961 | switch (notation) {
|
962 | case 'fixed':
|
963 | return exports.toFixed(value, precision);
|
964 |
|
965 | case 'exponential':
|
966 | return exports.toExponential(value, precision);
|
967 |
|
968 | case 'engineering':
|
969 | return exports.toEngineering(value, precision);
|
970 |
|
971 | case 'auto':
|
972 |
|
973 |
|
974 | if (options && options.exponential && (options.exponential.lower !== undefined || options.exponential.upper !== undefined)) {
|
975 | var fixedOptions = objectUtils.map(options, function (x) {
|
976 | return x;
|
977 | });
|
978 | fixedOptions.exponential = undefined;
|
979 |
|
980 | if (options.exponential.lower !== undefined) {
|
981 | fixedOptions.lowerExp = Math.round(Math.log(options.exponential.lower) / Math.LN10);
|
982 | }
|
983 |
|
984 | if (options.exponential.upper !== undefined) {
|
985 | fixedOptions.upperExp = Math.round(Math.log(options.exponential.upper) / Math.LN10);
|
986 | }
|
987 |
|
988 | console.warn('Deprecation warning: Formatting options exponential.lower and exponential.upper ' + '(minimum and maximum value) ' + 'are replaced with exponential.lowerExp and exponential.upperExp ' + '(minimum and maximum exponent) since version 4.0.0. ' + 'Replace ' + JSON.stringify(options) + ' with ' + JSON.stringify(fixedOptions));
|
989 | return exports.toPrecision(value, precision, fixedOptions);
|
990 | }
|
991 |
|
992 | return exports.toPrecision(value, precision, options && options)
|
993 | .replace(/((\.\d*?)(0+))($|e)/, function () {
|
994 | var digits = arguments[2];
|
995 | var e = arguments[4];
|
996 | return digits !== '.' ? digits + e : e;
|
997 | });
|
998 |
|
999 | default:
|
1000 | throw new Error('Unknown notation "' + notation + '". ' + 'Choose "auto", "exponential", or "fixed".');
|
1001 | }
|
1002 | };
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 | exports.splitNumber = function (value) {
|
1012 |
|
1013 | var match = String(value).toLowerCase().match(/^0*?(-?)(\d+\.?\d*)(e([+-]?\d+))?$/);
|
1014 |
|
1015 | if (!match) {
|
1016 | throw new SyntaxError('Invalid number ' + value);
|
1017 | }
|
1018 |
|
1019 | var sign = match[1];
|
1020 | var digits = match[2];
|
1021 | var exponent = parseFloat(match[4] || '0');
|
1022 | var dot = digits.indexOf('.');
|
1023 | exponent += dot !== -1 ? dot - 1 : digits.length - 1;
|
1024 | var coefficients = digits.replace('.', '')
|
1025 | .replace(/^0*/, function (zeros) {
|
1026 |
|
1027 | exponent -= zeros.length;
|
1028 | return '';
|
1029 | }).replace(/0*$/, '')
|
1030 | .split('').map(function (d) {
|
1031 | return parseInt(d);
|
1032 | });
|
1033 |
|
1034 | if (coefficients.length === 0) {
|
1035 | coefficients.push(0);
|
1036 | exponent++;
|
1037 | }
|
1038 |
|
1039 | return {
|
1040 | sign: sign,
|
1041 | coefficients: coefficients,
|
1042 | exponent: exponent
|
1043 | };
|
1044 | };
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 | exports.toEngineering = function (value, precision) {
|
1053 | if (isNaN(value) || !isFinite(value)) {
|
1054 | return String(value);
|
1055 | }
|
1056 |
|
1057 | var rounded = exports.roundDigits(exports.splitNumber(value), precision);
|
1058 | var e = rounded.exponent;
|
1059 | var c = rounded.coefficients;
|
1060 |
|
1061 | var newExp = e % 3 === 0 ? e : e < 0 ? e - 3 - e % 3 : e - e % 3;
|
1062 |
|
1063 | if (exports.isNumber(precision)) {
|
1064 |
|
1065 | if (precision > c.length) c = c.concat(zeros(precision - c.length));
|
1066 | } else {
|
1067 |
|
1068 | var significandsDiff = e >= 0 ? e : Math.abs(newExp);
|
1069 |
|
1070 | if (c.length - 1 < significandsDiff) c = c.concat(zeros(significandsDiff - (c.length - 1)));
|
1071 | }
|
1072 |
|
1073 |
|
1074 | var expDiff = Math.abs(e - newExp);
|
1075 | var decimalIdx = 1;
|
1076 |
|
1077 | while (--expDiff >= 0) {
|
1078 | decimalIdx++;
|
1079 | }
|
1080 |
|
1081 |
|
1082 |
|
1083 | var decimals = c.slice(decimalIdx).join('');
|
1084 | var decimalVal = exports.isNumber(precision) && decimals.length || decimals.match(/[1-9]/) ? '.' + decimals : '';
|
1085 | var str = c.slice(0, decimalIdx).join('') + decimalVal + 'e' + (e >= 0 ? '+' : '') + newExp.toString();
|
1086 | return rounded.sign + str;
|
1087 | };
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 | exports.toFixed = function (value, precision) {
|
1097 | if (isNaN(value) || !isFinite(value)) {
|
1098 | return String(value);
|
1099 | }
|
1100 |
|
1101 | var splitValue = exports.splitNumber(value);
|
1102 | var rounded = typeof precision === 'number' ? exports.roundDigits(splitValue, splitValue.exponent + 1 + precision) : splitValue;
|
1103 | var c = rounded.coefficients;
|
1104 | var p = rounded.exponent + 1;
|
1105 |
|
1106 |
|
1107 | var pp = p + (precision || 0);
|
1108 |
|
1109 | if (c.length < pp) {
|
1110 | c = c.concat(zeros(pp - c.length));
|
1111 | }
|
1112 |
|
1113 |
|
1114 | if (p < 0) {
|
1115 | c = zeros(-p + 1).concat(c);
|
1116 | p = 1;
|
1117 | }
|
1118 |
|
1119 |
|
1120 | if (p < c.length) {
|
1121 | c.splice(p, 0, p === 0 ? '0.' : '.');
|
1122 | }
|
1123 |
|
1124 | return rounded.sign + c.join('');
|
1125 | };
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 | exports.toExponential = function (value, precision) {
|
1136 | if (isNaN(value) || !isFinite(value)) {
|
1137 | return String(value);
|
1138 | }
|
1139 |
|
1140 |
|
1141 | var split = exports.splitNumber(value);
|
1142 | var rounded = precision ? exports.roundDigits(split, precision) : split;
|
1143 | var c = rounded.coefficients;
|
1144 | var e = rounded.exponent;
|
1145 |
|
1146 | if (c.length < precision) {
|
1147 | c = c.concat(zeros(precision - c.length));
|
1148 | }
|
1149 |
|
1150 |
|
1151 | var first = c.shift();
|
1152 | return rounded.sign + first + (c.length > 0 ? '.' + c.join('') : '') + 'e' + (e >= 0 ? '+' : '') + e;
|
1153 | };
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 | exports.toPrecision = function (value, precision, options) {
|
1167 | if (isNaN(value) || !isFinite(value)) {
|
1168 | return String(value);
|
1169 | }
|
1170 |
|
1171 |
|
1172 | var lowerExp = options && options.lowerExp !== undefined ? options.lowerExp : -3;
|
1173 | var upperExp = options && options.upperExp !== undefined ? options.upperExp : 5;
|
1174 | var split = exports.splitNumber(value);
|
1175 |
|
1176 | if (split.exponent < lowerExp || split.exponent >= upperExp) {
|
1177 |
|
1178 | return exports.toExponential(value, precision);
|
1179 | } else {
|
1180 | var rounded = precision ? exports.roundDigits(split, precision) : split;
|
1181 | var c = rounded.coefficients;
|
1182 | var e = rounded.exponent;
|
1183 |
|
1184 | if (c.length < precision) {
|
1185 | c = c.concat(zeros(precision - c.length));
|
1186 | }
|
1187 |
|
1188 |
|
1189 |
|
1190 | c = c.concat(zeros(e - c.length + 1 + (c.length < precision ? precision - c.length : 0)));
|
1191 |
|
1192 | c = zeros(-e).concat(c);
|
1193 | var dot = e > 0 ? e : 0;
|
1194 |
|
1195 | if (dot < c.length - 1) {
|
1196 | c.splice(dot + 1, 0, '.');
|
1197 | }
|
1198 |
|
1199 | return rounded.sign + c.join('');
|
1200 | }
|
1201 | };
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 | exports.roundDigits = function (split, precision) {
|
1213 |
|
1214 | var rounded = {
|
1215 | sign: split.sign,
|
1216 | coefficients: split.coefficients,
|
1217 | exponent: split.exponent
|
1218 | };
|
1219 | var c = rounded.coefficients;
|
1220 |
|
1221 | while (precision <= 0) {
|
1222 | c.unshift(0);
|
1223 | rounded.exponent++;
|
1224 | precision++;
|
1225 | }
|
1226 |
|
1227 | if (c.length > precision) {
|
1228 | var removed = c.splice(precision, c.length - precision);
|
1229 |
|
1230 | if (removed[0] >= 5) {
|
1231 | var i = precision - 1;
|
1232 | c[i]++;
|
1233 |
|
1234 | while (c[i] === 10) {
|
1235 | c.pop();
|
1236 |
|
1237 | if (i === 0) {
|
1238 | c.unshift(0);
|
1239 | rounded.exponent++;
|
1240 | i++;
|
1241 | }
|
1242 |
|
1243 | i--;
|
1244 | c[i]++;
|
1245 | }
|
1246 | }
|
1247 | }
|
1248 |
|
1249 | return rounded;
|
1250 | };
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 | function zeros(length) {
|
1259 | var arr = [];
|
1260 |
|
1261 | for (var i = 0; i < length; i++) {
|
1262 | arr.push(0);
|
1263 | }
|
1264 |
|
1265 | return arr;
|
1266 | }
|
1267 |
|
1268 |
|
1269 |
|
1270 |
|
1271 |
|
1272 |
|
1273 |
|
1274 |
|
1275 |
|
1276 |
|
1277 |
|
1278 |
|
1279 |
|
1280 | exports.digits = function (value) {
|
1281 | return value.toExponential().replace(/e.*$/, '')
|
1282 | .replace(/^0\.?0*|\./, '')
|
1283 | .length;
|
1284 | };
|
1285 |
|
1286 |
|
1287 |
|
1288 |
|
1289 |
|
1290 | exports.DBL_EPSILON = Number.EPSILON || 2.2204460492503130808472633361816E-16;
|
1291 |
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 | exports.nearlyEqual = function (x, y, epsilon) {
|
1302 |
|
1303 | if (epsilon === null || epsilon === undefined) {
|
1304 | return x === y;
|
1305 | }
|
1306 |
|
1307 | if (x === y) {
|
1308 | return true;
|
1309 | }
|
1310 |
|
1311 |
|
1312 | if (isNaN(x) || isNaN(y)) {
|
1313 | return false;
|
1314 | }
|
1315 |
|
1316 |
|
1317 | if (isFinite(x) && isFinite(y)) {
|
1318 |
|
1319 | var diff = Math.abs(x - y);
|
1320 |
|
1321 | if (diff < exports.DBL_EPSILON) {
|
1322 | return true;
|
1323 | } else {
|
1324 |
|
1325 | return diff <= Math.max(Math.abs(x), Math.abs(y)) * epsilon;
|
1326 | }
|
1327 | }
|
1328 |
|
1329 |
|
1330 | return false;
|
1331 | };
|
1332 |
|
1333 | }),
|
1334 |
|
1335 | (function(module, exports, __webpack_require__) {
|
1336 |
|
1337 | "use strict";
|
1338 |
|
1339 |
|
1340 | var escapeLatex = __webpack_require__(180);
|
1341 |
|
1342 | exports.symbols = {
|
1343 |
|
1344 | Alpha: 'A',
|
1345 | alpha: '\\alpha',
|
1346 | Beta: 'B',
|
1347 | beta: '\\beta',
|
1348 | Gamma: '\\Gamma',
|
1349 | gamma: '\\gamma',
|
1350 | Delta: '\\Delta',
|
1351 | delta: '\\delta',
|
1352 | Epsilon: 'E',
|
1353 | epsilon: '\\epsilon',
|
1354 | varepsilon: '\\varepsilon',
|
1355 | Zeta: 'Z',
|
1356 | zeta: '\\zeta',
|
1357 | Eta: 'H',
|
1358 | eta: '\\eta',
|
1359 | Theta: '\\Theta',
|
1360 | theta: '\\theta',
|
1361 | vartheta: '\\vartheta',
|
1362 | Iota: 'I',
|
1363 | iota: '\\iota',
|
1364 | Kappa: 'K',
|
1365 | kappa: '\\kappa',
|
1366 | varkappa: '\\varkappa',
|
1367 | Lambda: '\\Lambda',
|
1368 | lambda: '\\lambda',
|
1369 | Mu: 'M',
|
1370 | mu: '\\mu',
|
1371 | Nu: 'N',
|
1372 | nu: '\\nu',
|
1373 | Xi: '\\Xi',
|
1374 | xi: '\\xi',
|
1375 | Omicron: 'O',
|
1376 | omicron: 'o',
|
1377 | Pi: '\\Pi',
|
1378 | pi: '\\pi',
|
1379 | varpi: '\\varpi',
|
1380 | Rho: 'P',
|
1381 | rho: '\\rho',
|
1382 | varrho: '\\varrho',
|
1383 | Sigma: '\\Sigma',
|
1384 | sigma: '\\sigma',
|
1385 | varsigma: '\\varsigma',
|
1386 | Tau: 'T',
|
1387 | tau: '\\tau',
|
1388 | Upsilon: "\\Upsilon",
|
1389 | upsilon: "\\upsilon",
|
1390 | Phi: '\\Phi',
|
1391 | phi: '\\phi',
|
1392 | varphi: '\\varphi',
|
1393 | Chi: 'X',
|
1394 | chi: '\\chi',
|
1395 | Psi: '\\Psi',
|
1396 | psi: '\\psi',
|
1397 | Omega: '\\Omega',
|
1398 | omega: '\\omega',
|
1399 |
|
1400 | 'true': '\\mathrm{True}',
|
1401 | 'false': '\\mathrm{False}',
|
1402 |
|
1403 | i: 'i',
|
1404 |
|
1405 | inf: '\\infty',
|
1406 | Inf: '\\infty',
|
1407 | infinity: '\\infty',
|
1408 | Infinity: '\\infty',
|
1409 | oo: '\\infty',
|
1410 | lim: '\\lim',
|
1411 | 'undefined': '\\mathbf{?}'
|
1412 | };
|
1413 | exports.operators = {
|
1414 | 'transpose': '^\\top',
|
1415 | 'ctranspose': '^H',
|
1416 | 'factorial': '!',
|
1417 | 'pow': '^',
|
1418 | 'dotPow': '.^\\wedge',
|
1419 |
|
1420 | 'unaryPlus': '+',
|
1421 | 'unaryMinus': '-',
|
1422 | 'bitNot': '\\~',
|
1423 |
|
1424 | 'not': '\\neg',
|
1425 | 'multiply': '\\cdot',
|
1426 | 'divide': '\\frac',
|
1427 |
|
1428 | 'dotMultiply': '.\\cdot',
|
1429 |
|
1430 | 'dotDivide': '.:',
|
1431 |
|
1432 | 'mod': '\\mod',
|
1433 | 'add': '+',
|
1434 | 'subtract': '-',
|
1435 | 'to': '\\rightarrow',
|
1436 | 'leftShift': '<<',
|
1437 | 'rightArithShift': '>>',
|
1438 | 'rightLogShift': '>>>',
|
1439 | 'equal': '=',
|
1440 | 'unequal': '\\neq',
|
1441 | 'smaller': '<',
|
1442 | 'larger': '>',
|
1443 | 'smallerEq': '\\leq',
|
1444 | 'largerEq': '\\geq',
|
1445 | 'bitAnd': '\\&',
|
1446 | 'bitXor': "\\underline{|}",
|
1447 | 'bitOr': '|',
|
1448 | 'and': '\\wedge',
|
1449 | 'xor': '\\veebar',
|
1450 | 'or': '\\vee'
|
1451 | };
|
1452 | exports.defaultTemplate = "\\mathrm{${name}}\\left(${args}\\right)";
|
1453 | var units = {
|
1454 | deg: '^\\circ'
|
1455 | };
|
1456 |
|
1457 | exports.escape = function (string) {
|
1458 | return escapeLatex(string, {
|
1459 | 'preserveFormatting': true
|
1460 | });
|
1461 | };
|
1462 |
|
1463 |
|
1464 |
|
1465 | exports.toSymbol = function (name, isUnit) {
|
1466 | isUnit = typeof isUnit === 'undefined' ? false : isUnit;
|
1467 |
|
1468 | if (isUnit) {
|
1469 | if (units.hasOwnProperty(name)) {
|
1470 | return units[name];
|
1471 | }
|
1472 |
|
1473 | return '\\mathrm{' + exports.escape(name) + '}';
|
1474 | }
|
1475 |
|
1476 | if (exports.symbols.hasOwnProperty(name)) {
|
1477 | return exports.symbols[name];
|
1478 | }
|
1479 |
|
1480 | return exports.escape(name);
|
1481 | };
|
1482 |
|
1483 | }),
|
1484 |
|
1485 | (function(module, exports, __webpack_require__) {
|
1486 |
|
1487 | "use strict";
|
1488 |
|
1489 |
|
1490 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
1491 |
|
1492 | var isBigNumber = __webpack_require__(81);
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 |
|
1501 |
|
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 | exports.clone = function clone(x) {
|
1507 | var type = _typeof(x);
|
1508 |
|
1509 |
|
1510 | if (type === 'number' || type === 'string' || type === 'boolean' || x === null || x === undefined) {
|
1511 | return x;
|
1512 | }
|
1513 |
|
1514 |
|
1515 | if (typeof x.clone === 'function') {
|
1516 | return x.clone();
|
1517 | }
|
1518 |
|
1519 |
|
1520 | if (Array.isArray(x)) {
|
1521 | return x.map(function (value) {
|
1522 | return clone(value);
|
1523 | });
|
1524 | }
|
1525 |
|
1526 | if (x instanceof Date) return new Date(x.valueOf());
|
1527 | if (isBigNumber(x)) return x;
|
1528 |
|
1529 | if (x instanceof RegExp) throw new TypeError('Cannot clone ' + x);
|
1530 |
|
1531 |
|
1532 | return exports.map(x, clone);
|
1533 | };
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 | exports.map = function (object, callback) {
|
1543 | var clone = {};
|
1544 |
|
1545 | for (var key in object) {
|
1546 | if (exports.hasOwnProperty(object, key)) {
|
1547 | clone[key] = callback(object[key]);
|
1548 | }
|
1549 | }
|
1550 |
|
1551 | return clone;
|
1552 | };
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 | exports.extend = function (a, b) {
|
1562 | for (var prop in b) {
|
1563 | if (exports.hasOwnProperty(b, prop)) {
|
1564 | a[prop] = b[prop];
|
1565 | }
|
1566 | }
|
1567 |
|
1568 | return a;
|
1569 | };
|
1570 |
|
1571 |
|
1572 |
|
1573 |
|
1574 |
|
1575 |
|
1576 |
|
1577 |
|
1578 | exports.deepExtend = function deepExtend(a, b) {
|
1579 |
|
1580 | if (Array.isArray(b)) {
|
1581 | throw new TypeError('Arrays are not supported by deepExtend');
|
1582 | }
|
1583 |
|
1584 | for (var prop in b) {
|
1585 | if (exports.hasOwnProperty(b, prop)) {
|
1586 | if (b[prop] && b[prop].constructor === Object) {
|
1587 | if (a[prop] === undefined) {
|
1588 | a[prop] = {};
|
1589 | }
|
1590 |
|
1591 | if (a[prop].constructor === Object) {
|
1592 | deepExtend(a[prop], b[prop]);
|
1593 | } else {
|
1594 | a[prop] = b[prop];
|
1595 | }
|
1596 | } else if (Array.isArray(b[prop])) {
|
1597 | throw new TypeError('Arrays are not supported by deepExtend');
|
1598 | } else {
|
1599 | a[prop] = b[prop];
|
1600 | }
|
1601 | }
|
1602 | }
|
1603 |
|
1604 | return a;
|
1605 | };
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 |
|
1612 |
|
1613 |
|
1614 | exports.deepEqual = function deepEqual(a, b) {
|
1615 | var prop, i, len;
|
1616 |
|
1617 | if (Array.isArray(a)) {
|
1618 | if (!Array.isArray(b)) {
|
1619 | return false;
|
1620 | }
|
1621 |
|
1622 | if (a.length !== b.length) {
|
1623 | return false;
|
1624 | }
|
1625 |
|
1626 | for (i = 0, len = a.length; i < len; i++) {
|
1627 | if (!exports.deepEqual(a[i], b[i])) {
|
1628 | return false;
|
1629 | }
|
1630 | }
|
1631 |
|
1632 | return true;
|
1633 | } else if (a instanceof Object) {
|
1634 | if (Array.isArray(b) || !(b instanceof Object)) {
|
1635 | return false;
|
1636 | }
|
1637 |
|
1638 | for (prop in a) {
|
1639 |
|
1640 | if (!exports.deepEqual(a[prop], b[prop])) {
|
1641 | return false;
|
1642 | }
|
1643 | }
|
1644 |
|
1645 | for (prop in b) {
|
1646 |
|
1647 | if (!exports.deepEqual(a[prop], b[prop])) {
|
1648 | return false;
|
1649 | }
|
1650 | }
|
1651 |
|
1652 | return true;
|
1653 | } else {
|
1654 | return a === b;
|
1655 | }
|
1656 | };
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 | exports.canDefineProperty = function () {
|
1664 |
|
1665 | try {
|
1666 | if (Object.defineProperty) {
|
1667 | Object.defineProperty({}, 'x', {
|
1668 | get: function get() {}
|
1669 | });
|
1670 | return true;
|
1671 | }
|
1672 | } catch (e) {}
|
1673 |
|
1674 | return false;
|
1675 | };
|
1676 |
|
1677 |
|
1678 |
|
1679 |
|
1680 |
|
1681 |
|
1682 |
|
1683 |
|
1684 |
|
1685 |
|
1686 |
|
1687 |
|
1688 | exports.lazy = function (object, prop, fn) {
|
1689 | if (exports.canDefineProperty()) {
|
1690 | var _uninitialized = true;
|
1691 |
|
1692 | var _value;
|
1693 |
|
1694 | Object.defineProperty(object, prop, {
|
1695 | get: function get() {
|
1696 | if (_uninitialized) {
|
1697 | _value = fn();
|
1698 | _uninitialized = false;
|
1699 | }
|
1700 |
|
1701 | return _value;
|
1702 | },
|
1703 | set: function set(value) {
|
1704 | _value = value;
|
1705 | _uninitialized = false;
|
1706 | },
|
1707 | configurable: true,
|
1708 | enumerable: true
|
1709 | });
|
1710 | } else {
|
1711 |
|
1712 | object[prop] = fn();
|
1713 | }
|
1714 | };
|
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 | exports.traverse = function (object, path) {
|
1725 | var obj = object;
|
1726 |
|
1727 | if (path) {
|
1728 | var names = path.split('.');
|
1729 |
|
1730 | for (var i = 0; i < names.length; i++) {
|
1731 | var name = names[i];
|
1732 |
|
1733 | if (!(name in obj)) {
|
1734 | obj[name] = {};
|
1735 | }
|
1736 |
|
1737 | obj = obj[name];
|
1738 | }
|
1739 | }
|
1740 |
|
1741 | return obj;
|
1742 | };
|
1743 |
|
1744 |
|
1745 |
|
1746 |
|
1747 |
|
1748 |
|
1749 |
|
1750 | exports.hasOwnProperty = function (object, property) {
|
1751 | return object && Object.hasOwnProperty.call(object, property);
|
1752 | };
|
1753 |
|
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 |
|
1759 |
|
1760 |
|
1761 |
|
1762 |
|
1763 |
|
1764 |
|
1765 |
|
1766 |
|
1767 | exports.isFactory = function (object) {
|
1768 | return object && typeof object.factory === 'function';
|
1769 | };
|
1770 |
|
1771 | }),
|
1772 |
|
1773 | (function(module, exports, __webpack_require__) {
|
1774 |
|
1775 | "use strict";
|
1776 |
|
1777 |
|
1778 | var clone = __webpack_require__(5).clone;
|
1779 |
|
1780 | function factory(type, config, load, typed) {
|
1781 | var DenseMatrix = type.DenseMatrix;
|
1782 | |
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 |
|
1797 |
|
1798 | var algorithm14 = function algorithm14(a, b, callback, inverse) {
|
1799 |
|
1800 | var adata = a._data;
|
1801 | var asize = a._size;
|
1802 | var adt = a._datatype;
|
1803 |
|
1804 | var dt;
|
1805 |
|
1806 | var cf = callback;
|
1807 |
|
1808 | if (typeof adt === 'string') {
|
1809 |
|
1810 | dt = adt;
|
1811 |
|
1812 | b = typed.convert(b, dt);
|
1813 |
|
1814 | cf = typed.find(callback, [dt, dt]);
|
1815 | }
|
1816 |
|
1817 |
|
1818 | var cdata = asize.length > 0 ? _iterate(cf, 0, asize, asize[0], adata, b, inverse) : [];
|
1819 |
|
1820 | return new DenseMatrix({
|
1821 | data: cdata,
|
1822 | size: clone(asize),
|
1823 | datatype: dt
|
1824 | });
|
1825 | };
|
1826 |
|
1827 |
|
1828 | function _iterate(f, level, s, n, av, bv, inverse) {
|
1829 |
|
1830 | var cv = [];
|
1831 |
|
1832 | if (level === s.length - 1) {
|
1833 |
|
1834 | for (var i = 0; i < n; i++) {
|
1835 |
|
1836 | cv[i] = inverse ? f(bv, av[i]) : f(av[i], bv);
|
1837 | }
|
1838 | } else {
|
1839 |
|
1840 | for (var j = 0; j < n; j++) {
|
1841 |
|
1842 | cv[j] = _iterate(f, level + 1, s, s[level + 1], av[j], bv, inverse);
|
1843 | }
|
1844 | }
|
1845 |
|
1846 | return cv;
|
1847 | }
|
1848 |
|
1849 | return algorithm14;
|
1850 | }
|
1851 |
|
1852 | exports.name = 'algorithm14';
|
1853 | exports.factory = factory;
|
1854 |
|
1855 | }),
|
1856 |
|
1857 | (function(module, exports, __webpack_require__) {
|
1858 |
|
1859 | "use strict";
|
1860 |
|
1861 |
|
1862 | var DimensionError = __webpack_require__(8);
|
1863 |
|
1864 | function factory(type, config, load, typed) {
|
1865 | var DenseMatrix = type.DenseMatrix;
|
1866 | |
1867 |
|
1868 |
|
1869 |
|
1870 |
|
1871 |
|
1872 |
|
1873 |
|
1874 |
|
1875 |
|
1876 |
|
1877 |
|
1878 |
|
1879 |
|
1880 |
|
1881 | var algorithm13 = function algorithm13(a, b, callback) {
|
1882 |
|
1883 | var adata = a._data;
|
1884 | var asize = a._size;
|
1885 | var adt = a._datatype;
|
1886 |
|
1887 | var bdata = b._data;
|
1888 | var bsize = b._size;
|
1889 | var bdt = b._datatype;
|
1890 |
|
1891 | var csize = [];
|
1892 |
|
1893 | if (asize.length !== bsize.length) {
|
1894 | throw new DimensionError(asize.length, bsize.length);
|
1895 | }
|
1896 |
|
1897 |
|
1898 | for (var s = 0; s < asize.length; s++) {
|
1899 |
|
1900 | if (asize[s] !== bsize[s]) {
|
1901 | throw new RangeError('Dimension mismatch. Matrix A (' + asize + ') must match Matrix B (' + bsize + ')');
|
1902 | }
|
1903 |
|
1904 |
|
1905 | csize[s] = asize[s];
|
1906 | }
|
1907 |
|
1908 |
|
1909 | var dt;
|
1910 |
|
1911 | var cf = callback;
|
1912 |
|
1913 | if (typeof adt === 'string' && adt === bdt) {
|
1914 |
|
1915 | dt = adt;
|
1916 |
|
1917 | cf = typed.find(callback, [dt, dt]);
|
1918 | }
|
1919 |
|
1920 |
|
1921 | var cdata = csize.length > 0 ? _iterate(cf, 0, csize, csize[0], adata, bdata) : [];
|
1922 |
|
1923 | return new DenseMatrix({
|
1924 | data: cdata,
|
1925 | size: csize,
|
1926 | datatype: dt
|
1927 | });
|
1928 | };
|
1929 |
|
1930 |
|
1931 | function _iterate(f, level, s, n, av, bv) {
|
1932 |
|
1933 | var cv = [];
|
1934 |
|
1935 | if (level === s.length - 1) {
|
1936 |
|
1937 | for (var i = 0; i < n; i++) {
|
1938 |
|
1939 | cv[i] = f(av[i], bv[i]);
|
1940 | }
|
1941 | } else {
|
1942 |
|
1943 | for (var j = 0; j < n; j++) {
|
1944 |
|
1945 | cv[j] = _iterate(f, level + 1, s, s[level + 1], av[j], bv[j]);
|
1946 | }
|
1947 | }
|
1948 |
|
1949 | return cv;
|
1950 | }
|
1951 |
|
1952 | return algorithm13;
|
1953 | }
|
1954 |
|
1955 | exports.name = 'algorithm13';
|
1956 | exports.factory = factory;
|
1957 |
|
1958 | }),
|
1959 |
|
1960 | (function(module, exports, __webpack_require__) {
|
1961 |
|
1962 | "use strict";
|
1963 |
|
1964 |
|
1965 |
|
1966 |
|
1967 |
|
1968 |
|
1969 |
|
1970 |
|
1971 |
|
1972 |
|
1973 |
|
1974 | function DimensionError(actual, expected, relation) {
|
1975 | if (!(this instanceof DimensionError)) {
|
1976 | throw new SyntaxError('Constructor must be called with the new operator');
|
1977 | }
|
1978 |
|
1979 | this.actual = actual;
|
1980 | this.expected = expected;
|
1981 | this.relation = relation;
|
1982 | this.message = 'Dimension mismatch (' + (Array.isArray(actual) ? '[' + actual.join(', ') + ']' : actual) + ' ' + (this.relation || '!=') + ' ' + (Array.isArray(expected) ? '[' + expected.join(', ') + ']' : expected) + ')';
|
1983 | this.stack = new Error().stack;
|
1984 | }
|
1985 |
|
1986 | DimensionError.prototype = new RangeError();
|
1987 | DimensionError.prototype.constructor = RangeError;
|
1988 | DimensionError.prototype.name = 'DimensionError';
|
1989 | DimensionError.prototype.isDimensionError = true;
|
1990 | module.exports = DimensionError;
|
1991 |
|
1992 | }),
|
1993 |
|
1994 | (function(module, exports, __webpack_require__) {
|
1995 |
|
1996 | "use strict";
|
1997 |
|
1998 |
|
1999 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
2000 |
|
2001 | var formatNumber = __webpack_require__(3).format;
|
2002 |
|
2003 | var formatBigNumber = __webpack_require__(175).format;
|
2004 |
|
2005 | var isBigNumber = __webpack_require__(81);
|
2006 |
|
2007 |
|
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 |
|
2013 | exports.isString = function (value) {
|
2014 | return typeof value === 'string';
|
2015 | };
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 |
|
2022 |
|
2023 | exports.endsWith = function (text, search) {
|
2024 | var start = text.length - search.length;
|
2025 | var end = text.length;
|
2026 | return text.substring(start, end) === search;
|
2027 | };
|
2028 |
|
2029 |
|
2030 |
|
2031 |
|
2032 |
|
2033 |
|
2034 |
|
2035 |
|
2036 |
|
2037 |
|
2038 |
|
2039 |
|
2040 |
|
2041 |
|
2042 |
|
2043 |
|
2044 |
|
2045 |
|
2046 |
|
2047 |
|
2048 |
|
2049 |
|
2050 |
|
2051 |
|
2052 |
|
2053 |
|
2054 |
|
2055 |
|
2056 |
|
2057 |
|
2058 |
|
2059 |
|
2060 |
|
2061 |
|
2062 |
|
2063 |
|
2064 |
|
2065 | exports.format = function (value, options) {
|
2066 | if (typeof value === 'number') {
|
2067 | return formatNumber(value, options);
|
2068 | }
|
2069 |
|
2070 | if (isBigNumber(value)) {
|
2071 | return formatBigNumber(value, options);
|
2072 | }
|
2073 |
|
2074 |
|
2075 |
|
2076 | if (looksLikeFraction(value)) {
|
2077 | if (!options || options.fraction !== 'decimal') {
|
2078 |
|
2079 | return value.s * value.n + '/' + value.d;
|
2080 | } else {
|
2081 |
|
2082 | return value.toString();
|
2083 | }
|
2084 | }
|
2085 |
|
2086 | if (Array.isArray(value)) {
|
2087 | return formatArray(value, options);
|
2088 | }
|
2089 |
|
2090 | if (exports.isString(value)) {
|
2091 | return '"' + value + '"';
|
2092 | }
|
2093 |
|
2094 | if (typeof value === 'function') {
|
2095 | return value.syntax ? String(value.syntax) : 'function';
|
2096 | }
|
2097 |
|
2098 | if (value && _typeof(value) === 'object') {
|
2099 | if (typeof value.format === 'function') {
|
2100 | return value.format(options);
|
2101 | } else if (value && value.toString() !== {}.toString()) {
|
2102 |
|
2103 | return value.toString();
|
2104 | } else {
|
2105 | var entries = [];
|
2106 |
|
2107 | for (var key in value) {
|
2108 | if (value.hasOwnProperty(key)) {
|
2109 | entries.push('"' + key + '": ' + exports.format(value[key], options));
|
2110 | }
|
2111 | }
|
2112 |
|
2113 | return '{' + entries.join(', ') + '}';
|
2114 | }
|
2115 | }
|
2116 |
|
2117 | return String(value);
|
2118 | };
|
2119 |
|
2120 |
|
2121 |
|
2122 |
|
2123 |
|
2124 |
|
2125 |
|
2126 |
|
2127 | exports.stringify = function (value) {
|
2128 | var text = String(value);
|
2129 | var escaped = '';
|
2130 | var i = 0;
|
2131 |
|
2132 | while (i < text.length) {
|
2133 | var c = text.charAt(i);
|
2134 |
|
2135 | if (c === '\\') {
|
2136 | escaped += c;
|
2137 | i++;
|
2138 | c = text.charAt(i);
|
2139 |
|
2140 | if (c === '' || '"\\/bfnrtu'.indexOf(c) === -1) {
|
2141 | escaped += '\\';
|
2142 | }
|
2143 |
|
2144 | escaped += c;
|
2145 | } else if (c === '"') {
|
2146 | escaped += '\\"';
|
2147 | } else {
|
2148 | escaped += c;
|
2149 | }
|
2150 |
|
2151 | i++;
|
2152 | }
|
2153 |
|
2154 | return '"' + escaped + '"';
|
2155 | };
|
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 |
|
2161 |
|
2162 |
|
2163 | exports.escape = function (value) {
|
2164 | var text = String(value);
|
2165 | text = text.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>');
|
2166 | return text;
|
2167 | };
|
2168 |
|
2169 |
|
2170 |
|
2171 |
|
2172 |
|
2173 |
|
2174 |
|
2175 |
|
2176 |
|
2177 |
|
2178 |
|
2179 |
|
2180 | function formatArray(array, options) {
|
2181 | if (Array.isArray(array)) {
|
2182 | var str = '[';
|
2183 | var len = array.length;
|
2184 |
|
2185 | for (var i = 0; i < len; i++) {
|
2186 | if (i !== 0) {
|
2187 | str += ', ';
|
2188 | }
|
2189 |
|
2190 | str += formatArray(array[i], options);
|
2191 | }
|
2192 |
|
2193 | str += ']';
|
2194 | return str;
|
2195 | } else {
|
2196 | return exports.format(array, options);
|
2197 | }
|
2198 | }
|
2199 |
|
2200 |
|
2201 |
|
2202 |
|
2203 |
|
2204 |
|
2205 |
|
2206 | function looksLikeFraction(value) {
|
2207 | return value && _typeof(value) === 'object' && typeof value.s === 'number' && typeof value.n === 'number' && typeof value.d === 'number' || false;
|
2208 | }
|
2209 |
|
2210 | }),
|
2211 |
|
2212 | (function(module, exports, __webpack_require__) {
|
2213 |
|
2214 | "use strict";
|
2215 |
|
2216 |
|
2217 | var extend = __webpack_require__(5).extend;
|
2218 |
|
2219 | var array = __webpack_require__(2);
|
2220 |
|
2221 | function factory(type, config, load, typed) {
|
2222 | var latex = __webpack_require__(4);
|
2223 |
|
2224 | var matrix = load(__webpack_require__(0));
|
2225 | var addScalar = load(__webpack_require__(17));
|
2226 | var multiplyScalar = load(__webpack_require__(21));
|
2227 | var equalScalar = load(__webpack_require__(11));
|
2228 | var algorithm11 = load(__webpack_require__(20));
|
2229 | var algorithm14 = load(__webpack_require__(6));
|
2230 | var DenseMatrix = type.DenseMatrix;
|
2231 | var SparseMatrix = type.SparseMatrix;
|
2232 | |
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 |
|
2238 |
|
2239 |
|
2240 |
|
2241 |
|
2242 |
|
2243 |
|
2244 |
|
2245 |
|
2246 |
|
2247 |
|
2248 |
|
2249 |
|
2250 |
|
2251 |
|
2252 |
|
2253 |
|
2254 |
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 |
|
2260 |
|
2261 |
|
2262 |
|
2263 |
|
2264 |
|
2265 |
|
2266 | var multiply = typed('multiply', extend({
|
2267 |
|
2268 | 'Array, Array': function ArrayArray(x, y) {
|
2269 |
|
2270 | _validateMatrixDimensions(array.size(x), array.size(y));
|
2271 |
|
2272 |
|
2273 | var m = multiply(matrix(x), matrix(y));
|
2274 |
|
2275 | return type.isMatrix(m) ? m.valueOf() : m;
|
2276 | },
|
2277 | 'Matrix, Matrix': function MatrixMatrix(x, y) {
|
2278 |
|
2279 | var xsize = x.size();
|
2280 | var ysize = y.size();
|
2281 |
|
2282 | _validateMatrixDimensions(xsize, ysize);
|
2283 |
|
2284 |
|
2285 | if (xsize.length === 1) {
|
2286 |
|
2287 | if (ysize.length === 1) {
|
2288 |
|
2289 | return _multiplyVectorVector(x, y, xsize[0]);
|
2290 | }
|
2291 |
|
2292 |
|
2293 | return _multiplyVectorMatrix(x, y);
|
2294 | }
|
2295 |
|
2296 |
|
2297 | if (ysize.length === 1) {
|
2298 |
|
2299 | return _multiplyMatrixVector(x, y);
|
2300 | }
|
2301 |
|
2302 |
|
2303 | return _multiplyMatrixMatrix(x, y);
|
2304 | },
|
2305 | 'Matrix, Array': function MatrixArray(x, y) {
|
2306 |
|
2307 | return multiply(x, matrix(y));
|
2308 | },
|
2309 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
2310 |
|
2311 | return multiply(matrix(x, y.storage()), y);
|
2312 | },
|
2313 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
2314 | return algorithm11(x, y, multiplyScalar, false);
|
2315 | },
|
2316 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
2317 | return algorithm14(x, y, multiplyScalar, false);
|
2318 | },
|
2319 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
2320 | return algorithm11(y, x, multiplyScalar, true);
|
2321 | },
|
2322 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
2323 | return algorithm14(y, x, multiplyScalar, true);
|
2324 | },
|
2325 | 'Array, any': function ArrayAny(x, y) {
|
2326 |
|
2327 | return algorithm14(matrix(x), y, multiplyScalar, false).valueOf();
|
2328 | },
|
2329 | 'any, Array': function anyArray(x, y) {
|
2330 |
|
2331 | return algorithm14(matrix(y), x, multiplyScalar, true).valueOf();
|
2332 | },
|
2333 | 'any, any': multiplyScalar,
|
2334 | 'any, any, ...any': function anyAnyAny(x, y, rest) {
|
2335 | var result = multiply(x, y);
|
2336 |
|
2337 | for (var i = 0; i < rest.length; i++) {
|
2338 | result = multiply(result, rest[i]);
|
2339 | }
|
2340 |
|
2341 | return result;
|
2342 | }
|
2343 | }, multiplyScalar.signatures));
|
2344 |
|
2345 | function _validateMatrixDimensions(size1, size2) {
|
2346 |
|
2347 | switch (size1.length) {
|
2348 | case 1:
|
2349 |
|
2350 | switch (size2.length) {
|
2351 | case 1:
|
2352 |
|
2353 | if (size1[0] !== size2[0]) {
|
2354 |
|
2355 | throw new RangeError('Dimension mismatch in multiplication. Vectors must have the same length');
|
2356 | }
|
2357 |
|
2358 | break;
|
2359 |
|
2360 | case 2:
|
2361 |
|
2362 | if (size1[0] !== size2[0]) {
|
2363 |
|
2364 | throw new RangeError('Dimension mismatch in multiplication. Vector length (' + size1[0] + ') must match Matrix rows (' + size2[0] + ')');
|
2365 | }
|
2366 |
|
2367 | break;
|
2368 |
|
2369 | default:
|
2370 | throw new Error('Can only multiply a 1 or 2 dimensional matrix (Matrix B has ' + size2.length + ' dimensions)');
|
2371 | }
|
2372 |
|
2373 | break;
|
2374 |
|
2375 | case 2:
|
2376 |
|
2377 | switch (size2.length) {
|
2378 | case 1:
|
2379 |
|
2380 | if (size1[1] !== size2[0]) {
|
2381 |
|
2382 | throw new RangeError('Dimension mismatch in multiplication. Matrix columns (' + size1[1] + ') must match Vector length (' + size2[0] + ')');
|
2383 | }
|
2384 |
|
2385 | break;
|
2386 |
|
2387 | case 2:
|
2388 |
|
2389 | if (size1[1] !== size2[0]) {
|
2390 |
|
2391 | throw new RangeError('Dimension mismatch in multiplication. Matrix A columns (' + size1[1] + ') must match Matrix B rows (' + size2[0] + ')');
|
2392 | }
|
2393 |
|
2394 | break;
|
2395 |
|
2396 | default:
|
2397 | throw new Error('Can only multiply a 1 or 2 dimensional matrix (Matrix B has ' + size2.length + ' dimensions)');
|
2398 | }
|
2399 |
|
2400 | break;
|
2401 |
|
2402 | default:
|
2403 | throw new Error('Can only multiply a 1 or 2 dimensional matrix (Matrix A has ' + size1.length + ' dimensions)');
|
2404 | }
|
2405 | }
|
2406 | |
2407 |
|
2408 |
|
2409 |
|
2410 |
|
2411 |
|
2412 |
|
2413 |
|
2414 |
|
2415 |
|
2416 | function _multiplyVectorVector(a, b, n) {
|
2417 |
|
2418 | if (n === 0) {
|
2419 | throw new Error('Cannot multiply two empty vectors');
|
2420 | }
|
2421 |
|
2422 |
|
2423 | var adata = a._data;
|
2424 | var adt = a._datatype;
|
2425 |
|
2426 | var bdata = b._data;
|
2427 | var bdt = b._datatype;
|
2428 |
|
2429 | var dt;
|
2430 |
|
2431 | var af = addScalar;
|
2432 |
|
2433 | var mf = multiplyScalar;
|
2434 |
|
2435 | if (adt && bdt && adt === bdt && typeof adt === 'string') {
|
2436 |
|
2437 | dt = adt;
|
2438 |
|
2439 | af = typed.find(addScalar, [dt, dt]);
|
2440 | mf = typed.find(multiplyScalar, [dt, dt]);
|
2441 | }
|
2442 |
|
2443 |
|
2444 | var c = mf(adata[0], bdata[0]);
|
2445 |
|
2446 | for (var i = 1; i < n; i++) {
|
2447 |
|
2448 | c = af(c, mf(adata[i], bdata[i]));
|
2449 | }
|
2450 |
|
2451 | return c;
|
2452 | }
|
2453 | |
2454 |
|
2455 |
|
2456 |
|
2457 |
|
2458 |
|
2459 |
|
2460 |
|
2461 |
|
2462 |
|
2463 | function _multiplyVectorMatrix(a, b) {
|
2464 |
|
2465 | if (b.storage() !== 'dense') {
|
2466 | throw new Error('Support for SparseMatrix not implemented');
|
2467 | }
|
2468 |
|
2469 | return _multiplyVectorDenseMatrix(a, b);
|
2470 | }
|
2471 | |
2472 |
|
2473 |
|
2474 |
|
2475 |
|
2476 |
|
2477 |
|
2478 |
|
2479 |
|
2480 |
|
2481 | function _multiplyVectorDenseMatrix(a, b) {
|
2482 |
|
2483 | var adata = a._data;
|
2484 | var asize = a._size;
|
2485 | var adt = a._datatype;
|
2486 |
|
2487 | var bdata = b._data;
|
2488 | var bsize = b._size;
|
2489 | var bdt = b._datatype;
|
2490 |
|
2491 | var alength = asize[0];
|
2492 | var bcolumns = bsize[1];
|
2493 |
|
2494 | var dt;
|
2495 |
|
2496 | var af = addScalar;
|
2497 |
|
2498 | var mf = multiplyScalar;
|
2499 |
|
2500 | if (adt && bdt && adt === bdt && typeof adt === 'string') {
|
2501 |
|
2502 | dt = adt;
|
2503 |
|
2504 | af = typed.find(addScalar, [dt, dt]);
|
2505 | mf = typed.find(multiplyScalar, [dt, dt]);
|
2506 | }
|
2507 |
|
2508 |
|
2509 | var c = [];
|
2510 |
|
2511 | for (var j = 0; j < bcolumns; j++) {
|
2512 |
|
2513 | var sum = mf(adata[0], bdata[0][j]);
|
2514 |
|
2515 | for (var i = 1; i < alength; i++) {
|
2516 |
|
2517 | sum = af(sum, mf(adata[i], bdata[i][j]));
|
2518 | }
|
2519 |
|
2520 | c[j] = sum;
|
2521 | }
|
2522 |
|
2523 |
|
2524 | return new DenseMatrix({
|
2525 | data: c,
|
2526 | size: [bcolumns],
|
2527 | datatype: dt
|
2528 | });
|
2529 | }
|
2530 | |
2531 |
|
2532 |
|
2533 |
|
2534 |
|
2535 |
|
2536 |
|
2537 |
|
2538 |
|
2539 |
|
2540 | var _multiplyMatrixVector = typed('_multiplyMatrixVector', {
|
2541 | 'DenseMatrix, any': _multiplyDenseMatrixVector,
|
2542 | 'SparseMatrix, any': _multiplySparseMatrixVector
|
2543 | });
|
2544 | |
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 | var _multiplyMatrixMatrix = typed('_multiplyMatrixMatrix', {
|
2555 | 'DenseMatrix, DenseMatrix': _multiplyDenseMatrixDenseMatrix,
|
2556 | 'DenseMatrix, SparseMatrix': _multiplyDenseMatrixSparseMatrix,
|
2557 | 'SparseMatrix, DenseMatrix': _multiplySparseMatrixDenseMatrix,
|
2558 | 'SparseMatrix, SparseMatrix': _multiplySparseMatrixSparseMatrix
|
2559 | });
|
2560 | |
2561 |
|
2562 |
|
2563 |
|
2564 |
|
2565 |
|
2566 |
|
2567 |
|
2568 |
|
2569 |
|
2570 | function _multiplyDenseMatrixVector(a, b) {
|
2571 |
|
2572 | var adata = a._data;
|
2573 | var asize = a._size;
|
2574 | var adt = a._datatype;
|
2575 |
|
2576 | var bdata = b._data;
|
2577 | var bdt = b._datatype;
|
2578 |
|
2579 | var arows = asize[0];
|
2580 | var acolumns = asize[1];
|
2581 |
|
2582 | var dt;
|
2583 |
|
2584 | var af = addScalar;
|
2585 |
|
2586 | var mf = multiplyScalar;
|
2587 |
|
2588 | if (adt && bdt && adt === bdt && typeof adt === 'string') {
|
2589 |
|
2590 | dt = adt;
|
2591 |
|
2592 | af = typed.find(addScalar, [dt, dt]);
|
2593 | mf = typed.find(multiplyScalar, [dt, dt]);
|
2594 | }
|
2595 |
|
2596 |
|
2597 | var c = [];
|
2598 |
|
2599 | for (var i = 0; i < arows; i++) {
|
2600 |
|
2601 | var row = adata[i];
|
2602 |
|
2603 | var sum = mf(row[0], bdata[0]);
|
2604 |
|
2605 | for (var j = 1; j < acolumns; j++) {
|
2606 |
|
2607 | sum = af(sum, mf(row[j], bdata[j]));
|
2608 | }
|
2609 |
|
2610 | c[i] = sum;
|
2611 | }
|
2612 |
|
2613 |
|
2614 | return new DenseMatrix({
|
2615 | data: c,
|
2616 | size: [arows],
|
2617 | datatype: dt
|
2618 | });
|
2619 | }
|
2620 | |
2621 |
|
2622 |
|
2623 |
|
2624 |
|
2625 |
|
2626 |
|
2627 |
|
2628 |
|
2629 |
|
2630 | function _multiplyDenseMatrixDenseMatrix(a, b) {
|
2631 |
|
2632 | var adata = a._data;
|
2633 | var asize = a._size;
|
2634 | var adt = a._datatype;
|
2635 |
|
2636 | var bdata = b._data;
|
2637 | var bsize = b._size;
|
2638 | var bdt = b._datatype;
|
2639 |
|
2640 | var arows = asize[0];
|
2641 | var acolumns = asize[1];
|
2642 | var bcolumns = bsize[1];
|
2643 |
|
2644 | var dt;
|
2645 |
|
2646 | var af = addScalar;
|
2647 |
|
2648 | var mf = multiplyScalar;
|
2649 |
|
2650 | if (adt && bdt && adt === bdt && typeof adt === 'string') {
|
2651 |
|
2652 | dt = adt;
|
2653 |
|
2654 | af = typed.find(addScalar, [dt, dt]);
|
2655 | mf = typed.find(multiplyScalar, [dt, dt]);
|
2656 | }
|
2657 |
|
2658 |
|
2659 | var c = [];
|
2660 |
|
2661 | for (var i = 0; i < arows; i++) {
|
2662 |
|
2663 | var row = adata[i];
|
2664 |
|
2665 | c[i] = [];
|
2666 |
|
2667 | for (var j = 0; j < bcolumns; j++) {
|
2668 |
|
2669 | var sum = mf(row[0], bdata[0][j]);
|
2670 |
|
2671 | for (var x = 1; x < acolumns; x++) {
|
2672 |
|
2673 | sum = af(sum, mf(row[x], bdata[x][j]));
|
2674 | }
|
2675 |
|
2676 | c[i][j] = sum;
|
2677 | }
|
2678 | }
|
2679 |
|
2680 |
|
2681 | return new DenseMatrix({
|
2682 | data: c,
|
2683 | size: [arows, bcolumns],
|
2684 | datatype: dt
|
2685 | });
|
2686 | }
|
2687 | |
2688 |
|
2689 |
|
2690 |
|
2691 |
|
2692 |
|
2693 |
|
2694 |
|
2695 |
|
2696 |
|
2697 | function _multiplyDenseMatrixSparseMatrix(a, b) {
|
2698 |
|
2699 | var adata = a._data;
|
2700 | var asize = a._size;
|
2701 | var adt = a._datatype;
|
2702 |
|
2703 | var bvalues = b._values;
|
2704 | var bindex = b._index;
|
2705 | var bptr = b._ptr;
|
2706 | var bsize = b._size;
|
2707 | var bdt = b._datatype;
|
2708 |
|
2709 | if (!bvalues) {
|
2710 | throw new Error('Cannot multiply Dense Matrix times Pattern only Matrix');
|
2711 | }
|
2712 |
|
2713 |
|
2714 | var arows = asize[0];
|
2715 | var bcolumns = bsize[1];
|
2716 |
|
2717 | var dt;
|
2718 |
|
2719 | var af = addScalar;
|
2720 |
|
2721 | var mf = multiplyScalar;
|
2722 |
|
2723 | var eq = equalScalar;
|
2724 |
|
2725 | var zero = 0;
|
2726 |
|
2727 | if (adt && bdt && adt === bdt && typeof adt === 'string') {
|
2728 |
|
2729 | dt = adt;
|
2730 |
|
2731 | af = typed.find(addScalar, [dt, dt]);
|
2732 | mf = typed.find(multiplyScalar, [dt, dt]);
|
2733 | eq = typed.find(equalScalar, [dt, dt]);
|
2734 |
|
2735 | zero = typed.convert(0, dt);
|
2736 | }
|
2737 |
|
2738 |
|
2739 | var cvalues = [];
|
2740 | var cindex = [];
|
2741 | var cptr = [];
|
2742 |
|
2743 | var c = new SparseMatrix({
|
2744 | values: cvalues,
|
2745 | index: cindex,
|
2746 | ptr: cptr,
|
2747 | size: [arows, bcolumns],
|
2748 | datatype: dt
|
2749 | });
|
2750 |
|
2751 | for (var jb = 0; jb < bcolumns; jb++) {
|
2752 |
|
2753 | cptr[jb] = cindex.length;
|
2754 |
|
2755 | var kb0 = bptr[jb];
|
2756 | var kb1 = bptr[jb + 1];
|
2757 |
|
2758 | if (kb1 > kb0) {
|
2759 |
|
2760 | var last = 0;
|
2761 |
|
2762 | for (var i = 0; i < arows; i++) {
|
2763 |
|
2764 | var mark = i + 1;
|
2765 |
|
2766 | var cij = void 0;
|
2767 |
|
2768 | for (var kb = kb0; kb < kb1; kb++) {
|
2769 |
|
2770 | var ib = bindex[kb];
|
2771 |
|
2772 | if (last !== mark) {
|
2773 |
|
2774 | cij = mf(adata[i][ib], bvalues[kb]);
|
2775 |
|
2776 | last = mark;
|
2777 | } else {
|
2778 |
|
2779 | cij = af(cij, mf(adata[i][ib], bvalues[kb]));
|
2780 | }
|
2781 | }
|
2782 |
|
2783 |
|
2784 | if (last === mark && !eq(cij, zero)) {
|
2785 |
|
2786 | cindex.push(i);
|
2787 | cvalues.push(cij);
|
2788 | }
|
2789 | }
|
2790 | }
|
2791 | }
|
2792 |
|
2793 |
|
2794 | cptr[bcolumns] = cindex.length;
|
2795 |
|
2796 | return c;
|
2797 | }
|
2798 | |
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 |
|
2806 |
|
2807 |
|
2808 | function _multiplySparseMatrixVector(a, b) {
|
2809 |
|
2810 | var avalues = a._values;
|
2811 | var aindex = a._index;
|
2812 | var aptr = a._ptr;
|
2813 | var adt = a._datatype;
|
2814 |
|
2815 | if (!avalues) {
|
2816 | throw new Error('Cannot multiply Pattern only Matrix times Dense Matrix');
|
2817 | }
|
2818 |
|
2819 |
|
2820 | var bdata = b._data;
|
2821 | var bdt = b._datatype;
|
2822 |
|
2823 | var arows = a._size[0];
|
2824 | var brows = b._size[0];
|
2825 |
|
2826 | var cvalues = [];
|
2827 | var cindex = [];
|
2828 | var cptr = [];
|
2829 |
|
2830 | var dt;
|
2831 |
|
2832 | var af = addScalar;
|
2833 |
|
2834 | var mf = multiplyScalar;
|
2835 |
|
2836 | var eq = equalScalar;
|
2837 |
|
2838 | var zero = 0;
|
2839 |
|
2840 | if (adt && bdt && adt === bdt && typeof adt === 'string') {
|
2841 |
|
2842 | dt = adt;
|
2843 |
|
2844 | af = typed.find(addScalar, [dt, dt]);
|
2845 | mf = typed.find(multiplyScalar, [dt, dt]);
|
2846 | eq = typed.find(equalScalar, [dt, dt]);
|
2847 |
|
2848 | zero = typed.convert(0, dt);
|
2849 | }
|
2850 |
|
2851 |
|
2852 | var x = [];
|
2853 |
|
2854 | var w = [];
|
2855 |
|
2856 | cptr[0] = 0;
|
2857 |
|
2858 | for (var ib = 0; ib < brows; ib++) {
|
2859 |
|
2860 | var vbi = bdata[ib];
|
2861 |
|
2862 | if (!eq(vbi, zero)) {
|
2863 |
|
2864 | for (var ka0 = aptr[ib], ka1 = aptr[ib + 1], ka = ka0; ka < ka1; ka++) {
|
2865 |
|
2866 | var ia = aindex[ka];
|
2867 |
|
2868 | if (!w[ia]) {
|
2869 |
|
2870 | w[ia] = true;
|
2871 |
|
2872 | cindex.push(ia);
|
2873 |
|
2874 | x[ia] = mf(vbi, avalues[ka]);
|
2875 | } else {
|
2876 |
|
2877 | x[ia] = af(x[ia], mf(vbi, avalues[ka]));
|
2878 | }
|
2879 | }
|
2880 | }
|
2881 | }
|
2882 |
|
2883 |
|
2884 | for (var p1 = cindex.length, p = 0; p < p1; p++) {
|
2885 |
|
2886 | var ic = cindex[p];
|
2887 |
|
2888 | cvalues[p] = x[ic];
|
2889 | }
|
2890 |
|
2891 |
|
2892 | cptr[1] = cindex.length;
|
2893 |
|
2894 | return new SparseMatrix({
|
2895 | values: cvalues,
|
2896 | index: cindex,
|
2897 | ptr: cptr,
|
2898 | size: [arows, 1],
|
2899 | datatype: dt
|
2900 | });
|
2901 | }
|
2902 | |
2903 |
|
2904 |
|
2905 |
|
2906 |
|
2907 |
|
2908 |
|
2909 |
|
2910 |
|
2911 |
|
2912 | function _multiplySparseMatrixDenseMatrix(a, b) {
|
2913 |
|
2914 | var avalues = a._values;
|
2915 | var aindex = a._index;
|
2916 | var aptr = a._ptr;
|
2917 | var adt = a._datatype;
|
2918 |
|
2919 | if (!avalues) {
|
2920 | throw new Error('Cannot multiply Pattern only Matrix times Dense Matrix');
|
2921 | }
|
2922 |
|
2923 |
|
2924 | var bdata = b._data;
|
2925 | var bdt = b._datatype;
|
2926 |
|
2927 | var arows = a._size[0];
|
2928 | var brows = b._size[0];
|
2929 | var bcolumns = b._size[1];
|
2930 |
|
2931 | var dt;
|
2932 |
|
2933 | var af = addScalar;
|
2934 |
|
2935 | var mf = multiplyScalar;
|
2936 |
|
2937 | var eq = equalScalar;
|
2938 |
|
2939 | var zero = 0;
|
2940 |
|
2941 | if (adt && bdt && adt === bdt && typeof adt === 'string') {
|
2942 |
|
2943 | dt = adt;
|
2944 |
|
2945 | af = typed.find(addScalar, [dt, dt]);
|
2946 | mf = typed.find(multiplyScalar, [dt, dt]);
|
2947 | eq = typed.find(equalScalar, [dt, dt]);
|
2948 |
|
2949 | zero = typed.convert(0, dt);
|
2950 | }
|
2951 |
|
2952 |
|
2953 | var cvalues = [];
|
2954 | var cindex = [];
|
2955 | var cptr = [];
|
2956 |
|
2957 | var c = new SparseMatrix({
|
2958 | values: cvalues,
|
2959 | index: cindex,
|
2960 | ptr: cptr,
|
2961 | size: [arows, bcolumns],
|
2962 | datatype: dt
|
2963 | });
|
2964 |
|
2965 | var x = [];
|
2966 |
|
2967 | var w = [];
|
2968 |
|
2969 | for (var jb = 0; jb < bcolumns; jb++) {
|
2970 |
|
2971 | cptr[jb] = cindex.length;
|
2972 |
|
2973 | var mark = jb + 1;
|
2974 |
|
2975 | for (var ib = 0; ib < brows; ib++) {
|
2976 |
|
2977 | var vbij = bdata[ib][jb];
|
2978 |
|
2979 | if (!eq(vbij, zero)) {
|
2980 |
|
2981 | for (var ka0 = aptr[ib], ka1 = aptr[ib + 1], ka = ka0; ka < ka1; ka++) {
|
2982 |
|
2983 | var ia = aindex[ka];
|
2984 |
|
2985 | if (w[ia] !== mark) {
|
2986 |
|
2987 | w[ia] = mark;
|
2988 |
|
2989 | cindex.push(ia);
|
2990 |
|
2991 | x[ia] = mf(vbij, avalues[ka]);
|
2992 | } else {
|
2993 |
|
2994 | x[ia] = af(x[ia], mf(vbij, avalues[ka]));
|
2995 | }
|
2996 | }
|
2997 | }
|
2998 | }
|
2999 |
|
3000 |
|
3001 | for (var p0 = cptr[jb], p1 = cindex.length, p = p0; p < p1; p++) {
|
3002 |
|
3003 | var ic = cindex[p];
|
3004 |
|
3005 | cvalues[p] = x[ic];
|
3006 | }
|
3007 | }
|
3008 |
|
3009 |
|
3010 | cptr[bcolumns] = cindex.length;
|
3011 |
|
3012 | return c;
|
3013 | }
|
3014 | |
3015 |
|
3016 |
|
3017 |
|
3018 |
|
3019 |
|
3020 |
|
3021 |
|
3022 |
|
3023 |
|
3024 | function _multiplySparseMatrixSparseMatrix(a, b) {
|
3025 |
|
3026 | var avalues = a._values;
|
3027 | var aindex = a._index;
|
3028 | var aptr = a._ptr;
|
3029 | var adt = a._datatype;
|
3030 |
|
3031 | var bvalues = b._values;
|
3032 | var bindex = b._index;
|
3033 | var bptr = b._ptr;
|
3034 | var bdt = b._datatype;
|
3035 |
|
3036 | var arows = a._size[0];
|
3037 | var bcolumns = b._size[1];
|
3038 |
|
3039 | var values = avalues && bvalues;
|
3040 |
|
3041 | var dt;
|
3042 |
|
3043 | var af = addScalar;
|
3044 |
|
3045 | var mf = multiplyScalar;
|
3046 |
|
3047 | if (adt && bdt && adt === bdt && typeof adt === 'string') {
|
3048 |
|
3049 | dt = adt;
|
3050 |
|
3051 | af = typed.find(addScalar, [dt, dt]);
|
3052 | mf = typed.find(multiplyScalar, [dt, dt]);
|
3053 | }
|
3054 |
|
3055 |
|
3056 | var cvalues = values ? [] : undefined;
|
3057 | var cindex = [];
|
3058 | var cptr = [];
|
3059 |
|
3060 | var c = new SparseMatrix({
|
3061 | values: cvalues,
|
3062 | index: cindex,
|
3063 | ptr: cptr,
|
3064 | size: [arows, bcolumns],
|
3065 | datatype: dt
|
3066 | });
|
3067 |
|
3068 | var x = values ? [] : undefined;
|
3069 |
|
3070 | var w = [];
|
3071 |
|
3072 | var ka, ka0, ka1, kb, kb0, kb1, ia, ib;
|
3073 |
|
3074 | for (var jb = 0; jb < bcolumns; jb++) {
|
3075 |
|
3076 | cptr[jb] = cindex.length;
|
3077 |
|
3078 | var mark = jb + 1;
|
3079 |
|
3080 | for (kb0 = bptr[jb], kb1 = bptr[jb + 1], kb = kb0; kb < kb1; kb++) {
|
3081 |
|
3082 | ib = bindex[kb];
|
3083 |
|
3084 | if (values) {
|
3085 |
|
3086 | for (ka0 = aptr[ib], ka1 = aptr[ib + 1], ka = ka0; ka < ka1; ka++) {
|
3087 |
|
3088 | ia = aindex[ka];
|
3089 |
|
3090 | if (w[ia] !== mark) {
|
3091 |
|
3092 | w[ia] = mark;
|
3093 |
|
3094 | cindex.push(ia);
|
3095 |
|
3096 | x[ia] = mf(bvalues[kb], avalues[ka]);
|
3097 | } else {
|
3098 |
|
3099 | x[ia] = af(x[ia], mf(bvalues[kb], avalues[ka]));
|
3100 | }
|
3101 | }
|
3102 | } else {
|
3103 |
|
3104 | for (ka0 = aptr[ib], ka1 = aptr[ib + 1], ka = ka0; ka < ka1; ka++) {
|
3105 |
|
3106 | ia = aindex[ka];
|
3107 |
|
3108 | if (w[ia] !== mark) {
|
3109 |
|
3110 | w[ia] = mark;
|
3111 |
|
3112 | cindex.push(ia);
|
3113 | }
|
3114 | }
|
3115 | }
|
3116 | }
|
3117 |
|
3118 |
|
3119 | if (values) {
|
3120 |
|
3121 | for (var p0 = cptr[jb], p1 = cindex.length, p = p0; p < p1; p++) {
|
3122 |
|
3123 | var ic = cindex[p];
|
3124 |
|
3125 | cvalues[p] = x[ic];
|
3126 | }
|
3127 | }
|
3128 | }
|
3129 |
|
3130 |
|
3131 | cptr[bcolumns] = cindex.length;
|
3132 |
|
3133 | return c;
|
3134 | }
|
3135 |
|
3136 | multiply.toTex = {
|
3137 | 2: "\\left(${args[0]}".concat(latex.operators['multiply'], "${args[1]}\\right)")
|
3138 | };
|
3139 | return multiply;
|
3140 | }
|
3141 |
|
3142 | exports.name = 'multiply';
|
3143 | exports.factory = factory;
|
3144 |
|
3145 | }),
|
3146 |
|
3147 | (function(module, exports, __webpack_require__) {
|
3148 |
|
3149 | "use strict";
|
3150 |
|
3151 |
|
3152 | var nearlyEqual = __webpack_require__(3).nearlyEqual;
|
3153 |
|
3154 | var bigNearlyEqual = __webpack_require__(32);
|
3155 |
|
3156 | function factory(type, config, load, typed) {
|
3157 | |
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 |
|
3164 |
|
3165 | var equalScalar = typed('equalScalar', {
|
3166 | 'boolean, boolean': function booleanBoolean(x, y) {
|
3167 | return x === y;
|
3168 | },
|
3169 | 'number, number': function numberNumber(x, y) {
|
3170 | return x === y || nearlyEqual(x, y, config.epsilon);
|
3171 | },
|
3172 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
3173 | return x.eq(y) || bigNearlyEqual(x, y, config.epsilon);
|
3174 | },
|
3175 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
3176 | return x.equals(y);
|
3177 | },
|
3178 | 'Complex, Complex': function ComplexComplex(x, y) {
|
3179 | return x.equals(y);
|
3180 | },
|
3181 | 'Unit, Unit': function UnitUnit(x, y) {
|
3182 | if (!x.equalBase(y)) {
|
3183 | throw new Error('Cannot compare units with different base');
|
3184 | }
|
3185 |
|
3186 | return equalScalar(x.value, y.value);
|
3187 | }
|
3188 | });
|
3189 | return equalScalar;
|
3190 | }
|
3191 |
|
3192 | exports.factory = factory;
|
3193 |
|
3194 | }),
|
3195 |
|
3196 | (function(module, exports, __webpack_require__) {
|
3197 |
|
3198 | "use strict";
|
3199 |
|
3200 |
|
3201 | function factory(type, config, load, typed) {
|
3202 | var numeric = load(__webpack_require__(65));
|
3203 | var getTypeOf = load(__webpack_require__(26));
|
3204 | |
3205 |
|
3206 |
|
3207 |
|
3208 |
|
3209 |
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 |
|
3217 |
|
3218 | var divideScalar = typed('divide', {
|
3219 | 'number, number': function numberNumber(x, y) {
|
3220 | return x / y;
|
3221 | },
|
3222 | 'Complex, Complex': function ComplexComplex(x, y) {
|
3223 | return x.div(y);
|
3224 | },
|
3225 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
3226 | return x.div(y);
|
3227 | },
|
3228 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
3229 | return x.div(y);
|
3230 | },
|
3231 | 'Unit, number | Fraction | BigNumber': function UnitNumberFractionBigNumber(x, y) {
|
3232 | var res = x.clone();
|
3233 |
|
3234 | var one = numeric(1, getTypeOf(y));
|
3235 | res.value = divideScalar(res.value === null ? res._normalize(one) : res.value, y);
|
3236 | return res;
|
3237 | },
|
3238 | 'number | Fraction | BigNumber, Unit': function numberFractionBigNumberUnit(x, y) {
|
3239 | var res = y.clone();
|
3240 | res = res.pow(-1);
|
3241 |
|
3242 | var one = numeric(1, getTypeOf(x));
|
3243 | res.value = divideScalar(x, y.value === null ? y._normalize(one) : y.value);
|
3244 | return res;
|
3245 | },
|
3246 | 'Unit, Unit': function UnitUnit(x, y) {
|
3247 | return x.divide(y);
|
3248 | }
|
3249 | });
|
3250 | return divideScalar;
|
3251 | }
|
3252 |
|
3253 | exports.factory = factory;
|
3254 |
|
3255 | }),
|
3256 |
|
3257 | (function(module, exports, __webpack_require__) {
|
3258 |
|
3259 | "use strict";
|
3260 |
|
3261 |
|
3262 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
3263 |
|
3264 | var hasOwnProperty = __webpack_require__(5).hasOwnProperty;
|
3265 |
|
3266 |
|
3267 |
|
3268 |
|
3269 |
|
3270 |
|
3271 |
|
3272 |
|
3273 |
|
3274 |
|
3275 | function getSafeProperty(object, prop) {
|
3276 |
|
3277 | if (isPlainObject(object) && isSafeProperty(object, prop)) {
|
3278 | return object[prop];
|
3279 | }
|
3280 |
|
3281 | if (typeof object[prop] === 'function' && isSafeMethod(object, prop)) {
|
3282 | throw new Error('Cannot access method "' + prop + '" as a property');
|
3283 | }
|
3284 |
|
3285 | throw new Error('No access to property "' + prop + '"');
|
3286 | }
|
3287 |
|
3288 |
|
3289 |
|
3290 |
|
3291 |
|
3292 |
|
3293 |
|
3294 |
|
3295 |
|
3296 |
|
3297 |
|
3298 |
|
3299 | function setSafeProperty(object, prop, value) {
|
3300 |
|
3301 | if (isPlainObject(object) && isSafeProperty(object, prop)) {
|
3302 | object[prop] = value;
|
3303 | return value;
|
3304 | }
|
3305 |
|
3306 | throw new Error('No access to property "' + prop + '"');
|
3307 | }
|
3308 |
|
3309 |
|
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 |
|
3315 |
|
3316 | function isSafeProperty(object, prop) {
|
3317 | if (!object || _typeof(object) !== 'object') {
|
3318 | return false;
|
3319 | }
|
3320 |
|
3321 |
|
3322 |
|
3323 | if (hasOwnProperty(safeNativeProperties, prop)) {
|
3324 | return true;
|
3325 | }
|
3326 |
|
3327 |
|
3328 |
|
3329 | if (prop in Object.prototype) {
|
3330 |
|
3331 |
|
3332 |
|
3333 | return false;
|
3334 | }
|
3335 |
|
3336 |
|
3337 |
|
3338 | if (prop in Function.prototype) {
|
3339 |
|
3340 |
|
3341 |
|
3342 | return false;
|
3343 | }
|
3344 |
|
3345 | return true;
|
3346 | }
|
3347 |
|
3348 |
|
3349 |
|
3350 |
|
3351 |
|
3352 |
|
3353 |
|
3354 |
|
3355 |
|
3356 | function validateSafeMethod(object, method) {
|
3357 | if (!isSafeMethod(object, method)) {
|
3358 | throw new Error('No access to method "' + method + '"');
|
3359 | }
|
3360 | }
|
3361 |
|
3362 |
|
3363 |
|
3364 |
|
3365 |
|
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 | function isSafeMethod(object, method) {
|
3371 | if (!object || typeof object[method] !== 'function') {
|
3372 | return false;
|
3373 | }
|
3374 |
|
3375 |
|
3376 |
|
3377 |
|
3378 | if (hasOwnProperty(object, method) && Object.getPrototypeOf && method in Object.getPrototypeOf(object)) {
|
3379 | return false;
|
3380 | }
|
3381 |
|
3382 |
|
3383 |
|
3384 | if (hasOwnProperty(safeNativeMethods, method)) {
|
3385 | return true;
|
3386 | }
|
3387 |
|
3388 |
|
3389 |
|
3390 | if (method in Object.prototype) {
|
3391 |
|
3392 |
|
3393 |
|
3394 | return false;
|
3395 | }
|
3396 |
|
3397 |
|
3398 |
|
3399 | if (method in Function.prototype) {
|
3400 |
|
3401 |
|
3402 |
|
3403 | return false;
|
3404 | }
|
3405 |
|
3406 | return true;
|
3407 | }
|
3408 |
|
3409 | function isPlainObject(object) {
|
3410 | return _typeof(object) === 'object' && object && object.constructor === Object;
|
3411 | }
|
3412 |
|
3413 | var safeNativeProperties = {
|
3414 | length: true,
|
3415 | name: true
|
3416 | };
|
3417 | var safeNativeMethods = {
|
3418 | toString: true,
|
3419 | valueOf: true,
|
3420 | toLocaleString: true
|
3421 | };
|
3422 | exports.getSafeProperty = getSafeProperty;
|
3423 | exports.setSafeProperty = setSafeProperty;
|
3424 | exports.isSafeProperty = isSafeProperty;
|
3425 | exports.validateSafeMethod = validateSafeMethod;
|
3426 | exports.isSafeMethod = isSafeMethod;
|
3427 | exports.isPlainObject = isPlainObject;
|
3428 |
|
3429 | }),
|
3430 |
|
3431 | (function(module, exports, __webpack_require__) {
|
3432 |
|
3433 | "use strict";
|
3434 |
|
3435 |
|
3436 | var extend = __webpack_require__(5).extend;
|
3437 |
|
3438 | function factory(type, config, load, typed) {
|
3439 | var matrix = load(__webpack_require__(0));
|
3440 | var addScalar = load(__webpack_require__(17));
|
3441 |
|
3442 | var latex = __webpack_require__(4);
|
3443 |
|
3444 | var algorithm01 = load(__webpack_require__(37));
|
3445 | var algorithm04 = load(__webpack_require__(85));
|
3446 | var algorithm10 = load(__webpack_require__(41));
|
3447 | var algorithm13 = load(__webpack_require__(7));
|
3448 | var algorithm14 = load(__webpack_require__(6));
|
3449 | |
3450 |
|
3451 |
|
3452 |
|
3453 |
|
3454 |
|
3455 |
|
3456 |
|
3457 |
|
3458 |
|
3459 |
|
3460 |
|
3461 |
|
3462 |
|
3463 |
|
3464 |
|
3465 |
|
3466 |
|
3467 |
|
3468 |
|
3469 |
|
3470 |
|
3471 |
|
3472 |
|
3473 |
|
3474 |
|
3475 |
|
3476 |
|
3477 |
|
3478 |
|
3479 |
|
3480 |
|
3481 |
|
3482 |
|
3483 |
|
3484 | var add = typed('add', extend({
|
3485 |
|
3486 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
3487 | return algorithm13(x, y, addScalar);
|
3488 | },
|
3489 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
3490 | return algorithm01(x, y, addScalar, false);
|
3491 | },
|
3492 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
3493 | return algorithm01(y, x, addScalar, true);
|
3494 | },
|
3495 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
3496 | return algorithm04(x, y, addScalar);
|
3497 | },
|
3498 | 'Array, Array': function ArrayArray(x, y) {
|
3499 |
|
3500 | return add(matrix(x), matrix(y)).valueOf();
|
3501 | },
|
3502 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
3503 |
|
3504 | return add(matrix(x), y);
|
3505 | },
|
3506 | 'Matrix, Array': function MatrixArray(x, y) {
|
3507 |
|
3508 | return add(x, matrix(y));
|
3509 | },
|
3510 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
3511 | return algorithm14(x, y, addScalar, false);
|
3512 | },
|
3513 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
3514 | return algorithm10(x, y, addScalar, false);
|
3515 | },
|
3516 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
3517 | return algorithm14(y, x, addScalar, true);
|
3518 | },
|
3519 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
3520 | return algorithm10(y, x, addScalar, true);
|
3521 | },
|
3522 | 'Array, any': function ArrayAny(x, y) {
|
3523 |
|
3524 | return algorithm14(matrix(x), y, addScalar, false).valueOf();
|
3525 | },
|
3526 | 'any, Array': function anyArray(x, y) {
|
3527 |
|
3528 | return algorithm14(matrix(y), x, addScalar, true).valueOf();
|
3529 | },
|
3530 | 'any, any': addScalar,
|
3531 | 'any, any, ...any': function anyAnyAny(x, y, rest) {
|
3532 | var result = add(x, y);
|
3533 |
|
3534 | for (var i = 0; i < rest.length; i++) {
|
3535 | result = add(result, rest[i]);
|
3536 | }
|
3537 |
|
3538 | return result;
|
3539 | }
|
3540 | }, addScalar.signatures));
|
3541 | add.toTex = {
|
3542 | 2: "\\left(${args[0]}".concat(latex.operators['add'], "${args[1]}\\right)")
|
3543 | };
|
3544 | return add;
|
3545 | }
|
3546 |
|
3547 | exports.name = 'add';
|
3548 | exports.factory = factory;
|
3549 |
|
3550 | }),
|
3551 |
|
3552 | (function(module, exports, __webpack_require__) {
|
3553 |
|
3554 | "use strict";
|
3555 |
|
3556 |
|
3557 | var DimensionError = __webpack_require__(8);
|
3558 |
|
3559 | function factory(type, config, load, typed) {
|
3560 | var latex = __webpack_require__(4);
|
3561 |
|
3562 | var matrix = load(__webpack_require__(0));
|
3563 | var addScalar = load(__webpack_require__(17));
|
3564 | var unaryMinus = load(__webpack_require__(39));
|
3565 | var algorithm01 = load(__webpack_require__(37));
|
3566 | var algorithm03 = load(__webpack_require__(18));
|
3567 | var algorithm05 = load(__webpack_require__(66));
|
3568 | var algorithm10 = load(__webpack_require__(41));
|
3569 | var algorithm13 = load(__webpack_require__(7));
|
3570 | var algorithm14 = load(__webpack_require__(6));
|
3571 |
|
3572 | |
3573 |
|
3574 |
|
3575 |
|
3576 |
|
3577 |
|
3578 |
|
3579 |
|
3580 |
|
3581 |
|
3582 |
|
3583 |
|
3584 |
|
3585 |
|
3586 |
|
3587 |
|
3588 |
|
3589 |
|
3590 |
|
3591 |
|
3592 |
|
3593 |
|
3594 |
|
3595 |
|
3596 |
|
3597 |
|
3598 |
|
3599 |
|
3600 |
|
3601 |
|
3602 |
|
3603 |
|
3604 |
|
3605 |
|
3606 | var subtract = typed('subtract', {
|
3607 | 'number, number': function numberNumber(x, y) {
|
3608 | return x - y;
|
3609 | },
|
3610 | 'Complex, Complex': function ComplexComplex(x, y) {
|
3611 | return x.sub(y);
|
3612 | },
|
3613 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
3614 | return x.minus(y);
|
3615 | },
|
3616 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
3617 | return x.sub(y);
|
3618 | },
|
3619 | 'Unit, Unit': function UnitUnit(x, y) {
|
3620 | if (x.value === null) {
|
3621 | throw new Error('Parameter x contains a unit with undefined value');
|
3622 | }
|
3623 |
|
3624 | if (y.value === null) {
|
3625 | throw new Error('Parameter y contains a unit with undefined value');
|
3626 | }
|
3627 |
|
3628 | if (!x.equalBase(y)) {
|
3629 | throw new Error('Units do not match');
|
3630 | }
|
3631 |
|
3632 | var res = x.clone();
|
3633 | res.value = subtract(res.value, y.value);
|
3634 | res.fixPrefix = false;
|
3635 | return res;
|
3636 | },
|
3637 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
3638 | checkEqualDimensions(x, y);
|
3639 | return algorithm05(x, y, subtract);
|
3640 | },
|
3641 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
3642 | checkEqualDimensions(x, y);
|
3643 | return algorithm03(y, x, subtract, true);
|
3644 | },
|
3645 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
3646 | checkEqualDimensions(x, y);
|
3647 | return algorithm01(x, y, subtract, false);
|
3648 | },
|
3649 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
3650 | checkEqualDimensions(x, y);
|
3651 | return algorithm13(x, y, subtract);
|
3652 | },
|
3653 | 'Array, Array': function ArrayArray(x, y) {
|
3654 |
|
3655 | return subtract(matrix(x), matrix(y)).valueOf();
|
3656 | },
|
3657 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
3658 |
|
3659 | return subtract(matrix(x), y);
|
3660 | },
|
3661 | 'Matrix, Array': function MatrixArray(x, y) {
|
3662 |
|
3663 | return subtract(x, matrix(y));
|
3664 | },
|
3665 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
3666 | return algorithm10(x, unaryMinus(y), addScalar);
|
3667 | },
|
3668 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
3669 | return algorithm14(x, y, subtract);
|
3670 | },
|
3671 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
3672 | return algorithm10(y, x, subtract, true);
|
3673 | },
|
3674 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
3675 | return algorithm14(y, x, subtract, true);
|
3676 | },
|
3677 | 'Array, any': function ArrayAny(x, y) {
|
3678 |
|
3679 | return algorithm14(matrix(x), y, subtract, false).valueOf();
|
3680 | },
|
3681 | 'any, Array': function anyArray(x, y) {
|
3682 |
|
3683 | return algorithm14(matrix(y), x, subtract, true).valueOf();
|
3684 | }
|
3685 | });
|
3686 | subtract.toTex = {
|
3687 | 2: "\\left(${args[0]}".concat(latex.operators['subtract'], "${args[1]}\\right)")
|
3688 | };
|
3689 | return subtract;
|
3690 | }
|
3691 |
|
3692 |
|
3693 |
|
3694 |
|
3695 |
|
3696 |
|
3697 |
|
3698 |
|
3699 | function checkEqualDimensions(x, y) {
|
3700 | var xsize = x.size();
|
3701 | var ysize = y.size();
|
3702 |
|
3703 | if (xsize.length !== ysize.length) {
|
3704 | throw new DimensionError(xsize.length, ysize.length);
|
3705 | }
|
3706 | }
|
3707 |
|
3708 | exports.name = 'subtract';
|
3709 | exports.factory = factory;
|
3710 |
|
3711 | }),
|
3712 |
|
3713 | (function(module, exports, __webpack_require__) {
|
3714 |
|
3715 | "use strict";
|
3716 |
|
3717 |
|
3718 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
3719 |
|
3720 | var keywords = __webpack_require__(114);
|
3721 |
|
3722 | var deepEqual = __webpack_require__(5).deepEqual;
|
3723 |
|
3724 | var hasOwnProperty = __webpack_require__(5).hasOwnProperty;
|
3725 |
|
3726 | function factory(type, config, load, typed, math) {
|
3727 | |
3728 |
|
3729 |
|
3730 | function Node() {
|
3731 | if (!(this instanceof Node)) {
|
3732 | throw new SyntaxError('Constructor must be called with the new operator');
|
3733 | }
|
3734 | }
|
3735 | |
3736 |
|
3737 |
|
3738 |
|
3739 |
|
3740 |
|
3741 |
|
3742 | Node.prototype.eval = function (scope) {
|
3743 | return this.compile().eval(scope);
|
3744 | };
|
3745 |
|
3746 | Node.prototype.type = 'Node';
|
3747 | Node.prototype.isNode = true;
|
3748 | Node.prototype.comment = '';
|
3749 | |
3750 |
|
3751 |
|
3752 |
|
3753 |
|
3754 |
|
3755 |
|
3756 |
|
3757 | Node.prototype.compile = function () {
|
3758 | var expr = this._compile(math.expression.mathWithTransform, {});
|
3759 |
|
3760 | var args = {};
|
3761 | var context = null;
|
3762 | return {
|
3763 | eval: function evalNode(scope) {
|
3764 | var s = scope || {};
|
3765 |
|
3766 | _validateScope(s);
|
3767 |
|
3768 | return expr(s, args, context);
|
3769 | }
|
3770 | };
|
3771 | };
|
3772 | |
3773 |
|
3774 |
|
3775 |
|
3776 |
|
3777 |
|
3778 |
|
3779 |
|
3780 |
|
3781 |
|
3782 |
|
3783 |
|
3784 |
|
3785 |
|
3786 |
|
3787 | Node.prototype._compile = function (math, argNames) {
|
3788 | throw new Error('Method _compile should be implemented by type ' + this.type);
|
3789 | };
|
3790 | |
3791 |
|
3792 |
|
3793 |
|
3794 |
|
3795 |
|
3796 | Node.prototype.forEach = function (callback) {
|
3797 |
|
3798 | throw new Error('Cannot run forEach on a Node interface');
|
3799 | };
|
3800 | |
3801 |
|
3802 |
|
3803 |
|
3804 |
|
3805 |
|
3806 |
|
3807 |
|
3808 | Node.prototype.map = function (callback) {
|
3809 |
|
3810 | throw new Error('Cannot run map on a Node interface');
|
3811 | };
|
3812 | |
3813 |
|
3814 |
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 |
|
3820 | Node.prototype._ifNode = function (node) {
|
3821 | if (!type.isNode(node)) {
|
3822 | throw new TypeError('Callback function must return a Node');
|
3823 | }
|
3824 |
|
3825 | return node;
|
3826 | };
|
3827 | |
3828 |
|
3829 |
|
3830 |
|
3831 |
|
3832 |
|
3833 |
|
3834 |
|
3835 | Node.prototype.traverse = function (callback) {
|
3836 |
|
3837 | callback(this, null, null);
|
3838 |
|
3839 |
|
3840 | function _traverse(node, callback) {
|
3841 | node.forEach(function (child, path, parent) {
|
3842 | callback(child, path, parent);
|
3843 |
|
3844 | _traverse(child, callback);
|
3845 | });
|
3846 | }
|
3847 |
|
3848 | _traverse(this, callback);
|
3849 | };
|
3850 | |
3851 |
|
3852 |
|
3853 |
|
3854 |
|
3855 |
|
3856 |
|
3857 |
|
3858 |
|
3859 |
|
3860 |
|
3861 |
|
3862 |
|
3863 |
|
3864 |
|
3865 |
|
3866 |
|
3867 |
|
3868 |
|
3869 |
|
3870 |
|
3871 |
|
3872 |
|
3873 | Node.prototype.transform = function (callback) {
|
3874 |
|
3875 | function _transform(node, callback) {
|
3876 | return node.map(function (child, path, parent) {
|
3877 | var replacement = callback(child, path, parent);
|
3878 | return _transform(replacement, callback);
|
3879 | });
|
3880 | }
|
3881 |
|
3882 | var replacement = callback(this, null, null);
|
3883 |
|
3884 | return _transform(replacement, callback);
|
3885 | };
|
3886 | |
3887 |
|
3888 |
|
3889 |
|
3890 |
|
3891 |
|
3892 |
|
3893 |
|
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 |
|
3900 |
|
3901 |
|
3902 | Node.prototype.filter = function (callback) {
|
3903 | var nodes = [];
|
3904 | this.traverse(function (node, path, parent) {
|
3905 | if (callback(node, path, parent)) {
|
3906 | nodes.push(node);
|
3907 | }
|
3908 | });
|
3909 | return nodes;
|
3910 | };
|
3911 |
|
3912 |
|
3913 | Node.prototype.find = function () {
|
3914 | throw new Error('Function Node.find is deprecated. Use Node.filter instead.');
|
3915 | };
|
3916 |
|
3917 |
|
3918 | Node.prototype.match = function () {
|
3919 | throw new Error('Function Node.match is deprecated. See functions Node.filter, Node.transform, Node.traverse.');
|
3920 | };
|
3921 | |
3922 |
|
3923 |
|
3924 |
|
3925 |
|
3926 |
|
3927 | Node.prototype.clone = function () {
|
3928 |
|
3929 | throw new Error('Cannot clone a Node interface');
|
3930 | };
|
3931 | |
3932 |
|
3933 |
|
3934 |
|
3935 |
|
3936 |
|
3937 | Node.prototype.cloneDeep = function () {
|
3938 | return this.map(function (node) {
|
3939 | return node.cloneDeep();
|
3940 | });
|
3941 | };
|
3942 | |
3943 |
|
3944 |
|
3945 |
|
3946 |
|
3947 |
|
3948 |
|
3949 |
|
3950 | Node.prototype.equals = function (other) {
|
3951 | return other ? deepEqual(this, other) : false;
|
3952 | };
|
3953 | |
3954 |
|
3955 |
|
3956 |
|
3957 |
|
3958 |
|
3959 |
|
3960 |
|
3961 |
|
3962 |
|
3963 |
|
3964 |
|
3965 |
|
3966 |
|
3967 |
|
3968 |
|
3969 |
|
3970 | Node.prototype.toString = function (options) {
|
3971 | var customString;
|
3972 |
|
3973 | if (options && _typeof(options) === 'object') {
|
3974 | switch (_typeof(options.handler)) {
|
3975 | case 'object':
|
3976 | case 'undefined':
|
3977 | break;
|
3978 |
|
3979 | case 'function':
|
3980 | customString = options.handler(this, options);
|
3981 | break;
|
3982 |
|
3983 | default:
|
3984 | throw new TypeError('Object or function expected as callback');
|
3985 | }
|
3986 | }
|
3987 |
|
3988 | if (typeof customString !== 'undefined') {
|
3989 | return customString;
|
3990 | }
|
3991 |
|
3992 | return this._toString(options);
|
3993 | };
|
3994 | |
3995 |
|
3996 |
|
3997 |
|
3998 |
|
3999 |
|
4000 |
|
4001 |
|
4002 | Node.prototype.toJSON = function () {
|
4003 | throw new Error('Cannot serialize object: toJSON not implemented by ' + this.type);
|
4004 | };
|
4005 | |
4006 |
|
4007 |
|
4008 |
|
4009 |
|
4010 |
|
4011 |
|
4012 |
|
4013 |
|
4014 |
|
4015 |
|
4016 |
|
4017 |
|
4018 |
|
4019 |
|
4020 |
|
4021 |
|
4022 | Node.prototype.toHTML = function (options) {
|
4023 | var customString;
|
4024 |
|
4025 | if (options && _typeof(options) === 'object') {
|
4026 | switch (_typeof(options.handler)) {
|
4027 | case 'object':
|
4028 | case 'undefined':
|
4029 | break;
|
4030 |
|
4031 | case 'function':
|
4032 | customString = options.handler(this, options);
|
4033 | break;
|
4034 |
|
4035 | default:
|
4036 | throw new TypeError('Object or function expected as callback');
|
4037 | }
|
4038 | }
|
4039 |
|
4040 | if (typeof customString !== 'undefined') {
|
4041 | return customString;
|
4042 | }
|
4043 |
|
4044 | return this.toHTML(options);
|
4045 | };
|
4046 | |
4047 |
|
4048 |
|
4049 |
|
4050 |
|
4051 |
|
4052 |
|
4053 |
|
4054 | Node.prototype._toString = function () {
|
4055 |
|
4056 | throw new Error('_toString not implemented for ' + this.type);
|
4057 | };
|
4058 | |
4059 |
|
4060 |
|
4061 |
|
4062 |
|
4063 |
|
4064 |
|
4065 |
|
4066 |
|
4067 |
|
4068 |
|
4069 |
|
4070 |
|
4071 |
|
4072 |
|
4073 |
|
4074 |
|
4075 | Node.prototype.toTex = function (options) {
|
4076 | var customTex;
|
4077 |
|
4078 | if (options && _typeof(options) === 'object') {
|
4079 | switch (_typeof(options.handler)) {
|
4080 | case 'object':
|
4081 | case 'undefined':
|
4082 | break;
|
4083 |
|
4084 | case 'function':
|
4085 | customTex = options.handler(this, options);
|
4086 | break;
|
4087 |
|
4088 | default:
|
4089 | throw new TypeError('Object or function expected as callback');
|
4090 | }
|
4091 | }
|
4092 |
|
4093 | if (typeof customTex !== 'undefined') {
|
4094 | return customTex;
|
4095 | }
|
4096 |
|
4097 | return this._toTex(options);
|
4098 | };
|
4099 | |
4100 |
|
4101 |
|
4102 |
|
4103 |
|
4104 |
|
4105 |
|
4106 |
|
4107 |
|
4108 | Node.prototype._toTex = function (options) {
|
4109 |
|
4110 | throw new Error('_toTex not implemented for ' + this.type);
|
4111 | };
|
4112 | |
4113 |
|
4114 |
|
4115 |
|
4116 |
|
4117 |
|
4118 | Node.prototype.getIdentifier = function () {
|
4119 | return this.type;
|
4120 | };
|
4121 | |
4122 |
|
4123 |
|
4124 |
|
4125 |
|
4126 |
|
4127 | Node.prototype.getContent = function () {
|
4128 | return this;
|
4129 | };
|
4130 | |
4131 |
|
4132 |
|
4133 |
|
4134 |
|
4135 |
|
4136 |
|
4137 | function _validateScope(scope) {
|
4138 | for (var symbol in scope) {
|
4139 | if (hasOwnProperty(scope, symbol)) {
|
4140 | if (symbol in keywords) {
|
4141 | throw new Error('Scope contains an illegal symbol, "' + symbol + '" is a reserved keyword');
|
4142 | }
|
4143 | }
|
4144 | }
|
4145 | }
|
4146 |
|
4147 | return Node;
|
4148 | }
|
4149 |
|
4150 | exports.name = 'Node';
|
4151 | exports.path = 'expression.node';
|
4152 | exports.math = true;
|
4153 |
|
4154 | exports.factory = factory;
|
4155 |
|
4156 | }),
|
4157 |
|
4158 | (function(module, exports, __webpack_require__) {
|
4159 |
|
4160 | "use strict";
|
4161 |
|
4162 |
|
4163 | function factory(type, config, load, typed) {
|
4164 | |
4165 |
|
4166 |
|
4167 |
|
4168 |
|
4169 |
|
4170 |
|
4171 |
|
4172 |
|
4173 |
|
4174 |
|
4175 |
|
4176 |
|
4177 | var add = typed('add', {
|
4178 | 'number, number': function numberNumber(x, y) {
|
4179 | return x + y;
|
4180 | },
|
4181 | 'Complex, Complex': function ComplexComplex(x, y) {
|
4182 | return x.add(y);
|
4183 | },
|
4184 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
4185 | return x.plus(y);
|
4186 | },
|
4187 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
4188 | return x.add(y);
|
4189 | },
|
4190 | 'Unit, Unit': function UnitUnit(x, y) {
|
4191 | if (x.value === null || x.value === undefined) throw new Error('Parameter x contains a unit with undefined value');
|
4192 | if (y.value === null || y.value === undefined) throw new Error('Parameter y contains a unit with undefined value');
|
4193 | if (!x.equalBase(y)) throw new Error('Units do not match');
|
4194 | var res = x.clone();
|
4195 | res.value = add(res.value, y.value);
|
4196 | res.fixPrefix = false;
|
4197 | return res;
|
4198 | }
|
4199 | });
|
4200 | return add;
|
4201 | }
|
4202 |
|
4203 | exports.factory = factory;
|
4204 |
|
4205 | }),
|
4206 |
|
4207 | (function(module, exports, __webpack_require__) {
|
4208 |
|
4209 | "use strict";
|
4210 |
|
4211 |
|
4212 | var DimensionError = __webpack_require__(8);
|
4213 |
|
4214 | function factory(type, config, load, typed) {
|
4215 | var DenseMatrix = type.DenseMatrix;
|
4216 | |
4217 |
|
4218 |
|
4219 |
|
4220 |
|
4221 |
|
4222 |
|
4223 |
|
4224 |
|
4225 |
|
4226 |
|
4227 |
|
4228 |
|
4229 |
|
4230 |
|
4231 |
|
4232 |
|
4233 |
|
4234 |
|
4235 |
|
4236 | var algorithm03 = function algorithm03(denseMatrix, sparseMatrix, callback, inverse) {
|
4237 |
|
4238 | var adata = denseMatrix._data;
|
4239 | var asize = denseMatrix._size;
|
4240 | var adt = denseMatrix._datatype;
|
4241 |
|
4242 | var bvalues = sparseMatrix._values;
|
4243 | var bindex = sparseMatrix._index;
|
4244 | var bptr = sparseMatrix._ptr;
|
4245 | var bsize = sparseMatrix._size;
|
4246 | var bdt = sparseMatrix._datatype;
|
4247 |
|
4248 | if (asize.length !== bsize.length) {
|
4249 | throw new DimensionError(asize.length, bsize.length);
|
4250 | }
|
4251 |
|
4252 |
|
4253 | if (asize[0] !== bsize[0] || asize[1] !== bsize[1]) {
|
4254 | throw new RangeError('Dimension mismatch. Matrix A (' + asize + ') must match Matrix B (' + bsize + ')');
|
4255 | }
|
4256 |
|
4257 |
|
4258 | if (!bvalues) {
|
4259 | throw new Error('Cannot perform operation on Dense Matrix and Pattern Sparse Matrix');
|
4260 | }
|
4261 |
|
4262 |
|
4263 | var rows = asize[0];
|
4264 | var columns = asize[1];
|
4265 |
|
4266 | var dt;
|
4267 |
|
4268 | var zero = 0;
|
4269 |
|
4270 | var cf = callback;
|
4271 |
|
4272 | if (typeof adt === 'string' && adt === bdt) {
|
4273 |
|
4274 | dt = adt;
|
4275 |
|
4276 | zero = typed.convert(0, dt);
|
4277 |
|
4278 | cf = typed.find(callback, [dt, dt]);
|
4279 | }
|
4280 |
|
4281 |
|
4282 | var cdata = [];
|
4283 |
|
4284 | for (var z = 0; z < rows; z++) {
|
4285 |
|
4286 | cdata[z] = [];
|
4287 | }
|
4288 |
|
4289 |
|
4290 | var x = [];
|
4291 |
|
4292 | var w = [];
|
4293 |
|
4294 | for (var j = 0; j < columns; j++) {
|
4295 |
|
4296 | var mark = j + 1;
|
4297 |
|
4298 | for (var k0 = bptr[j], k1 = bptr[j + 1], k = k0; k < k1; k++) {
|
4299 |
|
4300 | var i = bindex[k];
|
4301 |
|
4302 | x[i] = inverse ? cf(bvalues[k], adata[i][j]) : cf(adata[i][j], bvalues[k]);
|
4303 | w[i] = mark;
|
4304 | }
|
4305 |
|
4306 |
|
4307 | for (var y = 0; y < rows; y++) {
|
4308 |
|
4309 | if (w[y] === mark) {
|
4310 |
|
4311 | cdata[y][j] = x[y];
|
4312 | } else {
|
4313 |
|
4314 | cdata[y][j] = inverse ? cf(zero, adata[y][j]) : cf(adata[y][j], zero);
|
4315 | }
|
4316 | }
|
4317 | }
|
4318 |
|
4319 |
|
4320 | return new DenseMatrix({
|
4321 | data: cdata,
|
4322 | size: [rows, columns],
|
4323 | datatype: dt
|
4324 | });
|
4325 | };
|
4326 |
|
4327 | return algorithm03;
|
4328 | }
|
4329 |
|
4330 | exports.name = 'algorithm03';
|
4331 | exports.factory = factory;
|
4332 |
|
4333 | }),
|
4334 |
|
4335 | (function(module, exports, __webpack_require__) {
|
4336 |
|
4337 | "use strict";
|
4338 |
|
4339 |
|
4340 | function factory(type, config, load, typed) {
|
4341 | var DenseMatrix = type.DenseMatrix;
|
4342 | |
4343 |
|
4344 |
|
4345 |
|
4346 |
|
4347 |
|
4348 |
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 |
|
4356 |
|
4357 |
|
4358 |
|
4359 |
|
4360 |
|
4361 |
|
4362 | var algorithm12 = function algorithm12(s, b, callback, inverse) {
|
4363 |
|
4364 | var avalues = s._values;
|
4365 | var aindex = s._index;
|
4366 | var aptr = s._ptr;
|
4367 | var asize = s._size;
|
4368 | var adt = s._datatype;
|
4369 |
|
4370 | if (!avalues) {
|
4371 | throw new Error('Cannot perform operation on Pattern Sparse Matrix and Scalar value');
|
4372 | }
|
4373 |
|
4374 |
|
4375 | var rows = asize[0];
|
4376 | var columns = asize[1];
|
4377 |
|
4378 | var dt;
|
4379 |
|
4380 | var cf = callback;
|
4381 |
|
4382 | if (typeof adt === 'string') {
|
4383 |
|
4384 | dt = adt;
|
4385 |
|
4386 | b = typed.convert(b, dt);
|
4387 |
|
4388 | cf = typed.find(callback, [dt, dt]);
|
4389 | }
|
4390 |
|
4391 |
|
4392 | var cdata = [];
|
4393 |
|
4394 | var c = new DenseMatrix({
|
4395 | data: cdata,
|
4396 | size: [rows, columns],
|
4397 | datatype: dt
|
4398 | });
|
4399 |
|
4400 | var x = [];
|
4401 |
|
4402 | var w = [];
|
4403 |
|
4404 | for (var j = 0; j < columns; j++) {
|
4405 |
|
4406 | var mark = j + 1;
|
4407 |
|
4408 | for (var k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
|
4409 |
|
4410 | var r = aindex[k];
|
4411 |
|
4412 | x[r] = avalues[k];
|
4413 | w[r] = mark;
|
4414 | }
|
4415 |
|
4416 |
|
4417 | for (var i = 0; i < rows; i++) {
|
4418 |
|
4419 | if (j === 0) {
|
4420 |
|
4421 | cdata[i] = [];
|
4422 | }
|
4423 |
|
4424 |
|
4425 | if (w[i] === mark) {
|
4426 |
|
4427 | cdata[i][j] = inverse ? cf(b, x[i]) : cf(x[i], b);
|
4428 | } else {
|
4429 |
|
4430 | cdata[i][j] = inverse ? cf(b, 0) : cf(0, b);
|
4431 | }
|
4432 | }
|
4433 | }
|
4434 |
|
4435 |
|
4436 | return c;
|
4437 | };
|
4438 |
|
4439 | return algorithm12;
|
4440 | }
|
4441 |
|
4442 | exports.name = 'algorithm12';
|
4443 | exports.factory = factory;
|
4444 |
|
4445 | }),
|
4446 |
|
4447 | (function(module, exports, __webpack_require__) {
|
4448 |
|
4449 | "use strict";
|
4450 |
|
4451 |
|
4452 | function factory(type, config, load, typed) {
|
4453 | var equalScalar = load(__webpack_require__(11));
|
4454 | var SparseMatrix = type.SparseMatrix;
|
4455 | |
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 |
|
4464 |
|
4465 |
|
4466 |
|
4467 |
|
4468 |
|
4469 |
|
4470 |
|
4471 |
|
4472 |
|
4473 |
|
4474 |
|
4475 | var algorithm11 = function algorithm11(s, b, callback, inverse) {
|
4476 |
|
4477 | var avalues = s._values;
|
4478 | var aindex = s._index;
|
4479 | var aptr = s._ptr;
|
4480 | var asize = s._size;
|
4481 | var adt = s._datatype;
|
4482 |
|
4483 | if (!avalues) {
|
4484 | throw new Error('Cannot perform operation on Pattern Sparse Matrix and Scalar value');
|
4485 | }
|
4486 |
|
4487 |
|
4488 | var rows = asize[0];
|
4489 | var columns = asize[1];
|
4490 |
|
4491 | var dt;
|
4492 |
|
4493 | var eq = equalScalar;
|
4494 |
|
4495 | var zero = 0;
|
4496 |
|
4497 | var cf = callback;
|
4498 |
|
4499 | if (typeof adt === 'string') {
|
4500 |
|
4501 | dt = adt;
|
4502 |
|
4503 | eq = typed.find(equalScalar, [dt, dt]);
|
4504 |
|
4505 | zero = typed.convert(0, dt);
|
4506 |
|
4507 | b = typed.convert(b, dt);
|
4508 |
|
4509 | cf = typed.find(callback, [dt, dt]);
|
4510 | }
|
4511 |
|
4512 |
|
4513 | var cvalues = [];
|
4514 | var cindex = [];
|
4515 | var cptr = [];
|
4516 |
|
4517 | var c = new SparseMatrix({
|
4518 | values: cvalues,
|
4519 | index: cindex,
|
4520 | ptr: cptr,
|
4521 | size: [rows, columns],
|
4522 | datatype: dt
|
4523 | });
|
4524 |
|
4525 | for (var j = 0; j < columns; j++) {
|
4526 |
|
4527 | cptr[j] = cindex.length;
|
4528 |
|
4529 | for (var k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
|
4530 |
|
4531 | var i = aindex[k];
|
4532 |
|
4533 | var v = inverse ? cf(b, avalues[k]) : cf(avalues[k], b);
|
4534 |
|
4535 | if (!eq(v, zero)) {
|
4536 |
|
4537 | cindex.push(i);
|
4538 | cvalues.push(v);
|
4539 | }
|
4540 | }
|
4541 | }
|
4542 |
|
4543 |
|
4544 | cptr[columns] = cindex.length;
|
4545 |
|
4546 | return c;
|
4547 | };
|
4548 |
|
4549 | return algorithm11;
|
4550 | }
|
4551 |
|
4552 | exports.name = 'algorithm11';
|
4553 | exports.factory = factory;
|
4554 |
|
4555 | }),
|
4556 |
|
4557 | (function(module, exports, __webpack_require__) {
|
4558 |
|
4559 | "use strict";
|
4560 |
|
4561 |
|
4562 | function factory(type, config, load, typed) {
|
4563 | |
4564 |
|
4565 |
|
4566 |
|
4567 |
|
4568 |
|
4569 |
|
4570 |
|
4571 |
|
4572 |
|
4573 |
|
4574 |
|
4575 |
|
4576 | var multiplyScalar = typed('multiplyScalar', {
|
4577 | 'number, number': function numberNumber(x, y) {
|
4578 | return x * y;
|
4579 | },
|
4580 | 'Complex, Complex': function ComplexComplex(x, y) {
|
4581 | return x.mul(y);
|
4582 | },
|
4583 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
4584 | return x.times(y);
|
4585 | },
|
4586 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
4587 | return x.mul(y);
|
4588 | },
|
4589 | 'number | Fraction | BigNumber | Complex, Unit': function numberFractionBigNumberComplexUnit(x, y) {
|
4590 | var res = y.clone();
|
4591 | res.value = res.value === null ? res._normalize(x) : multiplyScalar(res.value, x);
|
4592 | return res;
|
4593 | },
|
4594 | 'Unit, number | Fraction | BigNumber | Complex': function UnitNumberFractionBigNumberComplex(x, y) {
|
4595 | var res = x.clone();
|
4596 | res.value = res.value === null ? res._normalize(y) : multiplyScalar(res.value, y);
|
4597 | return res;
|
4598 | },
|
4599 | 'Unit, Unit': function UnitUnit(x, y) {
|
4600 | return x.multiply(y);
|
4601 | }
|
4602 | });
|
4603 | return multiplyScalar;
|
4604 | }
|
4605 |
|
4606 | exports.factory = factory;
|
4607 |
|
4608 | }),
|
4609 |
|
4610 | (function(module, exports, __webpack_require__) {
|
4611 |
|
4612 | "use strict";
|
4613 |
|
4614 |
|
4615 | var IndexError = __webpack_require__(48);
|
4616 |
|
4617 |
|
4618 |
|
4619 |
|
4620 |
|
4621 |
|
4622 |
|
4623 | exports.transform = function (err) {
|
4624 | if (err && err.isIndexError) {
|
4625 | return new IndexError(err.index + 1, err.min + 1, err.max !== undefined ? err.max + 1 : undefined);
|
4626 | }
|
4627 |
|
4628 | return err;
|
4629 | };
|
4630 |
|
4631 | }),
|
4632 |
|
4633 | (function(module, exports, __webpack_require__) {
|
4634 |
|
4635 | "use strict";
|
4636 |
|
4637 |
|
4638 | var clone = __webpack_require__(5).clone;
|
4639 |
|
4640 | var validateIndex = __webpack_require__(2).validateIndex;
|
4641 |
|
4642 | var getSafeProperty = __webpack_require__(13).getSafeProperty;
|
4643 |
|
4644 | var setSafeProperty = __webpack_require__(13).setSafeProperty;
|
4645 |
|
4646 | var DimensionError = __webpack_require__(8);
|
4647 |
|
4648 | function factory(type, config, load, typed) {
|
4649 | var matrix = load(__webpack_require__(0));
|
4650 | |
4651 |
|
4652 |
|
4653 |
|
4654 |
|
4655 |
|
4656 |
|
4657 |
|
4658 |
|
4659 |
|
4660 |
|
4661 |
|
4662 |
|
4663 |
|
4664 |
|
4665 |
|
4666 |
|
4667 |
|
4668 |
|
4669 |
|
4670 |
|
4671 |
|
4672 |
|
4673 |
|
4674 |
|
4675 |
|
4676 |
|
4677 |
|
4678 |
|
4679 |
|
4680 |
|
4681 |
|
4682 |
|
4683 |
|
4684 |
|
4685 | var subset = typed('subset', {
|
4686 |
|
4687 | 'Array, Index': function ArrayIndex(value, index) {
|
4688 | var m = matrix(value);
|
4689 | var subset = m.subset(index);
|
4690 |
|
4691 | return index.isScalar() ? subset : subset.valueOf();
|
4692 | },
|
4693 | 'Matrix, Index': function MatrixIndex(value, index) {
|
4694 | return value.subset(index);
|
4695 | },
|
4696 | 'Object, Index': _getObjectProperty,
|
4697 | 'string, Index': _getSubstring,
|
4698 |
|
4699 | 'Array, Index, any': function ArrayIndexAny(value, index, replacement) {
|
4700 | return matrix(clone(value)).subset(index, replacement, undefined).valueOf();
|
4701 | },
|
4702 | 'Array, Index, any, any': function ArrayIndexAnyAny(value, index, replacement, defaultValue) {
|
4703 | return matrix(clone(value)).subset(index, replacement, defaultValue).valueOf();
|
4704 | },
|
4705 | 'Matrix, Index, any': function MatrixIndexAny(value, index, replacement) {
|
4706 | return value.clone().subset(index, replacement);
|
4707 | },
|
4708 | 'Matrix, Index, any, any': function MatrixIndexAnyAny(value, index, replacement, defaultValue) {
|
4709 | return value.clone().subset(index, replacement, defaultValue);
|
4710 | },
|
4711 | 'string, Index, string': _setSubstring,
|
4712 | 'string, Index, string, string': _setSubstring,
|
4713 | 'Object, Index, any': _setObjectProperty
|
4714 | });
|
4715 | subset.toTex = undefined;
|
4716 |
|
4717 | return subset;
|
4718 | |
4719 |
|
4720 |
|
4721 |
|
4722 |
|
4723 |
|
4724 |
|
4725 |
|
4726 | function _getSubstring(str, index) {
|
4727 | if (!type.isIndex(index)) {
|
4728 |
|
4729 | throw new TypeError('Index expected');
|
4730 | }
|
4731 |
|
4732 | if (index.size().length !== 1) {
|
4733 | throw new DimensionError(index.size().length, 1);
|
4734 | }
|
4735 |
|
4736 |
|
4737 | var strLen = str.length;
|
4738 | validateIndex(index.min()[0], strLen);
|
4739 | validateIndex(index.max()[0], strLen);
|
4740 | var range = index.dimension(0);
|
4741 | var substr = '';
|
4742 | range.forEach(function (v) {
|
4743 | substr += str.charAt(v);
|
4744 | });
|
4745 | return substr;
|
4746 | }
|
4747 | |
4748 |
|
4749 |
|
4750 |
|
4751 |
|
4752 |
|
4753 |
|
4754 |
|
4755 |
|
4756 |
|
4757 |
|
4758 |
|
4759 | function _setSubstring(str, index, replacement, defaultValue) {
|
4760 | if (!index || index.isIndex !== true) {
|
4761 |
|
4762 | throw new TypeError('Index expected');
|
4763 | }
|
4764 |
|
4765 | if (index.size().length !== 1) {
|
4766 | throw new DimensionError(index.size().length, 1);
|
4767 | }
|
4768 |
|
4769 | if (defaultValue !== undefined) {
|
4770 | if (typeof defaultValue !== 'string' || defaultValue.length !== 1) {
|
4771 | throw new TypeError('Single character expected as defaultValue');
|
4772 | }
|
4773 | } else {
|
4774 | defaultValue = ' ';
|
4775 | }
|
4776 |
|
4777 | var range = index.dimension(0);
|
4778 | var len = range.size()[0];
|
4779 |
|
4780 | if (len !== replacement.length) {
|
4781 | throw new DimensionError(range.size()[0], replacement.length);
|
4782 | }
|
4783 |
|
4784 |
|
4785 | var strLen = str.length;
|
4786 | validateIndex(index.min()[0]);
|
4787 | validateIndex(index.max()[0]);
|
4788 |
|
4789 | var chars = [];
|
4790 |
|
4791 | for (var i = 0; i < strLen; i++) {
|
4792 | chars[i] = str.charAt(i);
|
4793 | }
|
4794 |
|
4795 | range.forEach(function (v, i) {
|
4796 | chars[v] = replacement.charAt(i[0]);
|
4797 | });
|
4798 |
|
4799 | if (chars.length > strLen) {
|
4800 | for (var _i = strLen - 1, _len = chars.length; _i < _len; _i++) {
|
4801 | if (!chars[_i]) {
|
4802 | chars[_i] = defaultValue;
|
4803 | }
|
4804 | }
|
4805 | }
|
4806 |
|
4807 | return chars.join('');
|
4808 | }
|
4809 | }
|
4810 |
|
4811 |
|
4812 |
|
4813 |
|
4814 |
|
4815 |
|
4816 |
|
4817 |
|
4818 |
|
4819 | function _getObjectProperty(object, index) {
|
4820 | if (index.size().length !== 1) {
|
4821 | throw new DimensionError(index.size(), 1);
|
4822 | }
|
4823 |
|
4824 | var key = index.dimension(0);
|
4825 |
|
4826 | if (typeof key !== 'string') {
|
4827 | throw new TypeError('String expected as index to retrieve an object property');
|
4828 | }
|
4829 |
|
4830 | return getSafeProperty(object, key);
|
4831 | }
|
4832 |
|
4833 |
|
4834 |
|
4835 |
|
4836 |
|
4837 |
|
4838 |
|
4839 |
|
4840 |
|
4841 |
|
4842 | function _setObjectProperty(object, index, replacement) {
|
4843 | if (index.size().length !== 1) {
|
4844 | throw new DimensionError(index.size(), 1);
|
4845 | }
|
4846 |
|
4847 | var key = index.dimension(0);
|
4848 |
|
4849 | if (typeof key !== 'string') {
|
4850 | throw new TypeError('String expected as index to retrieve an object property');
|
4851 | }
|
4852 |
|
4853 |
|
4854 | var updated = clone(object);
|
4855 | setSafeProperty(updated, key, replacement);
|
4856 | return updated;
|
4857 | }
|
4858 |
|
4859 | exports.name = 'subset';
|
4860 | exports.factory = factory;
|
4861 |
|
4862 | }),
|
4863 |
|
4864 | (function(module, exports, __webpack_require__) {
|
4865 |
|
4866 | "use strict";
|
4867 |
|
4868 |
|
4869 | var clone = __webpack_require__(5).clone;
|
4870 |
|
4871 | var isInteger = __webpack_require__(3).isInteger;
|
4872 |
|
4873 | function factory(type) {
|
4874 | |
4875 |
|
4876 |
|
4877 |
|
4878 |
|
4879 |
|
4880 |
|
4881 |
|
4882 |
|
4883 |
|
4884 |
|
4885 |
|
4886 |
|
4887 |
|
4888 |
|
4889 |
|
4890 |
|
4891 |
|
4892 |
|
4893 |
|
4894 | function Index(ranges) {
|
4895 | if (!(this instanceof Index)) {
|
4896 | throw new SyntaxError('Constructor must be called with the new operator');
|
4897 | }
|
4898 |
|
4899 | this._dimensions = [];
|
4900 | this._isScalar = true;
|
4901 |
|
4902 | for (var i = 0, ii = arguments.length; i < ii; i++) {
|
4903 | var arg = arguments[i];
|
4904 |
|
4905 | if (type.isRange(arg)) {
|
4906 | this._dimensions.push(arg);
|
4907 |
|
4908 | this._isScalar = false;
|
4909 | } else if (Array.isArray(arg) || type.isMatrix(arg)) {
|
4910 |
|
4911 | var m = _createImmutableMatrix(arg.valueOf());
|
4912 |
|
4913 | this._dimensions.push(m);
|
4914 |
|
4915 |
|
4916 | var size = m.size();
|
4917 |
|
4918 | if (size.length !== 1 || size[0] !== 1) {
|
4919 | this._isScalar = false;
|
4920 | }
|
4921 | } else if (typeof arg === 'number') {
|
4922 | this._dimensions.push(_createImmutableMatrix([arg]));
|
4923 | } else if (typeof arg === 'string') {
|
4924 |
|
4925 | this._dimensions.push(arg);
|
4926 | } else {
|
4927 | throw new TypeError('Dimension must be an Array, Matrix, number, string, or Range');
|
4928 | }
|
4929 |
|
4930 | }
|
4931 | }
|
4932 | |
4933 |
|
4934 |
|
4935 |
|
4936 |
|
4937 | Index.prototype.type = 'Index';
|
4938 | Index.prototype.isIndex = true;
|
4939 |
|
4940 | function _createImmutableMatrix(arg) {
|
4941 |
|
4942 | for (var i = 0, l = arg.length; i < l; i++) {
|
4943 | if (typeof arg[i] !== 'number' || !isInteger(arg[i])) {
|
4944 | throw new TypeError('Index parameters must be positive integer numbers');
|
4945 | }
|
4946 | }
|
4947 |
|
4948 |
|
4949 | return new type.ImmutableDenseMatrix(arg);
|
4950 | }
|
4951 | |
4952 |
|
4953 |
|
4954 |
|
4955 |
|
4956 |
|
4957 |
|
4958 | Index.prototype.clone = function () {
|
4959 | var index = new Index();
|
4960 | index._dimensions = clone(this._dimensions);
|
4961 | index._isScalar = this._isScalar;
|
4962 | return index;
|
4963 | };
|
4964 | |
4965 |
|
4966 |
|
4967 |
|
4968 |
|
4969 |
|
4970 |
|
4971 |
|
4972 |
|
4973 | Index.create = function (ranges) {
|
4974 | var index = new Index();
|
4975 | Index.apply(index, ranges);
|
4976 | return index;
|
4977 | };
|
4978 | |
4979 |
|
4980 |
|
4981 |
|
4982 |
|
4983 |
|
4984 |
|
4985 | Index.prototype.size = function () {
|
4986 | var size = [];
|
4987 |
|
4988 | for (var i = 0, ii = this._dimensions.length; i < ii; i++) {
|
4989 | var d = this._dimensions[i];
|
4990 | size[i] = typeof d === 'string' ? 1 : d.size()[0];
|
4991 | }
|
4992 |
|
4993 | return size;
|
4994 | };
|
4995 | |
4996 |
|
4997 |
|
4998 |
|
4999 |
|
5000 |
|
5001 |
|
5002 | Index.prototype.max = function () {
|
5003 | var values = [];
|
5004 |
|
5005 | for (var i = 0, ii = this._dimensions.length; i < ii; i++) {
|
5006 | var range = this._dimensions[i];
|
5007 | values[i] = typeof range === 'string' ? range : range.max();
|
5008 | }
|
5009 |
|
5010 | return values;
|
5011 | };
|
5012 | |
5013 |
|
5014 |
|
5015 |
|
5016 |
|
5017 |
|
5018 |
|
5019 | Index.prototype.min = function () {
|
5020 | var values = [];
|
5021 |
|
5022 | for (var i = 0, ii = this._dimensions.length; i < ii; i++) {
|
5023 | var range = this._dimensions[i];
|
5024 | values[i] = typeof range === 'string' ? range : range.min();
|
5025 | }
|
5026 |
|
5027 | return values;
|
5028 | };
|
5029 | |
5030 |
|
5031 |
|
5032 |
|
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 | Index.prototype.forEach = function (callback) {
|
5039 | for (var i = 0, ii = this._dimensions.length; i < ii; i++) {
|
5040 | callback(this._dimensions[i], i, this);
|
5041 | }
|
5042 | };
|
5043 | |
5044 |
|
5045 |
|
5046 |
|
5047 |
|
5048 |
|
5049 |
|
5050 |
|
5051 | Index.prototype.dimension = function (dim) {
|
5052 | return this._dimensions[dim] || null;
|
5053 | };
|
5054 | |
5055 |
|
5056 |
|
5057 |
|
5058 |
|
5059 |
|
5060 | Index.prototype.isObjectProperty = function () {
|
5061 | return this._dimensions.length === 1 && typeof this._dimensions[0] === 'string';
|
5062 | };
|
5063 | |
5064 |
|
5065 |
|
5066 |
|
5067 |
|
5068 |
|
5069 |
|
5070 | Index.prototype.getObjectProperty = function () {
|
5071 | return this.isObjectProperty() ? this._dimensions[0] : null;
|
5072 | };
|
5073 | |
5074 |
|
5075 |
|
5076 |
|
5077 |
|
5078 |
|
5079 |
|
5080 |
|
5081 |
|
5082 |
|
5083 | Index.prototype.isScalar = function () {
|
5084 | return this._isScalar;
|
5085 | };
|
5086 | |
5087 |
|
5088 |
|
5089 |
|
5090 |
|
5091 |
|
5092 |
|
5093 |
|
5094 | Index.prototype.toArray = function () {
|
5095 | var array = [];
|
5096 |
|
5097 | for (var i = 0, ii = this._dimensions.length; i < ii; i++) {
|
5098 | var dimension = this._dimensions[i];
|
5099 | array.push(typeof dimension === 'string' ? dimension : dimension.toArray());
|
5100 | }
|
5101 |
|
5102 | return array;
|
5103 | };
|
5104 | |
5105 |
|
5106 |
|
5107 |
|
5108 |
|
5109 |
|
5110 |
|
5111 |
|
5112 | Index.prototype.valueOf = Index.prototype.toArray;
|
5113 | |
5114 |
|
5115 |
|
5116 |
|
5117 |
|
5118 |
|
5119 | Index.prototype.toString = function () {
|
5120 | var strings = [];
|
5121 |
|
5122 | for (var i = 0, ii = this._dimensions.length; i < ii; i++) {
|
5123 | var dimension = this._dimensions[i];
|
5124 |
|
5125 | if (typeof dimension === 'string') {
|
5126 | strings.push(JSON.stringify(dimension));
|
5127 | } else {
|
5128 | strings.push(dimension.toString());
|
5129 | }
|
5130 | }
|
5131 |
|
5132 | return '[' + strings.join(', ') + ']';
|
5133 | };
|
5134 | |
5135 |
|
5136 |
|
5137 |
|
5138 |
|
5139 |
|
5140 |
|
5141 |
|
5142 | Index.prototype.toJSON = function () {
|
5143 | return {
|
5144 | mathjs: 'Index',
|
5145 | dimensions: this._dimensions
|
5146 | };
|
5147 | };
|
5148 | |
5149 |
|
5150 |
|
5151 |
|
5152 |
|
5153 |
|
5154 |
|
5155 |
|
5156 |
|
5157 | Index.fromJSON = function (json) {
|
5158 | return Index.create(json.dimensions);
|
5159 | };
|
5160 |
|
5161 | return Index;
|
5162 | }
|
5163 |
|
5164 | exports.name = 'Index';
|
5165 | exports.path = 'type';
|
5166 | exports.factory = factory;
|
5167 |
|
5168 | }),
|
5169 |
|
5170 | (function(module, exports, __webpack_require__) {
|
5171 |
|
5172 | "use strict";
|
5173 |
|
5174 |
|
5175 | var deepMap = __webpack_require__(1);
|
5176 |
|
5177 | function factory(type, config, load, typed) {
|
5178 | |
5179 |
|
5180 |
|
5181 |
|
5182 |
|
5183 |
|
5184 |
|
5185 |
|
5186 |
|
5187 |
|
5188 |
|
5189 |
|
5190 |
|
5191 |
|
5192 |
|
5193 |
|
5194 |
|
5195 |
|
5196 |
|
5197 |
|
5198 |
|
5199 |
|
5200 |
|
5201 |
|
5202 | var abs = typed('abs', {
|
5203 | 'number': Math.abs,
|
5204 | 'Complex': function Complex(x) {
|
5205 | return x.abs();
|
5206 | },
|
5207 | 'BigNumber': function BigNumber(x) {
|
5208 | return x.abs();
|
5209 | },
|
5210 | 'Fraction': function Fraction(x) {
|
5211 | return x.abs();
|
5212 | },
|
5213 | 'Array | Matrix': function ArrayMatrix(x) {
|
5214 |
|
5215 | return deepMap(x, abs, true);
|
5216 | },
|
5217 | 'Unit': function Unit(x) {
|
5218 | return x.abs();
|
5219 | }
|
5220 | });
|
5221 | abs.toTex = {
|
5222 | 1: "\\left|${args[0]}\\right|"
|
5223 | };
|
5224 | return abs;
|
5225 | }
|
5226 |
|
5227 | exports.name = 'abs';
|
5228 | exports.factory = factory;
|
5229 |
|
5230 | }),
|
5231 |
|
5232 | (function(module, exports, __webpack_require__) {
|
5233 |
|
5234 | "use strict";
|
5235 |
|
5236 |
|
5237 | function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); }
|
5238 |
|
5239 | function factory(type, config, load, typed) {
|
5240 | |
5241 |
|
5242 |
|
5243 |
|
5244 |
|
5245 |
|
5246 |
|
5247 |
|
5248 |
|
5249 |
|
5250 |
|
5251 |
|
5252 |
|
5253 |
|
5254 |
|
5255 |
|
5256 |
|
5257 |
|
5258 |
|
5259 |
|
5260 |
|
5261 |
|
5262 |
|
5263 |
|
5264 |
|
5265 |
|
5266 |
|
5267 |
|
5268 |
|
5269 |
|
5270 |
|
5271 |
|
5272 |
|
5273 |
|
5274 |
|
5275 |
|
5276 |
|
5277 |
|
5278 |
|
5279 |
|
5280 |
|
5281 |
|
5282 |
|
5283 |
|
5284 |
|
5285 |
|
5286 |
|
5287 |
|
5288 |
|
5289 |
|
5290 |
|
5291 |
|
5292 |
|
5293 |
|
5294 |
|
5295 |
|
5296 |
|
5297 |
|
5298 | var _typeof = typed('_typeof', {
|
5299 | 'any': function any(x) {
|
5300 | var t = _typeof2(x);
|
5301 |
|
5302 | if (t === 'object') {
|
5303 |
|
5304 | if (x === null) return 'null';
|
5305 | if (Array.isArray(x)) return 'Array';
|
5306 | if (x instanceof Date) return 'Date';
|
5307 | if (x instanceof RegExp) return 'RegExp';
|
5308 |
|
5309 | if (type.isBigNumber(x)) return 'BigNumber';
|
5310 | if (type.isComplex(x)) return 'Complex';
|
5311 | if (type.isFraction(x)) return 'Fraction';
|
5312 | if (type.isMatrix(x)) return 'Matrix';
|
5313 | if (type.isUnit(x)) return 'Unit';
|
5314 | if (type.isIndex(x)) return 'Index';
|
5315 | if (type.isRange(x)) return 'Range';
|
5316 | if (type.isResultSet(x)) return 'ResultSet';
|
5317 | if (type.isNode(x)) return x.type;
|
5318 | if (type.isChain(x)) return 'Chain';
|
5319 | if (type.isHelp(x)) return 'Help';
|
5320 | return 'Object';
|
5321 | }
|
5322 |
|
5323 | if (t === 'function') return 'Function';
|
5324 | return t;
|
5325 | }
|
5326 | });
|
5327 |
|
5328 | _typeof.toTex = undefined;
|
5329 |
|
5330 | return _typeof;
|
5331 | }
|
5332 |
|
5333 | exports.name = 'typeof';
|
5334 | exports.factory = factory;
|
5335 |
|
5336 | }),
|
5337 |
|
5338 | (function(module, exports, __webpack_require__) {
|
5339 |
|
5340 | "use strict";
|
5341 |
|
5342 |
|
5343 | var DimensionError = __webpack_require__(8);
|
5344 |
|
5345 | function factory(type, config, load, typed) {
|
5346 | var equalScalar = load(__webpack_require__(11));
|
5347 | var SparseMatrix = type.SparseMatrix;
|
5348 | |
5349 |
|
5350 |
|
5351 |
|
5352 |
|
5353 |
|
5354 |
|
5355 |
|
5356 |
|
5357 |
|
5358 |
|
5359 |
|
5360 |
|
5361 |
|
5362 |
|
5363 |
|
5364 |
|
5365 |
|
5366 |
|
5367 |
|
5368 | var algorithm02 = function algorithm02(denseMatrix, sparseMatrix, callback, inverse) {
|
5369 |
|
5370 | var adata = denseMatrix._data;
|
5371 | var asize = denseMatrix._size;
|
5372 | var adt = denseMatrix._datatype;
|
5373 |
|
5374 | var bvalues = sparseMatrix._values;
|
5375 | var bindex = sparseMatrix._index;
|
5376 | var bptr = sparseMatrix._ptr;
|
5377 | var bsize = sparseMatrix._size;
|
5378 | var bdt = sparseMatrix._datatype;
|
5379 |
|
5380 | if (asize.length !== bsize.length) {
|
5381 | throw new DimensionError(asize.length, bsize.length);
|
5382 | }
|
5383 |
|
5384 |
|
5385 | if (asize[0] !== bsize[0] || asize[1] !== bsize[1]) {
|
5386 | throw new RangeError('Dimension mismatch. Matrix A (' + asize + ') must match Matrix B (' + bsize + ')');
|
5387 | }
|
5388 |
|
5389 |
|
5390 | if (!bvalues) {
|
5391 | throw new Error('Cannot perform operation on Dense Matrix and Pattern Sparse Matrix');
|
5392 | }
|
5393 |
|
5394 |
|
5395 | var rows = asize[0];
|
5396 | var columns = asize[1];
|
5397 |
|
5398 | var dt;
|
5399 |
|
5400 | var eq = equalScalar;
|
5401 |
|
5402 | var zero = 0;
|
5403 |
|
5404 | var cf = callback;
|
5405 |
|
5406 | if (typeof adt === 'string' && adt === bdt) {
|
5407 |
|
5408 | dt = adt;
|
5409 |
|
5410 | eq = typed.find(equalScalar, [dt, dt]);
|
5411 |
|
5412 | zero = typed.convert(0, dt);
|
5413 |
|
5414 | cf = typed.find(callback, [dt, dt]);
|
5415 | }
|
5416 |
|
5417 |
|
5418 | var cvalues = [];
|
5419 | var cindex = [];
|
5420 | var cptr = [];
|
5421 |
|
5422 | for (var j = 0; j < columns; j++) {
|
5423 |
|
5424 | cptr[j] = cindex.length;
|
5425 |
|
5426 | for (var k0 = bptr[j], k1 = bptr[j + 1], k = k0; k < k1; k++) {
|
5427 |
|
5428 | var i = bindex[k];
|
5429 |
|
5430 | var cij = inverse ? cf(bvalues[k], adata[i][j]) : cf(adata[i][j], bvalues[k]);
|
5431 |
|
5432 | if (!eq(cij, zero)) {
|
5433 |
|
5434 | cindex.push(i);
|
5435 | cvalues.push(cij);
|
5436 | }
|
5437 | }
|
5438 | }
|
5439 |
|
5440 |
|
5441 | cptr[columns] = cindex.length;
|
5442 |
|
5443 | return new SparseMatrix({
|
5444 | values: cvalues,
|
5445 | index: cindex,
|
5446 | ptr: cptr,
|
5447 | size: [rows, columns],
|
5448 | datatype: dt
|
5449 | });
|
5450 | };
|
5451 |
|
5452 | return algorithm02;
|
5453 | }
|
5454 |
|
5455 | exports.name = 'algorithm02';
|
5456 | exports.factory = factory;
|
5457 |
|
5458 | }),
|
5459 |
|
5460 | (function(module, exports, __webpack_require__) {
|
5461 |
|
5462 | "use strict";
|
5463 |
|
5464 |
|
5465 | var array = __webpack_require__(2);
|
5466 |
|
5467 | function factory(type, config, load, typed) {
|
5468 | var matrix = load(__webpack_require__(0));
|
5469 | |
5470 |
|
5471 |
|
5472 |
|
5473 |
|
5474 |
|
5475 |
|
5476 |
|
5477 |
|
5478 |
|
5479 |
|
5480 |
|
5481 |
|
5482 |
|
5483 |
|
5484 |
|
5485 |
|
5486 |
|
5487 |
|
5488 |
|
5489 |
|
5490 |
|
5491 |
|
5492 |
|
5493 | var size = typed('size', {
|
5494 | 'Matrix': function Matrix(x) {
|
5495 |
|
5496 | return matrix(x.size());
|
5497 | },
|
5498 | 'Array': array.size,
|
5499 | 'string': function string(x) {
|
5500 | return config.matrix === 'Array' ? [x.length] : matrix([x.length]);
|
5501 | },
|
5502 | 'number | Complex | BigNumber | Unit | boolean | null': function numberComplexBigNumberUnitBooleanNull(x) {
|
5503 |
|
5504 | return config.matrix === 'Array' ? [] : matrix([]);
|
5505 | }
|
5506 | });
|
5507 | size.toTex = undefined;
|
5508 |
|
5509 | return size;
|
5510 | }
|
5511 |
|
5512 | exports.name = 'size';
|
5513 | exports.factory = factory;
|
5514 |
|
5515 | }),
|
5516 |
|
5517 | (function(module, exports, __webpack_require__) {
|
5518 |
|
5519 | "use strict";
|
5520 |
|
5521 |
|
5522 | var DimensionError = __webpack_require__(8);
|
5523 |
|
5524 | function factory(type, config, load, typed) {
|
5525 | var DenseMatrix = type.DenseMatrix;
|
5526 | |
5527 |
|
5528 |
|
5529 |
|
5530 |
|
5531 |
|
5532 |
|
5533 |
|
5534 |
|
5535 |
|
5536 |
|
5537 |
|
5538 |
|
5539 |
|
5540 |
|
5541 | var algorithm07 = function algorithm07(a, b, callback) {
|
5542 |
|
5543 | var asize = a._size;
|
5544 | var adt = a._datatype;
|
5545 |
|
5546 | var bsize = b._size;
|
5547 | var bdt = b._datatype;
|
5548 |
|
5549 | if (asize.length !== bsize.length) {
|
5550 | throw new DimensionError(asize.length, bsize.length);
|
5551 | }
|
5552 |
|
5553 |
|
5554 | if (asize[0] !== bsize[0] || asize[1] !== bsize[1]) {
|
5555 | throw new RangeError('Dimension mismatch. Matrix A (' + asize + ') must match Matrix B (' + bsize + ')');
|
5556 | }
|
5557 |
|
5558 |
|
5559 | var rows = asize[0];
|
5560 | var columns = asize[1];
|
5561 |
|
5562 | var dt;
|
5563 |
|
5564 | var zero = 0;
|
5565 |
|
5566 | var cf = callback;
|
5567 |
|
5568 | if (typeof adt === 'string' && adt === bdt) {
|
5569 |
|
5570 | dt = adt;
|
5571 |
|
5572 | zero = typed.convert(0, dt);
|
5573 |
|
5574 | cf = typed.find(callback, [dt, dt]);
|
5575 | }
|
5576 |
|
5577 |
|
5578 | var i, j;
|
5579 |
|
5580 | var cdata = [];
|
5581 |
|
5582 | for (i = 0; i < rows; i++) {
|
5583 | cdata[i] = [];
|
5584 | }
|
5585 |
|
5586 |
|
5587 | var c = new DenseMatrix({
|
5588 | data: cdata,
|
5589 | size: [rows, columns],
|
5590 | datatype: dt
|
5591 | });
|
5592 |
|
5593 | var xa = [];
|
5594 | var xb = [];
|
5595 |
|
5596 | var wa = [];
|
5597 | var wb = [];
|
5598 |
|
5599 | for (j = 0; j < columns; j++) {
|
5600 |
|
5601 | var mark = j + 1;
|
5602 |
|
5603 | _scatter(a, j, wa, xa, mark);
|
5604 |
|
5605 |
|
5606 | _scatter(b, j, wb, xb, mark);
|
5607 |
|
5608 |
|
5609 | for (i = 0; i < rows; i++) {
|
5610 |
|
5611 | var va = wa[i] === mark ? xa[i] : zero;
|
5612 | var vb = wb[i] === mark ? xb[i] : zero;
|
5613 |
|
5614 | cdata[i][j] = cf(va, vb);
|
5615 | }
|
5616 | }
|
5617 |
|
5618 |
|
5619 | return c;
|
5620 | };
|
5621 |
|
5622 | function _scatter(m, j, w, x, mark) {
|
5623 |
|
5624 | var values = m._values;
|
5625 | var index = m._index;
|
5626 | var ptr = m._ptr;
|
5627 |
|
5628 | for (var k = ptr[j], k1 = ptr[j + 1]; k < k1; k++) {
|
5629 |
|
5630 | var i = index[k];
|
5631 |
|
5632 | w[i] = mark;
|
5633 | x[i] = values[k];
|
5634 | }
|
5635 | }
|
5636 |
|
5637 | return algorithm07;
|
5638 | }
|
5639 |
|
5640 | exports.name = 'algorithm07';
|
5641 | exports.factory = factory;
|
5642 |
|
5643 | }),
|
5644 |
|
5645 | (function(module, exports, __webpack_require__) {
|
5646 |
|
5647 | "use strict";
|
5648 |
|
5649 |
|
5650 | var naturalSort = __webpack_require__(288);
|
5651 |
|
5652 | function factory(type, config, load, typed) {
|
5653 | var getTypeOf = load(__webpack_require__(26));
|
5654 | var compare = load(__webpack_require__(55));
|
5655 | var compareBooleans = compare.signatures['boolean,boolean'];
|
5656 | |
5657 |
|
5658 |
|
5659 |
|
5660 |
|
5661 |
|
5662 |
|
5663 |
|
5664 |
|
5665 |
|
5666 |
|
5667 |
|
5668 |
|
5669 |
|
5670 |
|
5671 |
|
5672 |
|
5673 |
|
5674 |
|
5675 |
|
5676 |
|
5677 |
|
5678 |
|
5679 |
|
5680 |
|
5681 |
|
5682 |
|
5683 |
|
5684 |
|
5685 |
|
5686 |
|
5687 |
|
5688 |
|
5689 |
|
5690 |
|
5691 |
|
5692 |
|
5693 |
|
5694 |
|
5695 |
|
5696 |
|
5697 |
|
5698 |
|
5699 |
|
5700 |
|
5701 |
|
5702 |
|
5703 |
|
5704 |
|
5705 |
|
5706 |
|
5707 |
|
5708 |
|
5709 |
|
5710 |
|
5711 |
|
5712 |
|
5713 |
|
5714 |
|
5715 |
|
5716 |
|
5717 |
|
5718 |
|
5719 |
|
5720 |
|
5721 |
|
5722 |
|
5723 |
|
5724 |
|
5725 | var compareNatural = typed('compareNatural', {
|
5726 | 'any, any': function anyAny(x, y) {
|
5727 | var typeX = getTypeOf(x);
|
5728 | var typeY = getTypeOf(y);
|
5729 | var c;
|
5730 |
|
5731 | if ((typeX === 'number' || typeX === 'BigNumber' || typeX === 'Fraction') && (typeY === 'number' || typeY === 'BigNumber' || typeY === 'Fraction')) {
|
5732 | c = compare(x, y);
|
5733 |
|
5734 | if (c.toString() !== '0') {
|
5735 |
|
5736 | return c > 0 ? 1 : -1;
|
5737 | } else {
|
5738 | return naturalSort(typeX, typeY);
|
5739 | }
|
5740 | }
|
5741 |
|
5742 |
|
5743 | if (typeX === 'Array' || typeX === 'Matrix' || typeY === 'Array' || typeY === 'Matrix') {
|
5744 | c = compareMatricesAndArrays(x, y);
|
5745 |
|
5746 | if (c !== 0) {
|
5747 | return c;
|
5748 | } else {
|
5749 | return naturalSort(typeX, typeY);
|
5750 | }
|
5751 | }
|
5752 |
|
5753 |
|
5754 | if (typeX !== typeY) {
|
5755 | return naturalSort(typeX, typeY);
|
5756 | }
|
5757 |
|
5758 | if (typeX === 'Complex') {
|
5759 | return compareComplexNumbers(x, y);
|
5760 | }
|
5761 |
|
5762 | if (typeX === 'Unit') {
|
5763 | if (x.equalBase(y)) {
|
5764 | return compareNatural(x.value, y.value);
|
5765 | }
|
5766 |
|
5767 |
|
5768 | return compareArrays(x.formatUnits(), y.formatUnits());
|
5769 | }
|
5770 |
|
5771 | if (typeX === 'boolean') {
|
5772 | return compareBooleans(x, y);
|
5773 | }
|
5774 |
|
5775 | if (typeX === 'string') {
|
5776 | return naturalSort(x, y);
|
5777 | }
|
5778 |
|
5779 | if (typeX === 'Object') {
|
5780 | return compareObjects(x, y);
|
5781 | }
|
5782 |
|
5783 | if (typeX === 'null') {
|
5784 | return 0;
|
5785 | }
|
5786 |
|
5787 | if (typeX === 'undefined') {
|
5788 | return 0;
|
5789 | }
|
5790 |
|
5791 |
|
5792 | throw new TypeError('Unsupported type of value "' + typeX + '"');
|
5793 | }
|
5794 | });
|
5795 | compareNatural.toTex = undefined;
|
5796 |
|
5797 | |
5798 |
|
5799 |
|
5800 |
|
5801 |
|
5802 |
|
5803 |
|
5804 |
|
5805 | function compareMatricesAndArrays(x, y) {
|
5806 | if (type.isSparseMatrix(x) && type.isSparseMatrix(y)) {
|
5807 | return compareArrays(x.toJSON().values, y.toJSON().values);
|
5808 | }
|
5809 |
|
5810 | if (type.isSparseMatrix(x)) {
|
5811 |
|
5812 | return compareMatricesAndArrays(x.toArray(), y);
|
5813 | }
|
5814 |
|
5815 | if (type.isSparseMatrix(y)) {
|
5816 |
|
5817 | return compareMatricesAndArrays(x, y.toArray());
|
5818 | }
|
5819 |
|
5820 |
|
5821 | if (type.isDenseMatrix(x)) {
|
5822 | return compareMatricesAndArrays(x.toJSON().data, y);
|
5823 | }
|
5824 |
|
5825 | if (type.isDenseMatrix(y)) {
|
5826 | return compareMatricesAndArrays(x, y.toJSON().data);
|
5827 | }
|
5828 |
|
5829 |
|
5830 | if (!Array.isArray(x)) {
|
5831 | return compareMatricesAndArrays([x], y);
|
5832 | }
|
5833 |
|
5834 | if (!Array.isArray(y)) {
|
5835 | return compareMatricesAndArrays(x, [y]);
|
5836 | }
|
5837 |
|
5838 | return compareArrays(x, y);
|
5839 | }
|
5840 | |
5841 |
|
5842 |
|
5843 |
|
5844 |
|
5845 |
|
5846 |
|
5847 |
|
5848 |
|
5849 |
|
5850 |
|
5851 |
|
5852 |
|
5853 | function compareArrays(x, y) {
|
5854 |
|
5855 | for (var i = 0, ii = Math.min(x.length, y.length); i < ii; i++) {
|
5856 | var v = compareNatural(x[i], y[i]);
|
5857 |
|
5858 | if (v !== 0) {
|
5859 | return v;
|
5860 | }
|
5861 | }
|
5862 |
|
5863 |
|
5864 | if (x.length > y.length) {
|
5865 | return 1;
|
5866 | }
|
5867 |
|
5868 | if (x.length < y.length) {
|
5869 | return -1;
|
5870 | }
|
5871 |
|
5872 |
|
5873 | return 0;
|
5874 | }
|
5875 | |
5876 |
|
5877 |
|
5878 |
|
5879 |
|
5880 |
|
5881 |
|
5882 |
|
5883 |
|
5884 |
|
5885 |
|
5886 |
|
5887 | function compareObjects(x, y) {
|
5888 | var keysX = Object.keys(x);
|
5889 | var keysY = Object.keys(y);
|
5890 |
|
5891 | keysX.sort(naturalSort);
|
5892 | keysY.sort(naturalSort);
|
5893 | var c = compareArrays(keysX, keysY);
|
5894 |
|
5895 | if (c !== 0) {
|
5896 | return c;
|
5897 | }
|
5898 |
|
5899 |
|
5900 | for (var i = 0; i < keysX.length; i++) {
|
5901 | var v = compareNatural(x[keysX[i]], y[keysY[i]]);
|
5902 |
|
5903 | if (v !== 0) {
|
5904 | return v;
|
5905 | }
|
5906 | }
|
5907 |
|
5908 | return 0;
|
5909 | }
|
5910 |
|
5911 | return compareNatural;
|
5912 | }
|
5913 |
|
5914 |
|
5915 |
|
5916 |
|
5917 |
|
5918 |
|
5919 |
|
5920 |
|
5921 |
|
5922 |
|
5923 |
|
5924 |
|
5925 | function compareComplexNumbers(x, y) {
|
5926 | if (x.re > y.re) {
|
5927 | return 1;
|
5928 | }
|
5929 |
|
5930 | if (x.re < y.re) {
|
5931 | return -1;
|
5932 | }
|
5933 |
|
5934 | if (x.im > y.im) {
|
5935 | return 1;
|
5936 | }
|
5937 |
|
5938 | if (x.im < y.im) {
|
5939 | return -1;
|
5940 | }
|
5941 |
|
5942 | return 0;
|
5943 | }
|
5944 |
|
5945 | exports.name = 'compareNatural';
|
5946 | exports.factory = factory;
|
5947 |
|
5948 | }),
|
5949 |
|
5950 | (function(module, exports, __webpack_require__) {
|
5951 |
|
5952 | "use strict";
|
5953 |
|
5954 |
|
5955 | exports.array = __webpack_require__(2);
|
5956 | exports['boolean'] = __webpack_require__(185);
|
5957 | exports['function'] = __webpack_require__(36);
|
5958 | exports.number = __webpack_require__(3);
|
5959 | exports.object = __webpack_require__(5);
|
5960 | exports.string = __webpack_require__(9);
|
5961 | exports.emitter = __webpack_require__(104);
|
5962 |
|
5963 | }),
|
5964 |
|
5965 | (function(module, exports, __webpack_require__) {
|
5966 |
|
5967 | "use strict";
|
5968 |
|
5969 |
|
5970 |
|
5971 |
|
5972 |
|
5973 |
|
5974 |
|
5975 |
|
5976 |
|
5977 |
|
5978 |
|
5979 | module.exports = function nearlyEqual(x, y, epsilon) {
|
5980 |
|
5981 | if (epsilon === null || epsilon === undefined) {
|
5982 | return x.eq(y);
|
5983 | }
|
5984 |
|
5985 |
|
5986 | if (x.eq(y)) {
|
5987 | return true;
|
5988 | }
|
5989 |
|
5990 |
|
5991 | if (x.isNaN() || y.isNaN()) {
|
5992 | return false;
|
5993 | }
|
5994 |
|
5995 |
|
5996 | if (x.isFinite() && y.isFinite()) {
|
5997 |
|
5998 | var diff = x.minus(y).abs();
|
5999 |
|
6000 | if (diff.isZero()) {
|
6001 | return true;
|
6002 | } else {
|
6003 |
|
6004 | var max = x.constructor.max(x.abs(), y.abs());
|
6005 | return diff.lte(max.times(epsilon));
|
6006 | }
|
6007 | }
|
6008 |
|
6009 |
|
6010 | return false;
|
6011 | };
|
6012 |
|
6013 | }),
|
6014 |
|
6015 | (function(module, exports, __webpack_require__) {
|
6016 |
|
6017 | "use strict";
|
6018 |
|
6019 |
|
6020 | var nearlyEqual = __webpack_require__(3).nearlyEqual;
|
6021 |
|
6022 | var bigNearlyEqual = __webpack_require__(32);
|
6023 |
|
6024 | function factory(type, config, load, typed) {
|
6025 | var matrix = load(__webpack_require__(0));
|
6026 | var algorithm03 = load(__webpack_require__(18));
|
6027 | var algorithm07 = load(__webpack_require__(29));
|
6028 | var algorithm12 = load(__webpack_require__(19));
|
6029 | var algorithm13 = load(__webpack_require__(7));
|
6030 | var algorithm14 = load(__webpack_require__(6));
|
6031 |
|
6032 | var latex = __webpack_require__(4);
|
6033 | |
6034 |
|
6035 |
|
6036 |
|
6037 |
|
6038 |
|
6039 |
|
6040 |
|
6041 |
|
6042 |
|
6043 |
|
6044 |
|
6045 |
|
6046 |
|
6047 |
|
6048 |
|
6049 |
|
6050 |
|
6051 |
|
6052 |
|
6053 |
|
6054 |
|
6055 |
|
6056 |
|
6057 |
|
6058 |
|
6059 |
|
6060 |
|
6061 |
|
6062 |
|
6063 |
|
6064 |
|
6065 |
|
6066 | var larger = typed('larger', {
|
6067 | 'boolean, boolean': function booleanBoolean(x, y) {
|
6068 | return x > y;
|
6069 | },
|
6070 | 'number, number': function numberNumber(x, y) {
|
6071 | return x > y && !nearlyEqual(x, y, config.epsilon);
|
6072 | },
|
6073 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
6074 | return x.gt(y) && !bigNearlyEqual(x, y, config.epsilon);
|
6075 | },
|
6076 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
6077 | return x.compare(y) === 1;
|
6078 | },
|
6079 | 'Complex, Complex': function ComplexComplex() {
|
6080 | throw new TypeError('No ordering relation is defined for complex numbers');
|
6081 | },
|
6082 | 'Unit, Unit': function UnitUnit(x, y) {
|
6083 | if (!x.equalBase(y)) {
|
6084 | throw new Error('Cannot compare units with different base');
|
6085 | }
|
6086 |
|
6087 | return larger(x.value, y.value);
|
6088 | },
|
6089 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
6090 | return algorithm07(x, y, larger);
|
6091 | },
|
6092 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
6093 | return algorithm03(y, x, larger, true);
|
6094 | },
|
6095 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
6096 | return algorithm03(x, y, larger, false);
|
6097 | },
|
6098 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
6099 | return algorithm13(x, y, larger);
|
6100 | },
|
6101 | 'Array, Array': function ArrayArray(x, y) {
|
6102 |
|
6103 | return larger(matrix(x), matrix(y)).valueOf();
|
6104 | },
|
6105 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
6106 |
|
6107 | return larger(matrix(x), y);
|
6108 | },
|
6109 | 'Matrix, Array': function MatrixArray(x, y) {
|
6110 |
|
6111 | return larger(x, matrix(y));
|
6112 | },
|
6113 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
6114 | return algorithm12(x, y, larger, false);
|
6115 | },
|
6116 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
6117 | return algorithm14(x, y, larger, false);
|
6118 | },
|
6119 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
6120 | return algorithm12(y, x, larger, true);
|
6121 | },
|
6122 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
6123 | return algorithm14(y, x, larger, true);
|
6124 | },
|
6125 | 'Array, any': function ArrayAny(x, y) {
|
6126 |
|
6127 | return algorithm14(matrix(x), y, larger, false).valueOf();
|
6128 | },
|
6129 | 'any, Array': function anyArray(x, y) {
|
6130 |
|
6131 | return algorithm14(matrix(y), x, larger, true).valueOf();
|
6132 | }
|
6133 | });
|
6134 | larger.toTex = {
|
6135 | 2: "\\left(${args[0]}".concat(latex.operators['larger'], "${args[1]}\\right)")
|
6136 | };
|
6137 | return larger;
|
6138 | }
|
6139 |
|
6140 | exports.name = 'larger';
|
6141 | exports.factory = factory;
|
6142 |
|
6143 | }),
|
6144 |
|
6145 | (function(module, exports, __webpack_require__) {
|
6146 |
|
6147 | "use strict";
|
6148 |
|
6149 |
|
6150 | var deepMap = __webpack_require__(1);
|
6151 |
|
6152 | var number = __webpack_require__(3);
|
6153 |
|
6154 | function factory(type, config, load, typed) {
|
6155 | |
6156 |
|
6157 |
|
6158 |
|
6159 |
|
6160 |
|
6161 |
|
6162 |
|
6163 |
|
6164 |
|
6165 |
|
6166 |
|
6167 |
|
6168 |
|
6169 |
|
6170 |
|
6171 |
|
6172 |
|
6173 |
|
6174 |
|
6175 |
|
6176 |
|
6177 |
|
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 |
|
6184 | var isInteger = typed('isInteger', {
|
6185 | 'number': number.isInteger,
|
6186 |
|
6187 | 'BigNumber': function BigNumber(x) {
|
6188 | return x.isInt();
|
6189 | },
|
6190 | 'Fraction': function Fraction(x) {
|
6191 | return x.d === 1 && isFinite(x.n);
|
6192 | },
|
6193 | 'Array | Matrix': function ArrayMatrix(x) {
|
6194 | return deepMap(x, isInteger);
|
6195 | }
|
6196 | });
|
6197 | return isInteger;
|
6198 | }
|
6199 |
|
6200 | exports.name = 'isInteger';
|
6201 | exports.factory = factory;
|
6202 |
|
6203 | }),
|
6204 |
|
6205 | (function(module, exports, __webpack_require__) {
|
6206 |
|
6207 | "use strict";
|
6208 |
|
6209 |
|
6210 | var isMatrix = __webpack_require__(56);
|
6211 |
|
6212 |
|
6213 |
|
6214 |
|
6215 |
|
6216 |
|
6217 |
|
6218 | module.exports = function isCollection(x) {
|
6219 | return Array.isArray(x) || isMatrix(x);
|
6220 | };
|
6221 |
|
6222 | }),
|
6223 |
|
6224 | (function(module, exports, __webpack_require__) {
|
6225 |
|
6226 | "use strict";
|
6227 |
|
6228 |
|
6229 |
|
6230 |
|
6231 |
|
6232 |
|
6233 |
|
6234 |
|
6235 |
|
6236 |
|
6237 |
|
6238 |
|
6239 |
|
6240 |
|
6241 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
6242 |
|
6243 | exports.memoize = function (fn, hasher) {
|
6244 | return function memoize() {
|
6245 | if (_typeof(memoize.cache) !== 'object') {
|
6246 | memoize.cache = {};
|
6247 | }
|
6248 |
|
6249 | var args = [];
|
6250 |
|
6251 | for (var i = 0; i < arguments.length; i++) {
|
6252 | args[i] = arguments[i];
|
6253 | }
|
6254 |
|
6255 | var hash = hasher ? hasher(args) : JSON.stringify(args);
|
6256 |
|
6257 | if (!(hash in memoize.cache)) {
|
6258 | memoize.cache[hash] = fn.apply(fn, args);
|
6259 | }
|
6260 |
|
6261 | return memoize.cache[hash];
|
6262 | };
|
6263 | };
|
6264 |
|
6265 |
|
6266 |
|
6267 |
|
6268 |
|
6269 |
|
6270 |
|
6271 |
|
6272 | exports.maxArgumentCount = function (fn) {
|
6273 | return Object.keys(fn.signatures || {}).reduce(function (args, signature) {
|
6274 | var count = (signature.match(/,/g) || []).length + 1;
|
6275 | return Math.max(args, count);
|
6276 | }, -1);
|
6277 | };
|
6278 |
|
6279 |
|
6280 |
|
6281 |
|
6282 |
|
6283 |
|
6284 |
|
6285 |
|
6286 | exports.callWithRightArgumentCount = function (fn, args, argCount) {
|
6287 | return Object.keys(fn.signatures || {}).reduce(function (args, signature) {
|
6288 | var count = (signature.match(/,/g) || []).length + 1;
|
6289 | return Math.max(args, count);
|
6290 | }, -1);
|
6291 | };
|
6292 |
|
6293 | }),
|
6294 |
|
6295 | (function(module, exports, __webpack_require__) {
|
6296 |
|
6297 | "use strict";
|
6298 |
|
6299 |
|
6300 | var DimensionError = __webpack_require__(8);
|
6301 |
|
6302 | function factory(type, config, load, typed) {
|
6303 | var DenseMatrix = type.DenseMatrix;
|
6304 | |
6305 |
|
6306 |
|
6307 |
|
6308 |
|
6309 |
|
6310 |
|
6311 |
|
6312 |
|
6313 |
|
6314 |
|
6315 |
|
6316 |
|
6317 |
|
6318 |
|
6319 |
|
6320 |
|
6321 |
|
6322 |
|
6323 |
|
6324 | var algorithm01 = function algorithm01(denseMatrix, sparseMatrix, callback, inverse) {
|
6325 |
|
6326 | var adata = denseMatrix._data;
|
6327 | var asize = denseMatrix._size;
|
6328 | var adt = denseMatrix._datatype;
|
6329 |
|
6330 | var bvalues = sparseMatrix._values;
|
6331 | var bindex = sparseMatrix._index;
|
6332 | var bptr = sparseMatrix._ptr;
|
6333 | var bsize = sparseMatrix._size;
|
6334 | var bdt = sparseMatrix._datatype;
|
6335 |
|
6336 | if (asize.length !== bsize.length) {
|
6337 | throw new DimensionError(asize.length, bsize.length);
|
6338 | }
|
6339 |
|
6340 |
|
6341 | if (asize[0] !== bsize[0] || asize[1] !== bsize[1]) {
|
6342 | throw new RangeError('Dimension mismatch. Matrix A (' + asize + ') must match Matrix B (' + bsize + ')');
|
6343 | }
|
6344 |
|
6345 |
|
6346 | if (!bvalues) {
|
6347 | throw new Error('Cannot perform operation on Dense Matrix and Pattern Sparse Matrix');
|
6348 | }
|
6349 |
|
6350 |
|
6351 | var rows = asize[0];
|
6352 | var columns = asize[1];
|
6353 |
|
6354 | var dt = typeof adt === 'string' && adt === bdt ? adt : undefined;
|
6355 |
|
6356 | var cf = dt ? typed.find(callback, [dt, dt]) : callback;
|
6357 |
|
6358 | var i, j;
|
6359 |
|
6360 | var cdata = [];
|
6361 |
|
6362 | for (i = 0; i < rows; i++) {
|
6363 | cdata[i] = [];
|
6364 | }
|
6365 |
|
6366 |
|
6367 | var x = [];
|
6368 |
|
6369 | var w = [];
|
6370 |
|
6371 | for (j = 0; j < columns; j++) {
|
6372 |
|
6373 | var mark = j + 1;
|
6374 |
|
6375 | for (var k0 = bptr[j], k1 = bptr[j + 1], k = k0; k < k1; k++) {
|
6376 |
|
6377 | i = bindex[k];
|
6378 |
|
6379 | x[i] = inverse ? cf(bvalues[k], adata[i][j]) : cf(adata[i][j], bvalues[k]);
|
6380 |
|
6381 | w[i] = mark;
|
6382 | }
|
6383 |
|
6384 |
|
6385 | for (i = 0; i < rows; i++) {
|
6386 |
|
6387 | if (w[i] === mark) {
|
6388 |
|
6389 | cdata[i][j] = x[i];
|
6390 | } else {
|
6391 |
|
6392 | cdata[i][j] = adata[i][j];
|
6393 | }
|
6394 | }
|
6395 | }
|
6396 |
|
6397 |
|
6398 | return new DenseMatrix({
|
6399 | data: cdata,
|
6400 | size: [rows, columns],
|
6401 | datatype: dt
|
6402 | });
|
6403 | };
|
6404 |
|
6405 | return algorithm01;
|
6406 | }
|
6407 |
|
6408 | exports.name = 'algorithm01';
|
6409 | exports.factory = factory;
|
6410 |
|
6411 | }),
|
6412 |
|
6413 | (function(module, exports, __webpack_require__) {
|
6414 |
|
6415 | "use strict";
|
6416 |
|
6417 |
|
6418 | var nearlyEqual = __webpack_require__(3).nearlyEqual;
|
6419 |
|
6420 | var bigNearlyEqual = __webpack_require__(32);
|
6421 |
|
6422 | function factory(type, config, load, typed) {
|
6423 | var matrix = load(__webpack_require__(0));
|
6424 | var algorithm03 = load(__webpack_require__(18));
|
6425 | var algorithm07 = load(__webpack_require__(29));
|
6426 | var algorithm12 = load(__webpack_require__(19));
|
6427 | var algorithm13 = load(__webpack_require__(7));
|
6428 | var algorithm14 = load(__webpack_require__(6));
|
6429 |
|
6430 | var latex = __webpack_require__(4);
|
6431 | |
6432 |
|
6433 |
|
6434 |
|
6435 |
|
6436 |
|
6437 |
|
6438 |
|
6439 |
|
6440 |
|
6441 |
|
6442 |
|
6443 |
|
6444 |
|
6445 |
|
6446 |
|
6447 |
|
6448 |
|
6449 |
|
6450 |
|
6451 |
|
6452 |
|
6453 |
|
6454 |
|
6455 |
|
6456 |
|
6457 |
|
6458 |
|
6459 |
|
6460 |
|
6461 |
|
6462 |
|
6463 |
|
6464 | var smaller = typed('smaller', {
|
6465 | 'boolean, boolean': function booleanBoolean(x, y) {
|
6466 | return x < y;
|
6467 | },
|
6468 | 'number, number': function numberNumber(x, y) {
|
6469 | return x < y && !nearlyEqual(x, y, config.epsilon);
|
6470 | },
|
6471 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
6472 | return x.lt(y) && !bigNearlyEqual(x, y, config.epsilon);
|
6473 | },
|
6474 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
6475 | return x.compare(y) === -1;
|
6476 | },
|
6477 | 'Complex, Complex': function ComplexComplex(x, y) {
|
6478 | throw new TypeError('No ordering relation is defined for complex numbers');
|
6479 | },
|
6480 | 'Unit, Unit': function UnitUnit(x, y) {
|
6481 | if (!x.equalBase(y)) {
|
6482 | throw new Error('Cannot compare units with different base');
|
6483 | }
|
6484 |
|
6485 | return smaller(x.value, y.value);
|
6486 | },
|
6487 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
6488 | return algorithm07(x, y, smaller);
|
6489 | },
|
6490 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
6491 | return algorithm03(y, x, smaller, true);
|
6492 | },
|
6493 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
6494 | return algorithm03(x, y, smaller, false);
|
6495 | },
|
6496 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
6497 | return algorithm13(x, y, smaller);
|
6498 | },
|
6499 | 'Array, Array': function ArrayArray(x, y) {
|
6500 |
|
6501 | return smaller(matrix(x), matrix(y)).valueOf();
|
6502 | },
|
6503 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
6504 |
|
6505 | return smaller(matrix(x), y);
|
6506 | },
|
6507 | 'Matrix, Array': function MatrixArray(x, y) {
|
6508 |
|
6509 | return smaller(x, matrix(y));
|
6510 | },
|
6511 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
6512 | return algorithm12(x, y, smaller, false);
|
6513 | },
|
6514 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
6515 | return algorithm14(x, y, smaller, false);
|
6516 | },
|
6517 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
6518 | return algorithm12(y, x, smaller, true);
|
6519 | },
|
6520 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
6521 | return algorithm14(y, x, smaller, true);
|
6522 | },
|
6523 | 'Array, any': function ArrayAny(x, y) {
|
6524 |
|
6525 | return algorithm14(matrix(x), y, smaller, false).valueOf();
|
6526 | },
|
6527 | 'any, Array': function anyArray(x, y) {
|
6528 |
|
6529 | return algorithm14(matrix(y), x, smaller, true).valueOf();
|
6530 | }
|
6531 | });
|
6532 | smaller.toTex = {
|
6533 | 2: "\\left(${args[0]}".concat(latex.operators['smaller'], "${args[1]}\\right)")
|
6534 | };
|
6535 | return smaller;
|
6536 | }
|
6537 |
|
6538 | exports.name = 'smaller';
|
6539 | exports.factory = factory;
|
6540 |
|
6541 | }),
|
6542 |
|
6543 | (function(module, exports, __webpack_require__) {
|
6544 |
|
6545 | "use strict";
|
6546 |
|
6547 |
|
6548 | var deepMap = __webpack_require__(1);
|
6549 |
|
6550 | function factory(type, config, load, typed) {
|
6551 | var latex = __webpack_require__(4);
|
6552 | |
6553 |
|
6554 |
|
6555 |
|
6556 |
|
6557 |
|
6558 |
|
6559 |
|
6560 |
|
6561 |
|
6562 |
|
6563 |
|
6564 |
|
6565 |
|
6566 |
|
6567 |
|
6568 |
|
6569 |
|
6570 |
|
6571 |
|
6572 |
|
6573 |
|
6574 |
|
6575 |
|
6576 |
|
6577 | var unaryMinus = typed('unaryMinus', {
|
6578 | 'number': function number(x) {
|
6579 | return -x;
|
6580 | },
|
6581 | 'Complex': function Complex(x) {
|
6582 | return x.neg();
|
6583 | },
|
6584 | 'BigNumber': function BigNumber(x) {
|
6585 | return x.neg();
|
6586 | },
|
6587 | 'Fraction': function Fraction(x) {
|
6588 | return x.neg();
|
6589 | },
|
6590 | 'Unit': function Unit(x) {
|
6591 | var res = x.clone();
|
6592 | res.value = unaryMinus(x.value);
|
6593 | return res;
|
6594 | },
|
6595 | 'Array | Matrix': function ArrayMatrix(x) {
|
6596 |
|
6597 | return deepMap(x, unaryMinus, true);
|
6598 | }
|
6599 |
|
6600 | });
|
6601 | unaryMinus.toTex = {
|
6602 | 1: "".concat(latex.operators['unaryMinus'], "\\left(${args[0]}\\right)")
|
6603 | };
|
6604 | return unaryMinus;
|
6605 | }
|
6606 |
|
6607 | exports.name = 'unaryMinus';
|
6608 | exports.factory = factory;
|
6609 |
|
6610 | }),
|
6611 |
|
6612 | (function(module, exports, __webpack_require__) {
|
6613 |
|
6614 | "use strict";
|
6615 |
|
6616 |
|
6617 | function factory(type, config, load, typed) {
|
6618 | var getType = load(__webpack_require__(26));
|
6619 | |
6620 |
|
6621 |
|
6622 |
|
6623 |
|
6624 |
|
6625 |
|
6626 |
|
6627 |
|
6628 |
|
6629 |
|
6630 | return function improveErrorMessage(err, fnName, value) {
|
6631 |
|
6632 | var details;
|
6633 |
|
6634 | if (String(err).indexOf('Unexpected type') !== -1) {
|
6635 | details = arguments.length > 2 ? ' (type: ' + getType(value) + ', value: ' + JSON.stringify(value) + ')' : ' (type: ' + err.data.actual + ')';
|
6636 | return new TypeError('Cannot calculate ' + fnName + ', unexpected type of argument' + details);
|
6637 | }
|
6638 |
|
6639 | if (String(err).indexOf('complex numbers') !== -1) {
|
6640 | details = arguments.length > 2 ? ' (type: ' + getType(value) + ', value: ' + JSON.stringify(value) + ')' : '';
|
6641 | return new TypeError('Cannot calculate ' + fnName + ', no ordering relation is defined for complex numbers' + details);
|
6642 | }
|
6643 |
|
6644 | return err;
|
6645 | };
|
6646 | }
|
6647 |
|
6648 | exports.factory = factory;
|
6649 |
|
6650 | }),
|
6651 |
|
6652 | (function(module, exports, __webpack_require__) {
|
6653 |
|
6654 | "use strict";
|
6655 |
|
6656 |
|
6657 | function factory(type, config, load, typed) {
|
6658 | var DenseMatrix = type.DenseMatrix;
|
6659 | |
6660 |
|
6661 |
|
6662 |
|
6663 |
|
6664 |
|
6665 |
|
6666 |
|
6667 |
|
6668 |
|
6669 |
|
6670 |
|
6671 |
|
6672 |
|
6673 |
|
6674 |
|
6675 |
|
6676 |
|
6677 |
|
6678 |
|
6679 | var algorithm10 = function algorithm10(s, b, callback, inverse) {
|
6680 |
|
6681 | var avalues = s._values;
|
6682 | var aindex = s._index;
|
6683 | var aptr = s._ptr;
|
6684 | var asize = s._size;
|
6685 | var adt = s._datatype;
|
6686 |
|
6687 | if (!avalues) {
|
6688 | throw new Error('Cannot perform operation on Pattern Sparse Matrix and Scalar value');
|
6689 | }
|
6690 |
|
6691 |
|
6692 | var rows = asize[0];
|
6693 | var columns = asize[1];
|
6694 |
|
6695 | var dt;
|
6696 |
|
6697 | var cf = callback;
|
6698 |
|
6699 | if (typeof adt === 'string') {
|
6700 |
|
6701 | dt = adt;
|
6702 |
|
6703 | b = typed.convert(b, dt);
|
6704 |
|
6705 | cf = typed.find(callback, [dt, dt]);
|
6706 | }
|
6707 |
|
6708 |
|
6709 | var cdata = [];
|
6710 |
|
6711 | var c = new DenseMatrix({
|
6712 | data: cdata,
|
6713 | size: [rows, columns],
|
6714 | datatype: dt
|
6715 | });
|
6716 |
|
6717 | var x = [];
|
6718 |
|
6719 | var w = [];
|
6720 |
|
6721 | for (var j = 0; j < columns; j++) {
|
6722 |
|
6723 | var mark = j + 1;
|
6724 |
|
6725 | for (var k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
|
6726 |
|
6727 | var r = aindex[k];
|
6728 |
|
6729 | x[r] = avalues[k];
|
6730 | w[r] = mark;
|
6731 | }
|
6732 |
|
6733 |
|
6734 | for (var i = 0; i < rows; i++) {
|
6735 |
|
6736 | if (j === 0) {
|
6737 |
|
6738 | cdata[i] = [];
|
6739 | }
|
6740 |
|
6741 |
|
6742 | if (w[i] === mark) {
|
6743 |
|
6744 | cdata[i][j] = inverse ? cf(b, x[i]) : cf(x[i], b);
|
6745 | } else {
|
6746 |
|
6747 | cdata[i][j] = b;
|
6748 | }
|
6749 | }
|
6750 | }
|
6751 |
|
6752 |
|
6753 | return c;
|
6754 | };
|
6755 |
|
6756 | return algorithm10;
|
6757 | }
|
6758 |
|
6759 | exports.name = 'algorithm10';
|
6760 | exports.factory = factory;
|
6761 |
|
6762 | }),
|
6763 |
|
6764 | (function(module, exports, __webpack_require__) {
|
6765 |
|
6766 | "use strict";
|
6767 |
|
6768 |
|
6769 | var isInteger = __webpack_require__(3).isInteger;
|
6770 |
|
6771 | var size = __webpack_require__(2).size;
|
6772 |
|
6773 | function factory(type, config, load, typed) {
|
6774 | var latex = __webpack_require__(4);
|
6775 |
|
6776 | var identity = load(__webpack_require__(50));
|
6777 | var multiply = load(__webpack_require__(10));
|
6778 | var matrix = load(__webpack_require__(0));
|
6779 | var fraction = load(__webpack_require__(83));
|
6780 | var number = load(__webpack_require__(64));
|
6781 | |
6782 |
|
6783 |
|
6784 |
|
6785 |
|
6786 |
|
6787 |
|
6788 |
|
6789 |
|
6790 |
|
6791 |
|
6792 |
|
6793 |
|
6794 |
|
6795 |
|
6796 |
|
6797 |
|
6798 |
|
6799 |
|
6800 |
|
6801 |
|
6802 |
|
6803 |
|
6804 |
|
6805 |
|
6806 |
|
6807 |
|
6808 |
|
6809 |
|
6810 |
|
6811 |
|
6812 |
|
6813 |
|
6814 | var pow = typed('pow', {
|
6815 | 'number, number': _pow,
|
6816 | 'Complex, Complex': function ComplexComplex(x, y) {
|
6817 | return x.pow(y);
|
6818 | },
|
6819 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
6820 | if (y.isInteger() || x >= 0 || config.predictable) {
|
6821 | return x.pow(y);
|
6822 | } else {
|
6823 | return new type.Complex(x.toNumber(), 0).pow(y.toNumber(), 0);
|
6824 | }
|
6825 | },
|
6826 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
6827 | if (y.d !== 1) {
|
6828 | if (config.predictable) {
|
6829 | throw new Error('Function pow does not support non-integer exponents for fractions.');
|
6830 | } else {
|
6831 | return _pow(x.valueOf(), y.valueOf());
|
6832 | }
|
6833 | } else {
|
6834 | return x.pow(y);
|
6835 | }
|
6836 | },
|
6837 | 'Array, number': _powArray,
|
6838 | 'Array, BigNumber': function ArrayBigNumber(x, y) {
|
6839 | return _powArray(x, y.toNumber());
|
6840 | },
|
6841 | 'Matrix, number': _powMatrix,
|
6842 | 'Matrix, BigNumber': function MatrixBigNumber(x, y) {
|
6843 | return _powMatrix(x, y.toNumber());
|
6844 | },
|
6845 | 'Unit, number | BigNumber': function UnitNumberBigNumber(x, y) {
|
6846 | return x.pow(y);
|
6847 | }
|
6848 | });
|
6849 | |
6850 |
|
6851 |
|
6852 |
|
6853 |
|
6854 |
|
6855 |
|
6856 |
|
6857 | function _pow(x, y) {
|
6858 |
|
6859 |
|
6860 | if (config.predictable && !isInteger(y) && x < 0) {
|
6861 |
|
6862 | try {
|
6863 | var yFrac = fraction(y);
|
6864 | var yNum = number(yFrac);
|
6865 |
|
6866 | if (y === yNum || Math.abs((y - yNum) / y) < 1e-14) {
|
6867 | if (yFrac.d % 2 === 1) {
|
6868 | return (yFrac.n % 2 === 0 ? 1 : -1) * Math.pow(-x, y);
|
6869 | }
|
6870 | }
|
6871 | } catch (ex) {}
|
6872 |
|
6873 |
|
6874 | }
|
6875 |
|
6876 |
|
6877 |
|
6878 | if (x * x < 1 && y === Infinity || x * x > 1 && y === -Infinity) {
|
6879 | return 0;
|
6880 | }
|
6881 |
|
6882 |
|
6883 |
|
6884 |
|
6885 | if (config.predictable && (x < -1 && y === Infinity || x > -1 && x < 0 && y === -Infinity)) {
|
6886 | return NaN;
|
6887 | }
|
6888 |
|
6889 | if (isInteger(y) || x >= 0 || config.predictable) {
|
6890 | return Math.pow(x, y);
|
6891 | } else {
|
6892 | return new type.Complex(x, 0).pow(y, 0);
|
6893 | }
|
6894 | }
|
6895 | |
6896 |
|
6897 |
|
6898 |
|
6899 |
|
6900 |
|
6901 |
|
6902 |
|
6903 |
|
6904 | function _powArray(x, y) {
|
6905 | if (!isInteger(y) || y < 0) {
|
6906 | throw new TypeError('For A^b, b must be a positive integer (value is ' + y + ')');
|
6907 | }
|
6908 |
|
6909 |
|
6910 | var s = size(x);
|
6911 |
|
6912 | if (s.length !== 2) {
|
6913 | throw new Error('For A^b, A must be 2 dimensional (A has ' + s.length + ' dimensions)');
|
6914 | }
|
6915 |
|
6916 | if (s[0] !== s[1]) {
|
6917 | throw new Error('For A^b, A must be square (size is ' + s[0] + 'x' + s[1] + ')');
|
6918 | }
|
6919 |
|
6920 | var res = identity(s[0]).valueOf();
|
6921 | var px = x;
|
6922 |
|
6923 | while (y >= 1) {
|
6924 | if ((y & 1) === 1) {
|
6925 | res = multiply(px, res);
|
6926 | }
|
6927 |
|
6928 | y >>= 1;
|
6929 | px = multiply(px, px);
|
6930 | }
|
6931 |
|
6932 | return res;
|
6933 | }
|
6934 | |
6935 |
|
6936 |
|
6937 |
|
6938 |
|
6939 |
|
6940 |
|
6941 |
|
6942 |
|
6943 | function _powMatrix(x, y) {
|
6944 | return matrix(_powArray(x.valueOf(), y));
|
6945 | }
|
6946 |
|
6947 | pow.toTex = {
|
6948 | 2: "\\left(${args[0]}\\right)".concat(latex.operators['pow'], "{${args[1]}}")
|
6949 | };
|
6950 | return pow;
|
6951 | }
|
6952 |
|
6953 | exports.name = 'pow';
|
6954 | exports.factory = factory;
|
6955 |
|
6956 | }),
|
6957 |
|
6958 | (function(module, exports, __webpack_require__) {
|
6959 |
|
6960 | "use strict";
|
6961 |
|
6962 |
|
6963 | var isInteger = __webpack_require__(3).isInteger;
|
6964 |
|
6965 | var resize = __webpack_require__(2).resize;
|
6966 |
|
6967 | function factory(type, config, load, typed) {
|
6968 | var matrix = load(__webpack_require__(0));
|
6969 | |
6970 |
|
6971 |
|
6972 |
|
6973 |
|
6974 |
|
6975 |
|
6976 |
|
6977 |
|
6978 |
|
6979 |
|
6980 |
|
6981 |
|
6982 |
|
6983 |
|
6984 |
|
6985 |
|
6986 |
|
6987 |
|
6988 |
|
6989 |
|
6990 |
|
6991 |
|
6992 |
|
6993 |
|
6994 |
|
6995 |
|
6996 |
|
6997 |
|
6998 |
|
6999 |
|
7000 |
|
7001 | var zeros = typed('zeros', {
|
7002 | '': function _() {
|
7003 | return config.matrix === 'Array' ? _zeros([]) : _zeros([], 'default');
|
7004 | },
|
7005 |
|
7006 |
|
7007 | '...number | BigNumber | string': function numberBigNumberString(size) {
|
7008 | var last = size[size.length - 1];
|
7009 |
|
7010 | if (typeof last === 'string') {
|
7011 | var format = size.pop();
|
7012 | return _zeros(size, format);
|
7013 | } else if (config.matrix === 'Array') {
|
7014 | return _zeros(size);
|
7015 | } else {
|
7016 | return _zeros(size, 'default');
|
7017 | }
|
7018 | },
|
7019 | 'Array': _zeros,
|
7020 | 'Matrix': function Matrix(size) {
|
7021 | var format = size.storage();
|
7022 | return _zeros(size.valueOf(), format);
|
7023 | },
|
7024 | 'Array | Matrix, string': function ArrayMatrixString(size, format) {
|
7025 | return _zeros(size.valueOf(), format);
|
7026 | }
|
7027 | });
|
7028 | zeros.toTex = undefined;
|
7029 |
|
7030 | return zeros;
|
7031 | |
7032 |
|
7033 |
|
7034 |
|
7035 |
|
7036 |
|
7037 |
|
7038 |
|
7039 | function _zeros(size, format) {
|
7040 | var hasBigNumbers = _normalize(size);
|
7041 |
|
7042 | var defaultValue = hasBigNumbers ? new type.BigNumber(0) : 0;
|
7043 |
|
7044 | _validate(size);
|
7045 |
|
7046 | if (format) {
|
7047 |
|
7048 | var m = matrix(format);
|
7049 |
|
7050 | if (size.length > 0) {
|
7051 | return m.resize(size, defaultValue);
|
7052 | }
|
7053 |
|
7054 | return m;
|
7055 | } else {
|
7056 |
|
7057 | var arr = [];
|
7058 |
|
7059 | if (size.length > 0) {
|
7060 | return resize(arr, size, defaultValue);
|
7061 | }
|
7062 |
|
7063 | return arr;
|
7064 | }
|
7065 | }
|
7066 |
|
7067 |
|
7068 | function _normalize(size) {
|
7069 | var hasBigNumbers = false;
|
7070 | size.forEach(function (value, index, arr) {
|
7071 | if (type.isBigNumber(value)) {
|
7072 | hasBigNumbers = true;
|
7073 | arr[index] = value.toNumber();
|
7074 | }
|
7075 | });
|
7076 | return hasBigNumbers;
|
7077 | }
|
7078 |
|
7079 |
|
7080 | function _validate(size) {
|
7081 | size.forEach(function (value) {
|
7082 | if (typeof value !== 'number' || !isInteger(value) || value < 0) {
|
7083 | throw new Error('Parameters in function zeros must be positive integers');
|
7084 | }
|
7085 | });
|
7086 | }
|
7087 | }
|
7088 |
|
7089 |
|
7090 | exports.name = 'zeros';
|
7091 | exports.factory = factory;
|
7092 |
|
7093 | }),
|
7094 |
|
7095 | (function(module, exports, __webpack_require__) {
|
7096 |
|
7097 | "use strict";
|
7098 |
|
7099 |
|
7100 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
7101 |
|
7102 | var ArgumentsError = __webpack_require__(57);
|
7103 |
|
7104 | var deepMap = __webpack_require__(1);
|
7105 |
|
7106 | function factory(type, config, load, typed) {
|
7107 | var numeric = load(__webpack_require__(65));
|
7108 | var AccessorNode = load(__webpack_require__(113));
|
7109 | var ArrayNode = load(__webpack_require__(116));
|
7110 | var AssignmentNode = load(__webpack_require__(117));
|
7111 | var BlockNode = load(__webpack_require__(118));
|
7112 | var ConditionalNode = load(__webpack_require__(119));
|
7113 | var ConstantNode = load(__webpack_require__(58));
|
7114 | var FunctionAssignmentNode = load(__webpack_require__(120));
|
7115 | var IndexNode = load(__webpack_require__(121));
|
7116 | var ObjectNode = load(__webpack_require__(122));
|
7117 | var OperatorNode = load(__webpack_require__(59));
|
7118 | var ParenthesisNode = load(__webpack_require__(68));
|
7119 | var FunctionNode = load(__webpack_require__(69));
|
7120 | var RangeNode = load(__webpack_require__(123));
|
7121 | var RelationalNode = load(__webpack_require__(124));
|
7122 | var SymbolNode = load(__webpack_require__(54));
|
7123 | |
7124 |
|
7125 |
|
7126 |
|
7127 |
|
7128 |
|
7129 |
|
7130 |
|
7131 |
|
7132 |
|
7133 |
|
7134 |
|
7135 |
|
7136 |
|
7137 |
|
7138 |
|
7139 |
|
7140 |
|
7141 |
|
7142 |
|
7143 |
|
7144 |
|
7145 |
|
7146 |
|
7147 |
|
7148 |
|
7149 |
|
7150 |
|
7151 |
|
7152 |
|
7153 |
|
7154 |
|
7155 |
|
7156 | function parse(expr, options) {
|
7157 | if (arguments.length !== 1 && arguments.length !== 2) {
|
7158 | throw new ArgumentsError('parse', arguments.length, 1, 2);
|
7159 | }
|
7160 |
|
7161 |
|
7162 | var extraNodes = options && options.nodes ? options.nodes : {};
|
7163 |
|
7164 | if (typeof expr === 'string') {
|
7165 |
|
7166 | return parseStart(expr, extraNodes);
|
7167 | } else if (Array.isArray(expr) || expr instanceof type.Matrix) {
|
7168 |
|
7169 | return deepMap(expr, function (elem) {
|
7170 | if (typeof elem !== 'string') throw new TypeError('String expected');
|
7171 | return parseStart(elem, extraNodes);
|
7172 | });
|
7173 | } else {
|
7174 |
|
7175 | throw new TypeError('String or matrix expected');
|
7176 | }
|
7177 | }
|
7178 |
|
7179 |
|
7180 | var TOKENTYPE = {
|
7181 | NULL: 0,
|
7182 | DELIMITER: 1,
|
7183 | NUMBER: 2,
|
7184 | SYMBOL: 3,
|
7185 | UNKNOWN: 4
|
7186 |
|
7187 | };
|
7188 | var DELIMITERS = {
|
7189 | ',': true,
|
7190 | '(': true,
|
7191 | ')': true,
|
7192 | '[': true,
|
7193 | ']': true,
|
7194 | '{': true,
|
7195 | '}': true,
|
7196 | '"': true,
|
7197 | '\'': true,
|
7198 | ';': true,
|
7199 | '+': true,
|
7200 | '-': true,
|
7201 | '*': true,
|
7202 | '.*': true,
|
7203 | '/': true,
|
7204 | './': true,
|
7205 | '%': true,
|
7206 | '^': true,
|
7207 | '.^': true,
|
7208 | '~': true,
|
7209 | '!': true,
|
7210 | '&': true,
|
7211 | '|': true,
|
7212 | '^|': true,
|
7213 | '=': true,
|
7214 | ':': true,
|
7215 | '?': true,
|
7216 | '==': true,
|
7217 | '!=': true,
|
7218 | '<': true,
|
7219 | '>': true,
|
7220 | '<=': true,
|
7221 | '>=': true,
|
7222 | '<<': true,
|
7223 | '>>': true,
|
7224 | '>>>': true
|
7225 |
|
7226 | };
|
7227 | var NAMED_DELIMITERS = {
|
7228 | 'mod': true,
|
7229 | 'to': true,
|
7230 | 'in': true,
|
7231 | 'and': true,
|
7232 | 'xor': true,
|
7233 | 'or': true,
|
7234 | 'not': true
|
7235 | };
|
7236 | var CONSTANTS = {
|
7237 | 'true': true,
|
7238 | 'false': false,
|
7239 | 'null': null,
|
7240 | 'undefined': undefined
|
7241 | };
|
7242 | var NUMERIC_CONSTANTS = ['NaN', 'Infinity'];
|
7243 |
|
7244 | function initialState() {
|
7245 | return {
|
7246 | extraNodes: {},
|
7247 |
|
7248 | expression: '',
|
7249 |
|
7250 | comment: '',
|
7251 |
|
7252 | index: 0,
|
7253 |
|
7254 | token: '',
|
7255 |
|
7256 | tokenType: TOKENTYPE.NULL,
|
7257 |
|
7258 | nestingLevel: 0,
|
7259 |
|
7260 | conditionalLevel: null
|
7261 |
|
7262 | };
|
7263 | }
|
7264 | |
7265 |
|
7266 |
|
7267 |
|
7268 |
|
7269 |
|
7270 |
|
7271 |
|
7272 |
|
7273 |
|
7274 | function currentString(state, length) {
|
7275 | return state.expression.substr(state.index, length);
|
7276 | }
|
7277 | |
7278 |
|
7279 |
|
7280 |
|
7281 |
|
7282 |
|
7283 |
|
7284 |
|
7285 |
|
7286 | function currentCharacter(state) {
|
7287 | return currentString(state, 1);
|
7288 | }
|
7289 | |
7290 |
|
7291 |
|
7292 |
|
7293 |
|
7294 |
|
7295 |
|
7296 |
|
7297 | function next(state) {
|
7298 | state.index++;
|
7299 | }
|
7300 | |
7301 |
|
7302 |
|
7303 |
|
7304 |
|
7305 |
|
7306 |
|
7307 | function prevCharacter(state) {
|
7308 | return state.expression.charAt(state.index - 1);
|
7309 | }
|
7310 | |
7311 |
|
7312 |
|
7313 |
|
7314 |
|
7315 |
|
7316 |
|
7317 | function nextCharacter(state) {
|
7318 | return state.expression.charAt(state.index + 1);
|
7319 | }
|
7320 | |
7321 |
|
7322 |
|
7323 |
|
7324 |
|
7325 |
|
7326 |
|
7327 | function getToken(state) {
|
7328 | state.tokenType = TOKENTYPE.NULL;
|
7329 | state.token = '';
|
7330 | state.comment = '';
|
7331 |
|
7332 |
|
7333 | while (parse.isWhitespace(currentCharacter(state), state.nestingLevel)) {
|
7334 | next(state);
|
7335 | }
|
7336 |
|
7337 |
|
7338 | if (currentCharacter(state) === '#') {
|
7339 | while (currentCharacter(state) !== '\n' && currentCharacter(state) !== '') {
|
7340 | state.comment += currentCharacter(state);
|
7341 | next(state);
|
7342 | }
|
7343 | }
|
7344 |
|
7345 |
|
7346 | if (currentCharacter(state) === '') {
|
7347 |
|
7348 | state.tokenType = TOKENTYPE.DELIMITER;
|
7349 | return;
|
7350 | }
|
7351 |
|
7352 |
|
7353 | if (currentCharacter(state) === '\n' && !state.nestingLevel) {
|
7354 | state.tokenType = TOKENTYPE.DELIMITER;
|
7355 | state.token = currentCharacter(state);
|
7356 | next(state);
|
7357 | return;
|
7358 | }
|
7359 |
|
7360 | var c1 = currentCharacter(state);
|
7361 | var c2 = currentString(state, 2);
|
7362 | var c3 = currentString(state, 3);
|
7363 |
|
7364 | if (c3.length === 3 && DELIMITERS[c3]) {
|
7365 | state.tokenType = TOKENTYPE.DELIMITER;
|
7366 | state.token = c3;
|
7367 | next(state);
|
7368 | next(state);
|
7369 | next(state);
|
7370 | return;
|
7371 | }
|
7372 |
|
7373 |
|
7374 | if (c2.length === 2 && DELIMITERS[c2]) {
|
7375 | state.tokenType = TOKENTYPE.DELIMITER;
|
7376 | state.token = c2;
|
7377 | next(state);
|
7378 | next(state);
|
7379 | return;
|
7380 | }
|
7381 |
|
7382 |
|
7383 | if (DELIMITERS[c1]) {
|
7384 | state.tokenType = TOKENTYPE.DELIMITER;
|
7385 | state.token = c1;
|
7386 | next(state);
|
7387 | return;
|
7388 | }
|
7389 |
|
7390 |
|
7391 | if (parse.isDigitDot(c1)) {
|
7392 | state.tokenType = TOKENTYPE.NUMBER;
|
7393 |
|
7394 | if (currentCharacter(state) === '.') {
|
7395 | state.token += currentCharacter(state);
|
7396 | next(state);
|
7397 |
|
7398 | if (!parse.isDigit(currentCharacter(state))) {
|
7399 |
|
7400 | state.tokenType = TOKENTYPE.DELIMITER;
|
7401 | }
|
7402 | } else {
|
7403 | while (parse.isDigit(currentCharacter(state))) {
|
7404 | state.token += currentCharacter(state);
|
7405 | next(state);
|
7406 | }
|
7407 |
|
7408 | if (parse.isDecimalMark(currentCharacter(state), nextCharacter(state))) {
|
7409 | state.token += currentCharacter(state);
|
7410 | next(state);
|
7411 | }
|
7412 | }
|
7413 |
|
7414 | while (parse.isDigit(currentCharacter(state))) {
|
7415 | state.token += currentCharacter(state);
|
7416 | next(state);
|
7417 | }
|
7418 |
|
7419 |
|
7420 | if (currentCharacter(state) === 'E' || currentCharacter(state) === 'e') {
|
7421 | if (parse.isDigit(nextCharacter(state)) || nextCharacter(state) === '-' || nextCharacter(state) === '+') {
|
7422 | state.token += currentCharacter(state);
|
7423 | next(state);
|
7424 |
|
7425 | if (currentCharacter(state) === '+' || currentCharacter(state) === '-') {
|
7426 | state.token += currentCharacter(state);
|
7427 | next(state);
|
7428 | }
|
7429 |
|
7430 |
|
7431 | if (!parse.isDigit(currentCharacter(state))) {
|
7432 | throw createSyntaxError(state, 'Digit expected, got "' + currentCharacter(state) + '"');
|
7433 | }
|
7434 |
|
7435 | while (parse.isDigit(currentCharacter(state))) {
|
7436 | state.token += currentCharacter(state);
|
7437 | next(state);
|
7438 | }
|
7439 |
|
7440 | if (parse.isDecimalMark(currentCharacter(state), nextCharacter(state))) {
|
7441 | throw createSyntaxError(state, 'Digit expected, got "' + currentCharacter(state) + '"');
|
7442 | }
|
7443 | } else if (nextCharacter(state) === '.') {
|
7444 | next(state);
|
7445 | throw createSyntaxError(state, 'Digit expected, got "' + currentCharacter(state) + '"');
|
7446 | }
|
7447 | }
|
7448 |
|
7449 | return;
|
7450 | }
|
7451 |
|
7452 |
|
7453 | if (parse.isAlpha(currentCharacter(state), prevCharacter(state), nextCharacter(state))) {
|
7454 | while (parse.isAlpha(currentCharacter(state), prevCharacter(state), nextCharacter(state)) || parse.isDigit(currentCharacter(state))) {
|
7455 | state.token += currentCharacter(state);
|
7456 | next(state);
|
7457 | }
|
7458 |
|
7459 | if (NAMED_DELIMITERS.hasOwnProperty(state.token)) {
|
7460 | state.tokenType = TOKENTYPE.DELIMITER;
|
7461 | } else {
|
7462 | state.tokenType = TOKENTYPE.SYMBOL;
|
7463 | }
|
7464 |
|
7465 | return;
|
7466 | }
|
7467 |
|
7468 |
|
7469 | state.tokenType = TOKENTYPE.UNKNOWN;
|
7470 |
|
7471 | while (currentCharacter(state) !== '') {
|
7472 | state.token += currentCharacter(state);
|
7473 | next(state);
|
7474 | }
|
7475 |
|
7476 | throw createSyntaxError(state, 'Syntax error in part "' + state.token + '"');
|
7477 | }
|
7478 | |
7479 |
|
7480 |
|
7481 |
|
7482 |
|
7483 | function getTokenSkipNewline(state) {
|
7484 | do {
|
7485 | getToken(state);
|
7486 | } while (state.token === '\n');
|
7487 |
|
7488 | }
|
7489 | |
7490 |
|
7491 |
|
7492 |
|
7493 |
|
7494 |
|
7495 | function openParams(state) {
|
7496 | state.nestingLevel++;
|
7497 | }
|
7498 | |
7499 |
|
7500 |
|
7501 |
|
7502 |
|
7503 |
|
7504 | function closeParams(state) {
|
7505 | state.nestingLevel--;
|
7506 | }
|
7507 | |
7508 |
|
7509 |
|
7510 |
|
7511 |
|
7512 |
|
7513 |
|
7514 |
|
7515 |
|
7516 |
|
7517 |
|
7518 |
|
7519 |
|
7520 |
|
7521 |
|
7522 |
|
7523 |
|
7524 |
|
7525 |
|
7526 |
|
7527 | parse.isAlpha = function isAlpha(c, cPrev, cNext) {
|
7528 | return parse.isValidLatinOrGreek(c) || parse.isValidMathSymbol(c, cNext) || parse.isValidMathSymbol(cPrev, c);
|
7529 | };
|
7530 | |
7531 |
|
7532 |
|
7533 |
|
7534 |
|
7535 |
|
7536 |
|
7537 | parse.isValidLatinOrGreek = function isValidLatinOrGreek(c) {
|
7538 | return /^[a-zA-Z_$\u00C0-\u02AF\u0370-\u03FF\u2100-\u214F]$/.test(c);
|
7539 | };
|
7540 | |
7541 |
|
7542 |
|
7543 |
|
7544 |
|
7545 |
|
7546 |
|
7547 |
|
7548 |
|
7549 |
|
7550 |
|
7551 |
|
7552 |
|
7553 |
|
7554 |
|
7555 |
|
7556 |
|
7557 | parse.isValidMathSymbol = function isValidMathSymbol(high, low) {
|
7558 | return /^[\uD835]$/.test(high) && /^[\uDC00-\uDFFF]$/.test(low) && /^[^\uDC55\uDC9D\uDCA0\uDCA1\uDCA3\uDCA4\uDCA7\uDCA8\uDCAD\uDCBA\uDCBC\uDCC4\uDD06\uDD0B\uDD0C\uDD15\uDD1D\uDD3A\uDD3F\uDD45\uDD47-\uDD49\uDD51\uDEA6\uDEA7\uDFCC\uDFCD]$/.test(low);
|
7559 | };
|
7560 | |
7561 |
|
7562 |
|
7563 |
|
7564 |
|
7565 |
|
7566 |
|
7567 |
|
7568 | parse.isWhitespace = function isWhitespace(c, nestingLevel) {
|
7569 |
|
7570 | return c === ' ' || c === '\t' || c === '\n' && nestingLevel > 0;
|
7571 | };
|
7572 | |
7573 |
|
7574 |
|
7575 |
|
7576 |
|
7577 |
|
7578 |
|
7579 |
|
7580 |
|
7581 | parse.isDecimalMark = function isDecimalMark(c, cNext) {
|
7582 | return c === '.' && cNext !== '/' && cNext !== '*' && cNext !== '^';
|
7583 | };
|
7584 | |
7585 |
|
7586 |
|
7587 |
|
7588 |
|
7589 |
|
7590 |
|
7591 | parse.isDigitDot = function isDigitDot(c) {
|
7592 | return c >= '0' && c <= '9' || c === '.';
|
7593 | };
|
7594 | |
7595 |
|
7596 |
|
7597 |
|
7598 |
|
7599 |
|
7600 |
|
7601 | parse.isDigit = function isDigit(c) {
|
7602 | return c >= '0' && c <= '9';
|
7603 | };
|
7604 | |
7605 |
|
7606 |
|
7607 |
|
7608 |
|
7609 |
|
7610 |
|
7611 | function parseStart(expression, extraNodes) {
|
7612 | var state = initialState();
|
7613 |
|
7614 | _extends(state, {
|
7615 | expression: expression,
|
7616 | extraNodes: extraNodes
|
7617 | });
|
7618 |
|
7619 | getToken(state);
|
7620 | var node = parseBlock(state);
|
7621 |
|
7622 |
|
7623 | if (state.token !== '') {
|
7624 | if (state.tokenType === TOKENTYPE.DELIMITER) {
|
7625 |
|
7626 |
|
7627 | throw createError(state, 'Unexpected operator ' + state.token);
|
7628 | } else {
|
7629 | throw createSyntaxError(state, 'Unexpected part "' + state.token + '"');
|
7630 | }
|
7631 | }
|
7632 |
|
7633 | return node;
|
7634 | }
|
7635 | |
7636 |
|
7637 |
|
7638 |
|
7639 |
|
7640 |
|
7641 |
|
7642 |
|
7643 |
|
7644 | function parseBlock(state) {
|
7645 | var node;
|
7646 | var blocks = [];
|
7647 | var visible;
|
7648 |
|
7649 | if (state.token !== '' && state.token !== '\n' && state.token !== ';') {
|
7650 | node = parseAssignment(state);
|
7651 | node.comment = state.comment;
|
7652 | }
|
7653 |
|
7654 |
|
7655 | while (state.token === '\n' || state.token === ';') {
|
7656 |
|
7657 | if (blocks.length === 0 && node) {
|
7658 | visible = state.token !== ';';
|
7659 | blocks.push({
|
7660 | node: node,
|
7661 | visible: visible
|
7662 | });
|
7663 | }
|
7664 |
|
7665 | getToken(state);
|
7666 |
|
7667 | if (state.token !== '\n' && state.token !== ';' && state.token !== '') {
|
7668 | node = parseAssignment(state);
|
7669 | node.comment = state.comment;
|
7670 | visible = state.token !== ';';
|
7671 | blocks.push({
|
7672 | node: node,
|
7673 | visible: visible
|
7674 | });
|
7675 | }
|
7676 | }
|
7677 |
|
7678 | if (blocks.length > 0) {
|
7679 | return new BlockNode(blocks);
|
7680 | } else {
|
7681 | if (!node) {
|
7682 | node = new ConstantNode(undefined);
|
7683 | node.comment = state.comment;
|
7684 | }
|
7685 |
|
7686 | return node;
|
7687 | }
|
7688 | }
|
7689 | |
7690 |
|
7691 |
|
7692 |
|
7693 |
|
7694 |
|
7695 |
|
7696 |
|
7697 |
|
7698 |
|
7699 | function parseAssignment(state) {
|
7700 | var name, args, value, valid;
|
7701 | var node = parseConditional(state);
|
7702 |
|
7703 | if (state.token === '=') {
|
7704 | if (type.isSymbolNode(node)) {
|
7705 |
|
7706 | name = node.name;
|
7707 | getTokenSkipNewline(state);
|
7708 | value = parseAssignment(state);
|
7709 | return new AssignmentNode(new SymbolNode(name), value);
|
7710 | } else if (type.isAccessorNode(node)) {
|
7711 |
|
7712 | getTokenSkipNewline(state);
|
7713 | value = parseAssignment(state);
|
7714 | return new AssignmentNode(node.object, node.index, value);
|
7715 | } else if (type.isFunctionNode(node) && type.isSymbolNode(node.fn)) {
|
7716 |
|
7717 | valid = true;
|
7718 | args = [];
|
7719 | name = node.name;
|
7720 | node.args.forEach(function (arg, index) {
|
7721 | if (type.isSymbolNode(arg)) {
|
7722 | args[index] = arg.name;
|
7723 | } else {
|
7724 | valid = false;
|
7725 | }
|
7726 | });
|
7727 |
|
7728 | if (valid) {
|
7729 | getTokenSkipNewline(state);
|
7730 | value = parseAssignment(state);
|
7731 | return new FunctionAssignmentNode(name, args, value);
|
7732 | }
|
7733 | }
|
7734 |
|
7735 | throw createSyntaxError(state, 'Invalid left hand side of assignment operator =');
|
7736 | }
|
7737 |
|
7738 | return node;
|
7739 | }
|
7740 | |
7741 |
|
7742 |
|
7743 |
|
7744 |
|
7745 |
|
7746 |
|
7747 |
|
7748 |
|
7749 |
|
7750 |
|
7751 |
|
7752 | function parseConditional(state) {
|
7753 | var node = parseLogicalOr(state);
|
7754 |
|
7755 | while (state.token === '?') {
|
7756 |
|
7757 |
|
7758 |
|
7759 | var prev = state.conditionalLevel;
|
7760 | state.conditionalLevel = state.nestingLevel;
|
7761 | getTokenSkipNewline(state);
|
7762 | var condition = node;
|
7763 | var trueExpr = parseAssignment(state);
|
7764 | if (state.token !== ':') throw createSyntaxError(state, 'False part of conditional expression expected');
|
7765 | state.conditionalLevel = null;
|
7766 | getTokenSkipNewline(state);
|
7767 | var falseExpr = parseAssignment(state);
|
7768 |
|
7769 | node = new ConditionalNode(condition, trueExpr, falseExpr);
|
7770 |
|
7771 | state.conditionalLevel = prev;
|
7772 | }
|
7773 |
|
7774 | return node;
|
7775 | }
|
7776 | |
7777 |
|
7778 |
|
7779 |
|
7780 |
|
7781 |
|
7782 |
|
7783 | function parseLogicalOr(state) {
|
7784 | var node = parseLogicalXor(state);
|
7785 |
|
7786 | while (state.token === 'or') {
|
7787 |
|
7788 | getTokenSkipNewline(state);
|
7789 | node = new OperatorNode('or', 'or', [node, parseLogicalXor(state)]);
|
7790 | }
|
7791 |
|
7792 | return node;
|
7793 | }
|
7794 | |
7795 |
|
7796 |
|
7797 |
|
7798 |
|
7799 |
|
7800 |
|
7801 | function parseLogicalXor(state) {
|
7802 | var node = parseLogicalAnd(state);
|
7803 |
|
7804 | while (state.token === 'xor') {
|
7805 |
|
7806 | getTokenSkipNewline(state);
|
7807 | node = new OperatorNode('xor', 'xor', [node, parseLogicalAnd(state)]);
|
7808 | }
|
7809 |
|
7810 | return node;
|
7811 | }
|
7812 | |
7813 |
|
7814 |
|
7815 |
|
7816 |
|
7817 |
|
7818 |
|
7819 | function parseLogicalAnd(state) {
|
7820 | var node = parseBitwiseOr(state);
|
7821 |
|
7822 | while (state.token === 'and') {
|
7823 |
|
7824 | getTokenSkipNewline(state);
|
7825 | node = new OperatorNode('and', 'and', [node, parseBitwiseOr(state)]);
|
7826 | }
|
7827 |
|
7828 | return node;
|
7829 | }
|
7830 | |
7831 |
|
7832 |
|
7833 |
|
7834 |
|
7835 |
|
7836 |
|
7837 | function parseBitwiseOr(state) {
|
7838 | var node = parseBitwiseXor(state);
|
7839 |
|
7840 | while (state.token === '|') {
|
7841 |
|
7842 | getTokenSkipNewline(state);
|
7843 | node = new OperatorNode('|', 'bitOr', [node, parseBitwiseXor(state)]);
|
7844 | }
|
7845 |
|
7846 | return node;
|
7847 | }
|
7848 | |
7849 |
|
7850 |
|
7851 |
|
7852 |
|
7853 |
|
7854 |
|
7855 | function parseBitwiseXor(state) {
|
7856 | var node = parseBitwiseAnd(state);
|
7857 |
|
7858 | while (state.token === '^|') {
|
7859 |
|
7860 | getTokenSkipNewline(state);
|
7861 | node = new OperatorNode('^|', 'bitXor', [node, parseBitwiseAnd(state)]);
|
7862 | }
|
7863 |
|
7864 | return node;
|
7865 | }
|
7866 | |
7867 |
|
7868 |
|
7869 |
|
7870 |
|
7871 |
|
7872 |
|
7873 | function parseBitwiseAnd(state) {
|
7874 | var node = parseRelational(state);
|
7875 |
|
7876 | while (state.token === '&') {
|
7877 |
|
7878 | getTokenSkipNewline(state);
|
7879 | node = new OperatorNode('&', 'bitAnd', [node, parseRelational(state)]);
|
7880 | }
|
7881 |
|
7882 | return node;
|
7883 | }
|
7884 | |
7885 |
|
7886 |
|
7887 |
|
7888 |
|
7889 |
|
7890 | function parseRelational(state) {
|
7891 | var params = [parseShift(state)];
|
7892 | var conditionals = [];
|
7893 | var operators = {
|
7894 | '==': 'equal',
|
7895 | '!=': 'unequal',
|
7896 | '<': 'smaller',
|
7897 | '>': 'larger',
|
7898 | '<=': 'smallerEq',
|
7899 | '>=': 'largerEq'
|
7900 | };
|
7901 |
|
7902 | while (operators.hasOwnProperty(state.token)) {
|
7903 |
|
7904 | var cond = {
|
7905 | name: state.token,
|
7906 | fn: operators[state.token]
|
7907 | };
|
7908 | conditionals.push(cond);
|
7909 | getTokenSkipNewline(state);
|
7910 | params.push(parseShift(state));
|
7911 | }
|
7912 |
|
7913 | if (params.length === 1) {
|
7914 | return params[0];
|
7915 | } else if (params.length === 2) {
|
7916 | return new OperatorNode(conditionals[0].name, conditionals[0].fn, params);
|
7917 | } else {
|
7918 | return new RelationalNode(conditionals.map(function (c) {
|
7919 | return c.fn;
|
7920 | }), params);
|
7921 | }
|
7922 | }
|
7923 | |
7924 |
|
7925 |
|
7926 |
|
7927 |
|
7928 |
|
7929 |
|
7930 | function parseShift(state) {
|
7931 | var node, operators, name, fn, params;
|
7932 | node = parseConversion(state);
|
7933 | operators = {
|
7934 | '<<': 'leftShift',
|
7935 | '>>': 'rightArithShift',
|
7936 | '>>>': 'rightLogShift'
|
7937 | };
|
7938 |
|
7939 | while (operators.hasOwnProperty(state.token)) {
|
7940 | name = state.token;
|
7941 | fn = operators[name];
|
7942 | getTokenSkipNewline(state);
|
7943 | params = [node, parseConversion(state)];
|
7944 | node = new OperatorNode(name, fn, params);
|
7945 | }
|
7946 |
|
7947 | return node;
|
7948 | }
|
7949 | |
7950 |
|
7951 |
|
7952 |
|
7953 |
|
7954 |
|
7955 |
|
7956 | function parseConversion(state) {
|
7957 | var node, operators, name, fn, params;
|
7958 | node = parseRange(state);
|
7959 | operators = {
|
7960 | 'to': 'to',
|
7961 | 'in': 'to'
|
7962 |
|
7963 | };
|
7964 |
|
7965 | while (operators.hasOwnProperty(state.token)) {
|
7966 | name = state.token;
|
7967 | fn = operators[name];
|
7968 | getTokenSkipNewline(state);
|
7969 |
|
7970 | if (name === 'in' && state.token === '') {
|
7971 |
|
7972 | node = new OperatorNode('*', 'multiply', [node, new SymbolNode('in')], true);
|
7973 | } else {
|
7974 |
|
7975 | params = [node, parseRange(state)];
|
7976 | node = new OperatorNode(name, fn, params);
|
7977 | }
|
7978 | }
|
7979 |
|
7980 | return node;
|
7981 | }
|
7982 | |
7983 |
|
7984 |
|
7985 |
|
7986 |
|
7987 |
|
7988 |
|
7989 | function parseRange(state) {
|
7990 | var node;
|
7991 | var params = [];
|
7992 |
|
7993 | if (state.token === ':') {
|
7994 |
|
7995 | node = new ConstantNode(1);
|
7996 | } else {
|
7997 |
|
7998 | node = parseAddSubtract(state);
|
7999 | }
|
8000 |
|
8001 | if (state.token === ':' && state.conditionalLevel !== state.nestingLevel) {
|
8002 |
|
8003 | params.push(node);
|
8004 |
|
8005 | while (state.token === ':' && params.length < 3) {
|
8006 |
|
8007 | getTokenSkipNewline(state);
|
8008 |
|
8009 | if (state.token === ')' || state.token === ']' || state.token === ',' || state.token === '') {
|
8010 |
|
8011 | params.push(new SymbolNode('end'));
|
8012 | } else {
|
8013 |
|
8014 | params.push(parseAddSubtract(state));
|
8015 | }
|
8016 | }
|
8017 |
|
8018 | if (params.length === 3) {
|
8019 |
|
8020 | node = new RangeNode(params[0], params[2], params[1]);
|
8021 | } else {
|
8022 |
|
8023 |
|
8024 | node = new RangeNode(params[0], params[1]);
|
8025 | }
|
8026 | }
|
8027 |
|
8028 | return node;
|
8029 | }
|
8030 | |
8031 |
|
8032 |
|
8033 |
|
8034 |
|
8035 |
|
8036 |
|
8037 | function parseAddSubtract(state) {
|
8038 | var node, operators, name, fn, params;
|
8039 | node = parseMultiplyDivide(state);
|
8040 | operators = {
|
8041 | '+': 'add',
|
8042 | '-': 'subtract'
|
8043 | };
|
8044 |
|
8045 | while (operators.hasOwnProperty(state.token)) {
|
8046 | name = state.token;
|
8047 | fn = operators[name];
|
8048 | getTokenSkipNewline(state);
|
8049 | params = [node, parseMultiplyDivide(state)];
|
8050 | node = new OperatorNode(name, fn, params);
|
8051 | }
|
8052 |
|
8053 | return node;
|
8054 | }
|
8055 | |
8056 |
|
8057 |
|
8058 |
|
8059 |
|
8060 |
|
8061 |
|
8062 | function parseMultiplyDivide(state) {
|
8063 | var node, last, operators, name, fn;
|
8064 | node = parseImplicitMultiplication(state);
|
8065 | last = node;
|
8066 | operators = {
|
8067 | '*': 'multiply',
|
8068 | '.*': 'dotMultiply',
|
8069 | '/': 'divide',
|
8070 | './': 'dotDivide',
|
8071 | '%': 'mod',
|
8072 | 'mod': 'mod'
|
8073 | };
|
8074 |
|
8075 | while (true) {
|
8076 | if (operators.hasOwnProperty(state.token)) {
|
8077 |
|
8078 | name = state.token;
|
8079 | fn = operators[name];
|
8080 | getTokenSkipNewline(state);
|
8081 | last = parseImplicitMultiplication(state);
|
8082 | node = new OperatorNode(name, fn, [node, last]);
|
8083 | } else {
|
8084 | break;
|
8085 | }
|
8086 | }
|
8087 |
|
8088 | return node;
|
8089 | }
|
8090 | |
8091 |
|
8092 |
|
8093 |
|
8094 |
|
8095 |
|
8096 |
|
8097 | function parseImplicitMultiplication(state) {
|
8098 | var node, last;
|
8099 | node = parseRule2(state);
|
8100 | last = node;
|
8101 |
|
8102 | while (true) {
|
8103 | if (state.tokenType === TOKENTYPE.SYMBOL || state.token === 'in' && type.isConstantNode(node) || state.tokenType === TOKENTYPE.NUMBER && !type.isConstantNode(last) && (!type.isOperatorNode(last) || last.op === '!') || state.token === '(') {
|
8104 |
|
8105 |
|
8106 |
|
8107 |
|
8108 |
|
8109 | last = parseRule2(state);
|
8110 | node = new OperatorNode('*', 'multiply', [node, last], true
|
8111 |
|
8112 | );
|
8113 | } else {
|
8114 | break;
|
8115 | }
|
8116 | }
|
8117 |
|
8118 | return node;
|
8119 | }
|
8120 | |
8121 |
|
8122 |
|
8123 |
|
8124 |
|
8125 |
|
8126 |
|
8127 |
|
8128 |
|
8129 | function parseRule2(state) {
|
8130 | var node = parseUnary(state);
|
8131 | var last = node;
|
8132 | var tokenStates = [];
|
8133 |
|
8134 | while (true) {
|
8135 |
|
8136 | if (state.token === '/' && type.isConstantNode(last)) {
|
8137 |
|
8138 | tokenStates.push(_extends({}, state));
|
8139 | getTokenSkipNewline(state);
|
8140 |
|
8141 | if (state.tokenType === TOKENTYPE.NUMBER) {
|
8142 |
|
8143 | tokenStates.push(_extends({}, state));
|
8144 | getTokenSkipNewline(state);
|
8145 |
|
8146 | if (state.tokenType === TOKENTYPE.SYMBOL || state.token === '(') {
|
8147 |
|
8148 |
|
8149 | _extends(state, tokenStates.pop());
|
8150 |
|
8151 | tokenStates.pop();
|
8152 | last = parseUnary(state);
|
8153 | node = new OperatorNode('/', 'divide', [node, last]);
|
8154 | } else {
|
8155 |
|
8156 | tokenStates.pop();
|
8157 |
|
8158 | _extends(state, tokenStates.pop());
|
8159 |
|
8160 | break;
|
8161 | }
|
8162 | } else {
|
8163 |
|
8164 | _extends(state, tokenStates.pop());
|
8165 |
|
8166 | break;
|
8167 | }
|
8168 | } else {
|
8169 | break;
|
8170 | }
|
8171 | }
|
8172 |
|
8173 | return node;
|
8174 | }
|
8175 | |
8176 |
|
8177 |
|
8178 |
|
8179 |
|
8180 |
|
8181 |
|
8182 | function parseUnary(state) {
|
8183 | var name, params, fn;
|
8184 | var operators = {
|
8185 | '-': 'unaryMinus',
|
8186 | '+': 'unaryPlus',
|
8187 | '~': 'bitNot',
|
8188 | 'not': 'not'
|
8189 | };
|
8190 |
|
8191 | if (operators.hasOwnProperty(state.token)) {
|
8192 | fn = operators[state.token];
|
8193 | name = state.token;
|
8194 | getTokenSkipNewline(state);
|
8195 | params = [parseUnary(state)];
|
8196 | return new OperatorNode(name, fn, params);
|
8197 | }
|
8198 |
|
8199 | return parsePow(state);
|
8200 | }
|
8201 | |
8202 |
|
8203 |
|
8204 |
|
8205 |
|
8206 |
|
8207 |
|
8208 |
|
8209 | function parsePow(state) {
|
8210 | var node, name, fn, params;
|
8211 | node = parseLeftHandOperators(state);
|
8212 |
|
8213 | if (state.token === '^' || state.token === '.^') {
|
8214 | name = state.token;
|
8215 | fn = name === '^' ? 'pow' : 'dotPow';
|
8216 | getTokenSkipNewline(state);
|
8217 | params = [node, parseUnary(state)];
|
8218 |
|
8219 | node = new OperatorNode(name, fn, params);
|
8220 | }
|
8221 |
|
8222 | return node;
|
8223 | }
|
8224 | |
8225 |
|
8226 |
|
8227 |
|
8228 |
|
8229 |
|
8230 |
|
8231 | function parseLeftHandOperators(state) {
|
8232 | var node, operators, name, fn, params;
|
8233 | node = parseCustomNodes(state);
|
8234 | operators = {
|
8235 | '!': 'factorial',
|
8236 | '\'': 'ctranspose'
|
8237 | };
|
8238 |
|
8239 | while (operators.hasOwnProperty(state.token)) {
|
8240 | name = state.token;
|
8241 | fn = operators[name];
|
8242 | getToken(state);
|
8243 | params = [node];
|
8244 | node = new OperatorNode(name, fn, params);
|
8245 | node = parseAccessors(state, node);
|
8246 | }
|
8247 |
|
8248 | return node;
|
8249 | }
|
8250 | |
8251 |
|
8252 |
|
8253 |
|
8254 |
|
8255 |
|
8256 |
|
8257 |
|
8258 |
|
8259 |
|
8260 |
|
8261 |
|
8262 |
|
8263 |
|
8264 |
|
8265 |
|
8266 |
|
8267 |
|
8268 |
|
8269 |
|
8270 |
|
8271 |
|
8272 |
|
8273 |
|
8274 |
|
8275 |
|
8276 |
|
8277 |
|
8278 |
|
8279 |
|
8280 | function parseCustomNodes(state) {
|
8281 | var params = [];
|
8282 |
|
8283 | if (state.tokenType === TOKENTYPE.SYMBOL && state.extraNodes.hasOwnProperty(state.token)) {
|
8284 | var CustomNode = state.extraNodes[state.token];
|
8285 | getToken(state);
|
8286 |
|
8287 | if (state.token === '(') {
|
8288 | params = [];
|
8289 | openParams(state);
|
8290 | getToken(state);
|
8291 |
|
8292 | if (state.token !== ')') {
|
8293 | params.push(parseAssignment(state));
|
8294 |
|
8295 | while (state.token === ',') {
|
8296 |
|
8297 | getToken(state);
|
8298 | params.push(parseAssignment(state));
|
8299 | }
|
8300 | }
|
8301 |
|
8302 | if (state.token !== ')') {
|
8303 | throw createSyntaxError(state, 'Parenthesis ) expected');
|
8304 | }
|
8305 |
|
8306 | closeParams(state);
|
8307 | getToken(state);
|
8308 | }
|
8309 |
|
8310 |
|
8311 |
|
8312 | return new CustomNode(params);
|
8313 | }
|
8314 |
|
8315 | return parseSymbol(state);
|
8316 | }
|
8317 | |
8318 |
|
8319 |
|
8320 |
|
8321 |
|
8322 |
|
8323 |
|
8324 | function parseSymbol(state) {
|
8325 | var node, name;
|
8326 |
|
8327 | if (state.tokenType === TOKENTYPE.SYMBOL || state.tokenType === TOKENTYPE.DELIMITER && state.token in NAMED_DELIMITERS) {
|
8328 | name = state.token;
|
8329 | getToken(state);
|
8330 |
|
8331 | if (CONSTANTS.hasOwnProperty(name)) {
|
8332 |
|
8333 | node = new ConstantNode(CONSTANTS[name]);
|
8334 | } else if (NUMERIC_CONSTANTS.indexOf(name) !== -1) {
|
8335 |
|
8336 | node = new ConstantNode(numeric(name, 'number'));
|
8337 | } else {
|
8338 | node = new SymbolNode(name);
|
8339 | }
|
8340 |
|
8341 |
|
8342 | node = parseAccessors(state, node);
|
8343 | return node;
|
8344 | }
|
8345 |
|
8346 | return parseDoubleQuotesString(state);
|
8347 | }
|
8348 | |
8349 |
|
8350 |
|
8351 |
|
8352 |
|
8353 |
|
8354 |
|
8355 |
|
8356 |
|
8357 |
|
8358 |
|
8359 |
|
8360 |
|
8361 |
|
8362 |
|
8363 | function parseAccessors(state, node, types) {
|
8364 | var params;
|
8365 |
|
8366 | while ((state.token === '(' || state.token === '[' || state.token === '.') && (!types || types.indexOf(state.token) !== -1)) {
|
8367 |
|
8368 | params = [];
|
8369 |
|
8370 | if (state.token === '(') {
|
8371 | if (type.isSymbolNode(node) || type.isAccessorNode(node)) {
|
8372 |
|
8373 | openParams(state);
|
8374 | getToken(state);
|
8375 |
|
8376 | if (state.token !== ')') {
|
8377 | params.push(parseAssignment(state));
|
8378 |
|
8379 | while (state.token === ',') {
|
8380 |
|
8381 | getToken(state);
|
8382 | params.push(parseAssignment(state));
|
8383 | }
|
8384 | }
|
8385 |
|
8386 | if (state.token !== ')') {
|
8387 | throw createSyntaxError(state, 'Parenthesis ) expected');
|
8388 | }
|
8389 |
|
8390 | closeParams(state);
|
8391 | getToken(state);
|
8392 | node = new FunctionNode(node, params);
|
8393 | } else {
|
8394 |
|
8395 |
|
8396 |
|
8397 | return node;
|
8398 | }
|
8399 | } else if (state.token === '[') {
|
8400 |
|
8401 | openParams(state);
|
8402 | getToken(state);
|
8403 |
|
8404 | if (state.token !== ']') {
|
8405 | params.push(parseAssignment(state));
|
8406 |
|
8407 | while (state.token === ',') {
|
8408 |
|
8409 | getToken(state);
|
8410 | params.push(parseAssignment(state));
|
8411 | }
|
8412 | }
|
8413 |
|
8414 | if (state.token !== ']') {
|
8415 | throw createSyntaxError(state, 'Parenthesis ] expected');
|
8416 | }
|
8417 |
|
8418 | closeParams(state);
|
8419 | getToken(state);
|
8420 | node = new AccessorNode(node, new IndexNode(params));
|
8421 | } else {
|
8422 |
|
8423 | getToken(state);
|
8424 |
|
8425 | if (state.tokenType !== TOKENTYPE.SYMBOL) {
|
8426 | throw createSyntaxError(state, 'Property name expected after dot');
|
8427 | }
|
8428 |
|
8429 | params.push(new ConstantNode(state.token));
|
8430 | getToken(state);
|
8431 | var dotNotation = true;
|
8432 | node = new AccessorNode(node, new IndexNode(params, dotNotation));
|
8433 | }
|
8434 | }
|
8435 |
|
8436 | return node;
|
8437 | }
|
8438 | |
8439 |
|
8440 |
|
8441 |
|
8442 |
|
8443 |
|
8444 |
|
8445 | function parseDoubleQuotesString(state) {
|
8446 | var node, str;
|
8447 |
|
8448 | if (state.token === '"') {
|
8449 | str = parseDoubleQuotesStringToken(state);
|
8450 |
|
8451 | node = new ConstantNode(str);
|
8452 |
|
8453 | node = parseAccessors(state, node);
|
8454 | return node;
|
8455 | }
|
8456 |
|
8457 | return parseSingleQuotesString(state);
|
8458 | }
|
8459 | |
8460 |
|
8461 |
|
8462 |
|
8463 |
|
8464 |
|
8465 | function parseDoubleQuotesStringToken(state) {
|
8466 | var str = '';
|
8467 |
|
8468 | while (currentCharacter(state) !== '' && currentCharacter(state) !== '"') {
|
8469 | if (currentCharacter(state) === '\\') {
|
8470 |
|
8471 |
|
8472 | str += currentCharacter(state);
|
8473 | next(state);
|
8474 | }
|
8475 |
|
8476 | str += currentCharacter(state);
|
8477 | next(state);
|
8478 | }
|
8479 |
|
8480 | getToken(state);
|
8481 |
|
8482 | if (state.token !== '"') {
|
8483 | throw createSyntaxError(state, 'End of string " expected');
|
8484 | }
|
8485 |
|
8486 | getToken(state);
|
8487 | return JSON.parse('"' + str + '"');
|
8488 | }
|
8489 | |
8490 |
|
8491 |
|
8492 |
|
8493 |
|
8494 |
|
8495 |
|
8496 | function parseSingleQuotesString(state) {
|
8497 | var node, str;
|
8498 |
|
8499 | if (state.token === '\'') {
|
8500 | str = parseSingleQuotesStringToken(state);
|
8501 |
|
8502 | node = new ConstantNode(str);
|
8503 |
|
8504 | node = parseAccessors(state, node);
|
8505 | return node;
|
8506 | }
|
8507 |
|
8508 | return parseMatrix(state);
|
8509 | }
|
8510 | |
8511 |
|
8512 |
|
8513 |
|
8514 |
|
8515 |
|
8516 | function parseSingleQuotesStringToken(state) {
|
8517 | var str = '';
|
8518 |
|
8519 | while (currentCharacter(state) !== '' && currentCharacter(state) !== '\'') {
|
8520 | if (currentCharacter(state) === '\\') {
|
8521 |
|
8522 |
|
8523 | str += currentCharacter(state);
|
8524 | next(state);
|
8525 | }
|
8526 |
|
8527 | str += currentCharacter(state);
|
8528 | next(state);
|
8529 | }
|
8530 |
|
8531 | getToken(state);
|
8532 |
|
8533 | if (state.token !== '\'') {
|
8534 | throw createSyntaxError(state, 'End of string \' expected');
|
8535 | }
|
8536 |
|
8537 | getToken(state);
|
8538 | return JSON.parse('"' + str + '"');
|
8539 | }
|
8540 | |
8541 |
|
8542 |
|
8543 |
|
8544 |
|
8545 |
|
8546 |
|
8547 | function parseMatrix(state) {
|
8548 | var array, params, rows, cols;
|
8549 |
|
8550 | if (state.token === '[') {
|
8551 |
|
8552 | openParams(state);
|
8553 | getToken(state);
|
8554 |
|
8555 | if (state.token !== ']') {
|
8556 |
|
8557 | var row = parseRow(state);
|
8558 |
|
8559 | if (state.token === ';') {
|
8560 |
|
8561 | rows = 1;
|
8562 | params = [row];
|
8563 |
|
8564 | while (state.token === ';') {
|
8565 |
|
8566 | getToken(state);
|
8567 | params[rows] = parseRow(state);
|
8568 | rows++;
|
8569 | }
|
8570 |
|
8571 | if (state.token !== ']') {
|
8572 | throw createSyntaxError(state, 'End of matrix ] expected');
|
8573 | }
|
8574 |
|
8575 | closeParams(state);
|
8576 | getToken(state);
|
8577 |
|
8578 | cols = params[0].items.length;
|
8579 |
|
8580 | for (var r = 1; r < rows; r++) {
|
8581 | if (params[r].items.length !== cols) {
|
8582 | throw createError(state, 'Column dimensions mismatch ' + '(' + params[r].items.length + ' !== ' + cols + ')');
|
8583 | }
|
8584 | }
|
8585 |
|
8586 | array = new ArrayNode(params);
|
8587 | } else {
|
8588 |
|
8589 | if (state.token !== ']') {
|
8590 | throw createSyntaxError(state, 'End of matrix ] expected');
|
8591 | }
|
8592 |
|
8593 | closeParams(state);
|
8594 | getToken(state);
|
8595 | array = row;
|
8596 | }
|
8597 | } else {
|
8598 |
|
8599 | closeParams(state);
|
8600 | getToken(state);
|
8601 | array = new ArrayNode([]);
|
8602 | }
|
8603 |
|
8604 | return parseAccessors(state, array);
|
8605 | }
|
8606 |
|
8607 | return parseObject(state);
|
8608 | }
|
8609 | |
8610 |
|
8611 |
|
8612 |
|
8613 |
|
8614 |
|
8615 | function parseRow(state) {
|
8616 | var params = [parseAssignment(state)];
|
8617 | var len = 1;
|
8618 |
|
8619 | while (state.token === ',') {
|
8620 |
|
8621 | getToken(state);
|
8622 |
|
8623 | params[len] = parseAssignment(state);
|
8624 | len++;
|
8625 | }
|
8626 |
|
8627 | return new ArrayNode(params);
|
8628 | }
|
8629 | |
8630 |
|
8631 |
|
8632 |
|
8633 |
|
8634 |
|
8635 |
|
8636 | function parseObject(state) {
|
8637 | if (state.token === '{') {
|
8638 | openParams(state);
|
8639 | var key;
|
8640 | var properties = {};
|
8641 |
|
8642 | do {
|
8643 | getToken(state);
|
8644 |
|
8645 | if (state.token !== '}') {
|
8646 |
|
8647 | if (state.token === '"') {
|
8648 | key = parseDoubleQuotesStringToken(state);
|
8649 | } else if (state.token === '\'') {
|
8650 | key = parseSingleQuotesStringToken(state);
|
8651 | } else if (state.tokenType === TOKENTYPE.SYMBOL) {
|
8652 | key = state.token;
|
8653 | getToken(state);
|
8654 | } else {
|
8655 | throw createSyntaxError(state, 'Symbol or string expected as object key');
|
8656 | }
|
8657 |
|
8658 |
|
8659 | if (state.token !== ':') {
|
8660 | throw createSyntaxError(state, 'Colon : expected after object key');
|
8661 | }
|
8662 |
|
8663 | getToken(state);
|
8664 |
|
8665 | properties[key] = parseAssignment(state);
|
8666 | }
|
8667 | } while (state.token === ',');
|
8668 |
|
8669 |
|
8670 | if (state.token !== '}') {
|
8671 | throw createSyntaxError(state, 'Comma , or bracket } expected after object value');
|
8672 | }
|
8673 |
|
8674 | closeParams(state);
|
8675 | getToken(state);
|
8676 | var node = new ObjectNode(properties);
|
8677 |
|
8678 | node = parseAccessors(state, node);
|
8679 | return node;
|
8680 | }
|
8681 |
|
8682 | return parseNumber(state);
|
8683 | }
|
8684 | |
8685 |
|
8686 |
|
8687 |
|
8688 |
|
8689 |
|
8690 |
|
8691 | function parseNumber(state) {
|
8692 | var numberStr;
|
8693 |
|
8694 | if (state.tokenType === TOKENTYPE.NUMBER) {
|
8695 |
|
8696 | numberStr = state.token;
|
8697 | getToken(state);
|
8698 | return new ConstantNode(numeric(numberStr, config.number));
|
8699 | }
|
8700 |
|
8701 | return parseParentheses(state);
|
8702 | }
|
8703 | |
8704 |
|
8705 |
|
8706 |
|
8707 |
|
8708 |
|
8709 |
|
8710 | function parseParentheses(state) {
|
8711 | var node;
|
8712 |
|
8713 | if (state.token === '(') {
|
8714 |
|
8715 | openParams(state);
|
8716 | getToken(state);
|
8717 | node = parseAssignment(state);
|
8718 |
|
8719 | if (state.token !== ')') {
|
8720 | throw createSyntaxError(state, 'Parenthesis ) expected');
|
8721 | }
|
8722 |
|
8723 | closeParams(state);
|
8724 | getToken(state);
|
8725 | node = new ParenthesisNode(node);
|
8726 | node = parseAccessors(state, node);
|
8727 | return node;
|
8728 | }
|
8729 |
|
8730 | return parseEnd(state);
|
8731 | }
|
8732 | |
8733 |
|
8734 |
|
8735 |
|
8736 |
|
8737 |
|
8738 |
|
8739 | function parseEnd(state) {
|
8740 | if (state.token === '') {
|
8741 |
|
8742 | throw createSyntaxError(state, 'Unexpected end of expression');
|
8743 | } else {
|
8744 | throw createSyntaxError(state, 'Value expected');
|
8745 | }
|
8746 | }
|
8747 | |
8748 |
|
8749 |
|
8750 |
|
8751 |
|
8752 |
|
8753 | |
8754 |
|
8755 |
|
8756 |
|
8757 |
|
8758 |
|
8759 | |
8760 |
|
8761 |
|
8762 |
|
8763 |
|
8764 |
|
8765 |
|
8766 | function col(state) {
|
8767 | return state.index - state.token.length + 1;
|
8768 | }
|
8769 | |
8770 |
|
8771 |
|
8772 |
|
8773 |
|
8774 |
|
8775 |
|
8776 |
|
8777 | function createSyntaxError(state, message) {
|
8778 | var c = col(state);
|
8779 | var error = new SyntaxError(message + ' (char ' + c + ')');
|
8780 | error['char'] = c;
|
8781 | return error;
|
8782 | }
|
8783 | |
8784 |
|
8785 |
|
8786 |
|
8787 |
|
8788 |
|
8789 |
|
8790 |
|
8791 | function createError(state, message) {
|
8792 | var c = col(state);
|
8793 | var error = new SyntaxError(message + ' (char ' + c + ')');
|
8794 | error['char'] = c;
|
8795 | return error;
|
8796 | }
|
8797 |
|
8798 | return parse;
|
8799 | }
|
8800 |
|
8801 | exports.name = 'parse';
|
8802 | exports.path = 'expression';
|
8803 | exports.factory = factory;
|
8804 |
|
8805 | }),
|
8806 |
|
8807 | (function(module, exports, __webpack_require__) {
|
8808 |
|
8809 | "use strict";
|
8810 |
|
8811 |
|
8812 | var extend = __webpack_require__(5).extend;
|
8813 |
|
8814 | function factory(type, config, load, typed) {
|
8815 | var divideScalar = load(__webpack_require__(12));
|
8816 | var multiply = load(__webpack_require__(10));
|
8817 | var inv = load(__webpack_require__(70));
|
8818 | var matrix = load(__webpack_require__(0));
|
8819 | var algorithm11 = load(__webpack_require__(20));
|
8820 | var algorithm14 = load(__webpack_require__(6));
|
8821 | |
8822 |
|
8823 |
|
8824 |
|
8825 |
|
8826 |
|
8827 |
|
8828 |
|
8829 |
|
8830 |
|
8831 |
|
8832 |
|
8833 |
|
8834 |
|
8835 |
|
8836 |
|
8837 |
|
8838 |
|
8839 |
|
8840 |
|
8841 |
|
8842 |
|
8843 |
|
8844 |
|
8845 |
|
8846 |
|
8847 |
|
8848 |
|
8849 |
|
8850 |
|
8851 |
|
8852 |
|
8853 | var divide = typed('divide', extend({
|
8854 |
|
8855 | 'Array | Matrix, Array | Matrix': function ArrayMatrixArrayMatrix(x, y) {
|
8856 |
|
8857 |
|
8858 |
|
8859 |
|
8860 | return multiply(x, inv(y));
|
8861 | },
|
8862 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
8863 | return algorithm14(x, y, divideScalar, false);
|
8864 | },
|
8865 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
8866 | return algorithm11(x, y, divideScalar, false);
|
8867 | },
|
8868 | 'Array, any': function ArrayAny(x, y) {
|
8869 |
|
8870 | return algorithm14(matrix(x), y, divideScalar, false).valueOf();
|
8871 | },
|
8872 | 'any, Array | Matrix': function anyArrayMatrix(x, y) {
|
8873 | return multiply(x, inv(y));
|
8874 | }
|
8875 | }, divideScalar.signatures));
|
8876 | divide.toTex = {
|
8877 | 2: "\\frac{${args[0]}}{${args[1]}}"
|
8878 | };
|
8879 | return divide;
|
8880 | }
|
8881 |
|
8882 | exports.name = 'divide';
|
8883 | exports.factory = factory;
|
8884 |
|
8885 | }),
|
8886 |
|
8887 | (function(module, exports, __webpack_require__) {
|
8888 |
|
8889 | "use strict";
|
8890 |
|
8891 |
|
8892 | var deepMap = __webpack_require__(1);
|
8893 |
|
8894 | function factory(type, config, load, typed) {
|
8895 | |
8896 |
|
8897 |
|
8898 |
|
8899 |
|
8900 |
|
8901 |
|
8902 |
|
8903 |
|
8904 |
|
8905 |
|
8906 |
|
8907 |
|
8908 |
|
8909 |
|
8910 |
|
8911 |
|
8912 |
|
8913 |
|
8914 |
|
8915 |
|
8916 |
|
8917 |
|
8918 |
|
8919 | var sqrt = typed('sqrt', {
|
8920 | 'number': _sqrtNumber,
|
8921 | 'Complex': function Complex(x) {
|
8922 | return x.sqrt();
|
8923 | },
|
8924 | 'BigNumber': function BigNumber(x) {
|
8925 | if (!x.isNegative() || config.predictable) {
|
8926 | return x.sqrt();
|
8927 | } else {
|
8928 |
|
8929 | return _sqrtNumber(x.toNumber());
|
8930 | }
|
8931 | },
|
8932 | 'Array | Matrix': function ArrayMatrix(x) {
|
8933 |
|
8934 | return deepMap(x, sqrt, true);
|
8935 | },
|
8936 | 'Unit': function Unit(x) {
|
8937 |
|
8938 | return x.pow(0.5);
|
8939 | }
|
8940 | });
|
8941 | |
8942 |
|
8943 |
|
8944 |
|
8945 |
|
8946 |
|
8947 |
|
8948 | function _sqrtNumber(x) {
|
8949 | if (isNaN(x)) {
|
8950 | return NaN;
|
8951 | } else if (x >= 0 || config.predictable) {
|
8952 | return Math.sqrt(x);
|
8953 | } else {
|
8954 | return new type.Complex(x, 0).sqrt();
|
8955 | }
|
8956 | }
|
8957 |
|
8958 | sqrt.toTex = {
|
8959 | 1: "\\sqrt{${args[0]}}"
|
8960 | };
|
8961 | return sqrt;
|
8962 | }
|
8963 |
|
8964 | exports.name = 'sqrt';
|
8965 | exports.factory = factory;
|
8966 |
|
8967 | }),
|
8968 |
|
8969 | (function(module, exports, __webpack_require__) {
|
8970 |
|
8971 | "use strict";
|
8972 |
|
8973 |
|
8974 | var isMatrix = __webpack_require__(56);
|
8975 |
|
8976 |
|
8977 |
|
8978 |
|
8979 |
|
8980 |
|
8981 |
|
8982 |
|
8983 |
|
8984 | module.exports = function deepForEach(array, callback) {
|
8985 | if (isMatrix(array)) {
|
8986 | array = array.valueOf();
|
8987 | }
|
8988 |
|
8989 | for (var i = 0, ii = array.length; i < ii; i++) {
|
8990 | var value = array[i];
|
8991 |
|
8992 | if (Array.isArray(value)) {
|
8993 | deepForEach(value, callback);
|
8994 | } else {
|
8995 | callback(value);
|
8996 | }
|
8997 | }
|
8998 | };
|
8999 |
|
9000 | }),
|
9001 |
|
9002 | (function(module, exports, __webpack_require__) {
|
9003 |
|
9004 | "use strict";
|
9005 |
|
9006 |
|
9007 |
|
9008 |
|
9009 |
|
9010 |
|
9011 |
|
9012 |
|
9013 |
|
9014 |
|
9015 |
|
9016 |
|
9017 | function IndexError(index, min, max) {
|
9018 | if (!(this instanceof IndexError)) {
|
9019 | throw new SyntaxError('Constructor must be called with the new operator');
|
9020 | }
|
9021 |
|
9022 | this.index = index;
|
9023 |
|
9024 | if (arguments.length < 3) {
|
9025 | this.min = 0;
|
9026 | this.max = min;
|
9027 | } else {
|
9028 | this.min = min;
|
9029 | this.max = max;
|
9030 | }
|
9031 |
|
9032 | if (this.min !== undefined && this.index < this.min) {
|
9033 | this.message = 'Index out of range (' + this.index + ' < ' + this.min + ')';
|
9034 | } else if (this.max !== undefined && this.index >= this.max) {
|
9035 | this.message = 'Index out of range (' + this.index + ' > ' + (this.max - 1) + ')';
|
9036 | } else {
|
9037 | this.message = 'Index out of range (' + this.index + ')';
|
9038 | }
|
9039 |
|
9040 | this.stack = new Error().stack;
|
9041 | }
|
9042 |
|
9043 | IndexError.prototype = new RangeError();
|
9044 | IndexError.prototype.constructor = RangeError;
|
9045 | IndexError.prototype.name = 'IndexError';
|
9046 | IndexError.prototype.isIndexError = true;
|
9047 | module.exports = IndexError;
|
9048 |
|
9049 | }),
|
9050 |
|
9051 | (function(module, exports, __webpack_require__) {
|
9052 |
|
9053 | "use strict";
|
9054 |
|
9055 |
|
9056 | var util = __webpack_require__(31);
|
9057 |
|
9058 | var DimensionError = __webpack_require__(8);
|
9059 |
|
9060 | var string = util.string;
|
9061 | var array = util.array;
|
9062 | var object = util.object;
|
9063 | var number = util.number;
|
9064 | var isArray = Array.isArray;
|
9065 | var isNumber = number.isNumber;
|
9066 | var isInteger = number.isInteger;
|
9067 | var isString = string.isString;
|
9068 | var validateIndex = array.validateIndex;
|
9069 |
|
9070 | function factory(type, config, load, typed) {
|
9071 | var getArrayDataType = load(__webpack_require__(63));
|
9072 | var Matrix = load(__webpack_require__(84));
|
9073 |
|
9074 | |
9075 |
|
9076 |
|
9077 |
|
9078 |
|
9079 | function DenseMatrix(data, datatype) {
|
9080 | if (!(this instanceof DenseMatrix)) {
|
9081 | throw new SyntaxError('Constructor must be called with the new operator');
|
9082 | }
|
9083 |
|
9084 | if (datatype && !isString(datatype)) {
|
9085 | throw new Error('Invalid datatype: ' + datatype);
|
9086 | }
|
9087 |
|
9088 | if (type.isMatrix(data)) {
|
9089 |
|
9090 | if (data.type === 'DenseMatrix') {
|
9091 |
|
9092 | this._data = object.clone(data._data);
|
9093 | this._size = object.clone(data._size);
|
9094 | this._datatype = datatype || data._datatype;
|
9095 | } else {
|
9096 |
|
9097 | this._data = data.toArray();
|
9098 | this._size = data.size();
|
9099 | this._datatype = datatype || data._datatype;
|
9100 | }
|
9101 | } else if (data && isArray(data.data) && isArray(data.size)) {
|
9102 |
|
9103 | this._data = data.data;
|
9104 | this._size = data.size;
|
9105 | this._datatype = datatype || data.datatype;
|
9106 | } else if (isArray(data)) {
|
9107 |
|
9108 | this._data = preprocess(data);
|
9109 |
|
9110 | this._size = array.size(this._data);
|
9111 |
|
9112 | array.validate(this._data, this._size);
|
9113 |
|
9114 | this._datatype = datatype;
|
9115 | } else if (data) {
|
9116 |
|
9117 | throw new TypeError('Unsupported type of data (' + util.types.type(data) + ')');
|
9118 | } else {
|
9119 |
|
9120 | this._data = [];
|
9121 | this._size = [0];
|
9122 | this._datatype = datatype;
|
9123 | }
|
9124 | }
|
9125 |
|
9126 | DenseMatrix.prototype = new Matrix();
|
9127 | |
9128 |
|
9129 |
|
9130 |
|
9131 | DenseMatrix.prototype.type = 'DenseMatrix';
|
9132 | DenseMatrix.prototype.isDenseMatrix = true;
|
9133 | |
9134 |
|
9135 |
|
9136 |
|
9137 |
|
9138 |
|
9139 |
|
9140 |
|
9141 |
|
9142 |
|
9143 | DenseMatrix.prototype.getDataType = function () {
|
9144 | return getArrayDataType(this._data);
|
9145 | };
|
9146 | |
9147 |
|
9148 |
|
9149 |
|
9150 |
|
9151 |
|
9152 |
|
9153 |
|
9154 |
|
9155 |
|
9156 |
|
9157 | DenseMatrix.prototype.storage = function () {
|
9158 | return 'dense';
|
9159 | };
|
9160 | |
9161 |
|
9162 |
|
9163 |
|
9164 |
|
9165 |
|
9166 |
|
9167 |
|
9168 |
|
9169 |
|
9170 |
|
9171 | DenseMatrix.prototype.datatype = function () {
|
9172 | return this._datatype;
|
9173 | };
|
9174 | |
9175 |
|
9176 |
|
9177 |
|
9178 |
|
9179 |
|
9180 |
|
9181 |
|
9182 | DenseMatrix.prototype.create = function (data, datatype) {
|
9183 | return new DenseMatrix(data, datatype);
|
9184 | };
|
9185 | |
9186 |
|
9187 |
|
9188 |
|
9189 |
|
9190 |
|
9191 |
|
9192 |
|
9193 |
|
9194 |
|
9195 |
|
9196 |
|
9197 |
|
9198 |
|
9199 |
|
9200 |
|
9201 | DenseMatrix.prototype.subset = function (index, replacement, defaultValue) {
|
9202 | switch (arguments.length) {
|
9203 | case 1:
|
9204 | return _get(this, index);
|
9205 |
|
9206 |
|
9207 | case 2:
|
9208 | case 3:
|
9209 | return _set(this, index, replacement, defaultValue);
|
9210 |
|
9211 | default:
|
9212 | throw new SyntaxError('Wrong number of arguments');
|
9213 | }
|
9214 | };
|
9215 | |
9216 |
|
9217 |
|
9218 |
|
9219 |
|
9220 |
|
9221 |
|
9222 |
|
9223 | DenseMatrix.prototype.get = function (index) {
|
9224 | if (!isArray(index)) {
|
9225 | throw new TypeError('Array expected');
|
9226 | }
|
9227 |
|
9228 | if (index.length !== this._size.length) {
|
9229 | throw new DimensionError(index.length, this._size.length);
|
9230 | }
|
9231 |
|
9232 |
|
9233 | for (var x = 0; x < index.length; x++) {
|
9234 | validateIndex(index[x], this._size[x]);
|
9235 | }
|
9236 |
|
9237 | var data = this._data;
|
9238 |
|
9239 | for (var i = 0, ii = index.length; i < ii; i++) {
|
9240 | var indexI = index[i];
|
9241 | validateIndex(indexI, data.length);
|
9242 | data = data[indexI];
|
9243 | }
|
9244 |
|
9245 | return data;
|
9246 | };
|
9247 | |
9248 |
|
9249 |
|
9250 |
|
9251 |
|
9252 |
|
9253 |
|
9254 |
|
9255 |
|
9256 |
|
9257 |
|
9258 |
|
9259 | DenseMatrix.prototype.set = function (index, value, defaultValue) {
|
9260 | if (!isArray(index)) {
|
9261 | throw new TypeError('Array expected');
|
9262 | }
|
9263 |
|
9264 | if (index.length < this._size.length) {
|
9265 | throw new DimensionError(index.length, this._size.length, '<');
|
9266 | }
|
9267 |
|
9268 | var i, ii, indexI;
|
9269 |
|
9270 | var size = index.map(function (i) {
|
9271 | return i + 1;
|
9272 | });
|
9273 |
|
9274 | _fit(this, size, defaultValue);
|
9275 |
|
9276 |
|
9277 | var data = this._data;
|
9278 |
|
9279 | for (i = 0, ii = index.length - 1; i < ii; i++) {
|
9280 | indexI = index[i];
|
9281 | validateIndex(indexI, data.length);
|
9282 | data = data[indexI];
|
9283 | }
|
9284 |
|
9285 |
|
9286 | indexI = index[index.length - 1];
|
9287 | validateIndex(indexI, data.length);
|
9288 | data[indexI] = value;
|
9289 | return this;
|
9290 | };
|
9291 | |
9292 |
|
9293 |
|
9294 |
|
9295 |
|
9296 |
|
9297 |
|
9298 |
|
9299 |
|
9300 | function _get(matrix, index) {
|
9301 | if (!type.isIndex(index)) {
|
9302 | throw new TypeError('Invalid index');
|
9303 | }
|
9304 |
|
9305 | var isScalar = index.isScalar();
|
9306 |
|
9307 | if (isScalar) {
|
9308 |
|
9309 | return matrix.get(index.min());
|
9310 | } else {
|
9311 |
|
9312 | var size = index.size();
|
9313 |
|
9314 | if (size.length !== matrix._size.length) {
|
9315 | throw new DimensionError(size.length, matrix._size.length);
|
9316 | }
|
9317 |
|
9318 |
|
9319 | var min = index.min();
|
9320 | var max = index.max();
|
9321 |
|
9322 | for (var i = 0, ii = matrix._size.length; i < ii; i++) {
|
9323 | validateIndex(min[i], matrix._size[i]);
|
9324 | validateIndex(max[i], matrix._size[i]);
|
9325 | }
|
9326 |
|
9327 |
|
9328 |
|
9329 | return new DenseMatrix(_getSubmatrix(matrix._data, index, size.length, 0), matrix._datatype);
|
9330 | }
|
9331 | }
|
9332 | |
9333 |
|
9334 |
|
9335 |
|
9336 |
|
9337 |
|
9338 |
|
9339 |
|
9340 |
|
9341 |
|
9342 |
|
9343 |
|
9344 |
|
9345 | function _getSubmatrix(data, index, dims, dim) {
|
9346 | var last = dim === dims - 1;
|
9347 | var range = index.dimension(dim);
|
9348 |
|
9349 | if (last) {
|
9350 | return range.map(function (i) {
|
9351 | validateIndex(i, data.length);
|
9352 | return data[i];
|
9353 | }).valueOf();
|
9354 | } else {
|
9355 | return range.map(function (i) {
|
9356 | validateIndex(i, data.length);
|
9357 | var child = data[i];
|
9358 | return _getSubmatrix(child, index, dims, dim + 1);
|
9359 | }).valueOf();
|
9360 | }
|
9361 | }
|
9362 | |
9363 |
|
9364 |
|
9365 |
|
9366 |
|
9367 |
|
9368 |
|
9369 |
|
9370 |
|
9371 |
|
9372 |
|
9373 |
|
9374 |
|
9375 |
|
9376 | function _set(matrix, index, submatrix, defaultValue) {
|
9377 | if (!index || index.isIndex !== true) {
|
9378 | throw new TypeError('Invalid index');
|
9379 | }
|
9380 |
|
9381 |
|
9382 | var iSize = index.size();
|
9383 | var isScalar = index.isScalar();
|
9384 |
|
9385 | var sSize;
|
9386 |
|
9387 | if (type.isMatrix(submatrix)) {
|
9388 | sSize = submatrix.size();
|
9389 | submatrix = submatrix.valueOf();
|
9390 | } else {
|
9391 | sSize = array.size(submatrix);
|
9392 | }
|
9393 |
|
9394 | if (isScalar) {
|
9395 |
|
9396 |
|
9397 | if (sSize.length !== 0) {
|
9398 | throw new TypeError('Scalar expected');
|
9399 | }
|
9400 |
|
9401 | matrix.set(index.min(), submatrix, defaultValue);
|
9402 | } else {
|
9403 |
|
9404 |
|
9405 | if (iSize.length < matrix._size.length) {
|
9406 | throw new DimensionError(iSize.length, matrix._size.length, '<');
|
9407 | }
|
9408 |
|
9409 | if (sSize.length < iSize.length) {
|
9410 |
|
9411 | var i = 0;
|
9412 | var outer = 0;
|
9413 |
|
9414 | while (iSize[i] === 1 && sSize[i] === 1) {
|
9415 | i++;
|
9416 | }
|
9417 |
|
9418 | while (iSize[i] === 1) {
|
9419 | outer++;
|
9420 | i++;
|
9421 | }
|
9422 |
|
9423 |
|
9424 | submatrix = array.unsqueeze(submatrix, iSize.length, outer, sSize);
|
9425 | }
|
9426 |
|
9427 |
|
9428 | if (!object.deepEqual(iSize, sSize)) {
|
9429 | throw new DimensionError(iSize, sSize, '>');
|
9430 | }
|
9431 |
|
9432 |
|
9433 | var size = index.max().map(function (i) {
|
9434 | return i + 1;
|
9435 | });
|
9436 |
|
9437 | _fit(matrix, size, defaultValue);
|
9438 |
|
9439 |
|
9440 | var dims = iSize.length;
|
9441 | var dim = 0;
|
9442 |
|
9443 | _setSubmatrix(matrix._data, index, submatrix, dims, dim);
|
9444 | }
|
9445 |
|
9446 | return matrix;
|
9447 | }
|
9448 | |
9449 |
|
9450 |
|
9451 |
|
9452 |
|
9453 |
|
9454 |
|
9455 |
|
9456 |
|
9457 |
|
9458 |
|
9459 |
|
9460 | function _setSubmatrix(data, index, submatrix, dims, dim) {
|
9461 | var last = dim === dims - 1;
|
9462 | var range = index.dimension(dim);
|
9463 |
|
9464 | if (last) {
|
9465 | range.forEach(function (dataIndex, subIndex) {
|
9466 | validateIndex(dataIndex);
|
9467 | data[dataIndex] = submatrix[subIndex[0]];
|
9468 | });
|
9469 | } else {
|
9470 | range.forEach(function (dataIndex, subIndex) {
|
9471 | validateIndex(dataIndex);
|
9472 |
|
9473 | _setSubmatrix(data[dataIndex], index, submatrix[subIndex[0]], dims, dim + 1);
|
9474 | });
|
9475 | }
|
9476 | }
|
9477 | |
9478 |
|
9479 |
|
9480 |
|
9481 |
|
9482 |
|
9483 |
|
9484 |
|
9485 |
|
9486 |
|
9487 |
|
9488 |
|
9489 |
|
9490 |
|
9491 |
|
9492 | DenseMatrix.prototype.resize = function (size, defaultValue, copy) {
|
9493 |
|
9494 | if (!isArray(size)) {
|
9495 | throw new TypeError('Array expected');
|
9496 | }
|
9497 |
|
9498 |
|
9499 | var m = copy ? this.clone() : this;
|
9500 |
|
9501 | return _resize(m, size, defaultValue);
|
9502 | };
|
9503 |
|
9504 | function _resize(matrix, size, defaultValue) {
|
9505 |
|
9506 | if (size.length === 0) {
|
9507 |
|
9508 | var v = matrix._data;
|
9509 |
|
9510 | while (isArray(v)) {
|
9511 | v = v[0];
|
9512 | }
|
9513 |
|
9514 | return v;
|
9515 | }
|
9516 |
|
9517 |
|
9518 | matrix._size = size.slice(0);
|
9519 |
|
9520 | matrix._data = array.resize(matrix._data, matrix._size, defaultValue);
|
9521 |
|
9522 | return matrix;
|
9523 | }
|
9524 | |
9525 |
|
9526 |
|
9527 |
|
9528 |
|
9529 |
|
9530 |
|
9531 |
|
9532 |
|
9533 |
|
9534 |
|
9535 |
|
9536 |
|
9537 |
|
9538 |
|
9539 |
|
9540 | DenseMatrix.prototype.reshape = function (size, copy) {
|
9541 | var m = copy ? this.clone() : this;
|
9542 | m._data = array.reshape(m._data, size);
|
9543 | m._size = size.slice(0);
|
9544 | return m;
|
9545 | };
|
9546 | |
9547 |
|
9548 |
|
9549 |
|
9550 |
|
9551 |
|
9552 |
|
9553 |
|
9554 |
|
9555 |
|
9556 |
|
9557 | function _fit(matrix, size, defaultValue) {
|
9558 | var
|
9559 | newSize = matrix._size.slice(0);
|
9560 |
|
9561 | var changed = false;
|
9562 |
|
9563 | while (newSize.length < size.length) {
|
9564 | newSize.push(0);
|
9565 | changed = true;
|
9566 | }
|
9567 |
|
9568 |
|
9569 | for (var i = 0, ii = size.length; i < ii; i++) {
|
9570 | if (size[i] > newSize[i]) {
|
9571 | newSize[i] = size[i];
|
9572 | changed = true;
|
9573 | }
|
9574 | }
|
9575 |
|
9576 | if (changed) {
|
9577 |
|
9578 | _resize(matrix, newSize, defaultValue);
|
9579 | }
|
9580 | }
|
9581 | |
9582 |
|
9583 |
|
9584 |
|
9585 |
|
9586 |
|
9587 |
|
9588 | DenseMatrix.prototype.clone = function () {
|
9589 | var m = new DenseMatrix({
|
9590 | data: object.clone(this._data),
|
9591 | size: object.clone(this._size),
|
9592 | datatype: this._datatype
|
9593 | });
|
9594 | return m;
|
9595 | };
|
9596 | |
9597 |
|
9598 |
|
9599 |
|
9600 |
|
9601 |
|
9602 |
|
9603 | DenseMatrix.prototype.size = function () {
|
9604 | return this._size.slice(0);
|
9605 | };
|
9606 | |
9607 |
|
9608 |
|
9609 |
|
9610 |
|
9611 |
|
9612 |
|
9613 |
|
9614 |
|
9615 |
|
9616 |
|
9617 |
|
9618 | DenseMatrix.prototype.map = function (callback) {
|
9619 |
|
9620 | var me = this;
|
9621 |
|
9622 | var recurse = function recurse(value, index) {
|
9623 | if (isArray(value)) {
|
9624 | return value.map(function (child, i) {
|
9625 | return recurse(child, index.concat(i));
|
9626 | });
|
9627 | } else {
|
9628 | return callback(value, index, me);
|
9629 | }
|
9630 | };
|
9631 |
|
9632 |
|
9633 | return new DenseMatrix({
|
9634 | data: recurse(this._data, []),
|
9635 | size: object.clone(this._size),
|
9636 | datatype: this._datatype
|
9637 | });
|
9638 | };
|
9639 | |
9640 |
|
9641 |
|
9642 |
|
9643 |
|
9644 |
|
9645 |
|
9646 |
|
9647 |
|
9648 | DenseMatrix.prototype.forEach = function (callback) {
|
9649 |
|
9650 | var me = this;
|
9651 |
|
9652 | var recurse = function recurse(value, index) {
|
9653 | if (isArray(value)) {
|
9654 | value.forEach(function (child, i) {
|
9655 | recurse(child, index.concat(i));
|
9656 | });
|
9657 | } else {
|
9658 | callback(value, index, me);
|
9659 | }
|
9660 | };
|
9661 |
|
9662 | recurse(this._data, []);
|
9663 | };
|
9664 | |
9665 |
|
9666 |
|
9667 |
|
9668 |
|
9669 |
|
9670 |
|
9671 | DenseMatrix.prototype.toArray = function () {
|
9672 | return object.clone(this._data);
|
9673 | };
|
9674 | |
9675 |
|
9676 |
|
9677 |
|
9678 |
|
9679 |
|
9680 |
|
9681 | DenseMatrix.prototype.valueOf = function () {
|
9682 | return this._data;
|
9683 | };
|
9684 | |
9685 |
|
9686 |
|
9687 |
|
9688 |
|
9689 |
|
9690 |
|
9691 |
|
9692 |
|
9693 |
|
9694 |
|
9695 | DenseMatrix.prototype.format = function (options) {
|
9696 | return string.format(this._data, options);
|
9697 | };
|
9698 | |
9699 |
|
9700 |
|
9701 |
|
9702 |
|
9703 |
|
9704 |
|
9705 | DenseMatrix.prototype.toString = function () {
|
9706 | return string.format(this._data);
|
9707 | };
|
9708 | |
9709 |
|
9710 |
|
9711 |
|
9712 |
|
9713 |
|
9714 |
|
9715 | DenseMatrix.prototype.toJSON = function () {
|
9716 | return {
|
9717 | mathjs: 'DenseMatrix',
|
9718 | data: this._data,
|
9719 | size: this._size,
|
9720 | datatype: this._datatype
|
9721 | };
|
9722 | };
|
9723 | |
9724 |
|
9725 |
|
9726 |
|
9727 |
|
9728 |
|
9729 |
|
9730 |
|
9731 |
|
9732 |
|
9733 | DenseMatrix.prototype.diagonal = function (k) {
|
9734 |
|
9735 | if (k) {
|
9736 |
|
9737 | if (type.isBigNumber(k)) {
|
9738 | k = k.toNumber();
|
9739 | }
|
9740 |
|
9741 |
|
9742 | if (!isNumber(k) || !isInteger(k)) {
|
9743 | throw new TypeError('The parameter k must be an integer number');
|
9744 | }
|
9745 | } else {
|
9746 |
|
9747 | k = 0;
|
9748 | }
|
9749 |
|
9750 | var kSuper = k > 0 ? k : 0;
|
9751 | var kSub = k < 0 ? -k : 0;
|
9752 |
|
9753 | var rows = this._size[0];
|
9754 | var columns = this._size[1];
|
9755 |
|
9756 | var n = Math.min(rows - kSub, columns - kSuper);
|
9757 |
|
9758 | var data = [];
|
9759 |
|
9760 | for (var i = 0; i < n; i++) {
|
9761 | data[i] = this._data[i + kSub][i + kSuper];
|
9762 | }
|
9763 |
|
9764 |
|
9765 | return new DenseMatrix({
|
9766 | data: data,
|
9767 | size: [n],
|
9768 | datatype: this._datatype
|
9769 | });
|
9770 | };
|
9771 | |
9772 |
|
9773 |
|
9774 |
|
9775 |
|
9776 |
|
9777 |
|
9778 |
|
9779 |
|
9780 |
|
9781 |
|
9782 |
|
9783 |
|
9784 |
|
9785 | DenseMatrix.diagonal = function (size, value, k, defaultValue, datatype) {
|
9786 | if (!isArray(size)) {
|
9787 | throw new TypeError('Array expected, size parameter');
|
9788 | }
|
9789 |
|
9790 | if (size.length !== 2) {
|
9791 | throw new Error('Only two dimensions matrix are supported');
|
9792 | }
|
9793 |
|
9794 |
|
9795 | size = size.map(function (s) {
|
9796 |
|
9797 | if (type.isBigNumber(s)) {
|
9798 |
|
9799 | s = s.toNumber();
|
9800 | }
|
9801 |
|
9802 |
|
9803 | if (!isNumber(s) || !isInteger(s) || s < 1) {
|
9804 | throw new Error('Size values must be positive integers');
|
9805 | }
|
9806 |
|
9807 | return s;
|
9808 | });
|
9809 |
|
9810 | if (k) {
|
9811 |
|
9812 | if (type.isBigNumber(k)) {
|
9813 | k = k.toNumber();
|
9814 | }
|
9815 |
|
9816 |
|
9817 | if (!isNumber(k) || !isInteger(k)) {
|
9818 | throw new TypeError('The parameter k must be an integer number');
|
9819 | }
|
9820 | } else {
|
9821 |
|
9822 | k = 0;
|
9823 | }
|
9824 |
|
9825 | if (defaultValue && isString(datatype)) {
|
9826 |
|
9827 | defaultValue = typed.convert(defaultValue, datatype);
|
9828 | }
|
9829 |
|
9830 | var kSuper = k > 0 ? k : 0;
|
9831 | var kSub = k < 0 ? -k : 0;
|
9832 |
|
9833 | var rows = size[0];
|
9834 | var columns = size[1];
|
9835 |
|
9836 | var n = Math.min(rows - kSub, columns - kSuper);
|
9837 |
|
9838 | var _value;
|
9839 |
|
9840 |
|
9841 | if (isArray(value)) {
|
9842 |
|
9843 | if (value.length !== n) {
|
9844 |
|
9845 | throw new Error('Invalid value array length');
|
9846 | }
|
9847 |
|
9848 |
|
9849 | _value = function _value(i) {
|
9850 |
|
9851 | return value[i];
|
9852 | };
|
9853 | } else if (type.isMatrix(value)) {
|
9854 |
|
9855 | var ms = value.size();
|
9856 |
|
9857 | if (ms.length !== 1 || ms[0] !== n) {
|
9858 |
|
9859 | throw new Error('Invalid matrix length');
|
9860 | }
|
9861 |
|
9862 |
|
9863 | _value = function _value(i) {
|
9864 |
|
9865 | return value.get([i]);
|
9866 | };
|
9867 | } else {
|
9868 |
|
9869 | _value = function _value() {
|
9870 |
|
9871 | return value;
|
9872 | };
|
9873 | }
|
9874 |
|
9875 |
|
9876 | if (!defaultValue) {
|
9877 |
|
9878 | defaultValue = type.isBigNumber(_value(0)) ? new type.BigNumber(0) : 0;
|
9879 | }
|
9880 |
|
9881 |
|
9882 | var data = [];
|
9883 |
|
9884 | if (size.length > 0) {
|
9885 |
|
9886 | data = array.resize(data, size, defaultValue);
|
9887 |
|
9888 | for (var d = 0; d < n; d++) {
|
9889 | data[d + kSub][d + kSuper] = _value(d);
|
9890 | }
|
9891 | }
|
9892 |
|
9893 |
|
9894 | return new DenseMatrix({
|
9895 | data: data,
|
9896 | size: [rows, columns]
|
9897 | });
|
9898 | };
|
9899 | |
9900 |
|
9901 |
|
9902 |
|
9903 |
|
9904 |
|
9905 |
|
9906 |
|
9907 |
|
9908 |
|
9909 | DenseMatrix.fromJSON = function (json) {
|
9910 | return new DenseMatrix(json);
|
9911 | };
|
9912 | |
9913 |
|
9914 |
|
9915 |
|
9916 |
|
9917 |
|
9918 |
|
9919 |
|
9920 |
|
9921 |
|
9922 |
|
9923 | DenseMatrix.prototype.swapRows = function (i, j) {
|
9924 |
|
9925 | if (!isNumber(i) || !isInteger(i) || !isNumber(j) || !isInteger(j)) {
|
9926 | throw new Error('Row index must be positive integers');
|
9927 | }
|
9928 |
|
9929 |
|
9930 | if (this._size.length !== 2) {
|
9931 | throw new Error('Only two dimensional matrix is supported');
|
9932 | }
|
9933 |
|
9934 |
|
9935 | validateIndex(i, this._size[0]);
|
9936 | validateIndex(j, this._size[0]);
|
9937 |
|
9938 | DenseMatrix._swapRows(i, j, this._data);
|
9939 |
|
9940 |
|
9941 | return this;
|
9942 | };
|
9943 | |
9944 |
|
9945 |
|
9946 |
|
9947 |
|
9948 |
|
9949 |
|
9950 |
|
9951 |
|
9952 | DenseMatrix._swapRows = function (i, j, data) {
|
9953 |
|
9954 | var vi = data[i];
|
9955 | data[i] = data[j];
|
9956 | data[j] = vi;
|
9957 | };
|
9958 | |
9959 |
|
9960 |
|
9961 |
|
9962 |
|
9963 |
|
9964 |
|
9965 |
|
9966 |
|
9967 | function preprocess(data) {
|
9968 | for (var i = 0, ii = data.length; i < ii; i++) {
|
9969 | var elem = data[i];
|
9970 |
|
9971 | if (isArray(elem)) {
|
9972 | data[i] = preprocess(elem);
|
9973 | } else if (elem && elem.isMatrix === true) {
|
9974 | data[i] = preprocess(elem.valueOf());
|
9975 | }
|
9976 | }
|
9977 |
|
9978 | return data;
|
9979 | }
|
9980 |
|
9981 |
|
9982 | type.Matrix._storage.dense = DenseMatrix;
|
9983 | type.Matrix._storage['default'] = DenseMatrix;
|
9984 |
|
9985 | return DenseMatrix;
|
9986 | }
|
9987 |
|
9988 | exports.name = 'DenseMatrix';
|
9989 | exports.path = 'type';
|
9990 | exports.factory = factory;
|
9991 | exports.lazy = false;
|
9992 |
|
9993 | }),
|
9994 |
|
9995 | (function(module, exports, __webpack_require__) {
|
9996 |
|
9997 | "use strict";
|
9998 |
|
9999 |
|
10000 | var array = __webpack_require__(2);
|
10001 |
|
10002 | var isInteger = __webpack_require__(3).isInteger;
|
10003 |
|
10004 | function factory(type, config, load, typed) {
|
10005 | var matrix = load(__webpack_require__(0));
|
10006 | |
10007 |
|
10008 |
|
10009 |
|
10010 |
|
10011 |
|
10012 |
|
10013 |
|
10014 |
|
10015 |
|
10016 |
|
10017 |
|
10018 |
|
10019 |
|
10020 |
|
10021 |
|
10022 |
|
10023 |
|
10024 |
|
10025 |
|
10026 |
|
10027 |
|
10028 |
|
10029 |
|
10030 |
|
10031 |
|
10032 |
|
10033 |
|
10034 |
|
10035 |
|
10036 |
|
10037 | var identity = typed('identity', {
|
10038 | '': function _() {
|
10039 | return config.matrix === 'Matrix' ? matrix([]) : [];
|
10040 | },
|
10041 | 'string': function string(format) {
|
10042 | return matrix(format);
|
10043 | },
|
10044 | 'number | BigNumber': function numberBigNumber(rows) {
|
10045 | return _identity(rows, rows, config.matrix === 'Matrix' ? 'default' : undefined);
|
10046 | },
|
10047 | 'number | BigNumber, string': function numberBigNumberString(rows, format) {
|
10048 | return _identity(rows, rows, format);
|
10049 | },
|
10050 | 'number | BigNumber, number | BigNumber': function numberBigNumberNumberBigNumber(rows, cols) {
|
10051 | return _identity(rows, cols, config.matrix === 'Matrix' ? 'default' : undefined);
|
10052 | },
|
10053 | 'number | BigNumber, number | BigNumber, string': function numberBigNumberNumberBigNumberString(rows, cols, format) {
|
10054 | return _identity(rows, cols, format);
|
10055 | },
|
10056 | 'Array': function Array(size) {
|
10057 | return _identityVector(size);
|
10058 | },
|
10059 | 'Array, string': function ArrayString(size, format) {
|
10060 | return _identityVector(size, format);
|
10061 | },
|
10062 | 'Matrix': function Matrix(size) {
|
10063 | return _identityVector(size.valueOf(), size.storage());
|
10064 | },
|
10065 | 'Matrix, string': function MatrixString(size, format) {
|
10066 | return _identityVector(size.valueOf(), format);
|
10067 | }
|
10068 | });
|
10069 | identity.toTex = undefined;
|
10070 |
|
10071 | return identity;
|
10072 |
|
10073 | function _identityVector(size, format) {
|
10074 | switch (size.length) {
|
10075 | case 0:
|
10076 | return format ? matrix(format) : [];
|
10077 |
|
10078 | case 1:
|
10079 | return _identity(size[0], size[0], format);
|
10080 |
|
10081 | case 2:
|
10082 | return _identity(size[0], size[1], format);
|
10083 |
|
10084 | default:
|
10085 | throw new Error('Vector containing two values expected');
|
10086 | }
|
10087 | }
|
10088 | |
10089 |
|
10090 |
|
10091 |
|
10092 |
|
10093 |
|
10094 |
|
10095 |
|
10096 |
|
10097 |
|
10098 | function _identity(rows, cols, format) {
|
10099 |
|
10100 | var Big = type.isBigNumber(rows) || type.isBigNumber(cols) ? type.BigNumber : null;
|
10101 | if (type.isBigNumber(rows)) rows = rows.toNumber();
|
10102 | if (type.isBigNumber(cols)) cols = cols.toNumber();
|
10103 |
|
10104 | if (!isInteger(rows) || rows < 1) {
|
10105 | throw new Error('Parameters in function identity must be positive integers');
|
10106 | }
|
10107 |
|
10108 | if (!isInteger(cols) || cols < 1) {
|
10109 | throw new Error('Parameters in function identity must be positive integers');
|
10110 | }
|
10111 |
|
10112 | var one = Big ? new type.BigNumber(1) : 1;
|
10113 | var defaultValue = Big ? new Big(0) : 0;
|
10114 | var size = [rows, cols];
|
10115 |
|
10116 | if (format) {
|
10117 |
|
10118 | var F = type.Matrix.storage(format);
|
10119 |
|
10120 | return F.diagonal(size, one, 0, defaultValue);
|
10121 | }
|
10122 |
|
10123 |
|
10124 | var res = array.resize([], size, defaultValue);
|
10125 |
|
10126 | var minimum = rows < cols ? rows : cols;
|
10127 |
|
10128 | for (var d = 0; d < minimum; d++) {
|
10129 | res[d][d] = one;
|
10130 | }
|
10131 |
|
10132 | return res;
|
10133 | }
|
10134 | }
|
10135 |
|
10136 | exports.name = 'identity';
|
10137 | exports.factory = factory;
|
10138 |
|
10139 | }),
|
10140 |
|
10141 | (function(module, exports, __webpack_require__) {
|
10142 |
|
10143 | "use strict";
|
10144 |
|
10145 |
|
10146 | function factory(type, config, load, typed) {
|
10147 | var matrix = load(__webpack_require__(0));
|
10148 | var equalScalar = load(__webpack_require__(11));
|
10149 | var algorithm03 = load(__webpack_require__(18));
|
10150 | var algorithm07 = load(__webpack_require__(29));
|
10151 | var algorithm12 = load(__webpack_require__(19));
|
10152 | var algorithm13 = load(__webpack_require__(7));
|
10153 | var algorithm14 = load(__webpack_require__(6));
|
10154 |
|
10155 | var latex = __webpack_require__(4);
|
10156 | |
10157 |
|
10158 |
|
10159 |
|
10160 |
|
10161 |
|
10162 |
|
10163 |
|
10164 |
|
10165 |
|
10166 |
|
10167 |
|
10168 |
|
10169 |
|
10170 |
|
10171 |
|
10172 |
|
10173 |
|
10174 |
|
10175 |
|
10176 |
|
10177 |
|
10178 |
|
10179 |
|
10180 |
|
10181 |
|
10182 |
|
10183 |
|
10184 |
|
10185 |
|
10186 |
|
10187 |
|
10188 |
|
10189 |
|
10190 |
|
10191 |
|
10192 |
|
10193 |
|
10194 |
|
10195 |
|
10196 |
|
10197 |
|
10198 |
|
10199 |
|
10200 |
|
10201 |
|
10202 | var equal = typed('equal', {
|
10203 | 'any, any': function anyAny(x, y) {
|
10204 |
|
10205 | if (x === null) {
|
10206 | return y === null;
|
10207 | }
|
10208 |
|
10209 | if (y === null) {
|
10210 | return x === null;
|
10211 | }
|
10212 |
|
10213 | if (x === undefined) {
|
10214 | return y === undefined;
|
10215 | }
|
10216 |
|
10217 | if (y === undefined) {
|
10218 | return x === undefined;
|
10219 | }
|
10220 |
|
10221 | return equalScalar(x, y);
|
10222 | },
|
10223 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
10224 | return algorithm07(x, y, equalScalar);
|
10225 | },
|
10226 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
10227 | return algorithm03(y, x, equalScalar, true);
|
10228 | },
|
10229 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
10230 | return algorithm03(x, y, equalScalar, false);
|
10231 | },
|
10232 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
10233 | return algorithm13(x, y, equalScalar);
|
10234 | },
|
10235 | 'Array, Array': function ArrayArray(x, y) {
|
10236 |
|
10237 | return equal(matrix(x), matrix(y)).valueOf();
|
10238 | },
|
10239 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
10240 |
|
10241 | return equal(matrix(x), y);
|
10242 | },
|
10243 | 'Matrix, Array': function MatrixArray(x, y) {
|
10244 |
|
10245 | return equal(x, matrix(y));
|
10246 | },
|
10247 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
10248 | return algorithm12(x, y, equalScalar, false);
|
10249 | },
|
10250 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
10251 | return algorithm14(x, y, equalScalar, false);
|
10252 | },
|
10253 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
10254 | return algorithm12(y, x, equalScalar, true);
|
10255 | },
|
10256 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
10257 | return algorithm14(y, x, equalScalar, true);
|
10258 | },
|
10259 | 'Array, any': function ArrayAny(x, y) {
|
10260 |
|
10261 | return algorithm14(matrix(x), y, equalScalar, false).valueOf();
|
10262 | },
|
10263 | 'any, Array': function anyArray(x, y) {
|
10264 |
|
10265 | return algorithm14(matrix(y), x, equalScalar, true).valueOf();
|
10266 | }
|
10267 | });
|
10268 | equal.toTex = {
|
10269 | 2: "\\left(${args[0]}".concat(latex.operators['equal'], "${args[1]}\\right)")
|
10270 | };
|
10271 | return equal;
|
10272 | }
|
10273 |
|
10274 | exports.name = 'equal';
|
10275 | exports.factory = factory;
|
10276 |
|
10277 | }),
|
10278 |
|
10279 | (function(module, exports, __webpack_require__) {
|
10280 |
|
10281 | "use strict";
|
10282 |
|
10283 |
|
10284 | var deepMap = __webpack_require__(1);
|
10285 |
|
10286 | function factory(type, config, load, typed) {
|
10287 | |
10288 |
|
10289 |
|
10290 |
|
10291 |
|
10292 |
|
10293 |
|
10294 |
|
10295 |
|
10296 |
|
10297 |
|
10298 |
|
10299 |
|
10300 |
|
10301 |
|
10302 |
|
10303 |
|
10304 |
|
10305 |
|
10306 |
|
10307 |
|
10308 |
|
10309 |
|
10310 |
|
10311 |
|
10312 |
|
10313 |
|
10314 |
|
10315 |
|
10316 | var isNumeric = typed('isNumeric', {
|
10317 | 'number | BigNumber | Fraction | boolean': function numberBigNumberFractionBoolean() {
|
10318 | return true;
|
10319 | },
|
10320 | 'Complex | Unit | string | null | undefined | Node': function ComplexUnitStringNullUndefinedNode() {
|
10321 | return false;
|
10322 | },
|
10323 | 'Array | Matrix': function ArrayMatrix(x) {
|
10324 | return deepMap(x, isNumeric);
|
10325 | }
|
10326 | });
|
10327 | return isNumeric;
|
10328 | }
|
10329 |
|
10330 | exports.name = 'isNumeric';
|
10331 | exports.factory = factory;
|
10332 |
|
10333 | }),
|
10334 |
|
10335 | (function(module, exports, __webpack_require__) {
|
10336 |
|
10337 | "use strict";
|
10338 |
|
10339 |
|
10340 |
|
10341 |
|
10342 |
|
10343 |
|
10344 |
|
10345 |
|
10346 |
|
10347 |
|
10348 |
|
10349 |
|
10350 |
|
10351 |
|
10352 |
|
10353 |
|
10354 |
|
10355 |
|
10356 |
|
10357 | var properties = [{
|
10358 |
|
10359 | 'AssignmentNode': {},
|
10360 | 'FunctionAssignmentNode': {}
|
10361 | }, {
|
10362 |
|
10363 | 'ConditionalNode': {
|
10364 | latexLeftParens: false,
|
10365 | latexRightParens: false,
|
10366 | latexParens: false
|
10367 |
|
10368 |
|
10369 | }
|
10370 | }, {
|
10371 |
|
10372 | 'OperatorNode:or': {
|
10373 | associativity: 'left',
|
10374 | associativeWith: []
|
10375 | }
|
10376 | }, {
|
10377 |
|
10378 | 'OperatorNode:xor': {
|
10379 | associativity: 'left',
|
10380 | associativeWith: []
|
10381 | }
|
10382 | }, {
|
10383 |
|
10384 | 'OperatorNode:and': {
|
10385 | associativity: 'left',
|
10386 | associativeWith: []
|
10387 | }
|
10388 | }, {
|
10389 |
|
10390 | 'OperatorNode:bitOr': {
|
10391 | associativity: 'left',
|
10392 | associativeWith: []
|
10393 | }
|
10394 | }, {
|
10395 |
|
10396 | 'OperatorNode:bitXor': {
|
10397 | associativity: 'left',
|
10398 | associativeWith: []
|
10399 | }
|
10400 | }, {
|
10401 |
|
10402 | 'OperatorNode:bitAnd': {
|
10403 | associativity: 'left',
|
10404 | associativeWith: []
|
10405 | }
|
10406 | }, {
|
10407 |
|
10408 | 'OperatorNode:equal': {
|
10409 | associativity: 'left',
|
10410 | associativeWith: []
|
10411 | },
|
10412 | 'OperatorNode:unequal': {
|
10413 | associativity: 'left',
|
10414 | associativeWith: []
|
10415 | },
|
10416 | 'OperatorNode:smaller': {
|
10417 | associativity: 'left',
|
10418 | associativeWith: []
|
10419 | },
|
10420 | 'OperatorNode:larger': {
|
10421 | associativity: 'left',
|
10422 | associativeWith: []
|
10423 | },
|
10424 | 'OperatorNode:smallerEq': {
|
10425 | associativity: 'left',
|
10426 | associativeWith: []
|
10427 | },
|
10428 | 'OperatorNode:largerEq': {
|
10429 | associativity: 'left',
|
10430 | associativeWith: []
|
10431 | },
|
10432 | 'RelationalNode': {
|
10433 | associativity: 'left',
|
10434 | associativeWith: []
|
10435 | }
|
10436 | }, {
|
10437 |
|
10438 | 'OperatorNode:leftShift': {
|
10439 | associativity: 'left',
|
10440 | associativeWith: []
|
10441 | },
|
10442 | 'OperatorNode:rightArithShift': {
|
10443 | associativity: 'left',
|
10444 | associativeWith: []
|
10445 | },
|
10446 | 'OperatorNode:rightLogShift': {
|
10447 | associativity: 'left',
|
10448 | associativeWith: []
|
10449 | }
|
10450 | }, {
|
10451 |
|
10452 | 'OperatorNode:to': {
|
10453 | associativity: 'left',
|
10454 | associativeWith: []
|
10455 | }
|
10456 | }, {
|
10457 |
|
10458 | 'RangeNode': {}
|
10459 | }, {
|
10460 |
|
10461 | 'OperatorNode:add': {
|
10462 | associativity: 'left',
|
10463 | associativeWith: ['OperatorNode:add', 'OperatorNode:subtract']
|
10464 | },
|
10465 | 'OperatorNode:subtract': {
|
10466 | associativity: 'left',
|
10467 | associativeWith: []
|
10468 | }
|
10469 | }, {
|
10470 |
|
10471 | 'OperatorNode:multiply': {
|
10472 | associativity: 'left',
|
10473 | associativeWith: ['OperatorNode:multiply', 'OperatorNode:divide', 'Operator:dotMultiply', 'Operator:dotDivide']
|
10474 | },
|
10475 | 'OperatorNode:divide': {
|
10476 | associativity: 'left',
|
10477 | associativeWith: [],
|
10478 | latexLeftParens: false,
|
10479 | latexRightParens: false,
|
10480 | latexParens: false
|
10481 |
|
10482 |
|
10483 |
|
10484 | },
|
10485 | 'OperatorNode:dotMultiply': {
|
10486 | associativity: 'left',
|
10487 | associativeWith: ['OperatorNode:multiply', 'OperatorNode:divide', 'OperatorNode:dotMultiply', 'OperatorNode:doDivide']
|
10488 | },
|
10489 | 'OperatorNode:dotDivide': {
|
10490 | associativity: 'left',
|
10491 | associativeWith: []
|
10492 | },
|
10493 | 'OperatorNode:mod': {
|
10494 | associativity: 'left',
|
10495 | associativeWith: []
|
10496 | }
|
10497 | }, {
|
10498 |
|
10499 | 'OperatorNode:unaryPlus': {
|
10500 | associativity: 'right'
|
10501 | },
|
10502 | 'OperatorNode:unaryMinus': {
|
10503 | associativity: 'right'
|
10504 | },
|
10505 | 'OperatorNode:bitNot': {
|
10506 | associativity: 'right'
|
10507 | },
|
10508 | 'OperatorNode:not': {
|
10509 | associativity: 'right'
|
10510 | }
|
10511 | }, {
|
10512 |
|
10513 | 'OperatorNode:pow': {
|
10514 | associativity: 'right',
|
10515 | associativeWith: [],
|
10516 | latexRightParens: false
|
10517 |
|
10518 |
|
10519 |
|
10520 | },
|
10521 | 'OperatorNode:dotPow': {
|
10522 | associativity: 'right',
|
10523 | associativeWith: []
|
10524 | }
|
10525 | }, {
|
10526 |
|
10527 | 'OperatorNode:factorial': {
|
10528 | associativity: 'left'
|
10529 | }
|
10530 | }, {
|
10531 |
|
10532 | 'OperatorNode:transpose': {
|
10533 | associativity: 'left'
|
10534 | }
|
10535 | }];
|
10536 |
|
10537 |
|
10538 |
|
10539 |
|
10540 |
|
10541 |
|
10542 |
|
10543 |
|
10544 |
|
10545 |
|
10546 | function getPrecedence(_node, parenthesis) {
|
10547 | var node = _node;
|
10548 |
|
10549 | if (parenthesis !== 'keep') {
|
10550 |
|
10551 | node = _node.getContent();
|
10552 | }
|
10553 |
|
10554 | var identifier = node.getIdentifier();
|
10555 |
|
10556 | for (var i = 0; i < properties.length; i++) {
|
10557 | if (identifier in properties[i]) {
|
10558 | return i;
|
10559 | }
|
10560 | }
|
10561 |
|
10562 | return null;
|
10563 | }
|
10564 |
|
10565 |
|
10566 |
|
10567 |
|
10568 |
|
10569 |
|
10570 |
|
10571 |
|
10572 |
|
10573 |
|
10574 |
|
10575 |
|
10576 | function getAssociativity(_node, parenthesis) {
|
10577 | var node = _node;
|
10578 |
|
10579 | if (parenthesis !== 'keep') {
|
10580 |
|
10581 | node = _node.getContent();
|
10582 | }
|
10583 |
|
10584 | var identifier = node.getIdentifier();
|
10585 | var index = getPrecedence(node, parenthesis);
|
10586 |
|
10587 | if (index === null) {
|
10588 |
|
10589 | return null;
|
10590 | }
|
10591 |
|
10592 | var property = properties[index][identifier];
|
10593 |
|
10594 | if (property.hasOwnProperty('associativity')) {
|
10595 | if (property.associativity === 'left') {
|
10596 | return 'left';
|
10597 | }
|
10598 |
|
10599 | if (property.associativity === 'right') {
|
10600 | return 'right';
|
10601 | }
|
10602 |
|
10603 |
|
10604 | throw Error('\'' + identifier + '\' has the invalid associativity \'' + property.associativity + '\'.');
|
10605 | }
|
10606 |
|
10607 |
|
10608 | return null;
|
10609 | }
|
10610 |
|
10611 |
|
10612 |
|
10613 |
|
10614 |
|
10615 |
|
10616 |
|
10617 |
|
10618 |
|
10619 |
|
10620 |
|
10621 | function isAssociativeWith(nodeA, nodeB, parenthesis) {
|
10622 |
|
10623 | var a = parenthesis !== 'keep' ? nodeA.getContent() : nodeA;
|
10624 | var b = parenthesis !== 'keep' ? nodeA.getContent() : nodeB;
|
10625 | var identifierA = a.getIdentifier();
|
10626 | var identifierB = b.getIdentifier();
|
10627 | var index = getPrecedence(a, parenthesis);
|
10628 |
|
10629 | if (index === null) {
|
10630 |
|
10631 | return null;
|
10632 | }
|
10633 |
|
10634 | var property = properties[index][identifierA];
|
10635 |
|
10636 | if (property.hasOwnProperty('associativeWith') && property.associativeWith instanceof Array) {
|
10637 | for (var i = 0; i < property.associativeWith.length; i++) {
|
10638 | if (property.associativeWith[i] === identifierB) {
|
10639 | return true;
|
10640 | }
|
10641 | }
|
10642 |
|
10643 | return false;
|
10644 | }
|
10645 |
|
10646 |
|
10647 | return null;
|
10648 | }
|
10649 |
|
10650 | module.exports.properties = properties;
|
10651 | module.exports.getPrecedence = getPrecedence;
|
10652 | module.exports.getAssociativity = getAssociativity;
|
10653 | module.exports.isAssociativeWith = isAssociativeWith;
|
10654 |
|
10655 | }),
|
10656 |
|
10657 | (function(module, exports, __webpack_require__) {
|
10658 |
|
10659 | "use strict";
|
10660 |
|
10661 |
|
10662 | var latex = __webpack_require__(4);
|
10663 |
|
10664 | var escape = __webpack_require__(9).escape;
|
10665 |
|
10666 | var hasOwnProperty = __webpack_require__(5).hasOwnProperty;
|
10667 |
|
10668 | var getSafeProperty = __webpack_require__(13).getSafeProperty;
|
10669 |
|
10670 | function factory(type, config, load, typed, math) {
|
10671 | var Node = load(__webpack_require__(16));
|
10672 | |
10673 |
|
10674 |
|
10675 |
|
10676 |
|
10677 |
|
10678 | function isValuelessUnit(name) {
|
10679 | return type.Unit ? type.Unit.isValuelessUnit(name) : false;
|
10680 | }
|
10681 | |
10682 |
|
10683 |
|
10684 |
|
10685 |
|
10686 |
|
10687 |
|
10688 |
|
10689 |
|
10690 | function SymbolNode(name) {
|
10691 | if (!(this instanceof SymbolNode)) {
|
10692 | throw new SyntaxError('Constructor must be called with the new operator');
|
10693 | }
|
10694 |
|
10695 |
|
10696 | if (typeof name !== 'string') throw new TypeError('String expected for parameter "name"');
|
10697 | this.name = name;
|
10698 | }
|
10699 |
|
10700 | SymbolNode.prototype = new Node();
|
10701 | SymbolNode.prototype.type = 'SymbolNode';
|
10702 | SymbolNode.prototype.isSymbolNode = true;
|
10703 | |
10704 |
|
10705 |
|
10706 |
|
10707 |
|
10708 |
|
10709 |
|
10710 |
|
10711 |
|
10712 |
|
10713 |
|
10714 |
|
10715 |
|
10716 |
|
10717 | SymbolNode.prototype._compile = function (math, argNames) {
|
10718 | var name = this.name;
|
10719 |
|
10720 | if (hasOwnProperty(argNames, name)) {
|
10721 |
|
10722 |
|
10723 | return function (scope, args, context) {
|
10724 | return args[name];
|
10725 | };
|
10726 | } else if (name in math) {
|
10727 | return function (scope, args, context) {
|
10728 | return name in scope ? getSafeProperty(scope, name) : getSafeProperty(math, name);
|
10729 | };
|
10730 | } else {
|
10731 | var isUnit = isValuelessUnit(name);
|
10732 | return function (scope, args, context) {
|
10733 | return name in scope ? getSafeProperty(scope, name) : isUnit ? new type.Unit(null, name) : undef(name);
|
10734 | };
|
10735 | }
|
10736 | };
|
10737 | |
10738 |
|
10739 |
|
10740 |
|
10741 |
|
10742 |
|
10743 | SymbolNode.prototype.forEach = function (callback) {}
|
10744 |
|
10745 | |
10746 |
|
10747 |
|
10748 |
|
10749 |
|
10750 |
|
10751 | ;
|
10752 |
|
10753 | SymbolNode.prototype.map = function (callback) {
|
10754 | return this.clone();
|
10755 | };
|
10756 | |
10757 |
|
10758 |
|
10759 |
|
10760 |
|
10761 |
|
10762 | function undef(name) {
|
10763 | throw new Error('Undefined symbol ' + name);
|
10764 | }
|
10765 | |
10766 |
|
10767 |
|
10768 |
|
10769 |
|
10770 |
|
10771 | SymbolNode.prototype.clone = function () {
|
10772 | return new SymbolNode(this.name);
|
10773 | };
|
10774 | |
10775 |
|
10776 |
|
10777 |
|
10778 |
|
10779 |
|
10780 |
|
10781 |
|
10782 | SymbolNode.prototype._toString = function (options) {
|
10783 | return this.name;
|
10784 | };
|
10785 | |
10786 |
|
10787 |
|
10788 |
|
10789 |
|
10790 |
|
10791 |
|
10792 |
|
10793 | SymbolNode.prototype.toHTML = function (options) {
|
10794 | var name = escape(this.name);
|
10795 |
|
10796 | if (name === 'true' || name === 'false') {
|
10797 | return '<span class="math-symbol math-boolean">' + name + '</span>';
|
10798 | } else if (name === 'i') {
|
10799 | return '<span class="math-symbol math-imaginary-symbol">' + name + '</span>';
|
10800 | } else if (name === 'Infinity') {
|
10801 | return '<span class="math-symbol math-infinity-symbol">' + name + '</span>';
|
10802 | } else if (name === 'NaN') {
|
10803 | return '<span class="math-symbol math-nan-symbol">' + name + '</span>';
|
10804 | } else if (name === 'null') {
|
10805 | return '<span class="math-symbol math-null-symbol">' + name + '</span>';
|
10806 | } else if (name === 'undefined') {
|
10807 | return '<span class="math-symbol math-undefined-symbol">' + name + '</span>';
|
10808 | }
|
10809 |
|
10810 | return '<span class="math-symbol">' + name + '</span>';
|
10811 | };
|
10812 | |
10813 |
|
10814 |
|
10815 |
|
10816 |
|
10817 |
|
10818 | SymbolNode.prototype.toJSON = function () {
|
10819 | return {
|
10820 | mathjs: 'SymbolNode',
|
10821 | name: this.name
|
10822 | };
|
10823 | };
|
10824 | |
10825 |
|
10826 |
|
10827 |
|
10828 |
|
10829 |
|
10830 |
|
10831 |
|
10832 |
|
10833 | SymbolNode.fromJSON = function (json) {
|
10834 | return new SymbolNode(json.name);
|
10835 | };
|
10836 | |
10837 |
|
10838 |
|
10839 |
|
10840 |
|
10841 |
|
10842 |
|
10843 |
|
10844 | SymbolNode.prototype._toTex = function (options) {
|
10845 | var isUnit = false;
|
10846 |
|
10847 | if (typeof math[this.name] === 'undefined' && isValuelessUnit(this.name)) {
|
10848 | isUnit = true;
|
10849 | }
|
10850 |
|
10851 | var symbol = latex.toSymbol(this.name, isUnit);
|
10852 |
|
10853 | if (symbol[0] === '\\') {
|
10854 |
|
10855 | return symbol;
|
10856 | }
|
10857 |
|
10858 |
|
10859 | return ' ' + symbol;
|
10860 | };
|
10861 |
|
10862 | return SymbolNode;
|
10863 | }
|
10864 |
|
10865 | exports.name = 'SymbolNode';
|
10866 | exports.path = 'expression.node';
|
10867 | exports.math = true;
|
10868 |
|
10869 | exports.factory = factory;
|
10870 |
|
10871 | }),
|
10872 |
|
10873 | (function(module, exports, __webpack_require__) {
|
10874 |
|
10875 | "use strict";
|
10876 |
|
10877 |
|
10878 | var nearlyEqual = __webpack_require__(3).nearlyEqual;
|
10879 |
|
10880 | var bigNearlyEqual = __webpack_require__(32);
|
10881 |
|
10882 | function factory(type, config, load, typed) {
|
10883 | var matrix = load(__webpack_require__(0));
|
10884 | var algorithm03 = load(__webpack_require__(18));
|
10885 | var algorithm05 = load(__webpack_require__(66));
|
10886 | var algorithm12 = load(__webpack_require__(19));
|
10887 | var algorithm13 = load(__webpack_require__(7));
|
10888 | var algorithm14 = load(__webpack_require__(6));
|
10889 | |
10890 |
|
10891 |
|
10892 |
|
10893 |
|
10894 |
|
10895 |
|
10896 |
|
10897 |
|
10898 |
|
10899 |
|
10900 |
|
10901 |
|
10902 |
|
10903 |
|
10904 |
|
10905 |
|
10906 |
|
10907 |
|
10908 |
|
10909 |
|
10910 |
|
10911 |
|
10912 |
|
10913 |
|
10914 |
|
10915 |
|
10916 |
|
10917 |
|
10918 |
|
10919 |
|
10920 |
|
10921 |
|
10922 |
|
10923 |
|
10924 |
|
10925 |
|
10926 |
|
10927 | var compare = typed('compare', {
|
10928 | 'boolean, boolean': function booleanBoolean(x, y) {
|
10929 | return x === y ? 0 : x > y ? 1 : -1;
|
10930 | },
|
10931 | 'number, number': function numberNumber(x, y) {
|
10932 | return x === y || nearlyEqual(x, y, config.epsilon) ? 0 : x > y ? 1 : -1;
|
10933 | },
|
10934 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
10935 | return x.eq(y) || bigNearlyEqual(x, y, config.epsilon) ? new type.BigNumber(0) : new type.BigNumber(x.cmp(y));
|
10936 | },
|
10937 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
10938 | return new type.Fraction(x.compare(y));
|
10939 | },
|
10940 | 'Complex, Complex': function ComplexComplex() {
|
10941 | throw new TypeError('No ordering relation is defined for complex numbers');
|
10942 | },
|
10943 | 'Unit, Unit': function UnitUnit(x, y) {
|
10944 | if (!x.equalBase(y)) {
|
10945 | throw new Error('Cannot compare units with different base');
|
10946 | }
|
10947 |
|
10948 | return compare(x.value, y.value);
|
10949 | },
|
10950 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
10951 | return algorithm05(x, y, compare);
|
10952 | },
|
10953 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
10954 | return algorithm03(y, x, compare, true);
|
10955 | },
|
10956 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
10957 | return algorithm03(x, y, compare, false);
|
10958 | },
|
10959 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
10960 | return algorithm13(x, y, compare);
|
10961 | },
|
10962 | 'Array, Array': function ArrayArray(x, y) {
|
10963 |
|
10964 | return compare(matrix(x), matrix(y)).valueOf();
|
10965 | },
|
10966 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
10967 |
|
10968 | return compare(matrix(x), y);
|
10969 | },
|
10970 | 'Matrix, Array': function MatrixArray(x, y) {
|
10971 |
|
10972 | return compare(x, matrix(y));
|
10973 | },
|
10974 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
10975 | return algorithm12(x, y, compare, false);
|
10976 | },
|
10977 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
10978 | return algorithm14(x, y, compare, false);
|
10979 | },
|
10980 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
10981 | return algorithm12(y, x, compare, true);
|
10982 | },
|
10983 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
10984 | return algorithm14(y, x, compare, true);
|
10985 | },
|
10986 | 'Array, any': function ArrayAny(x, y) {
|
10987 |
|
10988 | return algorithm14(matrix(x), y, compare, false).valueOf();
|
10989 | },
|
10990 | 'any, Array': function anyArray(x, y) {
|
10991 |
|
10992 | return algorithm14(matrix(y), x, compare, true).valueOf();
|
10993 | }
|
10994 | });
|
10995 | compare.toTex = undefined;
|
10996 |
|
10997 | return compare;
|
10998 | }
|
10999 |
|
11000 | exports.name = 'compare';
|
11001 | exports.factory = factory;
|
11002 |
|
11003 | }),
|
11004 |
|
11005 | (function(module, exports, __webpack_require__) {
|
11006 |
|
11007 | "use strict";
|
11008 |
|
11009 |
|
11010 |
|
11011 |
|
11012 |
|
11013 |
|
11014 |
|
11015 |
|
11016 | module.exports = function isMatrix(x) {
|
11017 | return x && x.constructor.prototype.isMatrix || false;
|
11018 | };
|
11019 |
|
11020 | }),
|
11021 |
|
11022 | (function(module, exports, __webpack_require__) {
|
11023 |
|
11024 | "use strict";
|
11025 |
|
11026 |
|
11027 |
|
11028 |
|
11029 |
|
11030 |
|
11031 |
|
11032 |
|
11033 |
|
11034 |
|
11035 |
|
11036 | function ArgumentsError(fn, count, min, max) {
|
11037 | if (!(this instanceof ArgumentsError)) {
|
11038 | throw new SyntaxError('Constructor must be called with the new operator');
|
11039 | }
|
11040 |
|
11041 | this.fn = fn;
|
11042 | this.count = count;
|
11043 | this.min = min;
|
11044 | this.max = max;
|
11045 | this.message = 'Wrong number of arguments in function ' + fn + ' (' + count + ' provided, ' + min + (max !== undefined && max !== null ? '-' + max : '') + ' expected)';
|
11046 | this.stack = new Error().stack;
|
11047 | }
|
11048 |
|
11049 | ArgumentsError.prototype = new Error();
|
11050 | ArgumentsError.prototype.constructor = Error;
|
11051 | ArgumentsError.prototype.name = 'ArgumentsError';
|
11052 | ArgumentsError.prototype.isArgumentsError = true;
|
11053 | module.exports = ArgumentsError;
|
11054 |
|
11055 | }),
|
11056 |
|
11057 | (function(module, exports, __webpack_require__) {
|
11058 |
|
11059 | "use strict";
|
11060 |
|
11061 |
|
11062 | var format = __webpack_require__(9).format;
|
11063 |
|
11064 | var escapeLatex = __webpack_require__(4).escape;
|
11065 |
|
11066 | function factory(type, config, load, typed) {
|
11067 | var Node = load(__webpack_require__(16));
|
11068 | var getType = load(__webpack_require__(26));
|
11069 | |
11070 |
|
11071 |
|
11072 |
|
11073 |
|
11074 |
|
11075 |
|
11076 |
|
11077 |
|
11078 |
|
11079 |
|
11080 |
|
11081 |
|
11082 | function ConstantNode(value) {
|
11083 | if (!(this instanceof ConstantNode)) {
|
11084 | throw new SyntaxError('Constructor must be called with the new operator');
|
11085 | }
|
11086 |
|
11087 | if (arguments.length === 2) {
|
11088 |
|
11089 | throw new SyntaxError('new ConstantNode(valueStr, valueType) is not supported anymore since math v4.0.0. Use new ConstantNode(value) instead, where value is a non-stringified value.');
|
11090 | }
|
11091 |
|
11092 | this.value = value;
|
11093 | }
|
11094 |
|
11095 | ConstantNode.prototype = new Node();
|
11096 | ConstantNode.prototype.type = 'ConstantNode';
|
11097 | ConstantNode.prototype.isConstantNode = true;
|
11098 | |
11099 |
|
11100 |
|
11101 |
|
11102 |
|
11103 |
|
11104 |
|
11105 |
|
11106 |
|
11107 |
|
11108 |
|
11109 |
|
11110 |
|
11111 |
|
11112 | ConstantNode.prototype._compile = function (math, argNames) {
|
11113 | var value = this.value;
|
11114 | return function evalConstantNode() {
|
11115 | return value;
|
11116 | };
|
11117 | };
|
11118 | |
11119 |
|
11120 |
|
11121 |
|
11122 |
|
11123 |
|
11124 | ConstantNode.prototype.forEach = function (callback) {}
|
11125 |
|
11126 | |
11127 |
|
11128 |
|
11129 |
|
11130 |
|
11131 |
|
11132 | ;
|
11133 |
|
11134 | ConstantNode.prototype.map = function (callback) {
|
11135 | return this.clone();
|
11136 | };
|
11137 | |
11138 |
|
11139 |
|
11140 |
|
11141 |
|
11142 |
|
11143 | ConstantNode.prototype.clone = function () {
|
11144 | return new ConstantNode(this.value);
|
11145 | };
|
11146 | |
11147 |
|
11148 |
|
11149 |
|
11150 |
|
11151 |
|
11152 |
|
11153 | ConstantNode.prototype._toString = function (options) {
|
11154 | return format(this.value, options);
|
11155 | };
|
11156 | |
11157 |
|
11158 |
|
11159 |
|
11160 |
|
11161 |
|
11162 |
|
11163 | ConstantNode.prototype.toHTML = function (options) {
|
11164 | var value = this._toString(options);
|
11165 |
|
11166 | switch (getType(this.value)) {
|
11167 | case 'number':
|
11168 | case 'BigNumber':
|
11169 | case 'Fraction':
|
11170 | return '<span class="math-number">' + value + '</span>';
|
11171 |
|
11172 | case 'string':
|
11173 | return '<span class="math-string">' + value + '</span>';
|
11174 |
|
11175 | case 'boolean':
|
11176 | return '<span class="math-boolean">' + value + '</span>';
|
11177 |
|
11178 | case 'null':
|
11179 | return '<span class="math-null-symbol">' + value + '</span>';
|
11180 |
|
11181 | case 'undefined':
|
11182 | return '<span class="math-undefined">' + value + '</span>';
|
11183 |
|
11184 | default:
|
11185 | return '<span class="math-symbol">' + value + '</span>';
|
11186 | }
|
11187 | };
|
11188 | |
11189 |
|
11190 |
|
11191 |
|
11192 |
|
11193 |
|
11194 | ConstantNode.prototype.toJSON = function () {
|
11195 | return {
|
11196 | mathjs: 'ConstantNode',
|
11197 | value: this.value
|
11198 | };
|
11199 | };
|
11200 | |
11201 |
|
11202 |
|
11203 |
|
11204 |
|
11205 |
|
11206 |
|
11207 |
|
11208 |
|
11209 | ConstantNode.fromJSON = function (json) {
|
11210 | return new ConstantNode(json.value);
|
11211 | };
|
11212 | |
11213 |
|
11214 |
|
11215 |
|
11216 |
|
11217 |
|
11218 |
|
11219 | ConstantNode.prototype._toTex = function (options) {
|
11220 | var value = this._toString(options);
|
11221 |
|
11222 | switch (getType(this.value)) {
|
11223 | case 'string':
|
11224 | return '\\mathtt{' + escapeLatex(value) + '}';
|
11225 |
|
11226 | case 'number':
|
11227 | case 'BigNumber':
|
11228 | var index = value.toLowerCase().indexOf('e');
|
11229 |
|
11230 | if (index !== -1) {
|
11231 | return value.substring(0, index) + '\\cdot10^{' + value.substring(index + 1) + '}';
|
11232 | }
|
11233 |
|
11234 | return value;
|
11235 |
|
11236 | case 'Fraction':
|
11237 | return this.value.toLatex();
|
11238 |
|
11239 | default:
|
11240 | return value;
|
11241 | }
|
11242 | };
|
11243 |
|
11244 | return ConstantNode;
|
11245 | }
|
11246 |
|
11247 | exports.name = 'ConstantNode';
|
11248 | exports.path = 'expression.node';
|
11249 | exports.factory = factory;
|
11250 |
|
11251 | }),
|
11252 |
|
11253 | (function(module, exports, __webpack_require__) {
|
11254 |
|
11255 | "use strict";
|
11256 |
|
11257 |
|
11258 | var latex = __webpack_require__(4);
|
11259 |
|
11260 | var map = __webpack_require__(2).map;
|
11261 |
|
11262 | var escape = __webpack_require__(9).escape;
|
11263 |
|
11264 | var isSafeMethod = __webpack_require__(13).isSafeMethod;
|
11265 |
|
11266 | var getSafeProperty = __webpack_require__(13).getSafeProperty;
|
11267 |
|
11268 | var operators = __webpack_require__(53);
|
11269 |
|
11270 | function factory(type, config, load, typed) {
|
11271 | var Node = load(__webpack_require__(16));
|
11272 | |
11273 |
|
11274 |
|
11275 |
|
11276 |
|
11277 |
|
11278 |
|
11279 |
|
11280 |
|
11281 |
|
11282 |
|
11283 | function OperatorNode(op, fn, args, implicit) {
|
11284 | if (!(this instanceof OperatorNode)) {
|
11285 | throw new SyntaxError('Constructor must be called with the new operator');
|
11286 | }
|
11287 |
|
11288 |
|
11289 | if (typeof op !== 'string') {
|
11290 | throw new TypeError('string expected for parameter "op"');
|
11291 | }
|
11292 |
|
11293 | if (typeof fn !== 'string') {
|
11294 | throw new TypeError('string expected for parameter "fn"');
|
11295 | }
|
11296 |
|
11297 | if (!Array.isArray(args) || !args.every(type.isNode)) {
|
11298 | throw new TypeError('Array containing Nodes expected for parameter "args"');
|
11299 | }
|
11300 |
|
11301 | this.implicit = implicit === true;
|
11302 | this.op = op;
|
11303 | this.fn = fn;
|
11304 | this.args = args || [];
|
11305 | }
|
11306 |
|
11307 | OperatorNode.prototype = new Node();
|
11308 | OperatorNode.prototype.type = 'OperatorNode';
|
11309 | OperatorNode.prototype.isOperatorNode = true;
|
11310 | |
11311 |
|
11312 |
|
11313 |
|
11314 |
|
11315 |
|
11316 |
|
11317 |
|
11318 |
|
11319 |
|
11320 |
|
11321 |
|
11322 |
|
11323 |
|
11324 | OperatorNode.prototype._compile = function (math, argNames) {
|
11325 |
|
11326 | if (typeof this.fn !== 'string' || !isSafeMethod(math, this.fn)) {
|
11327 | if (!math[this.fn]) {
|
11328 | throw new Error('Function ' + this.fn + ' missing in provided namespace "math"');
|
11329 | } else {
|
11330 | throw new Error('No access to function "' + this.fn + '"');
|
11331 | }
|
11332 | }
|
11333 |
|
11334 | var fn = getSafeProperty(math, this.fn);
|
11335 | var evalArgs = map(this.args, function (arg) {
|
11336 | return arg._compile(math, argNames);
|
11337 | });
|
11338 |
|
11339 | if (evalArgs.length === 1) {
|
11340 | var evalArg0 = evalArgs[0];
|
11341 | return function evalOperatorNode(scope, args, context) {
|
11342 | return fn(evalArg0(scope, args, context));
|
11343 | };
|
11344 | } else if (evalArgs.length === 2) {
|
11345 | var _evalArg = evalArgs[0];
|
11346 | var evalArg1 = evalArgs[1];
|
11347 | return function evalOperatorNode(scope, args, context) {
|
11348 | return fn(_evalArg(scope, args, context), evalArg1(scope, args, context));
|
11349 | };
|
11350 | } else {
|
11351 | return function evalOperatorNode(scope, args, context) {
|
11352 | return fn.apply(null, map(evalArgs, function (evalArg) {
|
11353 | return evalArg(scope, args, context);
|
11354 | }));
|
11355 | };
|
11356 | }
|
11357 | };
|
11358 | |
11359 |
|
11360 |
|
11361 |
|
11362 |
|
11363 |
|
11364 | OperatorNode.prototype.forEach = function (callback) {
|
11365 | for (var i = 0; i < this.args.length; i++) {
|
11366 | callback(this.args[i], 'args[' + i + ']', this);
|
11367 | }
|
11368 | };
|
11369 | |
11370 |
|
11371 |
|
11372 |
|
11373 |
|
11374 |
|
11375 |
|
11376 |
|
11377 | OperatorNode.prototype.map = function (callback) {
|
11378 | var args = [];
|
11379 |
|
11380 | for (var i = 0; i < this.args.length; i++) {
|
11381 | args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
|
11382 | }
|
11383 |
|
11384 | return new OperatorNode(this.op, this.fn, args, this.implicit);
|
11385 | };
|
11386 | |
11387 |
|
11388 |
|
11389 |
|
11390 |
|
11391 |
|
11392 | OperatorNode.prototype.clone = function () {
|
11393 | return new OperatorNode(this.op, this.fn, this.args.slice(0), this.implicit);
|
11394 | };
|
11395 | |
11396 |
|
11397 |
|
11398 |
|
11399 |
|
11400 |
|
11401 |
|
11402 | OperatorNode.prototype.isUnary = function () {
|
11403 | return this.args.length === 1;
|
11404 | };
|
11405 | |
11406 |
|
11407 |
|
11408 |
|
11409 |
|
11410 |
|
11411 |
|
11412 | OperatorNode.prototype.isBinary = function () {
|
11413 | return this.args.length === 2;
|
11414 | };
|
11415 | |
11416 |
|
11417 |
|
11418 |
|
11419 |
|
11420 |
|
11421 |
|
11422 |
|
11423 |
|
11424 |
|
11425 |
|
11426 |
|
11427 |
|
11428 |
|
11429 |
|
11430 | function calculateNecessaryParentheses(root, parenthesis, implicit, args, latex) {
|
11431 |
|
11432 | var precedence = operators.getPrecedence(root, parenthesis);
|
11433 | var associativity = operators.getAssociativity(root, parenthesis);
|
11434 |
|
11435 | if (parenthesis === 'all' || args.length > 2 && root.getIdentifier() !== 'OperatorNode:add' && root.getIdentifier() !== 'OperatorNode:multiply') {
|
11436 | var parens = args.map(function (arg) {
|
11437 | switch (arg.getContent().type) {
|
11438 |
|
11439 | case 'ArrayNode':
|
11440 | case 'ConstantNode':
|
11441 | case 'SymbolNode':
|
11442 | case 'ParenthesisNode':
|
11443 | return false;
|
11444 |
|
11445 | default:
|
11446 | return true;
|
11447 | }
|
11448 | });
|
11449 | return parens;
|
11450 | }
|
11451 |
|
11452 | var result;
|
11453 |
|
11454 | switch (args.length) {
|
11455 | case 0:
|
11456 | result = [];
|
11457 | break;
|
11458 |
|
11459 | case 1:
|
11460 |
|
11461 |
|
11462 | var operandPrecedence = operators.getPrecedence(args[0], parenthesis);
|
11463 |
|
11464 | if (latex && operandPrecedence !== null) {
|
11465 | var operandIdentifier;
|
11466 | var rootIdentifier;
|
11467 |
|
11468 | if (parenthesis === 'keep') {
|
11469 | operandIdentifier = args[0].getIdentifier();
|
11470 | rootIdentifier = root.getIdentifier();
|
11471 | } else {
|
11472 |
|
11473 | operandIdentifier = args[0].getContent().getIdentifier();
|
11474 | rootIdentifier = root.getContent().getIdentifier();
|
11475 | }
|
11476 |
|
11477 | if (operators.properties[precedence][rootIdentifier].latexLeftParens === false) {
|
11478 | result = [false];
|
11479 | break;
|
11480 | }
|
11481 |
|
11482 | if (operators.properties[operandPrecedence][operandIdentifier].latexParens === false) {
|
11483 | result = [false];
|
11484 | break;
|
11485 | }
|
11486 | }
|
11487 |
|
11488 | if (operandPrecedence === null) {
|
11489 |
|
11490 | result = [false];
|
11491 | break;
|
11492 | }
|
11493 |
|
11494 | if (operandPrecedence <= precedence) {
|
11495 |
|
11496 | result = [true];
|
11497 | break;
|
11498 | }
|
11499 |
|
11500 |
|
11501 | result = [false];
|
11502 | break;
|
11503 |
|
11504 | case 2:
|
11505 |
|
11506 | var lhsParens;
|
11507 |
|
11508 |
|
11509 | var lhsPrecedence = operators.getPrecedence(args[0], parenthesis);
|
11510 |
|
11511 | var assocWithLhs = operators.isAssociativeWith(root, args[0], parenthesis);
|
11512 |
|
11513 | if (lhsPrecedence === null) {
|
11514 |
|
11515 |
|
11516 | lhsParens = false;
|
11517 | } else if (lhsPrecedence === precedence && associativity === 'right' && !assocWithLhs) {
|
11518 |
|
11519 |
|
11520 |
|
11521 |
|
11522 | lhsParens = true;
|
11523 | } else if (lhsPrecedence < precedence) {
|
11524 | lhsParens = true;
|
11525 | } else {
|
11526 | lhsParens = false;
|
11527 | }
|
11528 |
|
11529 | var rhsParens;
|
11530 |
|
11531 |
|
11532 | var rhsPrecedence = operators.getPrecedence(args[1], parenthesis);
|
11533 |
|
11534 | var assocWithRhs = operators.isAssociativeWith(root, args[1], parenthesis);
|
11535 |
|
11536 | if (rhsPrecedence === null) {
|
11537 |
|
11538 |
|
11539 | rhsParens = false;
|
11540 | } else if (rhsPrecedence === precedence && associativity === 'left' && !assocWithRhs) {
|
11541 |
|
11542 |
|
11543 |
|
11544 |
|
11545 | rhsParens = true;
|
11546 | } else if (rhsPrecedence < precedence) {
|
11547 | rhsParens = true;
|
11548 | } else {
|
11549 | rhsParens = false;
|
11550 | }
|
11551 |
|
11552 |
|
11553 | if (latex) {
|
11554 | var _rootIdentifier;
|
11555 |
|
11556 | var lhsIdentifier;
|
11557 | var rhsIdentifier;
|
11558 |
|
11559 | if (parenthesis === 'keep') {
|
11560 | _rootIdentifier = root.getIdentifier();
|
11561 | lhsIdentifier = root.args[0].getIdentifier();
|
11562 | rhsIdentifier = root.args[1].getIdentifier();
|
11563 | } else {
|
11564 |
|
11565 | _rootIdentifier = root.getContent().getIdentifier();
|
11566 | lhsIdentifier = root.args[0].getContent().getIdentifier();
|
11567 | rhsIdentifier = root.args[1].getContent().getIdentifier();
|
11568 | }
|
11569 |
|
11570 | if (lhsPrecedence !== null) {
|
11571 | if (operators.properties[precedence][_rootIdentifier].latexLeftParens === false) {
|
11572 | lhsParens = false;
|
11573 | }
|
11574 |
|
11575 | if (operators.properties[lhsPrecedence][lhsIdentifier].latexParens === false) {
|
11576 | lhsParens = false;
|
11577 | }
|
11578 | }
|
11579 |
|
11580 | if (rhsPrecedence !== null) {
|
11581 | if (operators.properties[precedence][_rootIdentifier].latexRightParens === false) {
|
11582 | rhsParens = false;
|
11583 | }
|
11584 |
|
11585 | if (operators.properties[rhsPrecedence][rhsIdentifier].latexParens === false) {
|
11586 | rhsParens = false;
|
11587 | }
|
11588 | }
|
11589 | }
|
11590 |
|
11591 | result = [lhsParens, rhsParens];
|
11592 | break;
|
11593 |
|
11594 | default:
|
11595 | if (root.getIdentifier() === 'OperatorNode:add' || root.getIdentifier() === 'OperatorNode:multiply') {
|
11596 | result = args.map(function (arg) {
|
11597 | var argPrecedence = operators.getPrecedence(arg, parenthesis);
|
11598 | var assocWithArg = operators.isAssociativeWith(root, arg, parenthesis);
|
11599 | var argAssociativity = operators.getAssociativity(arg, parenthesis);
|
11600 |
|
11601 | if (argPrecedence === null) {
|
11602 |
|
11603 | return false;
|
11604 | } else if (precedence === argPrecedence && associativity === argAssociativity && !assocWithArg) {
|
11605 | return true;
|
11606 | } else if (argPrecedence < precedence) {
|
11607 | return true;
|
11608 | }
|
11609 |
|
11610 | return false;
|
11611 | });
|
11612 | }
|
11613 |
|
11614 | break;
|
11615 | }
|
11616 |
|
11617 |
|
11618 |
|
11619 |
|
11620 | if (args.length >= 2 && root.getIdentifier() === 'OperatorNode:multiply' && root.implicit && parenthesis === 'auto' && implicit === 'hide') {
|
11621 | result = args.map(function (arg, index) {
|
11622 | var isParenthesisNode = arg.getIdentifier() === 'ParenthesisNode';
|
11623 |
|
11624 | if (result[index] || isParenthesisNode) {
|
11625 |
|
11626 | return true;
|
11627 | }
|
11628 |
|
11629 | return false;
|
11630 | });
|
11631 | }
|
11632 |
|
11633 | return result;
|
11634 | }
|
11635 | |
11636 |
|
11637 |
|
11638 |
|
11639 |
|
11640 |
|
11641 |
|
11642 | OperatorNode.prototype._toString = function (options) {
|
11643 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
11644 | var implicit = options && options.implicit ? options.implicit : 'hide';
|
11645 | var args = this.args;
|
11646 | var parens = calculateNecessaryParentheses(this, parenthesis, implicit, args, false);
|
11647 |
|
11648 | if (args.length === 1) {
|
11649 |
|
11650 | var assoc = operators.getAssociativity(this, parenthesis);
|
11651 | var operand = args[0].toString(options);
|
11652 |
|
11653 | if (parens[0]) {
|
11654 | operand = '(' + operand + ')';
|
11655 | }
|
11656 |
|
11657 |
|
11658 | var opIsNamed = /[a-zA-Z]+/.test(this.op);
|
11659 |
|
11660 | if (assoc === 'right') {
|
11661 |
|
11662 | return this.op + (opIsNamed ? ' ' : '') + operand;
|
11663 | } else if (assoc === 'left') {
|
11664 |
|
11665 | return operand + (opIsNamed ? ' ' : '') + this.op;
|
11666 | }
|
11667 |
|
11668 |
|
11669 | return operand + this.op;
|
11670 | } else if (args.length === 2) {
|
11671 | var lhs = args[0].toString(options);
|
11672 |
|
11673 | var rhs = args[1].toString(options);
|
11674 |
|
11675 | if (parens[0]) {
|
11676 |
|
11677 | lhs = '(' + lhs + ')';
|
11678 | }
|
11679 |
|
11680 | if (parens[1]) {
|
11681 |
|
11682 | rhs = '(' + rhs + ')';
|
11683 | }
|
11684 |
|
11685 | if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
|
11686 | return lhs + ' ' + rhs;
|
11687 | }
|
11688 |
|
11689 | return lhs + ' ' + this.op + ' ' + rhs;
|
11690 | } else if (args.length > 2 && (this.getIdentifier() === 'OperatorNode:add' || this.getIdentifier() === 'OperatorNode:multiply')) {
|
11691 | var stringifiedArgs = args.map(function (arg, index) {
|
11692 | arg = arg.toString(options);
|
11693 |
|
11694 | if (parens[index]) {
|
11695 |
|
11696 | arg = '(' + arg + ')';
|
11697 | }
|
11698 |
|
11699 | return arg;
|
11700 | });
|
11701 |
|
11702 | if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
|
11703 | return stringifiedArgs.join(' ');
|
11704 | }
|
11705 |
|
11706 | return stringifiedArgs.join(' ' + this.op + ' ');
|
11707 | } else {
|
11708 |
|
11709 | return this.fn + '(' + this.args.join(', ') + ')';
|
11710 | }
|
11711 | };
|
11712 | |
11713 |
|
11714 |
|
11715 |
|
11716 |
|
11717 |
|
11718 | OperatorNode.prototype.toJSON = function () {
|
11719 | return {
|
11720 | mathjs: 'OperatorNode',
|
11721 | op: this.op,
|
11722 | fn: this.fn,
|
11723 | args: this.args,
|
11724 | implicit: this.implicit
|
11725 | };
|
11726 | };
|
11727 | |
11728 |
|
11729 |
|
11730 |
|
11731 |
|
11732 |
|
11733 |
|
11734 |
|
11735 |
|
11736 | OperatorNode.fromJSON = function (json) {
|
11737 | return new OperatorNode(json.op, json.fn, json.args, json.implicit);
|
11738 | };
|
11739 | |
11740 |
|
11741 |
|
11742 |
|
11743 |
|
11744 |
|
11745 |
|
11746 | OperatorNode.prototype.toHTML = function (options) {
|
11747 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
11748 | var implicit = options && options.implicit ? options.implicit : 'hide';
|
11749 | var args = this.args;
|
11750 | var parens = calculateNecessaryParentheses(this, parenthesis, implicit, args, false);
|
11751 |
|
11752 | if (args.length === 1) {
|
11753 |
|
11754 | var assoc = operators.getAssociativity(this, parenthesis);
|
11755 | var operand = args[0].toHTML(options);
|
11756 |
|
11757 | if (parens[0]) {
|
11758 | operand = '<span class="math-parenthesis math-round-parenthesis">(</span>' + operand + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
11759 | }
|
11760 |
|
11761 | if (assoc === 'right') {
|
11762 |
|
11763 | return '<span class="math-operator math-unary-operator math-lefthand-unary-operator">' + escape(this.op) + '</span>' + operand;
|
11764 | } else {
|
11765 |
|
11766 | return operand + '<span class="math-operator math-unary-operator math-righthand-unary-operator">' + escape(this.op) + '</span>';
|
11767 | }
|
11768 | } else if (args.length === 2) {
|
11769 |
|
11770 | var lhs = args[0].toHTML(options);
|
11771 |
|
11772 | var rhs = args[1].toHTML(options);
|
11773 |
|
11774 | if (parens[0]) {
|
11775 |
|
11776 | lhs = '<span class="math-parenthesis math-round-parenthesis">(</span>' + lhs + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
11777 | }
|
11778 |
|
11779 | if (parens[1]) {
|
11780 |
|
11781 | rhs = '<span class="math-parenthesis math-round-parenthesis">(</span>' + rhs + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
11782 | }
|
11783 |
|
11784 | if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
|
11785 | return lhs + '<span class="math-operator math-binary-operator math-implicit-binary-operator"></span>' + rhs;
|
11786 | }
|
11787 |
|
11788 | return lhs + '<span class="math-operator math-binary-operator math-explicit-binary-operator">' + escape(this.op) + '</span>' + rhs;
|
11789 | } else {
|
11790 | var stringifiedArgs = args.map(function (arg, index) {
|
11791 | arg = arg.toHTML(options);
|
11792 |
|
11793 | if (parens[index]) {
|
11794 |
|
11795 | arg = '<span class="math-parenthesis math-round-parenthesis">(</span>' + arg + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
11796 | }
|
11797 |
|
11798 | return arg;
|
11799 | });
|
11800 |
|
11801 | if (args.length > 2 && (this.getIdentifier() === 'OperatorNode:add' || this.getIdentifier() === 'OperatorNode:multiply')) {
|
11802 | if (this.implicit && this.getIdentifier() === 'OperatorNode:multiply' && implicit === 'hide') {
|
11803 | return stringifiedArgs.join('<span class="math-operator math-binary-operator math-implicit-binary-operator"></span>');
|
11804 | }
|
11805 |
|
11806 | return stringifiedArgs.join('<span class="math-operator math-binary-operator math-explicit-binary-operator">' + escape(this.op) + '</span>');
|
11807 | } else {
|
11808 |
|
11809 | return '<span class="math-function">' + escape(this.fn) + '</span><span class="math-paranthesis math-round-parenthesis">(</span>' + stringifiedArgs.join('<span class="math-separator">,</span>') + '<span class="math-paranthesis math-round-parenthesis">)</span>';
|
11810 | }
|
11811 | }
|
11812 | };
|
11813 | |
11814 |
|
11815 |
|
11816 |
|
11817 |
|
11818 |
|
11819 |
|
11820 | OperatorNode.prototype._toTex = function (options) {
|
11821 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
11822 | var implicit = options && options.implicit ? options.implicit : 'hide';
|
11823 | var args = this.args;
|
11824 | var parens = calculateNecessaryParentheses(this, parenthesis, implicit, args, true);
|
11825 | var op = latex.operators[this.fn];
|
11826 | op = typeof op === 'undefined' ? this.op : op;
|
11827 |
|
11828 | if (args.length === 1) {
|
11829 |
|
11830 | var assoc = operators.getAssociativity(this, parenthesis);
|
11831 | var operand = args[0].toTex(options);
|
11832 |
|
11833 | if (parens[0]) {
|
11834 | operand = "\\left(".concat(operand, "\\right)");
|
11835 | }
|
11836 |
|
11837 | if (assoc === 'right') {
|
11838 |
|
11839 | return op + operand;
|
11840 | } else if (assoc === 'left') {
|
11841 |
|
11842 | return operand + op;
|
11843 | }
|
11844 |
|
11845 |
|
11846 | return operand + op;
|
11847 | } else if (args.length === 2) {
|
11848 |
|
11849 | var lhs = args[0];
|
11850 |
|
11851 | var lhsTex = lhs.toTex(options);
|
11852 |
|
11853 | if (parens[0]) {
|
11854 | lhsTex = "\\left(".concat(lhsTex, "\\right)");
|
11855 | }
|
11856 |
|
11857 | var rhs = args[1];
|
11858 |
|
11859 | var rhsTex = rhs.toTex(options);
|
11860 |
|
11861 | if (parens[1]) {
|
11862 | rhsTex = "\\left(".concat(rhsTex, "\\right)");
|
11863 | }
|
11864 |
|
11865 |
|
11866 | var lhsIdentifier;
|
11867 |
|
11868 | if (parenthesis === 'keep') {
|
11869 | lhsIdentifier = lhs.getIdentifier();
|
11870 | } else {
|
11871 |
|
11872 | lhsIdentifier = lhs.getContent().getIdentifier();
|
11873 | }
|
11874 |
|
11875 | switch (this.getIdentifier()) {
|
11876 | case 'OperatorNode:divide':
|
11877 |
|
11878 | return op + '{' + lhsTex + '}' + '{' + rhsTex + '}';
|
11879 |
|
11880 | case 'OperatorNode:pow':
|
11881 | lhsTex = '{' + lhsTex + '}';
|
11882 | rhsTex = '{' + rhsTex + '}';
|
11883 |
|
11884 | switch (lhsIdentifier) {
|
11885 | case 'ConditionalNode':
|
11886 |
|
11887 | case 'OperatorNode:divide':
|
11888 | lhsTex = "\\left(".concat(lhsTex, "\\right)");
|
11889 | }
|
11890 |
|
11891 | break;
|
11892 |
|
11893 | case 'OperatorNode:multiply':
|
11894 | if (this.implicit && implicit === 'hide') {
|
11895 | return lhsTex + '~' + rhsTex;
|
11896 | }
|
11897 |
|
11898 | }
|
11899 |
|
11900 | return lhsTex + op + rhsTex;
|
11901 | } else if (args.length > 2 && (this.getIdentifier() === 'OperatorNode:add' || this.getIdentifier() === 'OperatorNode:multiply')) {
|
11902 | var texifiedArgs = args.map(function (arg, index) {
|
11903 | arg = arg.toTex(options);
|
11904 |
|
11905 | if (parens[index]) {
|
11906 | arg = "\\left(".concat(arg, "\\right)");
|
11907 | }
|
11908 |
|
11909 | return arg;
|
11910 | });
|
11911 |
|
11912 | if (this.getIdentifier() === 'OperatorNode:multiply' && this.implicit) {
|
11913 | return texifiedArgs.join('~');
|
11914 | }
|
11915 |
|
11916 | return texifiedArgs.join(op);
|
11917 | } else {
|
11918 |
|
11919 |
|
11920 |
|
11921 | return '\\mathrm{' + this.fn + '}\\left(' + args.map(function (arg) {
|
11922 | return arg.toTex(options);
|
11923 | }).join(',') + '\\right)';
|
11924 | }
|
11925 | };
|
11926 | |
11927 |
|
11928 |
|
11929 |
|
11930 |
|
11931 |
|
11932 | OperatorNode.prototype.getIdentifier = function () {
|
11933 | return this.type + ':' + this.fn;
|
11934 | };
|
11935 |
|
11936 | return OperatorNode;
|
11937 | }
|
11938 |
|
11939 | exports.name = 'OperatorNode';
|
11940 | exports.path = 'expression.node';
|
11941 | exports.factory = factory;
|
11942 |
|
11943 | }),
|
11944 |
|
11945 | (function(module, exports, __webpack_require__) {
|
11946 |
|
11947 | "use strict";
|
11948 |
|
11949 |
|
11950 | var deepMap = __webpack_require__(1);
|
11951 |
|
11952 | function factory(type, config, load, typed) {
|
11953 | |
11954 |
|
11955 |
|
11956 |
|
11957 |
|
11958 |
|
11959 |
|
11960 |
|
11961 |
|
11962 |
|
11963 |
|
11964 |
|
11965 |
|
11966 |
|
11967 |
|
11968 |
|
11969 |
|
11970 |
|
11971 |
|
11972 |
|
11973 |
|
11974 |
|
11975 |
|
11976 |
|
11977 |
|
11978 |
|
11979 |
|
11980 |
|
11981 |
|
11982 |
|
11983 |
|
11984 |
|
11985 |
|
11986 | var isZero = typed('isZero', {
|
11987 | 'number': function number(x) {
|
11988 | return x === 0;
|
11989 | },
|
11990 | 'BigNumber': function BigNumber(x) {
|
11991 | return x.isZero();
|
11992 | },
|
11993 | 'Complex': function Complex(x) {
|
11994 | return x.re === 0 && x.im === 0;
|
11995 | },
|
11996 | 'Fraction': function Fraction(x) {
|
11997 | return x.d === 1 && x.n === 0;
|
11998 | },
|
11999 | 'Unit': function Unit(x) {
|
12000 | return isZero(x.value);
|
12001 | },
|
12002 | 'Array | Matrix': function ArrayMatrix(x) {
|
12003 | return deepMap(x, isZero);
|
12004 | }
|
12005 | });
|
12006 | return isZero;
|
12007 | }
|
12008 |
|
12009 | exports.name = 'isZero';
|
12010 | exports.factory = factory;
|
12011 |
|
12012 | }),
|
12013 |
|
12014 | (function(module, exports, __webpack_require__) {
|
12015 |
|
12016 | "use strict";
|
12017 |
|
12018 |
|
12019 | var deepMap = __webpack_require__(1);
|
12020 |
|
12021 | function factory(type, config, load, typed) {
|
12022 | |
12023 |
|
12024 |
|
12025 |
|
12026 |
|
12027 |
|
12028 |
|
12029 |
|
12030 |
|
12031 |
|
12032 |
|
12033 |
|
12034 |
|
12035 |
|
12036 |
|
12037 |
|
12038 |
|
12039 |
|
12040 |
|
12041 |
|
12042 |
|
12043 |
|
12044 |
|
12045 |
|
12046 |
|
12047 |
|
12048 |
|
12049 |
|
12050 |
|
12051 | var isNegative = typed('isNegative', {
|
12052 | 'number': function number(x) {
|
12053 | return x < 0;
|
12054 | },
|
12055 | 'BigNumber': function BigNumber(x) {
|
12056 | return x.isNeg() && !x.isZero() && !x.isNaN();
|
12057 | },
|
12058 | 'Fraction': function Fraction(x) {
|
12059 | return x.s < 0;
|
12060 | },
|
12061 | 'Unit': function Unit(x) {
|
12062 | return isNegative(x.value);
|
12063 | },
|
12064 | 'Array | Matrix': function ArrayMatrix(x) {
|
12065 | return deepMap(x, isNegative);
|
12066 | }
|
12067 | });
|
12068 | return isNegative;
|
12069 | }
|
12070 |
|
12071 | exports.name = 'isNegative';
|
12072 | exports.factory = factory;
|
12073 |
|
12074 | }),
|
12075 |
|
12076 | (function(module, exports, __webpack_require__) {
|
12077 |
|
12078 | "use strict";
|
12079 |
|
12080 |
|
12081 | var isCollection = __webpack_require__(35);
|
12082 |
|
12083 |
|
12084 |
|
12085 |
|
12086 |
|
12087 |
|
12088 |
|
12089 |
|
12090 | module.exports = function containsCollections(array) {
|
12091 | for (var i = 0; i < array.length; i++) {
|
12092 | if (isCollection(array[i])) {
|
12093 | return true;
|
12094 | }
|
12095 | }
|
12096 |
|
12097 | return false;
|
12098 | };
|
12099 |
|
12100 | }),
|
12101 |
|
12102 | (function(module, exports, __webpack_require__) {
|
12103 |
|
12104 | "use strict";
|
12105 |
|
12106 |
|
12107 | function factory(type, config, load, typed) {
|
12108 | var _typeof = load(__webpack_require__(26));
|
12109 |
|
12110 | function getArrayDataType(array) {
|
12111 | var _type;
|
12112 |
|
12113 |
|
12114 | var _length = 0;
|
12115 |
|
12116 | for (var i = 0; i < array.length; i++) {
|
12117 | var item = array[i];
|
12118 | var isArray = Array.isArray(item);
|
12119 |
|
12120 | if (i === 0 && isArray) {
|
12121 | _length = item.length;
|
12122 | }
|
12123 |
|
12124 |
|
12125 | if (isArray && item.length !== _length) {
|
12126 | return undefined;
|
12127 | }
|
12128 |
|
12129 | var itemType = isArray ? getArrayDataType(item)
|
12130 | : _typeof(item);
|
12131 |
|
12132 | if (_type === undefined) {
|
12133 | _type = itemType;
|
12134 | } else if (_type !== itemType) {
|
12135 | return 'mixed';
|
12136 | } else {
|
12137 | }
|
12138 | }
|
12139 |
|
12140 | return _type;
|
12141 | }
|
12142 |
|
12143 | return getArrayDataType;
|
12144 | }
|
12145 |
|
12146 |
|
12147 |
|
12148 |
|
12149 |
|
12150 |
|
12151 |
|
12152 |
|
12153 |
|
12154 |
|
12155 | exports.factory = factory;
|
12156 |
|
12157 | }),
|
12158 |
|
12159 | (function(module, exports, __webpack_require__) {
|
12160 |
|
12161 | "use strict";
|
12162 |
|
12163 |
|
12164 | var deepMap = __webpack_require__(1);
|
12165 |
|
12166 | function factory(type, config, load, typed) {
|
12167 | |
12168 |
|
12169 |
|
12170 |
|
12171 |
|
12172 |
|
12173 |
|
12174 |
|
12175 |
|
12176 |
|
12177 |
|
12178 |
|
12179 |
|
12180 |
|
12181 |
|
12182 |
|
12183 |
|
12184 |
|
12185 |
|
12186 |
|
12187 |
|
12188 |
|
12189 |
|
12190 |
|
12191 |
|
12192 | var number = typed('number', {
|
12193 | '': function _() {
|
12194 | return 0;
|
12195 | },
|
12196 | 'number': function number(x) {
|
12197 | return x;
|
12198 | },
|
12199 | 'string': function string(x) {
|
12200 | if (x === 'NaN') return NaN;
|
12201 | var num = Number(x);
|
12202 |
|
12203 | if (isNaN(num)) {
|
12204 | throw new SyntaxError('String "' + x + '" is no valid number');
|
12205 | }
|
12206 |
|
12207 | return num;
|
12208 | },
|
12209 | 'BigNumber': function BigNumber(x) {
|
12210 | return x.toNumber();
|
12211 | },
|
12212 | 'Fraction': function Fraction(x) {
|
12213 | return x.valueOf();
|
12214 | },
|
12215 | 'Unit': function Unit(x) {
|
12216 | throw new Error('Second argument with valueless unit expected');
|
12217 | },
|
12218 | 'null': function _null(x) {
|
12219 | return 0;
|
12220 | },
|
12221 | 'Unit, string | Unit': function UnitStringUnit(unit, valuelessUnit) {
|
12222 | return unit.toNumber(valuelessUnit);
|
12223 | },
|
12224 | 'Array | Matrix': function ArrayMatrix(x) {
|
12225 | return deepMap(x, number);
|
12226 | }
|
12227 | });
|
12228 | number.toTex = {
|
12229 | 0: "0",
|
12230 | 1: "\\left(${args[0]}\\right)",
|
12231 | 2: "\\left(\\left(${args[0]}\\right)${args[1]}\\right)"
|
12232 | };
|
12233 | return number;
|
12234 | }
|
12235 |
|
12236 | exports.name = 'number';
|
12237 | exports.factory = factory;
|
12238 |
|
12239 | }),
|
12240 |
|
12241 | (function(module, exports, __webpack_require__) {
|
12242 |
|
12243 | "use strict";
|
12244 |
|
12245 |
|
12246 | function factory(type, config, load, typed) {
|
12247 | var getTypeOf = load(__webpack_require__(26));
|
12248 | var validInputTypes = {
|
12249 | 'string': true,
|
12250 | 'number': true,
|
12251 | 'BigNumber': true,
|
12252 | 'Fraction': true
|
12253 |
|
12254 | };
|
12255 | var validOutputTypes = {
|
12256 | 'number': load(__webpack_require__(64)),
|
12257 | 'BigNumber': load(__webpack_require__(105)),
|
12258 | 'Fraction': load(__webpack_require__(83))
|
12259 | |
12260 |
|
12261 |
|
12262 |
|
12263 |
|
12264 |
|
12265 |
|
12266 |
|
12267 |
|
12268 | };
|
12269 |
|
12270 | var numeric = function numeric(value, outputType) {
|
12271 | var inputType = getTypeOf(value);
|
12272 |
|
12273 | if (!(inputType in validInputTypes)) {
|
12274 | throw new TypeError('Cannot convert ' + value + ' of type "' + inputType + '"; valid input types are ' + Object.keys(validInputTypes).join(', '));
|
12275 | }
|
12276 |
|
12277 | if (!(outputType in validOutputTypes)) {
|
12278 | throw new TypeError('Cannot convert ' + value + ' to type "' + outputType + '"; valid output types are ' + Object.keys(validOutputTypes).join(', '));
|
12279 | }
|
12280 |
|
12281 | if (outputType === inputType) {
|
12282 | return value;
|
12283 | } else {
|
12284 | return validOutputTypes[outputType](value);
|
12285 | }
|
12286 | };
|
12287 |
|
12288 | numeric.toTex = function (node, options) {
|
12289 |
|
12290 | return node.args[0].toTex();
|
12291 | };
|
12292 |
|
12293 | return numeric;
|
12294 | }
|
12295 |
|
12296 |
|
12297 |
|
12298 | exports.path = 'type';
|
12299 | exports.name = '_numeric';
|
12300 | exports.factory = factory;
|
12301 |
|
12302 | }),
|
12303 |
|
12304 | (function(module, exports, __webpack_require__) {
|
12305 |
|
12306 | "use strict";
|
12307 |
|
12308 |
|
12309 | var DimensionError = __webpack_require__(8);
|
12310 |
|
12311 | function factory(type, config, load, typed) {
|
12312 | var equalScalar = load(__webpack_require__(11));
|
12313 | var SparseMatrix = type.SparseMatrix;
|
12314 | |
12315 |
|
12316 |
|
12317 |
|
12318 |
|
12319 |
|
12320 |
|
12321 |
|
12322 |
|
12323 |
|
12324 |
|
12325 |
|
12326 |
|
12327 |
|
12328 |
|
12329 |
|
12330 |
|
12331 |
|
12332 |
|
12333 | var algorithm05 = function algorithm05(a, b, callback) {
|
12334 |
|
12335 | var avalues = a._values;
|
12336 | var aindex = a._index;
|
12337 | var aptr = a._ptr;
|
12338 | var asize = a._size;
|
12339 | var adt = a._datatype;
|
12340 |
|
12341 | var bvalues = b._values;
|
12342 | var bindex = b._index;
|
12343 | var bptr = b._ptr;
|
12344 | var bsize = b._size;
|
12345 | var bdt = b._datatype;
|
12346 |
|
12347 | if (asize.length !== bsize.length) {
|
12348 | throw new DimensionError(asize.length, bsize.length);
|
12349 | }
|
12350 |
|
12351 |
|
12352 | if (asize[0] !== bsize[0] || asize[1] !== bsize[1]) {
|
12353 | throw new RangeError('Dimension mismatch. Matrix A (' + asize + ') must match Matrix B (' + bsize + ')');
|
12354 | }
|
12355 |
|
12356 |
|
12357 | var rows = asize[0];
|
12358 | var columns = asize[1];
|
12359 |
|
12360 | var dt;
|
12361 |
|
12362 | var eq = equalScalar;
|
12363 |
|
12364 | var zero = 0;
|
12365 |
|
12366 | var cf = callback;
|
12367 |
|
12368 | if (typeof adt === 'string' && adt === bdt) {
|
12369 |
|
12370 | dt = adt;
|
12371 |
|
12372 | eq = typed.find(equalScalar, [dt, dt]);
|
12373 |
|
12374 | zero = typed.convert(0, dt);
|
12375 |
|
12376 | cf = typed.find(callback, [dt, dt]);
|
12377 | }
|
12378 |
|
12379 |
|
12380 | var cvalues = avalues && bvalues ? [] : undefined;
|
12381 | var cindex = [];
|
12382 | var cptr = [];
|
12383 |
|
12384 | var c = new SparseMatrix({
|
12385 | values: cvalues,
|
12386 | index: cindex,
|
12387 | ptr: cptr,
|
12388 | size: [rows, columns],
|
12389 | datatype: dt
|
12390 | });
|
12391 |
|
12392 | var xa = cvalues ? [] : undefined;
|
12393 | var xb = cvalues ? [] : undefined;
|
12394 |
|
12395 | var wa = [];
|
12396 | var wb = [];
|
12397 |
|
12398 | var i, j, k, k1;
|
12399 |
|
12400 | for (j = 0; j < columns; j++) {
|
12401 |
|
12402 | cptr[j] = cindex.length;
|
12403 |
|
12404 | var mark = j + 1;
|
12405 |
|
12406 | for (k = aptr[j], k1 = aptr[j + 1]; k < k1; k++) {
|
12407 |
|
12408 | i = aindex[k];
|
12409 |
|
12410 | cindex.push(i);
|
12411 |
|
12412 | wa[i] = mark;
|
12413 |
|
12414 | if (xa) {
|
12415 | xa[i] = avalues[k];
|
12416 | }
|
12417 | }
|
12418 |
|
12419 |
|
12420 | for (k = bptr[j], k1 = bptr[j + 1]; k < k1; k++) {
|
12421 |
|
12422 | i = bindex[k];
|
12423 |
|
12424 | if (wa[i] !== mark) {
|
12425 |
|
12426 | cindex.push(i);
|
12427 | }
|
12428 |
|
12429 |
|
12430 | wb[i] = mark;
|
12431 |
|
12432 | if (xb) {
|
12433 | xb[i] = bvalues[k];
|
12434 | }
|
12435 | }
|
12436 |
|
12437 |
|
12438 | if (cvalues) {
|
12439 |
|
12440 | k = cptr[j];
|
12441 |
|
12442 | while (k < cindex.length) {
|
12443 |
|
12444 | i = cindex[k];
|
12445 |
|
12446 | var wai = wa[i];
|
12447 | var wbi = wb[i];
|
12448 |
|
12449 | if (wai === mark || wbi === mark) {
|
12450 |
|
12451 | var va = wai === mark ? xa[i] : zero;
|
12452 | var vb = wbi === mark ? xb[i] : zero;
|
12453 |
|
12454 | var vc = cf(va, vb);
|
12455 |
|
12456 | if (!eq(vc, zero)) {
|
12457 |
|
12458 | cvalues.push(vc);
|
12459 |
|
12460 | k++;
|
12461 | } else {
|
12462 |
|
12463 | cindex.splice(k, 1);
|
12464 | }
|
12465 | }
|
12466 | }
|
12467 | }
|
12468 | }
|
12469 |
|
12470 |
|
12471 | cptr[columns] = cindex.length;
|
12472 |
|
12473 | return c;
|
12474 | };
|
12475 |
|
12476 | return algorithm05;
|
12477 | }
|
12478 |
|
12479 | exports.name = 'algorithm05';
|
12480 | exports.factory = factory;
|
12481 |
|
12482 | }),
|
12483 |
|
12484 | (function(module, exports, __webpack_require__) {
|
12485 |
|
12486 | "use strict";
|
12487 |
|
12488 |
|
12489 | var isInteger = __webpack_require__(3).isInteger;
|
12490 |
|
12491 | var toFixed = __webpack_require__(3).toFixed;
|
12492 |
|
12493 | var deepMap = __webpack_require__(1);
|
12494 |
|
12495 | var NO_INT = 'Number of decimals in function round must be an integer';
|
12496 |
|
12497 | function factory(type, config, load, typed) {
|
12498 | var matrix = load(__webpack_require__(0));
|
12499 | var equalScalar = load(__webpack_require__(11));
|
12500 | var zeros = load(__webpack_require__(43));
|
12501 | var algorithm11 = load(__webpack_require__(20));
|
12502 | var algorithm12 = load(__webpack_require__(19));
|
12503 | var algorithm14 = load(__webpack_require__(6));
|
12504 | |
12505 |
|
12506 |
|
12507 |
|
12508 |
|
12509 |
|
12510 |
|
12511 |
|
12512 |
|
12513 |
|
12514 |
|
12515 |
|
12516 |
|
12517 |
|
12518 |
|
12519 |
|
12520 |
|
12521 |
|
12522 |
|
12523 |
|
12524 |
|
12525 |
|
12526 |
|
12527 |
|
12528 |
|
12529 |
|
12530 |
|
12531 |
|
12532 |
|
12533 |
|
12534 |
|
12535 |
|
12536 | var round = typed('round', {
|
12537 | 'number': function number(x) {
|
12538 | return _round(x, 0);
|
12539 | },
|
12540 | 'number, number': function numberNumber(x, n) {
|
12541 | if (!isInteger(n)) {
|
12542 | throw new TypeError(NO_INT);
|
12543 | }
|
12544 |
|
12545 | if (n < 0 || n > 15) {
|
12546 | throw new Error('Number of decimals in function round must be in te range of 0-15');
|
12547 | }
|
12548 |
|
12549 | return _round(x, n);
|
12550 | },
|
12551 | 'Complex': function Complex(x) {
|
12552 | return x.round();
|
12553 | },
|
12554 | 'Complex, number': function ComplexNumber(x, n) {
|
12555 | if (n % 1) {
|
12556 | throw new TypeError(NO_INT);
|
12557 | }
|
12558 |
|
12559 | return x.round(n);
|
12560 | },
|
12561 | 'Complex, BigNumber': function ComplexBigNumber(x, n) {
|
12562 | if (!n.isInteger()) {
|
12563 | throw new TypeError(NO_INT);
|
12564 | }
|
12565 |
|
12566 | var _n = n.toNumber();
|
12567 |
|
12568 | return x.round(_n);
|
12569 | },
|
12570 | 'number, BigNumber': function numberBigNumber(x, n) {
|
12571 | if (!n.isInteger()) {
|
12572 | throw new TypeError(NO_INT);
|
12573 | }
|
12574 |
|
12575 | return new type.BigNumber(x).toDecimalPlaces(n.toNumber());
|
12576 | },
|
12577 | 'BigNumber': function BigNumber(x) {
|
12578 | return x.toDecimalPlaces(0);
|
12579 | },
|
12580 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, n) {
|
12581 | if (!n.isInteger()) {
|
12582 | throw new TypeError(NO_INT);
|
12583 | }
|
12584 |
|
12585 | return x.toDecimalPlaces(n.toNumber());
|
12586 | },
|
12587 | 'Fraction': function Fraction(x) {
|
12588 | return x.round();
|
12589 | },
|
12590 | 'Fraction, number': function FractionNumber(x, n) {
|
12591 | if (n % 1) {
|
12592 | throw new TypeError(NO_INT);
|
12593 | }
|
12594 |
|
12595 | return x.round(n);
|
12596 | },
|
12597 | 'Array | Matrix': function ArrayMatrix(x) {
|
12598 |
|
12599 | return deepMap(x, round, true);
|
12600 | },
|
12601 | 'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
12602 | return algorithm11(x, y, round, false);
|
12603 | },
|
12604 | 'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
12605 | return algorithm14(x, y, round, false);
|
12606 | },
|
12607 | 'number | Complex | BigNumber, SparseMatrix': function numberComplexBigNumberSparseMatrix(x, y) {
|
12608 |
|
12609 | if (equalScalar(x, 0)) {
|
12610 |
|
12611 | return zeros(y.size(), y.storage());
|
12612 | }
|
12613 |
|
12614 | return algorithm12(y, x, round, true);
|
12615 | },
|
12616 | 'number | Complex | BigNumber, DenseMatrix': function numberComplexBigNumberDenseMatrix(x, y) {
|
12617 |
|
12618 | if (equalScalar(x, 0)) {
|
12619 |
|
12620 | return zeros(y.size(), y.storage());
|
12621 | }
|
12622 |
|
12623 | return algorithm14(y, x, round, true);
|
12624 | },
|
12625 | 'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
|
12626 |
|
12627 | return algorithm14(matrix(x), y, round, false).valueOf();
|
12628 | },
|
12629 | 'number | Complex | BigNumber, Array': function numberComplexBigNumberArray(x, y) {
|
12630 |
|
12631 | return algorithm14(matrix(y), x, round, true).valueOf();
|
12632 | }
|
12633 | });
|
12634 | round.toTex = {
|
12635 | 1: "\\left\\lfloor${args[0]}\\right\\rceil",
|
12636 | 2: undefined
|
12637 |
|
12638 | };
|
12639 | return round;
|
12640 | }
|
12641 |
|
12642 |
|
12643 |
|
12644 |
|
12645 |
|
12646 |
|
12647 |
|
12648 |
|
12649 |
|
12650 |
|
12651 | function _round(value, decimals) {
|
12652 | return parseFloat(toFixed(value, decimals));
|
12653 | }
|
12654 |
|
12655 | exports.name = 'round';
|
12656 | exports.factory = factory;
|
12657 |
|
12658 | }),
|
12659 |
|
12660 | (function(module, exports, __webpack_require__) {
|
12661 |
|
12662 | "use strict";
|
12663 |
|
12664 |
|
12665 | function factory(type, config, load, typed) {
|
12666 | var Node = load(__webpack_require__(16));
|
12667 | |
12668 |
|
12669 |
|
12670 |
|
12671 |
|
12672 |
|
12673 |
|
12674 |
|
12675 | function ParenthesisNode(content) {
|
12676 | if (!(this instanceof ParenthesisNode)) {
|
12677 | throw new SyntaxError('Constructor must be called with the new operator');
|
12678 | }
|
12679 |
|
12680 |
|
12681 | if (!type.isNode(content)) {
|
12682 | throw new TypeError('Node expected for parameter "content"');
|
12683 | }
|
12684 |
|
12685 | this.content = content;
|
12686 | }
|
12687 |
|
12688 | ParenthesisNode.prototype = new Node();
|
12689 | ParenthesisNode.prototype.type = 'ParenthesisNode';
|
12690 | ParenthesisNode.prototype.isParenthesisNode = true;
|
12691 | |
12692 |
|
12693 |
|
12694 |
|
12695 |
|
12696 |
|
12697 |
|
12698 |
|
12699 |
|
12700 |
|
12701 |
|
12702 |
|
12703 |
|
12704 |
|
12705 | ParenthesisNode.prototype._compile = function (math, argNames) {
|
12706 | return this.content._compile(math, argNames);
|
12707 | };
|
12708 | |
12709 |
|
12710 |
|
12711 |
|
12712 |
|
12713 |
|
12714 |
|
12715 | ParenthesisNode.prototype.getContent = function () {
|
12716 | return this.content.getContent();
|
12717 | };
|
12718 | |
12719 |
|
12720 |
|
12721 |
|
12722 |
|
12723 |
|
12724 | ParenthesisNode.prototype.forEach = function (callback) {
|
12725 | callback(this.content, 'content', this);
|
12726 | };
|
12727 | |
12728 |
|
12729 |
|
12730 |
|
12731 |
|
12732 |
|
12733 |
|
12734 |
|
12735 | ParenthesisNode.prototype.map = function (callback) {
|
12736 | var content = callback(this.content, 'content', this);
|
12737 | return new ParenthesisNode(content);
|
12738 | };
|
12739 | |
12740 |
|
12741 |
|
12742 |
|
12743 |
|
12744 |
|
12745 | ParenthesisNode.prototype.clone = function () {
|
12746 | return new ParenthesisNode(this.content);
|
12747 | };
|
12748 | |
12749 |
|
12750 |
|
12751 |
|
12752 |
|
12753 |
|
12754 |
|
12755 |
|
12756 | ParenthesisNode.prototype._toString = function (options) {
|
12757 | if (!options || options && !options.parenthesis || options && options.parenthesis === 'keep') {
|
12758 | return '(' + this.content.toString(options) + ')';
|
12759 | }
|
12760 |
|
12761 | return this.content.toString(options);
|
12762 | };
|
12763 | |
12764 |
|
12765 |
|
12766 |
|
12767 |
|
12768 |
|
12769 | ParenthesisNode.prototype.toJSON = function () {
|
12770 | return {
|
12771 | mathjs: 'ParenthesisNode',
|
12772 | content: this.content
|
12773 | };
|
12774 | };
|
12775 | |
12776 |
|
12777 |
|
12778 |
|
12779 |
|
12780 |
|
12781 |
|
12782 |
|
12783 |
|
12784 | ParenthesisNode.fromJSON = function (json) {
|
12785 | return new ParenthesisNode(json.content);
|
12786 | };
|
12787 | |
12788 |
|
12789 |
|
12790 |
|
12791 |
|
12792 |
|
12793 |
|
12794 |
|
12795 | ParenthesisNode.prototype.toHTML = function (options) {
|
12796 | if (!options || options && !options.parenthesis || options && options.parenthesis === 'keep') {
|
12797 | return '<span class="math-parenthesis math-round-parenthesis">(</span>' + this.content.toHTML(options) + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
12798 | }
|
12799 |
|
12800 | return this.content.toHTML(options);
|
12801 | };
|
12802 | |
12803 |
|
12804 |
|
12805 |
|
12806 |
|
12807 |
|
12808 |
|
12809 |
|
12810 | ParenthesisNode.prototype._toTex = function (options) {
|
12811 | if (!options || options && !options.parenthesis || options && options.parenthesis === 'keep') {
|
12812 | return "\\left(".concat(this.content.toTex(options), "\\right)");
|
12813 | }
|
12814 |
|
12815 | return this.content.toTex(options);
|
12816 | };
|
12817 |
|
12818 | return ParenthesisNode;
|
12819 | }
|
12820 |
|
12821 | exports.name = 'ParenthesisNode';
|
12822 | exports.path = 'expression.node';
|
12823 | exports.factory = factory;
|
12824 |
|
12825 | }),
|
12826 |
|
12827 | (function(module, exports, __webpack_require__) {
|
12828 |
|
12829 | "use strict";
|
12830 |
|
12831 |
|
12832 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
12833 |
|
12834 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
12835 |
|
12836 | var latex = __webpack_require__(4);
|
12837 |
|
12838 | var escape = __webpack_require__(9).escape;
|
12839 |
|
12840 | var hasOwnProperty = __webpack_require__(5).hasOwnProperty;
|
12841 |
|
12842 | var map = __webpack_require__(2).map;
|
12843 |
|
12844 | var validateSafeMethod = __webpack_require__(13).validateSafeMethod;
|
12845 |
|
12846 | var getSafeProperty = __webpack_require__(13).getSafeProperty;
|
12847 |
|
12848 | function factory(type, config, load, typed, math) {
|
12849 | var Node = load(__webpack_require__(16));
|
12850 | var SymbolNode = load(__webpack_require__(54));
|
12851 | |
12852 |
|
12853 |
|
12854 |
|
12855 |
|
12856 |
|
12857 |
|
12858 |
|
12859 |
|
12860 | function FunctionNode(fn, args) {
|
12861 | if (!(this instanceof FunctionNode)) {
|
12862 | throw new SyntaxError('Constructor must be called with the new operator');
|
12863 | }
|
12864 |
|
12865 | if (typeof fn === 'string') {
|
12866 | fn = new SymbolNode(fn);
|
12867 | }
|
12868 |
|
12869 |
|
12870 | if (!type.isNode(fn)) throw new TypeError('Node expected as parameter "fn"');
|
12871 |
|
12872 | if (!Array.isArray(args) || !args.every(type.isNode)) {
|
12873 | throw new TypeError('Array containing Nodes expected for parameter "args"');
|
12874 | }
|
12875 |
|
12876 | this.fn = fn;
|
12877 | this.args = args || [];
|
12878 |
|
12879 | Object.defineProperty(this, 'name', {
|
12880 | get: function () {
|
12881 | return this.fn.name || '';
|
12882 | }.bind(this),
|
12883 | set: function set() {
|
12884 | throw new Error('Cannot assign a new name, name is read-only');
|
12885 | }
|
12886 | });
|
12887 |
|
12888 | var deprecated = function deprecated() {
|
12889 | throw new Error('Property `FunctionNode.object` is deprecated, use `FunctionNode.fn` instead');
|
12890 | };
|
12891 |
|
12892 | Object.defineProperty(this, 'object', {
|
12893 | get: deprecated,
|
12894 | set: deprecated
|
12895 | });
|
12896 | }
|
12897 |
|
12898 | FunctionNode.prototype = new Node();
|
12899 | FunctionNode.prototype.type = 'FunctionNode';
|
12900 | FunctionNode.prototype.isFunctionNode = true;
|
12901 | /**
|
12902 | * Compile a node into a JavaScript function.
|
12903 | * This basically pre-calculates as much as possible and only leaves open
|
12904 | * calculations which depend on a dynamic scope with variables.
|
12905 | * @param {Object} math Math.js namespace with functions and constants.
|
12906 | * @param {Object} argNames An object with argument names as key and `true`
|
12907 | * as value. Used in the SymbolNode to optimize
|
12908 | * for arguments from user assigned functions
|
12909 | * (see FunctionAssignmentNode) or special symbols
|
12910 | * like `end` (see IndexNode).
|
12911 | * @return {function} Returns a function which can be called like:
|
12912 | * evalNode(scope: Object, args: Object, context: *)
|
12913 | */
|
12914 |
|
12915 | FunctionNode.prototype._compile = function (math, argNames) {
|
12916 | if (!(this instanceof FunctionNode)) {
|
12917 | throw new TypeError('No valid FunctionNode');
|
12918 | }
|
12919 |
|
12920 |
|
12921 | var evalArgs = map(this.args, function (arg) {
|
12922 | return arg._compile(math, argNames);
|
12923 | });
|
12924 |
|
12925 | if (type.isSymbolNode(this.fn)) {
|
12926 |
|
12927 | var name = this.fn.name;
|
12928 | var fn = name in math ? getSafeProperty(math, name) : undefined;
|
12929 | var isRaw = typeof fn === 'function' && fn.rawArgs === true;
|
12930 |
|
12931 | if (isRaw) {
|
12932 |
|
12933 |
|
12934 | var rawArgs = this.args;
|
12935 | return function evalFunctionNode(scope, args, context) {
|
12936 | return (name in scope ? getSafeProperty(scope, name) : fn)(rawArgs, math, _extends({}, scope, args));
|
12937 | };
|
12938 | } else {
|
12939 |
|
12940 | if (evalArgs.length === 1) {
|
12941 | var evalArg0 = evalArgs[0];
|
12942 | return function evalFunctionNode(scope, args, context) {
|
12943 | return (name in scope ? getSafeProperty(scope, name) : fn)(evalArg0(scope, args, context));
|
12944 | };
|
12945 | } else if (evalArgs.length === 2) {
|
12946 | var _evalArg = evalArgs[0];
|
12947 | var evalArg1 = evalArgs[1];
|
12948 | return function evalFunctionNode(scope, args, context) {
|
12949 | return (name in scope ? getSafeProperty(scope, name) : fn)(_evalArg(scope, args, context), evalArg1(scope, args, context));
|
12950 | };
|
12951 | } else {
|
12952 | return function evalFunctionNode(scope, args, context) {
|
12953 | return (name in scope ? getSafeProperty(scope, name) : fn).apply(null, map(evalArgs, function (evalArg) {
|
12954 | return evalArg(scope, args, context);
|
12955 | }));
|
12956 | };
|
12957 | }
|
12958 | }
|
12959 | } else if (type.isAccessorNode(this.fn) && type.isIndexNode(this.fn.index) && this.fn.index.isObjectProperty()) {
|
12960 |
|
12961 | var evalObject = this.fn.object._compile(math, argNames);
|
12962 |
|
12963 | var prop = this.fn.index.getObjectProperty();
|
12964 | var _rawArgs = this.args;
|
12965 | return function evalFunctionNode(scope, args, context) {
|
12966 | var object = evalObject(scope, args, context);
|
12967 | validateSafeMethod(object, prop);
|
12968 | var isRaw = object[prop] && object[prop].rawArgs;
|
12969 | return isRaw ? object[prop](_rawArgs, math, _extends({}, scope, args))
|
12970 | : object[prop].apply(object, map(evalArgs, function (evalArg) {
|
12971 |
|
12972 | return evalArg(scope, args, context);
|
12973 | }));
|
12974 | };
|
12975 | } else {
|
12976 |
|
12977 |
|
12978 | var evalFn = this.fn._compile(math, argNames);
|
12979 |
|
12980 | var _rawArgs2 = this.args;
|
12981 | return function evalFunctionNode(scope, args, context) {
|
12982 | var fn = evalFn(scope, args, context);
|
12983 | var isRaw = fn && fn.rawArgs;
|
12984 | return isRaw ? fn(_rawArgs2, math, _extends({}, scope, args))
|
12985 | : fn.apply(fn, map(evalArgs, function (evalArg) {
|
12986 |
|
12987 | return evalArg(scope, args, context);
|
12988 | }));
|
12989 | };
|
12990 | }
|
12991 | };
|
12992 | |
12993 |
|
12994 |
|
12995 |
|
12996 |
|
12997 |
|
12998 | FunctionNode.prototype.forEach = function (callback) {
|
12999 | callback(this.fn, 'fn', this);
|
13000 |
|
13001 | for (var i = 0; i < this.args.length; i++) {
|
13002 | callback(this.args[i], 'args[' + i + ']', this);
|
13003 | }
|
13004 | };
|
13005 | |
13006 |
|
13007 |
|
13008 |
|
13009 |
|
13010 |
|
13011 |
|
13012 |
|
13013 | FunctionNode.prototype.map = function (callback) {
|
13014 | var fn = this._ifNode(callback(this.fn, 'fn', this));
|
13015 |
|
13016 | var args = [];
|
13017 |
|
13018 | for (var i = 0; i < this.args.length; i++) {
|
13019 | args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
|
13020 | }
|
13021 |
|
13022 | return new FunctionNode(fn, args);
|
13023 | };
|
13024 | |
13025 |
|
13026 |
|
13027 |
|
13028 |
|
13029 |
|
13030 | FunctionNode.prototype.clone = function () {
|
13031 | return new FunctionNode(this.fn, this.args.slice(0));
|
13032 | };
|
13033 |
|
13034 |
|
13035 |
|
13036 | var nodeToString = FunctionNode.prototype.toString;
|
13037 | |
13038 |
|
13039 |
|
13040 |
|
13041 |
|
13042 |
|
13043 |
|
13044 |
|
13045 |
|
13046 |
|
13047 |
|
13048 |
|
13049 |
|
13050 | FunctionNode.prototype.toString = function (options) {
|
13051 | var customString;
|
13052 | var name = this.fn.toString(options);
|
13053 |
|
13054 | if (options && _typeof(options.handler) === 'object' && hasOwnProperty(options.handler, name)) {
|
13055 |
|
13056 | customString = options.handler[name](this, options);
|
13057 | }
|
13058 |
|
13059 | if (typeof customString !== 'undefined') {
|
13060 | return customString;
|
13061 | }
|
13062 |
|
13063 |
|
13064 | return nodeToString.call(this, options);
|
13065 | };
|
13066 | |
13067 |
|
13068 |
|
13069 |
|
13070 |
|
13071 |
|
13072 |
|
13073 | FunctionNode.prototype._toString = function (options) {
|
13074 | var args = this.args.map(function (arg) {
|
13075 | return arg.toString(options);
|
13076 | });
|
13077 | var fn = type.isFunctionAssignmentNode(this.fn) ? '(' + this.fn.toString(options) + ')' : this.fn.toString(options);
|
13078 |
|
13079 | return fn + '(' + args.join(', ') + ')';
|
13080 | };
|
13081 | |
13082 |
|
13083 |
|
13084 |
|
13085 |
|
13086 |
|
13087 | FunctionNode.prototype.toJSON = function () {
|
13088 | return {
|
13089 | mathjs: 'FunctionNode',
|
13090 | fn: this.fn,
|
13091 | args: this.args
|
13092 | };
|
13093 | };
|
13094 | |
13095 |
|
13096 |
|
13097 |
|
13098 |
|
13099 |
|
13100 |
|
13101 |
|
13102 |
|
13103 | FunctionNode.fromJSON = function (json) {
|
13104 | return new FunctionNode(json.fn, json.args);
|
13105 | };
|
13106 | |
13107 |
|
13108 |
|
13109 |
|
13110 |
|
13111 |
|
13112 |
|
13113 | FunctionNode.prototype.toHTML = function (options) {
|
13114 | var args = this.args.map(function (arg) {
|
13115 | return arg.toHTML(options);
|
13116 | });
|
13117 |
|
13118 | return '<span class="math-function">' + escape(this.fn) + '</span><span class="math-paranthesis math-round-parenthesis">(</span>' + args.join('<span class="math-separator">,</span>') + '<span class="math-paranthesis math-round-parenthesis">)</span>';
|
13119 | };
|
13120 | |
13121 |
|
13122 |
|
13123 |
|
13124 |
|
13125 |
|
13126 |
|
13127 |
|
13128 |
|
13129 |
|
13130 | function expandTemplate(template, node, options) {
|
13131 | var latex = '';
|
13132 |
|
13133 |
|
13134 | var regex = new RegExp('\\$(?:\\{([a-z_][a-z_0-9]*)(?:\\[([0-9]+)\\])?\\}|\\$)', 'ig');
|
13135 | var inputPos = 0;
|
13136 |
|
13137 | var match;
|
13138 |
|
13139 | while ((match = regex.exec(template)) !== null) {
|
13140 |
|
13141 |
|
13142 | latex += template.substring(inputPos, match.index);
|
13143 | inputPos = match.index;
|
13144 |
|
13145 | if (match[0] === '$$') {
|
13146 |
|
13147 | latex += '$';
|
13148 | inputPos++;
|
13149 | } else {
|
13150 |
|
13151 | inputPos += match[0].length;
|
13152 | var property = node[match[1]];
|
13153 |
|
13154 | if (!property) {
|
13155 | throw new ReferenceError('Template: Property ' + match[1] + ' does not exist.');
|
13156 | }
|
13157 |
|
13158 | if (match[2] === undefined) {
|
13159 |
|
13160 | switch (_typeof(property)) {
|
13161 | case 'string':
|
13162 | latex += property;
|
13163 | break;
|
13164 |
|
13165 | case 'object':
|
13166 | if (type.isNode(property)) {
|
13167 | latex += property.toTex(options);
|
13168 | } else if (Array.isArray(property)) {
|
13169 |
|
13170 | latex += property.map(function (arg, index) {
|
13171 | if (type.isNode(arg)) {
|
13172 | return arg.toTex(options);
|
13173 | }
|
13174 |
|
13175 | throw new TypeError('Template: ' + match[1] + '[' + index + '] is not a Node.');
|
13176 | }).join(',');
|
13177 | } else {
|
13178 | throw new TypeError('Template: ' + match[1] + ' has to be a Node, String or array of Nodes');
|
13179 | }
|
13180 |
|
13181 | break;
|
13182 |
|
13183 | default:
|
13184 | throw new TypeError('Template: ' + match[1] + ' has to be a Node, String or array of Nodes');
|
13185 | }
|
13186 | } else {
|
13187 |
|
13188 | if (type.isNode(property[match[2]] && property[match[2]])) {
|
13189 | latex += property[match[2]].toTex(options);
|
13190 | } else {
|
13191 | throw new TypeError('Template: ' + match[1] + '[' + match[2] + '] is not a Node.');
|
13192 | }
|
13193 | }
|
13194 | }
|
13195 | }
|
13196 |
|
13197 | latex += template.slice(inputPos);
|
13198 |
|
13199 | return latex;
|
13200 | }
|
13201 |
|
13202 |
|
13203 |
|
13204 | var nodeToTex = FunctionNode.prototype.toTex;
|
13205 | |
13206 |
|
13207 |
|
13208 |
|
13209 |
|
13210 |
|
13211 |
|
13212 |
|
13213 |
|
13214 |
|
13215 |
|
13216 |
|
13217 | FunctionNode.prototype.toTex = function (options) {
|
13218 | var customTex;
|
13219 |
|
13220 | if (options && _typeof(options.handler) === 'object' && hasOwnProperty(options.handler, this.name)) {
|
13221 |
|
13222 | customTex = options.handler[this.name](this, options);
|
13223 | }
|
13224 |
|
13225 | if (typeof customTex !== 'undefined') {
|
13226 | return customTex;
|
13227 | }
|
13228 |
|
13229 |
|
13230 | return nodeToTex.call(this, options);
|
13231 | };
|
13232 | |
13233 |
|
13234 |
|
13235 |
|
13236 |
|
13237 |
|
13238 |
|
13239 | FunctionNode.prototype._toTex = function (options) {
|
13240 | var args = this.args.map(function (arg) {
|
13241 |
|
13242 | return arg.toTex(options);
|
13243 | });
|
13244 | var latexConverter;
|
13245 |
|
13246 | if (math[this.name] && (typeof math[this.name].toTex === 'function' || _typeof(math[this.name].toTex) === 'object' || typeof math[this.name].toTex === 'string')) {
|
13247 |
|
13248 | latexConverter = math[this.name].toTex;
|
13249 | }
|
13250 |
|
13251 | var customToTex;
|
13252 |
|
13253 | switch (_typeof(latexConverter)) {
|
13254 | case 'function':
|
13255 |
|
13256 | customToTex = latexConverter(this, options);
|
13257 | break;
|
13258 |
|
13259 | case 'string':
|
13260 |
|
13261 | customToTex = expandTemplate(latexConverter, this, options);
|
13262 | break;
|
13263 |
|
13264 | case 'object':
|
13265 |
|
13266 | switch (_typeof(latexConverter[args.length])) {
|
13267 | case 'function':
|
13268 | customToTex = latexConverter[args.length](this, options);
|
13269 | break;
|
13270 |
|
13271 | case 'string':
|
13272 | customToTex = expandTemplate(latexConverter[args.length], this, options);
|
13273 | break;
|
13274 | }
|
13275 |
|
13276 | }
|
13277 |
|
13278 | if (typeof customToTex !== 'undefined') {
|
13279 | return customToTex;
|
13280 | }
|
13281 |
|
13282 | return expandTemplate(latex.defaultTemplate, this, options);
|
13283 | };
|
13284 | |
13285 |
|
13286 |
|
13287 |
|
13288 |
|
13289 |
|
13290 | FunctionNode.prototype.getIdentifier = function () {
|
13291 | return this.type + ':' + this.name;
|
13292 | };
|
13293 |
|
13294 | return FunctionNode;
|
13295 | }
|
13296 |
|
13297 | exports.name = 'FunctionNode';
|
13298 | exports.path = 'expression.node';
|
13299 | exports.math = true;
|
13300 |
|
13301 | exports.factory = factory;
|
13302 |
|
13303 | }),
|
13304 |
|
13305 | (function(module, exports, __webpack_require__) {
|
13306 |
|
13307 | "use strict";
|
13308 |
|
13309 |
|
13310 | var util = __webpack_require__(31);
|
13311 |
|
13312 | function factory(type, config, load, typed) {
|
13313 | var matrix = load(__webpack_require__(0));
|
13314 | var divideScalar = load(__webpack_require__(12));
|
13315 | var addScalar = load(__webpack_require__(17));
|
13316 | var multiply = load(__webpack_require__(10));
|
13317 | var unaryMinus = load(__webpack_require__(39));
|
13318 | var det = load(__webpack_require__(128));
|
13319 | var identity = load(__webpack_require__(50));
|
13320 | var abs = load(__webpack_require__(25));
|
13321 | |
13322 |
|
13323 |
|
13324 |
|
13325 |
|
13326 |
|
13327 |
|
13328 |
|
13329 |
|
13330 |
|
13331 |
|
13332 |
|
13333 |
|
13334 |
|
13335 |
|
13336 |
|
13337 |
|
13338 |
|
13339 |
|
13340 |
|
13341 |
|
13342 | var inv = typed('inv', {
|
13343 | 'Array | Matrix': function ArrayMatrix(x) {
|
13344 | var size = type.isMatrix(x) ? x.size() : util.array.size(x);
|
13345 |
|
13346 | switch (size.length) {
|
13347 | case 1:
|
13348 |
|
13349 | if (size[0] === 1) {
|
13350 | if (type.isMatrix(x)) {
|
13351 | return matrix([divideScalar(1, x.valueOf()[0])]);
|
13352 | } else {
|
13353 | return [divideScalar(1, x[0])];
|
13354 | }
|
13355 | } else {
|
13356 | throw new RangeError('Matrix must be square ' + '(size: ' + util.string.format(size) + ')');
|
13357 | }
|
13358 |
|
13359 | case 2:
|
13360 |
|
13361 | var rows = size[0];
|
13362 | var cols = size[1];
|
13363 |
|
13364 | if (rows === cols) {
|
13365 | if (type.isMatrix(x)) {
|
13366 | return matrix(_inv(x.valueOf(), rows, cols), x.storage());
|
13367 | } else {
|
13368 |
|
13369 | return _inv(x, rows, cols);
|
13370 | }
|
13371 | } else {
|
13372 | throw new RangeError('Matrix must be square ' + '(size: ' + util.string.format(size) + ')');
|
13373 | }
|
13374 |
|
13375 | default:
|
13376 |
|
13377 | throw new RangeError('Matrix must be two dimensional ' + '(size: ' + util.string.format(size) + ')');
|
13378 | }
|
13379 | },
|
13380 | 'any': function any(x) {
|
13381 |
|
13382 | return divideScalar(1, x);
|
13383 | }
|
13384 | });
|
13385 | |
13386 |
|
13387 |
|
13388 |
|
13389 |
|
13390 |
|
13391 |
|
13392 |
|
13393 |
|
13394 | function _inv(mat, rows, cols) {
|
13395 | var r, s, f, value, temp;
|
13396 |
|
13397 | if (rows === 1) {
|
13398 |
|
13399 | value = mat[0][0];
|
13400 |
|
13401 | if (value === 0) {
|
13402 | throw Error('Cannot calculate inverse, determinant is zero');
|
13403 | }
|
13404 |
|
13405 | return [[divideScalar(1, value)]];
|
13406 | } else if (rows === 2) {
|
13407 |
|
13408 | var d = det(mat);
|
13409 |
|
13410 | if (d === 0) {
|
13411 | throw Error('Cannot calculate inverse, determinant is zero');
|
13412 | }
|
13413 |
|
13414 | return [[divideScalar(mat[1][1], d), divideScalar(unaryMinus(mat[0][1]), d)], [divideScalar(unaryMinus(mat[1][0]), d), divideScalar(mat[0][0], d)]];
|
13415 | } else {
|
13416 |
|
13417 |
|
13418 |
|
13419 |
|
13420 |
|
13421 |
|
13422 | var A = mat.concat();
|
13423 |
|
13424 | for (r = 0; r < rows; r++) {
|
13425 | A[r] = A[r].concat();
|
13426 | }
|
13427 |
|
13428 |
|
13429 |
|
13430 | var B = identity(rows).valueOf();
|
13431 |
|
13432 | for (var c = 0; c < cols; c++) {
|
13433 |
|
13434 | var ABig = abs(A[c][c]);
|
13435 | var rBig = c;
|
13436 | r = c + 1;
|
13437 |
|
13438 | while (r < rows) {
|
13439 | if (abs(A[r][c]) > ABig) {
|
13440 | ABig = abs(A[r][c]);
|
13441 | rBig = r;
|
13442 | }
|
13443 |
|
13444 | r++;
|
13445 | }
|
13446 |
|
13447 | if (ABig === 0) {
|
13448 | throw Error('Cannot calculate inverse, determinant is zero');
|
13449 | }
|
13450 |
|
13451 | r = rBig;
|
13452 |
|
13453 | if (r !== c) {
|
13454 | temp = A[c];
|
13455 | A[c] = A[r];
|
13456 | A[r] = temp;
|
13457 | temp = B[c];
|
13458 | B[c] = B[r];
|
13459 | B[r] = temp;
|
13460 | }
|
13461 |
|
13462 |
|
13463 | var Ac = A[c];
|
13464 | var Bc = B[c];
|
13465 |
|
13466 | for (r = 0; r < rows; r++) {
|
13467 | var Ar = A[r];
|
13468 | var Br = B[r];
|
13469 |
|
13470 | if (r !== c) {
|
13471 |
|
13472 | if (Ar[c] !== 0) {
|
13473 | f = divideScalar(unaryMinus(Ar[c]), Ac[c]);
|
13474 |
|
13475 |
|
13476 | for (s = c; s < cols; s++) {
|
13477 | Ar[s] = addScalar(Ar[s], multiply(f, Ac[s]));
|
13478 | }
|
13479 |
|
13480 | for (s = 0; s < cols; s++) {
|
13481 | Br[s] = addScalar(Br[s], multiply(f, Bc[s]));
|
13482 | }
|
13483 | }
|
13484 | } else {
|
13485 |
|
13486 |
|
13487 | f = Ac[c];
|
13488 |
|
13489 | for (s = c; s < cols; s++) {
|
13490 | Ar[s] = divideScalar(Ar[s], f);
|
13491 | }
|
13492 |
|
13493 | for (s = 0; s < cols; s++) {
|
13494 | Br[s] = divideScalar(Br[s], f);
|
13495 | }
|
13496 | }
|
13497 | }
|
13498 | }
|
13499 |
|
13500 | return B;
|
13501 | }
|
13502 | }
|
13503 |
|
13504 | inv.toTex = {
|
13505 | 1: "\\left(${args[0]}\\right)^{-1}"
|
13506 | };
|
13507 | return inv;
|
13508 | }
|
13509 |
|
13510 | exports.name = 'inv';
|
13511 | exports.factory = factory;
|
13512 |
|
13513 | }),
|
13514 |
|
13515 | (function(module, exports, __webpack_require__) {
|
13516 |
|
13517 | "use strict";
|
13518 |
|
13519 |
|
13520 | var deepMap = __webpack_require__(1);
|
13521 |
|
13522 | function factory(type, config, load, typed) {
|
13523 | |
13524 |
|
13525 |
|
13526 |
|
13527 |
|
13528 |
|
13529 |
|
13530 |
|
13531 |
|
13532 |
|
13533 |
|
13534 |
|
13535 |
|
13536 |
|
13537 |
|
13538 |
|
13539 |
|
13540 |
|
13541 |
|
13542 |
|
13543 |
|
13544 |
|
13545 |
|
13546 |
|
13547 |
|
13548 | var conj = typed('conj', {
|
13549 | 'number': function number(x) {
|
13550 | return x;
|
13551 | },
|
13552 | 'BigNumber': function BigNumber(x) {
|
13553 | return x;
|
13554 | },
|
13555 | 'Complex': function Complex(x) {
|
13556 | return x.conjugate();
|
13557 | },
|
13558 | 'Array | Matrix': function ArrayMatrix(x) {
|
13559 | return deepMap(x, conj);
|
13560 | }
|
13561 | });
|
13562 | conj.toTex = {
|
13563 | 1: "\\left(${args[0]}\\right)^*"
|
13564 | };
|
13565 | return conj;
|
13566 | }
|
13567 |
|
13568 | exports.name = 'conj';
|
13569 | exports.factory = factory;
|
13570 |
|
13571 | }),
|
13572 |
|
13573 | (function(module, exports, __webpack_require__) {
|
13574 |
|
13575 | "use strict";
|
13576 |
|
13577 |
|
13578 | var clone = __webpack_require__(5).clone;
|
13579 |
|
13580 | var format = __webpack_require__(9).format;
|
13581 |
|
13582 | function factory(type, config, load, typed) {
|
13583 | var latex = __webpack_require__(4);
|
13584 |
|
13585 | var matrix = load(__webpack_require__(0));
|
13586 | var DenseMatrix = type.DenseMatrix;
|
13587 | var SparseMatrix = type.SparseMatrix;
|
13588 | |
13589 |
|
13590 |
|
13591 |
|
13592 |
|
13593 |
|
13594 |
|
13595 |
|
13596 |
|
13597 |
|
13598 |
|
13599 |
|
13600 |
|
13601 |
|
13602 |
|
13603 |
|
13604 |
|
13605 |
|
13606 |
|
13607 |
|
13608 |
|
13609 |
|
13610 |
|
13611 | var transpose = typed('transpose', {
|
13612 | 'Array': function Array(x) {
|
13613 |
|
13614 | return transpose(matrix(x)).valueOf();
|
13615 | },
|
13616 | 'Matrix': function Matrix(x) {
|
13617 |
|
13618 | var size = x.size();
|
13619 |
|
13620 | var c;
|
13621 |
|
13622 | switch (size.length) {
|
13623 | case 1:
|
13624 |
|
13625 | c = x.clone();
|
13626 | break;
|
13627 |
|
13628 | case 2:
|
13629 |
|
13630 | var rows = size[0];
|
13631 | var columns = size[1];
|
13632 |
|
13633 | if (columns === 0) {
|
13634 |
|
13635 | throw new RangeError('Cannot transpose a 2D matrix with no columns (size: ' + format(size) + ')');
|
13636 | }
|
13637 |
|
13638 |
|
13639 | switch (x.storage()) {
|
13640 | case 'dense':
|
13641 | c = _denseTranspose(x, rows, columns);
|
13642 | break;
|
13643 |
|
13644 | case 'sparse':
|
13645 | c = _sparseTranspose(x, rows, columns);
|
13646 | break;
|
13647 | }
|
13648 |
|
13649 | break;
|
13650 |
|
13651 | default:
|
13652 |
|
13653 | throw new RangeError('Matrix must be a vector or two dimensional (size: ' + format(this._size) + ')');
|
13654 | }
|
13655 |
|
13656 | return c;
|
13657 | },
|
13658 |
|
13659 | 'any': function any(x) {
|
13660 | return clone(x);
|
13661 | }
|
13662 | });
|
13663 |
|
13664 | function _denseTranspose(m, rows, columns) {
|
13665 |
|
13666 | var data = m._data;
|
13667 |
|
13668 | var transposed = [];
|
13669 | var transposedRow;
|
13670 |
|
13671 | for (var j = 0; j < columns; j++) {
|
13672 |
|
13673 | transposedRow = transposed[j] = [];
|
13674 |
|
13675 | for (var i = 0; i < rows; i++) {
|
13676 |
|
13677 | transposedRow[i] = clone(data[i][j]);
|
13678 | }
|
13679 | }
|
13680 |
|
13681 |
|
13682 | return new DenseMatrix({
|
13683 | data: transposed,
|
13684 | size: [columns, rows],
|
13685 | datatype: m._datatype
|
13686 | });
|
13687 | }
|
13688 |
|
13689 | function _sparseTranspose(m, rows, columns) {
|
13690 |
|
13691 | var values = m._values;
|
13692 | var index = m._index;
|
13693 | var ptr = m._ptr;
|
13694 |
|
13695 | var cvalues = values ? [] : undefined;
|
13696 | var cindex = [];
|
13697 | var cptr = [];
|
13698 |
|
13699 | var w = [];
|
13700 |
|
13701 | for (var x = 0; x < rows; x++) {
|
13702 | w[x] = 0;
|
13703 | }
|
13704 |
|
13705 |
|
13706 | var p, l, j;
|
13707 |
|
13708 | for (p = 0, l = index.length; p < l; p++) {
|
13709 |
|
13710 | w[index[p]]++;
|
13711 | }
|
13712 |
|
13713 |
|
13714 | var sum = 0;
|
13715 |
|
13716 | for (var i = 0; i < rows; i++) {
|
13717 |
|
13718 | cptr.push(sum);
|
13719 |
|
13720 | sum += w[i];
|
13721 |
|
13722 | w[i] = cptr[i];
|
13723 | }
|
13724 |
|
13725 |
|
13726 | cptr.push(sum);
|
13727 |
|
13728 | for (j = 0; j < columns; j++) {
|
13729 |
|
13730 | for (var k0 = ptr[j], k1 = ptr[j + 1], k = k0; k < k1; k++) {
|
13731 |
|
13732 | var q = w[index[k]]++;
|
13733 |
|
13734 | cindex[q] = j;
|
13735 |
|
13736 | if (values) {
|
13737 | cvalues[q] = clone(values[k]);
|
13738 | }
|
13739 | }
|
13740 | }
|
13741 |
|
13742 |
|
13743 | return new SparseMatrix({
|
13744 | values: cvalues,
|
13745 | index: cindex,
|
13746 | ptr: cptr,
|
13747 | size: [columns, rows],
|
13748 | datatype: m._datatype
|
13749 | });
|
13750 | }
|
13751 |
|
13752 | transpose.toTex = {
|
13753 | 1: "\\left(${args[0]}\\right)".concat(latex.operators['transpose'])
|
13754 | };
|
13755 | return transpose;
|
13756 | }
|
13757 |
|
13758 | exports.name = 'transpose';
|
13759 | exports.factory = factory;
|
13760 |
|
13761 | }),
|
13762 |
|
13763 | (function(module, exports, __webpack_require__) {
|
13764 |
|
13765 | "use strict";
|
13766 |
|
13767 |
|
13768 | var deepMap = __webpack_require__(1);
|
13769 |
|
13770 | function factory(type, config, load, typed) {
|
13771 | |
13772 |
|
13773 |
|
13774 |
|
13775 |
|
13776 |
|
13777 |
|
13778 |
|
13779 |
|
13780 |
|
13781 |
|
13782 |
|
13783 |
|
13784 |
|
13785 |
|
13786 |
|
13787 |
|
13788 |
|
13789 |
|
13790 |
|
13791 |
|
13792 |
|
13793 |
|
13794 |
|
13795 |
|
13796 |
|
13797 |
|
13798 |
|
13799 |
|
13800 |
|
13801 |
|
13802 | var isPositive = typed('isPositive', {
|
13803 | 'number': function number(x) {
|
13804 | return x > 0;
|
13805 | },
|
13806 | 'BigNumber': function BigNumber(x) {
|
13807 | return !x.isNeg() && !x.isZero() && !x.isNaN();
|
13808 | },
|
13809 | 'Fraction': function Fraction(x) {
|
13810 | return x.s > 0 && x.n > 0;
|
13811 | },
|
13812 | 'Unit': function Unit(x) {
|
13813 | return isPositive(x.value);
|
13814 | },
|
13815 | 'Array | Matrix': function ArrayMatrix(x) {
|
13816 | return deepMap(x, isPositive);
|
13817 | }
|
13818 | });
|
13819 | return isPositive;
|
13820 | }
|
13821 |
|
13822 | exports.name = 'isPositive';
|
13823 | exports.factory = factory;
|
13824 |
|
13825 | }),
|
13826 |
|
13827 | (function(module, exports, __webpack_require__) {
|
13828 |
|
13829 | "use strict";
|
13830 |
|
13831 |
|
13832 | var scatter = __webpack_require__(234);
|
13833 |
|
13834 | var DimensionError = __webpack_require__(8);
|
13835 |
|
13836 | function factory(type, config, load, typed) {
|
13837 | var equalScalar = load(__webpack_require__(11));
|
13838 | var SparseMatrix = type.SparseMatrix;
|
13839 | |
13840 |
|
13841 |
|
13842 |
|
13843 |
|
13844 |
|
13845 |
|
13846 |
|
13847 |
|
13848 |
|
13849 |
|
13850 |
|
13851 |
|
13852 |
|
13853 |
|
13854 |
|
13855 |
|
13856 |
|
13857 |
|
13858 | var algorithm06 = function algorithm06(a, b, callback) {
|
13859 |
|
13860 | var avalues = a._values;
|
13861 | var asize = a._size;
|
13862 | var adt = a._datatype;
|
13863 |
|
13864 | var bvalues = b._values;
|
13865 | var bsize = b._size;
|
13866 | var bdt = b._datatype;
|
13867 |
|
13868 | if (asize.length !== bsize.length) {
|
13869 | throw new DimensionError(asize.length, bsize.length);
|
13870 | }
|
13871 |
|
13872 |
|
13873 | if (asize[0] !== bsize[0] || asize[1] !== bsize[1]) {
|
13874 | throw new RangeError('Dimension mismatch. Matrix A (' + asize + ') must match Matrix B (' + bsize + ')');
|
13875 | }
|
13876 |
|
13877 |
|
13878 | var rows = asize[0];
|
13879 | var columns = asize[1];
|
13880 |
|
13881 | var dt;
|
13882 |
|
13883 | var eq = equalScalar;
|
13884 |
|
13885 | var zero = 0;
|
13886 |
|
13887 | var cf = callback;
|
13888 |
|
13889 | if (typeof adt === 'string' && adt === bdt) {
|
13890 |
|
13891 | dt = adt;
|
13892 |
|
13893 | eq = typed.find(equalScalar, [dt, dt]);
|
13894 |
|
13895 | zero = typed.convert(0, dt);
|
13896 |
|
13897 | cf = typed.find(callback, [dt, dt]);
|
13898 | }
|
13899 |
|
13900 |
|
13901 | var cvalues = avalues && bvalues ? [] : undefined;
|
13902 | var cindex = [];
|
13903 | var cptr = [];
|
13904 |
|
13905 | var c = new SparseMatrix({
|
13906 | values: cvalues,
|
13907 | index: cindex,
|
13908 | ptr: cptr,
|
13909 | size: [rows, columns],
|
13910 | datatype: dt
|
13911 | });
|
13912 |
|
13913 | var x = cvalues ? [] : undefined;
|
13914 |
|
13915 | var w = [];
|
13916 |
|
13917 | var u = [];
|
13918 |
|
13919 | for (var j = 0; j < columns; j++) {
|
13920 |
|
13921 | cptr[j] = cindex.length;
|
13922 |
|
13923 | var mark = j + 1;
|
13924 |
|
13925 | scatter(a, j, w, x, u, mark, c, cf);
|
13926 |
|
13927 | scatter(b, j, w, x, u, mark, c, cf);
|
13928 |
|
13929 | if (x) {
|
13930 |
|
13931 | var k = cptr[j];
|
13932 |
|
13933 | while (k < cindex.length) {
|
13934 |
|
13935 | var i = cindex[k];
|
13936 |
|
13937 | if (u[i] === mark) {
|
13938 |
|
13939 | var v = x[i];
|
13940 |
|
13941 | if (!eq(v, zero)) {
|
13942 |
|
13943 | cvalues.push(v);
|
13944 |
|
13945 | k++;
|
13946 | } else {
|
13947 |
|
13948 | cindex.splice(k, 1);
|
13949 | }
|
13950 | } else {
|
13951 |
|
13952 | cindex.splice(k, 1);
|
13953 | }
|
13954 | }
|
13955 | } else {
|
13956 |
|
13957 | var p = cptr[j];
|
13958 |
|
13959 | while (p < cindex.length) {
|
13960 |
|
13961 | var r = cindex[p];
|
13962 |
|
13963 | if (u[r] !== mark) {
|
13964 |
|
13965 | cindex.splice(p, 1);
|
13966 | } else {
|
13967 |
|
13968 | p++;
|
13969 | }
|
13970 | }
|
13971 | }
|
13972 | }
|
13973 |
|
13974 |
|
13975 | cptr[columns] = cindex.length;
|
13976 |
|
13977 | return c;
|
13978 | };
|
13979 |
|
13980 | return algorithm06;
|
13981 | }
|
13982 |
|
13983 | exports.name = 'algorithm06';
|
13984 | exports.factory = factory;
|
13985 |
|
13986 | }),
|
13987 |
|
13988 | (function(module, exports, __webpack_require__) {
|
13989 |
|
13990 | "use strict";
|
13991 |
|
13992 |
|
13993 | var deepMap = __webpack_require__(1);
|
13994 |
|
13995 | function factory(type, config, load, typed) {
|
13996 | var gamma = load(__webpack_require__(141));
|
13997 |
|
13998 | var latex = __webpack_require__(4);
|
13999 | |
14000 |
|
14001 |
|
14002 |
|
14003 |
|
14004 |
|
14005 |
|
14006 |
|
14007 |
|
14008 |
|
14009 |
|
14010 |
|
14011 |
|
14012 |
|
14013 |
|
14014 |
|
14015 |
|
14016 |
|
14017 |
|
14018 |
|
14019 |
|
14020 |
|
14021 |
|
14022 |
|
14023 | var factorial = typed('factorial', {
|
14024 | 'number': function number(n) {
|
14025 | if (n < 0) {
|
14026 | throw new Error('Value must be non-negative');
|
14027 | }
|
14028 |
|
14029 | return gamma(n + 1);
|
14030 | },
|
14031 | 'BigNumber': function BigNumber(n) {
|
14032 | if (n.isNegative()) {
|
14033 | throw new Error('Value must be non-negative');
|
14034 | }
|
14035 |
|
14036 | return gamma(n.plus(1));
|
14037 | },
|
14038 | 'Array | Matrix': function ArrayMatrix(n) {
|
14039 | return deepMap(n, factorial);
|
14040 | }
|
14041 | });
|
14042 | factorial.toTex = {
|
14043 | 1: "\\left(${args[0]}\\right)".concat(latex.operators['factorial'])
|
14044 | };
|
14045 | return factorial;
|
14046 | }
|
14047 |
|
14048 | exports.name = 'factorial';
|
14049 | exports.factory = factory;
|
14050 |
|
14051 | }),
|
14052 |
|
14053 | (function(module, exports, __webpack_require__) {
|
14054 |
|
14055 | "use strict";
|
14056 |
|
14057 |
|
14058 | var isInteger = __webpack_require__(3).isInteger;
|
14059 |
|
14060 | var product = __webpack_require__(95);
|
14061 |
|
14062 | function factory(type, config, load, typed) {
|
14063 | |
14064 |
|
14065 |
|
14066 |
|
14067 |
|
14068 |
|
14069 |
|
14070 |
|
14071 |
|
14072 |
|
14073 |
|
14074 |
|
14075 |
|
14076 |
|
14077 |
|
14078 |
|
14079 |
|
14080 |
|
14081 |
|
14082 |
|
14083 |
|
14084 |
|
14085 |
|
14086 | var combinations = typed('combinations', {
|
14087 | 'number, number': function numberNumber(n, k) {
|
14088 | var prodrange, nMinusk;
|
14089 |
|
14090 | if (!isInteger(n) || n < 0) {
|
14091 | throw new TypeError('Positive integer value expected in function combinations');
|
14092 | }
|
14093 |
|
14094 | if (!isInteger(k) || k < 0) {
|
14095 | throw new TypeError('Positive integer value expected in function combinations');
|
14096 | }
|
14097 |
|
14098 | if (k > n) {
|
14099 | throw new TypeError('k must be less than or equal to n');
|
14100 | }
|
14101 |
|
14102 | nMinusk = n - k;
|
14103 |
|
14104 | if (k < nMinusk) {
|
14105 | prodrange = product(nMinusk + 1, n);
|
14106 | return prodrange / product(1, k);
|
14107 | }
|
14108 |
|
14109 | prodrange = product(k + 1, n);
|
14110 | return prodrange / product(1, nMinusk);
|
14111 | },
|
14112 | 'BigNumber, BigNumber': function BigNumberBigNumber(n, k) {
|
14113 | var max, result, i, ii;
|
14114 | var one = new type.BigNumber(1);
|
14115 |
|
14116 | if (!isPositiveInteger(n) || !isPositiveInteger(k)) {
|
14117 | throw new TypeError('Positive integer value expected in function combinations');
|
14118 | }
|
14119 |
|
14120 | if (k.gt(n)) {
|
14121 | throw new TypeError('k must be less than n in function combinations');
|
14122 | }
|
14123 |
|
14124 | max = n.minus(k);
|
14125 | if (k.lt(max)) max = k;
|
14126 | result = one;
|
14127 |
|
14128 | for (i = one, ii = n.minus(max); i.lte(ii); i = i.plus(1)) {
|
14129 | result = result.times(max.plus(i)).dividedBy(i);
|
14130 | }
|
14131 |
|
14132 | return result;
|
14133 | }
|
14134 |
|
14135 | });
|
14136 | combinations.toTex = {
|
14137 | 2: "\\binom{${args[0]}}{${args[1]}}"
|
14138 | };
|
14139 | return combinations;
|
14140 | }
|
14141 |
|
14142 |
|
14143 |
|
14144 |
|
14145 |
|
14146 |
|
14147 |
|
14148 | function isPositiveInteger(n) {
|
14149 | return n.isInteger() && n.gte(0);
|
14150 | }
|
14151 |
|
14152 | exports.name = 'combinations';
|
14153 | exports.factory = factory;
|
14154 |
|
14155 | }),
|
14156 |
|
14157 | (function(module, exports, __webpack_require__) {
|
14158 |
|
14159 | "use strict";
|
14160 |
|
14161 |
|
14162 | function factory(type, config, load, typed) {
|
14163 | var matrix = load(__webpack_require__(0));
|
14164 | var smaller = load(__webpack_require__(38));
|
14165 | var larger = load(__webpack_require__(33));
|
14166 | var smallerEq = load(__webpack_require__(144));
|
14167 | var largerEq = load(__webpack_require__(89));
|
14168 | var ZERO = new type.BigNumber(0);
|
14169 | var ONE = new type.BigNumber(1);
|
14170 | |
14171 |
|
14172 |
|
14173 |
|
14174 |
|
14175 |
|
14176 |
|
14177 |
|
14178 |
|
14179 |
|
14180 |
|
14181 |
|
14182 |
|
14183 |
|
14184 |
|
14185 |
|
14186 |
|
14187 |
|
14188 |
|
14189 |
|
14190 |
|
14191 |
|
14192 |
|
14193 |
|
14194 |
|
14195 |
|
14196 |
|
14197 |
|
14198 |
|
14199 |
|
14200 |
|
14201 |
|
14202 |
|
14203 |
|
14204 |
|
14205 |
|
14206 |
|
14207 |
|
14208 |
|
14209 |
|
14210 |
|
14211 |
|
14212 |
|
14213 |
|
14214 | var range = typed('range', {
|
14215 |
|
14216 |
|
14217 | 'string': _strRange,
|
14218 | 'string, boolean': _strRange,
|
14219 | 'number, number': function numberNumber(start, end) {
|
14220 | return _out(_rangeEx(start, end, 1));
|
14221 | },
|
14222 | 'number, number, number': function numberNumberNumber(start, end, step) {
|
14223 | return _out(_rangeEx(start, end, step));
|
14224 | },
|
14225 | 'number, number, boolean': function numberNumberBoolean(start, end, includeEnd) {
|
14226 | return includeEnd ? _out(_rangeInc(start, end, 1)) : _out(_rangeEx(start, end, 1));
|
14227 | },
|
14228 | 'number, number, number, boolean': function numberNumberNumberBoolean(start, end, step, includeEnd) {
|
14229 | return includeEnd ? _out(_rangeInc(start, end, step)) : _out(_rangeEx(start, end, step));
|
14230 | },
|
14231 | 'BigNumber, BigNumber': function BigNumberBigNumber(start, end) {
|
14232 | return _out(_bigRangeEx(start, end, ONE));
|
14233 | },
|
14234 | 'BigNumber, BigNumber, BigNumber': function BigNumberBigNumberBigNumber(start, end, step) {
|
14235 | return _out(_bigRangeEx(start, end, step));
|
14236 | },
|
14237 | 'BigNumber, BigNumber, boolean': function BigNumberBigNumberBoolean(start, end, includeEnd) {
|
14238 | return includeEnd ? _out(_bigRangeInc(start, end, ONE)) : _out(_bigRangeEx(start, end, ONE));
|
14239 | },
|
14240 | 'BigNumber, BigNumber, BigNumber, boolean': function BigNumberBigNumberBigNumberBoolean(start, end, step, includeEnd) {
|
14241 | return includeEnd ? _out(_bigRangeInc(start, end, step)) : _out(_bigRangeEx(start, end, step));
|
14242 | }
|
14243 | });
|
14244 | range.toTex = undefined;
|
14245 |
|
14246 | return range;
|
14247 |
|
14248 | function _out(arr) {
|
14249 | return config.matrix === 'Array' ? arr : matrix(arr);
|
14250 | }
|
14251 |
|
14252 | function _strRange(str, includeEnd) {
|
14253 | var r = _parse(str);
|
14254 |
|
14255 | if (!r) {
|
14256 | throw new SyntaxError('String "' + str + '" is no valid range');
|
14257 | }
|
14258 |
|
14259 | var fn;
|
14260 |
|
14261 | if (config.number === 'BigNumber') {
|
14262 | fn = includeEnd ? _bigRangeInc : _bigRangeEx;
|
14263 | return _out(fn(new type.BigNumber(r.start), new type.BigNumber(r.end), new type.BigNumber(r.step)));
|
14264 | } else {
|
14265 | fn = includeEnd ? _rangeInc : _rangeEx;
|
14266 | return _out(fn(r.start, r.end, r.step));
|
14267 | }
|
14268 | }
|
14269 | |
14270 |
|
14271 |
|
14272 |
|
14273 |
|
14274 |
|
14275 |
|
14276 |
|
14277 |
|
14278 |
|
14279 | function _rangeEx(start, end, step) {
|
14280 | var array = [];
|
14281 | var x = start;
|
14282 |
|
14283 | if (step > 0) {
|
14284 | while (smaller(x, end)) {
|
14285 | array.push(x);
|
14286 | x += step;
|
14287 | }
|
14288 | } else if (step < 0) {
|
14289 | while (larger(x, end)) {
|
14290 | array.push(x);
|
14291 | x += step;
|
14292 | }
|
14293 | }
|
14294 |
|
14295 | return array;
|
14296 | }
|
14297 | |
14298 |
|
14299 |
|
14300 |
|
14301 |
|
14302 |
|
14303 |
|
14304 |
|
14305 |
|
14306 |
|
14307 | function _rangeInc(start, end, step) {
|
14308 | var array = [];
|
14309 | var x = start;
|
14310 |
|
14311 | if (step > 0) {
|
14312 | while (smallerEq(x, end)) {
|
14313 | array.push(x);
|
14314 | x += step;
|
14315 | }
|
14316 | } else if (step < 0) {
|
14317 | while (largerEq(x, end)) {
|
14318 | array.push(x);
|
14319 | x += step;
|
14320 | }
|
14321 | }
|
14322 |
|
14323 | return array;
|
14324 | }
|
14325 | |
14326 |
|
14327 |
|
14328 |
|
14329 |
|
14330 |
|
14331 |
|
14332 |
|
14333 |
|
14334 |
|
14335 | function _bigRangeEx(start, end, step) {
|
14336 | var array = [];
|
14337 | var x = start;
|
14338 |
|
14339 | if (step.gt(ZERO)) {
|
14340 | while (smaller(x, end)) {
|
14341 | array.push(x);
|
14342 | x = x.plus(step);
|
14343 | }
|
14344 | } else if (step.lt(ZERO)) {
|
14345 | while (larger(x, end)) {
|
14346 | array.push(x);
|
14347 | x = x.plus(step);
|
14348 | }
|
14349 | }
|
14350 |
|
14351 | return array;
|
14352 | }
|
14353 | |
14354 |
|
14355 |
|
14356 |
|
14357 |
|
14358 |
|
14359 |
|
14360 |
|
14361 |
|
14362 |
|
14363 | function _bigRangeInc(start, end, step) {
|
14364 | var array = [];
|
14365 | var x = start;
|
14366 |
|
14367 | if (step.gt(ZERO)) {
|
14368 | while (smallerEq(x, end)) {
|
14369 | array.push(x);
|
14370 | x = x.plus(step);
|
14371 | }
|
14372 | } else if (step.lt(ZERO)) {
|
14373 | while (largerEq(x, end)) {
|
14374 | array.push(x);
|
14375 | x = x.plus(step);
|
14376 | }
|
14377 | }
|
14378 |
|
14379 | return array;
|
14380 | }
|
14381 | |
14382 |
|
14383 |
|
14384 |
|
14385 |
|
14386 |
|
14387 |
|
14388 |
|
14389 |
|
14390 |
|
14391 |
|
14392 | function _parse(str) {
|
14393 | var args = str.split(':');
|
14394 |
|
14395 | var nums = args.map(function (arg) {
|
14396 |
|
14397 | return Number(arg);
|
14398 | });
|
14399 | var invalid = nums.some(function (num) {
|
14400 | return isNaN(num);
|
14401 | });
|
14402 |
|
14403 | if (invalid) {
|
14404 | return null;
|
14405 | }
|
14406 |
|
14407 | switch (nums.length) {
|
14408 | case 2:
|
14409 | return {
|
14410 | start: nums[0],
|
14411 | end: nums[1],
|
14412 | step: 1
|
14413 | };
|
14414 |
|
14415 | case 3:
|
14416 | return {
|
14417 | start: nums[0],
|
14418 | end: nums[2],
|
14419 | step: nums[1]
|
14420 | };
|
14421 |
|
14422 | default:
|
14423 | return null;
|
14424 | }
|
14425 | }
|
14426 | }
|
14427 |
|
14428 | exports.name = 'range';
|
14429 | exports.factory = factory;
|
14430 |
|
14431 | }),
|
14432 |
|
14433 | (function(module, exports, __webpack_require__) {
|
14434 |
|
14435 | "use strict";
|
14436 |
|
14437 |
|
14438 | var clone = __webpack_require__(5).clone;
|
14439 |
|
14440 | var array = __webpack_require__(2);
|
14441 |
|
14442 | var IndexError = __webpack_require__(48);
|
14443 |
|
14444 | var DimensionError = __webpack_require__(8);
|
14445 |
|
14446 | function factory(type, config, load, typed) {
|
14447 | var matrix = load(__webpack_require__(0));
|
14448 | var isInteger = load(__webpack_require__(34));
|
14449 | |
14450 |
|
14451 |
|
14452 |
|
14453 |
|
14454 |
|
14455 |
|
14456 |
|
14457 |
|
14458 |
|
14459 |
|
14460 |
|
14461 |
|
14462 |
|
14463 |
|
14464 |
|
14465 |
|
14466 |
|
14467 |
|
14468 |
|
14469 |
|
14470 |
|
14471 |
|
14472 |
|
14473 |
|
14474 |
|
14475 |
|
14476 |
|
14477 |
|
14478 |
|
14479 | var concat = typed('concat', {
|
14480 |
|
14481 | '...Array | Matrix | number | BigNumber': function ArrayMatrixNumberBigNumber(args) {
|
14482 | var i;
|
14483 | var len = args.length;
|
14484 | var dim = -1;
|
14485 |
|
14486 | var prevDim;
|
14487 | var asMatrix = false;
|
14488 | var matrices = [];
|
14489 |
|
14490 | for (i = 0; i < len; i++) {
|
14491 | var arg = args[i];
|
14492 |
|
14493 | if (type.isMatrix(arg)) {
|
14494 | asMatrix = true;
|
14495 | }
|
14496 |
|
14497 | if (type.isNumber(arg) || type.isBigNumber(arg)) {
|
14498 | if (i !== len - 1) {
|
14499 | throw new Error('Dimension must be specified as last argument');
|
14500 | }
|
14501 |
|
14502 |
|
14503 | prevDim = dim;
|
14504 | dim = arg.valueOf();
|
14505 |
|
14506 | if (!isInteger(dim)) {
|
14507 | throw new TypeError('Integer number expected for dimension');
|
14508 | }
|
14509 |
|
14510 | if (dim < 0 || i > 0 && dim > prevDim) {
|
14511 |
|
14512 | throw new IndexError(dim, prevDim + 1);
|
14513 | }
|
14514 | } else {
|
14515 |
|
14516 | var m = clone(arg).valueOf();
|
14517 | var size = array.size(m);
|
14518 | matrices[i] = m;
|
14519 | prevDim = dim;
|
14520 | dim = size.length - 1;
|
14521 |
|
14522 | if (i > 0 && dim !== prevDim) {
|
14523 | throw new DimensionError(prevDim + 1, dim + 1);
|
14524 | }
|
14525 | }
|
14526 | }
|
14527 |
|
14528 | if (matrices.length === 0) {
|
14529 | throw new SyntaxError('At least one matrix expected');
|
14530 | }
|
14531 |
|
14532 | var res = matrices.shift();
|
14533 |
|
14534 | while (matrices.length) {
|
14535 | res = _concat(res, matrices.shift(), dim, 0);
|
14536 | }
|
14537 |
|
14538 | return asMatrix ? matrix(res) : res;
|
14539 | },
|
14540 | '...string': function string(args) {
|
14541 | return args.join('');
|
14542 | }
|
14543 | });
|
14544 | concat.toTex = undefined;
|
14545 |
|
14546 | return concat;
|
14547 | }
|
14548 |
|
14549 |
|
14550 |
|
14551 |
|
14552 |
|
14553 |
|
14554 |
|
14555 |
|
14556 |
|
14557 |
|
14558 |
|
14559 |
|
14560 | function _concat(a, b, concatDim, dim) {
|
14561 | if (dim < concatDim) {
|
14562 |
|
14563 | if (a.length !== b.length) {
|
14564 | throw new DimensionError(a.length, b.length);
|
14565 | }
|
14566 |
|
14567 | var c = [];
|
14568 |
|
14569 | for (var i = 0; i < a.length; i++) {
|
14570 | c[i] = _concat(a[i], b[i], concatDim, dim + 1);
|
14571 | }
|
14572 |
|
14573 | return c;
|
14574 | } else {
|
14575 |
|
14576 | return a.concat(b);
|
14577 | }
|
14578 | }
|
14579 |
|
14580 | exports.name = 'concat';
|
14581 | exports.factory = factory;
|
14582 |
|
14583 | }),
|
14584 |
|
14585 | (function(module, exports, __webpack_require__) {
|
14586 |
|
14587 | "use strict";
|
14588 |
|
14589 |
|
14590 | var deepMap = __webpack_require__(1);
|
14591 |
|
14592 | function factory(type, config, load, typed) {
|
14593 | |
14594 |
|
14595 |
|
14596 |
|
14597 |
|
14598 |
|
14599 |
|
14600 |
|
14601 |
|
14602 |
|
14603 |
|
14604 |
|
14605 |
|
14606 |
|
14607 |
|
14608 |
|
14609 |
|
14610 |
|
14611 |
|
14612 |
|
14613 |
|
14614 |
|
14615 |
|
14616 |
|
14617 |
|
14618 |
|
14619 |
|
14620 |
|
14621 |
|
14622 | var isNaN = typed('isNaN', {
|
14623 | 'number': function number(x) {
|
14624 | return Number.isNaN(x);
|
14625 | },
|
14626 | 'BigNumber': function BigNumber(x) {
|
14627 | return x.isNaN();
|
14628 | },
|
14629 | 'Fraction': function Fraction(x) {
|
14630 | return false;
|
14631 | },
|
14632 | 'Complex': function Complex(x) {
|
14633 | return x.isNaN();
|
14634 | },
|
14635 | 'Unit': function Unit(x) {
|
14636 | return Number.isNaN(x.value);
|
14637 | },
|
14638 | 'Array | Matrix': function ArrayMatrix(x) {
|
14639 | return deepMap(x, Number.isNaN);
|
14640 | }
|
14641 | });
|
14642 | return isNaN;
|
14643 | }
|
14644 |
|
14645 | exports.name = 'isNaN';
|
14646 | exports.factory = factory;
|
14647 |
|
14648 | }),
|
14649 |
|
14650 | (function(module, exports, __webpack_require__) {
|
14651 |
|
14652 | "use strict";
|
14653 |
|
14654 |
|
14655 | var arraySize = __webpack_require__(2).size;
|
14656 |
|
14657 | var isMatrix = __webpack_require__(56);
|
14658 |
|
14659 | var IndexError = __webpack_require__(48);
|
14660 |
|
14661 |
|
14662 |
|
14663 |
|
14664 |
|
14665 |
|
14666 |
|
14667 |
|
14668 |
|
14669 |
|
14670 |
|
14671 | module.exports = function (mat, dim, callback) {
|
14672 | var size = Array.isArray(mat) ? arraySize(mat) : mat.size();
|
14673 |
|
14674 | if (dim < 0 || dim >= size.length) {
|
14675 |
|
14676 | throw new IndexError(dim, size.length);
|
14677 | }
|
14678 |
|
14679 | if (isMatrix(mat)) {
|
14680 | return mat.create(_reduce(mat.valueOf(), dim, callback));
|
14681 | } else {
|
14682 | return _reduce(mat, dim, callback);
|
14683 | }
|
14684 | };
|
14685 |
|
14686 |
|
14687 |
|
14688 |
|
14689 |
|
14690 |
|
14691 |
|
14692 |
|
14693 |
|
14694 |
|
14695 | function _reduce(mat, dim, callback) {
|
14696 | var i, ret, val, tran;
|
14697 |
|
14698 | if (dim <= 0) {
|
14699 | if (!Array.isArray(mat[0])) {
|
14700 | val = mat[0];
|
14701 |
|
14702 | for (i = 1; i < mat.length; i++) {
|
14703 | val = callback(val, mat[i]);
|
14704 | }
|
14705 |
|
14706 | return val;
|
14707 | } else {
|
14708 | tran = _switch(mat);
|
14709 | ret = [];
|
14710 |
|
14711 | for (i = 0; i < tran.length; i++) {
|
14712 | ret[i] = _reduce(tran[i], dim - 1, callback);
|
14713 | }
|
14714 |
|
14715 | return ret;
|
14716 | }
|
14717 | } else {
|
14718 | ret = [];
|
14719 |
|
14720 | for (i = 0; i < mat.length; i++) {
|
14721 | ret[i] = _reduce(mat[i], dim - 1, callback);
|
14722 | }
|
14723 |
|
14724 | return ret;
|
14725 | }
|
14726 | }
|
14727 |
|
14728 |
|
14729 |
|
14730 |
|
14731 |
|
14732 |
|
14733 |
|
14734 |
|
14735 | function _switch(mat) {
|
14736 | var I = mat.length;
|
14737 | var J = mat[0].length;
|
14738 | var i, j;
|
14739 | var ret = [];
|
14740 |
|
14741 | for (j = 0; j < J; j++) {
|
14742 | var tmp = [];
|
14743 |
|
14744 | for (i = 0; i < I; i++) {
|
14745 | tmp.push(mat[i][j]);
|
14746 | }
|
14747 |
|
14748 | ret.push(tmp);
|
14749 | }
|
14750 |
|
14751 | return ret;
|
14752 | }
|
14753 |
|
14754 | }),
|
14755 |
|
14756 | (function(module, exports, __webpack_require__) {
|
14757 |
|
14758 | "use strict";
|
14759 |
|
14760 |
|
14761 |
|
14762 |
|
14763 |
|
14764 |
|
14765 |
|
14766 | module.exports = function isBigNumber(x) {
|
14767 | return x && x.constructor.prototype.isBigNumber || false;
|
14768 | };
|
14769 |
|
14770 | }),
|
14771 |
|
14772 | (function(module, exports, __webpack_require__) {
|
14773 |
|
14774 | "use strict";
|
14775 |
|
14776 |
|
14777 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
14778 |
|
14779 | var Complex = __webpack_require__(178);
|
14780 |
|
14781 | var format = __webpack_require__(3).format;
|
14782 |
|
14783 | var isNumber = __webpack_require__(3).isNumber;
|
14784 |
|
14785 | function factory(type, config, load, typed, math) {
|
14786 | |
14787 |
|
14788 |
|
14789 | Complex.prototype.type = 'Complex';
|
14790 | Complex.prototype.isComplex = true;
|
14791 | |
14792 |
|
14793 |
|
14794 |
|
14795 |
|
14796 |
|
14797 | Complex.prototype.toJSON = function () {
|
14798 | return {
|
14799 | mathjs: 'Complex',
|
14800 | re: this.re,
|
14801 | im: this.im
|
14802 | };
|
14803 | };
|
14804 | |
14805 |
|
14806 |
|
14807 |
|
14808 |
|
14809 |
|
14810 |
|
14811 | Complex.prototype.toPolar = function () {
|
14812 | return {
|
14813 | r: this.abs(),
|
14814 | phi: this.arg()
|
14815 | };
|
14816 | };
|
14817 | |
14818 |
|
14819 |
|
14820 |
|
14821 |
|
14822 |
|
14823 |
|
14824 |
|
14825 |
|
14826 |
|
14827 |
|
14828 | Complex.prototype.format = function (options) {
|
14829 | var str = '';
|
14830 | var im = this.im;
|
14831 | var re = this.re;
|
14832 | var strRe = format(this.re, options);
|
14833 | var strIm = format(this.im, options);
|
14834 |
|
14835 | var precision = isNumber(options) ? options : options ? options.precision : null;
|
14836 |
|
14837 | if (precision !== null) {
|
14838 | var epsilon = Math.pow(10, -precision);
|
14839 |
|
14840 | if (Math.abs(re / im) < epsilon) {
|
14841 | re = 0;
|
14842 | }
|
14843 |
|
14844 | if (Math.abs(im / re) < epsilon) {
|
14845 | im = 0;
|
14846 | }
|
14847 | }
|
14848 |
|
14849 | if (im === 0) {
|
14850 |
|
14851 | str = strRe;
|
14852 | } else if (re === 0) {
|
14853 |
|
14854 | if (im === 1) {
|
14855 | str = 'i';
|
14856 | } else if (im === -1) {
|
14857 | str = '-i';
|
14858 | } else {
|
14859 | str = strIm + 'i';
|
14860 | }
|
14861 | } else {
|
14862 |
|
14863 | if (im < 0) {
|
14864 | if (im === -1) {
|
14865 | str = strRe + ' - i';
|
14866 | } else {
|
14867 | str = strRe + ' - ' + strIm.substring(1) + 'i';
|
14868 | }
|
14869 | } else {
|
14870 | if (im === 1) {
|
14871 | str = strRe + ' + i';
|
14872 | } else {
|
14873 | str = strRe + ' + ' + strIm + 'i';
|
14874 | }
|
14875 | }
|
14876 | }
|
14877 |
|
14878 | return str;
|
14879 | };
|
14880 | |
14881 |
|
14882 |
|
14883 |
|
14884 |
|
14885 |
|
14886 |
|
14887 |
|
14888 |
|
14889 |
|
14890 |
|
14891 |
|
14892 |
|
14893 | Complex.fromPolar = function (args) {
|
14894 | switch (arguments.length) {
|
14895 | case 1:
|
14896 | var arg = arguments[0];
|
14897 |
|
14898 | if (_typeof(arg) === 'object') {
|
14899 | return Complex(arg);
|
14900 | }
|
14901 |
|
14902 | throw new TypeError('Input has to be an object with r and phi keys.');
|
14903 |
|
14904 | case 2:
|
14905 | var r = arguments[0];
|
14906 | var phi = arguments[1];
|
14907 |
|
14908 | if (isNumber(r)) {
|
14909 | if (type.isUnit(phi) && phi.hasBase('ANGLE')) {
|
14910 |
|
14911 | phi = phi.toNumber('rad');
|
14912 | }
|
14913 |
|
14914 | if (isNumber(phi)) {
|
14915 | return new Complex({
|
14916 | r: r,
|
14917 | phi: phi
|
14918 | });
|
14919 | }
|
14920 |
|
14921 | throw new TypeError('Phi is not a number nor an angle unit.');
|
14922 | } else {
|
14923 | throw new TypeError('Radius r is not a number.');
|
14924 | }
|
14925 |
|
14926 | default:
|
14927 | throw new SyntaxError('Wrong number of arguments in function fromPolar');
|
14928 | }
|
14929 | };
|
14930 |
|
14931 | Complex.prototype.valueOf = Complex.prototype.toString;
|
14932 | |
14933 |
|
14934 |
|
14935 |
|
14936 |
|
14937 |
|
14938 |
|
14939 |
|
14940 |
|
14941 | Complex.fromJSON = function (json) {
|
14942 | return new Complex(json);
|
14943 | };
|
14944 |
|
14945 |
|
14946 | Complex.EPSILON = config.epsilon;
|
14947 |
|
14948 | math.on('config', function (curr, prev) {
|
14949 | if (curr.epsilon !== prev.epsilon) {
|
14950 | Complex.EPSILON = curr.epsilon;
|
14951 | }
|
14952 | });
|
14953 | |
14954 |
|
14955 |
|
14956 |
|
14957 |
|
14958 |
|
14959 |
|
14960 |
|
14961 |
|
14962 |
|
14963 |
|
14964 |
|
14965 |
|
14966 |
|
14967 |
|
14968 |
|
14969 | Complex.compare = function (a, b) {
|
14970 | if (a.re > b.re) {
|
14971 | return 1;
|
14972 | }
|
14973 |
|
14974 | if (a.re < b.re) {
|
14975 | return -1;
|
14976 | }
|
14977 |
|
14978 | if (a.im > b.im) {
|
14979 | return 1;
|
14980 | }
|
14981 |
|
14982 | if (a.im < b.im) {
|
14983 | return -1;
|
14984 | }
|
14985 |
|
14986 | return 0;
|
14987 | };
|
14988 |
|
14989 | return Complex;
|
14990 | }
|
14991 |
|
14992 | exports.name = 'Complex';
|
14993 | exports.path = 'type';
|
14994 | exports.factory = factory;
|
14995 | exports.math = true;
|
14996 |
|
14997 | }),
|
14998 |
|
14999 | (function(module, exports, __webpack_require__) {
|
15000 |
|
15001 | "use strict";
|
15002 |
|
15003 |
|
15004 | var deepMap = __webpack_require__(1);
|
15005 |
|
15006 | function factory(type, config, load, typed) {
|
15007 | |
15008 |
|
15009 |
|
15010 |
|
15011 |
|
15012 |
|
15013 |
|
15014 |
|
15015 |
|
15016 |
|
15017 |
|
15018 |
|
15019 |
|
15020 |
|
15021 |
|
15022 |
|
15023 |
|
15024 |
|
15025 |
|
15026 |
|
15027 |
|
15028 |
|
15029 |
|
15030 |
|
15031 |
|
15032 | var fraction = typed('fraction', {
|
15033 | 'number': function number(x) {
|
15034 | if (!isFinite(x) || isNaN(x)) {
|
15035 | throw new Error(x + ' cannot be represented as a fraction');
|
15036 | }
|
15037 |
|
15038 | return new type.Fraction(x);
|
15039 | },
|
15040 | 'string': function string(x) {
|
15041 | return new type.Fraction(x);
|
15042 | },
|
15043 | 'number, number': function numberNumber(numerator, denominator) {
|
15044 | return new type.Fraction(numerator, denominator);
|
15045 | },
|
15046 | 'null': function _null(x) {
|
15047 | return new type.Fraction(0);
|
15048 | },
|
15049 | 'BigNumber': function BigNumber(x) {
|
15050 | return new type.Fraction(x.toString());
|
15051 | },
|
15052 | 'Fraction': function Fraction(x) {
|
15053 | return x;
|
15054 | },
|
15055 | 'Object': function Object(x) {
|
15056 | return new type.Fraction(x);
|
15057 | },
|
15058 | 'Array | Matrix': function ArrayMatrix(x) {
|
15059 | return deepMap(x, fraction);
|
15060 | }
|
15061 | });
|
15062 | return fraction;
|
15063 | }
|
15064 |
|
15065 | exports.name = 'fraction';
|
15066 | exports.factory = factory;
|
15067 |
|
15068 | }),
|
15069 |
|
15070 | (function(module, exports, __webpack_require__) {
|
15071 |
|
15072 | "use strict";
|
15073 |
|
15074 |
|
15075 | var util = __webpack_require__(31);
|
15076 |
|
15077 | var string = util.string;
|
15078 | var isString = string.isString;
|
15079 |
|
15080 | function factory(type, config, load, typed) {
|
15081 | |
15082 |
|
15083 |
|
15084 |
|
15085 |
|
15086 |
|
15087 |
|
15088 |
|
15089 |
|
15090 |
|
15091 |
|
15092 |
|
15093 |
|
15094 |
|
15095 |
|
15096 |
|
15097 |
|
15098 |
|
15099 |
|
15100 |
|
15101 |
|
15102 |
|
15103 | function Matrix() {
|
15104 | if (!(this instanceof Matrix)) {
|
15105 | throw new SyntaxError('Constructor must be called with the new operator');
|
15106 | }
|
15107 | }
|
15108 | |
15109 |
|
15110 |
|
15111 |
|
15112 |
|
15113 | Matrix.prototype.type = 'Matrix';
|
15114 | Matrix.prototype.isMatrix = true;
|
15115 | |
15116 |
|
15117 |
|
15118 |
|
15119 |
|
15120 |
|
15121 |
|
15122 |
|
15123 | Matrix.storage = function (format) {
|
15124 |
|
15125 | if (!isString(format)) {
|
15126 | throw new TypeError('format must be a string value');
|
15127 | }
|
15128 |
|
15129 |
|
15130 | var constructor = Matrix._storage[format];
|
15131 |
|
15132 | if (!constructor) {
|
15133 | throw new SyntaxError('Unsupported matrix storage format: ' + format);
|
15134 | }
|
15135 |
|
15136 |
|
15137 | return constructor;
|
15138 | }; // a map with all constructors for all storage types
|
15139 |
|
15140 |
|
15141 | Matrix._storage = {};
|
15142 | |
15143 |
|
15144 |
|
15145 |
|
15146 |
|
15147 |
|
15148 |
|
15149 |
|
15150 |
|
15151 | Matrix.prototype.storage = function () {
|
15152 |
|
15153 | throw new Error('Cannot invoke storage on a Matrix interface');
|
15154 | };
|
15155 | |
15156 |
|
15157 |
|
15158 |
|
15159 |
|
15160 |
|
15161 |
|
15162 |
|
15163 |
|
15164 |
|
15165 | Matrix.prototype.datatype = function () {
|
15166 |
|
15167 | throw new Error('Cannot invoke datatype on a Matrix interface');
|
15168 | };
|
15169 | |
15170 |
|
15171 |
|
15172 |
|
15173 |
|
15174 |
|
15175 |
|
15176 | Matrix.prototype.create = function (data, datatype) {
|
15177 | throw new Error('Cannot invoke create on a Matrix interface');
|
15178 | };
|
15179 | |
15180 |
|
15181 |
|
15182 |
|
15183 |
|
15184 |
|
15185 |
|
15186 |
|
15187 |
|
15188 |
|
15189 |
|
15190 |
|
15191 |
|
15192 |
|
15193 |
|
15194 | Matrix.prototype.subset = function (index, replacement, defaultValue) {
|
15195 |
|
15196 | throw new Error('Cannot invoke subset on a Matrix interface');
|
15197 | };
|
15198 | |
15199 |
|
15200 |
|
15201 |
|
15202 |
|
15203 |
|
15204 |
|
15205 | Matrix.prototype.get = function (index) {
|
15206 |
|
15207 | throw new Error('Cannot invoke get on a Matrix interface');
|
15208 | };
|
15209 | |
15210 |
|
15211 |
|
15212 |
|
15213 |
|
15214 |
|
15215 |
|
15216 |
|
15217 |
|
15218 |
|
15219 |
|
15220 | Matrix.prototype.set = function (index, value, defaultValue) {
|
15221 |
|
15222 | throw new Error('Cannot invoke set on a Matrix interface');
|
15223 | };
|
15224 | |
15225 |
|
15226 |
|
15227 |
|
15228 |
|
15229 |
|
15230 |
|
15231 |
|
15232 |
|
15233 |
|
15234 |
|
15235 |
|
15236 |
|
15237 |
|
15238 | Matrix.prototype.resize = function (size, defaultValue) {
|
15239 |
|
15240 | throw new Error('Cannot invoke resize on a Matrix interface');
|
15241 | };
|
15242 | |
15243 |
|
15244 |
|
15245 |
|
15246 |
|
15247 |
|
15248 |
|
15249 |
|
15250 |
|
15251 |
|
15252 |
|
15253 | Matrix.prototype.reshape = function (size, defaultValue) {
|
15254 |
|
15255 | throw new Error('Cannot invoke reshape on a Matrix interface');
|
15256 | };
|
15257 | |
15258 |
|
15259 |
|
15260 |
|
15261 |
|
15262 |
|
15263 | Matrix.prototype.clone = function () {
|
15264 |
|
15265 | throw new Error('Cannot invoke clone on a Matrix interface');
|
15266 | };
|
15267 | |
15268 |
|
15269 |
|
15270 |
|
15271 |
|
15272 |
|
15273 | Matrix.prototype.size = function () {
|
15274 |
|
15275 | throw new Error('Cannot invoke size on a Matrix interface');
|
15276 | };
|
15277 | |
15278 |
|
15279 |
|
15280 |
|
15281 |
|
15282 |
|
15283 |
|
15284 |
|
15285 |
|
15286 |
|
15287 |
|
15288 |
|
15289 | Matrix.prototype.map = function (callback, skipZeros) {
|
15290 |
|
15291 | throw new Error('Cannot invoke map on a Matrix interface');
|
15292 | };
|
15293 | |
15294 |
|
15295 |
|
15296 |
|
15297 |
|
15298 |
|
15299 |
|
15300 |
|
15301 | Matrix.prototype.forEach = function (callback) {
|
15302 |
|
15303 | throw new Error('Cannot invoke forEach on a Matrix interface');
|
15304 | };
|
15305 | |
15306 |
|
15307 |
|
15308 |
|
15309 |
|
15310 |
|
15311 | Matrix.prototype.toArray = function () {
|
15312 |
|
15313 | throw new Error('Cannot invoke toArray on a Matrix interface');
|
15314 | };
|
15315 | |
15316 |
|
15317 |
|
15318 |
|
15319 |
|
15320 |
|
15321 | Matrix.prototype.valueOf = function () {
|
15322 |
|
15323 | throw new Error('Cannot invoke valueOf on a Matrix interface');
|
15324 | };
|
15325 | |
15326 |
|
15327 |
|
15328 |
|
15329 |
|
15330 |
|
15331 |
|
15332 |
|
15333 |
|
15334 |
|
15335 | Matrix.prototype.format = function (options) {
|
15336 |
|
15337 | throw new Error('Cannot invoke format on a Matrix interface');
|
15338 | };
|
15339 | |
15340 |
|
15341 |
|
15342 |
|
15343 |
|
15344 |
|
15345 | Matrix.prototype.toString = function () {
|
15346 |
|
15347 | throw new Error('Cannot invoke toString on a Matrix interface');
|
15348 | };
|
15349 |
|
15350 |
|
15351 | return Matrix;
|
15352 | }
|
15353 |
|
15354 | exports.name = 'Matrix';
|
15355 | exports.path = 'type';
|
15356 | exports.factory = factory;
|
15357 |
|
15358 | }),
|
15359 |
|
15360 | (function(module, exports, __webpack_require__) {
|
15361 |
|
15362 | "use strict";
|
15363 |
|
15364 |
|
15365 | var DimensionError = __webpack_require__(8);
|
15366 |
|
15367 | function factory(type, config, load, typed) {
|
15368 | var equalScalar = load(__webpack_require__(11));
|
15369 | var SparseMatrix = type.SparseMatrix;
|
15370 | |
15371 |
|
15372 |
|
15373 |
|
15374 |
|
15375 |
|
15376 |
|
15377 |
|
15378 |
|
15379 |
|
15380 |
|
15381 |
|
15382 |
|
15383 |
|
15384 |
|
15385 |
|
15386 |
|
15387 |
|
15388 |
|
15389 | var algorithm04 = function algorithm04(a, b, callback) {
|
15390 |
|
15391 | var avalues = a._values;
|
15392 | var aindex = a._index;
|
15393 | var aptr = a._ptr;
|
15394 | var asize = a._size;
|
15395 | var adt = a._datatype;
|
15396 |
|
15397 | var bvalues = b._values;
|
15398 | var bindex = b._index;
|
15399 | var bptr = b._ptr;
|
15400 | var bsize = b._size;
|
15401 | var bdt = b._datatype;
|
15402 |
|
15403 | if (asize.length !== bsize.length) {
|
15404 | throw new DimensionError(asize.length, bsize.length);
|
15405 | }
|
15406 |
|
15407 |
|
15408 | if (asize[0] !== bsize[0] || asize[1] !== bsize[1]) {
|
15409 | throw new RangeError('Dimension mismatch. Matrix A (' + asize + ') must match Matrix B (' + bsize + ')');
|
15410 | }
|
15411 |
|
15412 |
|
15413 | var rows = asize[0];
|
15414 | var columns = asize[1];
|
15415 |
|
15416 | var dt;
|
15417 |
|
15418 | var eq = equalScalar;
|
15419 |
|
15420 | var zero = 0;
|
15421 |
|
15422 | var cf = callback;
|
15423 |
|
15424 | if (typeof adt === 'string' && adt === bdt) {
|
15425 |
|
15426 | dt = adt;
|
15427 |
|
15428 | eq = typed.find(equalScalar, [dt, dt]);
|
15429 |
|
15430 | zero = typed.convert(0, dt);
|
15431 |
|
15432 | cf = typed.find(callback, [dt, dt]);
|
15433 | }
|
15434 |
|
15435 |
|
15436 | var cvalues = avalues && bvalues ? [] : undefined;
|
15437 | var cindex = [];
|
15438 | var cptr = [];
|
15439 |
|
15440 | var c = new SparseMatrix({
|
15441 | values: cvalues,
|
15442 | index: cindex,
|
15443 | ptr: cptr,
|
15444 | size: [rows, columns],
|
15445 | datatype: dt
|
15446 | });
|
15447 |
|
15448 | var xa = avalues && bvalues ? [] : undefined;
|
15449 | var xb = avalues && bvalues ? [] : undefined;
|
15450 |
|
15451 | var wa = [];
|
15452 | var wb = [];
|
15453 |
|
15454 | var i, j, k, k0, k1;
|
15455 |
|
15456 | for (j = 0; j < columns; j++) {
|
15457 |
|
15458 | cptr[j] = cindex.length;
|
15459 |
|
15460 | var mark = j + 1;
|
15461 |
|
15462 | for (k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
|
15463 |
|
15464 | i = aindex[k];
|
15465 |
|
15466 | cindex.push(i);
|
15467 |
|
15468 | wa[i] = mark;
|
15469 |
|
15470 | if (xa) {
|
15471 | xa[i] = avalues[k];
|
15472 | }
|
15473 | }
|
15474 |
|
15475 |
|
15476 | for (k0 = bptr[j], k1 = bptr[j + 1], k = k0; k < k1; k++) {
|
15477 |
|
15478 | i = bindex[k];
|
15479 |
|
15480 | if (wa[i] === mark) {
|
15481 |
|
15482 | if (xa) {
|
15483 |
|
15484 | var v = cf(xa[i], bvalues[k]);
|
15485 |
|
15486 | if (!eq(v, zero)) {
|
15487 |
|
15488 | xa[i] = v;
|
15489 | } else {
|
15490 |
|
15491 | wa[i] = null;
|
15492 | }
|
15493 | }
|
15494 | } else {
|
15495 |
|
15496 | cindex.push(i);
|
15497 |
|
15498 | wb[i] = mark;
|
15499 |
|
15500 | if (xb) {
|
15501 | xb[i] = bvalues[k];
|
15502 | }
|
15503 | }
|
15504 | }
|
15505 |
|
15506 |
|
15507 | if (xa && xb) {
|
15508 |
|
15509 | k = cptr[j];
|
15510 |
|
15511 | while (k < cindex.length) {
|
15512 |
|
15513 | i = cindex[k];
|
15514 |
|
15515 | if (wa[i] === mark) {
|
15516 |
|
15517 | cvalues[k] = xa[i];
|
15518 |
|
15519 | k++;
|
15520 | } else if (wb[i] === mark) {
|
15521 |
|
15522 | cvalues[k] = xb[i];
|
15523 |
|
15524 | k++;
|
15525 | } else {
|
15526 |
|
15527 | cindex.splice(k, 1);
|
15528 | }
|
15529 | }
|
15530 | }
|
15531 | }
|
15532 |
|
15533 |
|
15534 | cptr[columns] = cindex.length;
|
15535 |
|
15536 | return c;
|
15537 | };
|
15538 |
|
15539 | return algorithm04;
|
15540 | }
|
15541 |
|
15542 | exports.name = 'algorithm04';
|
15543 | exports.factory = factory;
|
15544 |
|
15545 | }),
|
15546 |
|
15547 | (function(module, exports, __webpack_require__) {
|
15548 |
|
15549 | "use strict";
|
15550 |
|
15551 |
|
15552 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
15553 |
|
15554 | function factory(type, config, load, typed, math) {
|
15555 | var parse = load(__webpack_require__(44));
|
15556 | var equal = load(__webpack_require__(51));
|
15557 | var ConstantNode = load(__webpack_require__(58));
|
15558 | var FunctionNode = load(__webpack_require__(69));
|
15559 | var OperatorNode = load(__webpack_require__(59));
|
15560 | var ParenthesisNode = load(__webpack_require__(68));
|
15561 | var SymbolNode = load(__webpack_require__(54));
|
15562 | var simplifyConstant = load(__webpack_require__(125));
|
15563 | var simplifyCore = load(__webpack_require__(127));
|
15564 | var resolve = load(__webpack_require__(206));
|
15565 | var util = load(__webpack_require__(126));
|
15566 | var isCommutative = util.isCommutative;
|
15567 | var isAssociative = util.isAssociative;
|
15568 | var flatten = util.flatten;
|
15569 | var unflattenr = util.unflattenr;
|
15570 | var unflattenl = util.unflattenl;
|
15571 | var createMakeNodeFunction = util.createMakeNodeFunction;
|
15572 | |
15573 |
|
15574 |
|
15575 |
|
15576 |
|
15577 |
|
15578 |
|
15579 |
|
15580 |
|
15581 |
|
15582 |
|
15583 |
|
15584 |
|
15585 |
|
15586 |
|
15587 |
|
15588 |
|
15589 |
|
15590 |
|
15591 |
|
15592 |
|
15593 |
|
15594 |
|
15595 |
|
15596 |
|
15597 |
|
15598 |
|
15599 |
|
15600 |
|
15601 |
|
15602 |
|
15603 |
|
15604 |
|
15605 |
|
15606 |
|
15607 |
|
15608 |
|
15609 |
|
15610 |
|
15611 |
|
15612 |
|
15613 |
|
15614 |
|
15615 |
|
15616 |
|
15617 |
|
15618 |
|
15619 |
|
15620 |
|
15621 |
|
15622 |
|
15623 |
|
15624 |
|
15625 |
|
15626 |
|
15627 |
|
15628 |
|
15629 |
|
15630 |
|
15631 |
|
15632 |
|
15633 |
|
15634 |
|
15635 |
|
15636 |
|
15637 |
|
15638 |
|
15639 |
|
15640 |
|
15641 | var simplify = typed('simplify', {
|
15642 | 'string': function string(expr) {
|
15643 | return simplify(parse(expr), simplify.rules, {}, {});
|
15644 | },
|
15645 | 'string, Object': function stringObject(expr, scope) {
|
15646 | return simplify(parse(expr), simplify.rules, scope, {});
|
15647 | },
|
15648 | 'string, Object, Object': function stringObjectObject(expr, scope, options) {
|
15649 | return simplify(parse(expr), simplify.rules, scope, options);
|
15650 | },
|
15651 | 'string, Array': function stringArray(expr, rules) {
|
15652 | return simplify(parse(expr), rules, {}, {});
|
15653 | },
|
15654 | 'string, Array, Object': function stringArrayObject(expr, rules, scope) {
|
15655 | return simplify(parse(expr), rules, scope, {});
|
15656 | },
|
15657 | 'string, Array, Object, Object': function stringArrayObjectObject(expr, rules, scope, options) {
|
15658 | return simplify(parse(expr), rules, scope, options);
|
15659 | },
|
15660 | 'Node, Object': function NodeObject(expr, scope) {
|
15661 | return simplify(expr, simplify.rules, scope, {});
|
15662 | },
|
15663 | 'Node, Object, Object': function NodeObjectObject(expr, scope, options) {
|
15664 | return simplify(expr, simplify.rules, scope, options);
|
15665 | },
|
15666 | 'Node': function Node(expr) {
|
15667 | return simplify(expr, simplify.rules, {}, {});
|
15668 | },
|
15669 | 'Node, Array': function NodeArray(expr, rules) {
|
15670 | return simplify(expr, rules, {}, {});
|
15671 | },
|
15672 | 'Node, Array, Object': function NodeArrayObject(expr, rules, scope) {
|
15673 | return simplify(expr, rules, scope, {});
|
15674 | },
|
15675 | 'Node, Array, Object, Object': function NodeArrayObjectObject(expr, rules, scope, options) {
|
15676 | rules = _buildRules(rules);
|
15677 | var res = resolve(expr, scope);
|
15678 | res = removeParens(res);
|
15679 | var visited = {};
|
15680 | var str = res.toString({
|
15681 | parenthesis: 'all'
|
15682 | });
|
15683 |
|
15684 | while (!visited[str]) {
|
15685 | visited[str] = true;
|
15686 | _lastsym = 0;
|
15687 |
|
15688 | for (var i = 0; i < rules.length; i++) {
|
15689 | if (typeof rules[i] === 'function') {
|
15690 | res = rules[i](res, options);
|
15691 | } else {
|
15692 | flatten(res);
|
15693 | res = applyRule(res, rules[i]);
|
15694 | }
|
15695 |
|
15696 | unflattenl(res);
|
15697 | }
|
15698 |
|
15699 | str = res.toString({
|
15700 | parenthesis: 'all'
|
15701 | });
|
15702 | }
|
15703 |
|
15704 | return res;
|
15705 | }
|
15706 | });
|
15707 | simplify.simplifyCore = simplifyCore;
|
15708 | simplify.resolve = resolve;
|
15709 |
|
15710 | function removeParens(node) {
|
15711 | return node.transform(function (node, path, parent) {
|
15712 | return type.isParenthesisNode(node) ? node.content : node;
|
15713 | });
|
15714 | }
|
15715 |
|
15716 |
|
15717 | var SUPPORTED_CONSTANTS = {
|
15718 | "true": true,
|
15719 | "false": true,
|
15720 | e: true,
|
15721 | i: true,
|
15722 | Infinity: true,
|
15723 | LN2: true,
|
15724 | LN10: true,
|
15725 | LOG2E: true,
|
15726 | LOG10E: true,
|
15727 | NaN: true,
|
15728 | phi: true,
|
15729 | pi: true,
|
15730 | SQRT1_2: true,
|
15731 | SQRT2: true,
|
15732 | tau: true
|
15733 |
|
15734 |
|
15735 |
|
15736 |
|
15737 |
|
15738 |
|
15739 |
|
15740 |
|
15741 |
|
15742 |
|
15743 |
|
15744 |
|
15745 | };
|
15746 | simplify.rules = [simplifyCore,
|
15747 |
|
15748 |
|
15749 |
|
15750 |
|
15751 |
|
15752 |
|
15753 | {
|
15754 | l: 'log(e)',
|
15755 | r: '1'
|
15756 | },
|
15757 | {
|
15758 | l: 'n-n1',
|
15759 | r: 'n+-n1'
|
15760 | },
|
15761 | {
|
15762 | l: '-(c*v)',
|
15763 | r: '(-c) * v'
|
15764 | },
|
15765 | {
|
15766 | l: '-v',
|
15767 | r: '(-1) * v'
|
15768 | }, {
|
15769 | l: 'n/n1^n2',
|
15770 | r: 'n*n1^-n2'
|
15771 | },
|
15772 | {
|
15773 | l: 'n/n1',
|
15774 | r: 'n*n1^-1'
|
15775 | },
|
15776 | {
|
15777 | l: '(n ^ n1) ^ n2',
|
15778 | r: 'n ^ (n1 * n2)'
|
15779 | },
|
15780 | {
|
15781 | l: 'n*n',
|
15782 | r: 'n^2'
|
15783 | }, {
|
15784 | l: 'n * n^n1',
|
15785 | r: 'n^(n1+1)'
|
15786 | }, {
|
15787 | l: 'n^n1 * n^n2',
|
15788 | r: 'n^(n1+n2)'
|
15789 | },
|
15790 | {
|
15791 | l: 'n+n',
|
15792 | r: '2*n'
|
15793 | }, {
|
15794 | l: 'n+-n',
|
15795 | r: '0'
|
15796 | }, {
|
15797 | l: 'n1*n2 + n2',
|
15798 | r: '(n1+1)*n2'
|
15799 | }, {
|
15800 | l: 'n1*n3 + n2*n3',
|
15801 | r: '(n1+n2)*n3'
|
15802 | },
|
15803 | {
|
15804 | l: 'n1 + -1 * (n2 + n3)',
|
15805 | r: 'n1 + -1 * n2 + -1 * n3'
|
15806 | }, simplifyConstant, {
|
15807 | l: '(-n)*n1',
|
15808 | r: '-(n*n1)'
|
15809 | },
|
15810 |
|
15811 | {
|
15812 | l: 'c+v',
|
15813 | r: 'v+c',
|
15814 | context: {
|
15815 | 'add': {
|
15816 | commutative: false
|
15817 | }
|
15818 | }
|
15819 | }, {
|
15820 | l: 'v*c',
|
15821 | r: 'c*v',
|
15822 | context: {
|
15823 | 'multiply': {
|
15824 | commutative: false
|
15825 | }
|
15826 | }
|
15827 | },
|
15828 |
|
15829 | {
|
15830 | l: 'n+-n1',
|
15831 | r: 'n-n1'
|
15832 | },
|
15833 | {
|
15834 | l: 'n*(n1^-1)',
|
15835 | r: 'n/n1'
|
15836 | },
|
15837 | {
|
15838 | l: 'n*n1^-n2',
|
15839 | r: 'n/n1^n2'
|
15840 | }, {
|
15841 | l: 'n1^-1',
|
15842 | r: '1/n1'
|
15843 | }, {
|
15844 | l: 'n*(n1/n2)',
|
15845 | r: '(n*n1)/n2'
|
15846 | },
|
15847 | {
|
15848 | l: 'n-(n1+n2)',
|
15849 | r: 'n-n1-n2'
|
15850 | },
|
15851 |
|
15852 |
|
15853 | {
|
15854 | l: '1*n',
|
15855 | r: 'n'
|
15856 |
|
15857 | }];
|
15858 | |
15859 |
|
15860 |
|
15861 |
|
15862 |
|
15863 |
|
15864 |
|
15865 |
|
15866 |
|
15867 |
|
15868 |
|
15869 |
|
15870 |
|
15871 |
|
15872 |
|
15873 |
|
15874 |
|
15875 | function _buildRules(rules) {
|
15876 |
|
15877 | var ruleSet = [];
|
15878 |
|
15879 | for (var i = 0; i < rules.length; i++) {
|
15880 | var rule = rules[i];
|
15881 | var newRule = void 0;
|
15882 |
|
15883 | var ruleType = _typeof(rule);
|
15884 |
|
15885 | switch (ruleType) {
|
15886 | case 'string':
|
15887 | var lr = rule.split('->');
|
15888 |
|
15889 | if (lr.length === 2) {
|
15890 | rule = {
|
15891 | l: lr[0],
|
15892 | r: lr[1]
|
15893 | };
|
15894 | } else {
|
15895 | throw SyntaxError('Could not parse rule: ' + rule);
|
15896 | }
|
15897 |
|
15898 |
|
15899 |
|
15900 | case 'object':
|
15901 | newRule = {
|
15902 | l: removeParens(parse(rule.l)),
|
15903 | r: removeParens(parse(rule.r))
|
15904 | };
|
15905 |
|
15906 | if (rule.context) {
|
15907 | newRule.evaluate = rule.context;
|
15908 | }
|
15909 |
|
15910 | if (rule.evaluate) {
|
15911 | newRule.evaluate = parse(rule.evaluate);
|
15912 | }
|
15913 |
|
15914 | if (isAssociative(newRule.l)) {
|
15915 | var makeNode = createMakeNodeFunction(newRule.l);
|
15916 |
|
15917 | var expandsym = _getExpandPlaceholderSymbol();
|
15918 |
|
15919 | newRule.expanded = {};
|
15920 | newRule.expanded.l = makeNode([newRule.l.clone(), expandsym]);
|
15921 |
|
15922 |
|
15923 | flatten(newRule.expanded.l);
|
15924 | unflattenr(newRule.expanded.l);
|
15925 | newRule.expanded.r = makeNode([newRule.r, expandsym]);
|
15926 | }
|
15927 |
|
15928 | break;
|
15929 |
|
15930 | case 'function':
|
15931 | newRule = rule;
|
15932 | break;
|
15933 |
|
15934 | default:
|
15935 | throw TypeError('Unsupported type of rule: ' + ruleType);
|
15936 | }
|
15937 |
|
15938 |
|
15939 |
|
15940 | ruleSet.push(newRule);
|
15941 | }
|
15942 |
|
15943 | return ruleSet;
|
15944 | }
|
15945 |
|
15946 | var _lastsym = 0;
|
15947 |
|
15948 | function _getExpandPlaceholderSymbol() {
|
15949 | return new SymbolNode('_p' + _lastsym++);
|
15950 | }
|
15951 | |
15952 |
|
15953 |
|
15954 |
|
15955 |
|
15956 |
|
15957 |
|
15958 |
|
15959 | var applyRule = typed('applyRule', {
|
15960 | 'Node, Object': function NodeObject(node, rule) {
|
15961 |
|
15962 |
|
15963 | var res = node;
|
15964 |
|
15965 |
|
15966 |
|
15967 | if (res instanceof OperatorNode || res instanceof FunctionNode) {
|
15968 | if (res.args) {
|
15969 | for (var i = 0; i < res.args.length; i++) {
|
15970 | res.args[i] = applyRule(res.args[i], rule);
|
15971 | }
|
15972 | }
|
15973 | } else if (res instanceof ParenthesisNode) {
|
15974 | if (res.content) {
|
15975 | res.content = applyRule(res.content, rule);
|
15976 | }
|
15977 | }
|
15978 |
|
15979 |
|
15980 | var repl = rule.r;
|
15981 |
|
15982 | var matches = _ruleMatch(rule.l, res)[0];
|
15983 |
|
15984 |
|
15985 |
|
15986 | if (!matches && rule.expanded) {
|
15987 | repl = rule.expanded.r;
|
15988 | matches = _ruleMatch(rule.expanded.l, res)[0];
|
15989 | }
|
15990 |
|
15991 | if (matches) {
|
15992 |
|
15993 |
|
15994 |
|
15995 | var implicit = res.implicit;
|
15996 | res = repl.clone();
|
15997 |
|
15998 | if (implicit && 'implicit' in repl) {
|
15999 | res.implicit = true;
|
16000 | }
|
16001 |
|
16002 |
|
16003 | var _transform = function _transform(node) {
|
16004 | if (node.isSymbolNode && matches.placeholders.hasOwnProperty(node.name)) {
|
16005 | return matches.placeholders[node.name].clone();
|
16006 | } else {
|
16007 | return node.map(_transform);
|
16008 | }
|
16009 | };
|
16010 |
|
16011 | res = _transform(res);
|
16012 |
|
16013 | }
|
16014 |
|
16015 | return res;
|
16016 | }
|
16017 | });
|
16018 | |
16019 |
|
16020 |
|
16021 |
|
16022 |
|
16023 |
|
16024 |
|
16025 |
|
16026 |
|
16027 | function getSplits(node, context) {
|
16028 | var res = [];
|
16029 | var right, rightArgs;
|
16030 | var makeNode = createMakeNodeFunction(node);
|
16031 |
|
16032 | if (isCommutative(node, context)) {
|
16033 | for (var i = 0; i < node.args.length; i++) {
|
16034 | rightArgs = node.args.slice(0);
|
16035 | rightArgs.splice(i, 1);
|
16036 | right = rightArgs.length === 1 ? rightArgs[0] : makeNode(rightArgs);
|
16037 | res.push(makeNode([node.args[i], right]));
|
16038 | }
|
16039 | } else {
|
16040 | rightArgs = node.args.slice(1);
|
16041 | right = rightArgs.length === 1 ? rightArgs[0] : makeNode(rightArgs);
|
16042 | res.push(makeNode([node.args[0], right]));
|
16043 | }
|
16044 |
|
16045 | return res;
|
16046 | }
|
16047 | |
16048 |
|
16049 |
|
16050 |
|
16051 |
|
16052 | function mergeMatch(match1, match2) {
|
16053 | var res = {
|
16054 | placeholders: {}
|
16055 |
|
16056 | };
|
16057 |
|
16058 | if (!match1.placeholders && !match2.placeholders) {
|
16059 | return res;
|
16060 | } else if (!match1.placeholders) {
|
16061 | return match2;
|
16062 | } else if (!match2.placeholders) {
|
16063 | return match1;
|
16064 | }
|
16065 |
|
16066 |
|
16067 | for (var key in match1.placeholders) {
|
16068 | res.placeholders[key] = match1.placeholders[key];
|
16069 |
|
16070 | if (match2.placeholders.hasOwnProperty(key)) {
|
16071 | if (!_exactMatch(match1.placeholders[key], match2.placeholders[key])) {
|
16072 | return null;
|
16073 | }
|
16074 | }
|
16075 | }
|
16076 |
|
16077 | for (var _key in match2.placeholders) {
|
16078 | res.placeholders[_key] = match2.placeholders[_key];
|
16079 | }
|
16080 |
|
16081 | return res;
|
16082 | }
|
16083 | |
16084 |
|
16085 |
|
16086 |
|
16087 |
|
16088 |
|
16089 | function combineChildMatches(list1, list2) {
|
16090 | var res = [];
|
16091 |
|
16092 | if (list1.length === 0 || list2.length === 0) {
|
16093 | return res;
|
16094 | }
|
16095 |
|
16096 | var merged;
|
16097 |
|
16098 | for (var i1 = 0; i1 < list1.length; i1++) {
|
16099 | for (var i2 = 0; i2 < list2.length; i2++) {
|
16100 | merged = mergeMatch(list1[i1], list2[i2]);
|
16101 |
|
16102 | if (merged) {
|
16103 | res.push(merged);
|
16104 | }
|
16105 | }
|
16106 | }
|
16107 |
|
16108 | return res;
|
16109 | }
|
16110 | |
16111 |
|
16112 |
|
16113 |
|
16114 |
|
16115 |
|
16116 |
|
16117 | function mergeChildMatches(childMatches) {
|
16118 | if (childMatches.length === 0) {
|
16119 | return childMatches;
|
16120 | }
|
16121 |
|
16122 | var sets = childMatches.reduce(combineChildMatches);
|
16123 | var uniqueSets = [];
|
16124 | var unique = {};
|
16125 |
|
16126 | for (var i = 0; i < sets.length; i++) {
|
16127 | var s = JSON.stringify(sets[i]);
|
16128 |
|
16129 | if (!unique[s]) {
|
16130 | unique[s] = true;
|
16131 | uniqueSets.push(sets[i]);
|
16132 | }
|
16133 | }
|
16134 |
|
16135 | return uniqueSets;
|
16136 | }
|
16137 | |
16138 |
|
16139 |
|
16140 |
|
16141 |
|
16142 |
|
16143 |
|
16144 |
|
16145 |
|
16146 | function _ruleMatch(rule, node, isSplit) {
|
16147 |
|
16148 |
|
16149 |
|
16150 |
|
16151 | var res = [{
|
16152 | placeholders: {}
|
16153 | }];
|
16154 |
|
16155 | if (rule instanceof OperatorNode && node instanceof OperatorNode || rule instanceof FunctionNode && node instanceof FunctionNode) {
|
16156 |
|
16157 | if (rule instanceof OperatorNode) {
|
16158 | if (rule.op !== node.op || rule.fn !== node.fn) {
|
16159 | return [];
|
16160 | }
|
16161 | } else if (rule instanceof FunctionNode) {
|
16162 | if (rule.name !== node.name) {
|
16163 | return [];
|
16164 | }
|
16165 | }
|
16166 |
|
16167 |
|
16168 | if (node.args.length === 1 && rule.args.length === 1 || !isAssociative(node) || isSplit) {
|
16169 |
|
16170 | var childMatches = [];
|
16171 |
|
16172 | for (var i = 0; i < rule.args.length; i++) {
|
16173 | var childMatch = _ruleMatch(rule.args[i], node.args[i]);
|
16174 |
|
16175 | if (childMatch.length === 0) {
|
16176 |
|
16177 | return [];
|
16178 | }
|
16179 |
|
16180 |
|
16181 | childMatches.push(childMatch);
|
16182 | }
|
16183 |
|
16184 | res = mergeChildMatches(childMatches);
|
16185 | } else if (node.args.length >= 2 && rule.args.length === 2) {
|
16186 |
|
16187 |
|
16188 |
|
16189 | var splits = getSplits(node, rule.context);
|
16190 | var splitMatches = [];
|
16191 |
|
16192 | for (var _i = 0; _i < splits.length; _i++) {
|
16193 | var matchSet = _ruleMatch(rule, splits[_i], true);
|
16194 |
|
16195 |
|
16196 | splitMatches = splitMatches.concat(matchSet);
|
16197 | }
|
16198 |
|
16199 | return splitMatches;
|
16200 | } else if (rule.args.length > 2) {
|
16201 | throw Error('Unexpected non-binary associative function: ' + rule.toString());
|
16202 | } else {
|
16203 |
|
16204 | return [];
|
16205 | }
|
16206 | } else if (rule instanceof SymbolNode) {
|
16207 |
|
16208 |
|
16209 |
|
16210 |
|
16211 | if (rule.name.length === 0) {
|
16212 | throw new Error('Symbol in rule has 0 length...!?');
|
16213 | }
|
16214 |
|
16215 | if (math.hasOwnProperty(rule.name)) {
|
16216 | if (!SUPPORTED_CONSTANTS[rule.name]) {
|
16217 | throw new Error('Built in constant: ' + rule.name + ' is not supported by simplify.');
|
16218 | }
|
16219 |
|
16220 |
|
16221 | if (rule.name !== node.name) {
|
16222 | return [];
|
16223 | }
|
16224 | } else if (rule.name[0] === 'n' || rule.name.substring(0, 2) === '_p') {
|
16225 |
|
16226 |
|
16227 |
|
16228 | res[0].placeholders[rule.name] = node;
|
16229 | } else if (rule.name[0] === 'v') {
|
16230 |
|
16231 | if (!type.isConstantNode(node)) {
|
16232 | res[0].placeholders[rule.name] = node;
|
16233 | } else {
|
16234 |
|
16235 | return [];
|
16236 | }
|
16237 | } else if (rule.name[0] === 'c') {
|
16238 |
|
16239 | if (node instanceof ConstantNode) {
|
16240 | res[0].placeholders[rule.name] = node;
|
16241 | } else {
|
16242 |
|
16243 | return [];
|
16244 | }
|
16245 | } else {
|
16246 | throw new Error('Invalid symbol in rule: ' + rule.name);
|
16247 | }
|
16248 | } else if (rule instanceof ConstantNode) {
|
16249 |
|
16250 | if (!equal(rule.value, node.value)) {
|
16251 | return [];
|
16252 | }
|
16253 | } else {
|
16254 |
|
16255 | return [];
|
16256 | }
|
16257 |
|
16258 |
|
16259 |
|
16260 | return res;
|
16261 | }
|
16262 | |
16263 |
|
16264 |
|
16265 |
|
16266 |
|
16267 |
|
16268 |
|
16269 |
|
16270 |
|
16271 | function _exactMatch(p, q) {
|
16272 | if (p instanceof ConstantNode && q instanceof ConstantNode) {
|
16273 | if (!equal(p.value, q.value)) {
|
16274 | return false;
|
16275 | }
|
16276 | } else if (p instanceof SymbolNode && q instanceof SymbolNode) {
|
16277 | if (p.name !== q.name) {
|
16278 | return false;
|
16279 | }
|
16280 | } else if (p instanceof OperatorNode && q instanceof OperatorNode || p instanceof FunctionNode && q instanceof FunctionNode) {
|
16281 | if (p instanceof OperatorNode) {
|
16282 | if (p.op !== q.op || p.fn !== q.fn) {
|
16283 | return false;
|
16284 | }
|
16285 | } else if (p instanceof FunctionNode) {
|
16286 | if (p.name !== q.name) {
|
16287 | return false;
|
16288 | }
|
16289 | }
|
16290 |
|
16291 | if (p.args.length !== q.args.length) {
|
16292 | return false;
|
16293 | }
|
16294 |
|
16295 | for (var i = 0; i < p.args.length; i++) {
|
16296 | if (!_exactMatch(p.args[i], q.args[i])) {
|
16297 | return false;
|
16298 | }
|
16299 | }
|
16300 | } else {
|
16301 | return false;
|
16302 | }
|
16303 |
|
16304 | return true;
|
16305 | }
|
16306 |
|
16307 | return simplify;
|
16308 | }
|
16309 |
|
16310 | exports.math = true;
|
16311 | exports.name = 'simplify';
|
16312 | exports.factory = factory;
|
16313 |
|
16314 | }),
|
16315 |
|
16316 | (function(module, exports, __webpack_require__) {
|
16317 |
|
16318 | "use strict";
|
16319 |
|
16320 |
|
16321 | var util = __webpack_require__(31);
|
16322 |
|
16323 | var object = util.object;
|
16324 |
|
16325 | function factory(type, config, load, typed) {
|
16326 | var matrix = load(__webpack_require__(0));
|
16327 | var abs = load(__webpack_require__(25));
|
16328 | var addScalar = load(__webpack_require__(17));
|
16329 | var divideScalar = load(__webpack_require__(12));
|
16330 | var multiplyScalar = load(__webpack_require__(21));
|
16331 | var subtract = load(__webpack_require__(15));
|
16332 | var larger = load(__webpack_require__(33));
|
16333 | var equalScalar = load(__webpack_require__(11));
|
16334 | var unaryMinus = load(__webpack_require__(39));
|
16335 | var SparseMatrix = type.SparseMatrix;
|
16336 | var DenseMatrix = type.DenseMatrix;
|
16337 | var Spa = type.Spa;
|
16338 | |
16339 |
|
16340 |
|
16341 |
|
16342 |
|
16343 |
|
16344 |
|
16345 |
|
16346 |
|
16347 |
|
16348 |
|
16349 |
|
16350 |
|
16351 |
|
16352 |
|
16353 |
|
16354 |
|
16355 |
|
16356 |
|
16357 |
|
16358 |
|
16359 |
|
16360 |
|
16361 |
|
16362 |
|
16363 |
|
16364 |
|
16365 | var lup = typed('lup', {
|
16366 | 'DenseMatrix': function DenseMatrix(m) {
|
16367 | return _denseLUP(m);
|
16368 | },
|
16369 | 'SparseMatrix': function SparseMatrix(m) {
|
16370 | return _sparseLUP(m);
|
16371 | },
|
16372 | 'Array': function Array(a) {
|
16373 |
|
16374 | var m = matrix(a);
|
16375 |
|
16376 | var r = _denseLUP(m);
|
16377 |
|
16378 |
|
16379 | return {
|
16380 | L: r.L.valueOf(),
|
16381 | U: r.U.valueOf(),
|
16382 | p: r.p
|
16383 | };
|
16384 | }
|
16385 | });
|
16386 |
|
16387 | function _denseLUP(m) {
|
16388 |
|
16389 | var rows = m._size[0];
|
16390 | var columns = m._size[1];
|
16391 |
|
16392 | var n = Math.min(rows, columns);
|
16393 |
|
16394 | var data = object.clone(m._data);
|
16395 |
|
16396 | var ldata = [];
|
16397 | var lsize = [rows, n];
|
16398 |
|
16399 | var udata = [];
|
16400 | var usize = [n, columns];
|
16401 |
|
16402 | var i, j, k;
|
16403 |
|
16404 | var p = [];
|
16405 |
|
16406 | for (i = 0; i < rows; i++) {
|
16407 | p[i] = i;
|
16408 | }
|
16409 |
|
16410 |
|
16411 | for (j = 0; j < columns; j++) {
|
16412 |
|
16413 | if (j > 0) {
|
16414 |
|
16415 | for (i = 0; i < rows; i++) {
|
16416 |
|
16417 | var min = Math.min(i, j);
|
16418 |
|
16419 | var s = 0;
|
16420 |
|
16421 | for (k = 0; k < min; k++) {
|
16422 |
|
16423 | s = addScalar(s, multiplyScalar(data[i][k], data[k][j]));
|
16424 | }
|
16425 |
|
16426 | data[i][j] = subtract(data[i][j], s);
|
16427 | }
|
16428 | }
|
16429 |
|
16430 |
|
16431 | var pi = j;
|
16432 | var pabsv = 0;
|
16433 | var vjj = 0;
|
16434 |
|
16435 | for (i = j; i < rows; i++) {
|
16436 |
|
16437 | var v = data[i][j];
|
16438 |
|
16439 | var absv = abs(v);
|
16440 |
|
16441 | if (larger(absv, pabsv)) {
|
16442 |
|
16443 | pi = i;
|
16444 |
|
16445 | pabsv = absv;
|
16446 |
|
16447 | vjj = v;
|
16448 | }
|
16449 | }
|
16450 |
|
16451 |
|
16452 | if (j !== pi) {
|
16453 |
|
16454 | p[j] = [p[pi], p[pi] = p[j]][0];
|
16455 |
|
16456 | DenseMatrix._swapRows(j, pi, data);
|
16457 | }
|
16458 |
|
16459 |
|
16460 | if (j < rows) {
|
16461 |
|
16462 | for (i = j + 1; i < rows; i++) {
|
16463 |
|
16464 | var vij = data[i][j];
|
16465 |
|
16466 | if (!equalScalar(vij, 0)) {
|
16467 |
|
16468 | data[i][j] = divideScalar(data[i][j], vjj);
|
16469 | }
|
16470 | }
|
16471 | }
|
16472 | }
|
16473 |
|
16474 |
|
16475 | for (j = 0; j < columns; j++) {
|
16476 |
|
16477 | for (i = 0; i < rows; i++) {
|
16478 |
|
16479 | if (j === 0) {
|
16480 |
|
16481 | if (i < columns) {
|
16482 |
|
16483 | udata[i] = [];
|
16484 | }
|
16485 |
|
16486 |
|
16487 | ldata[i] = [];
|
16488 | }
|
16489 |
|
16490 |
|
16491 | if (i < j) {
|
16492 |
|
16493 | if (i < columns) {
|
16494 |
|
16495 | udata[i][j] = data[i][j];
|
16496 | }
|
16497 |
|
16498 |
|
16499 | if (j < rows) {
|
16500 |
|
16501 | ldata[i][j] = 0;
|
16502 | }
|
16503 |
|
16504 | continue;
|
16505 | }
|
16506 |
|
16507 |
|
16508 | if (i === j) {
|
16509 |
|
16510 | if (i < columns) {
|
16511 |
|
16512 | udata[i][j] = data[i][j];
|
16513 | }
|
16514 |
|
16515 |
|
16516 | if (j < rows) {
|
16517 |
|
16518 | ldata[i][j] = 1;
|
16519 | }
|
16520 |
|
16521 | continue;
|
16522 | }
|
16523 |
|
16524 |
|
16525 | if (i < columns) {
|
16526 |
|
16527 | udata[i][j] = 0;
|
16528 | }
|
16529 |
|
16530 |
|
16531 | if (j < rows) {
|
16532 |
|
16533 | ldata[i][j] = data[i][j];
|
16534 | }
|
16535 | }
|
16536 | }
|
16537 |
|
16538 |
|
16539 | var l = new DenseMatrix({
|
16540 | data: ldata,
|
16541 | size: lsize
|
16542 | });
|
16543 |
|
16544 | var u = new DenseMatrix({
|
16545 | data: udata,
|
16546 | size: usize
|
16547 | });
|
16548 |
|
16549 | var pv = [];
|
16550 |
|
16551 | for (i = 0, n = p.length; i < n; i++) {
|
16552 | pv[p[i]] = i;
|
16553 | }
|
16554 |
|
16555 |
|
16556 | return {
|
16557 | L: l,
|
16558 | U: u,
|
16559 | p: pv,
|
16560 | toString: function toString() {
|
16561 | return 'L: ' + this.L.toString() + '\nU: ' + this.U.toString() + '\nP: ' + this.p;
|
16562 | }
|
16563 | };
|
16564 | }
|
16565 |
|
16566 | function _sparseLUP(m) {
|
16567 |
|
16568 | var rows = m._size[0];
|
16569 | var columns = m._size[1];
|
16570 |
|
16571 | var n = Math.min(rows, columns);
|
16572 |
|
16573 | var values = m._values;
|
16574 | var index = m._index;
|
16575 | var ptr = m._ptr;
|
16576 |
|
16577 | var lvalues = [];
|
16578 | var lindex = [];
|
16579 | var lptr = [];
|
16580 | var lsize = [rows, n];
|
16581 |
|
16582 | var uvalues = [];
|
16583 | var uindex = [];
|
16584 | var uptr = [];
|
16585 | var usize = [n, columns];
|
16586 |
|
16587 | var i, j, k;
|
16588 |
|
16589 | var pvCo = [];
|
16590 | var pvOc = [];
|
16591 |
|
16592 | for (i = 0; i < rows; i++) {
|
16593 | pvCo[i] = i;
|
16594 | pvOc[i] = i;
|
16595 | }
|
16596 |
|
16597 |
|
16598 | var swapIndeces = function swapIndeces(x, y) {
|
16599 |
|
16600 | var kx = pvOc[x];
|
16601 | var ky = pvOc[y];
|
16602 |
|
16603 | pvCo[kx] = y;
|
16604 | pvCo[ky] = x;
|
16605 |
|
16606 | pvOc[x] = ky;
|
16607 | pvOc[y] = kx;
|
16608 | };
|
16609 |
|
16610 |
|
16611 | var _loop = function _loop() {
|
16612 |
|
16613 | var spa = new Spa();
|
16614 |
|
16615 | if (j < rows) {
|
16616 |
|
16617 | lptr.push(lvalues.length);
|
16618 |
|
16619 | lvalues.push(1);
|
16620 | lindex.push(j);
|
16621 | }
|
16622 |
|
16623 |
|
16624 | uptr.push(uvalues.length);
|
16625 |
|
16626 | var k0 = ptr[j];
|
16627 | var k1 = ptr[j + 1];
|
16628 |
|
16629 | for (k = k0; k < k1; k++) {
|
16630 |
|
16631 | i = index[k];
|
16632 |
|
16633 | spa.set(pvCo[i], values[k]);
|
16634 | }
|
16635 |
|
16636 |
|
16637 | if (j > 0) {
|
16638 |
|
16639 | spa.forEach(0, j - 1, function (k, vkj) {
|
16640 |
|
16641 | SparseMatrix._forEachRow(k, lvalues, lindex, lptr, function (i, vik) {
|
16642 |
|
16643 | if (i > k) {
|
16644 |
|
16645 | spa.accumulate(i, unaryMinus(multiplyScalar(vik, vkj)));
|
16646 | }
|
16647 | });
|
16648 | });
|
16649 | }
|
16650 |
|
16651 |
|
16652 | var pi = j;
|
16653 | var vjj = spa.get(j);
|
16654 | var pabsv = abs(vjj);
|
16655 |
|
16656 | spa.forEach(j + 1, rows - 1, function (x, v) {
|
16657 |
|
16658 | var absv = abs(v);
|
16659 |
|
16660 | if (larger(absv, pabsv)) {
|
16661 |
|
16662 | pi = x;
|
16663 |
|
16664 | pabsv = absv;
|
16665 |
|
16666 | vjj = v;
|
16667 | }
|
16668 | });
|
16669 |
|
16670 | if (j !== pi) {
|
16671 |
|
16672 | SparseMatrix._swapRows(j, pi, lsize[1], lvalues, lindex, lptr);
|
16673 |
|
16674 |
|
16675 | SparseMatrix._swapRows(j, pi, usize[1], uvalues, uindex, uptr);
|
16676 |
|
16677 |
|
16678 | spa.swap(j, pi);
|
16679 |
|
16680 | swapIndeces(j, pi);
|
16681 | }
|
16682 |
|
16683 |
|
16684 | spa.forEach(0, rows - 1, function (x, v) {
|
16685 |
|
16686 | if (x <= j) {
|
16687 |
|
16688 | uvalues.push(v);
|
16689 | uindex.push(x);
|
16690 | } else {
|
16691 |
|
16692 | v = divideScalar(v, vjj);
|
16693 |
|
16694 | if (!equalScalar(v, 0)) {
|
16695 |
|
16696 | lvalues.push(v);
|
16697 | lindex.push(x);
|
16698 | }
|
16699 | }
|
16700 | });
|
16701 | };
|
16702 |
|
16703 | for (j = 0; j < columns; j++) {
|
16704 | _loop();
|
16705 | }
|
16706 |
|
16707 |
|
16708 | uptr.push(uvalues.length);
|
16709 | lptr.push(lvalues.length);
|
16710 |
|
16711 | return {
|
16712 | L: new SparseMatrix({
|
16713 | values: lvalues,
|
16714 | index: lindex,
|
16715 | ptr: lptr,
|
16716 | size: lsize
|
16717 | }),
|
16718 | U: new SparseMatrix({
|
16719 | values: uvalues,
|
16720 | index: uindex,
|
16721 | ptr: uptr,
|
16722 | size: usize
|
16723 | }),
|
16724 | p: pvCo,
|
16725 | toString: function toString() {
|
16726 | return 'L: ' + this.L.toString() + '\nU: ' + this.U.toString() + '\nP: ' + this.p;
|
16727 | }
|
16728 | };
|
16729 | }
|
16730 |
|
16731 | return lup;
|
16732 | }
|
16733 |
|
16734 | exports.name = 'lup';
|
16735 | exports.factory = factory;
|
16736 |
|
16737 | }),
|
16738 |
|
16739 | (function(module, exports, __webpack_require__) {
|
16740 |
|
16741 | "use strict";
|
16742 |
|
16743 |
|
16744 | function factory() {
|
16745 | |
16746 |
|
16747 |
|
16748 |
|
16749 |
|
16750 |
|
16751 |
|
16752 | var csFlip = function csFlip(i) {
|
16753 |
|
16754 | return -i - 2;
|
16755 | };
|
16756 |
|
16757 | return csFlip;
|
16758 | }
|
16759 |
|
16760 | exports.name = 'csFlip';
|
16761 | exports.path = 'algebra.sparse';
|
16762 | exports.factory = factory;
|
16763 |
|
16764 | }),
|
16765 |
|
16766 | (function(module, exports, __webpack_require__) {
|
16767 |
|
16768 | "use strict";
|
16769 |
|
16770 |
|
16771 | var nearlyEqual = __webpack_require__(3).nearlyEqual;
|
16772 |
|
16773 | var bigNearlyEqual = __webpack_require__(32);
|
16774 |
|
16775 | function factory(type, config, load, typed) {
|
16776 | var matrix = load(__webpack_require__(0));
|
16777 | var algorithm03 = load(__webpack_require__(18));
|
16778 | var algorithm07 = load(__webpack_require__(29));
|
16779 | var algorithm12 = load(__webpack_require__(19));
|
16780 | var algorithm13 = load(__webpack_require__(7));
|
16781 | var algorithm14 = load(__webpack_require__(6));
|
16782 |
|
16783 | var latex = __webpack_require__(4);
|
16784 | |
16785 |
|
16786 |
|
16787 |
|
16788 |
|
16789 |
|
16790 |
|
16791 |
|
16792 |
|
16793 |
|
16794 |
|
16795 |
|
16796 |
|
16797 |
|
16798 |
|
16799 |
|
16800 |
|
16801 |
|
16802 |
|
16803 |
|
16804 |
|
16805 |
|
16806 |
|
16807 |
|
16808 |
|
16809 |
|
16810 |
|
16811 |
|
16812 |
|
16813 | var largerEq = typed('largerEq', {
|
16814 | 'boolean, boolean': function booleanBoolean(x, y) {
|
16815 | return x >= y;
|
16816 | },
|
16817 | 'number, number': function numberNumber(x, y) {
|
16818 | return x >= y || nearlyEqual(x, y, config.epsilon);
|
16819 | },
|
16820 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
16821 | return x.gte(y) || bigNearlyEqual(x, y, config.epsilon);
|
16822 | },
|
16823 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
16824 | return x.compare(y) !== -1;
|
16825 | },
|
16826 | 'Complex, Complex': function ComplexComplex() {
|
16827 | throw new TypeError('No ordering relation is defined for complex numbers');
|
16828 | },
|
16829 | 'Unit, Unit': function UnitUnit(x, y) {
|
16830 | if (!x.equalBase(y)) {
|
16831 | throw new Error('Cannot compare units with different base');
|
16832 | }
|
16833 |
|
16834 | return largerEq(x.value, y.value);
|
16835 | },
|
16836 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
16837 | return algorithm07(x, y, largerEq);
|
16838 | },
|
16839 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
16840 | return algorithm03(y, x, largerEq, true);
|
16841 | },
|
16842 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
16843 | return algorithm03(x, y, largerEq, false);
|
16844 | },
|
16845 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
16846 | return algorithm13(x, y, largerEq);
|
16847 | },
|
16848 | 'Array, Array': function ArrayArray(x, y) {
|
16849 |
|
16850 | return largerEq(matrix(x), matrix(y)).valueOf();
|
16851 | },
|
16852 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
16853 |
|
16854 | return largerEq(matrix(x), y);
|
16855 | },
|
16856 | 'Matrix, Array': function MatrixArray(x, y) {
|
16857 |
|
16858 | return largerEq(x, matrix(y));
|
16859 | },
|
16860 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
16861 | return algorithm12(x, y, largerEq, false);
|
16862 | },
|
16863 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
16864 | return algorithm14(x, y, largerEq, false);
|
16865 | },
|
16866 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
16867 | return algorithm12(y, x, largerEq, true);
|
16868 | },
|
16869 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
16870 | return algorithm14(y, x, largerEq, true);
|
16871 | },
|
16872 | 'Array, any': function ArrayAny(x, y) {
|
16873 |
|
16874 | return algorithm14(matrix(x), y, largerEq, false).valueOf();
|
16875 | },
|
16876 | 'any, Array': function anyArray(x, y) {
|
16877 |
|
16878 | return algorithm14(matrix(y), x, largerEq, true).valueOf();
|
16879 | }
|
16880 | });
|
16881 | largerEq.toTex = {
|
16882 | 2: "\\left(${args[0]}".concat(latex.operators['largerEq'], "${args[1]}\\right)")
|
16883 | };
|
16884 | return largerEq;
|
16885 | }
|
16886 |
|
16887 | exports.name = 'largerEq';
|
16888 | exports.factory = factory;
|
16889 |
|
16890 | }),
|
16891 |
|
16892 | (function(module, exports, __webpack_require__) {
|
16893 |
|
16894 | "use strict";
|
16895 |
|
16896 |
|
16897 | var util = __webpack_require__(31);
|
16898 |
|
16899 | var string = util.string;
|
16900 | var array = util.array;
|
16901 | var isArray = Array.isArray;
|
16902 |
|
16903 | function factory(type) {
|
16904 | var DenseMatrix = type.DenseMatrix;
|
16905 | |
16906 |
|
16907 |
|
16908 |
|
16909 |
|
16910 |
|
16911 |
|
16912 |
|
16913 |
|
16914 |
|
16915 | var solveValidation = function solveValidation(m, b, copy) {
|
16916 |
|
16917 | var size = m.size();
|
16918 |
|
16919 | if (size.length !== 2) {
|
16920 | throw new RangeError('Matrix must be two dimensional (size: ' + string.format(size) + ')');
|
16921 | }
|
16922 |
|
16923 |
|
16924 | var rows = size[0];
|
16925 | var columns = size[1];
|
16926 |
|
16927 | if (rows !== columns) {
|
16928 | throw new RangeError('Matrix must be square (size: ' + string.format(size) + ')');
|
16929 | }
|
16930 |
|
16931 |
|
16932 | var data, i, bdata;
|
16933 |
|
16934 | if (type.isMatrix(b)) {
|
16935 |
|
16936 | var msize = b.size();
|
16937 |
|
16938 | if (msize.length === 1) {
|
16939 |
|
16940 | if (msize[0] !== rows) {
|
16941 | throw new RangeError('Dimension mismatch. Matrix columns must match vector length.');
|
16942 | }
|
16943 |
|
16944 |
|
16945 | data = [];
|
16946 |
|
16947 | bdata = b._data;
|
16948 |
|
16949 | for (i = 0; i < rows; i++) {
|
16950 |
|
16951 | data[i] = [bdata[i]];
|
16952 | }
|
16953 |
|
16954 |
|
16955 | return new DenseMatrix({
|
16956 | data: data,
|
16957 | size: [rows, 1],
|
16958 | datatype: b._datatype
|
16959 | });
|
16960 | }
|
16961 |
|
16962 |
|
16963 | if (msize.length === 2) {
|
16964 |
|
16965 | if (msize[0] !== rows || msize[1] !== 1) {
|
16966 | throw new RangeError('Dimension mismatch. Matrix columns must match vector length.');
|
16967 | }
|
16968 |
|
16969 |
|
16970 | if (type.isDenseMatrix(b)) {
|
16971 |
|
16972 | if (copy) {
|
16973 |
|
16974 | data = [];
|
16975 |
|
16976 | bdata = b._data;
|
16977 |
|
16978 | for (i = 0; i < rows; i++) {
|
16979 |
|
16980 | data[i] = [bdata[i][0]];
|
16981 | }
|
16982 |
|
16983 |
|
16984 | return new DenseMatrix({
|
16985 | data: data,
|
16986 | size: [rows, 1],
|
16987 | datatype: b._datatype
|
16988 | });
|
16989 | }
|
16990 |
|
16991 |
|
16992 | return b;
|
16993 | }
|
16994 |
|
16995 |
|
16996 | data = [];
|
16997 |
|
16998 | for (i = 0; i < rows; i++) {
|
16999 | data[i] = [0];
|
17000 | }
|
17001 |
|
17002 |
|
17003 | var values = b._values;
|
17004 | var index = b._index;
|
17005 | var ptr = b._ptr;
|
17006 |
|
17007 | for (var k1 = ptr[1], k = ptr[0]; k < k1; k++) {
|
17008 |
|
17009 | i = index[k];
|
17010 |
|
17011 | data[i][0] = values[k];
|
17012 | }
|
17013 |
|
17014 |
|
17015 | return new DenseMatrix({
|
17016 | data: data,
|
17017 | size: [rows, 1],
|
17018 | datatype: b._datatype
|
17019 | });
|
17020 | }
|
17021 |
|
17022 |
|
17023 | throw new RangeError('Dimension mismatch. Matrix columns must match vector length.');
|
17024 | }
|
17025 |
|
17026 |
|
17027 | if (isArray(b)) {
|
17028 |
|
17029 | var asize = array.size(b);
|
17030 |
|
17031 | if (asize.length === 1) {
|
17032 |
|
17033 | if (asize[0] !== rows) {
|
17034 | throw new RangeError('Dimension mismatch. Matrix columns must match vector length.');
|
17035 | }
|
17036 |
|
17037 |
|
17038 | data = [];
|
17039 |
|
17040 | for (i = 0; i < rows; i++) {
|
17041 |
|
17042 | data[i] = [b[i]];
|
17043 | }
|
17044 |
|
17045 |
|
17046 | return new DenseMatrix({
|
17047 | data: data,
|
17048 | size: [rows, 1]
|
17049 | });
|
17050 | }
|
17051 |
|
17052 | if (asize.length === 2) {
|
17053 |
|
17054 | if (asize[0] !== rows || asize[1] !== 1) {
|
17055 | throw new RangeError('Dimension mismatch. Matrix columns must match vector length.');
|
17056 | }
|
17057 |
|
17058 |
|
17059 | data = [];
|
17060 |
|
17061 | for (i = 0; i < rows; i++) {
|
17062 |
|
17063 | data[i] = [b[i][0]];
|
17064 | }
|
17065 |
|
17066 |
|
17067 | return new DenseMatrix({
|
17068 | data: data,
|
17069 | size: [rows, 1]
|
17070 | });
|
17071 | }
|
17072 |
|
17073 |
|
17074 | throw new RangeError('Dimension mismatch. Matrix columns must match vector length.');
|
17075 | }
|
17076 | };
|
17077 |
|
17078 | return solveValidation;
|
17079 | }
|
17080 |
|
17081 | exports.factory = factory;
|
17082 |
|
17083 | }),
|
17084 |
|
17085 | (function(module, exports, __webpack_require__) {
|
17086 |
|
17087 | "use strict";
|
17088 |
|
17089 |
|
17090 | var deepMap = __webpack_require__(1);
|
17091 |
|
17092 | function factory(type, config, load, typed) {
|
17093 | var divideScalar = load(__webpack_require__(12));
|
17094 | |
17095 |
|
17096 |
|
17097 |
|
17098 |
|
17099 |
|
17100 |
|
17101 |
|
17102 |
|
17103 |
|
17104 |
|
17105 |
|
17106 |
|
17107 |
|
17108 |
|
17109 |
|
17110 |
|
17111 |
|
17112 |
|
17113 |
|
17114 |
|
17115 |
|
17116 |
|
17117 |
|
17118 |
|
17119 |
|
17120 |
|
17121 |
|
17122 |
|
17123 |
|
17124 |
|
17125 |
|
17126 |
|
17127 |
|
17128 |
|
17129 | var log = typed('log', {
|
17130 | 'number': function number(x) {
|
17131 | if (x >= 0 || config.predictable) {
|
17132 | return Math.log(x);
|
17133 | } else {
|
17134 |
|
17135 | return new type.Complex(x, 0).log();
|
17136 | }
|
17137 | },
|
17138 | 'Complex': function Complex(x) {
|
17139 | return x.log();
|
17140 | },
|
17141 | 'BigNumber': function BigNumber(x) {
|
17142 | if (!x.isNegative() || config.predictable) {
|
17143 | return x.ln();
|
17144 | } else {
|
17145 |
|
17146 | return new type.Complex(x.toNumber(), 0).log();
|
17147 | }
|
17148 | },
|
17149 | 'Array | Matrix': function ArrayMatrix(x) {
|
17150 | return deepMap(x, log);
|
17151 | },
|
17152 | 'any, any': function anyAny(x, base) {
|
17153 |
|
17154 | return divideScalar(log(x), log(base));
|
17155 | }
|
17156 | });
|
17157 | log.toTex = {
|
17158 | 1: "\\ln\\left(${args[0]}\\right)",
|
17159 | 2: "\\log_{${args[1]}}\\left(${args[0]}\\right)"
|
17160 | };
|
17161 | return log;
|
17162 | }
|
17163 |
|
17164 | exports.name = 'log';
|
17165 | exports.factory = factory;
|
17166 |
|
17167 | }),
|
17168 |
|
17169 | (function(module, exports, __webpack_require__) {
|
17170 |
|
17171 | "use strict";
|
17172 |
|
17173 |
|
17174 | var bitNot = __webpack_require__(93);
|
17175 |
|
17176 |
|
17177 |
|
17178 |
|
17179 |
|
17180 |
|
17181 |
|
17182 |
|
17183 |
|
17184 | module.exports = function bitwise(x, y, func) {
|
17185 | var BigNumber = x.constructor;
|
17186 | var xBits, yBits;
|
17187 | var xSign = +(x.s < 0);
|
17188 | var ySign = +(y.s < 0);
|
17189 |
|
17190 | if (xSign) {
|
17191 | xBits = decCoefficientToBinaryString(bitNot(x));
|
17192 |
|
17193 | for (var i = 0; i < xBits.length; ++i) {
|
17194 | xBits[i] ^= 1;
|
17195 | }
|
17196 | } else {
|
17197 | xBits = decCoefficientToBinaryString(x);
|
17198 | }
|
17199 |
|
17200 | if (ySign) {
|
17201 | yBits = decCoefficientToBinaryString(bitNot(y));
|
17202 |
|
17203 | for (var _i = 0; _i < yBits.length; ++_i) {
|
17204 | yBits[_i] ^= 1;
|
17205 | }
|
17206 | } else {
|
17207 | yBits = decCoefficientToBinaryString(y);
|
17208 | }
|
17209 |
|
17210 | var minBits, maxBits, minSign;
|
17211 |
|
17212 | if (xBits.length <= yBits.length) {
|
17213 | minBits = xBits;
|
17214 | maxBits = yBits;
|
17215 | minSign = xSign;
|
17216 | } else {
|
17217 | minBits = yBits;
|
17218 | maxBits = xBits;
|
17219 | minSign = ySign;
|
17220 | }
|
17221 |
|
17222 | var shortLen = minBits.length;
|
17223 | var longLen = maxBits.length;
|
17224 | var expFuncVal = func(xSign, ySign) ^ 1;
|
17225 | var outVal = new BigNumber(expFuncVal ^ 1);
|
17226 | var twoPower = new BigNumber(1);
|
17227 | var two = new BigNumber(2);
|
17228 | var prevPrec = BigNumber.precision;
|
17229 | BigNumber.config({
|
17230 | precision: 1E9
|
17231 | });
|
17232 |
|
17233 | while (shortLen > 0) {
|
17234 | if (func(minBits[--shortLen], maxBits[--longLen]) === expFuncVal) {
|
17235 | outVal = outVal.plus(twoPower);
|
17236 | }
|
17237 |
|
17238 | twoPower = twoPower.times(two);
|
17239 | }
|
17240 |
|
17241 | while (longLen > 0) {
|
17242 | if (func(minSign, maxBits[--longLen]) === expFuncVal) {
|
17243 | outVal = outVal.plus(twoPower);
|
17244 | }
|
17245 |
|
17246 | twoPower = twoPower.times(two);
|
17247 | }
|
17248 |
|
17249 | BigNumber.config({
|
17250 | precision: prevPrec
|
17251 | });
|
17252 |
|
17253 | if (expFuncVal === 0) {
|
17254 | outVal.s = -outVal.s;
|
17255 | }
|
17256 |
|
17257 | return outVal;
|
17258 | };
|
17259 |
|
17260 |
|
17261 |
|
17262 | function decCoefficientToBinaryString(x) {
|
17263 |
|
17264 | var a = x.d;
|
17265 |
|
17266 | var r = a[0] + '';
|
17267 |
|
17268 | for (var i = 1; i < a.length; ++i) {
|
17269 | var s = a[i] + '';
|
17270 |
|
17271 | for (var z = 7 - s.length; z--;) {
|
17272 | s = '0' + s;
|
17273 | }
|
17274 |
|
17275 | r += s;
|
17276 | }
|
17277 |
|
17278 | var j = r.length;
|
17279 |
|
17280 | while (r.charAt(j) === '0') {
|
17281 | j--;
|
17282 | }
|
17283 |
|
17284 | var xe = x.e;
|
17285 | var str = r.slice(0, j + 1 || 1);
|
17286 | var strL = str.length;
|
17287 |
|
17288 | if (xe > 0) {
|
17289 | if (++xe > strL) {
|
17290 |
|
17291 | xe -= strL;
|
17292 |
|
17293 | while (xe--) {
|
17294 | str += '0';
|
17295 | }
|
17296 | } else if (xe < strL) {
|
17297 | str = str.slice(0, xe) + '.' + str.slice(xe);
|
17298 | }
|
17299 | }
|
17300 |
|
17301 |
|
17302 | var arr = [0];
|
17303 |
|
17304 | for (var _i2 = 0; _i2 < str.length;) {
|
17305 | var arrL = arr.length;
|
17306 |
|
17307 | while (arrL--) {
|
17308 | arr[arrL] *= 10;
|
17309 | }
|
17310 |
|
17311 | arr[0] += parseInt(str.charAt(_i2++));
|
17312 |
|
17313 | for (var _j = 0; _j < arr.length; ++_j) {
|
17314 | if (arr[_j] > 1) {
|
17315 | if (arr[_j + 1] === null || arr[_j + 1] === undefined) {
|
17316 | arr[_j + 1] = 0;
|
17317 | }
|
17318 |
|
17319 | arr[_j + 1] += arr[_j] >> 1;
|
17320 | arr[_j] &= 1;
|
17321 | }
|
17322 | }
|
17323 | }
|
17324 |
|
17325 | return arr.reverse();
|
17326 | }
|
17327 |
|
17328 | }),
|
17329 |
|
17330 | (function(module, exports, __webpack_require__) {
|
17331 |
|
17332 | "use strict";
|
17333 |
|
17334 |
|
17335 |
|
17336 |
|
17337 |
|
17338 |
|
17339 |
|
17340 |
|
17341 | module.exports = function bitNot(x) {
|
17342 | if (x.isFinite() && !x.isInteger()) {
|
17343 | throw new Error('Integer expected in function bitNot');
|
17344 | }
|
17345 |
|
17346 | var BigNumber = x.constructor;
|
17347 | var prevPrec = BigNumber.precision;
|
17348 | BigNumber.config({
|
17349 | precision: 1E9
|
17350 | });
|
17351 | var result = x.plus(new BigNumber(1));
|
17352 | result.s = -result.s || null;
|
17353 | BigNumber.config({
|
17354 | precision: prevPrec
|
17355 | });
|
17356 | return result;
|
17357 | };
|
17358 |
|
17359 | }),
|
17360 |
|
17361 | (function(module, exports, __webpack_require__) {
|
17362 |
|
17363 | "use strict";
|
17364 |
|
17365 |
|
17366 | var DimensionError = __webpack_require__(8);
|
17367 |
|
17368 | function factory(type, config, load, typed) {
|
17369 | var equalScalar = load(__webpack_require__(11));
|
17370 | var SparseMatrix = type.SparseMatrix;
|
17371 | |
17372 |
|
17373 |
|
17374 |
|
17375 |
|
17376 |
|
17377 |
|
17378 |
|
17379 |
|
17380 |
|
17381 |
|
17382 |
|
17383 |
|
17384 |
|
17385 |
|
17386 |
|
17387 |
|
17388 |
|
17389 |
|
17390 | var algorithm08 = function algorithm08(a, b, callback) {
|
17391 |
|
17392 | var avalues = a._values;
|
17393 | var aindex = a._index;
|
17394 | var aptr = a._ptr;
|
17395 | var asize = a._size;
|
17396 | var adt = a._datatype;
|
17397 |
|
17398 | var bvalues = b._values;
|
17399 | var bindex = b._index;
|
17400 | var bptr = b._ptr;
|
17401 | var bsize = b._size;
|
17402 | var bdt = b._datatype;
|
17403 |
|
17404 | if (asize.length !== bsize.length) {
|
17405 | throw new DimensionError(asize.length, bsize.length);
|
17406 | }
|
17407 |
|
17408 |
|
17409 | if (asize[0] !== bsize[0] || asize[1] !== bsize[1]) {
|
17410 | throw new RangeError('Dimension mismatch. Matrix A (' + asize + ') must match Matrix B (' + bsize + ')');
|
17411 | }
|
17412 |
|
17413 |
|
17414 | if (!avalues || !bvalues) {
|
17415 | throw new Error('Cannot perform operation on Pattern Sparse Matrices');
|
17416 | }
|
17417 |
|
17418 |
|
17419 | var rows = asize[0];
|
17420 | var columns = asize[1];
|
17421 |
|
17422 | var dt;
|
17423 |
|
17424 | var eq = equalScalar;
|
17425 |
|
17426 | var zero = 0;
|
17427 |
|
17428 | var cf = callback;
|
17429 |
|
17430 | if (typeof adt === 'string' && adt === bdt) {
|
17431 |
|
17432 | dt = adt;
|
17433 |
|
17434 | eq = typed.find(equalScalar, [dt, dt]);
|
17435 |
|
17436 | zero = typed.convert(0, dt);
|
17437 |
|
17438 | cf = typed.find(callback, [dt, dt]);
|
17439 | }
|
17440 |
|
17441 |
|
17442 | var cvalues = [];
|
17443 | var cindex = [];
|
17444 | var cptr = [];
|
17445 |
|
17446 | var c = new SparseMatrix({
|
17447 | values: cvalues,
|
17448 | index: cindex,
|
17449 | ptr: cptr,
|
17450 | size: [rows, columns],
|
17451 | datatype: dt
|
17452 | });
|
17453 |
|
17454 | var x = [];
|
17455 |
|
17456 | var w = [];
|
17457 |
|
17458 | var k, k0, k1, i;
|
17459 |
|
17460 | for (var j = 0; j < columns; j++) {
|
17461 |
|
17462 | cptr[j] = cindex.length;
|
17463 |
|
17464 | var mark = j + 1;
|
17465 |
|
17466 | for (k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
|
17467 |
|
17468 | i = aindex[k];
|
17469 |
|
17470 | w[i] = mark;
|
17471 |
|
17472 | x[i] = avalues[k];
|
17473 |
|
17474 | cindex.push(i);
|
17475 | }
|
17476 |
|
17477 |
|
17478 | for (k0 = bptr[j], k1 = bptr[j + 1], k = k0; k < k1; k++) {
|
17479 |
|
17480 | i = bindex[k];
|
17481 |
|
17482 | if (w[i] === mark) {
|
17483 |
|
17484 | x[i] = cf(x[i], bvalues[k]);
|
17485 | }
|
17486 | }
|
17487 |
|
17488 |
|
17489 | k = cptr[j];
|
17490 |
|
17491 | while (k < cindex.length) {
|
17492 |
|
17493 | i = cindex[k];
|
17494 |
|
17495 | var v = x[i];
|
17496 |
|
17497 | if (!eq(v, zero)) {
|
17498 |
|
17499 | cvalues.push(v);
|
17500 |
|
17501 | k++;
|
17502 | } else {
|
17503 |
|
17504 | cindex.splice(k, 1);
|
17505 | }
|
17506 | }
|
17507 | }
|
17508 |
|
17509 |
|
17510 | cptr[columns] = cindex.length;
|
17511 |
|
17512 | return c;
|
17513 | };
|
17514 |
|
17515 | return algorithm08;
|
17516 | }
|
17517 |
|
17518 | exports.name = 'algorithm08';
|
17519 | exports.factory = factory;
|
17520 |
|
17521 | }),
|
17522 |
|
17523 | (function(module, exports) {
|
17524 |
|
17525 |
|
17526 |
|
17527 |
|
17528 |
|
17529 | function product(i, n) {
|
17530 | var half;
|
17531 |
|
17532 | if (n < i) {
|
17533 | return 1;
|
17534 | }
|
17535 |
|
17536 | if (n === i) {
|
17537 | return n;
|
17538 | }
|
17539 |
|
17540 | half = n + i >> 1;
|
17541 |
|
17542 | return product(i, half) * product(half + 1, n);
|
17543 | }
|
17544 |
|
17545 | module.exports = product;
|
17546 |
|
17547 | }),
|
17548 |
|
17549 | (function(module, exports, __webpack_require__) {
|
17550 |
|
17551 | "use strict";
|
17552 |
|
17553 |
|
17554 | var arraySize = __webpack_require__(2).size;
|
17555 |
|
17556 | var isMatrix = __webpack_require__(56);
|
17557 |
|
17558 | var IndexError = __webpack_require__(48);
|
17559 |
|
17560 | function factory(type, config, load, typed) {
|
17561 | var isInteger = load(__webpack_require__(34));
|
17562 | |
17563 |
|
17564 |
|
17565 |
|
17566 |
|
17567 |
|
17568 |
|
17569 |
|
17570 |
|
17571 |
|
17572 |
|
17573 |
|
17574 |
|
17575 |
|
17576 |
|
17577 |
|
17578 |
|
17579 |
|
17580 |
|
17581 |
|
17582 |
|
17583 |
|
17584 |
|
17585 |
|
17586 |
|
17587 |
|
17588 |
|
17589 |
|
17590 |
|
17591 |
|
17592 |
|
17593 |
|
17594 |
|
17595 | var apply = typed('apply', {
|
17596 | 'Array | Matrix, number | BigNumber, function': function ArrayMatrixNumberBigNumberFunction(mat, dim, callback) {
|
17597 | if (!isInteger(dim)) {
|
17598 | throw new TypeError('Integer number expected for dimension');
|
17599 | }
|
17600 |
|
17601 | var size = Array.isArray(mat) ? arraySize(mat) : mat.size();
|
17602 |
|
17603 | if (dim < 0 || dim >= size.length) {
|
17604 | throw new IndexError(dim, size.length);
|
17605 | }
|
17606 |
|
17607 | if (isMatrix(mat)) {
|
17608 | return mat.create(_apply(mat.valueOf(), dim, callback));
|
17609 | } else {
|
17610 | return _apply(mat, dim, callback);
|
17611 | }
|
17612 | }
|
17613 | });
|
17614 | apply.toTex = undefined;
|
17615 |
|
17616 | return apply;
|
17617 | }
|
17618 |
|
17619 |
|
17620 |
|
17621 |
|
17622 |
|
17623 |
|
17624 |
|
17625 |
|
17626 |
|
17627 |
|
17628 | function _apply(mat, dim, callback) {
|
17629 | var i, ret, tran;
|
17630 |
|
17631 | if (dim <= 0) {
|
17632 | if (!Array.isArray(mat[0])) {
|
17633 | return callback(mat);
|
17634 | } else {
|
17635 | tran = _switch(mat);
|
17636 | ret = [];
|
17637 |
|
17638 | for (i = 0; i < tran.length; i++) {
|
17639 | ret[i] = _apply(tran[i], dim - 1, callback);
|
17640 | }
|
17641 |
|
17642 | return ret;
|
17643 | }
|
17644 | } else {
|
17645 | ret = [];
|
17646 |
|
17647 | for (i = 0; i < mat.length; i++) {
|
17648 | ret[i] = _apply(mat[i], dim - 1, callback);
|
17649 | }
|
17650 |
|
17651 | return ret;
|
17652 | }
|
17653 | }
|
17654 |
|
17655 |
|
17656 |
|
17657 |
|
17658 |
|
17659 |
|
17660 |
|
17661 |
|
17662 | function _switch(mat) {
|
17663 | var I = mat.length;
|
17664 | var J = mat[0].length;
|
17665 | var i, j;
|
17666 | var ret = [];
|
17667 |
|
17668 | for (j = 0; j < J; j++) {
|
17669 | var tmp = [];
|
17670 |
|
17671 | for (i = 0; i < I; i++) {
|
17672 | tmp.push(mat[i][j]);
|
17673 | }
|
17674 |
|
17675 | ret.push(tmp);
|
17676 | }
|
17677 |
|
17678 | return ret;
|
17679 | }
|
17680 |
|
17681 | exports.name = 'apply';
|
17682 | exports.factory = factory;
|
17683 |
|
17684 | }),
|
17685 |
|
17686 | (function(module, exports, __webpack_require__) {
|
17687 |
|
17688 | "use strict";
|
17689 |
|
17690 |
|
17691 | var isInteger = __webpack_require__(3).isInteger;
|
17692 |
|
17693 | function factory(type, config, load, typed) {
|
17694 | var isNumeric = load(__webpack_require__(52));
|
17695 | var isNaN = load(__webpack_require__(79));
|
17696 | var asc = load(__webpack_require__(55));
|
17697 |
|
17698 | function desc(a, b) {
|
17699 | return -asc(a, b);
|
17700 | }
|
17701 | |
17702 |
|
17703 |
|
17704 |
|
17705 |
|
17706 |
|
17707 |
|
17708 |
|
17709 |
|
17710 |
|
17711 |
|
17712 |
|
17713 |
|
17714 |
|
17715 |
|
17716 |
|
17717 |
|
17718 |
|
17719 |
|
17720 |
|
17721 |
|
17722 |
|
17723 |
|
17724 |
|
17725 |
|
17726 |
|
17727 |
|
17728 |
|
17729 |
|
17730 |
|
17731 |
|
17732 |
|
17733 |
|
17734 |
|
17735 | return typed('partitionSelect', {
|
17736 | 'Array | Matrix, number': function ArrayMatrixNumber(x, k) {
|
17737 | return _partitionSelect(x, k, asc);
|
17738 | },
|
17739 | 'Array | Matrix, number, string': function ArrayMatrixNumberString(x, k, compare) {
|
17740 | if (compare === 'asc') {
|
17741 | return _partitionSelect(x, k, asc);
|
17742 | } else if (compare === 'desc') {
|
17743 | return _partitionSelect(x, k, desc);
|
17744 | } else {
|
17745 | throw new Error('Compare string must be "asc" or "desc"');
|
17746 | }
|
17747 | },
|
17748 | 'Array | Matrix, number, function': _partitionSelect
|
17749 | });
|
17750 |
|
17751 | function _partitionSelect(x, k, compare) {
|
17752 | if (!isInteger(k) || k < 0) {
|
17753 | throw new Error('k must be a non-negative integer');
|
17754 | }
|
17755 |
|
17756 | if (type.isMatrix(x)) {
|
17757 | var size = x.size();
|
17758 |
|
17759 | if (size.length > 1) {
|
17760 | throw new Error('Only one dimensional matrices supported');
|
17761 | }
|
17762 |
|
17763 | return quickSelect(x.valueOf(), k, compare);
|
17764 | }
|
17765 |
|
17766 | if (Array.isArray(x)) {
|
17767 | return quickSelect(x, k, compare);
|
17768 | }
|
17769 | }
|
17770 | |
17771 |
|
17772 |
|
17773 |
|
17774 |
|
17775 |
|
17776 |
|
17777 |
|
17778 |
|
17779 |
|
17780 |
|
17781 |
|
17782 | function quickSelect(arr, k, compare) {
|
17783 | if (k >= arr.length) {
|
17784 | throw new Error('k out of bounds');
|
17785 | }
|
17786 |
|
17787 |
|
17788 | for (var i = 0; i < arr.length; i++) {
|
17789 | if (isNumeric(arr[i]) && isNaN(arr[i])) {
|
17790 | return arr[i];
|
17791 | }
|
17792 | }
|
17793 |
|
17794 | var from = 0;
|
17795 | var to = arr.length - 1;
|
17796 |
|
17797 | while (from < to) {
|
17798 | var r = from;
|
17799 | var w = to;
|
17800 | var pivot = arr[Math.floor(Math.random() * (to - from + 1)) + from];
|
17801 |
|
17802 | while (r < w) {
|
17803 |
|
17804 | if (compare(arr[r], pivot) >= 0) {
|
17805 |
|
17806 | var tmp = arr[w];
|
17807 | arr[w] = arr[r];
|
17808 | arr[r] = tmp;
|
17809 | --w;
|
17810 | } else {
|
17811 |
|
17812 | ++r;
|
17813 | }
|
17814 | }
|
17815 |
|
17816 |
|
17817 | if (compare(arr[r], pivot) > 0) {
|
17818 | --r;
|
17819 | }
|
17820 |
|
17821 |
|
17822 | if (k <= r) {
|
17823 | to = r;
|
17824 | } else {
|
17825 | from = r + 1;
|
17826 | }
|
17827 | }
|
17828 |
|
17829 | return arr[k];
|
17830 | }
|
17831 | }
|
17832 |
|
17833 | exports.name = 'partitionSelect';
|
17834 | exports.factory = factory;
|
17835 |
|
17836 | }),
|
17837 |
|
17838 | (function(module, exports, __webpack_require__) {
|
17839 |
|
17840 | "use strict";
|
17841 |
|
17842 |
|
17843 | var deepForEach = __webpack_require__(47);
|
17844 |
|
17845 | var reduce = __webpack_require__(80);
|
17846 |
|
17847 | var containsCollections = __webpack_require__(62);
|
17848 |
|
17849 | function factory(type, config, load, typed) {
|
17850 | var larger = load(__webpack_require__(33));
|
17851 | var improveErrorMessage = load(__webpack_require__(40));
|
17852 | |
17853 |
|
17854 |
|
17855 |
|
17856 |
|
17857 |
|
17858 |
|
17859 |
|
17860 |
|
17861 |
|
17862 |
|
17863 |
|
17864 |
|
17865 |
|
17866 |
|
17867 |
|
17868 |
|
17869 |
|
17870 |
|
17871 |
|
17872 |
|
17873 |
|
17874 |
|
17875 |
|
17876 |
|
17877 |
|
17878 |
|
17879 |
|
17880 |
|
17881 |
|
17882 |
|
17883 |
|
17884 | var max = typed('max', {
|
17885 |
|
17886 | 'Array | Matrix': _max,
|
17887 |
|
17888 | 'Array | Matrix, number | BigNumber': function ArrayMatrixNumberBigNumber(array, dim) {
|
17889 | return reduce(array, dim.valueOf(), _largest);
|
17890 | },
|
17891 |
|
17892 | '...': function _(args) {
|
17893 | if (containsCollections(args)) {
|
17894 | throw new TypeError('Scalar values expected in function max');
|
17895 | }
|
17896 |
|
17897 | return _max(args);
|
17898 | }
|
17899 | });
|
17900 | max.toTex = "\\max\\left(${args}\\right)";
|
17901 | return max;
|
17902 | |
17903 |
|
17904 |
|
17905 |
|
17906 |
|
17907 |
|
17908 |
|
17909 |
|
17910 | function _largest(x, y) {
|
17911 | try {
|
17912 | return larger(x, y) ? x : y;
|
17913 | } catch (err) {
|
17914 | throw improveErrorMessage(err, 'max', y);
|
17915 | }
|
17916 | }
|
17917 | |
17918 |
|
17919 |
|
17920 |
|
17921 |
|
17922 |
|
17923 |
|
17924 |
|
17925 | function _max(array) {
|
17926 | var max;
|
17927 | deepForEach(array, function (value) {
|
17928 | try {
|
17929 | if (isNaN(value) && typeof value === 'number') {
|
17930 | max = NaN;
|
17931 | } else if (max === undefined || larger(value, max)) {
|
17932 | max = value;
|
17933 | }
|
17934 | } catch (err) {
|
17935 | throw improveErrorMessage(err, 'max', value);
|
17936 | }
|
17937 | });
|
17938 |
|
17939 | if (max === undefined) {
|
17940 | throw new Error('Cannot calculate max of an empty array');
|
17941 | }
|
17942 |
|
17943 | return max;
|
17944 | }
|
17945 | }
|
17946 |
|
17947 | exports.name = 'max';
|
17948 | exports.factory = factory;
|
17949 |
|
17950 | }),
|
17951 |
|
17952 | (function(module, exports, __webpack_require__) {
|
17953 |
|
17954 | "use strict";
|
17955 |
|
17956 |
|
17957 | var deepForEach = __webpack_require__(47);
|
17958 |
|
17959 | var reduce = __webpack_require__(80);
|
17960 |
|
17961 | var containsCollections = __webpack_require__(62);
|
17962 |
|
17963 | function factory(type, config, load, typed) {
|
17964 | var add = load(__webpack_require__(17));
|
17965 | var improveErrorMessage = load(__webpack_require__(40));
|
17966 | |
17967 |
|
17968 |
|
17969 |
|
17970 |
|
17971 |
|
17972 |
|
17973 |
|
17974 |
|
17975 |
|
17976 |
|
17977 |
|
17978 |
|
17979 |
|
17980 |
|
17981 |
|
17982 |
|
17983 |
|
17984 |
|
17985 |
|
17986 |
|
17987 |
|
17988 |
|
17989 |
|
17990 | var sum = typed('sum', {
|
17991 |
|
17992 | 'Array | Matrix': _sum,
|
17993 |
|
17994 | 'Array | Matrix, number | BigNumber': _nsumDim,
|
17995 |
|
17996 | '...': function _(args) {
|
17997 | if (containsCollections(args)) {
|
17998 | throw new TypeError('Scalar values expected in function sum');
|
17999 | }
|
18000 |
|
18001 | return _sum(args);
|
18002 | }
|
18003 | });
|
18004 | sum.toTex = undefined;
|
18005 |
|
18006 | return sum;
|
18007 | |
18008 |
|
18009 |
|
18010 |
|
18011 |
|
18012 |
|
18013 |
|
18014 | function _sum(array) {
|
18015 | var sum;
|
18016 | deepForEach(array, function (value) {
|
18017 | try {
|
18018 | sum = sum === undefined ? value : add(sum, value);
|
18019 | } catch (err) {
|
18020 | throw improveErrorMessage(err, 'sum', value);
|
18021 | }
|
18022 | });
|
18023 |
|
18024 | if (sum === undefined) {
|
18025 | switch (config.number) {
|
18026 | case 'number':
|
18027 | return 0;
|
18028 |
|
18029 | case 'BigNumber':
|
18030 | return new type.BigNumber(0);
|
18031 |
|
18032 | case 'Fraction':
|
18033 | return new type.Fraction(0);
|
18034 |
|
18035 | default:
|
18036 | return 0;
|
18037 | }
|
18038 | }
|
18039 |
|
18040 | return sum;
|
18041 | }
|
18042 |
|
18043 | function _nsumDim(array, dim) {
|
18044 | try {
|
18045 | var _sum2 = reduce(array, dim, add);
|
18046 |
|
18047 | return _sum2;
|
18048 | } catch (err) {
|
18049 | throw improveErrorMessage(err, 'sum');
|
18050 | }
|
18051 | }
|
18052 | }
|
18053 |
|
18054 | exports.name = 'sum';
|
18055 | exports.factory = factory;
|
18056 |
|
18057 | }),
|
18058 |
|
18059 | (function(module, exports, __webpack_require__) {
|
18060 |
|
18061 | "use strict";
|
18062 |
|
18063 |
|
18064 | var ArgumentsError = __webpack_require__(57);
|
18065 |
|
18066 | var isCollection = __webpack_require__(35);
|
18067 |
|
18068 | var isNumber = __webpack_require__(3).isNumber;
|
18069 |
|
18070 |
|
18071 |
|
18072 | function factory(type, config, load, typed, math) {
|
18073 | var matrix = load(__webpack_require__(0));
|
18074 |
|
18075 | var array = __webpack_require__(2);
|
18076 |
|
18077 |
|
18078 | var rng = load(__webpack_require__(298));
|
18079 | |
18080 |
|
18081 |
|
18082 |
|
18083 |
|
18084 |
|
18085 |
|
18086 |
|
18087 |
|
18088 |
|
18089 |
|
18090 |
|
18091 |
|
18092 |
|
18093 |
|
18094 |
|
18095 |
|
18096 |
|
18097 |
|
18098 |
|
18099 |
|
18100 |
|
18101 |
|
18102 |
|
18103 | function distribution(name) {
|
18104 | if (!distributions.hasOwnProperty(name)) {
|
18105 | throw new Error('Unknown distribution ' + name);
|
18106 | }
|
18107 |
|
18108 | var args = Array.prototype.slice.call(arguments, 1);
|
18109 | var distribution = distributions[name].apply(this, args);
|
18110 | return function (distribution) {
|
18111 |
|
18112 | var randFunctions = {
|
18113 | random: function random(arg1, arg2, arg3) {
|
18114 | var size, min, max;
|
18115 |
|
18116 | if (arguments.length > 3) {
|
18117 | throw new ArgumentsError('random', arguments.length, 0, 3);
|
18118 | } else if (arguments.length === 1) {
|
18119 |
|
18120 | if (isCollection(arg1)) {
|
18121 | size = arg1;
|
18122 | } else {
|
18123 | max = arg1;
|
18124 | }
|
18125 | } else if (arguments.length === 2) {
|
18126 |
|
18127 | if (isCollection(arg1)) {
|
18128 | size = arg1;
|
18129 | max = arg2;
|
18130 | } else {
|
18131 | min = arg1;
|
18132 | max = arg2;
|
18133 | }
|
18134 | } else {
|
18135 |
|
18136 | size = arg1;
|
18137 | min = arg2;
|
18138 | max = arg3;
|
18139 | }
|
18140 |
|
18141 |
|
18142 | if (min !== undefined && !isNumber(min) || max !== undefined && !isNumber(max)) {
|
18143 | throw new TypeError('Invalid argument in function random');
|
18144 | }
|
18145 |
|
18146 | if (max === undefined) max = 1;
|
18147 | if (min === undefined) min = 0;
|
18148 |
|
18149 | if (size !== undefined) {
|
18150 | var res = _randomDataForMatrix(size.valueOf(), min, max, _random);
|
18151 |
|
18152 | return type.isMatrix(size) ? matrix(res) : res;
|
18153 | }
|
18154 |
|
18155 | return _random(min, max);
|
18156 | },
|
18157 | randomInt: typed({
|
18158 | 'number | Array': function numberArray(arg) {
|
18159 | var min = 0;
|
18160 |
|
18161 | if (isCollection(arg)) {
|
18162 | var size = arg;
|
18163 | var max = 1;
|
18164 |
|
18165 | var res = _randomDataForMatrix(size.valueOf(), min, max, _randomInt);
|
18166 |
|
18167 | return type.isMatrix(size) ? matrix(res) : res;
|
18168 | } else {
|
18169 | var _max = arg;
|
18170 | return _randomInt(min, _max);
|
18171 | }
|
18172 | },
|
18173 | 'number | Array, number': function numberArrayNumber(arg1, arg2) {
|
18174 | if (isCollection(arg1)) {
|
18175 | var size = arg1;
|
18176 | var max = arg2;
|
18177 | var min = 0;
|
18178 |
|
18179 | var res = _randomDataForMatrix(size.valueOf(), min, max, _randomInt);
|
18180 |
|
18181 | return type.isMatrix(size) ? matrix(res) : res;
|
18182 | } else {
|
18183 | var _min = arg1;
|
18184 | var _max2 = arg2;
|
18185 | return _randomInt(_min, _max2);
|
18186 | }
|
18187 | },
|
18188 | 'Array, number, number': function ArrayNumberNumber(size, min, max) {
|
18189 | var res = _randomDataForMatrix(size.valueOf(), min, max, _randomInt);
|
18190 |
|
18191 | return size && size.isMatrix === true ? matrix(res) : res;
|
18192 | }
|
18193 | }),
|
18194 | pickRandom: typed({
|
18195 | 'Array': function Array(possibles) {
|
18196 | return _pickRandom(possibles);
|
18197 | },
|
18198 | 'Array, number | Array': function ArrayNumberArray(possibles, arg2) {
|
18199 | var number, weights;
|
18200 |
|
18201 | if (Array.isArray(arg2)) {
|
18202 | weights = arg2;
|
18203 | } else if (isNumber(arg2)) {
|
18204 | number = arg2;
|
18205 | } else {
|
18206 | throw new TypeError('Invalid argument in function pickRandom');
|
18207 | }
|
18208 |
|
18209 | return _pickRandom(possibles, number, weights);
|
18210 | },
|
18211 | 'Array, number | Array, Array | number': function ArrayNumberArrayArrayNumber(possibles, arg2, arg3) {
|
18212 | var number, weights;
|
18213 |
|
18214 | if (Array.isArray(arg2)) {
|
18215 | weights = arg2;
|
18216 | number = arg3;
|
18217 | } else {
|
18218 | weights = arg3;
|
18219 | number = arg2;
|
18220 | }
|
18221 |
|
18222 | if (!Array.isArray(weights) || !isNumber(number)) {
|
18223 | throw new TypeError('Invalid argument in function pickRandom');
|
18224 | }
|
18225 |
|
18226 | return _pickRandom(possibles, number, weights);
|
18227 | }
|
18228 | })
|
18229 | };
|
18230 |
|
18231 | function _pickRandom(possibles, number, weights) {
|
18232 | var single = typeof number === 'undefined';
|
18233 |
|
18234 | if (single) {
|
18235 | number = 1;
|
18236 | }
|
18237 |
|
18238 | if (type.isMatrix(possibles)) {
|
18239 | possibles = possibles.valueOf();
|
18240 | } else if (!Array.isArray(possibles)) {
|
18241 | throw new TypeError('Unsupported type of value in function pickRandom');
|
18242 | }
|
18243 |
|
18244 | if (array.size(possibles).length > 1) {
|
18245 | throw new Error('Only one dimensional vectors supported');
|
18246 | }
|
18247 |
|
18248 | var totalWeights = 0;
|
18249 |
|
18250 | if (typeof weights !== 'undefined') {
|
18251 | if (weights.length !== possibles.length) {
|
18252 | throw new Error('Weights must have the same length as possibles');
|
18253 | }
|
18254 |
|
18255 | for (var i = 0, len = weights.length; i < len; i++) {
|
18256 | if (!isNumber(weights[i]) || weights[i] < 0) {
|
18257 | throw new Error('Weights must be an array of positive numbers');
|
18258 | }
|
18259 |
|
18260 | totalWeights += weights[i];
|
18261 | }
|
18262 | }
|
18263 |
|
18264 | var length = possibles.length;
|
18265 |
|
18266 | if (length === 0) {
|
18267 | return [];
|
18268 | } else if (number >= length) {
|
18269 | return number > 1 ? possibles : possibles[0];
|
18270 | }
|
18271 |
|
18272 | var result = [];
|
18273 | var pick;
|
18274 |
|
18275 | while (result.length < number) {
|
18276 | if (typeof weights === 'undefined') {
|
18277 | pick = possibles[Math.floor(rng() * length)];
|
18278 | } else {
|
18279 | var randKey = rng() * totalWeights;
|
18280 |
|
18281 | for (var _i = 0, _len = possibles.length; _i < _len; _i++) {
|
18282 | randKey -= weights[_i];
|
18283 |
|
18284 | if (randKey < 0) {
|
18285 | pick = possibles[_i];
|
18286 | break;
|
18287 | }
|
18288 | }
|
18289 | }
|
18290 |
|
18291 | if (result.indexOf(pick) === -1) {
|
18292 | result.push(pick);
|
18293 | }
|
18294 | }
|
18295 |
|
18296 | return single ? result[0] : result;
|
18297 | }
|
18298 |
|
18299 | function _random(min, max) {
|
18300 | return min + distribution() * (max - min);
|
18301 | }
|
18302 |
|
18303 | function _randomInt(min, max) {
|
18304 | return Math.floor(min + distribution() * (max - min));
|
18305 | }
|
18306 |
|
18307 |
|
18308 | function _randomDataForMatrix(size, min, max, randFunc) {
|
18309 | var data = [];
|
18310 | size = size.slice(0);
|
18311 |
|
18312 | if (size.length > 1) {
|
18313 | for (var i = 0, length = size.shift(); i < length; i++) {
|
18314 | data.push(_randomDataForMatrix(size, min, max, randFunc));
|
18315 | }
|
18316 | } else {
|
18317 | for (var _i2 = 0, _length = size.shift(); _i2 < _length; _i2++) {
|
18318 | data.push(randFunc(min, max));
|
18319 | }
|
18320 | }
|
18321 |
|
18322 | return data;
|
18323 | }
|
18324 |
|
18325 | return randFunctions;
|
18326 | }(distribution);
|
18327 | }
|
18328 |
|
18329 |
|
18330 |
|
18331 | var distributions = {
|
18332 | uniform: function uniform() {
|
18333 | return rng;
|
18334 | },
|
18335 |
|
18336 |
|
18337 |
|
18338 |
|
18339 | normal: function normal() {
|
18340 | return function () {
|
18341 | var u1;
|
18342 | var u2;
|
18343 | var picked = -1;
|
18344 |
|
18345 |
|
18346 | while (picked < 0 || picked > 1) {
|
18347 | u1 = rng();
|
18348 | u2 = rng();
|
18349 | picked = 1 / 6 * Math.pow(-2 * Math.log(u1), 0.5) * Math.cos(2 * Math.PI * u2) + 0.5;
|
18350 | }
|
18351 |
|
18352 | return picked;
|
18353 | };
|
18354 | }
|
18355 | };
|
18356 | distribution.toTex = undefined;
|
18357 |
|
18358 | return distribution;
|
18359 | }
|
18360 |
|
18361 | exports.name = 'distribution';
|
18362 | exports.factory = factory;
|
18363 |
|
18364 | }),
|
18365 |
|
18366 | (function(module, exports, __webpack_require__) {
|
18367 |
|
18368 | "use strict";
|
18369 |
|
18370 |
|
18371 | var DEFAULT_NORMALIZATION = 'unbiased';
|
18372 |
|
18373 | var deepForEach = __webpack_require__(47);
|
18374 |
|
18375 | function factory(type, config, load, typed) {
|
18376 | var apply = load(__webpack_require__(96));
|
18377 | var add = load(__webpack_require__(17));
|
18378 | var subtract = load(__webpack_require__(15));
|
18379 | var multiply = load(__webpack_require__(21));
|
18380 | var divide = load(__webpack_require__(12));
|
18381 | var isNaN = load(__webpack_require__(79));
|
18382 | var improveErrorMessage = load(__webpack_require__(40));
|
18383 | |
18384 |
|
18385 |
|
18386 |
|
18387 |
|
18388 |
|
18389 |
|
18390 |
|
18391 |
|
18392 |
|
18393 |
|
18394 |
|
18395 |
|
18396 |
|
18397 |
|
18398 |
|
18399 |
|
18400 |
|
18401 |
|
18402 |
|
18403 |
|
18404 |
|
18405 |
|
18406 |
|
18407 |
|
18408 |
|
18409 |
|
18410 |
|
18411 |
|
18412 |
|
18413 |
|
18414 |
|
18415 |
|
18416 |
|
18417 |
|
18418 |
|
18419 |
|
18420 |
|
18421 |
|
18422 |
|
18423 |
|
18424 |
|
18425 |
|
18426 |
|
18427 |
|
18428 |
|
18429 |
|
18430 |
|
18431 |
|
18432 |
|
18433 |
|
18434 |
|
18435 |
|
18436 |
|
18437 | var variance = typed('variance', {
|
18438 |
|
18439 | 'Array | Matrix': function ArrayMatrix(array) {
|
18440 | return _var(array, DEFAULT_NORMALIZATION);
|
18441 | },
|
18442 |
|
18443 | 'Array | Matrix, string': _var,
|
18444 |
|
18445 | 'Array | Matrix, number | BigNumber': function ArrayMatrixNumberBigNumber(array, dim) {
|
18446 | return _varDim(array, dim, DEFAULT_NORMALIZATION);
|
18447 | },
|
18448 |
|
18449 | 'Array | Matrix, number | BigNumber, string': _varDim,
|
18450 |
|
18451 | '...': function _(args) {
|
18452 | return _var(args, DEFAULT_NORMALIZATION);
|
18453 | }
|
18454 | });
|
18455 | variance.toTex = "\\mathrm{Var}\\left(${args}\\right)";
|
18456 | return variance;
|
18457 | |
18458 |
|
18459 |
|
18460 |
|
18461 |
|
18462 |
|
18463 |
|
18464 |
|
18465 |
|
18466 |
|
18467 |
|
18468 |
|
18469 | function _var(array, normalization) {
|
18470 | var sum = 0;
|
18471 | var num = 0;
|
18472 |
|
18473 | if (array.length === 0) {
|
18474 | throw new SyntaxError('Function var requires one or more parameters (0 provided)');
|
18475 | }
|
18476 |
|
18477 |
|
18478 | deepForEach(array, function (value) {
|
18479 | try {
|
18480 | sum = add(sum, value);
|
18481 | num++;
|
18482 | } catch (err) {
|
18483 | throw improveErrorMessage(err, 'var', value);
|
18484 | }
|
18485 | });
|
18486 | if (num === 0) throw new Error('Cannot calculate var of an empty array');
|
18487 | var mean = divide(sum, num);
|
18488 |
|
18489 | sum = 0;
|
18490 | deepForEach(array, function (value) {
|
18491 | var diff = subtract(value, mean);
|
18492 | sum = add(sum, multiply(diff, diff));
|
18493 | });
|
18494 |
|
18495 | if (isNaN(sum)) {
|
18496 | return sum;
|
18497 | }
|
18498 |
|
18499 | switch (normalization) {
|
18500 | case 'uncorrected':
|
18501 | return divide(sum, num);
|
18502 |
|
18503 | case 'biased':
|
18504 | return divide(sum, num + 1);
|
18505 |
|
18506 | case 'unbiased':
|
18507 | var zero = type.isBigNumber(sum) ? new type.BigNumber(0) : 0;
|
18508 | return num === 1 ? zero : divide(sum, num - 1);
|
18509 |
|
18510 | default:
|
18511 | throw new Error('Unknown normalization "' + normalization + '". ' + 'Choose "unbiased" (default), "uncorrected", or "biased".');
|
18512 | }
|
18513 | }
|
18514 |
|
18515 | function _varDim(array, dim, normalization) {
|
18516 | try {
|
18517 | if (array.length === 0) {
|
18518 | throw new SyntaxError('Function var requires one or more parameters (0 provided)');
|
18519 | }
|
18520 |
|
18521 | return apply(array, dim, function (x) {
|
18522 | return _var(x, normalization);
|
18523 | });
|
18524 | } catch (err) {
|
18525 | throw improveErrorMessage(err, 'var');
|
18526 | }
|
18527 | }
|
18528 | }
|
18529 |
|
18530 | exports.name = 'var';
|
18531 | exports.factory = factory;
|
18532 |
|
18533 | }),
|
18534 |
|
18535 | (function(module, exports, __webpack_require__) {
|
18536 |
|
18537 | "use strict";
|
18538 |
|
18539 |
|
18540 | function factory(type, config, load, typed) {
|
18541 | |
18542 |
|
18543 |
|
18544 |
|
18545 |
|
18546 |
|
18547 |
|
18548 |
|
18549 | return function compileInlineExpression(expression, math, scope) {
|
18550 |
|
18551 | var symbol = expression.filter(function (node) {
|
18552 | return type.isSymbolNode(node) && !(node.name in math) && !(node.name in scope);
|
18553 | })[0];
|
18554 |
|
18555 | if (!symbol) {
|
18556 | throw new Error('No undefined variable found in inline expression "' + expression + '"');
|
18557 | }
|
18558 |
|
18559 |
|
18560 | var name = symbol.name;
|
18561 |
|
18562 | var subScope = Object.create(scope);
|
18563 | var eq = expression.compile();
|
18564 | return function inlineExpression(x) {
|
18565 | subScope[name] = x;
|
18566 | return eq.eval(subScope);
|
18567 | };
|
18568 | };
|
18569 | }
|
18570 |
|
18571 | exports.factory = factory;
|
18572 |
|
18573 | }),
|
18574 |
|
18575 | (function(module, exports, __webpack_require__) {
|
18576 |
|
18577 | "use strict";
|
18578 |
|
18579 |
|
18580 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
18581 |
|
18582 | var typedFunction = __webpack_require__(164);
|
18583 |
|
18584 | var digits = __webpack_require__(3).digits;
|
18585 |
|
18586 | var isBigNumber = __webpack_require__(81);
|
18587 |
|
18588 | var isMatrix = __webpack_require__(56);
|
18589 |
|
18590 |
|
18591 | var _createTyped = function createTyped() {
|
18592 |
|
18593 |
|
18594 | _createTyped = typedFunction.create;
|
18595 | return typedFunction;
|
18596 | };
|
18597 |
|
18598 |
|
18599 |
|
18600 |
|
18601 |
|
18602 |
|
18603 |
|
18604 | exports.create = function create(type) {
|
18605 |
|
18606 |
|
18607 |
|
18608 |
|
18609 |
|
18610 |
|
18611 |
|
18612 |
|
18613 |
|
18614 |
|
18615 |
|
18616 |
|
18617 |
|
18618 |
|
18619 | type.isNumber = function (x) {
|
18620 | return typeof x === 'number';
|
18621 | };
|
18622 |
|
18623 | type.isComplex = function (x) {
|
18624 | return type.Complex && x instanceof type.Complex || false;
|
18625 | };
|
18626 |
|
18627 | type.isBigNumber = isBigNumber;
|
18628 |
|
18629 | type.isFraction = function (x) {
|
18630 | return type.Fraction && x instanceof type.Fraction || false;
|
18631 | };
|
18632 |
|
18633 | type.isUnit = function (x) {
|
18634 | return x && x.constructor.prototype.isUnit || false;
|
18635 | };
|
18636 |
|
18637 | type.isString = function (x) {
|
18638 | return typeof x === 'string';
|
18639 | };
|
18640 |
|
18641 | type.isArray = Array.isArray;
|
18642 | type.isMatrix = isMatrix;
|
18643 |
|
18644 | type.isDenseMatrix = function (x) {
|
18645 | return x && x.isDenseMatrix && x.constructor.prototype.isMatrix || false;
|
18646 | };
|
18647 |
|
18648 | type.isSparseMatrix = function (x) {
|
18649 | return x && x.isSparseMatrix && x.constructor.prototype.isMatrix || false;
|
18650 | };
|
18651 |
|
18652 | type.isRange = function (x) {
|
18653 | return x && x.constructor.prototype.isRange || false;
|
18654 | };
|
18655 |
|
18656 | type.isIndex = function (x) {
|
18657 | return x && x.constructor.prototype.isIndex || false;
|
18658 | };
|
18659 |
|
18660 | type.isBoolean = function (x) {
|
18661 | return typeof x === 'boolean';
|
18662 | };
|
18663 |
|
18664 | type.isResultSet = function (x) {
|
18665 | return x && x.constructor.prototype.isResultSet || false;
|
18666 | };
|
18667 |
|
18668 | type.isHelp = function (x) {
|
18669 | return x && x.constructor.prototype.isHelp || false;
|
18670 | };
|
18671 |
|
18672 | type.isFunction = function (x) {
|
18673 | return typeof x === 'function';
|
18674 | };
|
18675 |
|
18676 | type.isDate = function (x) {
|
18677 | return x instanceof Date;
|
18678 | };
|
18679 |
|
18680 | type.isRegExp = function (x) {
|
18681 | return x instanceof RegExp;
|
18682 | };
|
18683 |
|
18684 | type.isObject = function (x) {
|
18685 | return _typeof(x) === 'object' && x.constructor === Object && !type.isComplex(x) && !type.isFraction(x);
|
18686 | };
|
18687 |
|
18688 | type.isNull = function (x) {
|
18689 | return x === null;
|
18690 | };
|
18691 |
|
18692 | type.isUndefined = function (x) {
|
18693 | return x === undefined;
|
18694 | };
|
18695 |
|
18696 | type.isAccessorNode = function (x) {
|
18697 | return x && x.isAccessorNode && x.constructor.prototype.isNode || false;
|
18698 | };
|
18699 |
|
18700 | type.isArrayNode = function (x) {
|
18701 | return x && x.isArrayNode && x.constructor.prototype.isNode || false;
|
18702 | };
|
18703 |
|
18704 | type.isAssignmentNode = function (x) {
|
18705 | return x && x.isAssignmentNode && x.constructor.prototype.isNode || false;
|
18706 | };
|
18707 |
|
18708 | type.isBlockNode = function (x) {
|
18709 | return x && x.isBlockNode && x.constructor.prototype.isNode || false;
|
18710 | };
|
18711 |
|
18712 | type.isConditionalNode = function (x) {
|
18713 | return x && x.isConditionalNode && x.constructor.prototype.isNode || false;
|
18714 | };
|
18715 |
|
18716 | type.isConstantNode = function (x) {
|
18717 | return x && x.isConstantNode && x.constructor.prototype.isNode || false;
|
18718 | };
|
18719 |
|
18720 | type.isFunctionAssignmentNode = function (x) {
|
18721 | return x && x.isFunctionAssignmentNode && x.constructor.prototype.isNode || false;
|
18722 | };
|
18723 |
|
18724 | type.isFunctionNode = function (x) {
|
18725 | return x && x.isFunctionNode && x.constructor.prototype.isNode || false;
|
18726 | };
|
18727 |
|
18728 | type.isIndexNode = function (x) {
|
18729 | return x && x.isIndexNode && x.constructor.prototype.isNode || false;
|
18730 | };
|
18731 |
|
18732 | type.isNode = function (x) {
|
18733 | return x && x.isNode && x.constructor.prototype.isNode || false;
|
18734 | };
|
18735 |
|
18736 | type.isObjectNode = function (x) {
|
18737 | return x && x.isObjectNode && x.constructor.prototype.isNode || false;
|
18738 | };
|
18739 |
|
18740 | type.isOperatorNode = function (x) {
|
18741 | return x && x.isOperatorNode && x.constructor.prototype.isNode || false;
|
18742 | };
|
18743 |
|
18744 | type.isParenthesisNode = function (x) {
|
18745 | return x && x.isParenthesisNode && x.constructor.prototype.isNode || false;
|
18746 | };
|
18747 |
|
18748 | type.isRangeNode = function (x) {
|
18749 | return x && x.isRangeNode && x.constructor.prototype.isNode || false;
|
18750 | };
|
18751 |
|
18752 | type.isSymbolNode = function (x) {
|
18753 | return x && x.isSymbolNode && x.constructor.prototype.isNode || false;
|
18754 | };
|
18755 |
|
18756 | type.isChain = function (x) {
|
18757 | return x && x.constructor.prototype.isChain || false;
|
18758 | };
|
18759 |
|
18760 |
|
18761 | var typed = _createTyped();
|
18762 |
|
18763 |
|
18764 |
|
18765 |
|
18766 | typed.types = [{
|
18767 | name: 'number',
|
18768 | test: type.isNumber
|
18769 | }, {
|
18770 | name: 'Complex',
|
18771 | test: type.isComplex
|
18772 | }, {
|
18773 | name: 'BigNumber',
|
18774 | test: type.isBigNumber
|
18775 | }, {
|
18776 | name: 'Fraction',
|
18777 | test: type.isFraction
|
18778 | }, {
|
18779 | name: 'Unit',
|
18780 | test: type.isUnit
|
18781 | }, {
|
18782 | name: 'string',
|
18783 | test: type.isString
|
18784 | }, {
|
18785 | name: 'Array',
|
18786 | test: type.isArray
|
18787 | }, {
|
18788 | name: 'Matrix',
|
18789 | test: type.isMatrix
|
18790 | }, {
|
18791 | name: 'DenseMatrix',
|
18792 | test: type.isDenseMatrix
|
18793 | }, {
|
18794 | name: 'SparseMatrix',
|
18795 | test: type.isSparseMatrix
|
18796 | }, {
|
18797 | name: 'Range',
|
18798 | test: type.isRange
|
18799 | }, {
|
18800 | name: 'Index',
|
18801 | test: type.isIndex
|
18802 | }, {
|
18803 | name: 'boolean',
|
18804 | test: type.isBoolean
|
18805 | }, {
|
18806 | name: 'ResultSet',
|
18807 | test: type.isResultSet
|
18808 | }, {
|
18809 | name: 'Help',
|
18810 | test: type.isHelp
|
18811 | }, {
|
18812 | name: 'function',
|
18813 | test: type.isFunction
|
18814 | }, {
|
18815 | name: 'Date',
|
18816 | test: type.isDate
|
18817 | }, {
|
18818 | name: 'RegExp',
|
18819 | test: type.isRegExp
|
18820 | }, {
|
18821 | name: 'null',
|
18822 | test: type.isNull
|
18823 | }, {
|
18824 | name: 'undefined',
|
18825 | test: type.isUndefined
|
18826 | }, {
|
18827 | name: 'OperatorNode',
|
18828 | test: type.isOperatorNode
|
18829 | }, {
|
18830 | name: 'ConstantNode',
|
18831 | test: type.isConstantNode
|
18832 | }, {
|
18833 | name: 'SymbolNode',
|
18834 | test: type.isSymbolNode
|
18835 | }, {
|
18836 | name: 'ParenthesisNode',
|
18837 | test: type.isParenthesisNode
|
18838 | }, {
|
18839 | name: 'FunctionNode',
|
18840 | test: type.isFunctionNode
|
18841 | }, {
|
18842 | name: 'FunctionAssignmentNode',
|
18843 | test: type.isFunctionAssignmentNode
|
18844 | }, {
|
18845 | name: 'ArrayNode',
|
18846 | test: type.isArrayNode
|
18847 | }, {
|
18848 | name: 'AssignmentNode',
|
18849 | test: type.isAssignmentNode
|
18850 | }, {
|
18851 | name: 'BlockNode',
|
18852 | test: type.isBlockNode
|
18853 | }, {
|
18854 | name: 'ConditionalNode',
|
18855 | test: type.isConditionalNode
|
18856 | }, {
|
18857 | name: 'IndexNode',
|
18858 | test: type.isIndexNode
|
18859 | }, {
|
18860 | name: 'RangeNode',
|
18861 | test: type.isRangeNode
|
18862 | }, {
|
18863 | name: 'Node',
|
18864 | test: type.isNode
|
18865 | }, {
|
18866 | name: 'Object',
|
18867 | test: type.isObject
|
18868 |
|
18869 | }];
|
18870 |
|
18871 | typed.conversions = [{
|
18872 | from: 'number',
|
18873 | to: 'BigNumber',
|
18874 | convert: function convert(x) {
|
18875 |
|
18876 | if (digits(x) > 15) {
|
18877 | throw new TypeError('Cannot implicitly convert a number with >15 significant digits to BigNumber ' + '(value: ' + x + '). ' + 'Use function bignumber(x) to convert to BigNumber.');
|
18878 | }
|
18879 |
|
18880 | return new type.BigNumber(x);
|
18881 | }
|
18882 | }, {
|
18883 | from: 'number',
|
18884 | to: 'Complex',
|
18885 | convert: function convert(x) {
|
18886 | return new type.Complex(x, 0);
|
18887 | }
|
18888 | }, {
|
18889 | from: 'number',
|
18890 | to: 'string',
|
18891 | convert: function convert(x) {
|
18892 | return x + '';
|
18893 | }
|
18894 | }, {
|
18895 | from: 'BigNumber',
|
18896 | to: 'Complex',
|
18897 | convert: function convert(x) {
|
18898 | return new type.Complex(x.toNumber(), 0);
|
18899 | }
|
18900 | }, {
|
18901 | from: 'Fraction',
|
18902 | to: 'BigNumber',
|
18903 | convert: function convert(x) {
|
18904 | throw new TypeError('Cannot implicitly convert a Fraction to BigNumber or vice versa. ' + 'Use function bignumber(x) to convert to BigNumber or fraction(x) to convert to Fraction.');
|
18905 | }
|
18906 | }, {
|
18907 | from: 'Fraction',
|
18908 | to: 'Complex',
|
18909 | convert: function convert(x) {
|
18910 | return new type.Complex(x.valueOf(), 0);
|
18911 | }
|
18912 | }, {
|
18913 | from: 'number',
|
18914 | to: 'Fraction',
|
18915 | convert: function convert(x) {
|
18916 | var f = new type.Fraction(x);
|
18917 |
|
18918 | if (f.valueOf() !== x) {
|
18919 | throw new TypeError('Cannot implicitly convert a number to a Fraction when there will be a loss of precision ' + '(value: ' + x + '). ' + 'Use function fraction(x) to convert to Fraction.');
|
18920 | }
|
18921 |
|
18922 | return new type.Fraction(x);
|
18923 | }
|
18924 | }, {
|
18925 |
|
18926 |
|
18927 |
|
18928 |
|
18929 |
|
18930 |
|
18931 |
|
18932 | from: 'string',
|
18933 | to: 'number',
|
18934 | convert: function convert(x) {
|
18935 | var n = Number(x);
|
18936 |
|
18937 | if (isNaN(n)) {
|
18938 | throw new Error('Cannot convert "' + x + '" to a number');
|
18939 | }
|
18940 |
|
18941 | return n;
|
18942 | }
|
18943 | }, {
|
18944 | from: 'string',
|
18945 | to: 'BigNumber',
|
18946 | convert: function convert(x) {
|
18947 | try {
|
18948 | return new type.BigNumber(x);
|
18949 | } catch (err) {
|
18950 | throw new Error('Cannot convert "' + x + '" to BigNumber');
|
18951 | }
|
18952 | }
|
18953 | }, {
|
18954 | from: 'string',
|
18955 | to: 'Fraction',
|
18956 | convert: function convert(x) {
|
18957 | try {
|
18958 | return new type.Fraction(x);
|
18959 | } catch (err) {
|
18960 | throw new Error('Cannot convert "' + x + '" to Fraction');
|
18961 | }
|
18962 | }
|
18963 | }, {
|
18964 | from: 'string',
|
18965 | to: 'Complex',
|
18966 | convert: function convert(x) {
|
18967 | try {
|
18968 | return new type.Complex(x);
|
18969 | } catch (err) {
|
18970 | throw new Error('Cannot convert "' + x + '" to Complex');
|
18971 | }
|
18972 | }
|
18973 | }, {
|
18974 | from: 'boolean',
|
18975 | to: 'number',
|
18976 | convert: function convert(x) {
|
18977 | return +x;
|
18978 | }
|
18979 | }, {
|
18980 | from: 'boolean',
|
18981 | to: 'BigNumber',
|
18982 | convert: function convert(x) {
|
18983 | return new type.BigNumber(+x);
|
18984 | }
|
18985 | }, {
|
18986 | from: 'boolean',
|
18987 | to: 'Fraction',
|
18988 | convert: function convert(x) {
|
18989 | return new type.Fraction(+x);
|
18990 | }
|
18991 | }, {
|
18992 | from: 'boolean',
|
18993 | to: 'string',
|
18994 | convert: function convert(x) {
|
18995 | return +x;
|
18996 | }
|
18997 | }, {
|
18998 | from: 'Array',
|
18999 | to: 'Matrix',
|
19000 | convert: function convert(array) {
|
19001 | return new type.DenseMatrix(array);
|
19002 | }
|
19003 | }, {
|
19004 | from: 'Matrix',
|
19005 | to: 'Array',
|
19006 | convert: function convert(matrix) {
|
19007 | return matrix.valueOf();
|
19008 | }
|
19009 | }];
|
19010 | return typed;
|
19011 | };
|
19012 |
|
19013 | }),
|
19014 |
|
19015 | (function(module, exports, __webpack_require__) {
|
19016 |
|
19017 | "use strict";
|
19018 |
|
19019 |
|
19020 | var Emitter = __webpack_require__(165);
|
19021 |
|
19022 |
|
19023 |
|
19024 |
|
19025 |
|
19026 |
|
19027 |
|
19028 | exports.mixin = function (obj) {
|
19029 |
|
19030 | var emitter = new Emitter();
|
19031 |
|
19032 | obj.on = emitter.on.bind(emitter);
|
19033 | obj.off = emitter.off.bind(emitter);
|
19034 | obj.once = emitter.once.bind(emitter);
|
19035 | obj.emit = emitter.emit.bind(emitter);
|
19036 | return obj;
|
19037 | };
|
19038 |
|
19039 | }),
|
19040 |
|
19041 | (function(module, exports, __webpack_require__) {
|
19042 |
|
19043 | "use strict";
|
19044 |
|
19045 |
|
19046 | var deepMap = __webpack_require__(1);
|
19047 |
|
19048 | function factory(type, config, load, typed) {
|
19049 | |
19050 |
|
19051 |
|
19052 |
|
19053 |
|
19054 |
|
19055 |
|
19056 |
|
19057 |
|
19058 |
|
19059 |
|
19060 |
|
19061 |
|
19062 |
|
19063 |
|
19064 |
|
19065 |
|
19066 |
|
19067 |
|
19068 |
|
19069 |
|
19070 |
|
19071 |
|
19072 |
|
19073 |
|
19074 | var bignumber = typed('bignumber', {
|
19075 | '': function _() {
|
19076 | return new type.BigNumber(0);
|
19077 | },
|
19078 | 'number': function number(x) {
|
19079 |
|
19080 | return new type.BigNumber(x + '');
|
19081 | },
|
19082 | 'string': function string(x) {
|
19083 | return new type.BigNumber(x);
|
19084 | },
|
19085 | 'BigNumber': function BigNumber(x) {
|
19086 |
|
19087 | return x;
|
19088 | },
|
19089 | 'Fraction': function Fraction(x) {
|
19090 | return new type.BigNumber(x.n).div(x.d).times(x.s);
|
19091 | },
|
19092 | 'null': function _null(x) {
|
19093 | return new type.BigNumber(0);
|
19094 | },
|
19095 | 'Array | Matrix': function ArrayMatrix(x) {
|
19096 | return deepMap(x, bignumber);
|
19097 | }
|
19098 | });
|
19099 | bignumber.toTex = {
|
19100 | 0: '0',
|
19101 | 1: "\\left(${args[0]}\\right)"
|
19102 | };
|
19103 | return bignumber;
|
19104 | }
|
19105 |
|
19106 | exports.name = 'bignumber';
|
19107 | exports.factory = factory;
|
19108 |
|
19109 | }),
|
19110 |
|
19111 | (function(module, exports, __webpack_require__) {
|
19112 |
|
19113 | "use strict";
|
19114 |
|
19115 |
|
19116 | var number = __webpack_require__(3);
|
19117 |
|
19118 | function factory(type, config, load, typed) {
|
19119 | |
19120 |
|
19121 |
|
19122 |
|
19123 |
|
19124 |
|
19125 |
|
19126 |
|
19127 |
|
19128 |
|
19129 |
|
19130 |
|
19131 |
|
19132 |
|
19133 |
|
19134 |
|
19135 |
|
19136 |
|
19137 |
|
19138 |
|
19139 |
|
19140 |
|
19141 |
|
19142 |
|
19143 |
|
19144 |
|
19145 |
|
19146 |
|
19147 |
|
19148 |
|
19149 |
|
19150 | function Range(start, end, step) {
|
19151 | if (!(this instanceof Range)) {
|
19152 | throw new SyntaxError('Constructor must be called with the new operator');
|
19153 | }
|
19154 |
|
19155 | var hasStart = start !== null && start !== undefined;
|
19156 | var hasEnd = end !== null && end !== undefined;
|
19157 | var hasStep = step !== null && step !== undefined;
|
19158 |
|
19159 | if (hasStart) {
|
19160 | if (type.isBigNumber(start)) {
|
19161 | start = start.toNumber();
|
19162 | } else if (typeof start !== 'number') {
|
19163 | throw new TypeError('Parameter start must be a number');
|
19164 | }
|
19165 | }
|
19166 |
|
19167 | if (hasEnd) {
|
19168 | if (type.isBigNumber(end)) {
|
19169 | end = end.toNumber();
|
19170 | } else if (typeof end !== 'number') {
|
19171 | throw new TypeError('Parameter end must be a number');
|
19172 | }
|
19173 | }
|
19174 |
|
19175 | if (hasStep) {
|
19176 | if (type.isBigNumber(step)) {
|
19177 | step = step.toNumber();
|
19178 | } else if (typeof step !== 'number') {
|
19179 | throw new TypeError('Parameter step must be a number');
|
19180 | }
|
19181 | }
|
19182 |
|
19183 | this.start = hasStart ? parseFloat(start) : 0;
|
19184 | this.end = hasEnd ? parseFloat(end) : 0;
|
19185 | this.step = hasStep ? parseFloat(step) : 1;
|
19186 | }
|
19187 | |
19188 |
|
19189 |
|
19190 |
|
19191 |
|
19192 | Range.prototype.type = 'Range';
|
19193 | Range.prototype.isRange = true;
|
19194 | |
19195 |
|
19196 |
|
19197 |
|
19198 |
|
19199 |
|
19200 |
|
19201 |
|
19202 |
|
19203 |
|
19204 | Range.parse = function (str) {
|
19205 | if (typeof str !== 'string') {
|
19206 | return null;
|
19207 | }
|
19208 |
|
19209 | var args = str.split(':');
|
19210 | var nums = args.map(function (arg) {
|
19211 | return parseFloat(arg);
|
19212 | });
|
19213 | var invalid = nums.some(function (num) {
|
19214 | return isNaN(num);
|
19215 | });
|
19216 |
|
19217 | if (invalid) {
|
19218 | return null;
|
19219 | }
|
19220 |
|
19221 | switch (nums.length) {
|
19222 | case 2:
|
19223 | return new Range(nums[0], nums[1]);
|
19224 |
|
19225 | case 3:
|
19226 | return new Range(nums[0], nums[2], nums[1]);
|
19227 |
|
19228 | default:
|
19229 | return null;
|
19230 | }
|
19231 | };
|
19232 | |
19233 |
|
19234 |
|
19235 |
|
19236 |
|
19237 |
|
19238 | Range.prototype.clone = function () {
|
19239 | return new Range(this.start, this.end, this.step);
|
19240 | };
|
19241 | |
19242 |
|
19243 |
|
19244 |
|
19245 |
|
19246 |
|
19247 |
|
19248 |
|
19249 | Range.prototype.size = function () {
|
19250 | var len = 0;
|
19251 | var start = this.start;
|
19252 | var step = this.step;
|
19253 | var end = this.end;
|
19254 | var diff = end - start;
|
19255 |
|
19256 | if (number.sign(step) === number.sign(diff)) {
|
19257 | len = Math.ceil(diff / step);
|
19258 | } else if (diff === 0) {
|
19259 | len = 0;
|
19260 | }
|
19261 |
|
19262 | if (isNaN(len)) {
|
19263 | len = 0;
|
19264 | }
|
19265 |
|
19266 | return [len];
|
19267 | };
|
19268 | |
19269 |
|
19270 |
|
19271 |
|
19272 |
|
19273 |
|
19274 |
|
19275 | Range.prototype.min = function () {
|
19276 | var size = this.size()[0];
|
19277 |
|
19278 | if (size > 0) {
|
19279 | if (this.step > 0) {
|
19280 |
|
19281 | return this.start;
|
19282 | } else {
|
19283 |
|
19284 | return this.start + (size - 1) * this.step;
|
19285 | }
|
19286 | } else {
|
19287 | return undefined;
|
19288 | }
|
19289 | };
|
19290 | |
19291 |
|
19292 |
|
19293 |
|
19294 |
|
19295 |
|
19296 |
|
19297 | Range.prototype.max = function () {
|
19298 | var size = this.size()[0];
|
19299 |
|
19300 | if (size > 0) {
|
19301 | if (this.step > 0) {
|
19302 |
|
19303 | return this.start + (size - 1) * this.step;
|
19304 | } else {
|
19305 |
|
19306 | return this.start;
|
19307 | }
|
19308 | } else {
|
19309 | return undefined;
|
19310 | }
|
19311 | };
|
19312 | |
19313 |
|
19314 |
|
19315 |
|
19316 |
|
19317 |
|
19318 |
|
19319 |
|
19320 |
|
19321 | Range.prototype.forEach = function (callback) {
|
19322 | var x = this.start;
|
19323 | var step = this.step;
|
19324 | var end = this.end;
|
19325 | var i = 0;
|
19326 |
|
19327 | if (step > 0) {
|
19328 | while (x < end) {
|
19329 | callback(x, [i], this);
|
19330 | x += step;
|
19331 | i++;
|
19332 | }
|
19333 | } else if (step < 0) {
|
19334 | while (x > end) {
|
19335 | callback(x, [i], this);
|
19336 | x += step;
|
19337 | i++;
|
19338 | }
|
19339 | }
|
19340 | };
|
19341 | |
19342 |
|
19343 |
|
19344 |
|
19345 |
|
19346 |
|
19347 |
|
19348 |
|
19349 |
|
19350 |
|
19351 |
|
19352 | Range.prototype.map = function (callback) {
|
19353 | var array = [];
|
19354 | this.forEach(function (value, index, obj) {
|
19355 | array[index[0]] = callback(value, index, obj);
|
19356 | });
|
19357 | return array;
|
19358 | };
|
19359 | |
19360 |
|
19361 |
|
19362 |
|
19363 |
|
19364 |
|
19365 |
|
19366 | Range.prototype.toArray = function () {
|
19367 | var array = [];
|
19368 | this.forEach(function (value, index) {
|
19369 | array[index[0]] = value;
|
19370 | });
|
19371 | return array;
|
19372 | };
|
19373 | |
19374 |
|
19375 |
|
19376 |
|
19377 |
|
19378 |
|
19379 |
|
19380 | Range.prototype.valueOf = function () {
|
19381 |
|
19382 | return this.toArray();
|
19383 | };
|
19384 | |
19385 |
|
19386 |
|
19387 |
|
19388 |
|
19389 |
|
19390 |
|
19391 |
|
19392 |
|
19393 |
|
19394 |
|
19395 |
|
19396 | Range.prototype.format = function (options) {
|
19397 | var str = number.format(this.start, options);
|
19398 |
|
19399 | if (this.step !== 1) {
|
19400 | str += ':' + number.format(this.step, options);
|
19401 | }
|
19402 |
|
19403 | str += ':' + number.format(this.end, options);
|
19404 | return str;
|
19405 | };
|
19406 | |
19407 |
|
19408 |
|
19409 |
|
19410 |
|
19411 |
|
19412 |
|
19413 | Range.prototype.toString = function () {
|
19414 | return this.format();
|
19415 | };
|
19416 | |
19417 |
|
19418 |
|
19419 |
|
19420 |
|
19421 |
|
19422 |
|
19423 |
|
19424 | Range.prototype.toJSON = function () {
|
19425 | return {
|
19426 | mathjs: 'Range',
|
19427 | start: this.start,
|
19428 | end: this.end,
|
19429 | step: this.step
|
19430 | };
|
19431 | };
|
19432 | |
19433 |
|
19434 |
|
19435 |
|
19436 |
|
19437 |
|
19438 |
|
19439 |
|
19440 |
|
19441 | Range.fromJSON = function (json) {
|
19442 | return new Range(json.start, json.end, json.step);
|
19443 | };
|
19444 |
|
19445 | return Range;
|
19446 | }
|
19447 |
|
19448 | exports.name = 'Range';
|
19449 | exports.path = 'type';
|
19450 | exports.factory = factory;
|
19451 |
|
19452 | }),
|
19453 |
|
19454 | (function(module, exports, __webpack_require__) {
|
19455 |
|
19456 | "use strict";
|
19457 |
|
19458 |
|
19459 | function factory(type, config, load, typed) {
|
19460 | |
19461 |
|
19462 |
|
19463 |
|
19464 |
|
19465 |
|
19466 | function ResultSet(entries) {
|
19467 | if (!(this instanceof ResultSet)) {
|
19468 | throw new SyntaxError('Constructor must be called with the new operator');
|
19469 | }
|
19470 |
|
19471 | this.entries = entries || [];
|
19472 | }
|
19473 | |
19474 |
|
19475 |
|
19476 |
|
19477 |
|
19478 | ResultSet.prototype.type = 'ResultSet';
|
19479 | ResultSet.prototype.isResultSet = true;
|
19480 | |
19481 |
|
19482 |
|
19483 |
|
19484 |
|
19485 |
|
19486 | ResultSet.prototype.valueOf = function () {
|
19487 | return this.entries;
|
19488 | };
|
19489 | |
19490 |
|
19491 |
|
19492 |
|
19493 |
|
19494 |
|
19495 |
|
19496 | ResultSet.prototype.toString = function () {
|
19497 | return '[' + this.entries.join(', ') + ']';
|
19498 | };
|
19499 | |
19500 |
|
19501 |
|
19502 |
|
19503 |
|
19504 |
|
19505 |
|
19506 |
|
19507 | ResultSet.prototype.toJSON = function () {
|
19508 | return {
|
19509 | mathjs: 'ResultSet',
|
19510 | entries: this.entries
|
19511 | };
|
19512 | };
|
19513 | |
19514 |
|
19515 |
|
19516 |
|
19517 |
|
19518 |
|
19519 |
|
19520 |
|
19521 |
|
19522 | ResultSet.fromJSON = function (json) {
|
19523 | return new ResultSet(json.entries);
|
19524 | };
|
19525 |
|
19526 | return ResultSet;
|
19527 | }
|
19528 |
|
19529 | exports.name = 'ResultSet';
|
19530 | exports.path = 'type';
|
19531 | exports.factory = factory;
|
19532 |
|
19533 | }),
|
19534 |
|
19535 | (function(module, exports, __webpack_require__) {
|
19536 |
|
19537 | "use strict";
|
19538 |
|
19539 |
|
19540 | var memoize = __webpack_require__(36).memoize;
|
19541 |
|
19542 |
|
19543 |
|
19544 |
|
19545 |
|
19546 |
|
19547 |
|
19548 | exports.e = memoize(function (BigNumber) {
|
19549 | return new BigNumber(1).exp();
|
19550 | }, hasher);
|
19551 |
|
19552 |
|
19553 |
|
19554 |
|
19555 |
|
19556 |
|
19557 | exports.phi = memoize(function (BigNumber) {
|
19558 | return new BigNumber(1).plus(new BigNumber(5).sqrt()).div(2);
|
19559 | }, hasher);
|
19560 |
|
19561 |
|
19562 |
|
19563 |
|
19564 |
|
19565 |
|
19566 | exports.pi = memoize(function (BigNumber) {
|
19567 | return BigNumber.acos(-1);
|
19568 | }, hasher);
|
19569 |
|
19570 |
|
19571 |
|
19572 |
|
19573 |
|
19574 |
|
19575 | exports.tau = memoize(function (BigNumber) {
|
19576 | return exports.pi(BigNumber).times(2);
|
19577 | }, hasher);
|
19578 |
|
19579 |
|
19580 |
|
19581 |
|
19582 |
|
19583 |
|
19584 |
|
19585 |
|
19586 |
|
19587 | function hasher(args) {
|
19588 | return args[0].precision;
|
19589 | }
|
19590 |
|
19591 | }),
|
19592 |
|
19593 | (function(module, exports, __webpack_require__) {
|
19594 |
|
19595 | "use strict";
|
19596 |
|
19597 |
|
19598 | var deepMap = __webpack_require__(1);
|
19599 |
|
19600 | function factory(type, config, load, typed) {
|
19601 | var ceil = load(__webpack_require__(110));
|
19602 | var floor = load(__webpack_require__(111));
|
19603 | |
19604 |
|
19605 |
|
19606 |
|
19607 |
|
19608 |
|
19609 |
|
19610 |
|
19611 |
|
19612 |
|
19613 |
|
19614 |
|
19615 |
|
19616 |
|
19617 |
|
19618 |
|
19619 |
|
19620 |
|
19621 |
|
19622 |
|
19623 |
|
19624 |
|
19625 |
|
19626 |
|
19627 |
|
19628 |
|
19629 |
|
19630 |
|
19631 | var fix = typed('fix', {
|
19632 | 'number': function number(x) {
|
19633 | return x > 0 ? floor(x) : ceil(x);
|
19634 | },
|
19635 | 'Complex': function Complex(x) {
|
19636 | return new type.Complex(x.re > 0 ? Math.floor(x.re) : Math.ceil(x.re), x.im > 0 ? Math.floor(x.im) : Math.ceil(x.im));
|
19637 | },
|
19638 | 'BigNumber': function BigNumber(x) {
|
19639 | return x.isNegative() ? ceil(x) : floor(x);
|
19640 | },
|
19641 | 'Fraction': function Fraction(x) {
|
19642 | return x.s < 0 ? x.ceil() : x.floor();
|
19643 | },
|
19644 | 'Array | Matrix': function ArrayMatrix(x) {
|
19645 |
|
19646 | return deepMap(x, fix, true);
|
19647 | }
|
19648 | });
|
19649 | fix.toTex = {
|
19650 | 1: "\\mathrm{${name}}\\left(${args[0]}\\right)"
|
19651 | };
|
19652 | return fix;
|
19653 | }
|
19654 |
|
19655 | exports.name = 'fix';
|
19656 | exports.factory = factory;
|
19657 |
|
19658 | }),
|
19659 |
|
19660 | (function(module, exports, __webpack_require__) {
|
19661 |
|
19662 | "use strict";
|
19663 |
|
19664 |
|
19665 | var deepMap = __webpack_require__(1);
|
19666 |
|
19667 | var nearlyEqual = __webpack_require__(3).nearlyEqual;
|
19668 |
|
19669 | var bigNearlyEqual = __webpack_require__(32);
|
19670 |
|
19671 | function factory(type, config, load, typed) {
|
19672 | var round = load(__webpack_require__(67));
|
19673 | |
19674 |
|
19675 |
|
19676 |
|
19677 |
|
19678 |
|
19679 |
|
19680 |
|
19681 |
|
19682 |
|
19683 |
|
19684 |
|
19685 |
|
19686 |
|
19687 |
|
19688 |
|
19689 |
|
19690 |
|
19691 |
|
19692 |
|
19693 |
|
19694 |
|
19695 |
|
19696 |
|
19697 |
|
19698 |
|
19699 |
|
19700 |
|
19701 |
|
19702 | var ceil = typed('ceil', {
|
19703 | 'number': function number(x) {
|
19704 | if (nearlyEqual(x, round(x), config.epsilon)) {
|
19705 | return round(x);
|
19706 | } else {
|
19707 | return Math.ceil(x);
|
19708 | }
|
19709 | },
|
19710 | 'Complex': function Complex(x) {
|
19711 | return x.ceil();
|
19712 | },
|
19713 | 'BigNumber': function BigNumber(x) {
|
19714 | if (bigNearlyEqual(x, round(x), config.epsilon)) {
|
19715 | return round(x);
|
19716 | } else {
|
19717 | return x.ceil();
|
19718 | }
|
19719 | },
|
19720 | 'Fraction': function Fraction(x) {
|
19721 | return x.ceil();
|
19722 | },
|
19723 | 'Array | Matrix': function ArrayMatrix(x) {
|
19724 |
|
19725 | return deepMap(x, ceil, true);
|
19726 | }
|
19727 | });
|
19728 | ceil.toTex = {
|
19729 | 1: "\\left\\lceil${args[0]}\\right\\rceil"
|
19730 | };
|
19731 | return ceil;
|
19732 | }
|
19733 |
|
19734 | exports.name = 'ceil';
|
19735 | exports.factory = factory;
|
19736 |
|
19737 | }),
|
19738 |
|
19739 | (function(module, exports, __webpack_require__) {
|
19740 |
|
19741 | "use strict";
|
19742 |
|
19743 |
|
19744 | var deepMap = __webpack_require__(1);
|
19745 |
|
19746 | var nearlyEqual = __webpack_require__(3).nearlyEqual;
|
19747 |
|
19748 | var bigNearlyEqual = __webpack_require__(32);
|
19749 |
|
19750 | function factory(type, config, load, typed) {
|
19751 | var round = load(__webpack_require__(67));
|
19752 | |
19753 |
|
19754 |
|
19755 |
|
19756 |
|
19757 |
|
19758 |
|
19759 |
|
19760 |
|
19761 |
|
19762 |
|
19763 |
|
19764 |
|
19765 |
|
19766 |
|
19767 |
|
19768 |
|
19769 |
|
19770 |
|
19771 |
|
19772 |
|
19773 |
|
19774 |
|
19775 |
|
19776 |
|
19777 |
|
19778 |
|
19779 |
|
19780 | var floor = typed('floor', {
|
19781 | 'number': function number(x) {
|
19782 | if (nearlyEqual(x, round(x), config.epsilon)) {
|
19783 | return round(x);
|
19784 | } else {
|
19785 | return Math.floor(x);
|
19786 | }
|
19787 | },
|
19788 | 'Complex': function Complex(x) {
|
19789 | return x.floor();
|
19790 | },
|
19791 | 'BigNumber': function BigNumber(x) {
|
19792 | if (bigNearlyEqual(x, round(x), config.epsilon)) {
|
19793 | return round(x);
|
19794 | } else {
|
19795 | return x.floor();
|
19796 | }
|
19797 | },
|
19798 | 'Fraction': function Fraction(x) {
|
19799 | return x.floor();
|
19800 | },
|
19801 | 'Array | Matrix': function ArrayMatrix(x) {
|
19802 |
|
19803 | return deepMap(x, floor, true);
|
19804 | }
|
19805 | });
|
19806 | floor.toTex = {
|
19807 | 1: "\\left\\lfloor${args[0]}\\right\\rfloor"
|
19808 | };
|
19809 | return floor;
|
19810 | }
|
19811 |
|
19812 | exports.name = 'floor';
|
19813 | exports.factory = factory;
|
19814 |
|
19815 | }),
|
19816 |
|
19817 | (function(module, exports, __webpack_require__) {
|
19818 |
|
19819 | "use strict";
|
19820 |
|
19821 |
|
19822 | var string = __webpack_require__(9);
|
19823 |
|
19824 | function factory(type, config, load, typed) {
|
19825 | |
19826 |
|
19827 |
|
19828 |
|
19829 |
|
19830 |
|
19831 |
|
19832 |
|
19833 |
|
19834 |
|
19835 |
|
19836 |
|
19837 |
|
19838 |
|
19839 |
|
19840 |
|
19841 |
|
19842 |
|
19843 |
|
19844 |
|
19845 |
|
19846 |
|
19847 |
|
19848 |
|
19849 |
|
19850 |
|
19851 |
|
19852 |
|
19853 |
|
19854 |
|
19855 |
|
19856 |
|
19857 |
|
19858 |
|
19859 |
|
19860 |
|
19861 |
|
19862 |
|
19863 |
|
19864 |
|
19865 |
|
19866 |
|
19867 |
|
19868 |
|
19869 |
|
19870 |
|
19871 |
|
19872 |
|
19873 |
|
19874 |
|
19875 |
|
19876 |
|
19877 |
|
19878 |
|
19879 |
|
19880 |
|
19881 |
|
19882 |
|
19883 |
|
19884 |
|
19885 |
|
19886 |
|
19887 |
|
19888 |
|
19889 |
|
19890 |
|
19891 |
|
19892 |
|
19893 |
|
19894 |
|
19895 |
|
19896 |
|
19897 |
|
19898 |
|
19899 |
|
19900 |
|
19901 |
|
19902 |
|
19903 |
|
19904 |
|
19905 |
|
19906 |
|
19907 |
|
19908 |
|
19909 |
|
19910 |
|
19911 |
|
19912 |
|
19913 |
|
19914 |
|
19915 |
|
19916 |
|
19917 |
|
19918 |
|
19919 |
|
19920 |
|
19921 |
|
19922 |
|
19923 |
|
19924 |
|
19925 | var format = typed('format', {
|
19926 | 'any': string.format,
|
19927 | 'any, Object | function | number': string.format
|
19928 | });
|
19929 | format.toTex = undefined;
|
19930 |
|
19931 | return format;
|
19932 | }
|
19933 |
|
19934 | exports.name = 'format';
|
19935 | exports.factory = factory;
|
19936 |
|
19937 | }),
|
19938 |
|
19939 | (function(module, exports, __webpack_require__) {
|
19940 |
|
19941 | "use strict";
|
19942 |
|
19943 |
|
19944 | var getSafeProperty = __webpack_require__(13).getSafeProperty;
|
19945 |
|
19946 | function factory(type, config, load, typed) {
|
19947 | var Node = load(__webpack_require__(16));
|
19948 | var access = load(__webpack_require__(115));
|
19949 | |
19950 |
|
19951 |
|
19952 |
|
19953 |
|
19954 |
|
19955 |
|
19956 |
|
19957 |
|
19958 |
|
19959 | function AccessorNode(object, index) {
|
19960 | if (!(this instanceof AccessorNode)) {
|
19961 | throw new SyntaxError('Constructor must be called with the new operator');
|
19962 | }
|
19963 |
|
19964 | if (!type.isNode(object)) {
|
19965 | throw new TypeError('Node expected for parameter "object"');
|
19966 | }
|
19967 |
|
19968 | if (!type.isIndexNode(index)) {
|
19969 | throw new TypeError('IndexNode expected for parameter "index"');
|
19970 | }
|
19971 |
|
19972 | this.object = object || null;
|
19973 | this.index = index;
|
19974 |
|
19975 | Object.defineProperty(this, 'name', {
|
19976 | get: function () {
|
19977 | if (this.index) {
|
19978 | return this.index.isObjectProperty() ? this.index.getObjectProperty() : '';
|
19979 | } else {
|
19980 | return this.object.name || '';
|
19981 | }
|
19982 | }.bind(this),
|
19983 | set: function set() {
|
19984 | throw new Error('Cannot assign a new name, name is read-only');
|
19985 | }
|
19986 | });
|
19987 | }
|
19988 |
|
19989 | AccessorNode.prototype = new Node();
|
19990 | AccessorNode.prototype.type = 'AccessorNode';
|
19991 | AccessorNode.prototype.isAccessorNode = true;
|
19992 | |
19993 |
|
19994 |
|
19995 |
|
19996 |
|
19997 |
|
19998 |
|
19999 |
|
20000 |
|
20001 |
|
20002 |
|
20003 |
|
20004 |
|
20005 |
|
20006 | AccessorNode.prototype._compile = function (math, argNames) {
|
20007 | var evalObject = this.object._compile(math, argNames);
|
20008 |
|
20009 | var evalIndex = this.index._compile(math, argNames);
|
20010 |
|
20011 | if (this.index.isObjectProperty()) {
|
20012 | var prop = this.index.getObjectProperty();
|
20013 | return function evalAccessorNode(scope, args, context) {
|
20014 | return getSafeProperty(evalObject(scope, args, context), prop);
|
20015 | };
|
20016 | } else {
|
20017 | return function evalAccessorNode(scope, args, context) {
|
20018 | var object = evalObject(scope, args, context);
|
20019 | var index = evalIndex(scope, args, object);
|
20020 |
|
20021 | return access(object, index);
|
20022 | };
|
20023 | }
|
20024 | };
|
20025 | |
20026 |
|
20027 |
|
20028 |
|
20029 |
|
20030 |
|
20031 | AccessorNode.prototype.forEach = function (callback) {
|
20032 | callback(this.object, 'object', this);
|
20033 | callback(this.index, 'index', this);
|
20034 | };
|
20035 | |
20036 |
|
20037 |
|
20038 |
|
20039 |
|
20040 |
|
20041 |
|
20042 |
|
20043 | AccessorNode.prototype.map = function (callback) {
|
20044 | return new AccessorNode(this._ifNode(callback(this.object, 'object', this)), this._ifNode(callback(this.index, 'index', this)));
|
20045 | };
|
20046 | |
20047 |
|
20048 |
|
20049 |
|
20050 |
|
20051 |
|
20052 | AccessorNode.prototype.clone = function () {
|
20053 | return new AccessorNode(this.object, this.index);
|
20054 | };
|
20055 | |
20056 |
|
20057 |
|
20058 |
|
20059 |
|
20060 |
|
20061 |
|
20062 | AccessorNode.prototype._toString = function (options) {
|
20063 | var object = this.object.toString(options);
|
20064 |
|
20065 | if (needParenthesis(this.object)) {
|
20066 | object = '(' + object + ')';
|
20067 | }
|
20068 |
|
20069 | return object + this.index.toString(options);
|
20070 | };
|
20071 | |
20072 |
|
20073 |
|
20074 |
|
20075 |
|
20076 |
|
20077 |
|
20078 | AccessorNode.prototype.toHTML = function (options) {
|
20079 | var object = this.object.toHTML(options);
|
20080 |
|
20081 | if (needParenthesis(this.object)) {
|
20082 | object = '<span class="math-parenthesis math-round-parenthesis">(</span>' + object + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
20083 | }
|
20084 |
|
20085 | return object + this.index.toHTML(options);
|
20086 | };
|
20087 | |
20088 |
|
20089 |
|
20090 |
|
20091 |
|
20092 |
|
20093 |
|
20094 | AccessorNode.prototype._toTex = function (options) {
|
20095 | var object = this.object.toTex(options);
|
20096 |
|
20097 | if (needParenthesis(this.object)) {
|
20098 | object = "\\left(' + object + '\\right)";
|
20099 | }
|
20100 |
|
20101 | return object + this.index.toTex(options);
|
20102 | };
|
20103 | |
20104 |
|
20105 |
|
20106 |
|
20107 |
|
20108 |
|
20109 | AccessorNode.prototype.toJSON = function () {
|
20110 | return {
|
20111 | mathjs: 'AccessorNode',
|
20112 | object: this.object,
|
20113 | index: this.index
|
20114 | };
|
20115 | };
|
20116 | |
20117 |
|
20118 |
|
20119 |
|
20120 |
|
20121 |
|
20122 |
|
20123 |
|
20124 |
|
20125 | AccessorNode.fromJSON = function (json) {
|
20126 | return new AccessorNode(json.object, json.index);
|
20127 | };
|
20128 | |
20129 |
|
20130 |
|
20131 |
|
20132 |
|
20133 |
|
20134 | function needParenthesis(node) {
|
20135 |
|
20136 | return !(type.isAccessorNode(node) || type.isArrayNode(node) || type.isConstantNode(node) || type.isFunctionNode(node) || type.isObjectNode(node) || type.isParenthesisNode(node) || type.isSymbolNode(node));
|
20137 | }
|
20138 |
|
20139 | return AccessorNode;
|
20140 | }
|
20141 |
|
20142 | exports.name = 'AccessorNode';
|
20143 | exports.path = 'expression.node';
|
20144 | exports.factory = factory;
|
20145 |
|
20146 | }),
|
20147 |
|
20148 | (function(module, exports, __webpack_require__) {
|
20149 |
|
20150 | "use strict";
|
20151 |
|
20152 |
|
20153 | module.exports = {
|
20154 | end: true
|
20155 | };
|
20156 |
|
20157 | }),
|
20158 |
|
20159 | (function(module, exports, __webpack_require__) {
|
20160 |
|
20161 | "use strict";
|
20162 |
|
20163 |
|
20164 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
20165 |
|
20166 | var errorTransform = __webpack_require__(22).transform;
|
20167 |
|
20168 | var getSafeProperty = __webpack_require__(13).getSafeProperty;
|
20169 |
|
20170 | function factory(type, config, load, typed) {
|
20171 | var subset = load(__webpack_require__(23));
|
20172 | |
20173 |
|
20174 |
|
20175 |
|
20176 |
|
20177 |
|
20178 |
|
20179 |
|
20180 |
|
20181 |
|
20182 |
|
20183 |
|
20184 | return function access(object, index) {
|
20185 | try {
|
20186 | if (Array.isArray(object)) {
|
20187 | return subset(object, index);
|
20188 | } else if (object && typeof object.subset === 'function') {
|
20189 |
|
20190 | return object.subset(index);
|
20191 | } else if (typeof object === 'string') {
|
20192 |
|
20193 | return subset(object, index);
|
20194 | } else if (_typeof(object) === 'object') {
|
20195 | if (!index.isObjectProperty()) {
|
20196 | throw new TypeError('Cannot apply a numeric index as object property');
|
20197 | }
|
20198 |
|
20199 | return getSafeProperty(object, index.getObjectProperty());
|
20200 | } else {
|
20201 | throw new TypeError('Cannot apply index: unsupported type of object');
|
20202 | }
|
20203 | } catch (err) {
|
20204 | throw errorTransform(err);
|
20205 | }
|
20206 | };
|
20207 | }
|
20208 |
|
20209 | exports.factory = factory;
|
20210 |
|
20211 | }),
|
20212 |
|
20213 | (function(module, exports, __webpack_require__) {
|
20214 |
|
20215 | "use strict";
|
20216 |
|
20217 |
|
20218 | var map = __webpack_require__(2).map;
|
20219 |
|
20220 | function factory(type, config, load, typed) {
|
20221 | var Node = load(__webpack_require__(16));
|
20222 | |
20223 |
|
20224 |
|
20225 |
|
20226 |
|
20227 |
|
20228 |
|
20229 | function ArrayNode(items) {
|
20230 | if (!(this instanceof ArrayNode)) {
|
20231 | throw new SyntaxError('Constructor must be called with the new operator');
|
20232 | }
|
20233 |
|
20234 | this.items = items || [];
|
20235 |
|
20236 | if (!Array.isArray(this.items) || !this.items.every(type.isNode)) {
|
20237 | throw new TypeError('Array containing Nodes expected');
|
20238 | }
|
20239 |
|
20240 |
|
20241 | var deprecated = function deprecated() {
|
20242 | throw new Error('Property `ArrayNode.nodes` is deprecated, use `ArrayNode.items` instead');
|
20243 | };
|
20244 |
|
20245 | Object.defineProperty(this, 'nodes', {
|
20246 | get: deprecated,
|
20247 | set: deprecated
|
20248 | });
|
20249 | }
|
20250 |
|
20251 | ArrayNode.prototype = new Node();
|
20252 | ArrayNode.prototype.type = 'ArrayNode';
|
20253 | ArrayNode.prototype.isArrayNode = true;
|
20254 | /**
|
20255 | * Compile a node into a JavaScript function.
|
20256 | * This basically pre-calculates as much as possible and only leaves open
|
20257 | * calculations which depend on a dynamic scope with variables.
|
20258 | * @param {Object} math Math.js namespace with functions and constants.
|
20259 | * @param {Object} argNames An object with argument names as key and `true`
|
20260 | * as value. Used in the SymbolNode to optimize
|
20261 | * for arguments from user assigned functions
|
20262 | * (see FunctionAssignmentNode) or special symbols
|
20263 | * like `end` (see IndexNode).
|
20264 | * @return {function} Returns a function which can be called like:
|
20265 | * evalNode(scope: Object, args: Object, context: *)
|
20266 | */
|
20267 |
|
20268 | ArrayNode.prototype._compile = function (math, argNames) {
|
20269 | var evalItems = map(this.items, function (item) {
|
20270 | return item._compile(math, argNames);
|
20271 | });
|
20272 | var asMatrix = math.config().matrix !== 'Array';
|
20273 |
|
20274 | if (asMatrix) {
|
20275 | var matrix = math.matrix;
|
20276 | return function evalArrayNode(scope, args, context) {
|
20277 | return matrix(map(evalItems, function (evalItem) {
|
20278 | return evalItem(scope, args, context);
|
20279 | }));
|
20280 | };
|
20281 | } else {
|
20282 | return function evalArrayNode(scope, args, context) {
|
20283 | return map(evalItems, function (evalItem) {
|
20284 | return evalItem(scope, args, context);
|
20285 | });
|
20286 | };
|
20287 | }
|
20288 | };
|
20289 | |
20290 |
|
20291 |
|
20292 |
|
20293 |
|
20294 |
|
20295 | ArrayNode.prototype.forEach = function (callback) {
|
20296 | for (var i = 0; i < this.items.length; i++) {
|
20297 | var node = this.items[i];
|
20298 | callback(node, 'items[' + i + ']', this);
|
20299 | }
|
20300 | };
|
20301 | |
20302 |
|
20303 |
|
20304 |
|
20305 |
|
20306 |
|
20307 |
|
20308 |
|
20309 | ArrayNode.prototype.map = function (callback) {
|
20310 | var items = [];
|
20311 |
|
20312 | for (var i = 0; i < this.items.length; i++) {
|
20313 | items[i] = this._ifNode(callback(this.items[i], 'items[' + i + ']', this));
|
20314 | }
|
20315 |
|
20316 | return new ArrayNode(items);
|
20317 | };
|
20318 | |
20319 |
|
20320 |
|
20321 |
|
20322 |
|
20323 |
|
20324 | ArrayNode.prototype.clone = function () {
|
20325 | return new ArrayNode(this.items.slice(0));
|
20326 | };
|
20327 | |
20328 |
|
20329 |
|
20330 |
|
20331 |
|
20332 |
|
20333 |
|
20334 |
|
20335 | ArrayNode.prototype._toString = function (options) {
|
20336 | var items = this.items.map(function (node) {
|
20337 | return node.toString(options);
|
20338 | });
|
20339 | return '[' + items.join(', ') + ']';
|
20340 | };
|
20341 | |
20342 |
|
20343 |
|
20344 |
|
20345 |
|
20346 |
|
20347 | ArrayNode.prototype.toJSON = function () {
|
20348 | return {
|
20349 | mathjs: 'ArrayNode',
|
20350 | items: this.items
|
20351 | };
|
20352 | };
|
20353 | |
20354 |
|
20355 |
|
20356 |
|
20357 |
|
20358 |
|
20359 |
|
20360 |
|
20361 |
|
20362 | ArrayNode.fromJSON = function (json) {
|
20363 | return new ArrayNode(json.items);
|
20364 | };
|
20365 | |
20366 |
|
20367 |
|
20368 |
|
20369 |
|
20370 |
|
20371 |
|
20372 |
|
20373 | ArrayNode.prototype.toHTML = function (options) {
|
20374 | var items = this.items.map(function (node) {
|
20375 | return node.toHTML(options);
|
20376 | });
|
20377 | return '<span class="math-parenthesis math-square-parenthesis">[</span>' + items.join('<span class="math-separator">,</span>') + '<span class="math-parenthesis math-square-parenthesis">]</span>';
|
20378 | };
|
20379 | |
20380 |
|
20381 |
|
20382 |
|
20383 |
|
20384 |
|
20385 |
|
20386 | ArrayNode.prototype._toTex = function (options) {
|
20387 | var s = '\\begin{bmatrix}';
|
20388 | this.items.forEach(function (node) {
|
20389 | if (node.items) {
|
20390 | s += node.items.map(function (childNode) {
|
20391 | return childNode.toTex(options);
|
20392 | }).join('&');
|
20393 | } else {
|
20394 | s += node.toTex(options);
|
20395 | }
|
20396 |
|
20397 |
|
20398 | s += '\\\\';
|
20399 | });
|
20400 | s += '\\end{bmatrix}';
|
20401 | return s;
|
20402 | };
|
20403 |
|
20404 | return ArrayNode;
|
20405 | }
|
20406 |
|
20407 | exports.name = 'ArrayNode';
|
20408 | exports.path = 'expression.node';
|
20409 | exports.factory = factory;
|
20410 |
|
20411 | }),
|
20412 |
|
20413 | (function(module, exports, __webpack_require__) {
|
20414 |
|
20415 | "use strict";
|
20416 |
|
20417 |
|
20418 | var getSafeProperty = __webpack_require__(13).getSafeProperty;
|
20419 |
|
20420 | var setSafeProperty = __webpack_require__(13).setSafeProperty;
|
20421 |
|
20422 | function factory(type, config, load, typed) {
|
20423 | var Node = load(__webpack_require__(16));
|
20424 | var assign = load(__webpack_require__(205));
|
20425 | var access = load(__webpack_require__(115));
|
20426 |
|
20427 | var operators = __webpack_require__(53);
|
20428 | |
20429 |
|
20430 |
|
20431 |
|
20432 |
|
20433 |
|
20434 |
|
20435 |
|
20436 |
|
20437 |
|
20438 |
|
20439 |
|
20440 |
|
20441 |
|
20442 |
|
20443 |
|
20444 |
|
20445 |
|
20446 |
|
20447 |
|
20448 |
|
20449 |
|
20450 |
|
20451 |
|
20452 |
|
20453 |
|
20454 |
|
20455 |
|
20456 | function AssignmentNode(object, index, value) {
|
20457 | if (!(this instanceof AssignmentNode)) {
|
20458 | throw new SyntaxError('Constructor must be called with the new operator');
|
20459 | }
|
20460 |
|
20461 | this.object = object;
|
20462 | this.index = value ? index : null;
|
20463 | this.value = value || index;
|
20464 |
|
20465 | if (!type.isSymbolNode(object) && !type.isAccessorNode(object)) {
|
20466 | throw new TypeError('SymbolNode or AccessorNode expected as "object"');
|
20467 | }
|
20468 |
|
20469 | if (type.isSymbolNode(object) && object.name === 'end') {
|
20470 | throw new Error('Cannot assign to symbol "end"');
|
20471 | }
|
20472 |
|
20473 | if (this.index && !type.isIndexNode(this.index)) {
|
20474 |
|
20475 | throw new TypeError('IndexNode expected as "index"');
|
20476 | }
|
20477 |
|
20478 | if (!type.isNode(this.value)) {
|
20479 | throw new TypeError('Node expected as "value"');
|
20480 | }
|
20481 |
|
20482 |
|
20483 | Object.defineProperty(this, 'name', {
|
20484 | get: function () {
|
20485 | if (this.index) {
|
20486 | return this.index.isObjectProperty() ? this.index.getObjectProperty() : '';
|
20487 | } else {
|
20488 | return this.object.name || '';
|
20489 | }
|
20490 | }.bind(this),
|
20491 | set: function set() {
|
20492 | throw new Error('Cannot assign a new name, name is read-only');
|
20493 | }
|
20494 | });
|
20495 | }
|
20496 |
|
20497 | AssignmentNode.prototype = new Node();
|
20498 | AssignmentNode.prototype.type = 'AssignmentNode';
|
20499 | AssignmentNode.prototype.isAssignmentNode = true;
|
20500 | |
20501 |
|
20502 |
|
20503 |
|
20504 |
|
20505 |
|
20506 |
|
20507 |
|
20508 |
|
20509 |
|
20510 |
|
20511 |
|
20512 |
|
20513 |
|
20514 | AssignmentNode.prototype._compile = function (math, argNames) {
|
20515 | var evalObject = this.object._compile(math, argNames);
|
20516 |
|
20517 | var evalIndex = this.index ? this.index._compile(math, argNames) : null;
|
20518 |
|
20519 | var evalValue = this.value._compile(math, argNames);
|
20520 |
|
20521 | var name = this.object.name;
|
20522 |
|
20523 | if (!this.index) {
|
20524 |
|
20525 | if (!type.isSymbolNode(this.object)) {
|
20526 | throw new TypeError('SymbolNode expected as object');
|
20527 | }
|
20528 |
|
20529 | return function evalAssignmentNode(scope, args, context) {
|
20530 | return setSafeProperty(scope, name, evalValue(scope, args, context));
|
20531 | };
|
20532 | } else if (this.index.isObjectProperty()) {
|
20533 |
|
20534 | var prop = this.index.getObjectProperty();
|
20535 | return function evalAssignmentNode(scope, args, context) {
|
20536 | var object = evalObject(scope, args, context);
|
20537 | var value = evalValue(scope, args, context);
|
20538 | return setSafeProperty(object, prop, value);
|
20539 | };
|
20540 | } else if (type.isSymbolNode(this.object)) {
|
20541 |
|
20542 | return function evalAssignmentNode(scope, args, context) {
|
20543 | var childObject = evalObject(scope, args, context);
|
20544 | var value = evalValue(scope, args, context);
|
20545 | var index = evalIndex(scope, args, childObject);
|
20546 |
|
20547 | setSafeProperty(scope, name, assign(childObject, index, value));
|
20548 | return value;
|
20549 | };
|
20550 | } else {
|
20551 |
|
20552 |
|
20553 |
|
20554 |
|
20555 |
|
20556 | var evalParentObject = this.object.object._compile(math, argNames);
|
20557 |
|
20558 | if (this.object.index.isObjectProperty()) {
|
20559 | var parentProp = this.object.index.getObjectProperty();
|
20560 | return function evalAssignmentNode(scope, args, context) {
|
20561 | var parent = evalParentObject(scope, args, context);
|
20562 | var childObject = getSafeProperty(parent, parentProp);
|
20563 | var index = evalIndex(scope, args, childObject);
|
20564 |
|
20565 | var value = evalValue(scope, args, context);
|
20566 | setSafeProperty(parent, parentProp, assign(childObject, index, value));
|
20567 | return value;
|
20568 | };
|
20569 | } else {
|
20570 |
|
20571 | var evalParentIndex = this.object.index._compile(math, argNames);
|
20572 |
|
20573 | return function evalAssignmentNode(scope, args, context) {
|
20574 | var parent = evalParentObject(scope, args, context);
|
20575 | var parentIndex = evalParentIndex(scope, args, parent);
|
20576 |
|
20577 | var childObject = access(parent, parentIndex);
|
20578 | var index = evalIndex(scope, args, childObject);
|
20579 |
|
20580 | var value = evalValue(scope, args, context);
|
20581 | assign(parent, parentIndex, assign(childObject, index, value));
|
20582 | return value;
|
20583 | };
|
20584 | }
|
20585 | }
|
20586 | };
|
20587 | |
20588 |
|
20589 |
|
20590 |
|
20591 |
|
20592 |
|
20593 | AssignmentNode.prototype.forEach = function (callback) {
|
20594 | callback(this.object, 'object', this);
|
20595 |
|
20596 | if (this.index) {
|
20597 | callback(this.index, 'index', this);
|
20598 | }
|
20599 |
|
20600 | callback(this.value, 'value', this);
|
20601 | };
|
20602 | |
20603 |
|
20604 |
|
20605 |
|
20606 |
|
20607 |
|
20608 |
|
20609 |
|
20610 | AssignmentNode.prototype.map = function (callback) {
|
20611 | var object = this._ifNode(callback(this.object, 'object', this));
|
20612 |
|
20613 | var index = this.index ? this._ifNode(callback(this.index, 'index', this)) : null;
|
20614 |
|
20615 | var value = this._ifNode(callback(this.value, 'value', this));
|
20616 |
|
20617 | return new AssignmentNode(object, index, value);
|
20618 | };
|
20619 | |
20620 |
|
20621 |
|
20622 |
|
20623 |
|
20624 |
|
20625 | AssignmentNode.prototype.clone = function () {
|
20626 | return new AssignmentNode(this.object, this.index, this.value);
|
20627 | };
|
20628 | |
20629 |
|
20630 |
|
20631 |
|
20632 |
|
20633 |
|
20634 |
|
20635 |
|
20636 | function needParenthesis(node, parenthesis) {
|
20637 | if (!parenthesis) {
|
20638 | parenthesis = 'keep';
|
20639 | }
|
20640 |
|
20641 | var precedence = operators.getPrecedence(node, parenthesis);
|
20642 | var exprPrecedence = operators.getPrecedence(node.value, parenthesis);
|
20643 | return parenthesis === 'all' || exprPrecedence !== null && exprPrecedence <= precedence;
|
20644 | }
|
20645 | |
20646 |
|
20647 |
|
20648 |
|
20649 |
|
20650 |
|
20651 |
|
20652 | AssignmentNode.prototype._toString = function (options) {
|
20653 | var object = this.object.toString(options);
|
20654 | var index = this.index ? this.index.toString(options) : '';
|
20655 | var value = this.value.toString(options);
|
20656 |
|
20657 | if (needParenthesis(this, options && options.parenthesis)) {
|
20658 | value = '(' + value + ')';
|
20659 | }
|
20660 |
|
20661 | return object + index + ' = ' + value;
|
20662 | };
|
20663 | |
20664 |
|
20665 |
|
20666 |
|
20667 |
|
20668 |
|
20669 | AssignmentNode.prototype.toJSON = function () {
|
20670 | return {
|
20671 | mathjs: 'AssignmentNode',
|
20672 | object: this.object,
|
20673 | index: this.index,
|
20674 | value: this.value
|
20675 | };
|
20676 | };
|
20677 | |
20678 |
|
20679 |
|
20680 |
|
20681 |
|
20682 |
|
20683 |
|
20684 |
|
20685 |
|
20686 | AssignmentNode.fromJSON = function (json) {
|
20687 | return new AssignmentNode(json.object, json.index, json.value);
|
20688 | };
|
20689 | |
20690 |
|
20691 |
|
20692 |
|
20693 |
|
20694 |
|
20695 |
|
20696 | AssignmentNode.prototype.toHTML = function (options) {
|
20697 | var object = this.object.toHTML(options);
|
20698 | var index = this.index ? this.index.toHTML(options) : '';
|
20699 | var value = this.value.toHTML(options);
|
20700 |
|
20701 | if (needParenthesis(this, options && options.parenthesis)) {
|
20702 | value = '<span class="math-paranthesis math-round-parenthesis">(</span>' + value + '<span class="math-paranthesis math-round-parenthesis">)</span>';
|
20703 | }
|
20704 |
|
20705 | return object + index + '<span class="math-operator math-assignment-operator math-variable-assignment-operator math-binary-operator">=</span>' + value;
|
20706 | };
|
20707 | |
20708 |
|
20709 |
|
20710 |
|
20711 |
|
20712 |
|
20713 |
|
20714 | AssignmentNode.prototype._toTex = function (options) {
|
20715 | var object = this.object.toTex(options);
|
20716 | var index = this.index ? this.index.toTex(options) : '';
|
20717 | var value = this.value.toTex(options);
|
20718 |
|
20719 | if (needParenthesis(this, options && options.parenthesis)) {
|
20720 | value = "\\left(".concat(value, "\\right)");
|
20721 | }
|
20722 |
|
20723 | return object + index + ':=' + value;
|
20724 | };
|
20725 |
|
20726 | return AssignmentNode;
|
20727 | }
|
20728 |
|
20729 | exports.name = 'AssignmentNode';
|
20730 | exports.path = 'expression.node';
|
20731 | exports.factory = factory;
|
20732 |
|
20733 | }),
|
20734 |
|
20735 | (function(module, exports, __webpack_require__) {
|
20736 |
|
20737 | "use strict";
|
20738 |
|
20739 |
|
20740 | var forEach = __webpack_require__(2).forEach;
|
20741 |
|
20742 | var map = __webpack_require__(2).map;
|
20743 |
|
20744 | function factory(type, config, load, typed) {
|
20745 | var Node = load(__webpack_require__(16));
|
20746 | var ResultSet = load(__webpack_require__(107));
|
20747 | |
20748 |
|
20749 |
|
20750 |
|
20751 |
|
20752 |
|
20753 |
|
20754 |
|
20755 |
|
20756 |
|
20757 | function BlockNode(blocks) {
|
20758 | if (!(this instanceof BlockNode)) {
|
20759 | throw new SyntaxError('Constructor must be called with the new operator');
|
20760 | }
|
20761 |
|
20762 |
|
20763 | if (!Array.isArray(blocks)) throw new Error('Array expected');
|
20764 | this.blocks = blocks.map(function (block) {
|
20765 | var node = block && block.node;
|
20766 | var visible = block && block.visible !== undefined ? block.visible : true;
|
20767 | if (!type.isNode(node)) throw new TypeError('Property "node" must be a Node');
|
20768 | if (typeof visible !== 'boolean') throw new TypeError('Property "visible" must be a boolean');
|
20769 | return {
|
20770 | node: node,
|
20771 | visible: visible
|
20772 | };
|
20773 | });
|
20774 | }
|
20775 |
|
20776 | BlockNode.prototype = new Node();
|
20777 | BlockNode.prototype.type = 'BlockNode';
|
20778 | BlockNode.prototype.isBlockNode = true;
|
20779 | |
20780 |
|
20781 |
|
20782 |
|
20783 |
|
20784 |
|
20785 |
|
20786 |
|
20787 |
|
20788 |
|
20789 |
|
20790 |
|
20791 |
|
20792 |
|
20793 | BlockNode.prototype._compile = function (math, argNames) {
|
20794 | var evalBlocks = map(this.blocks, function (block) {
|
20795 | return {
|
20796 | eval: block.node._compile(math, argNames),
|
20797 | visible: block.visible
|
20798 | };
|
20799 | });
|
20800 | return function evalBlockNodes(scope, args, context) {
|
20801 | var results = [];
|
20802 | forEach(evalBlocks, function evalBlockNode(block) {
|
20803 | var result = block.eval(scope, args, context);
|
20804 |
|
20805 | if (block.visible) {
|
20806 | results.push(result);
|
20807 | }
|
20808 | });
|
20809 | return new ResultSet(results);
|
20810 | };
|
20811 | };
|
20812 | |
20813 |
|
20814 |
|
20815 |
|
20816 |
|
20817 |
|
20818 | BlockNode.prototype.forEach = function (callback) {
|
20819 | for (var i = 0; i < this.blocks.length; i++) {
|
20820 | callback(this.blocks[i].node, 'blocks[' + i + '].node', this);
|
20821 | }
|
20822 | };
|
20823 | |
20824 |
|
20825 |
|
20826 |
|
20827 |
|
20828 |
|
20829 |
|
20830 |
|
20831 | BlockNode.prototype.map = function (callback) {
|
20832 | var blocks = [];
|
20833 |
|
20834 | for (var i = 0; i < this.blocks.length; i++) {
|
20835 | var block = this.blocks[i];
|
20836 |
|
20837 | var node = this._ifNode(callback(block.node, 'blocks[' + i + '].node', this));
|
20838 |
|
20839 | blocks[i] = {
|
20840 | node: node,
|
20841 | visible: block.visible
|
20842 | };
|
20843 | }
|
20844 |
|
20845 | return new BlockNode(blocks);
|
20846 | };
|
20847 | |
20848 |
|
20849 |
|
20850 |
|
20851 |
|
20852 |
|
20853 | BlockNode.prototype.clone = function () {
|
20854 | var blocks = this.blocks.map(function (block) {
|
20855 | return {
|
20856 | node: block.node,
|
20857 | visible: block.visible
|
20858 | };
|
20859 | });
|
20860 | return new BlockNode(blocks);
|
20861 | };
|
20862 | |
20863 |
|
20864 |
|
20865 |
|
20866 |
|
20867 |
|
20868 |
|
20869 |
|
20870 | BlockNode.prototype._toString = function (options) {
|
20871 | return this.blocks.map(function (param) {
|
20872 | return param.node.toString(options) + (param.visible ? '' : ';');
|
20873 | }).join('\n');
|
20874 | };
|
20875 | |
20876 |
|
20877 |
|
20878 |
|
20879 |
|
20880 |
|
20881 | BlockNode.prototype.toJSON = function () {
|
20882 | return {
|
20883 | mathjs: 'BlockNode',
|
20884 | blocks: this.blocks
|
20885 | };
|
20886 | };
|
20887 | |
20888 |
|
20889 |
|
20890 |
|
20891 |
|
20892 |
|
20893 |
|
20894 |
|
20895 |
|
20896 | BlockNode.fromJSON = function (json) {
|
20897 | return new BlockNode(json.blocks);
|
20898 | };
|
20899 | |
20900 |
|
20901 |
|
20902 |
|
20903 |
|
20904 |
|
20905 |
|
20906 |
|
20907 | BlockNode.prototype.toHTML = function (options) {
|
20908 | return this.blocks.map(function (param) {
|
20909 | return param.node.toHTML(options) + (param.visible ? '' : '<span class="math-separator">;</span>');
|
20910 | }).join('<span class="math-separator"><br /></span>');
|
20911 | };
|
20912 | |
20913 |
|
20914 |
|
20915 |
|
20916 |
|
20917 |
|
20918 |
|
20919 | BlockNode.prototype._toTex = function (options) {
|
20920 | return this.blocks.map(function (param) {
|
20921 | return param.node.toTex(options) + (param.visible ? '' : ';');
|
20922 | }).join('\\;\\;\n');
|
20923 | };
|
20924 |
|
20925 | return BlockNode;
|
20926 | }
|
20927 |
|
20928 | exports.name = 'BlockNode';
|
20929 | exports.path = 'expression.node';
|
20930 | exports.factory = factory;
|
20931 |
|
20932 | }),
|
20933 |
|
20934 | (function(module, exports, __webpack_require__) {
|
20935 |
|
20936 | "use strict";
|
20937 |
|
20938 |
|
20939 | var operators = __webpack_require__(53);
|
20940 |
|
20941 | function factory(type, config, load, typed) {
|
20942 | var Node = load(__webpack_require__(16));
|
20943 | var mathTypeOf = load(__webpack_require__(26));
|
20944 | |
20945 |
|
20946 |
|
20947 |
|
20948 |
|
20949 |
|
20950 |
|
20951 |
|
20952 |
|
20953 |
|
20954 |
|
20955 | function ConditionalNode(condition, trueExpr, falseExpr) {
|
20956 | if (!(this instanceof ConditionalNode)) {
|
20957 | throw new SyntaxError('Constructor must be called with the new operator');
|
20958 | }
|
20959 |
|
20960 | if (!type.isNode(condition)) throw new TypeError('Parameter condition must be a Node');
|
20961 | if (!type.isNode(trueExpr)) throw new TypeError('Parameter trueExpr must be a Node');
|
20962 | if (!type.isNode(falseExpr)) throw new TypeError('Parameter falseExpr must be a Node');
|
20963 | this.condition = condition;
|
20964 | this.trueExpr = trueExpr;
|
20965 | this.falseExpr = falseExpr;
|
20966 | }
|
20967 |
|
20968 | ConditionalNode.prototype = new Node();
|
20969 | ConditionalNode.prototype.type = 'ConditionalNode';
|
20970 | ConditionalNode.prototype.isConditionalNode = true;
|
20971 | |
20972 |
|
20973 |
|
20974 |
|
20975 |
|
20976 |
|
20977 |
|
20978 |
|
20979 |
|
20980 |
|
20981 |
|
20982 |
|
20983 |
|
20984 |
|
20985 | ConditionalNode.prototype._compile = function (math, argNames) {
|
20986 | var evalCondition = this.condition._compile(math, argNames);
|
20987 |
|
20988 | var evalTrueExpr = this.trueExpr._compile(math, argNames);
|
20989 |
|
20990 | var evalFalseExpr = this.falseExpr._compile(math, argNames);
|
20991 |
|
20992 | return function evalConditionalNode(scope, args, context) {
|
20993 | return testCondition(evalCondition(scope, args, context)) ? evalTrueExpr(scope, args, context) : evalFalseExpr(scope, args, context);
|
20994 | };
|
20995 | };
|
20996 | |
20997 |
|
20998 |
|
20999 |
|
21000 |
|
21001 |
|
21002 | ConditionalNode.prototype.forEach = function (callback) {
|
21003 | callback(this.condition, 'condition', this);
|
21004 | callback(this.trueExpr, 'trueExpr', this);
|
21005 | callback(this.falseExpr, 'falseExpr', this);
|
21006 | };
|
21007 | |
21008 |
|
21009 |
|
21010 |
|
21011 |
|
21012 |
|
21013 |
|
21014 |
|
21015 | ConditionalNode.prototype.map = function (callback) {
|
21016 | return new ConditionalNode(this._ifNode(callback(this.condition, 'condition', this)), this._ifNode(callback(this.trueExpr, 'trueExpr', this)), this._ifNode(callback(this.falseExpr, 'falseExpr', this)));
|
21017 | };
|
21018 | |
21019 |
|
21020 |
|
21021 |
|
21022 |
|
21023 |
|
21024 | ConditionalNode.prototype.clone = function () {
|
21025 | return new ConditionalNode(this.condition, this.trueExpr, this.falseExpr);
|
21026 | };
|
21027 | |
21028 |
|
21029 |
|
21030 |
|
21031 |
|
21032 |
|
21033 |
|
21034 | ConditionalNode.prototype._toString = function (options) {
|
21035 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
21036 | var precedence = operators.getPrecedence(this, parenthesis);
|
21037 |
|
21038 |
|
21039 |
|
21040 |
|
21041 | var condition = this.condition.toString(options);
|
21042 | var conditionPrecedence = operators.getPrecedence(this.condition, parenthesis);
|
21043 |
|
21044 | if (parenthesis === 'all' || this.condition.type === 'OperatorNode' || conditionPrecedence !== null && conditionPrecedence <= precedence) {
|
21045 | condition = '(' + condition + ')';
|
21046 | }
|
21047 |
|
21048 | var trueExpr = this.trueExpr.toString(options);
|
21049 | var truePrecedence = operators.getPrecedence(this.trueExpr, parenthesis);
|
21050 |
|
21051 | if (parenthesis === 'all' || this.trueExpr.type === 'OperatorNode' || truePrecedence !== null && truePrecedence <= precedence) {
|
21052 | trueExpr = '(' + trueExpr + ')';
|
21053 | }
|
21054 |
|
21055 | var falseExpr = this.falseExpr.toString(options);
|
21056 | var falsePrecedence = operators.getPrecedence(this.falseExpr, parenthesis);
|
21057 |
|
21058 | if (parenthesis === 'all' || this.falseExpr.type === 'OperatorNode' || falsePrecedence !== null && falsePrecedence <= precedence) {
|
21059 | falseExpr = '(' + falseExpr + ')';
|
21060 | }
|
21061 |
|
21062 | return condition + ' ? ' + trueExpr + ' : ' + falseExpr;
|
21063 | };
|
21064 | |
21065 |
|
21066 |
|
21067 |
|
21068 |
|
21069 |
|
21070 | ConditionalNode.prototype.toJSON = function () {
|
21071 | return {
|
21072 | mathjs: 'ConditionalNode',
|
21073 | condition: this.condition,
|
21074 | trueExpr: this.trueExpr,
|
21075 | falseExpr: this.falseExpr
|
21076 | };
|
21077 | };
|
21078 | |
21079 |
|
21080 |
|
21081 |
|
21082 |
|
21083 |
|
21084 |
|
21085 |
|
21086 |
|
21087 | ConditionalNode.fromJSON = function (json) {
|
21088 | return new ConditionalNode(json.condition, json.trueExpr, json.falseExpr);
|
21089 | };
|
21090 | |
21091 |
|
21092 |
|
21093 |
|
21094 |
|
21095 |
|
21096 |
|
21097 | ConditionalNode.prototype.toHTML = function (options) {
|
21098 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
21099 | var precedence = operators.getPrecedence(this, parenthesis);
|
21100 |
|
21101 |
|
21102 |
|
21103 |
|
21104 | var condition = this.condition.toHTML(options);
|
21105 | var conditionPrecedence = operators.getPrecedence(this.condition, parenthesis);
|
21106 |
|
21107 | if (parenthesis === 'all' || this.condition.type === 'OperatorNode' || conditionPrecedence !== null && conditionPrecedence <= precedence) {
|
21108 | condition = '<span class="math-parenthesis math-round-parenthesis">(</span>' + condition + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
21109 | }
|
21110 |
|
21111 | var trueExpr = this.trueExpr.toHTML(options);
|
21112 | var truePrecedence = operators.getPrecedence(this.trueExpr, parenthesis);
|
21113 |
|
21114 | if (parenthesis === 'all' || this.trueExpr.type === 'OperatorNode' || truePrecedence !== null && truePrecedence <= precedence) {
|
21115 | trueExpr = '<span class="math-parenthesis math-round-parenthesis">(</span>' + trueExpr + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
21116 | }
|
21117 |
|
21118 | var falseExpr = this.falseExpr.toHTML(options);
|
21119 | var falsePrecedence = operators.getPrecedence(this.falseExpr, parenthesis);
|
21120 |
|
21121 | if (parenthesis === 'all' || this.falseExpr.type === 'OperatorNode' || falsePrecedence !== null && falsePrecedence <= precedence) {
|
21122 | falseExpr = '<span class="math-parenthesis math-round-parenthesis">(</span>' + falseExpr + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
21123 | }
|
21124 |
|
21125 | return condition + '<span class="math-operator math-conditional-operator">?</span>' + trueExpr + '<span class="math-operator math-conditional-operator">:</span>' + falseExpr;
|
21126 | };
|
21127 | |
21128 |
|
21129 |
|
21130 |
|
21131 |
|
21132 |
|
21133 |
|
21134 | ConditionalNode.prototype._toTex = function (options) {
|
21135 | return '\\begin{cases} {' + this.trueExpr.toTex(options) + '}, &\\quad{\\text{if }\\;' + this.condition.toTex(options) + '}\\\\{' + this.falseExpr.toTex(options) + '}, &\\quad{\\text{otherwise}}\\end{cases}';
|
21136 | };
|
21137 | |
21138 |
|
21139 |
|
21140 |
|
21141 |
|
21142 |
|
21143 |
|
21144 | function testCondition(condition) {
|
21145 | if (typeof condition === 'number' || typeof condition === 'boolean' || typeof condition === 'string') {
|
21146 | return !!condition;
|
21147 | }
|
21148 |
|
21149 | if (condition) {
|
21150 | if (type.isBigNumber(condition)) {
|
21151 | return !condition.isZero();
|
21152 | }
|
21153 |
|
21154 | if (type.isComplex(condition)) {
|
21155 | return !!(condition.re || condition.im);
|
21156 | }
|
21157 |
|
21158 | if (type.isUnit(condition)) {
|
21159 | return !!condition.value;
|
21160 | }
|
21161 | }
|
21162 |
|
21163 | if (condition === null || condition === undefined) {
|
21164 | return false;
|
21165 | }
|
21166 |
|
21167 | throw new TypeError('Unsupported type of condition "' + mathTypeOf(condition) + '"');
|
21168 | }
|
21169 |
|
21170 | return ConditionalNode;
|
21171 | }
|
21172 |
|
21173 | exports.name = 'ConditionalNode';
|
21174 | exports.path = 'expression.node';
|
21175 | exports.factory = factory;
|
21176 |
|
21177 | }),
|
21178 |
|
21179 | (function(module, exports, __webpack_require__) {
|
21180 |
|
21181 | "use strict";
|
21182 |
|
21183 |
|
21184 | var keywords = __webpack_require__(114);
|
21185 |
|
21186 | var escape = __webpack_require__(9).escape;
|
21187 |
|
21188 | var forEach = __webpack_require__(2).forEach;
|
21189 |
|
21190 | var join = __webpack_require__(2).join;
|
21191 |
|
21192 | var latex = __webpack_require__(4);
|
21193 |
|
21194 | var operators = __webpack_require__(53);
|
21195 |
|
21196 | var setSafeProperty = __webpack_require__(13).setSafeProperty;
|
21197 |
|
21198 | function factory(type, config, load, typed) {
|
21199 | var Node = load(__webpack_require__(16));
|
21200 | |
21201 |
|
21202 |
|
21203 |
|
21204 |
|
21205 |
|
21206 |
|
21207 |
|
21208 |
|
21209 |
|
21210 |
|
21211 |
|
21212 |
|
21213 | function FunctionAssignmentNode(name, params, expr) {
|
21214 | if (!(this instanceof FunctionAssignmentNode)) {
|
21215 | throw new SyntaxError('Constructor must be called with the new operator');
|
21216 | }
|
21217 |
|
21218 |
|
21219 | if (typeof name !== 'string') throw new TypeError('String expected for parameter "name"');
|
21220 | if (!Array.isArray(params)) throw new TypeError('Array containing strings or objects expected for parameter "params"');
|
21221 | if (!type.isNode(expr)) throw new TypeError('Node expected for parameter "expr"');
|
21222 | if (name in keywords) throw new Error('Illegal function name, "' + name + '" is a reserved keyword');
|
21223 | this.name = name;
|
21224 | this.params = params.map(function (param) {
|
21225 | return param && param.name || param;
|
21226 | });
|
21227 | this.types = params.map(function (param) {
|
21228 | return param && param.type || 'any';
|
21229 | });
|
21230 | this.expr = expr;
|
21231 | }
|
21232 |
|
21233 | FunctionAssignmentNode.prototype = new Node();
|
21234 | FunctionAssignmentNode.prototype.type = 'FunctionAssignmentNode';
|
21235 | FunctionAssignmentNode.prototype.isFunctionAssignmentNode = true;
|
21236 | |
21237 |
|
21238 |
|
21239 |
|
21240 |
|
21241 |
|
21242 |
|
21243 |
|
21244 |
|
21245 |
|
21246 |
|
21247 |
|
21248 |
|
21249 |
|
21250 | FunctionAssignmentNode.prototype._compile = function (math, argNames) {
|
21251 | var childArgNames = Object.create(argNames);
|
21252 | forEach(this.params, function (param) {
|
21253 | childArgNames[param] = true;
|
21254 | });
|
21255 |
|
21256 | var evalExpr = this.expr._compile(math, childArgNames);
|
21257 |
|
21258 | var name = this.name;
|
21259 | var params = this.params;
|
21260 | var signature = join(this.types, ',');
|
21261 | var syntax = name + '(' + join(this.params, ', ') + ')';
|
21262 | return function evalFunctionAssignmentNode(scope, args, context) {
|
21263 | var signatures = {};
|
21264 |
|
21265 | signatures[signature] = function () {
|
21266 | var childArgs = Object.create(args);
|
21267 |
|
21268 | for (var i = 0; i < params.length; i++) {
|
21269 | childArgs[params[i]] = arguments[i];
|
21270 | }
|
21271 |
|
21272 | return evalExpr(scope, childArgs, context);
|
21273 | };
|
21274 |
|
21275 | var fn = typed(name, signatures);
|
21276 | fn.syntax = syntax;
|
21277 | setSafeProperty(scope, name, fn);
|
21278 | return fn;
|
21279 | };
|
21280 | };
|
21281 | |
21282 |
|
21283 |
|
21284 |
|
21285 |
|
21286 |
|
21287 | FunctionAssignmentNode.prototype.forEach = function (callback) {
|
21288 | callback(this.expr, 'expr', this);
|
21289 | };
|
21290 | |
21291 |
|
21292 |
|
21293 |
|
21294 |
|
21295 |
|
21296 |
|
21297 |
|
21298 | FunctionAssignmentNode.prototype.map = function (callback) {
|
21299 | var expr = this._ifNode(callback(this.expr, 'expr', this));
|
21300 |
|
21301 | return new FunctionAssignmentNode(this.name, this.params.slice(0), expr);
|
21302 | };
|
21303 | |
21304 |
|
21305 |
|
21306 |
|
21307 |
|
21308 |
|
21309 | FunctionAssignmentNode.prototype.clone = function () {
|
21310 | return new FunctionAssignmentNode(this.name, this.params.slice(0), this.expr);
|
21311 | };
|
21312 | |
21313 |
|
21314 |
|
21315 |
|
21316 |
|
21317 |
|
21318 |
|
21319 |
|
21320 | function needParenthesis(node, parenthesis) {
|
21321 | var precedence = operators.getPrecedence(node, parenthesis);
|
21322 | var exprPrecedence = operators.getPrecedence(node.expr, parenthesis);
|
21323 | return parenthesis === 'all' || exprPrecedence !== null && exprPrecedence <= precedence;
|
21324 | }
|
21325 | |
21326 |
|
21327 |
|
21328 |
|
21329 |
|
21330 |
|
21331 |
|
21332 | FunctionAssignmentNode.prototype._toString = function (options) {
|
21333 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
21334 | var expr = this.expr.toString(options);
|
21335 |
|
21336 | if (needParenthesis(this, parenthesis)) {
|
21337 | expr = '(' + expr + ')';
|
21338 | }
|
21339 |
|
21340 | return this.name + '(' + this.params.join(', ') + ') = ' + expr;
|
21341 | };
|
21342 | |
21343 |
|
21344 |
|
21345 |
|
21346 |
|
21347 |
|
21348 | FunctionAssignmentNode.prototype.toJSON = function () {
|
21349 | var types = this.types;
|
21350 | return {
|
21351 | mathjs: 'FunctionAssignmentNode',
|
21352 | name: this.name,
|
21353 | params: this.params.map(function (param, index) {
|
21354 | return {
|
21355 | name: param,
|
21356 | type: types[index]
|
21357 | };
|
21358 | }),
|
21359 | expr: this.expr
|
21360 | };
|
21361 | };
|
21362 | |
21363 |
|
21364 |
|
21365 |
|
21366 |
|
21367 |
|
21368 |
|
21369 |
|
21370 |
|
21371 | FunctionAssignmentNode.fromJSON = function (json) {
|
21372 | return new FunctionAssignmentNode(json.name, json.params, json.expr);
|
21373 | };
|
21374 | |
21375 |
|
21376 |
|
21377 |
|
21378 |
|
21379 |
|
21380 |
|
21381 | FunctionAssignmentNode.prototype.toHTML = function (options) {
|
21382 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
21383 | var params = [];
|
21384 |
|
21385 | for (var i = 0; i < this.params.length; i++) {
|
21386 | params.push('<span class="math-symbol math-parameter">' + escape(this.params[i]) + '</span>');
|
21387 | }
|
21388 |
|
21389 | var expr = this.expr.toHTML(options);
|
21390 |
|
21391 | if (needParenthesis(this, parenthesis)) {
|
21392 | expr = '<span class="math-parenthesis math-round-parenthesis">(</span>' + expr + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
21393 | }
|
21394 |
|
21395 | return '<span class="math-function">' + escape(this.name) + '</span>' + '<span class="math-parenthesis math-round-parenthesis">(</span>' + params.join('<span class="math-separator">,</span>') + '<span class="math-parenthesis math-round-parenthesis">)</span><span class="math-operator math-assignment-operator math-variable-assignment-operator math-binary-operator">=</span>' + expr;
|
21396 | };
|
21397 | |
21398 |
|
21399 |
|
21400 |
|
21401 |
|
21402 |
|
21403 |
|
21404 | FunctionAssignmentNode.prototype._toTex = function (options) {
|
21405 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
21406 | var expr = this.expr.toTex(options);
|
21407 |
|
21408 | if (needParenthesis(this, parenthesis)) {
|
21409 | expr = "\\left(".concat(expr, "\\right)");
|
21410 | }
|
21411 |
|
21412 | return '\\mathrm{' + this.name + '}\\left(' + this.params.map(latex.toSymbol).join(',') + '\\right):=' + expr;
|
21413 | };
|
21414 |
|
21415 | return FunctionAssignmentNode;
|
21416 | }
|
21417 |
|
21418 | exports.name = 'FunctionAssignmentNode';
|
21419 | exports.path = 'expression.node';
|
21420 | exports.factory = factory;
|
21421 |
|
21422 | }),
|
21423 |
|
21424 | (function(module, exports, __webpack_require__) {
|
21425 |
|
21426 | "use strict";
|
21427 |
|
21428 |
|
21429 | var map = __webpack_require__(2).map;
|
21430 |
|
21431 | var escape = __webpack_require__(9).escape;
|
21432 |
|
21433 | function factory(type, config, load, typed) {
|
21434 | var Node = load(__webpack_require__(16));
|
21435 | var Range = load(__webpack_require__(106));
|
21436 | var isArray = Array.isArray;
|
21437 | |
21438 |
|
21439 |
|
21440 |
|
21441 |
|
21442 |
|
21443 |
|
21444 |
|
21445 |
|
21446 |
|
21447 |
|
21448 |
|
21449 |
|
21450 |
|
21451 |
|
21452 |
|
21453 | function IndexNode(dimensions, dotNotation) {
|
21454 | if (!(this instanceof IndexNode)) {
|
21455 | throw new SyntaxError('Constructor must be called with the new operator');
|
21456 | }
|
21457 |
|
21458 | this.dimensions = dimensions;
|
21459 | this.dotNotation = dotNotation || false;
|
21460 |
|
21461 | if (!isArray(dimensions) || !dimensions.every(type.isNode)) {
|
21462 | throw new TypeError('Array containing Nodes expected for parameter "dimensions"');
|
21463 | }
|
21464 |
|
21465 | if (this.dotNotation && !this.isObjectProperty()) {
|
21466 | throw new Error('dotNotation only applicable for object properties');
|
21467 | }
|
21468 |
|
21469 |
|
21470 | var deprecated = function deprecated() {
|
21471 | throw new Error('Property `IndexNode.object` is deprecated, use `IndexNode.fn` instead');
|
21472 | };
|
21473 |
|
21474 | Object.defineProperty(this, 'object', {
|
21475 | get: deprecated,
|
21476 | set: deprecated
|
21477 | });
|
21478 | }
|
21479 |
|
21480 | IndexNode.prototype = new Node();
|
21481 | IndexNode.prototype.type = 'IndexNode';
|
21482 | IndexNode.prototype.isIndexNode = true;
|
21483 | /**
|
21484 | * Compile a node into a JavaScript function.
|
21485 | * This basically pre-calculates as much as possible and only leaves open
|
21486 | * calculations which depend on a dynamic scope with variables.
|
21487 | * @param {Object} math Math.js namespace with functions and constants.
|
21488 | * @param {Object} argNames An object with argument names as key and `true`
|
21489 | * as value. Used in the SymbolNode to optimize
|
21490 | * for arguments from user assigned functions
|
21491 | * (see FunctionAssignmentNode) or special symbols
|
21492 | * like `end` (see IndexNode).
|
21493 | * @return {function} Returns a function which can be called like:
|
21494 | * evalNode(scope: Object, args: Object, context: *)
|
21495 | */
|
21496 |
|
21497 | IndexNode.prototype._compile = function (math, argNames) {
|
21498 |
|
21499 |
|
21500 |
|
21501 |
|
21502 |
|
21503 | var evalDimensions = map(this.dimensions, function (range, i) {
|
21504 | if (type.isRangeNode(range)) {
|
21505 | if (range.needsEnd()) {
|
21506 |
|
21507 | var childArgNames = Object.create(argNames);
|
21508 | childArgNames['end'] = true;
|
21509 |
|
21510 | var evalStart = range.start._compile(math, childArgNames);
|
21511 |
|
21512 | var evalEnd = range.end._compile(math, childArgNames);
|
21513 |
|
21514 | var evalStep = range.step ? range.step._compile(math, childArgNames) : function () {
|
21515 | return 1;
|
21516 | };
|
21517 | return function evalDimension(scope, args, context) {
|
21518 | var size = math.size(context).valueOf();
|
21519 | var childArgs = Object.create(args);
|
21520 | childArgs['end'] = size[i];
|
21521 | return createRange(evalStart(scope, childArgs, context), evalEnd(scope, childArgs, context), evalStep(scope, childArgs, context));
|
21522 | };
|
21523 | } else {
|
21524 |
|
21525 | var _evalStart = range.start._compile(math, argNames);
|
21526 |
|
21527 | var _evalEnd = range.end._compile(math, argNames);
|
21528 |
|
21529 | var _evalStep = range.step ? range.step._compile(math, argNames) : function () {
|
21530 | return 1;
|
21531 | };
|
21532 |
|
21533 | return function evalDimension(scope, args, context) {
|
21534 | return createRange(_evalStart(scope, args, context), _evalEnd(scope, args, context), _evalStep(scope, args, context));
|
21535 | };
|
21536 | }
|
21537 | } else if (type.isSymbolNode(range) && range.name === 'end') {
|
21538 |
|
21539 | var _childArgNames = Object.create(argNames);
|
21540 |
|
21541 | _childArgNames['end'] = true;
|
21542 |
|
21543 | var evalRange = range._compile(math, _childArgNames);
|
21544 |
|
21545 | return function evalDimension(scope, args, context) {
|
21546 | var size = math.size(context).valueOf();
|
21547 | var childArgs = Object.create(args);
|
21548 | childArgs['end'] = size[i];
|
21549 | return evalRange(scope, childArgs, context);
|
21550 | };
|
21551 | } else {
|
21552 |
|
21553 | var _evalRange = range._compile(math, argNames);
|
21554 |
|
21555 | return function evalDimension(scope, args, context) {
|
21556 | return _evalRange(scope, args, context);
|
21557 | };
|
21558 | }
|
21559 | });
|
21560 | return function evalIndexNode(scope, args, context) {
|
21561 | var dimensions = map(evalDimensions, function (evalDimension) {
|
21562 | return evalDimension(scope, args, context);
|
21563 | });
|
21564 | return math.index.apply(math, dimensions);
|
21565 | };
|
21566 | };
|
21567 | |
21568 |
|
21569 |
|
21570 |
|
21571 |
|
21572 |
|
21573 | IndexNode.prototype.forEach = function (callback) {
|
21574 | for (var i = 0; i < this.dimensions.length; i++) {
|
21575 | callback(this.dimensions[i], 'dimensions[' + i + ']', this);
|
21576 | }
|
21577 | };
|
21578 | |
21579 |
|
21580 |
|
21581 |
|
21582 |
|
21583 |
|
21584 |
|
21585 |
|
21586 | IndexNode.prototype.map = function (callback) {
|
21587 | var dimensions = [];
|
21588 |
|
21589 | for (var i = 0; i < this.dimensions.length; i++) {
|
21590 | dimensions[i] = this._ifNode(callback(this.dimensions[i], 'dimensions[' + i + ']', this));
|
21591 | }
|
21592 |
|
21593 | return new IndexNode(dimensions);
|
21594 | };
|
21595 | |
21596 |
|
21597 |
|
21598 |
|
21599 |
|
21600 |
|
21601 | IndexNode.prototype.clone = function () {
|
21602 | return new IndexNode(this.dimensions.slice(0));
|
21603 | };
|
21604 | |
21605 |
|
21606 |
|
21607 |
|
21608 |
|
21609 |
|
21610 | IndexNode.prototype.isObjectProperty = function () {
|
21611 | return this.dimensions.length === 1 && type.isConstantNode(this.dimensions[0]) && typeof this.dimensions[0].value === 'string';
|
21612 | };
|
21613 | |
21614 |
|
21615 |
|
21616 |
|
21617 |
|
21618 |
|
21619 |
|
21620 | IndexNode.prototype.getObjectProperty = function () {
|
21621 | return this.isObjectProperty() ? this.dimensions[0].value : null;
|
21622 | };
|
21623 | |
21624 |
|
21625 |
|
21626 |
|
21627 |
|
21628 |
|
21629 |
|
21630 | IndexNode.prototype._toString = function (options) {
|
21631 |
|
21632 | return this.dotNotation ? '.' + this.getObjectProperty() : '[' + this.dimensions.join(', ') + ']';
|
21633 | };
|
21634 | |
21635 |
|
21636 |
|
21637 |
|
21638 |
|
21639 |
|
21640 | IndexNode.prototype.toJSON = function () {
|
21641 | return {
|
21642 | mathjs: 'IndexNode',
|
21643 | dimensions: this.dimensions,
|
21644 | dotNotation: this.dotNotation
|
21645 | };
|
21646 | };
|
21647 | |
21648 |
|
21649 |
|
21650 |
|
21651 |
|
21652 |
|
21653 |
|
21654 |
|
21655 |
|
21656 | IndexNode.fromJSON = function (json) {
|
21657 | return new IndexNode(json.dimensions, json.dotNotation);
|
21658 | };
|
21659 | |
21660 |
|
21661 |
|
21662 |
|
21663 |
|
21664 |
|
21665 |
|
21666 | IndexNode.prototype.toHTML = function (options) {
|
21667 |
|
21668 | var dimensions = [];
|
21669 |
|
21670 | for (var i = 0; i < this.dimensions.length; i++) {
|
21671 | dimensions[i] = this.dimensions[i].toHTML();
|
21672 | }
|
21673 |
|
21674 | if (this.dotNotation) {
|
21675 | return '<span class="math-operator math-accessor-operator">.</span>' + '<span class="math-symbol math-property">' + escape(this.getObjectProperty()) + '</span>';
|
21676 | } else {
|
21677 | return '<span class="math-parenthesis math-square-parenthesis">[</span>' + dimensions.join('<span class="math-separator">,</span>') + '<span class="math-parenthesis math-square-parenthesis">]</span>';
|
21678 | }
|
21679 | };
|
21680 | |
21681 |
|
21682 |
|
21683 |
|
21684 |
|
21685 |
|
21686 |
|
21687 | IndexNode.prototype._toTex = function (options) {
|
21688 | var dimensions = this.dimensions.map(function (range) {
|
21689 | return range.toTex(options);
|
21690 | });
|
21691 | return this.dotNotation ? '.' + this.getObjectProperty() + '' : '_{' + dimensions.join(',') + '}';
|
21692 | };
|
21693 |
|
21694 |
|
21695 | function createRange(start, end, step) {
|
21696 | return new Range(type.isBigNumber(start) ? start.toNumber() : start, type.isBigNumber(end) ? end.toNumber() : end, type.isBigNumber(step) ? step.toNumber() : step);
|
21697 | }
|
21698 |
|
21699 | return IndexNode;
|
21700 | }
|
21701 |
|
21702 | exports.name = 'IndexNode';
|
21703 | exports.path = 'expression.node';
|
21704 | exports.factory = factory;
|
21705 |
|
21706 | }),
|
21707 |
|
21708 | (function(module, exports, __webpack_require__) {
|
21709 |
|
21710 | "use strict";
|
21711 |
|
21712 |
|
21713 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
21714 |
|
21715 | var stringify = __webpack_require__(9).stringify;
|
21716 |
|
21717 | var escape = __webpack_require__(9).escape;
|
21718 |
|
21719 | var isSafeProperty = __webpack_require__(13).isSafeProperty;
|
21720 |
|
21721 | var hasOwnProperty = __webpack_require__(5).hasOwnProperty;
|
21722 |
|
21723 | function factory(type, config, load, typed) {
|
21724 | var Node = load(__webpack_require__(16));
|
21725 | |
21726 |
|
21727 |
|
21728 |
|
21729 |
|
21730 |
|
21731 |
|
21732 | function ObjectNode(properties) {
|
21733 | if (!(this instanceof ObjectNode)) {
|
21734 | throw new SyntaxError('Constructor must be called with the new operator');
|
21735 | }
|
21736 |
|
21737 | this.properties = properties || {};
|
21738 |
|
21739 | if (properties) {
|
21740 | if (!(_typeof(properties) === 'object') || !Object.keys(properties).every(function (key) {
|
21741 | return type.isNode(properties[key]);
|
21742 | })) {
|
21743 | throw new TypeError('Object containing Nodes expected');
|
21744 | }
|
21745 | }
|
21746 | }
|
21747 |
|
21748 | ObjectNode.prototype = new Node();
|
21749 | ObjectNode.prototype.type = 'ObjectNode';
|
21750 | ObjectNode.prototype.isObjectNode = true;
|
21751 | |
21752 |
|
21753 |
|
21754 |
|
21755 |
|
21756 |
|
21757 |
|
21758 |
|
21759 |
|
21760 |
|
21761 |
|
21762 |
|
21763 |
|
21764 |
|
21765 | ObjectNode.prototype._compile = function (math, argNames) {
|
21766 | var evalEntries = {};
|
21767 |
|
21768 | for (var key in this.properties) {
|
21769 | if (hasOwnProperty(this.properties, key)) {
|
21770 |
|
21771 |
|
21772 | var stringifiedKey = stringify(key);
|
21773 | var parsedKey = JSON.parse(stringifiedKey);
|
21774 |
|
21775 | if (!isSafeProperty(this.properties, parsedKey)) {
|
21776 | throw new Error('No access to property "' + parsedKey + '"');
|
21777 | }
|
21778 |
|
21779 | evalEntries[parsedKey] = this.properties[key]._compile(math, argNames);
|
21780 | }
|
21781 | }
|
21782 |
|
21783 | return function evalObjectNode(scope, args, context) {
|
21784 | var obj = {};
|
21785 |
|
21786 | for (var _key in evalEntries) {
|
21787 | if (hasOwnProperty(evalEntries, _key)) {
|
21788 | obj[_key] = evalEntries[_key](scope, args, context);
|
21789 | }
|
21790 | }
|
21791 |
|
21792 | return obj;
|
21793 | };
|
21794 | };
|
21795 | |
21796 |
|
21797 |
|
21798 |
|
21799 |
|
21800 |
|
21801 | ObjectNode.prototype.forEach = function (callback) {
|
21802 | for (var key in this.properties) {
|
21803 | if (this.properties.hasOwnProperty(key)) {
|
21804 | callback(this.properties[key], 'properties[' + stringify(key) + ']', this);
|
21805 | }
|
21806 | }
|
21807 | };
|
21808 | |
21809 |
|
21810 |
|
21811 |
|
21812 |
|
21813 |
|
21814 |
|
21815 |
|
21816 | ObjectNode.prototype.map = function (callback) {
|
21817 | var properties = {};
|
21818 |
|
21819 | for (var key in this.properties) {
|
21820 | if (this.properties.hasOwnProperty(key)) {
|
21821 | properties[key] = this._ifNode(callback(this.properties[key], 'properties[' + stringify(key) + ']', this));
|
21822 | }
|
21823 | }
|
21824 |
|
21825 | return new ObjectNode(properties);
|
21826 | };
|
21827 | |
21828 |
|
21829 |
|
21830 |
|
21831 |
|
21832 |
|
21833 | ObjectNode.prototype.clone = function () {
|
21834 | var properties = {};
|
21835 |
|
21836 | for (var key in this.properties) {
|
21837 | if (this.properties.hasOwnProperty(key)) {
|
21838 | properties[key] = this.properties[key];
|
21839 | }
|
21840 | }
|
21841 |
|
21842 | return new ObjectNode(properties);
|
21843 | };
|
21844 | |
21845 |
|
21846 |
|
21847 |
|
21848 |
|
21849 |
|
21850 |
|
21851 |
|
21852 | ObjectNode.prototype._toString = function (options) {
|
21853 | var entries = [];
|
21854 |
|
21855 | for (var key in this.properties) {
|
21856 | if (this.properties.hasOwnProperty(key)) {
|
21857 | entries.push(stringify(key) + ': ' + this.properties[key].toString(options));
|
21858 | }
|
21859 | }
|
21860 |
|
21861 | return '{' + entries.join(', ') + '}';
|
21862 | };
|
21863 | |
21864 |
|
21865 |
|
21866 |
|
21867 |
|
21868 |
|
21869 | ObjectNode.prototype.toJSON = function () {
|
21870 | return {
|
21871 | mathjs: 'ObjectNode',
|
21872 | properties: this.properties
|
21873 | };
|
21874 | };
|
21875 | |
21876 |
|
21877 |
|
21878 |
|
21879 |
|
21880 |
|
21881 |
|
21882 |
|
21883 |
|
21884 | ObjectNode.fromJSON = function (json) {
|
21885 | return new ObjectNode(json.properties);
|
21886 | };
|
21887 | |
21888 |
|
21889 |
|
21890 |
|
21891 |
|
21892 |
|
21893 |
|
21894 |
|
21895 | ObjectNode.prototype.toHTML = function (options) {
|
21896 | var entries = [];
|
21897 |
|
21898 | for (var key in this.properties) {
|
21899 | if (this.properties.hasOwnProperty(key)) {
|
21900 | entries.push('<span class="math-symbol math-property">' + escape(key) + '</span>' + '<span class="math-operator math-assignment-operator math-property-assignment-operator math-binary-operator">:</span>' + this.properties[key].toHTML(options));
|
21901 | }
|
21902 | }
|
21903 |
|
21904 | return '<span class="math-parenthesis math-curly-parenthesis">{</span>' + entries.join('<span class="math-separator">,</span>') + '<span class="math-parenthesis math-curly-parenthesis">}</span>';
|
21905 | };
|
21906 | |
21907 |
|
21908 |
|
21909 |
|
21910 |
|
21911 |
|
21912 |
|
21913 | ObjectNode.prototype._toTex = function (options) {
|
21914 | var entries = [];
|
21915 |
|
21916 | for (var key in this.properties) {
|
21917 | if (this.properties.hasOwnProperty(key)) {
|
21918 | entries.push('\\mathbf{' + key + ':} & ' + this.properties[key].toTex(options) + '\\\\');
|
21919 | }
|
21920 | }
|
21921 |
|
21922 | return "\\left\\{\\begin{array}{ll}".concat(entries.join('\n'), "\\end{array}\\right\\}");
|
21923 | };
|
21924 |
|
21925 | return ObjectNode;
|
21926 | }
|
21927 |
|
21928 | exports.name = 'ObjectNode';
|
21929 | exports.path = 'expression.node';
|
21930 | exports.factory = factory;
|
21931 |
|
21932 | }),
|
21933 |
|
21934 | (function(module, exports, __webpack_require__) {
|
21935 |
|
21936 | "use strict";
|
21937 |
|
21938 |
|
21939 | var operators = __webpack_require__(53);
|
21940 |
|
21941 | function factory(type, config, load, typed) {
|
21942 | var Node = load(__webpack_require__(16));
|
21943 | |
21944 |
|
21945 |
|
21946 |
|
21947 |
|
21948 |
|
21949 |
|
21950 |
|
21951 |
|
21952 | function RangeNode(start, end, step) {
|
21953 | if (!(this instanceof RangeNode)) {
|
21954 | throw new SyntaxError('Constructor must be called with the new operator');
|
21955 | }
|
21956 |
|
21957 |
|
21958 | if (!type.isNode(start)) throw new TypeError('Node expected');
|
21959 | if (!type.isNode(end)) throw new TypeError('Node expected');
|
21960 | if (step && !type.isNode(step)) throw new TypeError('Node expected');
|
21961 | if (arguments.length > 3) throw new Error('Too many arguments');
|
21962 | this.start = start;
|
21963 |
|
21964 | this.end = end;
|
21965 |
|
21966 | this.step = step || null;
|
21967 | }
|
21968 |
|
21969 | RangeNode.prototype = new Node();
|
21970 | RangeNode.prototype.type = 'RangeNode';
|
21971 | RangeNode.prototype.isRangeNode = true;
|
21972 | |
21973 |
|
21974 |
|
21975 |
|
21976 |
|
21977 |
|
21978 | RangeNode.prototype.needsEnd = function () {
|
21979 |
|
21980 | var endSymbols = this.filter(function (node) {
|
21981 | return type.isSymbolNode(node) && node.name === 'end';
|
21982 | });
|
21983 | return endSymbols.length > 0;
|
21984 | };
|
21985 | |
21986 |
|
21987 |
|
21988 |
|
21989 |
|
21990 |
|
21991 |
|
21992 |
|
21993 |
|
21994 |
|
21995 |
|
21996 |
|
21997 |
|
21998 |
|
21999 |
|
22000 | RangeNode.prototype._compile = function (math, argNames) {
|
22001 | var range = math.range;
|
22002 |
|
22003 | var evalStart = this.start._compile(math, argNames);
|
22004 |
|
22005 | var evalEnd = this.end._compile(math, argNames);
|
22006 |
|
22007 | if (this.step) {
|
22008 | var evalStep = this.step._compile(math, argNames);
|
22009 |
|
22010 | return function evalRangeNode(scope, args, context) {
|
22011 | return range(evalStart(scope, args, context), evalEnd(scope, args, context), evalStep(scope, args, context));
|
22012 | };
|
22013 | } else {
|
22014 | return function evalRangeNode(scope, args, context) {
|
22015 | return range(evalStart(scope, args, context), evalEnd(scope, args, context));
|
22016 | };
|
22017 | }
|
22018 | };
|
22019 | |
22020 |
|
22021 |
|
22022 |
|
22023 |
|
22024 |
|
22025 | RangeNode.prototype.forEach = function (callback) {
|
22026 | callback(this.start, 'start', this);
|
22027 | callback(this.end, 'end', this);
|
22028 |
|
22029 | if (this.step) {
|
22030 | callback(this.step, 'step', this);
|
22031 | }
|
22032 | };
|
22033 | |
22034 |
|
22035 |
|
22036 |
|
22037 |
|
22038 |
|
22039 |
|
22040 |
|
22041 | RangeNode.prototype.map = function (callback) {
|
22042 | return new RangeNode(this._ifNode(callback(this.start, 'start', this)), this._ifNode(callback(this.end, 'end', this)), this.step && this._ifNode(callback(this.step, 'step', this)));
|
22043 | };
|
22044 | |
22045 |
|
22046 |
|
22047 |
|
22048 |
|
22049 |
|
22050 | RangeNode.prototype.clone = function () {
|
22051 | return new RangeNode(this.start, this.end, this.step && this.step);
|
22052 | };
|
22053 | |
22054 |
|
22055 |
|
22056 |
|
22057 |
|
22058 |
|
22059 |
|
22060 |
|
22061 |
|
22062 | function calculateNecessaryParentheses(node, parenthesis) {
|
22063 | var precedence = operators.getPrecedence(node, parenthesis);
|
22064 | var parens = {};
|
22065 | var startPrecedence = operators.getPrecedence(node.start, parenthesis);
|
22066 | parens.start = startPrecedence !== null && startPrecedence <= precedence || parenthesis === 'all';
|
22067 |
|
22068 | if (node.step) {
|
22069 | var stepPrecedence = operators.getPrecedence(node.step, parenthesis);
|
22070 | parens.step = stepPrecedence !== null && stepPrecedence <= precedence || parenthesis === 'all';
|
22071 | }
|
22072 |
|
22073 | var endPrecedence = operators.getPrecedence(node.end, parenthesis);
|
22074 | parens.end = endPrecedence !== null && endPrecedence <= precedence || parenthesis === 'all';
|
22075 | return parens;
|
22076 | }
|
22077 | |
22078 |
|
22079 |
|
22080 |
|
22081 |
|
22082 |
|
22083 |
|
22084 | RangeNode.prototype._toString = function (options) {
|
22085 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
22086 | var parens = calculateNecessaryParentheses(this, parenthesis);
|
22087 |
|
22088 | var str;
|
22089 | var start = this.start.toString(options);
|
22090 |
|
22091 | if (parens.start) {
|
22092 | start = '(' + start + ')';
|
22093 | }
|
22094 |
|
22095 | str = start;
|
22096 |
|
22097 | if (this.step) {
|
22098 | var step = this.step.toString(options);
|
22099 |
|
22100 | if (parens.step) {
|
22101 | step = '(' + step + ')';
|
22102 | }
|
22103 |
|
22104 | str += ':' + step;
|
22105 | }
|
22106 |
|
22107 | var end = this.end.toString(options);
|
22108 |
|
22109 | if (parens.end) {
|
22110 | end = '(' + end + ')';
|
22111 | }
|
22112 |
|
22113 | str += ':' + end;
|
22114 | return str;
|
22115 | };
|
22116 | |
22117 |
|
22118 |
|
22119 |
|
22120 |
|
22121 |
|
22122 | RangeNode.prototype.toJSON = function () {
|
22123 | return {
|
22124 | mathjs: 'RangeNode',
|
22125 | start: this.start,
|
22126 | end: this.end,
|
22127 | step: this.step
|
22128 | };
|
22129 | };
|
22130 | |
22131 |
|
22132 |
|
22133 |
|
22134 |
|
22135 |
|
22136 |
|
22137 |
|
22138 |
|
22139 | RangeNode.fromJSON = function (json) {
|
22140 | return new RangeNode(json.start, json.end, json.step);
|
22141 | };
|
22142 | |
22143 |
|
22144 |
|
22145 |
|
22146 |
|
22147 |
|
22148 |
|
22149 | RangeNode.prototype.toHTML = function (options) {
|
22150 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
22151 | var parens = calculateNecessaryParentheses(this, parenthesis);
|
22152 |
|
22153 | var str;
|
22154 | var start = this.start.toHTML(options);
|
22155 |
|
22156 | if (parens.start) {
|
22157 | start = '<span class="math-parenthesis math-round-parenthesis">(</span>' + start + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
22158 | }
|
22159 |
|
22160 | str = start;
|
22161 |
|
22162 | if (this.step) {
|
22163 | var step = this.step.toHTML(options);
|
22164 |
|
22165 | if (parens.step) {
|
22166 | step = '<span class="math-parenthesis math-round-parenthesis">(</span>' + step + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
22167 | }
|
22168 |
|
22169 | str += '<span class="math-operator math-range-operator">:</span>' + step;
|
22170 | }
|
22171 |
|
22172 | var end = this.end.toHTML(options);
|
22173 |
|
22174 | if (parens.end) {
|
22175 | end = '<span class="math-parenthesis math-round-parenthesis">(</span>' + end + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
22176 | }
|
22177 |
|
22178 | str += '<span class="math-operator math-range-operator">:</span>' + end;
|
22179 | return str;
|
22180 | };
|
22181 | |
22182 |
|
22183 |
|
22184 |
|
22185 |
|
22186 |
|
22187 |
|
22188 | RangeNode.prototype._toTex = function (options) {
|
22189 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
22190 | var parens = calculateNecessaryParentheses(this, parenthesis);
|
22191 | var str = this.start.toTex(options);
|
22192 |
|
22193 | if (parens.start) {
|
22194 | str = "\\left(".concat(str, "\\right)");
|
22195 | }
|
22196 |
|
22197 | if (this.step) {
|
22198 | var step = this.step.toTex(options);
|
22199 |
|
22200 | if (parens.step) {
|
22201 | step = "\\left(".concat(step, "\\right)");
|
22202 | }
|
22203 |
|
22204 | str += ':' + step;
|
22205 | }
|
22206 |
|
22207 | var end = this.end.toTex(options);
|
22208 |
|
22209 | if (parens.end) {
|
22210 | end = "\\left(".concat(end, "\\right)");
|
22211 | }
|
22212 |
|
22213 | str += ':' + end;
|
22214 | return str;
|
22215 | };
|
22216 |
|
22217 | return RangeNode;
|
22218 | }
|
22219 |
|
22220 | exports.name = 'RangeNode';
|
22221 | exports.path = 'expression.node';
|
22222 | exports.factory = factory;
|
22223 |
|
22224 | }),
|
22225 |
|
22226 | (function(module, exports, __webpack_require__) {
|
22227 |
|
22228 | "use strict";
|
22229 |
|
22230 |
|
22231 | var operators = __webpack_require__(53);
|
22232 |
|
22233 | var latex = __webpack_require__(4);
|
22234 |
|
22235 | var escape = __webpack_require__(9).escape;
|
22236 |
|
22237 | function factory(type, config, load, typed) {
|
22238 | var Node = load(__webpack_require__(16));
|
22239 |
|
22240 | var getSafeProperty = __webpack_require__(13).getSafeProperty;
|
22241 | |
22242 |
|
22243 |
|
22244 |
|
22245 |
|
22246 |
|
22247 |
|
22248 |
|
22249 |
|
22250 |
|
22251 |
|
22252 | function RelationalNode(conditionals, params) {
|
22253 | if (!(this instanceof RelationalNode)) {
|
22254 | throw new SyntaxError('Constructor must be called with the new operator');
|
22255 | }
|
22256 |
|
22257 | if (!Array.isArray(conditionals)) throw new TypeError('Parameter conditionals must be an array');
|
22258 | if (!Array.isArray(params)) throw new TypeError('Parameter params must be an array');
|
22259 | if (conditionals.length !== params.length - 1) throw new TypeError('Parameter params must contain exactly one more element than parameter conditionals');
|
22260 | this.conditionals = conditionals;
|
22261 | this.params = params;
|
22262 | }
|
22263 |
|
22264 | RelationalNode.prototype = new Node();
|
22265 | RelationalNode.prototype.type = 'RelationalNode';
|
22266 | RelationalNode.prototype.isRelationalNode = true;
|
22267 | |
22268 |
|
22269 |
|
22270 |
|
22271 |
|
22272 |
|
22273 |
|
22274 |
|
22275 |
|
22276 |
|
22277 |
|
22278 |
|
22279 |
|
22280 |
|
22281 | RelationalNode.prototype._compile = function (math, argNames) {
|
22282 | var self = this;
|
22283 | var compiled = this.params.map(function (p) {
|
22284 | return p._compile(math, argNames);
|
22285 | });
|
22286 | return function evalRelationalNode(scope, args, context) {
|
22287 | var evalLhs;
|
22288 | var evalRhs = compiled[0](scope, args, context);
|
22289 |
|
22290 | for (var i = 0; i < self.conditionals.length; i++) {
|
22291 | evalLhs = evalRhs;
|
22292 | evalRhs = compiled[i + 1](scope, args, context);
|
22293 | var condFn = getSafeProperty(math, self.conditionals[i]);
|
22294 |
|
22295 | if (!condFn(evalLhs, evalRhs)) {
|
22296 | return false;
|
22297 | }
|
22298 | }
|
22299 |
|
22300 | return true;
|
22301 | };
|
22302 | };
|
22303 | |
22304 |
|
22305 |
|
22306 |
|
22307 |
|
22308 |
|
22309 | RelationalNode.prototype.forEach = function (callback) {
|
22310 | var _this = this;
|
22311 |
|
22312 | this.params.forEach(function (n, i) {
|
22313 | return callback(n, 'params[' + i + ']', _this);
|
22314 | }, this);
|
22315 | };
|
22316 | |
22317 |
|
22318 |
|
22319 |
|
22320 |
|
22321 |
|
22322 |
|
22323 |
|
22324 | RelationalNode.prototype.map = function (callback) {
|
22325 | var _this2 = this;
|
22326 |
|
22327 | return new RelationalNode(this.conditionals.slice(), this.params.map(function (n, i) {
|
22328 | return _this2._ifNode(callback(n, 'params[' + i + ']', _this2));
|
22329 | }, this));
|
22330 | };
|
22331 | |
22332 |
|
22333 |
|
22334 |
|
22335 |
|
22336 |
|
22337 | RelationalNode.prototype.clone = function () {
|
22338 | return new RelationalNode(this.conditionals, this.params);
|
22339 | };
|
22340 | |
22341 |
|
22342 |
|
22343 |
|
22344 |
|
22345 |
|
22346 |
|
22347 | RelationalNode.prototype._toString = function (options) {
|
22348 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
22349 | var precedence = operators.getPrecedence(this, parenthesis);
|
22350 | var paramStrings = this.params.map(function (p, index) {
|
22351 | var paramPrecedence = operators.getPrecedence(p, parenthesis);
|
22352 | return parenthesis === 'all' || paramPrecedence !== null && paramPrecedence <= precedence ? '(' + p.toString(options) + ')' : p.toString(options);
|
22353 | });
|
22354 | var operatorMap = {
|
22355 | 'equal': '==',
|
22356 | 'unequal': '!=',
|
22357 | 'smaller': '<',
|
22358 | 'larger': '>',
|
22359 | 'smallerEq': '<=',
|
22360 | 'largerEq': '>='
|
22361 | };
|
22362 | var ret = paramStrings[0];
|
22363 |
|
22364 | for (var i = 0; i < this.conditionals.length; i++) {
|
22365 | ret += ' ' + operatorMap[this.conditionals[i]] + ' ' + paramStrings[i + 1];
|
22366 | }
|
22367 |
|
22368 | return ret;
|
22369 | };
|
22370 | |
22371 |
|
22372 |
|
22373 |
|
22374 |
|
22375 |
|
22376 | RelationalNode.prototype.toJSON = function () {
|
22377 | return {
|
22378 | mathjs: 'RelationalNode',
|
22379 | conditionals: this.conditionals,
|
22380 | params: this.params
|
22381 | };
|
22382 | };
|
22383 | |
22384 |
|
22385 |
|
22386 |
|
22387 |
|
22388 |
|
22389 |
|
22390 |
|
22391 |
|
22392 | RelationalNode.fromJSON = function (json) {
|
22393 | return new RelationalNode(json.conditionals, json.params);
|
22394 | };
|
22395 | |
22396 |
|
22397 |
|
22398 |
|
22399 |
|
22400 |
|
22401 |
|
22402 | RelationalNode.prototype.toHTML = function (options) {
|
22403 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
22404 | var precedence = operators.getPrecedence(this, parenthesis);
|
22405 | var paramStrings = this.params.map(function (p, index) {
|
22406 | var paramPrecedence = operators.getPrecedence(p, parenthesis);
|
22407 | return parenthesis === 'all' || paramPrecedence !== null && paramPrecedence <= precedence ? '<span class="math-parenthesis math-round-parenthesis">(</span>' + p.toHTML(options) + '<span class="math-parenthesis math-round-parenthesis">)</span>' : p.toHTML(options);
|
22408 | });
|
22409 | var operatorMap = {
|
22410 | 'equal': '==',
|
22411 | 'unequal': '!=',
|
22412 | 'smaller': '<',
|
22413 | 'larger': '>',
|
22414 | 'smallerEq': '<=',
|
22415 | 'largerEq': '>='
|
22416 | };
|
22417 | var ret = paramStrings[0];
|
22418 |
|
22419 | for (var i = 0; i < this.conditionals.length; i++) {
|
22420 | ret += '<span class="math-operator math-binary-operator math-explicit-binary-operator">' + escape(operatorMap[this.conditionals[i]]) + '</span>' + paramStrings[i + 1];
|
22421 | }
|
22422 |
|
22423 | return ret;
|
22424 | };
|
22425 | |
22426 |
|
22427 |
|
22428 |
|
22429 |
|
22430 |
|
22431 |
|
22432 | RelationalNode.prototype._toTex = function (options) {
|
22433 | var parenthesis = options && options.parenthesis ? options.parenthesis : 'keep';
|
22434 | var precedence = operators.getPrecedence(this, parenthesis);
|
22435 | var paramStrings = this.params.map(function (p, index) {
|
22436 | var paramPrecedence = operators.getPrecedence(p, parenthesis);
|
22437 | return parenthesis === 'all' || paramPrecedence !== null && paramPrecedence <= precedence ? '\\left(' + p.toTex(options) + '\right)' : p.toTex(options);
|
22438 | });
|
22439 | var ret = paramStrings[0];
|
22440 |
|
22441 | for (var i = 0; i < this.conditionals.length; i++) {
|
22442 | ret += latex.operators[this.conditionals[i]] + paramStrings[i + 1];
|
22443 | }
|
22444 |
|
22445 | return ret;
|
22446 | };
|
22447 |
|
22448 | return RelationalNode;
|
22449 | }
|
22450 |
|
22451 | exports.name = 'RelationalNode';
|
22452 | exports.path = 'expression.node';
|
22453 | exports.factory = factory;
|
22454 |
|
22455 | }),
|
22456 |
|
22457 | (function(module, exports, __webpack_require__) {
|
22458 |
|
22459 | "use strict";
|
22460 |
|
22461 |
|
22462 | function factory(type, config, load, typed, math) {
|
22463 | var util = load(__webpack_require__(126));
|
22464 | var isCommutative = util.isCommutative;
|
22465 | var isAssociative = util.isAssociative;
|
22466 | var allChildren = util.allChildren;
|
22467 | var createMakeNodeFunction = util.createMakeNodeFunction;
|
22468 | var ConstantNode = math.expression.node.ConstantNode;
|
22469 | var OperatorNode = math.expression.node.OperatorNode;
|
22470 | var FunctionNode = math.expression.node.FunctionNode;
|
22471 |
|
22472 | function simplifyConstant(expr, options) {
|
22473 | var res = foldFraction(expr, options);
|
22474 | return type.isNode(res) ? res : _toNode(res);
|
22475 | }
|
22476 |
|
22477 | function _eval(fnname, args, options) {
|
22478 | try {
|
22479 | return _toNumber(math[fnname].apply(null, args), options);
|
22480 | } catch (ignore) {
|
22481 |
|
22482 | args = args.map(function (x) {
|
22483 | if (type.isFraction(x)) {
|
22484 | return x.valueOf();
|
22485 | }
|
22486 |
|
22487 | return x;
|
22488 | });
|
22489 | return _toNumber(math[fnname].apply(null, args), options);
|
22490 | }
|
22491 | }
|
22492 |
|
22493 | var _toNode = typed({
|
22494 | 'Fraction': _fractionToNode,
|
22495 | 'number': function number(n) {
|
22496 | if (n < 0) {
|
22497 | return unaryMinusNode(new ConstantNode(-n));
|
22498 | }
|
22499 |
|
22500 | return new ConstantNode(n);
|
22501 | },
|
22502 | 'BigNumber': function BigNumber(n) {
|
22503 | if (n < 0) {
|
22504 | return unaryMinusNode(new ConstantNode(-n));
|
22505 | }
|
22506 |
|
22507 | return new ConstantNode(n);
|
22508 | },
|
22509 | 'Complex': function Complex(s) {
|
22510 | throw new Error('Cannot convert Complex number to Node');
|
22511 | }
|
22512 | });
|
22513 |
|
22514 |
|
22515 | function _exactFraction(n, options) {
|
22516 | var exactFractions = options && options.exactFractions !== false;
|
22517 |
|
22518 | if (exactFractions && isFinite(n)) {
|
22519 | var f = math.fraction(n);
|
22520 |
|
22521 | if (f.valueOf() === n) {
|
22522 | return f;
|
22523 | }
|
22524 | }
|
22525 |
|
22526 | return n;
|
22527 | }
|
22528 |
|
22529 |
|
22530 |
|
22531 | var _toNumber = typed({
|
22532 | 'string, Object': function stringObject(s, options) {
|
22533 | if (config.number === 'BigNumber') {
|
22534 | return math.bignumber(s);
|
22535 | } else if (config.number === 'Fraction') {
|
22536 | return math.fraction(s);
|
22537 | } else {
|
22538 | var n = parseFloat(s);
|
22539 | return _exactFraction(n, options);
|
22540 | }
|
22541 | },
|
22542 | 'Fraction, Object': function FractionObject(s, options) {
|
22543 | return s;
|
22544 | },
|
22545 |
|
22546 | 'BigNumber, Object': function BigNumberObject(s, options) {
|
22547 | return s;
|
22548 | },
|
22549 |
|
22550 | 'number, Object': function numberObject(s, options) {
|
22551 | return _exactFraction(s, options);
|
22552 | },
|
22553 | 'Complex, Object': function ComplexObject(s, options) {
|
22554 | if (s.im !== 0) {
|
22555 | return s;
|
22556 | }
|
22557 |
|
22558 | return _exactFraction(s.re, options);
|
22559 | }
|
22560 | });
|
22561 |
|
22562 | function unaryMinusNode(n) {
|
22563 | return new OperatorNode('-', 'unaryMinus', [n]);
|
22564 | }
|
22565 |
|
22566 | function _fractionToNode(f) {
|
22567 | var n;
|
22568 | var vn = f.s * f.n;
|
22569 |
|
22570 | if (vn < 0) {
|
22571 | n = new OperatorNode('-', 'unaryMinus', [new ConstantNode(-vn)]);
|
22572 | } else {
|
22573 | n = new ConstantNode(vn);
|
22574 | }
|
22575 |
|
22576 | if (f.d === 1) {
|
22577 | return n;
|
22578 | }
|
22579 |
|
22580 | return new OperatorNode('/', 'divide', [n, new ConstantNode(f.d)]);
|
22581 | }
|
22582 | |
22583 |
|
22584 |
|
22585 |
|
22586 |
|
22587 |
|
22588 |
|
22589 |
|
22590 |
|
22591 |
|
22592 |
|
22593 |
|
22594 | function foldOp(fn, args, makeNode, options) {
|
22595 | return args.reduce(function (a, b) {
|
22596 | if (!type.isNode(a) && !type.isNode(b)) {
|
22597 | try {
|
22598 | return _eval(fn, [a, b], options);
|
22599 | } catch (ignoreandcontinue) {}
|
22600 |
|
22601 | a = _toNode(a);
|
22602 | b = _toNode(b);
|
22603 | } else if (!type.isNode(a)) {
|
22604 | a = _toNode(a);
|
22605 | } else if (!type.isNode(b)) {
|
22606 | b = _toNode(b);
|
22607 | }
|
22608 |
|
22609 | return makeNode([a, b]);
|
22610 | });
|
22611 | }
|
22612 |
|
22613 |
|
22614 | function foldFraction(node, options) {
|
22615 | switch (node.type) {
|
22616 | case 'SymbolNode':
|
22617 | return node;
|
22618 |
|
22619 | case 'ConstantNode':
|
22620 | if (typeof node.value === 'number' || !isNaN(node.value)) {
|
22621 | return _toNumber(node.value, options);
|
22622 | }
|
22623 |
|
22624 | return node;
|
22625 |
|
22626 | case 'FunctionNode':
|
22627 | if (math[node.name] && math[node.name].rawArgs) {
|
22628 | return node;
|
22629 | }
|
22630 |
|
22631 |
|
22632 | var operatorFunctions = ['add', 'multiply'];
|
22633 |
|
22634 | if (operatorFunctions.indexOf(node.name) === -1) {
|
22635 | var _args = node.args.map(function (arg) {
|
22636 | return foldFraction(arg, options);
|
22637 | });
|
22638 |
|
22639 |
|
22640 | if (!_args.some(type.isNode)) {
|
22641 | try {
|
22642 | return _eval(node.name, _args, options);
|
22643 | } catch (ignoreandcontine) {}
|
22644 | }
|
22645 |
|
22646 |
|
22647 | _args = _args.map(function (arg) {
|
22648 | return type.isNode(arg) ? arg : _toNode(arg);
|
22649 | });
|
22650 | return new FunctionNode(node.name, _args);
|
22651 | } else {}
|
22652 |
|
22653 |
|
22654 |
|
22655 |
|
22656 | case 'OperatorNode':
|
22657 | var fn = node.fn.toString();
|
22658 | var args;
|
22659 | var res;
|
22660 | var makeNode = createMakeNodeFunction(node);
|
22661 |
|
22662 | if (node.isUnary()) {
|
22663 | args = [foldFraction(node.args[0], options)];
|
22664 |
|
22665 | if (!type.isNode(args[0])) {
|
22666 | res = _eval(fn, args, options);
|
22667 | } else {
|
22668 | res = makeNode(args);
|
22669 | }
|
22670 | } else if (isAssociative(node)) {
|
22671 | args = allChildren(node);
|
22672 | args = args.map(function (arg) {
|
22673 | return foldFraction(arg, options);
|
22674 | });
|
22675 |
|
22676 | if (isCommutative(fn)) {
|
22677 |
|
22678 | var consts = [];
|
22679 | var vars = [];
|
22680 |
|
22681 | for (var i = 0; i < args.length; i++) {
|
22682 | if (!type.isNode(args[i])) {
|
22683 | consts.push(args[i]);
|
22684 | } else {
|
22685 | vars.push(args[i]);
|
22686 | }
|
22687 | }
|
22688 |
|
22689 | if (consts.length > 1) {
|
22690 | res = foldOp(fn, consts, makeNode, options);
|
22691 | vars.unshift(res);
|
22692 | res = foldOp(fn, vars, makeNode, options);
|
22693 | } else {
|
22694 |
|
22695 | res = foldOp(fn, args, makeNode, options);
|
22696 | }
|
22697 | } else {
|
22698 |
|
22699 | res = foldOp(fn, args, makeNode, options);
|
22700 | }
|
22701 | } else {
|
22702 |
|
22703 | args = node.args.map(function (arg) {
|
22704 | return foldFraction(arg, options);
|
22705 | });
|
22706 | res = foldOp(fn, args, makeNode, options);
|
22707 | }
|
22708 |
|
22709 | return res;
|
22710 |
|
22711 | case 'ParenthesisNode':
|
22712 |
|
22713 | return foldFraction(node.content, options);
|
22714 |
|
22715 | case 'AccessorNode':
|
22716 |
|
22717 |
|
22718 | case 'ArrayNode':
|
22719 |
|
22720 |
|
22721 | case 'AssignmentNode':
|
22722 |
|
22723 |
|
22724 | case 'BlockNode':
|
22725 |
|
22726 |
|
22727 | case 'FunctionAssignmentNode':
|
22728 |
|
22729 |
|
22730 | case 'IndexNode':
|
22731 |
|
22732 |
|
22733 | case 'ObjectNode':
|
22734 |
|
22735 |
|
22736 | case 'RangeNode':
|
22737 |
|
22738 |
|
22739 | case 'UpdateNode':
|
22740 |
|
22741 |
|
22742 | case 'ConditionalNode':
|
22743 |
|
22744 |
|
22745 | default:
|
22746 | throw new Error("Unimplemented node type in simplifyConstant: ".concat(node.type));
|
22747 | }
|
22748 | }
|
22749 |
|
22750 | return simplifyConstant;
|
22751 | }
|
22752 |
|
22753 | exports.math = true;
|
22754 | exports.name = 'simplifyConstant';
|
22755 | exports.path = 'algebra.simplify';
|
22756 | exports.factory = factory;
|
22757 |
|
22758 | }),
|
22759 |
|
22760 | (function(module, exports, __webpack_require__) {
|
22761 |
|
22762 | "use strict";
|
22763 |
|
22764 |
|
22765 | function factory(type, config, load, typed, math) {
|
22766 | var FunctionNode = math.expression.node.FunctionNode;
|
22767 | var OperatorNode = math.expression.node.OperatorNode;
|
22768 | var SymbolNode = math.expression.node.SymbolNode;
|
22769 |
|
22770 |
|
22771 |
|
22772 |
|
22773 | var commutative = {
|
22774 | 'add': true,
|
22775 | 'multiply': true
|
22776 | };
|
22777 | var associative = {
|
22778 | 'add': true,
|
22779 | 'multiply': true
|
22780 | };
|
22781 |
|
22782 | function isCommutative(node, context) {
|
22783 | if (!type.isOperatorNode(node)) {
|
22784 | return true;
|
22785 | }
|
22786 |
|
22787 | var name = node.fn.toString();
|
22788 |
|
22789 | if (context && context.hasOwnProperty(name) && context[name].hasOwnProperty('commutative')) {
|
22790 | return context[name].commutative;
|
22791 | }
|
22792 |
|
22793 | return commutative[name] || false;
|
22794 | }
|
22795 |
|
22796 | function isAssociative(node, context) {
|
22797 | if (!type.isOperatorNode(node)) {
|
22798 | return false;
|
22799 | }
|
22800 |
|
22801 | var name = node.fn.toString();
|
22802 |
|
22803 | if (context && context.hasOwnProperty(name) && context[name].hasOwnProperty('associative')) {
|
22804 | return context[name].associative;
|
22805 | }
|
22806 |
|
22807 | return associative[name] || false;
|
22808 | }
|
22809 | |
22810 |
|
22811 |
|
22812 |
|
22813 |
|
22814 |
|
22815 | function flatten(node) {
|
22816 | if (!node.args || node.args.length === 0) {
|
22817 | return node;
|
22818 | }
|
22819 |
|
22820 | node.args = allChildren(node);
|
22821 |
|
22822 | for (var i = 0; i < node.args.length; i++) {
|
22823 | flatten(node.args[i]);
|
22824 | }
|
22825 | }
|
22826 | |
22827 |
|
22828 |
|
22829 |
|
22830 |
|
22831 |
|
22832 | function allChildren(node) {
|
22833 | var op;
|
22834 | var children = [];
|
22835 |
|
22836 | var findChildren = function findChildren(node) {
|
22837 | for (var i = 0; i < node.args.length; i++) {
|
22838 | var child = node.args[i];
|
22839 |
|
22840 | if (type.isOperatorNode(child) && op === child.op) {
|
22841 | findChildren(child);
|
22842 | } else {
|
22843 | children.push(child);
|
22844 | }
|
22845 | }
|
22846 | };
|
22847 |
|
22848 | if (isAssociative(node)) {
|
22849 | op = node.op;
|
22850 | findChildren(node);
|
22851 | return children;
|
22852 | } else {
|
22853 | return node.args;
|
22854 | }
|
22855 | }
|
22856 | |
22857 |
|
22858 |
|
22859 |
|
22860 |
|
22861 | function unflattenr(node) {
|
22862 | if (!node.args || node.args.length === 0) {
|
22863 | return;
|
22864 | }
|
22865 |
|
22866 | var makeNode = createMakeNodeFunction(node);
|
22867 | var l = node.args.length;
|
22868 |
|
22869 | for (var i = 0; i < l; i++) {
|
22870 | unflattenr(node.args[i]);
|
22871 | }
|
22872 |
|
22873 | if (l > 2 && isAssociative(node)) {
|
22874 | var curnode = node.args.pop();
|
22875 |
|
22876 | while (node.args.length > 0) {
|
22877 | curnode = makeNode([node.args.pop(), curnode]);
|
22878 | }
|
22879 |
|
22880 | node.args = curnode.args;
|
22881 | }
|
22882 | }
|
22883 | |
22884 |
|
22885 |
|
22886 |
|
22887 |
|
22888 | function unflattenl(node) {
|
22889 | if (!node.args || node.args.length === 0) {
|
22890 | return;
|
22891 | }
|
22892 |
|
22893 | var makeNode = createMakeNodeFunction(node);
|
22894 | var l = node.args.length;
|
22895 |
|
22896 | for (var i = 0; i < l; i++) {
|
22897 | unflattenl(node.args[i]);
|
22898 | }
|
22899 |
|
22900 | if (l > 2 && isAssociative(node)) {
|
22901 | var curnode = node.args.shift();
|
22902 |
|
22903 | while (node.args.length > 0) {
|
22904 | curnode = makeNode([curnode, node.args.shift()]);
|
22905 | }
|
22906 |
|
22907 | node.args = curnode.args;
|
22908 | }
|
22909 | }
|
22910 |
|
22911 | function createMakeNodeFunction(node) {
|
22912 | if (type.isOperatorNode(node)) {
|
22913 | return function (args) {
|
22914 | try {
|
22915 | return new OperatorNode(node.op, node.fn, args, node.implicit);
|
22916 | } catch (err) {
|
22917 | console.error(err);
|
22918 | return [];
|
22919 | }
|
22920 | };
|
22921 | } else {
|
22922 | return function (args) {
|
22923 | return new FunctionNode(new SymbolNode(node.name), args);
|
22924 | };
|
22925 | }
|
22926 | }
|
22927 |
|
22928 | return {
|
22929 | createMakeNodeFunction: createMakeNodeFunction,
|
22930 | isCommutative: isCommutative,
|
22931 | isAssociative: isAssociative,
|
22932 | flatten: flatten,
|
22933 | allChildren: allChildren,
|
22934 | unflattenr: unflattenr,
|
22935 | unflattenl: unflattenl
|
22936 | };
|
22937 | }
|
22938 |
|
22939 | exports.factory = factory;
|
22940 | exports.math = true;
|
22941 |
|
22942 | }),
|
22943 |
|
22944 | (function(module, exports, __webpack_require__) {
|
22945 |
|
22946 | "use strict";
|
22947 |
|
22948 |
|
22949 | function factory(type, config, load, typed, math) {
|
22950 | var equal = load(__webpack_require__(51));
|
22951 | var isZero = load(__webpack_require__(60));
|
22952 | var add = load(__webpack_require__(14));
|
22953 | var subtract = load(__webpack_require__(15));
|
22954 | var multiply = load(__webpack_require__(10));
|
22955 | var divide = load(__webpack_require__(45));
|
22956 | var pow = load(__webpack_require__(42));
|
22957 | var ConstantNode = math.expression.node.ConstantNode;
|
22958 | var OperatorNode = math.expression.node.OperatorNode;
|
22959 | var FunctionNode = math.expression.node.FunctionNode;
|
22960 | var ParenthesisNode = math.expression.node.ParenthesisNode;
|
22961 | var node0 = new ConstantNode(0);
|
22962 | var node1 = new ConstantNode(1);
|
22963 | |
22964 |
|
22965 |
|
22966 |
|
22967 |
|
22968 |
|
22969 |
|
22970 |
|
22971 |
|
22972 |
|
22973 |
|
22974 |
|
22975 |
|
22976 |
|
22977 |
|
22978 |
|
22979 |
|
22980 |
|
22981 |
|
22982 |
|
22983 |
|
22984 |
|
22985 |
|
22986 |
|
22987 | function simplifyCore(node) {
|
22988 | if (type.isOperatorNode(node) && node.isUnary()) {
|
22989 | var a0 = simplifyCore(node.args[0]);
|
22990 |
|
22991 | if (node.op === '+') {
|
22992 |
|
22993 | return a0;
|
22994 | }
|
22995 |
|
22996 | if (node.op === '-') {
|
22997 |
|
22998 | if (type.isOperatorNode(a0)) {
|
22999 | if (a0.isUnary() && a0.op === '-') {
|
23000 | return a0.args[0];
|
23001 | } else if (a0.isBinary() && a0.fn === 'subtract') {
|
23002 | return new OperatorNode('-', 'subtract', [a0.args[1], a0.args[0]]);
|
23003 | }
|
23004 | }
|
23005 |
|
23006 | return new OperatorNode(node.op, node.fn, [a0]);
|
23007 | }
|
23008 | } else if (type.isOperatorNode(node) && node.isBinary()) {
|
23009 | var _a = simplifyCore(node.args[0]);
|
23010 |
|
23011 | var a1 = simplifyCore(node.args[1]);
|
23012 |
|
23013 | if (node.op === '+') {
|
23014 | if (type.isConstantNode(_a)) {
|
23015 | if (isZero(_a.value)) {
|
23016 | return a1;
|
23017 | } else if (type.isConstantNode(a1)) {
|
23018 | return new ConstantNode(add(_a.value, a1.value));
|
23019 | }
|
23020 | }
|
23021 |
|
23022 | if (type.isConstantNode(a1) && isZero(a1.value)) {
|
23023 | return _a;
|
23024 | }
|
23025 |
|
23026 | if (type.isOperatorNode(a1) && a1.isUnary() && a1.op === '-') {
|
23027 | return new OperatorNode('-', 'subtract', [_a, a1.args[0]]);
|
23028 | }
|
23029 |
|
23030 | return new OperatorNode(node.op, node.fn, a1 ? [_a, a1] : [_a]);
|
23031 | } else if (node.op === '-') {
|
23032 | if (type.isConstantNode(_a) && a1) {
|
23033 | if (type.isConstantNode(a1)) {
|
23034 | return new ConstantNode(subtract(_a.value, a1.value));
|
23035 | } else if (isZero(_a.value)) {
|
23036 | return new OperatorNode('-', 'unaryMinus', [a1]);
|
23037 | }
|
23038 | }
|
23039 |
|
23040 |
|
23041 | if (node.fn === 'subtract') {
|
23042 | if (type.isConstantNode(a1) && isZero(a1.value)) {
|
23043 | return _a;
|
23044 | }
|
23045 |
|
23046 | if (type.isOperatorNode(a1) && a1.isUnary() && a1.op === '-') {
|
23047 | return simplifyCore(new OperatorNode('+', 'add', [_a, a1.args[0]]));
|
23048 | }
|
23049 |
|
23050 | return new OperatorNode(node.op, node.fn, [_a, a1]);
|
23051 | }
|
23052 | } else if (node.op === '*') {
|
23053 | if (type.isConstantNode(_a)) {
|
23054 | if (isZero(_a.value)) {
|
23055 | return node0;
|
23056 | } else if (equal(_a.value, 1)) {
|
23057 | return a1;
|
23058 | } else if (type.isConstantNode(a1)) {
|
23059 | return new ConstantNode(multiply(_a.value, a1.value));
|
23060 | }
|
23061 | }
|
23062 |
|
23063 | if (type.isConstantNode(a1)) {
|
23064 | if (isZero(a1.value)) {
|
23065 | return node0;
|
23066 | } else if (equal(a1.value, 1)) {
|
23067 | return _a;
|
23068 | } else if (type.isOperatorNode(_a) && _a.isBinary() && _a.op === node.op) {
|
23069 | var a00 = _a.args[0];
|
23070 |
|
23071 | if (type.isConstantNode(a00)) {
|
23072 | var a00a1 = new ConstantNode(multiply(a00.value, a1.value));
|
23073 | return new OperatorNode(node.op, node.fn, [a00a1, _a.args[1]], node.implicit);
|
23074 | }
|
23075 | }
|
23076 |
|
23077 | return new OperatorNode(node.op, node.fn, [a1, _a], node.implicit);
|
23078 | }
|
23079 |
|
23080 | return new OperatorNode(node.op, node.fn, [_a, a1], node.implicit);
|
23081 | } else if (node.op === '/') {
|
23082 | if (type.isConstantNode(_a)) {
|
23083 | if (isZero(_a.value)) {
|
23084 | return node0;
|
23085 | } else if (type.isConstantNode(a1) && (equal(a1.value, 1) || equal(a1.value, 2) || equal(a1.value, 4))) {
|
23086 | return new ConstantNode(divide(_a.value, a1.value));
|
23087 | }
|
23088 | }
|
23089 |
|
23090 | return new OperatorNode(node.op, node.fn, [_a, a1]);
|
23091 | } else if (node.op === '^') {
|
23092 | if (type.isConstantNode(a1)) {
|
23093 | if (isZero(a1.value)) {
|
23094 | return node1;
|
23095 | } else if (equal(a1.value, 1)) {
|
23096 | return _a;
|
23097 | } else {
|
23098 | if (type.isConstantNode(_a)) {
|
23099 |
|
23100 | return new ConstantNode(pow(_a.value, a1.value));
|
23101 | } else if (type.isOperatorNode(_a) && _a.isBinary() && _a.op === '^') {
|
23102 | var a01 = _a.args[1];
|
23103 |
|
23104 | if (type.isConstantNode(a01)) {
|
23105 | return new OperatorNode(node.op, node.fn, [_a.args[0], new ConstantNode(multiply(a01.value, a1.value))]);
|
23106 | }
|
23107 | }
|
23108 | }
|
23109 | }
|
23110 |
|
23111 | return new OperatorNode(node.op, node.fn, [_a, a1]);
|
23112 | }
|
23113 | } else if (type.isParenthesisNode(node)) {
|
23114 | var c = simplifyCore(node.content);
|
23115 |
|
23116 | if (type.isParenthesisNode(c) || type.isSymbolNode(c) || type.isConstantNode(c)) {
|
23117 | return c;
|
23118 | }
|
23119 |
|
23120 | return new ParenthesisNode(c);
|
23121 | } else if (type.isFunctionNode(node)) {
|
23122 | var args = node.args.map(simplifyCore).map(function (arg) {
|
23123 | return type.isParenthesisNode(arg) ? arg.content : arg;
|
23124 | });
|
23125 | return new FunctionNode(simplifyCore(node.fn), args);
|
23126 | } else {
|
23127 | }
|
23128 |
|
23129 | return node;
|
23130 | }
|
23131 |
|
23132 | return simplifyCore;
|
23133 | }
|
23134 |
|
23135 | exports.math = true;
|
23136 | exports.name = 'simplifyCore';
|
23137 | exports.path = 'algebra.simplify';
|
23138 | exports.factory = factory;
|
23139 |
|
23140 | }),
|
23141 |
|
23142 | (function(module, exports, __webpack_require__) {
|
23143 |
|
23144 | "use strict";
|
23145 |
|
23146 |
|
23147 | var util = __webpack_require__(31);
|
23148 |
|
23149 | var object = util.object;
|
23150 | var string = util.string;
|
23151 |
|
23152 | function factory(type, config, load, typed) {
|
23153 | var matrix = load(__webpack_require__(0));
|
23154 | var subtract = load(__webpack_require__(15));
|
23155 | var multiply = load(__webpack_require__(10));
|
23156 | var unaryMinus = load(__webpack_require__(39));
|
23157 | var lup = load(__webpack_require__(87));
|
23158 | |
23159 |
|
23160 |
|
23161 |
|
23162 |
|
23163 |
|
23164 |
|
23165 |
|
23166 |
|
23167 |
|
23168 |
|
23169 |
|
23170 |
|
23171 |
|
23172 |
|
23173 |
|
23174 |
|
23175 |
|
23176 |
|
23177 |
|
23178 |
|
23179 |
|
23180 |
|
23181 |
|
23182 |
|
23183 |
|
23184 | var det = typed('det', {
|
23185 | 'any': function any(x) {
|
23186 | return object.clone(x);
|
23187 | },
|
23188 | 'Array | Matrix': function det(x) {
|
23189 | var size;
|
23190 |
|
23191 | if (type.isMatrix(x)) {
|
23192 | size = x.size();
|
23193 | } else if (Array.isArray(x)) {
|
23194 | x = matrix(x);
|
23195 | size = x.size();
|
23196 | } else {
|
23197 |
|
23198 | size = [];
|
23199 | }
|
23200 |
|
23201 | switch (size.length) {
|
23202 | case 0:
|
23203 |
|
23204 | return object.clone(x);
|
23205 |
|
23206 | case 1:
|
23207 |
|
23208 | if (size[0] === 1) {
|
23209 | return object.clone(x.valueOf()[0]);
|
23210 | } else {
|
23211 | throw new RangeError('Matrix must be square ' + '(size: ' + string.format(size) + ')');
|
23212 | }
|
23213 |
|
23214 | case 2:
|
23215 |
|
23216 | var rows = size[0];
|
23217 | var cols = size[1];
|
23218 |
|
23219 | if (rows === cols) {
|
23220 | return _det(x.clone().valueOf(), rows, cols);
|
23221 | } else {
|
23222 | throw new RangeError('Matrix must be square ' + '(size: ' + string.format(size) + ')');
|
23223 | }
|
23224 |
|
23225 | default:
|
23226 |
|
23227 | throw new RangeError('Matrix must be two dimensional ' + '(size: ' + string.format(size) + ')');
|
23228 | }
|
23229 | }
|
23230 | });
|
23231 | det.toTex = {
|
23232 | 1: "\\det\\left(${args[0]}\\right)"
|
23233 | };
|
23234 | return det;
|
23235 | |
23236 |
|
23237 |
|
23238 |
|
23239 |
|
23240 |
|
23241 |
|
23242 |
|
23243 |
|
23244 | function _det(matrix, rows, cols) {
|
23245 | if (rows === 1) {
|
23246 |
|
23247 | return object.clone(matrix[0][0]);
|
23248 | } else if (rows === 2) {
|
23249 |
|
23250 |
|
23251 | return subtract(multiply(matrix[0][0], matrix[1][1]), multiply(matrix[1][0], matrix[0][1]));
|
23252 | } else {
|
23253 |
|
23254 | var decomp = lup(matrix);
|
23255 |
|
23256 | var _det2 = decomp.U[0][0];
|
23257 |
|
23258 | for (var _i = 1; _i < rows; _i++) {
|
23259 | _det2 = multiply(_det2, decomp.U[_i][_i]);
|
23260 | }
|
23261 |
|
23262 |
|
23263 |
|
23264 | var evenCycles = 0;
|
23265 | var i = 0;
|
23266 | var visited = [];
|
23267 |
|
23268 | while (true) {
|
23269 | while (visited[i]) {
|
23270 | i++;
|
23271 | }
|
23272 |
|
23273 | if (i >= rows) break;
|
23274 | var j = i;
|
23275 | var cycleLen = 0;
|
23276 |
|
23277 | while (!visited[decomp.p[j]]) {
|
23278 | visited[decomp.p[j]] = true;
|
23279 | j = decomp.p[j];
|
23280 | cycleLen++;
|
23281 | }
|
23282 |
|
23283 | if (cycleLen % 2 === 0) {
|
23284 | evenCycles++;
|
23285 | }
|
23286 | }
|
23287 |
|
23288 | return evenCycles % 2 === 0 ? _det2 : unaryMinus(_det2);
|
23289 | }
|
23290 | }
|
23291 | }
|
23292 |
|
23293 | exports.name = 'det';
|
23294 | exports.factory = factory;
|
23295 |
|
23296 | }),
|
23297 |
|
23298 | (function(module, exports, __webpack_require__) {
|
23299 |
|
23300 | "use strict";
|
23301 |
|
23302 |
|
23303 | function factory(type, config, load, typed) {
|
23304 | var parse = load(__webpack_require__(44));
|
23305 | |
23306 |
|
23307 |
|
23308 |
|
23309 |
|
23310 |
|
23311 |
|
23312 |
|
23313 |
|
23314 |
|
23315 |
|
23316 |
|
23317 |
|
23318 |
|
23319 |
|
23320 |
|
23321 |
|
23322 |
|
23323 |
|
23324 |
|
23325 |
|
23326 |
|
23327 |
|
23328 |
|
23329 |
|
23330 |
|
23331 |
|
23332 |
|
23333 |
|
23334 |
|
23335 |
|
23336 |
|
23337 |
|
23338 |
|
23339 |
|
23340 |
|
23341 |
|
23342 |
|
23343 |
|
23344 |
|
23345 | return typed('parse', {
|
23346 | 'string | Array | Matrix': parse,
|
23347 | 'string | Array | Matrix, Object': parse
|
23348 | });
|
23349 | }
|
23350 |
|
23351 | exports.name = 'parse';
|
23352 | exports.factory = factory;
|
23353 |
|
23354 | }),
|
23355 |
|
23356 | (function(module, exports, __webpack_require__) {
|
23357 |
|
23358 | "use strict";
|
23359 |
|
23360 |
|
23361 | var nearlyEqual = __webpack_require__(3).nearlyEqual;
|
23362 |
|
23363 | var bigNearlyEqual = __webpack_require__(32);
|
23364 |
|
23365 | function factory(type, config, load, typed) {
|
23366 | var matrix = load(__webpack_require__(0));
|
23367 | var algorithm03 = load(__webpack_require__(18));
|
23368 | var algorithm07 = load(__webpack_require__(29));
|
23369 | var algorithm12 = load(__webpack_require__(19));
|
23370 | var algorithm13 = load(__webpack_require__(7));
|
23371 | var algorithm14 = load(__webpack_require__(6));
|
23372 |
|
23373 | var latex = __webpack_require__(4);
|
23374 | |
23375 |
|
23376 |
|
23377 |
|
23378 |
|
23379 |
|
23380 |
|
23381 |
|
23382 |
|
23383 |
|
23384 |
|
23385 |
|
23386 |
|
23387 |
|
23388 |
|
23389 |
|
23390 |
|
23391 |
|
23392 |
|
23393 |
|
23394 |
|
23395 |
|
23396 |
|
23397 |
|
23398 |
|
23399 |
|
23400 |
|
23401 |
|
23402 |
|
23403 |
|
23404 |
|
23405 |
|
23406 |
|
23407 |
|
23408 |
|
23409 |
|
23410 |
|
23411 |
|
23412 |
|
23413 |
|
23414 |
|
23415 |
|
23416 |
|
23417 |
|
23418 |
|
23419 | var unequal = typed('unequal', {
|
23420 | 'any, any': function anyAny(x, y) {
|
23421 |
|
23422 | if (x === null) {
|
23423 | return y !== null;
|
23424 | }
|
23425 |
|
23426 | if (y === null) {
|
23427 | return x !== null;
|
23428 | }
|
23429 |
|
23430 | if (x === undefined) {
|
23431 | return y !== undefined;
|
23432 | }
|
23433 |
|
23434 | if (y === undefined) {
|
23435 | return x !== undefined;
|
23436 | }
|
23437 |
|
23438 | return _unequal(x, y);
|
23439 | },
|
23440 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
23441 | return algorithm07(x, y, _unequal);
|
23442 | },
|
23443 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
23444 | return algorithm03(y, x, _unequal, true);
|
23445 | },
|
23446 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
23447 | return algorithm03(x, y, _unequal, false);
|
23448 | },
|
23449 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
23450 | return algorithm13(x, y, _unequal);
|
23451 | },
|
23452 | 'Array, Array': function ArrayArray(x, y) {
|
23453 |
|
23454 | return unequal(matrix(x), matrix(y)).valueOf();
|
23455 | },
|
23456 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
23457 |
|
23458 | return unequal(matrix(x), y);
|
23459 | },
|
23460 | 'Matrix, Array': function MatrixArray(x, y) {
|
23461 |
|
23462 | return unequal(x, matrix(y));
|
23463 | },
|
23464 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
23465 | return algorithm12(x, y, _unequal, false);
|
23466 | },
|
23467 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
23468 | return algorithm14(x, y, _unequal, false);
|
23469 | },
|
23470 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
23471 | return algorithm12(y, x, _unequal, true);
|
23472 | },
|
23473 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
23474 | return algorithm14(y, x, _unequal, true);
|
23475 | },
|
23476 | 'Array, any': function ArrayAny(x, y) {
|
23477 |
|
23478 | return algorithm14(matrix(x), y, _unequal, false).valueOf();
|
23479 | },
|
23480 | 'any, Array': function anyArray(x, y) {
|
23481 |
|
23482 | return algorithm14(matrix(y), x, _unequal, true).valueOf();
|
23483 | }
|
23484 | });
|
23485 |
|
23486 | var _unequal = typed('_unequal', {
|
23487 | 'boolean, boolean': function booleanBoolean(x, y) {
|
23488 | return x !== y;
|
23489 | },
|
23490 | 'number, number': function numberNumber(x, y) {
|
23491 | return !nearlyEqual(x, y, config.epsilon);
|
23492 | },
|
23493 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
23494 | return !bigNearlyEqual(x, y, config.epsilon);
|
23495 | },
|
23496 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
23497 | return !x.equals(y);
|
23498 | },
|
23499 | 'Complex, Complex': function ComplexComplex(x, y) {
|
23500 | return !x.equals(y);
|
23501 | },
|
23502 | 'Unit, Unit': function UnitUnit(x, y) {
|
23503 | if (!x.equalBase(y)) {
|
23504 | throw new Error('Cannot compare units with different base');
|
23505 | }
|
23506 |
|
23507 | return unequal(x.value, y.value);
|
23508 | }
|
23509 | });
|
23510 |
|
23511 | unequal.toTex = {
|
23512 | 2: "\\left(${args[0]}".concat(latex.operators['unequal'], "${args[1]}\\right)")
|
23513 | };
|
23514 | return unequal;
|
23515 | }
|
23516 |
|
23517 | exports.name = 'unequal';
|
23518 | exports.factory = factory;
|
23519 |
|
23520 | }),
|
23521 |
|
23522 | (function(module, exports, __webpack_require__) {
|
23523 |
|
23524 | "use strict";
|
23525 |
|
23526 |
|
23527 | var number = __webpack_require__(3);
|
23528 |
|
23529 | var deepMap = __webpack_require__(1);
|
23530 |
|
23531 | function factory(type, config, load, typed) {
|
23532 | |
23533 |
|
23534 |
|
23535 |
|
23536 |
|
23537 |
|
23538 |
|
23539 |
|
23540 |
|
23541 |
|
23542 |
|
23543 |
|
23544 |
|
23545 |
|
23546 |
|
23547 |
|
23548 |
|
23549 |
|
23550 |
|
23551 |
|
23552 |
|
23553 |
|
23554 |
|
23555 |
|
23556 |
|
23557 |
|
23558 |
|
23559 |
|
23560 |
|
23561 |
|
23562 | var sign = typed('sign', {
|
23563 | 'number': number.sign,
|
23564 | 'Complex': function Complex(x) {
|
23565 | return x.sign();
|
23566 | },
|
23567 | 'BigNumber': function BigNumber(x) {
|
23568 | return new type.BigNumber(x.cmp(0));
|
23569 | },
|
23570 | 'Fraction': function Fraction(x) {
|
23571 | return new type.Fraction(x.s, 1);
|
23572 | },
|
23573 | 'Array | Matrix': function ArrayMatrix(x) {
|
23574 |
|
23575 | return deepMap(x, sign, true);
|
23576 | },
|
23577 | 'Unit': function Unit(x) {
|
23578 | return sign(x.value);
|
23579 | }
|
23580 | });
|
23581 | sign.toTex = {
|
23582 | 1: "\\mathrm{${name}}\\left(${args[0]}\\right)"
|
23583 | };
|
23584 | return sign;
|
23585 | }
|
23586 |
|
23587 | exports.name = 'sign';
|
23588 | exports.factory = factory;
|
23589 |
|
23590 | }),
|
23591 |
|
23592 | (function(module, exports, __webpack_require__) {
|
23593 |
|
23594 | "use strict";
|
23595 |
|
23596 |
|
23597 | var util = __webpack_require__(31);
|
23598 |
|
23599 | var number = util.number;
|
23600 | var isInteger = number.isInteger;
|
23601 |
|
23602 | function factory(type, config, load, typed) {
|
23603 | var csSqr = load(__webpack_require__(209));
|
23604 | var csLu = load(__webpack_require__(217));
|
23605 | |
23606 |
|
23607 |
|
23608 |
|
23609 |
|
23610 |
|
23611 |
|
23612 |
|
23613 |
|
23614 |
|
23615 |
|
23616 |
|
23617 |
|
23618 |
|
23619 |
|
23620 |
|
23621 |
|
23622 |
|
23623 |
|
23624 |
|
23625 |
|
23626 |
|
23627 |
|
23628 |
|
23629 |
|
23630 |
|
23631 |
|
23632 |
|
23633 |
|
23634 |
|
23635 |
|
23636 |
|
23637 |
|
23638 |
|
23639 |
|
23640 |
|
23641 |
|
23642 |
|
23643 | var slu = typed('slu', {
|
23644 | 'SparseMatrix, number, number': function SparseMatrixNumberNumber(a, order, threshold) {
|
23645 |
|
23646 | if (!isInteger(order) || order < 0 || order > 3) {
|
23647 | throw new Error('Symbolic Ordering and Analysis order must be an integer number in the interval [0, 3]');
|
23648 | }
|
23649 |
|
23650 |
|
23651 | if (threshold < 0 || threshold > 1) {
|
23652 | throw new Error('Partial pivoting threshold must be a number from 0 to 1');
|
23653 | }
|
23654 |
|
23655 |
|
23656 | var s = csSqr(order, a, false);
|
23657 |
|
23658 | var f = csLu(a, s, threshold);
|
23659 |
|
23660 | return {
|
23661 | L: f.L,
|
23662 | U: f.U,
|
23663 | p: f.pinv,
|
23664 | q: s.q,
|
23665 | toString: function toString() {
|
23666 | return 'L: ' + this.L.toString() + '\nU: ' + this.U.toString() + '\np: ' + this.p.toString() + (this.q ? '\nq: ' + this.q.toString() : '') + '\n';
|
23667 | }
|
23668 | };
|
23669 | }
|
23670 | });
|
23671 | return slu;
|
23672 | }
|
23673 |
|
23674 | exports.name = 'slu';
|
23675 | exports.factory = factory;
|
23676 |
|
23677 | }),
|
23678 |
|
23679 | (function(module, exports, __webpack_require__) {
|
23680 |
|
23681 | "use strict";
|
23682 |
|
23683 |
|
23684 | function factory() {
|
23685 | |
23686 |
|
23687 |
|
23688 |
|
23689 |
|
23690 |
|
23691 |
|
23692 |
|
23693 |
|
23694 |
|
23695 |
|
23696 |
|
23697 |
|
23698 | var csTdfs = function csTdfs(j, k, w, head, next, post, stack) {
|
23699 |
|
23700 | var top = 0;
|
23701 |
|
23702 | w[stack] = j;
|
23703 |
|
23704 | while (top >= 0) {
|
23705 |
|
23706 | var p = w[stack + top];
|
23707 |
|
23708 | var i = w[head + p];
|
23709 |
|
23710 | if (i === -1) {
|
23711 |
|
23712 | top--;
|
23713 |
|
23714 | post[k++] = p;
|
23715 | } else {
|
23716 |
|
23717 | w[head + p] = w[next + i];
|
23718 |
|
23719 | ++top;
|
23720 |
|
23721 | w[stack + top] = i;
|
23722 | }
|
23723 | }
|
23724 |
|
23725 | return k;
|
23726 | };
|
23727 |
|
23728 | return csTdfs;
|
23729 | }
|
23730 |
|
23731 | exports.name = 'csTdfs';
|
23732 | exports.path = 'algebra.sparse';
|
23733 | exports.factory = factory;
|
23734 |
|
23735 | }),
|
23736 |
|
23737 | (function(module, exports, __webpack_require__) {
|
23738 |
|
23739 | "use strict";
|
23740 |
|
23741 |
|
23742 | function factory() {
|
23743 | |
23744 |
|
23745 |
|
23746 |
|
23747 |
|
23748 |
|
23749 |
|
23750 |
|
23751 | var csMarked = function csMarked(w, j) {
|
23752 |
|
23753 | return w[j] < 0;
|
23754 | };
|
23755 |
|
23756 | return csMarked;
|
23757 | }
|
23758 |
|
23759 | exports.name = 'csMarked';
|
23760 | exports.path = 'algebra.sparse';
|
23761 | exports.factory = factory;
|
23762 |
|
23763 | }),
|
23764 |
|
23765 | (function(module, exports, __webpack_require__) {
|
23766 |
|
23767 | "use strict";
|
23768 |
|
23769 |
|
23770 | function factory(type, config, load) {
|
23771 | var csFlip = load(__webpack_require__(88));
|
23772 | |
23773 |
|
23774 |
|
23775 |
|
23776 |
|
23777 |
|
23778 |
|
23779 |
|
23780 |
|
23781 | var csMark = function csMark(w, j) {
|
23782 |
|
23783 | w[j] = csFlip(w[j]);
|
23784 | };
|
23785 |
|
23786 | return csMark;
|
23787 | }
|
23788 |
|
23789 | exports.name = 'csMark';
|
23790 | exports.path = 'algebra.sparse';
|
23791 | exports.factory = factory;
|
23792 |
|
23793 | }),
|
23794 |
|
23795 | (function(module, exports, __webpack_require__) {
|
23796 |
|
23797 | "use strict";
|
23798 |
|
23799 |
|
23800 | function factory(type, config, load, typed) {
|
23801 | var matrix = load(__webpack_require__(0));
|
23802 | var divideScalar = load(__webpack_require__(12));
|
23803 | var multiplyScalar = load(__webpack_require__(21));
|
23804 | var subtract = load(__webpack_require__(15));
|
23805 | var equalScalar = load(__webpack_require__(11));
|
23806 | var solveValidation = load(__webpack_require__(90));
|
23807 | var DenseMatrix = type.DenseMatrix;
|
23808 | |
23809 |
|
23810 |
|
23811 |
|
23812 |
|
23813 |
|
23814 |
|
23815 |
|
23816 |
|
23817 |
|
23818 |
|
23819 |
|
23820 |
|
23821 |
|
23822 |
|
23823 |
|
23824 |
|
23825 |
|
23826 |
|
23827 |
|
23828 |
|
23829 |
|
23830 |
|
23831 |
|
23832 |
|
23833 | var lsolve = typed('lsolve', {
|
23834 | 'SparseMatrix, Array | Matrix': function SparseMatrixArrayMatrix(m, b) {
|
23835 |
|
23836 | return _sparseForwardSubstitution(m, b);
|
23837 | },
|
23838 | 'DenseMatrix, Array | Matrix': function DenseMatrixArrayMatrix(m, b) {
|
23839 |
|
23840 | return _denseForwardSubstitution(m, b);
|
23841 | },
|
23842 | 'Array, Array | Matrix': function ArrayArrayMatrix(a, b) {
|
23843 |
|
23844 | var m = matrix(a);
|
23845 |
|
23846 | var r = _denseForwardSubstitution(m, b);
|
23847 |
|
23848 |
|
23849 | return r.valueOf();
|
23850 | }
|
23851 | });
|
23852 |
|
23853 | function _denseForwardSubstitution(m, b) {
|
23854 |
|
23855 | b = solveValidation(m, b, true);
|
23856 |
|
23857 | var bdata = b._data;
|
23858 |
|
23859 | var rows = m._size[0];
|
23860 | var columns = m._size[1];
|
23861 |
|
23862 | var x = [];
|
23863 |
|
23864 | var data = m._data;
|
23865 |
|
23866 | for (var j = 0; j < columns; j++) {
|
23867 |
|
23868 | var bj = bdata[j][0] || 0;
|
23869 |
|
23870 | var xj = void 0;
|
23871 |
|
23872 | if (!equalScalar(bj, 0)) {
|
23873 |
|
23874 | var vjj = data[j][j];
|
23875 |
|
23876 | if (equalScalar(vjj, 0)) {
|
23877 |
|
23878 | throw new Error('Linear system cannot be solved since matrix is singular');
|
23879 | }
|
23880 |
|
23881 |
|
23882 | xj = divideScalar(bj, vjj);
|
23883 |
|
23884 | for (var i = j + 1; i < rows; i++) {
|
23885 |
|
23886 | bdata[i] = [subtract(bdata[i][0] || 0, multiplyScalar(xj, data[i][j]))];
|
23887 | }
|
23888 | } else {
|
23889 |
|
23890 | xj = 0;
|
23891 | }
|
23892 |
|
23893 |
|
23894 | x[j] = [xj];
|
23895 | }
|
23896 |
|
23897 |
|
23898 | return new DenseMatrix({
|
23899 | data: x,
|
23900 | size: [rows, 1]
|
23901 | });
|
23902 | }
|
23903 |
|
23904 | function _sparseForwardSubstitution(m, b) {
|
23905 |
|
23906 | b = solveValidation(m, b, true);
|
23907 |
|
23908 | var bdata = b._data;
|
23909 |
|
23910 | var rows = m._size[0];
|
23911 | var columns = m._size[1];
|
23912 |
|
23913 | var values = m._values;
|
23914 | var index = m._index;
|
23915 | var ptr = m._ptr;
|
23916 |
|
23917 | var i, k;
|
23918 |
|
23919 | var x = [];
|
23920 |
|
23921 | for (var j = 0; j < columns; j++) {
|
23922 |
|
23923 | var bj = bdata[j][0] || 0;
|
23924 |
|
23925 | if (!equalScalar(bj, 0)) {
|
23926 |
|
23927 | var vjj = 0;
|
23928 |
|
23929 | var jvalues = [];
|
23930 | var jindex = [];
|
23931 |
|
23932 | var l = ptr[j + 1];
|
23933 |
|
23934 | for (k = ptr[j]; k < l; k++) {
|
23935 |
|
23936 | i = index[k];
|
23937 |
|
23938 | if (i === j) {
|
23939 |
|
23940 | vjj = values[k];
|
23941 | } else if (i > j) {
|
23942 |
|
23943 | jvalues.push(values[k]);
|
23944 | jindex.push(i);
|
23945 | }
|
23946 | }
|
23947 |
|
23948 |
|
23949 | if (equalScalar(vjj, 0)) {
|
23950 |
|
23951 | throw new Error('Linear system cannot be solved since matrix is singular');
|
23952 | }
|
23953 |
|
23954 |
|
23955 | var xj = divideScalar(bj, vjj);
|
23956 |
|
23957 | for (k = 0, l = jindex.length; k < l; k++) {
|
23958 |
|
23959 | i = jindex[k];
|
23960 |
|
23961 | bdata[i] = [subtract(bdata[i][0] || 0, multiplyScalar(xj, jvalues[k]))];
|
23962 | }
|
23963 |
|
23964 |
|
23965 | x[j] = [xj];
|
23966 | } else {
|
23967 |
|
23968 | x[j] = [0];
|
23969 | }
|
23970 | }
|
23971 |
|
23972 |
|
23973 | return new DenseMatrix({
|
23974 | data: x,
|
23975 | size: [rows, 1]
|
23976 | });
|
23977 | }
|
23978 |
|
23979 | return lsolve;
|
23980 | }
|
23981 |
|
23982 | exports.name = 'lsolve';
|
23983 | exports.factory = factory;
|
23984 |
|
23985 | }),
|
23986 |
|
23987 | (function(module, exports, __webpack_require__) {
|
23988 |
|
23989 | "use strict";
|
23990 |
|
23991 |
|
23992 | function factory(type, config, load, typed) {
|
23993 | var matrix = load(__webpack_require__(0));
|
23994 | var divideScalar = load(__webpack_require__(12));
|
23995 | var multiplyScalar = load(__webpack_require__(21));
|
23996 | var subtract = load(__webpack_require__(15));
|
23997 | var equalScalar = load(__webpack_require__(11));
|
23998 | var solveValidation = load(__webpack_require__(90));
|
23999 | var DenseMatrix = type.DenseMatrix;
|
24000 | |
24001 |
|
24002 |
|
24003 |
|
24004 |
|
24005 |
|
24006 |
|
24007 |
|
24008 |
|
24009 |
|
24010 |
|
24011 |
|
24012 |
|
24013 |
|
24014 |
|
24015 |
|
24016 |
|
24017 |
|
24018 |
|
24019 |
|
24020 |
|
24021 |
|
24022 |
|
24023 |
|
24024 |
|
24025 | var usolve = typed('usolve', {
|
24026 | 'SparseMatrix, Array | Matrix': function SparseMatrixArrayMatrix(m, b) {
|
24027 |
|
24028 | return _sparseBackwardSubstitution(m, b);
|
24029 | },
|
24030 | 'DenseMatrix, Array | Matrix': function DenseMatrixArrayMatrix(m, b) {
|
24031 |
|
24032 | return _denseBackwardSubstitution(m, b);
|
24033 | },
|
24034 | 'Array, Array | Matrix': function ArrayArrayMatrix(a, b) {
|
24035 |
|
24036 | var m = matrix(a);
|
24037 |
|
24038 | var r = _denseBackwardSubstitution(m, b);
|
24039 |
|
24040 |
|
24041 | return r.valueOf();
|
24042 | }
|
24043 | });
|
24044 |
|
24045 | function _denseBackwardSubstitution(m, b) {
|
24046 |
|
24047 | b = solveValidation(m, b, true);
|
24048 |
|
24049 | var bdata = b._data;
|
24050 |
|
24051 | var rows = m._size[0];
|
24052 | var columns = m._size[1];
|
24053 |
|
24054 | var x = [];
|
24055 |
|
24056 | var data = m._data;
|
24057 |
|
24058 | for (var j = columns - 1; j >= 0; j--) {
|
24059 |
|
24060 | var bj = bdata[j][0] || 0;
|
24061 |
|
24062 | var xj = void 0;
|
24063 |
|
24064 | if (!equalScalar(bj, 0)) {
|
24065 |
|
24066 | var vjj = data[j][j];
|
24067 |
|
24068 | if (equalScalar(vjj, 0)) {
|
24069 |
|
24070 | throw new Error('Linear system cannot be solved since matrix is singular');
|
24071 | }
|
24072 |
|
24073 |
|
24074 | xj = divideScalar(bj, vjj);
|
24075 |
|
24076 | for (var i = j - 1; i >= 0; i--) {
|
24077 |
|
24078 | bdata[i] = [subtract(bdata[i][0] || 0, multiplyScalar(xj, data[i][j]))];
|
24079 | }
|
24080 | } else {
|
24081 |
|
24082 | xj = 0;
|
24083 | }
|
24084 |
|
24085 |
|
24086 | x[j] = [xj];
|
24087 | }
|
24088 |
|
24089 |
|
24090 | return new DenseMatrix({
|
24091 | data: x,
|
24092 | size: [rows, 1]
|
24093 | });
|
24094 | }
|
24095 |
|
24096 | function _sparseBackwardSubstitution(m, b) {
|
24097 |
|
24098 | b = solveValidation(m, b, true);
|
24099 |
|
24100 | var bdata = b._data;
|
24101 |
|
24102 | var rows = m._size[0];
|
24103 | var columns = m._size[1];
|
24104 |
|
24105 | var values = m._values;
|
24106 | var index = m._index;
|
24107 | var ptr = m._ptr;
|
24108 |
|
24109 | var i, k;
|
24110 |
|
24111 | var x = [];
|
24112 |
|
24113 | for (var j = columns - 1; j >= 0; j--) {
|
24114 |
|
24115 | var bj = bdata[j][0] || 0;
|
24116 |
|
24117 | if (!equalScalar(bj, 0)) {
|
24118 |
|
24119 | var vjj = 0;
|
24120 |
|
24121 | var jvalues = [];
|
24122 | var jindex = [];
|
24123 |
|
24124 | var f = ptr[j];
|
24125 | var l = ptr[j + 1];
|
24126 |
|
24127 | for (k = l - 1; k >= f; k--) {
|
24128 |
|
24129 | i = index[k];
|
24130 |
|
24131 | if (i === j) {
|
24132 |
|
24133 | vjj = values[k];
|
24134 | } else if (i < j) {
|
24135 |
|
24136 | jvalues.push(values[k]);
|
24137 | jindex.push(i);
|
24138 | }
|
24139 | }
|
24140 |
|
24141 |
|
24142 | if (equalScalar(vjj, 0)) {
|
24143 |
|
24144 | throw new Error('Linear system cannot be solved since matrix is singular');
|
24145 | }
|
24146 |
|
24147 |
|
24148 | var xj = divideScalar(bj, vjj);
|
24149 |
|
24150 | for (k = 0, l = jindex.length; k < l; k++) {
|
24151 |
|
24152 | i = jindex[k];
|
24153 |
|
24154 | bdata[i] = [subtract(bdata[i][0], multiplyScalar(xj, jvalues[k]))];
|
24155 | }
|
24156 |
|
24157 |
|
24158 | x[j] = [xj];
|
24159 | } else {
|
24160 |
|
24161 | x[j] = [0];
|
24162 | }
|
24163 | }
|
24164 |
|
24165 |
|
24166 | return new DenseMatrix({
|
24167 | data: x,
|
24168 | size: [rows, 1]
|
24169 | });
|
24170 | }
|
24171 |
|
24172 | return usolve;
|
24173 | }
|
24174 |
|
24175 | exports.name = 'usolve';
|
24176 | exports.factory = factory;
|
24177 |
|
24178 | }),
|
24179 |
|
24180 | (function(module, exports, __webpack_require__) {
|
24181 |
|
24182 | "use strict";
|
24183 |
|
24184 |
|
24185 | function factory(type, config, load, typed) {
|
24186 | var matrix = load(__webpack_require__(0));
|
24187 | var divideScalar = load(__webpack_require__(12));
|
24188 |
|
24189 | var latex = __webpack_require__(4);
|
24190 |
|
24191 | var algorithm02 = load(__webpack_require__(27));
|
24192 | var algorithm03 = load(__webpack_require__(18));
|
24193 | var algorithm07 = load(__webpack_require__(29));
|
24194 | var algorithm11 = load(__webpack_require__(20));
|
24195 | var algorithm12 = load(__webpack_require__(19));
|
24196 | var algorithm13 = load(__webpack_require__(7));
|
24197 | var algorithm14 = load(__webpack_require__(6));
|
24198 | |
24199 |
|
24200 |
|
24201 |
|
24202 |
|
24203 |
|
24204 |
|
24205 |
|
24206 |
|
24207 |
|
24208 |
|
24209 |
|
24210 |
|
24211 |
|
24212 |
|
24213 |
|
24214 |
|
24215 |
|
24216 |
|
24217 |
|
24218 |
|
24219 |
|
24220 |
|
24221 |
|
24222 |
|
24223 |
|
24224 |
|
24225 | var dotDivide = typed('dotDivide', {
|
24226 | 'any, any': divideScalar,
|
24227 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
24228 | return algorithm07(x, y, divideScalar, false);
|
24229 | },
|
24230 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
24231 | return algorithm02(y, x, divideScalar, true);
|
24232 | },
|
24233 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
24234 | return algorithm03(x, y, divideScalar, false);
|
24235 | },
|
24236 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
24237 | return algorithm13(x, y, divideScalar);
|
24238 | },
|
24239 | 'Array, Array': function ArrayArray(x, y) {
|
24240 |
|
24241 | return dotDivide(matrix(x), matrix(y)).valueOf();
|
24242 | },
|
24243 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
24244 |
|
24245 | return dotDivide(matrix(x), y);
|
24246 | },
|
24247 | 'Matrix, Array': function MatrixArray(x, y) {
|
24248 |
|
24249 | return dotDivide(x, matrix(y));
|
24250 | },
|
24251 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
24252 | return algorithm11(x, y, divideScalar, false);
|
24253 | },
|
24254 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
24255 | return algorithm14(x, y, divideScalar, false);
|
24256 | },
|
24257 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
24258 | return algorithm12(y, x, divideScalar, true);
|
24259 | },
|
24260 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
24261 | return algorithm14(y, x, divideScalar, true);
|
24262 | },
|
24263 | 'Array, any': function ArrayAny(x, y) {
|
24264 |
|
24265 | return algorithm14(matrix(x), y, divideScalar, false).valueOf();
|
24266 | },
|
24267 | 'any, Array': function anyArray(x, y) {
|
24268 |
|
24269 | return algorithm14(matrix(y), x, divideScalar, true).valueOf();
|
24270 | }
|
24271 | });
|
24272 | dotDivide.toTex = {
|
24273 | 2: "\\left(${args[0]}".concat(latex.operators['dotDivide'], "${args[1]}\\right)")
|
24274 | };
|
24275 | return dotDivide;
|
24276 | }
|
24277 |
|
24278 | exports.name = 'dotDivide';
|
24279 | exports.factory = factory;
|
24280 |
|
24281 | }),
|
24282 |
|
24283 | (function(module, exports, __webpack_require__) {
|
24284 |
|
24285 | "use strict";
|
24286 |
|
24287 |
|
24288 | var DimensionError = __webpack_require__(8);
|
24289 |
|
24290 | function factory(type, config, load, typed) {
|
24291 | var equalScalar = load(__webpack_require__(11));
|
24292 | var SparseMatrix = type.SparseMatrix;
|
24293 | |
24294 |
|
24295 |
|
24296 |
|
24297 |
|
24298 |
|
24299 |
|
24300 |
|
24301 |
|
24302 |
|
24303 |
|
24304 |
|
24305 |
|
24306 |
|
24307 |
|
24308 |
|
24309 |
|
24310 |
|
24311 |
|
24312 | var algorithm09 = function algorithm09(a, b, callback) {
|
24313 |
|
24314 | var avalues = a._values;
|
24315 | var aindex = a._index;
|
24316 | var aptr = a._ptr;
|
24317 | var asize = a._size;
|
24318 | var adt = a._datatype;
|
24319 |
|
24320 | var bvalues = b._values;
|
24321 | var bindex = b._index;
|
24322 | var bptr = b._ptr;
|
24323 | var bsize = b._size;
|
24324 | var bdt = b._datatype;
|
24325 |
|
24326 | if (asize.length !== bsize.length) {
|
24327 | throw new DimensionError(asize.length, bsize.length);
|
24328 | }
|
24329 |
|
24330 |
|
24331 | if (asize[0] !== bsize[0] || asize[1] !== bsize[1]) {
|
24332 | throw new RangeError('Dimension mismatch. Matrix A (' + asize + ') must match Matrix B (' + bsize + ')');
|
24333 | }
|
24334 |
|
24335 |
|
24336 | var rows = asize[0];
|
24337 | var columns = asize[1];
|
24338 |
|
24339 | var dt;
|
24340 |
|
24341 | var eq = equalScalar;
|
24342 |
|
24343 | var zero = 0;
|
24344 |
|
24345 | var cf = callback;
|
24346 |
|
24347 | if (typeof adt === 'string' && adt === bdt) {
|
24348 |
|
24349 | dt = adt;
|
24350 |
|
24351 | eq = typed.find(equalScalar, [dt, dt]);
|
24352 |
|
24353 | zero = typed.convert(0, dt);
|
24354 |
|
24355 | cf = typed.find(callback, [dt, dt]);
|
24356 | }
|
24357 |
|
24358 |
|
24359 | var cvalues = avalues && bvalues ? [] : undefined;
|
24360 | var cindex = [];
|
24361 | var cptr = [];
|
24362 |
|
24363 | var c = new SparseMatrix({
|
24364 | values: cvalues,
|
24365 | index: cindex,
|
24366 | ptr: cptr,
|
24367 | size: [rows, columns],
|
24368 | datatype: dt
|
24369 | });
|
24370 |
|
24371 | var x = cvalues ? [] : undefined;
|
24372 |
|
24373 | var w = [];
|
24374 |
|
24375 | var i, j, k, k0, k1;
|
24376 |
|
24377 | for (j = 0; j < columns; j++) {
|
24378 |
|
24379 | cptr[j] = cindex.length;
|
24380 |
|
24381 | var mark = j + 1;
|
24382 |
|
24383 | if (x) {
|
24384 |
|
24385 | for (k0 = bptr[j], k1 = bptr[j + 1], k = k0; k < k1; k++) {
|
24386 |
|
24387 | i = bindex[k];
|
24388 |
|
24389 | w[i] = mark;
|
24390 | x[i] = bvalues[k];
|
24391 | }
|
24392 | }
|
24393 |
|
24394 |
|
24395 | for (k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
|
24396 |
|
24397 | i = aindex[k];
|
24398 |
|
24399 | if (x) {
|
24400 |
|
24401 | var vb = w[i] === mark ? x[i] : zero;
|
24402 |
|
24403 | var vc = cf(avalues[k], vb);
|
24404 |
|
24405 | if (!eq(vc, zero)) {
|
24406 |
|
24407 | cindex.push(i);
|
24408 |
|
24409 | cvalues.push(vc);
|
24410 | }
|
24411 | } else {
|
24412 |
|
24413 | cindex.push(i);
|
24414 | }
|
24415 | }
|
24416 | }
|
24417 |
|
24418 |
|
24419 | cptr[columns] = cindex.length;
|
24420 |
|
24421 | return c;
|
24422 | };
|
24423 |
|
24424 | return algorithm09;
|
24425 | }
|
24426 |
|
24427 | exports.name = 'algorithm09';
|
24428 | exports.factory = factory;
|
24429 |
|
24430 | }),
|
24431 |
|
24432 | (function(module, exports, __webpack_require__) {
|
24433 |
|
24434 | "use strict";
|
24435 |
|
24436 |
|
24437 | function factory(type, config, load, typed) {
|
24438 | var add = load(__webpack_require__(14));
|
24439 | var subtract = load(__webpack_require__(15));
|
24440 | var multiply = load(__webpack_require__(10));
|
24441 | var divide = load(__webpack_require__(45));
|
24442 | var pow = load(__webpack_require__(42));
|
24443 | var factorial = load(__webpack_require__(75));
|
24444 | var combinations = load(__webpack_require__(76));
|
24445 | var isNegative = load(__webpack_require__(61));
|
24446 | var isInteger = load(__webpack_require__(34));
|
24447 | var larger = load(__webpack_require__(33));
|
24448 | |
24449 |
|
24450 |
|
24451 |
|
24452 |
|
24453 |
|
24454 |
|
24455 |
|
24456 |
|
24457 |
|
24458 |
|
24459 |
|
24460 |
|
24461 |
|
24462 |
|
24463 |
|
24464 |
|
24465 |
|
24466 |
|
24467 |
|
24468 |
|
24469 |
|
24470 |
|
24471 |
|
24472 |
|
24473 | var stirlingS2 = typed('stirlingS2', {
|
24474 | 'number | BigNumber, number | BigNumber': function numberBigNumberNumberBigNumber(n, k) {
|
24475 | if (!isInteger(n) || isNegative(n) || !isInteger(k) || isNegative(k)) {
|
24476 | throw new TypeError('Non-negative integer value expected in function stirlingS2');
|
24477 | } else if (larger(k, n)) {
|
24478 | throw new TypeError('k must be less than or equal to n in function stirlingS2');
|
24479 | }
|
24480 |
|
24481 |
|
24482 | var kFactorial = factorial(k);
|
24483 | var result = 0;
|
24484 |
|
24485 | for (var i = 0; i <= k; i++) {
|
24486 | var negativeOne = pow(-1, subtract(k, i));
|
24487 | var kChooseI = combinations(k, i);
|
24488 | var iPower = pow(i, n);
|
24489 | result = add(result, multiply(multiply(kChooseI, iPower), negativeOne));
|
24490 | }
|
24491 |
|
24492 | return divide(result, kFactorial);
|
24493 | }
|
24494 | });
|
24495 | stirlingS2.toTex = {
|
24496 | 2: "\\mathrm{S}\\left(${args}\\right)"
|
24497 | };
|
24498 | return stirlingS2;
|
24499 | }
|
24500 |
|
24501 | exports.name = 'stirlingS2';
|
24502 | exports.factory = factory;
|
24503 |
|
24504 | }),
|
24505 |
|
24506 | (function(module, exports, __webpack_require__) {
|
24507 |
|
24508 | "use strict";
|
24509 |
|
24510 |
|
24511 | var deepMap = __webpack_require__(1);
|
24512 |
|
24513 | var isInteger = __webpack_require__(3).isInteger;
|
24514 |
|
24515 | function factory(type, config, load, typed) {
|
24516 | var multiply = load(__webpack_require__(10));
|
24517 | var pow = load(__webpack_require__(42));
|
24518 |
|
24519 | var product = __webpack_require__(95);
|
24520 | |
24521 |
|
24522 |
|
24523 |
|
24524 |
|
24525 |
|
24526 |
|
24527 |
|
24528 |
|
24529 |
|
24530 |
|
24531 |
|
24532 |
|
24533 |
|
24534 |
|
24535 |
|
24536 |
|
24537 |
|
24538 |
|
24539 |
|
24540 |
|
24541 |
|
24542 |
|
24543 |
|
24544 |
|
24545 | var gamma = typed('gamma', {
|
24546 | 'number': function number(n) {
|
24547 | var t, x;
|
24548 |
|
24549 | if (isInteger(n)) {
|
24550 | if (n <= 0) {
|
24551 | return isFinite(n) ? Infinity : NaN;
|
24552 | }
|
24553 |
|
24554 | if (n > 171) {
|
24555 | return Infinity;
|
24556 | }
|
24557 |
|
24558 | return product(1, n - 1);
|
24559 | }
|
24560 |
|
24561 | if (n < 0.5) {
|
24562 | return Math.PI / (Math.sin(Math.PI * n) * gamma(1 - n));
|
24563 | }
|
24564 |
|
24565 | if (n >= 171.35) {
|
24566 | return Infinity;
|
24567 | }
|
24568 |
|
24569 | if (n > 85.0) {
|
24570 |
|
24571 | var twoN = n * n;
|
24572 | var threeN = twoN * n;
|
24573 | var fourN = threeN * n;
|
24574 | var fiveN = fourN * n;
|
24575 | return Math.sqrt(2 * Math.PI / n) * Math.pow(n / Math.E, n) * (1 + 1 / (12 * n) + 1 / (288 * twoN) - 139 / (51840 * threeN) - 571 / (2488320 * fourN) + 163879 / (209018880 * fiveN) + 5246819 / (75246796800 * fiveN * n));
|
24576 | }
|
24577 |
|
24578 | --n;
|
24579 | x = p[0];
|
24580 |
|
24581 | for (var i = 1; i < p.length; ++i) {
|
24582 | x += p[i] / (n + i);
|
24583 | }
|
24584 |
|
24585 | t = n + g + 0.5;
|
24586 | return Math.sqrt(2 * Math.PI) * Math.pow(t, n + 0.5) * Math.exp(-t) * x;
|
24587 | },
|
24588 | 'Complex': function Complex(n) {
|
24589 | var t, x;
|
24590 |
|
24591 | if (n.im === 0) {
|
24592 | return gamma(n.re);
|
24593 | }
|
24594 |
|
24595 | n = new type.Complex(n.re - 1, n.im);
|
24596 | x = new type.Complex(p[0], 0);
|
24597 |
|
24598 | for (var i = 1; i < p.length; ++i) {
|
24599 | var real = n.re + i;
|
24600 |
|
24601 | var den = real * real + n.im * n.im;
|
24602 |
|
24603 | if (den !== 0) {
|
24604 | x.re += p[i] * real / den;
|
24605 | x.im += -(p[i] * n.im) / den;
|
24606 | } else {
|
24607 | x.re = p[i] < 0 ? -Infinity : Infinity;
|
24608 | }
|
24609 | }
|
24610 |
|
24611 | t = new type.Complex(n.re + g + 0.5, n.im);
|
24612 | var twoPiSqrt = Math.sqrt(2 * Math.PI);
|
24613 | n.re += 0.5;
|
24614 | var result = pow(t, n);
|
24615 |
|
24616 | if (result.im === 0) {
|
24617 |
|
24618 | result.re *= twoPiSqrt;
|
24619 | } else if (result.re === 0) {
|
24620 | result.im *= twoPiSqrt;
|
24621 | } else {
|
24622 | result.re *= twoPiSqrt;
|
24623 | result.im *= twoPiSqrt;
|
24624 | }
|
24625 |
|
24626 | var r = Math.exp(-t.re);
|
24627 |
|
24628 | t.re = r * Math.cos(-t.im);
|
24629 | t.im = r * Math.sin(-t.im);
|
24630 | return multiply(multiply(result, t), x);
|
24631 | },
|
24632 | 'BigNumber': function BigNumber(n) {
|
24633 | if (n.isInteger()) {
|
24634 | return n.isNegative() || n.isZero() ? new type.BigNumber(Infinity) : bigFactorial(n.minus(1));
|
24635 | }
|
24636 |
|
24637 | if (!n.isFinite()) {
|
24638 | return new type.BigNumber(n.isNegative() ? NaN : Infinity);
|
24639 | }
|
24640 |
|
24641 | throw new Error('Integer BigNumber expected');
|
24642 | },
|
24643 | 'Array | Matrix': function ArrayMatrix(n) {
|
24644 | return deepMap(n, gamma);
|
24645 | }
|
24646 | });
|
24647 | |
24648 |
|
24649 |
|
24650 |
|
24651 |
|
24652 |
|
24653 | function bigFactorial(n) {
|
24654 | if (n.isZero()) {
|
24655 | return new type.BigNumber(1);
|
24656 | }
|
24657 |
|
24658 | var precision = config.precision + (Math.log(n.toNumber()) | 0);
|
24659 | var Big = type.BigNumber.clone({
|
24660 | precision: precision
|
24661 | });
|
24662 | var res = new Big(n);
|
24663 | var value = n.toNumber() - 1;
|
24664 |
|
24665 | while (value > 1) {
|
24666 | res = res.times(value);
|
24667 | value--;
|
24668 | }
|
24669 |
|
24670 | return new type.BigNumber(res.toPrecision(type.BigNumber.precision));
|
24671 | }
|
24672 |
|
24673 | gamma.toTex = {
|
24674 | 1: "\\Gamma\\left(${args[0]}\\right)"
|
24675 | };
|
24676 | return gamma;
|
24677 | }
|
24678 |
|
24679 |
|
24680 | var g = 4.7421875;
|
24681 | var p = [0.99999999999999709182, 57.156235665862923517, -59.597960355475491248, 14.136097974741747174, -0.49191381609762019978, 0.33994649984811888699e-4, 0.46523628927048575665e-4, -0.98374475304879564677e-4, 0.15808870322491248884e-3, -0.21026444172410488319e-3, 0.21743961811521264320e-3, -0.16431810653676389022e-3, 0.84418223983852743293e-4, -0.26190838401581408670e-4, 0.36899182659531622704e-5];
|
24682 | exports.name = 'gamma';
|
24683 | exports.factory = factory;
|
24684 |
|
24685 | }),
|
24686 |
|
24687 | (function(module, exports, __webpack_require__) {
|
24688 |
|
24689 | "use strict";
|
24690 |
|
24691 |
|
24692 | var deepMap = __webpack_require__(1);
|
24693 |
|
24694 | function factory(type, config, load, typed) {
|
24695 | var latex = __webpack_require__(4);
|
24696 | |
24697 |
|
24698 |
|
24699 |
|
24700 |
|
24701 |
|
24702 |
|
24703 |
|
24704 |
|
24705 |
|
24706 |
|
24707 |
|
24708 |
|
24709 |
|
24710 |
|
24711 |
|
24712 |
|
24713 |
|
24714 |
|
24715 |
|
24716 |
|
24717 |
|
24718 |
|
24719 |
|
24720 |
|
24721 |
|
24722 |
|
24723 | var not = typed('not', {
|
24724 | 'number': function number(x) {
|
24725 | return !x;
|
24726 | },
|
24727 | 'Complex': function Complex(x) {
|
24728 | return x.re === 0 && x.im === 0;
|
24729 | },
|
24730 | 'BigNumber': function BigNumber(x) {
|
24731 | return x.isZero() || x.isNaN();
|
24732 | },
|
24733 | 'Unit': function Unit(x) {
|
24734 | return x.value !== null ? not(x.value) : true;
|
24735 | },
|
24736 | 'Array | Matrix': function ArrayMatrix(x) {
|
24737 | return deepMap(x, not);
|
24738 | }
|
24739 | });
|
24740 | not.toTex = {
|
24741 | 1: latex.operators['not'] + "\\left(${args[0]}\\right)"
|
24742 | };
|
24743 | return not;
|
24744 | }
|
24745 |
|
24746 | exports.name = 'not';
|
24747 | exports.factory = factory;
|
24748 |
|
24749 | }),
|
24750 |
|
24751 | (function(module, exports, __webpack_require__) {
|
24752 |
|
24753 | "use strict";
|
24754 |
|
24755 |
|
24756 | var clone = __webpack_require__(5).clone;
|
24757 |
|
24758 | var validateIndex = __webpack_require__(2).validateIndex;
|
24759 |
|
24760 | function factory(type, config, load, typed) {
|
24761 | var MatrixIndex = load(__webpack_require__(24));
|
24762 | var matrix = load(__webpack_require__(0));
|
24763 | var range = load(__webpack_require__(77));
|
24764 | |
24765 |
|
24766 |
|
24767 |
|
24768 |
|
24769 |
|
24770 |
|
24771 |
|
24772 |
|
24773 |
|
24774 |
|
24775 |
|
24776 |
|
24777 |
|
24778 |
|
24779 |
|
24780 |
|
24781 |
|
24782 |
|
24783 |
|
24784 |
|
24785 |
|
24786 | var column = typed('column', {
|
24787 | 'Matrix, number': _column,
|
24788 | 'Array, number': function ArrayNumber(value, column) {
|
24789 | return _column(matrix(clone(value)), column).valueOf();
|
24790 | }
|
24791 | });
|
24792 | column.toTex = undefined;
|
24793 |
|
24794 | return column;
|
24795 | |
24796 |
|
24797 |
|
24798 |
|
24799 |
|
24800 |
|
24801 |
|
24802 | function _column(value, column) {
|
24803 |
|
24804 | if (value.size().length !== 2) {
|
24805 | throw new Error('Only two dimensional matrix is supported');
|
24806 | }
|
24807 |
|
24808 | validateIndex(column, value.size()[1]);
|
24809 | var rowRange = range(0, value.size()[0]);
|
24810 | var index = new MatrixIndex(rowRange, column);
|
24811 | return value.subset(index);
|
24812 | }
|
24813 | }
|
24814 |
|
24815 | exports.name = 'column';
|
24816 | exports.factory = factory;
|
24817 |
|
24818 | }),
|
24819 |
|
24820 | (function(module, exports, __webpack_require__) {
|
24821 |
|
24822 | "use strict";
|
24823 |
|
24824 |
|
24825 | var nearlyEqual = __webpack_require__(3).nearlyEqual;
|
24826 |
|
24827 | var bigNearlyEqual = __webpack_require__(32);
|
24828 |
|
24829 | function factory(type, config, load, typed) {
|
24830 | var matrix = load(__webpack_require__(0));
|
24831 | var algorithm03 = load(__webpack_require__(18));
|
24832 | var algorithm07 = load(__webpack_require__(29));
|
24833 | var algorithm12 = load(__webpack_require__(19));
|
24834 | var algorithm13 = load(__webpack_require__(7));
|
24835 | var algorithm14 = load(__webpack_require__(6));
|
24836 |
|
24837 | var latex = __webpack_require__(4);
|
24838 | |
24839 |
|
24840 |
|
24841 |
|
24842 |
|
24843 |
|
24844 |
|
24845 |
|
24846 |
|
24847 |
|
24848 |
|
24849 |
|
24850 |
|
24851 |
|
24852 |
|
24853 |
|
24854 |
|
24855 |
|
24856 |
|
24857 |
|
24858 |
|
24859 |
|
24860 |
|
24861 |
|
24862 |
|
24863 |
|
24864 |
|
24865 |
|
24866 |
|
24867 | var smallerEq = typed('smallerEq', {
|
24868 | 'boolean, boolean': function booleanBoolean(x, y) {
|
24869 | return x <= y;
|
24870 | },
|
24871 | 'number, number': function numberNumber(x, y) {
|
24872 | return x <= y || nearlyEqual(x, y, config.epsilon);
|
24873 | },
|
24874 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
24875 | return x.lte(y) || bigNearlyEqual(x, y, config.epsilon);
|
24876 | },
|
24877 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
24878 | return x.compare(y) !== 1;
|
24879 | },
|
24880 | 'Complex, Complex': function ComplexComplex() {
|
24881 | throw new TypeError('No ordering relation is defined for complex numbers');
|
24882 | },
|
24883 | 'Unit, Unit': function UnitUnit(x, y) {
|
24884 | if (!x.equalBase(y)) {
|
24885 | throw new Error('Cannot compare units with different base');
|
24886 | }
|
24887 |
|
24888 | return smallerEq(x.value, y.value);
|
24889 | },
|
24890 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
24891 | return algorithm07(x, y, smallerEq);
|
24892 | },
|
24893 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
24894 | return algorithm03(y, x, smallerEq, true);
|
24895 | },
|
24896 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
24897 | return algorithm03(x, y, smallerEq, false);
|
24898 | },
|
24899 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
24900 | return algorithm13(x, y, smallerEq);
|
24901 | },
|
24902 | 'Array, Array': function ArrayArray(x, y) {
|
24903 |
|
24904 | return smallerEq(matrix(x), matrix(y)).valueOf();
|
24905 | },
|
24906 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
24907 |
|
24908 | return smallerEq(matrix(x), y);
|
24909 | },
|
24910 | 'Matrix, Array': function MatrixArray(x, y) {
|
24911 |
|
24912 | return smallerEq(x, matrix(y));
|
24913 | },
|
24914 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
24915 | return algorithm12(x, y, smallerEq, false);
|
24916 | },
|
24917 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
24918 | return algorithm14(x, y, smallerEq, false);
|
24919 | },
|
24920 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
24921 | return algorithm12(y, x, smallerEq, true);
|
24922 | },
|
24923 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
24924 | return algorithm14(y, x, smallerEq, true);
|
24925 | },
|
24926 | 'Array, any': function ArrayAny(x, y) {
|
24927 |
|
24928 | return algorithm14(matrix(x), y, smallerEq, false).valueOf();
|
24929 | },
|
24930 | 'any, Array': function anyArray(x, y) {
|
24931 |
|
24932 | return algorithm14(matrix(y), x, smallerEq, true).valueOf();
|
24933 | }
|
24934 | });
|
24935 | smallerEq.toTex = {
|
24936 | 2: "\\left(${args[0]}".concat(latex.operators['smallerEq'], "${args[1]}\\right)")
|
24937 | };
|
24938 | return smallerEq;
|
24939 | }
|
24940 |
|
24941 | exports.name = 'smallerEq';
|
24942 | exports.factory = factory;
|
24943 |
|
24944 | }),
|
24945 |
|
24946 | (function(module, exports, __webpack_require__) {
|
24947 |
|
24948 | "use strict";
|
24949 |
|
24950 |
|
24951 | var maxArgumentCount = __webpack_require__(36).maxArgumentCount;
|
24952 |
|
24953 | function factory(type, config, load, typed) {
|
24954 | |
24955 |
|
24956 |
|
24957 |
|
24958 |
|
24959 |
|
24960 |
|
24961 |
|
24962 |
|
24963 |
|
24964 |
|
24965 |
|
24966 |
|
24967 |
|
24968 |
|
24969 |
|
24970 |
|
24971 |
|
24972 |
|
24973 |
|
24974 |
|
24975 |
|
24976 |
|
24977 |
|
24978 | var map = typed('map', {
|
24979 | 'Array, function': _map,
|
24980 | 'Matrix, function': function MatrixFunction(x, callback) {
|
24981 | return x.map(callback);
|
24982 | }
|
24983 | });
|
24984 | map.toTex = undefined;
|
24985 |
|
24986 | return map;
|
24987 | }
|
24988 |
|
24989 |
|
24990 |
|
24991 |
|
24992 |
|
24993 |
|
24994 |
|
24995 |
|
24996 |
|
24997 | function _map(array, callback) {
|
24998 |
|
24999 | var args = maxArgumentCount(callback);
|
25000 |
|
25001 | var recurse = function recurse(value, index) {
|
25002 | if (Array.isArray(value)) {
|
25003 | return value.map(function (child, i) {
|
25004 |
|
25005 | return recurse(child, index.concat(i));
|
25006 | });
|
25007 | } else {
|
25008 |
|
25009 | if (args === 1) {
|
25010 | return callback(value);
|
25011 | } else if (args === 2) {
|
25012 | return callback(value, index);
|
25013 | } else {
|
25014 |
|
25015 | return callback(value, index, array);
|
25016 | }
|
25017 | }
|
25018 | };
|
25019 |
|
25020 | return recurse(array, []);
|
25021 | }
|
25022 |
|
25023 | exports.name = 'map';
|
25024 | exports.factory = factory;
|
25025 |
|
25026 | }),
|
25027 |
|
25028 | (function(module, exports, __webpack_require__) {
|
25029 |
|
25030 | "use strict";
|
25031 |
|
25032 |
|
25033 | var clone = __webpack_require__(5).clone;
|
25034 |
|
25035 | var validateIndex = __webpack_require__(2).validateIndex;
|
25036 |
|
25037 | function factory(type, config, load, typed) {
|
25038 | var MatrixIndex = load(__webpack_require__(24));
|
25039 | var matrix = load(__webpack_require__(0));
|
25040 | var range = load(__webpack_require__(77));
|
25041 | |
25042 |
|
25043 |
|
25044 |
|
25045 |
|
25046 |
|
25047 |
|
25048 |
|
25049 |
|
25050 |
|
25051 |
|
25052 |
|
25053 |
|
25054 |
|
25055 |
|
25056 |
|
25057 |
|
25058 |
|
25059 |
|
25060 |
|
25061 |
|
25062 |
|
25063 | var row = typed('row', {
|
25064 | 'Matrix, number': _row,
|
25065 | 'Array, number': function ArrayNumber(value, row) {
|
25066 | return _row(matrix(clone(value)), row).valueOf();
|
25067 | }
|
25068 | });
|
25069 | row.toTex = undefined;
|
25070 |
|
25071 | return row;
|
25072 | |
25073 |
|
25074 |
|
25075 |
|
25076 |
|
25077 |
|
25078 |
|
25079 | function _row(value, row) {
|
25080 |
|
25081 | if (value.size().length !== 2) {
|
25082 | throw new Error('Only two dimensional matrix is supported');
|
25083 | }
|
25084 |
|
25085 | validateIndex(row, value.size()[0]);
|
25086 | var columnRange = range(0, value.size()[1]);
|
25087 | var index = new MatrixIndex(row, columnRange);
|
25088 | return value.subset(index);
|
25089 | }
|
25090 | }
|
25091 |
|
25092 | exports.name = 'row';
|
25093 | exports.factory = factory;
|
25094 |
|
25095 | }),
|
25096 |
|
25097 | (function(module, exports, __webpack_require__) {
|
25098 |
|
25099 | "use strict";
|
25100 |
|
25101 |
|
25102 | function factory(type, config, load, typed) {
|
25103 | var matrix = load(__webpack_require__(0));
|
25104 |
|
25105 | var _typeof = load(__webpack_require__(26));
|
25106 |
|
25107 | var algorithm13 = load(__webpack_require__(7));
|
25108 | var algorithm14 = load(__webpack_require__(6));
|
25109 | |
25110 |
|
25111 |
|
25112 |
|
25113 |
|
25114 |
|
25115 |
|
25116 |
|
25117 |
|
25118 |
|
25119 |
|
25120 |
|
25121 |
|
25122 |
|
25123 |
|
25124 |
|
25125 |
|
25126 |
|
25127 |
|
25128 |
|
25129 |
|
25130 |
|
25131 |
|
25132 |
|
25133 |
|
25134 |
|
25135 |
|
25136 |
|
25137 |
|
25138 | var compareText = typed('compareText', {
|
25139 | 'any, any': _compareText,
|
25140 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
25141 | return algorithm13(x, y, _compareText);
|
25142 | },
|
25143 | 'Array, Array': function ArrayArray(x, y) {
|
25144 |
|
25145 | return compareText(matrix(x), matrix(y)).valueOf();
|
25146 | },
|
25147 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
25148 |
|
25149 | return compareText(matrix(x), y);
|
25150 | },
|
25151 | 'Matrix, Array': function MatrixArray(x, y) {
|
25152 |
|
25153 | return compareText(x, matrix(y));
|
25154 | },
|
25155 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
25156 | return algorithm14(x, y, _compareText, false);
|
25157 | },
|
25158 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
25159 | return algorithm14(y, x, _compareText, true);
|
25160 | },
|
25161 | 'Array, any': function ArrayAny(x, y) {
|
25162 |
|
25163 | return algorithm14(matrix(x), y, _compareText, false).valueOf();
|
25164 | },
|
25165 | 'any, Array': function anyArray(x, y) {
|
25166 |
|
25167 | return algorithm14(matrix(y), x, _compareText, true).valueOf();
|
25168 | }
|
25169 | });
|
25170 | |
25171 |
|
25172 |
|
25173 |
|
25174 |
|
25175 |
|
25176 |
|
25177 |
|
25178 | function _compareText(x, y) {
|
25179 |
|
25180 | if (!type.isString(x)) {
|
25181 | throw new TypeError('Unexpected type of argument in function compareText ' + '(expected: string or Array or Matrix, actual: ' + _typeof(x) + ', index: 0)');
|
25182 | }
|
25183 |
|
25184 | if (!type.isString(y)) {
|
25185 | throw new TypeError('Unexpected type of argument in function compareText ' + '(expected: string or Array or Matrix, actual: ' + _typeof(y) + ', index: 1)');
|
25186 | }
|
25187 |
|
25188 | return x === y ? 0 : x > y ? 1 : -1;
|
25189 | }
|
25190 |
|
25191 | compareText.toTex = undefined;
|
25192 |
|
25193 | return compareText;
|
25194 | }
|
25195 |
|
25196 | exports.name = 'compareText';
|
25197 | exports.factory = factory;
|
25198 |
|
25199 | }),
|
25200 |
|
25201 | (function(module, exports, __webpack_require__) {
|
25202 |
|
25203 | "use strict";
|
25204 |
|
25205 |
|
25206 | var flatten = __webpack_require__(2).flatten;
|
25207 |
|
25208 | var identify = __webpack_require__(2).identify;
|
25209 |
|
25210 | var generalize = __webpack_require__(2).generalize;
|
25211 |
|
25212 | function factory(type, config, load, typed) {
|
25213 | var MatrixIndex = load(__webpack_require__(24));
|
25214 | var DenseMatrix = load(__webpack_require__(49));
|
25215 | var size = load(__webpack_require__(28));
|
25216 | var subset = load(__webpack_require__(23));
|
25217 | var compareNatural = load(__webpack_require__(30));
|
25218 | |
25219 |
|
25220 |
|
25221 |
|
25222 |
|
25223 |
|
25224 |
|
25225 |
|
25226 |
|
25227 |
|
25228 |
|
25229 |
|
25230 |
|
25231 |
|
25232 |
|
25233 |
|
25234 |
|
25235 |
|
25236 |
|
25237 |
|
25238 |
|
25239 |
|
25240 | var setDifference = typed('setDifference', {
|
25241 | 'Array | Matrix, Array | Matrix': function ArrayMatrixArrayMatrix(a1, a2) {
|
25242 | var result;
|
25243 |
|
25244 | if (subset(size(a1), new MatrixIndex(0)) === 0) {
|
25245 |
|
25246 | result = [];
|
25247 | } else if (subset(size(a2), new MatrixIndex(0)) === 0) {
|
25248 |
|
25249 | return flatten(a1.toArray());
|
25250 | } else {
|
25251 | var b1 = identify(flatten(Array.isArray(a1) ? a1 : a1.toArray()).sort(compareNatural));
|
25252 | var b2 = identify(flatten(Array.isArray(a2) ? a2 : a2.toArray()).sort(compareNatural));
|
25253 | result = [];
|
25254 | var inb2;
|
25255 |
|
25256 | for (var i = 0; i < b1.length; i++) {
|
25257 | inb2 = false;
|
25258 |
|
25259 | for (var j = 0; j < b2.length; j++) {
|
25260 | if (compareNatural(b1[i].value, b2[j].value) === 0 && b1[i].identifier === b2[j].identifier) {
|
25261 |
|
25262 | inb2 = true;
|
25263 | break;
|
25264 | }
|
25265 | }
|
25266 |
|
25267 | if (!inb2) {
|
25268 | result.push(b1[i]);
|
25269 | }
|
25270 | }
|
25271 | }
|
25272 |
|
25273 |
|
25274 | if (Array.isArray(a1) && Array.isArray(a2)) {
|
25275 | return generalize(result);
|
25276 | }
|
25277 |
|
25278 |
|
25279 | return new DenseMatrix(generalize(result));
|
25280 | }
|
25281 | });
|
25282 | return setDifference;
|
25283 | }
|
25284 |
|
25285 | exports.name = 'setDifference';
|
25286 | exports.factory = factory;
|
25287 |
|
25288 | }),
|
25289 |
|
25290 | (function(module, exports, __webpack_require__) {
|
25291 |
|
25292 | "use strict";
|
25293 |
|
25294 |
|
25295 | var flatten = __webpack_require__(2).flatten;
|
25296 |
|
25297 | var identify = __webpack_require__(2).identify;
|
25298 |
|
25299 | var generalize = __webpack_require__(2).generalize;
|
25300 |
|
25301 | function factory(type, config, load, typed) {
|
25302 | var MatrixIndex = load(__webpack_require__(24));
|
25303 | var DenseMatrix = load(__webpack_require__(49));
|
25304 | var size = load(__webpack_require__(28));
|
25305 | var subset = load(__webpack_require__(23));
|
25306 | var compareNatural = load(__webpack_require__(30));
|
25307 | |
25308 |
|
25309 |
|
25310 |
|
25311 |
|
25312 |
|
25313 |
|
25314 |
|
25315 |
|
25316 |
|
25317 |
|
25318 |
|
25319 |
|
25320 |
|
25321 |
|
25322 |
|
25323 |
|
25324 |
|
25325 |
|
25326 |
|
25327 |
|
25328 |
|
25329 | var setIntersect = typed('setIntersect', {
|
25330 | 'Array | Matrix, Array | Matrix': function ArrayMatrixArrayMatrix(a1, a2) {
|
25331 | var result;
|
25332 |
|
25333 | if (subset(size(a1), new MatrixIndex(0)) === 0 || subset(size(a2), new MatrixIndex(0)) === 0) {
|
25334 |
|
25335 | result = [];
|
25336 | } else {
|
25337 | var b1 = identify(flatten(Array.isArray(a1) ? a1 : a1.toArray()).sort(compareNatural));
|
25338 | var b2 = identify(flatten(Array.isArray(a2) ? a2 : a2.toArray()).sort(compareNatural));
|
25339 | result = [];
|
25340 |
|
25341 | for (var i = 0; i < b1.length; i++) {
|
25342 | for (var j = 0; j < b2.length; j++) {
|
25343 | if (compareNatural(b1[i].value, b2[j].value) === 0 && b1[i].identifier === b2[j].identifier) {
|
25344 |
|
25345 | result.push(b1[i]);
|
25346 | break;
|
25347 | }
|
25348 | }
|
25349 | }
|
25350 | }
|
25351 |
|
25352 |
|
25353 | if (Array.isArray(a1) && Array.isArray(a2)) {
|
25354 | return generalize(result);
|
25355 | }
|
25356 |
|
25357 |
|
25358 | return new DenseMatrix(generalize(result));
|
25359 | }
|
25360 | });
|
25361 | return setIntersect;
|
25362 | }
|
25363 |
|
25364 | exports.name = 'setIntersect';
|
25365 | exports.factory = factory;
|
25366 |
|
25367 | }),
|
25368 |
|
25369 | (function(module, exports, __webpack_require__) {
|
25370 |
|
25371 | "use strict";
|
25372 |
|
25373 |
|
25374 | var flatten = __webpack_require__(2).flatten;
|
25375 |
|
25376 | function factory(type, config, load, typed) {
|
25377 | var MatrixIndex = load(__webpack_require__(24));
|
25378 | var concat = load(__webpack_require__(78));
|
25379 | var size = load(__webpack_require__(28));
|
25380 | var subset = load(__webpack_require__(23));
|
25381 | var setDifference = load(__webpack_require__(148));
|
25382 | |
25383 |
|
25384 |
|
25385 |
|
25386 |
|
25387 |
|
25388 |
|
25389 |
|
25390 |
|
25391 |
|
25392 |
|
25393 |
|
25394 |
|
25395 |
|
25396 |
|
25397 |
|
25398 |
|
25399 |
|
25400 |
|
25401 |
|
25402 |
|
25403 |
|
25404 | var setSymDifference = typed('setSymDifference', {
|
25405 | 'Array | Matrix, Array | Matrix': function ArrayMatrixArrayMatrix(a1, a2) {
|
25406 | if (subset(size(a1), new MatrixIndex(0)) === 0) {
|
25407 |
|
25408 | return flatten(a2);
|
25409 | } else if (subset(size(a2), new MatrixIndex(0)) === 0) {
|
25410 | return flatten(a1);
|
25411 | }
|
25412 |
|
25413 | var b1 = flatten(a1);
|
25414 | var b2 = flatten(a2);
|
25415 | return concat(setDifference(b1, b2), setDifference(b2, b1));
|
25416 | }
|
25417 | });
|
25418 | return setSymDifference;
|
25419 | }
|
25420 |
|
25421 | exports.name = 'setSymDifference';
|
25422 | exports.factory = factory;
|
25423 |
|
25424 | }),
|
25425 |
|
25426 | (function(module, exports, __webpack_require__) {
|
25427 |
|
25428 | "use strict";
|
25429 |
|
25430 |
|
25431 | var flatten = __webpack_require__(2).flatten;
|
25432 |
|
25433 | var containsCollections = __webpack_require__(62);
|
25434 |
|
25435 | function factory(type, config, load, typed) {
|
25436 | var add = load(__webpack_require__(17));
|
25437 | var divide = load(__webpack_require__(12));
|
25438 | var compare = load(__webpack_require__(55));
|
25439 | var partitionSelect = load(__webpack_require__(97));
|
25440 | var improveErrorMessage = load(__webpack_require__(40));
|
25441 | |
25442 |
|
25443 |
|
25444 |
|
25445 |
|
25446 |
|
25447 |
|
25448 |
|
25449 |
|
25450 |
|
25451 |
|
25452 |
|
25453 |
|
25454 |
|
25455 |
|
25456 |
|
25457 |
|
25458 |
|
25459 |
|
25460 |
|
25461 |
|
25462 |
|
25463 |
|
25464 |
|
25465 |
|
25466 |
|
25467 |
|
25468 | var median = typed('median', {
|
25469 |
|
25470 | 'Array | Matrix': _median,
|
25471 |
|
25472 | 'Array | Matrix, number | BigNumber': function ArrayMatrixNumberBigNumber(array, dim) {
|
25473 |
|
25474 | throw new Error('median(A, dim) is not yet supported');
|
25475 | },
|
25476 |
|
25477 | '...': function _(args) {
|
25478 | if (containsCollections(args)) {
|
25479 | throw new TypeError('Scalar values expected in function median');
|
25480 | }
|
25481 |
|
25482 | return _median(args);
|
25483 | }
|
25484 | });
|
25485 | |
25486 |
|
25487 |
|
25488 |
|
25489 |
|
25490 |
|
25491 |
|
25492 | function _median(array) {
|
25493 | try {
|
25494 | array = flatten(array.valueOf());
|
25495 | var num = array.length;
|
25496 |
|
25497 | if (num === 0) {
|
25498 | throw new Error('Cannot calculate median of an empty array');
|
25499 | }
|
25500 |
|
25501 | if (num % 2 === 0) {
|
25502 |
|
25503 | var mid = num / 2 - 1;
|
25504 | var right = partitionSelect(array, mid + 1);
|
25505 |
|
25506 | var left = array[mid];
|
25507 |
|
25508 | for (var i = 0; i < mid; ++i) {
|
25509 | if (compare(array[i], left) > 0) {
|
25510 | left = array[i];
|
25511 | }
|
25512 | }
|
25513 |
|
25514 | return middle2(left, right);
|
25515 | } else {
|
25516 |
|
25517 | var m = partitionSelect(array, (num - 1) / 2);
|
25518 | return middle(m);
|
25519 | }
|
25520 | } catch (err) {
|
25521 | throw improveErrorMessage(err, 'median');
|
25522 | }
|
25523 | }
|
25524 |
|
25525 |
|
25526 | var middle = typed({
|
25527 | 'number | BigNumber | Complex | Unit': function numberBigNumberComplexUnit(value) {
|
25528 | return value;
|
25529 | }
|
25530 | });
|
25531 |
|
25532 | var middle2 = typed({
|
25533 | 'number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit': function numberBigNumberComplexUnitNumberBigNumberComplexUnit(left, right) {
|
25534 | return divide(add(left, right), 2);
|
25535 | }
|
25536 | });
|
25537 | median.toTex = undefined;
|
25538 |
|
25539 | return median;
|
25540 | }
|
25541 |
|
25542 | exports.name = 'median';
|
25543 | exports.factory = factory;
|
25544 |
|
25545 | }),
|
25546 |
|
25547 | (function(module, exports, __webpack_require__) {
|
25548 |
|
25549 | "use strict";
|
25550 |
|
25551 |
|
25552 | var size = __webpack_require__(2).size;
|
25553 |
|
25554 | var deepForEach = __webpack_require__(47);
|
25555 |
|
25556 | var reduce = __webpack_require__(80);
|
25557 |
|
25558 | var containsCollections = __webpack_require__(62);
|
25559 |
|
25560 | function factory(type, config, load, typed) {
|
25561 | var add = load(__webpack_require__(14));
|
25562 | var divide = load(__webpack_require__(45));
|
25563 | var improveErrorMessage = load(__webpack_require__(40));
|
25564 | |
25565 |
|
25566 |
|
25567 |
|
25568 |
|
25569 |
|
25570 |
|
25571 |
|
25572 |
|
25573 |
|
25574 |
|
25575 |
|
25576 |
|
25577 |
|
25578 |
|
25579 |
|
25580 |
|
25581 |
|
25582 |
|
25583 |
|
25584 |
|
25585 |
|
25586 |
|
25587 |
|
25588 |
|
25589 |
|
25590 |
|
25591 |
|
25592 | var mean = typed('mean', {
|
25593 |
|
25594 | 'Array | Matrix': _mean,
|
25595 |
|
25596 | 'Array | Matrix, number | BigNumber': _nmeanDim,
|
25597 |
|
25598 | '...': function _(args) {
|
25599 | if (containsCollections(args)) {
|
25600 | throw new TypeError('Scalar values expected in function mean');
|
25601 | }
|
25602 |
|
25603 | return _mean(args);
|
25604 | }
|
25605 | });
|
25606 | mean.toTex = undefined;
|
25607 |
|
25608 | return mean;
|
25609 | |
25610 |
|
25611 |
|
25612 |
|
25613 |
|
25614 |
|
25615 |
|
25616 |
|
25617 |
|
25618 | function _nmeanDim(array, dim) {
|
25619 | try {
|
25620 | var sum = reduce(array, dim, add);
|
25621 | var s = Array.isArray(array) ? size(array) : array.size();
|
25622 | return divide(sum, s[dim]);
|
25623 | } catch (err) {
|
25624 | throw improveErrorMessage(err, 'mean');
|
25625 | }
|
25626 | }
|
25627 | |
25628 |
|
25629 |
|
25630 |
|
25631 |
|
25632 |
|
25633 |
|
25634 |
|
25635 | function _mean(array) {
|
25636 | var sum = 0;
|
25637 | var num = 0;
|
25638 | deepForEach(array, function (value) {
|
25639 | try {
|
25640 | sum = add(sum, value);
|
25641 | num++;
|
25642 | } catch (err) {
|
25643 | throw improveErrorMessage(err, 'mean', value);
|
25644 | }
|
25645 | });
|
25646 |
|
25647 | if (num === 0) {
|
25648 | throw new Error('Cannot calculate mean of an empty array');
|
25649 | }
|
25650 |
|
25651 | return divide(sum, num);
|
25652 | }
|
25653 | }
|
25654 |
|
25655 | exports.name = 'mean';
|
25656 | exports.factory = factory;
|
25657 |
|
25658 | }),
|
25659 |
|
25660 | (function(module, exports, __webpack_require__) {
|
25661 |
|
25662 | "use strict";
|
25663 |
|
25664 |
|
25665 | var deepForEach = __webpack_require__(47);
|
25666 |
|
25667 | var reduce = __webpack_require__(80);
|
25668 |
|
25669 | var containsCollections = __webpack_require__(62);
|
25670 |
|
25671 | function factory(type, config, load, typed) {
|
25672 | var smaller = load(__webpack_require__(38));
|
25673 | var improveErrorMessage = load(__webpack_require__(40));
|
25674 | |
25675 |
|
25676 |
|
25677 |
|
25678 |
|
25679 |
|
25680 |
|
25681 |
|
25682 |
|
25683 |
|
25684 |
|
25685 |
|
25686 |
|
25687 |
|
25688 |
|
25689 |
|
25690 |
|
25691 |
|
25692 |
|
25693 |
|
25694 |
|
25695 |
|
25696 |
|
25697 |
|
25698 |
|
25699 |
|
25700 |
|
25701 |
|
25702 |
|
25703 |
|
25704 |
|
25705 |
|
25706 | var min = typed('min', {
|
25707 |
|
25708 | 'Array | Matrix': _min,
|
25709 |
|
25710 | 'Array | Matrix, number | BigNumber': function ArrayMatrixNumberBigNumber(array, dim) {
|
25711 | return reduce(array, dim.valueOf(), _smallest);
|
25712 | },
|
25713 |
|
25714 | '...': function _(args) {
|
25715 | if (containsCollections(args)) {
|
25716 | throw new TypeError('Scalar values expected in function min');
|
25717 | }
|
25718 |
|
25719 | return _min(args);
|
25720 | }
|
25721 | });
|
25722 | min.toTex = "\\min\\left(${args}\\right)";
|
25723 | return min;
|
25724 | |
25725 |
|
25726 |
|
25727 |
|
25728 |
|
25729 |
|
25730 |
|
25731 |
|
25732 | function _smallest(x, y) {
|
25733 | try {
|
25734 | return smaller(x, y) ? x : y;
|
25735 | } catch (err) {
|
25736 | throw improveErrorMessage(err, 'min', y);
|
25737 | }
|
25738 | }
|
25739 | |
25740 |
|
25741 |
|
25742 |
|
25743 |
|
25744 |
|
25745 |
|
25746 |
|
25747 | function _min(array) {
|
25748 | var min;
|
25749 | deepForEach(array, function (value) {
|
25750 | try {
|
25751 | if (isNaN(value) && typeof value === 'number') {
|
25752 | min = NaN;
|
25753 | } else if (min === undefined || smaller(value, min)) {
|
25754 | min = value;
|
25755 | }
|
25756 | } catch (err) {
|
25757 | throw improveErrorMessage(err, 'min', value);
|
25758 | }
|
25759 | });
|
25760 |
|
25761 | if (min === undefined) {
|
25762 | throw new Error('Cannot calculate min of an empty array');
|
25763 | }
|
25764 |
|
25765 | return min;
|
25766 | }
|
25767 | }
|
25768 |
|
25769 | exports.name = 'min';
|
25770 | exports.factory = factory;
|
25771 |
|
25772 | }),
|
25773 |
|
25774 | (function(module, exports, __webpack_require__) {
|
25775 |
|
25776 | "use strict";
|
25777 |
|
25778 |
|
25779 | function factory(type, config, load, typed) {
|
25780 | var sqrt = load(__webpack_require__(46));
|
25781 | var variance = load(__webpack_require__(101));
|
25782 | |
25783 |
|
25784 |
|
25785 |
|
25786 |
|
25787 |
|
25788 |
|
25789 |
|
25790 |
|
25791 |
|
25792 |
|
25793 |
|
25794 |
|
25795 |
|
25796 |
|
25797 |
|
25798 |
|
25799 |
|
25800 |
|
25801 |
|
25802 |
|
25803 |
|
25804 |
|
25805 |
|
25806 |
|
25807 |
|
25808 |
|
25809 |
|
25810 |
|
25811 |
|
25812 |
|
25813 |
|
25814 |
|
25815 |
|
25816 |
|
25817 |
|
25818 |
|
25819 |
|
25820 |
|
25821 |
|
25822 |
|
25823 |
|
25824 |
|
25825 |
|
25826 |
|
25827 |
|
25828 |
|
25829 |
|
25830 |
|
25831 |
|
25832 |
|
25833 |
|
25834 |
|
25835 | var std = typed('std', {
|
25836 |
|
25837 | 'Array | Matrix': _std,
|
25838 |
|
25839 | 'Array | Matrix, string': _std,
|
25840 |
|
25841 | 'Array | Matrix, number | BigNumber': _std,
|
25842 |
|
25843 | 'Array | Matrix, number | BigNumber, string': _std,
|
25844 |
|
25845 | '...': function _(args) {
|
25846 | return _std(args);
|
25847 | }
|
25848 | });
|
25849 | std.toTex = undefined;
|
25850 |
|
25851 | return std;
|
25852 |
|
25853 | function _std(array, normalization) {
|
25854 | if (array.length === 0) {
|
25855 | throw new SyntaxError('Function std requires one or more parameters (0 provided)');
|
25856 | }
|
25857 |
|
25858 | try {
|
25859 | return sqrt(variance.apply(null, arguments));
|
25860 | } catch (err) {
|
25861 | if (err instanceof TypeError && err.message.indexOf(' var') !== -1) {
|
25862 | throw new TypeError(err.message.replace(' var', ' std'));
|
25863 | } else {
|
25864 | throw err;
|
25865 | }
|
25866 | }
|
25867 | }
|
25868 | }
|
25869 |
|
25870 | exports.name = 'std';
|
25871 | exports.factory = factory;
|
25872 |
|
25873 | }),
|
25874 |
|
25875 | (function(module, exports, __webpack_require__) {
|
25876 |
|
25877 | function factory(construction, config, load, typed) {
|
25878 | var docs = {};
|
25879 |
|
25880 | docs.bignumber = __webpack_require__(356);
|
25881 | docs['boolean'] = __webpack_require__(357);
|
25882 | docs.complex = __webpack_require__(358);
|
25883 | docs.createUnit = __webpack_require__(359);
|
25884 | docs.fraction = __webpack_require__(360);
|
25885 | docs.index = __webpack_require__(361);
|
25886 | docs.matrix = __webpack_require__(362);
|
25887 | docs.number = __webpack_require__(363);
|
25888 | docs.sparse = __webpack_require__(364);
|
25889 | docs.splitUnit = __webpack_require__(365);
|
25890 | docs.string = __webpack_require__(366);
|
25891 | docs.unit = __webpack_require__(367);
|
25892 |
|
25893 | docs.e = __webpack_require__(156);
|
25894 | docs.E = __webpack_require__(156);
|
25895 | docs['false'] = __webpack_require__(368);
|
25896 | docs.i = __webpack_require__(369);
|
25897 | docs['Infinity'] = __webpack_require__(370);
|
25898 | docs.LN2 = __webpack_require__(371);
|
25899 | docs.LN10 = __webpack_require__(372);
|
25900 | docs.LOG2E = __webpack_require__(373);
|
25901 | docs.LOG10E = __webpack_require__(374);
|
25902 | docs.NaN = __webpack_require__(375);
|
25903 | docs['null'] = __webpack_require__(376);
|
25904 | docs.pi = __webpack_require__(157);
|
25905 | docs.PI = __webpack_require__(157);
|
25906 | docs.phi = __webpack_require__(377);
|
25907 | docs.SQRT1_2 = __webpack_require__(378);
|
25908 | docs.SQRT2 = __webpack_require__(379);
|
25909 | docs.tau = __webpack_require__(380);
|
25910 | docs['true'] = __webpack_require__(381);
|
25911 | docs.version = __webpack_require__(382);
|
25912 |
|
25913 |
|
25914 | docs.speedOfLight = {
|
25915 | description: 'Speed of light in vacuum',
|
25916 | examples: ['speedOfLight']
|
25917 | };
|
25918 | docs.gravitationConstant = {
|
25919 | description: 'Newtonian constant of gravitation',
|
25920 | examples: ['gravitationConstant']
|
25921 | };
|
25922 | docs.planckConstant = {
|
25923 | description: 'Planck constant',
|
25924 | examples: ['planckConstant']
|
25925 | };
|
25926 | docs.reducedPlanckConstant = {
|
25927 | description: 'Reduced Planck constant',
|
25928 | examples: ['reducedPlanckConstant']
|
25929 | };
|
25930 | docs.magneticConstant = {
|
25931 | description: 'Magnetic constant (vacuum permeability)',
|
25932 | examples: ['magneticConstant']
|
25933 | };
|
25934 | docs.electricConstant = {
|
25935 | description: 'Electric constant (vacuum permeability)',
|
25936 | examples: ['electricConstant']
|
25937 | };
|
25938 | docs.vacuumImpedance = {
|
25939 | description: 'Characteristic impedance of vacuum',
|
25940 | examples: ['vacuumImpedance']
|
25941 | };
|
25942 | docs.coulomb = {
|
25943 | description: 'Coulomb\'s constant',
|
25944 | examples: ['coulomb']
|
25945 | };
|
25946 | docs.elementaryCharge = {
|
25947 | description: 'Elementary charge',
|
25948 | examples: ['elementaryCharge']
|
25949 | };
|
25950 | docs.bohrMagneton = {
|
25951 | description: 'Borh magneton',
|
25952 | examples: ['bohrMagneton']
|
25953 | };
|
25954 | docs.conductanceQuantum = {
|
25955 | description: 'Conductance quantum',
|
25956 | examples: ['conductanceQuantum']
|
25957 | };
|
25958 | docs.inverseConductanceQuantum = {
|
25959 | description: 'Inverse conductance quantum',
|
25960 | examples: ['inverseConductanceQuantum']
|
25961 |
|
25962 | };
|
25963 | docs.magneticFluxQuantum = {
|
25964 | description: 'Magnetic flux quantum',
|
25965 | examples: ['magneticFluxQuantum']
|
25966 | };
|
25967 | docs.nuclearMagneton = {
|
25968 | description: 'Nuclear magneton',
|
25969 | examples: ['nuclearMagneton']
|
25970 | };
|
25971 | docs.klitzing = {
|
25972 | description: 'Von Klitzing constant',
|
25973 | examples: ['klitzing']
|
25974 | };
|
25975 | docs.bohrRadius = {
|
25976 | description: 'Borh radius',
|
25977 | examples: ['bohrRadius']
|
25978 | };
|
25979 | docs.classicalElectronRadius = {
|
25980 | description: 'Classical electron radius',
|
25981 | examples: ['classicalElectronRadius']
|
25982 | };
|
25983 | docs.electronMass = {
|
25984 | description: 'Electron mass',
|
25985 | examples: ['electronMass']
|
25986 | };
|
25987 | docs.fermiCoupling = {
|
25988 | description: 'Fermi coupling constant',
|
25989 | examples: ['fermiCoupling']
|
25990 | };
|
25991 | docs.fineStructure = {
|
25992 | description: 'Fine-structure constant',
|
25993 | examples: ['fineStructure']
|
25994 | };
|
25995 | docs.hartreeEnergy = {
|
25996 | description: 'Hartree energy',
|
25997 | examples: ['hartreeEnergy']
|
25998 | };
|
25999 | docs.protonMass = {
|
26000 | description: 'Proton mass',
|
26001 | examples: ['protonMass']
|
26002 | };
|
26003 | docs.deuteronMass = {
|
26004 | description: 'Deuteron Mass',
|
26005 | examples: ['deuteronMass']
|
26006 | };
|
26007 | docs.neutronMass = {
|
26008 | description: 'Neutron mass',
|
26009 | examples: ['neutronMass']
|
26010 | };
|
26011 | docs.quantumOfCirculation = {
|
26012 | description: 'Quantum of circulation',
|
26013 | examples: ['quantumOfCirculation']
|
26014 | };
|
26015 | docs.rydberg = {
|
26016 | description: 'Rydberg constant',
|
26017 | examples: ['rydberg']
|
26018 | };
|
26019 | docs.thomsonCrossSection = {
|
26020 | description: 'Thomson cross section',
|
26021 | examples: ['thomsonCrossSection']
|
26022 | };
|
26023 | docs.weakMixingAngle = {
|
26024 | description: 'Weak mixing angle',
|
26025 | examples: ['weakMixingAngle']
|
26026 | };
|
26027 | docs.efimovFactor = {
|
26028 | description: 'Efimov factor',
|
26029 | examples: ['efimovFactor']
|
26030 | };
|
26031 | docs.atomicMass = {
|
26032 | description: 'Atomic mass constant',
|
26033 | examples: ['atomicMass']
|
26034 | };
|
26035 | docs.avogadro = {
|
26036 | description: 'Avogadro\'s number',
|
26037 | examples: ['avogadro']
|
26038 | };
|
26039 | docs.boltzmann = {
|
26040 | description: 'Boltzmann constant',
|
26041 | examples: ['boltzmann']
|
26042 | };
|
26043 | docs.faraday = {
|
26044 | description: 'Faraday constant',
|
26045 | examples: ['faraday']
|
26046 | };
|
26047 | docs.firstRadiation = {
|
26048 | description: 'First radiation constant',
|
26049 | examples: ['firstRadiation']
|
26050 | };
|
26051 | docs.loschmidt = {
|
26052 | description: 'Loschmidt constant at T=273.15 K and p=101.325 kPa',
|
26053 | examples: ['loschmidt']
|
26054 | };
|
26055 | docs.gasConstant = {
|
26056 | description: 'Gas constant',
|
26057 | examples: ['gasConstant']
|
26058 | };
|
26059 | docs.molarPlanckConstant = {
|
26060 | description: 'Molar Planck constant',
|
26061 | examples: ['molarPlanckConstant']
|
26062 | };
|
26063 | docs.molarVolume = {
|
26064 | description: 'Molar volume of an ideal gas at T=273.15 K and p=101.325 kPa',
|
26065 | examples: ['molarVolume']
|
26066 | };
|
26067 | docs.sackurTetrode = {
|
26068 | description: 'Sackur-Tetrode constant at T=1 K and p=101.325 kPa',
|
26069 | examples: ['sackurTetrode']
|
26070 | };
|
26071 | docs.secondRadiation = {
|
26072 | description: 'Second radiation constant',
|
26073 | examples: ['secondRadiation']
|
26074 | };
|
26075 | docs.stefanBoltzmann = {
|
26076 | description: 'Stefan-Boltzmann constant',
|
26077 | examples: ['stefanBoltzmann']
|
26078 | };
|
26079 | docs.wienDisplacement = {
|
26080 | description: 'Wien displacement law constant',
|
26081 | examples: ['wienDisplacement']
|
26082 |
|
26083 | };
|
26084 | docs.molarMass = {
|
26085 | description: 'Molar mass constant',
|
26086 | examples: ['molarMass']
|
26087 | };
|
26088 | docs.molarMassC12 = {
|
26089 | description: 'Molar mass constant of carbon-12',
|
26090 | examples: ['molarMassC12']
|
26091 | };
|
26092 | docs.gravity = {
|
26093 | description: 'Standard acceleration of gravity (standard acceleration of free-fall on Earth)',
|
26094 | examples: ['gravity']
|
26095 | };
|
26096 | docs.planckLength = {
|
26097 | description: 'Planck length',
|
26098 | examples: ['planckLength']
|
26099 | };
|
26100 | docs.planckMass = {
|
26101 | description: 'Planck mass',
|
26102 | examples: ['planckMass']
|
26103 | };
|
26104 | docs.planckTime = {
|
26105 | description: 'Planck time',
|
26106 | examples: ['planckTime']
|
26107 | };
|
26108 | docs.planckCharge = {
|
26109 | description: 'Planck charge',
|
26110 | examples: ['planckCharge']
|
26111 | };
|
26112 | docs.planckTemperature = {
|
26113 | description: 'Planck temperature',
|
26114 | examples: ['planckTemperature']
|
26115 |
|
26116 | };
|
26117 | docs.derivative = __webpack_require__(383);
|
26118 | docs.lsolve = __webpack_require__(384);
|
26119 | docs.lup = __webpack_require__(385);
|
26120 | docs.lusolve = __webpack_require__(386);
|
26121 | docs.simplify = __webpack_require__(387);
|
26122 | docs.rationalize = __webpack_require__(388);
|
26123 | docs.slu = __webpack_require__(389);
|
26124 | docs.usolve = __webpack_require__(390);
|
26125 | docs.qr = __webpack_require__(391);
|
26126 |
|
26127 | docs.abs = __webpack_require__(392);
|
26128 | docs.add = __webpack_require__(393);
|
26129 | docs.cbrt = __webpack_require__(394);
|
26130 | docs.ceil = __webpack_require__(395);
|
26131 | docs.cube = __webpack_require__(396);
|
26132 | docs.divide = __webpack_require__(397);
|
26133 | docs.dotDivide = __webpack_require__(398);
|
26134 | docs.dotMultiply = __webpack_require__(399);
|
26135 | docs.dotPow = __webpack_require__(400);
|
26136 | docs.exp = __webpack_require__(401);
|
26137 | docs.expm = __webpack_require__(402);
|
26138 | docs.expm1 = __webpack_require__(403);
|
26139 | docs.fix = __webpack_require__(404);
|
26140 | docs.floor = __webpack_require__(405);
|
26141 | docs.gcd = __webpack_require__(406);
|
26142 | docs.hypot = __webpack_require__(407);
|
26143 | docs.lcm = __webpack_require__(408);
|
26144 | docs.log = __webpack_require__(409);
|
26145 | docs.log2 = __webpack_require__(410);
|
26146 | docs.log1p = __webpack_require__(411);
|
26147 | docs.log10 = __webpack_require__(412);
|
26148 | docs.mod = __webpack_require__(413);
|
26149 | docs.multiply = __webpack_require__(414);
|
26150 | docs.norm = __webpack_require__(415);
|
26151 | docs.nthRoot = __webpack_require__(416);
|
26152 | docs.nthRoots = __webpack_require__(417);
|
26153 | docs.pow = __webpack_require__(418);
|
26154 | docs.round = __webpack_require__(419);
|
26155 | docs.sign = __webpack_require__(420);
|
26156 | docs.sqrt = __webpack_require__(421);
|
26157 | docs.sqrtm = __webpack_require__(422);
|
26158 | docs.square = __webpack_require__(423);
|
26159 | docs.subtract = __webpack_require__(424);
|
26160 | docs.unaryMinus = __webpack_require__(425);
|
26161 | docs.unaryPlus = __webpack_require__(426);
|
26162 | docs.xgcd = __webpack_require__(427);
|
26163 |
|
26164 | docs.bitAnd = __webpack_require__(428);
|
26165 | docs.bitNot = __webpack_require__(429);
|
26166 | docs.bitOr = __webpack_require__(430);
|
26167 | docs.bitXor = __webpack_require__(431);
|
26168 | docs.leftShift = __webpack_require__(432);
|
26169 | docs.rightArithShift = __webpack_require__(433);
|
26170 | docs.rightLogShift = __webpack_require__(434);
|
26171 |
|
26172 | docs.bellNumbers = __webpack_require__(435);
|
26173 | docs.catalan = __webpack_require__(436);
|
26174 | docs.composition = __webpack_require__(437);
|
26175 | docs.stirlingS2 = __webpack_require__(438);
|
26176 |
|
26177 | docs['config'] = __webpack_require__(439);
|
26178 | docs['import'] = __webpack_require__(440);
|
26179 | docs['typed'] = __webpack_require__(441);
|
26180 |
|
26181 | docs.arg = __webpack_require__(442);
|
26182 | docs.conj = __webpack_require__(443);
|
26183 | docs.re = __webpack_require__(444);
|
26184 | docs.im = __webpack_require__(445);
|
26185 |
|
26186 | docs['eval'] = __webpack_require__(446);
|
26187 | docs.help = __webpack_require__(447);
|
26188 |
|
26189 | docs.distance = __webpack_require__(448);
|
26190 | docs.intersect = __webpack_require__(449);
|
26191 |
|
26192 | docs['and'] = __webpack_require__(450);
|
26193 | docs['not'] = __webpack_require__(451);
|
26194 | docs['or'] = __webpack_require__(452);
|
26195 | docs['xor'] = __webpack_require__(453);
|
26196 |
|
26197 | docs.column = __webpack_require__(454);
|
26198 | docs['concat'] = __webpack_require__(455);
|
26199 | docs.cross = __webpack_require__(456);
|
26200 | docs.ctranspose = __webpack_require__(457);
|
26201 | docs.det = __webpack_require__(458);
|
26202 | docs.diag = __webpack_require__(459);
|
26203 | docs.dot = __webpack_require__(460);
|
26204 | docs.getMatrixDataType = __webpack_require__(461);
|
26205 | docs.identity = __webpack_require__(462);
|
26206 | docs.filter = __webpack_require__(463);
|
26207 | docs.flatten = __webpack_require__(464);
|
26208 | docs.forEach = __webpack_require__(465);
|
26209 | docs.inv = __webpack_require__(466);
|
26210 | docs.kron = __webpack_require__(467);
|
26211 | docs.map = __webpack_require__(468);
|
26212 | docs.ones = __webpack_require__(469);
|
26213 | docs.partitionSelect = __webpack_require__(470);
|
26214 | docs.range = __webpack_require__(471);
|
26215 | docs.resize = __webpack_require__(472);
|
26216 | docs.reshape = __webpack_require__(473);
|
26217 | docs.row = __webpack_require__(474);
|
26218 | docs.size = __webpack_require__(475);
|
26219 | docs.sort = __webpack_require__(476);
|
26220 | docs.squeeze = __webpack_require__(477);
|
26221 | docs.subset = __webpack_require__(478);
|
26222 | docs.trace = __webpack_require__(479);
|
26223 | docs.transpose = __webpack_require__(480);
|
26224 | docs.zeros = __webpack_require__(481);
|
26225 |
|
26226 | docs.combinations = __webpack_require__(482);
|
26227 |
|
26228 | docs.factorial = __webpack_require__(483);
|
26229 | docs.gamma = __webpack_require__(484);
|
26230 | docs.kldivergence = __webpack_require__(485);
|
26231 | docs.multinomial = __webpack_require__(486);
|
26232 | docs.permutations = __webpack_require__(487);
|
26233 | docs.pickRandom = __webpack_require__(488);
|
26234 | docs.random = __webpack_require__(489);
|
26235 | docs.randomInt = __webpack_require__(490);
|
26236 |
|
26237 | docs.compare = __webpack_require__(491);
|
26238 | docs.compareNatural = __webpack_require__(492);
|
26239 | docs.compareText = __webpack_require__(493);
|
26240 | docs.deepEqual = __webpack_require__(494);
|
26241 | docs['equal'] = __webpack_require__(495);
|
26242 | docs.equalText = __webpack_require__(496);
|
26243 | docs.larger = __webpack_require__(497);
|
26244 | docs.largerEq = __webpack_require__(498);
|
26245 | docs.smaller = __webpack_require__(499);
|
26246 | docs.smallerEq = __webpack_require__(500);
|
26247 | docs.unequal = __webpack_require__(501);
|
26248 |
|
26249 | docs.setCartesian = __webpack_require__(502);
|
26250 | docs.setDifference = __webpack_require__(503);
|
26251 | docs.setDistinct = __webpack_require__(504);
|
26252 | docs.setIntersect = __webpack_require__(505);
|
26253 | docs.setIsSubset = __webpack_require__(506);
|
26254 | docs.setMultiplicity = __webpack_require__(507);
|
26255 | docs.setPowerset = __webpack_require__(508);
|
26256 | docs.setSize = __webpack_require__(509);
|
26257 | docs.setSymDifference = __webpack_require__(510);
|
26258 | docs.setUnion = __webpack_require__(511);
|
26259 |
|
26260 | docs.erf = __webpack_require__(512);
|
26261 |
|
26262 | docs.mad = __webpack_require__(513);
|
26263 | docs.max = __webpack_require__(514);
|
26264 | docs.mean = __webpack_require__(515);
|
26265 | docs.median = __webpack_require__(516);
|
26266 | docs.min = __webpack_require__(517);
|
26267 | docs.mode = __webpack_require__(518);
|
26268 | docs.prod = __webpack_require__(519);
|
26269 | docs.quantileSeq = __webpack_require__(520);
|
26270 | docs.std = __webpack_require__(521);
|
26271 | docs.sum = __webpack_require__(522);
|
26272 | docs['var'] = __webpack_require__(523);
|
26273 |
|
26274 | docs.acos = __webpack_require__(524);
|
26275 | docs.acosh = __webpack_require__(525);
|
26276 | docs.acot = __webpack_require__(526);
|
26277 | docs.acoth = __webpack_require__(527);
|
26278 | docs.acsc = __webpack_require__(528);
|
26279 | docs.acsch = __webpack_require__(529);
|
26280 | docs.asec = __webpack_require__(530);
|
26281 | docs.asech = __webpack_require__(531);
|
26282 | docs.asin = __webpack_require__(532);
|
26283 | docs.asinh = __webpack_require__(533);
|
26284 | docs.atan = __webpack_require__(534);
|
26285 | docs.atanh = __webpack_require__(535);
|
26286 | docs.atan2 = __webpack_require__(536);
|
26287 | docs.cos = __webpack_require__(537);
|
26288 | docs.cosh = __webpack_require__(538);
|
26289 | docs.cot = __webpack_require__(539);
|
26290 | docs.coth = __webpack_require__(540);
|
26291 | docs.csc = __webpack_require__(541);
|
26292 | docs.csch = __webpack_require__(542);
|
26293 | docs.sec = __webpack_require__(543);
|
26294 | docs.sech = __webpack_require__(544);
|
26295 | docs.sin = __webpack_require__(545);
|
26296 | docs.sinh = __webpack_require__(546);
|
26297 | docs.tan = __webpack_require__(547);
|
26298 | docs.tanh = __webpack_require__(548);
|
26299 |
|
26300 | docs.to = __webpack_require__(549);
|
26301 |
|
26302 | docs.clone = __webpack_require__(550);
|
26303 | docs.format = __webpack_require__(551);
|
26304 | docs.isNaN = __webpack_require__(552);
|
26305 | docs.isInteger = __webpack_require__(553);
|
26306 | docs.isNegative = __webpack_require__(554);
|
26307 | docs.isNumeric = __webpack_require__(555);
|
26308 | docs.hasNumericValue = __webpack_require__(556);
|
26309 | docs.isPositive = __webpack_require__(557);
|
26310 | docs.isPrime = __webpack_require__(558);
|
26311 | docs.isZero = __webpack_require__(559);
|
26312 |
|
26313 | docs['typeof'] = __webpack_require__(560);
|
26314 | return docs;
|
26315 | }
|
26316 |
|
26317 | exports.name = 'docs';
|
26318 | exports.path = 'expression';
|
26319 | exports.factory = factory;
|
26320 |
|
26321 | }),
|
26322 |
|
26323 | (function(module, exports) {
|
26324 |
|
26325 | module.exports = {
|
26326 | 'name': 'e',
|
26327 | 'category': 'Constants',
|
26328 | 'syntax': ['e'],
|
26329 | 'description': 'Euler\'s number, the base of the natural logarithm. Approximately equal to 2.71828',
|
26330 | 'examples': ['e', 'e ^ 2', 'exp(2)', 'log(e)'],
|
26331 | 'seealso': ['exp']
|
26332 | };
|
26333 |
|
26334 | }),
|
26335 |
|
26336 | (function(module, exports) {
|
26337 |
|
26338 | module.exports = {
|
26339 | 'name': 'pi',
|
26340 | 'category': 'Constants',
|
26341 | 'syntax': ['pi'],
|
26342 | 'description': 'The number pi is a mathematical constant that is the ratio of a circle\'s circumference to its diameter, and is approximately equal to 3.14159',
|
26343 | 'examples': ['pi', 'sin(pi/2)'],
|
26344 | 'seealso': ['tau']
|
26345 | };
|
26346 |
|
26347 | }),
|
26348 |
|
26349 | (function(module, exports, __webpack_require__) {
|
26350 |
|
26351 | "use strict";
|
26352 |
|
26353 |
|
26354 | function factory(type, config, load, typed, math) {
|
26355 | var Parser = load(__webpack_require__(159));
|
26356 | |
26357 |
|
26358 |
|
26359 |
|
26360 |
|
26361 |
|
26362 |
|
26363 |
|
26364 |
|
26365 |
|
26366 |
|
26367 |
|
26368 |
|
26369 |
|
26370 |
|
26371 |
|
26372 |
|
26373 |
|
26374 |
|
26375 |
|
26376 |
|
26377 |
|
26378 |
|
26379 |
|
26380 |
|
26381 |
|
26382 |
|
26383 |
|
26384 |
|
26385 |
|
26386 |
|
26387 |
|
26388 |
|
26389 |
|
26390 |
|
26391 |
|
26392 |
|
26393 |
|
26394 |
|
26395 |
|
26396 |
|
26397 |
|
26398 |
|
26399 |
|
26400 | return typed('parser', {
|
26401 | '': function _() {
|
26402 | return new Parser(math);
|
26403 | }
|
26404 | });
|
26405 | }
|
26406 |
|
26407 | exports.name = 'parser';
|
26408 | exports.factory = factory;
|
26409 | exports.math = true;
|
26410 |
|
26411 | }),
|
26412 |
|
26413 | (function(module, exports, __webpack_require__) {
|
26414 |
|
26415 | "use strict";
|
26416 |
|
26417 |
|
26418 | var extend = __webpack_require__(5).extend;
|
26419 |
|
26420 | var customs = __webpack_require__(13);
|
26421 |
|
26422 | function factory(type, config, load, typed, math) {
|
26423 | var _parse = load(__webpack_require__(44));
|
26424 | |
26425 |
|
26426 |
|
26427 |
|
26428 |
|
26429 |
|
26430 |
|
26431 |
|
26432 |
|
26433 |
|
26434 |
|
26435 |
|
26436 |
|
26437 |
|
26438 |
|
26439 |
|
26440 |
|
26441 |
|
26442 |
|
26443 |
|
26444 |
|
26445 |
|
26446 |
|
26447 |
|
26448 |
|
26449 |
|
26450 |
|
26451 |
|
26452 |
|
26453 |
|
26454 |
|
26455 |
|
26456 |
|
26457 |
|
26458 |
|
26459 |
|
26460 |
|
26461 |
|
26462 |
|
26463 |
|
26464 |
|
26465 |
|
26466 |
|
26467 |
|
26468 |
|
26469 |
|
26470 |
|
26471 |
|
26472 |
|
26473 |
|
26474 | function Parser() {
|
26475 | if (!(this instanceof Parser)) {
|
26476 | throw new SyntaxError('Constructor must be called with the new operator');
|
26477 | }
|
26478 |
|
26479 | this.scope = {};
|
26480 | }
|
26481 | |
26482 |
|
26483 |
|
26484 |
|
26485 |
|
26486 | Parser.prototype.type = 'Parser';
|
26487 | Parser.prototype.isParser = true;
|
26488 | |
26489 |
|
26490 |
|
26491 |
|
26492 |
|
26493 |
|
26494 |
|
26495 |
|
26496 |
|
26497 | Parser.prototype.parse = function (expr) {
|
26498 | throw new Error('Parser.parse is deprecated. Use math.parse instead.');
|
26499 | };
|
26500 | |
26501 |
|
26502 |
|
26503 |
|
26504 |
|
26505 |
|
26506 |
|
26507 |
|
26508 |
|
26509 | Parser.prototype.compile = function (expr) {
|
26510 | throw new Error('Parser.compile is deprecated. Use math.compile instead.');
|
26511 | };
|
26512 | |
26513 |
|
26514 |
|
26515 |
|
26516 |
|
26517 |
|
26518 |
|
26519 |
|
26520 | Parser.prototype.eval = function (expr) {
|
26521 |
|
26522 | return _parse(expr).compile().eval(this.scope);
|
26523 | };
|
26524 | |
26525 |
|
26526 |
|
26527 |
|
26528 |
|
26529 |
|
26530 |
|
26531 |
|
26532 | Parser.prototype.get = function (name) {
|
26533 |
|
26534 | return name in this.scope ? customs.getSafeProperty(this.scope, name) : undefined;
|
26535 | };
|
26536 | |
26537 |
|
26538 |
|
26539 |
|
26540 |
|
26541 |
|
26542 | Parser.prototype.getAll = function () {
|
26543 | return extend({}, this.scope);
|
26544 | };
|
26545 | |
26546 |
|
26547 |
|
26548 |
|
26549 |
|
26550 |
|
26551 |
|
26552 | Parser.prototype.set = function (name, value) {
|
26553 |
|
26554 | return customs.setSafeProperty(this.scope, name, value);
|
26555 | };
|
26556 | |
26557 |
|
26558 |
|
26559 |
|
26560 |
|
26561 |
|
26562 | Parser.prototype.remove = function (name) {
|
26563 |
|
26564 | delete this.scope[name];
|
26565 | };
|
26566 | |
26567 |
|
26568 |
|
26569 |
|
26570 |
|
26571 | Parser.prototype.clear = function () {
|
26572 | for (var name in this.scope) {
|
26573 | if (this.scope.hasOwnProperty(name)) {
|
26574 | delete this.scope[name];
|
26575 | }
|
26576 | }
|
26577 | };
|
26578 |
|
26579 | return Parser;
|
26580 | }
|
26581 |
|
26582 | exports.name = 'Parser';
|
26583 | exports.path = 'expression';
|
26584 | exports.factory = factory;
|
26585 | exports.math = true;
|
26586 |
|
26587 | }),
|
26588 |
|
26589 | (function(module, exports, __webpack_require__) {
|
26590 |
|
26591 | var __WEBPACK_AMD_DEFINE_RESULT__;;(function (globalScope) {
|
26592 | 'use strict';
|
26593 |
|
26594 |
|
26595 | |
26596 |
|
26597 |
|
26598 |
|
26599 |
|
26600 |
|
26601 |
|
26602 |
|
26603 |
|
26604 |
|
26605 |
|
26606 |
|
26607 |
|
26608 |
|
26609 | var EXP_LIMIT = 9e15,
|
26610 |
|
26611 |
|
26612 |
|
26613 | MAX_DIGITS = 1e9,
|
26614 |
|
26615 |
|
26616 | NUMERALS = '0123456789abcdef',
|
26617 |
|
26618 |
|
26619 | LN10 = '2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058',
|
26620 |
|
26621 |
|
26622 | PI = '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789',
|
26623 |
|
26624 |
|
26625 |
|
26626 | DEFAULTS = {
|
26627 |
|
26628 |
|
26629 |
|
26630 |
|
26631 |
|
26632 |
|
26633 | precision: 20,
|
26634 |
|
26635 |
|
26636 |
|
26637 |
|
26638 |
|
26639 |
|
26640 |
|
26641 |
|
26642 |
|
26643 |
|
26644 |
|
26645 |
|
26646 |
|
26647 |
|
26648 |
|
26649 |
|
26650 | rounding: 4,
|
26651 |
|
26652 |
|
26653 |
|
26654 |
|
26655 |
|
26656 |
|
26657 |
|
26658 |
|
26659 |
|
26660 |
|
26661 |
|
26662 |
|
26663 |
|
26664 |
|
26665 | modulo: 1,
|
26666 |
|
26667 |
|
26668 |
|
26669 | toExpNeg: -7,
|
26670 |
|
26671 |
|
26672 |
|
26673 | toExpPos: 21,
|
26674 |
|
26675 |
|
26676 |
|
26677 | minE: -EXP_LIMIT,
|
26678 |
|
26679 |
|
26680 |
|
26681 | maxE: EXP_LIMIT,
|
26682 |
|
26683 |
|
26684 | crypto: false
|
26685 | },
|
26686 |
|
26687 |
|
26688 |
|
26689 |
|
26690 |
|
26691 | Decimal, inexact, noConflict, quadrant,
|
26692 | external = true,
|
26693 |
|
26694 | decimalError = '[DecimalError] ',
|
26695 | invalidArgument = decimalError + 'Invalid argument: ',
|
26696 | precisionLimitExceeded = decimalError + 'Precision limit exceeded',
|
26697 | cryptoUnavailable = decimalError + 'crypto unavailable',
|
26698 |
|
26699 | mathfloor = Math.floor,
|
26700 | mathpow = Math.pow,
|
26701 |
|
26702 | isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,
|
26703 | isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,
|
26704 | isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,
|
26705 | isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,
|
26706 |
|
26707 | BASE = 1e7,
|
26708 | LOG_BASE = 7,
|
26709 | MAX_SAFE_INTEGER = 9007199254740991,
|
26710 |
|
26711 | LN10_PRECISION = LN10.length - 1,
|
26712 | PI_PRECISION = PI.length - 1,
|
26713 |
|
26714 |
|
26715 | P = { name: '[object Decimal]' };
|
26716 |
|
26717 |
|
26718 |
|
26719 |
|
26720 |
|
26721 | |
26722 |
|
26723 |
|
26724 |
|
26725 |
|
26726 |
|
26727 |
|
26728 |
|
26729 |
|
26730 |
|
26731 |
|
26732 |
|
26733 |
|
26734 |
|
26735 |
|
26736 |
|
26737 |
|
26738 |
|
26739 |
|
26740 |
|
26741 |
|
26742 |
|
26743 |
|
26744 |
|
26745 |
|
26746 |
|
26747 |
|
26748 |
|
26749 |
|
26750 |
|
26751 |
|
26752 |
|
26753 |
|
26754 |
|
26755 |
|
26756 |
|
26757 |
|
26758 |
|
26759 |
|
26760 |
|
26761 |
|
26762 |
|
26763 |
|
26764 |
|
26765 |
|
26766 |
|
26767 |
|
26768 |
|
26769 |
|
26770 |
|
26771 |
|
26772 |
|
26773 |
|
26774 |
|
26775 |
|
26776 |
|
26777 |
|
26778 |
|
26779 |
|
26780 |
|
26781 |
|
26782 |
|
26783 |
|
26784 | |
26785 |
|
26786 |
|
26787 |
|
26788 | P.absoluteValue = P.abs = function () {
|
26789 | var x = new this.constructor(this);
|
26790 | if (x.s < 0) x.s = 1;
|
26791 | return finalise(x);
|
26792 | };
|
26793 |
|
26794 |
|
26795 | |
26796 |
|
26797 |
|
26798 |
|
26799 |
|
26800 | P.ceil = function () {
|
26801 | return finalise(new this.constructor(this), this.e + 1, 2);
|
26802 | };
|
26803 |
|
26804 |
|
26805 | |
26806 |
|
26807 |
|
26808 |
|
26809 |
|
26810 |
|
26811 |
|
26812 |
|
26813 | P.comparedTo = P.cmp = function (y) {
|
26814 | var i, j, xdL, ydL,
|
26815 | x = this,
|
26816 | xd = x.d,
|
26817 | yd = (y = new x.constructor(y)).d,
|
26818 | xs = x.s,
|
26819 | ys = y.s;
|
26820 |
|
26821 |
|
26822 | if (!xd || !yd) {
|
26823 | return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
|
26824 | }
|
26825 |
|
26826 |
|
26827 | if (!xd[0] || !yd[0]) return xd[0] ? xs : yd[0] ? -ys : 0;
|
26828 |
|
26829 |
|
26830 | if (xs !== ys) return xs;
|
26831 |
|
26832 |
|
26833 | if (x.e !== y.e) return x.e > y.e ^ xs < 0 ? 1 : -1;
|
26834 |
|
26835 | xdL = xd.length;
|
26836 | ydL = yd.length;
|
26837 |
|
26838 |
|
26839 | for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) {
|
26840 | if (xd[i] !== yd[i]) return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
|
26841 | }
|
26842 |
|
26843 |
|
26844 | return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
|
26845 | };
|
26846 |
|
26847 |
|
26848 | |
26849 |
|
26850 |
|
26851 |
|
26852 |
|
26853 |
|
26854 |
|
26855 |
|
26856 |
|
26857 |
|
26858 |
|
26859 |
|
26860 |
|
26861 | P.cosine = P.cos = function () {
|
26862 | var pr, rm,
|
26863 | x = this,
|
26864 | Ctor = x.constructor;
|
26865 |
|
26866 | if (!x.d) return new Ctor(NaN);
|
26867 |
|
26868 |
|
26869 | if (!x.d[0]) return new Ctor(1);
|
26870 |
|
26871 | pr = Ctor.precision;
|
26872 | rm = Ctor.rounding;
|
26873 | Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
26874 | Ctor.rounding = 1;
|
26875 |
|
26876 | x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
|
26877 |
|
26878 | Ctor.precision = pr;
|
26879 | Ctor.rounding = rm;
|
26880 |
|
26881 | return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
|
26882 | };
|
26883 |
|
26884 |
|
26885 | |
26886 |
|
26887 |
|
26888 |
|
26889 |
|
26890 |
|
26891 |
|
26892 |
|
26893 |
|
26894 |
|
26895 |
|
26896 |
|
26897 |
|
26898 |
|
26899 |
|
26900 |
|
26901 | P.cubeRoot = P.cbrt = function () {
|
26902 | var e, m, n, r, rep, s, sd, t, t3, t3plusx,
|
26903 | x = this,
|
26904 | Ctor = x.constructor;
|
26905 |
|
26906 | if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
26907 | external = false;
|
26908 |
|
26909 |
|
26910 | s = x.s * Math.pow(x.s * x, 1 / 3);
|
26911 |
|
26912 |
|
26913 |
|
26914 | if (!s || Math.abs(s) == 1 / 0) {
|
26915 | n = digitsToString(x.d);
|
26916 | e = x.e;
|
26917 |
|
26918 |
|
26919 | if (s = (e - n.length + 1) % 3) n += (s == 1 || s == -2 ? '0' : '00');
|
26920 | s = Math.pow(n, 1 / 3);
|
26921 |
|
26922 |
|
26923 | e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
|
26924 |
|
26925 | if (s == 1 / 0) {
|
26926 | n = '5e' + e;
|
26927 | } else {
|
26928 | n = s.toExponential();
|
26929 | n = n.slice(0, n.indexOf('e') + 1) + e;
|
26930 | }
|
26931 |
|
26932 | r = new Ctor(n);
|
26933 | r.s = x.s;
|
26934 | } else {
|
26935 | r = new Ctor(s.toString());
|
26936 | }
|
26937 |
|
26938 | sd = (e = Ctor.precision) + 3;
|
26939 |
|
26940 |
|
26941 |
|
26942 | for (;;) {
|
26943 | t = r;
|
26944 | t3 = t.times(t).times(t);
|
26945 | t3plusx = t3.plus(x);
|
26946 | r = divide(t3plusx.plus(x).times(t), t3plusx.plus(t3), sd + 2, 1);
|
26947 |
|
26948 |
|
26949 | if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
26950 | n = n.slice(sd - 3, sd + 1);
|
26951 |
|
26952 |
|
26953 |
|
26954 | if (n == '9999' || !rep && n == '4999') {
|
26955 |
|
26956 |
|
26957 |
|
26958 | if (!rep) {
|
26959 | finalise(t, e + 1, 0);
|
26960 |
|
26961 | if (t.times(t).times(t).eq(x)) {
|
26962 | r = t;
|
26963 | break;
|
26964 | }
|
26965 | }
|
26966 |
|
26967 | sd += 4;
|
26968 | rep = 1;
|
26969 | } else {
|
26970 |
|
26971 |
|
26972 |
|
26973 | if (!+n || !+n.slice(1) && n.charAt(0) == '5') {
|
26974 |
|
26975 |
|
26976 | finalise(r, e + 1, 1);
|
26977 | m = !r.times(r).times(r).eq(x);
|
26978 | }
|
26979 |
|
26980 | break;
|
26981 | }
|
26982 | }
|
26983 | }
|
26984 |
|
26985 | external = true;
|
26986 |
|
26987 | return finalise(r, e, Ctor.rounding, m);
|
26988 | };
|
26989 |
|
26990 |
|
26991 | |
26992 |
|
26993 |
|
26994 |
|
26995 | P.decimalPlaces = P.dp = function () {
|
26996 | var w,
|
26997 | d = this.d,
|
26998 | n = NaN;
|
26999 |
|
27000 | if (d) {
|
27001 | w = d.length - 1;
|
27002 | n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
|
27003 |
|
27004 |
|
27005 | w = d[w];
|
27006 | if (w) for (; w % 10 == 0; w /= 10) n--;
|
27007 | if (n < 0) n = 0;
|
27008 | }
|
27009 |
|
27010 | return n;
|
27011 | };
|
27012 |
|
27013 |
|
27014 | |
27015 |
|
27016 |
|
27017 |
|
27018 |
|
27019 |
|
27020 |
|
27021 |
|
27022 |
|
27023 |
|
27024 |
|
27025 |
|
27026 |
|
27027 |
|
27028 |
|
27029 |
|
27030 |
|
27031 |
|
27032 |
|
27033 |
|
27034 |
|
27035 | P.dividedBy = P.div = function (y) {
|
27036 | return divide(this, new this.constructor(y));
|
27037 | };
|
27038 |
|
27039 |
|
27040 | |
27041 |
|
27042 |
|
27043 |
|
27044 |
|
27045 | P.dividedToIntegerBy = P.divToInt = function (y) {
|
27046 | var x = this,
|
27047 | Ctor = x.constructor;
|
27048 | return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
|
27049 | };
|
27050 |
|
27051 |
|
27052 | |
27053 |
|
27054 |
|
27055 |
|
27056 | P.equals = P.eq = function (y) {
|
27057 | return this.cmp(y) === 0;
|
27058 | };
|
27059 |
|
27060 |
|
27061 | |
27062 |
|
27063 |
|
27064 |
|
27065 |
|
27066 | P.floor = function () {
|
27067 | return finalise(new this.constructor(this), this.e + 1, 3);
|
27068 | };
|
27069 |
|
27070 |
|
27071 | |
27072 |
|
27073 |
|
27074 |
|
27075 |
|
27076 | P.greaterThan = P.gt = function (y) {
|
27077 | return this.cmp(y) > 0;
|
27078 | };
|
27079 |
|
27080 |
|
27081 | |
27082 |
|
27083 |
|
27084 |
|
27085 |
|
27086 | P.greaterThanOrEqualTo = P.gte = function (y) {
|
27087 | var k = this.cmp(y);
|
27088 | return k == 1 || k === 0;
|
27089 | };
|
27090 |
|
27091 |
|
27092 | |
27093 |
|
27094 |
|
27095 |
|
27096 |
|
27097 |
|
27098 |
|
27099 |
|
27100 |
|
27101 |
|
27102 |
|
27103 |
|
27104 |
|
27105 |
|
27106 |
|
27107 |
|
27108 |
|
27109 |
|
27110 |
|
27111 |
|
27112 |
|
27113 |
|
27114 |
|
27115 |
|
27116 |
|
27117 | P.hyperbolicCosine = P.cosh = function () {
|
27118 | var k, n, pr, rm, len,
|
27119 | x = this,
|
27120 | Ctor = x.constructor,
|
27121 | one = new Ctor(1);
|
27122 |
|
27123 | if (!x.isFinite()) return new Ctor(x.s ? 1 / 0 : NaN);
|
27124 | if (x.isZero()) return one;
|
27125 |
|
27126 | pr = Ctor.precision;
|
27127 | rm = Ctor.rounding;
|
27128 | Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
27129 | Ctor.rounding = 1;
|
27130 | len = x.d.length;
|
27131 |
|
27132 |
|
27133 |
|
27134 |
|
27135 |
|
27136 |
|
27137 | if (len < 32) {
|
27138 | k = Math.ceil(len / 3);
|
27139 | n = Math.pow(4, -k).toString();
|
27140 | } else {
|
27141 | k = 16;
|
27142 | n = '2.3283064365386962890625e-10';
|
27143 | }
|
27144 |
|
27145 | x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
|
27146 |
|
27147 |
|
27148 | var cosh2_x,
|
27149 | i = k,
|
27150 | d8 = new Ctor(8);
|
27151 | for (; i--;) {
|
27152 | cosh2_x = x.times(x);
|
27153 | x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
|
27154 | }
|
27155 |
|
27156 | return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
|
27157 | };
|
27158 |
|
27159 |
|
27160 | |
27161 |
|
27162 |
|
27163 |
|
27164 |
|
27165 |
|
27166 |
|
27167 |
|
27168 |
|
27169 |
|
27170 |
|
27171 |
|
27172 |
|
27173 |
|
27174 |
|
27175 |
|
27176 |
|
27177 |
|
27178 |
|
27179 |
|
27180 |
|
27181 |
|
27182 |
|
27183 |
|
27184 |
|
27185 |
|
27186 |
|
27187 |
|
27188 |
|
27189 |
|
27190 | P.hyperbolicSine = P.sinh = function () {
|
27191 | var k, pr, rm, len,
|
27192 | x = this,
|
27193 | Ctor = x.constructor;
|
27194 |
|
27195 | if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
27196 |
|
27197 | pr = Ctor.precision;
|
27198 | rm = Ctor.rounding;
|
27199 | Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
27200 | Ctor.rounding = 1;
|
27201 | len = x.d.length;
|
27202 |
|
27203 | if (len < 3) {
|
27204 | x = taylorSeries(Ctor, 2, x, x, true);
|
27205 | } else {
|
27206 |
|
27207 |
|
27208 |
|
27209 |
|
27210 |
|
27211 |
|
27212 |
|
27213 |
|
27214 |
|
27215 |
|
27216 | k = 1.4 * Math.sqrt(len);
|
27217 | k = k > 16 ? 16 : k | 0;
|
27218 |
|
27219 | x = x.times(Math.pow(5, -k));
|
27220 |
|
27221 | x = taylorSeries(Ctor, 2, x, x, true);
|
27222 |
|
27223 |
|
27224 | var sinh2_x,
|
27225 | d5 = new Ctor(5),
|
27226 | d16 = new Ctor(16),
|
27227 | d20 = new Ctor(20);
|
27228 | for (; k--;) {
|
27229 | sinh2_x = x.times(x);
|
27230 | x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
|
27231 | }
|
27232 | }
|
27233 |
|
27234 | Ctor.precision = pr;
|
27235 | Ctor.rounding = rm;
|
27236 |
|
27237 | return finalise(x, pr, rm, true);
|
27238 | };
|
27239 |
|
27240 |
|
27241 | |
27242 |
|
27243 |
|
27244 |
|
27245 |
|
27246 |
|
27247 |
|
27248 |
|
27249 |
|
27250 |
|
27251 |
|
27252 |
|
27253 |
|
27254 |
|
27255 |
|
27256 |
|
27257 | P.hyperbolicTangent = P.tanh = function () {
|
27258 | var pr, rm,
|
27259 | x = this,
|
27260 | Ctor = x.constructor;
|
27261 |
|
27262 | if (!x.isFinite()) return new Ctor(x.s);
|
27263 | if (x.isZero()) return new Ctor(x);
|
27264 |
|
27265 | pr = Ctor.precision;
|
27266 | rm = Ctor.rounding;
|
27267 | Ctor.precision = pr + 7;
|
27268 | Ctor.rounding = 1;
|
27269 |
|
27270 | return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
|
27271 | };
|
27272 |
|
27273 |
|
27274 | |
27275 |
|
27276 |
|
27277 |
|
27278 |
|
27279 |
|
27280 |
|
27281 |
|
27282 |
|
27283 |
|
27284 |
|
27285 |
|
27286 |
|
27287 |
|
27288 |
|
27289 |
|
27290 |
|
27291 |
|
27292 |
|
27293 | P.inverseCosine = P.acos = function () {
|
27294 | var halfPi,
|
27295 | x = this,
|
27296 | Ctor = x.constructor,
|
27297 | k = x.abs().cmp(1),
|
27298 | pr = Ctor.precision,
|
27299 | rm = Ctor.rounding;
|
27300 |
|
27301 | if (k !== -1) {
|
27302 | return k === 0
|
27303 |
|
27304 | ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0)
|
27305 |
|
27306 | : new Ctor(NaN);
|
27307 | }
|
27308 |
|
27309 | if (x.isZero()) return getPi(Ctor, pr + 4, rm).times(0.5);
|
27310 |
|
27311 |
|
27312 |
|
27313 | Ctor.precision = pr + 6;
|
27314 | Ctor.rounding = 1;
|
27315 |
|
27316 | x = x.asin();
|
27317 | halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
27318 |
|
27319 | Ctor.precision = pr;
|
27320 | Ctor.rounding = rm;
|
27321 |
|
27322 | return halfPi.minus(x);
|
27323 | };
|
27324 |
|
27325 |
|
27326 | |
27327 |
|
27328 |
|
27329 |
|
27330 |
|
27331 |
|
27332 |
|
27333 |
|
27334 |
|
27335 |
|
27336 |
|
27337 |
|
27338 |
|
27339 |
|
27340 |
|
27341 |
|
27342 |
|
27343 |
|
27344 |
|
27345 | P.inverseHyperbolicCosine = P.acosh = function () {
|
27346 | var pr, rm,
|
27347 | x = this,
|
27348 | Ctor = x.constructor;
|
27349 |
|
27350 | if (x.lte(1)) return new Ctor(x.eq(1) ? 0 : NaN);
|
27351 | if (!x.isFinite()) return new Ctor(x);
|
27352 |
|
27353 | pr = Ctor.precision;
|
27354 | rm = Ctor.rounding;
|
27355 | Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
|
27356 | Ctor.rounding = 1;
|
27357 | external = false;
|
27358 |
|
27359 | x = x.times(x).minus(1).sqrt().plus(x);
|
27360 |
|
27361 | external = true;
|
27362 | Ctor.precision = pr;
|
27363 | Ctor.rounding = rm;
|
27364 |
|
27365 | return x.ln();
|
27366 | };
|
27367 |
|
27368 |
|
27369 | |
27370 |
|
27371 |
|
27372 |
|
27373 |
|
27374 |
|
27375 |
|
27376 |
|
27377 |
|
27378 |
|
27379 |
|
27380 |
|
27381 |
|
27382 |
|
27383 |
|
27384 |
|
27385 | P.inverseHyperbolicSine = P.asinh = function () {
|
27386 | var pr, rm,
|
27387 | x = this,
|
27388 | Ctor = x.constructor;
|
27389 |
|
27390 | if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
27391 |
|
27392 | pr = Ctor.precision;
|
27393 | rm = Ctor.rounding;
|
27394 | Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
|
27395 | Ctor.rounding = 1;
|
27396 | external = false;
|
27397 |
|
27398 | x = x.times(x).plus(1).sqrt().plus(x);
|
27399 |
|
27400 | external = true;
|
27401 | Ctor.precision = pr;
|
27402 | Ctor.rounding = rm;
|
27403 |
|
27404 | return x.ln();
|
27405 | };
|
27406 |
|
27407 |
|
27408 | |
27409 |
|
27410 |
|
27411 |
|
27412 |
|
27413 |
|
27414 |
|
27415 |
|
27416 |
|
27417 |
|
27418 |
|
27419 |
|
27420 |
|
27421 |
|
27422 |
|
27423 |
|
27424 |
|
27425 |
|
27426 |
|
27427 | P.inverseHyperbolicTangent = P.atanh = function () {
|
27428 | var pr, rm, wpr, xsd,
|
27429 | x = this,
|
27430 | Ctor = x.constructor;
|
27431 |
|
27432 | if (!x.isFinite()) return new Ctor(NaN);
|
27433 | if (x.e >= 0) return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
|
27434 |
|
27435 | pr = Ctor.precision;
|
27436 | rm = Ctor.rounding;
|
27437 | xsd = x.sd();
|
27438 |
|
27439 | if (Math.max(xsd, pr) < 2 * -x.e - 1) return finalise(new Ctor(x), pr, rm, true);
|
27440 |
|
27441 | Ctor.precision = wpr = xsd - x.e;
|
27442 |
|
27443 | x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
|
27444 |
|
27445 | Ctor.precision = pr + 4;
|
27446 | Ctor.rounding = 1;
|
27447 |
|
27448 | x = x.ln();
|
27449 |
|
27450 | Ctor.precision = pr;
|
27451 | Ctor.rounding = rm;
|
27452 |
|
27453 | return x.times(0.5);
|
27454 | };
|
27455 |
|
27456 |
|
27457 | |
27458 |
|
27459 |
|
27460 |
|
27461 |
|
27462 |
|
27463 |
|
27464 |
|
27465 |
|
27466 |
|
27467 |
|
27468 |
|
27469 |
|
27470 |
|
27471 |
|
27472 |
|
27473 |
|
27474 |
|
27475 |
|
27476 |
|
27477 |
|
27478 | P.inverseSine = P.asin = function () {
|
27479 | var halfPi, k,
|
27480 | pr, rm,
|
27481 | x = this,
|
27482 | Ctor = x.constructor;
|
27483 |
|
27484 | if (x.isZero()) return new Ctor(x);
|
27485 |
|
27486 | k = x.abs().cmp(1);
|
27487 | pr = Ctor.precision;
|
27488 | rm = Ctor.rounding;
|
27489 |
|
27490 | if (k !== -1) {
|
27491 |
|
27492 |
|
27493 | if (k === 0) {
|
27494 | halfPi = getPi(Ctor, pr + 4, rm).times(0.5);
|
27495 | halfPi.s = x.s;
|
27496 | return halfPi;
|
27497 | }
|
27498 |
|
27499 |
|
27500 | return new Ctor(NaN);
|
27501 | }
|
27502 |
|
27503 |
|
27504 |
|
27505 | Ctor.precision = pr + 6;
|
27506 | Ctor.rounding = 1;
|
27507 |
|
27508 | x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
|
27509 |
|
27510 | Ctor.precision = pr;
|
27511 | Ctor.rounding = rm;
|
27512 |
|
27513 | return x.times(2);
|
27514 | };
|
27515 |
|
27516 |
|
27517 | |
27518 |
|
27519 |
|
27520 |
|
27521 |
|
27522 |
|
27523 |
|
27524 |
|
27525 |
|
27526 |
|
27527 |
|
27528 |
|
27529 |
|
27530 |
|
27531 |
|
27532 |
|
27533 |
|
27534 |
|
27535 | P.inverseTangent = P.atan = function () {
|
27536 | var i, j, k, n, px, t, r, wpr, x2,
|
27537 | x = this,
|
27538 | Ctor = x.constructor,
|
27539 | pr = Ctor.precision,
|
27540 | rm = Ctor.rounding;
|
27541 |
|
27542 | if (!x.isFinite()) {
|
27543 | if (!x.s) return new Ctor(NaN);
|
27544 | if (pr + 4 <= PI_PRECISION) {
|
27545 | r = getPi(Ctor, pr + 4, rm).times(0.5);
|
27546 | r.s = x.s;
|
27547 | return r;
|
27548 | }
|
27549 | } else if (x.isZero()) {
|
27550 | return new Ctor(x);
|
27551 | } else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
|
27552 | r = getPi(Ctor, pr + 4, rm).times(0.25);
|
27553 | r.s = x.s;
|
27554 | return r;
|
27555 | }
|
27556 |
|
27557 | Ctor.precision = wpr = pr + 10;
|
27558 | Ctor.rounding = 1;
|
27559 |
|
27560 |
|
27561 |
|
27562 |
|
27563 |
|
27564 |
|
27565 |
|
27566 | k = Math.min(28, wpr / LOG_BASE + 2 | 0);
|
27567 |
|
27568 | for (i = k; i; --i) x = x.div(x.times(x).plus(1).sqrt().plus(1));
|
27569 |
|
27570 | external = false;
|
27571 |
|
27572 | j = Math.ceil(wpr / LOG_BASE);
|
27573 | n = 1;
|
27574 | x2 = x.times(x);
|
27575 | r = new Ctor(x);
|
27576 | px = x;
|
27577 |
|
27578 |
|
27579 | for (; i !== -1;) {
|
27580 | px = px.times(x2);
|
27581 | t = r.minus(px.div(n += 2));
|
27582 |
|
27583 | px = px.times(x2);
|
27584 | r = t.plus(px.div(n += 2));
|
27585 |
|
27586 | if (r.d[j] !== void 0) for (i = j; r.d[i] === t.d[i] && i--;);
|
27587 | }
|
27588 |
|
27589 | if (k) r = r.times(2 << (k - 1));
|
27590 |
|
27591 | external = true;
|
27592 |
|
27593 | return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
|
27594 | };
|
27595 |
|
27596 |
|
27597 | |
27598 |
|
27599 |
|
27600 |
|
27601 | P.isFinite = function () {
|
27602 | return !!this.d;
|
27603 | };
|
27604 |
|
27605 |
|
27606 | |
27607 |
|
27608 |
|
27609 |
|
27610 | P.isInteger = P.isInt = function () {
|
27611 | return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
|
27612 | };
|
27613 |
|
27614 |
|
27615 | |
27616 |
|
27617 |
|
27618 |
|
27619 | P.isNaN = function () {
|
27620 | return !this.s;
|
27621 | };
|
27622 |
|
27623 |
|
27624 | |
27625 |
|
27626 |
|
27627 |
|
27628 | P.isNegative = P.isNeg = function () {
|
27629 | return this.s < 0;
|
27630 | };
|
27631 |
|
27632 |
|
27633 | |
27634 |
|
27635 |
|
27636 |
|
27637 | P.isPositive = P.isPos = function () {
|
27638 | return this.s > 0;
|
27639 | };
|
27640 |
|
27641 |
|
27642 | |
27643 |
|
27644 |
|
27645 |
|
27646 | P.isZero = function () {
|
27647 | return !!this.d && this.d[0] === 0;
|
27648 | };
|
27649 |
|
27650 |
|
27651 | |
27652 |
|
27653 |
|
27654 |
|
27655 | P.lessThan = P.lt = function (y) {
|
27656 | return this.cmp(y) < 0;
|
27657 | };
|
27658 |
|
27659 |
|
27660 | |
27661 |
|
27662 |
|
27663 |
|
27664 | P.lessThanOrEqualTo = P.lte = function (y) {
|
27665 | return this.cmp(y) < 1;
|
27666 | };
|
27667 |
|
27668 |
|
27669 | |
27670 |
|
27671 |
|
27672 |
|
27673 |
|
27674 |
|
27675 |
|
27676 |
|
27677 |
|
27678 |
|
27679 |
|
27680 |
|
27681 |
|
27682 |
|
27683 |
|
27684 |
|
27685 |
|
27686 |
|
27687 |
|
27688 |
|
27689 |
|
27690 |
|
27691 |
|
27692 |
|
27693 |
|
27694 |
|
27695 |
|
27696 |
|
27697 |
|
27698 |
|
27699 | P.logarithm = P.log = function (base) {
|
27700 | var isBase10, d, denominator, k, inf, num, sd, r,
|
27701 | arg = this,
|
27702 | Ctor = arg.constructor,
|
27703 | pr = Ctor.precision,
|
27704 | rm = Ctor.rounding,
|
27705 | guard = 5;
|
27706 |
|
27707 |
|
27708 | if (base == null) {
|
27709 | base = new Ctor(10);
|
27710 | isBase10 = true;
|
27711 | } else {
|
27712 | base = new Ctor(base);
|
27713 | d = base.d;
|
27714 |
|
27715 |
|
27716 | if (base.s < 0 || !d || !d[0] || base.eq(1)) return new Ctor(NaN);
|
27717 |
|
27718 | isBase10 = base.eq(10);
|
27719 | }
|
27720 |
|
27721 | d = arg.d;
|
27722 |
|
27723 |
|
27724 | if (arg.s < 0 || !d || !d[0] || arg.eq(1)) {
|
27725 | return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
|
27726 | }
|
27727 |
|
27728 |
|
27729 |
|
27730 | if (isBase10) {
|
27731 | if (d.length > 1) {
|
27732 | inf = true;
|
27733 | } else {
|
27734 | for (k = d[0]; k % 10 === 0;) k /= 10;
|
27735 | inf = k !== 1;
|
27736 | }
|
27737 | }
|
27738 |
|
27739 | external = false;
|
27740 | sd = pr + guard;
|
27741 | num = naturalLogarithm(arg, sd);
|
27742 | denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
27743 |
|
27744 |
|
27745 | r = divide(num, denominator, sd, 1);
|
27746 |
|
27747 |
|
27748 |
|
27749 |
|
27750 |
|
27751 |
|
27752 |
|
27753 |
|
27754 |
|
27755 |
|
27756 |
|
27757 |
|
27758 |
|
27759 |
|
27760 |
|
27761 | if (checkRoundingDigits(r.d, k = pr, rm)) {
|
27762 |
|
27763 | do {
|
27764 | sd += 10;
|
27765 | num = naturalLogarithm(arg, sd);
|
27766 | denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
27767 | r = divide(num, denominator, sd, 1);
|
27768 |
|
27769 | if (!inf) {
|
27770 |
|
27771 |
|
27772 | if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) {
|
27773 | r = finalise(r, pr + 1, 0);
|
27774 | }
|
27775 |
|
27776 | break;
|
27777 | }
|
27778 | } while (checkRoundingDigits(r.d, k += 10, rm));
|
27779 | }
|
27780 |
|
27781 | external = true;
|
27782 |
|
27783 | return finalise(r, pr, rm);
|
27784 | };
|
27785 |
|
27786 |
|
27787 | |
27788 |
|
27789 |
|
27790 |
|
27791 |
|
27792 |
|
27793 |
|
27794 |
|
27795 |
|
27796 |
|
27797 |
|
27798 |
|
27799 | |
27800 |
|
27801 |
|
27802 |
|
27803 |
|
27804 |
|
27805 |
|
27806 |
|
27807 |
|
27808 |
|
27809 |
|
27810 |
|
27811 | |
27812 |
|
27813 |
|
27814 |
|
27815 |
|
27816 |
|
27817 |
|
27818 |
|
27819 |
|
27820 |
|
27821 |
|
27822 |
|
27823 |
|
27824 |
|
27825 |
|
27826 |
|
27827 |
|
27828 |
|
27829 |
|
27830 |
|
27831 |
|
27832 | P.minus = P.sub = function (y) {
|
27833 | var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd,
|
27834 | x = this,
|
27835 | Ctor = x.constructor;
|
27836 |
|
27837 | y = new Ctor(y);
|
27838 |
|
27839 |
|
27840 | if (!x.d || !y.d) {
|
27841 |
|
27842 |
|
27843 | if (!x.s || !y.s) y = new Ctor(NaN);
|
27844 |
|
27845 |
|
27846 | else if (x.d) y.s = -y.s;
|
27847 |
|
27848 |
|
27849 |
|
27850 |
|
27851 | else y = new Ctor(y.d || x.s !== y.s ? x : NaN);
|
27852 |
|
27853 | return y;
|
27854 | }
|
27855 |
|
27856 |
|
27857 | if (x.s != y.s) {
|
27858 | y.s = -y.s;
|
27859 | return x.plus(y);
|
27860 | }
|
27861 |
|
27862 | xd = x.d;
|
27863 | yd = y.d;
|
27864 | pr = Ctor.precision;
|
27865 | rm = Ctor.rounding;
|
27866 |
|
27867 |
|
27868 | if (!xd[0] || !yd[0]) {
|
27869 |
|
27870 |
|
27871 | if (yd[0]) y.s = -y.s;
|
27872 |
|
27873 |
|
27874 | else if (xd[0]) y = new Ctor(x);
|
27875 |
|
27876 |
|
27877 |
|
27878 | else return new Ctor(rm === 3 ? -0 : 0);
|
27879 |
|
27880 | return external ? finalise(y, pr, rm) : y;
|
27881 | }
|
27882 |
|
27883 |
|
27884 |
|
27885 |
|
27886 | e = mathfloor(y.e / LOG_BASE);
|
27887 | xe = mathfloor(x.e / LOG_BASE);
|
27888 |
|
27889 | xd = xd.slice();
|
27890 | k = xe - e;
|
27891 |
|
27892 |
|
27893 | if (k) {
|
27894 | xLTy = k < 0;
|
27895 |
|
27896 | if (xLTy) {
|
27897 | d = xd;
|
27898 | k = -k;
|
27899 | len = yd.length;
|
27900 | } else {
|
27901 | d = yd;
|
27902 | e = xe;
|
27903 | len = xd.length;
|
27904 | }
|
27905 |
|
27906 |
|
27907 |
|
27908 |
|
27909 | i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
|
27910 |
|
27911 | if (k > i) {
|
27912 | k = i;
|
27913 | d.length = 1;
|
27914 | }
|
27915 |
|
27916 |
|
27917 | d.reverse();
|
27918 | for (i = k; i--;) d.push(0);
|
27919 | d.reverse();
|
27920 |
|
27921 |
|
27922 | } else {
|
27923 |
|
27924 |
|
27925 |
|
27926 | i = xd.length;
|
27927 | len = yd.length;
|
27928 | xLTy = i < len;
|
27929 | if (xLTy) len = i;
|
27930 |
|
27931 | for (i = 0; i < len; i++) {
|
27932 | if (xd[i] != yd[i]) {
|
27933 | xLTy = xd[i] < yd[i];
|
27934 | break;
|
27935 | }
|
27936 | }
|
27937 |
|
27938 | k = 0;
|
27939 | }
|
27940 |
|
27941 | if (xLTy) {
|
27942 | d = xd;
|
27943 | xd = yd;
|
27944 | yd = d;
|
27945 | y.s = -y.s;
|
27946 | }
|
27947 |
|
27948 | len = xd.length;
|
27949 |
|
27950 |
|
27951 |
|
27952 | for (i = yd.length - len; i > 0; --i) xd[len++] = 0;
|
27953 |
|
27954 |
|
27955 | for (i = yd.length; i > k;) {
|
27956 |
|
27957 | if (xd[--i] < yd[i]) {
|
27958 | for (j = i; j && xd[--j] === 0;) xd[j] = BASE - 1;
|
27959 | --xd[j];
|
27960 | xd[i] += BASE;
|
27961 | }
|
27962 |
|
27963 | xd[i] -= yd[i];
|
27964 | }
|
27965 |
|
27966 |
|
27967 | for (; xd[--len] === 0;) xd.pop();
|
27968 |
|
27969 |
|
27970 | for (; xd[0] === 0; xd.shift()) --e;
|
27971 |
|
27972 |
|
27973 | if (!xd[0]) return new Ctor(rm === 3 ? -0 : 0);
|
27974 |
|
27975 | y.d = xd;
|
27976 | y.e = getBase10Exponent(xd, e);
|
27977 |
|
27978 | return external ? finalise(y, pr, rm) : y;
|
27979 | };
|
27980 |
|
27981 |
|
27982 | |
27983 |
|
27984 |
|
27985 |
|
27986 |
|
27987 |
|
27988 |
|
27989 |
|
27990 |
|
27991 |
|
27992 |
|
27993 |
|
27994 |
|
27995 |
|
27996 |
|
27997 |
|
27998 |
|
27999 |
|
28000 |
|
28001 |
|
28002 |
|
28003 |
|
28004 |
|
28005 |
|
28006 | P.modulo = P.mod = function (y) {
|
28007 | var q,
|
28008 | x = this,
|
28009 | Ctor = x.constructor;
|
28010 |
|
28011 | y = new Ctor(y);
|
28012 |
|
28013 |
|
28014 | if (!x.d || !y.s || y.d && !y.d[0]) return new Ctor(NaN);
|
28015 |
|
28016 |
|
28017 | if (!y.d || x.d && !x.d[0]) {
|
28018 | return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
|
28019 | }
|
28020 |
|
28021 |
|
28022 | external = false;
|
28023 |
|
28024 | if (Ctor.modulo == 9) {
|
28025 |
|
28026 |
|
28027 |
|
28028 | q = divide(x, y.abs(), 0, 3, 1);
|
28029 | q.s *= y.s;
|
28030 | } else {
|
28031 | q = divide(x, y, 0, Ctor.modulo, 1);
|
28032 | }
|
28033 |
|
28034 | q = q.times(y);
|
28035 |
|
28036 | external = true;
|
28037 |
|
28038 | return x.minus(q);
|
28039 | };
|
28040 |
|
28041 |
|
28042 | |
28043 |
|
28044 |
|
28045 |
|
28046 |
|
28047 |
|
28048 | P.naturalExponential = P.exp = function () {
|
28049 | return naturalExponential(this);
|
28050 | };
|
28051 |
|
28052 |
|
28053 | |
28054 |
|
28055 |
|
28056 |
|
28057 |
|
28058 | P.naturalLogarithm = P.ln = function () {
|
28059 | return naturalLogarithm(this);
|
28060 | };
|
28061 |
|
28062 |
|
28063 | |
28064 |
|
28065 |
|
28066 |
|
28067 |
|
28068 | P.negated = P.neg = function () {
|
28069 | var x = new this.constructor(this);
|
28070 | x.s = -x.s;
|
28071 | return finalise(x);
|
28072 | };
|
28073 |
|
28074 |
|
28075 | |
28076 |
|
28077 |
|
28078 |
|
28079 |
|
28080 |
|
28081 |
|
28082 |
|
28083 |
|
28084 |
|
28085 |
|
28086 |
|
28087 |
|
28088 |
|
28089 |
|
28090 |
|
28091 |
|
28092 |
|
28093 |
|
28094 |
|
28095 |
|
28096 | P.plus = P.add = function (y) {
|
28097 | var carry, d, e, i, k, len, pr, rm, xd, yd,
|
28098 | x = this,
|
28099 | Ctor = x.constructor;
|
28100 |
|
28101 | y = new Ctor(y);
|
28102 |
|
28103 |
|
28104 | if (!x.d || !y.d) {
|
28105 |
|
28106 |
|
28107 | if (!x.s || !y.s) y = new Ctor(NaN);
|
28108 |
|
28109 |
|
28110 |
|
28111 |
|
28112 |
|
28113 | else if (!x.d) y = new Ctor(y.d || x.s === y.s ? x : NaN);
|
28114 |
|
28115 | return y;
|
28116 | }
|
28117 |
|
28118 |
|
28119 | if (x.s != y.s) {
|
28120 | y.s = -y.s;
|
28121 | return x.minus(y);
|
28122 | }
|
28123 |
|
28124 | xd = x.d;
|
28125 | yd = y.d;
|
28126 | pr = Ctor.precision;
|
28127 | rm = Ctor.rounding;
|
28128 |
|
28129 |
|
28130 | if (!xd[0] || !yd[0]) {
|
28131 |
|
28132 |
|
28133 |
|
28134 | if (!yd[0]) y = new Ctor(x);
|
28135 |
|
28136 | return external ? finalise(y, pr, rm) : y;
|
28137 | }
|
28138 |
|
28139 |
|
28140 |
|
28141 |
|
28142 | k = mathfloor(x.e / LOG_BASE);
|
28143 | e = mathfloor(y.e / LOG_BASE);
|
28144 |
|
28145 | xd = xd.slice();
|
28146 | i = k - e;
|
28147 |
|
28148 |
|
28149 | if (i) {
|
28150 |
|
28151 | if (i < 0) {
|
28152 | d = xd;
|
28153 | i = -i;
|
28154 | len = yd.length;
|
28155 | } else {
|
28156 | d = yd;
|
28157 | e = k;
|
28158 | len = xd.length;
|
28159 | }
|
28160 |
|
28161 |
|
28162 | k = Math.ceil(pr / LOG_BASE);
|
28163 | len = k > len ? k + 1 : len + 1;
|
28164 |
|
28165 | if (i > len) {
|
28166 | i = len;
|
28167 | d.length = 1;
|
28168 | }
|
28169 |
|
28170 |
|
28171 | d.reverse();
|
28172 | for (; i--;) d.push(0);
|
28173 | d.reverse();
|
28174 | }
|
28175 |
|
28176 | len = xd.length;
|
28177 | i = yd.length;
|
28178 |
|
28179 |
|
28180 | if (len - i < 0) {
|
28181 | i = len;
|
28182 | d = yd;
|
28183 | yd = xd;
|
28184 | xd = d;
|
28185 | }
|
28186 |
|
28187 |
|
28188 | for (carry = 0; i;) {
|
28189 | carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
|
28190 | xd[i] %= BASE;
|
28191 | }
|
28192 |
|
28193 | if (carry) {
|
28194 | xd.unshift(carry);
|
28195 | ++e;
|
28196 | }
|
28197 |
|
28198 |
|
28199 |
|
28200 | for (len = xd.length; xd[--len] == 0;) xd.pop();
|
28201 |
|
28202 | y.d = xd;
|
28203 | y.e = getBase10Exponent(xd, e);
|
28204 |
|
28205 | return external ? finalise(y, pr, rm) : y;
|
28206 | };
|
28207 |
|
28208 |
|
28209 | |
28210 |
|
28211 |
|
28212 |
|
28213 |
|
28214 |
|
28215 | P.precision = P.sd = function (z) {
|
28216 | var k,
|
28217 | x = this;
|
28218 |
|
28219 | if (z !== void 0 && z !== !!z && z !== 1 && z !== 0) throw Error(invalidArgument + z);
|
28220 |
|
28221 | if (x.d) {
|
28222 | k = getPrecision(x.d);
|
28223 | if (z && x.e + 1 > k) k = x.e + 1;
|
28224 | } else {
|
28225 | k = NaN;
|
28226 | }
|
28227 |
|
28228 | return k;
|
28229 | };
|
28230 |
|
28231 |
|
28232 | |
28233 |
|
28234 |
|
28235 |
|
28236 |
|
28237 | P.round = function () {
|
28238 | var x = this,
|
28239 | Ctor = x.constructor;
|
28240 |
|
28241 | return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
|
28242 | };
|
28243 |
|
28244 |
|
28245 | |
28246 |
|
28247 |
|
28248 |
|
28249 |
|
28250 |
|
28251 |
|
28252 |
|
28253 |
|
28254 |
|
28255 |
|
28256 |
|
28257 |
|
28258 |
|
28259 |
|
28260 | P.sine = P.sin = function () {
|
28261 | var pr, rm,
|
28262 | x = this,
|
28263 | Ctor = x.constructor;
|
28264 |
|
28265 | if (!x.isFinite()) return new Ctor(NaN);
|
28266 | if (x.isZero()) return new Ctor(x);
|
28267 |
|
28268 | pr = Ctor.precision;
|
28269 | rm = Ctor.rounding;
|
28270 | Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
28271 | Ctor.rounding = 1;
|
28272 |
|
28273 | x = sine(Ctor, toLessThanHalfPi(Ctor, x));
|
28274 |
|
28275 | Ctor.precision = pr;
|
28276 | Ctor.rounding = rm;
|
28277 |
|
28278 | return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
|
28279 | };
|
28280 |
|
28281 |
|
28282 | |
28283 |
|
28284 |
|
28285 |
|
28286 |
|
28287 |
|
28288 |
|
28289 |
|
28290 |
|
28291 |
|
28292 |
|
28293 |
|
28294 | P.squareRoot = P.sqrt = function () {
|
28295 | var m, n, sd, r, rep, t,
|
28296 | x = this,
|
28297 | d = x.d,
|
28298 | e = x.e,
|
28299 | s = x.s,
|
28300 | Ctor = x.constructor;
|
28301 |
|
28302 |
|
28303 | if (s !== 1 || !d || !d[0]) {
|
28304 | return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
|
28305 | }
|
28306 |
|
28307 | external = false;
|
28308 |
|
28309 |
|
28310 | s = Math.sqrt(+x);
|
28311 |
|
28312 |
|
28313 |
|
28314 | if (s == 0 || s == 1 / 0) {
|
28315 | n = digitsToString(d);
|
28316 |
|
28317 | if ((n.length + e) % 2 == 0) n += '0';
|
28318 | s = Math.sqrt(n);
|
28319 | e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
|
28320 |
|
28321 | if (s == 1 / 0) {
|
28322 | n = '1e' + e;
|
28323 | } else {
|
28324 | n = s.toExponential();
|
28325 | n = n.slice(0, n.indexOf('e') + 1) + e;
|
28326 | }
|
28327 |
|
28328 | r = new Ctor(n);
|
28329 | } else {
|
28330 | r = new Ctor(s.toString());
|
28331 | }
|
28332 |
|
28333 | sd = (e = Ctor.precision) + 3;
|
28334 |
|
28335 |
|
28336 | for (;;) {
|
28337 | t = r;
|
28338 | r = t.plus(divide(x, t, sd + 2, 1)).times(0.5);
|
28339 |
|
28340 |
|
28341 | if (digitsToString(t.d).slice(0, sd) === (n = digitsToString(r.d)).slice(0, sd)) {
|
28342 | n = n.slice(sd - 3, sd + 1);
|
28343 |
|
28344 |
|
28345 |
|
28346 | if (n == '9999' || !rep && n == '4999') {
|
28347 |
|
28348 |
|
28349 |
|
28350 | if (!rep) {
|
28351 | finalise(t, e + 1, 0);
|
28352 |
|
28353 | if (t.times(t).eq(x)) {
|
28354 | r = t;
|
28355 | break;
|
28356 | }
|
28357 | }
|
28358 |
|
28359 | sd += 4;
|
28360 | rep = 1;
|
28361 | } else {
|
28362 |
|
28363 |
|
28364 |
|
28365 | if (!+n || !+n.slice(1) && n.charAt(0) == '5') {
|
28366 |
|
28367 |
|
28368 | finalise(r, e + 1, 1);
|
28369 | m = !r.times(r).eq(x);
|
28370 | }
|
28371 |
|
28372 | break;
|
28373 | }
|
28374 | }
|
28375 | }
|
28376 |
|
28377 | external = true;
|
28378 |
|
28379 | return finalise(r, e, Ctor.rounding, m);
|
28380 | };
|
28381 |
|
28382 |
|
28383 | |
28384 |
|
28385 |
|
28386 |
|
28387 |
|
28388 |
|
28389 |
|
28390 |
|
28391 |
|
28392 |
|
28393 |
|
28394 |
|
28395 |
|
28396 | P.tangent = P.tan = function () {
|
28397 | var pr, rm,
|
28398 | x = this,
|
28399 | Ctor = x.constructor;
|
28400 |
|
28401 | if (!x.isFinite()) return new Ctor(NaN);
|
28402 | if (x.isZero()) return new Ctor(x);
|
28403 |
|
28404 | pr = Ctor.precision;
|
28405 | rm = Ctor.rounding;
|
28406 | Ctor.precision = pr + 10;
|
28407 | Ctor.rounding = 1;
|
28408 |
|
28409 | x = x.sin();
|
28410 | x.s = 1;
|
28411 | x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
|
28412 |
|
28413 | Ctor.precision = pr;
|
28414 | Ctor.rounding = rm;
|
28415 |
|
28416 | return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
|
28417 | };
|
28418 |
|
28419 |
|
28420 | |
28421 |
|
28422 |
|
28423 |
|
28424 |
|
28425 |
|
28426 |
|
28427 |
|
28428 |
|
28429 |
|
28430 |
|
28431 |
|
28432 |
|
28433 |
|
28434 |
|
28435 |
|
28436 |
|
28437 |
|
28438 |
|
28439 |
|
28440 |
|
28441 | P.times = P.mul = function (y) {
|
28442 | var carry, e, i, k, r, rL, t, xdL, ydL,
|
28443 | x = this,
|
28444 | Ctor = x.constructor,
|
28445 | xd = x.d,
|
28446 | yd = (y = new Ctor(y)).d;
|
28447 |
|
28448 | y.s *= x.s;
|
28449 |
|
28450 |
|
28451 | if (!xd || !xd[0] || !yd || !yd[0]) {
|
28452 |
|
28453 | return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd
|
28454 |
|
28455 |
|
28456 |
|
28457 | ? NaN
|
28458 |
|
28459 |
|
28460 |
|
28461 | : !xd || !yd ? y.s / 0 : y.s * 0);
|
28462 | }
|
28463 |
|
28464 | e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
|
28465 | xdL = xd.length;
|
28466 | ydL = yd.length;
|
28467 |
|
28468 |
|
28469 | if (xdL < ydL) {
|
28470 | r = xd;
|
28471 | xd = yd;
|
28472 | yd = r;
|
28473 | rL = xdL;
|
28474 | xdL = ydL;
|
28475 | ydL = rL;
|
28476 | }
|
28477 |
|
28478 |
|
28479 | r = [];
|
28480 | rL = xdL + ydL;
|
28481 | for (i = rL; i--;) r.push(0);
|
28482 |
|
28483 |
|
28484 | for (i = ydL; --i >= 0;) {
|
28485 | carry = 0;
|
28486 | for (k = xdL + i; k > i;) {
|
28487 | t = r[k] + yd[i] * xd[k - i - 1] + carry;
|
28488 | r[k--] = t % BASE | 0;
|
28489 | carry = t / BASE | 0;
|
28490 | }
|
28491 |
|
28492 | r[k] = (r[k] + carry) % BASE | 0;
|
28493 | }
|
28494 |
|
28495 |
|
28496 | for (; !r[--rL];) r.pop();
|
28497 |
|
28498 | if (carry) ++e;
|
28499 | else r.shift();
|
28500 |
|
28501 | y.d = r;
|
28502 | y.e = getBase10Exponent(r, e);
|
28503 |
|
28504 | return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
|
28505 | };
|
28506 |
|
28507 |
|
28508 | |
28509 |
|
28510 |
|
28511 |
|
28512 |
|
28513 |
|
28514 |
|
28515 |
|
28516 |
|
28517 |
|
28518 | P.toBinary = function (sd, rm) {
|
28519 | return toStringBinary(this, 2, sd, rm);
|
28520 | };
|
28521 |
|
28522 |
|
28523 | |
28524 |
|
28525 |
|
28526 |
|
28527 |
|
28528 |
|
28529 |
|
28530 |
|
28531 |
|
28532 |
|
28533 | P.toDecimalPlaces = P.toDP = function (dp, rm) {
|
28534 | var x = this,
|
28535 | Ctor = x.constructor;
|
28536 |
|
28537 | x = new Ctor(x);
|
28538 | if (dp === void 0) return x;
|
28539 |
|
28540 | checkInt32(dp, 0, MAX_DIGITS);
|
28541 |
|
28542 | if (rm === void 0) rm = Ctor.rounding;
|
28543 | else checkInt32(rm, 0, 8);
|
28544 |
|
28545 | return finalise(x, dp + x.e + 1, rm);
|
28546 | };
|
28547 |
|
28548 |
|
28549 | |
28550 |
|
28551 |
|
28552 |
|
28553 |
|
28554 |
|
28555 |
|
28556 |
|
28557 | P.toExponential = function (dp, rm) {
|
28558 | var str,
|
28559 | x = this,
|
28560 | Ctor = x.constructor;
|
28561 |
|
28562 | if (dp === void 0) {
|
28563 | str = finiteToString(x, true);
|
28564 | } else {
|
28565 | checkInt32(dp, 0, MAX_DIGITS);
|
28566 |
|
28567 | if (rm === void 0) rm = Ctor.rounding;
|
28568 | else checkInt32(rm, 0, 8);
|
28569 |
|
28570 | x = finalise(new Ctor(x), dp + 1, rm);
|
28571 | str = finiteToString(x, true, dp + 1);
|
28572 | }
|
28573 |
|
28574 | return x.isNeg() && !x.isZero() ? '-' + str : str;
|
28575 | };
|
28576 |
|
28577 |
|
28578 | |
28579 |
|
28580 |
|
28581 |
|
28582 |
|
28583 |
|
28584 |
|
28585 |
|
28586 |
|
28587 |
|
28588 |
|
28589 |
|
28590 |
|
28591 |
|
28592 |
|
28593 |
|
28594 | P.toFixed = function (dp, rm) {
|
28595 | var str, y,
|
28596 | x = this,
|
28597 | Ctor = x.constructor;
|
28598 |
|
28599 | if (dp === void 0) {
|
28600 | str = finiteToString(x);
|
28601 | } else {
|
28602 | checkInt32(dp, 0, MAX_DIGITS);
|
28603 |
|
28604 | if (rm === void 0) rm = Ctor.rounding;
|
28605 | else checkInt32(rm, 0, 8);
|
28606 |
|
28607 | y = finalise(new Ctor(x), dp + x.e + 1, rm);
|
28608 | str = finiteToString(y, false, dp + y.e + 1);
|
28609 | }
|
28610 |
|
28611 |
|
28612 |
|
28613 | return x.isNeg() && !x.isZero() ? '-' + str : str;
|
28614 | };
|
28615 |
|
28616 |
|
28617 | |
28618 |
|
28619 |
|
28620 |
|
28621 |
|
28622 |
|
28623 |
|
28624 |
|
28625 |
|
28626 |
|
28627 |
|
28628 | P.toFraction = function (maxD) {
|
28629 | var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r,
|
28630 | x = this,
|
28631 | xd = x.d,
|
28632 | Ctor = x.constructor;
|
28633 |
|
28634 | if (!xd) return new Ctor(x);
|
28635 |
|
28636 | n1 = d0 = new Ctor(1);
|
28637 | d1 = n0 = new Ctor(0);
|
28638 |
|
28639 | d = new Ctor(d1);
|
28640 | e = d.e = getPrecision(xd) - x.e - 1;
|
28641 | k = e % LOG_BASE;
|
28642 | d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
|
28643 |
|
28644 | if (maxD == null) {
|
28645 |
|
28646 |
|
28647 | maxD = e > 0 ? d : n1;
|
28648 | } else {
|
28649 | n = new Ctor(maxD);
|
28650 | if (!n.isInt() || n.lt(n1)) throw Error(invalidArgument + n);
|
28651 | maxD = n.gt(d) ? (e > 0 ? d : n1) : n;
|
28652 | }
|
28653 |
|
28654 | external = false;
|
28655 | n = new Ctor(digitsToString(xd));
|
28656 | pr = Ctor.precision;
|
28657 | Ctor.precision = e = xd.length * LOG_BASE * 2;
|
28658 |
|
28659 | for (;;) {
|
28660 | q = divide(n, d, 0, 1, 1);
|
28661 | d2 = d0.plus(q.times(d1));
|
28662 | if (d2.cmp(maxD) == 1) break;
|
28663 | d0 = d1;
|
28664 | d1 = d2;
|
28665 | d2 = n1;
|
28666 | n1 = n0.plus(q.times(d2));
|
28667 | n0 = d2;
|
28668 | d2 = d;
|
28669 | d = n.minus(q.times(d2));
|
28670 | n = d2;
|
28671 | }
|
28672 |
|
28673 | d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
|
28674 | n0 = n0.plus(d2.times(n1));
|
28675 | d0 = d0.plus(d2.times(d1));
|
28676 | n0.s = n1.s = x.s;
|
28677 |
|
28678 |
|
28679 | r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1
|
28680 | ? [n1, d1] : [n0, d0];
|
28681 |
|
28682 | Ctor.precision = pr;
|
28683 | external = true;
|
28684 |
|
28685 | return r;
|
28686 | };
|
28687 |
|
28688 |
|
28689 | |
28690 |
|
28691 |
|
28692 |
|
28693 |
|
28694 |
|
28695 |
|
28696 |
|
28697 |
|
28698 |
|
28699 | P.toHexadecimal = P.toHex = function (sd, rm) {
|
28700 | return toStringBinary(this, 16, sd, rm);
|
28701 | };
|
28702 |
|
28703 |
|
28704 | |
28705 |
|
28706 |
|
28707 |
|
28708 |
|
28709 |
|
28710 |
|
28711 |
|
28712 |
|
28713 |
|
28714 |
|
28715 |
|
28716 |
|
28717 |
|
28718 |
|
28719 |
|
28720 | P.toNearest = function (y, rm) {
|
28721 | var x = this,
|
28722 | Ctor = x.constructor;
|
28723 |
|
28724 | x = new Ctor(x);
|
28725 |
|
28726 | if (y == null) {
|
28727 |
|
28728 |
|
28729 | if (!x.d) return x;
|
28730 |
|
28731 | y = new Ctor(1);
|
28732 | rm = Ctor.rounding;
|
28733 | } else {
|
28734 | y = new Ctor(y);
|
28735 | if (rm === void 0) {
|
28736 | rm = Ctor.rounding;
|
28737 | } else {
|
28738 | checkInt32(rm, 0, 8);
|
28739 | }
|
28740 |
|
28741 |
|
28742 | if (!x.d) return y.s ? x : y;
|
28743 |
|
28744 |
|
28745 | if (!y.d) {
|
28746 | if (y.s) y.s = x.s;
|
28747 | return y;
|
28748 | }
|
28749 | }
|
28750 |
|
28751 |
|
28752 | if (y.d[0]) {
|
28753 | external = false;
|
28754 | x = divide(x, y, 0, rm, 1).times(y);
|
28755 | external = true;
|
28756 | finalise(x);
|
28757 |
|
28758 |
|
28759 | } else {
|
28760 | y.s = x.s;
|
28761 | x = y;
|
28762 | }
|
28763 |
|
28764 | return x;
|
28765 | };
|
28766 |
|
28767 |
|
28768 | |
28769 |
|
28770 |
|
28771 |
|
28772 |
|
28773 | P.toNumber = function () {
|
28774 | return +this;
|
28775 | };
|
28776 |
|
28777 |
|
28778 | |
28779 |
|
28780 |
|
28781 |
|
28782 |
|
28783 |
|
28784 |
|
28785 |
|
28786 |
|
28787 |
|
28788 | P.toOctal = function (sd, rm) {
|
28789 | return toStringBinary(this, 8, sd, rm);
|
28790 | };
|
28791 |
|
28792 |
|
28793 | |
28794 |
|
28795 |
|
28796 |
|
28797 |
|
28798 |
|
28799 |
|
28800 |
|
28801 |
|
28802 |
|
28803 |
|
28804 |
|
28805 |
|
28806 |
|
28807 |
|
28808 |
|
28809 |
|
28810 |
|
28811 |
|
28812 |
|
28813 |
|
28814 |
|
28815 |
|
28816 |
|
28817 |
|
28818 |
|
28819 |
|
28820 |
|
28821 |
|
28822 |
|
28823 |
|
28824 |
|
28825 |
|
28826 |
|
28827 |
|
28828 |
|
28829 |
|
28830 |
|
28831 |
|
28832 |
|
28833 |
|
28834 |
|
28835 |
|
28836 | P.toPower = P.pow = function (y) {
|
28837 | var e, k, pr, r, rm, s,
|
28838 | x = this,
|
28839 | Ctor = x.constructor,
|
28840 | yn = +(y = new Ctor(y));
|
28841 |
|
28842 |
|
28843 | if (!x.d || !y.d || !x.d[0] || !y.d[0]) return new Ctor(mathpow(+x, yn));
|
28844 |
|
28845 | x = new Ctor(x);
|
28846 |
|
28847 | if (x.eq(1)) return x;
|
28848 |
|
28849 | pr = Ctor.precision;
|
28850 | rm = Ctor.rounding;
|
28851 |
|
28852 | if (y.eq(1)) return finalise(x, pr, rm);
|
28853 |
|
28854 |
|
28855 | e = mathfloor(y.e / LOG_BASE);
|
28856 |
|
28857 |
|
28858 | if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
28859 | r = intPow(Ctor, x, k, pr);
|
28860 | return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
|
28861 | }
|
28862 |
|
28863 | s = x.s;
|
28864 |
|
28865 |
|
28866 | if (s < 0) {
|
28867 |
|
28868 |
|
28869 | if (e < y.d.length - 1) return new Ctor(NaN);
|
28870 |
|
28871 |
|
28872 | if ((y.d[e] & 1) == 0) s = 1;
|
28873 |
|
28874 |
|
28875 | if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
|
28876 | x.s = s;
|
28877 | return x;
|
28878 | }
|
28879 | }
|
28880 |
|
28881 |
|
28882 |
|
28883 |
|
28884 |
|
28885 | k = mathpow(+x, yn);
|
28886 | e = k == 0 || !isFinite(k)
|
28887 | ? mathfloor(yn * (Math.log('0.' + digitsToString(x.d)) / Math.LN10 + x.e + 1))
|
28888 | : new Ctor(k + '').e;
|
28889 |
|
28890 |
|
28891 |
|
28892 |
|
28893 | if (e > Ctor.maxE + 1 || e < Ctor.minE - 1) return new Ctor(e > 0 ? s / 0 : 0);
|
28894 |
|
28895 | external = false;
|
28896 | Ctor.rounding = x.s = 1;
|
28897 |
|
28898 |
|
28899 |
|
28900 |
|
28901 |
|
28902 | k = Math.min(12, (e + '').length);
|
28903 |
|
28904 |
|
28905 | r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
|
28906 |
|
28907 |
|
28908 | if (r.d) {
|
28909 |
|
28910 |
|
28911 | r = finalise(r, pr + 5, 1);
|
28912 |
|
28913 |
|
28914 |
|
28915 | if (checkRoundingDigits(r.d, pr, rm)) {
|
28916 | e = pr + 10;
|
28917 |
|
28918 |
|
28919 | r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
|
28920 |
|
28921 |
|
28922 | if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) {
|
28923 | r = finalise(r, pr + 1, 0);
|
28924 | }
|
28925 | }
|
28926 | }
|
28927 |
|
28928 | r.s = s;
|
28929 | external = true;
|
28930 | Ctor.rounding = rm;
|
28931 |
|
28932 | return finalise(r, pr, rm);
|
28933 | };
|
28934 |
|
28935 |
|
28936 | |
28937 |
|
28938 |
|
28939 |
|
28940 |
|
28941 |
|
28942 |
|
28943 |
|
28944 |
|
28945 |
|
28946 |
|
28947 | P.toPrecision = function (sd, rm) {
|
28948 | var str,
|
28949 | x = this,
|
28950 | Ctor = x.constructor;
|
28951 |
|
28952 | if (sd === void 0) {
|
28953 | str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
28954 | } else {
|
28955 | checkInt32(sd, 1, MAX_DIGITS);
|
28956 |
|
28957 | if (rm === void 0) rm = Ctor.rounding;
|
28958 | else checkInt32(rm, 0, 8);
|
28959 |
|
28960 | x = finalise(new Ctor(x), sd, rm);
|
28961 | str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
|
28962 | }
|
28963 |
|
28964 | return x.isNeg() && !x.isZero() ? '-' + str : str;
|
28965 | };
|
28966 |
|
28967 |
|
28968 | |
28969 |
|
28970 |
|
28971 |
|
28972 |
|
28973 |
|
28974 |
|
28975 |
|
28976 |
|
28977 |
|
28978 |
|
28979 |
|
28980 |
|
28981 |
|
28982 | P.toSignificantDigits = P.toSD = function (sd, rm) {
|
28983 | var x = this,
|
28984 | Ctor = x.constructor;
|
28985 |
|
28986 | if (sd === void 0) {
|
28987 | sd = Ctor.precision;
|
28988 | rm = Ctor.rounding;
|
28989 | } else {
|
28990 | checkInt32(sd, 1, MAX_DIGITS);
|
28991 |
|
28992 | if (rm === void 0) rm = Ctor.rounding;
|
28993 | else checkInt32(rm, 0, 8);
|
28994 | }
|
28995 |
|
28996 | return finalise(new Ctor(x), sd, rm);
|
28997 | };
|
28998 |
|
28999 |
|
29000 | |
29001 |
|
29002 |
|
29003 |
|
29004 |
|
29005 |
|
29006 |
|
29007 | P.toString = function () {
|
29008 | var x = this,
|
29009 | Ctor = x.constructor,
|
29010 | str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
29011 |
|
29012 | return x.isNeg() && !x.isZero() ? '-' + str : str;
|
29013 | };
|
29014 |
|
29015 |
|
29016 | |
29017 |
|
29018 |
|
29019 |
|
29020 | P.truncated = P.trunc = function () {
|
29021 | return finalise(new this.constructor(this), this.e + 1, 1);
|
29022 | };
|
29023 |
|
29024 |
|
29025 | |
29026 |
|
29027 |
|
29028 |
|
29029 |
|
29030 | P.valueOf = P.toJSON = function () {
|
29031 | var x = this,
|
29032 | Ctor = x.constructor,
|
29033 | str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
29034 |
|
29035 | return x.isNeg() ? '-' + str : str;
|
29036 | };
|
29037 |
|
29038 |
|
29039 | |
29040 |
|
29041 |
|
29042 |
|
29043 |
|
29044 |
|
29045 |
|
29046 |
|
29047 |
|
29048 |
|
29049 |
|
29050 |
|
29051 |
|
29052 |
|
29053 |
|
29054 | |
29055 |
|
29056 |
|
29057 |
|
29058 |
|
29059 |
|
29060 |
|
29061 |
|
29062 |
|
29063 |
|
29064 |
|
29065 |
|
29066 |
|
29067 |
|
29068 |
|
29069 |
|
29070 |
|
29071 |
|
29072 |
|
29073 |
|
29074 |
|
29075 |
|
29076 |
|
29077 |
|
29078 |
|
29079 |
|
29080 |
|
29081 |
|
29082 |
|
29083 |
|
29084 |
|
29085 |
|
29086 |
|
29087 |
|
29088 |
|
29089 |
|
29090 |
|
29091 |
|
29092 |
|
29093 |
|
29094 |
|
29095 |
|
29096 |
|
29097 |
|
29098 |
|
29099 |
|
29100 | function digitsToString(d) {
|
29101 | var i, k, ws,
|
29102 | indexOfLastWord = d.length - 1,
|
29103 | str = '',
|
29104 | w = d[0];
|
29105 |
|
29106 | if (indexOfLastWord > 0) {
|
29107 | str += w;
|
29108 | for (i = 1; i < indexOfLastWord; i++) {
|
29109 | ws = d[i] + '';
|
29110 | k = LOG_BASE - ws.length;
|
29111 | if (k) str += getZeroString(k);
|
29112 | str += ws;
|
29113 | }
|
29114 |
|
29115 | w = d[i];
|
29116 | ws = w + '';
|
29117 | k = LOG_BASE - ws.length;
|
29118 | if (k) str += getZeroString(k);
|
29119 | } else if (w === 0) {
|
29120 | return '0';
|
29121 | }
|
29122 |
|
29123 |
|
29124 | for (; w % 10 === 0;) w /= 10;
|
29125 |
|
29126 | return str + w;
|
29127 | }
|
29128 |
|
29129 |
|
29130 | function checkInt32(i, min, max) {
|
29131 | if (i !== ~~i || i < min || i > max) {
|
29132 | throw Error(invalidArgument + i);
|
29133 | }
|
29134 | }
|
29135 |
|
29136 |
|
29137 | |
29138 |
|
29139 |
|
29140 |
|
29141 |
|
29142 | function checkRoundingDigits(d, i, rm, repeating) {
|
29143 | var di, k, r, rd;
|
29144 |
|
29145 |
|
29146 | for (k = d[0]; k >= 10; k /= 10) --i;
|
29147 |
|
29148 |
|
29149 | if (--i < 0) {
|
29150 | i += LOG_BASE;
|
29151 | di = 0;
|
29152 | } else {
|
29153 | di = Math.ceil((i + 1) / LOG_BASE);
|
29154 | i %= LOG_BASE;
|
29155 | }
|
29156 |
|
29157 |
|
29158 |
|
29159 |
|
29160 | k = mathpow(10, LOG_BASE - i);
|
29161 | rd = d[di] % k | 0;
|
29162 |
|
29163 | if (repeating == null) {
|
29164 | if (i < 3) {
|
29165 | if (i == 0) rd = rd / 100 | 0;
|
29166 | else if (i == 1) rd = rd / 10 | 0;
|
29167 | r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 50000 || rd == 0;
|
29168 | } else {
|
29169 | r = (rm < 4 && rd + 1 == k || rm > 3 && rd + 1 == k / 2) &&
|
29170 | (d[di + 1] / k / 100 | 0) == mathpow(10, i - 2) - 1 ||
|
29171 | (rd == k / 2 || rd == 0) && (d[di + 1] / k / 100 | 0) == 0;
|
29172 | }
|
29173 | } else {
|
29174 | if (i < 4) {
|
29175 | if (i == 0) rd = rd / 1000 | 0;
|
29176 | else if (i == 1) rd = rd / 100 | 0;
|
29177 | else if (i == 2) rd = rd / 10 | 0;
|
29178 | r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
|
29179 | } else {
|
29180 | r = ((repeating || rm < 4) && rd + 1 == k ||
|
29181 | (!repeating && rm > 3) && rd + 1 == k / 2) &&
|
29182 | (d[di + 1] / k / 1000 | 0) == mathpow(10, i - 3) - 1;
|
29183 | }
|
29184 | }
|
29185 |
|
29186 | return r;
|
29187 | }
|
29188 |
|
29189 |
|
29190 |
|
29191 |
|
29192 |
|
29193 | function convertBase(str, baseIn, baseOut) {
|
29194 | var j,
|
29195 | arr = [0],
|
29196 | arrL,
|
29197 | i = 0,
|
29198 | strL = str.length;
|
29199 |
|
29200 | for (; i < strL;) {
|
29201 | for (arrL = arr.length; arrL--;) arr[arrL] *= baseIn;
|
29202 | arr[0] += NUMERALS.indexOf(str.charAt(i++));
|
29203 | for (j = 0; j < arr.length; j++) {
|
29204 | if (arr[j] > baseOut - 1) {
|
29205 | if (arr[j + 1] === void 0) arr[j + 1] = 0;
|
29206 | arr[j + 1] += arr[j] / baseOut | 0;
|
29207 | arr[j] %= baseOut;
|
29208 | }
|
29209 | }
|
29210 | }
|
29211 |
|
29212 | return arr.reverse();
|
29213 | }
|
29214 |
|
29215 |
|
29216 | |
29217 |
|
29218 |
|
29219 |
|
29220 |
|
29221 | function cosine(Ctor, x) {
|
29222 | var k, y,
|
29223 | len = x.d.length;
|
29224 |
|
29225 |
|
29226 |
|
29227 |
|
29228 |
|
29229 | if (len < 32) {
|
29230 | k = Math.ceil(len / 3);
|
29231 | y = Math.pow(4, -k).toString();
|
29232 | } else {
|
29233 | k = 16;
|
29234 | y = '2.3283064365386962890625e-10';
|
29235 | }
|
29236 |
|
29237 | Ctor.precision += k;
|
29238 |
|
29239 | x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
|
29240 |
|
29241 |
|
29242 | for (var i = k; i--;) {
|
29243 | var cos2x = x.times(x);
|
29244 | x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
|
29245 | }
|
29246 |
|
29247 | Ctor.precision -= k;
|
29248 |
|
29249 | return x;
|
29250 | }
|
29251 |
|
29252 |
|
29253 | |
29254 |
|
29255 |
|
29256 | var divide = (function () {
|
29257 |
|
29258 |
|
29259 | function multiplyInteger(x, k, base) {
|
29260 | var temp,
|
29261 | carry = 0,
|
29262 | i = x.length;
|
29263 |
|
29264 | for (x = x.slice(); i--;) {
|
29265 | temp = x[i] * k + carry;
|
29266 | x[i] = temp % base | 0;
|
29267 | carry = temp / base | 0;
|
29268 | }
|
29269 |
|
29270 | if (carry) x.unshift(carry);
|
29271 |
|
29272 | return x;
|
29273 | }
|
29274 |
|
29275 | function compare(a, b, aL, bL) {
|
29276 | var i, r;
|
29277 |
|
29278 | if (aL != bL) {
|
29279 | r = aL > bL ? 1 : -1;
|
29280 | } else {
|
29281 | for (i = r = 0; i < aL; i++) {
|
29282 | if (a[i] != b[i]) {
|
29283 | r = a[i] > b[i] ? 1 : -1;
|
29284 | break;
|
29285 | }
|
29286 | }
|
29287 | }
|
29288 |
|
29289 | return r;
|
29290 | }
|
29291 |
|
29292 | function subtract(a, b, aL, base) {
|
29293 | var i = 0;
|
29294 |
|
29295 |
|
29296 | for (; aL--;) {
|
29297 | a[aL] -= i;
|
29298 | i = a[aL] < b[aL] ? 1 : 0;
|
29299 | a[aL] = i * base + a[aL] - b[aL];
|
29300 | }
|
29301 |
|
29302 |
|
29303 | for (; !a[0] && a.length > 1;) a.shift();
|
29304 | }
|
29305 |
|
29306 | return function (x, y, pr, rm, dp, base) {
|
29307 | var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0,
|
29308 | yL, yz,
|
29309 | Ctor = x.constructor,
|
29310 | sign = x.s == y.s ? 1 : -1,
|
29311 | xd = x.d,
|
29312 | yd = y.d;
|
29313 |
|
29314 |
|
29315 | if (!xd || !xd[0] || !yd || !yd[0]) {
|
29316 |
|
29317 | return new Ctor(
|
29318 | !x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN :
|
29319 |
|
29320 |
|
29321 | xd && xd[0] == 0 || !yd ? sign * 0 : sign / 0);
|
29322 | }
|
29323 |
|
29324 | if (base) {
|
29325 | logBase = 1;
|
29326 | e = x.e - y.e;
|
29327 | } else {
|
29328 | base = BASE;
|
29329 | logBase = LOG_BASE;
|
29330 | e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
|
29331 | }
|
29332 |
|
29333 | yL = yd.length;
|
29334 | xL = xd.length;
|
29335 | q = new Ctor(sign);
|
29336 | qd = q.d = [];
|
29337 |
|
29338 |
|
29339 |
|
29340 | for (i = 0; yd[i] == (xd[i] || 0); i++);
|
29341 |
|
29342 | if (yd[i] > (xd[i] || 0)) e--;
|
29343 |
|
29344 | if (pr == null) {
|
29345 | sd = pr = Ctor.precision;
|
29346 | rm = Ctor.rounding;
|
29347 | } else if (dp) {
|
29348 | sd = pr + (x.e - y.e) + 1;
|
29349 | } else {
|
29350 | sd = pr;
|
29351 | }
|
29352 |
|
29353 | if (sd < 0) {
|
29354 | qd.push(1);
|
29355 | more = true;
|
29356 | } else {
|
29357 |
|
29358 |
|
29359 | sd = sd / logBase + 2 | 0;
|
29360 | i = 0;
|
29361 |
|
29362 |
|
29363 | if (yL == 1) {
|
29364 | k = 0;
|
29365 | yd = yd[0];
|
29366 | sd++;
|
29367 |
|
29368 |
|
29369 | for (; (i < xL || k) && sd--; i++) {
|
29370 | t = k * base + (xd[i] || 0);
|
29371 | qd[i] = t / yd | 0;
|
29372 | k = t % yd | 0;
|
29373 | }
|
29374 |
|
29375 | more = k || i < xL;
|
29376 |
|
29377 |
|
29378 | } else {
|
29379 |
|
29380 |
|
29381 | k = base / (yd[0] + 1) | 0;
|
29382 |
|
29383 | if (k > 1) {
|
29384 | yd = multiplyInteger(yd, k, base);
|
29385 | xd = multiplyInteger(xd, k, base);
|
29386 | yL = yd.length;
|
29387 | xL = xd.length;
|
29388 | }
|
29389 |
|
29390 | xi = yL;
|
29391 | rem = xd.slice(0, yL);
|
29392 | remL = rem.length;
|
29393 |
|
29394 |
|
29395 | for (; remL < yL;) rem[remL++] = 0;
|
29396 |
|
29397 | yz = yd.slice();
|
29398 | yz.unshift(0);
|
29399 | yd0 = yd[0];
|
29400 |
|
29401 | if (yd[1] >= base / 2) ++yd0;
|
29402 |
|
29403 | do {
|
29404 | k = 0;
|
29405 |
|
29406 |
|
29407 | cmp = compare(yd, rem, yL, remL);
|
29408 |
|
29409 |
|
29410 | if (cmp < 0) {
|
29411 |
|
29412 |
|
29413 | rem0 = rem[0];
|
29414 | if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
|
29415 |
|
29416 |
|
29417 | k = rem0 / yd0 | 0;
|
29418 |
|
29419 |
|
29420 |
|
29421 |
|
29422 |
|
29423 |
|
29424 |
|
29425 |
|
29426 |
|
29427 | if (k > 1) {
|
29428 | if (k >= base) k = base - 1;
|
29429 |
|
29430 |
|
29431 | prod = multiplyInteger(yd, k, base);
|
29432 | prodL = prod.length;
|
29433 | remL = rem.length;
|
29434 |
|
29435 |
|
29436 | cmp = compare(prod, rem, prodL, remL);
|
29437 |
|
29438 |
|
29439 | if (cmp == 1) {
|
29440 | k--;
|
29441 |
|
29442 |
|
29443 | subtract(prod, yL < prodL ? yz : yd, prodL, base);
|
29444 | }
|
29445 | } else {
|
29446 |
|
29447 |
|
29448 |
|
29449 |
|
29450 | if (k == 0) cmp = k = 1;
|
29451 | prod = yd.slice();
|
29452 | }
|
29453 |
|
29454 | prodL = prod.length;
|
29455 | if (prodL < remL) prod.unshift(0);
|
29456 |
|
29457 |
|
29458 | subtract(rem, prod, remL, base);
|
29459 |
|
29460 |
|
29461 | if (cmp == -1) {
|
29462 | remL = rem.length;
|
29463 |
|
29464 |
|
29465 | cmp = compare(yd, rem, yL, remL);
|
29466 |
|
29467 |
|
29468 | if (cmp < 1) {
|
29469 | k++;
|
29470 |
|
29471 |
|
29472 | subtract(rem, yL < remL ? yz : yd, remL, base);
|
29473 | }
|
29474 | }
|
29475 |
|
29476 | remL = rem.length;
|
29477 | } else if (cmp === 0) {
|
29478 | k++;
|
29479 | rem = [0];
|
29480 | }
|
29481 |
|
29482 |
|
29483 | qd[i++] = k;
|
29484 |
|
29485 |
|
29486 | if (cmp && rem[0]) {
|
29487 | rem[remL++] = xd[xi] || 0;
|
29488 | } else {
|
29489 | rem = [xd[xi]];
|
29490 | remL = 1;
|
29491 | }
|
29492 |
|
29493 | } while ((xi++ < xL || rem[0] !== void 0) && sd--);
|
29494 |
|
29495 | more = rem[0] !== void 0;
|
29496 | }
|
29497 |
|
29498 | // Leading zero?
|
29499 | if (!qd[0]) qd.shift();
|
29500 | }
|
29501 |
|
29502 | // logBase is 1 when divide is being used for base conversion.
|
29503 | if (logBase == 1) {
|
29504 | q.e = e;
|
29505 | inexact = more;
|
29506 | } else {
|
29507 |
|
29508 | // To calculate q.e, first get the number of digits of qd[0].
|
29509 | for (i = 1, k = qd[0]; k >= 10; k /= 10) i++;
|
29510 | q.e = i + e * logBase - 1;
|
29511 |
|
29512 | finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
|
29513 | }
|
29514 |
|
29515 | return q;
|
29516 | };
|
29517 | })();
|
29518 |
|
29519 |
|
29520 | /*
|
29521 | * Round `x` to `sd` significant digits using rounding mode `rm`.
|
29522 | * Check for over/under-flow.
|
29523 | */
|
29524 | function finalise(x, sd, rm, isTruncated) {
|
29525 | var digits, i, j, k, rd, roundUp, w, xd, xdi,
|
29526 | Ctor = x.constructor;
|
29527 |
|
29528 | // Don't round if sd is null or undefined.
|
29529 | out: if (sd != null) {
|
29530 | xd = x.d;
|
29531 |
|
29532 | // Infinity/NaN.
|
29533 | if (!xd) return x;
|
29534 |
|
29535 | // rd: the rounding digit, i.e. the digit after the digit that may be rounded up.
|
29536 | // w: the word of xd containing rd, a base 1e7 number.
|
29537 | // xdi: the index of w within xd.
|
29538 | // digits: the number of digits of w.
|
29539 | // i: what would be the index of rd within w if all the numbers were 7 digits long (i.e. if
|
29540 | // they had leading zeros)
|
29541 | // j: if > 0, the actual index of rd within w (if < 0, rd is a leading zero).
|
29542 |
|
29543 | // Get the length of the first word of the digits array xd.
|
29544 | for (digits = 1, k = xd[0]; k >= 10; k /= 10) digits++;
|
29545 | i = sd - digits;
|
29546 |
|
29547 | // Is the rounding digit in the first word of xd?
|
29548 | if (i < 0) {
|
29549 | i += LOG_BASE;
|
29550 | j = sd;
|
29551 | w = xd[xdi = 0];
|
29552 |
|
29553 | // Get the rounding digit at index j of w.
|
29554 | rd = w / mathpow(10, digits - j - 1) % 10 | 0;
|
29555 | } else {
|
29556 | xdi = Math.ceil((i + 1) / LOG_BASE);
|
29557 | k = xd.length;
|
29558 | if (xdi >= k) {
|
29559 | if (isTruncated) {
|
29560 |
|
29561 | // Needed by `naturalExponential`, `naturalLogarithm` and `squareRoot`.
|
29562 | for (; k++ <= xdi;) xd.push(0);
|
29563 | w = rd = 0;
|
29564 | digits = 1;
|
29565 | i %= LOG_BASE;
|
29566 | j = i - LOG_BASE + 1;
|
29567 | } else {
|
29568 | break out;
|
29569 | }
|
29570 | } else {
|
29571 | w = k = xd[xdi];
|
29572 |
|
29573 | // Get the number of digits of w.
|
29574 | for (digits = 1; k >= 10; k /= 10) digits++;
|
29575 |
|
29576 | // Get the index of rd within w.
|
29577 | i %= LOG_BASE;
|
29578 |
|
29579 | // Get the index of rd within w, adjusted for leading zeros.
|
29580 | // The number of leading zeros of w is given by LOG_BASE - digits.
|
29581 | j = i - LOG_BASE + digits;
|
29582 |
|
29583 | // Get the rounding digit at index j of w.
|
29584 | rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
|
29585 | }
|
29586 | }
|
29587 |
|
29588 | // Are there any non-zero digits after the rounding digit?
|
29589 | isTruncated = isTruncated || sd < 0 ||
|
29590 | xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits - j - 1));
|
29591 |
|
29592 | // The expression `w % mathpow(10, digits - j - 1)` returns all the digits of w to the right
|
29593 | // of the digit at (left-to-right) index j, e.g. if w is 908714 and j is 2, the expression
|
29594 | // will give 714.
|
29595 |
|
29596 | roundUp = rm < 4
|
29597 | ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
|
29598 | : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 &&
|
29599 |
|
29600 | // Check whether the digit to the left of the rounding digit is odd.
|
29601 | ((i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10) & 1 ||
|
29602 | rm == (x.s < 0 ? 8 : 7));
|
29603 |
|
29604 | if (sd < 1 || !xd[0]) {
|
29605 | xd.length = 0;
|
29606 | if (roundUp) {
|
29607 |
|
29608 | // Convert sd to decimal places.
|
29609 | sd -= x.e + 1;
|
29610 |
|
29611 | // 1, 0.1, 0.01, 0.001, 0.0001 etc.
|
29612 | xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
|
29613 | x.e = -sd || 0;
|
29614 | } else {
|
29615 |
|
29616 | // Zero.
|
29617 | xd[0] = x.e = 0;
|
29618 | }
|
29619 |
|
29620 | return x;
|
29621 | }
|
29622 |
|
29623 | // Remove excess digits.
|
29624 | if (i == 0) {
|
29625 | xd.length = xdi;
|
29626 | k = 1;
|
29627 | xdi--;
|
29628 | } else {
|
29629 | xd.length = xdi + 1;
|
29630 | k = mathpow(10, LOG_BASE - i);
|
29631 |
|
29632 | // E.g. 56700 becomes 56000 if 7 is the rounding digit.
|
29633 | // j > 0 means i > number of leading zeros of w.
|
29634 | xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
|
29635 | }
|
29636 |
|
29637 | if (roundUp) {
|
29638 | for (;;) {
|
29639 |
|
29640 | // Is the digit to be rounded up in the first word of xd?
|
29641 | if (xdi == 0) {
|
29642 |
|
29643 | // i will be the length of xd[0] before k is added.
|
29644 | for (i = 1, j = xd[0]; j >= 10; j /= 10) i++;
|
29645 | j = xd[0] += k;
|
29646 | for (k = 1; j >= 10; j /= 10) k++;
|
29647 |
|
29648 | // if i != k the length has increased.
|
29649 | if (i != k) {
|
29650 | x.e++;
|
29651 | if (xd[0] == BASE) xd[0] = 1;
|
29652 | }
|
29653 |
|
29654 | break;
|
29655 | } else {
|
29656 | xd[xdi] += k;
|
29657 | if (xd[xdi] != BASE) break;
|
29658 | xd[xdi--] = 0;
|
29659 | k = 1;
|
29660 | }
|
29661 | }
|
29662 | }
|
29663 |
|
29664 | // Remove trailing zeros.
|
29665 | for (i = xd.length; xd[--i] === 0;) xd.pop();
|
29666 | }
|
29667 |
|
29668 | if (external) {
|
29669 |
|
29670 | // Overflow?
|
29671 | if (x.e > Ctor.maxE) {
|
29672 |
|
29673 | // Infinity.
|
29674 | x.d = null;
|
29675 | x.e = NaN;
|
29676 |
|
29677 | // Underflow?
|
29678 | } else if (x.e < Ctor.minE) {
|
29679 |
|
29680 | // Zero.
|
29681 | x.e = 0;
|
29682 | x.d = [0];
|
29683 | // Ctor.underflow = true;
|
29684 | } // else Ctor.underflow = false;
|
29685 | }
|
29686 |
|
29687 | return x;
|
29688 | }
|
29689 |
|
29690 |
|
29691 | function finiteToString(x, isExp, sd) {
|
29692 | if (!x.isFinite()) return nonFiniteToString(x);
|
29693 | var k,
|
29694 | e = x.e,
|
29695 | str = digitsToString(x.d),
|
29696 | len = str.length;
|
29697 |
|
29698 | if (isExp) {
|
29699 | if (sd && (k = sd - len) > 0) {
|
29700 | str = str.charAt(0) + '.' + str.slice(1) + getZeroString(k);
|
29701 | } else if (len > 1) {
|
29702 | str = str.charAt(0) + '.' + str.slice(1);
|
29703 | }
|
29704 |
|
29705 | str = str + (x.e < 0 ? 'e' : 'e+') + x.e;
|
29706 | } else if (e < 0) {
|
29707 | str = '0.' + getZeroString(-e - 1) + str;
|
29708 | if (sd && (k = sd - len) > 0) str += getZeroString(k);
|
29709 | } else if (e >= len) {
|
29710 | str += getZeroString(e + 1 - len);
|
29711 | if (sd && (k = sd - e - 1) > 0) str = str + '.' + getZeroString(k);
|
29712 | } else {
|
29713 | if ((k = e + 1) < len) str = str.slice(0, k) + '.' + str.slice(k);
|
29714 | if (sd && (k = sd - len) > 0) {
|
29715 | if (e + 1 === len) str += '.';
|
29716 | str += getZeroString(k);
|
29717 | }
|
29718 | }
|
29719 |
|
29720 | return str;
|
29721 | }
|
29722 |
|
29723 |
|
29724 | // Calculate the base 10 exponent from the base 1e7 exponent.
|
29725 | function getBase10Exponent(digits, e) {
|
29726 | var w = digits[0];
|
29727 |
|
29728 | // Add the number of digits of the first word of the digits array.
|
29729 | for ( e *= LOG_BASE; w >= 10; w /= 10) e++;
|
29730 | return e;
|
29731 | }
|
29732 |
|
29733 |
|
29734 | function getLn10(Ctor, sd, pr) {
|
29735 | if (sd > LN10_PRECISION) {
|
29736 |
|
29737 | // Reset global state in case the exception is caught.
|
29738 | external = true;
|
29739 | if (pr) Ctor.precision = pr;
|
29740 | throw Error(precisionLimitExceeded);
|
29741 | }
|
29742 | return finalise(new Ctor(LN10), sd, 1, true);
|
29743 | }
|
29744 |
|
29745 |
|
29746 | function getPi(Ctor, sd, rm) {
|
29747 | if (sd > PI_PRECISION) throw Error(precisionLimitExceeded);
|
29748 | return finalise(new Ctor(PI), sd, rm, true);
|
29749 | }
|
29750 |
|
29751 |
|
29752 | function getPrecision(digits) {
|
29753 | var w = digits.length - 1,
|
29754 | len = w * LOG_BASE + 1;
|
29755 |
|
29756 | w = digits[w];
|
29757 |
|
29758 | // If non-zero...
|
29759 | if (w) {
|
29760 |
|
29761 | // Subtract the number of trailing zeros of the last word.
|
29762 | for (; w % 10 == 0; w /= 10) len--;
|
29763 |
|
29764 | // Add the number of digits of the first word.
|
29765 | for (w = digits[0]; w >= 10; w /= 10) len++;
|
29766 | }
|
29767 |
|
29768 | return len;
|
29769 | }
|
29770 |
|
29771 |
|
29772 | function getZeroString(k) {
|
29773 | var zs = '';
|
29774 | for (; k--;) zs += '0';
|
29775 | return zs;
|
29776 | }
|
29777 |
|
29778 |
|
29779 | /*
|
29780 | * Return a new Decimal whose value is the value of Decimal `x` to the power `n`, where `n` is an
|
29781 | * integer of type number.
|
29782 | *
|
29783 | * Implements 'exponentiation by squaring'. Called by `pow` and `parseOther`.
|
29784 | *
|
29785 | */
|
29786 | function intPow(Ctor, x, n, pr) {
|
29787 | var isTruncated,
|
29788 | r = new Ctor(1),
|
29789 |
|
29790 | // Max n of 9007199254740991 takes 53 loop iterations.
|
29791 | // Maximum digits array length; leaves [28, 34] guard digits.
|
29792 | k = Math.ceil(pr / LOG_BASE + 4);
|
29793 |
|
29794 | external = false;
|
29795 |
|
29796 | for (;;) {
|
29797 | if (n % 2) {
|
29798 | r = r.times(x);
|
29799 | if (truncate(r.d, k)) isTruncated = true;
|
29800 | }
|
29801 |
|
29802 | n = mathfloor(n / 2);
|
29803 | if (n === 0) {
|
29804 |
|
29805 | // To ensure correct rounding when r.d is truncated, increment the last word if it is zero.
|
29806 | n = r.d.length - 1;
|
29807 | if (isTruncated && r.d[n] === 0) ++r.d[n];
|
29808 | break;
|
29809 | }
|
29810 |
|
29811 | x = x.times(x);
|
29812 | truncate(x.d, k);
|
29813 | }
|
29814 |
|
29815 | external = true;
|
29816 |
|
29817 | return r;
|
29818 | }
|
29819 |
|
29820 |
|
29821 | function isOdd(n) {
|
29822 | return n.d[n.d.length - 1] & 1;
|
29823 | }
|
29824 |
|
29825 |
|
29826 | /*
|
29827 | * Handle `max` and `min`. `ltgt` is 'lt' or 'gt'.
|
29828 | */
|
29829 | function maxOrMin(Ctor, args, ltgt) {
|
29830 | var y,
|
29831 | x = new Ctor(args[0]),
|
29832 | i = 0;
|
29833 |
|
29834 | for (; ++i < args.length;) {
|
29835 | y = new Ctor(args[i]);
|
29836 | if (!y.s) {
|
29837 | x = y;
|
29838 | break;
|
29839 | } else if (x[ltgt](y)) {
|
29840 | x = y;
|
29841 | }
|
29842 | }
|
29843 |
|
29844 | return x;
|
29845 | }
|
29846 |
|
29847 |
|
29848 | /*
|
29849 | * Return a new Decimal whose value is the natural exponential of `x` rounded to `sd` significant
|
29850 | * digits.
|
29851 | *
|
29852 | * Taylor/Maclaurin series.
|
29853 | *
|
29854 | * exp(x) = x^0/0! + x^1/1! + x^2/2! + x^3/3! + ...
|
29855 | *
|
29856 | * Argument reduction:
|
29857 | * Repeat x = x / 32, k += 5, until |x| < 0.1
|
29858 | * exp(x) = exp(x / 2^k)^(2^k)
|
29859 | *
|
29860 | * Previously, the argument was initially reduced by
|
29861 | * exp(x) = exp(r) * 10^k where r = x - k * ln10, k = floor(x / ln10)
|
29862 | * to first put r in the range [0, ln10], before dividing by 32 until |x| < 0.1, but this was
|
29863 | * found to be slower than just dividing repeatedly by 32 as above.
|
29864 | *
|
29865 | * Max integer argument: exp('20723265836946413') = 6.3e+9000000000000000
|
29866 | * Min integer argument: exp('-20723265836946411') = 1.2e-9000000000000000
|
29867 | * (Math object integer min/max: Math.exp(709) = 8.2e+307, Math.exp(-745) = 5e-324)
|
29868 | *
|
29869 | * exp(Infinity) = Infinity
|
29870 | * exp(-Infinity) = 0
|
29871 | * exp(NaN) = NaN
|
29872 | * exp(±0) = 1
|
29873 | *
|
29874 | * exp(x) is non-terminating for any finite, non-zero x.
|
29875 | *
|
29876 | * The result will always be correctly rounded.
|
29877 | *
|
29878 | */
|
29879 | function naturalExponential(x, sd) {
|
29880 | var denominator, guard, j, pow, sum, t, wpr,
|
29881 | rep = 0,
|
29882 | i = 0,
|
29883 | k = 0,
|
29884 | Ctor = x.constructor,
|
29885 | rm = Ctor.rounding,
|
29886 | pr = Ctor.precision;
|
29887 |
|
29888 | // 0/NaN/Infinity?
|
29889 | if (!x.d || !x.d[0] || x.e > 17) {
|
29890 |
|
29891 | return new Ctor(x.d
|
29892 | ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0
|
29893 | : x.s ? x.s < 0 ? 0 : x : 0 / 0);
|
29894 | }
|
29895 |
|
29896 | if (sd == null) {
|
29897 | external = false;
|
29898 | wpr = pr;
|
29899 | } else {
|
29900 | wpr = sd;
|
29901 | }
|
29902 |
|
29903 | t = new Ctor(0.03125);
|
29904 |
|
29905 | // while abs(x) >= 0.1
|
29906 | while (x.e > -2) {
|
29907 |
|
29908 | // x = x / 2^5
|
29909 | x = x.times(t);
|
29910 | k += 5;
|
29911 | }
|
29912 |
|
29913 | // Use 2 * log10(2^k) + 5 (empirically derived) to estimate the increase in precision
|
29914 | // necessary to ensure the first 4 rounding digits are correct.
|
29915 | guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
|
29916 | wpr += guard;
|
29917 | denominator = pow = sum = new Ctor(1);
|
29918 | Ctor.precision = wpr;
|
29919 |
|
29920 | for (;;) {
|
29921 | pow = finalise(pow.times(x), wpr, 1);
|
29922 | denominator = denominator.times(++i);
|
29923 | t = sum.plus(divide(pow, denominator, wpr, 1));
|
29924 |
|
29925 | if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
|
29926 | j = k;
|
29927 | while (j--) sum = finalise(sum.times(sum), wpr, 1);
|
29928 |
|
29929 | // Check to see if the first 4 rounding digits are [49]999.
|
29930 | // If so, repeat the summation with a higher precision, otherwise
|
29931 | // e.g. with precision: 18, rounding: 1
|
29932 | // exp(18.404272462595034083567793919843761) = 98372560.1229999999 (should be 98372560.123)
|
29933 | // `wpr - guard` is the index of first rounding digit.
|
29934 | if (sd == null) {
|
29935 |
|
29936 | if (rep < 3 && checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
|
29937 | Ctor.precision = wpr += 10;
|
29938 | denominator = pow = t = new Ctor(1);
|
29939 | i = 0;
|
29940 | rep++;
|
29941 | } else {
|
29942 | return finalise(sum, Ctor.precision = pr, rm, external = true);
|
29943 | }
|
29944 | } else {
|
29945 | Ctor.precision = pr;
|
29946 | return sum;
|
29947 | }
|
29948 | }
|
29949 |
|
29950 | sum = t;
|
29951 | }
|
29952 | }
|
29953 |
|
29954 |
|
29955 | /*
|
29956 | * Return a new Decimal whose value is the natural logarithm of `x` rounded to `sd` significant
|
29957 | * digits.
|
29958 | *
|
29959 | * ln(-n) = NaN
|
29960 | * ln(0) = -Infinity
|
29961 | * ln(-0) = -Infinity
|
29962 | * ln(1) = 0
|
29963 | * ln(Infinity) = Infinity
|
29964 | * ln(-Infinity) = NaN
|
29965 | * ln(NaN) = NaN
|
29966 | *
|
29967 | * ln(n) (n != 1) is non-terminating.
|
29968 | *
|
29969 | */
|
29970 | function naturalLogarithm(y, sd) {
|
29971 | var c, c0, denominator, e, numerator, rep, sum, t, wpr, x1, x2,
|
29972 | n = 1,
|
29973 | guard = 10,
|
29974 | x = y,
|
29975 | xd = x.d,
|
29976 | Ctor = x.constructor,
|
29977 | rm = Ctor.rounding,
|
29978 | pr = Ctor.precision;
|
29979 |
|
29980 | // Is x negative or Infinity, NaN, 0 or 1?
|
29981 | if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) {
|
29982 | return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
|
29983 | }
|
29984 |
|
29985 | if (sd == null) {
|
29986 | external = false;
|
29987 | wpr = pr;
|
29988 | } else {
|
29989 | wpr = sd;
|
29990 | }
|
29991 |
|
29992 | Ctor.precision = wpr += guard;
|
29993 | c = digitsToString(xd);
|
29994 | c0 = c.charAt(0);
|
29995 |
|
29996 | if (Math.abs(e = x.e) < 1.5e15) {
|
29997 |
|
29998 | // Argument reduction.
|
29999 | // The series converges faster the closer the argument is to 1, so using
|
30000 | // ln(a^b) = b * ln(a), ln(a) = ln(a^b) / b
|
30001 | // multiply the argument by itself until the leading digits of the significand are 7, 8, 9,
|
30002 | // 10, 11, 12 or 13, recording the number of multiplications so the sum of the series can
|
30003 | // later be divided by this number, then separate out the power of 10 using
|
30004 | // ln(a*10^b) = ln(a) + b*ln(10).
|
30005 |
|
30006 | // max n is 21 (gives 0.9, 1.0 or 1.1) (9e15 / 21 = 4.2e14).
|
30007 | //while (c0 < 9 && c0 != 1 || c0 == 1 && c.charAt(1) > 1) {
|
30008 | // max n is 6 (gives 0.7 - 1.3)
|
30009 | while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
|
30010 | x = x.times(y);
|
30011 | c = digitsToString(x.d);
|
30012 | c0 = c.charAt(0);
|
30013 | n++;
|
30014 | }
|
30015 |
|
30016 | e = x.e;
|
30017 |
|
30018 | if (c0 > 1) {
|
30019 | x = new Ctor('0.' + c);
|
30020 | e++;
|
30021 | } else {
|
30022 | x = new Ctor(c0 + '.' + c.slice(1));
|
30023 | }
|
30024 | } else {
|
30025 |
|
30026 | // The argument reduction method above may result in overflow if the argument y is a massive
|
30027 | // number with exponent >= 1500000000000000 (9e15 / 6 = 1.5e15), so instead recall this
|
30028 | // function using ln(x*10^e) = ln(x) + e*ln(10).
|
30029 | t = getLn10(Ctor, wpr + 2, pr).times(e + '');
|
30030 | x = naturalLogarithm(new Ctor(c0 + '.' + c.slice(1)), wpr - guard).plus(t);
|
30031 | Ctor.precision = pr;
|
30032 |
|
30033 | return sd == null ? finalise(x, pr, rm, external = true) : x;
|
30034 | }
|
30035 |
|
30036 | // x1 is x reduced to a value near 1.
|
30037 | x1 = x;
|
30038 |
|
30039 | // Taylor series.
|
30040 | // ln(y) = ln((1 + x)/(1 - x)) = 2(x + x^3/3 + x^5/5 + x^7/7 + ...)
|
30041 | // where x = (y - 1)/(y + 1) (|x| < 1)
|
30042 | sum = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
|
30043 | x2 = finalise(x.times(x), wpr, 1);
|
30044 | denominator = 3;
|
30045 |
|
30046 | for (;;) {
|
30047 | numerator = finalise(numerator.times(x2), wpr, 1);
|
30048 | t = sum.plus(divide(numerator, new Ctor(denominator), wpr, 1));
|
30049 |
|
30050 | if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
|
30051 | sum = sum.times(2);
|
30052 |
|
30053 | // Reverse the argument reduction. Check that e is not 0 because, besides preventing an
|
30054 | // unnecessary calculation, -0 + 0 = +0 and to ensure correct rounding -0 needs to stay -0.
|
30055 | if (e !== 0) sum = sum.plus(getLn10(Ctor, wpr + 2, pr).times(e + ''));
|
30056 | sum = divide(sum, new Ctor(n), wpr, 1);
|
30057 |
|
30058 | // Is rm > 3 and the first 4 rounding digits 4999, or rm < 4 (or the summation has
|
30059 | // been repeated previously) and the first 4 rounding digits 9999?
|
30060 | // If so, restart the summation with a higher precision, otherwise
|
30061 | // e.g. with precision: 12, rounding: 1
|
30062 | // ln(135520028.6126091714265381533) = 18.7246299999 when it should be 18.72463.
|
30063 | // `wpr - guard` is the index of first rounding digit.
|
30064 | if (sd == null) {
|
30065 | if (checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
|
30066 | Ctor.precision = wpr += guard;
|
30067 | t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
|
30068 | x2 = finalise(x.times(x), wpr, 1);
|
30069 | denominator = rep = 1;
|
30070 | } else {
|
30071 | return finalise(sum, Ctor.precision = pr, rm, external = true);
|
30072 | }
|
30073 | } else {
|
30074 | Ctor.precision = pr;
|
30075 | return sum;
|
30076 | }
|
30077 | }
|
30078 |
|
30079 | sum = t;
|
30080 | denominator += 2;
|
30081 | }
|
30082 | }
|
30083 |
|
30084 |
|
30085 | // ±Infinity, NaN.
|
30086 | function nonFiniteToString(x) {
|
30087 | // Unsigned.
|
30088 | return String(x.s * x.s / 0);
|
30089 | }
|
30090 |
|
30091 |
|
30092 | /*
|
30093 | * Parse the value of a new Decimal `x` from string `str`.
|
30094 | */
|
30095 | function parseDecimal(x, str) {
|
30096 | var e, i, len;
|
30097 |
|
30098 | // Decimal point?
|
30099 | if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
|
30100 |
|
30101 | // Exponential form?
|
30102 | if ((i = str.search(/e/i)) > 0) {
|
30103 |
|
30104 | // Determine exponent.
|
30105 | if (e < 0) e = i;
|
30106 | e += +str.slice(i + 1);
|
30107 | str = str.substring(0, i);
|
30108 | } else if (e < 0) {
|
30109 |
|
30110 | // Integer.
|
30111 | e = str.length;
|
30112 | }
|
30113 |
|
30114 | // Determine leading zeros.
|
30115 | for (i = 0; str.charCodeAt(i) === 48; i++);
|
30116 |
|
30117 | // Determine trailing zeros.
|
30118 | for (len = str.length; str.charCodeAt(len - 1) === 48; --len);
|
30119 | str = str.slice(i, len);
|
30120 |
|
30121 | if (str) {
|
30122 | len -= i;
|
30123 | x.e = e = e - i - 1;
|
30124 | x.d = [];
|
30125 |
|
30126 | // Transform base
|
30127 |
|
30128 | // e is the base 10 exponent.
|
30129 | // i is where to slice str to get the first word of the digits array.
|
30130 | i = (e + 1) % LOG_BASE;
|
30131 | if (e < 0) i += LOG_BASE;
|
30132 |
|
30133 | if (i < len) {
|
30134 | if (i) x.d.push(+str.slice(0, i));
|
30135 | for (len -= LOG_BASE; i < len;) x.d.push(+str.slice(i, i += LOG_BASE));
|
30136 | str = str.slice(i);
|
30137 | i = LOG_BASE - str.length;
|
30138 | } else {
|
30139 | i -= len;
|
30140 | }
|
30141 |
|
30142 | for (; i--;) str += '0';
|
30143 | x.d.push(+str);
|
30144 |
|
30145 | if (external) {
|
30146 |
|
30147 | // Overflow?
|
30148 | if (x.e > x.constructor.maxE) {
|
30149 |
|
30150 | // Infinity.
|
30151 | x.d = null;
|
30152 | x.e = NaN;
|
30153 |
|
30154 | // Underflow?
|
30155 | } else if (x.e < x.constructor.minE) {
|
30156 |
|
30157 | // Zero.
|
30158 | x.e = 0;
|
30159 | x.d = [0];
|
30160 | // x.constructor.underflow = true;
|
30161 | } // else x.constructor.underflow = false;
|
30162 | }
|
30163 | } else {
|
30164 |
|
30165 | // Zero.
|
30166 | x.e = 0;
|
30167 | x.d = [0];
|
30168 | }
|
30169 |
|
30170 | return x;
|
30171 | }
|
30172 |
|
30173 |
|
30174 | /*
|
30175 | * Parse the value of a new Decimal `x` from a string `str`, which is not a decimal value.
|
30176 | */
|
30177 | function parseOther(x, str) {
|
30178 | var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
|
30179 |
|
30180 | if (str === 'Infinity' || str === 'NaN') {
|
30181 | if (!+str) x.s = NaN;
|
30182 | x.e = NaN;
|
30183 | x.d = null;
|
30184 | return x;
|
30185 | }
|
30186 |
|
30187 | if (isHex.test(str)) {
|
30188 | base = 16;
|
30189 | str = str.toLowerCase();
|
30190 | } else if (isBinary.test(str)) {
|
30191 | base = 2;
|
30192 | } else if (isOctal.test(str)) {
|
30193 | base = 8;
|
30194 | } else {
|
30195 | throw Error(invalidArgument + str);
|
30196 | }
|
30197 |
|
30198 | // Is there a binary exponent part?
|
30199 | i = str.search(/p/i);
|
30200 |
|
30201 | if (i > 0) {
|
30202 | p = +str.slice(i + 1);
|
30203 | str = str.substring(2, i);
|
30204 | } else {
|
30205 | str = str.slice(2);
|
30206 | }
|
30207 |
|
30208 | // Convert `str` as an integer then divide the result by `base` raised to a power such that the
|
30209 | // fraction part will be restored.
|
30210 | i = str.indexOf('.');
|
30211 | isFloat = i >= 0;
|
30212 | Ctor = x.constructor;
|
30213 |
|
30214 | if (isFloat) {
|
30215 | str = str.replace('.', '');
|
30216 | len = str.length;
|
30217 | i = len - i;
|
30218 |
|
30219 | // log[10](16) = 1.2041... , log[10](88) = 1.9444....
|
30220 | divisor = intPow(Ctor, new Ctor(base), i, i * 2);
|
30221 | }
|
30222 |
|
30223 | xd = convertBase(str, base, BASE);
|
30224 | xe = xd.length - 1;
|
30225 |
|
30226 | // Remove trailing zeros.
|
30227 | for (i = xe; xd[i] === 0; --i) xd.pop();
|
30228 | if (i < 0) return new Ctor(x.s * 0);
|
30229 | x.e = getBase10Exponent(xd, xe);
|
30230 | x.d = xd;
|
30231 | external = false;
|
30232 |
|
30233 | // At what precision to perform the division to ensure exact conversion?
|
30234 | // maxDecimalIntegerPartDigitCount = ceil(log[10](b) * otherBaseIntegerPartDigitCount)
|
30235 | // log[10](2) = 0.30103, log[10](8) = 0.90309, log[10](16) = 1.20412
|
30236 | // E.g. ceil(1.2 * 3) = 4, so up to 4 decimal digits are needed to represent 3 hex int digits.
|
30237 | // maxDecimalFractionPartDigitCount = {Hex:4|Oct:3|Bin:1} * otherBaseFractionPartDigitCount
|
30238 | // Therefore using 4 * the number of digits of str will always be enough.
|
30239 | if (isFloat) x = divide(x, divisor, len * 4);
|
30240 |
|
30241 | // Multiply by the binary exponent part if present.
|
30242 | if (p) x = x.times(Math.abs(p) < 54 ? Math.pow(2, p) : Decimal.pow(2, p));
|
30243 | external = true;
|
30244 |
|
30245 | return x;
|
30246 | }
|
30247 |
|
30248 |
|
30249 | /*
|
30250 | * sin(x) = x - x^3/3! + x^5/5! - ...
|
30251 | * |x| < pi/2
|
30252 | *
|
30253 | */
|
30254 | function sine(Ctor, x) {
|
30255 | var k,
|
30256 | len = x.d.length;
|
30257 |
|
30258 | if (len < 3) return taylorSeries(Ctor, 2, x, x);
|
30259 |
|
30260 | // Argument reduction: sin(5x) = 16*sin^5(x) - 20*sin^3(x) + 5*sin(x)
|
30261 | // i.e. sin(x) = 16*sin^5(x/5) - 20*sin^3(x/5) + 5*sin(x/5)
|
30262 | // and sin(x) = sin(x/5)(5 + sin^2(x/5)(16sin^2(x/5) - 20))
|
30263 |
|
30264 | // Estimate the optimum number of times to use the argument reduction.
|
30265 | k = 1.4 * Math.sqrt(len);
|
30266 | k = k > 16 ? 16 : k | 0;
|
30267 |
|
30268 | // Max k before Math.pow precision loss is 22
|
30269 | x = x.times(Math.pow(5, -k));
|
30270 | x = taylorSeries(Ctor, 2, x, x);
|
30271 |
|
30272 | // Reverse argument reduction
|
30273 | var sin2_x,
|
30274 | d5 = new Ctor(5),
|
30275 | d16 = new Ctor(16),
|
30276 | d20 = new Ctor(20);
|
30277 | for (; k--;) {
|
30278 | sin2_x = x.times(x);
|
30279 | x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
|
30280 | }
|
30281 |
|
30282 | return x;
|
30283 | }
|
30284 |
|
30285 |
|
30286 | // Calculate Taylor series for `cos`, `cosh`, `sin` and `sinh`.
|
30287 | function taylorSeries(Ctor, n, x, y, isHyperbolic) {
|
30288 | var j, t, u, x2,
|
30289 | i = 1,
|
30290 | pr = Ctor.precision,
|
30291 | k = Math.ceil(pr / LOG_BASE);
|
30292 |
|
30293 | external = false;
|
30294 | x2 = x.times(x);
|
30295 | u = new Ctor(y);
|
30296 |
|
30297 | for (;;) {
|
30298 | t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
|
30299 | u = isHyperbolic ? y.plus(t) : y.minus(t);
|
30300 | y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
|
30301 | t = u.plus(y);
|
30302 |
|
30303 | if (t.d[k] !== void 0) {
|
30304 | for (j = k; t.d[j] === u.d[j] && j--;);
|
30305 | if (j == -1) break;
|
30306 | }
|
30307 |
|
30308 | j = u;
|
30309 | u = y;
|
30310 | y = t;
|
30311 | t = j;
|
30312 | i++;
|
30313 | }
|
30314 |
|
30315 | external = true;
|
30316 | t.d.length = k + 1;
|
30317 |
|
30318 | return t;
|
30319 | }
|
30320 |
|
30321 |
|
30322 | // Return the absolute value of `x` reduced to less than or equal to half pi.
|
30323 | function toLessThanHalfPi(Ctor, x) {
|
30324 | var t,
|
30325 | isNeg = x.s < 0,
|
30326 | pi = getPi(Ctor, Ctor.precision, 1),
|
30327 | halfPi = pi.times(0.5);
|
30328 |
|
30329 | x = x.abs();
|
30330 |
|
30331 | if (x.lte(halfPi)) {
|
30332 | quadrant = isNeg ? 4 : 1;
|
30333 | return x;
|
30334 | }
|
30335 |
|
30336 | t = x.divToInt(pi);
|
30337 |
|
30338 | if (t.isZero()) {
|
30339 | quadrant = isNeg ? 3 : 2;
|
30340 | } else {
|
30341 | x = x.minus(t.times(pi));
|
30342 |
|
30343 | // 0 <= x < pi
|
30344 | if (x.lte(halfPi)) {
|
30345 | quadrant = isOdd(t) ? (isNeg ? 2 : 3) : (isNeg ? 4 : 1);
|
30346 | return x;
|
30347 | }
|
30348 |
|
30349 | quadrant = isOdd(t) ? (isNeg ? 1 : 4) : (isNeg ? 3 : 2);
|
30350 | }
|
30351 |
|
30352 | return x.minus(pi).abs();
|
30353 | }
|
30354 |
|
30355 |
|
30356 | /*
|
30357 | * Return the value of Decimal `x` as a string in base `baseOut`.
|
30358 | *
|
30359 | * If the optional `sd` argument is present include a binary exponent suffix.
|
30360 | */
|
30361 | function toStringBinary(x, baseOut, sd, rm) {
|
30362 | var base, e, i, k, len, roundUp, str, xd, y,
|
30363 | Ctor = x.constructor,
|
30364 | isExp = sd !== void 0;
|
30365 |
|
30366 | if (isExp) {
|
30367 | checkInt32(sd, 1, MAX_DIGITS);
|
30368 | if (rm === void 0) rm = Ctor.rounding;
|
30369 | else checkInt32(rm, 0, 8);
|
30370 | } else {
|
30371 | sd = Ctor.precision;
|
30372 | rm = Ctor.rounding;
|
30373 | }
|
30374 |
|
30375 | if (!x.isFinite()) {
|
30376 | str = nonFiniteToString(x);
|
30377 | } else {
|
30378 | str = finiteToString(x);
|
30379 | i = str.indexOf('.');
|
30380 |
|
30381 | // Use exponential notation according to `toExpPos` and `toExpNeg`? No, but if required:
|
30382 | // maxBinaryExponent = floor((decimalExponent + 1) * log[2](10))
|
30383 | // minBinaryExponent = floor(decimalExponent * log[2](10))
|
30384 | // log[2](10) = 3.321928094887362347870319429489390175864
|
30385 |
|
30386 | if (isExp) {
|
30387 | base = 2;
|
30388 | if (baseOut == 16) {
|
30389 | sd = sd * 4 - 3;
|
30390 | } else if (baseOut == 8) {
|
30391 | sd = sd * 3 - 2;
|
30392 | }
|
30393 | } else {
|
30394 | base = baseOut;
|
30395 | }
|
30396 |
|
30397 | // Convert the number as an integer then divide the result by its base raised to a power such
|
30398 | // that the fraction part will be restored.
|
30399 |
|
30400 | // Non-integer.
|
30401 | if (i >= 0) {
|
30402 | str = str.replace('.', '');
|
30403 | y = new Ctor(1);
|
30404 | y.e = str.length - i;
|
30405 | y.d = convertBase(finiteToString(y), 10, base);
|
30406 | y.e = y.d.length;
|
30407 | }
|
30408 |
|
30409 | xd = convertBase(str, 10, base);
|
30410 | e = len = xd.length;
|
30411 |
|
30412 | // Remove trailing zeros.
|
30413 | for (; xd[--len] == 0;) xd.pop();
|
30414 |
|
30415 | if (!xd[0]) {
|
30416 | str = isExp ? '0p+0' : '0';
|
30417 | } else {
|
30418 | if (i < 0) {
|
30419 | e--;
|
30420 | } else {
|
30421 | x = new Ctor(x);
|
30422 | x.d = xd;
|
30423 | x.e = e;
|
30424 | x = divide(x, y, sd, rm, 0, base);
|
30425 | xd = x.d;
|
30426 | e = x.e;
|
30427 | roundUp = inexact;
|
30428 | }
|
30429 |
|
30430 | // The rounding digit, i.e. the digit after the digit that may be rounded up.
|
30431 | i = xd[sd];
|
30432 | k = base / 2;
|
30433 | roundUp = roundUp || xd[sd + 1] !== void 0;
|
30434 |
|
30435 | roundUp = rm < 4
|
30436 | ? (i !== void 0 || roundUp) && (rm === 0 || rm === (x.s < 0 ? 3 : 2))
|
30437 | : i > k || i === k && (rm === 4 || roundUp || rm === 6 && xd[sd - 1] & 1 ||
|
30438 | rm === (x.s < 0 ? 8 : 7));
|
30439 |
|
30440 | xd.length = sd;
|
30441 |
|
30442 | if (roundUp) {
|
30443 |
|
30444 | // Rounding up may mean the previous digit has to be rounded up and so on.
|
30445 | for (; ++xd[--sd] > base - 1;) {
|
30446 | xd[sd] = 0;
|
30447 | if (!sd) {
|
30448 | ++e;
|
30449 | xd.unshift(1);
|
30450 | }
|
30451 | }
|
30452 | }
|
30453 |
|
30454 | // Determine trailing zeros.
|
30455 | for (len = xd.length; !xd[len - 1]; --len);
|
30456 |
|
30457 | // E.g. [4, 11, 15] becomes 4bf.
|
30458 | for (i = 0, str = ''; i < len; i++) str += NUMERALS.charAt(xd[i]);
|
30459 |
|
30460 | // Add binary exponent suffix?
|
30461 | if (isExp) {
|
30462 | if (len > 1) {
|
30463 | if (baseOut == 16 || baseOut == 8) {
|
30464 | i = baseOut == 16 ? 4 : 3;
|
30465 | for (--len; len % i; len++) str += '0';
|
30466 | xd = convertBase(str, base, baseOut);
|
30467 | for (len = xd.length; !xd[len - 1]; --len);
|
30468 |
|
30469 | // xd[0] will always be be 1
|
30470 | for (i = 1, str = '1.'; i < len; i++) str += NUMERALS.charAt(xd[i]);
|
30471 | } else {
|
30472 | str = str.charAt(0) + '.' + str.slice(1);
|
30473 | }
|
30474 | }
|
30475 |
|
30476 | str = str + (e < 0 ? 'p' : 'p+') + e;
|
30477 | } else if (e < 0) {
|
30478 | for (; ++e;) str = '0' + str;
|
30479 | str = '0.' + str;
|
30480 | } else {
|
30481 | if (++e > len) for (e -= len; e-- ;) str += '0';
|
30482 | else if (e < len) str = str.slice(0, e) + '.' + str.slice(e);
|
30483 | }
|
30484 | }
|
30485 |
|
30486 | str = (baseOut == 16 ? '0x' : baseOut == 2 ? '0b' : baseOut == 8 ? '0o' : '') + str;
|
30487 | }
|
30488 |
|
30489 | return x.s < 0 ? '-' + str : str;
|
30490 | }
|
30491 |
|
30492 |
|
30493 | // Does not strip trailing zeros.
|
30494 | function truncate(arr, len) {
|
30495 | if (arr.length > len) {
|
30496 | arr.length = len;
|
30497 | return true;
|
30498 | }
|
30499 | }
|
30500 |
|
30501 |
|
30502 | // Decimal methods
|
30503 |
|
30504 |
|
30505 | /*
|
30506 | * abs
|
30507 | * acos
|
30508 | * acosh
|
30509 | * add
|
30510 | * asin
|
30511 | * asinh
|
30512 | * atan
|
30513 | * atanh
|
30514 | * atan2
|
30515 | * cbrt
|
30516 | * ceil
|
30517 | * clone
|
30518 | * config
|
30519 | * cos
|
30520 | * cosh
|
30521 | * div
|
30522 | * exp
|
30523 | * floor
|
30524 | * hypot
|
30525 | * ln
|
30526 | * log
|
30527 | * log2
|
30528 | * log10
|
30529 | * max
|
30530 | * min
|
30531 | * mod
|
30532 | * mul
|
30533 | * pow
|
30534 | * random
|
30535 | * round
|
30536 | * set
|
30537 | * sign
|
30538 | * sin
|
30539 | * sinh
|
30540 | * sqrt
|
30541 | * sub
|
30542 | * tan
|
30543 | * tanh
|
30544 | * trunc
|
30545 | */
|
30546 |
|
30547 |
|
30548 | /*
|
30549 | * Return a new Decimal whose value is the absolute value of `x`.
|
30550 | *
|
30551 | * x {number|string|Decimal}
|
30552 | *
|
30553 | */
|
30554 | function abs(x) {
|
30555 | return new this(x).abs();
|
30556 | }
|
30557 |
|
30558 |
|
30559 | /*
|
30560 | * Return a new Decimal whose value is the arccosine in radians of `x`.
|
30561 | *
|
30562 | * x {number|string|Decimal}
|
30563 | *
|
30564 | */
|
30565 | function acos(x) {
|
30566 | return new this(x).acos();
|
30567 | }
|
30568 |
|
30569 |
|
30570 | /*
|
30571 | * Return a new Decimal whose value is the inverse of the hyperbolic cosine of `x`, rounded to
|
30572 | * `precision` significant digits using rounding mode `rounding`.
|
30573 | *
|
30574 | * x {number|string|Decimal} A value in radians.
|
30575 | *
|
30576 | */
|
30577 | function acosh(x) {
|
30578 | return new this(x).acosh();
|
30579 | }
|
30580 |
|
30581 |
|
30582 | /*
|
30583 | * Return a new Decimal whose value is the sum of `x` and `y`, rounded to `precision` significant
|
30584 | * digits using rounding mode `rounding`.
|
30585 | *
|
30586 | * x {number|string|Decimal}
|
30587 | * y {number|string|Decimal}
|
30588 | *
|
30589 | */
|
30590 | function add(x, y) {
|
30591 | return new this(x).plus(y);
|
30592 | }
|
30593 |
|
30594 |
|
30595 | /*
|
30596 | * Return a new Decimal whose value is the arcsine in radians of `x`, rounded to `precision`
|
30597 | * significant digits using rounding mode `rounding`.
|
30598 | *
|
30599 | * x {number|string|Decimal}
|
30600 | *
|
30601 | */
|
30602 | function asin(x) {
|
30603 | return new this(x).asin();
|
30604 | }
|
30605 |
|
30606 |
|
30607 | /*
|
30608 | * Return a new Decimal whose value is the inverse of the hyperbolic sine of `x`, rounded to
|
30609 | * `precision` significant digits using rounding mode `rounding`.
|
30610 | *
|
30611 | * x {number|string|Decimal} A value in radians.
|
30612 | *
|
30613 | */
|
30614 | function asinh(x) {
|
30615 | return new this(x).asinh();
|
30616 | }
|
30617 |
|
30618 |
|
30619 | /*
|
30620 | * Return a new Decimal whose value is the arctangent in radians of `x`, rounded to `precision`
|
30621 | * significant digits using rounding mode `rounding`.
|
30622 | *
|
30623 | * x {number|string|Decimal}
|
30624 | *
|
30625 | */
|
30626 | function atan(x) {
|
30627 | return new this(x).atan();
|
30628 | }
|
30629 |
|
30630 |
|
30631 | /*
|
30632 | * Return a new Decimal whose value is the inverse of the hyperbolic tangent of `x`, rounded to
|
30633 | * `precision` significant digits using rounding mode `rounding`.
|
30634 | *
|
30635 | * x {number|string|Decimal} A value in radians.
|
30636 | *
|
30637 | */
|
30638 | function atanh(x) {
|
30639 | return new this(x).atanh();
|
30640 | }
|
30641 |
|
30642 |
|
30643 | /*
|
30644 | * Return a new Decimal whose value is the arctangent in radians of `y/x` in the range -pi to pi
|
30645 | * (inclusive), rounded to `precision` significant digits using rounding mode `rounding`.
|
30646 | *
|
30647 | * Domain: [-Infinity, Infinity]
|
30648 | * Range: [-pi, pi]
|
30649 | *
|
30650 | * y {number|string|Decimal} The y-coordinate.
|
30651 | * x {number|string|Decimal} The x-coordinate.
|
30652 | *
|
30653 | * atan2(±0, -0) = ±pi
|
30654 | * atan2(±0, +0) = ±0
|
30655 | * atan2(±0, -x) = ±pi for x > 0
|
30656 | * atan2(±0, x) = ±0 for x > 0
|
30657 | * atan2(-y, ±0) = -pi/2 for y > 0
|
30658 | * atan2(y, ±0) = pi/2 for y > 0
|
30659 | * atan2(±y, -Infinity) = ±pi for finite y > 0
|
30660 | * atan2(±y, +Infinity) = ±0 for finite y > 0
|
30661 | * atan2(±Infinity, x) = ±pi/2 for finite x
|
30662 | * atan2(±Infinity, -Infinity) = ±3*pi/4
|
30663 | * atan2(±Infinity, +Infinity) = ±pi/4
|
30664 | * atan2(NaN, x) = NaN
|
30665 | * atan2(y, NaN) = NaN
|
30666 | *
|
30667 | */
|
30668 | function atan2(y, x) {
|
30669 | y = new this(y);
|
30670 | x = new this(x);
|
30671 | var r,
|
30672 | pr = this.precision,
|
30673 | rm = this.rounding,
|
30674 | wpr = pr + 4;
|
30675 |
|
30676 | // Either NaN
|
30677 | if (!y.s || !x.s) {
|
30678 | r = new this(NaN);
|
30679 |
|
30680 | // Both ±Infinity
|
30681 | } else if (!y.d && !x.d) {
|
30682 | r = getPi(this, wpr, 1).times(x.s > 0 ? 0.25 : 0.75);
|
30683 | r.s = y.s;
|
30684 |
|
30685 | // x is ±Infinity or y is ±0
|
30686 | } else if (!x.d || y.isZero()) {
|
30687 | r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
|
30688 | r.s = y.s;
|
30689 |
|
30690 | // y is ±Infinity or x is ±0
|
30691 | } else if (!y.d || x.isZero()) {
|
30692 | r = getPi(this, wpr, 1).times(0.5);
|
30693 | r.s = y.s;
|
30694 |
|
30695 | // Both non-zero and finite
|
30696 | } else if (x.s < 0) {
|
30697 | this.precision = wpr;
|
30698 | this.rounding = 1;
|
30699 | r = this.atan(divide(y, x, wpr, 1));
|
30700 | x = getPi(this, wpr, 1);
|
30701 | this.precision = pr;
|
30702 | this.rounding = rm;
|
30703 | r = y.s < 0 ? r.minus(x) : r.plus(x);
|
30704 | } else {
|
30705 | r = this.atan(divide(y, x, wpr, 1));
|
30706 | }
|
30707 |
|
30708 | return r;
|
30709 | }
|
30710 |
|
30711 |
|
30712 | /*
|
30713 | * Return a new Decimal whose value is the cube root of `x`, rounded to `precision` significant
|
30714 | * digits using rounding mode `rounding`.
|
30715 | *
|
30716 | * x {number|string|Decimal}
|
30717 | *
|
30718 | */
|
30719 | function cbrt(x) {
|
30720 | return new this(x).cbrt();
|
30721 | }
|
30722 |
|
30723 |
|
30724 | /*
|
30725 | * Return a new Decimal whose value is `x` rounded to an integer using `ROUND_CEIL`.
|
30726 | *
|
30727 | * x {number|string|Decimal}
|
30728 | *
|
30729 | */
|
30730 | function ceil(x) {
|
30731 | return finalise(x = new this(x), x.e + 1, 2);
|
30732 | }
|
30733 |
|
30734 |
|
30735 | /*
|
30736 | * Configure global settings for a Decimal constructor.
|
30737 | *
|
30738 | * `obj` is an object with one or more of the following properties,
|
30739 | *
|
30740 | * precision {number}
|
30741 | * rounding {number}
|
30742 | * toExpNeg {number}
|
30743 | * toExpPos {number}
|
30744 | * maxE {number}
|
30745 | * minE {number}
|
30746 | * modulo {number}
|
30747 | * crypto {boolean|number}
|
30748 | * defaults {true}
|
30749 | *
|
30750 | * E.g. Decimal.config({ precision: 20, rounding: 4 })
|
30751 | *
|
30752 | */
|
30753 | function config(obj) {
|
30754 | if (!obj || typeof obj !== 'object') throw Error(decimalError + 'Object expected');
|
30755 | var i, p, v,
|
30756 | useDefaults = obj.defaults === true,
|
30757 | ps = [
|
30758 | 'precision', 1, MAX_DIGITS,
|
30759 | 'rounding', 0, 8,
|
30760 | 'toExpNeg', -EXP_LIMIT, 0,
|
30761 | 'toExpPos', 0, EXP_LIMIT,
|
30762 | 'maxE', 0, EXP_LIMIT,
|
30763 | 'minE', -EXP_LIMIT, 0,
|
30764 | 'modulo', 0, 9
|
30765 | ];
|
30766 |
|
30767 | for (i = 0; i < ps.length; i += 3) {
|
30768 | if (p = ps[i], useDefaults) this[p] = DEFAULTS[p];
|
30769 | if ((v = obj[p]) !== void 0) {
|
30770 | if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2]) this[p] = v;
|
30771 | else throw Error(invalidArgument + p + ': ' + v);
|
30772 | }
|
30773 | }
|
30774 |
|
30775 | if (p = 'crypto', useDefaults) this[p] = DEFAULTS[p];
|
30776 | if ((v = obj[p]) !== void 0) {
|
30777 | if (v === true || v === false || v === 0 || v === 1) {
|
30778 | if (v) {
|
30779 | if (typeof crypto != 'undefined' && crypto &&
|
30780 | (crypto.getRandomValues || crypto.randomBytes)) {
|
30781 | this[p] = true;
|
30782 | } else {
|
30783 | throw Error(cryptoUnavailable);
|
30784 | }
|
30785 | } else {
|
30786 | this[p] = false;
|
30787 | }
|
30788 | } else {
|
30789 | throw Error(invalidArgument + p + ': ' + v);
|
30790 | }
|
30791 | }
|
30792 |
|
30793 | return this;
|
30794 | }
|
30795 |
|
30796 |
|
30797 | /*
|
30798 | * Return a new Decimal whose value is the cosine of `x`, rounded to `precision` significant
|
30799 | * digits using rounding mode `rounding`.
|
30800 | *
|
30801 | * x {number|string|Decimal} A value in radians.
|
30802 | *
|
30803 | */
|
30804 | function cos(x) {
|
30805 | return new this(x).cos();
|
30806 | }
|
30807 |
|
30808 |
|
30809 | /*
|
30810 | * Return a new Decimal whose value is the hyperbolic cosine of `x`, rounded to precision
|
30811 | * significant digits using rounding mode `rounding`.
|
30812 | *
|
30813 | * x {number|string|Decimal} A value in radians.
|
30814 | *
|
30815 | */
|
30816 | function cosh(x) {
|
30817 | return new this(x).cosh();
|
30818 | }
|
30819 |
|
30820 |
|
30821 | /*
|
30822 | * Create and return a Decimal constructor with the same configuration properties as this Decimal
|
30823 | * constructor.
|
30824 | *
|
30825 | */
|
30826 | function clone(obj) {
|
30827 | var i, p, ps;
|
30828 |
|
30829 | /*
|
30830 | * The Decimal constructor and exported function.
|
30831 | * Return a new Decimal instance.
|
30832 | *
|
30833 | * v {number|string|Decimal} A numeric value.
|
30834 | *
|
30835 | */
|
30836 | function Decimal(v) {
|
30837 | var e, i, t,
|
30838 | x = this;
|
30839 |
|
30840 | // Decimal called without new.
|
30841 | if (!(x instanceof Decimal)) return new Decimal(v);
|
30842 |
|
30843 | // Retain a reference to this Decimal constructor, and shadow Decimal.prototype.constructor
|
30844 | // which points to Object.
|
30845 | x.constructor = Decimal;
|
30846 |
|
30847 | // Duplicate.
|
30848 | if (v instanceof Decimal) {
|
30849 | x.s = v.s;
|
30850 |
|
30851 | if (external) {
|
30852 | if (!v.d || v.e > Decimal.maxE) {
|
30853 |
|
30854 | // Infinity.
|
30855 | x.e = NaN;
|
30856 | x.d = null;
|
30857 | } else if (v.e < Decimal.minE) {
|
30858 |
|
30859 | // Zero.
|
30860 | x.e = 0;
|
30861 | x.d = [0];
|
30862 | } else {
|
30863 | x.e = v.e;
|
30864 | x.d = v.d.slice();
|
30865 | }
|
30866 | } else {
|
30867 | x.e = v.e;
|
30868 | x.d = v.d ? v.d.slice() : v.d;
|
30869 | }
|
30870 |
|
30871 | return;
|
30872 | }
|
30873 |
|
30874 | t = typeof v;
|
30875 |
|
30876 | if (t === 'number') {
|
30877 | if (v === 0) {
|
30878 | x.s = 1 / v < 0 ? -1 : 1;
|
30879 | x.e = 0;
|
30880 | x.d = [0];
|
30881 | return;
|
30882 | }
|
30883 |
|
30884 | if (v < 0) {
|
30885 | v = -v;
|
30886 | x.s = -1;
|
30887 | } else {
|
30888 | x.s = 1;
|
30889 | }
|
30890 |
|
30891 | // Fast path for small integers.
|
30892 | if (v === ~~v && v < 1e7) {
|
30893 | for (e = 0, i = v; i >= 10; i /= 10) e++;
|
30894 |
|
30895 | if (external) {
|
30896 | if (e > Decimal.maxE) {
|
30897 | x.e = NaN;
|
30898 | x.d = null;
|
30899 | } else if (e < Decimal.minE) {
|
30900 | x.e = 0;
|
30901 | x.d = [0];
|
30902 | } else {
|
30903 | x.e = e;
|
30904 | x.d = [v];
|
30905 | }
|
30906 | } else {
|
30907 | x.e = e;
|
30908 | x.d = [v];
|
30909 | }
|
30910 |
|
30911 | return;
|
30912 |
|
30913 | // Infinity, NaN.
|
30914 | } else if (v * 0 !== 0) {
|
30915 | if (!v) x.s = NaN;
|
30916 | x.e = NaN;
|
30917 | x.d = null;
|
30918 | return;
|
30919 | }
|
30920 |
|
30921 | return parseDecimal(x, v.toString());
|
30922 |
|
30923 | } else if (t !== 'string') {
|
30924 | throw Error(invalidArgument + v);
|
30925 | }
|
30926 |
|
30927 | // Minus sign?
|
30928 | if (v.charCodeAt(0) === 45) {
|
30929 | v = v.slice(1);
|
30930 | x.s = -1;
|
30931 | } else {
|
30932 | x.s = 1;
|
30933 | }
|
30934 |
|
30935 | return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
|
30936 | }
|
30937 |
|
30938 | Decimal.prototype = P;
|
30939 |
|
30940 | Decimal.ROUND_UP = 0;
|
30941 | Decimal.ROUND_DOWN = 1;
|
30942 | Decimal.ROUND_CEIL = 2;
|
30943 | Decimal.ROUND_FLOOR = 3;
|
30944 | Decimal.ROUND_HALF_UP = 4;
|
30945 | Decimal.ROUND_HALF_DOWN = 5;
|
30946 | Decimal.ROUND_HALF_EVEN = 6;
|
30947 | Decimal.ROUND_HALF_CEIL = 7;
|
30948 | Decimal.ROUND_HALF_FLOOR = 8;
|
30949 | Decimal.EUCLID = 9;
|
30950 |
|
30951 | Decimal.config = Decimal.set = config;
|
30952 | Decimal.clone = clone;
|
30953 | Decimal.isDecimal = isDecimalInstance;
|
30954 |
|
30955 | Decimal.abs = abs;
|
30956 | Decimal.acos = acos;
|
30957 | Decimal.acosh = acosh; // ES6
|
30958 | Decimal.add = add;
|
30959 | Decimal.asin = asin;
|
30960 | Decimal.asinh = asinh; // ES6
|
30961 | Decimal.atan = atan;
|
30962 | Decimal.atanh = atanh; // ES6
|
30963 | Decimal.atan2 = atan2;
|
30964 | Decimal.cbrt = cbrt; // ES6
|
30965 | Decimal.ceil = ceil;
|
30966 | Decimal.cos = cos;
|
30967 | Decimal.cosh = cosh; // ES6
|
30968 | Decimal.div = div;
|
30969 | Decimal.exp = exp;
|
30970 | Decimal.floor = floor;
|
30971 | Decimal.hypot = hypot; // ES6
|
30972 | Decimal.ln = ln;
|
30973 | Decimal.log = log;
|
30974 | Decimal.log10 = log10; // ES6
|
30975 | Decimal.log2 = log2; // ES6
|
30976 | Decimal.max = max;
|
30977 | Decimal.min = min;
|
30978 | Decimal.mod = mod;
|
30979 | Decimal.mul = mul;
|
30980 | Decimal.pow = pow;
|
30981 | Decimal.random = random;
|
30982 | Decimal.round = round;
|
30983 | Decimal.sign = sign; // ES6
|
30984 | Decimal.sin = sin;
|
30985 | Decimal.sinh = sinh; // ES6
|
30986 | Decimal.sqrt = sqrt;
|
30987 | Decimal.sub = sub;
|
30988 | Decimal.tan = tan;
|
30989 | Decimal.tanh = tanh; // ES6
|
30990 | Decimal.trunc = trunc; // ES6
|
30991 |
|
30992 | if (obj === void 0) obj = {};
|
30993 | if (obj) {
|
30994 | if (obj.defaults !== true) {
|
30995 | ps = ['precision', 'rounding', 'toExpNeg', 'toExpPos', 'maxE', 'minE', 'modulo', 'crypto'];
|
30996 | for (i = 0; i < ps.length;) if (!obj.hasOwnProperty(p = ps[i++])) obj[p] = this[p];
|
30997 | }
|
30998 | }
|
30999 |
|
31000 | Decimal.config(obj);
|
31001 |
|
31002 | return Decimal;
|
31003 | }
|
31004 |
|
31005 |
|
31006 | /*
|
31007 | * Return a new Decimal whose value is `x` divided by `y`, rounded to `precision` significant
|
31008 | * digits using rounding mode `rounding`.
|
31009 | *
|
31010 | * x {number|string|Decimal}
|
31011 | * y {number|string|Decimal}
|
31012 | *
|
31013 | */
|
31014 | function div(x, y) {
|
31015 | return new this(x).div(y);
|
31016 | }
|
31017 |
|
31018 |
|
31019 | /*
|
31020 | * Return a new Decimal whose value is the natural exponential of `x`, rounded to `precision`
|
31021 | * significant digits using rounding mode `rounding`.
|
31022 | *
|
31023 | * x {number|string|Decimal} The power to which to raise the base of the natural log.
|
31024 | *
|
31025 | */
|
31026 | function exp(x) {
|
31027 | return new this(x).exp();
|
31028 | }
|
31029 |
|
31030 |
|
31031 | /*
|
31032 | * Return a new Decimal whose value is `x` round to an integer using `ROUND_FLOOR`.
|
31033 | *
|
31034 | * x {number|string|Decimal}
|
31035 | *
|
31036 | */
|
31037 | function floor(x) {
|
31038 | return finalise(x = new this(x), x.e + 1, 3);
|
31039 | }
|
31040 |
|
31041 |
|
31042 | /*
|
31043 | * Return a new Decimal whose value is the square root of the sum of the squares of the arguments,
|
31044 | * rounded to `precision` significant digits using rounding mode `rounding`.
|
31045 | *
|
31046 | * hypot(a, b, ...) = sqrt(a^2 + b^2 + ...)
|
31047 | *
|
31048 | */
|
31049 | function hypot() {
|
31050 | var i, n,
|
31051 | t = new this(0);
|
31052 |
|
31053 | external = false;
|
31054 |
|
31055 | for (i = 0; i < arguments.length;) {
|
31056 | n = new this(arguments[i++]);
|
31057 | if (!n.d) {
|
31058 | if (n.s) {
|
31059 | external = true;
|
31060 | return new this(1 / 0);
|
31061 | }
|
31062 | t = n;
|
31063 | } else if (t.d) {
|
31064 | t = t.plus(n.times(n));
|
31065 | }
|
31066 | }
|
31067 |
|
31068 | external = true;
|
31069 |
|
31070 | return t.sqrt();
|
31071 | }
|
31072 |
|
31073 |
|
31074 | /*
|
31075 | * Return true if object is a Decimal instance (where Decimal is any Decimal constructor),
|
31076 | * otherwise return false.
|
31077 | *
|
31078 | */
|
31079 | function isDecimalInstance(obj) {
|
31080 | return obj instanceof Decimal || obj && obj.name === '[object Decimal]' || false;
|
31081 | }
|
31082 |
|
31083 |
|
31084 | /*
|
31085 | * Return a new Decimal whose value is the natural logarithm of `x`, rounded to `precision`
|
31086 | * significant digits using rounding mode `rounding`.
|
31087 | *
|
31088 | * x {number|string|Decimal}
|
31089 | *
|
31090 | */
|
31091 | function ln(x) {
|
31092 | return new this(x).ln();
|
31093 | }
|
31094 |
|
31095 |
|
31096 | /*
|
31097 | * Return a new Decimal whose value is the log of `x` to the base `y`, or to base 10 if no base
|
31098 | * is specified, rounded to `precision` significant digits using rounding mode `rounding`.
|
31099 | *
|
31100 | * log[y](x)
|
31101 | *
|
31102 | * x {number|string|Decimal} The argument of the logarithm.
|
31103 | * y {number|string|Decimal} The base of the logarithm.
|
31104 | *
|
31105 | */
|
31106 | function log(x, y) {
|
31107 | return new this(x).log(y);
|
31108 | }
|
31109 |
|
31110 |
|
31111 | /*
|
31112 | * Return a new Decimal whose value is the base 2 logarithm of `x`, rounded to `precision`
|
31113 | * significant digits using rounding mode `rounding`.
|
31114 | *
|
31115 | * x {number|string|Decimal}
|
31116 | *
|
31117 | */
|
31118 | function log2(x) {
|
31119 | return new this(x).log(2);
|
31120 | }
|
31121 |
|
31122 |
|
31123 | /*
|
31124 | * Return a new Decimal whose value is the base 10 logarithm of `x`, rounded to `precision`
|
31125 | * significant digits using rounding mode `rounding`.
|
31126 | *
|
31127 | * x {number|string|Decimal}
|
31128 | *
|
31129 | */
|
31130 | function log10(x) {
|
31131 | return new this(x).log(10);
|
31132 | }
|
31133 |
|
31134 |
|
31135 | /*
|
31136 | * Return a new Decimal whose value is the maximum of the arguments.
|
31137 | *
|
31138 | * arguments {number|string|Decimal}
|
31139 | *
|
31140 | */
|
31141 | function max() {
|
31142 | return maxOrMin(this, arguments, 'lt');
|
31143 | }
|
31144 |
|
31145 |
|
31146 | /*
|
31147 | * Return a new Decimal whose value is the minimum of the arguments.
|
31148 | *
|
31149 | * arguments {number|string|Decimal}
|
31150 | *
|
31151 | */
|
31152 | function min() {
|
31153 | return maxOrMin(this, arguments, 'gt');
|
31154 | }
|
31155 |
|
31156 |
|
31157 | /*
|
31158 | * Return a new Decimal whose value is `x` modulo `y`, rounded to `precision` significant digits
|
31159 | * using rounding mode `rounding`.
|
31160 | *
|
31161 | * x {number|string|Decimal}
|
31162 | * y {number|string|Decimal}
|
31163 | *
|
31164 | */
|
31165 | function mod(x, y) {
|
31166 | return new this(x).mod(y);
|
31167 | }
|
31168 |
|
31169 |
|
31170 | /*
|
31171 | * Return a new Decimal whose value is `x` multiplied by `y`, rounded to `precision` significant
|
31172 | * digits using rounding mode `rounding`.
|
31173 | *
|
31174 | * x {number|string|Decimal}
|
31175 | * y {number|string|Decimal}
|
31176 | *
|
31177 | */
|
31178 | function mul(x, y) {
|
31179 | return new this(x).mul(y);
|
31180 | }
|
31181 |
|
31182 |
|
31183 | /*
|
31184 | * Return a new Decimal whose value is `x` raised to the power `y`, rounded to precision
|
31185 | * significant digits using rounding mode `rounding`.
|
31186 | *
|
31187 | * x {number|string|Decimal} The base.
|
31188 | * y {number|string|Decimal} The exponent.
|
31189 | *
|
31190 | */
|
31191 | function pow(x, y) {
|
31192 | return new this(x).pow(y);
|
31193 | }
|
31194 |
|
31195 |
|
31196 | /*
|
31197 | * Returns a new Decimal with a random value equal to or greater than 0 and less than 1, and with
|
31198 | * `sd`, or `Decimal.precision` if `sd` is omitted, significant digits (or less if trailing zeros
|
31199 | * are produced).
|
31200 | *
|
31201 | * [sd] {number} Significant digits. Integer, 0 to MAX_DIGITS inclusive.
|
31202 | *
|
31203 | */
|
31204 | function random(sd) {
|
31205 | var d, e, k, n,
|
31206 | i = 0,
|
31207 | r = new this(1),
|
31208 | rd = [];
|
31209 |
|
31210 | if (sd === void 0) sd = this.precision;
|
31211 | else checkInt32(sd, 1, MAX_DIGITS);
|
31212 |
|
31213 | k = Math.ceil(sd / LOG_BASE);
|
31214 |
|
31215 | if (!this.crypto) {
|
31216 | for (; i < k;) rd[i++] = Math.random() * 1e7 | 0;
|
31217 |
|
31218 | // Browsers supporting crypto.getRandomValues.
|
31219 | } else if (crypto.getRandomValues) {
|
31220 | d = crypto.getRandomValues(new Uint32Array(k));
|
31221 |
|
31222 | for (; i < k;) {
|
31223 | n = d[i];
|
31224 |
|
31225 | // 0 <= n < 4294967296
|
31226 | // Probability n >= 4.29e9, is 4967296 / 4294967296 = 0.00116 (1 in 865).
|
31227 | if (n >= 4.29e9) {
|
31228 | d[i] = crypto.getRandomValues(new Uint32Array(1))[0];
|
31229 | } else {
|
31230 |
|
31231 | // 0 <= n <= 4289999999
|
31232 | // 0 <= (n % 1e7) <= 9999999
|
31233 | rd[i++] = n % 1e7;
|
31234 | }
|
31235 | }
|
31236 |
|
31237 | // Node.js supporting crypto.randomBytes.
|
31238 | } else if (crypto.randomBytes) {
|
31239 |
|
31240 | // buffer
|
31241 | d = crypto.randomBytes(k *= 4);
|
31242 |
|
31243 | for (; i < k;) {
|
31244 |
|
31245 | // 0 <= n < 2147483648
|
31246 | n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 0x7f) << 24);
|
31247 |
|
31248 | // Probability n >= 2.14e9, is 7483648 / 2147483648 = 0.0035 (1 in 286).
|
31249 | if (n >= 2.14e9) {
|
31250 | crypto.randomBytes(4).copy(d, i);
|
31251 | } else {
|
31252 |
|
31253 | // 0 <= n <= 2139999999
|
31254 | // 0 <= (n % 1e7) <= 9999999
|
31255 | rd.push(n % 1e7);
|
31256 | i += 4;
|
31257 | }
|
31258 | }
|
31259 |
|
31260 | i = k / 4;
|
31261 | } else {
|
31262 | throw Error(cryptoUnavailable);
|
31263 | }
|
31264 |
|
31265 | k = rd[--i];
|
31266 | sd %= LOG_BASE;
|
31267 |
|
31268 | // Convert trailing digits to zeros according to sd.
|
31269 | if (k && sd) {
|
31270 | n = mathpow(10, LOG_BASE - sd);
|
31271 | rd[i] = (k / n | 0) * n;
|
31272 | }
|
31273 |
|
31274 | // Remove trailing words which are zero.
|
31275 | for (; rd[i] === 0; i--) rd.pop();
|
31276 |
|
31277 | // Zero?
|
31278 | if (i < 0) {
|
31279 | e = 0;
|
31280 | rd = [0];
|
31281 | } else {
|
31282 | e = -1;
|
31283 |
|
31284 | // Remove leading words which are zero and adjust exponent accordingly.
|
31285 | for (; rd[0] === 0; e -= LOG_BASE) rd.shift();
|
31286 |
|
31287 | // Count the digits of the first word of rd to determine leading zeros.
|
31288 | for (k = 1, n = rd[0]; n >= 10; n /= 10) k++;
|
31289 |
|
31290 | // Adjust the exponent for leading zeros of the first word of rd.
|
31291 | if (k < LOG_BASE) e -= LOG_BASE - k;
|
31292 | }
|
31293 |
|
31294 | r.e = e;
|
31295 | r.d = rd;
|
31296 |
|
31297 | return r;
|
31298 | }
|
31299 |
|
31300 |
|
31301 | /*
|
31302 | * Return a new Decimal whose value is `x` rounded to an integer using rounding mode `rounding`.
|
31303 | *
|
31304 | * To emulate `Math.round`, set rounding to 7 (ROUND_HALF_CEIL).
|
31305 | *
|
31306 | * x {number|string|Decimal}
|
31307 | *
|
31308 | */
|
31309 | function round(x) {
|
31310 | return finalise(x = new this(x), x.e + 1, this.rounding);
|
31311 | }
|
31312 |
|
31313 |
|
31314 | /*
|
31315 | * Return
|
31316 | * 1 if x > 0,
|
31317 | * -1 if x < 0,
|
31318 | * 0 if x is 0,
|
31319 | * -0 if x is -0,
|
31320 | * NaN otherwise
|
31321 | *
|
31322 | */
|
31323 | function sign(x) {
|
31324 | x = new this(x);
|
31325 | return x.d ? (x.d[0] ? x.s : 0 * x.s) : x.s || NaN;
|
31326 | }
|
31327 |
|
31328 |
|
31329 | /*
|
31330 | * Return a new Decimal whose value is the sine of `x`, rounded to `precision` significant digits
|
31331 | * using rounding mode `rounding`.
|
31332 | *
|
31333 | * x {number|string|Decimal} A value in radians.
|
31334 | *
|
31335 | */
|
31336 | function sin(x) {
|
31337 | return new this(x).sin();
|
31338 | }
|
31339 |
|
31340 |
|
31341 | /*
|
31342 | * Return a new Decimal whose value is the hyperbolic sine of `x`, rounded to `precision`
|
31343 | * significant digits using rounding mode `rounding`.
|
31344 | *
|
31345 | * x {number|string|Decimal} A value in radians.
|
31346 | *
|
31347 | */
|
31348 | function sinh(x) {
|
31349 | return new this(x).sinh();
|
31350 | }
|
31351 |
|
31352 |
|
31353 | /*
|
31354 | * Return a new Decimal whose value is the square root of `x`, rounded to `precision` significant
|
31355 | * digits using rounding mode `rounding`.
|
31356 | *
|
31357 | * x {number|string|Decimal}
|
31358 | *
|
31359 | */
|
31360 | function sqrt(x) {
|
31361 | return new this(x).sqrt();
|
31362 | }
|
31363 |
|
31364 |
|
31365 | /*
|
31366 | * Return a new Decimal whose value is `x` minus `y`, rounded to `precision` significant digits
|
31367 | * using rounding mode `rounding`.
|
31368 | *
|
31369 | * x {number|string|Decimal}
|
31370 | * y {number|string|Decimal}
|
31371 | *
|
31372 | */
|
31373 | function sub(x, y) {
|
31374 | return new this(x).sub(y);
|
31375 | }
|
31376 |
|
31377 |
|
31378 | /*
|
31379 | * Return a new Decimal whose value is the tangent of `x`, rounded to `precision` significant
|
31380 | * digits using rounding mode `rounding`.
|
31381 | *
|
31382 | * x {number|string|Decimal} A value in radians.
|
31383 | *
|
31384 | */
|
31385 | function tan(x) {
|
31386 | return new this(x).tan();
|
31387 | }
|
31388 |
|
31389 |
|
31390 | /*
|
31391 | * Return a new Decimal whose value is the hyperbolic tangent of `x`, rounded to `precision`
|
31392 | * significant digits using rounding mode `rounding`.
|
31393 | *
|
31394 | * x {number|string|Decimal} A value in radians.
|
31395 | *
|
31396 | */
|
31397 | function tanh(x) {
|
31398 | return new this(x).tanh();
|
31399 | }
|
31400 |
|
31401 |
|
31402 | /*
|
31403 | * Return a new Decimal whose value is `x` truncated to an integer.
|
31404 | *
|
31405 | * x {number|string|Decimal}
|
31406 | *
|
31407 | */
|
31408 | function trunc(x) {
|
31409 | return finalise(x = new this(x), x.e + 1, 1);
|
31410 | }
|
31411 |
|
31412 |
|
31413 | // Create and configure initial Decimal constructor.
|
31414 | Decimal = clone(DEFAULTS);
|
31415 |
|
31416 | Decimal['default'] = Decimal.Decimal = Decimal;
|
31417 |
|
31418 | // Create the internal constants from their string values.
|
31419 | LN10 = new Decimal(LN10);
|
31420 | PI = new Decimal(PI);
|
31421 |
|
31422 |
|
31423 | // Export.
|
31424 |
|
31425 |
|
31426 | // AMD.
|
31427 | if (true) {
|
31428 | !(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {
|
31429 | return Decimal;
|
31430 | }).call(exports, __webpack_require__, exports, module),
|
31431 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
31432 |
|
31433 | // Node and other environments that support module.exports.
|
31434 | } else {}
|
31435 | })(this);
|
31436 |
|
31437 |
|
31438 | /***/ }),
|
31439 | /* 161 */
|
31440 | /***/ (function(module, exports, __webpack_require__) {
|
31441 |
|
31442 | "use strict";
|
31443 |
|
31444 |
|
31445 | var core = __webpack_require__(162);
|
31446 | /**
|
31447 | * math.js factory function. Creates a new instance of math.js
|
31448 | *
|
31449 | * @param {Object} [config] Available configuration options:
|
31450 | * {number} epsilon
|
31451 | * Minimum relative difference between two
|
31452 | * compared values, used by all comparison functions.
|
31453 | * {string} matrix
|
31454 | * A string 'matrix' (default) or 'array'.
|
31455 | * {string} number
|
31456 | * A string 'number' (default), 'bignumber', or
|
31457 | * 'fraction'
|
31458 | * {number} precision
|
31459 | * The number of significant digits for BigNumbers.
|
31460 | * Not applicable for Numbers.
|
31461 | * {boolean} predictable
|
31462 | * Predictable output type of functions. When true,
|
31463 | * output type depends only on the input types. When
|
31464 | * false (default), output type can vary depending
|
31465 | * on input values. For example `math.sqrt(-4)`
|
31466 | * returns `complex('2i')` when predictable is false, and
|
31467 | * returns `NaN` when true.
|
31468 | */
|
31469 |
|
31470 |
|
31471 | function create(config) {
|
31472 | // create a new math.js instance
|
31473 | var math = core.create(config);
|
31474 | math.create = create; // import data types, functions, constants, expression parser, etc.
|
31475 |
|
31476 | math['import'](__webpack_require__(168));
|
31477 | return math;
|
31478 | } // return a new instance of math.js
|
31479 |
|
31480 |
|
31481 | module.exports = create();
|
31482 |
|
31483 | /***/ }),
|
31484 | /* 162 */
|
31485 | /***/ (function(module, exports, __webpack_require__) {
|
31486 |
|
31487 | "use strict";
|
31488 |
|
31489 |
|
31490 | __webpack_require__(163);
|
31491 |
|
31492 | var isFactory = __webpack_require__(5).isFactory;
|
31493 |
|
31494 | var typedFactory = __webpack_require__(103);
|
31495 |
|
31496 | var emitter = __webpack_require__(104);
|
31497 |
|
31498 | var importFactory = __webpack_require__(166);
|
31499 |
|
31500 | var configFactory = __webpack_require__(167);
|
31501 | /**
|
31502 | * Math.js core. Creates a new, empty math.js instance
|
31503 | * @param {Object} [options] Available options:
|
31504 | * {number} epsilon
|
31505 | * Minimum relative difference between two
|
31506 | * compared values, used by all comparison functions.
|
31507 | * {string} matrix
|
31508 | * A string 'Matrix' (default) or 'Array'.
|
31509 | * {string} number
|
31510 | * A string 'number' (default), 'BigNumber', or 'Fraction'
|
31511 | * {number} precision
|
31512 | * The number of significant digits for BigNumbers.
|
31513 | * Not applicable for Numbers.
|
31514 | * {boolean} predictable
|
31515 | * Predictable output type of functions. When true,
|
31516 | * output type depends only on the input types. When
|
31517 | * false (default), output type can vary depending
|
31518 | * on input values. For example `math.sqrt(-4)`
|
31519 | * returns `complex('2i')` when predictable is false, and
|
31520 | * returns `NaN` when true.
|
31521 | * {string} randomSeed
|
31522 | * Random seed for seeded pseudo random number generator.
|
31523 | * Set to null to randomly seed.
|
31524 | * @returns {Object} Returns a bare-bone math.js instance containing
|
31525 | * functions:
|
31526 | * - `import` to add new functions
|
31527 | * - `config` to change configuration
|
31528 | * - `on`, `off`, `once`, `emit` for events
|
31529 | */
|
31530 |
|
31531 |
|
31532 | exports.create = function create(options) {
|
31533 | // simple test for ES5 support
|
31534 | if (typeof Object.create !== 'function') {
|
31535 | throw new Error('ES5 not supported by this JavaScript engine. ' + 'Please load the es5-shim and es5-sham library for compatibility.');
|
31536 | } // cached factories and instances
|
31537 |
|
31538 |
|
31539 | var factories = [];
|
31540 | var instances = []; // create a namespace for the mathjs instance, and attach emitter functions
|
31541 |
|
31542 | var math = emitter.mixin({});
|
31543 | math.type = {};
|
31544 | math.expression = {
|
31545 | transform: {},
|
31546 | mathWithTransform: {} // create a new typed instance
|
31547 |
|
31548 | };
|
31549 | math.typed = typedFactory.create(math.type); // create configuration options. These are private
|
31550 |
|
31551 | var _config = {
|
31552 | // minimum relative difference between two compared values,
|
31553 | // used by all comparison functions
|
31554 | epsilon: 1e-12,
|
31555 | // type of default matrix output. Choose 'matrix' (default) or 'array'
|
31556 | matrix: 'Matrix',
|
31557 | // type of default number output. Choose 'number' (default) 'BigNumber', or 'Fraction
|
31558 | number: 'number',
|
31559 | // number of significant digits in BigNumbers
|
31560 | precision: 64,
|
31561 | // predictable output type of functions. When true, output type depends only
|
31562 | // on the input types. When false (default), output type can vary depending
|
31563 | // on input values. For example `math.sqrt(-4)` returns `complex('2i')` when
|
31564 | // predictable is false, and returns `NaN` when true.
|
31565 | predictable: false,
|
31566 | // random seed for seeded pseudo random number generation
|
31567 | // null = randomly seed
|
31568 | randomSeed: null
|
31569 | /**
|
31570 | * Load a function or data type from a factory.
|
31571 | * If the function or data type already exists, the existing instance is
|
31572 | * returned.
|
31573 | * @param {{type: string, name: string, factory: Function}} factory
|
31574 | * @returns {*}
|
31575 | */
|
31576 |
|
31577 | };
|
31578 |
|
31579 | function load(factory) {
|
31580 | if (!isFactory(factory)) {
|
31581 | throw new Error('Factory object with properties `type`, `name`, and `factory` expected');
|
31582 | }
|
31583 |
|
31584 | var index = factories.indexOf(factory);
|
31585 | var instance;
|
31586 |
|
31587 | if (index === -1) {
|
31588 | // doesn't yet exist
|
31589 | if (factory.math === true) {
|
31590 | // pass with math namespace
|
31591 | instance = factory.factory(math.type, _config, load, math.typed, math);
|
31592 | } else {
|
31593 | instance = factory.factory(math.type, _config, load, math.typed);
|
31594 | } // append to the cache
|
31595 |
|
31596 |
|
31597 | factories.push(factory);
|
31598 | instances.push(instance);
|
31599 | } else {
|
31600 | // already existing function, return the cached instance
|
31601 | instance = instances[index];
|
31602 | }
|
31603 |
|
31604 | return instance;
|
31605 | } // load the import and config functions
|
31606 |
|
31607 |
|
31608 | math['import'] = load(importFactory);
|
31609 | math['config'] = load(configFactory);
|
31610 | math.expression.mathWithTransform['config'] = math['config']; // apply options
|
31611 |
|
31612 | if (options) {
|
31613 | math.config(options);
|
31614 | }
|
31615 |
|
31616 | return math;
|
31617 | };
|
31618 |
|
31619 | /***/ }),
|
31620 | /* 163 */
|
31621 | /***/ (function(module, exports) {
|
31622 |
|
31623 | // TODO: remove these polyfills as soon as we have a build process that transpiles the code to ES5
|
31624 | // Polyfill for IE 11 (Number.isFinite is used in `complex.js`)
|
31625 | // source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite
|
31626 | Number.isFinite = Number.isFinite || function (value) {
|
31627 | return typeof value === 'number' && isFinite(value);
|
31628 | }; // Polyfill for IE 11
|
31629 | // source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN
|
31630 |
|
31631 |
|
31632 | Number.isNaN = Number.isNaN || function (value) {
|
31633 | return value !== value; // eslint-disable-line no-self-compare
|
31634 | };
|
31635 |
|
31636 | /***/ }),
|
31637 | /* 164 */
|
31638 | /***/ (function(module, exports, __webpack_require__) {
|
31639 |
|
31640 | "use strict";
|
31641 | var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/**
|
31642 | * typed-function
|
31643 | *
|
31644 | * Type checking for JavaScript functions
|
31645 | *
|
31646 | * https://github.com/josdejong/typed-function
|
31647 | */
|
31648 |
|
31649 |
|
31650 | (function (root, factory) {
|
31651 | if (true) {
|
31652 | // AMD. Register as an anonymous module.
|
31653 | !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
|
31654 | __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
|
31655 | (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
|
31656 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
31657 | } else {}
|
31658 | }(this, function () {
|
31659 |
|
31660 | function ok () {
|
31661 | return true;
|
31662 | }
|
31663 |
|
31664 | function notOk () {
|
31665 | return false;
|
31666 | }
|
31667 |
|
31668 | function undef () {
|
31669 | return undefined;
|
31670 | }
|
31671 |
|
31672 | /**
|
31673 | * @typedef {{
|
31674 | * params: Param[],
|
31675 | * fn: function
|
31676 | * }} Signature
|
31677 | *
|
31678 | * @typedef {{
|
31679 | * types: Type[],
|
31680 | * restParam: boolean
|
31681 | * }} Param
|
31682 | *
|
31683 | * @typedef {{
|
31684 | * name: string,
|
31685 | * typeIndex: number,
|
31686 | * test: function,
|
31687 | * conversion?: ConversionDef,
|
31688 | * conversionIndex: number,
|
31689 | * }} Type
|
31690 | *
|
31691 | * @typedef {{
|
31692 | * from: string,
|
31693 | * to: string,
|
31694 | * convert: function (*) : *
|
31695 | * }} ConversionDef
|
31696 | *
|
31697 | * @typedef {{
|
31698 | * name: string,
|
31699 | * test: function(*) : boolean
|
31700 | * }} TypeDef
|
31701 | */
|
31702 |
|
31703 | // create a new instance of typed-function
|
31704 | function create () {
|
31705 | // data type tests
|
31706 | var _types = [
|
31707 | { name: 'number', test: function (x) { return typeof x === 'number' } },
|
31708 | { name: 'string', test: function (x) { return typeof x === 'string' } },
|
31709 | { name: 'boolean', test: function (x) { return typeof x === 'boolean' } },
|
31710 | { name: 'Function', test: function (x) { return typeof x === 'function'} },
|
31711 | { name: 'Array', test: Array.isArray },
|
31712 | { name: 'Date', test: function (x) { return x instanceof Date } },
|
31713 | { name: 'RegExp', test: function (x) { return x instanceof RegExp } },
|
31714 | { name: 'Object', test: function (x) {
|
31715 | return typeof x === 'object' && x.constructor === Object
|
31716 | }},
|
31717 | { name: 'null', test: function (x) { return x === null } },
|
31718 | { name: 'undefined', test: function (x) { return x === undefined } }
|
31719 | ];
|
31720 |
|
31721 | var anyType = {
|
31722 | name: 'any',
|
31723 | test: ok
|
31724 | }
|
31725 |
|
31726 | // types which need to be ignored
|
31727 | var _ignore = [];
|
31728 |
|
31729 | // type conversions
|
31730 | var _conversions = [];
|
31731 |
|
31732 | // This is a temporary object, will be replaced with a typed function at the end
|
31733 | var typed = {
|
31734 | types: _types,
|
31735 | conversions: _conversions,
|
31736 | ignore: _ignore
|
31737 | };
|
31738 |
|
31739 | /**
|
31740 | * Find the test function for a type
|
31741 | * @param {String} typeName
|
31742 | * @return {TypeDef} Returns the type definition when found,
|
31743 | * Throws a TypeError otherwise
|
31744 | */
|
31745 | function findTypeByName (typeName) {
|
31746 | var entry = findInArray(typed.types, function (entry) {
|
31747 | return entry.name === typeName;
|
31748 | });
|
31749 |
|
31750 | if (entry) {
|
31751 | return entry;
|
31752 | }
|
31753 |
|
31754 | if (typeName === 'any') { // special baked-in case 'any'
|
31755 | return anyType;
|
31756 | }
|
31757 |
|
31758 | var hint = findInArray(typed.types, function (entry) {
|
31759 | return entry.name.toLowerCase() === typeName.toLowerCase();
|
31760 | });
|
31761 |
|
31762 | throw new TypeError('Unknown type "' + typeName + '"' +
|
31763 | (hint ? ('. Did you mean "' + hint.name + '"?') : ''));
|
31764 | }
|
31765 |
|
31766 | /**
|
31767 | * Find the index of a type definition. Handles special case 'any'
|
31768 | * @param {TypeDef} type
|
31769 | * @return {number}
|
31770 | */
|
31771 | function findTypeIndex(type) {
|
31772 | if (type === anyType) {
|
31773 | return 999;
|
31774 | }
|
31775 |
|
31776 | return typed.types.indexOf(type);
|
31777 | }
|
31778 |
|
31779 | /**
|
31780 | * Find a type that matches a value.
|
31781 | * @param {*} value
|
31782 | * @return {string} Returns the name of the first type for which
|
31783 | * the type test matches the value.
|
31784 | */
|
31785 | function findTypeName(value) {
|
31786 | var entry = findInArray(typed.types, function (entry) {
|
31787 | return entry.test(value);
|
31788 | });
|
31789 |
|
31790 | if (entry) {
|
31791 | return entry.name;
|
31792 | }
|
31793 |
|
31794 | throw new TypeError('Value has unknown type. Value: ' + value);
|
31795 | }
|
31796 |
|
31797 | /**
|
31798 | * Find a specific signature from a (composed) typed function, for example:
|
31799 | *
|
31800 | * typed.find(fn, ['number', 'string'])
|
31801 | * typed.find(fn, 'number, string')
|
31802 | *
|
31803 | * Function find only only works for exact matches.
|
31804 | *
|
31805 | * @param {Function} fn A typed-function
|
31806 | * @param {string | string[]} signature Signature to be found, can be
|
31807 | * an array or a comma separated string.
|
31808 | * @return {Function} Returns the matching signature, or
|
31809 | * throws an error when no signature
|
31810 | * is found.
|
31811 | */
|
31812 | function find (fn, signature) {
|
31813 | if (!fn.signatures) {
|
31814 | throw new TypeError('Function is no typed-function');
|
31815 | }
|
31816 |
|
31817 | // normalize input
|
31818 | var arr;
|
31819 | if (typeof signature === 'string') {
|
31820 | arr = signature.split(',');
|
31821 | for (var i = 0; i < arr.length; i++) {
|
31822 | arr[i] = arr[i].trim();
|
31823 | }
|
31824 | }
|
31825 | else if (Array.isArray(signature)) {
|
31826 | arr = signature;
|
31827 | }
|
31828 | else {
|
31829 | throw new TypeError('String array or a comma separated string expected');
|
31830 | }
|
31831 |
|
31832 | var str = arr.join(',');
|
31833 |
|
31834 | // find an exact match
|
31835 | var match = fn.signatures[str];
|
31836 | if (match) {
|
31837 | return match;
|
31838 | }
|
31839 |
|
31840 | // TODO: extend find to match non-exact signatures
|
31841 |
|
31842 | throw new TypeError('Signature not found (signature: ' + (fn.name || 'unnamed') + '(' + arr.join(', ') + '))');
|
31843 | }
|
31844 |
|
31845 | /**
|
31846 | * Convert a given value to another data type.
|
31847 | * @param {*} value
|
31848 | * @param {string} type
|
31849 | */
|
31850 | function convert (value, type) {
|
31851 | var from = findTypeName(value);
|
31852 |
|
31853 | // check conversion is needed
|
31854 | if (type === from) {
|
31855 | return value;
|
31856 | }
|
31857 |
|
31858 | for (var i = 0; i < typed.conversions.length; i++) {
|
31859 | var conversion = typed.conversions[i];
|
31860 | if (conversion.from === from && conversion.to === type) {
|
31861 | return conversion.convert(value);
|
31862 | }
|
31863 | }
|
31864 |
|
31865 | throw new Error('Cannot convert from ' + from + ' to ' + type);
|
31866 | }
|
31867 |
|
31868 | /**
|
31869 | * Stringify parameters in a normalized way
|
31870 | * @param {Param[]} params
|
31871 | * @return {string}
|
31872 | */
|
31873 | function stringifyParams (params) {
|
31874 | return params
|
31875 | .map(function (param) {
|
31876 | var typeNames = param.types.map(getTypeName);
|
31877 |
|
31878 | return (param.restParam ? '...' : '') + typeNames.join('|');
|
31879 | })
|
31880 | .join(',');
|
31881 | }
|
31882 |
|
31883 | /**
|
31884 | * Parse a parameter, like "...number | boolean"
|
31885 | * @param {string} param
|
31886 | * @param {ConversionDef[]} conversions
|
31887 | * @return {Param} param
|
31888 | */
|
31889 | function parseParam (param, conversions) {
|
31890 | var restParam = param.indexOf('...') === 0;
|
31891 | var types = (!restParam)
|
31892 | ? param
|
31893 | : (param.length > 3)
|
31894 | ? param.slice(3)
|
31895 | : 'any';
|
31896 |
|
31897 | var typeNames = types.split('|').map(trim)
|
31898 | .filter(notEmpty)
|
31899 | .filter(notIgnore);
|
31900 |
|
31901 | var matchingConversions = filterConversions(conversions, typeNames);
|
31902 |
|
31903 | var exactTypes = typeNames.map(function (typeName) {
|
31904 | var type = findTypeByName(typeName);
|
31905 |
|
31906 | return {
|
31907 | name: typeName,
|
31908 | typeIndex: findTypeIndex(type),
|
31909 | test: type.test,
|
31910 | conversion: null,
|
31911 | conversionIndex: -1
|
31912 | };
|
31913 | });
|
31914 |
|
31915 | var convertibleTypes = matchingConversions.map(function (conversion) {
|
31916 | var type = findTypeByName(conversion.from);
|
31917 |
|
31918 | return {
|
31919 | name: conversion.from,
|
31920 | typeIndex: findTypeIndex(type),
|
31921 | test: type.test,
|
31922 | conversion: conversion,
|
31923 | conversionIndex: conversions.indexOf(conversion)
|
31924 | };
|
31925 | });
|
31926 |
|
31927 | return {
|
31928 | types: exactTypes.concat(convertibleTypes),
|
31929 | restParam: restParam
|
31930 | };
|
31931 | }
|
31932 |
|
31933 | /**
|
31934 | * Parse a signature with comma separated parameters,
|
31935 | * like "number | boolean, ...string"
|
31936 | * @param {string} signature
|
31937 | * @param {function} fn
|
31938 | * @param {ConversionDef[]} conversions
|
31939 | * @return {Signature | null} signature
|
31940 | */
|
31941 | function parseSignature (signature, fn, conversions) {
|
31942 | var params = [];
|
31943 |
|
31944 | if (signature.trim() !== '') {
|
31945 | params = signature
|
31946 | .split(',')
|
31947 | .map(trim)
|
31948 | .map(function (param, index, array) {
|
31949 | var parsedParam = parseParam(param, conversions);
|
31950 |
|
31951 | if (parsedParam.restParam && (index !== array.length - 1)) {
|
31952 | throw new SyntaxError('Unexpected rest parameter "' + param + '": ' +
|
31953 | 'only allowed for the last parameter');
|
31954 | }
|
31955 |
|
31956 | return parsedParam;
|
31957 | });
|
31958 | }
|
31959 |
|
31960 | if (params.some(isInvalidParam)) {
|
31961 | // invalid signature: at least one parameter has no types
|
31962 | // (they may have been filtered)
|
31963 | return null;
|
31964 | }
|
31965 |
|
31966 | return {
|
31967 | params: params,
|
31968 | fn: fn
|
31969 | };
|
31970 | }
|
31971 |
|
31972 | /**
|
31973 | * Test whether a set of params contains a restParam
|
31974 | * @param {Param[]} params
|
31975 | * @return {boolean} Returns true when the last parameter is a restParam
|
31976 | */
|
31977 | function hasRestParam(params) {
|
31978 | var param = last(params)
|
31979 | return param ? param.restParam : false;
|
31980 | }
|
31981 |
|
31982 | /**
|
31983 | * Test whether a parameter contains conversions
|
31984 | * @param {Param} param
|
31985 | * @return {boolean} Returns true when at least one of the parameters
|
31986 | * contains a conversion.
|
31987 | */
|
31988 | function hasConversions(param) {
|
31989 | return param.types.some(function (type) {
|
31990 | return type.conversion != null;
|
31991 | });
|
31992 | }
|
31993 |
|
31994 | /**
|
31995 | * Create a type test for a single parameter, which can have one or multiple
|
31996 | * types.
|
31997 | * @param {Param} param
|
31998 | * @return {function(x: *) : boolean} Returns a test function
|
31999 | */
|
32000 | function compileTest(param) {
|
32001 | if (!param || param.types.length === 0) {
|
32002 | // nothing to do
|
32003 | return ok;
|
32004 | }
|
32005 | else if (param.types.length === 1) {
|
32006 | return findTypeByName(param.types[0].name).test;
|
32007 | }
|
32008 | else if (param.types.length === 2) {
|
32009 | var test0 = findTypeByName(param.types[0].name).test;
|
32010 | var test1 = findTypeByName(param.types[1].name).test;
|
32011 | return function or(x) {
|
32012 | return test0(x) || test1(x);
|
32013 | }
|
32014 | }
|
32015 | else { // param.types.length > 2
|
32016 | var tests = param.types.map(function (type) {
|
32017 | return findTypeByName(type.name).test;
|
32018 | })
|
32019 | return function or(x) {
|
32020 | for (var i = 0; i < tests.length; i++) {
|
32021 | if (tests[i](x)) {
|
32022 | return true;
|
32023 | }
|
32024 | }
|
32025 | return false;
|
32026 | }
|
32027 | }
|
32028 | }
|
32029 |
|
32030 | /**
|
32031 | * Create a test for all parameters of a signature
|
32032 | * @param {Param[]} params
|
32033 | * @return {function(args: Array<*>) : boolean}
|
32034 | */
|
32035 | function compileTests(params) {
|
32036 | var tests, test0, test1;
|
32037 |
|
32038 | if (hasRestParam(params)) {
|
32039 | // variable arguments like '...number'
|
32040 | tests = initial(params).map(compileTest);
|
32041 | var varIndex = tests.length;
|
32042 | var lastTest = compileTest(last(params));
|
32043 | var testRestParam = function (args) {
|
32044 | for (var i = varIndex; i < args.length; i++) {
|
32045 | if (!lastTest(args[i])) {
|
32046 | return false;
|
32047 | }
|
32048 | }
|
32049 | return true;
|
32050 | }
|
32051 |
|
32052 | return function testArgs(args) {
|
32053 | for (var i = 0; i < tests.length; i++) {
|
32054 | if (!tests[i](args[i])) {
|
32055 | return false;
|
32056 | }
|
32057 | }
|
32058 | return testRestParam(args) && (args.length >= varIndex + 1);
|
32059 | };
|
32060 | }
|
32061 | else {
|
32062 | // no variable arguments
|
32063 | if (params.length === 0) {
|
32064 | return function testArgs(args) {
|
32065 | return args.length === 0;
|
32066 | };
|
32067 | }
|
32068 | else if (params.length === 1) {
|
32069 | test0 = compileTest(params[0]);
|
32070 | return function testArgs(args) {
|
32071 | return test0(args[0]) && args.length === 1;
|
32072 | };
|
32073 | }
|
32074 | else if (params.length === 2) {
|
32075 | test0 = compileTest(params[0]);
|
32076 | test1 = compileTest(params[1]);
|
32077 | return function testArgs(args) {
|
32078 | return test0(args[0]) && test1(args[1]) && args.length === 2;
|
32079 | };
|
32080 | }
|
32081 | else { // arguments.length > 2
|
32082 | tests = params.map(compileTest);
|
32083 | return function testArgs(args) {
|
32084 | for (var i = 0; i < tests.length; i++) {
|
32085 | if (!tests[i](args[i])) {
|
32086 | return false;
|
32087 | }
|
32088 | }
|
32089 | return args.length === tests.length;
|
32090 | };
|
32091 | }
|
32092 | }
|
32093 | }
|
32094 |
|
32095 | /**
|
32096 | * Find the parameter at a specific index of a signature.
|
32097 | * Handles rest parameters.
|
32098 | * @param {Signature} signature
|
32099 | * @param {number} index
|
32100 | * @return {Param | null} Returns the matching parameter when found,
|
32101 | * null otherwise.
|
32102 | */
|
32103 | function getParamAtIndex(signature, index) {
|
32104 | return index < signature.params.length
|
32105 | ? signature.params[index]
|
32106 | : hasRestParam(signature.params)
|
32107 | ? last(signature.params)
|
32108 | : null
|
32109 | }
|
32110 |
|
32111 | /**
|
32112 | * Get all type names of a parameter
|
32113 | * @param {Signature} signature
|
32114 | * @param {number} index
|
32115 | * @param {boolean} excludeConversions
|
32116 | * @return {string[]} Returns an array with type names
|
32117 | */
|
32118 | function getExpectedTypeNames (signature, index, excludeConversions) {
|
32119 | var param = getParamAtIndex(signature, index);
|
32120 | var types = param
|
32121 | ? excludeConversions
|
32122 | ? param.types.filter(isExactType)
|
32123 | : param.types
|
32124 | : [];
|
32125 |
|
32126 | return types.map(getTypeName);
|
32127 | }
|
32128 |
|
32129 | /**
|
32130 | * Returns the name of a type
|
32131 | * @param {Type} type
|
32132 | * @return {string} Returns the type name
|
32133 | */
|
32134 | function getTypeName(type) {
|
32135 | return type.name;
|
32136 | }
|
32137 |
|
32138 | /**
|
32139 | * Test whether a type is an exact type or conversion
|
32140 | * @param {Type} type
|
32141 | * @return {boolean} Returns true when
|
32142 | */
|
32143 | function isExactType(type) {
|
32144 | return type.conversion === null || type.conversion === undefined;
|
32145 | }
|
32146 |
|
32147 | /**
|
32148 | * Helper function for creating error messages: create an array with
|
32149 | * all available types on a specific argument index.
|
32150 | * @param {Signature[]} signatures
|
32151 | * @param {number} index
|
32152 | * @return {string[]} Returns an array with available types
|
32153 | */
|
32154 | function mergeExpectedParams(signatures, index) {
|
32155 | var typeNames = uniq(flatMap(signatures, function (signature) {
|
32156 | return getExpectedTypeNames(signature, index, false);
|
32157 | }));
|
32158 |
|
32159 | return (typeNames.indexOf('any') !== -1) ? ['any'] : typeNames;
|
32160 | }
|
32161 |
|
32162 | /**
|
32163 | * Create
|
32164 | * @param {string} name The name of the function
|
32165 | * @param {array.<*>} args The actual arguments passed to the function
|
32166 | * @param {Signature[]} signatures A list with available signatures
|
32167 | * @return {TypeError} Returns a type error with additional data
|
32168 | * attached to it in the property `data`
|
32169 | */
|
32170 | function createError(name, args, signatures) {
|
32171 | var err, expected;
|
32172 | var _name = name || 'unnamed';
|
32173 |
|
32174 | // test for wrong type at some index
|
32175 | var matchingSignatures = signatures;
|
32176 | var index;
|
32177 | for (index = 0; index < args.length; index++) {
|
32178 | var nextMatchingDefs = matchingSignatures.filter(function (signature) {
|
32179 | var test = compileTest(getParamAtIndex(signature, index));
|
32180 | return (index < signature.params.length || hasRestParam(signature.params)) &&
|
32181 | test(args[index]);
|
32182 | });
|
32183 |
|
32184 | if (nextMatchingDefs.length === 0) {
|
32185 | // no matching signatures anymore, throw error "wrong type"
|
32186 | expected = mergeExpectedParams(matchingSignatures, index);
|
32187 | if (expected.length > 0) {
|
32188 | var actualType = findTypeName(args[index]);
|
32189 |
|
32190 | err = new TypeError('Unexpected type of argument in function ' + _name +
|
32191 | ' (expected: ' + expected.join(' or ') +
|
32192 | ', actual: ' + actualType + ', index: ' + index + ')');
|
32193 | err.data = {
|
32194 | category: 'wrongType',
|
32195 | fn: _name,
|
32196 | index: index,
|
32197 | actual: actualType,
|
32198 | expected: expected
|
32199 | }
|
32200 | return err;
|
32201 | }
|
32202 | }
|
32203 | else {
|
32204 | matchingSignatures = nextMatchingDefs;
|
32205 | }
|
32206 | }
|
32207 |
|
32208 | // test for too few arguments
|
32209 | var lengths = matchingSignatures.map(function (signature) {
|
32210 | return hasRestParam(signature.params) ? Infinity : signature.params.length;
|
32211 | });
|
32212 | if (args.length < Math.min.apply(null, lengths)) {
|
32213 | expected = mergeExpectedParams(matchingSignatures, index);
|
32214 | err = new TypeError('Too few arguments in function ' + _name +
|
32215 | ' (expected: ' + expected.join(' or ') +
|
32216 | ', index: ' + args.length + ')');
|
32217 | err.data = {
|
32218 | category: 'tooFewArgs',
|
32219 | fn: _name,
|
32220 | index: args.length,
|
32221 | expected: expected
|
32222 | }
|
32223 | return err;
|
32224 | }
|
32225 |
|
32226 | // test for too many arguments
|
32227 | var maxLength = Math.max.apply(null, lengths);
|
32228 | if (args.length > maxLength) {
|
32229 | err = new TypeError('Too many arguments in function ' + _name +
|
32230 | ' (expected: ' + maxLength + ', actual: ' + args.length + ')');
|
32231 | err.data = {
|
32232 | category: 'tooManyArgs',
|
32233 | fn: _name,
|
32234 | index: args.length,
|
32235 | expectedLength: maxLength
|
32236 | }
|
32237 | return err;
|
32238 | }
|
32239 |
|
32240 | err = new TypeError('Arguments of type "' + args.join(', ') +
|
32241 | '" do not match any of the defined signatures of function ' + _name + '.');
|
32242 | err.data = {
|
32243 | category: 'mismatch',
|
32244 | actual: args.map(findTypeName)
|
32245 | }
|
32246 | return err;
|
32247 | }
|
32248 |
|
32249 | /**
|
32250 | * Find the lowest index of all exact types of a parameter (no conversions)
|
32251 | * @param {Param} param
|
32252 | * @return {number} Returns the index of the lowest type in typed.types
|
32253 | */
|
32254 | function getLowestTypeIndex (param) {
|
32255 | var min = 999;
|
32256 |
|
32257 | for (var i = 0; i < param.types.length; i++) {
|
32258 | if (isExactType(param.types[i])) {
|
32259 | min = Math.min(min, param.types[i].typeIndex);
|
32260 | }
|
32261 | }
|
32262 |
|
32263 | return min;
|
32264 | }
|
32265 |
|
32266 | /**
|
32267 | * Find the lowest index of the conversion of all types of the parameter
|
32268 | * having a conversion
|
32269 | * @param {Param} param
|
32270 | * @return {number} Returns the lowest index of the conversions of this type
|
32271 | */
|
32272 | function getLowestConversionIndex (param) {
|
32273 | var min = 999;
|
32274 |
|
32275 | for (var i = 0; i < param.types.length; i++) {
|
32276 | if (!isExactType(param.types[i])) {
|
32277 | min = Math.min(min, param.types[i].conversionIndex);
|
32278 | }
|
32279 | }
|
32280 |
|
32281 | return min;
|
32282 | }
|
32283 |
|
32284 | /**
|
32285 | * Compare two params
|
32286 | * @param {Param} param1
|
32287 | * @param {Param} param2
|
32288 | * @return {number} returns a negative number when param1 must get a lower
|
32289 | * index than param2, a positive number when the opposite,
|
32290 | * or zero when both are equal
|
32291 | */
|
32292 | function compareParams (param1, param2) {
|
32293 | var c;
|
32294 |
|
32295 | // compare having a rest parameter or not
|
32296 | c = param1.restParam - param2.restParam;
|
32297 | if (c !== 0) {
|
32298 | return c;
|
32299 | }
|
32300 |
|
32301 | // compare having conversions or not
|
32302 | c = hasConversions(param1) - hasConversions(param2);
|
32303 | if (c !== 0) {
|
32304 | return c;
|
32305 | }
|
32306 |
|
32307 | // compare the index of the types
|
32308 | c = getLowestTypeIndex(param1) - getLowestTypeIndex(param2);
|
32309 | if (c !== 0) {
|
32310 | return c;
|
32311 | }
|
32312 |
|
32313 | // compare the index of any conversion
|
32314 | return getLowestConversionIndex(param1) - getLowestConversionIndex(param2);
|
32315 | }
|
32316 |
|
32317 | /**
|
32318 | * Compare two signatures
|
32319 | * @param {Signature} signature1
|
32320 | * @param {Signature} signature2
|
32321 | * @return {number} returns a negative number when param1 must get a lower
|
32322 | * index than param2, a positive number when the opposite,
|
32323 | * or zero when both are equal
|
32324 | */
|
32325 | function compareSignatures (signature1, signature2) {
|
32326 | var len = Math.min(signature1.params.length, signature2.params.length);
|
32327 | var i;
|
32328 | var c;
|
32329 |
|
32330 | // compare whether the params have conversions at all or not
|
32331 | c = signature1.params.some(hasConversions) - signature2.params.some(hasConversions)
|
32332 | if (c !== 0) {
|
32333 | return c;
|
32334 | }
|
32335 |
|
32336 | // next compare whether the params have conversions one by one
|
32337 | for (i = 0; i < len; i++) {
|
32338 | c = hasConversions(signature1.params[i]) - hasConversions(signature2.params[i]);
|
32339 | if (c !== 0) {
|
32340 | return c;
|
32341 | }
|
32342 | }
|
32343 |
|
32344 | // compare the types of the params one by one
|
32345 | for (i = 0; i < len; i++) {
|
32346 | c = compareParams(signature1.params[i], signature2.params[i]);
|
32347 | if (c !== 0) {
|
32348 | return c;
|
32349 | }
|
32350 | }
|
32351 |
|
32352 | // compare the number of params
|
32353 | return signature1.params.length - signature2.params.length;
|
32354 | }
|
32355 |
|
32356 | /**
|
32357 | * Get params containing all types that can be converted to the defined types.
|
32358 | *
|
32359 | * @param {ConversionDef[]} conversions
|
32360 | * @param {string[]} typeNames
|
32361 | * @return {ConversionDef[]} Returns the conversions that are available
|
32362 | * for every type (if any)
|
32363 | */
|
32364 | function filterConversions(conversions, typeNames) {
|
32365 | var matches = {};
|
32366 |
|
32367 | conversions.forEach(function (conversion) {
|
32368 | if (typeNames.indexOf(conversion.from) === -1 &&
|
32369 | typeNames.indexOf(conversion.to) !== -1 &&
|
32370 | !matches[conversion.from]) {
|
32371 | matches[conversion.from] = conversion;
|
32372 | }
|
32373 | });
|
32374 |
|
32375 | return Object.keys(matches).map(function (from) {
|
32376 | return matches[from];
|
32377 | });
|
32378 | }
|
32379 |
|
32380 | /**
|
32381 | * Preprocess arguments before calling the original function:
|
32382 | * - if needed convert the parameters
|
32383 | * - in case of rest parameters, move the rest parameters into an Array
|
32384 | * @param {Param[]} params
|
32385 | * @param {function} fn
|
32386 | * @return {function} Returns a wrapped function
|
32387 | */
|
32388 | function compileArgsPreprocessing(params, fn) {
|
32389 | var fnConvert = fn;
|
32390 |
|
32391 | // TODO: can we make this wrapper function smarter/simpler?
|
32392 |
|
32393 | if (params.some(hasConversions)) {
|
32394 | var restParam = hasRestParam(params);
|
32395 | var compiledConversions = params.map(compileArgConversion)
|
32396 |
|
32397 | fnConvert = function convertArgs() {
|
32398 | var args = [];
|
32399 | var last = restParam ? arguments.length - 1 : arguments.length;
|
32400 | for (var i = 0; i < last; i++) {
|
32401 | args[i] = compiledConversions[i](arguments[i]);
|
32402 | }
|
32403 | if (restParam) {
|
32404 | args[last] = arguments[last].map(compiledConversions[last]);
|
32405 | }
|
32406 |
|
32407 | return fn.apply(null, args);
|
32408 | }
|
32409 | }
|
32410 |
|
32411 | var fnPreprocess = fnConvert;
|
32412 | if (hasRestParam(params)) {
|
32413 | var offset = params.length - 1;
|
32414 |
|
32415 | fnPreprocess = function preprocessRestParams () {
|
32416 | return fnConvert.apply(null,
|
32417 | slice(arguments, 0, offset).concat([slice(arguments, offset)]));
|
32418 | }
|
32419 | }
|
32420 |
|
32421 | return fnPreprocess;
|
32422 | }
|
32423 |
|
32424 | /**
|
32425 | * Compile conversion for a parameter to the right type
|
32426 | * @param {Param} param
|
32427 | * @return {function} Returns the wrapped function that will convert arguments
|
32428 | *
|
32429 | */
|
32430 | function compileArgConversion(param) {
|
32431 | var test0, test1, conversion0, conversion1;
|
32432 | var tests = [];
|
32433 | var conversions = [];
|
32434 |
|
32435 | param.types.forEach(function (type) {
|
32436 | if (type.conversion) {
|
32437 | tests.push(findTypeByName(type.conversion.from).test);
|
32438 | conversions.push(type.conversion.convert);
|
32439 | }
|
32440 | });
|
32441 |
|
32442 | // create optimized conversion functions depending on the number of conversions
|
32443 | switch (conversions.length) {
|
32444 | case 0:
|
32445 | return function convertArg(arg) {
|
32446 | return arg;
|
32447 | }
|
32448 |
|
32449 | case 1:
|
32450 | test0 = tests[0]
|
32451 | conversion0 = conversions[0];
|
32452 | return function convertArg(arg) {
|
32453 | if (test0(arg)) {
|
32454 | return conversion0(arg)
|
32455 | }
|
32456 | return arg;
|
32457 | }
|
32458 |
|
32459 | case 2:
|
32460 | test0 = tests[0]
|
32461 | test1 = tests[1]
|
32462 | conversion0 = conversions[0];
|
32463 | conversion1 = conversions[1];
|
32464 | return function convertArg(arg) {
|
32465 | if (test0(arg)) {
|
32466 | return conversion0(arg)
|
32467 | }
|
32468 | if (test1(arg)) {
|
32469 | return conversion1(arg)
|
32470 | }
|
32471 | return arg;
|
32472 | }
|
32473 |
|
32474 | default:
|
32475 | return function convertArg(arg) {
|
32476 | for (var i = 0; i < conversions.length; i++) {
|
32477 | if (tests[i](arg)) {
|
32478 | return conversions[i](arg);
|
32479 | }
|
32480 | }
|
32481 | return arg;
|
32482 | }
|
32483 | }
|
32484 | }
|
32485 |
|
32486 | /**
|
32487 | * Convert an array with signatures into a map with signatures,
|
32488 | * where signatures with union types are split into separate signatures
|
32489 | *
|
32490 | * Throws an error when there are conflicting types
|
32491 | *
|
32492 | * @param {Signature[]} signatures
|
32493 | * @return {Object.<string, function>} Returns a map with signatures
|
32494 | * as key and the original function
|
32495 | * of this signature as value.
|
32496 | */
|
32497 | function createSignaturesMap(signatures) {
|
32498 | var signaturesMap = {};
|
32499 | signatures.forEach(function (signature) {
|
32500 | if (!signature.params.some(hasConversions)) {
|
32501 | splitParams(signature.params, true).forEach(function (params) {
|
32502 | signaturesMap[stringifyParams(params)] = signature.fn;
|
32503 | });
|
32504 | }
|
32505 | });
|
32506 |
|
32507 | return signaturesMap;
|
32508 | }
|
32509 |
|
32510 | /**
|
32511 | * Split params with union types in to separate params.
|
32512 | *
|
32513 | * For example:
|
32514 | *
|
32515 | * splitParams([['Array', 'Object'], ['string', 'RegExp'])
|
32516 | * // returns:
|
32517 | * // [
|
32518 | * // ['Array', 'string'],
|
32519 | * // ['Array', 'RegExp'],
|
32520 | * // ['Object', 'string'],
|
32521 | * // ['Object', 'RegExp']
|
32522 | * // ]
|
32523 | *
|
32524 | * @param {Param[]} params
|
32525 | * @param {boolean} ignoreConversionTypes
|
32526 | * @return {Param[]}
|
32527 | */
|
32528 | function splitParams(params, ignoreConversionTypes) {
|
32529 | function _splitParams(params, index, types) {
|
32530 | if (index < params.length) {
|
32531 | var param = params[index]
|
32532 | var filteredTypes = ignoreConversionTypes
|
32533 | ? param.types.filter(isExactType)
|
32534 | : param.types;
|
32535 | var typeGroups
|
32536 |
|
32537 | if (param.restParam) {
|
32538 | // split the types of a rest parameter in two:
|
32539 | // one with only exact types, and one with exact types and conversions
|
32540 | var exactTypes = filteredTypes.filter(isExactType)
|
32541 | typeGroups = exactTypes.length < filteredTypes.length
|
32542 | ? [exactTypes, filteredTypes]
|
32543 | : [filteredTypes]
|
32544 |
|
32545 | }
|
32546 | else {
|
32547 | // split all the types of a regular parameter into one type per group
|
32548 | typeGroups = filteredTypes.map(function (type) {
|
32549 | return [type]
|
32550 | })
|
32551 | }
|
32552 |
|
32553 | // recurse over the groups with types
|
32554 | return flatMap(typeGroups, function (typeGroup) {
|
32555 | return _splitParams(params, index + 1, types.concat([typeGroup]));
|
32556 | });
|
32557 |
|
32558 | }
|
32559 | else {
|
32560 | // we've reached the end of the parameters. Now build a new Param
|
32561 | var splittedParams = types.map(function (type, typeIndex) {
|
32562 | return {
|
32563 | types: type,
|
32564 | restParam: (typeIndex === params.length - 1) && hasRestParam(params)
|
32565 | }
|
32566 | });
|
32567 |
|
32568 | return [splittedParams];
|
32569 | }
|
32570 | }
|
32571 |
|
32572 | return _splitParams(params, 0, []);
|
32573 | }
|
32574 |
|
32575 | /**
|
32576 | * Test whether two signatures have a conflicting signature
|
32577 | * @param {Signature} signature1
|
32578 | * @param {Signature} signature2
|
32579 | * @return {boolean} Returns true when the signatures conflict, false otherwise.
|
32580 | */
|
32581 | function hasConflictingParams(signature1, signature2) {
|
32582 | var ii = Math.max(signature1.params.length, signature2.params.length);
|
32583 |
|
32584 | for (var i = 0; i < ii; i++) {
|
32585 | var typesNames1 = getExpectedTypeNames(signature1, i, true);
|
32586 | var typesNames2 = getExpectedTypeNames(signature2, i, true);
|
32587 |
|
32588 | if (!hasOverlap(typesNames1, typesNames2)) {
|
32589 | return false;
|
32590 | }
|
32591 | }
|
32592 |
|
32593 | var len1 = signature1.params.length;
|
32594 | var len2 = signature2.params.length;
|
32595 | var restParam1 = hasRestParam(signature1.params);
|
32596 | var restParam2 = hasRestParam(signature2.params);
|
32597 |
|
32598 | return restParam1
|
32599 | ? restParam2 ? (len1 === len2) : (len2 >= len1)
|
32600 | : restParam2 ? (len1 >= len2) : (len1 === len2)
|
32601 | }
|
32602 |
|
32603 | /**
|
32604 | * Create a typed function
|
32605 | * @param {String} name The name for the typed function
|
32606 | * @param {Object.<string, function>} signaturesMap
|
32607 | * An object with one or
|
32608 | * multiple signatures as key, and the
|
32609 | * function corresponding to the
|
32610 | * signature as value.
|
32611 | * @return {function} Returns the created typed function.
|
32612 | */
|
32613 | function createTypedFunction(name, signaturesMap) {
|
32614 | if (Object.keys(signaturesMap).length === 0) {
|
32615 | throw new SyntaxError('No signatures provided');
|
32616 | }
|
32617 |
|
32618 | // parse the signatures, and check for conflicts
|
32619 | var parsedSignatures = [];
|
32620 | Object.keys(signaturesMap)
|
32621 | .map(function (signature) {
|
32622 | return parseSignature(signature, signaturesMap[signature], typed.conversions);
|
32623 | })
|
32624 | .filter(notNull)
|
32625 | .forEach(function (parsedSignature) {
|
32626 | // check whether this parameter conflicts with already parsed signatures
|
32627 | var conflictingSignature = findInArray(parsedSignatures, function (s) {
|
32628 | return hasConflictingParams(s, parsedSignature)
|
32629 | });
|
32630 | if (conflictingSignature) {
|
32631 | throw new TypeError('Conflicting signatures "' +
|
32632 | stringifyParams(conflictingSignature.params) + '" and "' +
|
32633 | stringifyParams(parsedSignature.params) + '".');
|
32634 | }
|
32635 |
|
32636 | parsedSignatures.push(parsedSignature);
|
32637 | });
|
32638 |
|
32639 | // split and filter the types of the signatures, and then order them
|
32640 | var signatures = flatMap(parsedSignatures, function (parsedSignature) {
|
32641 | var params = parsedSignature ? splitParams(parsedSignature.params, false) : []
|
32642 |
|
32643 | return params.map(function (params) {
|
32644 | return {
|
32645 | params: params,
|
32646 | fn: parsedSignature.fn
|
32647 | };
|
32648 | });
|
32649 | }).filter(notNull);
|
32650 |
|
32651 | signatures.sort(compareSignatures);
|
32652 |
|
32653 | // we create a highly optimized checks for the first couple of signatures with max 2 arguments
|
32654 | var ok0 = signatures[0] && signatures[0].params.length <= 2 && !hasRestParam(signatures[0].params);
|
32655 | var ok1 = signatures[1] && signatures[1].params.length <= 2 && !hasRestParam(signatures[1].params);
|
32656 | var ok2 = signatures[2] && signatures[2].params.length <= 2 && !hasRestParam(signatures[2].params);
|
32657 | var ok3 = signatures[3] && signatures[3].params.length <= 2 && !hasRestParam(signatures[3].params);
|
32658 | var ok4 = signatures[4] && signatures[4].params.length <= 2 && !hasRestParam(signatures[4].params);
|
32659 | var ok5 = signatures[5] && signatures[5].params.length <= 2 && !hasRestParam(signatures[5].params);
|
32660 | var allOk = ok0 && ok1 && ok2 && ok3 && ok4 && ok5;
|
32661 |
|
32662 | // compile the tests
|
32663 | var tests = signatures.map(function (signature) {
|
32664 | return compileTests(signature.params);
|
32665 | });
|
32666 |
|
32667 | var test00 = ok0 ? compileTest(signatures[0].params[0]) : notOk;
|
32668 | var test10 = ok1 ? compileTest(signatures[1].params[0]) : notOk;
|
32669 | var test20 = ok2 ? compileTest(signatures[2].params[0]) : notOk;
|
32670 | var test30 = ok3 ? compileTest(signatures[3].params[0]) : notOk;
|
32671 | var test40 = ok4 ? compileTest(signatures[4].params[0]) : notOk;
|
32672 | var test50 = ok5 ? compileTest(signatures[5].params[0]) : notOk;
|
32673 |
|
32674 | var test01 = ok0 ? compileTest(signatures[0].params[1]) : notOk;
|
32675 | var test11 = ok1 ? compileTest(signatures[1].params[1]) : notOk;
|
32676 | var test21 = ok2 ? compileTest(signatures[2].params[1]) : notOk;
|
32677 | var test31 = ok3 ? compileTest(signatures[3].params[1]) : notOk;
|
32678 | var test41 = ok4 ? compileTest(signatures[4].params[1]) : notOk;
|
32679 | var test51 = ok5 ? compileTest(signatures[5].params[1]) : notOk;
|
32680 |
|
32681 | // compile the functions
|
32682 | var fns = signatures.map(function(signature) {
|
32683 | return compileArgsPreprocessing(signature.params, signature.fn)
|
32684 | });
|
32685 |
|
32686 | var fn0 = ok0 ? fns[0] : undef;
|
32687 | var fn1 = ok1 ? fns[1] : undef;
|
32688 | var fn2 = ok2 ? fns[2] : undef;
|
32689 | var fn3 = ok3 ? fns[3] : undef;
|
32690 | var fn4 = ok4 ? fns[4] : undef;
|
32691 | var fn5 = ok5 ? fns[5] : undef;
|
32692 |
|
32693 | var len0 = ok0 ? signatures[0].params.length : -1;
|
32694 | var len1 = ok1 ? signatures[1].params.length : -1;
|
32695 | var len2 = ok2 ? signatures[2].params.length : -1;
|
32696 | var len3 = ok3 ? signatures[3].params.length : -1;
|
32697 | var len4 = ok4 ? signatures[4].params.length : -1;
|
32698 | var len5 = ok5 ? signatures[5].params.length : -1;
|
32699 |
|
32700 | // simple and generic, but also slow
|
32701 | var iStart = allOk ? 6 : 0;
|
32702 | var iEnd = signatures.length;
|
32703 | var generic = function generic() {
|
32704 | 'use strict';
|
32705 |
|
32706 | for (var i = iStart; i < iEnd; i++) {
|
32707 | if (tests[i](arguments)) {
|
32708 | return fns[i].apply(null, arguments);
|
32709 | }
|
32710 | }
|
32711 |
|
32712 | throw createError(name, arguments, signatures);
|
32713 | }
|
32714 |
|
32715 | // create the typed function
|
32716 | // fast, specialized version. Falls back to the slower, generic one if needed
|
32717 | var fn = function fn(arg0, arg1) {
|
32718 | 'use strict';
|
32719 |
|
32720 | if (arguments.length === len0 && test00(arg0) && test01(arg1)) { return fn0.apply(null, arguments); }
|
32721 | if (arguments.length === len1 && test10(arg0) && test11(arg1)) { return fn1.apply(null, arguments); }
|
32722 | if (arguments.length === len2 && test20(arg0) && test21(arg1)) { return fn2.apply(null, arguments); }
|
32723 | if (arguments.length === len3 && test30(arg0) && test31(arg1)) { return fn3.apply(null, arguments); }
|
32724 | if (arguments.length === len4 && test40(arg0) && test41(arg1)) { return fn4.apply(null, arguments); }
|
32725 | if (arguments.length === len5 && test50(arg0) && test51(arg1)) { return fn5.apply(null, arguments); }
|
32726 |
|
32727 | return generic.apply(null, arguments);
|
32728 | }
|
32729 |
|
32730 | // attach name the typed function
|
32731 | try {
|
32732 | Object.defineProperty(fn, 'name', {value: name});
|
32733 | }
|
32734 | catch (err) {
|
32735 | // old browsers do not support Object.defineProperty and some don't support setting the name property
|
32736 | // the function name is not essential for the functioning, it's mostly useful for debugging,
|
32737 | // so it's fine to have unnamed functions.
|
32738 | }
|
32739 |
|
32740 | // attach signatures to the function
|
32741 | fn.signatures = createSignaturesMap(signatures);
|
32742 |
|
32743 | return fn;
|
32744 | }
|
32745 |
|
32746 | /**
|
32747 | * Test whether a type should be NOT be ignored
|
32748 | * @param {string} typeName
|
32749 | * @return {boolean}
|
32750 | */
|
32751 | function notIgnore(typeName) {
|
32752 | return typed.ignore.indexOf(typeName) === -1;
|
32753 | }
|
32754 |
|
32755 | /**
|
32756 | * trim a string
|
32757 | * @param {string} str
|
32758 | * @return {string}
|
32759 | */
|
32760 | function trim(str) {
|
32761 | return str.trim();
|
32762 | }
|
32763 |
|
32764 | /**
|
32765 | * Test whether a string is not empty
|
32766 | * @param {string} str
|
32767 | * @return {boolean}
|
32768 | */
|
32769 | function notEmpty(str) {
|
32770 | return !!str;
|
32771 | }
|
32772 |
|
32773 | /**
|
32774 | * test whether a value is not strict equal to null
|
32775 | * @param {*} value
|
32776 | * @return {boolean}
|
32777 | */
|
32778 | function notNull(value) {
|
32779 | return value !== null;
|
32780 | }
|
32781 |
|
32782 | /**
|
32783 | * Test whether a parameter has no types defined
|
32784 | * @param {Param} param
|
32785 | * @return {boolean}
|
32786 | */
|
32787 | function isInvalidParam (param) {
|
32788 | return param.types.length === 0;
|
32789 | }
|
32790 |
|
32791 | /**
|
32792 | * Return all but the last items of an array
|
32793 | * @param {Array} arr
|
32794 | * @return {Array}
|
32795 | */
|
32796 | function initial(arr) {
|
32797 | return arr.slice(0, arr.length - 1);
|
32798 | }
|
32799 |
|
32800 | /**
|
32801 | * return the last item of an array
|
32802 | * @param {Array} arr
|
32803 | * @return {*}
|
32804 | */
|
32805 | function last(arr) {
|
32806 | return arr[arr.length - 1];
|
32807 | }
|
32808 |
|
32809 | /**
|
32810 | * Slice an array or function Arguments
|
32811 | * @param {Array | Arguments | IArguments} arr
|
32812 | * @param {number} start
|
32813 | * @param {number} [end]
|
32814 | * @return {Array}
|
32815 | */
|
32816 | function slice(arr, start, end) {
|
32817 | return Array.prototype.slice.call(arr, start, end);
|
32818 | }
|
32819 |
|
32820 | /**
|
32821 | * Test whether an array contains some item
|
32822 | * @param {Array} array
|
32823 | * @param {*} item
|
32824 | * @return {boolean} Returns true if array contains item, false if not.
|
32825 | */
|
32826 | function contains(array, item) {
|
32827 | return array.indexOf(item) !== -1;
|
32828 | }
|
32829 |
|
32830 | /**
|
32831 | * Test whether two arrays have overlapping items
|
32832 | * @param {Array} array1
|
32833 | * @param {Array} array2
|
32834 | * @return {boolean} Returns true when at least one item exists in both arrays
|
32835 | */
|
32836 | function hasOverlap(array1, array2) {
|
32837 | for (var i = 0; i < array1.length; i++) {
|
32838 | if (contains(array2, array1[i])) {
|
32839 | return true;
|
32840 | }
|
32841 | }
|
32842 |
|
32843 | return false;
|
32844 | }
|
32845 |
|
32846 | /**
|
32847 | * Return the first item from an array for which test(arr[i]) returns true
|
32848 | * @param {Array} arr
|
32849 | * @param {function} test
|
32850 | * @return {* | undefined} Returns the first matching item
|
32851 | * or undefined when there is no match
|
32852 | */
|
32853 | function findInArray(arr, test) {
|
32854 | for (var i = 0; i < arr.length; i++) {
|
32855 | if (test(arr[i])) {
|
32856 | return arr[i];
|
32857 | }
|
32858 | }
|
32859 | return undefined;
|
32860 | }
|
32861 |
|
32862 | /**
|
32863 | * Filter unique items of an array with strings
|
32864 | * @param {string[]} arr
|
32865 | * @return {string[]}
|
32866 | */
|
32867 | function uniq(arr) {
|
32868 | var entries = {}
|
32869 | for (var i = 0; i < arr.length; i++) {
|
32870 | entries[arr[i]] = true;
|
32871 | }
|
32872 | return Object.keys(entries);
|
32873 | }
|
32874 |
|
32875 | /**
|
32876 | * Flat map the result invoking a callback for every item in an array.
|
32877 | * https://gist.github.com/samgiles/762ee337dff48623e729
|
32878 | * @param {Array} arr
|
32879 | * @param {function} callback
|
32880 | * @return {Array}
|
32881 | */
|
32882 | function flatMap(arr, callback) {
|
32883 | return Array.prototype.concat.apply([], arr.map(callback));
|
32884 | }
|
32885 |
|
32886 | /**
|
32887 | * Retrieve the function name from a set of typed functions,
|
32888 | * and check whether the name of all functions match (if given)
|
32889 | * @param {function[]} fns
|
32890 | */
|
32891 | function getName (fns) {
|
32892 | var name = '';
|
32893 |
|
32894 | for (var i = 0; i < fns.length; i++) {
|
32895 | var fn = fns[i];
|
32896 |
|
32897 | // check whether the names are the same when defined
|
32898 | if ((typeof fn.signatures === 'object' || typeof fn.signature === 'string') && fn.name !== '') {
|
32899 | if (name === '') {
|
32900 | name = fn.name;
|
32901 | }
|
32902 | else if (name !== fn.name) {
|
32903 | var err = new Error('Function names do not match (expected: ' + name + ', actual: ' + fn.name + ')');
|
32904 | err.data = {
|
32905 | actual: fn.name,
|
32906 | expected: name
|
32907 | };
|
32908 | throw err;
|
32909 | }
|
32910 | }
|
32911 | }
|
32912 |
|
32913 | return name;
|
32914 | }
|
32915 |
|
32916 | // extract and merge all signatures of a list with typed functions
|
32917 | function extractSignatures(fns) {
|
32918 | var err;
|
32919 | var signaturesMap = {};
|
32920 |
|
32921 | function validateUnique(_signature, _fn) {
|
32922 | if (signaturesMap.hasOwnProperty(_signature) && _fn !== signaturesMap[_signature]) {
|
32923 | err = new Error('Signature "' + _signature + '" is defined twice');
|
32924 | err.data = {signature: _signature};
|
32925 | throw err;
|
32926 | // else: both signatures point to the same function, that's fine
|
32927 | }
|
32928 | }
|
32929 |
|
32930 | for (var i = 0; i < fns.length; i++) {
|
32931 | var fn = fns[i];
|
32932 |
|
32933 | // test whether this is a typed-function
|
32934 | if (typeof fn.signatures === 'object') {
|
32935 | // merge the signatures
|
32936 | for (var signature in fn.signatures) {
|
32937 | if (fn.signatures.hasOwnProperty(signature)) {
|
32938 | validateUnique(signature, fn.signatures[signature]);
|
32939 | signaturesMap[signature] = fn.signatures[signature];
|
32940 | }
|
32941 | }
|
32942 | }
|
32943 | else if (typeof fn.signature === 'string') {
|
32944 | validateUnique(fn.signature, fn);
|
32945 | signaturesMap[fn.signature] = fn;
|
32946 | }
|
32947 | else {
|
32948 | err = new TypeError('Function is no typed-function (index: ' + i + ')');
|
32949 | err.data = {index: i};
|
32950 | throw err;
|
32951 | }
|
32952 | }
|
32953 |
|
32954 | return signaturesMap;
|
32955 | }
|
32956 |
|
32957 | typed = createTypedFunction('typed', {
|
32958 | 'string, Object': createTypedFunction,
|
32959 | 'Object': function (signaturesMap) {
|
32960 | // find existing name
|
32961 | var fns = [];
|
32962 | for (var signature in signaturesMap) {
|
32963 | if (signaturesMap.hasOwnProperty(signature)) {
|
32964 | fns.push(signaturesMap[signature]);
|
32965 | }
|
32966 | }
|
32967 | var name = getName(fns);
|
32968 | return createTypedFunction(name, signaturesMap);
|
32969 | },
|
32970 | '...Function': function (fns) {
|
32971 | return createTypedFunction(getName(fns), extractSignatures(fns));
|
32972 | },
|
32973 | 'string, ...Function': function (name, fns) {
|
32974 | return createTypedFunction(name, extractSignatures(fns));
|
32975 | }
|
32976 | });
|
32977 |
|
32978 | typed.create = create;
|
32979 | typed.types = _types;
|
32980 | typed.conversions = _conversions;
|
32981 | typed.ignore = _ignore;
|
32982 | typed.convert = convert;
|
32983 | typed.find = find;
|
32984 |
|
32985 | /**
|
32986 | * add a type
|
32987 | * @param {{name: string, test: function}} type
|
32988 | * @param {boolean} [beforeObjectTest=true]
|
32989 | * If true, the new test will be inserted before
|
32990 | * the test with name 'Object' (if any), since
|
32991 | * tests for Object match Array and classes too.
|
32992 | */
|
32993 | typed.addType = function (type, beforeObjectTest) {
|
32994 | if (!type || typeof type.name !== 'string' || typeof type.test !== 'function') {
|
32995 | throw new TypeError('Object with properties {name: string, test: function} expected');
|
32996 | }
|
32997 |
|
32998 | if (beforeObjectTest !== false) {
|
32999 | for (var i = 0; i < typed.types.length; i++) {
|
33000 | if (typed.types[i].name === 'Object') {
|
33001 | typed.types.splice(i, 0, type);
|
33002 | return
|
33003 | }
|
33004 | }
|
33005 | }
|
33006 |
|
33007 | typed.types.push(type);
|
33008 | };
|
33009 |
|
33010 | // add a conversion
|
33011 | typed.addConversion = function (conversion) {
|
33012 | if (!conversion
|
33013 | || typeof conversion.from !== 'string'
|
33014 | || typeof conversion.to !== 'string'
|
33015 | || typeof conversion.convert !== 'function') {
|
33016 | throw new TypeError('Object with properties {from: string, to: string, convert: function} expected');
|
33017 | }
|
33018 |
|
33019 | typed.conversions.push(conversion);
|
33020 | };
|
33021 |
|
33022 | return typed;
|
33023 | }
|
33024 |
|
33025 | return create();
|
33026 | }));
|
33027 |
|
33028 | /***/ }),
|
33029 | /* 165 */
|
33030 | /***/ (function(module, exports) {
|
33031 |
|
33032 | function E () {
|
33033 | // Keep this empty so it's easier to inherit from
|
33034 | // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
|
33035 | }
|
33036 |
|
33037 | E.prototype = {
|
33038 | on: function (name, callback, ctx) {
|
33039 | var e = this.e || (this.e = {});
|
33040 |
|
33041 | (e[name] || (e[name] = [])).push({
|
33042 | fn: callback,
|
33043 | ctx: ctx
|
33044 | });
|
33045 |
|
33046 | return this;
|
33047 | },
|
33048 |
|
33049 | once: function (name, callback, ctx) {
|
33050 | var self = this;
|
33051 | function listener () {
|
33052 | self.off(name, listener);
|
33053 | callback.apply(ctx, arguments);
|
33054 | };
|
33055 |
|
33056 | listener._ = callback
|
33057 | return this.on(name, listener, ctx);
|
33058 | },
|
33059 |
|
33060 | emit: function (name) {
|
33061 | var data = [].slice.call(arguments, 1);
|
33062 | var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
|
33063 | var i = 0;
|
33064 | var len = evtArr.length;
|
33065 |
|
33066 | for (i; i < len; i++) {
|
33067 | evtArr[i].fn.apply(evtArr[i].ctx, data);
|
33068 | }
|
33069 |
|
33070 | return this;
|
33071 | },
|
33072 |
|
33073 | off: function (name, callback) {
|
33074 | var e = this.e || (this.e = {});
|
33075 | var evts = e[name];
|
33076 | var liveEvents = [];
|
33077 |
|
33078 | if (evts && callback) {
|
33079 | for (var i = 0, len = evts.length; i < len; i++) {
|
33080 | if (evts[i].fn !== callback && evts[i].fn._ !== callback)
|
33081 | liveEvents.push(evts[i]);
|
33082 | }
|
33083 | }
|
33084 |
|
33085 | // Remove event from queue to prevent memory leak
|
33086 | // Suggested by https://github.com/lazd
|
33087 | // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
|
33088 |
|
33089 | (liveEvents.length)
|
33090 | ? e[name] = liveEvents
|
33091 | : delete e[name];
|
33092 |
|
33093 | return this;
|
33094 | }
|
33095 | };
|
33096 |
|
33097 | module.exports = E;
|
33098 | module.exports.TinyEmitter = E;
|
33099 |
|
33100 |
|
33101 | /***/ }),
|
33102 | /* 166 */
|
33103 | /***/ (function(module, exports, __webpack_require__) {
|
33104 |
|
33105 | "use strict";
|
33106 |
|
33107 |
|
33108 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
33109 |
|
33110 | var lazy = __webpack_require__(5).lazy;
|
33111 |
|
33112 | var isFactory = __webpack_require__(5).isFactory;
|
33113 |
|
33114 | var traverse = __webpack_require__(5).traverse;
|
33115 |
|
33116 | var ArgumentsError = __webpack_require__(57);
|
33117 |
|
33118 | function factory(type, config, load, typed, math) {
|
33119 | /**
|
33120 | * Import functions from an object or a module
|
33121 | *
|
33122 | * Syntax:
|
33123 | *
|
33124 | * math.import(object)
|
33125 | * math.import(object, options)
|
33126 | *
|
33127 | * Where:
|
33128 | *
|
33129 | * - `object: Object`
|
33130 | * An object with functions to be imported.
|
33131 | * - `options: Object` An object with import options. Available options:
|
33132 | * - `override: boolean`
|
33133 | * If true, existing functions will be overwritten. False by default.
|
33134 | * - `silent: boolean`
|
33135 | * If true, the function will not throw errors on duplicates or invalid
|
33136 | * types. False by default.
|
33137 | * - `wrap: boolean`
|
33138 | * If true, the functions will be wrapped in a wrapper function
|
33139 | * which converts data types like Matrix to primitive data types like Array.
|
33140 | * The wrapper is needed when extending math.js with libraries which do not
|
33141 | * support these data type. False by default.
|
33142 | *
|
33143 | * Examples:
|
33144 | *
|
33145 | * // define new functions and variables
|
33146 | * math.import({
|
33147 | * myvalue: 42,
|
33148 | * hello: function (name) {
|
33149 | * return 'hello, ' + name + '!'
|
33150 | * }
|
33151 | * })
|
33152 | *
|
33153 | * // use the imported function and variable
|
33154 | * math.myvalue * 2 // 84
|
33155 | * math.hello('user') // 'hello, user!'
|
33156 | *
|
33157 | * // import the npm module 'numbers'
|
33158 | * // (must be installed first with `npm install numbers`)
|
33159 | * math.import(require('numbers'), {wrap: true})
|
33160 | *
|
33161 | * math.fibonacci(7) // returns 13
|
33162 | *
|
33163 | * @param {Object | Array} object Object with functions to be imported.
|
33164 | * @param {Object} [options] Import options.
|
33165 | */
|
33166 | function mathImport(object, options) {
|
33167 | var num = arguments.length;
|
33168 |
|
33169 | if (num !== 1 && num !== 2) {
|
33170 | throw new ArgumentsError('import', num, 1, 2);
|
33171 | }
|
33172 |
|
33173 | if (!options) {
|
33174 | options = {};
|
33175 | } // TODO: allow a typed-function with name too
|
33176 |
|
33177 |
|
33178 | if (isFactory(object)) {
|
33179 | _importFactory(object, options);
|
33180 | } else if (Array.isArray(object)) {
|
33181 | object.forEach(function (entry) {
|
33182 | mathImport(entry, options);
|
33183 | });
|
33184 | } else if (_typeof(object) === 'object') {
|
33185 | // a map with functions
|
33186 | for (var name in object) {
|
33187 | if (object.hasOwnProperty(name)) {
|
33188 | var value = object[name];
|
33189 |
|
33190 | if (isSupportedType(value)) {
|
33191 | _import(name, value, options);
|
33192 | } else if (isFactory(object)) {
|
33193 | _importFactory(object, options);
|
33194 | } else {
|
33195 | mathImport(value, options);
|
33196 | }
|
33197 | }
|
33198 | }
|
33199 | } else {
|
33200 | if (!options.silent) {
|
33201 | throw new TypeError('Factory, Object, or Array expected');
|
33202 | }
|
33203 | }
|
33204 | }
|
33205 | /**
|
33206 | * Add a property to the math namespace and create a chain proxy for it.
|
33207 | * @param {string} name
|
33208 | * @param {*} value
|
33209 | * @param {Object} options See import for a description of the options
|
33210 | * @private
|
33211 | */
|
33212 |
|
33213 |
|
33214 | function _import(name, value, options) {
|
33215 | // TODO: refactor this function, it's to complicated and contains duplicate code
|
33216 | if (options.wrap && typeof value === 'function') {
|
33217 | // create a wrapper around the function
|
33218 | value = _wrap(value);
|
33219 | }
|
33220 |
|
33221 | if (isTypedFunction(math[name]) && isTypedFunction(value)) {
|
33222 | if (options.override) {
|
33223 | // give the typed function the right name
|
33224 | value = typed(name, value.signatures);
|
33225 | } else {
|
33226 | // merge the existing and typed function
|
33227 | value = typed(math[name], value);
|
33228 | }
|
33229 |
|
33230 | math[name] = value;
|
33231 |
|
33232 | _importTransform(name, value);
|
33233 |
|
33234 | math.emit('import', name, function resolver() {
|
33235 | return value;
|
33236 | });
|
33237 | return;
|
33238 | }
|
33239 |
|
33240 | if (math[name] === undefined || options.override) {
|
33241 | math[name] = value;
|
33242 |
|
33243 | _importTransform(name, value);
|
33244 |
|
33245 | math.emit('import', name, function resolver() {
|
33246 | return value;
|
33247 | });
|
33248 | return;
|
33249 | }
|
33250 |
|
33251 | if (!options.silent) {
|
33252 | throw new Error('Cannot import "' + name + '": already exists');
|
33253 | }
|
33254 | }
|
33255 |
|
33256 | function _importTransform(name, value) {
|
33257 | if (value && typeof value.transform === 'function') {
|
33258 | math.expression.transform[name] = value.transform;
|
33259 |
|
33260 | if (allowedInExpressions(name)) {
|
33261 | math.expression.mathWithTransform[name] = value.transform;
|
33262 | }
|
33263 | } else {
|
33264 | // remove existing transform
|
33265 | delete math.expression.transform[name];
|
33266 |
|
33267 | if (allowedInExpressions(name)) {
|
33268 | math.expression.mathWithTransform[name] = value;
|
33269 | }
|
33270 | }
|
33271 | }
|
33272 |
|
33273 | function _deleteTransform(name) {
|
33274 | delete math.expression.transform[name];
|
33275 |
|
33276 | if (allowedInExpressions(name)) {
|
33277 | math.expression.mathWithTransform[name] = math[name];
|
33278 | } else {
|
33279 | delete math.expression.mathWithTransform[name];
|
33280 | }
|
33281 | }
|
33282 | /**
|
33283 | * Create a wrapper a round an function which converts the arguments
|
33284 | * to their primitive values (like convert a Matrix to Array)
|
33285 | * @param {Function} fn
|
33286 | * @return {Function} Returns the wrapped function
|
33287 | * @private
|
33288 | */
|
33289 |
|
33290 |
|
33291 | function _wrap(fn) {
|
33292 | var wrapper = function wrapper() {
|
33293 | var args = [];
|
33294 |
|
33295 | for (var i = 0, len = arguments.length; i < len; i++) {
|
33296 | var arg = arguments[i];
|
33297 | args[i] = arg && arg.valueOf();
|
33298 | }
|
33299 |
|
33300 | return fn.apply(math, args);
|
33301 | };
|
33302 |
|
33303 | if (fn.transform) {
|
33304 | wrapper.transform = fn.transform;
|
33305 | }
|
33306 |
|
33307 | return wrapper;
|
33308 | }
|
33309 | /**
|
33310 | * Import an instance of a factory into math.js
|
33311 | * @param {{factory: Function, name: string, path: string, math: boolean}} factory
|
33312 | * @param {Object} options See import for a description of the options
|
33313 | * @private
|
33314 | */
|
33315 |
|
33316 |
|
33317 | function _importFactory(factory, options) {
|
33318 | if (typeof factory.name === 'string') {
|
33319 | var name = factory.name;
|
33320 | var existingTransform = name in math.expression.transform;
|
33321 | var namespace = factory.path ? traverse(math, factory.path) : math;
|
33322 | var existing = namespace.hasOwnProperty(name) ? namespace[name] : undefined;
|
33323 |
|
33324 | var resolver = function resolver() {
|
33325 | var instance = load(factory);
|
33326 |
|
33327 | if (instance && typeof instance.transform === 'function') {
|
33328 | throw new Error('Transforms cannot be attached to factory functions. ' + 'Please create a separate function for it with exports.path="expression.transform"');
|
33329 | }
|
33330 |
|
33331 | if (isTypedFunction(existing) && isTypedFunction(instance)) {
|
33332 | if (options.override) {// replace the existing typed function (nothing to do)
|
33333 | } else {
|
33334 | // merge the existing and new typed function
|
33335 | instance = typed(existing, instance);
|
33336 | }
|
33337 |
|
33338 | return instance;
|
33339 | }
|
33340 |
|
33341 | if (existing === undefined || options.override) {
|
33342 | return instance;
|
33343 | }
|
33344 |
|
33345 | if (!options.silent) {
|
33346 | throw new Error('Cannot import "' + name + '": already exists');
|
33347 | }
|
33348 | };
|
33349 |
|
33350 | if (factory.lazy !== false) {
|
33351 | lazy(namespace, name, resolver);
|
33352 |
|
33353 | if (existingTransform) {
|
33354 | _deleteTransform(name);
|
33355 | } else {
|
33356 | if (factory.path === 'expression.transform' || factoryAllowedInExpressions(factory)) {
|
33357 | lazy(math.expression.mathWithTransform, name, resolver);
|
33358 | }
|
33359 | }
|
33360 | } else {
|
33361 | namespace[name] = resolver();
|
33362 |
|
33363 | if (existingTransform) {
|
33364 | _deleteTransform(name);
|
33365 | } else {
|
33366 | if (factory.path === 'expression.transform' || factoryAllowedInExpressions(factory)) {
|
33367 | math.expression.mathWithTransform[name] = resolver();
|
33368 | }
|
33369 | }
|
33370 | }
|
33371 |
|
33372 | math.emit('import', name, resolver, factory.path);
|
33373 | } else {
|
33374 | // unnamed factory.
|
33375 | // no lazy loading
|
33376 | load(factory);
|
33377 | }
|
33378 | }
|
33379 | /**
|
33380 | * Check whether given object is a type which can be imported
|
33381 | * @param {Function | number | string | boolean | null | Unit | Complex} object
|
33382 | * @return {boolean}
|
33383 | * @private
|
33384 | */
|
33385 |
|
33386 |
|
33387 | function isSupportedType(object) {
|
33388 | return typeof object === 'function' || typeof object === 'number' || typeof object === 'string' || typeof object === 'boolean' || object === null || object && type.isUnit(object) || object && type.isComplex(object) || object && type.isBigNumber(object) || object && type.isFraction(object) || object && type.isMatrix(object) || object && Array.isArray(object);
|
33389 | }
|
33390 | /**
|
33391 | * Test whether a given thing is a typed-function
|
33392 | * @param {*} fn
|
33393 | * @return {boolean} Returns true when `fn` is a typed-function
|
33394 | */
|
33395 |
|
33396 |
|
33397 | function isTypedFunction(fn) {
|
33398 | return typeof fn === 'function' && _typeof(fn.signatures) === 'object';
|
33399 | }
|
33400 |
|
33401 | function allowedInExpressions(name) {
|
33402 | return !unsafe.hasOwnProperty(name);
|
33403 | }
|
33404 |
|
33405 | function factoryAllowedInExpressions(factory) {
|
33406 | return factory.path === undefined && !unsafe.hasOwnProperty(factory.name);
|
33407 | } // namespaces and functions not available in the parser for safety reasons
|
33408 |
|
33409 |
|
33410 | var unsafe = {
|
33411 | 'expression': true,
|
33412 | 'type': true,
|
33413 | 'docs': true,
|
33414 | 'error': true,
|
33415 | 'json': true,
|
33416 | 'chain': true // chain method not supported. Note that there is a unit chain too.
|
33417 |
|
33418 | };
|
33419 | return mathImport;
|
33420 | }
|
33421 |
|
33422 | exports.math = true; // request access to the math namespace as 5th argument of the factory function
|
33423 |
|
33424 | exports.name = 'import';
|
33425 | exports.factory = factory;
|
33426 | exports.lazy = true;
|
33427 |
|
33428 | /***/ }),
|
33429 | /* 167 */
|
33430 | /***/ (function(module, exports, __webpack_require__) {
|
33431 |
|
33432 | "use strict";
|
33433 |
|
33434 |
|
33435 | var object = __webpack_require__(5);
|
33436 |
|
33437 | function factory(type, config, load, typed, math) {
|
33438 | var MATRIX = ['Matrix', 'Array']; // valid values for option matrix
|
33439 |
|
33440 | var NUMBER = ['number', 'BigNumber', 'Fraction']; // valid values for option number
|
33441 |
|
33442 | /**
|
33443 | * Set configuration options for math.js, and get current options.
|
33444 | * Will emit a 'config' event, with arguments (curr, prev, changes).
|
33445 | *
|
33446 | * Syntax:
|
33447 | *
|
33448 | * math.config(config: Object): Object
|
33449 | *
|
33450 | * Examples:
|
33451 | *
|
33452 | * math.config().number // outputs 'number'
|
33453 | * math.eval('0.4') // outputs number 0.4
|
33454 | * math.config({number: 'Fraction'})
|
33455 | * math.eval('0.4') // outputs Fraction 2/5
|
33456 | *
|
33457 | * @param {Object} [options] Available options:
|
33458 | * {number} epsilon
|
33459 | * Minimum relative difference between two
|
33460 | * compared values, used by all comparison functions.
|
33461 | * {string} matrix
|
33462 | * A string 'Matrix' (default) or 'Array'.
|
33463 | * {string} number
|
33464 | * A string 'number' (default), 'BigNumber', or 'Fraction'
|
33465 | * {number} precision
|
33466 | * The number of significant digits for BigNumbers.
|
33467 | * Not applicable for Numbers.
|
33468 | * {string} parenthesis
|
33469 | * How to display parentheses in LaTeX and string
|
33470 | * output.
|
33471 | * {string} randomSeed
|
33472 | * Random seed for seeded pseudo random number generator.
|
33473 | * Set to null to randomly seed.
|
33474 | * @return {Object} Returns the current configuration
|
33475 | */
|
33476 |
|
33477 | function _config(options) {
|
33478 | if (options) {
|
33479 | var prev = object.map(config, object.clone); // validate some of the options
|
33480 |
|
33481 | validateOption(options, 'matrix', MATRIX);
|
33482 | validateOption(options, 'number', NUMBER); // merge options
|
33483 |
|
33484 | object.deepExtend(config, options);
|
33485 | var curr = object.map(config, object.clone);
|
33486 | var changes = object.map(options, object.clone); // emit 'config' event
|
33487 |
|
33488 | math.emit('config', curr, prev, changes);
|
33489 | return curr;
|
33490 | } else {
|
33491 | return object.map(config, object.clone);
|
33492 | }
|
33493 | } // attach the valid options to the function so they can be extended
|
33494 |
|
33495 |
|
33496 | _config.MATRIX = MATRIX;
|
33497 | _config.NUMBER = NUMBER;
|
33498 | return _config;
|
33499 | }
|
33500 | /**
|
33501 | * Test whether an Array contains a specific item.
|
33502 | * @param {Array.<string>} array
|
33503 | * @param {string} item
|
33504 | * @return {boolean}
|
33505 | */
|
33506 |
|
33507 |
|
33508 | function contains(array, item) {
|
33509 | return array.indexOf(item) !== -1;
|
33510 | }
|
33511 | /**
|
33512 | * Find a string in an array. Case insensitive search
|
33513 | * @param {Array.<string>} array
|
33514 | * @param {string} item
|
33515 | * @return {number} Returns the index when found. Returns -1 when not found
|
33516 | */
|
33517 |
|
33518 |
|
33519 | function findIndex(array, item) {
|
33520 | return array.map(function (i) {
|
33521 | return i.toLowerCase();
|
33522 | }).indexOf(item.toLowerCase());
|
33523 | }
|
33524 | /**
|
33525 | * Validate an option
|
33526 | * @param {Object} options Object with options
|
33527 | * @param {string} name Name of the option to validate
|
33528 | * @param {Array.<string>} values Array with valid values for this option
|
33529 | */
|
33530 |
|
33531 |
|
33532 | function validateOption(options, name, values) {
|
33533 | if (options[name] !== undefined && !contains(values, options[name])) {
|
33534 | var index = findIndex(values, options[name]);
|
33535 |
|
33536 | if (index !== -1) {
|
33537 | // right value, wrong casing
|
33538 | // TODO: lower case values are deprecated since v3, remove this warning some day.
|
33539 | console.warn('Warning: Wrong casing for configuration option "' + name + '", should be "' + values[index] + '" instead of "' + options[name] + '".');
|
33540 | options[name] = values[index]; // change the option to the right casing
|
33541 | } else {
|
33542 | // unknown value
|
33543 | console.warn('Warning: Unknown value "' + options[name] + '" for configuration option "' + name + '". Available options: ' + values.map(JSON.stringify).join(', ') + '.');
|
33544 | }
|
33545 | }
|
33546 | }
|
33547 |
|
33548 | exports.name = 'config';
|
33549 | exports.math = true; // request the math namespace as fifth argument
|
33550 |
|
33551 | exports.factory = factory;
|
33552 |
|
33553 | /***/ }),
|
33554 | /* 168 */
|
33555 | /***/ (function(module, exports, __webpack_require__) {
|
33556 |
|
33557 | // This file contains all factory functions of math.js
|
33558 | module.exports = [__webpack_require__(169), // data types (Matrix, Complex, Unit, ...)
|
33559 | __webpack_require__(200), // constants
|
33560 | __webpack_require__(202), // functions
|
33561 | // load ./expression *after* ./function since we need to
|
33562 | // attach transforms to functions that are imported there
|
33563 | __webpack_require__(355), // expression parsing
|
33564 | __webpack_require__(585), // serialization utility (math.json.reviver)
|
33565 | __webpack_require__(587) // errors
|
33566 | ];
|
33567 |
|
33568 | /***/ }),
|
33569 | /* 169 */
|
33570 | /***/ (function(module, exports, __webpack_require__) {
|
33571 |
|
33572 | "use strict";
|
33573 |
|
33574 |
|
33575 | module.exports = [__webpack_require__(170), __webpack_require__(172), __webpack_require__(173), __webpack_require__(177), __webpack_require__(181), __webpack_require__(184), __webpack_require__(64), __webpack_require__(65), __webpack_require__(192), __webpack_require__(193), __webpack_require__(194)];
|
33576 |
|
33577 | /***/ }),
|
33578 | /* 170 */
|
33579 | /***/ (function(module, exports, __webpack_require__) {
|
33580 |
|
33581 | "use strict";
|
33582 |
|
33583 |
|
33584 | module.exports = [// type
|
33585 | __webpack_require__(171), // construction function
|
33586 | __webpack_require__(105)];
|
33587 |
|
33588 | /***/ }),
|
33589 | /* 171 */
|
33590 | /***/ (function(module, __webpack_exports__, __webpack_require__) {
|
33591 |
|
33592 | "use strict";
|
33593 | __webpack_require__.r(__webpack_exports__);
|
33594 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "factory", function() { return factory; });
|
33595 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "name", function() { return name; });
|
33596 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "path", function() { return path; });
|
33597 | /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "math", function() { return math; });
|
33598 | /* harmony import */ var decimal_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(160);
|
33599 | /* harmony import */ var decimal_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(decimal_js__WEBPACK_IMPORTED_MODULE_0__);
|
33600 |
|
33601 |
|
33602 |
|
33603 | function factory(type, config, load, typed, math) {
|
33604 | var BigNumber = decimal_js__WEBPACK_IMPORTED_MODULE_0___default.a.clone({
|
33605 | precision: config.precision
|
33606 | });
|
33607 | /**
|
33608 | * Attach type information
|
33609 | */
|
33610 |
|
33611 | BigNumber.prototype.type = 'BigNumber';
|
33612 | BigNumber.prototype.isBigNumber = true;
|
33613 | /**
|
33614 | * Get a JSON representation of a BigNumber containing
|
33615 | * type information
|
33616 | * @returns {Object} Returns a JSON object structured as:
|
33617 | * `{"mathjs": "BigNumber", "value": "0.2"}`
|
33618 | */
|
33619 |
|
33620 | BigNumber.prototype.toJSON = function () {
|
33621 | return {
|
33622 | mathjs: 'BigNumber',
|
33623 | value: this.toString()
|
33624 | };
|
33625 | };
|
33626 | /**
|
33627 | * Instantiate a BigNumber from a JSON object
|
33628 | * @param {Object} json a JSON object structured as:
|
33629 | * `{"mathjs": "BigNumber", "value": "0.2"}`
|
33630 | * @return {BigNumber}
|
33631 | */
|
33632 |
|
33633 |
|
33634 | BigNumber.fromJSON = function (json) {
|
33635 | return new BigNumber(json.value);
|
33636 | }; // listen for changed in the configuration, automatically apply changed precision
|
33637 |
|
33638 |
|
33639 | math.on('config', function (curr, prev) {
|
33640 | if (curr.precision !== prev.precision) {
|
33641 | BigNumber.config({
|
33642 | precision: curr.precision
|
33643 | });
|
33644 | }
|
33645 | });
|
33646 | return BigNumber;
|
33647 | }
|
33648 | var name = 'BigNumber';
|
33649 | var path = 'type';
|
33650 | var math = true; // request access to the math namespace
|
33651 |
|
33652 | /***/ }),
|
33653 | /* 172 */
|
33654 | /***/ (function(module, exports, __webpack_require__) {
|
33655 |
|
33656 | "use strict";
|
33657 |
|
33658 |
|
33659 | var deepMap = __webpack_require__(1);
|
33660 |
|
33661 | function factory(type, config, load, typed) {
|
33662 | /**
|
33663 | * Create a boolean or convert a string or number to a boolean.
|
33664 | * In case of a number, `true` is returned for non-zero numbers, and `false` in
|
33665 | * case of zero.
|
33666 | * Strings can be `'true'` or `'false'`, or can contain a number.
|
33667 | * When value is a matrix, all elements will be converted to boolean.
|
33668 | *
|
33669 | * Syntax:
|
33670 | *
|
33671 | * math.boolean(x)
|
33672 | *
|
33673 | * Examples:
|
33674 | *
|
33675 | * math.boolean(0) // returns false
|
33676 | * math.boolean(1) // returns true
|
33677 | * math.boolean(-3) // returns true
|
33678 | * math.boolean('true') // returns true
|
33679 | * math.boolean('false') // returns false
|
33680 | * math.boolean([1, 0, 1, 1]) // returns [true, false, true, true]
|
33681 | *
|
33682 | * See also:
|
33683 | *
|
33684 | * bignumber, complex, index, matrix, string, unit
|
33685 | *
|
33686 | * @param {string | number | boolean | Array | Matrix | null} value A value of any type
|
33687 | * @return {boolean | Array | Matrix} The boolean value
|
33688 | */
|
33689 | var bool = typed('bool', {
|
33690 | '': function _() {
|
33691 | return false;
|
33692 | },
|
33693 | 'boolean': function boolean(x) {
|
33694 | return x;
|
33695 | },
|
33696 | 'number': function number(x) {
|
33697 | return !!x;
|
33698 | },
|
33699 | 'null': function _null(x) {
|
33700 | return false;
|
33701 | },
|
33702 | 'BigNumber': function BigNumber(x) {
|
33703 | return !x.isZero();
|
33704 | },
|
33705 | 'string': function string(x) {
|
33706 | // try case insensitive
|
33707 | var lcase = x.toLowerCase();
|
33708 |
|
33709 | if (lcase === 'true') {
|
33710 | return true;
|
33711 | } else if (lcase === 'false') {
|
33712 | return false;
|
33713 | } // test whether value is a valid number
|
33714 |
|
33715 |
|
33716 | var num = Number(x);
|
33717 |
|
33718 | if (x !== '' && !isNaN(num)) {
|
33719 | return !!num;
|
33720 | }
|
33721 |
|
33722 | throw new Error('Cannot convert "' + x + '" to a boolean');
|
33723 | },
|
33724 | 'Array | Matrix': function ArrayMatrix(x) {
|
33725 | return deepMap(x, bool);
|
33726 | }
|
33727 | });
|
33728 | return bool;
|
33729 | }
|
33730 |
|
33731 | exports.name = 'boolean';
|
33732 | exports.factory = factory;
|
33733 |
|
33734 | /***/ }),
|
33735 | /* 173 */
|
33736 | /***/ (function(module, exports, __webpack_require__) {
|
33737 |
|
33738 | "use strict";
|
33739 |
|
33740 |
|
33741 | module.exports = [// type
|
33742 | __webpack_require__(174), // construction function
|
33743 | __webpack_require__(176)];
|
33744 |
|
33745 | /***/ }),
|
33746 | /* 174 */
|
33747 | /***/ (function(module, exports, __webpack_require__) {
|
33748 |
|
33749 | "use strict";
|
33750 |
|
33751 |
|
33752 | var format = __webpack_require__(9).format;
|
33753 |
|
33754 | var lazy = __webpack_require__(5).lazy;
|
33755 |
|
33756 | function factory(type, config, load, typed, math) {
|
33757 | /**
|
33758 | * @constructor Chain
|
33759 | * Wrap any value in a chain, allowing to perform chained operations on
|
33760 | * the value.
|
33761 | *
|
33762 | * All methods available in the math.js library can be called upon the chain,
|
33763 | * and then will be evaluated with the value itself as first argument.
|
33764 | * The chain can be closed by executing chain.done(), which will return
|
33765 | * the final value.
|
33766 | *
|
33767 | * The Chain has a number of special functions:
|
33768 | * - done() Finalize the chained operation and return the
|
33769 | * chain's value.
|
33770 | * - valueOf() The same as done()
|
33771 | * - toString() Returns a string representation of the chain's value.
|
33772 | *
|
33773 | * @param {*} [value]
|
33774 | */
|
33775 | function Chain(value) {
|
33776 | if (!(this instanceof Chain)) {
|
33777 | throw new SyntaxError('Constructor must be called with the new operator');
|
33778 | }
|
33779 |
|
33780 | if (type.isChain(value)) {
|
33781 | this.value = value.value;
|
33782 | } else {
|
33783 | this.value = value;
|
33784 | }
|
33785 | }
|
33786 | /**
|
33787 | * Attach type information
|
33788 | */
|
33789 |
|
33790 |
|
33791 | Chain.prototype.type = 'Chain';
|
33792 | Chain.prototype.isChain = true;
|
33793 | /**
|
33794 | * Close the chain. Returns the final value.
|
33795 | * Does the same as method valueOf()
|
33796 | * @returns {*} value
|
33797 | */
|
33798 |
|
33799 | Chain.prototype.done = function () {
|
33800 | return this.value;
|
33801 | };
|
33802 | /**
|
33803 | * Close the chain. Returns the final value.
|
33804 | * Does the same as method done()
|
33805 | * @returns {*} value
|
33806 | */
|
33807 |
|
33808 |
|
33809 | Chain.prototype.valueOf = function () {
|
33810 | return this.value;
|
33811 | };
|
33812 | /**
|
33813 | * Get a string representation of the value in the chain
|
33814 | * @returns {string}
|
33815 | */
|
33816 |
|
33817 |
|
33818 | Chain.prototype.toString = function () {
|
33819 | return format(this.value);
|
33820 | };
|
33821 | /**
|
33822 | * Get a JSON representation of the chain
|
33823 | * @returns {Object}
|
33824 | */
|
33825 |
|
33826 |
|
33827 | Chain.prototype.toJSON = function () {
|
33828 | return {
|
33829 | mathjs: 'Chain',
|
33830 | value: this.value
|
33831 | };
|
33832 | };
|
33833 | /**
|
33834 | * Instantiate a Chain from its JSON representation
|
33835 | * @param {Object} json An object structured like
|
33836 | * `{"mathjs": "Chain", value: ...}`,
|
33837 | * where mathjs is optional
|
33838 | * @returns {Chain}
|
33839 | */
|
33840 |
|
33841 |
|
33842 | Chain.fromJSON = function (json) {
|
33843 | return new Chain(json.value);
|
33844 | };
|
33845 | /**
|
33846 | * Create a proxy method for the chain
|
33847 | * @param {string} name
|
33848 | * @param {Function} fn The function to be proxied
|
33849 | * If fn is no function, it is silently ignored.
|
33850 | * @private
|
33851 | */
|
33852 |
|
33853 |
|
33854 | function createProxy(name, fn) {
|
33855 | if (typeof fn === 'function') {
|
33856 | Chain.prototype[name] = chainify(fn);
|
33857 | }
|
33858 | }
|
33859 | /**
|
33860 | * Create a proxy method for the chain
|
33861 | * @param {string} name
|
33862 | * @param {function} resolver The function resolving with the
|
33863 | * function to be proxied
|
33864 | * @private
|
33865 | */
|
33866 |
|
33867 |
|
33868 | function createLazyProxy(name, resolver) {
|
33869 | lazy(Chain.prototype, name, function outerResolver() {
|
33870 | var fn = resolver();
|
33871 |
|
33872 | if (typeof fn === 'function') {
|
33873 | return chainify(fn);
|
33874 | }
|
33875 |
|
33876 | return undefined; // if not a function, ignore
|
33877 | });
|
33878 | }
|
33879 | /**
|
33880 | * Make a function chainable
|
33881 | * @param {function} fn
|
33882 | * @return {Function} chain function
|
33883 | * @private
|
33884 | */
|
33885 |
|
33886 |
|
33887 | function chainify(fn) {
|
33888 | return function () {
|
33889 | var args = [this.value]; // `this` will be the context of a Chain instance
|
33890 |
|
33891 | for (var i = 0; i < arguments.length; i++) {
|
33892 | args[i + 1] = arguments[i];
|
33893 | }
|
33894 |
|
33895 | return new Chain(fn.apply(fn, args));
|
33896 | };
|
33897 | }
|
33898 | /**
|
33899 | * Create a proxy for a single method, or an object with multiple methods.
|
33900 | * Example usage:
|
33901 | *
|
33902 | * Chain.createProxy('add', function add (x, y) {...})
|
33903 | * Chain.createProxy({
|
33904 | * add: function add (x, y) {...},
|
33905 | * subtract: function subtract (x, y) {...}
|
33906 | * }
|
33907 | *
|
33908 | * @param {string | Object} arg0 A name (string), or an object with
|
33909 | * functions
|
33910 | * @param {*} [arg1] A function, when arg0 is a name
|
33911 | */
|
33912 |
|
33913 |
|
33914 | Chain.createProxy = function (arg0, arg1) {
|
33915 | if (typeof arg0 === 'string') {
|
33916 | // createProxy(name, value)
|
33917 | createProxy(arg0, arg1);
|
33918 | } else {
|
33919 | // createProxy(values)
|
33920 | for (var prop in arg0) {
|
33921 | if (arg0.hasOwnProperty(prop)) {
|
33922 | createProxy(prop, arg0[prop]);
|
33923 | }
|
33924 | }
|
33925 | }
|
33926 | }; // create proxy for everything that is in math.js
|
33927 |
|
33928 |
|
33929 | Chain.createProxy(math); // register on the import event, automatically add a proxy for every imported function.
|
33930 |
|
33931 | math.on('import', function (name, resolver, path) {
|
33932 | if (path === undefined) {
|
33933 | // an imported function (not a data type or something special)
|
33934 | createLazyProxy(name, resolver);
|
33935 | }
|
33936 | });
|
33937 | return Chain;
|
33938 | }
|
33939 |
|
33940 | exports.name = 'Chain';
|
33941 | exports.path = 'type';
|
33942 | exports.factory = factory;
|
33943 | exports.math = true; // require providing the math namespace as 5th argument
|
33944 |
|
33945 | exports.lazy = false; // we need to register a listener on the import events, so no lazy loading
|
33946 |
|
33947 | /***/ }),
|
33948 | /* 175 */
|
33949 | /***/ (function(module, exports, __webpack_require__) {
|
33950 |
|
33951 | "use strict";
|
33952 |
|
33953 |
|
33954 | var objectUtils = __webpack_require__(5);
|
33955 | /**
|
33956 | * Convert a BigNumber to a formatted string representation.
|
33957 | *
|
33958 | * Syntax:
|
33959 | *
|
33960 | * format(value)
|
33961 | * format(value, options)
|
33962 | * format(value, precision)
|
33963 | * format(value, fn)
|
33964 | *
|
33965 | * Where:
|
33966 | *
|
33967 | * {number} value The value to be formatted
|
33968 | * {Object} options An object with formatting options. Available options:
|
33969 | * {string} notation
|
33970 | * Number notation. Choose from:
|
33971 | * 'fixed' Always use regular number notation.
|
33972 | * For example '123.40' and '14000000'
|
33973 | * 'exponential' Always use exponential notation.
|
33974 | * For example '1.234e+2' and '1.4e+7'
|
33975 | * 'auto' (default) Regular number notation for numbers
|
33976 | * having an absolute value between
|
33977 | * `lower` and `upper` bounds, and uses
|
33978 | * exponential notation elsewhere.
|
33979 | * Lower bound is included, upper bound
|
33980 | * is excluded.
|
33981 | * For example '123.4' and '1.4e7'.
|
33982 | * {number} precision A number between 0 and 16 to round
|
33983 | * the digits of the number.
|
33984 | * In case of notations 'exponential',
|
33985 | * 'engineering', and 'auto',
|
33986 | * `precision` defines the total
|
33987 | * number of significant digits returned.
|
33988 | * In case of notation 'fixed',
|
33989 | * `precision` defines the number of
|
33990 | * significant digits after the decimal
|
33991 | * point.
|
33992 | * `precision` is undefined by default.
|
33993 | * {number} lowerExp Exponent determining the lower boundary
|
33994 | * for formatting a value with an exponent
|
33995 | * when `notation='auto`.
|
33996 | * Default value is `-3`.
|
33997 | * {number} upperExp Exponent determining the upper boundary
|
33998 | * for formatting a value with an exponent
|
33999 | * when `notation='auto`.
|
34000 | * Default value is `5`.
|
34001 | * {Function} fn A custom formatting function. Can be used to override the
|
34002 | * built-in notations. Function `fn` is called with `value` as
|
34003 | * parameter and must return a string. Is useful for example to
|
34004 | * format all values inside a matrix in a particular way.
|
34005 | *
|
34006 | * Examples:
|
34007 | *
|
34008 | * format(6.4) // '6.4'
|
34009 | * format(1240000) // '1.24e6'
|
34010 | * format(1/3) // '0.3333333333333333'
|
34011 | * format(1/3, 3) // '0.333'
|
34012 | * format(21385, 2) // '21000'
|
34013 | * format(12e8, {notation: 'fixed'}) // returns '1200000000'
|
34014 | * format(2.3, {notation: 'fixed', precision: 4}) // returns '2.3000'
|
34015 | * format(52.8, {notation: 'exponential'}) // returns '5.28e+1'
|
34016 | * format(12400, {notation: 'engineering'}) // returns '12.400e+3'
|
34017 | *
|
34018 | * @param {BigNumber} value
|
34019 | * @param {Object | Function | number} [options]
|
34020 | * @return {string} str The formatted value
|
34021 | */
|
34022 |
|
34023 |
|
34024 | exports.format = function (value, options) {
|
34025 | if (typeof options === 'function') {
|
34026 | // handle format(value, fn)
|
34027 | return options(value);
|
34028 | } // handle special cases
|
34029 |
|
34030 |
|
34031 | if (!value.isFinite()) {
|
34032 | return value.isNaN() ? 'NaN' : value.gt(0) ? 'Infinity' : '-Infinity';
|
34033 | } // default values for options
|
34034 |
|
34035 |
|
34036 | var notation = 'auto';
|
34037 | var precision;
|
34038 |
|
34039 | if (options !== undefined) {
|
34040 | // determine notation from options
|
34041 | if (options.notation) {
|
34042 | notation = options.notation;
|
34043 | } // determine precision from options
|
34044 |
|
34045 |
|
34046 | if (typeof options === 'number') {
|
34047 | precision = options;
|
34048 | } else if (options.precision) {
|
34049 | precision = options.precision;
|
34050 | }
|
34051 | } // handle the various notations
|
34052 |
|
34053 |
|
34054 | switch (notation) {
|
34055 | case 'fixed':
|
34056 | return exports.toFixed(value, precision);
|
34057 |
|
34058 | case 'exponential':
|
34059 | return exports.toExponential(value, precision);
|
34060 |
|
34061 | case 'engineering':
|
34062 | return exports.toEngineering(value, precision);
|
34063 |
|
34064 | case 'auto':
|
34065 | // TODO: clean up some day. Deprecated since: 2018-01-24
|
34066 | // @deprecated upper and lower are replaced with upperExp and lowerExp since v4.0.0
|
34067 | if (options && options.exponential && (options.exponential.lower !== undefined || options.exponential.upper !== undefined)) {
|
34068 | var fixedOptions = objectUtils.map(options, function (x) {
|
34069 | return x;
|
34070 | });
|
34071 | fixedOptions.exponential = undefined;
|
34072 |
|
34073 | if (options.exponential.lower !== undefined) {
|
34074 | fixedOptions.lowerExp = Math.round(Math.log(options.exponential.lower) / Math.LN10);
|
34075 | }
|
34076 |
|
34077 | if (options.exponential.upper !== undefined) {
|
34078 | fixedOptions.upperExp = Math.round(Math.log(options.exponential.upper) / Math.LN10);
|
34079 | }
|
34080 |
|
34081 | console.warn('Deprecation warning: Formatting options exponential.lower and exponential.upper ' + '(minimum and maximum value) ' + 'are replaced with exponential.lowerExp and exponential.upperExp ' + '(minimum and maximum exponent) since version 4.0.0. ' + 'Replace ' + JSON.stringify(options) + ' with ' + JSON.stringify(fixedOptions));
|
34082 | return exports.format(value, fixedOptions);
|
34083 | } // determine lower and upper bound for exponential notation.
|
34084 | // TODO: implement support for upper and lower to be BigNumbers themselves
|
34085 |
|
34086 |
|
34087 | var lowerExp = options && options.lowerExp !== undefined ? options.lowerExp : -3;
|
34088 | var upperExp = options && options.upperExp !== undefined ? options.upperExp : 5; // handle special case zero
|
34089 |
|
34090 | if (value.isZero()) return '0'; // determine whether or not to output exponential notation
|
34091 |
|
34092 | var str;
|
34093 | var exp = value.e;
|
34094 |
|
34095 | if (exp >= lowerExp && exp < upperExp) {
|
34096 | // normal number notation
|
34097 | str = value.toSignificantDigits(precision).toFixed();
|
34098 | } else {
|
34099 | // exponential notation
|
34100 | str = exports.toExponential(value, precision);
|
34101 | } // remove trailing zeros after the decimal point
|
34102 |
|
34103 |
|
34104 | return str.replace(/((\.\d*?)(0+))($|e)/, function () {
|
34105 | var digits = arguments[2];
|
34106 | var e = arguments[4];
|
34107 | return digits !== '.' ? digits + e : e;
|
34108 | });
|
34109 |
|
34110 | default:
|
34111 | throw new Error('Unknown notation "' + notation + '". ' + 'Choose "auto", "exponential", or "fixed".');
|
34112 | }
|
34113 | };
|
34114 | /**
|
34115 | * Format a BigNumber in engineering notation. Like '1.23e+6', '2.3e+0', '3.500e-3'
|
34116 | * @param {BigNumber | string} value
|
34117 | * @param {number} [precision] Optional number of significant figures to return.
|
34118 | */
|
34119 |
|
34120 |
|
34121 | exports.toEngineering = function (value, precision) {
|
34122 | // find nearest lower multiple of 3 for exponent
|
34123 | var e = value.e;
|
34124 | var newExp = e % 3 === 0 ? e : e < 0 ? e - 3 - e % 3 : e - e % 3; // find difference in exponents, and calculate the value without exponent
|
34125 |
|
34126 | var expDiff = Math.abs(e - newExp);
|
34127 | var valueWithoutExp = value.mul(Math.pow(10, expDiff - e));
|
34128 | return valueWithoutExp.toPrecision(precision).toString() + 'e' + (e >= 0 ? '+' : '') + newExp.toString();
|
34129 | };
|
34130 | /**
|
34131 | * Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3'
|
34132 | * @param {BigNumber} value
|
34133 | * @param {number} [precision] Number of digits in formatted output.
|
34134 | * If not provided, the maximum available digits
|
34135 | * is used.
|
34136 | * @returns {string} str
|
34137 | */
|
34138 |
|
34139 |
|
34140 | exports.toExponential = function (value, precision) {
|
34141 | if (precision !== undefined) {
|
34142 | return value.toExponential(precision - 1); // Note the offset of one
|
34143 | } else {
|
34144 | return value.toExponential();
|
34145 | }
|
34146 | };
|
34147 | /**
|
34148 | * Format a number with fixed notation.
|
34149 | * @param {BigNumber} value
|
34150 | * @param {number} [precision=undefined] Optional number of decimals after the
|
34151 | * decimal point. Undefined by default.
|
34152 | */
|
34153 |
|
34154 |
|
34155 | exports.toFixed = function (value, precision) {
|
34156 | return value.toFixed(precision);
|
34157 | };
|
34158 |
|
34159 | /***/ }),
|
34160 | /* 176 */
|
34161 | /***/ (function(module, exports, __webpack_require__) {
|
34162 |
|
34163 | "use strict";
|
34164 |
|
34165 |
|
34166 | function factory(type, config, load, typed) {
|
34167 | /**
|
34168 | * Wrap any value in a chain, allowing to perform chained operations on
|
34169 | * the value.
|
34170 | *
|
34171 | * All methods available in the math.js library can be called upon the chain,
|
34172 | * and then will be evaluated with the value itself as first argument.
|
34173 | * The chain can be closed by executing `chain.done()`, which returns
|
34174 | * the final value.
|
34175 | *
|
34176 | * The chain has a number of special functions:
|
34177 | *
|
34178 | * - `done()` Finalize the chain and return the chain's value.
|
34179 | * - `valueOf()` The same as `done()`
|
34180 | * - `toString()` Executes `math.format()` onto the chain's value, returning
|
34181 | * a string representation of the value.
|
34182 | *
|
34183 | * Syntax:
|
34184 | *
|
34185 | * math.chain(value)
|
34186 | *
|
34187 | * Examples:
|
34188 | *
|
34189 | * math.chain(3)
|
34190 | * .add(4)
|
34191 | * .subtract(2)
|
34192 | * .done() // 5
|
34193 | *
|
34194 | * math.chain( [[1, 2], [3, 4]] )
|
34195 | * .subset(math.index(0, 0), 8)
|
34196 | * .multiply(3)
|
34197 | * .done() // [[24, 6], [9, 12]]
|
34198 | *
|
34199 | * @param {*} [value] A value of any type on which to start a chained operation.
|
34200 | * @return {math.type.Chain} The created chain
|
34201 | */
|
34202 | return typed('chain', {
|
34203 | '': function _() {
|
34204 | return new type.Chain();
|
34205 | },
|
34206 | 'any': function any(value) {
|
34207 | return new type.Chain(value);
|
34208 | }
|
34209 | });
|
34210 | }
|
34211 |
|
34212 | exports.name = 'chain';
|
34213 | exports.factory = factory;
|
34214 |
|
34215 | /***/ }),
|
34216 | /* 177 */
|
34217 | /***/ (function(module, exports, __webpack_require__) {
|
34218 |
|
34219 | "use strict";
|
34220 |
|
34221 |
|
34222 | module.exports = [// type
|
34223 | __webpack_require__(82), // construction function
|
34224 | __webpack_require__(179)];
|
34225 |
|
34226 | /***/ }),
|
34227 | /* 178 */
|
34228 | /***/ (function(module, exports, __webpack_require__) {
|
34229 |
|
34230 | var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/**
|
34231 | * @license Complex.js v2.0.11 11/02/2016
|
34232 | *
|
34233 | * Copyright (c) 2016, Robert Eisele (robert@xarg.org)
|
34234 | * Dual licensed under the MIT or GPL Version 2 licenses.
|
34235 | **/
|
34236 |
|
34237 | /**
|
34238 | *
|
34239 | * This class allows the manipulation of complex numbers.
|
34240 | * You can pass a complex number in different formats. Either as object, double, string or two integer parameters.
|
34241 | *
|
34242 | * Object form
|
34243 | * { re: <real>, im: <imaginary> }
|
34244 | * { arg: <angle>, abs: <radius> }
|
34245 | * { phi: <angle>, r: <radius> }
|
34246 | *
|
34247 | * Array / Vector form
|
34248 | * [ real, imaginary ]
|
34249 | *
|
34250 | * Double form
|
34251 | * 99.3 - Single double value
|
34252 | *
|
34253 | * String form
|
34254 | * '23.1337' - Simple real number
|
34255 | * '15+3i' - a simple complex number
|
34256 | * '3-i' - a simple complex number
|
34257 | *
|
34258 | * Example:
|
34259 | *
|
34260 | * var c = new Complex('99.3+8i');
|
34261 | * c.mul({r: 3, i: 9}).div(4.9).sub(3, 2);
|
34262 | *
|
34263 | */
|
34264 |
|
34265 | (function(root) {
|
34266 |
|
34267 | 'use strict';
|
34268 |
|
34269 | var cosh = function(x) {
|
34270 | return (Math.exp(x) + Math.exp(-x)) * 0.5;
|
34271 | };
|
34272 |
|
34273 | var sinh = function(x) {
|
34274 | return (Math.exp(x) - Math.exp(-x)) * 0.5;
|
34275 | };
|
34276 |
|
34277 | /**
|
34278 | * Calculates cos(x) - 1 using Taylor series if x is small.
|
34279 | *
|
34280 | * @param {number} x
|
34281 | * @returns {number} cos(x) - 1
|
34282 | */
|
34283 |
|
34284 | var cosm1 = function(x) {
|
34285 | var limit = Math.PI/4;
|
34286 | if (x < -limit || x > limit) {
|
34287 | return (Math.cos(x) - 1.0);
|
34288 | }
|
34289 |
|
34290 | var xx = x * x;
|
34291 | return xx *
|
34292 | (-0.5 + xx *
|
34293 | (1/24 + xx *
|
34294 | (-1/720 + xx *
|
34295 | (1/40320 + xx *
|
34296 | (-1/3628800 + xx *
|
34297 | (1/4790014600 + xx *
|
34298 | (-1/87178291200 + xx *
|
34299 | (1/20922789888000)
|
34300 | )
|
34301 | )
|
34302 | )
|
34303 | )
|
34304 | )
|
34305 | )
|
34306 | )
|
34307 | };
|
34308 |
|
34309 | var hypot = function(x, y) {
|
34310 |
|
34311 | var a = Math.abs(x);
|
34312 | var b = Math.abs(y);
|
34313 |
|
34314 | if (a < 3000 && b < 3000) {
|
34315 | return Math.sqrt(a * a + b * b);
|
34316 | }
|
34317 |
|
34318 | if (a < b) {
|
34319 | a = b;
|
34320 | b = x / y;
|
34321 | } else {
|
34322 | b = y / x;
|
34323 | }
|
34324 | return a * Math.sqrt(1 + b * b);
|
34325 | };
|
34326 |
|
34327 | var parser_exit = function() {
|
34328 | throw SyntaxError('Invalid Param');
|
34329 | };
|
34330 |
|
34331 | /**
|
34332 | * Calculates log(sqrt(a^2+b^2)) in a way to avoid overflows
|
34333 | *
|
34334 | * @param {number} a
|
34335 | * @param {number} b
|
34336 | * @returns {number}
|
34337 | */
|
34338 | function logHypot(a, b) {
|
34339 |
|
34340 | var _a = Math.abs(a);
|
34341 | var _b = Math.abs(b);
|
34342 |
|
34343 | if (a === 0) {
|
34344 | return Math.log(_b);
|
34345 | }
|
34346 |
|
34347 | if (b === 0) {
|
34348 | return Math.log(_a);
|
34349 | }
|
34350 |
|
34351 | if (_a < 3000 && _b < 3000) {
|
34352 | return Math.log(a * a + b * b) * 0.5;
|
34353 | }
|
34354 |
|
34355 | /* I got 4 ideas to compute this property without overflow:
|
34356 | *
|
34357 | * Testing 1000000 times with random samples for a,b ∈ [1, 1000000000] against a big decimal library to get an error estimate
|
34358 | *
|
34359 | * 1. Only eliminate the square root: (OVERALL ERROR: 3.9122483030951116e-11)
|
34360 |
|
34361 | Math.log(a * a + b * b) / 2
|
34362 |
|
34363 | *
|
34364 | *
|
34365 | * 2. Try to use the non-overflowing pythagoras: (OVERALL ERROR: 8.889760039210159e-10)
|
34366 |
|
34367 | var fn = function(a, b) {
|
34368 | a = Math.abs(a);
|
34369 | b = Math.abs(b);
|
34370 | var t = Math.min(a, b);
|
34371 | a = Math.max(a, b);
|
34372 | t = t / a;
|
34373 |
|
34374 | return Math.log(a) + Math.log(1 + t * t) / 2;
|
34375 | };
|
34376 |
|
34377 | * 3. Abuse the identity cos(atan(y/x) = x / sqrt(x^2+y^2): (OVERALL ERROR: 3.4780178737037204e-10)
|
34378 |
|
34379 | Math.log(a / Math.cos(Math.atan2(b, a)))
|
34380 |
|
34381 | * 4. Use 3. and apply log rules: (OVERALL ERROR: 1.2014087502620896e-9)
|
34382 |
|
34383 | Math.log(a) - Math.log(Math.cos(Math.atan2(b, a)))
|
34384 |
|
34385 | */
|
34386 |
|
34387 | return Math.log(a / Math.cos(Math.atan2(b, a)));
|
34388 | }
|
34389 |
|
34390 | var parse = function(a, b) {
|
34391 |
|
34392 | var z = {'re': 0, 'im': 0};
|
34393 |
|
34394 | if (a === undefined || a === null) {
|
34395 | z['re'] =
|
34396 | z['im'] = 0;
|
34397 | } else if (b !== undefined) {
|
34398 | z['re'] = a;
|
34399 | z['im'] = b;
|
34400 | } else
|
34401 | switch (typeof a) {
|
34402 |
|
34403 | case 'object':
|
34404 |
|
34405 | if ('im' in a && 're' in a) {
|
34406 | z['re'] = a['re'];
|
34407 | z['im'] = a['im'];
|
34408 | } else if ('abs' in a && 'arg' in a) {
|
34409 | if (!Number.isFinite(a['abs']) && Number.isFinite(a['arg'])) {
|
34410 | return Complex['INFINITY'];
|
34411 | }
|
34412 | z['re'] = a['abs'] * Math.cos(a['arg']);
|
34413 | z['im'] = a['abs'] * Math.sin(a['arg']);
|
34414 | } else if ('r' in a && 'phi' in a) {
|
34415 | if (!Number.isFinite(a['r']) && Number.isFinite(a['phi'])) {
|
34416 | return Complex['INFINITY'];
|
34417 | }
|
34418 | z['re'] = a['r'] * Math.cos(a['phi']);
|
34419 | z['im'] = a['r'] * Math.sin(a['phi']);
|
34420 | } else if (a.length === 2) { // Quick array check
|
34421 | z['re'] = a[0];
|
34422 | z['im'] = a[1];
|
34423 | } else {
|
34424 | parser_exit();
|
34425 | }
|
34426 | break;
|
34427 |
|
34428 | case 'string':
|
34429 |
|
34430 | z['im'] = /* void */
|
34431 | z['re'] = 0;
|
34432 |
|
34433 | var tokens = a.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g);
|
34434 | var plus = 1;
|
34435 | var minus = 0;
|
34436 |
|
34437 | if (tokens === null) {
|
34438 | parser_exit();
|
34439 | }
|
34440 |
|
34441 | for (var i = 0; i < tokens.length; i++) {
|
34442 |
|
34443 | var c = tokens[i];
|
34444 |
|
34445 | if (c === ' ' || c === '\t' || c === '\n') {
|
34446 | /* void */
|
34447 | } else if (c === '+') {
|
34448 | plus++;
|
34449 | } else if (c === '-') {
|
34450 | minus++;
|
34451 | } else if (c === 'i' || c === 'I') {
|
34452 |
|
34453 | if (plus + minus === 0) {
|
34454 | parser_exit();
|
34455 | }
|
34456 |
|
34457 | if (tokens[i + 1] !== ' ' && !isNaN(tokens[i + 1])) {
|
34458 | z['im'] += parseFloat((minus % 2 ? '-' : '') + tokens[i + 1]);
|
34459 | i++;
|
34460 | } else {
|
34461 | z['im'] += parseFloat((minus % 2 ? '-' : '') + '1');
|
34462 | }
|
34463 | plus = minus = 0;
|
34464 |
|
34465 | } else {
|
34466 |
|
34467 | if (plus + minus === 0 || isNaN(c)) {
|
34468 | parser_exit();
|
34469 | }
|
34470 |
|
34471 | if (tokens[i + 1] === 'i' || tokens[i + 1] === 'I') {
|
34472 | z['im'] += parseFloat((minus % 2 ? '-' : '') + c);
|
34473 | i++;
|
34474 | } else {
|
34475 | z['re'] += parseFloat((minus % 2 ? '-' : '') + c);
|
34476 | }
|
34477 | plus = minus = 0;
|
34478 | }
|
34479 | }
|
34480 |
|
34481 | // Still something on the stack
|
34482 | if (plus + minus > 0) {
|
34483 | parser_exit();
|
34484 | }
|
34485 | break;
|
34486 |
|
34487 | case 'number':
|
34488 | z['im'] = 0;
|
34489 | z['re'] = a;
|
34490 | break;
|
34491 |
|
34492 | default:
|
34493 | parser_exit();
|
34494 | }
|
34495 |
|
34496 | if (isNaN(z['re']) || isNaN(z['im'])) {
|
34497 | // If a calculation is NaN, we treat it as NaN and don't throw
|
34498 | //parser_exit();
|
34499 | }
|
34500 |
|
34501 | return z;
|
34502 | };
|
34503 |
|
34504 | /**
|
34505 | * @constructor
|
34506 | * @returns {Complex}
|
34507 | */
|
34508 | function Complex(a, b) {
|
34509 |
|
34510 | if (!(this instanceof Complex)) {
|
34511 | return new Complex(a, b);
|
34512 | }
|
34513 |
|
34514 | var z = parse(a, b);
|
34515 |
|
34516 | this['re'] = z['re'];
|
34517 | this['im'] = z['im'];
|
34518 | }
|
34519 |
|
34520 | Complex.prototype = {
|
34521 |
|
34522 | 're': 0,
|
34523 | 'im': 0,
|
34524 |
|
34525 | /**
|
34526 | * Calculates the sign of a complex number, which is a normalized complex
|
34527 | *
|
34528 | * @returns {Complex}
|
34529 | */
|
34530 | 'sign': function() {
|
34531 |
|
34532 | var abs = this['abs']();
|
34533 |
|
34534 | return new Complex(
|
34535 | this['re'] / abs,
|
34536 | this['im'] / abs);
|
34537 | },
|
34538 |
|
34539 | /**
|
34540 | * Adds two complex numbers
|
34541 | *
|
34542 | * @returns {Complex}
|
34543 | */
|
34544 | 'add': function(a, b) {
|
34545 |
|
34546 | var z = new Complex(a, b);
|
34547 |
|
34548 | // Infinity + Infinity = NaN
|
34549 | if (this['isInfinite']() && z['isInfinite']()) {
|
34550 | return Complex['NAN'];
|
34551 | }
|
34552 |
|
34553 | // Infinity + z = Infinity { where z != Infinity }
|
34554 | if (this['isInfinite']() || z['isInfinite']()) {
|
34555 | return Complex['INFINITY'];
|
34556 | }
|
34557 |
|
34558 | return new Complex(
|
34559 | this['re'] + z['re'],
|
34560 | this['im'] + z['im']);
|
34561 | },
|
34562 |
|
34563 | /**
|
34564 | * Subtracts two complex numbers
|
34565 | *
|
34566 | * @returns {Complex}
|
34567 | */
|
34568 | 'sub': function(a, b) {
|
34569 |
|
34570 | var z = new Complex(a, b);
|
34571 |
|
34572 | // Infinity - Infinity = NaN
|
34573 | if (this['isInfinite']() && z['isInfinite']()) {
|
34574 | return Complex['NAN'];
|
34575 | }
|
34576 |
|
34577 | // Infinity - z = Infinity { where z != Infinity }
|
34578 | if (this['isInfinite']() || z['isInfinite']()) {
|
34579 | return Complex['INFINITY'];
|
34580 | }
|
34581 |
|
34582 | return new Complex(
|
34583 | this['re'] - z['re'],
|
34584 | this['im'] - z['im']);
|
34585 | },
|
34586 |
|
34587 | /**
|
34588 | * Multiplies two complex numbers
|
34589 | *
|
34590 | * @returns {Complex}
|
34591 | */
|
34592 | 'mul': function(a, b) {
|
34593 |
|
34594 | var z = new Complex(a, b);
|
34595 |
|
34596 | // Infinity * 0 = NaN
|
34597 | if ((this['isInfinite']() && z['isZero']()) || (this['isZero']() && z['isInfinite']())) {
|
34598 | return Complex['NAN'];
|
34599 | }
|
34600 |
|
34601 | // Infinity * z = Infinity { where z != 0 }
|
34602 | if (this['isInfinite']() || z['isInfinite']()) {
|
34603 | return Complex['INFINITY'];
|
34604 | }
|
34605 |
|
34606 | // Short circuit for real values
|
34607 | if (z['im'] === 0 && this['im'] === 0) {
|
34608 | return new Complex(this['re'] * z['re'], 0);
|
34609 | }
|
34610 |
|
34611 | return new Complex(
|
34612 | this['re'] * z['re'] - this['im'] * z['im'],
|
34613 | this['re'] * z['im'] + this['im'] * z['re']);
|
34614 | },
|
34615 |
|
34616 | /**
|
34617 | * Divides two complex numbers
|
34618 | *
|
34619 | * @returns {Complex}
|
34620 | */
|
34621 | 'div': function(a, b) {
|
34622 |
|
34623 | var z = new Complex(a, b);
|
34624 |
|
34625 | // 0 / 0 = NaN and Infinity / Infinity = NaN
|
34626 | if ((this['isZero']() && z['isZero']()) || (this['isInfinite']() && z['isInfinite']())) {
|
34627 | return Complex['NAN'];
|
34628 | }
|
34629 |
|
34630 | // Infinity / 0 = Infinity
|
34631 | if (this['isInfinite']() || z['isZero']()) {
|
34632 | return Complex['INFINITY'];
|
34633 | }
|
34634 |
|
34635 | // 0 / Infinity = 0
|
34636 | if (this['isZero']() || z['isInfinite']()) {
|
34637 | return Complex['ZERO'];
|
34638 | }
|
34639 |
|
34640 | a = this['re'];
|
34641 | b = this['im'];
|
34642 |
|
34643 | var c = z['re'];
|
34644 | var d = z['im'];
|
34645 | var t, x;
|
34646 |
|
34647 | if (0 === d) {
|
34648 | // Divisor is real
|
34649 | return new Complex(a / c, b / c);
|
34650 | }
|
34651 |
|
34652 | if (Math.abs(c) < Math.abs(d)) {
|
34653 |
|
34654 | x = c / d;
|
34655 | t = c * x + d;
|
34656 |
|
34657 | return new Complex(
|
34658 | (a * x + b) / t,
|
34659 | (b * x - a) / t);
|
34660 |
|
34661 | } else {
|
34662 |
|
34663 | x = d / c;
|
34664 | t = d * x + c;
|
34665 |
|
34666 | return new Complex(
|
34667 | (a + b * x) / t,
|
34668 | (b - a * x) / t);
|
34669 | }
|
34670 | },
|
34671 |
|
34672 | /**
|
34673 | * Calculate the power of two complex numbers
|
34674 | *
|
34675 | * @returns {Complex}
|
34676 | */
|
34677 | 'pow': function(a, b) {
|
34678 |
|
34679 | var z = new Complex(a, b);
|
34680 |
|
34681 | a = this['re'];
|
34682 | b = this['im'];
|
34683 |
|
34684 | if (z['isZero']()) {
|
34685 | return Complex['ONE'];
|
34686 | }
|
34687 |
|
34688 | // If the exponent is real
|
34689 | if (z['im'] === 0) {
|
34690 |
|
34691 | if (b === 0 && a >= 0) {
|
34692 |
|
34693 | return new Complex(Math.pow(a, z['re']), 0);
|
34694 |
|
34695 | } else if (a === 0) { // If base is fully imaginary
|
34696 |
|
34697 | switch ((z['re'] % 4 + 4) % 4) {
|
34698 | case 0:
|
34699 | return new Complex(Math.pow(b, z['re']), 0);
|
34700 | case 1:
|
34701 | return new Complex(0, Math.pow(b, z['re']));
|
34702 | case 2:
|
34703 | return new Complex(-Math.pow(b, z['re']), 0);
|
34704 | case 3:
|
34705 | return new Complex(0, -Math.pow(b, z['re']));
|
34706 | }
|
34707 | }
|
34708 | }
|
34709 |
|
34710 | /* I couldn't find a good formula, so here is a derivation and optimization
|
34711 | *
|
34712 | * z_1^z_2 = (a + bi)^(c + di)
|
34713 | * = exp((c + di) * log(a + bi)
|
34714 | * = pow(a^2 + b^2, (c + di) / 2) * exp(i(c + di)atan2(b, a))
|
34715 | * =>...
|
34716 | * Re = (pow(a^2 + b^2, c / 2) * exp(-d * atan2(b, a))) * cos(d * log(a^2 + b^2) / 2 + c * atan2(b, a))
|
34717 | * Im = (pow(a^2 + b^2, c / 2) * exp(-d * atan2(b, a))) * sin(d * log(a^2 + b^2) / 2 + c * atan2(b, a))
|
34718 | *
|
34719 | * =>...
|
34720 | * Re = exp(c * log(sqrt(a^2 + b^2)) - d * atan2(b, a)) * cos(d * log(sqrt(a^2 + b^2)) + c * atan2(b, a))
|
34721 | * Im = exp(c * log(sqrt(a^2 + b^2)) - d * atan2(b, a)) * sin(d * log(sqrt(a^2 + b^2)) + c * atan2(b, a))
|
34722 | *
|
34723 | * =>
|
34724 | * Re = exp(c * logsq2 - d * arg(z_1)) * cos(d * logsq2 + c * arg(z_1))
|
34725 | * Im = exp(c * logsq2 - d * arg(z_1)) * sin(d * logsq2 + c * arg(z_1))
|
34726 | *
|
34727 | */
|
34728 |
|
34729 | if (a === 0 && b === 0 && z['re'] > 0 && z['im'] >= 0) {
|
34730 | return Complex['ZERO'];
|
34731 | }
|
34732 |
|
34733 | var arg = Math.atan2(b, a);
|
34734 | var loh = logHypot(a, b);
|
34735 |
|
34736 | a = Math.exp(z['re'] * loh - z['im'] * arg);
|
34737 | b = z['im'] * loh + z['re'] * arg;
|
34738 | return new Complex(
|
34739 | a * Math.cos(b),
|
34740 | a * Math.sin(b));
|
34741 | },
|
34742 |
|
34743 | /**
|
34744 | * Calculate the complex square root
|
34745 | *
|
34746 | * @returns {Complex}
|
34747 | */
|
34748 | 'sqrt': function() {
|
34749 |
|
34750 | var a = this['re'];
|
34751 | var b = this['im'];
|
34752 | var r = this['abs']();
|
34753 |
|
34754 | var re, im;
|
34755 |
|
34756 | if (a >= 0) {
|
34757 |
|
34758 | if (b === 0) {
|
34759 | return new Complex(Math.sqrt(a), 0);
|
34760 | }
|
34761 |
|
34762 | re = 0.5 * Math.sqrt(2.0 * (r + a));
|
34763 | } else {
|
34764 | re = Math.abs(b) / Math.sqrt(2 * (r - a));
|
34765 | }
|
34766 |
|
34767 | if (a <= 0) {
|
34768 | im = 0.5 * Math.sqrt(2.0 * (r - a));
|
34769 | } else {
|
34770 | im = Math.abs(b) / Math.sqrt(2 * (r + a));
|
34771 | }
|
34772 |
|
34773 | return new Complex(re, b < 0 ? -im : im);
|
34774 | },
|
34775 |
|
34776 | /**
|
34777 | * Calculate the complex exponent
|
34778 | *
|
34779 | * @returns {Complex}
|
34780 | */
|
34781 | 'exp': function() {
|
34782 |
|
34783 | var tmp = Math.exp(this['re']);
|
34784 |
|
34785 | if (this['im'] === 0) {
|
34786 | //return new Complex(tmp, 0);
|
34787 | }
|
34788 | return new Complex(
|
34789 | tmp * Math.cos(this['im']),
|
34790 | tmp * Math.sin(this['im']));
|
34791 | },
|
34792 |
|
34793 | /**
|
34794 | * Calculate the complex exponent and subtracts one.
|
34795 | *
|
34796 | * This may be more accurate than `Complex(x).exp().sub(1)` if
|
34797 | * `x` is small.
|
34798 | *
|
34799 | * @returns {Complex}
|
34800 | */
|
34801 | 'expm1': function() {
|
34802 |
|
34803 | /**
|
34804 | * exp(a + i*b) - 1
|
34805 | = exp(a) * (cos(b) + j*sin(b)) - 1
|
34806 | = expm1(a)*cos(b) + cosm1(b) + j*exp(a)*sin(b)
|
34807 | */
|
34808 |
|
34809 | var a = this['re'];
|
34810 | var b = this['im'];
|
34811 |
|
34812 | return new Complex(
|
34813 | Math.expm1(a) * Math.cos(b) + cosm1(b),
|
34814 | Math.exp(a) * Math.sin(b));
|
34815 | },
|
34816 |
|
34817 | /**
|
34818 | * Calculate the natural log
|
34819 | *
|
34820 | * @returns {Complex}
|
34821 | */
|
34822 | 'log': function() {
|
34823 |
|
34824 | var a = this['re'];
|
34825 | var b = this['im'];
|
34826 |
|
34827 | if (b === 0 && a > 0) {
|
34828 | //return new Complex(Math.log(a), 0);
|
34829 | }
|
34830 |
|
34831 | return new Complex(
|
34832 | logHypot(a, b),
|
34833 | Math.atan2(b, a));
|
34834 | },
|
34835 |
|
34836 | /**
|
34837 | * Calculate the magnitude of the complex number
|
34838 | *
|
34839 | * @returns {number}
|
34840 | */
|
34841 | 'abs': function() {
|
34842 |
|
34843 | return hypot(this['re'], this['im']);
|
34844 | },
|
34845 |
|
34846 | /**
|
34847 | * Calculate the angle of the complex number
|
34848 | *
|
34849 | * @returns {number}
|
34850 | */
|
34851 | 'arg': function() {
|
34852 |
|
34853 | return Math.atan2(this['im'], this['re']);
|
34854 | },
|
34855 |
|
34856 | /**
|
34857 | * Calculate the sine of the complex number
|
34858 | *
|
34859 | * @returns {Complex}
|
34860 | */
|
34861 | 'sin': function() {
|
34862 |
|
34863 | // sin(c) = (e^b - e^(-b)) / (2i)
|
34864 |
|
34865 | var a = this['re'];
|
34866 | var b = this['im'];
|
34867 |
|
34868 | return new Complex(
|
34869 | Math.sin(a) * cosh(b),
|
34870 | Math.cos(a) * sinh(b));
|
34871 | },
|
34872 |
|
34873 | /**
|
34874 | * Calculate the cosine
|
34875 | *
|
34876 | * @returns {Complex}
|
34877 | */
|
34878 | 'cos': function() {
|
34879 |
|
34880 | // cos(z) = (e^b + e^(-b)) / 2
|
34881 |
|
34882 | var a = this['re'];
|
34883 | var b = this['im'];
|
34884 |
|
34885 | return new Complex(
|
34886 | Math.cos(a) * cosh(b),
|
34887 | -Math.sin(a) * sinh(b));
|
34888 | },
|
34889 |
|
34890 | /**
|
34891 | * Calculate the tangent
|
34892 | *
|
34893 | * @returns {Complex}
|
34894 | */
|
34895 | 'tan': function() {
|
34896 |
|
34897 | // tan(c) = (e^(ci) - e^(-ci)) / (i(e^(ci) + e^(-ci)))
|
34898 |
|
34899 | var a = 2 * this['re'];
|
34900 | var b = 2 * this['im'];
|
34901 | var d = Math.cos(a) + cosh(b);
|
34902 |
|
34903 | return new Complex(
|
34904 | Math.sin(a) / d,
|
34905 | sinh(b) / d);
|
34906 | },
|
34907 |
|
34908 | /**
|
34909 | * Calculate the cotangent
|
34910 | *
|
34911 | * @returns {Complex}
|
34912 | */
|
34913 | 'cot': function() {
|
34914 |
|
34915 | // cot(c) = i(e^(ci) + e^(-ci)) / (e^(ci) - e^(-ci))
|
34916 |
|
34917 | var a = 2 * this['re'];
|
34918 | var b = 2 * this['im'];
|
34919 | var d = Math.cos(a) - cosh(b);
|
34920 |
|
34921 | return new Complex(
|
34922 | -Math.sin(a) / d,
|
34923 | sinh(b) / d);
|
34924 | },
|
34925 |
|
34926 | /**
|
34927 | * Calculate the secant
|
34928 | *
|
34929 | * @returns {Complex}
|
34930 | */
|
34931 | 'sec': function() {
|
34932 |
|
34933 | // sec(c) = 2 / (e^(ci) + e^(-ci))
|
34934 |
|
34935 | var a = this['re'];
|
34936 | var b = this['im'];
|
34937 | var d = 0.5 * cosh(2 * b) + 0.5 * Math.cos(2 * a);
|
34938 |
|
34939 | return new Complex(
|
34940 | Math.cos(a) * cosh(b) / d,
|
34941 | Math.sin(a) * sinh(b) / d);
|
34942 | },
|
34943 |
|
34944 | /**
|
34945 | * Calculate the cosecans
|
34946 | *
|
34947 | * @returns {Complex}
|
34948 | */
|
34949 | 'csc': function() {
|
34950 |
|
34951 | // csc(c) = 2i / (e^(ci) - e^(-ci))
|
34952 |
|
34953 | var a = this['re'];
|
34954 | var b = this['im'];
|
34955 | var d = 0.5 * cosh(2 * b) - 0.5 * Math.cos(2 * a);
|
34956 |
|
34957 | return new Complex(
|
34958 | Math.sin(a) * cosh(b) / d,
|
34959 | -Math.cos(a) * sinh(b) / d);
|
34960 | },
|
34961 |
|
34962 | /**
|
34963 | * Calculate the complex arcus sinus
|
34964 | *
|
34965 | * @returns {Complex}
|
34966 | */
|
34967 | 'asin': function() {
|
34968 |
|
34969 | // asin(c) = -i * log(ci + sqrt(1 - c^2))
|
34970 |
|
34971 | var a = this['re'];
|
34972 | var b = this['im'];
|
34973 |
|
34974 | var t1 = new Complex(
|
34975 | b * b - a * a + 1,
|
34976 | -2 * a * b)['sqrt']();
|
34977 |
|
34978 | var t2 = new Complex(
|
34979 | t1['re'] - b,
|
34980 | t1['im'] + a)['log']();
|
34981 |
|
34982 | return new Complex(t2['im'], -t2['re']);
|
34983 | },
|
34984 |
|
34985 | /**
|
34986 | * Calculate the complex arcus cosinus
|
34987 | *
|
34988 | * @returns {Complex}
|
34989 | */
|
34990 | 'acos': function() {
|
34991 |
|
34992 | // acos(c) = i * log(c - i * sqrt(1 - c^2))
|
34993 |
|
34994 | var a = this['re'];
|
34995 | var b = this['im'];
|
34996 |
|
34997 | var t1 = new Complex(
|
34998 | b * b - a * a + 1,
|
34999 | -2 * a * b)['sqrt']();
|
35000 |
|
35001 | var t2 = new Complex(
|
35002 | t1['re'] - b,
|
35003 | t1['im'] + a)['log']();
|
35004 |
|
35005 | return new Complex(Math.PI / 2 - t2['im'], t2['re']);
|
35006 | },
|
35007 |
|
35008 | /**
|
35009 | * Calculate the complex arcus tangent
|
35010 | *
|
35011 | * @returns {Complex}
|
35012 | */
|
35013 | 'atan': function() {
|
35014 |
|
35015 | // atan(c) = i / 2 log((i + x) / (i - x))
|
35016 |
|
35017 | var a = this['re'];
|
35018 | var b = this['im'];
|
35019 |
|
35020 | if (a === 0) {
|
35021 |
|
35022 | if (b === 1) {
|
35023 | return new Complex(0, Infinity);
|
35024 | }
|
35025 |
|
35026 | if (b === -1) {
|
35027 | return new Complex(0, -Infinity);
|
35028 | }
|
35029 | }
|
35030 |
|
35031 | var d = a * a + (1.0 - b) * (1.0 - b);
|
35032 |
|
35033 | var t1 = new Complex(
|
35034 | (1 - b * b - a * a) / d,
|
35035 | -2 * a / d).log();
|
35036 |
|
35037 | return new Complex(-0.5 * t1['im'], 0.5 * t1['re']);
|
35038 | },
|
35039 |
|
35040 | /**
|
35041 | * Calculate the complex arcus cotangent
|
35042 | *
|
35043 | * @returns {Complex}
|
35044 | */
|
35045 | 'acot': function() {
|
35046 |
|
35047 | // acot(c) = i / 2 log((c - i) / (c + i))
|
35048 |
|
35049 | var a = this['re'];
|
35050 | var b = this['im'];
|
35051 |
|
35052 | if (b === 0) {
|
35053 | return new Complex(Math.atan2(1, a), 0);
|
35054 | }
|
35055 |
|
35056 | var d = a * a + b * b;
|
35057 | return (d !== 0)
|
35058 | ? new Complex(
|
35059 | a / d,
|
35060 | -b / d).atan()
|
35061 | : new Complex(
|
35062 | (a !== 0) ? a / 0 : 0,
|
35063 | (b !== 0) ? -b / 0 : 0).atan();
|
35064 | },
|
35065 |
|
35066 | /**
|
35067 | * Calculate the complex arcus secant
|
35068 | *
|
35069 | * @returns {Complex}
|
35070 | */
|
35071 | 'asec': function() {
|
35072 |
|
35073 | // asec(c) = -i * log(1 / c + sqrt(1 - i / c^2))
|
35074 |
|
35075 | var a = this['re'];
|
35076 | var b = this['im'];
|
35077 |
|
35078 | if (a === 0 && b === 0) {
|
35079 | return new Complex(0, Infinity);
|
35080 | }
|
35081 |
|
35082 | var d = a * a + b * b;
|
35083 | return (d !== 0)
|
35084 | ? new Complex(
|
35085 | a / d,
|
35086 | -b / d).acos()
|
35087 | : new Complex(
|
35088 | (a !== 0) ? a / 0 : 0,
|
35089 | (b !== 0) ? -b / 0 : 0).acos();
|
35090 | },
|
35091 |
|
35092 | /**
|
35093 | * Calculate the complex arcus cosecans
|
35094 | *
|
35095 | * @returns {Complex}
|
35096 | */
|
35097 | 'acsc': function() {
|
35098 |
|
35099 | // acsc(c) = -i * log(i / c + sqrt(1 - 1 / c^2))
|
35100 |
|
35101 | var a = this['re'];
|
35102 | var b = this['im'];
|
35103 |
|
35104 | if (a === 0 && b === 0) {
|
35105 | return new Complex(Math.PI / 2, Infinity);
|
35106 | }
|
35107 |
|
35108 | var d = a * a + b * b;
|
35109 | return (d !== 0)
|
35110 | ? new Complex(
|
35111 | a / d,
|
35112 | -b / d).asin()
|
35113 | : new Complex(
|
35114 | (a !== 0) ? a / 0 : 0,
|
35115 | (b !== 0) ? -b / 0 : 0).asin();
|
35116 | },
|
35117 |
|
35118 | /**
|
35119 | * Calculate the complex sinh
|
35120 | *
|
35121 | * @returns {Complex}
|
35122 | */
|
35123 | 'sinh': function() {
|
35124 |
|
35125 | // sinh(c) = (e^c - e^-c) / 2
|
35126 |
|
35127 | var a = this['re'];
|
35128 | var b = this['im'];
|
35129 |
|
35130 | return new Complex(
|
35131 | sinh(a) * Math.cos(b),
|
35132 | cosh(a) * Math.sin(b));
|
35133 | },
|
35134 |
|
35135 | /**
|
35136 | * Calculate the complex cosh
|
35137 | *
|
35138 | * @returns {Complex}
|
35139 | */
|
35140 | 'cosh': function() {
|
35141 |
|
35142 | // cosh(c) = (e^c + e^-c) / 2
|
35143 |
|
35144 | var a = this['re'];
|
35145 | var b = this['im'];
|
35146 |
|
35147 | return new Complex(
|
35148 | cosh(a) * Math.cos(b),
|
35149 | sinh(a) * Math.sin(b));
|
35150 | },
|
35151 |
|
35152 | /**
|
35153 | * Calculate the complex tanh
|
35154 | *
|
35155 | * @returns {Complex}
|
35156 | */
|
35157 | 'tanh': function() {
|
35158 |
|
35159 | // tanh(c) = (e^c - e^-c) / (e^c + e^-c)
|
35160 |
|
35161 | var a = 2 * this['re'];
|
35162 | var b = 2 * this['im'];
|
35163 | var d = cosh(a) + Math.cos(b);
|
35164 |
|
35165 | return new Complex(
|
35166 | sinh(a) / d,
|
35167 | Math.sin(b) / d);
|
35168 | },
|
35169 |
|
35170 | /**
|
35171 | * Calculate the complex coth
|
35172 | *
|
35173 | * @returns {Complex}
|
35174 | */
|
35175 | 'coth': function() {
|
35176 |
|
35177 | // coth(c) = (e^c + e^-c) / (e^c - e^-c)
|
35178 |
|
35179 | var a = 2 * this['re'];
|
35180 | var b = 2 * this['im'];
|
35181 | var d = cosh(a) - Math.cos(b);
|
35182 |
|
35183 | return new Complex(
|
35184 | sinh(a) / d,
|
35185 | -Math.sin(b) / d);
|
35186 | },
|
35187 |
|
35188 | /**
|
35189 | * Calculate the complex coth
|
35190 | *
|
35191 | * @returns {Complex}
|
35192 | */
|
35193 | 'csch': function() {
|
35194 |
|
35195 | // csch(c) = 2 / (e^c - e^-c)
|
35196 |
|
35197 | var a = this['re'];
|
35198 | var b = this['im'];
|
35199 | var d = Math.cos(2 * b) - cosh(2 * a);
|
35200 |
|
35201 | return new Complex(
|
35202 | -2 * sinh(a) * Math.cos(b) / d,
|
35203 | 2 * cosh(a) * Math.sin(b) / d);
|
35204 | },
|
35205 |
|
35206 | /**
|
35207 | * Calculate the complex sech
|
35208 | *
|
35209 | * @returns {Complex}
|
35210 | */
|
35211 | 'sech': function() {
|
35212 |
|
35213 | // sech(c) = 2 / (e^c + e^-c)
|
35214 |
|
35215 | var a = this['re'];
|
35216 | var b = this['im'];
|
35217 | var d = Math.cos(2 * b) + cosh(2 * a);
|
35218 |
|
35219 | return new Complex(
|
35220 | 2 * cosh(a) * Math.cos(b) / d,
|
35221 | -2 * sinh(a) * Math.sin(b) / d);
|
35222 | },
|
35223 |
|
35224 | /**
|
35225 | * Calculate the complex asinh
|
35226 | *
|
35227 | * @returns {Complex}
|
35228 | */
|
35229 | 'asinh': function() {
|
35230 |
|
35231 | // asinh(c) = log(c + sqrt(c^2 + 1))
|
35232 |
|
35233 | var tmp = this['im'];
|
35234 | this['im'] = -this['re'];
|
35235 | this['re'] = tmp;
|
35236 | var res = this['asin']();
|
35237 |
|
35238 | this['re'] = -this['im'];
|
35239 | this['im'] = tmp;
|
35240 | tmp = res['re'];
|
35241 |
|
35242 | res['re'] = -res['im'];
|
35243 | res['im'] = tmp;
|
35244 | return res;
|
35245 | },
|
35246 |
|
35247 | /**
|
35248 | * Calculate the complex asinh
|
35249 | *
|
35250 | * @returns {Complex}
|
35251 | */
|
35252 | 'acosh': function() {
|
35253 |
|
35254 | // acosh(c) = log(c + sqrt(c^2 - 1))
|
35255 |
|
35256 | var res = this['acos']();
|
35257 | if (res['im'] <= 0) {
|
35258 | var tmp = res['re'];
|
35259 | res['re'] = -res['im'];
|
35260 | res['im'] = tmp;
|
35261 | } else {
|
35262 | var tmp = res['im'];
|
35263 | res['im'] = -res['re'];
|
35264 | res['re'] = tmp;
|
35265 | }
|
35266 | return res;
|
35267 | },
|
35268 |
|
35269 | /**
|
35270 | * Calculate the complex atanh
|
35271 | *
|
35272 | * @returns {Complex}
|
35273 | */
|
35274 | 'atanh': function() {
|
35275 |
|
35276 | // atanh(c) = log((1+c) / (1-c)) / 2
|
35277 |
|
35278 | var a = this['re'];
|
35279 | var b = this['im'];
|
35280 |
|
35281 | var noIM = a > 1 && b === 0;
|
35282 | var oneMinus = 1 - a;
|
35283 | var onePlus = 1 + a;
|
35284 | var d = oneMinus * oneMinus + b * b;
|
35285 |
|
35286 | var x = (d !== 0)
|
35287 | ? new Complex(
|
35288 | (onePlus * oneMinus - b * b) / d,
|
35289 | (b * oneMinus + onePlus * b) / d)
|
35290 | : new Complex(
|
35291 | (a !== -1) ? (a / 0) : 0,
|
35292 | (b !== 0) ? (b / 0) : 0);
|
35293 |
|
35294 | var temp = x['re'];
|
35295 | x['re'] = logHypot(x['re'], x['im']) / 2;
|
35296 | x['im'] = Math.atan2(x['im'], temp) / 2;
|
35297 | if (noIM) {
|
35298 | x['im'] = -x['im'];
|
35299 | }
|
35300 | return x;
|
35301 | },
|
35302 |
|
35303 | /**
|
35304 | * Calculate the complex acoth
|
35305 | *
|
35306 | * @returns {Complex}
|
35307 | */
|
35308 | 'acoth': function() {
|
35309 |
|
35310 | // acoth(c) = log((c+1) / (c-1)) / 2
|
35311 |
|
35312 | var a = this['re'];
|
35313 | var b = this['im'];
|
35314 |
|
35315 | if (a === 0 && b === 0) {
|
35316 | return new Complex(0, Math.PI / 2);
|
35317 | }
|
35318 |
|
35319 | var d = a * a + b * b;
|
35320 | return (d !== 0)
|
35321 | ? new Complex(
|
35322 | a / d,
|
35323 | -b / d).atanh()
|
35324 | : new Complex(
|
35325 | (a !== 0) ? a / 0 : 0,
|
35326 | (b !== 0) ? -b / 0 : 0).atanh();
|
35327 | },
|
35328 |
|
35329 | /**
|
35330 | * Calculate the complex acsch
|
35331 | *
|
35332 | * @returns {Complex}
|
35333 | */
|
35334 | 'acsch': function() {
|
35335 |
|
35336 | // acsch(c) = log((1+sqrt(1+c^2))/c)
|
35337 |
|
35338 | var a = this['re'];
|
35339 | var b = this['im'];
|
35340 |
|
35341 | if (b === 0) {
|
35342 |
|
35343 | return new Complex(
|
35344 | (a !== 0)
|
35345 | ? Math.log(a + Math.sqrt(a * a + 1))
|
35346 | : Infinity, 0);
|
35347 | }
|
35348 |
|
35349 | var d = a * a + b * b;
|
35350 | return (d !== 0)
|
35351 | ? new Complex(
|
35352 | a / d,
|
35353 | -b / d).asinh()
|
35354 | : new Complex(
|
35355 | (a !== 0) ? a / 0 : 0,
|
35356 | (b !== 0) ? -b / 0 : 0).asinh();
|
35357 | },
|
35358 |
|
35359 | /**
|
35360 | * Calculate the complex asech
|
35361 | *
|
35362 | * @returns {Complex}
|
35363 | */
|
35364 | 'asech': function() {
|
35365 |
|
35366 | // asech(c) = log((1+sqrt(1-c^2))/c)
|
35367 |
|
35368 | var a = this['re'];
|
35369 | var b = this['im'];
|
35370 |
|
35371 | if (this['isZero']()) {
|
35372 | return Complex['INFINITY'];
|
35373 | }
|
35374 |
|
35375 | var d = a * a + b * b;
|
35376 | return (d !== 0)
|
35377 | ? new Complex(
|
35378 | a / d,
|
35379 | -b / d).acosh()
|
35380 | : new Complex(
|
35381 | (a !== 0) ? a / 0 : 0,
|
35382 | (b !== 0) ? -b / 0 : 0).acosh();
|
35383 | },
|
35384 |
|
35385 | /**
|
35386 | * Calculate the complex inverse 1/z
|
35387 | *
|
35388 | * @returns {Complex}
|
35389 | */
|
35390 | 'inverse': function() {
|
35391 |
|
35392 | // 1 / 0 = Infinity and 1 / Infinity = 0
|
35393 | if (this['isZero']()) {
|
35394 | return Complex['INFINITY'];
|
35395 | }
|
35396 |
|
35397 | if (this['isInfinite']()) {
|
35398 | return Complex['ZERO'];
|
35399 | }
|
35400 |
|
35401 | var a = this['re'];
|
35402 | var b = this['im'];
|
35403 |
|
35404 | var d = a * a + b * b;
|
35405 |
|
35406 | return new Complex(a / d, -b / d);
|
35407 | },
|
35408 |
|
35409 | /**
|
35410 | * Returns the complex conjugate
|
35411 | *
|
35412 | * @returns {Complex}
|
35413 | */
|
35414 | 'conjugate': function() {
|
35415 |
|
35416 | return new Complex(this['re'], -this['im']);
|
35417 | },
|
35418 |
|
35419 | /**
|
35420 | * Gets the negated complex number
|
35421 | *
|
35422 | * @returns {Complex}
|
35423 | */
|
35424 | 'neg': function() {
|
35425 |
|
35426 | return new Complex(-this['re'], -this['im']);
|
35427 | },
|
35428 |
|
35429 | /**
|
35430 | * Ceils the actual complex number
|
35431 | *
|
35432 | * @returns {Complex}
|
35433 | */
|
35434 | 'ceil': function(places) {
|
35435 |
|
35436 | places = Math.pow(10, places || 0);
|
35437 |
|
35438 | return new Complex(
|
35439 | Math.ceil(this['re'] * places) / places,
|
35440 | Math.ceil(this['im'] * places) / places);
|
35441 | },
|
35442 |
|
35443 | /**
|
35444 | * Floors the actual complex number
|
35445 | *
|
35446 | * @returns {Complex}
|
35447 | */
|
35448 | 'floor': function(places) {
|
35449 |
|
35450 | places = Math.pow(10, places || 0);
|
35451 |
|
35452 | return new Complex(
|
35453 | Math.floor(this['re'] * places) / places,
|
35454 | Math.floor(this['im'] * places) / places);
|
35455 | },
|
35456 |
|
35457 | /**
|
35458 | * Ceils the actual complex number
|
35459 | *
|
35460 | * @returns {Complex}
|
35461 | */
|
35462 | 'round': function(places) {
|
35463 |
|
35464 | places = Math.pow(10, places || 0);
|
35465 |
|
35466 | return new Complex(
|
35467 | Math.round(this['re'] * places) / places,
|
35468 | Math.round(this['im'] * places) / places);
|
35469 | },
|
35470 |
|
35471 | /**
|
35472 | * Compares two complex numbers
|
35473 | *
|
35474 | * **Note:** new Complex(Infinity).equals(Infinity) === false
|
35475 | *
|
35476 | * @returns {boolean}
|
35477 | */
|
35478 | 'equals': function(a, b) {
|
35479 |
|
35480 | var z = new Complex(a, b);
|
35481 |
|
35482 | return Math.abs(z['re'] - this['re']) <= Complex['EPSILON'] &&
|
35483 | Math.abs(z['im'] - this['im']) <= Complex['EPSILON'];
|
35484 | },
|
35485 |
|
35486 | /**
|
35487 | * Clones the actual object
|
35488 | *
|
35489 | * @returns {Complex}
|
35490 | */
|
35491 | 'clone': function() {
|
35492 |
|
35493 | return new Complex(this['re'], this['im']);
|
35494 | },
|
35495 |
|
35496 | /**
|
35497 | * Gets a string of the actual complex number
|
35498 | *
|
35499 | * @returns {string}
|
35500 | */
|
35501 | 'toString': function() {
|
35502 |
|
35503 | var a = this['re'];
|
35504 | var b = this['im'];
|
35505 | var ret = '';
|
35506 |
|
35507 | if (this['isNaN']()) {
|
35508 | return 'NaN';
|
35509 | }
|
35510 |
|
35511 | if (this['isZero']()) {
|
35512 | return '0';
|
35513 | }
|
35514 |
|
35515 | if (this['isInfinite']()) {
|
35516 | return 'Infinity';
|
35517 | }
|
35518 |
|
35519 | if (a !== 0) {
|
35520 | ret += a;
|
35521 | }
|
35522 |
|
35523 | if (b !== 0) {
|
35524 |
|
35525 | if (a !== 0) {
|
35526 | ret += b < 0 ? ' - ' : ' + ';
|
35527 | } else if (b < 0) {
|
35528 | ret += '-';
|
35529 | }
|
35530 |
|
35531 | b = Math.abs(b);
|
35532 |
|
35533 | if (1 !== b) {
|
35534 | ret += b;
|
35535 | }
|
35536 | ret += 'i';
|
35537 | }
|
35538 |
|
35539 | if (!ret)
|
35540 | return '0';
|
35541 |
|
35542 | return ret;
|
35543 | },
|
35544 |
|
35545 | /**
|
35546 | * Returns the actual number as a vector
|
35547 | *
|
35548 | * @returns {Array}
|
35549 | */
|
35550 | 'toVector': function() {
|
35551 |
|
35552 | return [this['re'], this['im']];
|
35553 | },
|
35554 |
|
35555 | /**
|
35556 | * Returns the actual real value of the current object
|
35557 | *
|
35558 | * @returns {number|null}
|
35559 | */
|
35560 | 'valueOf': function() {
|
35561 |
|
35562 | if (this['im'] === 0) {
|
35563 | return this['re'];
|
35564 | }
|
35565 | return null;
|
35566 | },
|
35567 |
|
35568 | /**
|
35569 | * Determines whether a complex number is not on the Riemann sphere.
|
35570 | *
|
35571 | * @returns {boolean}
|
35572 | */
|
35573 | 'isNaN': function() {
|
35574 | return isNaN(this['re']) || isNaN(this['im']);
|
35575 | },
|
35576 |
|
35577 | /**
|
35578 | * Determines whether or not a complex number is at the zero pole of the
|
35579 | * Riemann sphere.
|
35580 | *
|
35581 | * @returns {boolean}
|
35582 | */
|
35583 | 'isZero': function() {
|
35584 | return (
|
35585 | (this['re'] === 0 || this['re'] === -0) &&
|
35586 | (this['im'] === 0 || this['im'] === -0)
|
35587 | );
|
35588 | },
|
35589 |
|
35590 | /**
|
35591 | * Determines whether a complex number is not at the infinity pole of the
|
35592 | * Riemann sphere.
|
35593 | *
|
35594 | * @returns {boolean}
|
35595 | */
|
35596 | 'isFinite': function() {
|
35597 | return isFinite(this['re']) && isFinite(this['im']);
|
35598 | },
|
35599 |
|
35600 | /**
|
35601 | * Determines whether or not a complex number is at the infinity pole of the
|
35602 | * Riemann sphere.
|
35603 | *
|
35604 | * @returns {boolean}
|
35605 | */
|
35606 | 'isInfinite': function() {
|
35607 | return !(this['isNaN']() || this['isFinite']());
|
35608 | }
|
35609 | };
|
35610 |
|
35611 | Complex['ZERO'] = new Complex(0, 0);
|
35612 | Complex['ONE'] = new Complex(1, 0);
|
35613 | Complex['I'] = new Complex(0, 1);
|
35614 | Complex['PI'] = new Complex(Math.PI, 0);
|
35615 | Complex['E'] = new Complex(Math.E, 0);
|
35616 | Complex['INFINITY'] = new Complex(Infinity, Infinity);
|
35617 | Complex['NAN'] = new Complex(NaN, NaN);
|
35618 | Complex['EPSILON'] = 1e-16;
|
35619 |
|
35620 | if (true) {
|
35621 | !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function() {
|
35622 | return Complex;
|
35623 | }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
|
35624 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
35625 | } else {}
|
35626 |
|
35627 | })(this);
|
35628 |
|
35629 |
|
35630 | /***/ }),
|
35631 | /* 179 */
|
35632 | /***/ (function(module, exports, __webpack_require__) {
|
35633 |
|
35634 | "use strict";
|
35635 |
|
35636 |
|
35637 | var deepMap = __webpack_require__(1);
|
35638 |
|
35639 | function factory(type, config, load, typed) {
|
35640 | var latex = __webpack_require__(4);
|
35641 | /**
|
35642 | * Create a complex value or convert a value to a complex value.
|
35643 | *
|
35644 | * Syntax:
|
35645 | *
|
35646 | * math.complex() // creates a complex value with zero
|
35647 | * // as real and imaginary part.
|
35648 | * math.complex(re : number, im : string) // creates a complex value with provided
|
35649 | * // values for real and imaginary part.
|
35650 | * math.complex(re : number) // creates a complex value with provided
|
35651 | * // real value and zero imaginary part.
|
35652 | * math.complex(complex : Complex) // clones the provided complex value.
|
35653 | * math.complex(arg : string) // parses a string into a complex value.
|
35654 | * math.complex(array : Array) // converts the elements of the array
|
35655 | * // or matrix element wise into a
|
35656 | * // complex value.
|
35657 | * math.complex({re: number, im: number}) // creates a complex value with provided
|
35658 | * // values for real an imaginary part.
|
35659 | * math.complex({r: number, phi: number}) // creates a complex value with provided
|
35660 | * // polar coordinates
|
35661 | *
|
35662 | * Examples:
|
35663 | *
|
35664 | * const a = math.complex(3, -4) // a = Complex 3 - 4i
|
35665 | * a.re = 5 // a = Complex 5 - 4i
|
35666 | * const i = a.im // Number -4
|
35667 | * const b = math.complex('2 + 6i') // Complex 2 + 6i
|
35668 | * const c = math.complex() // Complex 0 + 0i
|
35669 | * const d = math.add(a, b) // Complex 5 + 2i
|
35670 | *
|
35671 | * See also:
|
35672 | *
|
35673 | * bignumber, boolean, index, matrix, number, string, unit
|
35674 | *
|
35675 | * @param {* | Array | Matrix} [args]
|
35676 | * Arguments specifying the real and imaginary part of the complex number
|
35677 | * @return {Complex | Array | Matrix} Returns a complex value
|
35678 | */
|
35679 |
|
35680 |
|
35681 | var complex = typed('complex', {
|
35682 | '': function _() {
|
35683 | return type.Complex.ZERO;
|
35684 | },
|
35685 | 'number': function number(x) {
|
35686 | return new type.Complex(x, 0);
|
35687 | },
|
35688 | 'number, number': function numberNumber(re, im) {
|
35689 | return new type.Complex(re, im);
|
35690 | },
|
35691 | // TODO: this signature should be redundant
|
35692 | 'BigNumber, BigNumber': function BigNumberBigNumber(re, im) {
|
35693 | return new type.Complex(re.toNumber(), im.toNumber());
|
35694 | },
|
35695 | 'Complex': function Complex(x) {
|
35696 | return x.clone();
|
35697 | },
|
35698 | 'string': function string(x) {
|
35699 | return type.Complex(x); // for example '2 + 3i'
|
35700 | },
|
35701 | 'null': function _null(x) {
|
35702 | return type.Complex(0);
|
35703 | },
|
35704 | 'Object': function Object(x) {
|
35705 | if ('re' in x && 'im' in x) {
|
35706 | return new type.Complex(x.re, x.im);
|
35707 | }
|
35708 |
|
35709 | if ('r' in x && 'phi' in x || 'abs' in x && 'arg' in x) {
|
35710 | return new type.Complex(x);
|
35711 | }
|
35712 |
|
35713 | throw new Error('Expected object with properties (re and im) or (r and phi) or (abs and arg)');
|
35714 | },
|
35715 | 'Array | Matrix': function ArrayMatrix(x) {
|
35716 | return deepMap(x, complex);
|
35717 | }
|
35718 | });
|
35719 | complex.toTex = {
|
35720 | 0: '0',
|
35721 | 1: "\\left(${args[0]}\\right)",
|
35722 | 2: "\\left(\\left(${args[0]}\\right)+".concat(latex.symbols['i'], "\\cdot\\left(${args[1]}\\right)\\right)")
|
35723 | };
|
35724 | return complex;
|
35725 | }
|
35726 |
|
35727 | exports.name = 'complex';
|
35728 | exports.factory = factory;
|
35729 |
|
35730 | /***/ }),
|
35731 | /* 180 */
|
35732 | /***/ (function(module, exports, __webpack_require__) {
|
35733 |
|
35734 | "use strict";
|
35735 |
|
35736 |
|
35737 | // Map the characters to escape to their escaped values. The list is derived
|
35738 | // from http://www.cespedes.org/blog/85/how-to-escape-latex-special-characters
|
35739 |
|
35740 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
35741 |
|
35742 | var defaultEscapes = {
|
35743 | "{": "\\{",
|
35744 | "}": "\\}",
|
35745 | "\\": "\\textbackslash{}",
|
35746 | "#": "\\#",
|
35747 | $: "\\$",
|
35748 | "%": "\\%",
|
35749 | "&": "\\&",
|
35750 | "^": "\\textasciicircum{}",
|
35751 | _: "\\_",
|
35752 | "~": "\\textasciitilde{}"
|
35753 | };
|
35754 | var formatEscapes = {
|
35755 | "\u2013": "\\--",
|
35756 | "\u2014": "\\---",
|
35757 | " ": "~",
|
35758 | "\t": "\\qquad{}",
|
35759 | "\r\n": "\\newline{}",
|
35760 | "\n": "\\newline{}"
|
35761 | };
|
35762 |
|
35763 | var defaultEscapeMapFn = function defaultEscapeMapFn(defaultEscapes, formatEscapes) {
|
35764 | return _extends({}, defaultEscapes, formatEscapes);
|
35765 | };
|
35766 |
|
35767 | /**
|
35768 | * Escape a string to be used in LaTeX documents.
|
35769 | * @param {string} str the string to be escaped.
|
35770 | * @param {boolean} params.preserveFormatting whether formatting escapes should
|
35771 | * be performed (default: false).
|
35772 | * @param {function} params.escapeMapFn the function to modify the escape maps.
|
35773 | * @return {string} the escaped string, ready to be used in LaTeX.
|
35774 | */
|
35775 | module.exports = function (str) {
|
35776 | var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
35777 | _ref$preserveFormatti = _ref.preserveFormatting,
|
35778 | preserveFormatting = _ref$preserveFormatti === undefined ? false : _ref$preserveFormatti,
|
35779 | _ref$escapeMapFn = _ref.escapeMapFn,
|
35780 | escapeMapFn = _ref$escapeMapFn === undefined ? defaultEscapeMapFn : _ref$escapeMapFn;
|
35781 |
|
35782 | var runningStr = String(str);
|
35783 | var result = "";
|
35784 |
|
35785 | var escapes = escapeMapFn(_extends({}, defaultEscapes), preserveFormatting ? _extends({}, formatEscapes) : {});
|
35786 | var escapeKeys = Object.keys(escapes); // as it is reused later on
|
35787 |
|
35788 | // Algorithm: Go through the string character by character, if it matches
|
35789 | // with one of the special characters then we'll replace it with the escaped
|
35790 | // version.
|
35791 |
|
35792 | var _loop = function _loop() {
|
35793 | var specialCharFound = false;
|
35794 | escapeKeys.forEach(function (key, index) {
|
35795 | if (specialCharFound) {
|
35796 | return;
|
35797 | }
|
35798 | if (runningStr.length >= key.length && runningStr.slice(0, key.length) === key) {
|
35799 | result += escapes[escapeKeys[index]];
|
35800 | runningStr = runningStr.slice(key.length, runningStr.length);
|
35801 | specialCharFound = true;
|
35802 | }
|
35803 | });
|
35804 | if (!specialCharFound) {
|
35805 | result += runningStr.slice(0, 1);
|
35806 | runningStr = runningStr.slice(1, runningStr.length);
|
35807 | }
|
35808 | };
|
35809 |
|
35810 | while (runningStr) {
|
35811 | _loop();
|
35812 | }
|
35813 | return result;
|
35814 | };
|
35815 |
|
35816 | /***/ }),
|
35817 | /* 181 */
|
35818 | /***/ (function(module, exports, __webpack_require__) {
|
35819 |
|
35820 | "use strict";
|
35821 |
|
35822 |
|
35823 | module.exports = [// type
|
35824 | __webpack_require__(182), // construction function
|
35825 | __webpack_require__(83)];
|
35826 |
|
35827 | /***/ }),
|
35828 | /* 182 */
|
35829 | /***/ (function(module, exports, __webpack_require__) {
|
35830 |
|
35831 | "use strict";
|
35832 |
|
35833 |
|
35834 | var Fraction = __webpack_require__(183);
|
35835 | /**
|
35836 | * Attach type information
|
35837 | */
|
35838 |
|
35839 |
|
35840 | Fraction.prototype.type = 'Fraction';
|
35841 | Fraction.prototype.isFraction = true;
|
35842 | /**
|
35843 | * Get a JSON representation of a Fraction containing type information
|
35844 | * @returns {Object} Returns a JSON object structured as:
|
35845 | * `{"mathjs": "Fraction", "n": 3, "d": 8}`
|
35846 | */
|
35847 |
|
35848 | Fraction.prototype.toJSON = function () {
|
35849 | return {
|
35850 | mathjs: 'Fraction',
|
35851 | n: this.s * this.n,
|
35852 | d: this.d
|
35853 | };
|
35854 | };
|
35855 | /**
|
35856 | * Instantiate a Fraction from a JSON object
|
35857 | * @param {Object} json a JSON object structured as:
|
35858 | * `{"mathjs": "Fraction", "n": 3, "d": 8}`
|
35859 | * @return {BigNumber}
|
35860 | */
|
35861 |
|
35862 |
|
35863 | Fraction.fromJSON = function (json) {
|
35864 | return new Fraction(json);
|
35865 | };
|
35866 |
|
35867 | function factory(type, config, load, typed) {
|
35868 | return Fraction;
|
35869 | }
|
35870 |
|
35871 | exports.name = 'Fraction';
|
35872 | exports.path = 'type';
|
35873 | exports.factory = factory;
|
35874 |
|
35875 | /***/ }),
|
35876 | /* 183 */
|
35877 | /***/ (function(module, exports, __webpack_require__) {
|
35878 |
|
35879 | var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/**
|
35880 | * @license Fraction.js v4.0.12 09/09/2015
|
35881 | * http://www.xarg.org/2014/03/rational-numbers-in-javascript/
|
35882 | *
|
35883 | * Copyright (c) 2015, Robert Eisele (robert@xarg.org)
|
35884 | * Dual licensed under the MIT or GPL Version 2 licenses.
|
35885 | **/
|
35886 |
|
35887 |
|
35888 | /**
|
35889 | *
|
35890 | * This class offers the possibility to calculate fractions.
|
35891 | * You can pass a fraction in different formats. Either as array, as double, as string or as an integer.
|
35892 | *
|
35893 | * Array/Object form
|
35894 | * [ 0 => <nominator>, 1 => <denominator> ]
|
35895 | * [ n => <nominator>, d => <denominator> ]
|
35896 | *
|
35897 | * Integer form
|
35898 | * - Single integer value
|
35899 | *
|
35900 | * Double form
|
35901 | * - Single double value
|
35902 | *
|
35903 | * String form
|
35904 | * 123.456 - a simple double
|
35905 | * 123/456 - a string fraction
|
35906 | * 123.'456' - a double with repeating decimal places
|
35907 | * 123.(456) - synonym
|
35908 | * 123.45'6' - a double with repeating last place
|
35909 | * 123.45(6) - synonym
|
35910 | *
|
35911 | * Example:
|
35912 | *
|
35913 | * var f = new Fraction("9.4'31'");
|
35914 | * f.mul([-4, 3]).div(4.9);
|
35915 | *
|
35916 | */
|
35917 |
|
35918 | (function(root) {
|
35919 |
|
35920 | "use strict";
|
35921 |
|
35922 | // Maximum search depth for cyclic rational numbers. 2000 should be more than enough.
|
35923 | // Example: 1/7 = 0.(142857) has 6 repeating decimal places.
|
35924 | // If MAX_CYCLE_LEN gets reduced, long cycles will not be detected and toString() only gets the first 10 digits
|
35925 | var MAX_CYCLE_LEN = 2000;
|
35926 |
|
35927 | // Parsed data to avoid calling "new" all the time
|
35928 | var P = {
|
35929 | "s": 1,
|
35930 | "n": 0,
|
35931 | "d": 1
|
35932 | };
|
35933 |
|
35934 | function createError(name) {
|
35935 |
|
35936 | function errorConstructor() {
|
35937 | var temp = Error.apply(this, arguments);
|
35938 | temp['name'] = this['name'] = name;
|
35939 | this['stack'] = temp['stack'];
|
35940 | this['message'] = temp['message'];
|
35941 | }
|
35942 |
|
35943 | /**
|
35944 | * Error constructor
|
35945 | *
|
35946 | * @constructor
|
35947 | */
|
35948 | function IntermediateInheritor() {}
|
35949 | IntermediateInheritor.prototype = Error.prototype;
|
35950 | errorConstructor.prototype = new IntermediateInheritor();
|
35951 |
|
35952 | return errorConstructor;
|
35953 | }
|
35954 |
|
35955 | var DivisionByZero = Fraction['DivisionByZero'] = createError('DivisionByZero');
|
35956 | var InvalidParameter = Fraction['InvalidParameter'] = createError('InvalidParameter');
|
35957 |
|
35958 | function assign(n, s) {
|
35959 |
|
35960 | if (isNaN(n = parseInt(n, 10))) {
|
35961 | throwInvalidParam();
|
35962 | }
|
35963 | return n * s;
|
35964 | }
|
35965 |
|
35966 | function throwInvalidParam() {
|
35967 | throw new InvalidParameter();
|
35968 | }
|
35969 |
|
35970 | var parse = function(p1, p2) {
|
35971 |
|
35972 | var n = 0, d = 1, s = 1;
|
35973 | var v = 0, w = 0, x = 0, y = 1, z = 1;
|
35974 |
|
35975 | var A = 0, B = 1;
|
35976 | var C = 1, D = 1;
|
35977 |
|
35978 | var N = 10000000;
|
35979 | var M;
|
35980 |
|
35981 | if (p1 === undefined || p1 === null) {
|
35982 | /* void */
|
35983 | } else if (p2 !== undefined) {
|
35984 | n = p1;
|
35985 | d = p2;
|
35986 | s = n * d;
|
35987 | } else
|
35988 | switch (typeof p1) {
|
35989 |
|
35990 | case "object":
|
35991 | {
|
35992 | if ("d" in p1 && "n" in p1) {
|
35993 | n = p1["n"];
|
35994 | d = p1["d"];
|
35995 | if ("s" in p1)
|
35996 | n *= p1["s"];
|
35997 | } else if (0 in p1) {
|
35998 | n = p1[0];
|
35999 | if (1 in p1)
|
36000 | d = p1[1];
|
36001 | } else {
|
36002 | throwInvalidParam();
|
36003 | }
|
36004 | s = n * d;
|
36005 | break;
|
36006 | }
|
36007 | case "number":
|
36008 | {
|
36009 | if (p1 < 0) {
|
36010 | s = p1;
|
36011 | p1 = -p1;
|
36012 | }
|
36013 |
|
36014 | if (p1 % 1 === 0) {
|
36015 | n = p1;
|
36016 | } else if (p1 > 0) { // check for != 0, scale would become NaN (log(0)), which converges really slow
|
36017 |
|
36018 | if (p1 >= 1) {
|
36019 | z = Math.pow(10, Math.floor(1 + Math.log(p1) / Math.LN10));
|
36020 | p1 /= z;
|
36021 | }
|
36022 |
|
36023 | // Using Farey Sequences
|
36024 | // http://www.johndcook.com/blog/2010/10/20/best-rational-approximation/
|
36025 |
|
36026 | while (B <= N && D <= N) {
|
36027 | M = (A + C) / (B + D);
|
36028 |
|
36029 | if (p1 === M) {
|
36030 | if (B + D <= N) {
|
36031 | n = A + C;
|
36032 | d = B + D;
|
36033 | } else if (D > B) {
|
36034 | n = C;
|
36035 | d = D;
|
36036 | } else {
|
36037 | n = A;
|
36038 | d = B;
|
36039 | }
|
36040 | break;
|
36041 |
|
36042 | } else {
|
36043 |
|
36044 | if (p1 > M) {
|
36045 | A += C;
|
36046 | B += D;
|
36047 | } else {
|
36048 | C += A;
|
36049 | D += B;
|
36050 | }
|
36051 |
|
36052 | if (B > N) {
|
36053 | n = C;
|
36054 | d = D;
|
36055 | } else {
|
36056 | n = A;
|
36057 | d = B;
|
36058 | }
|
36059 | }
|
36060 | }
|
36061 | n *= z;
|
36062 | } else if (isNaN(p1) || isNaN(p2)) {
|
36063 | d = n = NaN;
|
36064 | }
|
36065 | break;
|
36066 | }
|
36067 | case "string":
|
36068 | {
|
36069 | B = p1.match(/\d+|./g);
|
36070 |
|
36071 | if (B === null)
|
36072 | throwInvalidParam();
|
36073 |
|
36074 | if (B[A] === '-') {// Check for minus sign at the beginning
|
36075 | s = -1;
|
36076 | A++;
|
36077 | } else if (B[A] === '+') {// Check for plus sign at the beginning
|
36078 | A++;
|
36079 | }
|
36080 |
|
36081 | if (B.length === A + 1) { // Check if it's just a simple number "1234"
|
36082 | w = assign(B[A++], s);
|
36083 | } else if (B[A + 1] === '.' || B[A] === '.') { // Check if it's a decimal number
|
36084 |
|
36085 | if (B[A] !== '.') { // Handle 0.5 and .5
|
36086 | v = assign(B[A++], s);
|
36087 | }
|
36088 | A++;
|
36089 |
|
36090 | // Check for decimal places
|
36091 | if (A + 1 === B.length || B[A + 1] === '(' && B[A + 3] === ')' || B[A + 1] === "'" && B[A + 3] === "'") {
|
36092 | w = assign(B[A], s);
|
36093 | y = Math.pow(10, B[A].length);
|
36094 | A++;
|
36095 | }
|
36096 |
|
36097 | // Check for repeating places
|
36098 | if (B[A] === '(' && B[A + 2] === ')' || B[A] === "'" && B[A + 2] === "'") {
|
36099 | x = assign(B[A + 1], s);
|
36100 | z = Math.pow(10, B[A + 1].length) - 1;
|
36101 | A += 3;
|
36102 | }
|
36103 |
|
36104 | } else if (B[A + 1] === '/' || B[A + 1] === ':') { // Check for a simple fraction "123/456" or "123:456"
|
36105 | w = assign(B[A], s);
|
36106 | y = assign(B[A + 2], 1);
|
36107 | A += 3;
|
36108 | } else if (B[A + 3] === '/' && B[A + 1] === ' ') { // Check for a complex fraction "123 1/2"
|
36109 | v = assign(B[A], s);
|
36110 | w = assign(B[A + 2], s);
|
36111 | y = assign(B[A + 4], 1);
|
36112 | A += 5;
|
36113 | }
|
36114 |
|
36115 | if (B.length <= A) { // Check for more tokens on the stack
|
36116 | d = y * z;
|
36117 | s = /* void */
|
36118 | n = x + d * v + z * w;
|
36119 | break;
|
36120 | }
|
36121 |
|
36122 | /* Fall through on error */
|
36123 | }
|
36124 | default:
|
36125 | throwInvalidParam();
|
36126 | }
|
36127 |
|
36128 | if (d === 0) {
|
36129 | throw new DivisionByZero();
|
36130 | }
|
36131 |
|
36132 | P["s"] = s < 0 ? -1 : 1;
|
36133 | P["n"] = Math.abs(n);
|
36134 | P["d"] = Math.abs(d);
|
36135 | };
|
36136 |
|
36137 | function modpow(b, e, m) {
|
36138 |
|
36139 | var r = 1;
|
36140 | for (; e > 0; b = (b * b) % m, e >>= 1) {
|
36141 |
|
36142 | if (e & 1) {
|
36143 | r = (r * b) % m;
|
36144 | }
|
36145 | }
|
36146 | return r;
|
36147 | }
|
36148 |
|
36149 |
|
36150 | function cycleLen(n, d) {
|
36151 |
|
36152 | for (; d % 2 === 0;
|
36153 | d /= 2) {
|
36154 | }
|
36155 |
|
36156 | for (; d % 5 === 0;
|
36157 | d /= 5) {
|
36158 | }
|
36159 |
|
36160 | if (d === 1) // Catch non-cyclic numbers
|
36161 | return 0;
|
36162 |
|
36163 | // If we would like to compute really large numbers quicker, we could make use of Fermat's little theorem:
|
36164 | // 10^(d-1) % d == 1
|
36165 | // However, we don't need such large numbers and MAX_CYCLE_LEN should be the capstone,
|
36166 | // as we want to translate the numbers to strings.
|
36167 |
|
36168 | var rem = 10 % d;
|
36169 | var t = 1;
|
36170 |
|
36171 | for (; rem !== 1; t++) {
|
36172 | rem = rem * 10 % d;
|
36173 |
|
36174 | if (t > MAX_CYCLE_LEN)
|
36175 | return 0; // Returning 0 here means that we don't print it as a cyclic number. It's likely that the answer is `d-1`
|
36176 | }
|
36177 | return t;
|
36178 | }
|
36179 |
|
36180 |
|
36181 | function cycleStart(n, d, len) {
|
36182 |
|
36183 | var rem1 = 1;
|
36184 | var rem2 = modpow(10, len, d);
|
36185 |
|
36186 | for (var t = 0; t < 300; t++) { // s < ~log10(Number.MAX_VALUE)
|
36187 | // Solve 10^s == 10^(s+t) (mod d)
|
36188 |
|
36189 | if (rem1 === rem2)
|
36190 | return t;
|
36191 |
|
36192 | rem1 = rem1 * 10 % d;
|
36193 | rem2 = rem2 * 10 % d;
|
36194 | }
|
36195 | return 0;
|
36196 | }
|
36197 |
|
36198 | function gcd(a, b) {
|
36199 |
|
36200 | if (!a)
|
36201 | return b;
|
36202 | if (!b)
|
36203 | return a;
|
36204 |
|
36205 | while (1) {
|
36206 | a %= b;
|
36207 | if (!a)
|
36208 | return b;
|
36209 | b %= a;
|
36210 | if (!b)
|
36211 | return a;
|
36212 | }
|
36213 | };
|
36214 |
|
36215 | /**
|
36216 | * Module constructor
|
36217 | *
|
36218 | * @constructor
|
36219 | * @param {number|Fraction=} a
|
36220 | * @param {number=} b
|
36221 | */
|
36222 | function Fraction(a, b) {
|
36223 |
|
36224 | if (!(this instanceof Fraction)) {
|
36225 | return new Fraction(a, b);
|
36226 | }
|
36227 |
|
36228 | parse(a, b);
|
36229 |
|
36230 | if (Fraction['REDUCE']) {
|
36231 | a = gcd(P["d"], P["n"]); // Abuse a
|
36232 | } else {
|
36233 | a = 1;
|
36234 | }
|
36235 |
|
36236 | this["s"] = P["s"];
|
36237 | this["n"] = P["n"] / a;
|
36238 | this["d"] = P["d"] / a;
|
36239 | }
|
36240 |
|
36241 | /**
|
36242 | * Boolean global variable to be able to disable automatic reduction of the fraction
|
36243 | *
|
36244 | */
|
36245 | Fraction['REDUCE'] = 1;
|
36246 |
|
36247 | Fraction.prototype = {
|
36248 |
|
36249 | "s": 1,
|
36250 | "n": 0,
|
36251 | "d": 1,
|
36252 |
|
36253 | /**
|
36254 | * Calculates the absolute value
|
36255 | *
|
36256 | * Ex: new Fraction(-4).abs() => 4
|
36257 | **/
|
36258 | "abs": function() {
|
36259 |
|
36260 | return new Fraction(this["n"], this["d"]);
|
36261 | },
|
36262 |
|
36263 | /**
|
36264 | * Inverts the sign of the current fraction
|
36265 | *
|
36266 | * Ex: new Fraction(-4).neg() => 4
|
36267 | **/
|
36268 | "neg": function() {
|
36269 |
|
36270 | return new Fraction(-this["s"] * this["n"], this["d"]);
|
36271 | },
|
36272 |
|
36273 | /**
|
36274 | * Adds two rational numbers
|
36275 | *
|
36276 | * Ex: new Fraction({n: 2, d: 3}).add("14.9") => 467 / 30
|
36277 | **/
|
36278 | "add": function(a, b) {
|
36279 |
|
36280 | parse(a, b);
|
36281 | return new Fraction(
|
36282 | this["s"] * this["n"] * P["d"] + P["s"] * this["d"] * P["n"],
|
36283 | this["d"] * P["d"]
|
36284 | );
|
36285 | },
|
36286 |
|
36287 | /**
|
36288 | * Subtracts two rational numbers
|
36289 | *
|
36290 | * Ex: new Fraction({n: 2, d: 3}).add("14.9") => -427 / 30
|
36291 | **/
|
36292 | "sub": function(a, b) {
|
36293 |
|
36294 | parse(a, b);
|
36295 | return new Fraction(
|
36296 | this["s"] * this["n"] * P["d"] - P["s"] * this["d"] * P["n"],
|
36297 | this["d"] * P["d"]
|
36298 | );
|
36299 | },
|
36300 |
|
36301 | /**
|
36302 | * Multiplies two rational numbers
|
36303 | *
|
36304 | * Ex: new Fraction("-17.(345)").mul(3) => 5776 / 111
|
36305 | **/
|
36306 | "mul": function(a, b) {
|
36307 |
|
36308 | parse(a, b);
|
36309 | return new Fraction(
|
36310 | this["s"] * P["s"] * this["n"] * P["n"],
|
36311 | this["d"] * P["d"]
|
36312 | );
|
36313 | },
|
36314 |
|
36315 | /**
|
36316 | * Divides two rational numbers
|
36317 | *
|
36318 | * Ex: new Fraction("-17.(345)").inverse().div(3)
|
36319 | **/
|
36320 | "div": function(a, b) {
|
36321 |
|
36322 | parse(a, b);
|
36323 | return new Fraction(
|
36324 | this["s"] * P["s"] * this["n"] * P["d"],
|
36325 | this["d"] * P["n"]
|
36326 | );
|
36327 | },
|
36328 |
|
36329 | /**
|
36330 | * Clones the actual object
|
36331 | *
|
36332 | * Ex: new Fraction("-17.(345)").clone()
|
36333 | **/
|
36334 | "clone": function() {
|
36335 | return new Fraction(this);
|
36336 | },
|
36337 |
|
36338 | /**
|
36339 | * Calculates the modulo of two rational numbers - a more precise fmod
|
36340 | *
|
36341 | * Ex: new Fraction('4.(3)').mod([7, 8]) => (13/3) % (7/8) = (5/6)
|
36342 | **/
|
36343 | "mod": function(a, b) {
|
36344 |
|
36345 | if (isNaN(this['n']) || isNaN(this['d'])) {
|
36346 | return new Fraction(NaN);
|
36347 | }
|
36348 |
|
36349 | if (a === undefined) {
|
36350 | return new Fraction(this["s"] * this["n"] % this["d"], 1);
|
36351 | }
|
36352 |
|
36353 | parse(a, b);
|
36354 | if (0 === P["n"] && 0 === this["d"]) {
|
36355 | Fraction(0, 0); // Throw DivisionByZero
|
36356 | }
|
36357 |
|
36358 | /*
|
36359 | * First silly attempt, kinda slow
|
36360 | *
|
36361 | return that["sub"]({
|
36362 | "n": num["n"] * Math.floor((this.n / this.d) / (num.n / num.d)),
|
36363 | "d": num["d"],
|
36364 | "s": this["s"]
|
36365 | });*/
|
36366 |
|
36367 | /*
|
36368 | * New attempt: a1 / b1 = a2 / b2 * q + r
|
36369 | * => b2 * a1 = a2 * b1 * q + b1 * b2 * r
|
36370 | * => (b2 * a1 % a2 * b1) / (b1 * b2)
|
36371 | */
|
36372 | return new Fraction(
|
36373 | this["s"] * (P["d"] * this["n"]) % (P["n"] * this["d"]),
|
36374 | P["d"] * this["d"]
|
36375 | );
|
36376 | },
|
36377 |
|
36378 | /**
|
36379 | * Calculates the fractional gcd of two rational numbers
|
36380 | *
|
36381 | * Ex: new Fraction(5,8).gcd(3,7) => 1/56
|
36382 | */
|
36383 | "gcd": function(a, b) {
|
36384 |
|
36385 | parse(a, b);
|
36386 |
|
36387 | // gcd(a / b, c / d) = gcd(a, c) / lcm(b, d)
|
36388 |
|
36389 | return new Fraction(gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]), P["d"] * this["d"]);
|
36390 | },
|
36391 |
|
36392 | /**
|
36393 | * Calculates the fractional lcm of two rational numbers
|
36394 | *
|
36395 | * Ex: new Fraction(5,8).lcm(3,7) => 15
|
36396 | */
|
36397 | "lcm": function(a, b) {
|
36398 |
|
36399 | parse(a, b);
|
36400 |
|
36401 | // lcm(a / b, c / d) = lcm(a, c) / gcd(b, d)
|
36402 |
|
36403 | if (P["n"] === 0 && this["n"] === 0) {
|
36404 | return new Fraction;
|
36405 | }
|
36406 | return new Fraction(P["n"] * this["n"], gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]));
|
36407 | },
|
36408 |
|
36409 | /**
|
36410 | * Calculates the ceil of a rational number
|
36411 | *
|
36412 | * Ex: new Fraction('4.(3)').ceil() => (5 / 1)
|
36413 | **/
|
36414 | "ceil": function(places) {
|
36415 |
|
36416 | places = Math.pow(10, places || 0);
|
36417 |
|
36418 | if (isNaN(this["n"]) || isNaN(this["d"])) {
|
36419 | return new Fraction(NaN);
|
36420 | }
|
36421 | return new Fraction(Math.ceil(places * this["s"] * this["n"] / this["d"]), places);
|
36422 | },
|
36423 |
|
36424 | /**
|
36425 | * Calculates the floor of a rational number
|
36426 | *
|
36427 | * Ex: new Fraction('4.(3)').floor() => (4 / 1)
|
36428 | **/
|
36429 | "floor": function(places) {
|
36430 |
|
36431 | places = Math.pow(10, places || 0);
|
36432 |
|
36433 | if (isNaN(this["n"]) || isNaN(this["d"])) {
|
36434 | return new Fraction(NaN);
|
36435 | }
|
36436 | return new Fraction(Math.floor(places * this["s"] * this["n"] / this["d"]), places);
|
36437 | },
|
36438 |
|
36439 | /**
|
36440 | * Rounds a rational numbers
|
36441 | *
|
36442 | * Ex: new Fraction('4.(3)').round() => (4 / 1)
|
36443 | **/
|
36444 | "round": function(places) {
|
36445 |
|
36446 | places = Math.pow(10, places || 0);
|
36447 |
|
36448 | if (isNaN(this["n"]) || isNaN(this["d"])) {
|
36449 | return new Fraction(NaN);
|
36450 | }
|
36451 | return new Fraction(Math.round(places * this["s"] * this["n"] / this["d"]), places);
|
36452 | },
|
36453 |
|
36454 | /**
|
36455 | * Gets the inverse of the fraction, means numerator and denumerator are exchanged
|
36456 | *
|
36457 | * Ex: new Fraction([-3, 4]).inverse() => -4 / 3
|
36458 | **/
|
36459 | "inverse": function() {
|
36460 |
|
36461 | return new Fraction(this["s"] * this["d"], this["n"]);
|
36462 | },
|
36463 |
|
36464 | /**
|
36465 | * Calculates the fraction to some integer exponent
|
36466 | *
|
36467 | * Ex: new Fraction(-1,2).pow(-3) => -8
|
36468 | */
|
36469 | "pow": function(m) {
|
36470 |
|
36471 | if (m < 0) {
|
36472 | return new Fraction(Math.pow(this['s'] * this["d"], -m), Math.pow(this["n"], -m));
|
36473 | } else {
|
36474 | return new Fraction(Math.pow(this['s'] * this["n"], m), Math.pow(this["d"], m));
|
36475 | }
|
36476 | },
|
36477 |
|
36478 | /**
|
36479 | * Check if two rational numbers are the same
|
36480 | *
|
36481 | * Ex: new Fraction(19.6).equals([98, 5]);
|
36482 | **/
|
36483 | "equals": function(a, b) {
|
36484 |
|
36485 | parse(a, b);
|
36486 | return this["s"] * this["n"] * P["d"] === P["s"] * P["n"] * this["d"]; // Same as compare() === 0
|
36487 | },
|
36488 |
|
36489 | /**
|
36490 | * Check if two rational numbers are the same
|
36491 | *
|
36492 | * Ex: new Fraction(19.6).equals([98, 5]);
|
36493 | **/
|
36494 | "compare": function(a, b) {
|
36495 |
|
36496 | parse(a, b);
|
36497 | var t = (this["s"] * this["n"] * P["d"] - P["s"] * P["n"] * this["d"]);
|
36498 | return (0 < t) - (t < 0);
|
36499 | },
|
36500 |
|
36501 | "simplify": function(eps) {
|
36502 |
|
36503 | // First naive implementation, needs improvement
|
36504 |
|
36505 | if (isNaN(this['n']) || isNaN(this['d'])) {
|
36506 | return this;
|
36507 | }
|
36508 |
|
36509 | var cont = this['abs']()['toContinued']();
|
36510 |
|
36511 | eps = eps || 0.001;
|
36512 |
|
36513 | function rec(a) {
|
36514 | if (a.length === 1)
|
36515 | return new Fraction(a[0]);
|
36516 | return rec(a.slice(1))['inverse']()['add'](a[0]);
|
36517 | }
|
36518 |
|
36519 | for (var i = 0; i < cont.length; i++) {
|
36520 | var tmp = rec(cont.slice(0, i + 1));
|
36521 | if (tmp['sub'](this['abs']())['abs']().valueOf() < eps) {
|
36522 | return tmp['mul'](this['s']);
|
36523 | }
|
36524 | }
|
36525 | return this;
|
36526 | },
|
36527 |
|
36528 | /**
|
36529 | * Check if two rational numbers are divisible
|
36530 | *
|
36531 | * Ex: new Fraction(19.6).divisible(1.5);
|
36532 | */
|
36533 | "divisible": function(a, b) {
|
36534 |
|
36535 | parse(a, b);
|
36536 | return !(!(P["n"] * this["d"]) || ((this["n"] * P["d"]) % (P["n"] * this["d"])));
|
36537 | },
|
36538 |
|
36539 | /**
|
36540 | * Returns a decimal representation of the fraction
|
36541 | *
|
36542 | * Ex: new Fraction("100.'91823'").valueOf() => 100.91823918239183
|
36543 | **/
|
36544 | 'valueOf': function() {
|
36545 |
|
36546 | return this["s"] * this["n"] / this["d"];
|
36547 | },
|
36548 |
|
36549 | /**
|
36550 | * Returns a string-fraction representation of a Fraction object
|
36551 | *
|
36552 | * Ex: new Fraction("1.'3'").toFraction() => "4 1/3"
|
36553 | **/
|
36554 | 'toFraction': function(excludeWhole) {
|
36555 |
|
36556 | var whole, str = "";
|
36557 | var n = this["n"];
|
36558 | var d = this["d"];
|
36559 | if (this["s"] < 0) {
|
36560 | str += '-';
|
36561 | }
|
36562 |
|
36563 | if (d === 1) {
|
36564 | str += n;
|
36565 | } else {
|
36566 |
|
36567 | if (excludeWhole && (whole = Math.floor(n / d)) > 0) {
|
36568 | str += whole;
|
36569 | str += " ";
|
36570 | n %= d;
|
36571 | }
|
36572 |
|
36573 | str += n;
|
36574 | str += '/';
|
36575 | str += d;
|
36576 | }
|
36577 | return str;
|
36578 | },
|
36579 |
|
36580 | /**
|
36581 | * Returns a latex representation of a Fraction object
|
36582 | *
|
36583 | * Ex: new Fraction("1.'3'").toLatex() => "\frac{4}{3}"
|
36584 | **/
|
36585 | 'toLatex': function(excludeWhole) {
|
36586 |
|
36587 | var whole, str = "";
|
36588 | var n = this["n"];
|
36589 | var d = this["d"];
|
36590 | if (this["s"] < 0) {
|
36591 | str += '-';
|
36592 | }
|
36593 |
|
36594 | if (d === 1) {
|
36595 | str += n;
|
36596 | } else {
|
36597 |
|
36598 | if (excludeWhole && (whole = Math.floor(n / d)) > 0) {
|
36599 | str += whole;
|
36600 | n %= d;
|
36601 | }
|
36602 |
|
36603 | str += "\\frac{";
|
36604 | str += n;
|
36605 | str += '}{';
|
36606 | str += d;
|
36607 | str += '}';
|
36608 | }
|
36609 | return str;
|
36610 | },
|
36611 |
|
36612 | /**
|
36613 | * Returns an array of continued fraction elements
|
36614 | *
|
36615 | * Ex: new Fraction("7/8").toContinued() => [0,1,7]
|
36616 | */
|
36617 | 'toContinued': function() {
|
36618 |
|
36619 | var t;
|
36620 | var a = this['n'];
|
36621 | var b = this['d'];
|
36622 | var res = [];
|
36623 |
|
36624 | if (isNaN(this['n']) || isNaN(this['d'])) {
|
36625 | return res;
|
36626 | }
|
36627 |
|
36628 | do {
|
36629 | res.push(Math.floor(a / b));
|
36630 | t = a % b;
|
36631 | a = b;
|
36632 | b = t;
|
36633 | } while (a !== 1);
|
36634 |
|
36635 | return res;
|
36636 | },
|
36637 |
|
36638 | /**
|
36639 | * Creates a string representation of a fraction with all digits
|
36640 | *
|
36641 | * Ex: new Fraction("100.'91823'").toString() => "100.(91823)"
|
36642 | **/
|
36643 | 'toString': function(dec) {
|
36644 |
|
36645 | var g;
|
36646 | var N = this["n"];
|
36647 | var D = this["d"];
|
36648 |
|
36649 | if (isNaN(N) || isNaN(D)) {
|
36650 | return "NaN";
|
36651 | }
|
36652 |
|
36653 | if (!Fraction['REDUCE']) {
|
36654 | g = gcd(N, D);
|
36655 | N /= g;
|
36656 | D /= g;
|
36657 | }
|
36658 |
|
36659 | dec = dec || 15; // 15 = decimal places when no repitation
|
36660 |
|
36661 | var cycLen = cycleLen(N, D); // Cycle length
|
36662 | var cycOff = cycleStart(N, D, cycLen); // Cycle start
|
36663 |
|
36664 | var str = this['s'] === -1 ? "-" : "";
|
36665 |
|
36666 | str += N / D | 0;
|
36667 |
|
36668 | N %= D;
|
36669 | N *= 10;
|
36670 |
|
36671 | if (N)
|
36672 | str += ".";
|
36673 |
|
36674 | if (cycLen) {
|
36675 |
|
36676 | for (var i = cycOff; i--; ) {
|
36677 | str += N / D | 0;
|
36678 | N %= D;
|
36679 | N *= 10;
|
36680 | }
|
36681 | str += "(";
|
36682 | for (var i = cycLen; i--; ) {
|
36683 | str += N / D | 0;
|
36684 | N %= D;
|
36685 | N *= 10;
|
36686 | }
|
36687 | str += ")";
|
36688 | } else {
|
36689 | for (var i = dec; N && i--; ) {
|
36690 | str += N / D | 0;
|
36691 | N %= D;
|
36692 | N *= 10;
|
36693 | }
|
36694 | }
|
36695 | return str;
|
36696 | }
|
36697 | };
|
36698 |
|
36699 | if (true) {
|
36700 | !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function() {
|
36701 | return Fraction;
|
36702 | }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
|
36703 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
36704 | } else {}
|
36705 |
|
36706 | })(this);
|
36707 |
|
36708 |
|
36709 | /***/ }),
|
36710 | /* 184 */
|
36711 | /***/ (function(module, exports, __webpack_require__) {
|
36712 |
|
36713 | "use strict";
|
36714 |
|
36715 |
|
36716 | module.exports = [// types
|
36717 | __webpack_require__(84), __webpack_require__(49), __webpack_require__(186), __webpack_require__(187), __webpack_require__(188), __webpack_require__(189), __webpack_require__(24), __webpack_require__(106), // construction functions
|
36718 | __webpack_require__(190), __webpack_require__(0), __webpack_require__(191), // util functions
|
36719 | __webpack_require__(63)];
|
36720 |
|
36721 | /***/ }),
|
36722 | /* 185 */
|
36723 | /***/ (function(module, exports, __webpack_require__) {
|
36724 |
|
36725 | "use strict";
|
36726 |
|
36727 | /**
|
36728 | * Test whether value is a boolean
|
36729 | * @param {*} value
|
36730 | * @return {boolean} isBoolean
|
36731 | */
|
36732 |
|
36733 | exports.isBoolean = function (value) {
|
36734 | return typeof value === 'boolean';
|
36735 | };
|
36736 |
|
36737 | /***/ }),
|
36738 | /* 186 */
|
36739 | /***/ (function(module, exports, __webpack_require__) {
|
36740 |
|
36741 | "use strict";
|
36742 |
|
36743 |
|
36744 | var util = __webpack_require__(31);
|
36745 |
|
36746 | var DimensionError = __webpack_require__(8);
|
36747 |
|
36748 | var array = util.array;
|
36749 | var object = util.object;
|
36750 | var string = util.string;
|
36751 | var number = util.number;
|
36752 | var isArray = Array.isArray;
|
36753 | var isNumber = number.isNumber;
|
36754 | var isInteger = number.isInteger;
|
36755 | var isString = string.isString;
|
36756 | var validateIndex = array.validateIndex;
|
36757 |
|
36758 | function factory(type, config, load, typed) {
|
36759 | var Matrix = load(__webpack_require__(84)); // force loading Matrix (do not use via type.Matrix)
|
36760 |
|
36761 | var equalScalar = load(__webpack_require__(11));
|
36762 | var getArrayDataType = load(__webpack_require__(63));
|
36763 | /**
|
36764 | * Sparse Matrix implementation. This type implements a Compressed Column Storage format
|
36765 | * for sparse matrices.
|
36766 | * @class SparseMatrix
|
36767 | */
|
36768 |
|
36769 | function SparseMatrix(data, datatype) {
|
36770 | if (!(this instanceof SparseMatrix)) {
|
36771 | throw new SyntaxError('Constructor must be called with the new operator');
|
36772 | }
|
36773 |
|
36774 | if (datatype && !isString(datatype)) {
|
36775 | throw new Error('Invalid datatype: ' + datatype);
|
36776 | }
|
36777 |
|
36778 | if (type.isMatrix(data)) {
|
36779 | // create from matrix
|
36780 | _createFromMatrix(this, data, datatype);
|
36781 | } else if (data && isArray(data.index) && isArray(data.ptr) && isArray(data.size)) {
|
36782 | // initialize fields
|
36783 | this._values = data.values;
|
36784 | this._index = data.index;
|
36785 | this._ptr = data.ptr;
|
36786 | this._size = data.size;
|
36787 | this._datatype = datatype || data.datatype;
|
36788 | } else if (isArray(data)) {
|
36789 | // create from array
|
36790 | _createFromArray(this, data, datatype);
|
36791 | } else if (data) {
|
36792 | // unsupported type
|
36793 | throw new TypeError('Unsupported type of data (' + util.types.type(data) + ')');
|
36794 | } else {
|
36795 | // nothing provided
|
36796 | this._values = [];
|
36797 | this._index = [];
|
36798 | this._ptr = [0];
|
36799 | this._size = [0, 0];
|
36800 | this._datatype = datatype;
|
36801 | }
|
36802 | }
|
36803 |
|
36804 | function _createFromMatrix(matrix, source, datatype) {
|
36805 | // check matrix type
|
36806 | if (source.type === 'SparseMatrix') {
|
36807 | // clone arrays
|
36808 | matrix._values = source._values ? object.clone(source._values) : undefined;
|
36809 | matrix._index = object.clone(source._index);
|
36810 | matrix._ptr = object.clone(source._ptr);
|
36811 | matrix._size = object.clone(source._size);
|
36812 | matrix._datatype = datatype || source._datatype;
|
36813 | } else {
|
36814 | // build from matrix data
|
36815 | _createFromArray(matrix, source.valueOf(), datatype || source._datatype);
|
36816 | }
|
36817 | }
|
36818 |
|
36819 | function _createFromArray(matrix, data, datatype) {
|
36820 | // initialize fields
|
36821 | matrix._values = [];
|
36822 | matrix._index = [];
|
36823 | matrix._ptr = [];
|
36824 | matrix._datatype = datatype; // discover rows & columns, do not use math.size() to avoid looping array twice
|
36825 |
|
36826 | var rows = data.length;
|
36827 | var columns = 0; // equal signature to use
|
36828 |
|
36829 | var eq = equalScalar; // zero value
|
36830 |
|
36831 | var zero = 0;
|
36832 |
|
36833 | if (isString(datatype)) {
|
36834 | // find signature that matches (datatype, datatype)
|
36835 | eq = typed.find(equalScalar, [datatype, datatype]) || equalScalar; // convert 0 to the same datatype
|
36836 |
|
36837 | zero = typed.convert(0, datatype);
|
36838 | } // check we have rows (empty array)
|
36839 |
|
36840 |
|
36841 | if (rows > 0) {
|
36842 | // column index
|
36843 | var j = 0;
|
36844 |
|
36845 | do {
|
36846 | // store pointer to values index
|
36847 | matrix._ptr.push(matrix._index.length); // loop rows
|
36848 |
|
36849 |
|
36850 | for (var i = 0; i < rows; i++) {
|
36851 | // current row
|
36852 | var row = data[i]; // check row is an array
|
36853 |
|
36854 | if (isArray(row)) {
|
36855 | // update columns if needed (only on first column)
|
36856 | if (j === 0 && columns < row.length) {
|
36857 | columns = row.length;
|
36858 | } // check row has column
|
36859 |
|
36860 |
|
36861 | if (j < row.length) {
|
36862 | // value
|
36863 | var v = row[j]; // check value != 0
|
36864 |
|
36865 | if (!eq(v, zero)) {
|
36866 | // store value
|
36867 | matrix._values.push(v); // index
|
36868 |
|
36869 |
|
36870 | matrix._index.push(i);
|
36871 | }
|
36872 | }
|
36873 | } else {
|
36874 | // update columns if needed (only on first column)
|
36875 | if (j === 0 && columns < 1) {
|
36876 | columns = 1;
|
36877 | } // check value != 0 (row is a scalar)
|
36878 |
|
36879 |
|
36880 | if (!eq(row, zero)) {
|
36881 | // store value
|
36882 | matrix._values.push(row); // index
|
36883 |
|
36884 |
|
36885 | matrix._index.push(i);
|
36886 | }
|
36887 | }
|
36888 | } // increment index
|
36889 |
|
36890 |
|
36891 | j++;
|
36892 | } while (j < columns);
|
36893 | } // store number of values in ptr
|
36894 |
|
36895 |
|
36896 | matrix._ptr.push(matrix._index.length); // size
|
36897 |
|
36898 |
|
36899 | matrix._size = [rows, columns];
|
36900 | }
|
36901 |
|
36902 | SparseMatrix.prototype = new Matrix();
|
36903 | /**
|
36904 | * Attach type information
|
36905 | */
|
36906 |
|
36907 | SparseMatrix.prototype.type = 'SparseMatrix';
|
36908 | SparseMatrix.prototype.isSparseMatrix = true;
|
36909 | /**
|
36910 | * Get the matrix type
|
36911 | *
|
36912 | * Usage:
|
36913 | * const matrixType = matrix.getDataType() // retrieves the matrix type
|
36914 | *
|
36915 | * @memberOf SparseMatrix
|
36916 | * @return {string} type information; if multiple types are found from the Matrix, it will return "mixed"
|
36917 | */
|
36918 |
|
36919 | SparseMatrix.prototype.getDataType = function () {
|
36920 | return getArrayDataType(this._values);
|
36921 | };
|
36922 | /**
|
36923 | * Get the storage format used by the matrix.
|
36924 | *
|
36925 | * Usage:
|
36926 | * const format = matrix.storage() // retrieve storage format
|
36927 | *
|
36928 | * @memberof SparseMatrix
|
36929 | * @return {string} The storage format.
|
36930 | */
|
36931 |
|
36932 |
|
36933 | SparseMatrix.prototype.storage = function () {
|
36934 | return 'sparse';
|
36935 | };
|
36936 | /**
|
36937 | * Get the datatype of the data stored in the matrix.
|
36938 | *
|
36939 | * Usage:
|
36940 | * const format = matrix.datatype() // retrieve matrix datatype
|
36941 | *
|
36942 | * @memberof SparseMatrix
|
36943 | * @return {string} The datatype.
|
36944 | */
|
36945 |
|
36946 |
|
36947 | SparseMatrix.prototype.datatype = function () {
|
36948 | return this._datatype;
|
36949 | };
|
36950 | /**
|
36951 | * Create a new SparseMatrix
|
36952 | * @memberof SparseMatrix
|
36953 | * @param {Array} data
|
36954 | * @param {string} [datatype]
|
36955 | */
|
36956 |
|
36957 |
|
36958 | SparseMatrix.prototype.create = function (data, datatype) {
|
36959 | return new SparseMatrix(data, datatype);
|
36960 | };
|
36961 | /**
|
36962 | * Get the matrix density.
|
36963 | *
|
36964 | * Usage:
|
36965 | * const density = matrix.density() // retrieve matrix density
|
36966 | *
|
36967 | * @memberof SparseMatrix
|
36968 | * @return {number} The matrix density.
|
36969 | */
|
36970 |
|
36971 |
|
36972 | SparseMatrix.prototype.density = function () {
|
36973 | // rows & columns
|
36974 | var rows = this._size[0];
|
36975 | var columns = this._size[1]; // calculate density
|
36976 |
|
36977 | return rows !== 0 && columns !== 0 ? this._index.length / (rows * columns) : 0;
|
36978 | };
|
36979 | /**
|
36980 | * Get a subset of the matrix, or replace a subset of the matrix.
|
36981 | *
|
36982 | * Usage:
|
36983 | * const subset = matrix.subset(index) // retrieve subset
|
36984 | * const value = matrix.subset(index, replacement) // replace subset
|
36985 | *
|
36986 | * @memberof SparseMatrix
|
36987 | * @param {Index} index
|
36988 | * @param {Array | Matrix | *} [replacement]
|
36989 | * @param {*} [defaultValue=0] Default value, filled in on new entries when
|
36990 | * the matrix is resized. If not provided,
|
36991 | * new matrix elements will be filled with zeros.
|
36992 | */
|
36993 |
|
36994 |
|
36995 | SparseMatrix.prototype.subset = function (index, replacement, defaultValue) {
|
36996 | // check it is a pattern matrix
|
36997 | if (!this._values) {
|
36998 | throw new Error('Cannot invoke subset on a Pattern only matrix');
|
36999 | } // check arguments
|
37000 |
|
37001 |
|
37002 | switch (arguments.length) {
|
37003 | case 1:
|
37004 | return _getsubset(this, index);
|
37005 | // intentional fall through
|
37006 |
|
37007 | case 2:
|
37008 | case 3:
|
37009 | return _setsubset(this, index, replacement, defaultValue);
|
37010 |
|
37011 | default:
|
37012 | throw new SyntaxError('Wrong number of arguments');
|
37013 | }
|
37014 | };
|
37015 |
|
37016 | function _getsubset(matrix, idx) {
|
37017 | // check idx
|
37018 | if (!type.isIndex(idx)) {
|
37019 | throw new TypeError('Invalid index');
|
37020 | }
|
37021 |
|
37022 | var isScalar = idx.isScalar();
|
37023 |
|
37024 | if (isScalar) {
|
37025 | // return a scalar
|
37026 | return matrix.get(idx.min());
|
37027 | } // validate dimensions
|
37028 |
|
37029 |
|
37030 | var size = idx.size();
|
37031 |
|
37032 | if (size.length !== matrix._size.length) {
|
37033 | throw new DimensionError(size.length, matrix._size.length);
|
37034 | } // vars
|
37035 |
|
37036 |
|
37037 | var i, ii, k, kk; // validate if any of the ranges in the index is out of range
|
37038 |
|
37039 | var min = idx.min();
|
37040 | var max = idx.max();
|
37041 |
|
37042 | for (i = 0, ii = matrix._size.length; i < ii; i++) {
|
37043 | validateIndex(min[i], matrix._size[i]);
|
37044 | validateIndex(max[i], matrix._size[i]);
|
37045 | } // matrix arrays
|
37046 |
|
37047 |
|
37048 | var mvalues = matrix._values;
|
37049 | var mindex = matrix._index;
|
37050 | var mptr = matrix._ptr; // rows & columns dimensions for result matrix
|
37051 |
|
37052 | var rows = idx.dimension(0);
|
37053 | var columns = idx.dimension(1); // workspace & permutation vector
|
37054 |
|
37055 | var w = [];
|
37056 | var pv = []; // loop rows in resulting matrix
|
37057 |
|
37058 | rows.forEach(function (i, r) {
|
37059 | // update permutation vector
|
37060 | pv[i] = r[0]; // mark i in workspace
|
37061 |
|
37062 | w[i] = true;
|
37063 | }); // result matrix arrays
|
37064 |
|
37065 | var values = mvalues ? [] : undefined;
|
37066 | var index = [];
|
37067 | var ptr = []; // loop columns in result matrix
|
37068 |
|
37069 | columns.forEach(function (j) {
|
37070 | // update ptr
|
37071 | ptr.push(index.length); // loop values in column j
|
37072 |
|
37073 | for (k = mptr[j], kk = mptr[j + 1]; k < kk; k++) {
|
37074 | // row
|
37075 | i = mindex[k]; // check row is in result matrix
|
37076 |
|
37077 | if (w[i] === true) {
|
37078 | // push index
|
37079 | index.push(pv[i]); // check we need to process values
|
37080 |
|
37081 | if (values) {
|
37082 | values.push(mvalues[k]);
|
37083 | }
|
37084 | }
|
37085 | }
|
37086 | }); // update ptr
|
37087 |
|
37088 | ptr.push(index.length); // return matrix
|
37089 |
|
37090 | return new SparseMatrix({
|
37091 | values: values,
|
37092 | index: index,
|
37093 | ptr: ptr,
|
37094 | size: size,
|
37095 | datatype: matrix._datatype
|
37096 | });
|
37097 | }
|
37098 |
|
37099 | function _setsubset(matrix, index, submatrix, defaultValue) {
|
37100 | // check index
|
37101 | if (!index || index.isIndex !== true) {
|
37102 | throw new TypeError('Invalid index');
|
37103 | } // get index size and check whether the index contains a single value
|
37104 |
|
37105 |
|
37106 | var iSize = index.size();
|
37107 | var isScalar = index.isScalar(); // calculate the size of the submatrix, and convert it into an Array if needed
|
37108 |
|
37109 | var sSize;
|
37110 |
|
37111 | if (type.isMatrix(submatrix)) {
|
37112 | // submatrix size
|
37113 | sSize = submatrix.size(); // use array representation
|
37114 |
|
37115 | submatrix = submatrix.toArray();
|
37116 | } else {
|
37117 | // get submatrix size (array, scalar)
|
37118 | sSize = array.size(submatrix);
|
37119 | } // check index is a scalar
|
37120 |
|
37121 |
|
37122 | if (isScalar) {
|
37123 | // verify submatrix is a scalar
|
37124 | if (sSize.length !== 0) {
|
37125 | throw new TypeError('Scalar expected');
|
37126 | } // set value
|
37127 |
|
37128 |
|
37129 | matrix.set(index.min(), submatrix, defaultValue);
|
37130 | } else {
|
37131 | // validate dimensions, index size must be one or two dimensions
|
37132 | if (iSize.length !== 1 && iSize.length !== 2) {
|
37133 | throw new DimensionError(iSize.length, matrix._size.length, '<');
|
37134 | } // check submatrix and index have the same dimensions
|
37135 |
|
37136 |
|
37137 | if (sSize.length < iSize.length) {
|
37138 | // calculate number of missing outer dimensions
|
37139 | var i = 0;
|
37140 | var outer = 0;
|
37141 |
|
37142 | while (iSize[i] === 1 && sSize[i] === 1) {
|
37143 | i++;
|
37144 | }
|
37145 |
|
37146 | while (iSize[i] === 1) {
|
37147 | outer++;
|
37148 | i++;
|
37149 | } // unsqueeze both outer and inner dimensions
|
37150 |
|
37151 |
|
37152 | submatrix = array.unsqueeze(submatrix, iSize.length, outer, sSize);
|
37153 | } // check whether the size of the submatrix matches the index size
|
37154 |
|
37155 |
|
37156 | if (!object.deepEqual(iSize, sSize)) {
|
37157 | throw new DimensionError(iSize, sSize, '>');
|
37158 | } // offsets
|
37159 |
|
37160 |
|
37161 | var x0 = index.min()[0];
|
37162 | var y0 = index.min()[1]; // submatrix rows and columns
|
37163 |
|
37164 | var m = sSize[0];
|
37165 | var n = sSize[1]; // loop submatrix
|
37166 |
|
37167 | for (var x = 0; x < m; x++) {
|
37168 | // loop columns
|
37169 | for (var y = 0; y < n; y++) {
|
37170 | // value at i, j
|
37171 | var v = submatrix[x][y]; // invoke set (zero value will remove entry from matrix)
|
37172 |
|
37173 | matrix.set([x + x0, y + y0], v, defaultValue);
|
37174 | }
|
37175 | }
|
37176 | }
|
37177 |
|
37178 | return matrix;
|
37179 | }
|
37180 | /**
|
37181 | * Get a single element from the matrix.
|
37182 | * @memberof SparseMatrix
|
37183 | * @param {number[]} index Zero-based index
|
37184 | * @return {*} value
|
37185 | */
|
37186 |
|
37187 |
|
37188 | SparseMatrix.prototype.get = function (index) {
|
37189 | if (!isArray(index)) {
|
37190 | throw new TypeError('Array expected');
|
37191 | }
|
37192 |
|
37193 | if (index.length !== this._size.length) {
|
37194 | throw new DimensionError(index.length, this._size.length);
|
37195 | } // check it is a pattern matrix
|
37196 |
|
37197 |
|
37198 | if (!this._values) {
|
37199 | throw new Error('Cannot invoke get on a Pattern only matrix');
|
37200 | } // row and column
|
37201 |
|
37202 |
|
37203 | var i = index[0];
|
37204 | var j = index[1]; // check i, j are valid
|
37205 |
|
37206 | validateIndex(i, this._size[0]);
|
37207 | validateIndex(j, this._size[1]); // find value index
|
37208 |
|
37209 | var k = _getValueIndex(i, this._ptr[j], this._ptr[j + 1], this._index); // check k is prior to next column k and it is in the correct row
|
37210 |
|
37211 |
|
37212 | if (k < this._ptr[j + 1] && this._index[k] === i) {
|
37213 | return this._values[k];
|
37214 | }
|
37215 |
|
37216 | return 0;
|
37217 | };
|
37218 | /**
|
37219 | * Replace a single element in the matrix.
|
37220 | * @memberof SparseMatrix
|
37221 | * @param {number[]} index Zero-based index
|
37222 | * @param {*} v
|
37223 | * @param {*} [defaultValue] Default value, filled in on new entries when
|
37224 | * the matrix is resized. If not provided,
|
37225 | * new matrix elements will be set to zero.
|
37226 | * @return {SparseMatrix} self
|
37227 | */
|
37228 |
|
37229 |
|
37230 | SparseMatrix.prototype.set = function (index, v, defaultValue) {
|
37231 | if (!isArray(index)) {
|
37232 | throw new TypeError('Array expected');
|
37233 | }
|
37234 |
|
37235 | if (index.length !== this._size.length) {
|
37236 | throw new DimensionError(index.length, this._size.length);
|
37237 | } // check it is a pattern matrix
|
37238 |
|
37239 |
|
37240 | if (!this._values) {
|
37241 | throw new Error('Cannot invoke set on a Pattern only matrix');
|
37242 | } // row and column
|
37243 |
|
37244 |
|
37245 | var i = index[0];
|
37246 | var j = index[1]; // rows & columns
|
37247 |
|
37248 | var rows = this._size[0];
|
37249 | var columns = this._size[1]; // equal signature to use
|
37250 |
|
37251 | var eq = equalScalar; // zero value
|
37252 |
|
37253 | var zero = 0;
|
37254 |
|
37255 | if (isString(this._datatype)) {
|
37256 | // find signature that matches (datatype, datatype)
|
37257 | eq = typed.find(equalScalar, [this._datatype, this._datatype]) || equalScalar; // convert 0 to the same datatype
|
37258 |
|
37259 | zero = typed.convert(0, this._datatype);
|
37260 | } // check we need to resize matrix
|
37261 |
|
37262 |
|
37263 | if (i > rows - 1 || j > columns - 1) {
|
37264 | // resize matrix
|
37265 | _resize(this, Math.max(i + 1, rows), Math.max(j + 1, columns), defaultValue); // update rows & columns
|
37266 |
|
37267 |
|
37268 | rows = this._size[0];
|
37269 | columns = this._size[1];
|
37270 | } // check i, j are valid
|
37271 |
|
37272 |
|
37273 | validateIndex(i, rows);
|
37274 | validateIndex(j, columns); // find value index
|
37275 |
|
37276 | var k = _getValueIndex(i, this._ptr[j], this._ptr[j + 1], this._index); // check k is prior to next column k and it is in the correct row
|
37277 |
|
37278 |
|
37279 | if (k < this._ptr[j + 1] && this._index[k] === i) {
|
37280 | // check value != 0
|
37281 | if (!eq(v, zero)) {
|
37282 | // update value
|
37283 | this._values[k] = v;
|
37284 | } else {
|
37285 | // remove value from matrix
|
37286 | _remove(k, j, this._values, this._index, this._ptr);
|
37287 | }
|
37288 | } else {
|
37289 | // insert value @ (i, j)
|
37290 | _insert(k, i, j, v, this._values, this._index, this._ptr);
|
37291 | }
|
37292 |
|
37293 | return this;
|
37294 | };
|
37295 |
|
37296 | function _getValueIndex(i, top, bottom, index) {
|
37297 | // check row is on the bottom side
|
37298 | if (bottom - top === 0) {
|
37299 | return bottom;
|
37300 | } // loop rows [top, bottom[
|
37301 |
|
37302 |
|
37303 | for (var r = top; r < bottom; r++) {
|
37304 | // check we found value index
|
37305 | if (index[r] === i) {
|
37306 | return r;
|
37307 | }
|
37308 | } // we did not find row
|
37309 |
|
37310 |
|
37311 | return top;
|
37312 | }
|
37313 |
|
37314 | function _remove(k, j, values, index, ptr) {
|
37315 | // remove value @ k
|
37316 | values.splice(k, 1);
|
37317 | index.splice(k, 1); // update pointers
|
37318 |
|
37319 | for (var x = j + 1; x < ptr.length; x++) {
|
37320 | ptr[x]--;
|
37321 | }
|
37322 | }
|
37323 |
|
37324 | function _insert(k, i, j, v, values, index, ptr) {
|
37325 | // insert value
|
37326 | values.splice(k, 0, v); // update row for k
|
37327 |
|
37328 | index.splice(k, 0, i); // update column pointers
|
37329 |
|
37330 | for (var x = j + 1; x < ptr.length; x++) {
|
37331 | ptr[x]++;
|
37332 | }
|
37333 | }
|
37334 | /**
|
37335 | * Resize the matrix to the given size. Returns a copy of the matrix when
|
37336 | * `copy=true`, otherwise return the matrix itself (resize in place).
|
37337 | *
|
37338 | * @memberof SparseMatrix
|
37339 | * @param {number[]} size The new size the matrix should have.
|
37340 | * @param {*} [defaultValue=0] Default value, filled in on new entries.
|
37341 | * If not provided, the matrix elements will
|
37342 | * be filled with zeros.
|
37343 | * @param {boolean} [copy] Return a resized copy of the matrix
|
37344 | *
|
37345 | * @return {Matrix} The resized matrix
|
37346 | */
|
37347 |
|
37348 |
|
37349 | SparseMatrix.prototype.resize = function (size, defaultValue, copy) {
|
37350 | // validate arguments
|
37351 | if (!isArray(size)) {
|
37352 | throw new TypeError('Array expected');
|
37353 | }
|
37354 |
|
37355 | if (size.length !== 2) {
|
37356 | throw new Error('Only two dimensions matrix are supported');
|
37357 | } // check sizes
|
37358 |
|
37359 |
|
37360 | size.forEach(function (value) {
|
37361 | if (!number.isNumber(value) || !number.isInteger(value) || value < 0) {
|
37362 | throw new TypeError('Invalid size, must contain positive integers ' + '(size: ' + string.format(size) + ')');
|
37363 | }
|
37364 | }); // matrix to resize
|
37365 |
|
37366 | var m = copy ? this.clone() : this; // resize matrix
|
37367 |
|
37368 | return _resize(m, size[0], size[1], defaultValue);
|
37369 | };
|
37370 |
|
37371 | function _resize(matrix, rows, columns, defaultValue) {
|
37372 | // value to insert at the time of growing matrix
|
37373 | var value = defaultValue || 0; // equal signature to use
|
37374 |
|
37375 | var eq = equalScalar; // zero value
|
37376 |
|
37377 | var zero = 0;
|
37378 |
|
37379 | if (isString(matrix._datatype)) {
|
37380 | // find signature that matches (datatype, datatype)
|
37381 | eq = typed.find(equalScalar, [matrix._datatype, matrix._datatype]) || equalScalar; // convert 0 to the same datatype
|
37382 |
|
37383 | zero = typed.convert(0, matrix._datatype); // convert value to the same datatype
|
37384 |
|
37385 | value = typed.convert(value, matrix._datatype);
|
37386 | } // should we insert the value?
|
37387 |
|
37388 |
|
37389 | var ins = !eq(value, zero); // old columns and rows
|
37390 |
|
37391 | var r = matrix._size[0];
|
37392 | var c = matrix._size[1];
|
37393 | var i, j, k; // check we need to increase columns
|
37394 |
|
37395 | if (columns > c) {
|
37396 | // loop new columns
|
37397 | for (j = c; j < columns; j++) {
|
37398 | // update matrix._ptr for current column
|
37399 | matrix._ptr[j] = matrix._values.length; // check we need to insert matrix._values
|
37400 |
|
37401 | if (ins) {
|
37402 | // loop rows
|
37403 | for (i = 0; i < r; i++) {
|
37404 | // add new matrix._values
|
37405 | matrix._values.push(value); // update matrix._index
|
37406 |
|
37407 |
|
37408 | matrix._index.push(i);
|
37409 | }
|
37410 | }
|
37411 | } // store number of matrix._values in matrix._ptr
|
37412 |
|
37413 |
|
37414 | matrix._ptr[columns] = matrix._values.length;
|
37415 | } else if (columns < c) {
|
37416 | // truncate matrix._ptr
|
37417 | matrix._ptr.splice(columns + 1, c - columns); // truncate matrix._values and matrix._index
|
37418 |
|
37419 |
|
37420 | matrix._values.splice(matrix._ptr[columns], matrix._values.length);
|
37421 |
|
37422 | matrix._index.splice(matrix._ptr[columns], matrix._index.length);
|
37423 | } // update columns
|
37424 |
|
37425 |
|
37426 | c = columns; // check we need to increase rows
|
37427 |
|
37428 | if (rows > r) {
|
37429 | // check we have to insert values
|
37430 | if (ins) {
|
37431 | // inserts
|
37432 | var n = 0; // loop columns
|
37433 |
|
37434 | for (j = 0; j < c; j++) {
|
37435 | // update matrix._ptr for current column
|
37436 | matrix._ptr[j] = matrix._ptr[j] + n; // where to insert matrix._values
|
37437 |
|
37438 | k = matrix._ptr[j + 1] + n; // pointer
|
37439 |
|
37440 | var p = 0; // loop new rows, initialize pointer
|
37441 |
|
37442 | for (i = r; i < rows; i++, p++) {
|
37443 | // add value
|
37444 | matrix._values.splice(k + p, 0, value); // update matrix._index
|
37445 |
|
37446 |
|
37447 | matrix._index.splice(k + p, 0, i); // increment inserts
|
37448 |
|
37449 |
|
37450 | n++;
|
37451 | }
|
37452 | } // store number of matrix._values in matrix._ptr
|
37453 |
|
37454 |
|
37455 | matrix._ptr[c] = matrix._values.length;
|
37456 | }
|
37457 | } else if (rows < r) {
|
37458 | // deletes
|
37459 | var d = 0; // loop columns
|
37460 |
|
37461 | for (j = 0; j < c; j++) {
|
37462 | // update matrix._ptr for current column
|
37463 | matrix._ptr[j] = matrix._ptr[j] - d; // where matrix._values start for next column
|
37464 |
|
37465 | var k0 = matrix._ptr[j];
|
37466 | var k1 = matrix._ptr[j + 1] - d; // loop matrix._index
|
37467 |
|
37468 | for (k = k0; k < k1; k++) {
|
37469 | // row
|
37470 | i = matrix._index[k]; // check we need to delete value and matrix._index
|
37471 |
|
37472 | if (i > rows - 1) {
|
37473 | // remove value
|
37474 | matrix._values.splice(k, 1); // remove item from matrix._index
|
37475 |
|
37476 |
|
37477 | matrix._index.splice(k, 1); // increase deletes
|
37478 |
|
37479 |
|
37480 | d++;
|
37481 | }
|
37482 | }
|
37483 | } // update matrix._ptr for current column
|
37484 |
|
37485 |
|
37486 | matrix._ptr[j] = matrix._values.length;
|
37487 | } // update matrix._size
|
37488 |
|
37489 |
|
37490 | matrix._size[0] = rows;
|
37491 | matrix._size[1] = columns; // return matrix
|
37492 |
|
37493 | return matrix;
|
37494 | }
|
37495 | /**
|
37496 | * Reshape the matrix to the given size. Returns a copy of the matrix when
|
37497 | * `copy=true`, otherwise return the matrix itself (reshape in place).
|
37498 | *
|
37499 | * NOTE: This might be better suited to copy by default, instead of modifying
|
37500 | * in place. For now, it operates in place to remain consistent with
|
37501 | * resize().
|
37502 | *
|
37503 | * @memberof SparseMatrix
|
37504 | * @param {number[]} size The new size the matrix should have.
|
37505 | * @param {boolean} [copy] Return a reshaped copy of the matrix
|
37506 | *
|
37507 | * @return {Matrix} The reshaped matrix
|
37508 | */
|
37509 |
|
37510 |
|
37511 | SparseMatrix.prototype.reshape = function (size, copy) {
|
37512 | // validate arguments
|
37513 | if (!isArray(size)) {
|
37514 | throw new TypeError('Array expected');
|
37515 | }
|
37516 |
|
37517 | if (size.length !== 2) {
|
37518 | throw new Error('Sparse matrices can only be reshaped in two dimensions');
|
37519 | } // check sizes
|
37520 |
|
37521 |
|
37522 | size.forEach(function (value) {
|
37523 | if (!number.isNumber(value) || !number.isInteger(value) || value < 0) {
|
37524 | throw new TypeError('Invalid size, must contain positive integers ' + '(size: ' + string.format(size) + ')');
|
37525 | }
|
37526 | }); // m * n must not change
|
37527 |
|
37528 | if (this._size[0] * this._size[1] !== size[0] * size[1]) {
|
37529 | throw new Error('Reshaping sparse matrix will result in the wrong number of elements');
|
37530 | } // matrix to reshape
|
37531 |
|
37532 |
|
37533 | var m = copy ? this.clone() : this; // return unchanged if the same shape
|
37534 |
|
37535 | if (this._size[0] === size[0] && this._size[1] === size[1]) {
|
37536 | return m;
|
37537 | } // Convert to COO format (generate a column index)
|
37538 |
|
37539 |
|
37540 | var colIndex = [];
|
37541 |
|
37542 | for (var i = 0; i < m._ptr.length; i++) {
|
37543 | for (var j = 0; j < m._ptr[i + 1] - m._ptr[i]; j++) {
|
37544 | colIndex.push(i);
|
37545 | }
|
37546 | } // Clone the values array
|
37547 |
|
37548 |
|
37549 | var values = m._values.slice(); // Clone the row index array
|
37550 |
|
37551 |
|
37552 | var rowIndex = m._index.slice(); // Transform the (row, column) indices
|
37553 |
|
37554 |
|
37555 | for (var _i = 0; _i < m._index.length; _i++) {
|
37556 | var r1 = rowIndex[_i];
|
37557 | var c1 = colIndex[_i];
|
37558 | var flat = r1 * m._size[1] + c1;
|
37559 | colIndex[_i] = flat % size[1];
|
37560 | rowIndex[_i] = Math.floor(flat / size[1]);
|
37561 | } // Now reshaping is supposed to preserve the row-major order, BUT these sparse matrices are stored
|
37562 | // in column-major order, so we have to reorder the value array now. One option is to use a multisort,
|
37563 | // sorting several arrays based on some other array.
|
37564 | // OR, we could easily just:
|
37565 | // 1. Remove all values from the matrix
|
37566 |
|
37567 |
|
37568 | m._values.length = 0;
|
37569 | m._index.length = 0;
|
37570 | m._ptr.length = size[1] + 1;
|
37571 | m._size = size.slice();
|
37572 |
|
37573 | for (var _i2 = 0; _i2 < m._ptr.length; _i2++) {
|
37574 | m._ptr[_i2] = 0;
|
37575 | } // 2. Re-insert all elements in the proper order (simplified code from SparseMatrix.prototype.set)
|
37576 | // This step is probably the most time-consuming
|
37577 |
|
37578 |
|
37579 | for (var h = 0; h < values.length; h++) {
|
37580 | var _i3 = rowIndex[h];
|
37581 | var _j = colIndex[h];
|
37582 | var v = values[h];
|
37583 |
|
37584 | var k = _getValueIndex(_i3, m._ptr[_j], m._ptr[_j + 1], m._index);
|
37585 |
|
37586 | _insert(k, _i3, _j, v, m._values, m._index, m._ptr);
|
37587 | } // The value indices are inserted out of order, but apparently that's... still OK?
|
37588 |
|
37589 |
|
37590 | return m;
|
37591 | };
|
37592 | /**
|
37593 | * Create a clone of the matrix
|
37594 | * @memberof SparseMatrix
|
37595 | * @return {SparseMatrix} clone
|
37596 | */
|
37597 |
|
37598 |
|
37599 | SparseMatrix.prototype.clone = function () {
|
37600 | var m = new SparseMatrix({
|
37601 | values: this._values ? object.clone(this._values) : undefined,
|
37602 | index: object.clone(this._index),
|
37603 | ptr: object.clone(this._ptr),
|
37604 | size: object.clone(this._size),
|
37605 | datatype: this._datatype
|
37606 | });
|
37607 | return m;
|
37608 | };
|
37609 | /**
|
37610 | * Retrieve the size of the matrix.
|
37611 | * @memberof SparseMatrix
|
37612 | * @returns {number[]} size
|
37613 | */
|
37614 |
|
37615 |
|
37616 | SparseMatrix.prototype.size = function () {
|
37617 | return this._size.slice(0); // copy the Array
|
37618 | };
|
37619 | /**
|
37620 | * Create a new matrix with the results of the callback function executed on
|
37621 | * each entry of the matrix.
|
37622 | * @memberof SparseMatrix
|
37623 | * @param {Function} callback The callback function is invoked with three
|
37624 | * parameters: the value of the element, the index
|
37625 | * of the element, and the Matrix being traversed.
|
37626 | * @param {boolean} [skipZeros] Invoke callback function for non-zero values only.
|
37627 | *
|
37628 | * @return {SparseMatrix} matrix
|
37629 | */
|
37630 |
|
37631 |
|
37632 | SparseMatrix.prototype.map = function (callback, skipZeros) {
|
37633 | // check it is a pattern matrix
|
37634 | if (!this._values) {
|
37635 | throw new Error('Cannot invoke map on a Pattern only matrix');
|
37636 | } // matrix instance
|
37637 |
|
37638 |
|
37639 | var me = this; // rows and columns
|
37640 |
|
37641 | var rows = this._size[0];
|
37642 | var columns = this._size[1]; // invoke callback
|
37643 |
|
37644 | var invoke = function invoke(v, i, j) {
|
37645 | // invoke callback
|
37646 | return callback(v, [i, j], me);
|
37647 | }; // invoke _map
|
37648 |
|
37649 |
|
37650 | return _map(this, 0, rows - 1, 0, columns - 1, invoke, skipZeros);
|
37651 | };
|
37652 | /**
|
37653 | * Create a new matrix with the results of the callback function executed on the interval
|
37654 | * [minRow..maxRow, minColumn..maxColumn].
|
37655 | */
|
37656 |
|
37657 |
|
37658 | function _map(matrix, minRow, maxRow, minColumn, maxColumn, callback, skipZeros) {
|
37659 | // result arrays
|
37660 | var values = [];
|
37661 | var index = [];
|
37662 | var ptr = []; // equal signature to use
|
37663 |
|
37664 | var eq = equalScalar; // zero value
|
37665 |
|
37666 | var zero = 0;
|
37667 |
|
37668 | if (isString(matrix._datatype)) {
|
37669 | // find signature that matches (datatype, datatype)
|
37670 | eq = typed.find(equalScalar, [matrix._datatype, matrix._datatype]) || equalScalar; // convert 0 to the same datatype
|
37671 |
|
37672 | zero = typed.convert(0, matrix._datatype);
|
37673 | } // invoke callback
|
37674 |
|
37675 |
|
37676 | var invoke = function invoke(v, x, y) {
|
37677 | // invoke callback
|
37678 | v = callback(v, x, y); // check value != 0
|
37679 |
|
37680 | if (!eq(v, zero)) {
|
37681 | // store value
|
37682 | values.push(v); // index
|
37683 |
|
37684 | index.push(x);
|
37685 | }
|
37686 | }; // loop columns
|
37687 |
|
37688 |
|
37689 | for (var j = minColumn; j <= maxColumn; j++) {
|
37690 | // store pointer to values index
|
37691 | ptr.push(values.length); // k0 <= k < k1 where k0 = _ptr[j] && k1 = _ptr[j+1]
|
37692 |
|
37693 | var k0 = matrix._ptr[j];
|
37694 | var k1 = matrix._ptr[j + 1];
|
37695 |
|
37696 | if (skipZeros) {
|
37697 | // loop k within [k0, k1[
|
37698 | for (var k = k0; k < k1; k++) {
|
37699 | // row index
|
37700 | var i = matrix._index[k]; // check i is in range
|
37701 |
|
37702 | if (i >= minRow && i <= maxRow) {
|
37703 | // value @ k
|
37704 | invoke(matrix._values[k], i - minRow, j - minColumn);
|
37705 | }
|
37706 | }
|
37707 | } else {
|
37708 | // create a cache holding all defined values
|
37709 | var _values = {};
|
37710 |
|
37711 | for (var _k = k0; _k < k1; _k++) {
|
37712 | var _i4 = matrix._index[_k];
|
37713 | _values[_i4] = matrix._values[_k];
|
37714 | } // loop over all rows (indexes can be unordered so we can't use that),
|
37715 | // and either read the value or zero
|
37716 |
|
37717 |
|
37718 | for (var _i5 = minRow; _i5 <= maxRow; _i5++) {
|
37719 | var value = _i5 in _values ? _values[_i5] : 0;
|
37720 | invoke(value, _i5 - minRow, j - minColumn);
|
37721 | }
|
37722 | }
|
37723 | } // store number of values in ptr
|
37724 |
|
37725 |
|
37726 | ptr.push(values.length); // return sparse matrix
|
37727 |
|
37728 | return new SparseMatrix({
|
37729 | values: values,
|
37730 | index: index,
|
37731 | ptr: ptr,
|
37732 | size: [maxRow - minRow + 1, maxColumn - minColumn + 1]
|
37733 | });
|
37734 | }
|
37735 | /**
|
37736 | * Execute a callback function on each entry of the matrix.
|
37737 | * @memberof SparseMatrix
|
37738 | * @param {Function} callback The callback function is invoked with three
|
37739 | * parameters: the value of the element, the index
|
37740 | * of the element, and the Matrix being traversed.
|
37741 | * @param {boolean} [skipZeros] Invoke callback function for non-zero values only.
|
37742 | */
|
37743 |
|
37744 |
|
37745 | SparseMatrix.prototype.forEach = function (callback, skipZeros) {
|
37746 | // check it is a pattern matrix
|
37747 | if (!this._values) {
|
37748 | throw new Error('Cannot invoke forEach on a Pattern only matrix');
|
37749 | } // matrix instance
|
37750 |
|
37751 |
|
37752 | var me = this; // rows and columns
|
37753 |
|
37754 | var rows = this._size[0];
|
37755 | var columns = this._size[1]; // loop columns
|
37756 |
|
37757 | for (var j = 0; j < columns; j++) {
|
37758 | // k0 <= k < k1 where k0 = _ptr[j] && k1 = _ptr[j+1]
|
37759 | var k0 = this._ptr[j];
|
37760 | var k1 = this._ptr[j + 1];
|
37761 |
|
37762 | if (skipZeros) {
|
37763 | // loop k within [k0, k1[
|
37764 | for (var k = k0; k < k1; k++) {
|
37765 | // row index
|
37766 | var i = this._index[k]; // value @ k
|
37767 |
|
37768 | callback(this._values[k], [i, j], me);
|
37769 | }
|
37770 | } else {
|
37771 | // create a cache holding all defined values
|
37772 | var values = {};
|
37773 |
|
37774 | for (var _k2 = k0; _k2 < k1; _k2++) {
|
37775 | var _i6 = this._index[_k2];
|
37776 | values[_i6] = this._values[_k2];
|
37777 | } // loop over all rows (indexes can be unordered so we can't use that),
|
37778 | // and either read the value or zero
|
37779 |
|
37780 |
|
37781 | for (var _i7 = 0; _i7 < rows; _i7++) {
|
37782 | var value = _i7 in values ? values[_i7] : 0;
|
37783 | callback(value, [_i7, j], me);
|
37784 | }
|
37785 | }
|
37786 | }
|
37787 | };
|
37788 | /**
|
37789 | * Create an Array with a copy of the data of the SparseMatrix
|
37790 | * @memberof SparseMatrix
|
37791 | * @returns {Array} array
|
37792 | */
|
37793 |
|
37794 |
|
37795 | SparseMatrix.prototype.toArray = function () {
|
37796 | return _toArray(this._values, this._index, this._ptr, this._size, true);
|
37797 | };
|
37798 | /**
|
37799 | * Get the primitive value of the SparseMatrix: a two dimensions array
|
37800 | * @memberof SparseMatrix
|
37801 | * @returns {Array} array
|
37802 | */
|
37803 |
|
37804 |
|
37805 | SparseMatrix.prototype.valueOf = function () {
|
37806 | return _toArray(this._values, this._index, this._ptr, this._size, false);
|
37807 | };
|
37808 |
|
37809 | function _toArray(values, index, ptr, size, copy) {
|
37810 | // rows and columns
|
37811 | var rows = size[0];
|
37812 | var columns = size[1]; // result
|
37813 |
|
37814 | var a = []; // vars
|
37815 |
|
37816 | var i, j; // initialize array
|
37817 |
|
37818 | for (i = 0; i < rows; i++) {
|
37819 | a[i] = [];
|
37820 |
|
37821 | for (j = 0; j < columns; j++) {
|
37822 | a[i][j] = 0;
|
37823 | }
|
37824 | } // loop columns
|
37825 |
|
37826 |
|
37827 | for (j = 0; j < columns; j++) {
|
37828 | // k0 <= k < k1 where k0 = _ptr[j] && k1 = _ptr[j+1]
|
37829 | var k0 = ptr[j];
|
37830 | var k1 = ptr[j + 1]; // loop k within [k0, k1[
|
37831 |
|
37832 | for (var k = k0; k < k1; k++) {
|
37833 | // row index
|
37834 | i = index[k]; // set value (use one for pattern matrix)
|
37835 |
|
37836 | a[i][j] = values ? copy ? object.clone(values[k]) : values[k] : 1;
|
37837 | }
|
37838 | }
|
37839 |
|
37840 | return a;
|
37841 | }
|
37842 | /**
|
37843 | * Get a string representation of the matrix, with optional formatting options.
|
37844 | * @memberof SparseMatrix
|
37845 | * @param {Object | number | Function} [options] Formatting options. See
|
37846 | * lib/utils/number:format for a
|
37847 | * description of the available
|
37848 | * options.
|
37849 | * @returns {string} str
|
37850 | */
|
37851 |
|
37852 |
|
37853 | SparseMatrix.prototype.format = function (options) {
|
37854 | // rows and columns
|
37855 | var rows = this._size[0];
|
37856 | var columns = this._size[1]; // density
|
37857 |
|
37858 | var density = this.density(); // rows & columns
|
37859 |
|
37860 | var str = 'Sparse Matrix [' + string.format(rows, options) + ' x ' + string.format(columns, options) + '] density: ' + string.format(density, options) + '\n'; // loop columns
|
37861 |
|
37862 | for (var j = 0; j < columns; j++) {
|
37863 | // k0 <= k < k1 where k0 = _ptr[j] && k1 = _ptr[j+1]
|
37864 | var k0 = this._ptr[j];
|
37865 | var k1 = this._ptr[j + 1]; // loop k within [k0, k1[
|
37866 |
|
37867 | for (var k = k0; k < k1; k++) {
|
37868 | // row index
|
37869 | var i = this._index[k]; // append value
|
37870 |
|
37871 | str += '\n (' + string.format(i, options) + ', ' + string.format(j, options) + ') ==> ' + (this._values ? string.format(this._values[k], options) : 'X');
|
37872 | }
|
37873 | }
|
37874 |
|
37875 | return str;
|
37876 | };
|
37877 | /**
|
37878 | * Get a string representation of the matrix
|
37879 | * @memberof SparseMatrix
|
37880 | * @returns {string} str
|
37881 | */
|
37882 |
|
37883 |
|
37884 | SparseMatrix.prototype.toString = function () {
|
37885 | return string.format(this.toArray());
|
37886 | };
|
37887 | /**
|
37888 | * Get a JSON representation of the matrix
|
37889 | * @memberof SparseMatrix
|
37890 | * @returns {Object}
|
37891 | */
|
37892 |
|
37893 |
|
37894 | SparseMatrix.prototype.toJSON = function () {
|
37895 | return {
|
37896 | mathjs: 'SparseMatrix',
|
37897 | values: this._values,
|
37898 | index: this._index,
|
37899 | ptr: this._ptr,
|
37900 | size: this._size,
|
37901 | datatype: this._datatype
|
37902 | };
|
37903 | };
|
37904 | /**
|
37905 | * Get the kth Matrix diagonal.
|
37906 | *
|
37907 | * @memberof SparseMatrix
|
37908 | * @param {number | BigNumber} [k=0] The kth diagonal where the vector will retrieved.
|
37909 | *
|
37910 | * @returns {Matrix} The matrix vector with the diagonal values.
|
37911 | */
|
37912 |
|
37913 |
|
37914 | SparseMatrix.prototype.diagonal = function (k) {
|
37915 | // validate k if any
|
37916 | if (k) {
|
37917 | // convert BigNumber to a number
|
37918 | if (type.isBigNumber(k)) {
|
37919 | k = k.toNumber();
|
37920 | } // is must be an integer
|
37921 |
|
37922 |
|
37923 | if (!isNumber(k) || !isInteger(k)) {
|
37924 | throw new TypeError('The parameter k must be an integer number');
|
37925 | }
|
37926 | } else {
|
37927 | // default value
|
37928 | k = 0;
|
37929 | }
|
37930 |
|
37931 | var kSuper = k > 0 ? k : 0;
|
37932 | var kSub = k < 0 ? -k : 0; // rows & columns
|
37933 |
|
37934 | var rows = this._size[0];
|
37935 | var columns = this._size[1]; // number diagonal values
|
37936 |
|
37937 | var n = Math.min(rows - kSub, columns - kSuper); // diagonal arrays
|
37938 |
|
37939 | var values = [];
|
37940 | var index = [];
|
37941 | var ptr = []; // initial ptr value
|
37942 |
|
37943 | ptr[0] = 0; // loop columns
|
37944 |
|
37945 | for (var j = kSuper; j < columns && values.length < n; j++) {
|
37946 | // k0 <= k < k1 where k0 = _ptr[j] && k1 = _ptr[j+1]
|
37947 | var k0 = this._ptr[j];
|
37948 | var k1 = this._ptr[j + 1]; // loop x within [k0, k1[
|
37949 |
|
37950 | for (var x = k0; x < k1; x++) {
|
37951 | // row index
|
37952 | var i = this._index[x]; // check row
|
37953 |
|
37954 | if (i === j - kSuper + kSub) {
|
37955 | // value on this column
|
37956 | values.push(this._values[x]); // store row
|
37957 |
|
37958 | index[values.length - 1] = i - kSub; // exit loop
|
37959 |
|
37960 | break;
|
37961 | }
|
37962 | }
|
37963 | } // close ptr
|
37964 |
|
37965 |
|
37966 | ptr.push(values.length); // return matrix
|
37967 |
|
37968 | return new SparseMatrix({
|
37969 | values: values,
|
37970 | index: index,
|
37971 | ptr: ptr,
|
37972 | size: [n, 1]
|
37973 | });
|
37974 | };
|
37975 | /**
|
37976 | * Generate a matrix from a JSON object
|
37977 | * @memberof SparseMatrix
|
37978 | * @param {Object} json An object structured like
|
37979 | * `{"mathjs": "SparseMatrix", "values": [], "index": [], "ptr": [], "size": []}`,
|
37980 | * where mathjs is optional
|
37981 | * @returns {SparseMatrix}
|
37982 | */
|
37983 |
|
37984 |
|
37985 | SparseMatrix.fromJSON = function (json) {
|
37986 | return new SparseMatrix(json);
|
37987 | };
|
37988 | /**
|
37989 | * Create a diagonal matrix.
|
37990 | *
|
37991 | * @memberof SparseMatrix
|
37992 | * @param {Array} size The matrix size.
|
37993 | * @param {number | Array | Matrix } value The values for the diagonal.
|
37994 | * @param {number | BigNumber} [k=0] The kth diagonal where the vector will be filled in.
|
37995 | * @param {number} [defaultValue] The default value for non-diagonal
|
37996 | * @param {string} [datatype] The Matrix datatype, values must be of this datatype.
|
37997 | *
|
37998 | * @returns {SparseMatrix}
|
37999 | */
|
38000 |
|
38001 |
|
38002 | SparseMatrix.diagonal = function (size, value, k, defaultValue, datatype) {
|
38003 | if (!isArray(size)) {
|
38004 | throw new TypeError('Array expected, size parameter');
|
38005 | }
|
38006 |
|
38007 | if (size.length !== 2) {
|
38008 | throw new Error('Only two dimensions matrix are supported');
|
38009 | } // map size & validate
|
38010 |
|
38011 |
|
38012 | size = size.map(function (s) {
|
38013 | // check it is a big number
|
38014 | if (type.isBigNumber(s)) {
|
38015 | // convert it
|
38016 | s = s.toNumber();
|
38017 | } // validate arguments
|
38018 |
|
38019 |
|
38020 | if (!isNumber(s) || !isInteger(s) || s < 1) {
|
38021 | throw new Error('Size values must be positive integers');
|
38022 | }
|
38023 |
|
38024 | return s;
|
38025 | }); // validate k if any
|
38026 |
|
38027 | if (k) {
|
38028 | // convert BigNumber to a number
|
38029 | if (type.isBigNumber(k)) {
|
38030 | k = k.toNumber();
|
38031 | } // is must be an integer
|
38032 |
|
38033 |
|
38034 | if (!isNumber(k) || !isInteger(k)) {
|
38035 | throw new TypeError('The parameter k must be an integer number');
|
38036 | }
|
38037 | } else {
|
38038 | // default value
|
38039 | k = 0;
|
38040 | } // equal signature to use
|
38041 |
|
38042 |
|
38043 | var eq = equalScalar; // zero value
|
38044 |
|
38045 | var zero = 0;
|
38046 |
|
38047 | if (isString(datatype)) {
|
38048 | // find signature that matches (datatype, datatype)
|
38049 | eq = typed.find(equalScalar, [datatype, datatype]) || equalScalar; // convert 0 to the same datatype
|
38050 |
|
38051 | zero = typed.convert(0, datatype);
|
38052 | }
|
38053 |
|
38054 | var kSuper = k > 0 ? k : 0;
|
38055 | var kSub = k < 0 ? -k : 0; // rows and columns
|
38056 |
|
38057 | var rows = size[0];
|
38058 | var columns = size[1]; // number of non-zero items
|
38059 |
|
38060 | var n = Math.min(rows - kSub, columns - kSuper); // value extraction function
|
38061 |
|
38062 | var _value; // check value
|
38063 |
|
38064 |
|
38065 | if (isArray(value)) {
|
38066 | // validate array
|
38067 | if (value.length !== n) {
|
38068 | // number of values in array must be n
|
38069 | throw new Error('Invalid value array length');
|
38070 | } // define function
|
38071 |
|
38072 |
|
38073 | _value = function _value(i) {
|
38074 | // return value @ i
|
38075 | return value[i];
|
38076 | };
|
38077 | } else if (type.isMatrix(value)) {
|
38078 | // matrix size
|
38079 | var ms = value.size(); // validate matrix
|
38080 |
|
38081 | if (ms.length !== 1 || ms[0] !== n) {
|
38082 | // number of values in array must be n
|
38083 | throw new Error('Invalid matrix length');
|
38084 | } // define function
|
38085 |
|
38086 |
|
38087 | _value = function _value(i) {
|
38088 | // return value @ i
|
38089 | return value.get([i]);
|
38090 | };
|
38091 | } else {
|
38092 | // define function
|
38093 | _value = function _value() {
|
38094 | // return value
|
38095 | return value;
|
38096 | };
|
38097 | } // create arrays
|
38098 |
|
38099 |
|
38100 | var values = [];
|
38101 | var index = [];
|
38102 | var ptr = []; // loop items
|
38103 |
|
38104 | for (var j = 0; j < columns; j++) {
|
38105 | // number of rows with value
|
38106 | ptr.push(values.length); // diagonal index
|
38107 |
|
38108 | var i = j - kSuper; // check we need to set diagonal value
|
38109 |
|
38110 | if (i >= 0 && i < n) {
|
38111 | // get value @ i
|
38112 | var v = _value(i); // check for zero
|
38113 |
|
38114 |
|
38115 | if (!eq(v, zero)) {
|
38116 | // column
|
38117 | index.push(i + kSub); // add value
|
38118 |
|
38119 | values.push(v);
|
38120 | }
|
38121 | }
|
38122 | } // last value should be number of values
|
38123 |
|
38124 |
|
38125 | ptr.push(values.length); // create SparseMatrix
|
38126 |
|
38127 | return new SparseMatrix({
|
38128 | values: values,
|
38129 | index: index,
|
38130 | ptr: ptr,
|
38131 | size: [rows, columns]
|
38132 | });
|
38133 | };
|
38134 | /**
|
38135 | * Swap rows i and j in Matrix.
|
38136 | *
|
38137 | * @memberof SparseMatrix
|
38138 | * @param {number} i Matrix row index 1
|
38139 | * @param {number} j Matrix row index 2
|
38140 | *
|
38141 | * @return {Matrix} The matrix reference
|
38142 | */
|
38143 |
|
38144 |
|
38145 | SparseMatrix.prototype.swapRows = function (i, j) {
|
38146 | // check index
|
38147 | if (!isNumber(i) || !isInteger(i) || !isNumber(j) || !isInteger(j)) {
|
38148 | throw new Error('Row index must be positive integers');
|
38149 | } // check dimensions
|
38150 |
|
38151 |
|
38152 | if (this._size.length !== 2) {
|
38153 | throw new Error('Only two dimensional matrix is supported');
|
38154 | } // validate index
|
38155 |
|
38156 |
|
38157 | validateIndex(i, this._size[0]);
|
38158 | validateIndex(j, this._size[0]); // swap rows
|
38159 |
|
38160 | SparseMatrix._swapRows(i, j, this._size[1], this._values, this._index, this._ptr); // return current instance
|
38161 |
|
38162 |
|
38163 | return this;
|
38164 | };
|
38165 | /**
|
38166 | * Loop rows with data in column j.
|
38167 | *
|
38168 | * @param {number} j Column
|
38169 | * @param {Array} values Matrix values
|
38170 | * @param {Array} index Matrix row indeces
|
38171 | * @param {Array} ptr Matrix column pointers
|
38172 | * @param {Function} callback Callback function invoked for every row in column j
|
38173 | */
|
38174 |
|
38175 |
|
38176 | SparseMatrix._forEachRow = function (j, values, index, ptr, callback) {
|
38177 | // indeces for column j
|
38178 | var k0 = ptr[j];
|
38179 | var k1 = ptr[j + 1]; // loop
|
38180 |
|
38181 | for (var k = k0; k < k1; k++) {
|
38182 | // invoke callback
|
38183 | callback(index[k], values[k]);
|
38184 | }
|
38185 | };
|
38186 | /**
|
38187 | * Swap rows x and y in Sparse Matrix data structures.
|
38188 | *
|
38189 | * @param {number} x Matrix row index 1
|
38190 | * @param {number} y Matrix row index 2
|
38191 | * @param {number} columns Number of columns in matrix
|
38192 | * @param {Array} values Matrix values
|
38193 | * @param {Array} index Matrix row indeces
|
38194 | * @param {Array} ptr Matrix column pointers
|
38195 | */
|
38196 |
|
38197 |
|
38198 | SparseMatrix._swapRows = function (x, y, columns, values, index, ptr) {
|
38199 | // loop columns
|
38200 | for (var j = 0; j < columns; j++) {
|
38201 | // k0 <= k < k1 where k0 = _ptr[j] && k1 = _ptr[j+1]
|
38202 | var k0 = ptr[j];
|
38203 | var k1 = ptr[j + 1]; // find value index @ x
|
38204 |
|
38205 | var kx = _getValueIndex(x, k0, k1, index); // find value index @ x
|
38206 |
|
38207 |
|
38208 | var ky = _getValueIndex(y, k0, k1, index); // check both rows exist in matrix
|
38209 |
|
38210 |
|
38211 | if (kx < k1 && ky < k1 && index[kx] === x && index[ky] === y) {
|
38212 | // swap values (check for pattern matrix)
|
38213 | if (values) {
|
38214 | var v = values[kx];
|
38215 | values[kx] = values[ky];
|
38216 | values[ky] = v;
|
38217 | } // next column
|
38218 |
|
38219 |
|
38220 | continue;
|
38221 | } // check x row exist & no y row
|
38222 |
|
38223 |
|
38224 | if (kx < k1 && index[kx] === x && (ky >= k1 || index[ky] !== y)) {
|
38225 | // value @ x (check for pattern matrix)
|
38226 | var vx = values ? values[kx] : undefined; // insert value @ y
|
38227 |
|
38228 | index.splice(ky, 0, y);
|
38229 |
|
38230 | if (values) {
|
38231 | values.splice(ky, 0, vx);
|
38232 | } // remove value @ x (adjust array index if needed)
|
38233 |
|
38234 |
|
38235 | index.splice(ky <= kx ? kx + 1 : kx, 1);
|
38236 |
|
38237 | if (values) {
|
38238 | values.splice(ky <= kx ? kx + 1 : kx, 1);
|
38239 | } // next column
|
38240 |
|
38241 |
|
38242 | continue;
|
38243 | } // check y row exist & no x row
|
38244 |
|
38245 |
|
38246 | if (ky < k1 && index[ky] === y && (kx >= k1 || index[kx] !== x)) {
|
38247 | // value @ y (check for pattern matrix)
|
38248 | var vy = values ? values[ky] : undefined; // insert value @ x
|
38249 |
|
38250 | index.splice(kx, 0, x);
|
38251 |
|
38252 | if (values) {
|
38253 | values.splice(kx, 0, vy);
|
38254 | } // remove value @ y (adjust array index if needed)
|
38255 |
|
38256 |
|
38257 | index.splice(kx <= ky ? ky + 1 : ky, 1);
|
38258 |
|
38259 | if (values) {
|
38260 | values.splice(kx <= ky ? ky + 1 : ky, 1);
|
38261 | }
|
38262 | }
|
38263 | }
|
38264 | }; // register this type in the base class Matrix
|
38265 |
|
38266 |
|
38267 | type.Matrix._storage.sparse = SparseMatrix;
|
38268 | return SparseMatrix;
|
38269 | }
|
38270 |
|
38271 | exports.name = 'SparseMatrix';
|
38272 | exports.path = 'type';
|
38273 | exports.factory = factory;
|
38274 | exports.lazy = false; // no lazy loading, as we alter type.Matrix._storage
|
38275 |
|
38276 | /***/ }),
|
38277 | /* 187 */
|
38278 | /***/ (function(module, exports, __webpack_require__) {
|
38279 |
|
38280 | "use strict";
|
38281 |
|
38282 |
|
38283 | function factory(type, config, load) {
|
38284 | var add = load(__webpack_require__(14));
|
38285 | var equalScalar = load(__webpack_require__(11));
|
38286 | /**
|
38287 | * An ordered Sparse Accumulator is a representation for a sparse vector that includes a dense array
|
38288 | * of the vector elements and an ordered list of non-zero elements.
|
38289 | */
|
38290 |
|
38291 | function Spa() {
|
38292 | if (!(this instanceof Spa)) {
|
38293 | throw new SyntaxError('Constructor must be called with the new operator');
|
38294 | } // allocate vector, TODO use typed arrays
|
38295 |
|
38296 |
|
38297 | this._values = [];
|
38298 | this._heap = new type.FibonacciHeap();
|
38299 | }
|
38300 | /**
|
38301 | * Attach type information
|
38302 | */
|
38303 |
|
38304 |
|
38305 | Spa.prototype.type = 'Spa';
|
38306 | Spa.prototype.isSpa = true;
|
38307 | /**
|
38308 | * Set the value for index i.
|
38309 | *
|
38310 | * @param {number} i The index
|
38311 | * @param {number | BigNumber | Complex} The value at index i
|
38312 | */
|
38313 |
|
38314 | Spa.prototype.set = function (i, v) {
|
38315 | // check we have a value @ i
|
38316 | if (!this._values[i]) {
|
38317 | // insert in heap
|
38318 | var node = this._heap.insert(i, v); // set the value @ i
|
38319 |
|
38320 |
|
38321 | this._values[i] = node;
|
38322 | } else {
|
38323 | // update the value @ i
|
38324 | this._values[i].value = v;
|
38325 | }
|
38326 | };
|
38327 |
|
38328 | Spa.prototype.get = function (i) {
|
38329 | var node = this._values[i];
|
38330 |
|
38331 | if (node) {
|
38332 | return node.value;
|
38333 | }
|
38334 |
|
38335 | return 0;
|
38336 | };
|
38337 |
|
38338 | Spa.prototype.accumulate = function (i, v) {
|
38339 | // node @ i
|
38340 | var node = this._values[i];
|
38341 |
|
38342 | if (!node) {
|
38343 | // insert in heap
|
38344 | node = this._heap.insert(i, v); // initialize value
|
38345 |
|
38346 | this._values[i] = node;
|
38347 | } else {
|
38348 | // accumulate value
|
38349 | node.value = add(node.value, v);
|
38350 | }
|
38351 | };
|
38352 |
|
38353 | Spa.prototype.forEach = function (from, to, callback) {
|
38354 | // references
|
38355 | var heap = this._heap;
|
38356 | var values = this._values; // nodes
|
38357 |
|
38358 | var nodes = []; // node with minimum key, save it
|
38359 |
|
38360 | var node = heap.extractMinimum();
|
38361 |
|
38362 | if (node) {
|
38363 | nodes.push(node);
|
38364 | } // extract nodes from heap (ordered)
|
38365 |
|
38366 |
|
38367 | while (node && node.key <= to) {
|
38368 | // check it is in range
|
38369 | if (node.key >= from) {
|
38370 | // check value is not zero
|
38371 | if (!equalScalar(node.value, 0)) {
|
38372 | // invoke callback
|
38373 | callback(node.key, node.value, this);
|
38374 | }
|
38375 | } // extract next node, save it
|
38376 |
|
38377 |
|
38378 | node = heap.extractMinimum();
|
38379 |
|
38380 | if (node) {
|
38381 | nodes.push(node);
|
38382 | }
|
38383 | } // reinsert all nodes in heap
|
38384 |
|
38385 |
|
38386 | for (var i = 0; i < nodes.length; i++) {
|
38387 | // current node
|
38388 | var n = nodes[i]; // insert node in heap
|
38389 |
|
38390 | node = heap.insert(n.key, n.value); // update values
|
38391 |
|
38392 | values[node.key] = node;
|
38393 | }
|
38394 | };
|
38395 |
|
38396 | Spa.prototype.swap = function (i, j) {
|
38397 | // node @ i and j
|
38398 | var nodei = this._values[i];
|
38399 | var nodej = this._values[j]; // check we need to insert indeces
|
38400 |
|
38401 | if (!nodei && nodej) {
|
38402 | // insert in heap
|
38403 | nodei = this._heap.insert(i, nodej.value); // remove from heap
|
38404 |
|
38405 | this._heap.remove(nodej); // set values
|
38406 |
|
38407 |
|
38408 | this._values[i] = nodei;
|
38409 | this._values[j] = undefined;
|
38410 | } else if (nodei && !nodej) {
|
38411 | // insert in heap
|
38412 | nodej = this._heap.insert(j, nodei.value); // remove from heap
|
38413 |
|
38414 | this._heap.remove(nodei); // set values
|
38415 |
|
38416 |
|
38417 | this._values[j] = nodej;
|
38418 | this._values[i] = undefined;
|
38419 | } else if (nodei && nodej) {
|
38420 | // swap values
|
38421 | var v = nodei.value;
|
38422 | nodei.value = nodej.value;
|
38423 | nodej.value = v;
|
38424 | }
|
38425 | };
|
38426 |
|
38427 | return Spa;
|
38428 | }
|
38429 |
|
38430 | exports.name = 'Spa';
|
38431 | exports.path = 'type';
|
38432 | exports.factory = factory;
|
38433 |
|
38434 | /***/ }),
|
38435 | /* 188 */
|
38436 | /***/ (function(module, exports, __webpack_require__) {
|
38437 |
|
38438 | "use strict";
|
38439 |
|
38440 |
|
38441 | function factory(type, config, load, typed) {
|
38442 | var smaller = load(__webpack_require__(38));
|
38443 | var larger = load(__webpack_require__(33));
|
38444 | var oneOverLogPhi = 1.0 / Math.log((1.0 + Math.sqrt(5.0)) / 2.0);
|
38445 | /**
|
38446 | * Fibonacci Heap implementation, used interally for Matrix math.
|
38447 | * @class FibonacciHeap
|
38448 | * @constructor FibonacciHeap
|
38449 | */
|
38450 |
|
38451 | function FibonacciHeap() {
|
38452 | if (!(this instanceof FibonacciHeap)) {
|
38453 | throw new SyntaxError('Constructor must be called with the new operator');
|
38454 | } // initialize fields
|
38455 |
|
38456 |
|
38457 | this._minimum = null;
|
38458 | this._size = 0;
|
38459 | }
|
38460 | /**
|
38461 | * Attach type information
|
38462 | */
|
38463 |
|
38464 |
|
38465 | FibonacciHeap.prototype.type = 'FibonacciHeap';
|
38466 | FibonacciHeap.prototype.isFibonacciHeap = true;
|
38467 | /**
|
38468 | * Inserts a new data element into the heap. No heap consolidation is
|
38469 | * performed at this time, the new node is simply inserted into the root
|
38470 | * list of this heap. Running time: O(1) actual.
|
38471 | * @memberof FibonacciHeap
|
38472 | */
|
38473 |
|
38474 | FibonacciHeap.prototype.insert = function (key, value) {
|
38475 | // create node
|
38476 | var node = {
|
38477 | key: key,
|
38478 | value: value,
|
38479 | degree: 0 // check we have a node in the minimum
|
38480 |
|
38481 | };
|
38482 |
|
38483 | if (this._minimum) {
|
38484 | // minimum node
|
38485 | var minimum = this._minimum; // update left & right of node
|
38486 |
|
38487 | node.left = minimum;
|
38488 | node.right = minimum.right;
|
38489 | minimum.right = node;
|
38490 | node.right.left = node; // update minimum node in heap if needed
|
38491 |
|
38492 | if (smaller(key, minimum.key)) {
|
38493 | // node has a smaller key, use it as minimum
|
38494 | this._minimum = node;
|
38495 | }
|
38496 | } else {
|
38497 | // set left & right
|
38498 | node.left = node;
|
38499 | node.right = node; // this is the first node
|
38500 |
|
38501 | this._minimum = node;
|
38502 | } // increment number of nodes in heap
|
38503 |
|
38504 |
|
38505 | this._size++; // return node
|
38506 |
|
38507 | return node;
|
38508 | };
|
38509 | /**
|
38510 | * Returns the number of nodes in heap. Running time: O(1) actual.
|
38511 | * @memberof FibonacciHeap
|
38512 | */
|
38513 |
|
38514 |
|
38515 | FibonacciHeap.prototype.size = function () {
|
38516 | return this._size;
|
38517 | };
|
38518 | /**
|
38519 | * Removes all elements from this heap.
|
38520 | * @memberof FibonacciHeap
|
38521 | */
|
38522 |
|
38523 |
|
38524 | FibonacciHeap.prototype.clear = function () {
|
38525 | this._minimum = null;
|
38526 | this._size = 0;
|
38527 | };
|
38528 | /**
|
38529 | * Returns true if the heap is empty, otherwise false.
|
38530 | * @memberof FibonacciHeap
|
38531 | */
|
38532 |
|
38533 |
|
38534 | FibonacciHeap.prototype.isEmpty = function () {
|
38535 | return this._size === 0;
|
38536 | };
|
38537 | /**
|
38538 | * Extracts the node with minimum key from heap. Amortized running
|
38539 | * time: O(log n).
|
38540 | * @memberof FibonacciHeap
|
38541 | */
|
38542 |
|
38543 |
|
38544 | FibonacciHeap.prototype.extractMinimum = function () {
|
38545 | // node to remove
|
38546 | var node = this._minimum; // check we have a minimum
|
38547 |
|
38548 | if (node === null) {
|
38549 | return node;
|
38550 | } // current minimum
|
38551 |
|
38552 |
|
38553 | var minimum = this._minimum; // get number of children
|
38554 |
|
38555 | var numberOfChildren = node.degree; // pointer to the first child
|
38556 |
|
38557 | var x = node.child; // for each child of node do...
|
38558 |
|
38559 | while (numberOfChildren > 0) {
|
38560 | // store node in right side
|
38561 | var tempRight = x.right; // remove x from child list
|
38562 |
|
38563 | x.left.right = x.right;
|
38564 | x.right.left = x.left; // add x to root list of heap
|
38565 |
|
38566 | x.left = minimum;
|
38567 | x.right = minimum.right;
|
38568 | minimum.right = x;
|
38569 | x.right.left = x; // set Parent[x] to null
|
38570 |
|
38571 | x.parent = null;
|
38572 | x = tempRight;
|
38573 | numberOfChildren--;
|
38574 | } // remove node from root list of heap
|
38575 |
|
38576 |
|
38577 | node.left.right = node.right;
|
38578 | node.right.left = node.left; // update minimum
|
38579 |
|
38580 | if (node === node.right) {
|
38581 | // empty
|
38582 | minimum = null;
|
38583 | } else {
|
38584 | // update minimum
|
38585 | minimum = node.right; // we need to update the pointer to the root with minimum key
|
38586 |
|
38587 | minimum = _findMinimumNode(minimum, this._size);
|
38588 | } // decrement size of heap
|
38589 |
|
38590 |
|
38591 | this._size--; // update minimum
|
38592 |
|
38593 | this._minimum = minimum; // return node
|
38594 |
|
38595 | return node;
|
38596 | };
|
38597 | /**
|
38598 | * Removes a node from the heap given the reference to the node. The trees
|
38599 | * in the heap will be consolidated, if necessary. This operation may fail
|
38600 | * to remove the correct element if there are nodes with key value -Infinity.
|
38601 | * Running time: O(log n) amortized.
|
38602 | * @memberof FibonacciHeap
|
38603 | */
|
38604 |
|
38605 |
|
38606 | FibonacciHeap.prototype.remove = function (node) {
|
38607 | // decrease key value
|
38608 | this._minimum = _decreaseKey(this._minimum, node, -1); // remove the smallest
|
38609 |
|
38610 | this.extractMinimum();
|
38611 | };
|
38612 | /**
|
38613 | * Decreases the key value for a heap node, given the new value to take on.
|
38614 | * The structure of the heap may be changed and will not be consolidated.
|
38615 | * Running time: O(1) amortized.
|
38616 | * @memberof FibonacciHeap
|
38617 | */
|
38618 |
|
38619 |
|
38620 | function _decreaseKey(minimum, node, key) {
|
38621 | // set node key
|
38622 | node.key = key; // get parent node
|
38623 |
|
38624 | var parent = node.parent;
|
38625 |
|
38626 | if (parent && smaller(node.key, parent.key)) {
|
38627 | // remove node from parent
|
38628 | _cut(minimum, node, parent); // remove all nodes from parent to the root parent
|
38629 |
|
38630 |
|
38631 | _cascadingCut(minimum, parent);
|
38632 | } // update minimum node if needed
|
38633 |
|
38634 |
|
38635 | if (smaller(node.key, minimum.key)) {
|
38636 | minimum = node;
|
38637 | } // return minimum
|
38638 |
|
38639 |
|
38640 | return minimum;
|
38641 | }
|
38642 | /**
|
38643 | * The reverse of the link operation: removes node from the child list of parent.
|
38644 | * This method assumes that min is non-null. Running time: O(1).
|
38645 | * @memberof FibonacciHeap
|
38646 | */
|
38647 |
|
38648 |
|
38649 | function _cut(minimum, node, parent) {
|
38650 | // remove node from parent children and decrement Degree[parent]
|
38651 | node.left.right = node.right;
|
38652 | node.right.left = node.left;
|
38653 | parent.degree--; // reset y.child if necessary
|
38654 |
|
38655 | if (parent.child === node) {
|
38656 | parent.child = node.right;
|
38657 | } // remove child if degree is 0
|
38658 |
|
38659 |
|
38660 | if (parent.degree === 0) {
|
38661 | parent.child = null;
|
38662 | } // add node to root list of heap
|
38663 |
|
38664 |
|
38665 | node.left = minimum;
|
38666 | node.right = minimum.right;
|
38667 | minimum.right = node;
|
38668 | node.right.left = node; // set parent[node] to null
|
38669 |
|
38670 | node.parent = null; // set mark[node] to false
|
38671 |
|
38672 | node.mark = false;
|
38673 | }
|
38674 | /**
|
38675 | * Performs a cascading cut operation. This cuts node from its parent and then
|
38676 | * does the same for its parent, and so on up the tree.
|
38677 | * Running time: O(log n); O(1) excluding the recursion.
|
38678 | * @memberof FibonacciHeap
|
38679 | */
|
38680 |
|
38681 |
|
38682 | function _cascadingCut(minimum, node) {
|
38683 | // store parent node
|
38684 | var parent = node.parent; // if there's a parent...
|
38685 |
|
38686 | if (!parent) {
|
38687 | return;
|
38688 | } // if node is unmarked, set it marked
|
38689 |
|
38690 |
|
38691 | if (!node.mark) {
|
38692 | node.mark = true;
|
38693 | } else {
|
38694 | // it's marked, cut it from parent
|
38695 | _cut(minimum, node, parent); // cut its parent as well
|
38696 |
|
38697 |
|
38698 | _cascadingCut(parent);
|
38699 | }
|
38700 | }
|
38701 | /**
|
38702 | * Make the first node a child of the second one. Running time: O(1) actual.
|
38703 | * @memberof FibonacciHeap
|
38704 | */
|
38705 |
|
38706 |
|
38707 | var _linkNodes = function _linkNodes(node, parent) {
|
38708 | // remove node from root list of heap
|
38709 | node.left.right = node.right;
|
38710 | node.right.left = node.left; // make node a Child of parent
|
38711 |
|
38712 | node.parent = parent;
|
38713 |
|
38714 | if (!parent.child) {
|
38715 | parent.child = node;
|
38716 | node.right = node;
|
38717 | node.left = node;
|
38718 | } else {
|
38719 | node.left = parent.child;
|
38720 | node.right = parent.child.right;
|
38721 | parent.child.right = node;
|
38722 | node.right.left = node;
|
38723 | } // increase degree[parent]
|
38724 |
|
38725 |
|
38726 | parent.degree++; // set mark[node] false
|
38727 |
|
38728 | node.mark = false;
|
38729 | };
|
38730 |
|
38731 | function _findMinimumNode(minimum, size) {
|
38732 | // to find trees of the same degree efficiently we use an array of length O(log n) in which we keep a pointer to one root of each degree
|
38733 | var arraySize = Math.floor(Math.log(size) * oneOverLogPhi) + 1; // create list with initial capacity
|
38734 |
|
38735 | var array = new Array(arraySize); // find the number of root nodes.
|
38736 |
|
38737 | var numRoots = 0;
|
38738 | var x = minimum;
|
38739 |
|
38740 | if (x) {
|
38741 | numRoots++;
|
38742 | x = x.right;
|
38743 |
|
38744 | while (x !== minimum) {
|
38745 | numRoots++;
|
38746 | x = x.right;
|
38747 | }
|
38748 | } // vars
|
38749 |
|
38750 |
|
38751 | var y; // For each node in root list do...
|
38752 |
|
38753 | while (numRoots > 0) {
|
38754 | // access this node's degree..
|
38755 | var d = x.degree; // get next node
|
38756 |
|
38757 | var next = x.right; // check if there is a node already in array with the same degree
|
38758 |
|
38759 | while (true) {
|
38760 | // get node with the same degree is any
|
38761 | y = array[d];
|
38762 |
|
38763 | if (!y) {
|
38764 | break;
|
38765 | } // make one node with the same degree a child of the other, do this based on the key value.
|
38766 |
|
38767 |
|
38768 | if (larger(x.key, y.key)) {
|
38769 | var temp = y;
|
38770 | y = x;
|
38771 | x = temp;
|
38772 | } // make y a child of x
|
38773 |
|
38774 |
|
38775 | _linkNodes(y, x); // we have handled this degree, go to next one.
|
38776 |
|
38777 |
|
38778 | array[d] = null;
|
38779 | d++;
|
38780 | } // save this node for later when we might encounter another of the same degree.
|
38781 |
|
38782 |
|
38783 | array[d] = x; // move forward through list.
|
38784 |
|
38785 | x = next;
|
38786 | numRoots--;
|
38787 | } // Set min to null (effectively losing the root list) and reconstruct the root list from the array entries in array[].
|
38788 |
|
38789 |
|
38790 | minimum = null; // loop nodes in array
|
38791 |
|
38792 | for (var i = 0; i < arraySize; i++) {
|
38793 | // get current node
|
38794 | y = array[i];
|
38795 |
|
38796 | if (!y) {
|
38797 | continue;
|
38798 | } // check if we have a linked list
|
38799 |
|
38800 |
|
38801 | if (minimum) {
|
38802 | // First remove node from root list.
|
38803 | y.left.right = y.right;
|
38804 | y.right.left = y.left; // now add to root list, again.
|
38805 |
|
38806 | y.left = minimum;
|
38807 | y.right = minimum.right;
|
38808 | minimum.right = y;
|
38809 | y.right.left = y; // check if this is a new min.
|
38810 |
|
38811 | if (smaller(y.key, minimum.key)) {
|
38812 | minimum = y;
|
38813 | }
|
38814 | } else {
|
38815 | minimum = y;
|
38816 | }
|
38817 | }
|
38818 |
|
38819 | return minimum;
|
38820 | }
|
38821 |
|
38822 | return FibonacciHeap;
|
38823 | }
|
38824 |
|
38825 | exports.name = 'FibonacciHeap';
|
38826 | exports.path = 'type';
|
38827 | exports.factory = factory;
|
38828 |
|
38829 | /***/ }),
|
38830 | /* 189 */
|
38831 | /***/ (function(module, exports, __webpack_require__) {
|
38832 |
|
38833 | "use strict";
|
38834 |
|
38835 |
|
38836 | var util = __webpack_require__(31);
|
38837 |
|
38838 | var string = util.string;
|
38839 | var object = util.object;
|
38840 | var isArray = Array.isArray;
|
38841 | var isString = string.isString;
|
38842 |
|
38843 | function factory(type, config, load) {
|
38844 | var DenseMatrix = load(__webpack_require__(49));
|
38845 | var smaller = load(__webpack_require__(38));
|
38846 |
|
38847 | function ImmutableDenseMatrix(data, datatype) {
|
38848 | if (!(this instanceof ImmutableDenseMatrix)) {
|
38849 | throw new SyntaxError('Constructor must be called with the new operator');
|
38850 | }
|
38851 |
|
38852 | if (datatype && !isString(datatype)) {
|
38853 | throw new Error('Invalid datatype: ' + datatype);
|
38854 | }
|
38855 |
|
38856 | if (type.isMatrix(data) || isArray(data)) {
|
38857 | // use DenseMatrix implementation
|
38858 | var matrix = new DenseMatrix(data, datatype); // internal structures
|
38859 |
|
38860 | this._data = matrix._data;
|
38861 | this._size = matrix._size;
|
38862 | this._datatype = matrix._datatype;
|
38863 | this._min = null;
|
38864 | this._max = null;
|
38865 | } else if (data && isArray(data.data) && isArray(data.size)) {
|
38866 | // initialize fields from JSON representation
|
38867 | this._data = data.data;
|
38868 | this._size = data.size;
|
38869 | this._datatype = data.datatype;
|
38870 | this._min = typeof data.min !== 'undefined' ? data.min : null;
|
38871 | this._max = typeof data.max !== 'undefined' ? data.max : null;
|
38872 | } else if (data) {
|
38873 | // unsupported type
|
38874 | throw new TypeError('Unsupported type of data (' + util.types.type(data) + ')');
|
38875 | } else {
|
38876 | // nothing provided
|
38877 | this._data = [];
|
38878 | this._size = [0];
|
38879 | this._datatype = datatype;
|
38880 | this._min = null;
|
38881 | this._max = null;
|
38882 | }
|
38883 | }
|
38884 |
|
38885 | ImmutableDenseMatrix.prototype = new DenseMatrix();
|
38886 | /**
|
38887 | * Attach type information
|
38888 | */
|
38889 |
|
38890 | ImmutableDenseMatrix.prototype.type = 'ImmutableDenseMatrix';
|
38891 | ImmutableDenseMatrix.prototype.isImmutableDenseMatrix = true;
|
38892 | /**
|
38893 | * Get a subset of the matrix, or replace a subset of the matrix.
|
38894 | *
|
38895 | * Usage:
|
38896 | * const subset = matrix.subset(index) // retrieve subset
|
38897 | * const value = matrix.subset(index, replacement) // replace subset
|
38898 | *
|
38899 | * @param {Index} index
|
38900 | * @param {Array | ImmutableDenseMatrix | *} [replacement]
|
38901 | * @param {*} [defaultValue=0] Default value, filled in on new entries when
|
38902 | * the matrix is resized. If not provided,
|
38903 | * new matrix elements will be filled with zeros.
|
38904 | */
|
38905 |
|
38906 | ImmutableDenseMatrix.prototype.subset = function (index) {
|
38907 | switch (arguments.length) {
|
38908 | case 1:
|
38909 | // use base implementation
|
38910 | var m = DenseMatrix.prototype.subset.call(this, index); // check result is a matrix
|
38911 |
|
38912 | if (type.isMatrix(m)) {
|
38913 | // return immutable matrix
|
38914 | return new ImmutableDenseMatrix({
|
38915 | data: m._data,
|
38916 | size: m._size,
|
38917 | datatype: m._datatype
|
38918 | });
|
38919 | }
|
38920 |
|
38921 | return m;
|
38922 | // intentional fall through
|
38923 |
|
38924 | case 2:
|
38925 | case 3:
|
38926 | throw new Error('Cannot invoke set subset on an Immutable Matrix instance');
|
38927 |
|
38928 | default:
|
38929 | throw new SyntaxError('Wrong number of arguments');
|
38930 | }
|
38931 | };
|
38932 | /**
|
38933 | * Replace a single element in the matrix.
|
38934 | * @param {Number[]} index Zero-based index
|
38935 | * @param {*} value
|
38936 | * @param {*} [defaultValue] Default value, filled in on new entries when
|
38937 | * the matrix is resized. If not provided,
|
38938 | * new matrix elements will be left undefined.
|
38939 | * @return {ImmutableDenseMatrix} self
|
38940 | */
|
38941 |
|
38942 |
|
38943 | ImmutableDenseMatrix.prototype.set = function () {
|
38944 | throw new Error('Cannot invoke set on an Immutable Matrix instance');
|
38945 | };
|
38946 | /**
|
38947 | * Resize the matrix to the given size. Returns a copy of the matrix when
|
38948 | * `copy=true`, otherwise return the matrix itself (resize in place).
|
38949 | *
|
38950 | * @param {Number[]} size The new size the matrix should have.
|
38951 | * @param {*} [defaultValue=0] Default value, filled in on new entries.
|
38952 | * If not provided, the matrix elements will
|
38953 | * be filled with zeros.
|
38954 | * @param {boolean} [copy] Return a resized copy of the matrix
|
38955 | *
|
38956 | * @return {Matrix} The resized matrix
|
38957 | */
|
38958 |
|
38959 |
|
38960 | ImmutableDenseMatrix.prototype.resize = function () {
|
38961 | throw new Error('Cannot invoke resize on an Immutable Matrix instance');
|
38962 | };
|
38963 | /**
|
38964 | * Disallows reshaping in favor of immutability.
|
38965 | *
|
38966 | * @throws {Error} Operation not allowed
|
38967 | */
|
38968 |
|
38969 |
|
38970 | ImmutableDenseMatrix.prototype.reshape = function () {
|
38971 | throw new Error('Cannot invoke reshape on an Immutable Matrix instance');
|
38972 | };
|
38973 | /**
|
38974 | * Create a clone of the matrix
|
38975 | * @return {ImmutableDenseMatrix} clone
|
38976 | */
|
38977 |
|
38978 |
|
38979 | ImmutableDenseMatrix.prototype.clone = function () {
|
38980 | var m = new ImmutableDenseMatrix({
|
38981 | data: object.clone(this._data),
|
38982 | size: object.clone(this._size),
|
38983 | datatype: this._datatype
|
38984 | });
|
38985 | return m;
|
38986 | };
|
38987 | /**
|
38988 | * Get a JSON representation of the matrix
|
38989 | * @returns {Object}
|
38990 | */
|
38991 |
|
38992 |
|
38993 | ImmutableDenseMatrix.prototype.toJSON = function () {
|
38994 | return {
|
38995 | mathjs: 'ImmutableDenseMatrix',
|
38996 | data: this._data,
|
38997 | size: this._size,
|
38998 | datatype: this._datatype
|
38999 | };
|
39000 | };
|
39001 | /**
|
39002 | * Generate a matrix from a JSON object
|
39003 | * @param {Object} json An object structured like
|
39004 | * `{"mathjs": "ImmutableDenseMatrix", data: [], size: []}`,
|
39005 | * where mathjs is optional
|
39006 | * @returns {ImmutableDenseMatrix}
|
39007 | */
|
39008 |
|
39009 |
|
39010 | ImmutableDenseMatrix.fromJSON = function (json) {
|
39011 | return new ImmutableDenseMatrix(json);
|
39012 | };
|
39013 | /**
|
39014 | * Swap rows i and j in Matrix.
|
39015 | *
|
39016 | * @param {Number} i Matrix row index 1
|
39017 | * @param {Number} j Matrix row index 2
|
39018 | *
|
39019 | * @return {Matrix} The matrix reference
|
39020 | */
|
39021 |
|
39022 |
|
39023 | ImmutableDenseMatrix.prototype.swapRows = function () {
|
39024 | throw new Error('Cannot invoke swapRows on an Immutable Matrix instance');
|
39025 | };
|
39026 | /**
|
39027 | * Calculate the minimum value in the set
|
39028 | * @return {Number | undefined} min
|
39029 | */
|
39030 |
|
39031 |
|
39032 | ImmutableDenseMatrix.prototype.min = function () {
|
39033 | // check min has been calculated before
|
39034 | if (this._min === null) {
|
39035 | // minimum
|
39036 | var m = null; // compute min
|
39037 |
|
39038 | this.forEach(function (v) {
|
39039 | if (m === null || smaller(v, m)) {
|
39040 | m = v;
|
39041 | }
|
39042 | });
|
39043 | this._min = m !== null ? m : undefined;
|
39044 | }
|
39045 |
|
39046 | return this._min;
|
39047 | };
|
39048 | /**
|
39049 | * Calculate the maximum value in the set
|
39050 | * @return {Number | undefined} max
|
39051 | */
|
39052 |
|
39053 |
|
39054 | ImmutableDenseMatrix.prototype.max = function () {
|
39055 | // check max has been calculated before
|
39056 | if (this._max === null) {
|
39057 | // maximum
|
39058 | var m = null; // compute max
|
39059 |
|
39060 | this.forEach(function (v) {
|
39061 | if (m === null || smaller(m, v)) {
|
39062 | m = v;
|
39063 | }
|
39064 | });
|
39065 | this._max = m !== null ? m : undefined;
|
39066 | }
|
39067 |
|
39068 | return this._max;
|
39069 | }; // exports
|
39070 |
|
39071 |
|
39072 | return ImmutableDenseMatrix;
|
39073 | }
|
39074 |
|
39075 | exports.name = 'ImmutableDenseMatrix';
|
39076 | exports.path = 'type';
|
39077 | exports.factory = factory;
|
39078 |
|
39079 | /***/ }),
|
39080 | /* 190 */
|
39081 | /***/ (function(module, exports, __webpack_require__) {
|
39082 |
|
39083 | "use strict";
|
39084 |
|
39085 |
|
39086 | function factory(type, config, load, typed) {
|
39087 | /**
|
39088 | * Create an index. An Index can store ranges having start, step, and end
|
39089 | * for multiple dimensions.
|
39090 | * Matrix.get, Matrix.set, and math.subset accept an Index as input.
|
39091 | *
|
39092 | * Syntax:
|
39093 | *
|
39094 | * math.index(range1, range2, ...)
|
39095 | *
|
39096 | * Where each range can be any of:
|
39097 | *
|
39098 | * - A number
|
39099 | * - A string for getting/setting an object property
|
39100 | * - An instance of `Range`
|
39101 | * - A one-dimensional Array or a Matrix with numbers
|
39102 | *
|
39103 | * Indexes must be zero-based, integer numbers.
|
39104 | *
|
39105 | * Examples:
|
39106 | *
|
39107 | * const math = require('mathjs')
|
39108 | *
|
39109 | * const b = [1, 2, 3, 4, 5]
|
39110 | * math.subset(b, math.index([1, 2, 3])) // returns [2, 3, 4]
|
39111 | *
|
39112 | * const a = math.matrix([[1, 2], [3, 4]])
|
39113 | * a.subset(math.index(0, 1)) // returns 2
|
39114 | *
|
39115 | * See also:
|
39116 | *
|
39117 | * bignumber, boolean, complex, matrix, number, string, unit
|
39118 | *
|
39119 | * @param {...*} ranges Zero or more ranges or numbers.
|
39120 | * @return {Index} Returns the created index
|
39121 | */
|
39122 | return typed('index', {
|
39123 | '...number | string | BigNumber | Range | Array | Matrix': function numberStringBigNumberRangeArrayMatrix(args) {
|
39124 | var ranges = args.map(function (arg) {
|
39125 | if (type.isBigNumber(arg)) {
|
39126 | return arg.toNumber(); // convert BigNumber to Number
|
39127 | } else if (Array.isArray(arg) || type.isMatrix(arg)) {
|
39128 | return arg.map(function (elem) {
|
39129 | // convert BigNumber to Number
|
39130 | return type.isBigNumber(elem) ? elem.toNumber() : elem;
|
39131 | });
|
39132 | } else {
|
39133 | return arg;
|
39134 | }
|
39135 | });
|
39136 | var res = new type.Index();
|
39137 | type.Index.apply(res, ranges);
|
39138 | return res;
|
39139 | }
|
39140 | });
|
39141 | }
|
39142 |
|
39143 | exports.name = 'index';
|
39144 | exports.factory = factory;
|
39145 |
|
39146 | /***/ }),
|
39147 | /* 191 */
|
39148 | /***/ (function(module, exports, __webpack_require__) {
|
39149 |
|
39150 | "use strict";
|
39151 |
|
39152 |
|
39153 | function factory(type, config, load, typed) {
|
39154 | var SparseMatrix = type.SparseMatrix;
|
39155 | /**
|
39156 | * Create a Sparse Matrix. The function creates a new `math.type.Matrix` object from
|
39157 | * an `Array`. A Matrix has utility functions to manipulate the data in the
|
39158 | * matrix, like getting the size and getting or setting values in the matrix.
|
39159 | *
|
39160 | * Syntax:
|
39161 | *
|
39162 | * math.sparse() // creates an empty sparse matrix.
|
39163 | * math.sparse(data) // creates a sparse matrix with initial data.
|
39164 | * math.sparse(data, 'number') // creates a sparse matrix with initial data, number datatype.
|
39165 | *
|
39166 | * Examples:
|
39167 | *
|
39168 | * let m = math.sparse([[1, 2], [3, 4]])
|
39169 | * m.size() // Array [2, 2]
|
39170 | * m.resize([3, 2], 5)
|
39171 | * m.valueOf() // Array [[1, 2], [3, 4], [5, 5]]
|
39172 | * m.get([1, 0]) // number 3
|
39173 | *
|
39174 | * See also:
|
39175 | *
|
39176 | * bignumber, boolean, complex, index, number, string, unit, matrix
|
39177 | *
|
39178 | * @param {Array | Matrix} [data] A two dimensional array
|
39179 | *
|
39180 | * @return {Matrix} The created matrix
|
39181 | */
|
39182 |
|
39183 | var sparse = typed('sparse', {
|
39184 | '': function _() {
|
39185 | return new SparseMatrix([]);
|
39186 | },
|
39187 | 'string': function string(datatype) {
|
39188 | return new SparseMatrix([], datatype);
|
39189 | },
|
39190 | 'Array | Matrix': function ArrayMatrix(data) {
|
39191 | return new SparseMatrix(data);
|
39192 | },
|
39193 | 'Array | Matrix, string': function ArrayMatrixString(data, datatype) {
|
39194 | return new SparseMatrix(data, datatype);
|
39195 | }
|
39196 | });
|
39197 | sparse.toTex = {
|
39198 | 0: '\\begin{bsparse}\\end{bsparse}',
|
39199 | 1: "\\left(${args[0]}\\right)"
|
39200 | };
|
39201 | return sparse;
|
39202 | }
|
39203 |
|
39204 | exports.name = 'sparse';
|
39205 | exports.factory = factory;
|
39206 |
|
39207 | /***/ }),
|
39208 | /* 192 */
|
39209 | /***/ (function(module, exports, __webpack_require__) {
|
39210 |
|
39211 | "use strict";
|
39212 |
|
39213 |
|
39214 | module.exports = [// type
|
39215 | __webpack_require__(107)];
|
39216 |
|
39217 | /***/ }),
|
39218 | /* 193 */
|
39219 | /***/ (function(module, exports, __webpack_require__) {
|
39220 |
|
39221 | "use strict";
|
39222 |
|
39223 |
|
39224 | var deepMap = __webpack_require__(1);
|
39225 |
|
39226 | var number = __webpack_require__(3);
|
39227 |
|
39228 | function factory(type, config, load, typed) {
|
39229 | /**
|
39230 | * Create a string or convert any object into a string.
|
39231 | * Elements of Arrays and Matrices are processed element wise.
|
39232 | *
|
39233 | * Syntax:
|
39234 | *
|
39235 | * math.string(value)
|
39236 | *
|
39237 | * Examples:
|
39238 | *
|
39239 | * math.string(4.2) // returns string '4.2'
|
39240 | * math.string(math.complex(3, 2) // returns string '3 + 2i'
|
39241 | *
|
39242 | * const u = math.unit(5, 'km')
|
39243 | * math.string(u.to('m')) // returns string '5000 m'
|
39244 | *
|
39245 | * math.string([true, false]) // returns ['true', 'false']
|
39246 | *
|
39247 | * See also:
|
39248 | *
|
39249 | * bignumber, boolean, complex, index, matrix, number, unit
|
39250 | *
|
39251 | * @param {* | Array | Matrix | null} [value] A value to convert to a string
|
39252 | * @return {string | Array | Matrix} The created string
|
39253 | */
|
39254 | var string = typed('string', {
|
39255 | '': function _() {
|
39256 | return '';
|
39257 | },
|
39258 | 'number': number.format,
|
39259 | 'null': function _null(x) {
|
39260 | return 'null';
|
39261 | },
|
39262 | 'boolean': function boolean(x) {
|
39263 | return x + '';
|
39264 | },
|
39265 | 'string': function string(x) {
|
39266 | return x;
|
39267 | },
|
39268 | 'Array | Matrix': function ArrayMatrix(x) {
|
39269 | return deepMap(x, string);
|
39270 | },
|
39271 | 'any': function any(x) {
|
39272 | return String(x);
|
39273 | }
|
39274 | });
|
39275 | string.toTex = {
|
39276 | 0: '\\mathtt{""}',
|
39277 | 1: "\\mathrm{string}\\left(${args[0]}\\right)"
|
39278 | };
|
39279 | return string;
|
39280 | }
|
39281 |
|
39282 | exports.name = 'string';
|
39283 | exports.factory = factory;
|
39284 |
|
39285 | /***/ }),
|
39286 | /* 194 */
|
39287 | /***/ (function(module, exports, __webpack_require__) {
|
39288 |
|
39289 | "use strict";
|
39290 |
|
39291 |
|
39292 | module.exports = [// type
|
39293 | __webpack_require__(195), // construction function
|
39294 | __webpack_require__(196), // create new units
|
39295 | __webpack_require__(197), // split units
|
39296 | __webpack_require__(198), // physical constants
|
39297 | __webpack_require__(199)];
|
39298 |
|
39299 | /***/ }),
|
39300 | /* 195 */
|
39301 | /***/ (function(module, exports, __webpack_require__) {
|
39302 |
|
39303 | "use strict";
|
39304 |
|
39305 |
|
39306 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
39307 |
|
39308 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
39309 |
|
39310 | var endsWith = __webpack_require__(9).endsWith;
|
39311 |
|
39312 | var clone = __webpack_require__(5).clone;
|
39313 |
|
39314 | var constants = __webpack_require__(108);
|
39315 |
|
39316 | function factory(type, config, load, typed, math) {
|
39317 | var add = load(__webpack_require__(17));
|
39318 | var subtract = load(__webpack_require__(15));
|
39319 | var multiply = load(__webpack_require__(21));
|
39320 | var divide = load(__webpack_require__(12));
|
39321 | var pow = load(__webpack_require__(42));
|
39322 | var abs = load(__webpack_require__(25));
|
39323 | var fix = load(__webpack_require__(109));
|
39324 | var round = load(__webpack_require__(67));
|
39325 | var equal = load(__webpack_require__(51));
|
39326 | var isNumeric = load(__webpack_require__(52));
|
39327 | var format = load(__webpack_require__(112));
|
39328 | var getTypeOf = load(__webpack_require__(26));
|
39329 | var toNumber = load(__webpack_require__(64));
|
39330 | var Complex = load(__webpack_require__(82));
|
39331 | /**
|
39332 | * A unit can be constructed in the following ways:
|
39333 | *
|
39334 | * const a = new Unit(value, name)
|
39335 | * const b = new Unit(null, name)
|
39336 | * const c = Unit.parse(str)
|
39337 | *
|
39338 | * Example usage:
|
39339 | *
|
39340 | * const a = new Unit(5, 'cm') // 50 mm
|
39341 | * const b = Unit.parse('23 kg') // 23 kg
|
39342 | * const c = math.in(a, new Unit(null, 'm') // 0.05 m
|
39343 | * const d = new Unit(9.81, "m/s^2") // 9.81 m/s^2
|
39344 | *
|
39345 | * @class Unit
|
39346 | * @constructor Unit
|
39347 | * @param {number | BigNumber | Fraction | Complex | boolean} [value] A value like 5.2
|
39348 | * @param {string} [name] A unit name like "cm" or "inch", or a derived unit of the form: "u1[^ex1] [u2[^ex2] ...] [/ u3[^ex3] [u4[^ex4]]]", such as "kg m^2/s^2", where each unit appearing after the forward slash is taken to be in the denominator. "kg m^2 s^-2" is a synonym and is also acceptable. Any of the units can include a prefix.
|
39349 | */
|
39350 |
|
39351 | function Unit(value, name) {
|
39352 | if (!(this instanceof Unit)) {
|
39353 | throw new Error('Constructor must be called with the new operator');
|
39354 | }
|
39355 |
|
39356 | if (!(value === null || value === undefined || isNumeric(value) || type.isComplex(value))) {
|
39357 | throw new TypeError('First parameter in Unit constructor must be number, BigNumber, Fraction, Complex, or undefined');
|
39358 | }
|
39359 |
|
39360 | if (name !== undefined && (typeof name !== 'string' || name === '')) {
|
39361 | throw new TypeError('Second parameter in Unit constructor must be a string');
|
39362 | }
|
39363 |
|
39364 | if (name !== undefined) {
|
39365 | var u = Unit.parse(name);
|
39366 | this.units = u.units;
|
39367 | this.dimensions = u.dimensions;
|
39368 | } else {
|
39369 | this.units = [{
|
39370 | unit: UNIT_NONE,
|
39371 | prefix: PREFIXES.NONE,
|
39372 | // link to a list with supported prefixes
|
39373 | power: 0
|
39374 | }];
|
39375 | this.dimensions = [];
|
39376 |
|
39377 | for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
|
39378 | this.dimensions[i] = 0;
|
39379 | }
|
39380 | }
|
39381 |
|
39382 | this.value = value !== undefined && value !== null ? this._normalize(value) : null;
|
39383 | this.fixPrefix = false; // if true, function format will not search for the
|
39384 | // best prefix but leave it as initially provided.
|
39385 | // fixPrefix is set true by the method Unit.to
|
39386 | // The justification behind this is that if the constructor is explicitly called,
|
39387 | // the caller wishes the units to be returned exactly as he supplied.
|
39388 |
|
39389 | this.skipAutomaticSimplification = true;
|
39390 | }
|
39391 | /**
|
39392 | * Attach type information
|
39393 | */
|
39394 |
|
39395 |
|
39396 | Unit.prototype.type = 'Unit';
|
39397 | Unit.prototype.isUnit = true; // private variables and functions for the Unit parser
|
39398 |
|
39399 | var text, index, c;
|
39400 |
|
39401 | function skipWhitespace() {
|
39402 | while (c === ' ' || c === '\t') {
|
39403 | next();
|
39404 | }
|
39405 | }
|
39406 |
|
39407 | function isDigitDot(c) {
|
39408 | return c >= '0' && c <= '9' || c === '.';
|
39409 | }
|
39410 |
|
39411 | function isDigit(c) {
|
39412 | return c >= '0' && c <= '9';
|
39413 | }
|
39414 |
|
39415 | function next() {
|
39416 | index++;
|
39417 | c = text.charAt(index);
|
39418 | }
|
39419 |
|
39420 | function revert(oldIndex) {
|
39421 | index = oldIndex;
|
39422 | c = text.charAt(index);
|
39423 | }
|
39424 |
|
39425 | function parseNumber() {
|
39426 | var number = '';
|
39427 | var oldIndex;
|
39428 | oldIndex = index;
|
39429 |
|
39430 | if (c === '+') {
|
39431 | next();
|
39432 | } else if (c === '-') {
|
39433 | number += c;
|
39434 | next();
|
39435 | }
|
39436 |
|
39437 | if (!isDigitDot(c)) {
|
39438 | // a + or - must be followed by a digit
|
39439 | revert(oldIndex);
|
39440 | return null;
|
39441 | } // get number, can have a single dot
|
39442 |
|
39443 |
|
39444 | if (c === '.') {
|
39445 | number += c;
|
39446 | next();
|
39447 |
|
39448 | if (!isDigit(c)) {
|
39449 | // this is no legal number, it is just a dot
|
39450 | revert(oldIndex);
|
39451 | return null;
|
39452 | }
|
39453 | } else {
|
39454 | while (isDigit(c)) {
|
39455 | number += c;
|
39456 | next();
|
39457 | }
|
39458 |
|
39459 | if (c === '.') {
|
39460 | number += c;
|
39461 | next();
|
39462 | }
|
39463 | }
|
39464 |
|
39465 | while (isDigit(c)) {
|
39466 | number += c;
|
39467 | next();
|
39468 | } // check for exponential notation like "2.3e-4" or "1.23e50"
|
39469 |
|
39470 |
|
39471 | if (c === 'E' || c === 'e') {
|
39472 | // The grammar branches here. This could either be part of an exponent or the start of a unit that begins with the letter e, such as "4exabytes"
|
39473 | var tentativeNumber = '';
|
39474 | var tentativeIndex = index;
|
39475 | tentativeNumber += c;
|
39476 | next();
|
39477 |
|
39478 | if (c === '+' || c === '-') {
|
39479 | tentativeNumber += c;
|
39480 | next();
|
39481 | } // Scientific notation MUST be followed by an exponent (otherwise we assume it is not scientific notation)
|
39482 |
|
39483 |
|
39484 | if (!isDigit(c)) {
|
39485 | // The e or E must belong to something else, so return the number without the e or E.
|
39486 | revert(tentativeIndex);
|
39487 | return number;
|
39488 | } // We can now safely say that this is scientific notation.
|
39489 |
|
39490 |
|
39491 | number = number + tentativeNumber;
|
39492 |
|
39493 | while (isDigit(c)) {
|
39494 | number += c;
|
39495 | next();
|
39496 | }
|
39497 | }
|
39498 |
|
39499 | return number;
|
39500 | }
|
39501 |
|
39502 | function parseUnit() {
|
39503 | var unitName = ''; // Alphanumeric characters only; matches [a-zA-Z0-9]
|
39504 |
|
39505 | var code = text.charCodeAt(index);
|
39506 |
|
39507 | while (code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
39508 | unitName += c;
|
39509 | next();
|
39510 | code = text.charCodeAt(index);
|
39511 | } // Must begin with [a-zA-Z]
|
39512 |
|
39513 |
|
39514 | code = unitName.charCodeAt(0);
|
39515 |
|
39516 | if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
39517 | return unitName || null;
|
39518 | } else {
|
39519 | return null;
|
39520 | }
|
39521 | }
|
39522 |
|
39523 | function parseCharacter(toFind) {
|
39524 | if (c === toFind) {
|
39525 | next();
|
39526 | return toFind;
|
39527 | } else {
|
39528 | return null;
|
39529 | }
|
39530 | }
|
39531 | /**
|
39532 | * Parse a string into a unit. The value of the unit is parsed as number,
|
39533 | * BigNumber, or Fraction depending on the math.js config setting `number`.
|
39534 | *
|
39535 | * Throws an exception if the provided string does not contain a valid unit or
|
39536 | * cannot be parsed.
|
39537 | * @memberof Unit
|
39538 | * @param {string} str A string like "5.2 inch", "4e2 cm/s^2"
|
39539 | * @return {Unit} unit
|
39540 | */
|
39541 |
|
39542 |
|
39543 | Unit.parse = function (str, options) {
|
39544 | options = options || {};
|
39545 | text = str;
|
39546 | index = -1;
|
39547 | c = '';
|
39548 |
|
39549 | if (typeof text !== 'string') {
|
39550 | throw new TypeError('Invalid argument in Unit.parse, string expected');
|
39551 | }
|
39552 |
|
39553 | var unit = new Unit();
|
39554 | unit.units = [];
|
39555 | var powerMultiplierCurrent = 1;
|
39556 | var expectingUnit = false; // A unit should follow this pattern:
|
39557 | // [number] ...[ [*/] unit[^number] ]
|
39558 | // unit[^number] ... [ [*/] unit[^number] ]
|
39559 | // Rules:
|
39560 | // number is any floating point number.
|
39561 | // unit is any alphanumeric string beginning with an alpha. Units with names like e3 should be avoided because they look like the exponent of a floating point number!
|
39562 | // The string may optionally begin with a number.
|
39563 | // Each unit may optionally be followed by ^number.
|
39564 | // Whitespace or a forward slash is recommended between consecutive units, although the following technically is parseable:
|
39565 | // 2m^2kg/s^2
|
39566 | // it is not good form. If a unit starts with e, then it could be confused as a floating point number:
|
39567 | // 4erg
|
39568 |
|
39569 | next();
|
39570 | skipWhitespace(); // Optional number at the start of the string
|
39571 |
|
39572 | var valueStr = parseNumber();
|
39573 | var value = null;
|
39574 |
|
39575 | if (valueStr) {
|
39576 | if (config.number === 'BigNumber') {
|
39577 | value = new type.BigNumber(valueStr);
|
39578 | } else if (config.number === 'Fraction') {
|
39579 | value = new type.Fraction(valueStr);
|
39580 | } else {
|
39581 | // number
|
39582 | value = parseFloat(valueStr);
|
39583 | }
|
39584 |
|
39585 | skipWhitespace(); // Whitespace is not required here
|
39586 | // handle multiplication or division right after the value, like '1/s'
|
39587 |
|
39588 | if (parseCharacter('*')) {
|
39589 | powerMultiplierCurrent = 1;
|
39590 | expectingUnit = true;
|
39591 | } else if (parseCharacter('/')) {
|
39592 | powerMultiplierCurrent = -1;
|
39593 | expectingUnit = true;
|
39594 | }
|
39595 | } // Stack to keep track of powerMultipliers applied to each parentheses group
|
39596 |
|
39597 |
|
39598 | var powerMultiplierStack = []; // Running product of all elements in powerMultiplierStack
|
39599 |
|
39600 | var powerMultiplierStackProduct = 1;
|
39601 |
|
39602 | while (true) {
|
39603 | skipWhitespace(); // Check for and consume opening parentheses, pushing powerMultiplierCurrent to the stack
|
39604 | // A '(' will always appear directly before a unit.
|
39605 |
|
39606 | while (c === '(') {
|
39607 | powerMultiplierStack.push(powerMultiplierCurrent);
|
39608 | powerMultiplierStackProduct *= powerMultiplierCurrent;
|
39609 | powerMultiplierCurrent = 1;
|
39610 | next();
|
39611 | skipWhitespace();
|
39612 | } // Is there something here?
|
39613 |
|
39614 |
|
39615 | var uStr = void 0;
|
39616 |
|
39617 | if (c) {
|
39618 | var oldC = c;
|
39619 | uStr = parseUnit();
|
39620 |
|
39621 | if (uStr === null) {
|
39622 | throw new SyntaxError('Unexpected "' + oldC + '" in "' + text + '" at index ' + index.toString());
|
39623 | }
|
39624 | } else {
|
39625 | // End of input.
|
39626 | break;
|
39627 | } // Verify the unit exists and get the prefix (if any)
|
39628 |
|
39629 |
|
39630 | var res = _findUnit(uStr);
|
39631 |
|
39632 | if (res === null) {
|
39633 | // Unit not found.
|
39634 | throw new SyntaxError('Unit "' + uStr + '" not found.');
|
39635 | }
|
39636 |
|
39637 | var power = powerMultiplierCurrent * powerMultiplierStackProduct; // Is there a "^ number"?
|
39638 |
|
39639 | skipWhitespace();
|
39640 |
|
39641 | if (parseCharacter('^')) {
|
39642 | skipWhitespace();
|
39643 | var p = parseNumber();
|
39644 |
|
39645 | if (p === null) {
|
39646 | // No valid number found for the power!
|
39647 | throw new SyntaxError('In "' + str + '", "^" must be followed by a floating-point number');
|
39648 | }
|
39649 |
|
39650 | power *= p;
|
39651 | } // Add the unit to the list
|
39652 |
|
39653 |
|
39654 | unit.units.push({
|
39655 | unit: res.unit,
|
39656 | prefix: res.prefix,
|
39657 | power: power
|
39658 | });
|
39659 |
|
39660 | for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
|
39661 | unit.dimensions[i] += (res.unit.dimensions[i] || 0) * power;
|
39662 | } // Check for and consume closing parentheses, popping from the stack.
|
39663 | // A ')' will always follow a unit.
|
39664 |
|
39665 |
|
39666 | skipWhitespace();
|
39667 |
|
39668 | while (c === ')') {
|
39669 | if (powerMultiplierStack.length === 0) {
|
39670 | throw new SyntaxError('Unmatched ")" in "' + text + '" at index ' + index.toString());
|
39671 | }
|
39672 |
|
39673 | powerMultiplierStackProduct /= powerMultiplierStack.pop();
|
39674 | next();
|
39675 | skipWhitespace();
|
39676 | } // "*" and "/" should mean we are expecting something to come next.
|
39677 | // Is there a forward slash? If so, negate powerMultiplierCurrent. The next unit or paren group is in the denominator.
|
39678 |
|
39679 |
|
39680 | expectingUnit = false;
|
39681 |
|
39682 | if (parseCharacter('*')) {
|
39683 | // explicit multiplication
|
39684 | powerMultiplierCurrent = 1;
|
39685 | expectingUnit = true;
|
39686 | } else if (parseCharacter('/')) {
|
39687 | // division
|
39688 | powerMultiplierCurrent = -1;
|
39689 | expectingUnit = true;
|
39690 | } else {
|
39691 | // implicit multiplication
|
39692 | powerMultiplierCurrent = 1;
|
39693 | } // Replace the unit into the auto unit system
|
39694 |
|
39695 |
|
39696 | if (res.unit.base) {
|
39697 | var baseDim = res.unit.base.key;
|
39698 | UNIT_SYSTEMS.auto[baseDim] = {
|
39699 | unit: res.unit,
|
39700 | prefix: res.prefix
|
39701 | };
|
39702 | }
|
39703 | } // Has the string been entirely consumed?
|
39704 |
|
39705 |
|
39706 | skipWhitespace();
|
39707 |
|
39708 | if (c) {
|
39709 | throw new SyntaxError('Could not parse: "' + str + '"');
|
39710 | } // Is there a trailing slash?
|
39711 |
|
39712 |
|
39713 | if (expectingUnit) {
|
39714 | throw new SyntaxError('Trailing characters: "' + str + '"');
|
39715 | } // Is the parentheses stack empty?
|
39716 |
|
39717 |
|
39718 | if (powerMultiplierStack.length !== 0) {
|
39719 | throw new SyntaxError('Unmatched "(" in "' + text + '"');
|
39720 | } // Are there any units at all?
|
39721 |
|
39722 |
|
39723 | if (unit.units.length === 0 && !options.allowNoUnits) {
|
39724 | throw new SyntaxError('"' + str + '" contains no units');
|
39725 | }
|
39726 |
|
39727 | unit.value = value !== undefined ? unit._normalize(value) : null;
|
39728 | return unit;
|
39729 | };
|
39730 | /**
|
39731 | * create a copy of this unit
|
39732 | * @memberof Unit
|
39733 | * @return {Unit} Returns a cloned version of the unit
|
39734 | */
|
39735 |
|
39736 |
|
39737 | Unit.prototype.clone = function () {
|
39738 | var unit = new Unit();
|
39739 | unit.fixPrefix = this.fixPrefix;
|
39740 | unit.skipAutomaticSimplification = this.skipAutomaticSimplification;
|
39741 | unit.value = clone(this.value);
|
39742 | unit.dimensions = this.dimensions.slice(0);
|
39743 | unit.units = [];
|
39744 |
|
39745 | for (var i = 0; i < this.units.length; i++) {
|
39746 | unit.units[i] = {};
|
39747 |
|
39748 | for (var p in this.units[i]) {
|
39749 | if (this.units[i].hasOwnProperty(p)) {
|
39750 | unit.units[i][p] = this.units[i][p];
|
39751 | }
|
39752 | }
|
39753 | }
|
39754 |
|
39755 | return unit;
|
39756 | };
|
39757 | /**
|
39758 | * Return whether the unit is derived (such as m/s, or cm^2, but not N)
|
39759 | * @memberof Unit
|
39760 | * @return {boolean} True if the unit is derived
|
39761 | */
|
39762 |
|
39763 |
|
39764 | Unit.prototype._isDerived = function () {
|
39765 | if (this.units.length === 0) {
|
39766 | return false;
|
39767 | }
|
39768 |
|
39769 | return this.units.length > 1 || Math.abs(this.units[0].power - 1.0) > 1e-15;
|
39770 | };
|
39771 | /**
|
39772 | * Normalize a value, based on its currently set unit(s)
|
39773 | * @memberof Unit
|
39774 | * @param {number | BigNumber | Fraction | boolean} value
|
39775 | * @return {number | BigNumber | Fraction | boolean} normalized value
|
39776 | * @private
|
39777 | */
|
39778 |
|
39779 |
|
39780 | Unit.prototype._normalize = function (value) {
|
39781 | var unitValue, unitOffset, unitPower, unitPrefixValue;
|
39782 | var convert;
|
39783 |
|
39784 | if (value === null || value === undefined || this.units.length === 0) {
|
39785 | return value;
|
39786 | } else if (this._isDerived()) {
|
39787 | // This is a derived unit, so do not apply offsets.
|
39788 | // For example, with J kg^-1 degC^-1 you would NOT want to apply the offset.
|
39789 | var res = value;
|
39790 | convert = Unit._getNumberConverter(getTypeOf(value)); // convert to Fraction or BigNumber if needed
|
39791 |
|
39792 | for (var i = 0; i < this.units.length; i++) {
|
39793 | unitValue = convert(this.units[i].unit.value);
|
39794 | unitPrefixValue = convert(this.units[i].prefix.value);
|
39795 | unitPower = convert(this.units[i].power);
|
39796 | res = multiply(res, pow(multiply(unitValue, unitPrefixValue), unitPower));
|
39797 | }
|
39798 |
|
39799 | return res;
|
39800 | } else {
|
39801 | // This is a single unit of power 1, like kg or degC
|
39802 | convert = Unit._getNumberConverter(getTypeOf(value)); // convert to Fraction or BigNumber if needed
|
39803 |
|
39804 | unitValue = convert(this.units[0].unit.value);
|
39805 | unitOffset = convert(this.units[0].unit.offset);
|
39806 | unitPrefixValue = convert(this.units[0].prefix.value);
|
39807 | return multiply(add(value, unitOffset), multiply(unitValue, unitPrefixValue));
|
39808 | }
|
39809 | };
|
39810 | /**
|
39811 | * Denormalize a value, based on its currently set unit(s)
|
39812 | * @memberof Unit
|
39813 | * @param {number} value
|
39814 | * @param {number} [prefixValue] Optional prefix value to be used (ignored if this is a derived unit)
|
39815 | * @return {number} denormalized value
|
39816 | * @private
|
39817 | */
|
39818 |
|
39819 |
|
39820 | Unit.prototype._denormalize = function (value, prefixValue) {
|
39821 | var unitValue, unitOffset, unitPower, unitPrefixValue;
|
39822 | var convert;
|
39823 |
|
39824 | if (value === null || value === undefined || this.units.length === 0) {
|
39825 | return value;
|
39826 | } else if (this._isDerived()) {
|
39827 | // This is a derived unit, so do not apply offsets.
|
39828 | // For example, with J kg^-1 degC^-1 you would NOT want to apply the offset.
|
39829 | // Also, prefixValue is ignored--but we will still use the prefix value stored in each unit, since kg is usually preferable to g unless the user decides otherwise.
|
39830 | var res = value;
|
39831 | convert = Unit._getNumberConverter(getTypeOf(value)); // convert to Fraction or BigNumber if needed
|
39832 |
|
39833 | for (var i = 0; i < this.units.length; i++) {
|
39834 | unitValue = convert(this.units[i].unit.value);
|
39835 | unitPrefixValue = convert(this.units[i].prefix.value);
|
39836 | unitPower = convert(this.units[i].power);
|
39837 | res = divide(res, pow(multiply(unitValue, unitPrefixValue), unitPower));
|
39838 | }
|
39839 |
|
39840 | return res;
|
39841 | } else {
|
39842 | // This is a single unit of power 1, like kg or degC
|
39843 | convert = Unit._getNumberConverter(getTypeOf(value)); // convert to Fraction or BigNumber if needed
|
39844 |
|
39845 | unitValue = convert(this.units[0].unit.value);
|
39846 | unitPrefixValue = convert(this.units[0].prefix.value);
|
39847 | unitOffset = convert(this.units[0].unit.offset);
|
39848 |
|
39849 | if (prefixValue === undefined || prefixValue === null) {
|
39850 | return subtract(divide(divide(value, unitValue), unitPrefixValue), unitOffset);
|
39851 | } else {
|
39852 | return subtract(divide(divide(value, unitValue), prefixValue), unitOffset);
|
39853 | }
|
39854 | }
|
39855 | };
|
39856 | /**
|
39857 | * Find a unit from a string
|
39858 | * @memberof Unit
|
39859 | * @param {string} str A string like 'cm' or 'inch'
|
39860 | * @returns {Object | null} result When found, an object with fields unit and
|
39861 | * prefix is returned. Else, null is returned.
|
39862 | * @private
|
39863 | */
|
39864 |
|
39865 |
|
39866 | function _findUnit(str) {
|
39867 | // First, match units names exactly. For example, a user could define 'mm' as 10^-4 m, which is silly, but then we would want 'mm' to match the user-defined unit.
|
39868 | if (UNITS.hasOwnProperty(str)) {
|
39869 | var unit = UNITS[str];
|
39870 | var prefix = unit.prefixes[''];
|
39871 | return {
|
39872 | unit: unit,
|
39873 | prefix: prefix
|
39874 | };
|
39875 | }
|
39876 |
|
39877 | for (var name in UNITS) {
|
39878 | if (UNITS.hasOwnProperty(name)) {
|
39879 | if (endsWith(str, name)) {
|
39880 | var _unit = UNITS[name];
|
39881 | var prefixLen = str.length - name.length;
|
39882 | var prefixName = str.substring(0, prefixLen);
|
39883 |
|
39884 | var _prefix = _unit.prefixes.hasOwnProperty(prefixName) ? _unit.prefixes[prefixName] : undefined;
|
39885 |
|
39886 | if (_prefix !== undefined) {
|
39887 | // store unit, prefix, and value
|
39888 | return {
|
39889 | unit: _unit,
|
39890 | prefix: _prefix
|
39891 | };
|
39892 | }
|
39893 | }
|
39894 | }
|
39895 | }
|
39896 |
|
39897 | return null;
|
39898 | }
|
39899 | /**
|
39900 | * Test if the given expression is a unit.
|
39901 | * The unit can have a prefix but cannot have a value.
|
39902 | * @memberof Unit
|
39903 | * @param {string} name A string to be tested whether it is a value less unit.
|
39904 | * The unit can have prefix, like "cm"
|
39905 | * @return {boolean} true if the given string is a unit
|
39906 | */
|
39907 |
|
39908 |
|
39909 | Unit.isValuelessUnit = function (name) {
|
39910 | return _findUnit(name) !== null;
|
39911 | };
|
39912 | /**
|
39913 | * check if this unit has given base unit
|
39914 | * If this unit is a derived unit, this will ALWAYS return false, since by definition base units are not derived.
|
39915 | * @memberof Unit
|
39916 | * @param {BASE_UNITS | string | undefined} base
|
39917 | */
|
39918 |
|
39919 |
|
39920 | Unit.prototype.hasBase = function (base) {
|
39921 | if (typeof base === 'string') {
|
39922 | base = BASE_UNITS[base];
|
39923 | }
|
39924 |
|
39925 | if (!base) {
|
39926 | return false;
|
39927 | } // All dimensions must be the same
|
39928 |
|
39929 |
|
39930 | for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
|
39931 | if (Math.abs((this.dimensions[i] || 0) - (base.dimensions[i] || 0)) > 1e-12) {
|
39932 | return false;
|
39933 | }
|
39934 | }
|
39935 |
|
39936 | return true;
|
39937 | };
|
39938 | /**
|
39939 | * Check if this unit has a base or bases equal to another base or bases
|
39940 | * For derived units, the exponent on each base also must match
|
39941 | * @memberof Unit
|
39942 | * @param {Unit} other
|
39943 | * @return {boolean} true if equal base
|
39944 | */
|
39945 |
|
39946 |
|
39947 | Unit.prototype.equalBase = function (other) {
|
39948 | // All dimensions must be the same
|
39949 | for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
|
39950 | if (Math.abs((this.dimensions[i] || 0) - (other.dimensions[i] || 0)) > 1e-12) {
|
39951 | return false;
|
39952 | }
|
39953 | }
|
39954 |
|
39955 | return true;
|
39956 | };
|
39957 | /**
|
39958 | * Check if this unit equals another unit
|
39959 | * @memberof Unit
|
39960 | * @param {Unit} other
|
39961 | * @return {boolean} true if both units are equal
|
39962 | */
|
39963 |
|
39964 |
|
39965 | Unit.prototype.equals = function (other) {
|
39966 | return this.equalBase(other) && equal(this.value, other.value);
|
39967 | };
|
39968 | /**
|
39969 | * Multiply this unit with another one
|
39970 | * @memberof Unit
|
39971 | * @param {Unit} other
|
39972 | * @return {Unit} product of this unit and the other unit
|
39973 | */
|
39974 |
|
39975 |
|
39976 | Unit.prototype.multiply = function (other) {
|
39977 | var res = this.clone();
|
39978 |
|
39979 | for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
|
39980 | // Dimensions arrays may be of different lengths. Default to 0.
|
39981 | res.dimensions[i] = (this.dimensions[i] || 0) + (other.dimensions[i] || 0);
|
39982 | } // Append other's units list onto res
|
39983 |
|
39984 |
|
39985 | for (var _i = 0; _i < other.units.length; _i++) {
|
39986 | // Make a deep copy
|
39987 | var inverted = {};
|
39988 |
|
39989 | for (var key in other.units[_i]) {
|
39990 | inverted[key] = other.units[_i][key];
|
39991 | }
|
39992 |
|
39993 | res.units.push(inverted);
|
39994 | } // If at least one operand has a value, then the result should also have a value
|
39995 |
|
39996 |
|
39997 | if (this.value !== null || other.value !== null) {
|
39998 | var valThis = this.value === null ? this._normalize(1) : this.value;
|
39999 | var valOther = other.value === null ? other._normalize(1) : other.value;
|
40000 | res.value = multiply(valThis, valOther);
|
40001 | } else {
|
40002 | res.value = null;
|
40003 | }
|
40004 |
|
40005 | res.skipAutomaticSimplification = false;
|
40006 | return getNumericIfUnitless(res);
|
40007 | };
|
40008 | /**
|
40009 | * Divide this unit by another one
|
40010 | * @memberof Unit
|
40011 | * @param {Unit} other
|
40012 | * @return {Unit} result of dividing this unit by the other unit
|
40013 | */
|
40014 |
|
40015 |
|
40016 | Unit.prototype.divide = function (other) {
|
40017 | var res = this.clone();
|
40018 |
|
40019 | for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
|
40020 | // Dimensions arrays may be of different lengths. Default to 0.
|
40021 | res.dimensions[i] = (this.dimensions[i] || 0) - (other.dimensions[i] || 0);
|
40022 | } // Invert and append other's units list onto res
|
40023 |
|
40024 |
|
40025 | for (var _i2 = 0; _i2 < other.units.length; _i2++) {
|
40026 | // Make a deep copy
|
40027 | var inverted = {};
|
40028 |
|
40029 | for (var key in other.units[_i2]) {
|
40030 | inverted[key] = other.units[_i2][key];
|
40031 | }
|
40032 |
|
40033 | inverted.power = -inverted.power;
|
40034 | res.units.push(inverted);
|
40035 | } // If at least one operand has a value, the result should have a value
|
40036 |
|
40037 |
|
40038 | if (this.value !== null || other.value !== null) {
|
40039 | var valThis = this.value === null ? this._normalize(1) : this.value;
|
40040 | var valOther = other.value === null ? other._normalize(1) : other.value;
|
40041 | res.value = divide(valThis, valOther);
|
40042 | } else {
|
40043 | res.value = null;
|
40044 | }
|
40045 |
|
40046 | res.skipAutomaticSimplification = false;
|
40047 | return getNumericIfUnitless(res);
|
40048 | };
|
40049 | /**
|
40050 | * Calculate the power of a unit
|
40051 | * @memberof Unit
|
40052 | * @param {number | Fraction | BigNumber} p
|
40053 | * @returns {Unit} The result: this^p
|
40054 | */
|
40055 |
|
40056 |
|
40057 | Unit.prototype.pow = function (p) {
|
40058 | var res = this.clone();
|
40059 |
|
40060 | for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
|
40061 | // Dimensions arrays may be of different lengths. Default to 0.
|
40062 | res.dimensions[i] = (this.dimensions[i] || 0) * p;
|
40063 | } // Adjust the power of each unit in the list
|
40064 |
|
40065 |
|
40066 | for (var _i3 = 0; _i3 < res.units.length; _i3++) {
|
40067 | res.units[_i3].power *= p;
|
40068 | }
|
40069 |
|
40070 | if (res.value !== null) {
|
40071 | res.value = pow(res.value, p); // only allow numeric output, we don't want to return a Complex number
|
40072 | // if (!isNumeric(res.value)) {
|
40073 | // res.value = NaN
|
40074 | // }
|
40075 | // Update: Complex supported now
|
40076 | } else {
|
40077 | res.value = null;
|
40078 | }
|
40079 |
|
40080 | res.skipAutomaticSimplification = false;
|
40081 | return getNumericIfUnitless(res);
|
40082 | };
|
40083 | /**
|
40084 | * Return the numeric value of this unit if it is dimensionless, has a value, and config.predictable == false; or the original unit otherwise
|
40085 | * @param {Unit} unit
|
40086 | * @returns {number | Fraction | BigNumber | Unit} The numeric value of the unit if conditions are met, or the original unit otherwise
|
40087 | */
|
40088 |
|
40089 |
|
40090 | function getNumericIfUnitless(unit) {
|
40091 | if (unit.equalBase(BASE_UNITS.NONE) && unit.value !== null && !config.predictable) {
|
40092 | return unit.value;
|
40093 | } else {
|
40094 | return unit;
|
40095 | }
|
40096 | }
|
40097 | /**
|
40098 | * Calculate the absolute value of a unit
|
40099 | * @memberof Unit
|
40100 | * @param {number | Fraction | BigNumber} x
|
40101 | * @returns {Unit} The result: |x|, absolute value of x
|
40102 | */
|
40103 |
|
40104 |
|
40105 | Unit.prototype.abs = function () {
|
40106 | // This gives correct, but unexpected, results for units with an offset.
|
40107 | // For example, abs(-283.15 degC) = -263.15 degC !!!
|
40108 | var ret = this.clone();
|
40109 | ret.value = ret.value !== null ? abs(ret.value) : null;
|
40110 |
|
40111 | for (var i in ret.units) {
|
40112 | if (ret.units[i].unit.name === 'VA' || ret.units[i].unit.name === 'VAR') {
|
40113 | ret.units[i].unit = UNITS['W'];
|
40114 | }
|
40115 | }
|
40116 |
|
40117 | return ret;
|
40118 | };
|
40119 | /**
|
40120 | * Convert the unit to a specific unit name.
|
40121 | * @memberof Unit
|
40122 | * @param {string | Unit} valuelessUnit A unit without value. Can have prefix, like "cm"
|
40123 | * @returns {Unit} Returns a clone of the unit with a fixed prefix and unit.
|
40124 | */
|
40125 |
|
40126 |
|
40127 | Unit.prototype.to = function (valuelessUnit) {
|
40128 | var other;
|
40129 | var value = this.value === null ? this._normalize(1) : this.value;
|
40130 |
|
40131 | if (typeof valuelessUnit === 'string') {
|
40132 | // other = new Unit(null, valuelessUnit)
|
40133 | other = Unit.parse(valuelessUnit);
|
40134 |
|
40135 | if (!this.equalBase(other)) {
|
40136 | throw new Error("Units do not match ('".concat(other.toString(), "' != '").concat(this.toString(), "')"));
|
40137 | }
|
40138 |
|
40139 | if (other.value !== null) {
|
40140 | throw new Error('Cannot convert to a unit with a value');
|
40141 | }
|
40142 |
|
40143 | other.value = clone(value);
|
40144 | other.fixPrefix = true;
|
40145 | other.skipAutomaticSimplification = true;
|
40146 | return other;
|
40147 | } else if (type.isUnit(valuelessUnit)) {
|
40148 | if (!this.equalBase(valuelessUnit)) {
|
40149 | throw new Error("Units do not match ('".concat(valuelessUnit.toString(), "' != '").concat(this.toString(), "')"));
|
40150 | }
|
40151 |
|
40152 | if (valuelessUnit.value !== null) {
|
40153 | throw new Error('Cannot convert to a unit with a value');
|
40154 | }
|
40155 |
|
40156 | other = valuelessUnit.clone();
|
40157 | other.value = clone(value);
|
40158 | other.fixPrefix = true;
|
40159 | other.skipAutomaticSimplification = true;
|
40160 | return other;
|
40161 | } else {
|
40162 | throw new Error('String or Unit expected as parameter');
|
40163 | }
|
40164 | };
|
40165 | /**
|
40166 | * Return the value of the unit when represented with given valueless unit
|
40167 | * @memberof Unit
|
40168 | * @param {string | Unit} valuelessUnit For example 'cm' or 'inch'
|
40169 | * @return {number} Returns the unit value as number.
|
40170 | */
|
40171 | // TODO: deprecate Unit.toNumber? It's always better to use toNumeric
|
40172 |
|
40173 |
|
40174 | Unit.prototype.toNumber = function (valuelessUnit) {
|
40175 | return toNumber(this.toNumeric(valuelessUnit));
|
40176 | };
|
40177 | /**
|
40178 | * Return the value of the unit in the original numeric type
|
40179 | * @memberof Unit
|
40180 | * @param {string | Unit} valuelessUnit For example 'cm' or 'inch'
|
40181 | * @return {number | BigNumber | Fraction} Returns the unit value
|
40182 | */
|
40183 |
|
40184 |
|
40185 | Unit.prototype.toNumeric = function (valuelessUnit) {
|
40186 | var other;
|
40187 |
|
40188 | if (valuelessUnit) {
|
40189 | // Allow getting the numeric value without converting to a different unit
|
40190 | other = this.to(valuelessUnit);
|
40191 | } else {
|
40192 | other = this.clone();
|
40193 | }
|
40194 |
|
40195 | if (other._isDerived()) {
|
40196 | return other._denormalize(other.value);
|
40197 | } else {
|
40198 | return other._denormalize(other.value, other.units[0].prefix.value);
|
40199 | }
|
40200 | };
|
40201 | /**
|
40202 | * Get a string representation of the unit.
|
40203 | * @memberof Unit
|
40204 | * @return {string}
|
40205 | */
|
40206 |
|
40207 |
|
40208 | Unit.prototype.toString = function () {
|
40209 | return this.format();
|
40210 | };
|
40211 | /**
|
40212 | * Get a JSON representation of the unit
|
40213 | * @memberof Unit
|
40214 | * @returns {Object} Returns a JSON object structured as:
|
40215 | * `{"mathjs": "Unit", "value": 2, "unit": "cm", "fixPrefix": false}`
|
40216 | */
|
40217 |
|
40218 |
|
40219 | Unit.prototype.toJSON = function () {
|
40220 | return {
|
40221 | mathjs: 'Unit',
|
40222 | value: this._denormalize(this.value),
|
40223 | unit: this.formatUnits(),
|
40224 | fixPrefix: this.fixPrefix
|
40225 | };
|
40226 | };
|
40227 | /**
|
40228 | * Instantiate a Unit from a JSON object
|
40229 | * @memberof Unit
|
40230 | * @param {Object} json A JSON object structured as:
|
40231 | * `{"mathjs": "Unit", "value": 2, "unit": "cm", "fixPrefix": false}`
|
40232 | * @return {Unit}
|
40233 | */
|
40234 |
|
40235 |
|
40236 | Unit.fromJSON = function (json) {
|
40237 | var unit = new Unit(json.value, json.unit);
|
40238 | unit.fixPrefix = json.fixPrefix || false;
|
40239 | return unit;
|
40240 | };
|
40241 | /**
|
40242 | * Returns the string representation of the unit.
|
40243 | * @memberof Unit
|
40244 | * @return {string}
|
40245 | */
|
40246 |
|
40247 |
|
40248 | Unit.prototype.valueOf = Unit.prototype.toString;
|
40249 | /**
|
40250 | * Simplify this Unit's unit list and return a new Unit with the simplified list.
|
40251 | * The returned Unit will contain a list of the "best" units for formatting.
|
40252 | */
|
40253 |
|
40254 | Unit.prototype.simplify = function () {
|
40255 | var ret = this.clone();
|
40256 | var proposedUnitList = []; // Search for a matching base
|
40257 |
|
40258 | var matchingBase;
|
40259 |
|
40260 | for (var key in currentUnitSystem) {
|
40261 | if (ret.hasBase(BASE_UNITS[key])) {
|
40262 | matchingBase = key;
|
40263 | break;
|
40264 | }
|
40265 | }
|
40266 |
|
40267 | if (matchingBase === 'NONE') {
|
40268 | ret.units = [];
|
40269 | } else {
|
40270 | var matchingUnit;
|
40271 |
|
40272 | if (matchingBase) {
|
40273 | // Does the unit system have a matching unit?
|
40274 | if (currentUnitSystem.hasOwnProperty(matchingBase)) {
|
40275 | matchingUnit = currentUnitSystem[matchingBase];
|
40276 | }
|
40277 | }
|
40278 |
|
40279 | if (matchingUnit) {
|
40280 | ret.units = [{
|
40281 | unit: matchingUnit.unit,
|
40282 | prefix: matchingUnit.prefix,
|
40283 | power: 1.0
|
40284 | }];
|
40285 | } else {
|
40286 | // Multiple units or units with powers are formatted like this:
|
40287 | // 5 (kg m^2) / (s^3 mol)
|
40288 | // Build an representation from the base units of the current unit system
|
40289 | var missingBaseDim = false;
|
40290 |
|
40291 | for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
|
40292 | var baseDim = BASE_DIMENSIONS[i];
|
40293 |
|
40294 | if (Math.abs(ret.dimensions[i] || 0) > 1e-12) {
|
40295 | if (currentUnitSystem.hasOwnProperty(baseDim)) {
|
40296 | proposedUnitList.push({
|
40297 | unit: currentUnitSystem[baseDim].unit,
|
40298 | prefix: currentUnitSystem[baseDim].prefix,
|
40299 | power: ret.dimensions[i] || 0
|
40300 | });
|
40301 | } else {
|
40302 | missingBaseDim = true;
|
40303 | }
|
40304 | }
|
40305 | } // Is the proposed unit list "simpler" than the existing one?
|
40306 |
|
40307 |
|
40308 | if (proposedUnitList.length < ret.units.length && !missingBaseDim) {
|
40309 | // Replace this unit list with the proposed list
|
40310 | ret.units = proposedUnitList;
|
40311 | }
|
40312 | }
|
40313 | }
|
40314 |
|
40315 | return ret;
|
40316 | };
|
40317 | /**
|
40318 | * Returns a new Unit in the SI system with the same value as this one
|
40319 | */
|
40320 |
|
40321 |
|
40322 | Unit.prototype.toSI = function () {
|
40323 | var ret = this.clone();
|
40324 | var proposedUnitList = []; // Multiple units or units with powers are formatted like this:
|
40325 | // 5 (kg m^2) / (s^3 mol)
|
40326 | // Build an representation from the base units of the SI unit system
|
40327 |
|
40328 | for (var i = 0; i < BASE_DIMENSIONS.length; i++) {
|
40329 | var baseDim = BASE_DIMENSIONS[i];
|
40330 |
|
40331 | if (Math.abs(ret.dimensions[i] || 0) > 1e-12) {
|
40332 | if (UNIT_SYSTEMS['si'].hasOwnProperty(baseDim)) {
|
40333 | proposedUnitList.push({
|
40334 | unit: UNIT_SYSTEMS['si'][baseDim].unit,
|
40335 | prefix: UNIT_SYSTEMS['si'][baseDim].prefix,
|
40336 | power: ret.dimensions[i] || 0
|
40337 | });
|
40338 | } else {
|
40339 | throw new Error('Cannot express custom unit ' + baseDim + ' in SI units');
|
40340 | }
|
40341 | }
|
40342 | } // Replace this unit list with the proposed list
|
40343 |
|
40344 |
|
40345 | ret.units = proposedUnitList;
|
40346 | ret.fixPrefix = true;
|
40347 | ret.skipAutomaticSimplification = true;
|
40348 | return ret;
|
40349 | };
|
40350 | /**
|
40351 | * Get a string representation of the units of this Unit, without the value. The unit list is formatted as-is without first being simplified.
|
40352 | * @memberof Unit
|
40353 | * @return {string}
|
40354 | */
|
40355 |
|
40356 |
|
40357 | Unit.prototype.formatUnits = function () {
|
40358 | var strNum = '';
|
40359 | var strDen = '';
|
40360 | var nNum = 0;
|
40361 | var nDen = 0;
|
40362 |
|
40363 | for (var i = 0; i < this.units.length; i++) {
|
40364 | if (this.units[i].power > 0) {
|
40365 | nNum++;
|
40366 | strNum += ' ' + this.units[i].prefix.name + this.units[i].unit.name;
|
40367 |
|
40368 | if (Math.abs(this.units[i].power - 1.0) > 1e-15) {
|
40369 | strNum += '^' + this.units[i].power;
|
40370 | }
|
40371 | } else if (this.units[i].power < 0) {
|
40372 | nDen++;
|
40373 | }
|
40374 | }
|
40375 |
|
40376 | if (nDen > 0) {
|
40377 | for (var _i4 = 0; _i4 < this.units.length; _i4++) {
|
40378 | if (this.units[_i4].power < 0) {
|
40379 | if (nNum > 0) {
|
40380 | strDen += ' ' + this.units[_i4].prefix.name + this.units[_i4].unit.name;
|
40381 |
|
40382 | if (Math.abs(this.units[_i4].power + 1.0) > 1e-15) {
|
40383 | strDen += '^' + -this.units[_i4].power;
|
40384 | }
|
40385 | } else {
|
40386 | strDen += ' ' + this.units[_i4].prefix.name + this.units[_i4].unit.name;
|
40387 | strDen += '^' + this.units[_i4].power;
|
40388 | }
|
40389 | }
|
40390 | }
|
40391 | } // Remove leading " "
|
40392 |
|
40393 |
|
40394 | strNum = strNum.substr(1);
|
40395 | strDen = strDen.substr(1); // Add parans for better copy/paste back into the eval, for example, or for better pretty print formatting
|
40396 |
|
40397 | if (nNum > 1 && nDen > 0) {
|
40398 | strNum = '(' + strNum + ')';
|
40399 | }
|
40400 |
|
40401 | if (nDen > 1 && nNum > 0) {
|
40402 | strDen = '(' + strDen + ')';
|
40403 | }
|
40404 |
|
40405 | var str = strNum;
|
40406 |
|
40407 | if (nNum > 0 && nDen > 0) {
|
40408 | str += ' / ';
|
40409 | }
|
40410 |
|
40411 | str += strDen;
|
40412 | return str;
|
40413 | };
|
40414 | /**
|
40415 | * Get a string representation of the Unit, with optional formatting options.
|
40416 | * @memberof Unit
|
40417 | * @param {Object | number | Function} [options] Formatting options. See
|
40418 | * lib/utils/number:format for a
|
40419 | * description of the available
|
40420 | * options.
|
40421 | * @return {string}
|
40422 | */
|
40423 |
|
40424 |
|
40425 | Unit.prototype.format = function (options) {
|
40426 | // Simplfy the unit list, unless it is valueless or was created directly in the
|
40427 | // constructor or as the result of to or toSI
|
40428 | var simp = this.skipAutomaticSimplification || this.value === null ? this.clone() : this.simplify(); // Apply some custom logic for handling VA and VAR. The goal is to express the value of the unit as a real value, if possible. Otherwise, use a real-valued unit instead of a complex-valued one.
|
40429 |
|
40430 | var isImaginary = false;
|
40431 |
|
40432 | if (typeof simp.value !== 'undefined' && simp.value !== null && type.isComplex(simp.value)) {
|
40433 | // TODO: Make this better, for example, use relative magnitude of re and im rather than absolute
|
40434 | isImaginary = Math.abs(simp.value.re) < 1e-14;
|
40435 | }
|
40436 |
|
40437 | for (var i in simp.units) {
|
40438 | if (simp.units[i].unit) {
|
40439 | if (simp.units[i].unit.name === 'VA' && isImaginary) {
|
40440 | simp.units[i].unit = UNITS['VAR'];
|
40441 | } else if (simp.units[i].unit.name === 'VAR' && !isImaginary) {
|
40442 | simp.units[i].unit = UNITS['VA'];
|
40443 | }
|
40444 | }
|
40445 | } // Now apply the best prefix
|
40446 | // Units must have only one unit and not have the fixPrefix flag set
|
40447 |
|
40448 |
|
40449 | if (simp.units.length === 1 && !simp.fixPrefix) {
|
40450 | // Units must have integer powers, otherwise the prefix will change the
|
40451 | // outputted value by not-an-integer-power-of-ten
|
40452 | if (Math.abs(simp.units[0].power - Math.round(simp.units[0].power)) < 1e-14) {
|
40453 | // Apply the best prefix
|
40454 | simp.units[0].prefix = simp._bestPrefix();
|
40455 | }
|
40456 | }
|
40457 |
|
40458 | var value = simp._denormalize(simp.value);
|
40459 |
|
40460 | var str = simp.value !== null ? format(value, options || {}) : '';
|
40461 | var unitStr = simp.formatUnits();
|
40462 |
|
40463 | if (simp.value && type.isComplex(simp.value)) {
|
40464 | str = '(' + str + ')'; // Surround complex values with ( ) to enable better parsing
|
40465 | }
|
40466 |
|
40467 | if (unitStr.length > 0 && str.length > 0) {
|
40468 | str += ' ';
|
40469 | }
|
40470 |
|
40471 | str += unitStr;
|
40472 | return str;
|
40473 | };
|
40474 | /**
|
40475 | * Calculate the best prefix using current value.
|
40476 | * @memberof Unit
|
40477 | * @returns {Object} prefix
|
40478 | * @private
|
40479 | */
|
40480 |
|
40481 |
|
40482 | Unit.prototype._bestPrefix = function () {
|
40483 | if (this.units.length !== 1) {
|
40484 | throw new Error('Can only compute the best prefix for single units with integer powers, like kg, s^2, N^-1, and so forth!');
|
40485 | }
|
40486 |
|
40487 | if (Math.abs(this.units[0].power - Math.round(this.units[0].power)) >= 1e-14) {
|
40488 | throw new Error('Can only compute the best prefix for single units with integer powers, like kg, s^2, N^-1, and so forth!');
|
40489 | } // find the best prefix value (resulting in the value of which
|
40490 | // the absolute value of the log10 is closest to zero,
|
40491 | // though with a little offset of 1.2 for nicer values: you get a
|
40492 | // sequence 1mm 100mm 500mm 0.6m 1m 10m 100m 500m 0.6km 1km ...
|
40493 | // Note: the units value can be any numeric type, but to find the best
|
40494 | // prefix it's enough to work with limited precision of a regular number
|
40495 | // Update: using mathjs abs since we also allow complex numbers
|
40496 |
|
40497 |
|
40498 | var absValue = this.value !== null ? abs(this.value) : 0;
|
40499 | var absUnitValue = abs(this.units[0].unit.value);
|
40500 | var bestPrefix = this.units[0].prefix;
|
40501 |
|
40502 | if (absValue === 0) {
|
40503 | return bestPrefix;
|
40504 | }
|
40505 |
|
40506 | var power = this.units[0].power;
|
40507 | var bestDiff = Math.log(absValue / Math.pow(bestPrefix.value * absUnitValue, power)) / Math.LN10 - 1.2;
|
40508 | if (bestDiff > -2.200001 && bestDiff < 1.800001) return bestPrefix; // Allow the original prefix
|
40509 |
|
40510 | bestDiff = Math.abs(bestDiff);
|
40511 | var prefixes = this.units[0].unit.prefixes;
|
40512 |
|
40513 | for (var p in prefixes) {
|
40514 | if (prefixes.hasOwnProperty(p)) {
|
40515 | var prefix = prefixes[p];
|
40516 |
|
40517 | if (prefix.scientific) {
|
40518 | var diff = Math.abs(Math.log(absValue / Math.pow(prefix.value * absUnitValue, power)) / Math.LN10 - 1.2);
|
40519 |
|
40520 | if (diff < bestDiff || diff === bestDiff && prefix.name.length < bestPrefix.name.length) {
|
40521 | // choose the prefix with the smallest diff, or if equal, choose the one
|
40522 | // with the shortest name (can happen with SHORTLONG for example)
|
40523 | bestPrefix = prefix;
|
40524 | bestDiff = diff;
|
40525 | }
|
40526 | }
|
40527 | }
|
40528 | }
|
40529 |
|
40530 | return bestPrefix;
|
40531 | };
|
40532 | /**
|
40533 | * Returns an array of units whose sum is equal to this unit
|
40534 | * @memberof Unit
|
40535 | * @param {Array} [parts] An array of strings or valueless units.
|
40536 | *
|
40537 | * Example:
|
40538 | *
|
40539 | * const u = new Unit(1, 'm')
|
40540 | * u.splitUnit(['feet', 'inch'])
|
40541 | * [ 3 feet, 3.3700787401575 inch ]
|
40542 | *
|
40543 | * @return {Array} An array of units.
|
40544 | */
|
40545 |
|
40546 |
|
40547 | Unit.prototype.splitUnit = function (parts) {
|
40548 | var x = this.clone();
|
40549 | var ret = [];
|
40550 |
|
40551 | for (var i = 0; i < parts.length; i++) {
|
40552 | // Convert x to the requested unit
|
40553 | x = x.to(parts[i]);
|
40554 | if (i === parts.length - 1) break; // Get the numeric value of this unit
|
40555 |
|
40556 | var xNumeric = x.toNumeric(); // Check to see if xNumeric is nearly equal to an integer,
|
40557 | // since fix can incorrectly round down if there is round-off error
|
40558 |
|
40559 | var xRounded = round(xNumeric);
|
40560 | var xFixed = void 0;
|
40561 | var isNearlyEqual = equal(xRounded, xNumeric);
|
40562 |
|
40563 | if (isNearlyEqual) {
|
40564 | xFixed = xRounded;
|
40565 | } else {
|
40566 | xFixed = fix(x.toNumeric());
|
40567 | }
|
40568 |
|
40569 | var y = new Unit(xFixed, parts[i].toString());
|
40570 | ret.push(y);
|
40571 | x = subtract(x, y);
|
40572 | } // This little bit fixes a bug where the remainder should be 0 but is a little bit off.
|
40573 | // But instead of comparing x, the remainder, with zero--we will compare the sum of
|
40574 | // all the parts so far with the original value. If they are nearly equal,
|
40575 | // we set the remainder to 0.
|
40576 |
|
40577 |
|
40578 | var testSum = 0;
|
40579 |
|
40580 | for (var _i5 = 0; _i5 < ret.length; _i5++) {
|
40581 | testSum = add(testSum, ret[_i5].value);
|
40582 | }
|
40583 |
|
40584 | if (equal(testSum, this.value)) {
|
40585 | x.value = 0;
|
40586 | }
|
40587 |
|
40588 | ret.push(x);
|
40589 | return ret;
|
40590 | };
|
40591 |
|
40592 | var PREFIXES = {
|
40593 | NONE: {
|
40594 | '': {
|
40595 | name: '',
|
40596 | value: 1,
|
40597 | scientific: true
|
40598 | }
|
40599 | },
|
40600 | SHORT: {
|
40601 | '': {
|
40602 | name: '',
|
40603 | value: 1,
|
40604 | scientific: true
|
40605 | },
|
40606 | 'da': {
|
40607 | name: 'da',
|
40608 | value: 1e1,
|
40609 | scientific: false
|
40610 | },
|
40611 | 'h': {
|
40612 | name: 'h',
|
40613 | value: 1e2,
|
40614 | scientific: false
|
40615 | },
|
40616 | 'k': {
|
40617 | name: 'k',
|
40618 | value: 1e3,
|
40619 | scientific: true
|
40620 | },
|
40621 | 'M': {
|
40622 | name: 'M',
|
40623 | value: 1e6,
|
40624 | scientific: true
|
40625 | },
|
40626 | 'G': {
|
40627 | name: 'G',
|
40628 | value: 1e9,
|
40629 | scientific: true
|
40630 | },
|
40631 | 'T': {
|
40632 | name: 'T',
|
40633 | value: 1e12,
|
40634 | scientific: true
|
40635 | },
|
40636 | 'P': {
|
40637 | name: 'P',
|
40638 | value: 1e15,
|
40639 | scientific: true
|
40640 | },
|
40641 | 'E': {
|
40642 | name: 'E',
|
40643 | value: 1e18,
|
40644 | scientific: true
|
40645 | },
|
40646 | 'Z': {
|
40647 | name: 'Z',
|
40648 | value: 1e21,
|
40649 | scientific: true
|
40650 | },
|
40651 | 'Y': {
|
40652 | name: 'Y',
|
40653 | value: 1e24,
|
40654 | scientific: true
|
40655 | },
|
40656 | 'd': {
|
40657 | name: 'd',
|
40658 | value: 1e-1,
|
40659 | scientific: false
|
40660 | },
|
40661 | 'c': {
|
40662 | name: 'c',
|
40663 | value: 1e-2,
|
40664 | scientific: false
|
40665 | },
|
40666 | 'm': {
|
40667 | name: 'm',
|
40668 | value: 1e-3,
|
40669 | scientific: true
|
40670 | },
|
40671 | 'u': {
|
40672 | name: 'u',
|
40673 | value: 1e-6,
|
40674 | scientific: true
|
40675 | },
|
40676 | 'n': {
|
40677 | name: 'n',
|
40678 | value: 1e-9,
|
40679 | scientific: true
|
40680 | },
|
40681 | 'p': {
|
40682 | name: 'p',
|
40683 | value: 1e-12,
|
40684 | scientific: true
|
40685 | },
|
40686 | 'f': {
|
40687 | name: 'f',
|
40688 | value: 1e-15,
|
40689 | scientific: true
|
40690 | },
|
40691 | 'a': {
|
40692 | name: 'a',
|
40693 | value: 1e-18,
|
40694 | scientific: true
|
40695 | },
|
40696 | 'z': {
|
40697 | name: 'z',
|
40698 | value: 1e-21,
|
40699 | scientific: true
|
40700 | },
|
40701 | 'y': {
|
40702 | name: 'y',
|
40703 | value: 1e-24,
|
40704 | scientific: true
|
40705 | }
|
40706 | },
|
40707 | LONG: {
|
40708 | '': {
|
40709 | name: '',
|
40710 | value: 1,
|
40711 | scientific: true
|
40712 | },
|
40713 | 'deca': {
|
40714 | name: 'deca',
|
40715 | value: 1e1,
|
40716 | scientific: false
|
40717 | },
|
40718 | 'hecto': {
|
40719 | name: 'hecto',
|
40720 | value: 1e2,
|
40721 | scientific: false
|
40722 | },
|
40723 | 'kilo': {
|
40724 | name: 'kilo',
|
40725 | value: 1e3,
|
40726 | scientific: true
|
40727 | },
|
40728 | 'mega': {
|
40729 | name: 'mega',
|
40730 | value: 1e6,
|
40731 | scientific: true
|
40732 | },
|
40733 | 'giga': {
|
40734 | name: 'giga',
|
40735 | value: 1e9,
|
40736 | scientific: true
|
40737 | },
|
40738 | 'tera': {
|
40739 | name: 'tera',
|
40740 | value: 1e12,
|
40741 | scientific: true
|
40742 | },
|
40743 | 'peta': {
|
40744 | name: 'peta',
|
40745 | value: 1e15,
|
40746 | scientific: true
|
40747 | },
|
40748 | 'exa': {
|
40749 | name: 'exa',
|
40750 | value: 1e18,
|
40751 | scientific: true
|
40752 | },
|
40753 | 'zetta': {
|
40754 | name: 'zetta',
|
40755 | value: 1e21,
|
40756 | scientific: true
|
40757 | },
|
40758 | 'yotta': {
|
40759 | name: 'yotta',
|
40760 | value: 1e24,
|
40761 | scientific: true
|
40762 | },
|
40763 | 'deci': {
|
40764 | name: 'deci',
|
40765 | value: 1e-1,
|
40766 | scientific: false
|
40767 | },
|
40768 | 'centi': {
|
40769 | name: 'centi',
|
40770 | value: 1e-2,
|
40771 | scientific: false
|
40772 | },
|
40773 | 'milli': {
|
40774 | name: 'milli',
|
40775 | value: 1e-3,
|
40776 | scientific: true
|
40777 | },
|
40778 | 'micro': {
|
40779 | name: 'micro',
|
40780 | value: 1e-6,
|
40781 | scientific: true
|
40782 | },
|
40783 | 'nano': {
|
40784 | name: 'nano',
|
40785 | value: 1e-9,
|
40786 | scientific: true
|
40787 | },
|
40788 | 'pico': {
|
40789 | name: 'pico',
|
40790 | value: 1e-12,
|
40791 | scientific: true
|
40792 | },
|
40793 | 'femto': {
|
40794 | name: 'femto',
|
40795 | value: 1e-15,
|
40796 | scientific: true
|
40797 | },
|
40798 | 'atto': {
|
40799 | name: 'atto',
|
40800 | value: 1e-18,
|
40801 | scientific: true
|
40802 | },
|
40803 | 'zepto': {
|
40804 | name: 'zepto',
|
40805 | value: 1e-21,
|
40806 | scientific: true
|
40807 | },
|
40808 | 'yocto': {
|
40809 | name: 'yocto',
|
40810 | value: 1e-24,
|
40811 | scientific: true
|
40812 | }
|
40813 | },
|
40814 | SQUARED: {
|
40815 | '': {
|
40816 | name: '',
|
40817 | value: 1,
|
40818 | scientific: true
|
40819 | },
|
40820 | 'da': {
|
40821 | name: 'da',
|
40822 | value: 1e2,
|
40823 | scientific: false
|
40824 | },
|
40825 | 'h': {
|
40826 | name: 'h',
|
40827 | value: 1e4,
|
40828 | scientific: false
|
40829 | },
|
40830 | 'k': {
|
40831 | name: 'k',
|
40832 | value: 1e6,
|
40833 | scientific: true
|
40834 | },
|
40835 | 'M': {
|
40836 | name: 'M',
|
40837 | value: 1e12,
|
40838 | scientific: true
|
40839 | },
|
40840 | 'G': {
|
40841 | name: 'G',
|
40842 | value: 1e18,
|
40843 | scientific: true
|
40844 | },
|
40845 | 'T': {
|
40846 | name: 'T',
|
40847 | value: 1e24,
|
40848 | scientific: true
|
40849 | },
|
40850 | 'P': {
|
40851 | name: 'P',
|
40852 | value: 1e30,
|
40853 | scientific: true
|
40854 | },
|
40855 | 'E': {
|
40856 | name: 'E',
|
40857 | value: 1e36,
|
40858 | scientific: true
|
40859 | },
|
40860 | 'Z': {
|
40861 | name: 'Z',
|
40862 | value: 1e42,
|
40863 | scientific: true
|
40864 | },
|
40865 | 'Y': {
|
40866 | name: 'Y',
|
40867 | value: 1e48,
|
40868 | scientific: true
|
40869 | },
|
40870 | 'd': {
|
40871 | name: 'd',
|
40872 | value: 1e-2,
|
40873 | scientific: false
|
40874 | },
|
40875 | 'c': {
|
40876 | name: 'c',
|
40877 | value: 1e-4,
|
40878 | scientific: false
|
40879 | },
|
40880 | 'm': {
|
40881 | name: 'm',
|
40882 | value: 1e-6,
|
40883 | scientific: true
|
40884 | },
|
40885 | 'u': {
|
40886 | name: 'u',
|
40887 | value: 1e-12,
|
40888 | scientific: true
|
40889 | },
|
40890 | 'n': {
|
40891 | name: 'n',
|
40892 | value: 1e-18,
|
40893 | scientific: true
|
40894 | },
|
40895 | 'p': {
|
40896 | name: 'p',
|
40897 | value: 1e-24,
|
40898 | scientific: true
|
40899 | },
|
40900 | 'f': {
|
40901 | name: 'f',
|
40902 | value: 1e-30,
|
40903 | scientific: true
|
40904 | },
|
40905 | 'a': {
|
40906 | name: 'a',
|
40907 | value: 1e-36,
|
40908 | scientific: true
|
40909 | },
|
40910 | 'z': {
|
40911 | name: 'z',
|
40912 | value: 1e-42,
|
40913 | scientific: true
|
40914 | },
|
40915 | 'y': {
|
40916 | name: 'y',
|
40917 | value: 1e-48,
|
40918 | scientific: true
|
40919 | }
|
40920 | },
|
40921 | CUBIC: {
|
40922 | '': {
|
40923 | name: '',
|
40924 | value: 1,
|
40925 | scientific: true
|
40926 | },
|
40927 | 'da': {
|
40928 | name: 'da',
|
40929 | value: 1e3,
|
40930 | scientific: false
|
40931 | },
|
40932 | 'h': {
|
40933 | name: 'h',
|
40934 | value: 1e6,
|
40935 | scientific: false
|
40936 | },
|
40937 | 'k': {
|
40938 | name: 'k',
|
40939 | value: 1e9,
|
40940 | scientific: true
|
40941 | },
|
40942 | 'M': {
|
40943 | name: 'M',
|
40944 | value: 1e18,
|
40945 | scientific: true
|
40946 | },
|
40947 | 'G': {
|
40948 | name: 'G',
|
40949 | value: 1e27,
|
40950 | scientific: true
|
40951 | },
|
40952 | 'T': {
|
40953 | name: 'T',
|
40954 | value: 1e36,
|
40955 | scientific: true
|
40956 | },
|
40957 | 'P': {
|
40958 | name: 'P',
|
40959 | value: 1e45,
|
40960 | scientific: true
|
40961 | },
|
40962 | 'E': {
|
40963 | name: 'E',
|
40964 | value: 1e54,
|
40965 | scientific: true
|
40966 | },
|
40967 | 'Z': {
|
40968 | name: 'Z',
|
40969 | value: 1e63,
|
40970 | scientific: true
|
40971 | },
|
40972 | 'Y': {
|
40973 | name: 'Y',
|
40974 | value: 1e72,
|
40975 | scientific: true
|
40976 | },
|
40977 | 'd': {
|
40978 | name: 'd',
|
40979 | value: 1e-3,
|
40980 | scientific: false
|
40981 | },
|
40982 | 'c': {
|
40983 | name: 'c',
|
40984 | value: 1e-6,
|
40985 | scientific: false
|
40986 | },
|
40987 | 'm': {
|
40988 | name: 'm',
|
40989 | value: 1e-9,
|
40990 | scientific: true
|
40991 | },
|
40992 | 'u': {
|
40993 | name: 'u',
|
40994 | value: 1e-18,
|
40995 | scientific: true
|
40996 | },
|
40997 | 'n': {
|
40998 | name: 'n',
|
40999 | value: 1e-27,
|
41000 | scientific: true
|
41001 | },
|
41002 | 'p': {
|
41003 | name: 'p',
|
41004 | value: 1e-36,
|
41005 | scientific: true
|
41006 | },
|
41007 | 'f': {
|
41008 | name: 'f',
|
41009 | value: 1e-45,
|
41010 | scientific: true
|
41011 | },
|
41012 | 'a': {
|
41013 | name: 'a',
|
41014 | value: 1e-54,
|
41015 | scientific: true
|
41016 | },
|
41017 | 'z': {
|
41018 | name: 'z',
|
41019 | value: 1e-63,
|
41020 | scientific: true
|
41021 | },
|
41022 | 'y': {
|
41023 | name: 'y',
|
41024 | value: 1e-72,
|
41025 | scientific: true
|
41026 | }
|
41027 | },
|
41028 | BINARY_SHORT_SI: {
|
41029 | '': {
|
41030 | name: '',
|
41031 | value: 1,
|
41032 | scientific: true
|
41033 | },
|
41034 | 'k': {
|
41035 | name: 'k',
|
41036 | value: 1e3,
|
41037 | scientific: true
|
41038 | },
|
41039 | 'M': {
|
41040 | name: 'M',
|
41041 | value: 1e6,
|
41042 | scientific: true
|
41043 | },
|
41044 | 'G': {
|
41045 | name: 'G',
|
41046 | value: 1e9,
|
41047 | scientific: true
|
41048 | },
|
41049 | 'T': {
|
41050 | name: 'T',
|
41051 | value: 1e12,
|
41052 | scientific: true
|
41053 | },
|
41054 | 'P': {
|
41055 | name: 'P',
|
41056 | value: 1e15,
|
41057 | scientific: true
|
41058 | },
|
41059 | 'E': {
|
41060 | name: 'E',
|
41061 | value: 1e18,
|
41062 | scientific: true
|
41063 | },
|
41064 | 'Z': {
|
41065 | name: 'Z',
|
41066 | value: 1e21,
|
41067 | scientific: true
|
41068 | },
|
41069 | 'Y': {
|
41070 | name: 'Y',
|
41071 | value: 1e24,
|
41072 | scientific: true
|
41073 | }
|
41074 | },
|
41075 | BINARY_SHORT_IEC: {
|
41076 | '': {
|
41077 | name: '',
|
41078 | value: 1,
|
41079 | scientific: true
|
41080 | },
|
41081 | 'Ki': {
|
41082 | name: 'Ki',
|
41083 | value: 1024,
|
41084 | scientific: true
|
41085 | },
|
41086 | 'Mi': {
|
41087 | name: 'Mi',
|
41088 | value: Math.pow(1024, 2),
|
41089 | scientific: true
|
41090 | },
|
41091 | 'Gi': {
|
41092 | name: 'Gi',
|
41093 | value: Math.pow(1024, 3),
|
41094 | scientific: true
|
41095 | },
|
41096 | 'Ti': {
|
41097 | name: 'Ti',
|
41098 | value: Math.pow(1024, 4),
|
41099 | scientific: true
|
41100 | },
|
41101 | 'Pi': {
|
41102 | name: 'Pi',
|
41103 | value: Math.pow(1024, 5),
|
41104 | scientific: true
|
41105 | },
|
41106 | 'Ei': {
|
41107 | name: 'Ei',
|
41108 | value: Math.pow(1024, 6),
|
41109 | scientific: true
|
41110 | },
|
41111 | 'Zi': {
|
41112 | name: 'Zi',
|
41113 | value: Math.pow(1024, 7),
|
41114 | scientific: true
|
41115 | },
|
41116 | 'Yi': {
|
41117 | name: 'Yi',
|
41118 | value: Math.pow(1024, 8),
|
41119 | scientific: true
|
41120 | }
|
41121 | },
|
41122 | BINARY_LONG_SI: {
|
41123 | '': {
|
41124 | name: '',
|
41125 | value: 1,
|
41126 | scientific: true
|
41127 | },
|
41128 | 'kilo': {
|
41129 | name: 'kilo',
|
41130 | value: 1e3,
|
41131 | scientific: true
|
41132 | },
|
41133 | 'mega': {
|
41134 | name: 'mega',
|
41135 | value: 1e6,
|
41136 | scientific: true
|
41137 | },
|
41138 | 'giga': {
|
41139 | name: 'giga',
|
41140 | value: 1e9,
|
41141 | scientific: true
|
41142 | },
|
41143 | 'tera': {
|
41144 | name: 'tera',
|
41145 | value: 1e12,
|
41146 | scientific: true
|
41147 | },
|
41148 | 'peta': {
|
41149 | name: 'peta',
|
41150 | value: 1e15,
|
41151 | scientific: true
|
41152 | },
|
41153 | 'exa': {
|
41154 | name: 'exa',
|
41155 | value: 1e18,
|
41156 | scientific: true
|
41157 | },
|
41158 | 'zetta': {
|
41159 | name: 'zetta',
|
41160 | value: 1e21,
|
41161 | scientific: true
|
41162 | },
|
41163 | 'yotta': {
|
41164 | name: 'yotta',
|
41165 | value: 1e24,
|
41166 | scientific: true
|
41167 | }
|
41168 | },
|
41169 | BINARY_LONG_IEC: {
|
41170 | '': {
|
41171 | name: '',
|
41172 | value: 1,
|
41173 | scientific: true
|
41174 | },
|
41175 | 'kibi': {
|
41176 | name: 'kibi',
|
41177 | value: 1024,
|
41178 | scientific: true
|
41179 | },
|
41180 | 'mebi': {
|
41181 | name: 'mebi',
|
41182 | value: Math.pow(1024, 2),
|
41183 | scientific: true
|
41184 | },
|
41185 | 'gibi': {
|
41186 | name: 'gibi',
|
41187 | value: Math.pow(1024, 3),
|
41188 | scientific: true
|
41189 | },
|
41190 | 'tebi': {
|
41191 | name: 'tebi',
|
41192 | value: Math.pow(1024, 4),
|
41193 | scientific: true
|
41194 | },
|
41195 | 'pebi': {
|
41196 | name: 'pebi',
|
41197 | value: Math.pow(1024, 5),
|
41198 | scientific: true
|
41199 | },
|
41200 | 'exi': {
|
41201 | name: 'exi',
|
41202 | value: Math.pow(1024, 6),
|
41203 | scientific: true
|
41204 | },
|
41205 | 'zebi': {
|
41206 | name: 'zebi',
|
41207 | value: Math.pow(1024, 7),
|
41208 | scientific: true
|
41209 | },
|
41210 | 'yobi': {
|
41211 | name: 'yobi',
|
41212 | value: Math.pow(1024, 8),
|
41213 | scientific: true
|
41214 | }
|
41215 | },
|
41216 | BTU: {
|
41217 | '': {
|
41218 | name: '',
|
41219 | value: 1,
|
41220 | scientific: true
|
41221 | },
|
41222 | 'MM': {
|
41223 | name: 'MM',
|
41224 | value: 1e6,
|
41225 | scientific: true
|
41226 | }
|
41227 | }
|
41228 | };
|
41229 | PREFIXES.SHORTLONG = _extends(PREFIXES.SHORT, PREFIXES.LONG);
|
41230 | PREFIXES.BINARY_SHORT = _extends(PREFIXES.BINARY_SHORT_SI, PREFIXES.BINARY_SHORT_IEC);
|
41231 | PREFIXES.BINARY_LONG = _extends(PREFIXES.BINARY_LONG_SI, PREFIXES.BINARY_LONG_IEC);
|
41232 | /* Internally, each unit is represented by a value and a dimension array. The elements of the dimensions array have the following meaning:
|
41233 | * Index Dimension
|
41234 | * ----- ---------
|
41235 | * 0 Length
|
41236 | * 1 Mass
|
41237 | * 2 Time
|
41238 | * 3 Current
|
41239 | * 4 Temperature
|
41240 | * 5 Luminous intensity
|
41241 | * 6 Amount of substance
|
41242 | * 7 Angle
|
41243 | * 8 Bit (digital)
|
41244 | * For example, the unit "298.15 K" is a pure temperature and would have a value of 298.15 and a dimension array of [0, 0, 0, 0, 1, 0, 0, 0, 0]. The unit "1 cal / (gm °C)" can be written in terms of the 9 fundamental dimensions as [length^2] / ([time^2] * [temperature]), and would a value of (after conversion to SI) 4184.0 and a dimensions array of [2, 0, -2, 0, -1, 0, 0, 0, 0].
|
41245 | *
|
41246 | */
|
41247 |
|
41248 | var BASE_DIMENSIONS = ['MASS', 'LENGTH', 'TIME', 'CURRENT', 'TEMPERATURE', 'LUMINOUS_INTENSITY', 'AMOUNT_OF_SUBSTANCE', 'ANGLE', 'BIT'];
|
41249 | var BASE_UNITS = {
|
41250 | NONE: {
|
41251 | dimensions: [0, 0, 0, 0, 0, 0, 0, 0, 0]
|
41252 | },
|
41253 | MASS: {
|
41254 | dimensions: [1, 0, 0, 0, 0, 0, 0, 0, 0]
|
41255 | },
|
41256 | LENGTH: {
|
41257 | dimensions: [0, 1, 0, 0, 0, 0, 0, 0, 0]
|
41258 | },
|
41259 | TIME: {
|
41260 | dimensions: [0, 0, 1, 0, 0, 0, 0, 0, 0]
|
41261 | },
|
41262 | CURRENT: {
|
41263 | dimensions: [0, 0, 0, 1, 0, 0, 0, 0, 0]
|
41264 | },
|
41265 | TEMPERATURE: {
|
41266 | dimensions: [0, 0, 0, 0, 1, 0, 0, 0, 0]
|
41267 | },
|
41268 | LUMINOUS_INTENSITY: {
|
41269 | dimensions: [0, 0, 0, 0, 0, 1, 0, 0, 0]
|
41270 | },
|
41271 | AMOUNT_OF_SUBSTANCE: {
|
41272 | dimensions: [0, 0, 0, 0, 0, 0, 1, 0, 0]
|
41273 | },
|
41274 | FORCE: {
|
41275 | dimensions: [1, 1, -2, 0, 0, 0, 0, 0, 0]
|
41276 | },
|
41277 | SURFACE: {
|
41278 | dimensions: [0, 2, 0, 0, 0, 0, 0, 0, 0]
|
41279 | },
|
41280 | VOLUME: {
|
41281 | dimensions: [0, 3, 0, 0, 0, 0, 0, 0, 0]
|
41282 | },
|
41283 | ENERGY: {
|
41284 | dimensions: [1, 2, -2, 0, 0, 0, 0, 0, 0]
|
41285 | },
|
41286 | POWER: {
|
41287 | dimensions: [1, 2, -3, 0, 0, 0, 0, 0, 0]
|
41288 | },
|
41289 | PRESSURE: {
|
41290 | dimensions: [1, -1, -2, 0, 0, 0, 0, 0, 0]
|
41291 | },
|
41292 | ELECTRIC_CHARGE: {
|
41293 | dimensions: [0, 0, 1, 1, 0, 0, 0, 0, 0]
|
41294 | },
|
41295 | ELECTRIC_CAPACITANCE: {
|
41296 | dimensions: [-1, -2, 4, 2, 0, 0, 0, 0, 0]
|
41297 | },
|
41298 | ELECTRIC_POTENTIAL: {
|
41299 | dimensions: [1, 2, -3, -1, 0, 0, 0, 0, 0]
|
41300 | },
|
41301 | ELECTRIC_RESISTANCE: {
|
41302 | dimensions: [1, 2, -3, -2, 0, 0, 0, 0, 0]
|
41303 | },
|
41304 | ELECTRIC_INDUCTANCE: {
|
41305 | dimensions: [1, 2, -2, -2, 0, 0, 0, 0, 0]
|
41306 | },
|
41307 | ELECTRIC_CONDUCTANCE: {
|
41308 | dimensions: [-1, -2, 3, 2, 0, 0, 0, 0, 0]
|
41309 | },
|
41310 | MAGNETIC_FLUX: {
|
41311 | dimensions: [1, 2, -2, -1, 0, 0, 0, 0, 0]
|
41312 | },
|
41313 | MAGNETIC_FLUX_DENSITY: {
|
41314 | dimensions: [1, 0, -2, -1, 0, 0, 0, 0, 0]
|
41315 | },
|
41316 | FREQUENCY: {
|
41317 | dimensions: [0, 0, -1, 0, 0, 0, 0, 0, 0]
|
41318 | },
|
41319 | ANGLE: {
|
41320 | dimensions: [0, 0, 0, 0, 0, 0, 0, 1, 0]
|
41321 | },
|
41322 | BIT: {
|
41323 | dimensions: [0, 0, 0, 0, 0, 0, 0, 0, 1]
|
41324 | }
|
41325 | };
|
41326 |
|
41327 | for (var key in BASE_UNITS) {
|
41328 | BASE_UNITS[key].key = key;
|
41329 | }
|
41330 |
|
41331 | var BASE_UNIT_NONE = {};
|
41332 | var UNIT_NONE = {
|
41333 | name: '',
|
41334 | base: BASE_UNIT_NONE,
|
41335 | value: 1,
|
41336 | offset: 0,
|
41337 | dimensions: BASE_DIMENSIONS.map(function (x) {
|
41338 | return 0;
|
41339 | })
|
41340 | };
|
41341 | var UNITS = {
|
41342 | // length
|
41343 | meter: {
|
41344 | name: 'meter',
|
41345 | base: BASE_UNITS.LENGTH,
|
41346 | prefixes: PREFIXES.LONG,
|
41347 | value: 1,
|
41348 | offset: 0
|
41349 | },
|
41350 | inch: {
|
41351 | name: 'inch',
|
41352 | base: BASE_UNITS.LENGTH,
|
41353 | prefixes: PREFIXES.NONE,
|
41354 | value: 0.0254,
|
41355 | offset: 0
|
41356 | },
|
41357 | foot: {
|
41358 | name: 'foot',
|
41359 | base: BASE_UNITS.LENGTH,
|
41360 | prefixes: PREFIXES.NONE,
|
41361 | value: 0.3048,
|
41362 | offset: 0
|
41363 | },
|
41364 | yard: {
|
41365 | name: 'yard',
|
41366 | base: BASE_UNITS.LENGTH,
|
41367 | prefixes: PREFIXES.NONE,
|
41368 | value: 0.9144,
|
41369 | offset: 0
|
41370 | },
|
41371 | mile: {
|
41372 | name: 'mile',
|
41373 | base: BASE_UNITS.LENGTH,
|
41374 | prefixes: PREFIXES.NONE,
|
41375 | value: 1609.344,
|
41376 | offset: 0
|
41377 | },
|
41378 | link: {
|
41379 | name: 'link',
|
41380 | base: BASE_UNITS.LENGTH,
|
41381 | prefixes: PREFIXES.NONE,
|
41382 | value: 0.201168,
|
41383 | offset: 0
|
41384 | },
|
41385 | rod: {
|
41386 | name: 'rod',
|
41387 | base: BASE_UNITS.LENGTH,
|
41388 | prefixes: PREFIXES.NONE,
|
41389 | value: 5.0292,
|
41390 | offset: 0
|
41391 | },
|
41392 | chain: {
|
41393 | name: 'chain',
|
41394 | base: BASE_UNITS.LENGTH,
|
41395 | prefixes: PREFIXES.NONE,
|
41396 | value: 20.1168,
|
41397 | offset: 0
|
41398 | },
|
41399 | angstrom: {
|
41400 | name: 'angstrom',
|
41401 | base: BASE_UNITS.LENGTH,
|
41402 | prefixes: PREFIXES.NONE,
|
41403 | value: 1e-10,
|
41404 | offset: 0
|
41405 | },
|
41406 | m: {
|
41407 | name: 'm',
|
41408 | base: BASE_UNITS.LENGTH,
|
41409 | prefixes: PREFIXES.SHORT,
|
41410 | value: 1,
|
41411 | offset: 0
|
41412 | },
|
41413 | 'in': {
|
41414 | name: 'in',
|
41415 | base: BASE_UNITS.LENGTH,
|
41416 | prefixes: PREFIXES.NONE,
|
41417 | value: 0.0254,
|
41418 | offset: 0
|
41419 | },
|
41420 | ft: {
|
41421 | name: 'ft',
|
41422 | base: BASE_UNITS.LENGTH,
|
41423 | prefixes: PREFIXES.NONE,
|
41424 | value: 0.3048,
|
41425 | offset: 0
|
41426 | },
|
41427 | yd: {
|
41428 | name: 'yd',
|
41429 | base: BASE_UNITS.LENGTH,
|
41430 | prefixes: PREFIXES.NONE,
|
41431 | value: 0.9144,
|
41432 | offset: 0
|
41433 | },
|
41434 | mi: {
|
41435 | name: 'mi',
|
41436 | base: BASE_UNITS.LENGTH,
|
41437 | prefixes: PREFIXES.NONE,
|
41438 | value: 1609.344,
|
41439 | offset: 0
|
41440 | },
|
41441 | li: {
|
41442 | name: 'li',
|
41443 | base: BASE_UNITS.LENGTH,
|
41444 | prefixes: PREFIXES.NONE,
|
41445 | value: 0.201168,
|
41446 | offset: 0
|
41447 | },
|
41448 | rd: {
|
41449 | name: 'rd',
|
41450 | base: BASE_UNITS.LENGTH,
|
41451 | prefixes: PREFIXES.NONE,
|
41452 | value: 5.029210,
|
41453 | offset: 0
|
41454 | },
|
41455 | ch: {
|
41456 | name: 'ch',
|
41457 | base: BASE_UNITS.LENGTH,
|
41458 | prefixes: PREFIXES.NONE,
|
41459 | value: 20.1168,
|
41460 | offset: 0
|
41461 | },
|
41462 | mil: {
|
41463 | name: 'mil',
|
41464 | base: BASE_UNITS.LENGTH,
|
41465 | prefixes: PREFIXES.NONE,
|
41466 | value: 0.0000254,
|
41467 | offset: 0
|
41468 | },
|
41469 | // 1/1000 inch
|
41470 | // Surface
|
41471 | m2: {
|
41472 | name: 'm2',
|
41473 | base: BASE_UNITS.SURFACE,
|
41474 | prefixes: PREFIXES.SQUARED,
|
41475 | value: 1,
|
41476 | offset: 0
|
41477 | },
|
41478 | sqin: {
|
41479 | name: 'sqin',
|
41480 | base: BASE_UNITS.SURFACE,
|
41481 | prefixes: PREFIXES.NONE,
|
41482 | value: 0.00064516,
|
41483 | offset: 0
|
41484 | },
|
41485 | // 645.16 mm2
|
41486 | sqft: {
|
41487 | name: 'sqft',
|
41488 | base: BASE_UNITS.SURFACE,
|
41489 | prefixes: PREFIXES.NONE,
|
41490 | value: 0.09290304,
|
41491 | offset: 0
|
41492 | },
|
41493 | // 0.09290304 m2
|
41494 | sqyd: {
|
41495 | name: 'sqyd',
|
41496 | base: BASE_UNITS.SURFACE,
|
41497 | prefixes: PREFIXES.NONE,
|
41498 | value: 0.83612736,
|
41499 | offset: 0
|
41500 | },
|
41501 | // 0.83612736 m2
|
41502 | sqmi: {
|
41503 | name: 'sqmi',
|
41504 | base: BASE_UNITS.SURFACE,
|
41505 | prefixes: PREFIXES.NONE,
|
41506 | value: 2589988.110336,
|
41507 | offset: 0
|
41508 | },
|
41509 | // 2.589988110336 km2
|
41510 | sqrd: {
|
41511 | name: 'sqrd',
|
41512 | base: BASE_UNITS.SURFACE,
|
41513 | prefixes: PREFIXES.NONE,
|
41514 | value: 25.29295,
|
41515 | offset: 0
|
41516 | },
|
41517 | // 25.29295 m2
|
41518 | sqch: {
|
41519 | name: 'sqch',
|
41520 | base: BASE_UNITS.SURFACE,
|
41521 | prefixes: PREFIXES.NONE,
|
41522 | value: 404.6873,
|
41523 | offset: 0
|
41524 | },
|
41525 | // 404.6873 m2
|
41526 | sqmil: {
|
41527 | name: 'sqmil',
|
41528 | base: BASE_UNITS.SURFACE,
|
41529 | prefixes: PREFIXES.NONE,
|
41530 | value: 6.4516e-10,
|
41531 | offset: 0
|
41532 | },
|
41533 | // 6.4516 * 10^-10 m2
|
41534 | acre: {
|
41535 | name: 'acre',
|
41536 | base: BASE_UNITS.SURFACE,
|
41537 | prefixes: PREFIXES.NONE,
|
41538 | value: 4046.86,
|
41539 | offset: 0
|
41540 | },
|
41541 | // 4046.86 m2
|
41542 | hectare: {
|
41543 | name: 'hectare',
|
41544 | base: BASE_UNITS.SURFACE,
|
41545 | prefixes: PREFIXES.NONE,
|
41546 | value: 10000,
|
41547 | offset: 0
|
41548 | },
|
41549 | // 10000 m2
|
41550 | // Volume
|
41551 | m3: {
|
41552 | name: 'm3',
|
41553 | base: BASE_UNITS.VOLUME,
|
41554 | prefixes: PREFIXES.CUBIC,
|
41555 | value: 1,
|
41556 | offset: 0
|
41557 | },
|
41558 | L: {
|
41559 | name: 'L',
|
41560 | base: BASE_UNITS.VOLUME,
|
41561 | prefixes: PREFIXES.SHORT,
|
41562 | value: 0.001,
|
41563 | offset: 0
|
41564 | },
|
41565 | // litre
|
41566 | l: {
|
41567 | name: 'l',
|
41568 | base: BASE_UNITS.VOLUME,
|
41569 | prefixes: PREFIXES.SHORT,
|
41570 | value: 0.001,
|
41571 | offset: 0
|
41572 | },
|
41573 | // litre
|
41574 | litre: {
|
41575 | name: 'litre',
|
41576 | base: BASE_UNITS.VOLUME,
|
41577 | prefixes: PREFIXES.LONG,
|
41578 | value: 0.001,
|
41579 | offset: 0
|
41580 | },
|
41581 | cuin: {
|
41582 | name: 'cuin',
|
41583 | base: BASE_UNITS.VOLUME,
|
41584 | prefixes: PREFIXES.NONE,
|
41585 | value: 1.6387064e-5,
|
41586 | offset: 0
|
41587 | },
|
41588 | // 1.6387064e-5 m3
|
41589 | cuft: {
|
41590 | name: 'cuft',
|
41591 | base: BASE_UNITS.VOLUME,
|
41592 | prefixes: PREFIXES.NONE,
|
41593 | value: 0.028316846592,
|
41594 | offset: 0
|
41595 | },
|
41596 | // 28.316 846 592 L
|
41597 | cuyd: {
|
41598 | name: 'cuyd',
|
41599 | base: BASE_UNITS.VOLUME,
|
41600 | prefixes: PREFIXES.NONE,
|
41601 | value: 0.764554857984,
|
41602 | offset: 0
|
41603 | },
|
41604 | // 764.554 857 984 L
|
41605 | teaspoon: {
|
41606 | name: 'teaspoon',
|
41607 | base: BASE_UNITS.VOLUME,
|
41608 | prefixes: PREFIXES.NONE,
|
41609 | value: 0.000005,
|
41610 | offset: 0
|
41611 | },
|
41612 | // 5 mL
|
41613 | tablespoon: {
|
41614 | name: 'tablespoon',
|
41615 | base: BASE_UNITS.VOLUME,
|
41616 | prefixes: PREFIXES.NONE,
|
41617 | value: 0.000015,
|
41618 | offset: 0
|
41619 | },
|
41620 | // 15 mL
|
41621 | // {name: 'cup', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.000240, offset: 0}, // 240 mL // not possible, we have already another cup
|
41622 | drop: {
|
41623 | name: 'drop',
|
41624 | base: BASE_UNITS.VOLUME,
|
41625 | prefixes: PREFIXES.NONE,
|
41626 | value: 5e-8,
|
41627 | offset: 0
|
41628 | },
|
41629 | // 0.05 mL = 5e-8 m3
|
41630 | gtt: {
|
41631 | name: 'gtt',
|
41632 | base: BASE_UNITS.VOLUME,
|
41633 | prefixes: PREFIXES.NONE,
|
41634 | value: 5e-8,
|
41635 | offset: 0
|
41636 | },
|
41637 | // 0.05 mL = 5e-8 m3
|
41638 | // Liquid volume
|
41639 | minim: {
|
41640 | name: 'minim',
|
41641 | base: BASE_UNITS.VOLUME,
|
41642 | prefixes: PREFIXES.NONE,
|
41643 | value: 0.00000006161152,
|
41644 | offset: 0
|
41645 | },
|
41646 | // 0.06161152 mL
|
41647 | fluiddram: {
|
41648 | name: 'fluiddram',
|
41649 | base: BASE_UNITS.VOLUME,
|
41650 | prefixes: PREFIXES.NONE,
|
41651 | value: 0.0000036966911,
|
41652 | offset: 0
|
41653 | },
|
41654 | // 3.696691 mL
|
41655 | fluidounce: {
|
41656 | name: 'fluidounce',
|
41657 | base: BASE_UNITS.VOLUME,
|
41658 | prefixes: PREFIXES.NONE,
|
41659 | value: 0.00002957353,
|
41660 | offset: 0
|
41661 | },
|
41662 | // 29.57353 mL
|
41663 | gill: {
|
41664 | name: 'gill',
|
41665 | base: BASE_UNITS.VOLUME,
|
41666 | prefixes: PREFIXES.NONE,
|
41667 | value: 0.0001182941,
|
41668 | offset: 0
|
41669 | },
|
41670 | // 118.2941 mL
|
41671 | cc: {
|
41672 | name: 'cc',
|
41673 | base: BASE_UNITS.VOLUME,
|
41674 | prefixes: PREFIXES.NONE,
|
41675 | value: 1e-6,
|
41676 | offset: 0
|
41677 | },
|
41678 | // 1e-6 L
|
41679 | cup: {
|
41680 | name: 'cup',
|
41681 | base: BASE_UNITS.VOLUME,
|
41682 | prefixes: PREFIXES.NONE,
|
41683 | value: 0.0002365882,
|
41684 | offset: 0
|
41685 | },
|
41686 | // 236.5882 mL
|
41687 | pint: {
|
41688 | name: 'pint',
|
41689 | base: BASE_UNITS.VOLUME,
|
41690 | prefixes: PREFIXES.NONE,
|
41691 | value: 0.0004731765,
|
41692 | offset: 0
|
41693 | },
|
41694 | // 473.1765 mL
|
41695 | quart: {
|
41696 | name: 'quart',
|
41697 | base: BASE_UNITS.VOLUME,
|
41698 | prefixes: PREFIXES.NONE,
|
41699 | value: 0.0009463529,
|
41700 | offset: 0
|
41701 | },
|
41702 | // 946.3529 mL
|
41703 | gallon: {
|
41704 | name: 'gallon',
|
41705 | base: BASE_UNITS.VOLUME,
|
41706 | prefixes: PREFIXES.NONE,
|
41707 | value: 0.003785412,
|
41708 | offset: 0
|
41709 | },
|
41710 | // 3.785412 L
|
41711 | beerbarrel: {
|
41712 | name: 'beerbarrel',
|
41713 | base: BASE_UNITS.VOLUME,
|
41714 | prefixes: PREFIXES.NONE,
|
41715 | value: 0.1173478,
|
41716 | offset: 0
|
41717 | },
|
41718 | // 117.3478 L
|
41719 | oilbarrel: {
|
41720 | name: 'oilbarrel',
|
41721 | base: BASE_UNITS.VOLUME,
|
41722 | prefixes: PREFIXES.NONE,
|
41723 | value: 0.1589873,
|
41724 | offset: 0
|
41725 | },
|
41726 | // 158.9873 L
|
41727 | hogshead: {
|
41728 | name: 'hogshead',
|
41729 | base: BASE_UNITS.VOLUME,
|
41730 | prefixes: PREFIXES.NONE,
|
41731 | value: 0.2384810,
|
41732 | offset: 0
|
41733 | },
|
41734 | // 238.4810 L
|
41735 | // {name: 'min', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.00000006161152, offset: 0}, // 0.06161152 mL // min is already in use as minute
|
41736 | fldr: {
|
41737 | name: 'fldr',
|
41738 | base: BASE_UNITS.VOLUME,
|
41739 | prefixes: PREFIXES.NONE,
|
41740 | value: 0.0000036966911,
|
41741 | offset: 0
|
41742 | },
|
41743 | // 3.696691 mL
|
41744 | floz: {
|
41745 | name: 'floz',
|
41746 | base: BASE_UNITS.VOLUME,
|
41747 | prefixes: PREFIXES.NONE,
|
41748 | value: 0.00002957353,
|
41749 | offset: 0
|
41750 | },
|
41751 | // 29.57353 mL
|
41752 | gi: {
|
41753 | name: 'gi',
|
41754 | base: BASE_UNITS.VOLUME,
|
41755 | prefixes: PREFIXES.NONE,
|
41756 | value: 0.0001182941,
|
41757 | offset: 0
|
41758 | },
|
41759 | // 118.2941 mL
|
41760 | cp: {
|
41761 | name: 'cp',
|
41762 | base: BASE_UNITS.VOLUME,
|
41763 | prefixes: PREFIXES.NONE,
|
41764 | value: 0.0002365882,
|
41765 | offset: 0
|
41766 | },
|
41767 | // 236.5882 mL
|
41768 | pt: {
|
41769 | name: 'pt',
|
41770 | base: BASE_UNITS.VOLUME,
|
41771 | prefixes: PREFIXES.NONE,
|
41772 | value: 0.0004731765,
|
41773 | offset: 0
|
41774 | },
|
41775 | // 473.1765 mL
|
41776 | qt: {
|
41777 | name: 'qt',
|
41778 | base: BASE_UNITS.VOLUME,
|
41779 | prefixes: PREFIXES.NONE,
|
41780 | value: 0.0009463529,
|
41781 | offset: 0
|
41782 | },
|
41783 | // 946.3529 mL
|
41784 | gal: {
|
41785 | name: 'gal',
|
41786 | base: BASE_UNITS.VOLUME,
|
41787 | prefixes: PREFIXES.NONE,
|
41788 | value: 0.003785412,
|
41789 | offset: 0
|
41790 | },
|
41791 | // 3.785412 L
|
41792 | bbl: {
|
41793 | name: 'bbl',
|
41794 | base: BASE_UNITS.VOLUME,
|
41795 | prefixes: PREFIXES.NONE,
|
41796 | value: 0.1173478,
|
41797 | offset: 0
|
41798 | },
|
41799 | // 117.3478 L
|
41800 | obl: {
|
41801 | name: 'obl',
|
41802 | base: BASE_UNITS.VOLUME,
|
41803 | prefixes: PREFIXES.NONE,
|
41804 | value: 0.1589873,
|
41805 | offset: 0
|
41806 | },
|
41807 | // 158.9873 L
|
41808 | // {name: 'hogshead', base: BASE_UNITS.VOLUME, prefixes: PREFIXES.NONE, value: 0.2384810, offset: 0}, // 238.4810 L // TODO: hh?
|
41809 | // Mass
|
41810 | g: {
|
41811 | name: 'g',
|
41812 | base: BASE_UNITS.MASS,
|
41813 | prefixes: PREFIXES.SHORT,
|
41814 | value: 0.001,
|
41815 | offset: 0
|
41816 | },
|
41817 | gram: {
|
41818 | name: 'gram',
|
41819 | base: BASE_UNITS.MASS,
|
41820 | prefixes: PREFIXES.LONG,
|
41821 | value: 0.001,
|
41822 | offset: 0
|
41823 | },
|
41824 | ton: {
|
41825 | name: 'ton',
|
41826 | base: BASE_UNITS.MASS,
|
41827 | prefixes: PREFIXES.SHORT,
|
41828 | value: 907.18474,
|
41829 | offset: 0
|
41830 | },
|
41831 | tonne: {
|
41832 | name: 'tonne',
|
41833 | base: BASE_UNITS.MASS,
|
41834 | prefixes: PREFIXES.SHORT,
|
41835 | value: 1000,
|
41836 | offset: 0
|
41837 | },
|
41838 | grain: {
|
41839 | name: 'grain',
|
41840 | base: BASE_UNITS.MASS,
|
41841 | prefixes: PREFIXES.NONE,
|
41842 | value: 64.79891e-6,
|
41843 | offset: 0
|
41844 | },
|
41845 | dram: {
|
41846 | name: 'dram',
|
41847 | base: BASE_UNITS.MASS,
|
41848 | prefixes: PREFIXES.NONE,
|
41849 | value: 1.7718451953125e-3,
|
41850 | offset: 0
|
41851 | },
|
41852 | ounce: {
|
41853 | name: 'ounce',
|
41854 | base: BASE_UNITS.MASS,
|
41855 | prefixes: PREFIXES.NONE,
|
41856 | value: 28.349523125e-3,
|
41857 | offset: 0
|
41858 | },
|
41859 | poundmass: {
|
41860 | name: 'poundmass',
|
41861 | base: BASE_UNITS.MASS,
|
41862 | prefixes: PREFIXES.NONE,
|
41863 | value: 453.59237e-3,
|
41864 | offset: 0
|
41865 | },
|
41866 | hundredweight: {
|
41867 | name: 'hundredweight',
|
41868 | base: BASE_UNITS.MASS,
|
41869 | prefixes: PREFIXES.NONE,
|
41870 | value: 45.359237,
|
41871 | offset: 0
|
41872 | },
|
41873 | stick: {
|
41874 | name: 'stick',
|
41875 | base: BASE_UNITS.MASS,
|
41876 | prefixes: PREFIXES.NONE,
|
41877 | value: 115e-3,
|
41878 | offset: 0
|
41879 | },
|
41880 | stone: {
|
41881 | name: 'stone',
|
41882 | base: BASE_UNITS.MASS,
|
41883 | prefixes: PREFIXES.NONE,
|
41884 | value: 6.35029318,
|
41885 | offset: 0
|
41886 | },
|
41887 | gr: {
|
41888 | name: 'gr',
|
41889 | base: BASE_UNITS.MASS,
|
41890 | prefixes: PREFIXES.NONE,
|
41891 | value: 64.79891e-6,
|
41892 | offset: 0
|
41893 | },
|
41894 | dr: {
|
41895 | name: 'dr',
|
41896 | base: BASE_UNITS.MASS,
|
41897 | prefixes: PREFIXES.NONE,
|
41898 | value: 1.7718451953125e-3,
|
41899 | offset: 0
|
41900 | },
|
41901 | oz: {
|
41902 | name: 'oz',
|
41903 | base: BASE_UNITS.MASS,
|
41904 | prefixes: PREFIXES.NONE,
|
41905 | value: 28.349523125e-3,
|
41906 | offset: 0
|
41907 | },
|
41908 | lbm: {
|
41909 | name: 'lbm',
|
41910 | base: BASE_UNITS.MASS,
|
41911 | prefixes: PREFIXES.NONE,
|
41912 | value: 453.59237e-3,
|
41913 | offset: 0
|
41914 | },
|
41915 | cwt: {
|
41916 | name: 'cwt',
|
41917 | base: BASE_UNITS.MASS,
|
41918 | prefixes: PREFIXES.NONE,
|
41919 | value: 45.359237,
|
41920 | offset: 0
|
41921 | },
|
41922 | // Time
|
41923 | s: {
|
41924 | name: 's',
|
41925 | base: BASE_UNITS.TIME,
|
41926 | prefixes: PREFIXES.SHORT,
|
41927 | value: 1,
|
41928 | offset: 0
|
41929 | },
|
41930 | min: {
|
41931 | name: 'min',
|
41932 | base: BASE_UNITS.TIME,
|
41933 | prefixes: PREFIXES.NONE,
|
41934 | value: 60,
|
41935 | offset: 0
|
41936 | },
|
41937 | h: {
|
41938 | name: 'h',
|
41939 | base: BASE_UNITS.TIME,
|
41940 | prefixes: PREFIXES.NONE,
|
41941 | value: 3600,
|
41942 | offset: 0
|
41943 | },
|
41944 | second: {
|
41945 | name: 'second',
|
41946 | base: BASE_UNITS.TIME,
|
41947 | prefixes: PREFIXES.LONG,
|
41948 | value: 1,
|
41949 | offset: 0
|
41950 | },
|
41951 | sec: {
|
41952 | name: 'sec',
|
41953 | base: BASE_UNITS.TIME,
|
41954 | prefixes: PREFIXES.LONG,
|
41955 | value: 1,
|
41956 | offset: 0
|
41957 | },
|
41958 | minute: {
|
41959 | name: 'minute',
|
41960 | base: BASE_UNITS.TIME,
|
41961 | prefixes: PREFIXES.NONE,
|
41962 | value: 60,
|
41963 | offset: 0
|
41964 | },
|
41965 | hour: {
|
41966 | name: 'hour',
|
41967 | base: BASE_UNITS.TIME,
|
41968 | prefixes: PREFIXES.NONE,
|
41969 | value: 3600,
|
41970 | offset: 0
|
41971 | },
|
41972 | day: {
|
41973 | name: 'day',
|
41974 | base: BASE_UNITS.TIME,
|
41975 | prefixes: PREFIXES.NONE,
|
41976 | value: 86400,
|
41977 | offset: 0
|
41978 | },
|
41979 | week: {
|
41980 | name: 'week',
|
41981 | base: BASE_UNITS.TIME,
|
41982 | prefixes: PREFIXES.NONE,
|
41983 | value: 7 * 86400,
|
41984 | offset: 0
|
41985 | },
|
41986 | month: {
|
41987 | name: 'month',
|
41988 | base: BASE_UNITS.TIME,
|
41989 | prefixes: PREFIXES.NONE,
|
41990 | value: 2629800,
|
41991 | // 1/12th of Julian year
|
41992 | offset: 0
|
41993 | },
|
41994 | year: {
|
41995 | name: 'year',
|
41996 | base: BASE_UNITS.TIME,
|
41997 | prefixes: PREFIXES.NONE,
|
41998 | value: 31557600,
|
41999 | // Julian year
|
42000 | offset: 0
|
42001 | },
|
42002 | decade: {
|
42003 | name: 'decade',
|
42004 | base: BASE_UNITS.TIME,
|
42005 | prefixes: PREFIXES.NONE,
|
42006 | value: 315576000,
|
42007 | // Julian decade
|
42008 | offset: 0
|
42009 | },
|
42010 | century: {
|
42011 | name: 'century',
|
42012 | base: BASE_UNITS.TIME,
|
42013 | prefixes: PREFIXES.NONE,
|
42014 | value: 3155760000,
|
42015 | // Julian century
|
42016 | offset: 0
|
42017 | },
|
42018 | millennium: {
|
42019 | name: 'millennium',
|
42020 | base: BASE_UNITS.TIME,
|
42021 | prefixes: PREFIXES.NONE,
|
42022 | value: 31557600000,
|
42023 | // Julian millennium
|
42024 | offset: 0
|
42025 | },
|
42026 | // Frequency
|
42027 | hertz: {
|
42028 | name: 'Hertz',
|
42029 | base: BASE_UNITS.FREQUENCY,
|
42030 | prefixes: PREFIXES.LONG,
|
42031 | value: 1,
|
42032 | offset: 0,
|
42033 | reciprocal: true
|
42034 | },
|
42035 | Hz: {
|
42036 | name: 'Hz',
|
42037 | base: BASE_UNITS.FREQUENCY,
|
42038 | prefixes: PREFIXES.SHORT,
|
42039 | value: 1,
|
42040 | offset: 0,
|
42041 | reciprocal: true
|
42042 | },
|
42043 | // Angle
|
42044 | rad: {
|
42045 | name: 'rad',
|
42046 | base: BASE_UNITS.ANGLE,
|
42047 | prefixes: PREFIXES.SHORT,
|
42048 | value: 1,
|
42049 | offset: 0
|
42050 | },
|
42051 | radian: {
|
42052 | name: 'radian',
|
42053 | base: BASE_UNITS.ANGLE,
|
42054 | prefixes: PREFIXES.LONG,
|
42055 | value: 1,
|
42056 | offset: 0
|
42057 | },
|
42058 | // deg = rad / (2*pi) * 360 = rad / 0.017453292519943295769236907684888
|
42059 | deg: {
|
42060 | name: 'deg',
|
42061 | base: BASE_UNITS.ANGLE,
|
42062 | prefixes: PREFIXES.SHORT,
|
42063 | value: null,
|
42064 | // will be filled in by calculateAngleValues()
|
42065 | offset: 0
|
42066 | },
|
42067 | degree: {
|
42068 | name: 'degree',
|
42069 | base: BASE_UNITS.ANGLE,
|
42070 | prefixes: PREFIXES.LONG,
|
42071 | value: null,
|
42072 | // will be filled in by calculateAngleValues()
|
42073 | offset: 0
|
42074 | },
|
42075 | // grad = rad / (2*pi) * 400 = rad / 0.015707963267948966192313216916399
|
42076 | grad: {
|
42077 | name: 'grad',
|
42078 | base: BASE_UNITS.ANGLE,
|
42079 | prefixes: PREFIXES.SHORT,
|
42080 | value: null,
|
42081 | // will be filled in by calculateAngleValues()
|
42082 | offset: 0
|
42083 | },
|
42084 | gradian: {
|
42085 | name: 'gradian',
|
42086 | base: BASE_UNITS.ANGLE,
|
42087 | prefixes: PREFIXES.LONG,
|
42088 | value: null,
|
42089 | // will be filled in by calculateAngleValues()
|
42090 | offset: 0
|
42091 | },
|
42092 | // cycle = rad / (2*pi) = rad / 6.2831853071795864769252867665793
|
42093 | cycle: {
|
42094 | name: 'cycle',
|
42095 | base: BASE_UNITS.ANGLE,
|
42096 | prefixes: PREFIXES.NONE,
|
42097 | value: null,
|
42098 | // will be filled in by calculateAngleValues()
|
42099 | offset: 0
|
42100 | },
|
42101 | // arcsec = rad / (3600 * (360 / 2 * pi)) = rad / 0.0000048481368110953599358991410235795
|
42102 | arcsec: {
|
42103 | name: 'arcsec',
|
42104 | base: BASE_UNITS.ANGLE,
|
42105 | prefixes: PREFIXES.NONE,
|
42106 | value: null,
|
42107 | // will be filled in by calculateAngleValues()
|
42108 | offset: 0
|
42109 | },
|
42110 | // arcmin = rad / (60 * (360 / 2 * pi)) = rad / 0.00029088820866572159615394846141477
|
42111 | arcmin: {
|
42112 | name: 'arcmin',
|
42113 | base: BASE_UNITS.ANGLE,
|
42114 | prefixes: PREFIXES.NONE,
|
42115 | value: null,
|
42116 | // will be filled in by calculateAngleValues()
|
42117 | offset: 0
|
42118 | },
|
42119 | // Electric current
|
42120 | A: {
|
42121 | name: 'A',
|
42122 | base: BASE_UNITS.CURRENT,
|
42123 | prefixes: PREFIXES.SHORT,
|
42124 | value: 1,
|
42125 | offset: 0
|
42126 | },
|
42127 | ampere: {
|
42128 | name: 'ampere',
|
42129 | base: BASE_UNITS.CURRENT,
|
42130 | prefixes: PREFIXES.LONG,
|
42131 | value: 1,
|
42132 | offset: 0
|
42133 | },
|
42134 | // Temperature
|
42135 | // K(C) = °C + 273.15
|
42136 | // K(F) = (°F + 459.67) / 1.8
|
42137 | // K(R) = °R / 1.8
|
42138 | K: {
|
42139 | name: 'K',
|
42140 | base: BASE_UNITS.TEMPERATURE,
|
42141 | prefixes: PREFIXES.NONE,
|
42142 | value: 1,
|
42143 | offset: 0
|
42144 | },
|
42145 | degC: {
|
42146 | name: 'degC',
|
42147 | base: BASE_UNITS.TEMPERATURE,
|
42148 | prefixes: PREFIXES.NONE,
|
42149 | value: 1,
|
42150 | offset: 273.15
|
42151 | },
|
42152 | degF: {
|
42153 | name: 'degF',
|
42154 | base: BASE_UNITS.TEMPERATURE,
|
42155 | prefixes: PREFIXES.NONE,
|
42156 | value: 1 / 1.8,
|
42157 | offset: 459.67
|
42158 | },
|
42159 | degR: {
|
42160 | name: 'degR',
|
42161 | base: BASE_UNITS.TEMPERATURE,
|
42162 | prefixes: PREFIXES.NONE,
|
42163 | value: 1 / 1.8,
|
42164 | offset: 0
|
42165 | },
|
42166 | kelvin: {
|
42167 | name: 'kelvin',
|
42168 | base: BASE_UNITS.TEMPERATURE,
|
42169 | prefixes: PREFIXES.NONE,
|
42170 | value: 1,
|
42171 | offset: 0
|
42172 | },
|
42173 | celsius: {
|
42174 | name: 'celsius',
|
42175 | base: BASE_UNITS.TEMPERATURE,
|
42176 | prefixes: PREFIXES.NONE,
|
42177 | value: 1,
|
42178 | offset: 273.15
|
42179 | },
|
42180 | fahrenheit: {
|
42181 | name: 'fahrenheit',
|
42182 | base: BASE_UNITS.TEMPERATURE,
|
42183 | prefixes: PREFIXES.NONE,
|
42184 | value: 1 / 1.8,
|
42185 | offset: 459.67
|
42186 | },
|
42187 | rankine: {
|
42188 | name: 'rankine',
|
42189 | base: BASE_UNITS.TEMPERATURE,
|
42190 | prefixes: PREFIXES.NONE,
|
42191 | value: 1 / 1.8,
|
42192 | offset: 0
|
42193 | },
|
42194 | // amount of substance
|
42195 | mol: {
|
42196 | name: 'mol',
|
42197 | base: BASE_UNITS.AMOUNT_OF_SUBSTANCE,
|
42198 | prefixes: PREFIXES.SHORT,
|
42199 | value: 1,
|
42200 | offset: 0
|
42201 | },
|
42202 | mole: {
|
42203 | name: 'mole',
|
42204 | base: BASE_UNITS.AMOUNT_OF_SUBSTANCE,
|
42205 | prefixes: PREFIXES.LONG,
|
42206 | value: 1,
|
42207 | offset: 0
|
42208 | },
|
42209 | // luminous intensity
|
42210 | cd: {
|
42211 | name: 'cd',
|
42212 | base: BASE_UNITS.LUMINOUS_INTENSITY,
|
42213 | prefixes: PREFIXES.NONE,
|
42214 | value: 1,
|
42215 | offset: 0
|
42216 | },
|
42217 | candela: {
|
42218 | name: 'candela',
|
42219 | base: BASE_UNITS.LUMINOUS_INTENSITY,
|
42220 | prefixes: PREFIXES.NONE,
|
42221 | value: 1,
|
42222 | offset: 0
|
42223 | },
|
42224 | // TODO: units STERADIAN
|
42225 | // {name: 'sr', base: BASE_UNITS.STERADIAN, prefixes: PREFIXES.NONE, value: 1, offset: 0},
|
42226 | // {name: 'steradian', base: BASE_UNITS.STERADIAN, prefixes: PREFIXES.NONE, value: 1, offset: 0},
|
42227 | // Force
|
42228 | N: {
|
42229 | name: 'N',
|
42230 | base: BASE_UNITS.FORCE,
|
42231 | prefixes: PREFIXES.SHORT,
|
42232 | value: 1,
|
42233 | offset: 0
|
42234 | },
|
42235 | newton: {
|
42236 | name: 'newton',
|
42237 | base: BASE_UNITS.FORCE,
|
42238 | prefixes: PREFIXES.LONG,
|
42239 | value: 1,
|
42240 | offset: 0
|
42241 | },
|
42242 | dyn: {
|
42243 | name: 'dyn',
|
42244 | base: BASE_UNITS.FORCE,
|
42245 | prefixes: PREFIXES.SHORT,
|
42246 | value: 0.00001,
|
42247 | offset: 0
|
42248 | },
|
42249 | dyne: {
|
42250 | name: 'dyne',
|
42251 | base: BASE_UNITS.FORCE,
|
42252 | prefixes: PREFIXES.LONG,
|
42253 | value: 0.00001,
|
42254 | offset: 0
|
42255 | },
|
42256 | lbf: {
|
42257 | name: 'lbf',
|
42258 | base: BASE_UNITS.FORCE,
|
42259 | prefixes: PREFIXES.NONE,
|
42260 | value: 4.4482216152605,
|
42261 | offset: 0
|
42262 | },
|
42263 | poundforce: {
|
42264 | name: 'poundforce',
|
42265 | base: BASE_UNITS.FORCE,
|
42266 | prefixes: PREFIXES.NONE,
|
42267 | value: 4.4482216152605,
|
42268 | offset: 0
|
42269 | },
|
42270 | kip: {
|
42271 | name: 'kip',
|
42272 | base: BASE_UNITS.FORCE,
|
42273 | prefixes: PREFIXES.LONG,
|
42274 | value: 4448.2216,
|
42275 | offset: 0
|
42276 | },
|
42277 | // Energy
|
42278 | J: {
|
42279 | name: 'J',
|
42280 | base: BASE_UNITS.ENERGY,
|
42281 | prefixes: PREFIXES.SHORT,
|
42282 | value: 1,
|
42283 | offset: 0
|
42284 | },
|
42285 | joule: {
|
42286 | name: 'joule',
|
42287 | base: BASE_UNITS.ENERGY,
|
42288 | prefixes: PREFIXES.SHORT,
|
42289 | value: 1,
|
42290 | offset: 0
|
42291 | },
|
42292 | erg: {
|
42293 | name: 'erg',
|
42294 | base: BASE_UNITS.ENERGY,
|
42295 | prefixes: PREFIXES.NONE,
|
42296 | value: 1e-7,
|
42297 | offset: 0
|
42298 | },
|
42299 | Wh: {
|
42300 | name: 'Wh',
|
42301 | base: BASE_UNITS.ENERGY,
|
42302 | prefixes: PREFIXES.SHORT,
|
42303 | value: 3600,
|
42304 | offset: 0
|
42305 | },
|
42306 | BTU: {
|
42307 | name: 'BTU',
|
42308 | base: BASE_UNITS.ENERGY,
|
42309 | prefixes: PREFIXES.BTU,
|
42310 | value: 1055.05585262,
|
42311 | offset: 0
|
42312 | },
|
42313 | eV: {
|
42314 | name: 'eV',
|
42315 | base: BASE_UNITS.ENERGY,
|
42316 | prefixes: PREFIXES.SHORT,
|
42317 | value: 1.602176565e-19,
|
42318 | offset: 0
|
42319 | },
|
42320 | electronvolt: {
|
42321 | name: 'electronvolt',
|
42322 | base: BASE_UNITS.ENERGY,
|
42323 | prefixes: PREFIXES.LONG,
|
42324 | value: 1.602176565e-19,
|
42325 | offset: 0
|
42326 | },
|
42327 | // Power
|
42328 | W: {
|
42329 | name: 'W',
|
42330 | base: BASE_UNITS.POWER,
|
42331 | prefixes: PREFIXES.SHORT,
|
42332 | value: 1,
|
42333 | offset: 0
|
42334 | },
|
42335 | watt: {
|
42336 | name: 'watt',
|
42337 | base: BASE_UNITS.POWER,
|
42338 | prefixes: PREFIXES.LONG,
|
42339 | value: 1,
|
42340 | offset: 0
|
42341 | },
|
42342 | hp: {
|
42343 | name: 'hp',
|
42344 | base: BASE_UNITS.POWER,
|
42345 | prefixes: PREFIXES.NONE,
|
42346 | value: 745.6998715386,
|
42347 | offset: 0
|
42348 | },
|
42349 | // Electrical power units
|
42350 | VAR: {
|
42351 | name: 'VAR',
|
42352 | base: BASE_UNITS.POWER,
|
42353 | prefixes: PREFIXES.SHORT,
|
42354 | value: Complex.I,
|
42355 | offset: 0
|
42356 | },
|
42357 | VA: {
|
42358 | name: 'VA',
|
42359 | base: BASE_UNITS.POWER,
|
42360 | prefixes: PREFIXES.SHORT,
|
42361 | value: 1,
|
42362 | offset: 0
|
42363 | },
|
42364 | // Pressure
|
42365 | Pa: {
|
42366 | name: 'Pa',
|
42367 | base: BASE_UNITS.PRESSURE,
|
42368 | prefixes: PREFIXES.SHORT,
|
42369 | value: 1,
|
42370 | offset: 0
|
42371 | },
|
42372 | psi: {
|
42373 | name: 'psi',
|
42374 | base: BASE_UNITS.PRESSURE,
|
42375 | prefixes: PREFIXES.NONE,
|
42376 | value: 6894.75729276459,
|
42377 | offset: 0
|
42378 | },
|
42379 | atm: {
|
42380 | name: 'atm',
|
42381 | base: BASE_UNITS.PRESSURE,
|
42382 | prefixes: PREFIXES.NONE,
|
42383 | value: 101325,
|
42384 | offset: 0
|
42385 | },
|
42386 | bar: {
|
42387 | name: 'bar',
|
42388 | base: BASE_UNITS.PRESSURE,
|
42389 | prefixes: PREFIXES.SHORTLONG,
|
42390 | value: 100000,
|
42391 | offset: 0
|
42392 | },
|
42393 | torr: {
|
42394 | name: 'torr',
|
42395 | base: BASE_UNITS.PRESSURE,
|
42396 | prefixes: PREFIXES.NONE,
|
42397 | value: 133.322,
|
42398 | offset: 0
|
42399 | },
|
42400 | mmHg: {
|
42401 | name: 'mmHg',
|
42402 | base: BASE_UNITS.PRESSURE,
|
42403 | prefixes: PREFIXES.NONE,
|
42404 | value: 133.322,
|
42405 | offset: 0
|
42406 | },
|
42407 | mmH2O: {
|
42408 | name: 'mmH2O',
|
42409 | base: BASE_UNITS.PRESSURE,
|
42410 | prefixes: PREFIXES.NONE,
|
42411 | value: 9.80665,
|
42412 | offset: 0
|
42413 | },
|
42414 | cmH2O: {
|
42415 | name: 'cmH2O',
|
42416 | base: BASE_UNITS.PRESSURE,
|
42417 | prefixes: PREFIXES.NONE,
|
42418 | value: 98.0665,
|
42419 | offset: 0
|
42420 | },
|
42421 | // Electric charge
|
42422 | coulomb: {
|
42423 | name: 'coulomb',
|
42424 | base: BASE_UNITS.ELECTRIC_CHARGE,
|
42425 | prefixes: PREFIXES.LONG,
|
42426 | value: 1,
|
42427 | offset: 0
|
42428 | },
|
42429 | C: {
|
42430 | name: 'C',
|
42431 | base: BASE_UNITS.ELECTRIC_CHARGE,
|
42432 | prefixes: PREFIXES.SHORT,
|
42433 | value: 1,
|
42434 | offset: 0
|
42435 | },
|
42436 | // Electric capacitance
|
42437 | farad: {
|
42438 | name: 'farad',
|
42439 | base: BASE_UNITS.ELECTRIC_CAPACITANCE,
|
42440 | prefixes: PREFIXES.LONG,
|
42441 | value: 1,
|
42442 | offset: 0
|
42443 | },
|
42444 | F: {
|
42445 | name: 'F',
|
42446 | base: BASE_UNITS.ELECTRIC_CAPACITANCE,
|
42447 | prefixes: PREFIXES.SHORT,
|
42448 | value: 1,
|
42449 | offset: 0
|
42450 | },
|
42451 | // Electric potential
|
42452 | volt: {
|
42453 | name: 'volt',
|
42454 | base: BASE_UNITS.ELECTRIC_POTENTIAL,
|
42455 | prefixes: PREFIXES.LONG,
|
42456 | value: 1,
|
42457 | offset: 0
|
42458 | },
|
42459 | V: {
|
42460 | name: 'V',
|
42461 | base: BASE_UNITS.ELECTRIC_POTENTIAL,
|
42462 | prefixes: PREFIXES.SHORT,
|
42463 | value: 1,
|
42464 | offset: 0
|
42465 | },
|
42466 | // Electric resistance
|
42467 | ohm: {
|
42468 | name: 'ohm',
|
42469 | base: BASE_UNITS.ELECTRIC_RESISTANCE,
|
42470 | prefixes: PREFIXES.SHORTLONG,
|
42471 | // Both Mohm and megaohm are acceptable
|
42472 | value: 1,
|
42473 | offset: 0
|
42474 | },
|
42475 |
|
42476 | /*
|
42477 | * Unicode breaks in browsers if charset is not specified
|
42478 | Ω: {
|
42479 | name: 'Ω',
|
42480 | base: BASE_UNITS.ELECTRIC_RESISTANCE,
|
42481 | prefixes: PREFIXES.SHORT,
|
42482 | value: 1,
|
42483 | offset: 0
|
42484 | },
|
42485 | */
|
42486 | // Electric inductance
|
42487 | henry: {
|
42488 | name: 'henry',
|
42489 | base: BASE_UNITS.ELECTRIC_INDUCTANCE,
|
42490 | prefixes: PREFIXES.LONG,
|
42491 | value: 1,
|
42492 | offset: 0
|
42493 | },
|
42494 | H: {
|
42495 | name: 'H',
|
42496 | base: BASE_UNITS.ELECTRIC_INDUCTANCE,
|
42497 | prefixes: PREFIXES.SHORT,
|
42498 | value: 1,
|
42499 | offset: 0
|
42500 | },
|
42501 | // Electric conductance
|
42502 | siemens: {
|
42503 | name: 'siemens',
|
42504 | base: BASE_UNITS.ELECTRIC_CONDUCTANCE,
|
42505 | prefixes: PREFIXES.LONG,
|
42506 | value: 1,
|
42507 | offset: 0
|
42508 | },
|
42509 | S: {
|
42510 | name: 'S',
|
42511 | base: BASE_UNITS.ELECTRIC_CONDUCTANCE,
|
42512 | prefixes: PREFIXES.SHORT,
|
42513 | value: 1,
|
42514 | offset: 0
|
42515 | },
|
42516 | // Magnetic flux
|
42517 | weber: {
|
42518 | name: 'weber',
|
42519 | base: BASE_UNITS.MAGNETIC_FLUX,
|
42520 | prefixes: PREFIXES.LONG,
|
42521 | value: 1,
|
42522 | offset: 0
|
42523 | },
|
42524 | Wb: {
|
42525 | name: 'Wb',
|
42526 | base: BASE_UNITS.MAGNETIC_FLUX,
|
42527 | prefixes: PREFIXES.SHORT,
|
42528 | value: 1,
|
42529 | offset: 0
|
42530 | },
|
42531 | // Magnetic flux density
|
42532 | tesla: {
|
42533 | name: 'tesla',
|
42534 | base: BASE_UNITS.MAGNETIC_FLUX_DENSITY,
|
42535 | prefixes: PREFIXES.LONG,
|
42536 | value: 1,
|
42537 | offset: 0
|
42538 | },
|
42539 | T: {
|
42540 | name: 'T',
|
42541 | base: BASE_UNITS.MAGNETIC_FLUX_DENSITY,
|
42542 | prefixes: PREFIXES.SHORT,
|
42543 | value: 1,
|
42544 | offset: 0
|
42545 | },
|
42546 | // Binary
|
42547 | b: {
|
42548 | name: 'b',
|
42549 | base: BASE_UNITS.BIT,
|
42550 | prefixes: PREFIXES.BINARY_SHORT,
|
42551 | value: 1,
|
42552 | offset: 0
|
42553 | },
|
42554 | bits: {
|
42555 | name: 'bits',
|
42556 | base: BASE_UNITS.BIT,
|
42557 | prefixes: PREFIXES.BINARY_LONG,
|
42558 | value: 1,
|
42559 | offset: 0
|
42560 | },
|
42561 | B: {
|
42562 | name: 'B',
|
42563 | base: BASE_UNITS.BIT,
|
42564 | prefixes: PREFIXES.BINARY_SHORT,
|
42565 | value: 8,
|
42566 | offset: 0
|
42567 | },
|
42568 | bytes: {
|
42569 | name: 'bytes',
|
42570 | base: BASE_UNITS.BIT,
|
42571 | prefixes: PREFIXES.BINARY_LONG,
|
42572 | value: 8,
|
42573 | offset: 0
|
42574 | } // aliases (formerly plurals)
|
42575 |
|
42576 | };
|
42577 | var ALIASES = {
|
42578 | meters: 'meter',
|
42579 | inches: 'inch',
|
42580 | feet: 'foot',
|
42581 | yards: 'yard',
|
42582 | miles: 'mile',
|
42583 | links: 'link',
|
42584 | rods: 'rod',
|
42585 | chains: 'chain',
|
42586 | angstroms: 'angstrom',
|
42587 | lt: 'l',
|
42588 | litres: 'litre',
|
42589 | liter: 'litre',
|
42590 | liters: 'litre',
|
42591 | teaspoons: 'teaspoon',
|
42592 | tablespoons: 'tablespoon',
|
42593 | minims: 'minim',
|
42594 | fluiddrams: 'fluiddram',
|
42595 | fluidounces: 'fluidounce',
|
42596 | gills: 'gill',
|
42597 | cups: 'cup',
|
42598 | pints: 'pint',
|
42599 | quarts: 'quart',
|
42600 | gallons: 'gallon',
|
42601 | beerbarrels: 'beerbarrel',
|
42602 | oilbarrels: 'oilbarrel',
|
42603 | hogsheads: 'hogshead',
|
42604 | gtts: 'gtt',
|
42605 | grams: 'gram',
|
42606 | tons: 'ton',
|
42607 | tonnes: 'tonne',
|
42608 | grains: 'grain',
|
42609 | drams: 'dram',
|
42610 | ounces: 'ounce',
|
42611 | poundmasses: 'poundmass',
|
42612 | hundredweights: 'hundredweight',
|
42613 | sticks: 'stick',
|
42614 | lb: 'lbm',
|
42615 | lbs: 'lbm',
|
42616 | kips: 'kip',
|
42617 | acres: 'acre',
|
42618 | hectares: 'hectare',
|
42619 | sqfeet: 'sqft',
|
42620 | sqyard: 'sqyd',
|
42621 | sqmile: 'sqmi',
|
42622 | sqmiles: 'sqmi',
|
42623 | mmhg: 'mmHg',
|
42624 | mmh2o: 'mmH2O',
|
42625 | cmh2o: 'cmH2O',
|
42626 | seconds: 'second',
|
42627 | secs: 'second',
|
42628 | minutes: 'minute',
|
42629 | mins: 'minute',
|
42630 | hours: 'hour',
|
42631 | hr: 'hour',
|
42632 | hrs: 'hour',
|
42633 | days: 'day',
|
42634 | weeks: 'week',
|
42635 | months: 'month',
|
42636 | years: 'year',
|
42637 | decades: 'decade',
|
42638 | centuries: 'century',
|
42639 | millennia: 'millennium',
|
42640 | hertz: 'hertz',
|
42641 | radians: 'radian',
|
42642 | degrees: 'degree',
|
42643 | gradians: 'gradian',
|
42644 | cycles: 'cycle',
|
42645 | arcsecond: 'arcsec',
|
42646 | arcseconds: 'arcsec',
|
42647 | arcminute: 'arcmin',
|
42648 | arcminutes: 'arcmin',
|
42649 | BTUs: 'BTU',
|
42650 | watts: 'watt',
|
42651 | joules: 'joule',
|
42652 | amperes: 'ampere',
|
42653 | coulombs: 'coulomb',
|
42654 | volts: 'volt',
|
42655 | ohms: 'ohm',
|
42656 | farads: 'farad',
|
42657 | webers: 'weber',
|
42658 | teslas: 'tesla',
|
42659 | electronvolts: 'electronvolt',
|
42660 | moles: 'mole'
|
42661 | /**
|
42662 | * Calculate the values for the angle units.
|
42663 | * Value is calculated as number or BigNumber depending on the configuration
|
42664 | * @param {{number: 'number' | 'BigNumber'}} config
|
42665 | */
|
42666 |
|
42667 | };
|
42668 |
|
42669 | function calculateAngleValues(config) {
|
42670 | if (config.number === 'BigNumber') {
|
42671 | var pi = constants.pi(type.BigNumber);
|
42672 | UNITS.rad.value = new type.BigNumber(1);
|
42673 | UNITS.deg.value = pi.div(180); // 2 * pi / 360
|
42674 |
|
42675 | UNITS.grad.value = pi.div(200); // 2 * pi / 400
|
42676 |
|
42677 | UNITS.cycle.value = pi.times(2); // 2 * pi
|
42678 |
|
42679 | UNITS.arcsec.value = pi.div(648000); // 2 * pi / 360 / 3600
|
42680 |
|
42681 | UNITS.arcmin.value = pi.div(10800); // 2 * pi / 360 / 60
|
42682 | } else {
|
42683 | // number
|
42684 | UNITS.rad.value = 1;
|
42685 | UNITS.deg.value = Math.PI / 180; // 2 * pi / 360
|
42686 |
|
42687 | UNITS.grad.value = Math.PI / 200; // 2 * pi / 400
|
42688 |
|
42689 | UNITS.cycle.value = Math.PI * 2; // 2 * pi
|
42690 |
|
42691 | UNITS.arcsec.value = Math.PI / 648000; // 2 * pi / 360 / 3600
|
42692 |
|
42693 | UNITS.arcmin.value = Math.PI / 10800; // 2 * pi / 360 / 60
|
42694 | } // copy to the full names of the angles
|
42695 |
|
42696 |
|
42697 | UNITS.radian.value = UNITS.rad.value;
|
42698 | UNITS.degree.value = UNITS.deg.value;
|
42699 | UNITS.gradian.value = UNITS.grad.value;
|
42700 | } // apply the angle values now
|
42701 |
|
42702 |
|
42703 | calculateAngleValues(config); // recalculate the values on change of configuration
|
42704 |
|
42705 | math.on('config', function (curr, prev) {
|
42706 | if (curr.number !== prev.number) {
|
42707 | calculateAngleValues(curr);
|
42708 | }
|
42709 | });
|
42710 | /**
|
42711 | * A unit system is a set of dimensionally independent base units plus a set of derived units, formed by multiplication and division of the base units, that are by convention used with the unit system.
|
42712 | * A user perhaps could issue a command to select a preferred unit system, or use the default (see below).
|
42713 | * Auto unit system: The default unit system is updated on the fly anytime a unit is parsed. The corresponding unit in the default unit system is updated, so that answers are given in the same units the user supplies.
|
42714 | */
|
42715 |
|
42716 | var UNIT_SYSTEMS = {
|
42717 | si: {
|
42718 | // Base units
|
42719 | NONE: {
|
42720 | unit: UNIT_NONE,
|
42721 | prefix: PREFIXES.NONE['']
|
42722 | },
|
42723 | LENGTH: {
|
42724 | unit: UNITS.m,
|
42725 | prefix: PREFIXES.SHORT['']
|
42726 | },
|
42727 | MASS: {
|
42728 | unit: UNITS.g,
|
42729 | prefix: PREFIXES.SHORT['k']
|
42730 | },
|
42731 | TIME: {
|
42732 | unit: UNITS.s,
|
42733 | prefix: PREFIXES.SHORT['']
|
42734 | },
|
42735 | CURRENT: {
|
42736 | unit: UNITS.A,
|
42737 | prefix: PREFIXES.SHORT['']
|
42738 | },
|
42739 | TEMPERATURE: {
|
42740 | unit: UNITS.K,
|
42741 | prefix: PREFIXES.SHORT['']
|
42742 | },
|
42743 | LUMINOUS_INTENSITY: {
|
42744 | unit: UNITS.cd,
|
42745 | prefix: PREFIXES.SHORT['']
|
42746 | },
|
42747 | AMOUNT_OF_SUBSTANCE: {
|
42748 | unit: UNITS.mol,
|
42749 | prefix: PREFIXES.SHORT['']
|
42750 | },
|
42751 | ANGLE: {
|
42752 | unit: UNITS.rad,
|
42753 | prefix: PREFIXES.SHORT['']
|
42754 | },
|
42755 | BIT: {
|
42756 | unit: UNITS.bit,
|
42757 | prefix: PREFIXES.SHORT['']
|
42758 | },
|
42759 | // Derived units
|
42760 | FORCE: {
|
42761 | unit: UNITS.N,
|
42762 | prefix: PREFIXES.SHORT['']
|
42763 | },
|
42764 | ENERGY: {
|
42765 | unit: UNITS.J,
|
42766 | prefix: PREFIXES.SHORT['']
|
42767 | },
|
42768 | POWER: {
|
42769 | unit: UNITS.W,
|
42770 | prefix: PREFIXES.SHORT['']
|
42771 | },
|
42772 | PRESSURE: {
|
42773 | unit: UNITS.Pa,
|
42774 | prefix: PREFIXES.SHORT['']
|
42775 | },
|
42776 | ELECTRIC_CHARGE: {
|
42777 | unit: UNITS.C,
|
42778 | prefix: PREFIXES.SHORT['']
|
42779 | },
|
42780 | ELECTRIC_CAPACITANCE: {
|
42781 | unit: UNITS.F,
|
42782 | prefix: PREFIXES.SHORT['']
|
42783 | },
|
42784 | ELECTRIC_POTENTIAL: {
|
42785 | unit: UNITS.V,
|
42786 | prefix: PREFIXES.SHORT['']
|
42787 | },
|
42788 | ELECTRIC_RESISTANCE: {
|
42789 | unit: UNITS.ohm,
|
42790 | prefix: PREFIXES.SHORT['']
|
42791 | },
|
42792 | ELECTRIC_INDUCTANCE: {
|
42793 | unit: UNITS.H,
|
42794 | prefix: PREFIXES.SHORT['']
|
42795 | },
|
42796 | ELECTRIC_CONDUCTANCE: {
|
42797 | unit: UNITS.S,
|
42798 | prefix: PREFIXES.SHORT['']
|
42799 | },
|
42800 | MAGNETIC_FLUX: {
|
42801 | unit: UNITS.Wb,
|
42802 | prefix: PREFIXES.SHORT['']
|
42803 | },
|
42804 | MAGNETIC_FLUX_DENSITY: {
|
42805 | unit: UNITS.T,
|
42806 | prefix: PREFIXES.SHORT['']
|
42807 | },
|
42808 | FREQUENCY: {
|
42809 | unit: UNITS.Hz,
|
42810 | prefix: PREFIXES.SHORT['']
|
42811 | }
|
42812 | } // Clone to create the other unit systems
|
42813 |
|
42814 | };
|
42815 | UNIT_SYSTEMS.cgs = JSON.parse(JSON.stringify(UNIT_SYSTEMS.si));
|
42816 | UNIT_SYSTEMS.cgs.LENGTH = {
|
42817 | unit: UNITS.m,
|
42818 | prefix: PREFIXES.SHORT['c']
|
42819 | };
|
42820 | UNIT_SYSTEMS.cgs.MASS = {
|
42821 | unit: UNITS.g,
|
42822 | prefix: PREFIXES.SHORT['']
|
42823 | };
|
42824 | UNIT_SYSTEMS.cgs.FORCE = {
|
42825 | unit: UNITS.dyn,
|
42826 | prefix: PREFIXES.SHORT['']
|
42827 | };
|
42828 | UNIT_SYSTEMS.cgs.ENERGY = {
|
42829 | unit: UNITS.erg,
|
42830 | prefix: PREFIXES.NONE[''] // there are wholly 4 unique cgs systems for electricity and magnetism,
|
42831 | // so let's not worry about it unless somebody complains
|
42832 |
|
42833 | };
|
42834 | UNIT_SYSTEMS.us = JSON.parse(JSON.stringify(UNIT_SYSTEMS.si));
|
42835 | UNIT_SYSTEMS.us.LENGTH = {
|
42836 | unit: UNITS.ft,
|
42837 | prefix: PREFIXES.NONE['']
|
42838 | };
|
42839 | UNIT_SYSTEMS.us.MASS = {
|
42840 | unit: UNITS.lbm,
|
42841 | prefix: PREFIXES.NONE['']
|
42842 | };
|
42843 | UNIT_SYSTEMS.us.TEMPERATURE = {
|
42844 | unit: UNITS.degF,
|
42845 | prefix: PREFIXES.NONE['']
|
42846 | };
|
42847 | UNIT_SYSTEMS.us.FORCE = {
|
42848 | unit: UNITS.lbf,
|
42849 | prefix: PREFIXES.NONE['']
|
42850 | };
|
42851 | UNIT_SYSTEMS.us.ENERGY = {
|
42852 | unit: UNITS.BTU,
|
42853 | prefix: PREFIXES.BTU['']
|
42854 | };
|
42855 | UNIT_SYSTEMS.us.POWER = {
|
42856 | unit: UNITS.hp,
|
42857 | prefix: PREFIXES.NONE['']
|
42858 | };
|
42859 | UNIT_SYSTEMS.us.PRESSURE = {
|
42860 | unit: UNITS.psi,
|
42861 | prefix: PREFIXES.NONE[''] // Add additional unit systems here.
|
42862 | // Choose a unit system to seed the auto unit system.
|
42863 |
|
42864 | };
|
42865 | UNIT_SYSTEMS.auto = JSON.parse(JSON.stringify(UNIT_SYSTEMS.si)); // Set the current unit system
|
42866 |
|
42867 | var currentUnitSystem = UNIT_SYSTEMS.auto;
|
42868 | /**
|
42869 | * Set a unit system for formatting derived units.
|
42870 | * @param {string} [name] The name of the unit system.
|
42871 | */
|
42872 |
|
42873 | Unit.setUnitSystem = function (name) {
|
42874 | if (UNIT_SYSTEMS.hasOwnProperty(name)) {
|
42875 | currentUnitSystem = UNIT_SYSTEMS[name];
|
42876 | } else {
|
42877 | throw new Error('Unit system ' + name + ' does not exist. Choices are: ' + Object.keys(UNIT_SYSTEMS).join(', '));
|
42878 | }
|
42879 | };
|
42880 | /**
|
42881 | * Return the current unit system.
|
42882 | * @return {string} The current unit system.
|
42883 | */
|
42884 |
|
42885 |
|
42886 | Unit.getUnitSystem = function () {
|
42887 | for (var _key in UNIT_SYSTEMS) {
|
42888 | if (UNIT_SYSTEMS[_key] === currentUnitSystem) {
|
42889 | return _key;
|
42890 | }
|
42891 | }
|
42892 | };
|
42893 | /**
|
42894 | * Converters to convert from number to an other numeric type like BigNumber
|
42895 | * or Fraction
|
42896 | */
|
42897 |
|
42898 |
|
42899 | Unit.typeConverters = {
|
42900 | BigNumber: function BigNumber(x) {
|
42901 | return new type.BigNumber(x + ''); // stringify to prevent constructor error
|
42902 | },
|
42903 | Fraction: function Fraction(x) {
|
42904 | return new type.Fraction(x);
|
42905 | },
|
42906 | Complex: function Complex(x) {
|
42907 | return x;
|
42908 | },
|
42909 | number: function number(x) {
|
42910 | return x;
|
42911 | }
|
42912 | /**
|
42913 | * Retrieve the right convertor function corresponding with the type
|
42914 | * of provided exampleValue.
|
42915 | *
|
42916 | * @param {string} type A string 'number', 'BigNumber', or 'Fraction'
|
42917 | * In case of an unknown type,
|
42918 | * @return {Function}
|
42919 | */
|
42920 |
|
42921 | };
|
42922 |
|
42923 | Unit._getNumberConverter = function (type) {
|
42924 | if (!Unit.typeConverters[type]) {
|
42925 | throw new TypeError('Unsupported type "' + type + '"');
|
42926 | }
|
42927 |
|
42928 | return Unit.typeConverters[type];
|
42929 | }; // Add dimensions to each built-in unit
|
42930 |
|
42931 |
|
42932 | for (var _key2 in UNITS) {
|
42933 | var unit = UNITS[_key2];
|
42934 | unit.dimensions = unit.base.dimensions;
|
42935 | } // Create aliases
|
42936 |
|
42937 |
|
42938 | for (var name in ALIASES) {
|
42939 | if (ALIASES.hasOwnProperty(name)) {
|
42940 | var _unit2 = UNITS[ALIASES[name]];
|
42941 | var alias = {};
|
42942 |
|
42943 | for (var _key3 in _unit2) {
|
42944 | if (_unit2.hasOwnProperty(_key3)) {
|
42945 | alias[_key3] = _unit2[_key3];
|
42946 | }
|
42947 | }
|
42948 |
|
42949 | alias.name = name;
|
42950 | UNITS[name] = alias;
|
42951 | }
|
42952 | }
|
42953 |
|
42954 | function assertUnitNameIsValid(name) {
|
42955 | for (var i = 0; i < name.length; i++) {
|
42956 | var _c = name.charAt(i);
|
42957 |
|
42958 | var isValidAlpha = function isValidAlpha(p) {
|
42959 | return /^[a-zA-Z]$/.test(p);
|
42960 | };
|
42961 |
|
42962 | var _isDigit = function _isDigit(c) {
|
42963 | return c >= '0' && c <= '9';
|
42964 | };
|
42965 |
|
42966 | if (i === 0 && !isValidAlpha(_c)) {
|
42967 | throw new Error('Invalid unit name (must begin with alpha character): "' + name + '"');
|
42968 | }
|
42969 |
|
42970 | if (i > 0 && !(isValidAlpha(_c) || _isDigit(_c))) {
|
42971 | throw new Error('Invalid unit name (only alphanumeric characters are allowed): "' + name + '"');
|
42972 | }
|
42973 | }
|
42974 | }
|
42975 | /**
|
42976 | * Wrapper around createUnitSingle.
|
42977 | * Example:
|
42978 | * createUnit({
|
42979 | * foo: { },
|
42980 | * bar: {
|
42981 | * definition: 'kg/foo',
|
42982 | * aliases: ['ba', 'barr', 'bars'],
|
42983 | * offset: 200
|
42984 | * },
|
42985 | * baz: '4 bar'
|
42986 | * },
|
42987 | * {
|
42988 | * override: true
|
42989 | * })
|
42990 | * @param {object} obj Object map. Each key becomes a unit which is defined by its value.
|
42991 | * @param {object} options
|
42992 | */
|
42993 |
|
42994 |
|
42995 | Unit.createUnit = function (obj, options) {
|
42996 | if (_typeof(obj) !== 'object') {
|
42997 | throw new TypeError("createUnit expects first parameter to be of type 'Object'");
|
42998 | } // Remove all units and aliases we are overriding
|
42999 |
|
43000 |
|
43001 | if (options && options.override) {
|
43002 | for (var _key4 in obj) {
|
43003 | if (obj.hasOwnProperty(_key4)) {
|
43004 | Unit.deleteUnit(_key4);
|
43005 | }
|
43006 |
|
43007 | if (obj[_key4].aliases) {
|
43008 | for (var i = 0; i < obj[_key4].aliases.length; i++) {
|
43009 | Unit.deleteUnit(obj[_key4].aliases[i]);
|
43010 | }
|
43011 | }
|
43012 | }
|
43013 | } // TODO: traverse multiple times until all units have been added
|
43014 |
|
43015 |
|
43016 | var lastUnit;
|
43017 |
|
43018 | for (var _key5 in obj) {
|
43019 | if (obj.hasOwnProperty(_key5)) {
|
43020 | lastUnit = Unit.createUnitSingle(_key5, obj[_key5]);
|
43021 | }
|
43022 | }
|
43023 |
|
43024 | return lastUnit;
|
43025 | };
|
43026 | /**
|
43027 | * Create a user-defined unit and register it with the Unit type.
|
43028 | * Example:
|
43029 | * createUnitSingle('knot', '0.514444444 m/s')
|
43030 | * createUnitSingle('acre', new Unit(43560, 'ft^2'))
|
43031 | *
|
43032 | * @param {string} name The name of the new unit. Must be unique. Example: 'knot'
|
43033 | * @param {string, Unit} definition Definition of the unit in terms of existing units. For example, '0.514444444 m / s'.
|
43034 | * @param {Object} options (optional) An object containing any of the following properties:
|
43035 | * prefixes {string} "none", "short", "long", "binary_short", or "binary_long". The default is "none".
|
43036 | * aliases {Array} Array of strings. Example: ['knots', 'kt', 'kts']
|
43037 | * offset {Numeric} An offset to apply when converting from the unit. For example, the offset for celsius is 273.15 and the offset for farhenheit is 459.67. Default is 0.
|
43038 | *
|
43039 | * @return {Unit}
|
43040 | */
|
43041 |
|
43042 |
|
43043 | Unit.createUnitSingle = function (name, obj, options) {
|
43044 | if (typeof obj === 'undefined' || obj === null) {
|
43045 | obj = {};
|
43046 | }
|
43047 |
|
43048 | if (typeof name !== 'string') {
|
43049 | throw new TypeError("createUnitSingle expects first parameter to be of type 'string'");
|
43050 | } // Check collisions with existing units
|
43051 |
|
43052 |
|
43053 | if (UNITS.hasOwnProperty(name)) {
|
43054 | throw new Error('Cannot create unit "' + name + '": a unit with that name already exists');
|
43055 | } // TODO: Validate name for collisions with other built-in functions (like abs or cos, for example), and for acceptable variable names. For example, '42' is probably not a valid unit. Nor is '%', since it is also an operator.
|
43056 |
|
43057 |
|
43058 | assertUnitNameIsValid(name);
|
43059 | var defUnit = null; // The Unit from which the new unit will be created.
|
43060 |
|
43061 | var aliases = [];
|
43062 | var offset = 0;
|
43063 | var definition;
|
43064 | var prefixes;
|
43065 |
|
43066 | if (obj && obj.type === 'Unit') {
|
43067 | defUnit = obj.clone();
|
43068 | } else if (typeof obj === 'string') {
|
43069 | if (obj !== '') {
|
43070 | definition = obj;
|
43071 | }
|
43072 | } else if (_typeof(obj) === 'object') {
|
43073 | definition = obj.definition;
|
43074 | prefixes = obj.prefixes;
|
43075 | offset = obj.offset;
|
43076 |
|
43077 | if (obj.aliases) {
|
43078 | aliases = obj.aliases.valueOf(); // aliases could be a Matrix, so convert to Array
|
43079 | }
|
43080 | } else {
|
43081 | throw new TypeError('Cannot create unit "' + name + '" from "' + obj.toString() + '": expecting "string" or "Unit" or "Object"');
|
43082 | }
|
43083 |
|
43084 | if (aliases) {
|
43085 | for (var i = 0; i < aliases.length; i++) {
|
43086 | if (UNITS.hasOwnProperty(aliases[i])) {
|
43087 | throw new Error('Cannot create alias "' + aliases[i] + '": a unit with that name already exists');
|
43088 | }
|
43089 | }
|
43090 | }
|
43091 |
|
43092 | if (definition && typeof definition === 'string' && !defUnit) {
|
43093 | try {
|
43094 | defUnit = Unit.parse(definition, {
|
43095 | allowNoUnits: true
|
43096 | });
|
43097 | } catch (ex) {
|
43098 | ex.message = 'Could not create unit "' + name + '" from "' + definition + '": ' + ex.message;
|
43099 | throw ex;
|
43100 | }
|
43101 | } else if (definition && definition.type === 'Unit') {
|
43102 | defUnit = definition.clone();
|
43103 | }
|
43104 |
|
43105 | aliases = aliases || [];
|
43106 | offset = offset || 0;
|
43107 |
|
43108 | if (prefixes && prefixes.toUpperCase) {
|
43109 | prefixes = PREFIXES[prefixes.toUpperCase()] || PREFIXES.NONE;
|
43110 | } else {
|
43111 | prefixes = PREFIXES.NONE;
|
43112 | } // If defUnit is null, it is because the user did not
|
43113 | // specify a defintion. So create a new base dimension.
|
43114 |
|
43115 |
|
43116 | var newUnit = {};
|
43117 |
|
43118 | if (!defUnit) {
|
43119 | // Add a new base dimension
|
43120 | var baseName = name + '_STUFF'; // foo --> foo_STUFF, or the essence of foo
|
43121 |
|
43122 | if (BASE_DIMENSIONS.indexOf(baseName) >= 0) {
|
43123 | throw new Error('Cannot create new base unit "' + name + '": a base unit with that name already exists (and cannot be overridden)');
|
43124 | }
|
43125 |
|
43126 | BASE_DIMENSIONS.push(baseName); // Push 0 onto existing base units
|
43127 |
|
43128 | for (var b in BASE_UNITS) {
|
43129 | if (BASE_UNITS.hasOwnProperty(b)) {
|
43130 | BASE_UNITS[b].dimensions[BASE_DIMENSIONS.length - 1] = 0;
|
43131 | }
|
43132 | } // Add the new base unit
|
43133 |
|
43134 |
|
43135 | var newBaseUnit = {
|
43136 | dimensions: []
|
43137 | };
|
43138 |
|
43139 | for (var _i6 = 0; _i6 < BASE_DIMENSIONS.length; _i6++) {
|
43140 | newBaseUnit.dimensions[_i6] = 0;
|
43141 | }
|
43142 |
|
43143 | newBaseUnit.dimensions[BASE_DIMENSIONS.length - 1] = 1;
|
43144 | newBaseUnit.key = baseName;
|
43145 | BASE_UNITS[baseName] = newBaseUnit;
|
43146 | newUnit = {
|
43147 | name: name,
|
43148 | value: 1,
|
43149 | dimensions: BASE_UNITS[baseName].dimensions.slice(0),
|
43150 | prefixes: prefixes,
|
43151 | offset: offset,
|
43152 | base: BASE_UNITS[baseName]
|
43153 | };
|
43154 | currentUnitSystem[baseName] = {
|
43155 | unit: newUnit,
|
43156 | prefix: PREFIXES.NONE['']
|
43157 | };
|
43158 | } else {
|
43159 | newUnit = {
|
43160 | name: name,
|
43161 | value: defUnit.value,
|
43162 | dimensions: defUnit.dimensions.slice(0),
|
43163 | prefixes: prefixes,
|
43164 | offset: offset // Create a new base if no matching base exists
|
43165 |
|
43166 | };
|
43167 | var anyMatch = false;
|
43168 |
|
43169 | for (var _i7 in BASE_UNITS) {
|
43170 | if (BASE_UNITS.hasOwnProperty(_i7)) {
|
43171 | var match = true;
|
43172 |
|
43173 | for (var j = 0; j < BASE_DIMENSIONS.length; j++) {
|
43174 | if (Math.abs((newUnit.dimensions[j] || 0) - (BASE_UNITS[_i7].dimensions[j] || 0)) > 1e-12) {
|
43175 | match = false;
|
43176 | break;
|
43177 | }
|
43178 | }
|
43179 |
|
43180 | if (match) {
|
43181 | anyMatch = true;
|
43182 | newUnit.base = BASE_UNITS[_i7];
|
43183 | break;
|
43184 | }
|
43185 | }
|
43186 | }
|
43187 |
|
43188 | if (!anyMatch) {
|
43189 | var _baseName = name + '_STUFF'; // foo --> foo_STUFF, or the essence of foo
|
43190 | // Add the new base unit
|
43191 |
|
43192 |
|
43193 | var _newBaseUnit = {
|
43194 | dimensions: defUnit.dimensions.slice(0)
|
43195 | };
|
43196 | _newBaseUnit.key = _baseName;
|
43197 | BASE_UNITS[_baseName] = _newBaseUnit;
|
43198 | currentUnitSystem[_baseName] = {
|
43199 | unit: newUnit,
|
43200 | prefix: PREFIXES.NONE['']
|
43201 | };
|
43202 | newUnit.base = BASE_UNITS[_baseName];
|
43203 | }
|
43204 | }
|
43205 |
|
43206 | Unit.UNITS[name] = newUnit;
|
43207 |
|
43208 | for (var _i8 = 0; _i8 < aliases.length; _i8++) {
|
43209 | var aliasName = aliases[_i8];
|
43210 | var _alias = {};
|
43211 |
|
43212 | for (var _key6 in newUnit) {
|
43213 | if (newUnit.hasOwnProperty(_key6)) {
|
43214 | _alias[_key6] = newUnit[_key6];
|
43215 | }
|
43216 | }
|
43217 |
|
43218 | _alias.name = aliasName;
|
43219 | Unit.UNITS[aliasName] = _alias;
|
43220 | }
|
43221 |
|
43222 | return new Unit(null, name);
|
43223 | };
|
43224 |
|
43225 | Unit.deleteUnit = function (name) {
|
43226 | delete Unit.UNITS[name];
|
43227 | }; // expose arrays with prefixes, dimensions, units, systems
|
43228 |
|
43229 |
|
43230 | Unit.PREFIXES = PREFIXES;
|
43231 | Unit.BASE_DIMENSIONS = BASE_DIMENSIONS;
|
43232 | Unit.BASE_UNITS = BASE_UNITS;
|
43233 | Unit.UNIT_SYSTEMS = UNIT_SYSTEMS;
|
43234 | Unit.UNITS = UNITS;
|
43235 | return Unit;
|
43236 | }
|
43237 |
|
43238 | exports.name = 'Unit';
|
43239 | exports.path = 'type';
|
43240 | exports.factory = factory;
|
43241 | exports.math = true; // request access to the math namespace
|
43242 |
|
43243 | /***/ }),
|
43244 | /* 196 */
|
43245 | /***/ (function(module, exports, __webpack_require__) {
|
43246 |
|
43247 | "use strict";
|
43248 |
|
43249 |
|
43250 | var deepMap = __webpack_require__(1);
|
43251 |
|
43252 | function factory(type, config, load, typed) {
|
43253 | /**
|
43254 | * Create a unit. Depending on the passed arguments, the function
|
43255 | * will create and return a new math.type.Unit object.
|
43256 | * When a matrix is provided, all elements will be converted to units.
|
43257 | *
|
43258 | * Syntax:
|
43259 | *
|
43260 | * math.unit(unit : string)
|
43261 | * math.unit(value : number, unit : string)
|
43262 | *
|
43263 | * Examples:
|
43264 | *
|
43265 | * const a = math.unit(5, 'cm') // returns Unit 50 mm
|
43266 | * const b = math.unit('23 kg') // returns Unit 23 kg
|
43267 | * a.to('m') // returns Unit 0.05 m
|
43268 | *
|
43269 | * See also:
|
43270 | *
|
43271 | * bignumber, boolean, complex, index, matrix, number, string, createUnit
|
43272 | *
|
43273 | * @param {* | Array | Matrix} args A number and unit.
|
43274 | * @return {Unit | Array | Matrix} The created unit
|
43275 | */
|
43276 | var unit = typed('unit', {
|
43277 | 'Unit': function Unit(x) {
|
43278 | return x.clone();
|
43279 | },
|
43280 | 'string': function string(x) {
|
43281 | if (type.Unit.isValuelessUnit(x)) {
|
43282 | return new type.Unit(null, x); // a pure unit
|
43283 | }
|
43284 |
|
43285 | return type.Unit.parse(x, {
|
43286 | allowNoUnits: true
|
43287 | }); // a unit with value, like '5cm'
|
43288 | },
|
43289 | 'number | BigNumber | Fraction | Complex, string': function numberBigNumberFractionComplexString(value, unit) {
|
43290 | return new type.Unit(value, unit);
|
43291 | },
|
43292 | 'Array | Matrix': function ArrayMatrix(x) {
|
43293 | return deepMap(x, unit);
|
43294 | }
|
43295 | });
|
43296 | unit.toTex = {
|
43297 | 1: "\\left(${args[0]}\\right)",
|
43298 | 2: "\\left(\\left(${args[0]}\\right)${args[1]}\\right)"
|
43299 | };
|
43300 | return unit;
|
43301 | }
|
43302 |
|
43303 | exports.name = 'unit';
|
43304 | exports.factory = factory;
|
43305 |
|
43306 | /***/ }),
|
43307 | /* 197 */
|
43308 | /***/ (function(module, exports, __webpack_require__) {
|
43309 |
|
43310 | "use strict";
|
43311 |
|
43312 |
|
43313 | function factory(type, config, load, typed) {
|
43314 | /**
|
43315 | * Create a user-defined unit and register it with the Unit type.
|
43316 | *
|
43317 | * Syntax:
|
43318 | *
|
43319 | * math.createUnit({
|
43320 | * baseUnit1: {
|
43321 | * aliases: [string, ...]
|
43322 | * prefixes: object
|
43323 | * },
|
43324 | * unit2: {
|
43325 | * definition: string,
|
43326 | * aliases: [string, ...]
|
43327 | * prefixes: object,
|
43328 | * offset: number
|
43329 | * },
|
43330 | * unit3: string // Shortcut
|
43331 | * })
|
43332 | *
|
43333 | * // Another shortcut:
|
43334 | * math.createUnit(string, unit : string, [object])
|
43335 | *
|
43336 | * Examples:
|
43337 | *
|
43338 | * math.createUnit('foo')
|
43339 | * math.createUnit('knot', {definition: '0.514444444 m/s', aliases: ['knots', 'kt', 'kts']})
|
43340 | * math.createUnit('mph', '1 mile/hour')
|
43341 | *
|
43342 | * @param {string} name The name of the new unit. Must be unique. Example: 'knot'
|
43343 | * @param {string, Unit} definition Definition of the unit in terms of existing units. For example, '0.514444444 m / s'.
|
43344 | * @param {Object} options (optional) An object containing any of the following properties:
|
43345 | * - `prefixes {string}` "none", "short", "long", "binary_short", or "binary_long". The default is "none".
|
43346 | * - `aliases {Array}` Array of strings. Example: ['knots', 'kt', 'kts']
|
43347 | * - `offset {Numeric}` An offset to apply when converting from the unit. For example, the offset for celsius is 273.15. Default is 0.
|
43348 | *
|
43349 | * See also:
|
43350 | *
|
43351 | * unit
|
43352 | *
|
43353 | * @return {Unit} The new unit
|
43354 | */
|
43355 | var createUnit = typed('createUnit', {
|
43356 | // General function signature. First parameter is an object where each property is the definition of a new unit. The object keys are the unit names and the values are the definitions. The values can be objects, strings, or Units. If a property is an empty object or an empty string, a new base unit is created. The second parameter is the options.
|
43357 | 'Object, Object': function ObjectObject(obj, options) {
|
43358 | return type.Unit.createUnit(obj, options);
|
43359 | },
|
43360 | // Same as above but without the options.
|
43361 | 'Object': function Object(obj) {
|
43362 | return type.Unit.createUnit(obj, {});
|
43363 | },
|
43364 | // Shortcut method for creating one unit.
|
43365 | 'string, Unit | string | Object, Object': function stringUnitStringObjectObject(name, def, options) {
|
43366 | var obj = {};
|
43367 | obj[name] = def;
|
43368 | return type.Unit.createUnit(obj, options);
|
43369 | },
|
43370 | // Same as above but without the options.
|
43371 | 'string, Unit | string | Object': function stringUnitStringObject(name, def) {
|
43372 | var obj = {};
|
43373 | obj[name] = def;
|
43374 | return type.Unit.createUnit(obj, {});
|
43375 | },
|
43376 | // Without a definition, creates a base unit.
|
43377 | 'string': function string(name) {
|
43378 | var obj = {};
|
43379 | obj[name] = {};
|
43380 | return type.Unit.createUnit(obj, {});
|
43381 | }
|
43382 | });
|
43383 | return createUnit;
|
43384 | }
|
43385 |
|
43386 | exports.name = 'createUnit';
|
43387 | exports.factory = factory;
|
43388 |
|
43389 | /***/ }),
|
43390 | /* 198 */
|
43391 | /***/ (function(module, exports, __webpack_require__) {
|
43392 |
|
43393 | "use strict";
|
43394 |
|
43395 |
|
43396 | function factory(type, config, load, typed) {
|
43397 | /**
|
43398 | * Split a unit in an array of units whose sum is equal to the original unit.
|
43399 | *
|
43400 | * Syntax:
|
43401 | *
|
43402 | * splitUnit(unit: Unit, parts: Array.<Unit>)
|
43403 | *
|
43404 | * Example:
|
43405 | *
|
43406 | * math.splitUnit(new Unit(1, 'm'), ['feet', 'inch'])
|
43407 | * // [ 3 feet, 3.3700787401575 inch ]
|
43408 | *
|
43409 | * See also:
|
43410 | *
|
43411 | * unit
|
43412 | *
|
43413 | * @param {Array} [parts] An array of strings or valueless units.
|
43414 | * @return {Array} An array of units.
|
43415 | */
|
43416 | var splitUnit = typed('splitUnit', {
|
43417 | 'Unit, Array': function UnitArray(unit, parts) {
|
43418 | return unit.splitUnit(parts);
|
43419 | }
|
43420 | });
|
43421 | return splitUnit;
|
43422 | }
|
43423 |
|
43424 | exports.name = 'splitUnit';
|
43425 | exports.factory = factory;
|
43426 |
|
43427 | /***/ }),
|
43428 | /* 199 */
|
43429 | /***/ (function(module, exports, __webpack_require__) {
|
43430 |
|
43431 | "use strict";
|
43432 |
|
43433 |
|
43434 | var lazy = __webpack_require__(5).lazy;
|
43435 |
|
43436 | function factory(type, config, load, typed, math) {
|
43437 | // helper function to create a unit with a fixed prefix
|
43438 | function fixedUnit(str) {
|
43439 | var unit = type.Unit.parse(str);
|
43440 | unit.fixPrefix = true;
|
43441 | return unit;
|
43442 | } // Source: https://en.wikipedia.org/wiki/Physical_constant
|
43443 | // Universal constants
|
43444 |
|
43445 |
|
43446 | setLazyConstant(math, 'speedOfLight', function () {
|
43447 | return fixedUnit('299792458 m s^-1');
|
43448 | });
|
43449 | setLazyConstant(math, 'gravitationConstant', function () {
|
43450 | return fixedUnit('6.6738480e-11 m^3 kg^-1 s^-2');
|
43451 | });
|
43452 | setLazyConstant(math, 'planckConstant', function () {
|
43453 | return fixedUnit('6.626069311e-34 J s');
|
43454 | });
|
43455 | setLazyConstant(math, 'reducedPlanckConstant', function () {
|
43456 | return fixedUnit('1.05457172647e-34 J s');
|
43457 | }); // Electromagnetic constants
|
43458 |
|
43459 | setLazyConstant(math, 'magneticConstant', function () {
|
43460 | return fixedUnit('1.2566370614e-6 N A^-2');
|
43461 | });
|
43462 | setLazyConstant(math, 'electricConstant', function () {
|
43463 | return fixedUnit('8.854187817e-12 F m^-1');
|
43464 | });
|
43465 | setLazyConstant(math, 'vacuumImpedance', function () {
|
43466 | return fixedUnit('376.730313461 ohm');
|
43467 | });
|
43468 | setLazyConstant(math, 'coulomb', function () {
|
43469 | return fixedUnit('8.9875517873681764e9 N m^2 C^-2');
|
43470 | });
|
43471 | setLazyConstant(math, 'elementaryCharge', function () {
|
43472 | return fixedUnit('1.60217656535e-19 C');
|
43473 | });
|
43474 | setLazyConstant(math, 'bohrMagneton', function () {
|
43475 | return fixedUnit('9.2740096820e-24 J T^-1');
|
43476 | });
|
43477 | setLazyConstant(math, 'conductanceQuantum', function () {
|
43478 | return fixedUnit('7.748091734625e-5 S');
|
43479 | });
|
43480 | setLazyConstant(math, 'inverseConductanceQuantum', function () {
|
43481 | return fixedUnit('12906.403721742 ohm');
|
43482 | });
|
43483 | setLazyConstant(math, 'magneticFluxQuantum', function () {
|
43484 | return fixedUnit('2.06783375846e-15 Wb');
|
43485 | });
|
43486 | setLazyConstant(math, 'nuclearMagneton', function () {
|
43487 | return fixedUnit('5.0507835311e-27 J T^-1');
|
43488 | });
|
43489 | setLazyConstant(math, 'klitzing', function () {
|
43490 | return fixedUnit('25812.807443484 ohm');
|
43491 | }); // setLazyConstant(math, 'josephson', function () {return fixedUnit('4.8359787011e-14 Hz V^-1')}) // TODO: support for Hz needed
|
43492 | // Atomic and nuclear constants
|
43493 |
|
43494 | setLazyConstant(math, 'bohrRadius', function () {
|
43495 | return fixedUnit('5.291772109217e-11 m');
|
43496 | });
|
43497 | setLazyConstant(math, 'classicalElectronRadius', function () {
|
43498 | return fixedUnit('2.817940326727e-15 m');
|
43499 | });
|
43500 | setLazyConstant(math, 'electronMass', function () {
|
43501 | return fixedUnit('9.1093829140e-31 kg');
|
43502 | });
|
43503 | setLazyConstant(math, 'fermiCoupling', function () {
|
43504 | return fixedUnit('1.1663645e-5 GeV^-2');
|
43505 | });
|
43506 | setLazyConstant(math, 'fineStructure', function () {
|
43507 | return 7.297352569824e-3;
|
43508 | });
|
43509 | setLazyConstant(math, 'hartreeEnergy', function () {
|
43510 | return fixedUnit('4.3597443419e-18 J');
|
43511 | });
|
43512 | setLazyConstant(math, 'protonMass', function () {
|
43513 | return fixedUnit('1.67262177774e-27 kg');
|
43514 | });
|
43515 | setLazyConstant(math, 'deuteronMass', function () {
|
43516 | return fixedUnit('3.3435830926e-27 kg');
|
43517 | });
|
43518 | setLazyConstant(math, 'neutronMass', function () {
|
43519 | return fixedUnit('1.6749271613e-27 kg');
|
43520 | });
|
43521 | setLazyConstant(math, 'quantumOfCirculation', function () {
|
43522 | return fixedUnit('3.636947552024e-4 m^2 s^-1');
|
43523 | });
|
43524 | setLazyConstant(math, 'rydberg', function () {
|
43525 | return fixedUnit('10973731.56853955 m^-1');
|
43526 | });
|
43527 | setLazyConstant(math, 'thomsonCrossSection', function () {
|
43528 | return fixedUnit('6.65245873413e-29 m^2');
|
43529 | });
|
43530 | setLazyConstant(math, 'weakMixingAngle', function () {
|
43531 | return 0.222321;
|
43532 | });
|
43533 | setLazyConstant(math, 'efimovFactor', function () {
|
43534 | return 22.7;
|
43535 | }); // Physico-chemical constants
|
43536 |
|
43537 | setLazyConstant(math, 'atomicMass', function () {
|
43538 | return fixedUnit('1.66053892173e-27 kg');
|
43539 | });
|
43540 | setLazyConstant(math, 'avogadro', function () {
|
43541 | return fixedUnit('6.0221412927e23 mol^-1');
|
43542 | });
|
43543 | setLazyConstant(math, 'boltzmann', function () {
|
43544 | return fixedUnit('1.380648813e-23 J K^-1');
|
43545 | });
|
43546 | setLazyConstant(math, 'faraday', function () {
|
43547 | return fixedUnit('96485.336521 C mol^-1');
|
43548 | });
|
43549 | setLazyConstant(math, 'firstRadiation', function () {
|
43550 | return fixedUnit('3.7417715317e-16 W m^2');
|
43551 | }); // setLazyConstant(math, 'spectralRadiance', function () {return fixedUnit('1.19104286953e-16 W m^2 sr^-1')}) // TODO spectralRadiance
|
43552 |
|
43553 | setLazyConstant(math, 'loschmidt', function () {
|
43554 | return fixedUnit('2.686780524e25 m^-3');
|
43555 | });
|
43556 | setLazyConstant(math, 'gasConstant', function () {
|
43557 | return fixedUnit('8.314462175 J K^-1 mol^-1');
|
43558 | });
|
43559 | setLazyConstant(math, 'molarPlanckConstant', function () {
|
43560 | return fixedUnit('3.990312717628e-10 J s mol^-1');
|
43561 | });
|
43562 | setLazyConstant(math, 'molarVolume', function () {
|
43563 | return fixedUnit('2.241396820e-10 m^3 mol^-1');
|
43564 | });
|
43565 | setLazyConstant(math, 'sackurTetrode', function () {
|
43566 | return -1.164870823;
|
43567 | });
|
43568 | setLazyConstant(math, 'secondRadiation', function () {
|
43569 | return fixedUnit('1.438777013e-2 m K');
|
43570 | });
|
43571 | setLazyConstant(math, 'stefanBoltzmann', function () {
|
43572 | return fixedUnit('5.67037321e-8 W m^-2 K^-4');
|
43573 | });
|
43574 | setLazyConstant(math, 'wienDisplacement', function () {
|
43575 | return fixedUnit('2.897772126e-3 m K');
|
43576 | }); // Adopted values
|
43577 |
|
43578 | setLazyConstant(math, 'molarMass', function () {
|
43579 | return fixedUnit('1e-3 kg mol^-1');
|
43580 | });
|
43581 | setLazyConstant(math, 'molarMassC12', function () {
|
43582 | return fixedUnit('1.2e-2 kg mol^-1');
|
43583 | });
|
43584 | setLazyConstant(math, 'gravity', function () {
|
43585 | return fixedUnit('9.80665 m s^-2');
|
43586 | }); // atm is defined in Unit.js
|
43587 | // Natural units
|
43588 |
|
43589 | setLazyConstant(math, 'planckLength', function () {
|
43590 | return fixedUnit('1.61619997e-35 m');
|
43591 | });
|
43592 | setLazyConstant(math, 'planckMass', function () {
|
43593 | return fixedUnit('2.1765113e-8 kg');
|
43594 | });
|
43595 | setLazyConstant(math, 'planckTime', function () {
|
43596 | return fixedUnit('5.3910632e-44 s');
|
43597 | });
|
43598 | setLazyConstant(math, 'planckCharge', function () {
|
43599 | return fixedUnit('1.87554595641e-18 C');
|
43600 | });
|
43601 | setLazyConstant(math, 'planckTemperature', function () {
|
43602 | return fixedUnit('1.41683385e+32 K');
|
43603 | });
|
43604 | } // create a lazy constant in both math and mathWithTransform
|
43605 |
|
43606 |
|
43607 | function setLazyConstant(math, name, resolver) {
|
43608 | lazy(math, name, resolver);
|
43609 | lazy(math.expression.mathWithTransform, name, resolver);
|
43610 | }
|
43611 |
|
43612 | exports.factory = factory;
|
43613 | exports.lazy = false; // no lazy loading of constants, the constants themselves are lazy when needed
|
43614 |
|
43615 | exports.math = true; // request access to the math namespace
|
43616 |
|
43617 | /***/ }),
|
43618 | /* 200 */
|
43619 | /***/ (function(module, exports, __webpack_require__) {
|
43620 |
|
43621 | "use strict";
|
43622 |
|
43623 |
|
43624 | var object = __webpack_require__(5);
|
43625 |
|
43626 | var bigConstants = __webpack_require__(108);
|
43627 |
|
43628 | function factory(type, config, load, typed, math) {
|
43629 | // listen for changed in the configuration, automatically reload
|
43630 | // constants when needed
|
43631 | math.on('config', function (curr, prev) {
|
43632 | if (curr.number !== prev.number) {
|
43633 | factory(type, config, load, typed, math);
|
43634 | }
|
43635 | });
|
43636 | setConstant(math, 'true', true);
|
43637 | setConstant(math, 'false', false);
|
43638 | setConstant(math, 'null', null);
|
43639 | setConstant(math, 'uninitialized', 'Error: Constant uninitialized is removed since v4.0.0. Use null instead');
|
43640 |
|
43641 | if (config.number === 'BigNumber') {
|
43642 | setConstant(math, 'Infinity', new type.BigNumber(Infinity));
|
43643 | setConstant(math, 'NaN', new type.BigNumber(NaN));
|
43644 | setLazyConstant(math, 'pi', function () {
|
43645 | return bigConstants.pi(type.BigNumber);
|
43646 | });
|
43647 | setLazyConstant(math, 'tau', function () {
|
43648 | return bigConstants.tau(type.BigNumber);
|
43649 | });
|
43650 | setLazyConstant(math, 'e', function () {
|
43651 | return bigConstants.e(type.BigNumber);
|
43652 | });
|
43653 | setLazyConstant(math, 'phi', function () {
|
43654 | return bigConstants.phi(type.BigNumber);
|
43655 | }); // golden ratio, (1+sqrt(5))/2
|
43656 | // uppercase constants (for compatibility with built-in Math)
|
43657 |
|
43658 | setLazyConstant(math, 'E', function () {
|
43659 | return math.e;
|
43660 | });
|
43661 | setLazyConstant(math, 'LN2', function () {
|
43662 | return new type.BigNumber(2).ln();
|
43663 | });
|
43664 | setLazyConstant(math, 'LN10', function () {
|
43665 | return new type.BigNumber(10).ln();
|
43666 | });
|
43667 | setLazyConstant(math, 'LOG2E', function () {
|
43668 | return new type.BigNumber(1).div(new type.BigNumber(2).ln());
|
43669 | });
|
43670 | setLazyConstant(math, 'LOG10E', function () {
|
43671 | return new type.BigNumber(1).div(new type.BigNumber(10).ln());
|
43672 | });
|
43673 | setLazyConstant(math, 'PI', function () {
|
43674 | return math.pi;
|
43675 | });
|
43676 | setLazyConstant(math, 'SQRT1_2', function () {
|
43677 | return new type.BigNumber('0.5').sqrt();
|
43678 | });
|
43679 | setLazyConstant(math, 'SQRT2', function () {
|
43680 | return new type.BigNumber(2).sqrt();
|
43681 | });
|
43682 | } else {
|
43683 | setConstant(math, 'Infinity', Infinity);
|
43684 | setConstant(math, 'NaN', NaN);
|
43685 | setConstant(math, 'pi', Math.PI);
|
43686 | setConstant(math, 'tau', Math.PI * 2);
|
43687 | setConstant(math, 'e', Math.E);
|
43688 | setConstant(math, 'phi', 1.61803398874989484820458683436563811772030917980576286213545); // golden ratio, (1+sqrt(5))/2
|
43689 | // uppercase constants (for compatibility with built-in Math)
|
43690 |
|
43691 | setConstant(math, 'E', math.e);
|
43692 | setConstant(math, 'LN2', Math.LN2);
|
43693 | setConstant(math, 'LN10', Math.LN10);
|
43694 | setConstant(math, 'LOG2E', Math.LOG2E);
|
43695 | setConstant(math, 'LOG10E', Math.LOG10E);
|
43696 | setConstant(math, 'PI', math.pi);
|
43697 | setConstant(math, 'SQRT1_2', Math.SQRT1_2);
|
43698 | setConstant(math, 'SQRT2', Math.SQRT2);
|
43699 | } // complex i
|
43700 |
|
43701 |
|
43702 | if (type.Complex) {
|
43703 | setConstant(math, 'i', type.Complex.I);
|
43704 | } // meta information
|
43705 |
|
43706 |
|
43707 | setConstant(math, 'version', __webpack_require__(201));
|
43708 | } // create a constant in both math and mathWithTransform
|
43709 |
|
43710 |
|
43711 | function setConstant(math, name, value) {
|
43712 | math[name] = value;
|
43713 | math.expression.mathWithTransform[name] = value;
|
43714 | } // create a lazy constant in both math and mathWithTransform
|
43715 |
|
43716 |
|
43717 | function setLazyConstant(math, name, resolver) {
|
43718 | object.lazy(math, name, resolver);
|
43719 | object.lazy(math.expression.mathWithTransform, name, resolver);
|
43720 | }
|
43721 |
|
43722 | exports.factory = factory;
|
43723 | exports.lazy = false; // no lazy loading of constants, the constants themselves are lazy when needed
|
43724 |
|
43725 | exports.math = true; // request access to the math namespace
|
43726 |
|
43727 | /***/ }),
|
43728 | /* 201 */
|
43729 | /***/ (function(module, exports) {
|
43730 |
|
43731 | module.exports = '5.9.0'; // Note: This file is automatically generated when building math.js.
|
43732 | // Changes made in this file will be overwritten.
|
43733 |
|
43734 | /***/ }),
|
43735 | /* 202 */
|
43736 | /***/ (function(module, exports, __webpack_require__) {
|
43737 |
|
43738 | "use strict";
|
43739 |
|
43740 |
|
43741 | module.exports = [__webpack_require__(203), __webpack_require__(224), __webpack_require__(245), __webpack_require__(258), __webpack_require__(262), __webpack_require__(266), __webpack_require__(269), __webpack_require__(273), __webpack_require__(293), __webpack_require__(303), __webpack_require__(306), __webpack_require__(314), __webpack_require__(316), __webpack_require__(321), __webpack_require__(323), __webpack_require__(349), __webpack_require__(351)];
|
43742 |
|
43743 | /***/ }),
|
43744 | /* 203 */
|
43745 | /***/ (function(module, exports, __webpack_require__) {
|
43746 |
|
43747 | "use strict";
|
43748 |
|
43749 |
|
43750 | module.exports = [__webpack_require__(204), // simplify
|
43751 | __webpack_require__(86), // polynomial
|
43752 | __webpack_require__(207), // decomposition
|
43753 | __webpack_require__(208), __webpack_require__(87), __webpack_require__(132), // solver
|
43754 | __webpack_require__(136), __webpack_require__(222), __webpack_require__(137)];
|
43755 |
|
43756 | /***/ }),
|
43757 | /* 204 */
|
43758 | /***/ (function(module, exports, __webpack_require__) {
|
43759 |
|
43760 | "use strict";
|
43761 |
|
43762 |
|
43763 | function factory(type, config, load, typed) {
|
43764 | var parse = load(__webpack_require__(44));
|
43765 | var simplify = load(__webpack_require__(86));
|
43766 | var equal = load(__webpack_require__(51));
|
43767 | var isZero = load(__webpack_require__(60));
|
43768 | var getType = load(__webpack_require__(26));
|
43769 | var numeric = load(__webpack_require__(65));
|
43770 | var ConstantNode = load(__webpack_require__(58));
|
43771 | var FunctionNode = load(__webpack_require__(69));
|
43772 | var OperatorNode = load(__webpack_require__(59));
|
43773 | var ParenthesisNode = load(__webpack_require__(68));
|
43774 | var SymbolNode = load(__webpack_require__(54));
|
43775 | /**
|
43776 | * Takes the derivative of an expression expressed in parser Nodes.
|
43777 | * The derivative will be taken over the supplied variable in the
|
43778 | * second parameter. If there are multiple variables in the expression,
|
43779 | * it will return a partial derivative.
|
43780 | *
|
43781 | * This uses rules of differentiation which can be found here:
|
43782 | *
|
43783 | * - [Differentiation rules (Wikipedia)](https://en.wikipedia.org/wiki/Differentiation_rules)
|
43784 | *
|
43785 | * Syntax:
|
43786 | *
|
43787 | * derivative(expr, variable)
|
43788 | * derivative(expr, variable, options)
|
43789 | *
|
43790 | * Examples:
|
43791 | *
|
43792 | * math.derivative('x^2', 'x') // Node {2 * x}
|
43793 | * math.derivative('x^2', 'x', {simplify: false}) // Node {2 * 1 * x ^ (2 - 1)
|
43794 | * math.derivative('sin(2x)', 'x')) // Node {2 * cos(2 * x)}
|
43795 | * math.derivative('2*x', 'x').eval() // number 2
|
43796 | * math.derivative('x^2', 'x').eval({x: 4}) // number 8
|
43797 | * const f = math.parse('x^2')
|
43798 | * const x = math.parse('x')
|
43799 | * math.derivative(f, x) // Node {2 * x}
|
43800 | *
|
43801 | * See also:
|
43802 | *
|
43803 | * simplify, parse, eval
|
43804 | *
|
43805 | * @param {Node | string} expr The expression to differentiate
|
43806 | * @param {SymbolNode | string} variable The variable over which to differentiate
|
43807 | * @param {{simplify: boolean}} [options]
|
43808 | * There is one option available, `simplify`, which
|
43809 | * is true by default. When false, output will not
|
43810 | * be simplified.
|
43811 | * @return {ConstantNode | SymbolNode | ParenthesisNode | FunctionNode | OperatorNode} The derivative of `expr`
|
43812 | */
|
43813 |
|
43814 | var derivative = typed('derivative', {
|
43815 | 'Node, SymbolNode, Object': function NodeSymbolNodeObject(expr, variable, options) {
|
43816 | var constNodes = {};
|
43817 | constTag(constNodes, expr, variable.name);
|
43818 |
|
43819 | var res = _derivative(expr, constNodes);
|
43820 |
|
43821 | return options.simplify ? simplify(res) : res;
|
43822 | },
|
43823 | 'Node, SymbolNode': function NodeSymbolNode(expr, variable) {
|
43824 | return derivative(expr, variable, {
|
43825 | simplify: true
|
43826 | });
|
43827 | },
|
43828 | 'string, SymbolNode': function stringSymbolNode(expr, variable) {
|
43829 | return derivative(parse(expr), variable);
|
43830 | },
|
43831 | 'string, SymbolNode, Object': function stringSymbolNodeObject(expr, variable, options) {
|
43832 | return derivative(parse(expr), variable, options);
|
43833 | },
|
43834 | 'string, string': function stringString(expr, variable) {
|
43835 | return derivative(parse(expr), parse(variable));
|
43836 | },
|
43837 | 'string, string, Object': function stringStringObject(expr, variable, options) {
|
43838 | return derivative(parse(expr), parse(variable), options);
|
43839 | },
|
43840 | 'Node, string': function NodeString(expr, variable) {
|
43841 | return derivative(expr, parse(variable));
|
43842 | },
|
43843 | 'Node, string, Object': function NodeStringObject(expr, variable, options) {
|
43844 | return derivative(expr, parse(variable), options);
|
43845 | } // TODO: replace the 8 signatures above with 4 as soon as typed-function supports optional arguments
|
43846 |
|
43847 | /* TODO: implement and test syntax with order of derivatives -> implement as an option {order: number}
|
43848 | 'Node, SymbolNode, ConstantNode': function (expr, variable, {order}) {
|
43849 | let res = expr
|
43850 | for (let i = 0; i < order; i++) {
|
43851 | let constNodes = {}
|
43852 | constTag(constNodes, expr, variable.name)
|
43853 | res = _derivative(res, constNodes)
|
43854 | }
|
43855 | return res
|
43856 | }
|
43857 | */
|
43858 |
|
43859 | });
|
43860 | derivative._simplify = true;
|
43861 |
|
43862 | derivative.toTex = function (deriv) {
|
43863 | return _derivTex.apply(null, deriv.args);
|
43864 | }; // NOTE: the optional "order" parameter here is currently unused
|
43865 |
|
43866 |
|
43867 | var _derivTex = typed('_derivTex', {
|
43868 | 'Node, SymbolNode': function NodeSymbolNode(expr, x) {
|
43869 | if (type.isConstantNode(expr) && getType(expr.value) === 'string') {
|
43870 | return _derivTex(parse(expr.value).toString(), x.toString(), 1);
|
43871 | } else {
|
43872 | return _derivTex(expr.toString(), x.toString(), 1);
|
43873 | }
|
43874 | },
|
43875 | 'Node, ConstantNode': function NodeConstantNode(expr, x) {
|
43876 | if (getType(x.value) === 'string') {
|
43877 | return _derivTex(expr, parse(x.value));
|
43878 | } else {
|
43879 | throw new Error("The second parameter to 'derivative' is a non-string constant");
|
43880 | }
|
43881 | },
|
43882 | 'Node, SymbolNode, ConstantNode': function NodeSymbolNodeConstantNode(expr, x, order) {
|
43883 | return _derivTex(expr.toString(), x.name, order.value);
|
43884 | },
|
43885 | 'string, string, number': function stringStringNumber(expr, x, order) {
|
43886 | var d;
|
43887 |
|
43888 | if (order === 1) {
|
43889 | d = '{d\\over d' + x + '}';
|
43890 | } else {
|
43891 | d = '{d^{' + order + '}\\over d' + x + '^{' + order + '}}';
|
43892 | }
|
43893 |
|
43894 | return d + "\\left[".concat(expr, "\\right]");
|
43895 | }
|
43896 | });
|
43897 | /**
|
43898 | * Does a depth-first search on the expression tree to identify what Nodes
|
43899 | * are constants (e.g. 2 + 2), and stores the ones that are constants in
|
43900 | * constNodes. Classification is done as follows:
|
43901 | *
|
43902 | * 1. ConstantNodes are constants.
|
43903 | * 2. If there exists a SymbolNode, of which we are differentiating over,
|
43904 | * in the subtree it is not constant.
|
43905 | *
|
43906 | * @param {Object} constNodes Holds the nodes that are constant
|
43907 | * @param {ConstantNode | SymbolNode | ParenthesisNode | FunctionNode | OperatorNode} node
|
43908 | * @param {string} varName Variable that we are differentiating
|
43909 | * @return {boolean} if node is constant
|
43910 | */
|
43911 | // TODO: can we rewrite constTag into a pure function?
|
43912 |
|
43913 |
|
43914 | var constTag = typed('constTag', {
|
43915 | 'Object, ConstantNode, string': function ObjectConstantNodeString(constNodes, node) {
|
43916 | constNodes[node] = true;
|
43917 | return true;
|
43918 | },
|
43919 | 'Object, SymbolNode, string': function ObjectSymbolNodeString(constNodes, node, varName) {
|
43920 | // Treat other variables like constants. For reasoning, see:
|
43921 | // https://en.wikipedia.org/wiki/Partial_derivative
|
43922 | if (node.name !== varName) {
|
43923 | constNodes[node] = true;
|
43924 | return true;
|
43925 | }
|
43926 |
|
43927 | return false;
|
43928 | },
|
43929 | 'Object, ParenthesisNode, string': function ObjectParenthesisNodeString(constNodes, node, varName) {
|
43930 | return constTag(constNodes, node.content, varName);
|
43931 | },
|
43932 | 'Object, FunctionAssignmentNode, string': function ObjectFunctionAssignmentNodeString(constNodes, node, varName) {
|
43933 | if (node.params.indexOf(varName) === -1) {
|
43934 | constNodes[node] = true;
|
43935 | return true;
|
43936 | }
|
43937 |
|
43938 | return constTag(constNodes, node.expr, varName);
|
43939 | },
|
43940 | 'Object, FunctionNode | OperatorNode, string': function ObjectFunctionNodeOperatorNodeString(constNodes, node, varName) {
|
43941 | if (node.args.length > 0) {
|
43942 | var isConst = constTag(constNodes, node.args[0], varName);
|
43943 |
|
43944 | for (var i = 1; i < node.args.length; ++i) {
|
43945 | isConst = constTag(constNodes, node.args[i], varName) && isConst;
|
43946 | }
|
43947 |
|
43948 | if (isConst) {
|
43949 | constNodes[node] = true;
|
43950 | return true;
|
43951 | }
|
43952 | }
|
43953 |
|
43954 | return false;
|
43955 | }
|
43956 | });
|
43957 | /**
|
43958 | * Applies differentiation rules.
|
43959 | *
|
43960 | * @param {ConstantNode | SymbolNode | ParenthesisNode | FunctionNode | OperatorNode} node
|
43961 | * @param {Object} constNodes Holds the nodes that are constant
|
43962 | * @return {ConstantNode | SymbolNode | ParenthesisNode | FunctionNode | OperatorNode} The derivative of `expr`
|
43963 | */
|
43964 |
|
43965 | var _derivative = typed('_derivative', {
|
43966 | 'ConstantNode, Object': function ConstantNodeObject(node) {
|
43967 | return createConstantNode(0);
|
43968 | },
|
43969 | 'SymbolNode, Object': function SymbolNodeObject(node, constNodes) {
|
43970 | if (constNodes[node] !== undefined) {
|
43971 | return createConstantNode(0);
|
43972 | }
|
43973 |
|
43974 | return createConstantNode(1);
|
43975 | },
|
43976 | 'ParenthesisNode, Object': function ParenthesisNodeObject(node, constNodes) {
|
43977 | return new ParenthesisNode(_derivative(node.content, constNodes));
|
43978 | },
|
43979 | 'FunctionAssignmentNode, Object': function FunctionAssignmentNodeObject(node, constNodes) {
|
43980 | if (constNodes[node] !== undefined) {
|
43981 | return createConstantNode(0);
|
43982 | }
|
43983 |
|
43984 | return _derivative(node.expr, constNodes);
|
43985 | },
|
43986 | 'FunctionNode, Object': function FunctionNodeObject(node, constNodes) {
|
43987 | if (node.args.length !== 1) {
|
43988 | funcArgsCheck(node);
|
43989 | }
|
43990 |
|
43991 | if (constNodes[node] !== undefined) {
|
43992 | return createConstantNode(0);
|
43993 | }
|
43994 |
|
43995 | var arg0 = node.args[0];
|
43996 | var arg1;
|
43997 | var div = false; // is output a fraction?
|
43998 |
|
43999 | var negative = false; // is output negative?
|
44000 |
|
44001 | var funcDerivative;
|
44002 |
|
44003 | switch (node.name) {
|
44004 | case 'cbrt':
|
44005 | // d/dx(cbrt(x)) = 1 / (3x^(2/3))
|
44006 | div = true;
|
44007 | funcDerivative = new OperatorNode('*', 'multiply', [createConstantNode(3), new OperatorNode('^', 'pow', [arg0, new OperatorNode('/', 'divide', [createConstantNode(2), createConstantNode(3)])])]);
|
44008 | break;
|
44009 |
|
44010 | case 'sqrt':
|
44011 | case 'nthRoot':
|
44012 | // d/dx(sqrt(x)) = 1 / (2*sqrt(x))
|
44013 | if (node.args.length === 1) {
|
44014 | div = true;
|
44015 | funcDerivative = new OperatorNode('*', 'multiply', [createConstantNode(2), new FunctionNode('sqrt', [arg0])]);
|
44016 | } else if (node.args.length === 2) {
|
44017 | // Rearrange from nthRoot(x, a) -> x^(1/a)
|
44018 | arg1 = new OperatorNode('/', 'divide', [createConstantNode(1), node.args[1]]); // Is a variable?
|
44019 |
|
44020 | constNodes[arg1] = constNodes[node.args[1]];
|
44021 | return _derivative(new OperatorNode('^', 'pow', [arg0, arg1]), constNodes);
|
44022 | }
|
44023 |
|
44024 | break;
|
44025 |
|
44026 | case 'log10':
|
44027 | arg1 = createConstantNode(10);
|
44028 |
|
44029 | /* fall through! */
|
44030 |
|
44031 | case 'log':
|
44032 | if (!arg1 && node.args.length === 1) {
|
44033 | // d/dx(log(x)) = 1 / x
|
44034 | funcDerivative = arg0.clone();
|
44035 | div = true;
|
44036 | } else if (node.args.length === 1 && arg1 || node.args.length === 2 && constNodes[node.args[1]] !== undefined) {
|
44037 | // d/dx(log(x, c)) = 1 / (x*ln(c))
|
44038 | funcDerivative = new OperatorNode('*', 'multiply', [arg0.clone(), new FunctionNode('log', [arg1 || node.args[1]])]);
|
44039 | div = true;
|
44040 | } else if (node.args.length === 2) {
|
44041 | // d/dx(log(f(x), g(x))) = d/dx(log(f(x)) / log(g(x)))
|
44042 | return _derivative(new OperatorNode('/', 'divide', [new FunctionNode('log', [arg0]), new FunctionNode('log', [node.args[1]])]), constNodes);
|
44043 | }
|
44044 |
|
44045 | break;
|
44046 |
|
44047 | case 'pow':
|
44048 | constNodes[arg1] = constNodes[node.args[1]]; // Pass to pow operator node parser
|
44049 |
|
44050 | return _derivative(new OperatorNode('^', 'pow', [arg0, node.args[1]]), constNodes);
|
44051 |
|
44052 | case 'exp':
|
44053 | // d/dx(e^x) = e^x
|
44054 | funcDerivative = new FunctionNode('exp', [arg0.clone()]);
|
44055 | break;
|
44056 |
|
44057 | case 'sin':
|
44058 | // d/dx(sin(x)) = cos(x)
|
44059 | funcDerivative = new FunctionNode('cos', [arg0.clone()]);
|
44060 | break;
|
44061 |
|
44062 | case 'cos':
|
44063 | // d/dx(cos(x)) = -sin(x)
|
44064 | funcDerivative = new OperatorNode('-', 'unaryMinus', [new FunctionNode('sin', [arg0.clone()])]);
|
44065 | break;
|
44066 |
|
44067 | case 'tan':
|
44068 | // d/dx(tan(x)) = sec(x)^2
|
44069 | funcDerivative = new OperatorNode('^', 'pow', [new FunctionNode('sec', [arg0.clone()]), createConstantNode(2)]);
|
44070 | break;
|
44071 |
|
44072 | case 'sec':
|
44073 | // d/dx(sec(x)) = sec(x)tan(x)
|
44074 | funcDerivative = new OperatorNode('*', 'multiply', [node, new FunctionNode('tan', [arg0.clone()])]);
|
44075 | break;
|
44076 |
|
44077 | case 'csc':
|
44078 | // d/dx(csc(x)) = -csc(x)cot(x)
|
44079 | negative = true;
|
44080 | funcDerivative = new OperatorNode('*', 'multiply', [node, new FunctionNode('cot', [arg0.clone()])]);
|
44081 | break;
|
44082 |
|
44083 | case 'cot':
|
44084 | // d/dx(cot(x)) = -csc(x)^2
|
44085 | negative = true;
|
44086 | funcDerivative = new OperatorNode('^', 'pow', [new FunctionNode('csc', [arg0.clone()]), createConstantNode(2)]);
|
44087 | break;
|
44088 |
|
44089 | case 'asin':
|
44090 | // d/dx(asin(x)) = 1 / sqrt(1 - x^2)
|
44091 | div = true;
|
44092 | funcDerivative = new FunctionNode('sqrt', [new OperatorNode('-', 'subtract', [createConstantNode(1), new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)])])]);
|
44093 | break;
|
44094 |
|
44095 | case 'acos':
|
44096 | // d/dx(acos(x)) = -1 / sqrt(1 - x^2)
|
44097 | div = true;
|
44098 | negative = true;
|
44099 | funcDerivative = new FunctionNode('sqrt', [new OperatorNode('-', 'subtract', [createConstantNode(1), new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)])])]);
|
44100 | break;
|
44101 |
|
44102 | case 'atan':
|
44103 | // d/dx(atan(x)) = 1 / (x^2 + 1)
|
44104 | div = true;
|
44105 | funcDerivative = new OperatorNode('+', 'add', [new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)]), createConstantNode(1)]);
|
44106 | break;
|
44107 |
|
44108 | case 'asec':
|
44109 | // d/dx(asec(x)) = 1 / (|x|*sqrt(x^2 - 1))
|
44110 | div = true;
|
44111 | funcDerivative = new OperatorNode('*', 'multiply', [new FunctionNode('abs', [arg0.clone()]), new FunctionNode('sqrt', [new OperatorNode('-', 'subtract', [new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)]), createConstantNode(1)])])]);
|
44112 | break;
|
44113 |
|
44114 | case 'acsc':
|
44115 | // d/dx(acsc(x)) = -1 / (|x|*sqrt(x^2 - 1))
|
44116 | div = true;
|
44117 | negative = true;
|
44118 | funcDerivative = new OperatorNode('*', 'multiply', [new FunctionNode('abs', [arg0.clone()]), new FunctionNode('sqrt', [new OperatorNode('-', 'subtract', [new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)]), createConstantNode(1)])])]);
|
44119 | break;
|
44120 |
|
44121 | case 'acot':
|
44122 | // d/dx(acot(x)) = -1 / (x^2 + 1)
|
44123 | div = true;
|
44124 | negative = true;
|
44125 | funcDerivative = new OperatorNode('+', 'add', [new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)]), createConstantNode(1)]);
|
44126 | break;
|
44127 |
|
44128 | case 'sinh':
|
44129 | // d/dx(sinh(x)) = cosh(x)
|
44130 | funcDerivative = new FunctionNode('cosh', [arg0.clone()]);
|
44131 | break;
|
44132 |
|
44133 | case 'cosh':
|
44134 | // d/dx(cosh(x)) = sinh(x)
|
44135 | funcDerivative = new FunctionNode('sinh', [arg0.clone()]);
|
44136 | break;
|
44137 |
|
44138 | case 'tanh':
|
44139 | // d/dx(tanh(x)) = sech(x)^2
|
44140 | funcDerivative = new OperatorNode('^', 'pow', [new FunctionNode('sech', [arg0.clone()]), createConstantNode(2)]);
|
44141 | break;
|
44142 |
|
44143 | case 'sech':
|
44144 | // d/dx(sech(x)) = -sech(x)tanh(x)
|
44145 | negative = true;
|
44146 | funcDerivative = new OperatorNode('*', 'multiply', [node, new FunctionNode('tanh', [arg0.clone()])]);
|
44147 | break;
|
44148 |
|
44149 | case 'csch':
|
44150 | // d/dx(csch(x)) = -csch(x)coth(x)
|
44151 | negative = true;
|
44152 | funcDerivative = new OperatorNode('*', 'multiply', [node, new FunctionNode('coth', [arg0.clone()])]);
|
44153 | break;
|
44154 |
|
44155 | case 'coth':
|
44156 | // d/dx(coth(x)) = -csch(x)^2
|
44157 | negative = true;
|
44158 | funcDerivative = new OperatorNode('^', 'pow', [new FunctionNode('csch', [arg0.clone()]), createConstantNode(2)]);
|
44159 | break;
|
44160 |
|
44161 | case 'asinh':
|
44162 | // d/dx(asinh(x)) = 1 / sqrt(x^2 + 1)
|
44163 | div = true;
|
44164 | funcDerivative = new FunctionNode('sqrt', [new OperatorNode('+', 'add', [new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)]), createConstantNode(1)])]);
|
44165 | break;
|
44166 |
|
44167 | case 'acosh':
|
44168 | // d/dx(acosh(x)) = 1 / sqrt(x^2 - 1); XXX potentially only for x >= 1 (the real spectrum)
|
44169 | div = true;
|
44170 | funcDerivative = new FunctionNode('sqrt', [new OperatorNode('-', 'subtract', [new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)]), createConstantNode(1)])]);
|
44171 | break;
|
44172 |
|
44173 | case 'atanh':
|
44174 | // d/dx(atanh(x)) = 1 / (1 - x^2)
|
44175 | div = true;
|
44176 | funcDerivative = new OperatorNode('-', 'subtract', [createConstantNode(1), new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)])]);
|
44177 | break;
|
44178 |
|
44179 | case 'asech':
|
44180 | // d/dx(asech(x)) = -1 / (x*sqrt(1 - x^2))
|
44181 | div = true;
|
44182 | negative = true;
|
44183 | funcDerivative = new OperatorNode('*', 'multiply', [arg0.clone(), new FunctionNode('sqrt', [new OperatorNode('-', 'subtract', [createConstantNode(1), new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)])])])]);
|
44184 | break;
|
44185 |
|
44186 | case 'acsch':
|
44187 | // d/dx(acsch(x)) = -1 / (|x|*sqrt(x^2 + 1))
|
44188 | div = true;
|
44189 | negative = true;
|
44190 | funcDerivative = new OperatorNode('*', 'multiply', [new FunctionNode('abs', [arg0.clone()]), new FunctionNode('sqrt', [new OperatorNode('+', 'add', [new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)]), createConstantNode(1)])])]);
|
44191 | break;
|
44192 |
|
44193 | case 'acoth':
|
44194 | // d/dx(acoth(x)) = -1 / (1 - x^2)
|
44195 | div = true;
|
44196 | negative = true;
|
44197 | funcDerivative = new OperatorNode('-', 'subtract', [createConstantNode(1), new OperatorNode('^', 'pow', [arg0.clone(), createConstantNode(2)])]);
|
44198 | break;
|
44199 |
|
44200 | case 'abs':
|
44201 | // d/dx(abs(x)) = abs(x)/x
|
44202 | funcDerivative = new OperatorNode('/', 'divide', [new FunctionNode(new SymbolNode('abs'), [arg0.clone()]), arg0.clone()]);
|
44203 | break;
|
44204 |
|
44205 | case 'gamma': // Needs digamma function, d/dx(gamma(x)) = gamma(x)digamma(x)
|
44206 |
|
44207 | default:
|
44208 | throw new Error('Function "' + node.name + '" is not supported by derivative, or a wrong number of arguments is passed');
|
44209 | }
|
44210 |
|
44211 | var op, func;
|
44212 |
|
44213 | if (div) {
|
44214 | op = '/';
|
44215 | func = 'divide';
|
44216 | } else {
|
44217 | op = '*';
|
44218 | func = 'multiply';
|
44219 | }
|
44220 | /* Apply chain rule to all functions:
|
44221 | F(x) = f(g(x))
|
44222 | F'(x) = g'(x)*f'(g(x)) */
|
44223 |
|
44224 |
|
44225 | var chainDerivative = _derivative(arg0, constNodes);
|
44226 |
|
44227 | if (negative) {
|
44228 | chainDerivative = new OperatorNode('-', 'unaryMinus', [chainDerivative]);
|
44229 | }
|
44230 |
|
44231 | return new OperatorNode(op, func, [chainDerivative, funcDerivative]);
|
44232 | },
|
44233 | 'OperatorNode, Object': function OperatorNodeObject(node, constNodes) {
|
44234 | if (constNodes[node] !== undefined) {
|
44235 | return createConstantNode(0);
|
44236 | }
|
44237 |
|
44238 | if (node.op === '+') {
|
44239 | // d/dx(sum(f(x)) = sum(f'(x))
|
44240 | return new OperatorNode(node.op, node.fn, node.args.map(function (arg) {
|
44241 | return _derivative(arg, constNodes);
|
44242 | }));
|
44243 | }
|
44244 |
|
44245 | if (node.op === '-') {
|
44246 | // d/dx(+/-f(x)) = +/-f'(x)
|
44247 | if (node.isUnary()) {
|
44248 | return new OperatorNode(node.op, node.fn, [_derivative(node.args[0], constNodes)]);
|
44249 | } // Linearity of differentiation, d/dx(f(x) +/- g(x)) = f'(x) +/- g'(x)
|
44250 |
|
44251 |
|
44252 | if (node.isBinary()) {
|
44253 | return new OperatorNode(node.op, node.fn, [_derivative(node.args[0], constNodes), _derivative(node.args[1], constNodes)]);
|
44254 | }
|
44255 | }
|
44256 |
|
44257 | if (node.op === '*') {
|
44258 | // d/dx(c*f(x)) = c*f'(x)
|
44259 | var constantTerms = node.args.filter(function (arg) {
|
44260 | return constNodes[arg] !== undefined;
|
44261 | });
|
44262 |
|
44263 | if (constantTerms.length > 0) {
|
44264 | var nonConstantTerms = node.args.filter(function (arg) {
|
44265 | return constNodes[arg] === undefined;
|
44266 | });
|
44267 | var nonConstantNode = nonConstantTerms.length === 1 ? nonConstantTerms[0] : new OperatorNode('*', 'multiply', nonConstantTerms);
|
44268 | var newArgs = constantTerms.concat(_derivative(nonConstantNode, constNodes));
|
44269 | return new OperatorNode('*', 'multiply', newArgs);
|
44270 | } // Product Rule, d/dx(f(x)*g(x)) = f'(x)*g(x) + f(x)*g'(x)
|
44271 |
|
44272 |
|
44273 | return new OperatorNode('+', 'add', node.args.map(function (argOuter) {
|
44274 | return new OperatorNode('*', 'multiply', node.args.map(function (argInner) {
|
44275 | return argInner === argOuter ? _derivative(argInner, constNodes) : argInner.clone();
|
44276 | }));
|
44277 | }));
|
44278 | }
|
44279 |
|
44280 | if (node.op === '/' && node.isBinary()) {
|
44281 | var arg0 = node.args[0];
|
44282 | var arg1 = node.args[1]; // d/dx(f(x) / c) = f'(x) / c
|
44283 |
|
44284 | if (constNodes[arg1] !== undefined) {
|
44285 | return new OperatorNode('/', 'divide', [_derivative(arg0, constNodes), arg1]);
|
44286 | } // Reciprocal Rule, d/dx(c / f(x)) = -c(f'(x)/f(x)^2)
|
44287 |
|
44288 |
|
44289 | if (constNodes[arg0] !== undefined) {
|
44290 | return new OperatorNode('*', 'multiply', [new OperatorNode('-', 'unaryMinus', [arg0]), new OperatorNode('/', 'divide', [_derivative(arg1, constNodes), new OperatorNode('^', 'pow', [arg1.clone(), createConstantNode(2)])])]);
|
44291 | } // Quotient rule, d/dx(f(x) / g(x)) = (f'(x)g(x) - f(x)g'(x)) / g(x)^2
|
44292 |
|
44293 |
|
44294 | return new OperatorNode('/', 'divide', [new OperatorNode('-', 'subtract', [new OperatorNode('*', 'multiply', [_derivative(arg0, constNodes), arg1.clone()]), new OperatorNode('*', 'multiply', [arg0.clone(), _derivative(arg1, constNodes)])]), new OperatorNode('^', 'pow', [arg1.clone(), createConstantNode(2)])]);
|
44295 | }
|
44296 |
|
44297 | if (node.op === '^' && node.isBinary()) {
|
44298 | var _arg = node.args[0];
|
44299 | var _arg2 = node.args[1];
|
44300 |
|
44301 | if (constNodes[_arg] !== undefined) {
|
44302 | // If is secretly constant; 0^f(x) = 1 (in JS), 1^f(x) = 1
|
44303 | if (type.isConstantNode(_arg) && (isZero(_arg.value) || equal(_arg.value, 1))) {
|
44304 | return createConstantNode(0);
|
44305 | } // d/dx(c^f(x)) = c^f(x)*ln(c)*f'(x)
|
44306 |
|
44307 |
|
44308 | return new OperatorNode('*', 'multiply', [node, new OperatorNode('*', 'multiply', [new FunctionNode('log', [_arg.clone()]), _derivative(_arg2.clone(), constNodes)])]);
|
44309 | }
|
44310 |
|
44311 | if (constNodes[_arg2] !== undefined) {
|
44312 | if (type.isConstantNode(_arg2)) {
|
44313 | // If is secretly constant; f(x)^0 = 1 -> d/dx(1) = 0
|
44314 | if (isZero(_arg2.value)) {
|
44315 | return createConstantNode(0);
|
44316 | } // Ignore exponent; f(x)^1 = f(x)
|
44317 |
|
44318 |
|
44319 | if (equal(_arg2.value, 1)) {
|
44320 | return _derivative(_arg, constNodes);
|
44321 | }
|
44322 | } // Elementary Power Rule, d/dx(f(x)^c) = c*f'(x)*f(x)^(c-1)
|
44323 |
|
44324 |
|
44325 | var powMinusOne = new OperatorNode('^', 'pow', [_arg.clone(), new OperatorNode('-', 'subtract', [_arg2, createConstantNode(1)])]);
|
44326 | return new OperatorNode('*', 'multiply', [_arg2.clone(), new OperatorNode('*', 'multiply', [_derivative(_arg, constNodes), powMinusOne])]);
|
44327 | } // Functional Power Rule, d/dx(f^g) = f^g*[f'*(g/f) + g'ln(f)]
|
44328 |
|
44329 |
|
44330 | return new OperatorNode('*', 'multiply', [new OperatorNode('^', 'pow', [_arg.clone(), _arg2.clone()]), new OperatorNode('+', 'add', [new OperatorNode('*', 'multiply', [_derivative(_arg, constNodes), new OperatorNode('/', 'divide', [_arg2.clone(), _arg.clone()])]), new OperatorNode('*', 'multiply', [_derivative(_arg2, constNodes), new FunctionNode('log', [_arg.clone()])])])]);
|
44331 | }
|
44332 |
|
44333 | throw new Error('Operator "' + node.op + '" is not supported by derivative, or a wrong number of arguments is passed');
|
44334 | }
|
44335 | });
|
44336 | /**
|
44337 | * Ensures the number of arguments for a function are correct,
|
44338 | * and will throw an error otherwise.
|
44339 | *
|
44340 | * @param {FunctionNode} node
|
44341 | */
|
44342 |
|
44343 |
|
44344 | function funcArgsCheck(node) {
|
44345 | // TODO add min, max etc
|
44346 | if ((node.name === 'log' || node.name === 'nthRoot' || node.name === 'pow') && node.args.length === 2) {
|
44347 | return;
|
44348 | } // There should be an incorrect number of arguments if we reach here
|
44349 | // Change all args to constants to avoid unidentified
|
44350 | // symbol error when compiling function
|
44351 |
|
44352 |
|
44353 | for (var i = 0; i < node.args.length; ++i) {
|
44354 | node.args[i] = createConstantNode(0);
|
44355 | }
|
44356 |
|
44357 | node.compile().eval();
|
44358 | throw new Error('Expected TypeError, but none found');
|
44359 | }
|
44360 | /**
|
44361 | * Helper function to create a constant node with a specific type
|
44362 | * (number, BigNumber, Fraction)
|
44363 | * @param {number} value
|
44364 | * @param {string} [valueType]
|
44365 | * @return {ConstantNode}
|
44366 | */
|
44367 |
|
44368 |
|
44369 | function createConstantNode(value, valueType) {
|
44370 | return new ConstantNode(numeric(value, valueType || config.number));
|
44371 | }
|
44372 |
|
44373 | return derivative;
|
44374 | }
|
44375 |
|
44376 | exports.name = 'derivative';
|
44377 | exports.factory = factory;
|
44378 |
|
44379 | /***/ }),
|
44380 | /* 205 */
|
44381 | /***/ (function(module, exports, __webpack_require__) {
|
44382 |
|
44383 | "use strict";
|
44384 |
|
44385 |
|
44386 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
44387 |
|
44388 | var errorTransform = __webpack_require__(22).transform;
|
44389 |
|
44390 | var setSafeProperty = __webpack_require__(13).setSafeProperty;
|
44391 |
|
44392 | function factory(type, config, load, typed) {
|
44393 | var subset = load(__webpack_require__(23));
|
44394 | var matrix = load(__webpack_require__(0));
|
44395 | /**
|
44396 | * Replace part of an object:
|
44397 | *
|
44398 | * - Assign a property to an object
|
44399 | * - Replace a part of a string
|
44400 | * - Replace a matrix subset
|
44401 | *
|
44402 | * @param {Object | Array | Matrix | string} object
|
44403 | * @param {Index} index
|
44404 | * @param {*} value
|
44405 | * @return {Object | Array | Matrix | string} Returns the original object
|
44406 | * except in case of a string
|
44407 | */
|
44408 | // TODO: change assign to return the value instead of the object
|
44409 |
|
44410 | return function assign(object, index, value) {
|
44411 | try {
|
44412 | if (Array.isArray(object)) {
|
44413 | return matrix(object).subset(index, value).valueOf();
|
44414 | } else if (object && typeof object.subset === 'function') {
|
44415 | // Matrix
|
44416 | return object.subset(index, value);
|
44417 | } else if (typeof object === 'string') {
|
44418 | // TODO: move setStringSubset into a separate util file, use that
|
44419 | return subset(object, index, value);
|
44420 | } else if (_typeof(object) === 'object') {
|
44421 | if (!index.isObjectProperty()) {
|
44422 | throw TypeError('Cannot apply a numeric index as object property');
|
44423 | }
|
44424 |
|
44425 | setSafeProperty(object, index.getObjectProperty(), value);
|
44426 | return object;
|
44427 | } else {
|
44428 | throw new TypeError('Cannot apply index: unsupported type of object');
|
44429 | }
|
44430 | } catch (err) {
|
44431 | throw errorTransform(err);
|
44432 | }
|
44433 | };
|
44434 | }
|
44435 |
|
44436 | exports.factory = factory;
|
44437 |
|
44438 | /***/ }),
|
44439 | /* 206 */
|
44440 | /***/ (function(module, exports, __webpack_require__) {
|
44441 |
|
44442 | "use strict";
|
44443 |
|
44444 |
|
44445 | function factory(type, config, load, typed, math) {
|
44446 | var Node = math.expression.node.Node;
|
44447 | var OperatorNode = math.expression.node.OperatorNode;
|
44448 | var FunctionNode = math.expression.node.FunctionNode;
|
44449 | var ParenthesisNode = math.expression.node.ParenthesisNode;
|
44450 | /**
|
44451 | * resolve(expr, scope) replaces variable nodes with their scoped values
|
44452 | *
|
44453 | * Syntax:
|
44454 | *
|
44455 | * simplify.resolve(expr, scope)
|
44456 | *
|
44457 | * Examples:
|
44458 | *
|
44459 | * math.simplify.resolve('x + y', {x:1, y:2}) // Node {1 + 2}
|
44460 | * math.simplify.resolve(math.parse('x+y'), {x:1, y:2}) // Node {1 + 2}
|
44461 | * math.simplify('x+y', {x:2, y:'x+x'}).toString() // "6"
|
44462 | *
|
44463 | * @param {Node} node
|
44464 | * The expression tree to be simplified
|
44465 | * @param {Object} scope with variables to be resolved
|
44466 | */
|
44467 |
|
44468 | function resolve(node, scope) {
|
44469 | if (!scope) {
|
44470 | return node;
|
44471 | }
|
44472 |
|
44473 | if (type.isSymbolNode(node)) {
|
44474 | var value = scope[node.name];
|
44475 |
|
44476 | if (value instanceof Node) {
|
44477 | return resolve(value, scope);
|
44478 | } else if (typeof value === 'number') {
|
44479 | return math.parse(String(value));
|
44480 | }
|
44481 | } else if (type.isOperatorNode(node)) {
|
44482 | var args = node.args.map(function (arg) {
|
44483 | return resolve(arg, scope);
|
44484 | });
|
44485 | return new OperatorNode(node.op, node.fn, args, node.implicit);
|
44486 | } else if (type.isParenthesisNode(node)) {
|
44487 | return new ParenthesisNode(resolve(node.content, scope));
|
44488 | } else if (type.isFunctionNode(node)) {
|
44489 | var _args = node.args.map(function (arg) {
|
44490 | return resolve(arg, scope);
|
44491 | });
|
44492 |
|
44493 | return new FunctionNode(node.name, _args);
|
44494 | }
|
44495 |
|
44496 | return node;
|
44497 | }
|
44498 |
|
44499 | return resolve;
|
44500 | }
|
44501 |
|
44502 | exports.math = true;
|
44503 | exports.name = 'resolve';
|
44504 | exports.path = 'algebra.simplify';
|
44505 | exports.factory = factory;
|
44506 |
|
44507 | /***/ }),
|
44508 | /* 207 */
|
44509 | /***/ (function(module, exports, __webpack_require__) {
|
44510 |
|
44511 | "use strict";
|
44512 |
|
44513 |
|
44514 | function factory(type, config, load, typed) {
|
44515 | var simplify = load(__webpack_require__(86));
|
44516 | var simplifyCore = load(__webpack_require__(127));
|
44517 | var simplifyConstant = load(__webpack_require__(125));
|
44518 | var parse = load(__webpack_require__(129));
|
44519 |
|
44520 | var number = __webpack_require__(3);
|
44521 |
|
44522 | var ConstantNode = load(__webpack_require__(58));
|
44523 | var OperatorNode = load(__webpack_require__(59));
|
44524 | var SymbolNode = load(__webpack_require__(54));
|
44525 | /**
|
44526 | * Transform a rationalizable expression in a rational fraction.
|
44527 | * If rational fraction is one variable polynomial then converts
|
44528 | * the numerator and denominator in canonical form, with decreasing
|
44529 | * exponents, returning the coefficients of numerator.
|
44530 | *
|
44531 | * Syntax:
|
44532 | *
|
44533 | * rationalize(expr)
|
44534 | * rationalize(expr, detailed)
|
44535 | * rationalize(expr, scope)
|
44536 | * rationalize(expr, scope, detailed)
|
44537 | *
|
44538 | * Examples:
|
44539 | *
|
44540 | * math.rationalize('sin(x)+y')
|
44541 | * // Error: There is an unsolved function call
|
44542 | * math.rationalize('2x/y - y/(x+1)')
|
44543 | * // (2*x^2-y^2+2*x)/(x*y+y)
|
44544 | * math.rationalize('(2x+1)^6')
|
44545 | * // 64*x^6+192*x^5+240*x^4+160*x^3+60*x^2+12*x+1
|
44546 | * math.rationalize('2x/( (2x-1) / (3x+2) ) - 5x/ ( (3x+4) / (2x^2-5) ) + 3')
|
44547 | * // -20*x^4+28*x^3+104*x^2+6*x-12)/(6*x^2+5*x-4)
|
44548 | * math.rationalize('x/(1-x)/(x-2)/(x-3)/(x-4) + 2x/ ( (1-2x)/(2-3x) )/ ((3-4x)/(4-5x) )') =
|
44549 | * // (-30*x^7+344*x^6-1506*x^5+3200*x^4-3472*x^3+1846*x^2-381*x)/
|
44550 | * // (-8*x^6+90*x^5-383*x^4+780*x^3-797*x^2+390*x-72)
|
44551 | *
|
44552 | * math.rationalize('x+x+x+y',{y:1}) // 3*x+1
|
44553 | * math.rationalize('x+x+x+y',{}) // 3*x+y
|
44554 | *
|
44555 | * const ret = math.rationalize('x+x+x+y',{},true)
|
44556 | * // ret.expression=3*x+y, ret.variables = ["x","y"]
|
44557 | * const ret = math.rationalize('-2+5x^2',{},true)
|
44558 | * // ret.expression=5*x^2-2, ret.variables = ["x"], ret.coefficients=[-2,0,5]
|
44559 | *
|
44560 | * See also:
|
44561 | *
|
44562 | * simplify
|
44563 | *
|
44564 | * @param {Node|string} expr The expression to check if is a polynomial expression
|
44565 | * @param {Object|boolean} optional scope of expression or true for already evaluated rational expression at input
|
44566 | * @param {Boolean} detailed optional True if return an object, false if return expression node (default)
|
44567 | *
|
44568 | * @return {Object | Expression Node} The rational polynomial of `expr` or na object
|
44569 | * {Object}
|
44570 | * {Expression Node} expression: node simplified expression
|
44571 | * {Expression Node} numerator: simplified numerator of expression
|
44572 | * {Expression Node | boolean} denominator: simplified denominator or false (if there is no denominator)
|
44573 | * {Array} variables: variable names
|
44574 | * {Array} coefficients: coefficients of numerator sorted by increased exponent
|
44575 | * {Expression Node} node simplified expression
|
44576 | *
|
44577 | */
|
44578 |
|
44579 | var rationalize = typed('rationalize', {
|
44580 | 'string': function string(expr) {
|
44581 | return rationalize(parse(expr), {}, false);
|
44582 | },
|
44583 | 'string, boolean': function stringBoolean(expr, detailed) {
|
44584 | return rationalize(parse(expr), {}, detailed);
|
44585 | },
|
44586 | 'string, Object': function stringObject(expr, scope) {
|
44587 | return rationalize(parse(expr), scope, false);
|
44588 | },
|
44589 | 'string, Object, boolean': function stringObjectBoolean(expr, scope, detailed) {
|
44590 | return rationalize(parse(expr), scope, detailed);
|
44591 | },
|
44592 | 'Node': function Node(expr) {
|
44593 | return rationalize(expr, {}, false);
|
44594 | },
|
44595 | 'Node, boolean': function NodeBoolean(expr, detailed) {
|
44596 | return rationalize(expr, {}, detailed);
|
44597 | },
|
44598 | 'Node, Object': function NodeObject(expr, scope) {
|
44599 | return rationalize(expr, scope, false);
|
44600 | },
|
44601 | 'Node, Object, boolean': function NodeObjectBoolean(expr, scope, detailed) {
|
44602 | var setRules = rulesRationalize(); // Rules for change polynomial in near canonical form
|
44603 |
|
44604 | var polyRet = polynomial(expr, scope, true, setRules.firstRules); // Check if expression is a rationalizable polynomial
|
44605 |
|
44606 | var nVars = polyRet.variables.length;
|
44607 | expr = polyRet.expression;
|
44608 |
|
44609 | if (nVars >= 1) {
|
44610 | // If expression in not a constant
|
44611 | expr = expandPower(expr); // First expand power of polynomials (cannot be made from rules!)
|
44612 |
|
44613 | var sBefore; // Previous expression
|
44614 |
|
44615 | var rules;
|
44616 | var eDistrDiv = true;
|
44617 | var redoInic = false;
|
44618 | expr = simplify(expr, setRules.firstRules, {}, {
|
44619 | exactFractions: false
|
44620 | }); // Apply the initial rules, including succ div rules
|
44621 |
|
44622 | var s;
|
44623 |
|
44624 | while (true) {
|
44625 | // Apply alternately successive division rules and distr.div.rules
|
44626 | rules = eDistrDiv ? setRules.distrDivRules : setRules.sucDivRules;
|
44627 | expr = simplify(expr, rules); // until no more changes
|
44628 |
|
44629 | eDistrDiv = !eDistrDiv; // Swap between Distr.Div and Succ. Div. Rules
|
44630 |
|
44631 | s = expr.toString();
|
44632 |
|
44633 | if (s === sBefore) {
|
44634 | break; // No changes : end of the loop
|
44635 | }
|
44636 |
|
44637 | redoInic = true;
|
44638 | sBefore = s;
|
44639 | }
|
44640 |
|
44641 | if (redoInic) {
|
44642 | // Apply first rules again without succ div rules (if there are changes)
|
44643 | expr = simplify(expr, setRules.firstRulesAgain, {}, {
|
44644 | exactFractions: false
|
44645 | });
|
44646 | }
|
44647 |
|
44648 | expr = simplify(expr, setRules.finalRules, {}, {
|
44649 | exactFractions: false
|
44650 | }); // Apply final rules
|
44651 | } // NVars >= 1
|
44652 |
|
44653 |
|
44654 | var coefficients = [];
|
44655 | var retRationalize = {};
|
44656 |
|
44657 | if (expr.type === 'OperatorNode' && expr.isBinary() && expr.op === '/') {
|
44658 | // Separate numerator from denominator
|
44659 | if (nVars === 1) {
|
44660 | expr.args[0] = polyToCanonical(expr.args[0], coefficients);
|
44661 | expr.args[1] = polyToCanonical(expr.args[1]);
|
44662 | }
|
44663 |
|
44664 | if (detailed) {
|
44665 | retRationalize.numerator = expr.args[0];
|
44666 | retRationalize.denominator = expr.args[1];
|
44667 | }
|
44668 | } else {
|
44669 | if (nVars === 1) {
|
44670 | expr = polyToCanonical(expr, coefficients);
|
44671 | }
|
44672 |
|
44673 | if (detailed) {
|
44674 | retRationalize.numerator = expr;
|
44675 | retRationalize.denominator = null;
|
44676 | }
|
44677 | } // nVars
|
44678 |
|
44679 |
|
44680 | if (!detailed) return expr;
|
44681 | retRationalize.coefficients = coefficients;
|
44682 | retRationalize.variables = polyRet.variables;
|
44683 | retRationalize.expression = expr;
|
44684 | return retRationalize;
|
44685 | } // ^^^^^^^ end of rationalize ^^^^^^^^
|
44686 |
|
44687 | }); // end of typed rationalize
|
44688 |
|
44689 | /**
|
44690 | * Function to simplify an expression using an optional scope and
|
44691 | * return it if the expression is a polynomial expression, i.e.
|
44692 | * an expression with one or more variables and the operators
|
44693 | * +, -, *, and ^, where the exponent can only be a positive integer.
|
44694 | *
|
44695 | * Syntax:
|
44696 | *
|
44697 | * polynomial(expr,scope,extended, rules)
|
44698 | *
|
44699 | * @param {Node | string} expr The expression to simplify and check if is polynomial expression
|
44700 | * @param {object} scope Optional scope for expression simplification
|
44701 | * @param {boolean} extended Optional. Default is false. When true allows divide operator.
|
44702 | * @param {array} rules Optional. Default is no rule.
|
44703 | *
|
44704 | *
|
44705 | * @return {Object}
|
44706 | * {Object} node: node simplified expression
|
44707 | * {Array} variables: variable names
|
44708 | */
|
44709 |
|
44710 | function polynomial(expr, scope, extended, rules) {
|
44711 | var variables = [];
|
44712 | var node = simplify(expr, rules, scope, {
|
44713 | exactFractions: false
|
44714 | }); // Resolves any variables and functions with all defined parameters
|
44715 |
|
44716 | extended = !!extended;
|
44717 | var oper = '+-*' + (extended ? '/' : '');
|
44718 | recPoly(node);
|
44719 | var retFunc = {};
|
44720 | retFunc.expression = node;
|
44721 | retFunc.variables = variables;
|
44722 | return retFunc; // -------------------------------------------------------------------------------------------------------
|
44723 |
|
44724 | /**
|
44725 | * Function to simplify an expression using an optional scope and
|
44726 | * return it if the expression is a polynomial expression, i.e.
|
44727 | * an expression with one or more variables and the operators
|
44728 | * +, -, *, and ^, where the exponent can only be a positive integer.
|
44729 | *
|
44730 | * Syntax:
|
44731 | *
|
44732 | * recPoly(node)
|
44733 | *
|
44734 | *
|
44735 | * @param {Node} node The current sub tree expression in recursion
|
44736 | *
|
44737 | * @return nothing, throw an exception if error
|
44738 | */
|
44739 |
|
44740 | function recPoly(node) {
|
44741 | var tp = node.type; // node type
|
44742 |
|
44743 | if (tp === 'FunctionNode') {
|
44744 | // No function call in polynomial expression
|
44745 | throw new Error('There is an unsolved function call');
|
44746 | } else if (tp === 'OperatorNode') {
|
44747 | if (node.op === '^') {
|
44748 | if (node.args[1].fn === 'unaryMinus') {
|
44749 | node = node.args[0];
|
44750 | }
|
44751 |
|
44752 | if (node.args[1].type !== 'ConstantNode' || !number.isInteger(parseFloat(node.args[1].value))) {
|
44753 | throw new Error('There is a non-integer exponent');
|
44754 | } else {
|
44755 | recPoly(node.args[0]);
|
44756 | }
|
44757 | } else {
|
44758 | if (oper.indexOf(node.op) === -1) {
|
44759 | throw new Error('Operator ' + node.op + ' invalid in polynomial expression');
|
44760 | }
|
44761 |
|
44762 | for (var i = 0; i < node.args.length; i++) {
|
44763 | recPoly(node.args[i]);
|
44764 | }
|
44765 | } // type of operator
|
44766 |
|
44767 | } else if (tp === 'SymbolNode') {
|
44768 | var name = node.name; // variable name
|
44769 |
|
44770 | var pos = variables.indexOf(name);
|
44771 |
|
44772 | if (pos === -1) {
|
44773 | // new variable in expression
|
44774 | variables.push(name);
|
44775 | }
|
44776 | } else if (tp === 'ParenthesisNode') {
|
44777 | recPoly(node.content);
|
44778 | } else if (tp !== 'ConstantNode') {
|
44779 | throw new Error('type ' + tp + ' is not allowed in polynomial expression');
|
44780 | }
|
44781 | } // end of recPoly
|
44782 |
|
44783 | } // end of polynomial
|
44784 | // ---------------------------------------------------------------------------------------
|
44785 |
|
44786 | /**
|
44787 | * Return a rule set to rationalize an polynomial expression in rationalize
|
44788 | *
|
44789 | * Syntax:
|
44790 | *
|
44791 | * rulesRationalize()
|
44792 | *
|
44793 | * @return {array} rule set to rationalize an polynomial expression
|
44794 | */
|
44795 |
|
44796 |
|
44797 | function rulesRationalize() {
|
44798 | var oldRules = [simplifyCore, // sCore
|
44799 | {
|
44800 | l: 'n+n',
|
44801 | r: '2*n'
|
44802 | }, {
|
44803 | l: 'n+-n',
|
44804 | r: '0'
|
44805 | }, simplifyConstant, // sConstant
|
44806 | {
|
44807 | l: 'n*(n1^-1)',
|
44808 | r: 'n/n1'
|
44809 | }, {
|
44810 | l: 'n*n1^-n2',
|
44811 | r: 'n/n1^n2'
|
44812 | }, {
|
44813 | l: 'n1^-1',
|
44814 | r: '1/n1'
|
44815 | }, {
|
44816 | l: 'n*(n1/n2)',
|
44817 | r: '(n*n1)/n2'
|
44818 | }, {
|
44819 | l: '1*n',
|
44820 | r: 'n'
|
44821 | }];
|
44822 | var rulesFirst = [{
|
44823 | l: '(-n1)/(-n2)',
|
44824 | r: 'n1/n2'
|
44825 | }, // Unary division
|
44826 | {
|
44827 | l: '(-n1)*(-n2)',
|
44828 | r: 'n1*n2'
|
44829 | }, // Unary multiplication
|
44830 | {
|
44831 | l: 'n1--n2',
|
44832 | r: 'n1+n2'
|
44833 | }, // '--' elimination
|
44834 | {
|
44835 | l: 'n1-n2',
|
44836 | r: 'n1+(-n2)'
|
44837 | }, // Subtraction turn into add with un�ry minus
|
44838 | {
|
44839 | l: '(n1+n2)*n3',
|
44840 | r: '(n1*n3 + n2*n3)'
|
44841 | }, // Distributive 1
|
44842 | {
|
44843 | l: 'n1*(n2+n3)',
|
44844 | r: '(n1*n2+n1*n3)'
|
44845 | }, // Distributive 2
|
44846 | {
|
44847 | l: 'c1*n + c2*n',
|
44848 | r: '(c1+c2)*n'
|
44849 | }, // Joining constants
|
44850 | {
|
44851 | l: 'c1*n + n',
|
44852 | r: '(c1+1)*n'
|
44853 | }, // Joining constants
|
44854 | {
|
44855 | l: 'c1*n - c2*n',
|
44856 | r: '(c1-c2)*n'
|
44857 | }, // Joining constants
|
44858 | {
|
44859 | l: 'c1*n - n',
|
44860 | r: '(c1-1)*n'
|
44861 | }, // Joining constants
|
44862 | {
|
44863 | l: 'v/c',
|
44864 | r: '(1/c)*v'
|
44865 | }, // variable/constant (new!)
|
44866 | {
|
44867 | l: 'v/-c',
|
44868 | r: '-(1/c)*v'
|
44869 | }, // variable/constant (new!)
|
44870 | {
|
44871 | l: '-v*-c',
|
44872 | r: 'c*v'
|
44873 | }, // Inversion constant and variable 1
|
44874 | {
|
44875 | l: '-v*c',
|
44876 | r: '-c*v'
|
44877 | }, // Inversion constant and variable 2
|
44878 | {
|
44879 | l: 'v*-c',
|
44880 | r: '-c*v'
|
44881 | }, // Inversion constant and variable 3
|
44882 | {
|
44883 | l: 'v*c',
|
44884 | r: 'c*v'
|
44885 | }, // Inversion constant and variable 4
|
44886 | {
|
44887 | l: '-(-n1*n2)',
|
44888 | r: '(n1*n2)'
|
44889 | }, // Unary propagation
|
44890 | {
|
44891 | l: '-(n1*n2)',
|
44892 | r: '(-n1*n2)'
|
44893 | }, // Unary propagation
|
44894 | {
|
44895 | l: '-(-n1+n2)',
|
44896 | r: '(n1-n2)'
|
44897 | }, // Unary propagation
|
44898 | {
|
44899 | l: '-(n1+n2)',
|
44900 | r: '(-n1-n2)'
|
44901 | }, // Unary propagation
|
44902 | {
|
44903 | l: '(n1^n2)^n3',
|
44904 | r: '(n1^(n2*n3))'
|
44905 | }, // Power to Power
|
44906 | {
|
44907 | l: '-(-n1/n2)',
|
44908 | r: '(n1/n2)'
|
44909 | }, // Division and Unary
|
44910 | {
|
44911 | l: '-(n1/n2)',
|
44912 | r: '(-n1/n2)'
|
44913 | }]; // Divisao and Unary
|
44914 |
|
44915 | var rulesDistrDiv = [{
|
44916 | l: '(n1/n2 + n3/n4)',
|
44917 | r: '((n1*n4 + n3*n2)/(n2*n4))'
|
44918 | }, // Sum of fractions
|
44919 | {
|
44920 | l: '(n1/n2 + n3)',
|
44921 | r: '((n1 + n3*n2)/n2)'
|
44922 | }, // Sum fraction with number 1
|
44923 | {
|
44924 | l: '(n1 + n2/n3)',
|
44925 | r: '((n1*n3 + n2)/n3)'
|
44926 | }]; // Sum fraction with number 1
|
44927 |
|
44928 | var rulesSucDiv = [{
|
44929 | l: '(n1/(n2/n3))',
|
44930 | r: '((n1*n3)/n2)'
|
44931 | }, // Division simplification
|
44932 | {
|
44933 | l: '(n1/n2/n3)',
|
44934 | r: '(n1/(n2*n3))'
|
44935 | }];
|
44936 | var setRules = {}; // rules set in 4 steps.
|
44937 | // All rules => infinite loop
|
44938 | // setRules.allRules =oldRules.concat(rulesFirst,rulesDistrDiv,rulesSucDiv)
|
44939 |
|
44940 | setRules.firstRules = oldRules.concat(rulesFirst, rulesSucDiv); // First rule set
|
44941 |
|
44942 | setRules.distrDivRules = rulesDistrDiv; // Just distr. div. rules
|
44943 |
|
44944 | setRules.sucDivRules = rulesSucDiv; // Jus succ. div. rules
|
44945 |
|
44946 | setRules.firstRulesAgain = oldRules.concat(rulesFirst); // Last rules set without succ. div.
|
44947 | // Division simplification
|
44948 | // Second rule set.
|
44949 | // There is no aggregate expression with parentesis, but the only variable can be scattered.
|
44950 |
|
44951 | setRules.finalRules = [simplifyCore, // simplify.rules[0]
|
44952 | {
|
44953 | l: 'n*-n',
|
44954 | r: '-n^2'
|
44955 | }, // Joining multiply with power 1
|
44956 | {
|
44957 | l: 'n*n',
|
44958 | r: 'n^2'
|
44959 | }, // Joining multiply with power 2
|
44960 | simplifyConstant, // simplify.rules[14] old 3rd index in oldRules
|
44961 | {
|
44962 | l: 'n*-n^n1',
|
44963 | r: '-n^(n1+1)'
|
44964 | }, // Joining multiply with power 3
|
44965 | {
|
44966 | l: 'n*n^n1',
|
44967 | r: 'n^(n1+1)'
|
44968 | }, // Joining multiply with power 4
|
44969 | {
|
44970 | l: 'n^n1*-n^n2',
|
44971 | r: '-n^(n1+n2)'
|
44972 | }, // Joining multiply with power 5
|
44973 | {
|
44974 | l: 'n^n1*n^n2',
|
44975 | r: 'n^(n1+n2)'
|
44976 | }, // Joining multiply with power 6
|
44977 | {
|
44978 | l: 'n^n1*-n',
|
44979 | r: '-n^(n1+1)'
|
44980 | }, // Joining multiply with power 7
|
44981 | {
|
44982 | l: 'n^n1*n',
|
44983 | r: 'n^(n1+1)'
|
44984 | }, // Joining multiply with power 8
|
44985 | {
|
44986 | l: 'n^n1/-n',
|
44987 | r: '-n^(n1-1)'
|
44988 | }, // Joining multiply with power 8
|
44989 | {
|
44990 | l: 'n^n1/n',
|
44991 | r: 'n^(n1-1)'
|
44992 | }, // Joining division with power 1
|
44993 | {
|
44994 | l: 'n/-n^n1',
|
44995 | r: '-n^(1-n1)'
|
44996 | }, // Joining division with power 2
|
44997 | {
|
44998 | l: 'n/n^n1',
|
44999 | r: 'n^(1-n1)'
|
45000 | }, // Joining division with power 3
|
45001 | {
|
45002 | l: 'n^n1/-n^n2',
|
45003 | r: 'n^(n1-n2)'
|
45004 | }, // Joining division with power 4
|
45005 | {
|
45006 | l: 'n^n1/n^n2',
|
45007 | r: 'n^(n1-n2)'
|
45008 | }, // Joining division with power 5
|
45009 | {
|
45010 | l: 'n1+(-n2*n3)',
|
45011 | r: 'n1-n2*n3'
|
45012 | }, // Solving useless parenthesis 1
|
45013 | {
|
45014 | l: 'v*(-c)',
|
45015 | r: '-c*v'
|
45016 | }, // Solving useless unary 2
|
45017 | {
|
45018 | l: 'n1+-n2',
|
45019 | r: 'n1-n2'
|
45020 | }, // Solving +- together (new!)
|
45021 | {
|
45022 | l: 'v*c',
|
45023 | r: 'c*v'
|
45024 | }, // inversion constant with variable
|
45025 | {
|
45026 | l: '(n1^n2)^n3',
|
45027 | r: '(n1^(n2*n3))' // Power to Power
|
45028 |
|
45029 | }];
|
45030 | return setRules;
|
45031 | } // End rulesRationalize
|
45032 | // ---------------------------------------------------------------------------------------
|
45033 |
|
45034 | /**
|
45035 | * Expand recursively a tree node for handling with expressions with exponents
|
45036 | * (it's not for constants, symbols or functions with exponents)
|
45037 | * PS: The other parameters are internal for recursion
|
45038 | *
|
45039 | * Syntax:
|
45040 | *
|
45041 | * expandPower(node)
|
45042 | *
|
45043 | * @param {Node} node Current expression node
|
45044 | * @param {node} parent Parent current node inside the recursion
|
45045 | * @param (int} Parent number of chid inside the rercursion
|
45046 | *
|
45047 | * @return {node} node expression with all powers expanded.
|
45048 | */
|
45049 |
|
45050 |
|
45051 | function expandPower(node, parent, indParent) {
|
45052 | var tp = node.type;
|
45053 | var internal = arguments.length > 1; // TRUE in internal calls
|
45054 |
|
45055 | if (tp === 'OperatorNode' && node.isBinary()) {
|
45056 | var does = false;
|
45057 | var val;
|
45058 |
|
45059 | if (node.op === '^') {
|
45060 | // First operator: Parenthesis or UnaryMinus
|
45061 | if ((node.args[0].type === 'ParenthesisNode' || node.args[0].type === 'OperatorNode') && node.args[1].type === 'ConstantNode') {
|
45062 | // Second operator: Constant
|
45063 | val = parseFloat(node.args[1].value);
|
45064 | does = val >= 2 && number.isInteger(val);
|
45065 | }
|
45066 | }
|
45067 |
|
45068 | if (does) {
|
45069 | // Exponent >= 2
|
45070 | // Before:
|
45071 | // operator A --> Subtree
|
45072 | // parent pow
|
45073 | // constant
|
45074 | //
|
45075 | if (val > 2) {
|
45076 | // Exponent > 2,
|
45077 | // AFTER: (exponent > 2)
|
45078 | // operator A --> Subtree
|
45079 | // parent *
|
45080 | // deep clone (operator A --> Subtree
|
45081 | // pow
|
45082 | // constant - 1
|
45083 | //
|
45084 | var nEsqTopo = node.args[0];
|
45085 | var nDirTopo = new OperatorNode('^', 'pow', [node.args[0].cloneDeep(), new ConstantNode(val - 1)]);
|
45086 | node = new OperatorNode('*', 'multiply', [nEsqTopo, nDirTopo]);
|
45087 | } else {
|
45088 | // Expo = 2 - no power
|
45089 | // AFTER: (exponent = 2)
|
45090 | // operator A --> Subtree
|
45091 | // parent oper
|
45092 | // deep clone (operator A --> Subtree)
|
45093 | //
|
45094 | node = new OperatorNode('*', 'multiply', [node.args[0], node.args[0].cloneDeep()]);
|
45095 | }
|
45096 |
|
45097 | if (internal) {
|
45098 | // Change parent references in internal recursive calls
|
45099 | if (indParent === 'content') {
|
45100 | parent.content = node;
|
45101 | } else {
|
45102 | parent.args[indParent] = node;
|
45103 | }
|
45104 | }
|
45105 | } // does
|
45106 |
|
45107 | } // binary OperatorNode
|
45108 |
|
45109 |
|
45110 | if (tp === 'ParenthesisNode') {
|
45111 | // Recursion
|
45112 | expandPower(node.content, node, 'content');
|
45113 | } else if (tp !== 'ConstantNode' && tp !== 'SymbolNode') {
|
45114 | for (var i = 0; i < node.args.length; i++) {
|
45115 | expandPower(node.args[i], node, i);
|
45116 | }
|
45117 | }
|
45118 |
|
45119 | if (!internal) {
|
45120 | // return the root node
|
45121 | return node;
|
45122 | }
|
45123 | } // End expandPower
|
45124 | // ---------------------------------------------------------------------------------------
|
45125 |
|
45126 | /**
|
45127 | * Auxilary function for rationalize
|
45128 | * Convert near canonical polynomial in one variable in a canonical polynomial
|
45129 | * with one term for each exponent in decreasing order
|
45130 | *
|
45131 | * Syntax:
|
45132 | *
|
45133 | * polyToCanonical(node [, coefficients])
|
45134 | *
|
45135 | * @param {Node | string} expr The near canonical polynomial expression to convert in a a canonical polynomial expression
|
45136 | *
|
45137 | * The string or tree expression needs to be at below syntax, with free spaces:
|
45138 | * ( (^(-)? | [+-]? )cte (*)? var (^expo)? | cte )+
|
45139 | * Where 'var' is one variable with any valid name
|
45140 | * 'cte' are real numeric constants with any value. It can be omitted if equal than 1
|
45141 | * 'expo' are integers greater than 0. It can be omitted if equal than 1.
|
45142 | *
|
45143 | * @param {array} coefficients Optional returns coefficients sorted by increased exponent
|
45144 | *
|
45145 | *
|
45146 | * @return {node} new node tree with one variable polynomial or string error.
|
45147 | */
|
45148 |
|
45149 |
|
45150 | function polyToCanonical(node, coefficients) {
|
45151 | if (coefficients === undefined) {
|
45152 | coefficients = [];
|
45153 | } // coefficients.
|
45154 |
|
45155 |
|
45156 | coefficients[0] = 0; // index is the exponent
|
45157 |
|
45158 | var o = {};
|
45159 | o.cte = 1;
|
45160 | o.oper = '+'; // fire: mark with * or ^ when finds * or ^ down tree, reset to "" with + and -.
|
45161 | // It is used to deduce the exponent: 1 for *, 0 for "".
|
45162 |
|
45163 | o.fire = '';
|
45164 | var maxExpo = 0; // maximum exponent
|
45165 |
|
45166 | var varname = ''; // variable name
|
45167 |
|
45168 | recurPol(node, null, o);
|
45169 | maxExpo = coefficients.length - 1;
|
45170 | var first = true;
|
45171 | var no;
|
45172 |
|
45173 | for (var i = maxExpo; i >= 0; i--) {
|
45174 | if (coefficients[i] === 0) continue;
|
45175 | var n1 = new ConstantNode(first ? coefficients[i] : Math.abs(coefficients[i]));
|
45176 | var op = coefficients[i] < 0 ? '-' : '+';
|
45177 |
|
45178 | if (i > 0) {
|
45179 | // Is not a constant without variable
|
45180 | var n2 = new SymbolNode(varname);
|
45181 |
|
45182 | if (i > 1) {
|
45183 | var n3 = new ConstantNode(i);
|
45184 | n2 = new OperatorNode('^', 'pow', [n2, n3]);
|
45185 | }
|
45186 |
|
45187 | if (coefficients[i] === -1 && first) {
|
45188 | n1 = new OperatorNode('-', 'unaryMinus', [n2]);
|
45189 | } else if (Math.abs(coefficients[i]) === 1) {
|
45190 | n1 = n2;
|
45191 | } else {
|
45192 | n1 = new OperatorNode('*', 'multiply', [n1, n2]);
|
45193 | }
|
45194 | }
|
45195 |
|
45196 | if (first) {
|
45197 | no = n1;
|
45198 | } else if (op === '+') {
|
45199 | no = new OperatorNode('+', 'add', [no, n1]);
|
45200 | } else {
|
45201 | no = new OperatorNode('-', 'subtract', [no, n1]);
|
45202 | }
|
45203 |
|
45204 | first = false;
|
45205 | } // for
|
45206 |
|
45207 |
|
45208 | if (first) {
|
45209 | return new ConstantNode(0);
|
45210 | } else {
|
45211 | return no;
|
45212 | }
|
45213 | /**
|
45214 | * Recursive auxilary function inside polyToCanonical for
|
45215 | * converting expression in canonical form
|
45216 | *
|
45217 | * Syntax:
|
45218 | *
|
45219 | * recurPol(node, noPai, obj)
|
45220 | *
|
45221 | * @param {Node} node The current subpolynomial expression
|
45222 | * @param {Node | Null} noPai The current parent node
|
45223 | * @param {object} obj Object with many internal flags
|
45224 | *
|
45225 | * @return {} No return. If error, throws an exception
|
45226 | */
|
45227 |
|
45228 |
|
45229 | function recurPol(node, noPai, o) {
|
45230 | var tp = node.type;
|
45231 |
|
45232 | if (tp === 'FunctionNode') {
|
45233 | // ***** FunctionName *****
|
45234 | // No function call in polynomial expression
|
45235 | throw new Error('There is an unsolved function call');
|
45236 | } else if (tp === 'OperatorNode') {
|
45237 | // ***** OperatorName *****
|
45238 | if ('+-*^'.indexOf(node.op) === -1) throw new Error('Operator ' + node.op + ' invalid');
|
45239 |
|
45240 | if (noPai !== null) {
|
45241 | // -(unary),^ : children of *,+,-
|
45242 | if ((node.fn === 'unaryMinus' || node.fn === 'pow') && noPai.fn !== 'add' && noPai.fn !== 'subtract' && noPai.fn !== 'multiply') {
|
45243 | throw new Error('Invalid ' + node.op + ' placing');
|
45244 | } // -,+,* : children of +,-
|
45245 |
|
45246 |
|
45247 | if ((node.fn === 'subtract' || node.fn === 'add' || node.fn === 'multiply') && noPai.fn !== 'add' && noPai.fn !== 'subtract') {
|
45248 | throw new Error('Invalid ' + node.op + ' placing');
|
45249 | } // -,+ : first child
|
45250 |
|
45251 |
|
45252 | if ((node.fn === 'subtract' || node.fn === 'add' || node.fn === 'unaryMinus') && o.noFil !== 0) {
|
45253 | throw new Error('Invalid ' + node.op + ' placing');
|
45254 | }
|
45255 | } // Has parent
|
45256 | // Firers: ^,* Old: ^,&,-(unary): firers
|
45257 |
|
45258 |
|
45259 | if (node.op === '^' || node.op === '*') {
|
45260 | o.fire = node.op;
|
45261 | }
|
45262 |
|
45263 | for (var _i = 0; _i < node.args.length; _i++) {
|
45264 | // +,-: reset fire
|
45265 | if (node.fn === 'unaryMinus') o.oper = '-';
|
45266 |
|
45267 | if (node.op === '+' || node.fn === 'subtract') {
|
45268 | o.fire = '';
|
45269 | o.cte = 1; // default if there is no constant
|
45270 |
|
45271 | o.oper = _i === 0 ? '+' : node.op;
|
45272 | }
|
45273 |
|
45274 | o.noFil = _i; // number of son
|
45275 |
|
45276 | recurPol(node.args[_i], node, o);
|
45277 | } // for in children
|
45278 |
|
45279 | } else if (tp === 'SymbolNode') {
|
45280 | // ***** SymbolName *****
|
45281 | if (node.name !== varname && varname !== '') {
|
45282 | throw new Error('There is more than one variable');
|
45283 | }
|
45284 |
|
45285 | varname = node.name;
|
45286 |
|
45287 | if (noPai === null) {
|
45288 | coefficients[1] = 1;
|
45289 | return;
|
45290 | } // ^: Symbol is First child
|
45291 |
|
45292 |
|
45293 | if (noPai.op === '^' && o.noFil !== 0) {
|
45294 | throw new Error('In power the variable should be the first parameter');
|
45295 | } // *: Symbol is Second child
|
45296 |
|
45297 |
|
45298 | if (noPai.op === '*' && o.noFil !== 1) {
|
45299 | throw new Error('In multiply the variable should be the second parameter');
|
45300 | } // Symbol: firers '',* => it means there is no exponent above, so it's 1 (cte * var)
|
45301 |
|
45302 |
|
45303 | if (o.fire === '' || o.fire === '*') {
|
45304 | if (maxExpo < 1) coefficients[1] = 0;
|
45305 | coefficients[1] += o.cte * (o.oper === '+' ? 1 : -1);
|
45306 | maxExpo = Math.max(1, maxExpo);
|
45307 | }
|
45308 | } else if (tp === 'ConstantNode') {
|
45309 | var valor = parseFloat(node.value);
|
45310 |
|
45311 | if (noPai === null) {
|
45312 | coefficients[0] = valor;
|
45313 | return;
|
45314 | }
|
45315 |
|
45316 | if (noPai.op === '^') {
|
45317 | // cte: second child of power
|
45318 | if (o.noFil !== 1) throw new Error('Constant cannot be powered');
|
45319 |
|
45320 | if (!number.isInteger(valor) || valor <= 0) {
|
45321 | throw new Error('Non-integer exponent is not allowed');
|
45322 | }
|
45323 |
|
45324 | for (var _i2 = maxExpo + 1; _i2 < valor; _i2++) {
|
45325 | coefficients[_i2] = 0;
|
45326 | }
|
45327 |
|
45328 | if (valor > maxExpo) coefficients[valor] = 0;
|
45329 | coefficients[valor] += o.cte * (o.oper === '+' ? 1 : -1);
|
45330 | maxExpo = Math.max(valor, maxExpo);
|
45331 | return;
|
45332 | }
|
45333 |
|
45334 | o.cte = valor; // Cte: firer '' => There is no exponent and no multiplication, so the exponent is 0.
|
45335 |
|
45336 | if (o.fire === '') {
|
45337 | coefficients[0] += o.cte * (o.oper === '+' ? 1 : -1);
|
45338 | }
|
45339 | } else {
|
45340 | throw new Error('Type ' + tp + ' is not allowed');
|
45341 | }
|
45342 | } // End of recurPol
|
45343 |
|
45344 | } // End of polyToCanonical
|
45345 |
|
45346 |
|
45347 | return rationalize;
|
45348 | } // end of factory
|
45349 |
|
45350 |
|
45351 | exports.name = 'rationalize';
|
45352 | exports.factory = factory;
|
45353 |
|
45354 | /***/ }),
|
45355 | /* 208 */
|
45356 | /***/ (function(module, exports, __webpack_require__) {
|
45357 |
|
45358 | "use strict";
|
45359 |
|
45360 |
|
45361 | function factory(type, config, load, typed) {
|
45362 | var matrix = load(__webpack_require__(0));
|
45363 | var zeros = load(__webpack_require__(43));
|
45364 | var identity = load(__webpack_require__(50));
|
45365 | var isZero = load(__webpack_require__(60));
|
45366 | var unequal = load(__webpack_require__(130));
|
45367 | var sign = load(__webpack_require__(131));
|
45368 | var sqrt = load(__webpack_require__(46));
|
45369 | var conj = load(__webpack_require__(71));
|
45370 | var unaryMinus = load(__webpack_require__(39));
|
45371 | var addScalar = load(__webpack_require__(17));
|
45372 | var divideScalar = load(__webpack_require__(12));
|
45373 | var multiplyScalar = load(__webpack_require__(21));
|
45374 | var subtract = load(__webpack_require__(15));
|
45375 | /**
|
45376 | * Calculate the Matrix QR decomposition. Matrix `A` is decomposed in
|
45377 | * two matrices (`Q`, `R`) where `Q` is an
|
45378 | * orthogonal matrix and `R` is an upper triangular matrix.
|
45379 | *
|
45380 | * Syntax:
|
45381 | *
|
45382 | * math.qr(A)
|
45383 | *
|
45384 | * Example:
|
45385 | *
|
45386 | * const m = [
|
45387 | * [1, -1, 4],
|
45388 | * [1, 4, -2],
|
45389 | * [1, 4, 2],
|
45390 | * [1, -1, 0]
|
45391 | * ]
|
45392 | * const result = math.qr(m)
|
45393 | * // r = {
|
45394 | * // Q: [
|
45395 | * // [0.5, -0.5, 0.5],
|
45396 | * // [0.5, 0.5, -0.5],
|
45397 | * // [0.5, 0.5, 0.5],
|
45398 | * // [0.5, -0.5, -0.5],
|
45399 | * // ],
|
45400 | * // R: [
|
45401 | * // [2, 3, 2],
|
45402 | * // [0, 5, -2],
|
45403 | * // [0, 0, 4],
|
45404 | * // [0, 0, 0]
|
45405 | * // ]
|
45406 | * // }
|
45407 | *
|
45408 | * See also:
|
45409 | *
|
45410 | * lup, lusolve
|
45411 | *
|
45412 | * @param {Matrix | Array} A A two dimensional matrix or array
|
45413 | * for which to get the QR decomposition.
|
45414 | *
|
45415 | * @return {{Q: Array | Matrix, R: Array | Matrix}} Q: the orthogonal
|
45416 | * matrix and R: the upper triangular matrix
|
45417 | */
|
45418 |
|
45419 | var qr = typed('qr', {
|
45420 | 'DenseMatrix': function DenseMatrix(m) {
|
45421 | return _denseQR(m);
|
45422 | },
|
45423 | 'SparseMatrix': function SparseMatrix(m) {
|
45424 | return _sparseQR(m);
|
45425 | },
|
45426 | 'Array': function Array(a) {
|
45427 | // create dense matrix from array
|
45428 | var m = matrix(a); // lup, use matrix implementation
|
45429 |
|
45430 | var r = _denseQR(m); // result
|
45431 |
|
45432 |
|
45433 | return {
|
45434 | Q: r.Q.valueOf(),
|
45435 | R: r.R.valueOf()
|
45436 | };
|
45437 | }
|
45438 | });
|
45439 |
|
45440 | function _denseQR(m) {
|
45441 | // rows & columns (m x n)
|
45442 | var rows = m._size[0]; // m
|
45443 |
|
45444 | var cols = m._size[1]; // n
|
45445 |
|
45446 | var Q = identity([rows], 'dense');
|
45447 | var Qdata = Q._data;
|
45448 | var R = m.clone();
|
45449 | var Rdata = R._data; // vars
|
45450 |
|
45451 | var i, j, k;
|
45452 | var w = zeros([rows], '');
|
45453 |
|
45454 | for (k = 0; k < Math.min(cols, rows); ++k) {
|
45455 | /*
|
45456 | * **k-th Household matrix**
|
45457 | *
|
45458 | * The matrix I - 2*v*transpose(v)
|
45459 | * x = first column of A
|
45460 | * x1 = first element of x
|
45461 | * alpha = x1 / |x1| * |x|
|
45462 | * e1 = tranpose([1, 0, 0, ...])
|
45463 | * u = x - alpha * e1
|
45464 | * v = u / |u|
|
45465 | *
|
45466 | * Household matrix = I - 2 * v * tranpose(v)
|
45467 | *
|
45468 | * * Initially Q = I and R = A.
|
45469 | * * Household matrix is a reflection in a plane normal to v which
|
45470 | * will zero out all but the top right element in R.
|
45471 | * * Appplying reflection to both Q and R will not change product.
|
45472 | * * Repeat this process on the (1,1) minor to get R as an upper
|
45473 | * triangular matrix.
|
45474 | * * Reflections leave the magnitude of the columns of Q unchanged
|
45475 | * so Q remains othoganal.
|
45476 | *
|
45477 | */
|
45478 | var pivot = Rdata[k][k];
|
45479 | var sgn = unaryMinus(sign(pivot));
|
45480 | var conjSgn = conj(sgn);
|
45481 | var alphaSquared = 0;
|
45482 |
|
45483 | for (i = k; i < rows; i++) {
|
45484 | alphaSquared = addScalar(alphaSquared, multiplyScalar(Rdata[i][k], conj(Rdata[i][k])));
|
45485 | }
|
45486 |
|
45487 | var alpha = multiplyScalar(sgn, sqrt(alphaSquared));
|
45488 |
|
45489 | if (!isZero(alpha)) {
|
45490 | // first element in vector u
|
45491 | var u1 = subtract(pivot, alpha); // w = v * u1 / |u| (only elements k to (rows-1) are used)
|
45492 |
|
45493 | w[k] = 1;
|
45494 |
|
45495 | for (i = k + 1; i < rows; i++) {
|
45496 | w[i] = divideScalar(Rdata[i][k], u1);
|
45497 | } // tau = - conj(u1 / alpha)
|
45498 |
|
45499 |
|
45500 | var tau = unaryMinus(conj(divideScalar(u1, alpha)));
|
45501 | var s = void 0;
|
45502 | /*
|
45503 | * tau and w have been choosen so that
|
45504 | *
|
45505 | * 2 * v * tranpose(v) = tau * w * tranpose(w)
|
45506 | */
|
45507 |
|
45508 | /*
|
45509 | * -- calculate R = R - tau * w * tranpose(w) * R --
|
45510 | * Only do calculation with rows k to (rows-1)
|
45511 | * Additionally columns 0 to (k-1) will not be changed by this
|
45512 | * multiplication so do not bother recalculating them
|
45513 | */
|
45514 |
|
45515 | for (j = k; j < cols; j++) {
|
45516 | s = 0.0; // calculate jth element of [tranpose(w) * R]
|
45517 |
|
45518 | for (i = k; i < rows; i++) {
|
45519 | s = addScalar(s, multiplyScalar(conj(w[i]), Rdata[i][j]));
|
45520 | } // calculate the jth element of [tau * transpose(w) * R]
|
45521 |
|
45522 |
|
45523 | s = multiplyScalar(s, tau);
|
45524 |
|
45525 | for (i = k; i < rows; i++) {
|
45526 | Rdata[i][j] = multiplyScalar(subtract(Rdata[i][j], multiplyScalar(w[i], s)), conjSgn);
|
45527 | }
|
45528 | }
|
45529 | /*
|
45530 | * -- calculate Q = Q - tau * Q * w * transpose(w) --
|
45531 | * Q is a square matrix (rows x rows)
|
45532 | * Only do calculation with columns k to (rows-1)
|
45533 | * Additionally rows 0 to (k-1) will not be changed by this
|
45534 | * multiplication so do not bother recalculating them
|
45535 | */
|
45536 |
|
45537 |
|
45538 | for (i = 0; i < rows; i++) {
|
45539 | s = 0.0; // calculate ith element of [Q * w]
|
45540 |
|
45541 | for (j = k; j < rows; j++) {
|
45542 | s = addScalar(s, multiplyScalar(Qdata[i][j], w[j]));
|
45543 | } // calculate the ith element of [tau * Q * w]
|
45544 |
|
45545 |
|
45546 | s = multiplyScalar(s, tau);
|
45547 |
|
45548 | for (j = k; j < rows; ++j) {
|
45549 | Qdata[i][j] = divideScalar(subtract(Qdata[i][j], multiplyScalar(s, conj(w[j]))), conjSgn);
|
45550 | }
|
45551 | }
|
45552 | }
|
45553 | } // coerse almost zero elements to zero
|
45554 | // TODO I feel uneasy just zeroing these values
|
45555 |
|
45556 |
|
45557 | for (i = 0; i < rows; ++i) {
|
45558 | for (j = 0; j < i && j < cols; ++j) {
|
45559 | if (unequal(0, divideScalar(Rdata[i][j], 1e5))) {
|
45560 | throw new Error('math.qr(): unknown error - ' + 'R is not lower triangular (element (' + i + ', ' + j + ') = ' + Rdata[i][j] + ')');
|
45561 | }
|
45562 |
|
45563 | Rdata[i][j] = multiplyScalar(Rdata[i][j], 0);
|
45564 | }
|
45565 | } // return matrices
|
45566 |
|
45567 |
|
45568 | return {
|
45569 | Q: Q,
|
45570 | R: R,
|
45571 | toString: function toString() {
|
45572 | return 'Q: ' + this.Q.toString() + '\nR: ' + this.R.toString();
|
45573 | }
|
45574 | };
|
45575 | }
|
45576 |
|
45577 | function _sparseQR(m) {
|
45578 | throw new Error('qr not implemented for sparse matrices yet');
|
45579 | }
|
45580 |
|
45581 | return qr;
|
45582 | }
|
45583 |
|
45584 | exports.name = 'qr';
|
45585 | exports.factory = factory;
|
45586 |
|
45587 | /***/ }),
|
45588 | /* 209 */
|
45589 | /***/ (function(module, exports, __webpack_require__) {
|
45590 |
|
45591 | "use strict";
|
45592 |
|
45593 |
|
45594 | function factory(type, config, load) {
|
45595 | var csAmd = load(__webpack_require__(210));
|
45596 | var csPermute = load(__webpack_require__(212));
|
45597 | var csEtree = load(__webpack_require__(213));
|
45598 | var csPost = load(__webpack_require__(214));
|
45599 | var csCounts = load(__webpack_require__(215));
|
45600 | /**
|
45601 | * Symbolic ordering and analysis for QR and LU decompositions.
|
45602 | *
|
45603 | * @param {Number} order The ordering strategy (see csAmd for more details)
|
45604 | * @param {Matrix} a The A matrix
|
45605 | * @param {boolean} qr Symbolic ordering and analysis for QR decomposition (true) or
|
45606 | * symbolic ordering and analysis for LU decomposition (false)
|
45607 | *
|
45608 | * @return {Object} The Symbolic ordering and analysis for matrix A
|
45609 | *
|
45610 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
45611 | */
|
45612 |
|
45613 | var csSqr = function csSqr(order, a, qr) {
|
45614 | // a arrays
|
45615 | var aptr = a._ptr;
|
45616 | var asize = a._size; // columns
|
45617 |
|
45618 | var n = asize[1]; // vars
|
45619 |
|
45620 | var k; // symbolic analysis result
|
45621 |
|
45622 | var s = {}; // fill-reducing ordering
|
45623 |
|
45624 | s.q = csAmd(order, a); // validate results
|
45625 |
|
45626 | if (order && !s.q) {
|
45627 | return null;
|
45628 | } // QR symbolic analysis
|
45629 |
|
45630 |
|
45631 | if (qr) {
|
45632 | // apply permutations if needed
|
45633 | var c = order ? csPermute(a, null, s.q, 0) : a; // etree of C'*C, where C=A(:,q)
|
45634 |
|
45635 | s.parent = csEtree(c, 1); // post order elimination tree
|
45636 |
|
45637 | var post = csPost(s.parent, n); // col counts chol(C'*C)
|
45638 |
|
45639 | s.cp = csCounts(c, s.parent, post, 1); // check we have everything needed to calculate number of nonzero elements
|
45640 |
|
45641 | if (c && s.parent && s.cp && _vcount(c, s)) {
|
45642 | // calculate number of nonzero elements
|
45643 | for (s.unz = 0, k = 0; k < n; k++) {
|
45644 | s.unz += s.cp[k];
|
45645 | }
|
45646 | }
|
45647 | } else {
|
45648 | // for LU factorization only, guess nnz(L) and nnz(U)
|
45649 | s.unz = 4 * aptr[n] + n;
|
45650 | s.lnz = s.unz;
|
45651 | } // return result S
|
45652 |
|
45653 |
|
45654 | return s;
|
45655 | };
|
45656 | /**
|
45657 | * Compute nnz(V) = s.lnz, s.pinv, s.leftmost, s.m2 from A and s.parent
|
45658 | */
|
45659 |
|
45660 |
|
45661 | function _vcount(a, s) {
|
45662 | // a arrays
|
45663 | var aptr = a._ptr;
|
45664 | var aindex = a._index;
|
45665 | var asize = a._size; // rows & columns
|
45666 |
|
45667 | var m = asize[0];
|
45668 | var n = asize[1]; // initialize s arrays
|
45669 |
|
45670 | s.pinv = []; // (m + n)
|
45671 |
|
45672 | s.leftmost = []; // (m)
|
45673 | // vars
|
45674 |
|
45675 | var parent = s.parent;
|
45676 | var pinv = s.pinv;
|
45677 | var leftmost = s.leftmost; // workspace, next: first m entries, head: next n entries, tail: next n entries, nque: next n entries
|
45678 |
|
45679 | var w = []; // (m + 3 * n)
|
45680 |
|
45681 | var next = 0;
|
45682 | var head = m;
|
45683 | var tail = m + n;
|
45684 | var nque = m + 2 * n; // vars
|
45685 |
|
45686 | var i, k, p, p0, p1; // initialize w
|
45687 |
|
45688 | for (k = 0; k < n; k++) {
|
45689 | // queue k is empty
|
45690 | w[head + k] = -1;
|
45691 | w[tail + k] = -1;
|
45692 | w[nque + k] = 0;
|
45693 | } // initialize row arrays
|
45694 |
|
45695 |
|
45696 | for (i = 0; i < m; i++) {
|
45697 | leftmost[i] = -1;
|
45698 | } // loop columns backwards
|
45699 |
|
45700 |
|
45701 | for (k = n - 1; k >= 0; k--) {
|
45702 | // values & index for column k
|
45703 | for (p0 = aptr[k], p1 = aptr[k + 1], p = p0; p < p1; p++) {
|
45704 | // leftmost[i] = min(find(A(i,:)))
|
45705 | leftmost[aindex[p]] = k;
|
45706 | }
|
45707 | } // scan rows in reverse order
|
45708 |
|
45709 |
|
45710 | for (i = m - 1; i >= 0; i--) {
|
45711 | // row i is not yet ordered
|
45712 | pinv[i] = -1;
|
45713 | k = leftmost[i]; // check row i is empty
|
45714 |
|
45715 | if (k === -1) {
|
45716 | continue;
|
45717 | } // first row in queue k
|
45718 |
|
45719 |
|
45720 | if (w[nque + k]++ === 0) {
|
45721 | w[tail + k] = i;
|
45722 | } // put i at head of queue k
|
45723 |
|
45724 |
|
45725 | w[next + i] = w[head + k];
|
45726 | w[head + k] = i;
|
45727 | }
|
45728 |
|
45729 | s.lnz = 0;
|
45730 | s.m2 = m; // find row permutation and nnz(V)
|
45731 |
|
45732 | for (k = 0; k < n; k++) {
|
45733 | // remove row i from queue k
|
45734 | i = w[head + k]; // count V(k,k) as nonzero
|
45735 |
|
45736 | s.lnz++; // add a fictitious row
|
45737 |
|
45738 | if (i < 0) {
|
45739 | i = s.m2++;
|
45740 | } // associate row i with V(:,k)
|
45741 |
|
45742 |
|
45743 | pinv[i] = k; // skip if V(k+1:m,k) is empty
|
45744 |
|
45745 | if (--nque[k] <= 0) {
|
45746 | continue;
|
45747 | } // nque[k] is nnz (V(k+1:m,k))
|
45748 |
|
45749 |
|
45750 | s.lnz += w[nque + k]; // move all rows to parent of k
|
45751 |
|
45752 | var pa = parent[k];
|
45753 |
|
45754 | if (pa !== -1) {
|
45755 | if (w[nque + pa] === 0) {
|
45756 | w[tail + pa] = w[tail + k];
|
45757 | }
|
45758 |
|
45759 | w[next + w[tail + k]] = w[head + pa];
|
45760 | w[head + pa] = w[next + i];
|
45761 | w[nque + pa] += w[nque + k];
|
45762 | }
|
45763 | }
|
45764 |
|
45765 | for (i = 0; i < m; i++) {
|
45766 | if (pinv[i] < 0) {
|
45767 | pinv[i] = k++;
|
45768 | }
|
45769 | }
|
45770 |
|
45771 | return true;
|
45772 | }
|
45773 |
|
45774 | return csSqr;
|
45775 | }
|
45776 |
|
45777 | exports.name = 'csSqr';
|
45778 | exports.path = 'algebra.sparse';
|
45779 | exports.factory = factory;
|
45780 |
|
45781 | /***/ }),
|
45782 | /* 210 */
|
45783 | /***/ (function(module, exports, __webpack_require__) {
|
45784 |
|
45785 | "use strict";
|
45786 |
|
45787 |
|
45788 | function factory(type, config, load) {
|
45789 | var csFlip = load(__webpack_require__(88));
|
45790 | var csFkeep = load(__webpack_require__(211));
|
45791 | var csTdfs = load(__webpack_require__(133));
|
45792 | var add = load(__webpack_require__(14));
|
45793 | var multiply = load(__webpack_require__(10));
|
45794 | var transpose = load(__webpack_require__(72));
|
45795 | /**
|
45796 | * Approximate minimum degree ordering. The minimum degree algorithm is a widely used
|
45797 | * heuristic for finding a permutation P so that P*A*P' has fewer nonzeros in its factorization
|
45798 | * than A. It is a gready method that selects the sparsest pivot row and column during the course
|
45799 | * of a right looking sparse Cholesky factorization.
|
45800 | *
|
45801 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
45802 | *
|
45803 | * @param {Number} order 0: Natural, 1: Cholesky, 2: LU, 3: QR
|
45804 | * @param {Matrix} m Sparse Matrix
|
45805 | */
|
45806 |
|
45807 | var csAmd = function csAmd(order, a) {
|
45808 | // check input parameters
|
45809 | if (!a || order <= 0 || order > 3) {
|
45810 | return null;
|
45811 | } // a matrix arrays
|
45812 |
|
45813 |
|
45814 | var asize = a._size; // rows and columns
|
45815 |
|
45816 | var m = asize[0];
|
45817 | var n = asize[1]; // initialize vars
|
45818 |
|
45819 | var lemax = 0; // dense threshold
|
45820 |
|
45821 | var dense = Math.max(16, 10 * Math.sqrt(n));
|
45822 | dense = Math.min(n - 2, dense); // create target matrix C
|
45823 |
|
45824 | var cm = _createTargetMatrix(order, a, m, n, dense); // drop diagonal entries
|
45825 |
|
45826 |
|
45827 | csFkeep(cm, _diag, null); // C matrix arrays
|
45828 |
|
45829 | var cindex = cm._index;
|
45830 | var cptr = cm._ptr; // number of nonzero elements in C
|
45831 |
|
45832 | var cnz = cptr[n]; // allocate result (n+1)
|
45833 |
|
45834 | var P = []; // create workspace (8 * (n + 1))
|
45835 |
|
45836 | var W = [];
|
45837 | var len = 0; // first n + 1 entries
|
45838 |
|
45839 | var nv = n + 1; // next n + 1 entries
|
45840 |
|
45841 | var next = 2 * (n + 1); // next n + 1 entries
|
45842 |
|
45843 | var head = 3 * (n + 1); // next n + 1 entries
|
45844 |
|
45845 | var elen = 4 * (n + 1); // next n + 1 entries
|
45846 |
|
45847 | var degree = 5 * (n + 1); // next n + 1 entries
|
45848 |
|
45849 | var w = 6 * (n + 1); // next n + 1 entries
|
45850 |
|
45851 | var hhead = 7 * (n + 1); // last n + 1 entries
|
45852 | // use P as workspace for last
|
45853 |
|
45854 | var last = P; // initialize quotient graph
|
45855 |
|
45856 | var mark = _initializeQuotientGraph(n, cptr, W, len, head, last, next, hhead, nv, w, elen, degree); // initialize degree lists
|
45857 |
|
45858 |
|
45859 | var nel = _initializeDegreeLists(n, cptr, W, degree, elen, w, dense, nv, head, last, next); // minimum degree node
|
45860 |
|
45861 |
|
45862 | var mindeg = 0; // vars
|
45863 |
|
45864 | var i, j, k, k1, k2, e, pj, ln, nvi, pk, eln, p1, p2, pn, h, d; // while (selecting pivots) do
|
45865 |
|
45866 | while (nel < n) {
|
45867 | // select node of minimum approximate degree. amd() is now ready to start eliminating the graph. It first
|
45868 | // finds a node k of minimum degree and removes it from its degree list. The variable nel keeps track of thow
|
45869 | // many nodes have been eliminated.
|
45870 | for (k = -1; mindeg < n && (k = W[head + mindeg]) === -1; mindeg++) {
|
45871 | ;
|
45872 | }
|
45873 |
|
45874 | if (W[next + k] !== -1) {
|
45875 | last[W[next + k]] = -1;
|
45876 | } // remove k from degree list
|
45877 |
|
45878 |
|
45879 | W[head + mindeg] = W[next + k]; // elenk = |Ek|
|
45880 |
|
45881 | var elenk = W[elen + k]; // # of nodes k represents
|
45882 |
|
45883 | var nvk = W[nv + k]; // W[nv + k] nodes of A eliminated
|
45884 |
|
45885 | nel += nvk; // Construct a new element. The new element Lk is constructed in place if |Ek| = 0. nv[i] is
|
45886 | // negated for all nodes i in Lk to flag them as members of this set. Each node i is removed from the
|
45887 | // degree lists. All elements e in Ek are absorved into element k.
|
45888 |
|
45889 | var dk = 0; // flag k as in Lk
|
45890 |
|
45891 | W[nv + k] = -nvk;
|
45892 | var p = cptr[k]; // do in place if W[elen + k] === 0
|
45893 |
|
45894 | var pk1 = elenk === 0 ? p : cnz;
|
45895 | var pk2 = pk1;
|
45896 |
|
45897 | for (k1 = 1; k1 <= elenk + 1; k1++) {
|
45898 | if (k1 > elenk) {
|
45899 | // search the nodes in k
|
45900 | e = k; // list of nodes starts at cindex[pj]
|
45901 |
|
45902 | pj = p; // length of list of nodes in k
|
45903 |
|
45904 | ln = W[len + k] - elenk;
|
45905 | } else {
|
45906 | // search the nodes in e
|
45907 | e = cindex[p++];
|
45908 | pj = cptr[e]; // length of list of nodes in e
|
45909 |
|
45910 | ln = W[len + e];
|
45911 | }
|
45912 |
|
45913 | for (k2 = 1; k2 <= ln; k2++) {
|
45914 | i = cindex[pj++]; // check node i dead, or seen
|
45915 |
|
45916 | if ((nvi = W[nv + i]) <= 0) {
|
45917 | continue;
|
45918 | } // W[degree + Lk] += size of node i
|
45919 |
|
45920 |
|
45921 | dk += nvi; // negate W[nv + i] to denote i in Lk
|
45922 |
|
45923 | W[nv + i] = -nvi; // place i in Lk
|
45924 |
|
45925 | cindex[pk2++] = i;
|
45926 |
|
45927 | if (W[next + i] !== -1) {
|
45928 | last[W[next + i]] = last[i];
|
45929 | } // check we need to remove i from degree list
|
45930 |
|
45931 |
|
45932 | if (last[i] !== -1) {
|
45933 | W[next + last[i]] = W[next + i];
|
45934 | } else {
|
45935 | W[head + W[degree + i]] = W[next + i];
|
45936 | }
|
45937 | }
|
45938 |
|
45939 | if (e !== k) {
|
45940 | // absorb e into k
|
45941 | cptr[e] = csFlip(k); // e is now a dead element
|
45942 |
|
45943 | W[w + e] = 0;
|
45944 | }
|
45945 | } // cindex[cnz...nzmax] is free
|
45946 |
|
45947 |
|
45948 | if (elenk !== 0) {
|
45949 | cnz = pk2;
|
45950 | } // external degree of k - |Lk\i|
|
45951 |
|
45952 |
|
45953 | W[degree + k] = dk; // element k is in cindex[pk1..pk2-1]
|
45954 |
|
45955 | cptr[k] = pk1;
|
45956 | W[len + k] = pk2 - pk1; // k is now an element
|
45957 |
|
45958 | W[elen + k] = -2; // Find set differences. The scan1 function now computes the set differences |Le \ Lk| for all elements e. At the start of the
|
45959 | // scan, no entry in the w array is greater than or equal to mark.
|
45960 | // clear w if necessary
|
45961 |
|
45962 | mark = _wclear(mark, lemax, W, w, n); // scan 1: find |Le\Lk|
|
45963 |
|
45964 | for (pk = pk1; pk < pk2; pk++) {
|
45965 | i = cindex[pk]; // check if W[elen + i] empty, skip it
|
45966 |
|
45967 | if ((eln = W[elen + i]) <= 0) {
|
45968 | continue;
|
45969 | } // W[nv + i] was negated
|
45970 |
|
45971 |
|
45972 | nvi = -W[nv + i];
|
45973 | var wnvi = mark - nvi; // scan Ei
|
45974 |
|
45975 | for (p = cptr[i], p1 = cptr[i] + eln - 1; p <= p1; p++) {
|
45976 | e = cindex[p];
|
45977 |
|
45978 | if (W[w + e] >= mark) {
|
45979 | // decrement |Le\Lk|
|
45980 | W[w + e] -= nvi;
|
45981 | } else if (W[w + e] !== 0) {
|
45982 | // ensure e is a live element, 1st time e seen in scan 1
|
45983 | W[w + e] = W[degree + e] + wnvi;
|
45984 | }
|
45985 | }
|
45986 | } // degree update
|
45987 | // The second pass computes the approximate degree di, prunes the sets Ei and Ai, and computes a hash
|
45988 | // function h(i) for all nodes in Lk.
|
45989 | // scan2: degree update
|
45990 |
|
45991 |
|
45992 | for (pk = pk1; pk < pk2; pk++) {
|
45993 | // consider node i in Lk
|
45994 | i = cindex[pk];
|
45995 | p1 = cptr[i];
|
45996 | p2 = p1 + W[elen + i] - 1;
|
45997 | pn = p1; // scan Ei
|
45998 |
|
45999 | for (h = 0, d = 0, p = p1; p <= p2; p++) {
|
46000 | e = cindex[p]; // check e is an unabsorbed element
|
46001 |
|
46002 | if (W[w + e] !== 0) {
|
46003 | // dext = |Le\Lk|
|
46004 | var dext = W[w + e] - mark;
|
46005 |
|
46006 | if (dext > 0) {
|
46007 | // sum up the set differences
|
46008 | d += dext; // keep e in Ei
|
46009 |
|
46010 | cindex[pn++] = e; // compute the hash of node i
|
46011 |
|
46012 | h += e;
|
46013 | } else {
|
46014 | // aggressive absorb. e->k
|
46015 | cptr[e] = csFlip(k); // e is a dead element
|
46016 |
|
46017 | W[w + e] = 0;
|
46018 | }
|
46019 | }
|
46020 | } // W[elen + i] = |Ei|
|
46021 |
|
46022 |
|
46023 | W[elen + i] = pn - p1 + 1;
|
46024 | var p3 = pn;
|
46025 | var p4 = p1 + W[len + i]; // prune edges in Ai
|
46026 |
|
46027 | for (p = p2 + 1; p < p4; p++) {
|
46028 | j = cindex[p]; // check node j dead or in Lk
|
46029 |
|
46030 | var nvj = W[nv + j];
|
46031 |
|
46032 | if (nvj <= 0) {
|
46033 | continue;
|
46034 | } // degree(i) += |j|
|
46035 |
|
46036 |
|
46037 | d += nvj; // place j in node list of i
|
46038 |
|
46039 | cindex[pn++] = j; // compute hash for node i
|
46040 |
|
46041 | h += j;
|
46042 | } // check for mass elimination
|
46043 |
|
46044 |
|
46045 | if (d === 0) {
|
46046 | // absorb i into k
|
46047 | cptr[i] = csFlip(k);
|
46048 | nvi = -W[nv + i]; // |Lk| -= |i|
|
46049 |
|
46050 | dk -= nvi; // |k| += W[nv + i]
|
46051 |
|
46052 | nvk += nvi;
|
46053 | nel += nvi;
|
46054 | W[nv + i] = 0; // node i is dead
|
46055 |
|
46056 | W[elen + i] = -1;
|
46057 | } else {
|
46058 | // update degree(i)
|
46059 | W[degree + i] = Math.min(W[degree + i], d); // move first node to end
|
46060 |
|
46061 | cindex[pn] = cindex[p3]; // move 1st el. to end of Ei
|
46062 |
|
46063 | cindex[p3] = cindex[p1]; // add k as 1st element in of Ei
|
46064 |
|
46065 | cindex[p1] = k; // new len of adj. list of node i
|
46066 |
|
46067 | W[len + i] = pn - p1 + 1; // finalize hash of i
|
46068 |
|
46069 | h = (h < 0 ? -h : h) % n; // place i in hash bucket
|
46070 |
|
46071 | W[next + i] = W[hhead + h];
|
46072 | W[hhead + h] = i; // save hash of i in last[i]
|
46073 |
|
46074 | last[i] = h;
|
46075 | }
|
46076 | } // finalize |Lk|
|
46077 |
|
46078 |
|
46079 | W[degree + k] = dk;
|
46080 | lemax = Math.max(lemax, dk); // clear w
|
46081 |
|
46082 | mark = _wclear(mark + lemax, lemax, W, w, n); // Supernode detection. Supernode detection relies on the hash function h(i) computed for each node i.
|
46083 | // If two nodes have identical adjacency lists, their hash functions wil be identical.
|
46084 |
|
46085 | for (pk = pk1; pk < pk2; pk++) {
|
46086 | i = cindex[pk]; // check i is dead, skip it
|
46087 |
|
46088 | if (W[nv + i] >= 0) {
|
46089 | continue;
|
46090 | } // scan hash bucket of node i
|
46091 |
|
46092 |
|
46093 | h = last[i];
|
46094 | i = W[hhead + h]; // hash bucket will be empty
|
46095 |
|
46096 | W[hhead + h] = -1;
|
46097 |
|
46098 | for (; i !== -1 && W[next + i] !== -1; i = W[next + i], mark++) {
|
46099 | ln = W[len + i];
|
46100 | eln = W[elen + i];
|
46101 |
|
46102 | for (p = cptr[i] + 1; p <= cptr[i] + ln - 1; p++) {
|
46103 | W[w + cindex[p]] = mark;
|
46104 | }
|
46105 |
|
46106 | var jlast = i; // compare i with all j
|
46107 |
|
46108 | for (j = W[next + i]; j !== -1;) {
|
46109 | var ok = W[len + j] === ln && W[elen + j] === eln;
|
46110 |
|
46111 | for (p = cptr[j] + 1; ok && p <= cptr[j] + ln - 1; p++) {
|
46112 | // compare i and j
|
46113 | if (W[w + cindex[p]] !== mark) {
|
46114 | ok = 0;
|
46115 | }
|
46116 | } // check i and j are identical
|
46117 |
|
46118 |
|
46119 | if (ok) {
|
46120 | // absorb j into i
|
46121 | cptr[j] = csFlip(i);
|
46122 | W[nv + i] += W[nv + j];
|
46123 | W[nv + j] = 0; // node j is dead
|
46124 |
|
46125 | W[elen + j] = -1; // delete j from hash bucket
|
46126 |
|
46127 | j = W[next + j];
|
46128 | W[next + jlast] = j;
|
46129 | } else {
|
46130 | // j and i are different
|
46131 | jlast = j;
|
46132 | j = W[next + j];
|
46133 | }
|
46134 | }
|
46135 | }
|
46136 | } // Finalize new element. The elimination of node k is nearly complete. All nodes i in Lk are scanned one last time.
|
46137 | // Node i is removed from Lk if it is dead. The flagged status of nv[i] is cleared.
|
46138 |
|
46139 |
|
46140 | for (p = pk1, pk = pk1; pk < pk2; pk++) {
|
46141 | i = cindex[pk]; // check i is dead, skip it
|
46142 |
|
46143 | if ((nvi = -W[nv + i]) <= 0) {
|
46144 | continue;
|
46145 | } // restore W[nv + i]
|
46146 |
|
46147 |
|
46148 | W[nv + i] = nvi; // compute external degree(i)
|
46149 |
|
46150 | d = W[degree + i] + dk - nvi;
|
46151 | d = Math.min(d, n - nel - nvi);
|
46152 |
|
46153 | if (W[head + d] !== -1) {
|
46154 | last[W[head + d]] = i;
|
46155 | } // put i back in degree list
|
46156 |
|
46157 |
|
46158 | W[next + i] = W[head + d];
|
46159 | last[i] = -1;
|
46160 | W[head + d] = i; // find new minimum degree
|
46161 |
|
46162 | mindeg = Math.min(mindeg, d);
|
46163 | W[degree + i] = d; // place i in Lk
|
46164 |
|
46165 | cindex[p++] = i;
|
46166 | } // # nodes absorbed into k
|
46167 |
|
46168 |
|
46169 | W[nv + k] = nvk; // length of adj list of element k
|
46170 |
|
46171 | if ((W[len + k] = p - pk1) === 0) {
|
46172 | // k is a root of the tree
|
46173 | cptr[k] = -1; // k is now a dead element
|
46174 |
|
46175 | W[w + k] = 0;
|
46176 | }
|
46177 |
|
46178 | if (elenk !== 0) {
|
46179 | // free unused space in Lk
|
46180 | cnz = p;
|
46181 | }
|
46182 | } // Postordering. The elimination is complete, but no permutation has been computed. All that is left
|
46183 | // of the graph is the assembly tree (ptr) and a set of dead nodes and elements (i is a dead node if
|
46184 | // nv[i] is zero and a dead element if nv[i] > 0). It is from this information only that the final permutation
|
46185 | // is computed. The tree is restored by unflipping all of ptr.
|
46186 | // fix assembly tree
|
46187 |
|
46188 |
|
46189 | for (i = 0; i < n; i++) {
|
46190 | cptr[i] = csFlip(cptr[i]);
|
46191 | }
|
46192 |
|
46193 | for (j = 0; j <= n; j++) {
|
46194 | W[head + j] = -1;
|
46195 | } // place unordered nodes in lists
|
46196 |
|
46197 |
|
46198 | for (j = n; j >= 0; j--) {
|
46199 | // skip if j is an element
|
46200 | if (W[nv + j] > 0) {
|
46201 | continue;
|
46202 | } // place j in list of its parent
|
46203 |
|
46204 |
|
46205 | W[next + j] = W[head + cptr[j]];
|
46206 | W[head + cptr[j]] = j;
|
46207 | } // place elements in lists
|
46208 |
|
46209 |
|
46210 | for (e = n; e >= 0; e--) {
|
46211 | // skip unless e is an element
|
46212 | if (W[nv + e] <= 0) {
|
46213 | continue;
|
46214 | }
|
46215 |
|
46216 | if (cptr[e] !== -1) {
|
46217 | // place e in list of its parent
|
46218 | W[next + e] = W[head + cptr[e]];
|
46219 | W[head + cptr[e]] = e;
|
46220 | }
|
46221 | } // postorder the assembly tree
|
46222 |
|
46223 |
|
46224 | for (k = 0, i = 0; i <= n; i++) {
|
46225 | if (cptr[i] === -1) {
|
46226 | k = csTdfs(i, k, W, head, next, P, w);
|
46227 | }
|
46228 | } // remove last item in array
|
46229 |
|
46230 |
|
46231 | P.splice(P.length - 1, 1); // return P
|
46232 |
|
46233 | return P;
|
46234 | };
|
46235 | /**
|
46236 | * Creates the matrix that will be used by the approximate minimum degree ordering algorithm. The function accepts the matrix M as input and returns a permutation
|
46237 | * vector P. The amd algorithm operates on a symmetrix matrix, so one of three symmetric matrices is formed.
|
46238 | *
|
46239 | * Order: 0
|
46240 | * A natural ordering P=null matrix is returned.
|
46241 | *
|
46242 | * Order: 1
|
46243 | * Matrix must be square. This is appropriate for a Cholesky or LU factorization.
|
46244 | * P = M + M'
|
46245 | *
|
46246 | * Order: 2
|
46247 | * Dense columns from M' are dropped, M recreated from M'. This is appropriatefor LU factorization of unsymmetric matrices.
|
46248 | * P = M' * M
|
46249 | *
|
46250 | * Order: 3
|
46251 | * This is best used for QR factorization or LU factorization is matrix M has no dense rows. A dense row is a row with more than 10*sqr(columns) entries.
|
46252 | * P = M' * M
|
46253 | */
|
46254 |
|
46255 |
|
46256 | function _createTargetMatrix(order, a, m, n, dense) {
|
46257 | // compute A'
|
46258 | var at = transpose(a); // check order = 1, matrix must be square
|
46259 |
|
46260 | if (order === 1 && n === m) {
|
46261 | // C = A + A'
|
46262 | return add(a, at);
|
46263 | } // check order = 2, drop dense columns from M'
|
46264 |
|
46265 |
|
46266 | if (order === 2) {
|
46267 | // transpose arrays
|
46268 | var tindex = at._index;
|
46269 | var tptr = at._ptr; // new column index
|
46270 |
|
46271 | var p2 = 0; // loop A' columns (rows)
|
46272 |
|
46273 | for (var j = 0; j < m; j++) {
|
46274 | // column j of AT starts here
|
46275 | var p = tptr[j]; // new column j starts here
|
46276 |
|
46277 | tptr[j] = p2; // skip dense col j
|
46278 |
|
46279 | if (tptr[j + 1] - p > dense) {
|
46280 | continue;
|
46281 | } // map rows in column j of A
|
46282 |
|
46283 |
|
46284 | for (var p1 = tptr[j + 1]; p < p1; p++) {
|
46285 | tindex[p2++] = tindex[p];
|
46286 | }
|
46287 | } // finalize AT
|
46288 |
|
46289 |
|
46290 | tptr[m] = p2; // recreate A from new transpose matrix
|
46291 |
|
46292 | a = transpose(at); // use A' * A
|
46293 |
|
46294 | return multiply(at, a);
|
46295 | } // use A' * A, square or rectangular matrix
|
46296 |
|
46297 |
|
46298 | return multiply(at, a);
|
46299 | }
|
46300 | /**
|
46301 | * Initialize quotient graph. There are four kind of nodes and elements that must be represented:
|
46302 | *
|
46303 | * - A live node is a node i (or a supernode) that has not been selected as a pivot nad has not been merged into another supernode.
|
46304 | * - A dead node i is one that has been removed from the graph, having been absorved into r = flip(ptr[i]).
|
46305 | * - A live element e is one that is in the graph, having been formed when node e was selected as the pivot.
|
46306 | * - A dead element e is one that has benn absorved into a subsequent element s = flip(ptr[e]).
|
46307 | */
|
46308 |
|
46309 |
|
46310 | function _initializeQuotientGraph(n, cptr, W, len, head, last, next, hhead, nv, w, elen, degree) {
|
46311 | // Initialize quotient graph
|
46312 | for (var k = 0; k < n; k++) {
|
46313 | W[len + k] = cptr[k + 1] - cptr[k];
|
46314 | }
|
46315 |
|
46316 | W[len + n] = 0; // initialize workspace
|
46317 |
|
46318 | for (var i = 0; i <= n; i++) {
|
46319 | // degree list i is empty
|
46320 | W[head + i] = -1;
|
46321 | last[i] = -1;
|
46322 | W[next + i] = -1; // hash list i is empty
|
46323 |
|
46324 | W[hhead + i] = -1; // node i is just one node
|
46325 |
|
46326 | W[nv + i] = 1; // node i is alive
|
46327 |
|
46328 | W[w + i] = 1; // Ek of node i is empty
|
46329 |
|
46330 | W[elen + i] = 0; // degree of node i
|
46331 |
|
46332 | W[degree + i] = W[len + i];
|
46333 | } // clear w
|
46334 |
|
46335 |
|
46336 | var mark = _wclear(0, 0, W, w, n); // n is a dead element
|
46337 |
|
46338 |
|
46339 | W[elen + n] = -2; // n is a root of assembly tree
|
46340 |
|
46341 | cptr[n] = -1; // n is a dead element
|
46342 |
|
46343 | W[w + n] = 0; // return mark
|
46344 |
|
46345 | return mark;
|
46346 | }
|
46347 | /**
|
46348 | * Initialize degree lists. Each node is placed in its degree lists. Nodes of zero degree are eliminated immediately. Nodes with
|
46349 | * degree >= dense are alsol eliminated and merged into a placeholder node n, a dead element. Thes nodes will appera last in the
|
46350 | * output permutation p.
|
46351 | */
|
46352 |
|
46353 |
|
46354 | function _initializeDegreeLists(n, cptr, W, degree, elen, w, dense, nv, head, last, next) {
|
46355 | // result
|
46356 | var nel = 0; // loop columns
|
46357 |
|
46358 | for (var i = 0; i < n; i++) {
|
46359 | // degree @ i
|
46360 | var d = W[degree + i]; // check node i is empty
|
46361 |
|
46362 | if (d === 0) {
|
46363 | // element i is dead
|
46364 | W[elen + i] = -2;
|
46365 | nel++; // i is a root of assembly tree
|
46366 |
|
46367 | cptr[i] = -1;
|
46368 | W[w + i] = 0;
|
46369 | } else if (d > dense) {
|
46370 | // absorb i into element n
|
46371 | W[nv + i] = 0; // node i is dead
|
46372 |
|
46373 | W[elen + i] = -1;
|
46374 | nel++;
|
46375 | cptr[i] = csFlip(n);
|
46376 | W[nv + n]++;
|
46377 | } else {
|
46378 | var h = W[head + d];
|
46379 |
|
46380 | if (h !== -1) {
|
46381 | last[h] = i;
|
46382 | } // put node i in degree list d
|
46383 |
|
46384 |
|
46385 | W[next + i] = W[head + d];
|
46386 | W[head + d] = i;
|
46387 | }
|
46388 | }
|
46389 |
|
46390 | return nel;
|
46391 | }
|
46392 |
|
46393 | function _wclear(mark, lemax, W, w, n) {
|
46394 | if (mark < 2 || mark + lemax < 0) {
|
46395 | for (var k = 0; k < n; k++) {
|
46396 | if (W[w + k] !== 0) {
|
46397 | W[w + k] = 1;
|
46398 | }
|
46399 | }
|
46400 |
|
46401 | mark = 2;
|
46402 | } // at this point, W [0..n-1] < mark holds
|
46403 |
|
46404 |
|
46405 | return mark;
|
46406 | }
|
46407 |
|
46408 | function _diag(i, j) {
|
46409 | return i !== j;
|
46410 | }
|
46411 |
|
46412 | return csAmd;
|
46413 | }
|
46414 |
|
46415 | exports.name = 'csAmd';
|
46416 | exports.path = 'algebra.sparse';
|
46417 | exports.factory = factory;
|
46418 |
|
46419 | /***/ }),
|
46420 | /* 211 */
|
46421 | /***/ (function(module, exports, __webpack_require__) {
|
46422 |
|
46423 | "use strict";
|
46424 |
|
46425 |
|
46426 | function factory() {
|
46427 | /**
|
46428 | * Keeps entries in the matrix when the callback function returns true, removes the entry otherwise
|
46429 | *
|
46430 | * @param {Matrix} a The sparse matrix
|
46431 | * @param {function} callback The callback function, function will be invoked with the following args:
|
46432 | * - The entry row
|
46433 | * - The entry column
|
46434 | * - The entry value
|
46435 | * - The state parameter
|
46436 | * @param {any} other The state
|
46437 | *
|
46438 | * @return The number of nonzero elements in the matrix
|
46439 | *
|
46440 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
46441 | */
|
46442 | var csFkeep = function csFkeep(a, callback, other) {
|
46443 | // a arrays
|
46444 | var avalues = a._values;
|
46445 | var aindex = a._index;
|
46446 | var aptr = a._ptr;
|
46447 | var asize = a._size; // columns
|
46448 |
|
46449 | var n = asize[1]; // nonzero items
|
46450 |
|
46451 | var nz = 0; // loop columns
|
46452 |
|
46453 | for (var j = 0; j < n; j++) {
|
46454 | // get current location of col j
|
46455 | var p = aptr[j]; // record new location of col j
|
46456 |
|
46457 | aptr[j] = nz;
|
46458 |
|
46459 | for (; p < aptr[j + 1]; p++) {
|
46460 | // check we need to keep this item
|
46461 | if (callback(aindex[p], j, avalues ? avalues[p] : 1, other)) {
|
46462 | // keep A(i,j)
|
46463 | aindex[nz] = aindex[p]; // check we need to process values (pattern only)
|
46464 |
|
46465 | if (avalues) {
|
46466 | avalues[nz] = avalues[p];
|
46467 | } // increment nonzero items
|
46468 |
|
46469 |
|
46470 | nz++;
|
46471 | }
|
46472 | }
|
46473 | } // finalize A
|
46474 |
|
46475 |
|
46476 | aptr[n] = nz; // trim arrays
|
46477 |
|
46478 | aindex.splice(nz, aindex.length - nz); // check we need to process values (pattern only)
|
46479 |
|
46480 | if (avalues) {
|
46481 | avalues.splice(nz, avalues.length - nz);
|
46482 | } // return number of nonzero items
|
46483 |
|
46484 |
|
46485 | return nz;
|
46486 | };
|
46487 |
|
46488 | return csFkeep;
|
46489 | }
|
46490 |
|
46491 | exports.name = 'csFkeep';
|
46492 | exports.path = 'algebra.sparse';
|
46493 | exports.factory = factory;
|
46494 |
|
46495 | /***/ }),
|
46496 | /* 212 */
|
46497 | /***/ (function(module, exports, __webpack_require__) {
|
46498 |
|
46499 | "use strict";
|
46500 |
|
46501 |
|
46502 | function factory(type) {
|
46503 | var SparseMatrix = type.SparseMatrix;
|
46504 | /**
|
46505 | * Permutes a sparse matrix C = P * A * Q
|
46506 | *
|
46507 | * @param {Matrix} a The Matrix A
|
46508 | * @param {Array} pinv The row permutation vector
|
46509 | * @param {Array} q The column permutation vector
|
46510 | * @param {boolean} values Create a pattern matrix (false), values and pattern otherwise
|
46511 | *
|
46512 | * @return {Matrix} C = P * A * Q, null on error
|
46513 | *
|
46514 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
46515 | */
|
46516 |
|
46517 | var csPermute = function csPermute(a, pinv, q, values) {
|
46518 | // a arrays
|
46519 | var avalues = a._values;
|
46520 | var aindex = a._index;
|
46521 | var aptr = a._ptr;
|
46522 | var asize = a._size;
|
46523 | var adt = a._datatype; // rows & columns
|
46524 |
|
46525 | var m = asize[0];
|
46526 | var n = asize[1]; // c arrays
|
46527 |
|
46528 | var cvalues = values && a._values ? [] : null;
|
46529 | var cindex = []; // (aptr[n])
|
46530 |
|
46531 | var cptr = []; // (n + 1)
|
46532 | // initialize vars
|
46533 |
|
46534 | var nz = 0; // loop columns
|
46535 |
|
46536 | for (var k = 0; k < n; k++) {
|
46537 | // column k of C is column q[k] of A
|
46538 | cptr[k] = nz; // apply column permutation
|
46539 |
|
46540 | var j = q ? q[k] : k; // loop values in column j of A
|
46541 |
|
46542 | for (var t0 = aptr[j], t1 = aptr[j + 1], t = t0; t < t1; t++) {
|
46543 | // row i of A is row pinv[i] of C
|
46544 | var r = pinv ? pinv[aindex[t]] : aindex[t]; // index
|
46545 |
|
46546 | cindex[nz] = r; // check we need to populate values
|
46547 |
|
46548 | if (cvalues) {
|
46549 | cvalues[nz] = avalues[t];
|
46550 | } // increment number of nonzero elements
|
46551 |
|
46552 |
|
46553 | nz++;
|
46554 | }
|
46555 | } // finalize the last column of C
|
46556 |
|
46557 |
|
46558 | cptr[n] = nz; // return C matrix
|
46559 |
|
46560 | return new SparseMatrix({
|
46561 | values: cvalues,
|
46562 | index: cindex,
|
46563 | ptr: cptr,
|
46564 | size: [m, n],
|
46565 | datatype: adt
|
46566 | });
|
46567 | };
|
46568 |
|
46569 | return csPermute;
|
46570 | }
|
46571 |
|
46572 | exports.name = 'csPermute';
|
46573 | exports.path = 'algebra.sparse';
|
46574 | exports.factory = factory;
|
46575 |
|
46576 | /***/ }),
|
46577 | /* 213 */
|
46578 | /***/ (function(module, exports, __webpack_require__) {
|
46579 |
|
46580 | "use strict";
|
46581 |
|
46582 |
|
46583 | function factory() {
|
46584 | /**
|
46585 | * Computes the elimination tree of Matrix A (using triu(A)) or the
|
46586 | * elimination tree of A'A without forming A'A.
|
46587 | *
|
46588 | * @param {Matrix} a The A Matrix
|
46589 | * @param {boolean} ata A value of true the function computes the etree of A'A
|
46590 | *
|
46591 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
46592 | */
|
46593 | var csEtree = function csEtree(a, ata) {
|
46594 | // check inputs
|
46595 | if (!a) {
|
46596 | return null;
|
46597 | } // a arrays
|
46598 |
|
46599 |
|
46600 | var aindex = a._index;
|
46601 | var aptr = a._ptr;
|
46602 | var asize = a._size; // rows & columns
|
46603 |
|
46604 | var m = asize[0];
|
46605 | var n = asize[1]; // allocate result
|
46606 |
|
46607 | var parent = []; // (n)
|
46608 | // allocate workspace
|
46609 |
|
46610 | var w = []; // (n + (ata ? m : 0))
|
46611 |
|
46612 | var ancestor = 0; // first n entries in w
|
46613 |
|
46614 | var prev = n; // last m entries (ata = true)
|
46615 |
|
46616 | var i, inext; // check we are calculating A'A
|
46617 |
|
46618 | if (ata) {
|
46619 | // initialize workspace
|
46620 | for (i = 0; i < m; i++) {
|
46621 | w[prev + i] = -1;
|
46622 | }
|
46623 | } // loop columns
|
46624 |
|
46625 |
|
46626 | for (var k = 0; k < n; k++) {
|
46627 | // node k has no parent yet
|
46628 | parent[k] = -1; // nor does k have an ancestor
|
46629 |
|
46630 | w[ancestor + k] = -1; // values in column k
|
46631 |
|
46632 | for (var p0 = aptr[k], p1 = aptr[k + 1], p = p0; p < p1; p++) {
|
46633 | // row
|
46634 | var r = aindex[p]; // node
|
46635 |
|
46636 | i = ata ? w[prev + r] : r; // traverse from i to k
|
46637 |
|
46638 | for (; i !== -1 && i < k; i = inext) {
|
46639 | // inext = ancestor of i
|
46640 | inext = w[ancestor + i]; // path compression
|
46641 |
|
46642 | w[ancestor + i] = k; // check no anc., parent is k
|
46643 |
|
46644 | if (inext === -1) {
|
46645 | parent[i] = k;
|
46646 | }
|
46647 | }
|
46648 |
|
46649 | if (ata) {
|
46650 | w[prev + r] = k;
|
46651 | }
|
46652 | }
|
46653 | }
|
46654 |
|
46655 | return parent;
|
46656 | };
|
46657 |
|
46658 | return csEtree;
|
46659 | }
|
46660 |
|
46661 | exports.name = 'csEtree';
|
46662 | exports.path = 'algebra.sparse';
|
46663 | exports.factory = factory;
|
46664 |
|
46665 | /***/ }),
|
46666 | /* 214 */
|
46667 | /***/ (function(module, exports, __webpack_require__) {
|
46668 |
|
46669 | "use strict";
|
46670 |
|
46671 |
|
46672 | function factory(type, config, load) {
|
46673 | var csTdfs = load(__webpack_require__(133));
|
46674 | /**
|
46675 | * Post order a tree of forest
|
46676 | *
|
46677 | * @param {Array} parent The tree or forest
|
46678 | * @param {Number} n Number of columns
|
46679 | *
|
46680 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
46681 | */
|
46682 |
|
46683 | var csPost = function csPost(parent, n) {
|
46684 | // check inputs
|
46685 | if (!parent) {
|
46686 | return null;
|
46687 | } // vars
|
46688 |
|
46689 |
|
46690 | var k = 0;
|
46691 | var j; // allocate result
|
46692 |
|
46693 | var post = []; // (n)
|
46694 | // workspace, head: first n entries, next: next n entries, stack: last n entries
|
46695 |
|
46696 | var w = []; // (3 * n)
|
46697 |
|
46698 | var head = 0;
|
46699 | var next = n;
|
46700 | var stack = 2 * n; // initialize workspace
|
46701 |
|
46702 | for (j = 0; j < n; j++) {
|
46703 | // empty linked lists
|
46704 | w[head + j] = -1;
|
46705 | } // traverse nodes in reverse order
|
46706 |
|
46707 |
|
46708 | for (j = n - 1; j >= 0; j--) {
|
46709 | // check j is a root
|
46710 | if (parent[j] === -1) {
|
46711 | continue;
|
46712 | } // add j to list of its parent
|
46713 |
|
46714 |
|
46715 | w[next + j] = w[head + parent[j]];
|
46716 | w[head + parent[j]] = j;
|
46717 | } // loop nodes
|
46718 |
|
46719 |
|
46720 | for (j = 0; j < n; j++) {
|
46721 | // skip j if it is not a root
|
46722 | if (parent[j] !== -1) {
|
46723 | continue;
|
46724 | } // depth-first search
|
46725 |
|
46726 |
|
46727 | k = csTdfs(j, k, w, head, next, post, stack);
|
46728 | }
|
46729 |
|
46730 | return post;
|
46731 | };
|
46732 |
|
46733 | return csPost;
|
46734 | }
|
46735 |
|
46736 | exports.name = 'csPost';
|
46737 | exports.path = 'algebra.sparse';
|
46738 | exports.factory = factory;
|
46739 |
|
46740 | /***/ }),
|
46741 | /* 215 */
|
46742 | /***/ (function(module, exports, __webpack_require__) {
|
46743 |
|
46744 | "use strict";
|
46745 |
|
46746 |
|
46747 | function factory(type, config, load) {
|
46748 | var transpose = load(__webpack_require__(72));
|
46749 | var csLeaf = load(__webpack_require__(216));
|
46750 | /**
|
46751 | * Computes the column counts using the upper triangular part of A.
|
46752 | * It transposes A internally, none of the input parameters are modified.
|
46753 | *
|
46754 | * @param {Matrix} a The sparse matrix A
|
46755 | *
|
46756 | * @param {Matrix} ata Count the columns of A'A instead
|
46757 | *
|
46758 | * @return An array of size n of the column counts or null on error
|
46759 | *
|
46760 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
46761 | */
|
46762 |
|
46763 | var csCounts = function csCounts(a, parent, post, ata) {
|
46764 | // check inputs
|
46765 | if (!a || !parent || !post) {
|
46766 | return null;
|
46767 | } // a matrix arrays
|
46768 |
|
46769 |
|
46770 | var asize = a._size; // rows and columns
|
46771 |
|
46772 | var m = asize[0];
|
46773 | var n = asize[1]; // variables
|
46774 |
|
46775 | var i, j, k, J, p, p0, p1; // workspace size
|
46776 |
|
46777 | var s = 4 * n + (ata ? n + m + 1 : 0); // allocate workspace
|
46778 |
|
46779 | var w = []; // (s)
|
46780 |
|
46781 | var ancestor = 0; // first n entries
|
46782 |
|
46783 | var maxfirst = n; // next n entries
|
46784 |
|
46785 | var prevleaf = 2 * n; // next n entries
|
46786 |
|
46787 | var first = 3 * n; // next n entries
|
46788 |
|
46789 | var head = 4 * n; // next n + 1 entries (used when ata is true)
|
46790 |
|
46791 | var next = 5 * n + 1; // last entries in workspace
|
46792 | // clear workspace w[0..s-1]
|
46793 |
|
46794 | for (k = 0; k < s; k++) {
|
46795 | w[k] = -1;
|
46796 | } // allocate result
|
46797 |
|
46798 |
|
46799 | var colcount = []; // (n)
|
46800 | // AT = A'
|
46801 |
|
46802 | var at = transpose(a); // at arrays
|
46803 |
|
46804 | var tindex = at._index;
|
46805 | var tptr = at._ptr; // find w[first + j]
|
46806 |
|
46807 | for (k = 0; k < n; k++) {
|
46808 | j = post[k]; // colcount[j]=1 if j is a leaf
|
46809 |
|
46810 | colcount[j] = w[first + j] === -1 ? 1 : 0;
|
46811 |
|
46812 | for (; j !== -1 && w[first + j] === -1; j = parent[j]) {
|
46813 | w[first + j] = k;
|
46814 | }
|
46815 | } // initialize ata if needed
|
46816 |
|
46817 |
|
46818 | if (ata) {
|
46819 | // invert post
|
46820 | for (k = 0; k < n; k++) {
|
46821 | w[post[k]] = k;
|
46822 | } // loop rows (columns in AT)
|
46823 |
|
46824 |
|
46825 | for (i = 0; i < m; i++) {
|
46826 | // values in column i of AT
|
46827 | for (k = n, p0 = tptr[i], p1 = tptr[i + 1], p = p0; p < p1; p++) {
|
46828 | k = Math.min(k, w[tindex[p]]);
|
46829 | } // place row i in linked list k
|
46830 |
|
46831 |
|
46832 | w[next + i] = w[head + k];
|
46833 | w[head + k] = i;
|
46834 | }
|
46835 | } // each node in its own set
|
46836 |
|
46837 |
|
46838 | for (i = 0; i < n; i++) {
|
46839 | w[ancestor + i] = i;
|
46840 | }
|
46841 |
|
46842 | for (k = 0; k < n; k++) {
|
46843 | // j is the kth node in postordered etree
|
46844 | j = post[k]; // check j is not a root
|
46845 |
|
46846 | if (parent[j] !== -1) {
|
46847 | colcount[parent[j]]--;
|
46848 | } // J=j for LL'=A case
|
46849 |
|
46850 |
|
46851 | for (J = ata ? w[head + k] : j; J !== -1; J = ata ? w[next + J] : -1) {
|
46852 | for (p = tptr[J]; p < tptr[J + 1]; p++) {
|
46853 | i = tindex[p];
|
46854 | var r = csLeaf(i, j, w, first, maxfirst, prevleaf, ancestor); // check A(i,j) is in skeleton
|
46855 |
|
46856 | if (r.jleaf >= 1) {
|
46857 | colcount[j]++;
|
46858 | } // check account for overlap in q
|
46859 |
|
46860 |
|
46861 | if (r.jleaf === 2) {
|
46862 | colcount[r.q]--;
|
46863 | }
|
46864 | }
|
46865 | }
|
46866 |
|
46867 | if (parent[j] !== -1) {
|
46868 | w[ancestor + j] = parent[j];
|
46869 | }
|
46870 | } // sum up colcount's of each child
|
46871 |
|
46872 |
|
46873 | for (j = 0; j < n; j++) {
|
46874 | if (parent[j] !== -1) {
|
46875 | colcount[parent[j]] += colcount[j];
|
46876 | }
|
46877 | }
|
46878 |
|
46879 | return colcount;
|
46880 | };
|
46881 |
|
46882 | return csCounts;
|
46883 | }
|
46884 |
|
46885 | exports.name = 'csCounts';
|
46886 | exports.path = 'algebra.sparse';
|
46887 | exports.factory = factory;
|
46888 |
|
46889 | /***/ }),
|
46890 | /* 216 */
|
46891 | /***/ (function(module, exports, __webpack_require__) {
|
46892 |
|
46893 | "use strict";
|
46894 |
|
46895 |
|
46896 | function factory() {
|
46897 | /**
|
46898 | * This function determines if j is a leaf of the ith row subtree.
|
46899 | * Consider A(i,j), node j in ith row subtree and return lca(jprev,j)
|
46900 | *
|
46901 | * @param {Number} i The ith row subtree
|
46902 | * @param {Number} j The node to test
|
46903 | * @param {Array} w The workspace array
|
46904 | * @param {Number} first The index offset within the workspace for the first array
|
46905 | * @param {Number} maxfirst The index offset within the workspace for the maxfirst array
|
46906 | * @param {Number} prevleaf The index offset within the workspace for the prevleaf array
|
46907 | * @param {Number} ancestor The index offset within the workspace for the ancestor array
|
46908 | *
|
46909 | * @return {Object}
|
46910 | *
|
46911 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
46912 | */
|
46913 | var csLeaf = function csLeaf(i, j, w, first, maxfirst, prevleaf, ancestor) {
|
46914 | var s, sparent, jprev; // our result
|
46915 |
|
46916 | var jleaf = 0;
|
46917 | var q; // check j is a leaf
|
46918 |
|
46919 | if (i <= j || w[first + j] <= w[maxfirst + i]) {
|
46920 | return -1;
|
46921 | } // update max first[j] seen so far
|
46922 |
|
46923 |
|
46924 | w[maxfirst + i] = w[first + j]; // jprev = previous leaf of ith subtree
|
46925 |
|
46926 | jprev = w[prevleaf + i];
|
46927 | w[prevleaf + i] = j; // check j is first or subsequent leaf
|
46928 |
|
46929 | if (jprev === -1) {
|
46930 | // 1st leaf, q = root of ith subtree
|
46931 | jleaf = 1;
|
46932 | q = i;
|
46933 | } else {
|
46934 | // update jleaf
|
46935 | jleaf = 2; // q = least common ancester (jprev,j)
|
46936 |
|
46937 | for (q = jprev; q !== w[ancestor + q]; q = w[ancestor + q]) {
|
46938 | ;
|
46939 | }
|
46940 |
|
46941 | for (s = jprev; s !== q; s = sparent) {
|
46942 | // path compression
|
46943 | sparent = w[ancestor + s];
|
46944 | w[ancestor + s] = q;
|
46945 | }
|
46946 | }
|
46947 |
|
46948 | return {
|
46949 | jleaf: jleaf,
|
46950 | q: q
|
46951 | };
|
46952 | };
|
46953 |
|
46954 | return csLeaf;
|
46955 | }
|
46956 |
|
46957 | exports.name = 'csLeaf';
|
46958 | exports.path = 'algebra.sparse';
|
46959 | exports.factory = factory;
|
46960 |
|
46961 | /***/ }),
|
46962 | /* 217 */
|
46963 | /***/ (function(module, exports, __webpack_require__) {
|
46964 |
|
46965 | "use strict";
|
46966 |
|
46967 |
|
46968 | function factory(type, config, load) {
|
46969 | var abs = load(__webpack_require__(25));
|
46970 | var divideScalar = load(__webpack_require__(12));
|
46971 | var multiply = load(__webpack_require__(10));
|
46972 | var larger = load(__webpack_require__(33));
|
46973 | var largerEq = load(__webpack_require__(89));
|
46974 | var csSpsolve = load(__webpack_require__(218));
|
46975 | var SparseMatrix = type.SparseMatrix;
|
46976 | /**
|
46977 | * Computes the numeric LU factorization of the sparse matrix A. Implements a Left-looking LU factorization
|
46978 | * algorithm that computes L and U one column at a tume. At the kth step, it access columns 1 to k-1 of L
|
46979 | * and column k of A. Given the fill-reducing column ordering q (see parameter s) computes L, U and pinv so
|
46980 | * L * U = A(p, q), where p is the inverse of pinv.
|
46981 | *
|
46982 | * @param {Matrix} m The A Matrix to factorize
|
46983 | * @param {Object} s The symbolic analysis from csSqr(). Provides the fill-reducing
|
46984 | * column ordering q
|
46985 | * @param {Number} tol Partial pivoting threshold (1 for partial pivoting)
|
46986 | *
|
46987 | * @return {Number} The numeric LU factorization of A or null
|
46988 | *
|
46989 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
46990 | */
|
46991 |
|
46992 | var csLu = function csLu(m, s, tol) {
|
46993 | // validate input
|
46994 | if (!m) {
|
46995 | return null;
|
46996 | } // m arrays
|
46997 |
|
46998 |
|
46999 | var size = m._size; // columns
|
47000 |
|
47001 | var n = size[1]; // symbolic analysis result
|
47002 |
|
47003 | var q;
|
47004 | var lnz = 100;
|
47005 | var unz = 100; // update symbolic analysis parameters
|
47006 |
|
47007 | if (s) {
|
47008 | q = s.q;
|
47009 | lnz = s.lnz || lnz;
|
47010 | unz = s.unz || unz;
|
47011 | } // L arrays
|
47012 |
|
47013 |
|
47014 | var lvalues = []; // (lnz)
|
47015 |
|
47016 | var lindex = []; // (lnz)
|
47017 |
|
47018 | var lptr = []; // (n + 1)
|
47019 | // L
|
47020 |
|
47021 | var L = new SparseMatrix({
|
47022 | values: lvalues,
|
47023 | index: lindex,
|
47024 | ptr: lptr,
|
47025 | size: [n, n]
|
47026 | }); // U arrays
|
47027 |
|
47028 | var uvalues = []; // (unz)
|
47029 |
|
47030 | var uindex = []; // (unz)
|
47031 |
|
47032 | var uptr = []; // (n + 1)
|
47033 | // U
|
47034 |
|
47035 | var U = new SparseMatrix({
|
47036 | values: uvalues,
|
47037 | index: uindex,
|
47038 | ptr: uptr,
|
47039 | size: [n, n]
|
47040 | }); // inverse of permutation vector
|
47041 |
|
47042 | var pinv = []; // (n)
|
47043 | // vars
|
47044 |
|
47045 | var i, p; // allocate arrays
|
47046 |
|
47047 | var x = []; // (n)
|
47048 |
|
47049 | var xi = []; // (2 * n)
|
47050 | // initialize variables
|
47051 |
|
47052 | for (i = 0; i < n; i++) {
|
47053 | // clear workspace
|
47054 | x[i] = 0; // no rows pivotal yet
|
47055 |
|
47056 | pinv[i] = -1; // no cols of L yet
|
47057 |
|
47058 | lptr[i + 1] = 0;
|
47059 | } // reset number of nonzero elements in L and U
|
47060 |
|
47061 |
|
47062 | lnz = 0;
|
47063 | unz = 0; // compute L(:,k) and U(:,k)
|
47064 |
|
47065 | for (var k = 0; k < n; k++) {
|
47066 | // update ptr
|
47067 | lptr[k] = lnz;
|
47068 | uptr[k] = unz; // apply column permutations if needed
|
47069 |
|
47070 | var col = q ? q[k] : k; // solve triangular system, x = L\A(:,col)
|
47071 |
|
47072 | var top = csSpsolve(L, m, col, xi, x, pinv, 1); // find pivot
|
47073 |
|
47074 | var ipiv = -1;
|
47075 | var a = -1; // loop xi[] from top -> n
|
47076 |
|
47077 | for (p = top; p < n; p++) {
|
47078 | // x[i] is nonzero
|
47079 | i = xi[p]; // check row i is not yet pivotal
|
47080 |
|
47081 | if (pinv[i] < 0) {
|
47082 | // absolute value of x[i]
|
47083 | var xabs = abs(x[i]); // check absoulte value is greater than pivot value
|
47084 |
|
47085 | if (larger(xabs, a)) {
|
47086 | // largest pivot candidate so far
|
47087 | a = xabs;
|
47088 | ipiv = i;
|
47089 | }
|
47090 | } else {
|
47091 | // x(i) is the entry U(pinv[i],k)
|
47092 | uindex[unz] = pinv[i];
|
47093 | uvalues[unz++] = x[i];
|
47094 | }
|
47095 | } // validate we found a valid pivot
|
47096 |
|
47097 |
|
47098 | if (ipiv === -1 || a <= 0) {
|
47099 | return null;
|
47100 | } // update actual pivot column, give preference to diagonal value
|
47101 |
|
47102 |
|
47103 | if (pinv[col] < 0 && largerEq(abs(x[col]), multiply(a, tol))) {
|
47104 | ipiv = col;
|
47105 | } // the chosen pivot
|
47106 |
|
47107 |
|
47108 | var pivot = x[ipiv]; // last entry in U(:,k) is U(k,k)
|
47109 |
|
47110 | uindex[unz] = k;
|
47111 | uvalues[unz++] = pivot; // ipiv is the kth pivot row
|
47112 |
|
47113 | pinv[ipiv] = k; // first entry in L(:,k) is L(k,k) = 1
|
47114 |
|
47115 | lindex[lnz] = ipiv;
|
47116 | lvalues[lnz++] = 1; // L(k+1:n,k) = x / pivot
|
47117 |
|
47118 | for (p = top; p < n; p++) {
|
47119 | // row
|
47120 | i = xi[p]; // check x(i) is an entry in L(:,k)
|
47121 |
|
47122 | if (pinv[i] < 0) {
|
47123 | // save unpermuted row in L
|
47124 | lindex[lnz] = i; // scale pivot column
|
47125 |
|
47126 | lvalues[lnz++] = divideScalar(x[i], pivot);
|
47127 | } // x[0..n-1] = 0 for next k
|
47128 |
|
47129 |
|
47130 | x[i] = 0;
|
47131 | }
|
47132 | } // update ptr
|
47133 |
|
47134 |
|
47135 | lptr[n] = lnz;
|
47136 | uptr[n] = unz; // fix row indices of L for final pinv
|
47137 |
|
47138 | for (p = 0; p < lnz; p++) {
|
47139 | lindex[p] = pinv[lindex[p]];
|
47140 | } // trim arrays
|
47141 |
|
47142 |
|
47143 | lvalues.splice(lnz, lvalues.length - lnz);
|
47144 | lindex.splice(lnz, lindex.length - lnz);
|
47145 | uvalues.splice(unz, uvalues.length - unz);
|
47146 | uindex.splice(unz, uindex.length - unz); // return LU factor
|
47147 |
|
47148 | return {
|
47149 | L: L,
|
47150 | U: U,
|
47151 | pinv: pinv
|
47152 | };
|
47153 | };
|
47154 |
|
47155 | return csLu;
|
47156 | }
|
47157 |
|
47158 | exports.name = 'csLu';
|
47159 | exports.path = 'algebra.sparse';
|
47160 | exports.factory = factory;
|
47161 |
|
47162 | /***/ }),
|
47163 | /* 218 */
|
47164 | /***/ (function(module, exports, __webpack_require__) {
|
47165 |
|
47166 | "use strict";
|
47167 |
|
47168 |
|
47169 | function factory(type, config, load) {
|
47170 | var divideScalar = load(__webpack_require__(12));
|
47171 | var multiply = load(__webpack_require__(10));
|
47172 | var subtract = load(__webpack_require__(15));
|
47173 | var csReach = load(__webpack_require__(219));
|
47174 | /**
|
47175 | * The function csSpsolve() computes the solution to G * x = bk, where bk is the
|
47176 | * kth column of B. When lo is true, the function assumes G = L is lower triangular with the
|
47177 | * diagonal entry as the first entry in each column. When lo is true, the function assumes G = U
|
47178 | * is upper triangular with the diagonal entry as the last entry in each column.
|
47179 | *
|
47180 | * @param {Matrix} g The G matrix
|
47181 | * @param {Matrix} b The B matrix
|
47182 | * @param {Number} k The kth column in B
|
47183 | * @param {Array} xi The nonzero pattern xi[top] .. xi[n - 1], an array of size = 2 * n
|
47184 | * The first n entries is the nonzero pattern, the last n entries is the stack
|
47185 | * @param {Array} x The soluton to the linear system G * x = b
|
47186 | * @param {Array} pinv The inverse row permutation vector, must be null for L * x = b
|
47187 | * @param {boolean} lo The lower (true) upper triangular (false) flag
|
47188 | *
|
47189 | * @return {Number} The index for the nonzero pattern
|
47190 | *
|
47191 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
47192 | */
|
47193 |
|
47194 | var csSpsolve = function csSpsolve(g, b, k, xi, x, pinv, lo) {
|
47195 | // g arrays
|
47196 | var gvalues = g._values;
|
47197 | var gindex = g._index;
|
47198 | var gptr = g._ptr;
|
47199 | var gsize = g._size; // columns
|
47200 |
|
47201 | var n = gsize[1]; // b arrays
|
47202 |
|
47203 | var bvalues = b._values;
|
47204 | var bindex = b._index;
|
47205 | var bptr = b._ptr; // vars
|
47206 |
|
47207 | var p, p0, p1, q; // xi[top..n-1] = csReach(B(:,k))
|
47208 |
|
47209 | var top = csReach(g, b, k, xi, pinv); // clear x
|
47210 |
|
47211 | for (p = top; p < n; p++) {
|
47212 | x[xi[p]] = 0;
|
47213 | } // scatter b
|
47214 |
|
47215 |
|
47216 | for (p0 = bptr[k], p1 = bptr[k + 1], p = p0; p < p1; p++) {
|
47217 | x[bindex[p]] = bvalues[p];
|
47218 | } // loop columns
|
47219 |
|
47220 |
|
47221 | for (var px = top; px < n; px++) {
|
47222 | // x array index for px
|
47223 | var j = xi[px]; // apply permutation vector (U x = b), j maps to column J of G
|
47224 |
|
47225 | var J = pinv ? pinv[j] : j; // check column J is empty
|
47226 |
|
47227 | if (J < 0) {
|
47228 | continue;
|
47229 | } // column value indeces in G, p0 <= p < p1
|
47230 |
|
47231 |
|
47232 | p0 = gptr[J];
|
47233 | p1 = gptr[J + 1]; // x(j) /= G(j,j)
|
47234 |
|
47235 | x[j] = divideScalar(x[j], gvalues[lo ? p0 : p1 - 1]); // first entry L(j,j)
|
47236 |
|
47237 | p = lo ? p0 + 1 : p0;
|
47238 | q = lo ? p1 : p1 - 1; // loop
|
47239 |
|
47240 | for (; p < q; p++) {
|
47241 | // row
|
47242 | var i = gindex[p]; // x(i) -= G(i,j) * x(j)
|
47243 |
|
47244 | x[i] = subtract(x[i], multiply(gvalues[p], x[j]));
|
47245 | }
|
47246 | } // return top of stack
|
47247 |
|
47248 |
|
47249 | return top;
|
47250 | };
|
47251 |
|
47252 | return csSpsolve;
|
47253 | }
|
47254 |
|
47255 | exports.name = 'csSpsolve';
|
47256 | exports.path = 'algebra.sparse';
|
47257 | exports.factory = factory;
|
47258 |
|
47259 | /***/ }),
|
47260 | /* 219 */
|
47261 | /***/ (function(module, exports, __webpack_require__) {
|
47262 |
|
47263 | "use strict";
|
47264 |
|
47265 |
|
47266 | function factory(type, config, load) {
|
47267 | var csDfs = load(__webpack_require__(220));
|
47268 | var csMarked = load(__webpack_require__(134));
|
47269 | var csMark = load(__webpack_require__(135));
|
47270 | /**
|
47271 | * The csReach function computes X = Reach(B), where B is the nonzero pattern of the n-by-1
|
47272 | * sparse column of vector b. The function returns the set of nodes reachable from any node in B. The
|
47273 | * nonzero pattern xi of the solution x to the sparse linear system Lx=b is given by X=Reach(B).
|
47274 | *
|
47275 | * @param {Matrix} g The G matrix
|
47276 | * @param {Matrix} b The B matrix
|
47277 | * @param {Number} k The kth column in B
|
47278 | * @param {Array} xi The nonzero pattern xi[top] .. xi[n - 1], an array of size = 2 * n
|
47279 | * The first n entries is the nonzero pattern, the last n entries is the stack
|
47280 | * @param {Array} pinv The inverse row permutation vector
|
47281 | *
|
47282 | * @return {Number} The index for the nonzero pattern
|
47283 | *
|
47284 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
47285 | */
|
47286 |
|
47287 | var csReach = function csReach(g, b, k, xi, pinv) {
|
47288 | // g arrays
|
47289 | var gptr = g._ptr;
|
47290 | var gsize = g._size; // b arrays
|
47291 |
|
47292 | var bindex = b._index;
|
47293 | var bptr = b._ptr; // columns
|
47294 |
|
47295 | var n = gsize[1]; // vars
|
47296 |
|
47297 | var p, p0, p1; // initialize top
|
47298 |
|
47299 | var top = n; // loop column indeces in B
|
47300 |
|
47301 | for (p0 = bptr[k], p1 = bptr[k + 1], p = p0; p < p1; p++) {
|
47302 | // node i
|
47303 | var i = bindex[p]; // check node i is marked
|
47304 |
|
47305 | if (!csMarked(gptr, i)) {
|
47306 | // start a dfs at unmarked node i
|
47307 | top = csDfs(i, g, top, xi, pinv);
|
47308 | }
|
47309 | } // loop columns from top -> n - 1
|
47310 |
|
47311 |
|
47312 | for (p = top; p < n; p++) {
|
47313 | // restore G
|
47314 | csMark(gptr, xi[p]);
|
47315 | }
|
47316 |
|
47317 | return top;
|
47318 | };
|
47319 |
|
47320 | return csReach;
|
47321 | }
|
47322 |
|
47323 | exports.name = 'csReach';
|
47324 | exports.path = 'algebra.sparse';
|
47325 | exports.factory = factory;
|
47326 |
|
47327 | /***/ }),
|
47328 | /* 220 */
|
47329 | /***/ (function(module, exports, __webpack_require__) {
|
47330 |
|
47331 | "use strict";
|
47332 |
|
47333 |
|
47334 | function factory(type, config, load) {
|
47335 | var csMarked = load(__webpack_require__(134));
|
47336 | var csMark = load(__webpack_require__(135));
|
47337 | var csUnflip = load(__webpack_require__(221));
|
47338 | /**
|
47339 | * Depth-first search computes the nonzero pattern xi of the directed graph G (Matrix) starting
|
47340 | * at nodes in B (see csReach()).
|
47341 | *
|
47342 | * @param {Number} j The starting node for the DFS algorithm
|
47343 | * @param {Matrix} g The G matrix to search, ptr array modified, then restored
|
47344 | * @param {Number} top Start index in stack xi[top..n-1]
|
47345 | * @param {Number} k The kth column in B
|
47346 | * @param {Array} xi The nonzero pattern xi[top] .. xi[n - 1], an array of size = 2 * n
|
47347 | * The first n entries is the nonzero pattern, the last n entries is the stack
|
47348 | * @param {Array} pinv The inverse row permutation vector, must be null for L * x = b
|
47349 | *
|
47350 | * @return {Number} New value of top
|
47351 | *
|
47352 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
47353 | */
|
47354 |
|
47355 | var csDfs = function csDfs(j, g, top, xi, pinv) {
|
47356 | // g arrays
|
47357 | var index = g._index;
|
47358 | var ptr = g._ptr;
|
47359 | var size = g._size; // columns
|
47360 |
|
47361 | var n = size[1]; // vars
|
47362 |
|
47363 | var i, p, p2; // initialize head
|
47364 |
|
47365 | var head = 0; // initialize the recursion stack
|
47366 |
|
47367 | xi[0] = j; // loop
|
47368 |
|
47369 | while (head >= 0) {
|
47370 | // get j from the top of the recursion stack
|
47371 | j = xi[head]; // apply permutation vector
|
47372 |
|
47373 | var jnew = pinv ? pinv[j] : j; // check node j is marked
|
47374 |
|
47375 | if (!csMarked(ptr, j)) {
|
47376 | // mark node j as visited
|
47377 | csMark(ptr, j); // update stack (last n entries in xi)
|
47378 |
|
47379 | xi[n + head] = jnew < 0 ? 0 : csUnflip(ptr[jnew]);
|
47380 | } // node j done if no unvisited neighbors
|
47381 |
|
47382 |
|
47383 | var done = 1; // examine all neighbors of j, stack (last n entries in xi)
|
47384 |
|
47385 | for (p = xi[n + head], p2 = jnew < 0 ? 0 : csUnflip(ptr[jnew + 1]); p < p2; p++) {
|
47386 | // consider neighbor node i
|
47387 | i = index[p]; // check we have visited node i, skip it
|
47388 |
|
47389 | if (csMarked(ptr, i)) {
|
47390 | continue;
|
47391 | } // pause depth-first search of node j, update stack (last n entries in xi)
|
47392 |
|
47393 |
|
47394 | xi[n + head] = p; // start dfs at node i
|
47395 |
|
47396 | xi[++head] = i; // node j is not done
|
47397 |
|
47398 | done = 0; // break, to start dfs(i)
|
47399 |
|
47400 | break;
|
47401 | } // check depth-first search at node j is done
|
47402 |
|
47403 |
|
47404 | if (done) {
|
47405 | // remove j from the recursion stack
|
47406 | head--; // and place in the output stack
|
47407 |
|
47408 | xi[--top] = j;
|
47409 | }
|
47410 | }
|
47411 |
|
47412 | return top;
|
47413 | };
|
47414 |
|
47415 | return csDfs;
|
47416 | }
|
47417 |
|
47418 | exports.name = 'csDfs';
|
47419 | exports.path = 'algebra.sparse';
|
47420 | exports.factory = factory;
|
47421 |
|
47422 | /***/ }),
|
47423 | /* 221 */
|
47424 | /***/ (function(module, exports, __webpack_require__) {
|
47425 |
|
47426 | "use strict";
|
47427 |
|
47428 |
|
47429 | function factory(type, config, load) {
|
47430 | var csFlip = load(__webpack_require__(88));
|
47431 | /**
|
47432 | * Flips the value if it is negative of returns the same value otherwise.
|
47433 | *
|
47434 | * @param {Number} i The value to flip
|
47435 | *
|
47436 | * Reference: http://faculty.cse.tamu.edu/davis/publications.html
|
47437 | */
|
47438 |
|
47439 | var csUnflip = function csUnflip(i) {
|
47440 | // flip the value if it is negative
|
47441 | return i < 0 ? csFlip(i) : i;
|
47442 | };
|
47443 |
|
47444 | return csUnflip;
|
47445 | }
|
47446 |
|
47447 | exports.name = 'csUnflip';
|
47448 | exports.path = 'algebra.sparse';
|
47449 | exports.factory = factory;
|
47450 |
|
47451 | /***/ }),
|
47452 | /* 222 */
|
47453 | /***/ (function(module, exports, __webpack_require__) {
|
47454 |
|
47455 | "use strict";
|
47456 |
|
47457 |
|
47458 | var isArray = Array.isArray;
|
47459 |
|
47460 | function factory(type, config, load, typed) {
|
47461 | var matrix = load(__webpack_require__(0));
|
47462 | var lup = load(__webpack_require__(87));
|
47463 | var slu = load(__webpack_require__(132));
|
47464 | var csIpvec = load(__webpack_require__(223));
|
47465 | var solveValidation = load(__webpack_require__(90));
|
47466 | var usolve = load(__webpack_require__(137));
|
47467 | var lsolve = load(__webpack_require__(136));
|
47468 | /**
|
47469 | * Solves the linear system `A * x = b` where `A` is an [n x n] matrix and `b` is a [n] column vector.
|
47470 | *
|
47471 | * Syntax:
|
47472 | *
|
47473 | * math.lusolve(A, b) // returns column vector with the solution to the linear system A * x = b
|
47474 | * math.lusolve(lup, b) // returns column vector with the solution to the linear system A * x = b, lup = math.lup(A)
|
47475 | *
|
47476 | * Examples:
|
47477 | *
|
47478 | * const m = [[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]
|
47479 | *
|
47480 | * const x = math.lusolve(m, [-1, -1, -1, -1]) // x = [[-1], [-0.5], [-1/3], [-0.25]]
|
47481 | *
|
47482 | * const f = math.lup(m)
|
47483 | * const x1 = math.lusolve(f, [-1, -1, -1, -1]) // x1 = [[-1], [-0.5], [-1/3], [-0.25]]
|
47484 | * const x2 = math.lusolve(f, [1, 2, 1, -1]) // x2 = [[1], [1], [1/3], [-0.25]]
|
47485 | *
|
47486 | * const a = [[-2, 3], [2, 1]]
|
47487 | * const b = [11, 9]
|
47488 | * const x = math.lusolve(a, b) // [[2], [5]]
|
47489 | *
|
47490 | * See also:
|
47491 | *
|
47492 | * lup, slu, lsolve, usolve
|
47493 | *
|
47494 | * @param {Matrix | Array | Object} A Invertible Matrix or the Matrix LU decomposition
|
47495 | * @param {Matrix | Array} b Column Vector
|
47496 | * @param {number} [order] The Symbolic Ordering and Analysis order, see slu for details. Matrix must be a SparseMatrix
|
47497 | * @param {Number} [threshold] Partial pivoting threshold (1 for partial pivoting), see slu for details. Matrix must be a SparseMatrix.
|
47498 | *
|
47499 | * @return {DenseMatrix | Array} Column vector with the solution to the linear system A * x = b
|
47500 | */
|
47501 |
|
47502 | var lusolve = typed('lusolve', {
|
47503 | 'Array, Array | Matrix': function ArrayArrayMatrix(a, b) {
|
47504 | // convert a to matrix
|
47505 | a = matrix(a); // matrix lup decomposition
|
47506 |
|
47507 | var d = lup(a); // solve
|
47508 |
|
47509 | var x = _lusolve(d.L, d.U, d.p, null, b); // convert result to array
|
47510 |
|
47511 |
|
47512 | return x.valueOf();
|
47513 | },
|
47514 | 'DenseMatrix, Array | Matrix': function DenseMatrixArrayMatrix(a, b) {
|
47515 | // matrix lup decomposition
|
47516 | var d = lup(a); // solve
|
47517 |
|
47518 | return _lusolve(d.L, d.U, d.p, null, b);
|
47519 | },
|
47520 | 'SparseMatrix, Array | Matrix': function SparseMatrixArrayMatrix(a, b) {
|
47521 | // matrix lup decomposition
|
47522 | var d = lup(a); // solve
|
47523 |
|
47524 | return _lusolve(d.L, d.U, d.p, null, b);
|
47525 | },
|
47526 | 'SparseMatrix, Array | Matrix, number, number': function SparseMatrixArrayMatrixNumberNumber(a, b, order, threshold) {
|
47527 | // matrix lu decomposition
|
47528 | var d = slu(a, order, threshold); // solve
|
47529 |
|
47530 | return _lusolve(d.L, d.U, d.p, d.q, b);
|
47531 | },
|
47532 | 'Object, Array | Matrix': function ObjectArrayMatrix(d, b) {
|
47533 | // solve
|
47534 | return _lusolve(d.L, d.U, d.p, d.q, b);
|
47535 | }
|
47536 | });
|
47537 |
|
47538 | var _toMatrix = function _toMatrix(a) {
|
47539 | // check it is a matrix
|
47540 | if (type.isMatrix(a)) {
|
47541 | return a;
|
47542 | } // check array
|
47543 |
|
47544 |
|
47545 | if (isArray(a)) {
|
47546 | return matrix(a);
|
47547 | } // throw
|
47548 |
|
47549 |
|
47550 | throw new TypeError('Invalid Matrix LU decomposition');
|
47551 | };
|
47552 |
|
47553 | function _lusolve(l, u, p, q, b) {
|
47554 | // verify L, U, P
|
47555 | l = _toMatrix(l);
|
47556 | u = _toMatrix(u); // validate matrix and vector
|
47557 |
|
47558 | b = solveValidation(l, b, false); // apply row permutations if needed (b is a DenseMatrix)
|
47559 |
|
47560 | if (p) {
|
47561 | b._data = csIpvec(p, b._data);
|
47562 | } // use forward substitution to resolve L * y = b
|
47563 |
|
47564 |
|
47565 | var y = lsolve(l, b); // use backward substitution to resolve U * x = y
|
47566 |
|
47567 | var x = usolve(u, y); // apply column permutations if needed (x is a DenseMatrix)
|
47568 |
|
47569 | if (q) {
|
47570 | x._data = csIpvec(q, x._data);
|
47571 | } // return solution
|
47572 |
|
47573 |
|
47574 | return x;
|
47575 | }
|
47576 |
|
47577 | return lusolve;
|
47578 | }
|
47579 |
|
47580 | exports.name = 'lusolve';
|
47581 | exports.factory = factory;
|
47582 |
|
47583 | /***/ }),
|
47584 | /* 223 */
|
47585 | /***/ (function(module, exports, __webpack_require__) {
|
47586 |
|
47587 | "use strict";
|
47588 |
|
47589 |
|
47590 | function factory() {
|
47591 | /**
|
47592 | * Permutes a vector; x = P'b. In MATLAB notation, x(p)=b.
|
47593 | *
|
47594 | * @param {Array} p The permutation vector of length n. null value denotes identity
|
47595 | * @param {Array} b The input vector
|
47596 | *
|
47597 | * @return {Array} The output vector x = P'b
|
47598 | */
|
47599 | function csIpvec(p, b) {
|
47600 | // vars
|
47601 | var k;
|
47602 | var n = b.length;
|
47603 | var x = []; // check permutation vector was provided, p = null denotes identity
|
47604 |
|
47605 | if (p) {
|
47606 | // loop vector
|
47607 | for (k = 0; k < n; k++) {
|
47608 | // apply permutation
|
47609 | x[p[k]] = b[k];
|
47610 | }
|
47611 | } else {
|
47612 | // loop vector
|
47613 | for (k = 0; k < n; k++) {
|
47614 | // x[i] = b[i]
|
47615 | x[k] = b[k];
|
47616 | }
|
47617 | }
|
47618 |
|
47619 | return x;
|
47620 | }
|
47621 |
|
47622 | return csIpvec;
|
47623 | }
|
47624 |
|
47625 | exports.name = 'csIpvec';
|
47626 | exports.path = 'algebra.sparse';
|
47627 | exports.factory = factory;
|
47628 |
|
47629 | /***/ }),
|
47630 | /* 224 */
|
47631 | /***/ (function(module, exports, __webpack_require__) {
|
47632 |
|
47633 | "use strict";
|
47634 |
|
47635 |
|
47636 | module.exports = [__webpack_require__(25), __webpack_require__(14), __webpack_require__(17), __webpack_require__(225), __webpack_require__(110), __webpack_require__(226), __webpack_require__(45), __webpack_require__(138), __webpack_require__(227), __webpack_require__(228), __webpack_require__(229), __webpack_require__(230), __webpack_require__(109), __webpack_require__(111), __webpack_require__(231), __webpack_require__(232), __webpack_require__(233), __webpack_require__(91), __webpack_require__(235), __webpack_require__(236), __webpack_require__(237), __webpack_require__(238), __webpack_require__(10), __webpack_require__(239), __webpack_require__(240), __webpack_require__(241), __webpack_require__(42), __webpack_require__(67), __webpack_require__(131), __webpack_require__(46), __webpack_require__(242), __webpack_require__(15), __webpack_require__(39), __webpack_require__(243), __webpack_require__(244)];
|
47637 |
|
47638 | /***/ }),
|
47639 | /* 225 */
|
47640 | /***/ (function(module, exports, __webpack_require__) {
|
47641 |
|
47642 | "use strict";
|
47643 |
|
47644 |
|
47645 | var deepMap = __webpack_require__(1);
|
47646 |
|
47647 | function factory(type, config, load, typed) {
|
47648 | var unaryMinus = load(__webpack_require__(39));
|
47649 | var isNegative = load(__webpack_require__(61));
|
47650 | var matrix = load(__webpack_require__(0));
|
47651 | /**
|
47652 | * Calculate the cubic root of a value.
|
47653 | *
|
47654 | * For matrices, the function is evaluated element wise.
|
47655 | *
|
47656 | * Syntax:
|
47657 | *
|
47658 | * math.cbrt(x)
|
47659 | * math.cbrt(x, allRoots)
|
47660 | *
|
47661 | * Examples:
|
47662 | *
|
47663 | * math.cbrt(27) // returns 3
|
47664 | * math.cube(3) // returns 27
|
47665 | * math.cbrt(-64) // returns -4
|
47666 | * math.cbrt(math.unit('27 m^3')) // returns Unit 3 m
|
47667 | * math.cbrt([27, 64, 125]) // returns [3, 4, 5]
|
47668 | *
|
47669 | * const x = math.complex('8i')
|
47670 | * math.cbrt(x) // returns Complex 1.7320508075689 + i
|
47671 | * math.cbrt(x, true) // returns Matrix [
|
47672 | * // 1.7320508075689 + i
|
47673 | * // -1.7320508075689 + i
|
47674 | * // -2i
|
47675 | * // ]
|
47676 | *
|
47677 | * See also:
|
47678 | *
|
47679 | * square, sqrt, cube
|
47680 | *
|
47681 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x
|
47682 | * Value for which to calculate the cubic root.
|
47683 | * @param {boolean} [allRoots] Optional, false by default. Only applicable
|
47684 | * when `x` is a number or complex number. If true, all complex
|
47685 | * roots are returned, if false (default) the principal root is
|
47686 | * returned.
|
47687 | * @return {number | BigNumber | Complex | Unit | Array | Matrix}
|
47688 | * Returns the cubic root of `x`
|
47689 | */
|
47690 |
|
47691 | var cbrt = typed('cbrt', {
|
47692 | 'number': _cbrtNumber,
|
47693 | // note: signature 'number, boolean' is also supported,
|
47694 | // created by typed as it knows how to convert number to Complex
|
47695 | 'Complex': _cbrtComplex,
|
47696 | 'Complex, boolean': _cbrtComplex,
|
47697 | 'BigNumber': function BigNumber(x) {
|
47698 | return x.cbrt();
|
47699 | },
|
47700 | 'Unit': _cbrtUnit,
|
47701 | 'Array | Matrix': function ArrayMatrix(x) {
|
47702 | // deep map collection, skip zeros since cbrt(0) = 0
|
47703 | return deepMap(x, cbrt, true);
|
47704 | }
|
47705 | });
|
47706 | /**
|
47707 | * Calculate the cubic root for a complex number
|
47708 | * @param {Complex} x
|
47709 | * @param {boolean} [allRoots] If true, the function will return an array
|
47710 | * with all three roots. If false or undefined,
|
47711 | * the principal root is returned.
|
47712 | * @returns {Complex | Array.<Complex> | Matrix.<Complex>} Returns the cubic root(s) of x
|
47713 | * @private
|
47714 | */
|
47715 |
|
47716 | function _cbrtComplex(x, allRoots) {
|
47717 | // https://www.wikiwand.com/en/Cube_root#/Complex_numbers
|
47718 | var arg3 = x.arg() / 3;
|
47719 | var abs = x.abs(); // principal root:
|
47720 |
|
47721 | var principal = new type.Complex(_cbrtNumber(abs), 0).mul(new type.Complex(0, arg3).exp());
|
47722 |
|
47723 | if (allRoots) {
|
47724 | var all = [principal, new type.Complex(_cbrtNumber(abs), 0).mul(new type.Complex(0, arg3 + Math.PI * 2 / 3).exp()), new type.Complex(_cbrtNumber(abs), 0).mul(new type.Complex(0, arg3 - Math.PI * 2 / 3).exp())];
|
47725 | return config.matrix === 'Array' ? all : matrix(all);
|
47726 | } else {
|
47727 | return principal;
|
47728 | }
|
47729 | }
|
47730 | /**
|
47731 | * Calculate the cubic root for a Unit
|
47732 | * @param {Unit} x
|
47733 | * @return {Unit} Returns the cubic root of x
|
47734 | * @private
|
47735 | */
|
47736 |
|
47737 |
|
47738 | function _cbrtUnit(x) {
|
47739 | if (x.value && type.isComplex(x.value)) {
|
47740 | var result = x.clone();
|
47741 | result.value = 1.0;
|
47742 | result = result.pow(1.0 / 3); // Compute the units
|
47743 |
|
47744 | result.value = _cbrtComplex(x.value); // Compute the value
|
47745 |
|
47746 | return result;
|
47747 | } else {
|
47748 | var negate = isNegative(x.value);
|
47749 |
|
47750 | if (negate) {
|
47751 | x.value = unaryMinus(x.value);
|
47752 | } // TODO: create a helper function for this
|
47753 |
|
47754 |
|
47755 | var third;
|
47756 |
|
47757 | if (type.isBigNumber(x.value)) {
|
47758 | third = new type.BigNumber(1).div(3);
|
47759 | } else if (type.isFraction(x.value)) {
|
47760 | third = new type.Fraction(1, 3);
|
47761 | } else {
|
47762 | third = 1 / 3;
|
47763 | }
|
47764 |
|
47765 | var _result = x.pow(third);
|
47766 |
|
47767 | if (negate) {
|
47768 | _result.value = unaryMinus(_result.value);
|
47769 | }
|
47770 |
|
47771 | return _result;
|
47772 | }
|
47773 | }
|
47774 |
|
47775 | cbrt.toTex = {
|
47776 | 1: "\\sqrt[3]{${args[0]}}"
|
47777 | };
|
47778 | return cbrt;
|
47779 | }
|
47780 | /**
|
47781 | * Calculate cbrt for a number
|
47782 | *
|
47783 | * Code from es6-shim.js:
|
47784 | * https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L1564-L1577
|
47785 | *
|
47786 | * @param {number} x
|
47787 | * @returns {number | Complex} Returns the cubic root of x
|
47788 | * @private
|
47789 | */
|
47790 |
|
47791 |
|
47792 | var _cbrtNumber = Math.cbrt || function (x) {
|
47793 | if (x === 0) {
|
47794 | return x;
|
47795 | }
|
47796 |
|
47797 | var negate = x < 0;
|
47798 | var result;
|
47799 |
|
47800 | if (negate) {
|
47801 | x = -x;
|
47802 | }
|
47803 |
|
47804 | if (isFinite(x)) {
|
47805 | result = Math.exp(Math.log(x) / 3); // from https://en.wikipedia.org/wiki/Cube_root#Numerical_methods
|
47806 |
|
47807 | result = (x / (result * result) + 2 * result) / 3;
|
47808 | } else {
|
47809 | result = x;
|
47810 | }
|
47811 |
|
47812 | return negate ? -result : result;
|
47813 | };
|
47814 |
|
47815 | exports.name = 'cbrt';
|
47816 | exports.factory = factory;
|
47817 |
|
47818 | /***/ }),
|
47819 | /* 226 */
|
47820 | /***/ (function(module, exports, __webpack_require__) {
|
47821 |
|
47822 | "use strict";
|
47823 |
|
47824 |
|
47825 | var deepMap = __webpack_require__(1);
|
47826 |
|
47827 | function factory(type, config, load, typed) {
|
47828 | /**
|
47829 | * Compute the cube of a value, `x * x * x`.
|
47830 | * For matrices, the function is evaluated element wise.
|
47831 | *
|
47832 | * Syntax:
|
47833 | *
|
47834 | * math.cube(x)
|
47835 | *
|
47836 | * Examples:
|
47837 | *
|
47838 | * math.cube(2) // returns number 8
|
47839 | * math.pow(2, 3) // returns number 8
|
47840 | * math.cube(4) // returns number 64
|
47841 | * 4 * 4 * 4 // returns number 64
|
47842 | *
|
47843 | * math.cube([1, 2, 3, 4]) // returns Array [1, 8, 27, 64]
|
47844 | *
|
47845 | * See also:
|
47846 | *
|
47847 | * multiply, square, pow, cbrt
|
47848 | *
|
47849 | * @param {number | BigNumber | Fraction | Complex | Array | Matrix | Unit} x Number for which to calculate the cube
|
47850 | * @return {number | BigNumber | Fraction | Complex | Array | Matrix | Unit} Cube of x
|
47851 | */
|
47852 | var cube = typed('cube', {
|
47853 | 'number': function number(x) {
|
47854 | return x * x * x;
|
47855 | },
|
47856 | 'Complex': function Complex(x) {
|
47857 | return x.mul(x).mul(x); // Is faster than pow(x, 3)
|
47858 | },
|
47859 | 'BigNumber': function BigNumber(x) {
|
47860 | return x.times(x).times(x);
|
47861 | },
|
47862 | 'Fraction': function Fraction(x) {
|
47863 | return x.pow(3); // Is faster than mul()mul()mul()
|
47864 | },
|
47865 | 'Array | Matrix': function ArrayMatrix(x) {
|
47866 | // deep map collection, skip zeros since cube(0) = 0
|
47867 | return deepMap(x, cube, true);
|
47868 | },
|
47869 | 'Unit': function Unit(x) {
|
47870 | return x.pow(3);
|
47871 | }
|
47872 | });
|
47873 | cube.toTex = {
|
47874 | 1: "\\left(${args[0]}\\right)^3"
|
47875 | };
|
47876 | return cube;
|
47877 | }
|
47878 |
|
47879 | exports.name = 'cube';
|
47880 | exports.factory = factory;
|
47881 |
|
47882 | /***/ }),
|
47883 | /* 227 */
|
47884 | /***/ (function(module, exports, __webpack_require__) {
|
47885 |
|
47886 | "use strict";
|
47887 |
|
47888 |
|
47889 | function factory(type, config, load, typed) {
|
47890 | var matrix = load(__webpack_require__(0));
|
47891 | var multiplyScalar = load(__webpack_require__(21));
|
47892 |
|
47893 | var latex = __webpack_require__(4);
|
47894 |
|
47895 | var algorithm02 = load(__webpack_require__(27));
|
47896 | var algorithm09 = load(__webpack_require__(139));
|
47897 | var algorithm11 = load(__webpack_require__(20));
|
47898 | var algorithm13 = load(__webpack_require__(7));
|
47899 | var algorithm14 = load(__webpack_require__(6));
|
47900 | /**
|
47901 | * Multiply two matrices element wise. The function accepts both matrices and
|
47902 | * scalar values.
|
47903 | *
|
47904 | * Syntax:
|
47905 | *
|
47906 | * math.dotMultiply(x, y)
|
47907 | *
|
47908 | * Examples:
|
47909 | *
|
47910 | * math.dotMultiply(2, 4) // returns 8
|
47911 | *
|
47912 | * a = [[9, 5], [6, 1]]
|
47913 | * b = [[3, 2], [5, 2]]
|
47914 | *
|
47915 | * math.dotMultiply(a, b) // returns [[27, 10], [30, 2]]
|
47916 | * math.multiply(a, b) // returns [[52, 28], [23, 14]]
|
47917 | *
|
47918 | * See also:
|
47919 | *
|
47920 | * multiply, divide, dotDivide
|
47921 | *
|
47922 | * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Left hand value
|
47923 | * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Right hand value
|
47924 | * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} Multiplication of `x` and `y`
|
47925 | */
|
47926 |
|
47927 | var dotMultiply = typed('dotMultiply', {
|
47928 | 'any, any': multiplyScalar,
|
47929 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
47930 | return algorithm09(x, y, multiplyScalar, false);
|
47931 | },
|
47932 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
47933 | return algorithm02(y, x, multiplyScalar, true);
|
47934 | },
|
47935 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
47936 | return algorithm02(x, y, multiplyScalar, false);
|
47937 | },
|
47938 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
47939 | return algorithm13(x, y, multiplyScalar);
|
47940 | },
|
47941 | 'Array, Array': function ArrayArray(x, y) {
|
47942 | // use matrix implementation
|
47943 | return dotMultiply(matrix(x), matrix(y)).valueOf();
|
47944 | },
|
47945 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
47946 | // use matrix implementation
|
47947 | return dotMultiply(matrix(x), y);
|
47948 | },
|
47949 | 'Matrix, Array': function MatrixArray(x, y) {
|
47950 | // use matrix implementation
|
47951 | return dotMultiply(x, matrix(y));
|
47952 | },
|
47953 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
47954 | return algorithm11(x, y, multiplyScalar, false);
|
47955 | },
|
47956 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
47957 | return algorithm14(x, y, multiplyScalar, false);
|
47958 | },
|
47959 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
47960 | return algorithm11(y, x, multiplyScalar, true);
|
47961 | },
|
47962 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
47963 | return algorithm14(y, x, multiplyScalar, true);
|
47964 | },
|
47965 | 'Array, any': function ArrayAny(x, y) {
|
47966 | // use matrix implementation
|
47967 | return algorithm14(matrix(x), y, multiplyScalar, false).valueOf();
|
47968 | },
|
47969 | 'any, Array': function anyArray(x, y) {
|
47970 | // use matrix implementation
|
47971 | return algorithm14(matrix(y), x, multiplyScalar, true).valueOf();
|
47972 | }
|
47973 | });
|
47974 | dotMultiply.toTex = {
|
47975 | 2: "\\left(${args[0]}".concat(latex.operators['dotMultiply'], "${args[1]}\\right)")
|
47976 | };
|
47977 | return dotMultiply;
|
47978 | }
|
47979 |
|
47980 | exports.name = 'dotMultiply';
|
47981 | exports.factory = factory;
|
47982 |
|
47983 | /***/ }),
|
47984 | /* 228 */
|
47985 | /***/ (function(module, exports, __webpack_require__) {
|
47986 |
|
47987 | "use strict";
|
47988 |
|
47989 |
|
47990 | function factory(type, config, load, typed) {
|
47991 | var matrix = load(__webpack_require__(0));
|
47992 | var pow = load(__webpack_require__(42));
|
47993 |
|
47994 | var latex = __webpack_require__(4);
|
47995 |
|
47996 | var algorithm03 = load(__webpack_require__(18));
|
47997 | var algorithm07 = load(__webpack_require__(29));
|
47998 | var algorithm11 = load(__webpack_require__(20));
|
47999 | var algorithm12 = load(__webpack_require__(19));
|
48000 | var algorithm13 = load(__webpack_require__(7));
|
48001 | var algorithm14 = load(__webpack_require__(6));
|
48002 | /**
|
48003 | * Calculates the power of x to y element wise.
|
48004 | *
|
48005 | * Syntax:
|
48006 | *
|
48007 | * math.dotPow(x, y)
|
48008 | *
|
48009 | * Examples:
|
48010 | *
|
48011 | * math.dotPow(2, 3) // returns number 8
|
48012 | *
|
48013 | * const a = [[1, 2], [4, 3]]
|
48014 | * math.dotPow(a, 2) // returns Array [[1, 4], [16, 9]]
|
48015 | * math.pow(a, 2) // returns Array [[9, 8], [16, 17]]
|
48016 | *
|
48017 | * See also:
|
48018 | *
|
48019 | * pow, sqrt, multiply
|
48020 | *
|
48021 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x The base
|
48022 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} y The exponent
|
48023 | * @return {number | BigNumber | Complex | Unit | Array | Matrix} The value of `x` to the power `y`
|
48024 | */
|
48025 |
|
48026 | var dotPow = typed('dotPow', {
|
48027 | 'any, any': pow,
|
48028 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
48029 | return algorithm07(x, y, pow, false);
|
48030 | },
|
48031 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
48032 | return algorithm03(y, x, pow, true);
|
48033 | },
|
48034 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
48035 | return algorithm03(x, y, pow, false);
|
48036 | },
|
48037 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
48038 | return algorithm13(x, y, pow);
|
48039 | },
|
48040 | 'Array, Array': function ArrayArray(x, y) {
|
48041 | // use matrix implementation
|
48042 | return dotPow(matrix(x), matrix(y)).valueOf();
|
48043 | },
|
48044 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
48045 | // use matrix implementation
|
48046 | return dotPow(matrix(x), y);
|
48047 | },
|
48048 | 'Matrix, Array': function MatrixArray(x, y) {
|
48049 | // use matrix implementation
|
48050 | return dotPow(x, matrix(y));
|
48051 | },
|
48052 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
48053 | return algorithm11(x, y, dotPow, false);
|
48054 | },
|
48055 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
48056 | return algorithm14(x, y, dotPow, false);
|
48057 | },
|
48058 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
48059 | return algorithm12(y, x, dotPow, true);
|
48060 | },
|
48061 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
48062 | return algorithm14(y, x, dotPow, true);
|
48063 | },
|
48064 | 'Array, any': function ArrayAny(x, y) {
|
48065 | // use matrix implementation
|
48066 | return algorithm14(matrix(x), y, dotPow, false).valueOf();
|
48067 | },
|
48068 | 'any, Array': function anyArray(x, y) {
|
48069 | // use matrix implementation
|
48070 | return algorithm14(matrix(y), x, dotPow, true).valueOf();
|
48071 | }
|
48072 | });
|
48073 | dotPow.toTex = {
|
48074 | 2: "\\left(${args[0]}".concat(latex.operators['dotPow'], "${args[1]}\\right)")
|
48075 | };
|
48076 | return dotPow;
|
48077 | }
|
48078 |
|
48079 | exports.name = 'dotPow';
|
48080 | exports.factory = factory;
|
48081 |
|
48082 | /***/ }),
|
48083 | /* 229 */
|
48084 | /***/ (function(module, exports, __webpack_require__) {
|
48085 |
|
48086 | "use strict";
|
48087 |
|
48088 |
|
48089 | var deepMap = __webpack_require__(1);
|
48090 |
|
48091 | function factory(type, config, load, typed) {
|
48092 | /**
|
48093 | * Calculate the exponent of a value.
|
48094 | * For matrices, the function is evaluated element wise.
|
48095 | *
|
48096 | * Syntax:
|
48097 | *
|
48098 | * math.exp(x)
|
48099 | *
|
48100 | * Examples:
|
48101 | *
|
48102 | * math.exp(2) // returns number 7.3890560989306495
|
48103 | * math.pow(math.e, 2) // returns number 7.3890560989306495
|
48104 | * math.log(math.exp(2)) // returns number 2
|
48105 | *
|
48106 | * math.exp([1, 2, 3])
|
48107 | * // returns Array [
|
48108 | * // 2.718281828459045,
|
48109 | * // 7.3890560989306495,
|
48110 | * // 20.085536923187668
|
48111 | * // ]
|
48112 | *
|
48113 | * See also:
|
48114 | *
|
48115 | * expm1, log, pow
|
48116 | *
|
48117 | * @param {number | BigNumber | Complex | Array | Matrix} x A number or matrix to exponentiate
|
48118 | * @return {number | BigNumber | Complex | Array | Matrix} Exponent of `x`
|
48119 | */
|
48120 | var exp = typed('exp', {
|
48121 | 'number': Math.exp,
|
48122 | 'Complex': function Complex(x) {
|
48123 | return x.exp();
|
48124 | },
|
48125 | 'BigNumber': function BigNumber(x) {
|
48126 | return x.exp();
|
48127 | },
|
48128 | 'Array | Matrix': function ArrayMatrix(x) {
|
48129 | // TODO: exp(sparse) should return a dense matrix since exp(0)==1
|
48130 | return deepMap(x, exp);
|
48131 | }
|
48132 | });
|
48133 | exp.toTex = {
|
48134 | 1: "\\exp\\left(${args[0]}\\right)"
|
48135 | };
|
48136 | return exp;
|
48137 | }
|
48138 |
|
48139 | exports.name = 'exp';
|
48140 | exports.factory = factory;
|
48141 |
|
48142 | /***/ }),
|
48143 | /* 230 */
|
48144 | /***/ (function(module, exports, __webpack_require__) {
|
48145 |
|
48146 | "use strict";
|
48147 |
|
48148 |
|
48149 | var deepMap = __webpack_require__(1);
|
48150 |
|
48151 | function factory(type, config, load, typed) {
|
48152 | var latex = __webpack_require__(4);
|
48153 | /**
|
48154 | * Calculate the value of subtracting 1 from the exponential value.
|
48155 | * For matrices, the function is evaluated element wise.
|
48156 | *
|
48157 | * Syntax:
|
48158 | *
|
48159 | * math.expm1(x)
|
48160 | *
|
48161 | * Examples:
|
48162 | *
|
48163 | * math.expm1(2) // returns number 6.38905609893065
|
48164 | * math.pow(math.e, 2) - 1 // returns number 6.3890560989306495
|
48165 | * math.log(math.expm1(2) + 1) // returns number 2
|
48166 | *
|
48167 | * math.expm1([1, 2, 3])
|
48168 | * // returns Array [
|
48169 | * // 1.718281828459045,
|
48170 | * // 6.3890560989306495,
|
48171 | * // 19.085536923187668
|
48172 | * // ]
|
48173 | *
|
48174 | * See also:
|
48175 | *
|
48176 | * exp, log, pow
|
48177 | *
|
48178 | * @param {number | BigNumber | Complex | Array | Matrix} x A number or matrix to apply expm1
|
48179 | * @return {number | BigNumber | Complex | Array | Matrix} Exponent of `x`
|
48180 | */
|
48181 |
|
48182 |
|
48183 | var expm1 = typed('expm1', {
|
48184 | 'number': Math.expm1 || _expm1,
|
48185 | 'Complex': function Complex(x) {
|
48186 | var r = Math.exp(x.re);
|
48187 | return new type.Complex(r * Math.cos(x.im) - 1, r * Math.sin(x.im));
|
48188 | },
|
48189 | 'BigNumber': function BigNumber(x) {
|
48190 | return x.exp().minus(1);
|
48191 | },
|
48192 | 'Array | Matrix': function ArrayMatrix(x) {
|
48193 | return deepMap(x, expm1);
|
48194 | }
|
48195 | });
|
48196 | /**
|
48197 | * Calculates exponentiation minus 1.
|
48198 | * @param {number} x
|
48199 | * @return {number} res
|
48200 | * @private
|
48201 | */
|
48202 |
|
48203 | function _expm1(x) {
|
48204 | return x >= 2e-4 || x <= -2e-4 ? Math.exp(x) - 1 : x + x * x / 2 + x * x * x / 6;
|
48205 | }
|
48206 |
|
48207 | expm1.toTex = "\\left(e".concat(latex.operators['pow'], "{${args[0]}}-1\\right)");
|
48208 | return expm1;
|
48209 | }
|
48210 |
|
48211 | exports.name = 'expm1';
|
48212 | exports.factory = factory;
|
48213 |
|
48214 | /***/ }),
|
48215 | /* 231 */
|
48216 | /***/ (function(module, exports, __webpack_require__) {
|
48217 |
|
48218 | "use strict";
|
48219 |
|
48220 |
|
48221 | var isInteger = __webpack_require__(3).isInteger;
|
48222 |
|
48223 | function factory(type, config, load, typed) {
|
48224 | var matrix = load(__webpack_require__(0));
|
48225 | var algorithm01 = load(__webpack_require__(37));
|
48226 | var algorithm04 = load(__webpack_require__(85));
|
48227 | var algorithm10 = load(__webpack_require__(41));
|
48228 | var algorithm13 = load(__webpack_require__(7));
|
48229 | var algorithm14 = load(__webpack_require__(6));
|
48230 | /**
|
48231 | * Calculate the greatest common divisor for two or more values or arrays.
|
48232 | *
|
48233 | * For matrices, the function is evaluated element wise.
|
48234 | *
|
48235 | * Syntax:
|
48236 | *
|
48237 | * math.gcd(a, b)
|
48238 | * math.gcd(a, b, c, ...)
|
48239 | *
|
48240 | * Examples:
|
48241 | *
|
48242 | * math.gcd(8, 12) // returns 4
|
48243 | * math.gcd(-4, 6) // returns 2
|
48244 | * math.gcd(25, 15, -10) // returns 5
|
48245 | *
|
48246 | * math.gcd([8, -4], [12, 6]) // returns [4, 2]
|
48247 | *
|
48248 | * See also:
|
48249 | *
|
48250 | * lcm, xgcd
|
48251 | *
|
48252 | * @param {... number | BigNumber | Fraction | Array | Matrix} args Two or more integer numbers
|
48253 | * @return {number | BigNumber | Fraction | Array | Matrix} The greatest common divisor
|
48254 | */
|
48255 |
|
48256 | var gcd = typed('gcd', {
|
48257 | 'number, number': _gcd,
|
48258 | 'BigNumber, BigNumber': _gcdBigNumber,
|
48259 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
48260 | return x.gcd(y);
|
48261 | },
|
48262 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
48263 | return algorithm04(x, y, gcd);
|
48264 | },
|
48265 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
48266 | return algorithm01(y, x, gcd, true);
|
48267 | },
|
48268 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
48269 | return algorithm01(x, y, gcd, false);
|
48270 | },
|
48271 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
48272 | return algorithm13(x, y, gcd);
|
48273 | },
|
48274 | 'Array, Array': function ArrayArray(x, y) {
|
48275 | // use matrix implementation
|
48276 | return gcd(matrix(x), matrix(y)).valueOf();
|
48277 | },
|
48278 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
48279 | // use matrix implementation
|
48280 | return gcd(matrix(x), y);
|
48281 | },
|
48282 | 'Matrix, Array': function MatrixArray(x, y) {
|
48283 | // use matrix implementation
|
48284 | return gcd(x, matrix(y));
|
48285 | },
|
48286 | 'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
48287 | return algorithm10(x, y, gcd, false);
|
48288 | },
|
48289 | 'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
48290 | return algorithm14(x, y, gcd, false);
|
48291 | },
|
48292 | 'number | BigNumber, SparseMatrix': function numberBigNumberSparseMatrix(x, y) {
|
48293 | return algorithm10(y, x, gcd, true);
|
48294 | },
|
48295 | 'number | BigNumber, DenseMatrix': function numberBigNumberDenseMatrix(x, y) {
|
48296 | return algorithm14(y, x, gcd, true);
|
48297 | },
|
48298 | 'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
|
48299 | // use matrix implementation
|
48300 | return algorithm14(matrix(x), y, gcd, false).valueOf();
|
48301 | },
|
48302 | 'number | BigNumber, Array': function numberBigNumberArray(x, y) {
|
48303 | // use matrix implementation
|
48304 | return algorithm14(matrix(y), x, gcd, true).valueOf();
|
48305 | },
|
48306 | // TODO: need a smarter notation here
|
48307 | 'Array | Matrix | number | BigNumber, Array | Matrix | number | BigNumber, ...Array | Matrix | number | BigNumber': function ArrayMatrixNumberBigNumberArrayMatrixNumberBigNumberArrayMatrixNumberBigNumber(a, b, args) {
|
48308 | var res = gcd(a, b);
|
48309 |
|
48310 | for (var i = 0; i < args.length; i++) {
|
48311 | res = gcd(res, args[i]);
|
48312 | }
|
48313 |
|
48314 | return res;
|
48315 | }
|
48316 | });
|
48317 | gcd.toTex = "\\gcd\\left(${args}\\right)";
|
48318 | return gcd;
|
48319 | /**
|
48320 | * Calculate gcd for BigNumbers
|
48321 | * @param {BigNumber} a
|
48322 | * @param {BigNumber} b
|
48323 | * @returns {BigNumber} Returns greatest common denominator of a and b
|
48324 | * @private
|
48325 | */
|
48326 |
|
48327 | function _gcdBigNumber(a, b) {
|
48328 | if (!a.isInt() || !b.isInt()) {
|
48329 | throw new Error('Parameters in function gcd must be integer numbers');
|
48330 | } // https://en.wikipedia.org/wiki/Euclidean_algorithm
|
48331 |
|
48332 |
|
48333 | var zero = new type.BigNumber(0);
|
48334 |
|
48335 | while (!b.isZero()) {
|
48336 | var r = a.mod(b);
|
48337 | a = b;
|
48338 | b = r;
|
48339 | }
|
48340 |
|
48341 | return a.lt(zero) ? a.neg() : a;
|
48342 | }
|
48343 | }
|
48344 | /**
|
48345 | * Calculate gcd for numbers
|
48346 | * @param {number} a
|
48347 | * @param {number} b
|
48348 | * @returns {number} Returns the greatest common denominator of a and b
|
48349 | * @private
|
48350 | */
|
48351 |
|
48352 |
|
48353 | function _gcd(a, b) {
|
48354 | if (!isInteger(a) || !isInteger(b)) {
|
48355 | throw new Error('Parameters in function gcd must be integer numbers');
|
48356 | } // https://en.wikipedia.org/wiki/Euclidean_algorithm
|
48357 |
|
48358 |
|
48359 | var r;
|
48360 |
|
48361 | while (b !== 0) {
|
48362 | r = a % b;
|
48363 | a = b;
|
48364 | b = r;
|
48365 | }
|
48366 |
|
48367 | return a < 0 ? -a : a;
|
48368 | }
|
48369 |
|
48370 | exports.name = 'gcd';
|
48371 | exports.factory = factory;
|
48372 |
|
48373 | /***/ }),
|
48374 | /* 232 */
|
48375 | /***/ (function(module, exports, __webpack_require__) {
|
48376 |
|
48377 | "use strict";
|
48378 |
|
48379 |
|
48380 | var flatten = __webpack_require__(2).flatten;
|
48381 |
|
48382 | function factory(type, config, load, typed) {
|
48383 | var abs = load(__webpack_require__(25));
|
48384 | var add = load(__webpack_require__(17));
|
48385 | var divide = load(__webpack_require__(12));
|
48386 | var multiply = load(__webpack_require__(21));
|
48387 | var sqrt = load(__webpack_require__(46));
|
48388 | var smaller = load(__webpack_require__(38));
|
48389 | var isPositive = load(__webpack_require__(73));
|
48390 | /**
|
48391 | * Calculate the hypotenusa of a list with values. The hypotenusa is defined as:
|
48392 | *
|
48393 | * hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...)
|
48394 | *
|
48395 | * For matrix input, the hypotenusa is calculated for all values in the matrix.
|
48396 | *
|
48397 | * Syntax:
|
48398 | *
|
48399 | * math.hypot(a, b, ...)
|
48400 | * math.hypot([a, b, c, ...])
|
48401 | *
|
48402 | * Examples:
|
48403 | *
|
48404 | * math.hypot(3, 4) // 5
|
48405 | * math.hypot(3, 4, 5) // 7.0710678118654755
|
48406 | * math.hypot([3, 4, 5]) // 7.0710678118654755
|
48407 | * math.hypot(-2) // 2
|
48408 | *
|
48409 | * See also:
|
48410 | *
|
48411 | * abs, norm
|
48412 | *
|
48413 | * @param {... number | BigNumber | Array | Matrix} args A list with numeric values or an Array or Matrix.
|
48414 | * Matrix and Array input is flattened and returns a
|
48415 | * single number for the whole matrix.
|
48416 | * @return {number | BigNumber} Returns the hypothenusa of the input values.
|
48417 | */
|
48418 |
|
48419 | var hypot = typed('hypot', {
|
48420 | '... number | BigNumber': _hypot,
|
48421 | 'Array': function Array(x) {
|
48422 | return hypot.apply(hypot, flatten(x));
|
48423 | },
|
48424 | 'Matrix': function Matrix(x) {
|
48425 | return hypot.apply(hypot, flatten(x.toArray()));
|
48426 | }
|
48427 | });
|
48428 | /**
|
48429 | * Calculate the hypotenusa for an Array with values
|
48430 | * @param {Array.<number | BigNumber>} args
|
48431 | * @return {number | BigNumber} Returns the result
|
48432 | * @private
|
48433 | */
|
48434 |
|
48435 | function _hypot(args) {
|
48436 | // code based on `hypot` from es6-shim:
|
48437 | // https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L1619-L1633
|
48438 | var result = 0;
|
48439 | var largest = 0;
|
48440 |
|
48441 | for (var i = 0; i < args.length; i++) {
|
48442 | var value = abs(args[i]);
|
48443 |
|
48444 | if (smaller(largest, value)) {
|
48445 | result = multiply(result, multiply(divide(largest, value), divide(largest, value)));
|
48446 | result = add(result, 1);
|
48447 | largest = value;
|
48448 | } else {
|
48449 | result = add(result, isPositive(value) ? multiply(divide(value, largest), divide(value, largest)) : value);
|
48450 | }
|
48451 | }
|
48452 |
|
48453 | return multiply(largest, sqrt(result));
|
48454 | }
|
48455 |
|
48456 | hypot.toTex = "\\hypot\\left(${args}\\right)";
|
48457 | return hypot;
|
48458 | }
|
48459 |
|
48460 | exports.name = 'hypot';
|
48461 | exports.factory = factory;
|
48462 |
|
48463 | /***/ }),
|
48464 | /* 233 */
|
48465 | /***/ (function(module, exports, __webpack_require__) {
|
48466 |
|
48467 | "use strict";
|
48468 |
|
48469 |
|
48470 | var isInteger = __webpack_require__(3).isInteger;
|
48471 |
|
48472 | function factory(type, config, load, typed) {
|
48473 | var matrix = load(__webpack_require__(0));
|
48474 | var algorithm02 = load(__webpack_require__(27));
|
48475 | var algorithm06 = load(__webpack_require__(74));
|
48476 | var algorithm11 = load(__webpack_require__(20));
|
48477 | var algorithm13 = load(__webpack_require__(7));
|
48478 | var algorithm14 = load(__webpack_require__(6));
|
48479 | /**
|
48480 | * Calculate the least common multiple for two or more values or arrays.
|
48481 | *
|
48482 | * lcm is defined as:
|
48483 | *
|
48484 | * lcm(a, b) = abs(a * b) / gcd(a, b)
|
48485 | *
|
48486 | * For matrices, the function is evaluated element wise.
|
48487 | *
|
48488 | * Syntax:
|
48489 | *
|
48490 | * math.lcm(a, b)
|
48491 | * math.lcm(a, b, c, ...)
|
48492 | *
|
48493 | * Examples:
|
48494 | *
|
48495 | * math.lcm(4, 6) // returns 12
|
48496 | * math.lcm(6, 21) // returns 42
|
48497 | * math.lcm(6, 21, 5) // returns 210
|
48498 | *
|
48499 | * math.lcm([4, 6], [6, 21]) // returns [12, 42]
|
48500 | *
|
48501 | * See also:
|
48502 | *
|
48503 | * gcd, xgcd
|
48504 | *
|
48505 | * @param {... number | BigNumber | Array | Matrix} args Two or more integer numbers
|
48506 | * @return {number | BigNumber | Array | Matrix} The least common multiple
|
48507 | */
|
48508 |
|
48509 | var lcm = typed('lcm', {
|
48510 | 'number, number': _lcm,
|
48511 | 'BigNumber, BigNumber': _lcmBigNumber,
|
48512 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
48513 | return x.lcm(y);
|
48514 | },
|
48515 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
48516 | return algorithm06(x, y, lcm);
|
48517 | },
|
48518 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
48519 | return algorithm02(y, x, lcm, true);
|
48520 | },
|
48521 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
48522 | return algorithm02(x, y, lcm, false);
|
48523 | },
|
48524 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
48525 | return algorithm13(x, y, lcm);
|
48526 | },
|
48527 | 'Array, Array': function ArrayArray(x, y) {
|
48528 | // use matrix implementation
|
48529 | return lcm(matrix(x), matrix(y)).valueOf();
|
48530 | },
|
48531 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
48532 | // use matrix implementation
|
48533 | return lcm(matrix(x), y);
|
48534 | },
|
48535 | 'Matrix, Array': function MatrixArray(x, y) {
|
48536 | // use matrix implementation
|
48537 | return lcm(x, matrix(y));
|
48538 | },
|
48539 | 'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
48540 | return algorithm11(x, y, lcm, false);
|
48541 | },
|
48542 | 'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
48543 | return algorithm14(x, y, lcm, false);
|
48544 | },
|
48545 | 'number | BigNumber, SparseMatrix': function numberBigNumberSparseMatrix(x, y) {
|
48546 | return algorithm11(y, x, lcm, true);
|
48547 | },
|
48548 | 'number | BigNumber, DenseMatrix': function numberBigNumberDenseMatrix(x, y) {
|
48549 | return algorithm14(y, x, lcm, true);
|
48550 | },
|
48551 | 'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
|
48552 | // use matrix implementation
|
48553 | return algorithm14(matrix(x), y, lcm, false).valueOf();
|
48554 | },
|
48555 | 'number | BigNumber, Array': function numberBigNumberArray(x, y) {
|
48556 | // use matrix implementation
|
48557 | return algorithm14(matrix(y), x, lcm, true).valueOf();
|
48558 | },
|
48559 | // TODO: need a smarter notation here
|
48560 | 'Array | Matrix | number | BigNumber, Array | Matrix | number | BigNumber, ...Array | Matrix | number | BigNumber': function ArrayMatrixNumberBigNumberArrayMatrixNumberBigNumberArrayMatrixNumberBigNumber(a, b, args) {
|
48561 | var res = lcm(a, b);
|
48562 |
|
48563 | for (var i = 0; i < args.length; i++) {
|
48564 | res = lcm(res, args[i]);
|
48565 | }
|
48566 |
|
48567 | return res;
|
48568 | }
|
48569 | });
|
48570 | lcm.toTex = undefined; // use default template
|
48571 |
|
48572 | return lcm;
|
48573 | /**
|
48574 | * Calculate lcm for two BigNumbers
|
48575 | * @param {BigNumber} a
|
48576 | * @param {BigNumber} b
|
48577 | * @returns {BigNumber} Returns the least common multiple of a and b
|
48578 | * @private
|
48579 | */
|
48580 |
|
48581 | function _lcmBigNumber(a, b) {
|
48582 | if (!a.isInt() || !b.isInt()) {
|
48583 | throw new Error('Parameters in function lcm must be integer numbers');
|
48584 | }
|
48585 |
|
48586 | if (a.isZero() || b.isZero()) {
|
48587 | return new type.BigNumber(0);
|
48588 | } // https://en.wikipedia.org/wiki/Euclidean_algorithm
|
48589 | // evaluate lcm here inline to reduce overhead
|
48590 |
|
48591 |
|
48592 | var prod = a.times(b);
|
48593 |
|
48594 | while (!b.isZero()) {
|
48595 | var t = b;
|
48596 | b = a.mod(t);
|
48597 | a = t;
|
48598 | }
|
48599 |
|
48600 | return prod.div(a).abs();
|
48601 | }
|
48602 | }
|
48603 | /**
|
48604 | * Calculate lcm for two numbers
|
48605 | * @param {number} a
|
48606 | * @param {number} b
|
48607 | * @returns {number} Returns the least common multiple of a and b
|
48608 | * @private
|
48609 | */
|
48610 |
|
48611 |
|
48612 | function _lcm(a, b) {
|
48613 | if (!isInteger(a) || !isInteger(b)) {
|
48614 | throw new Error('Parameters in function lcm must be integer numbers');
|
48615 | }
|
48616 |
|
48617 | if (a === 0 || b === 0) {
|
48618 | return 0;
|
48619 | } // https://en.wikipedia.org/wiki/Euclidean_algorithm
|
48620 | // evaluate lcm here inline to reduce overhead
|
48621 |
|
48622 |
|
48623 | var t;
|
48624 | var prod = a * b;
|
48625 |
|
48626 | while (b !== 0) {
|
48627 | t = b;
|
48628 | b = a % t;
|
48629 | a = t;
|
48630 | }
|
48631 |
|
48632 | return Math.abs(prod / a);
|
48633 | }
|
48634 |
|
48635 | exports.name = 'lcm';
|
48636 | exports.factory = factory;
|
48637 |
|
48638 | /***/ }),
|
48639 | /* 234 */
|
48640 | /***/ (function(module, exports, __webpack_require__) {
|
48641 |
|
48642 | "use strict";
|
48643 |
|
48644 |
|
48645 | module.exports = function scatter(a, j, w, x, u, mark, c, f, inverse, update, value) {
|
48646 | // a arrays
|
48647 | var avalues = a._values;
|
48648 | var aindex = a._index;
|
48649 | var aptr = a._ptr; // c arrays
|
48650 |
|
48651 | var cindex = c._index; // vars
|
48652 |
|
48653 | var k, k0, k1, i; // check we need to process values (pattern matrix)
|
48654 |
|
48655 | if (x) {
|
48656 | // values in j
|
48657 | for (k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
|
48658 | // row
|
48659 | i = aindex[k]; // check value exists in current j
|
48660 |
|
48661 | if (w[i] !== mark) {
|
48662 | // i is new entry in j
|
48663 | w[i] = mark; // add i to pattern of C
|
48664 |
|
48665 | cindex.push(i); // x(i) = A, check we need to call function this time
|
48666 |
|
48667 | if (update) {
|
48668 | // copy value to workspace calling callback function
|
48669 | x[i] = inverse ? f(avalues[k], value) : f(value, avalues[k]); // function was called on current row
|
48670 |
|
48671 | u[i] = mark;
|
48672 | } else {
|
48673 | // copy value to workspace
|
48674 | x[i] = avalues[k];
|
48675 | }
|
48676 | } else {
|
48677 | // i exists in C already
|
48678 | x[i] = inverse ? f(avalues[k], x[i]) : f(x[i], avalues[k]); // function was called on current row
|
48679 |
|
48680 | u[i] = mark;
|
48681 | }
|
48682 | }
|
48683 | } else {
|
48684 | // values in j
|
48685 | for (k0 = aptr[j], k1 = aptr[j + 1], k = k0; k < k1; k++) {
|
48686 | // row
|
48687 | i = aindex[k]; // check value exists in current j
|
48688 |
|
48689 | if (w[i] !== mark) {
|
48690 | // i is new entry in j
|
48691 | w[i] = mark; // add i to pattern of C
|
48692 |
|
48693 | cindex.push(i);
|
48694 | } else {
|
48695 | // indicate function was called on current row
|
48696 | u[i] = mark;
|
48697 | }
|
48698 | }
|
48699 | }
|
48700 | };
|
48701 |
|
48702 | /***/ }),
|
48703 | /* 235 */
|
48704 | /***/ (function(module, exports, __webpack_require__) {
|
48705 |
|
48706 | "use strict";
|
48707 |
|
48708 |
|
48709 | var deepMap = __webpack_require__(1);
|
48710 |
|
48711 | function factory(type, config, load, typed) {
|
48712 | /**
|
48713 | * Calculate the 10-base logarithm of a value. This is the same as calculating `log(x, 10)`.
|
48714 | *
|
48715 | * For matrices, the function is evaluated element wise.
|
48716 | *
|
48717 | * Syntax:
|
48718 | *
|
48719 | * math.log10(x)
|
48720 | *
|
48721 | * Examples:
|
48722 | *
|
48723 | * math.log10(0.00001) // returns -5
|
48724 | * math.log10(10000) // returns 4
|
48725 | * math.log(10000) / math.log(10) // returns 4
|
48726 | * math.pow(10, 4) // returns 10000
|
48727 | *
|
48728 | * See also:
|
48729 | *
|
48730 | * exp, log, log1p, log2
|
48731 | *
|
48732 | * @param {number | BigNumber | Complex | Array | Matrix} x
|
48733 | * Value for which to calculate the logarithm.
|
48734 | * @return {number | BigNumber | Complex | Array | Matrix}
|
48735 | * Returns the 10-base logarithm of `x`
|
48736 | */
|
48737 | var log10 = typed('log10', {
|
48738 | 'number': function number(x) {
|
48739 | if (x >= 0 || config.predictable) {
|
48740 | return _log10(x);
|
48741 | } else {
|
48742 | // negative value -> complex value computation
|
48743 | return new type.Complex(x, 0).log().div(Math.LN10);
|
48744 | }
|
48745 | },
|
48746 | 'Complex': function Complex(x) {
|
48747 | return new type.Complex(x).log().div(Math.LN10);
|
48748 | },
|
48749 | 'BigNumber': function BigNumber(x) {
|
48750 | if (!x.isNegative() || config.predictable) {
|
48751 | return x.log();
|
48752 | } else {
|
48753 | // downgrade to number, return Complex valued result
|
48754 | return new type.Complex(x.toNumber(), 0).log().div(Math.LN10);
|
48755 | }
|
48756 | },
|
48757 | 'Array | Matrix': function ArrayMatrix(x) {
|
48758 | return deepMap(x, log10);
|
48759 | }
|
48760 | });
|
48761 | log10.toTex = {
|
48762 | 1: "\\log_{10}\\left(${args[0]}\\right)"
|
48763 | };
|
48764 | return log10;
|
48765 | }
|
48766 | /**
|
48767 | * Calculate the 10-base logarithm of a number
|
48768 | * @param {number} x
|
48769 | * @return {number}
|
48770 | * @private
|
48771 | */
|
48772 |
|
48773 |
|
48774 | var _log10 = Math.log10 || function (x) {
|
48775 | return Math.log(x) / Math.LN10;
|
48776 | };
|
48777 |
|
48778 | exports.name = 'log10';
|
48779 | exports.factory = factory;
|
48780 |
|
48781 | /***/ }),
|
48782 | /* 236 */
|
48783 | /***/ (function(module, exports, __webpack_require__) {
|
48784 |
|
48785 | "use strict";
|
48786 |
|
48787 |
|
48788 | var deepMap = __webpack_require__(1);
|
48789 |
|
48790 | function factory(type, config, load, typed) {
|
48791 | var divideScalar = load(__webpack_require__(12));
|
48792 | var log = load(__webpack_require__(91));
|
48793 | /**
|
48794 | * Calculate the logarithm of a `value+1`.
|
48795 | *
|
48796 | * For matrices, the function is evaluated element wise.
|
48797 | *
|
48798 | * Syntax:
|
48799 | *
|
48800 | * math.log1p(x)
|
48801 | * math.log1p(x, base)
|
48802 | *
|
48803 | * Examples:
|
48804 | *
|
48805 | * math.log1p(2.5) // returns 1.252762968495368
|
48806 | * math.exp(math.log1p(1.4)) // returns 2.4
|
48807 | *
|
48808 | * math.pow(10, 4) // returns 10000
|
48809 | * math.log1p(9999, 10) // returns 4
|
48810 | * math.log1p(9999) / math.log(10) // returns 4
|
48811 | *
|
48812 | * See also:
|
48813 | *
|
48814 | * exp, log, log2, log10
|
48815 | *
|
48816 | * @param {number | BigNumber | Complex | Array | Matrix} x
|
48817 | * Value for which to calculate the logarithm of `x+1`.
|
48818 | * @param {number | BigNumber | Complex} [base=e]
|
48819 | * Optional base for the logarithm. If not provided, the natural
|
48820 | * logarithm of `x+1` is calculated.
|
48821 | * @return {number | BigNumber | Complex | Array | Matrix}
|
48822 | * Returns the logarithm of `x+1`
|
48823 | */
|
48824 |
|
48825 | var log1p = typed('log1p', {
|
48826 | 'number': _log1pNumber,
|
48827 | 'Complex': _log1pComplex,
|
48828 | 'BigNumber': function BigNumber(x) {
|
48829 | var y = x.plus(1);
|
48830 |
|
48831 | if (!y.isNegative() || config.predictable) {
|
48832 | return y.ln();
|
48833 | } else {
|
48834 | // downgrade to number, return Complex valued result
|
48835 | return _log1pComplex(new type.Complex(x.toNumber(), 0));
|
48836 | }
|
48837 | },
|
48838 | 'Array | Matrix': function ArrayMatrix(x) {
|
48839 | return deepMap(x, log1p);
|
48840 | },
|
48841 | 'any, any': function anyAny(x, base) {
|
48842 | // calculate logarithm for a specified base, log1p(x, base)
|
48843 | return divideScalar(log1p(x), log(base));
|
48844 | }
|
48845 | });
|
48846 | /**
|
48847 | * Calculate the natural logarithm of a `number+1`
|
48848 | * @param {number} x
|
48849 | * @returns {number | Complex}
|
48850 | * @private
|
48851 | */
|
48852 |
|
48853 | function _log1pNumber(x) {
|
48854 | if (x >= -1 || config.predictable) {
|
48855 | return Math.log1p ? Math.log1p(x) : Math.log(x + 1);
|
48856 | } else {
|
48857 | // negative value -> complex value computation
|
48858 | return _log1pComplex(new type.Complex(x, 0));
|
48859 | }
|
48860 | }
|
48861 | /**
|
48862 | * Calculate the natural logarithm of a complex number + 1
|
48863 | * @param {Complex} x
|
48864 | * @returns {Complex}
|
48865 | * @private
|
48866 | */
|
48867 |
|
48868 |
|
48869 | function _log1pComplex(x) {
|
48870 | var xRe1p = x.re + 1;
|
48871 | return new type.Complex(Math.log(Math.sqrt(xRe1p * xRe1p + x.im * x.im)), Math.atan2(x.im, xRe1p));
|
48872 | }
|
48873 |
|
48874 | log1p.toTex = {
|
48875 | 1: "\\ln\\left(${args[0]}+1\\right)",
|
48876 | 2: "\\log_{${args[1]}}\\left(${args[0]}+1\\right)"
|
48877 | };
|
48878 | return log1p;
|
48879 | }
|
48880 |
|
48881 | exports.name = 'log1p';
|
48882 | exports.factory = factory;
|
48883 |
|
48884 | /***/ }),
|
48885 | /* 237 */
|
48886 | /***/ (function(module, exports, __webpack_require__) {
|
48887 |
|
48888 | "use strict";
|
48889 |
|
48890 |
|
48891 | var deepMap = __webpack_require__(1);
|
48892 |
|
48893 | function factory(type, config, load, typed) {
|
48894 | /**
|
48895 | * Calculate the 2-base of a value. This is the same as calculating `log(x, 2)`.
|
48896 | *
|
48897 | * For matrices, the function is evaluated element wise.
|
48898 | *
|
48899 | * Syntax:
|
48900 | *
|
48901 | * math.log2(x)
|
48902 | *
|
48903 | * Examples:
|
48904 | *
|
48905 | * math.log2(0.03125) // returns -5
|
48906 | * math.log2(16) // returns 4
|
48907 | * math.log2(16) / math.log2(2) // returns 4
|
48908 | * math.pow(2, 4) // returns 16
|
48909 | *
|
48910 | * See also:
|
48911 | *
|
48912 | * exp, log, log1p, log10
|
48913 | *
|
48914 | * @param {number | BigNumber | Complex | Array | Matrix} x
|
48915 | * Value for which to calculate the logarithm.
|
48916 | * @return {number | BigNumber | Complex | Array | Matrix}
|
48917 | * Returns the 2-base logarithm of `x`
|
48918 | */
|
48919 | var log2 = typed('log2', {
|
48920 | 'number': function number(x) {
|
48921 | if (x >= 0 || config.predictable) {
|
48922 | return Math.log2 ? Math.log2(x) : Math.log(x) / Math.LN2;
|
48923 | } else {
|
48924 | // negative value -> complex value computation
|
48925 | return _log2Complex(new type.Complex(x, 0));
|
48926 | }
|
48927 | },
|
48928 | 'Complex': _log2Complex,
|
48929 | 'BigNumber': function BigNumber(x) {
|
48930 | if (!x.isNegative() || config.predictable) {
|
48931 | return x.log(2);
|
48932 | } else {
|
48933 | // downgrade to number, return Complex valued result
|
48934 | return _log2Complex(new type.Complex(x.toNumber(), 0));
|
48935 | }
|
48936 | },
|
48937 | 'Array | Matrix': function ArrayMatrix(x) {
|
48938 | return deepMap(x, log2);
|
48939 | }
|
48940 | });
|
48941 | /**
|
48942 | * Calculate log2 for a complex value
|
48943 | * @param {Complex} x
|
48944 | * @returns {Complex}
|
48945 | * @private
|
48946 | */
|
48947 |
|
48948 | function _log2Complex(x) {
|
48949 | var newX = Math.sqrt(x.re * x.re + x.im * x.im);
|
48950 | return new type.Complex(Math.log2 ? Math.log2(newX) : Math.log(newX) / Math.LN2, Math.atan2(x.im, x.re) / Math.LN2);
|
48951 | }
|
48952 |
|
48953 | log2.toTex = "\\log_{2}\\left(${args[0]}\\right)";
|
48954 | return log2;
|
48955 | }
|
48956 |
|
48957 | exports.name = 'log2';
|
48958 | exports.factory = factory;
|
48959 |
|
48960 | /***/ }),
|
48961 | /* 238 */
|
48962 | /***/ (function(module, exports, __webpack_require__) {
|
48963 |
|
48964 | "use strict";
|
48965 |
|
48966 |
|
48967 | function factory(type, config, load, typed) {
|
48968 | var matrix = load(__webpack_require__(0));
|
48969 |
|
48970 | var latex = __webpack_require__(4);
|
48971 |
|
48972 | var algorithm02 = load(__webpack_require__(27));
|
48973 | var algorithm03 = load(__webpack_require__(18));
|
48974 | var algorithm05 = load(__webpack_require__(66));
|
48975 | var algorithm11 = load(__webpack_require__(20));
|
48976 | var algorithm12 = load(__webpack_require__(19));
|
48977 | var algorithm13 = load(__webpack_require__(7));
|
48978 | var algorithm14 = load(__webpack_require__(6));
|
48979 | /**
|
48980 | * Calculates the modulus, the remainder of an integer division.
|
48981 | *
|
48982 | * For matrices, the function is evaluated element wise.
|
48983 | *
|
48984 | * The modulus is defined as:
|
48985 | *
|
48986 | * x - y * floor(x / y)
|
48987 | *
|
48988 | * See https://en.wikipedia.org/wiki/Modulo_operation.
|
48989 | *
|
48990 | * Syntax:
|
48991 | *
|
48992 | * math.mod(x, y)
|
48993 | *
|
48994 | * Examples:
|
48995 | *
|
48996 | * math.mod(8, 3) // returns 2
|
48997 | * math.mod(11, 2) // returns 1
|
48998 | *
|
48999 | * function isOdd(x) {
|
49000 | * return math.mod(x, 2) != 0
|
49001 | * }
|
49002 | *
|
49003 | * isOdd(2) // returns false
|
49004 | * isOdd(3) // returns true
|
49005 | *
|
49006 | * See also:
|
49007 | *
|
49008 | * divide
|
49009 | *
|
49010 | * @param {number | BigNumber | Fraction | Array | Matrix} x Dividend
|
49011 | * @param {number | BigNumber | Fraction | Array | Matrix} y Divisor
|
49012 | * @return {number | BigNumber | Fraction | Array | Matrix} Returns the remainder of `x` divided by `y`.
|
49013 | */
|
49014 |
|
49015 | var mod = typed('mod', {
|
49016 | 'number, number': _mod,
|
49017 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
49018 | return y.isZero() ? x : x.mod(y);
|
49019 | },
|
49020 | 'Fraction, Fraction': function FractionFraction(x, y) {
|
49021 | return x.mod(y);
|
49022 | },
|
49023 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
49024 | return algorithm05(x, y, mod, false);
|
49025 | },
|
49026 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
49027 | return algorithm02(y, x, mod, true);
|
49028 | },
|
49029 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
49030 | return algorithm03(x, y, mod, false);
|
49031 | },
|
49032 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
49033 | return algorithm13(x, y, mod);
|
49034 | },
|
49035 | 'Array, Array': function ArrayArray(x, y) {
|
49036 | // use matrix implementation
|
49037 | return mod(matrix(x), matrix(y)).valueOf();
|
49038 | },
|
49039 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
49040 | // use matrix implementation
|
49041 | return mod(matrix(x), y);
|
49042 | },
|
49043 | 'Matrix, Array': function MatrixArray(x, y) {
|
49044 | // use matrix implementation
|
49045 | return mod(x, matrix(y));
|
49046 | },
|
49047 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
49048 | return algorithm11(x, y, mod, false);
|
49049 | },
|
49050 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
49051 | return algorithm14(x, y, mod, false);
|
49052 | },
|
49053 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
49054 | return algorithm12(y, x, mod, true);
|
49055 | },
|
49056 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
49057 | return algorithm14(y, x, mod, true);
|
49058 | },
|
49059 | 'Array, any': function ArrayAny(x, y) {
|
49060 | // use matrix implementation
|
49061 | return algorithm14(matrix(x), y, mod, false).valueOf();
|
49062 | },
|
49063 | 'any, Array': function anyArray(x, y) {
|
49064 | // use matrix implementation
|
49065 | return algorithm14(matrix(y), x, mod, true).valueOf();
|
49066 | }
|
49067 | });
|
49068 | mod.toTex = {
|
49069 | 2: "\\left(${args[0]}".concat(latex.operators['mod'], "${args[1]}\\right)")
|
49070 | };
|
49071 | return mod;
|
49072 | /**
|
49073 | * Calculate the modulus of two numbers
|
49074 | * @param {number} x
|
49075 | * @param {number} y
|
49076 | * @returns {number} res
|
49077 | * @private
|
49078 | */
|
49079 |
|
49080 | function _mod(x, y) {
|
49081 | if (y > 0) {
|
49082 | // We don't use JavaScript's % operator here as this doesn't work
|
49083 | // correctly for x < 0 and x === 0
|
49084 | // see https://en.wikipedia.org/wiki/Modulo_operation
|
49085 | return x - y * Math.floor(x / y);
|
49086 | } else if (y === 0) {
|
49087 | return x;
|
49088 | } else {
|
49089 | // y < 0
|
49090 | // TODO: implement mod for a negative divisor
|
49091 | throw new Error('Cannot calculate mod for a negative divisor');
|
49092 | }
|
49093 | }
|
49094 | }
|
49095 |
|
49096 | exports.name = 'mod';
|
49097 | exports.factory = factory;
|
49098 |
|
49099 | /***/ }),
|
49100 | /* 239 */
|
49101 | /***/ (function(module, exports, __webpack_require__) {
|
49102 |
|
49103 | "use strict";
|
49104 |
|
49105 |
|
49106 | function factory(type, config, load, typed) {
|
49107 | var abs = load(__webpack_require__(25));
|
49108 | var add = load(__webpack_require__(14));
|
49109 | var pow = load(__webpack_require__(42));
|
49110 | var conj = load(__webpack_require__(71));
|
49111 | var sqrt = load(__webpack_require__(46));
|
49112 | var multiply = load(__webpack_require__(10));
|
49113 | var equalScalar = load(__webpack_require__(11));
|
49114 | var larger = load(__webpack_require__(33));
|
49115 | var smaller = load(__webpack_require__(38));
|
49116 | var matrix = load(__webpack_require__(0));
|
49117 | /**
|
49118 | * Calculate the norm of a number, vector or matrix.
|
49119 | *
|
49120 | * The second parameter p is optional. If not provided, it defaults to 2.
|
49121 | *
|
49122 | * Syntax:
|
49123 | *
|
49124 | * math.norm(x)
|
49125 | * math.norm(x, p)
|
49126 | *
|
49127 | * Examples:
|
49128 | *
|
49129 | * math.abs(-3.5) // returns 3.5
|
49130 | * math.norm(-3.5) // returns 3.5
|
49131 | *
|
49132 | * math.norm(math.complex(3, -4)) // returns 5
|
49133 | *
|
49134 | * math.norm([1, 2, -3], Infinity) // returns 3
|
49135 | * math.norm([1, 2, -3], -Infinity) // returns 1
|
49136 | *
|
49137 | * math.norm([3, 4], 2) // returns 5
|
49138 | *
|
49139 | * math.norm([[1, 2], [3, 4]], 1) // returns 6
|
49140 | * math.norm([[1, 2], [3, 4]], 'inf') // returns 7
|
49141 | * math.norm([[1, 2], [3, 4]], 'fro') // returns 5.477225575051661
|
49142 | *
|
49143 | * See also:
|
49144 | *
|
49145 | * abs, hypot
|
49146 | *
|
49147 | * @param {number | BigNumber | Complex | Array | Matrix} x
|
49148 | * Value for which to calculate the norm
|
49149 | * @param {number | BigNumber | string} [p=2]
|
49150 | * Vector space.
|
49151 | * Supported numbers include Infinity and -Infinity.
|
49152 | * Supported strings are: 'inf', '-inf', and 'fro' (The Frobenius norm)
|
49153 | * @return {number | BigNumber} the p-norm
|
49154 | */
|
49155 |
|
49156 | var norm = typed('norm', {
|
49157 | 'number': Math.abs,
|
49158 | 'Complex': function Complex(x) {
|
49159 | return x.abs();
|
49160 | },
|
49161 | 'BigNumber': function BigNumber(x) {
|
49162 | // norm(x) = abs(x)
|
49163 | return x.abs();
|
49164 | },
|
49165 | 'boolean': function boolean(x) {
|
49166 | // norm(x) = abs(x)
|
49167 | return Math.abs(x);
|
49168 | },
|
49169 | 'Array': function Array(x) {
|
49170 | return _norm(matrix(x), 2);
|
49171 | },
|
49172 | 'Matrix': function Matrix(x) {
|
49173 | return _norm(x, 2);
|
49174 | },
|
49175 | 'number | Complex | BigNumber | boolean, number | BigNumber | string': function numberComplexBigNumberBooleanNumberBigNumberString(x) {
|
49176 | // ignore second parameter, TODO: remove the option of second parameter for these types
|
49177 | return norm(x);
|
49178 | },
|
49179 | 'Array, number | BigNumber | string': function ArrayNumberBigNumberString(x, p) {
|
49180 | return _norm(matrix(x), p);
|
49181 | },
|
49182 | 'Matrix, number | BigNumber | string': function MatrixNumberBigNumberString(x, p) {
|
49183 | return _norm(x, p);
|
49184 | }
|
49185 | });
|
49186 | /**
|
49187 | * Calculate the norm for an array
|
49188 | * @param {Matrix} x
|
49189 | * @param {number | string} p
|
49190 | * @returns {number} Returns the norm
|
49191 | * @private
|
49192 | */
|
49193 |
|
49194 | function _norm(x, p) {
|
49195 | // size
|
49196 | var sizeX = x.size(); // check if it is a vector
|
49197 |
|
49198 | if (sizeX.length === 1) {
|
49199 | // check p
|
49200 | if (p === Number.POSITIVE_INFINITY || p === 'inf') {
|
49201 | // norm(x, Infinity) = max(abs(x))
|
49202 | var pinf = 0; // skip zeros since abs(0) === 0
|
49203 |
|
49204 | x.forEach(function (value) {
|
49205 | var v = abs(value);
|
49206 |
|
49207 | if (larger(v, pinf)) {
|
49208 | pinf = v;
|
49209 | }
|
49210 | }, true);
|
49211 | return pinf;
|
49212 | }
|
49213 |
|
49214 | if (p === Number.NEGATIVE_INFINITY || p === '-inf') {
|
49215 | // norm(x, -Infinity) = min(abs(x))
|
49216 | var ninf; // skip zeros since abs(0) === 0
|
49217 |
|
49218 | x.forEach(function (value) {
|
49219 | var v = abs(value);
|
49220 |
|
49221 | if (!ninf || smaller(v, ninf)) {
|
49222 | ninf = v;
|
49223 | }
|
49224 | }, true);
|
49225 | return ninf || 0;
|
49226 | }
|
49227 |
|
49228 | if (p === 'fro') {
|
49229 | return _norm(x, 2);
|
49230 | }
|
49231 |
|
49232 | if (typeof p === 'number' && !isNaN(p)) {
|
49233 | // check p != 0
|
49234 | if (!equalScalar(p, 0)) {
|
49235 | // norm(x, p) = sum(abs(xi) ^ p) ^ 1/p
|
49236 | var n = 0; // skip zeros since abs(0) === 0
|
49237 |
|
49238 | x.forEach(function (value) {
|
49239 | n = add(pow(abs(value), p), n);
|
49240 | }, true);
|
49241 | return pow(n, 1 / p);
|
49242 | }
|
49243 |
|
49244 | return Number.POSITIVE_INFINITY;
|
49245 | } // invalid parameter value
|
49246 |
|
49247 |
|
49248 | throw new Error('Unsupported parameter value');
|
49249 | } // MxN matrix
|
49250 |
|
49251 |
|
49252 | if (sizeX.length === 2) {
|
49253 | // check p
|
49254 | if (p === 1) {
|
49255 | // norm(x) = the largest column sum
|
49256 | var c = []; // result
|
49257 |
|
49258 | var maxc = 0; // skip zeros since abs(0) == 0
|
49259 |
|
49260 | x.forEach(function (value, index) {
|
49261 | var j = index[1];
|
49262 | var cj = add(c[j] || 0, abs(value));
|
49263 |
|
49264 | if (larger(cj, maxc)) {
|
49265 | maxc = cj;
|
49266 | }
|
49267 |
|
49268 | c[j] = cj;
|
49269 | }, true);
|
49270 | return maxc;
|
49271 | }
|
49272 |
|
49273 | if (p === Number.POSITIVE_INFINITY || p === 'inf') {
|
49274 | // norm(x) = the largest row sum
|
49275 | var r = []; // result
|
49276 |
|
49277 | var maxr = 0; // skip zeros since abs(0) == 0
|
49278 |
|
49279 | x.forEach(function (value, index) {
|
49280 | var i = index[0];
|
49281 | var ri = add(r[i] || 0, abs(value));
|
49282 |
|
49283 | if (larger(ri, maxr)) {
|
49284 | maxr = ri;
|
49285 | }
|
49286 |
|
49287 | r[i] = ri;
|
49288 | }, true);
|
49289 | return maxr;
|
49290 | }
|
49291 |
|
49292 | if (p === 'fro') {
|
49293 | // norm(x) = sqrt(sum(diag(x'x)))
|
49294 | var fro = 0;
|
49295 | x.forEach(function (value, index) {
|
49296 | fro = add(fro, multiply(value, conj(value)));
|
49297 | });
|
49298 | return abs(sqrt(fro));
|
49299 | }
|
49300 |
|
49301 | if (p === 2) {
|
49302 | // not implemented
|
49303 | throw new Error('Unsupported parameter value, missing implementation of matrix singular value decomposition');
|
49304 | } // invalid parameter value
|
49305 |
|
49306 |
|
49307 | throw new Error('Unsupported parameter value');
|
49308 | }
|
49309 | }
|
49310 |
|
49311 | norm.toTex = {
|
49312 | 1: "\\left\\|${args[0]}\\right\\|",
|
49313 | 2: undefined // use default template
|
49314 |
|
49315 | };
|
49316 | return norm;
|
49317 | }
|
49318 |
|
49319 | exports.name = 'norm';
|
49320 | exports.factory = factory;
|
49321 |
|
49322 | /***/ }),
|
49323 | /* 240 */
|
49324 | /***/ (function(module, exports, __webpack_require__) {
|
49325 |
|
49326 | "use strict";
|
49327 |
|
49328 |
|
49329 | function factory(type, config, load, typed) {
|
49330 | var matrix = load(__webpack_require__(0));
|
49331 | var algorithm01 = load(__webpack_require__(37));
|
49332 | var algorithm02 = load(__webpack_require__(27));
|
49333 | var algorithm06 = load(__webpack_require__(74));
|
49334 | var algorithm11 = load(__webpack_require__(20));
|
49335 | var algorithm13 = load(__webpack_require__(7));
|
49336 | var algorithm14 = load(__webpack_require__(6));
|
49337 | /**
|
49338 | * Calculate the nth root of a value.
|
49339 | * The principal nth root of a positive real number A, is the positive real
|
49340 | * solution of the equation
|
49341 | *
|
49342 | * x^root = A
|
49343 | *
|
49344 | * For matrices, the function is evaluated element wise.
|
49345 | *
|
49346 | * Syntax:
|
49347 | *
|
49348 | * math.nthRoot(a)
|
49349 | * math.nthRoot(a, root)
|
49350 | *
|
49351 | * Examples:
|
49352 | *
|
49353 | * math.nthRoot(9, 2) // returns 3, as 3^2 == 9
|
49354 | * math.sqrt(9) // returns 3, as 3^2 == 9
|
49355 | * math.nthRoot(64, 3) // returns 4, as 4^3 == 64
|
49356 | *
|
49357 | * See also:
|
49358 | *
|
49359 | * sqrt, pow
|
49360 | *
|
49361 | * @param {number | BigNumber | Array | Matrix | Complex} a
|
49362 | * Value for which to calculate the nth root
|
49363 | * @param {number | BigNumber} [root=2] The root.
|
49364 | * @return {number | Complex | Array | Matrix} Returns the nth root of `a`
|
49365 | */
|
49366 |
|
49367 | var complexErr = '' + 'Complex number not supported in function nthRoot. ' + 'Use nthRoots instead.';
|
49368 | var nthRoot = typed('nthRoot', {
|
49369 | 'number': function number(x) {
|
49370 | return _nthRoot(x, 2);
|
49371 | },
|
49372 | 'number, number': _nthRoot,
|
49373 | 'BigNumber': function BigNumber(x) {
|
49374 | return _bigNthRoot(x, new type.BigNumber(2));
|
49375 | },
|
49376 | 'Complex': function Complex(x) {
|
49377 | throw new Error(complexErr);
|
49378 | },
|
49379 | 'Complex, number': function ComplexNumber(x, y) {
|
49380 | throw new Error(complexErr);
|
49381 | },
|
49382 | 'BigNumber, BigNumber': _bigNthRoot,
|
49383 | 'Array | Matrix': function ArrayMatrix(x) {
|
49384 | return nthRoot(x, 2);
|
49385 | },
|
49386 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
49387 | // density must be one (no zeros in matrix)
|
49388 | if (y.density() === 1) {
|
49389 | // sparse + sparse
|
49390 | return algorithm06(x, y, nthRoot);
|
49391 | } else {
|
49392 | // throw exception
|
49393 | throw new Error('Root must be non-zero');
|
49394 | }
|
49395 | },
|
49396 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
49397 | return algorithm02(y, x, nthRoot, true);
|
49398 | },
|
49399 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
49400 | // density must be one (no zeros in matrix)
|
49401 | if (y.density() === 1) {
|
49402 | // dense + sparse
|
49403 | return algorithm01(x, y, nthRoot, false);
|
49404 | } else {
|
49405 | // throw exception
|
49406 | throw new Error('Root must be non-zero');
|
49407 | }
|
49408 | },
|
49409 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
49410 | return algorithm13(x, y, nthRoot);
|
49411 | },
|
49412 | 'Array, Array': function ArrayArray(x, y) {
|
49413 | // use matrix implementation
|
49414 | return nthRoot(matrix(x), matrix(y)).valueOf();
|
49415 | },
|
49416 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
49417 | // use matrix implementation
|
49418 | return nthRoot(matrix(x), y);
|
49419 | },
|
49420 | 'Matrix, Array': function MatrixArray(x, y) {
|
49421 | // use matrix implementation
|
49422 | return nthRoot(x, matrix(y));
|
49423 | },
|
49424 | 'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
49425 | return algorithm11(x, y, nthRoot, false);
|
49426 | },
|
49427 | 'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
49428 | return algorithm14(x, y, nthRoot, false);
|
49429 | },
|
49430 | 'number | BigNumber, SparseMatrix': function numberBigNumberSparseMatrix(x, y) {
|
49431 | // density must be one (no zeros in matrix)
|
49432 | if (y.density() === 1) {
|
49433 | // sparse - scalar
|
49434 | return algorithm11(y, x, nthRoot, true);
|
49435 | } else {
|
49436 | // throw exception
|
49437 | throw new Error('Root must be non-zero');
|
49438 | }
|
49439 | },
|
49440 | 'number | BigNumber, DenseMatrix': function numberBigNumberDenseMatrix(x, y) {
|
49441 | return algorithm14(y, x, nthRoot, true);
|
49442 | },
|
49443 | 'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
|
49444 | // use matrix implementation
|
49445 | return nthRoot(matrix(x), y).valueOf();
|
49446 | },
|
49447 | 'number | BigNumber, Array': function numberBigNumberArray(x, y) {
|
49448 | // use matrix implementation
|
49449 | return nthRoot(x, matrix(y)).valueOf();
|
49450 | }
|
49451 | });
|
49452 | nthRoot.toTex = {
|
49453 | 2: "\\sqrt[${args[1]}]{${args[0]}}"
|
49454 | };
|
49455 | return nthRoot;
|
49456 | /**
|
49457 | * Calculate the nth root of a for BigNumbers, solve x^root == a
|
49458 | * https://rosettacode.org/wiki/Nth_root#JavaScript
|
49459 | * @param {BigNumber} a
|
49460 | * @param {BigNumber} root
|
49461 | * @private
|
49462 | */
|
49463 |
|
49464 | function _bigNthRoot(a, root) {
|
49465 | var precision = type.BigNumber.precision;
|
49466 | var Big = type.BigNumber.clone({
|
49467 | precision: precision + 2
|
49468 | });
|
49469 | var zero = new type.BigNumber(0);
|
49470 | var one = new Big(1);
|
49471 | var inv = root.isNegative();
|
49472 |
|
49473 | if (inv) {
|
49474 | root = root.neg();
|
49475 | }
|
49476 |
|
49477 | if (root.isZero()) {
|
49478 | throw new Error('Root must be non-zero');
|
49479 | }
|
49480 |
|
49481 | if (a.isNegative() && !root.abs().mod(2).equals(1)) {
|
49482 | throw new Error('Root must be odd when a is negative.');
|
49483 | } // edge cases zero and infinity
|
49484 |
|
49485 |
|
49486 | if (a.isZero()) {
|
49487 | return inv ? new Big(Infinity) : 0;
|
49488 | }
|
49489 |
|
49490 | if (!a.isFinite()) {
|
49491 | return inv ? zero : a;
|
49492 | }
|
49493 |
|
49494 | var x = a.abs().pow(one.div(root)); // If a < 0, we require that root is an odd integer,
|
49495 | // so (-1) ^ (1/root) = -1
|
49496 |
|
49497 | x = a.isNeg() ? x.neg() : x;
|
49498 | return new type.BigNumber((inv ? one.div(x) : x).toPrecision(precision));
|
49499 | }
|
49500 | }
|
49501 | /**
|
49502 | * Calculate the nth root of a, solve x^root == a
|
49503 | * https://rosettacode.org/wiki/Nth_root#JavaScript
|
49504 | * @param {number} a
|
49505 | * @param {number} root
|
49506 | * @private
|
49507 | */
|
49508 |
|
49509 |
|
49510 | function _nthRoot(a, root) {
|
49511 | var inv = root < 0;
|
49512 |
|
49513 | if (inv) {
|
49514 | root = -root;
|
49515 | }
|
49516 |
|
49517 | if (root === 0) {
|
49518 | throw new Error('Root must be non-zero');
|
49519 | }
|
49520 |
|
49521 | if (a < 0 && Math.abs(root) % 2 !== 1) {
|
49522 | throw new Error('Root must be odd when a is negative.');
|
49523 | } // edge cases zero and infinity
|
49524 |
|
49525 |
|
49526 | if (a === 0) {
|
49527 | return inv ? Infinity : 0;
|
49528 | }
|
49529 |
|
49530 | if (!isFinite(a)) {
|
49531 | return inv ? 0 : a;
|
49532 | }
|
49533 |
|
49534 | var x = Math.pow(Math.abs(a), 1 / root); // If a < 0, we require that root is an odd integer,
|
49535 | // so (-1) ^ (1/root) = -1
|
49536 |
|
49537 | x = a < 0 ? -x : x;
|
49538 | return inv ? 1 / x : x; // Very nice algorithm, but fails with nthRoot(-2, 3).
|
49539 | // Newton's method has some well-known problems at times:
|
49540 | // https://en.wikipedia.org/wiki/Newton%27s_method#Failure_analysis
|
49541 |
|
49542 | /*
|
49543 | let x = 1 // Initial guess
|
49544 | let xPrev = 1
|
49545 | let i = 0
|
49546 | const iMax = 10000
|
49547 | do {
|
49548 | const delta = (a / Math.pow(x, root - 1) - x) / root
|
49549 | xPrev = x
|
49550 | x = x + delta
|
49551 | i++
|
49552 | }
|
49553 | while (xPrev !== x && i < iMax)
|
49554 | if (xPrev !== x) {
|
49555 | throw new Error('Function nthRoot failed to converge')
|
49556 | }
|
49557 | return inv ? 1 / x : x
|
49558 | */
|
49559 | }
|
49560 |
|
49561 | exports.name = 'nthRoot';
|
49562 | exports.factory = factory;
|
49563 |
|
49564 | /***/ }),
|
49565 | /* 241 */
|
49566 | /***/ (function(module, exports, __webpack_require__) {
|
49567 |
|
49568 | "use strict";
|
49569 |
|
49570 |
|
49571 | var Complex = __webpack_require__(82);
|
49572 |
|
49573 | var typed = __webpack_require__(103);
|
49574 |
|
49575 | var complex = Complex.factory('Complex', {}, '', typed, {
|
49576 | on: function on(x, y) {}
|
49577 | });
|
49578 |
|
49579 | function factory(type, config, load, typed) {
|
49580 | /**
|
49581 | * Calculate the nth roots of a value.
|
49582 | * An nth root of a positive real number A,
|
49583 | * is a positive real solution of the equation "x^root = A".
|
49584 | * This function returns an array of complex values.
|
49585 | *
|
49586 | * Syntax:
|
49587 | *
|
49588 | * math.nthRoots(x)
|
49589 | * math.nthRoots(x, root)
|
49590 | *
|
49591 | * Examples:
|
49592 | *
|
49593 | * math.nthRoots(1)
|
49594 | * // returns [
|
49595 | * // {re: 1, im: 0},
|
49596 | * // {re: -1, im: 0}
|
49597 | * // ]
|
49598 | * nthRoots(1, 3)
|
49599 | * // returns [
|
49600 | * // { re: 1, im: 0 },
|
49601 | * // { re: -0.4999999999999998, im: 0.8660254037844387 },
|
49602 | * // { re: -0.5000000000000004, im: -0.8660254037844385 }
|
49603 | * ]
|
49604 | *
|
49605 | * See also:
|
49606 | *
|
49607 | * nthRoot, pow, sqrt
|
49608 | *
|
49609 | * @param {number | BigNumber | Fraction | Complex | Array | Matrix} x Number to be rounded
|
49610 | * @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
|
49611 | */
|
49612 | var nthRoots = typed('nthRoots', {
|
49613 | 'Complex': function Complex(x) {
|
49614 | return _nthComplexRoots(x, 2);
|
49615 | },
|
49616 | 'Complex, number': _nthComplexRoots
|
49617 | });
|
49618 | nthRoots.toTex = {
|
49619 | 2: "\\{y : $y^{args[1]} = {${args[0]}}\\}"
|
49620 | };
|
49621 | return nthRoots;
|
49622 | }
|
49623 | /**
|
49624 | * Each function here returns a real multiple of i as a Complex value.
|
49625 | * @param {number} val
|
49626 | * @return {Complex} val, i*val, -val or -i*val for index 0, 1, 2, 3
|
49627 | */
|
49628 | // This is used to fix float artifacts for zero-valued components.
|
49629 |
|
49630 |
|
49631 | var _calculateExactResult = [function realPos(val) {
|
49632 | return complex(val);
|
49633 | }, function imagPos(val) {
|
49634 | return complex(0, val);
|
49635 | }, function realNeg(val) {
|
49636 | return complex(-val);
|
49637 | }, function imagNeg(val) {
|
49638 | return complex(0, -val);
|
49639 | }];
|
49640 | /**
|
49641 | * Calculate the nth root of a Complex Number a using De Movire's Theorem.
|
49642 | * @param {Complex} a
|
49643 | * @param {number} root
|
49644 | * @return {Array} array of n Complex Roots
|
49645 | */
|
49646 |
|
49647 | function _nthComplexRoots(a, root) {
|
49648 | if (root < 0) throw new Error('Root must be greater than zero');
|
49649 | if (root === 0) throw new Error('Root must be non-zero');
|
49650 | if (root % 1 !== 0) throw new Error('Root must be an integer');
|
49651 | if (a === 0 || a.abs() === 0) return [complex(0)];
|
49652 | var aIsNumeric = typeof a === 'number';
|
49653 | var offset; // determine the offset (argument of a)/(pi/2)
|
49654 |
|
49655 | if (aIsNumeric || a.re === 0 || a.im === 0) {
|
49656 | if (aIsNumeric) {
|
49657 | offset = 2 * +(a < 0); // numeric value on the real axis
|
49658 | } else if (a.im === 0) {
|
49659 | offset = 2 * +(a.re < 0); // complex value on the real axis
|
49660 | } else {
|
49661 | offset = 2 * +(a.im < 0) + 1; // complex value on the imaginary axis
|
49662 | }
|
49663 | }
|
49664 |
|
49665 | var arg = a.arg();
|
49666 | var abs = a.abs();
|
49667 | var roots = [];
|
49668 | var r = Math.pow(abs, 1 / root);
|
49669 |
|
49670 | for (var k = 0; k < root; k++) {
|
49671 | var halfPiFactor = (offset + 4 * k) / root;
|
49672 | /**
|
49673 | * If (offset + 4*k)/root is an integral multiple of pi/2
|
49674 | * then we can produce a more exact result.
|
49675 | */
|
49676 |
|
49677 | if (halfPiFactor === Math.round(halfPiFactor)) {
|
49678 | roots.push(_calculateExactResult[halfPiFactor % 4](r));
|
49679 | continue;
|
49680 | }
|
49681 |
|
49682 | roots.push(complex({
|
49683 | r: r,
|
49684 | phi: (arg + 2 * Math.PI * k) / root
|
49685 | }));
|
49686 | }
|
49687 |
|
49688 | return roots;
|
49689 | }
|
49690 |
|
49691 | exports.name = 'nthRoots';
|
49692 | exports.factory = factory;
|
49693 |
|
49694 | /***/ }),
|
49695 | /* 242 */
|
49696 | /***/ (function(module, exports, __webpack_require__) {
|
49697 |
|
49698 | "use strict";
|
49699 |
|
49700 |
|
49701 | var deepMap = __webpack_require__(1);
|
49702 |
|
49703 | function factory(type, config, load, typed) {
|
49704 | /**
|
49705 | * Compute the square of a value, `x * x`.
|
49706 | * For matrices, the function is evaluated element wise.
|
49707 | *
|
49708 | * Syntax:
|
49709 | *
|
49710 | * math.square(x)
|
49711 | *
|
49712 | * Examples:
|
49713 | *
|
49714 | * math.square(2) // returns number 4
|
49715 | * math.square(3) // returns number 9
|
49716 | * math.pow(3, 2) // returns number 9
|
49717 | * math.multiply(3, 3) // returns number 9
|
49718 | *
|
49719 | * math.square([1, 2, 3, 4]) // returns Array [1, 4, 9, 16]
|
49720 | *
|
49721 | * See also:
|
49722 | *
|
49723 | * multiply, cube, sqrt, pow
|
49724 | *
|
49725 | * @param {number | BigNumber | Fraction | Complex | Array | Matrix | Unit} x
|
49726 | * Number for which to calculate the square
|
49727 | * @return {number | BigNumber | Fraction | Complex | Array | Matrix | Unit}
|
49728 | * Squared value
|
49729 | */
|
49730 | var square = typed('square', {
|
49731 | 'number': function number(x) {
|
49732 | return x * x;
|
49733 | },
|
49734 | 'Complex': function Complex(x) {
|
49735 | return x.mul(x);
|
49736 | },
|
49737 | 'BigNumber': function BigNumber(x) {
|
49738 | return x.times(x);
|
49739 | },
|
49740 | 'Fraction': function Fraction(x) {
|
49741 | return x.mul(x);
|
49742 | },
|
49743 | 'Array | Matrix': function ArrayMatrix(x) {
|
49744 | // deep map collection, skip zeros since square(0) = 0
|
49745 | return deepMap(x, square, true);
|
49746 | },
|
49747 | 'Unit': function Unit(x) {
|
49748 | return x.pow(2);
|
49749 | }
|
49750 | });
|
49751 | square.toTex = {
|
49752 | 1: "\\left(${args[0]}\\right)^2"
|
49753 | };
|
49754 | return square;
|
49755 | }
|
49756 |
|
49757 | exports.name = 'square';
|
49758 | exports.factory = factory;
|
49759 |
|
49760 | /***/ }),
|
49761 | /* 243 */
|
49762 | /***/ (function(module, exports, __webpack_require__) {
|
49763 |
|
49764 | "use strict";
|
49765 |
|
49766 |
|
49767 | var deepMap = __webpack_require__(1);
|
49768 |
|
49769 | function factory(type, config, load, typed) {
|
49770 | var latex = __webpack_require__(4);
|
49771 | /**
|
49772 | * Unary plus operation.
|
49773 | * Boolean values and strings will be converted to a number, numeric values will be returned as is.
|
49774 | *
|
49775 | * For matrices, the function is evaluated element wise.
|
49776 | *
|
49777 | * Syntax:
|
49778 | *
|
49779 | * math.unaryPlus(x)
|
49780 | *
|
49781 | * Examples:
|
49782 | *
|
49783 | * math.unaryPlus(3.5) // returns 3.5
|
49784 | * math.unaryPlus(1) // returns 1
|
49785 | *
|
49786 | * See also:
|
49787 | *
|
49788 | * unaryMinus, add, subtract
|
49789 | *
|
49790 | * @param {number | BigNumber | Fraction | string | Complex | Unit | Array | Matrix} x
|
49791 | * Input value
|
49792 | * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix}
|
49793 | * Returns the input value when numeric, converts to a number when input is non-numeric.
|
49794 | */
|
49795 |
|
49796 |
|
49797 | var unaryPlus = typed('unaryPlus', {
|
49798 | 'number': function number(x) {
|
49799 | return x;
|
49800 | },
|
49801 | 'Complex': function Complex(x) {
|
49802 | return x; // complex numbers are immutable
|
49803 | },
|
49804 | 'BigNumber': function BigNumber(x) {
|
49805 | return x; // bignumbers are immutable
|
49806 | },
|
49807 | 'Fraction': function Fraction(x) {
|
49808 | return x; // fractions are immutable
|
49809 | },
|
49810 | 'Unit': function Unit(x) {
|
49811 | return x.clone();
|
49812 | },
|
49813 | 'Array | Matrix': function ArrayMatrix(x) {
|
49814 | // deep map collection, skip zeros since unaryPlus(0) = 0
|
49815 | return deepMap(x, unaryPlus, true);
|
49816 | },
|
49817 | 'boolean | string': function booleanString(x) {
|
49818 | // convert to a number or bignumber
|
49819 | return config.number === 'BigNumber' ? new type.BigNumber(+x) : +x;
|
49820 | }
|
49821 | });
|
49822 | unaryPlus.toTex = {
|
49823 | 1: "".concat(latex.operators['unaryPlus'], "\\left(${args[0]}\\right)")
|
49824 | };
|
49825 | return unaryPlus;
|
49826 | }
|
49827 |
|
49828 | exports.name = 'unaryPlus';
|
49829 | exports.factory = factory;
|
49830 |
|
49831 | /***/ }),
|
49832 | /* 244 */
|
49833 | /***/ (function(module, exports, __webpack_require__) {
|
49834 |
|
49835 | "use strict";
|
49836 |
|
49837 |
|
49838 | var isInteger = __webpack_require__(3).isInteger;
|
49839 |
|
49840 | function factory(type, config, load, typed) {
|
49841 | var matrix = load(__webpack_require__(0));
|
49842 | /**
|
49843 | * Calculate the extended greatest common divisor for two values.
|
49844 | * See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
|
49845 | *
|
49846 | * Syntax:
|
49847 | *
|
49848 | * math.xgcd(a, b)
|
49849 | *
|
49850 | * Examples:
|
49851 | *
|
49852 | * math.xgcd(8, 12) // returns [4, -1, 1]
|
49853 | * math.gcd(8, 12) // returns 4
|
49854 | * math.xgcd(36163, 21199) // returns [1247, -7, 12]
|
49855 | *
|
49856 | * See also:
|
49857 | *
|
49858 | * gcd, lcm
|
49859 | *
|
49860 | * @param {number | BigNumber} a An integer number
|
49861 | * @param {number | BigNumber} b An integer number
|
49862 | * @return {Array} Returns an array containing 3 integers `[div, m, n]`
|
49863 | * where `div = gcd(a, b)` and `a*m + b*n = div`
|
49864 | */
|
49865 |
|
49866 | var xgcd = typed('xgcd', {
|
49867 | 'number, number': _xgcd,
|
49868 | 'BigNumber, BigNumber': _xgcdBigNumber // TODO: implement support for Fraction
|
49869 |
|
49870 | });
|
49871 | xgcd.toTex = undefined; // use default template
|
49872 |
|
49873 | return xgcd;
|
49874 | /**
|
49875 | * Calculate xgcd for two numbers
|
49876 | * @param {number} a
|
49877 | * @param {number} b
|
49878 | * @return {number} result
|
49879 | * @private
|
49880 | */
|
49881 |
|
49882 | function _xgcd(a, b) {
|
49883 | // source: https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm
|
49884 | var t; // used to swap two variables
|
49885 |
|
49886 | var q; // quotient
|
49887 |
|
49888 | var r; // remainder
|
49889 |
|
49890 | var x = 0;
|
49891 | var lastx = 1;
|
49892 | var y = 1;
|
49893 | var lasty = 0;
|
49894 |
|
49895 | if (!isInteger(a) || !isInteger(b)) {
|
49896 | throw new Error('Parameters in function xgcd must be integer numbers');
|
49897 | }
|
49898 |
|
49899 | while (b) {
|
49900 | q = Math.floor(a / b);
|
49901 | r = a - q * b;
|
49902 | t = x;
|
49903 | x = lastx - q * x;
|
49904 | lastx = t;
|
49905 | t = y;
|
49906 | y = lasty - q * y;
|
49907 | lasty = t;
|
49908 | a = b;
|
49909 | b = r;
|
49910 | }
|
49911 |
|
49912 | var res;
|
49913 |
|
49914 | if (a < 0) {
|
49915 | res = [-a, -lastx, -lasty];
|
49916 | } else {
|
49917 | res = [a, a ? lastx : 0, lasty];
|
49918 | }
|
49919 |
|
49920 | return config.matrix === 'Array' ? res : matrix(res);
|
49921 | }
|
49922 | /**
|
49923 | * Calculate xgcd for two BigNumbers
|
49924 | * @param {BigNumber} a
|
49925 | * @param {BigNumber} b
|
49926 | * @return {BigNumber[]} result
|
49927 | * @private
|
49928 | */
|
49929 |
|
49930 |
|
49931 | function _xgcdBigNumber(a, b) {
|
49932 | // source: https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm
|
49933 | var // used to swap two variables
|
49934 | t;
|
49935 | var // quotient
|
49936 | q;
|
49937 | var // remainder
|
49938 | r;
|
49939 | var zero = new type.BigNumber(0);
|
49940 | var one = new type.BigNumber(1);
|
49941 | var x = zero;
|
49942 | var lastx = one;
|
49943 | var y = one;
|
49944 | var lasty = zero;
|
49945 |
|
49946 | if (!a.isInt() || !b.isInt()) {
|
49947 | throw new Error('Parameters in function xgcd must be integer numbers');
|
49948 | }
|
49949 |
|
49950 | while (!b.isZero()) {
|
49951 | q = a.div(b).floor();
|
49952 | r = a.mod(b);
|
49953 | t = x;
|
49954 | x = lastx.minus(q.times(x));
|
49955 | lastx = t;
|
49956 | t = y;
|
49957 | y = lasty.minus(q.times(y));
|
49958 | lasty = t;
|
49959 | a = b;
|
49960 | b = r;
|
49961 | }
|
49962 |
|
49963 | var res;
|
49964 |
|
49965 | if (a.lt(zero)) {
|
49966 | res = [a.neg(), lastx.neg(), lasty.neg()];
|
49967 | } else {
|
49968 | res = [a, !a.isZero() ? lastx : 0, lasty];
|
49969 | }
|
49970 |
|
49971 | return config.matrix === 'Array' ? res : matrix(res);
|
49972 | }
|
49973 | }
|
49974 |
|
49975 | exports.name = 'xgcd';
|
49976 | exports.factory = factory;
|
49977 |
|
49978 | /***/ }),
|
49979 | /* 245 */
|
49980 | /***/ (function(module, exports, __webpack_require__) {
|
49981 |
|
49982 | "use strict";
|
49983 |
|
49984 |
|
49985 | module.exports = [__webpack_require__(246), __webpack_require__(248), __webpack_require__(249), __webpack_require__(251), __webpack_require__(253), __webpack_require__(255), __webpack_require__(257)];
|
49986 |
|
49987 | /***/ }),
|
49988 | /* 246 */
|
49989 | /***/ (function(module, exports, __webpack_require__) {
|
49990 |
|
49991 | "use strict";
|
49992 |
|
49993 |
|
49994 | var isInteger = __webpack_require__(3).isInteger;
|
49995 |
|
49996 | var bigBitAnd = __webpack_require__(247);
|
49997 |
|
49998 | function factory(type, config, load, typed) {
|
49999 | var latex = __webpack_require__(4);
|
50000 |
|
50001 | var matrix = load(__webpack_require__(0));
|
50002 | var algorithm02 = load(__webpack_require__(27));
|
50003 | var algorithm06 = load(__webpack_require__(74));
|
50004 | var algorithm11 = load(__webpack_require__(20));
|
50005 | var algorithm13 = load(__webpack_require__(7));
|
50006 | var algorithm14 = load(__webpack_require__(6));
|
50007 | /**
|
50008 | * Bitwise AND two values, `x & y`.
|
50009 | * For matrices, the function is evaluated element wise.
|
50010 | *
|
50011 | * Syntax:
|
50012 | *
|
50013 | * math.bitAnd(x, y)
|
50014 | *
|
50015 | * Examples:
|
50016 | *
|
50017 | * math.bitAnd(53, 131) // returns number 1
|
50018 | *
|
50019 | * math.bitAnd([1, 12, 31], 42) // returns Array [0, 8, 10]
|
50020 | *
|
50021 | * See also:
|
50022 | *
|
50023 | * bitNot, bitOr, bitXor, leftShift, rightArithShift, rightLogShift
|
50024 | *
|
50025 | * @param {number | BigNumber | Array | Matrix} x First value to and
|
50026 | * @param {number | BigNumber | Array | Matrix} y Second value to and
|
50027 | * @return {number | BigNumber | Array | Matrix} AND of `x` and `y`
|
50028 | */
|
50029 |
|
50030 | var bitAnd = typed('bitAnd', {
|
50031 | 'number, number': function numberNumber(x, y) {
|
50032 | if (!isInteger(x) || !isInteger(y)) {
|
50033 | throw new Error('Integers expected in function bitAnd');
|
50034 | }
|
50035 |
|
50036 | return x & y;
|
50037 | },
|
50038 | 'BigNumber, BigNumber': bigBitAnd,
|
50039 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
50040 | return algorithm06(x, y, bitAnd, false);
|
50041 | },
|
50042 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
50043 | return algorithm02(y, x, bitAnd, true);
|
50044 | },
|
50045 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
50046 | return algorithm02(x, y, bitAnd, false);
|
50047 | },
|
50048 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
50049 | return algorithm13(x, y, bitAnd);
|
50050 | },
|
50051 | 'Array, Array': function ArrayArray(x, y) {
|
50052 | // use matrix implementation
|
50053 | return bitAnd(matrix(x), matrix(y)).valueOf();
|
50054 | },
|
50055 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
50056 | // use matrix implementation
|
50057 | return bitAnd(matrix(x), y);
|
50058 | },
|
50059 | 'Matrix, Array': function MatrixArray(x, y) {
|
50060 | // use matrix implementation
|
50061 | return bitAnd(x, matrix(y));
|
50062 | },
|
50063 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
50064 | return algorithm11(x, y, bitAnd, false);
|
50065 | },
|
50066 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
50067 | return algorithm14(x, y, bitAnd, false);
|
50068 | },
|
50069 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
50070 | return algorithm11(y, x, bitAnd, true);
|
50071 | },
|
50072 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
50073 | return algorithm14(y, x, bitAnd, true);
|
50074 | },
|
50075 | 'Array, any': function ArrayAny(x, y) {
|
50076 | // use matrix implementation
|
50077 | return algorithm14(matrix(x), y, bitAnd, false).valueOf();
|
50078 | },
|
50079 | 'any, Array': function anyArray(x, y) {
|
50080 | // use matrix implementation
|
50081 | return algorithm14(matrix(y), x, bitAnd, true).valueOf();
|
50082 | }
|
50083 | });
|
50084 | bitAnd.toTex = {
|
50085 | 2: "\\left(${args[0]}".concat(latex.operators['bitAnd'], "${args[1]}\\right)")
|
50086 | };
|
50087 | return bitAnd;
|
50088 | }
|
50089 |
|
50090 | exports.name = 'bitAnd';
|
50091 | exports.factory = factory;
|
50092 |
|
50093 | /***/ }),
|
50094 | /* 247 */
|
50095 | /***/ (function(module, exports, __webpack_require__) {
|
50096 |
|
50097 | "use strict";
|
50098 |
|
50099 |
|
50100 | var bitwise = __webpack_require__(92);
|
50101 | /**
|
50102 | * Bitwise and for Bignumbers
|
50103 | *
|
50104 | * Special Cases:
|
50105 | * N & n = N
|
50106 | * n & 0 = 0
|
50107 | * n & -1 = n
|
50108 | * n & n = n
|
50109 | * I & I = I
|
50110 | * -I & -I = -I
|
50111 | * I & -I = 0
|
50112 | * I & n = n
|
50113 | * I & -n = I
|
50114 | * -I & n = 0
|
50115 | * -I & -n = -I
|
50116 | *
|
50117 | * @param {BigNumber} x
|
50118 | * @param {BigNumber} y
|
50119 | * @return {BigNumber} Result of `x` & `y`, is fully precise
|
50120 | * @private
|
50121 | */
|
50122 |
|
50123 |
|
50124 | module.exports = function bitAnd(x, y) {
|
50125 | if (x.isFinite() && !x.isInteger() || y.isFinite() && !y.isInteger()) {
|
50126 | throw new Error('Integers expected in function bitAnd');
|
50127 | }
|
50128 |
|
50129 | var BigNumber = x.constructor;
|
50130 |
|
50131 | if (x.isNaN() || y.isNaN()) {
|
50132 | return new BigNumber(NaN);
|
50133 | }
|
50134 |
|
50135 | if (x.isZero() || y.eq(-1) || x.eq(y)) {
|
50136 | return x;
|
50137 | }
|
50138 |
|
50139 | if (y.isZero() || x.eq(-1)) {
|
50140 | return y;
|
50141 | }
|
50142 |
|
50143 | if (!x.isFinite() || !y.isFinite()) {
|
50144 | if (!x.isFinite() && !y.isFinite()) {
|
50145 | if (x.isNegative() === y.isNegative()) {
|
50146 | return x;
|
50147 | }
|
50148 |
|
50149 | return new BigNumber(0);
|
50150 | }
|
50151 |
|
50152 | if (!x.isFinite()) {
|
50153 | if (y.isNegative()) {
|
50154 | return x;
|
50155 | }
|
50156 |
|
50157 | if (x.isNegative()) {
|
50158 | return new BigNumber(0);
|
50159 | }
|
50160 |
|
50161 | return y;
|
50162 | }
|
50163 |
|
50164 | if (!y.isFinite()) {
|
50165 | if (x.isNegative()) {
|
50166 | return y;
|
50167 | }
|
50168 |
|
50169 | if (y.isNegative()) {
|
50170 | return new BigNumber(0);
|
50171 | }
|
50172 |
|
50173 | return x;
|
50174 | }
|
50175 | }
|
50176 |
|
50177 | return bitwise(x, y, function (a, b) {
|
50178 | return a & b;
|
50179 | });
|
50180 | };
|
50181 |
|
50182 | /***/ }),
|
50183 | /* 248 */
|
50184 | /***/ (function(module, exports, __webpack_require__) {
|
50185 |
|
50186 | "use strict";
|
50187 |
|
50188 |
|
50189 | var deepMap = __webpack_require__(1);
|
50190 |
|
50191 | var bigBitNot = __webpack_require__(93);
|
50192 |
|
50193 | var isInteger = __webpack_require__(3).isInteger;
|
50194 |
|
50195 | function factory(type, config, load, typed) {
|
50196 | var latex = __webpack_require__(4);
|
50197 | /**
|
50198 | * Bitwise NOT value, `~x`.
|
50199 | * For matrices, the function is evaluated element wise.
|
50200 | * For units, the function is evaluated on the best prefix base.
|
50201 | *
|
50202 | * Syntax:
|
50203 | *
|
50204 | * math.bitNot(x)
|
50205 | *
|
50206 | * Examples:
|
50207 | *
|
50208 | * math.bitNot(1) // returns number -2
|
50209 | *
|
50210 | * math.bitNot([2, -3, 4]) // returns Array [-3, 2, 5]
|
50211 | *
|
50212 | * See also:
|
50213 | *
|
50214 | * bitAnd, bitOr, bitXor, leftShift, rightArithShift, rightLogShift
|
50215 | *
|
50216 | * @param {number | BigNumber | Array | Matrix} x Value to not
|
50217 | * @return {number | BigNumber | Array | Matrix} NOT of `x`
|
50218 | */
|
50219 |
|
50220 |
|
50221 | var bitNot = typed('bitNot', {
|
50222 | 'number': function number(x) {
|
50223 | if (!isInteger(x)) {
|
50224 | throw new Error('Integer expected in function bitNot');
|
50225 | }
|
50226 |
|
50227 | return ~x;
|
50228 | },
|
50229 | 'BigNumber': bigBitNot,
|
50230 | 'Array | Matrix': function ArrayMatrix(x) {
|
50231 | return deepMap(x, bitNot);
|
50232 | }
|
50233 | });
|
50234 | bitNot.toTex = {
|
50235 | 1: latex.operators['bitNot'] + "\\left(${args[0]}\\right)"
|
50236 | };
|
50237 | return bitNot;
|
50238 | }
|
50239 |
|
50240 | exports.name = 'bitNot';
|
50241 | exports.factory = factory;
|
50242 |
|
50243 | /***/ }),
|
50244 | /* 249 */
|
50245 | /***/ (function(module, exports, __webpack_require__) {
|
50246 |
|
50247 | "use strict";
|
50248 |
|
50249 |
|
50250 | var isInteger = __webpack_require__(3).isInteger;
|
50251 |
|
50252 | var bigBitOr = __webpack_require__(250);
|
50253 |
|
50254 | function factory(type, config, load, typed) {
|
50255 | var latex = __webpack_require__(4);
|
50256 |
|
50257 | var matrix = load(__webpack_require__(0));
|
50258 | var algorithm01 = load(__webpack_require__(37));
|
50259 | var algorithm04 = load(__webpack_require__(85));
|
50260 | var algorithm10 = load(__webpack_require__(41));
|
50261 | var algorithm13 = load(__webpack_require__(7));
|
50262 | var algorithm14 = load(__webpack_require__(6));
|
50263 | /**
|
50264 | * Bitwise OR two values, `x | y`.
|
50265 | * For matrices, the function is evaluated element wise.
|
50266 | * For units, the function is evaluated on the lowest print base.
|
50267 | *
|
50268 | * Syntax:
|
50269 | *
|
50270 | * math.bitOr(x, y)
|
50271 | *
|
50272 | * Examples:
|
50273 | *
|
50274 | * math.bitOr(1, 2) // returns number 3
|
50275 | *
|
50276 | * math.bitOr([1, 2, 3], 4) // returns Array [5, 6, 7]
|
50277 | *
|
50278 | * See also:
|
50279 | *
|
50280 | * bitAnd, bitNot, bitXor, leftShift, rightArithShift, rightLogShift
|
50281 | *
|
50282 | * @param {number | BigNumber | Array | Matrix} x First value to or
|
50283 | * @param {number | BigNumber | Array | Matrix} y Second value to or
|
50284 | * @return {number | BigNumber | Array | Matrix} OR of `x` and `y`
|
50285 | */
|
50286 |
|
50287 | var bitOr = typed('bitOr', {
|
50288 | 'number, number': function numberNumber(x, y) {
|
50289 | if (!isInteger(x) || !isInteger(y)) {
|
50290 | throw new Error('Integers expected in function bitOr');
|
50291 | }
|
50292 |
|
50293 | return x | y;
|
50294 | },
|
50295 | 'BigNumber, BigNumber': bigBitOr,
|
50296 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
50297 | return algorithm04(x, y, bitOr);
|
50298 | },
|
50299 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
50300 | return algorithm01(y, x, bitOr, true);
|
50301 | },
|
50302 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
50303 | return algorithm01(x, y, bitOr, false);
|
50304 | },
|
50305 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
50306 | return algorithm13(x, y, bitOr);
|
50307 | },
|
50308 | 'Array, Array': function ArrayArray(x, y) {
|
50309 | // use matrix implementation
|
50310 | return bitOr(matrix(x), matrix(y)).valueOf();
|
50311 | },
|
50312 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
50313 | // use matrix implementation
|
50314 | return bitOr(matrix(x), y);
|
50315 | },
|
50316 | 'Matrix, Array': function MatrixArray(x, y) {
|
50317 | // use matrix implementation
|
50318 | return bitOr(x, matrix(y));
|
50319 | },
|
50320 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
50321 | return algorithm10(x, y, bitOr, false);
|
50322 | },
|
50323 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
50324 | return algorithm14(x, y, bitOr, false);
|
50325 | },
|
50326 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
50327 | return algorithm10(y, x, bitOr, true);
|
50328 | },
|
50329 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
50330 | return algorithm14(y, x, bitOr, true);
|
50331 | },
|
50332 | 'Array, any': function ArrayAny(x, y) {
|
50333 | // use matrix implementation
|
50334 | return algorithm14(matrix(x), y, bitOr, false).valueOf();
|
50335 | },
|
50336 | 'any, Array': function anyArray(x, y) {
|
50337 | // use matrix implementation
|
50338 | return algorithm14(matrix(y), x, bitOr, true).valueOf();
|
50339 | }
|
50340 | });
|
50341 | bitOr.toTex = {
|
50342 | 2: "\\left(${args[0]}".concat(latex.operators['bitOr'], "${args[1]}\\right)")
|
50343 | };
|
50344 | return bitOr;
|
50345 | }
|
50346 |
|
50347 | exports.name = 'bitOr';
|
50348 | exports.factory = factory;
|
50349 |
|
50350 | /***/ }),
|
50351 | /* 250 */
|
50352 | /***/ (function(module, exports, __webpack_require__) {
|
50353 |
|
50354 | "use strict";
|
50355 |
|
50356 |
|
50357 | var bitwise = __webpack_require__(92);
|
50358 | /**
|
50359 | * Bitwise OR for BigNumbers
|
50360 | *
|
50361 | * Special Cases:
|
50362 | * N | n = N
|
50363 | * n | 0 = n
|
50364 | * n | -1 = -1
|
50365 | * n | n = n
|
50366 | * I | I = I
|
50367 | * -I | -I = -I
|
50368 | * I | -n = -1
|
50369 | * I | -I = -1
|
50370 | * I | n = I
|
50371 | * -I | n = -I
|
50372 | * -I | -n = -n
|
50373 | *
|
50374 | * @param {BigNumber} x
|
50375 | * @param {BigNumber} y
|
50376 | * @return {BigNumber} Result of `x` | `y`, fully precise
|
50377 | */
|
50378 |
|
50379 |
|
50380 | module.exports = function bitOr(x, y) {
|
50381 | if (x.isFinite() && !x.isInteger() || y.isFinite() && !y.isInteger()) {
|
50382 | throw new Error('Integers expected in function bitOr');
|
50383 | }
|
50384 |
|
50385 | var BigNumber = x.constructor;
|
50386 |
|
50387 | if (x.isNaN() || y.isNaN()) {
|
50388 | return new BigNumber(NaN);
|
50389 | }
|
50390 |
|
50391 | var negOne = new BigNumber(-1);
|
50392 |
|
50393 | if (x.isZero() || y.eq(negOne) || x.eq(y)) {
|
50394 | return y;
|
50395 | }
|
50396 |
|
50397 | if (y.isZero() || x.eq(negOne)) {
|
50398 | return x;
|
50399 | }
|
50400 |
|
50401 | if (!x.isFinite() || !y.isFinite()) {
|
50402 | if (!x.isFinite() && !x.isNegative() && y.isNegative() || x.isNegative() && !y.isNegative() && !y.isFinite()) {
|
50403 | return negOne;
|
50404 | }
|
50405 |
|
50406 | if (x.isNegative() && y.isNegative()) {
|
50407 | return x.isFinite() ? x : y;
|
50408 | }
|
50409 |
|
50410 | return x.isFinite() ? y : x;
|
50411 | }
|
50412 |
|
50413 | return bitwise(x, y, function (a, b) {
|
50414 | return a | b;
|
50415 | });
|
50416 | };
|
50417 |
|
50418 | /***/ }),
|
50419 | /* 251 */
|
50420 | /***/ (function(module, exports, __webpack_require__) {
|
50421 |
|
50422 | "use strict";
|
50423 |
|
50424 |
|
50425 | var isInteger = __webpack_require__(3).isInteger;
|
50426 |
|
50427 | var bigBitXor = __webpack_require__(252);
|
50428 |
|
50429 | function factory(type, config, load, typed) {
|
50430 | var latex = __webpack_require__(4);
|
50431 |
|
50432 | var matrix = load(__webpack_require__(0));
|
50433 | var algorithm03 = load(__webpack_require__(18));
|
50434 | var algorithm07 = load(__webpack_require__(29));
|
50435 | var algorithm12 = load(__webpack_require__(19));
|
50436 | var algorithm13 = load(__webpack_require__(7));
|
50437 | var algorithm14 = load(__webpack_require__(6));
|
50438 | /**
|
50439 | * Bitwise XOR two values, `x ^ y`.
|
50440 | * For matrices, the function is evaluated element wise.
|
50441 | *
|
50442 | * Syntax:
|
50443 | *
|
50444 | * math.bitXor(x, y)
|
50445 | *
|
50446 | * Examples:
|
50447 | *
|
50448 | * math.bitXor(1, 2) // returns number 3
|
50449 | *
|
50450 | * math.bitXor([2, 3, 4], 4) // returns Array [6, 7, 0]
|
50451 | *
|
50452 | * See also:
|
50453 | *
|
50454 | * bitAnd, bitNot, bitOr, leftShift, rightArithShift, rightLogShift
|
50455 | *
|
50456 | * @param {number | BigNumber | Array | Matrix} x First value to xor
|
50457 | * @param {number | BigNumber | Array | Matrix} y Second value to xor
|
50458 | * @return {number | BigNumber | Array | Matrix} XOR of `x` and `y`
|
50459 | */
|
50460 |
|
50461 | var bitXor = typed('bitXor', {
|
50462 | 'number, number': function numberNumber(x, y) {
|
50463 | if (!isInteger(x) || !isInteger(y)) {
|
50464 | throw new Error('Integers expected in function bitXor');
|
50465 | }
|
50466 |
|
50467 | return x ^ y;
|
50468 | },
|
50469 | 'BigNumber, BigNumber': bigBitXor,
|
50470 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
50471 | return algorithm07(x, y, bitXor);
|
50472 | },
|
50473 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
50474 | return algorithm03(y, x, bitXor, true);
|
50475 | },
|
50476 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
50477 | return algorithm03(x, y, bitXor, false);
|
50478 | },
|
50479 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
50480 | return algorithm13(x, y, bitXor);
|
50481 | },
|
50482 | 'Array, Array': function ArrayArray(x, y) {
|
50483 | // use matrix implementation
|
50484 | return bitXor(matrix(x), matrix(y)).valueOf();
|
50485 | },
|
50486 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
50487 | // use matrix implementation
|
50488 | return bitXor(matrix(x), y);
|
50489 | },
|
50490 | 'Matrix, Array': function MatrixArray(x, y) {
|
50491 | // use matrix implementation
|
50492 | return bitXor(x, matrix(y));
|
50493 | },
|
50494 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
50495 | return algorithm12(x, y, bitXor, false);
|
50496 | },
|
50497 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
50498 | return algorithm14(x, y, bitXor, false);
|
50499 | },
|
50500 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
50501 | return algorithm12(y, x, bitXor, true);
|
50502 | },
|
50503 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
50504 | return algorithm14(y, x, bitXor, true);
|
50505 | },
|
50506 | 'Array, any': function ArrayAny(x, y) {
|
50507 | // use matrix implementation
|
50508 | return algorithm14(matrix(x), y, bitXor, false).valueOf();
|
50509 | },
|
50510 | 'any, Array': function anyArray(x, y) {
|
50511 | // use matrix implementation
|
50512 | return algorithm14(matrix(y), x, bitXor, true).valueOf();
|
50513 | }
|
50514 | });
|
50515 | bitXor.toTex = {
|
50516 | 2: "\\left(${args[0]}".concat(latex.operators['bitXor'], "${args[1]}\\right)")
|
50517 | };
|
50518 | return bitXor;
|
50519 | }
|
50520 |
|
50521 | exports.name = 'bitXor';
|
50522 | exports.factory = factory;
|
50523 |
|
50524 | /***/ }),
|
50525 | /* 252 */
|
50526 | /***/ (function(module, exports, __webpack_require__) {
|
50527 |
|
50528 | "use strict";
|
50529 |
|
50530 |
|
50531 | var bitwise = __webpack_require__(92);
|
50532 |
|
50533 | var bitNot = __webpack_require__(93);
|
50534 | /**
|
50535 | * Bitwise XOR for BigNumbers
|
50536 | *
|
50537 | * Special Cases:
|
50538 | * N ^ n = N
|
50539 | * n ^ 0 = n
|
50540 | * n ^ n = 0
|
50541 | * n ^ -1 = ~n
|
50542 | * I ^ n = I
|
50543 | * I ^ -n = -I
|
50544 | * I ^ -I = -1
|
50545 | * -I ^ n = -I
|
50546 | * -I ^ -n = I
|
50547 | *
|
50548 | * @param {BigNumber} x
|
50549 | * @param {BigNumber} y
|
50550 | * @return {BigNumber} Result of `x` ^ `y`, fully precise
|
50551 | *
|
50552 | */
|
50553 |
|
50554 |
|
50555 | module.exports = function bitXor(x, y) {
|
50556 | if (x.isFinite() && !x.isInteger() || y.isFinite() && !y.isInteger()) {
|
50557 | throw new Error('Integers expected in function bitXor');
|
50558 | }
|
50559 |
|
50560 | var BigNumber = x.constructor;
|
50561 |
|
50562 | if (x.isNaN() || y.isNaN()) {
|
50563 | return new BigNumber(NaN);
|
50564 | }
|
50565 |
|
50566 | if (x.isZero()) {
|
50567 | return y;
|
50568 | }
|
50569 |
|
50570 | if (y.isZero()) {
|
50571 | return x;
|
50572 | }
|
50573 |
|
50574 | if (x.eq(y)) {
|
50575 | return new BigNumber(0);
|
50576 | }
|
50577 |
|
50578 | var negOne = new BigNumber(-1);
|
50579 |
|
50580 | if (x.eq(negOne)) {
|
50581 | return bitNot(y);
|
50582 | }
|
50583 |
|
50584 | if (y.eq(negOne)) {
|
50585 | return bitNot(x);
|
50586 | }
|
50587 |
|
50588 | if (!x.isFinite() || !y.isFinite()) {
|
50589 | if (!x.isFinite() && !y.isFinite()) {
|
50590 | return negOne;
|
50591 | }
|
50592 |
|
50593 | return new BigNumber(x.isNegative() === y.isNegative() ? Infinity : -Infinity);
|
50594 | }
|
50595 |
|
50596 | return bitwise(x, y, function (a, b) {
|
50597 | return a ^ b;
|
50598 | });
|
50599 | };
|
50600 |
|
50601 | /***/ }),
|
50602 | /* 253 */
|
50603 | /***/ (function(module, exports, __webpack_require__) {
|
50604 |
|
50605 | "use strict";
|
50606 |
|
50607 |
|
50608 | var isInteger = __webpack_require__(3).isInteger;
|
50609 |
|
50610 | var bigLeftShift = __webpack_require__(254);
|
50611 |
|
50612 | function factory(type, config, load, typed) {
|
50613 | var latex = __webpack_require__(4);
|
50614 |
|
50615 | var matrix = load(__webpack_require__(0));
|
50616 | var equalScalar = load(__webpack_require__(11));
|
50617 | var zeros = load(__webpack_require__(43));
|
50618 | var algorithm01 = load(__webpack_require__(37));
|
50619 | var algorithm02 = load(__webpack_require__(27));
|
50620 | var algorithm08 = load(__webpack_require__(94));
|
50621 | var algorithm10 = load(__webpack_require__(41));
|
50622 | var algorithm11 = load(__webpack_require__(20));
|
50623 | var algorithm13 = load(__webpack_require__(7));
|
50624 | var algorithm14 = load(__webpack_require__(6));
|
50625 | /**
|
50626 | * Bitwise left logical shift of a value x by y number of bits, `x << y`.
|
50627 | * For matrices, the function is evaluated element wise.
|
50628 | * For units, the function is evaluated on the best prefix base.
|
50629 | *
|
50630 | * Syntax:
|
50631 | *
|
50632 | * math.leftShift(x, y)
|
50633 | *
|
50634 | * Examples:
|
50635 | *
|
50636 | * math.leftShift(1, 2) // returns number 4
|
50637 | *
|
50638 | * math.leftShift([1, 2, 3], 4) // returns Array [16, 32, 64]
|
50639 | *
|
50640 | * See also:
|
50641 | *
|
50642 | * leftShift, bitNot, bitOr, bitXor, rightArithShift, rightLogShift
|
50643 | *
|
50644 | * @param {number | BigNumber | Array | Matrix} x Value to be shifted
|
50645 | * @param {number | BigNumber} y Amount of shifts
|
50646 | * @return {number | BigNumber | Array | Matrix} `x` shifted left `y` times
|
50647 | */
|
50648 |
|
50649 | var leftShift = typed('leftShift', {
|
50650 | 'number, number': function numberNumber(x, y) {
|
50651 | if (!isInteger(x) || !isInteger(y)) {
|
50652 | throw new Error('Integers expected in function leftShift');
|
50653 | }
|
50654 |
|
50655 | return x << y;
|
50656 | },
|
50657 | 'BigNumber, BigNumber': bigLeftShift,
|
50658 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
50659 | return algorithm08(x, y, leftShift, false);
|
50660 | },
|
50661 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
50662 | return algorithm02(y, x, leftShift, true);
|
50663 | },
|
50664 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
50665 | return algorithm01(x, y, leftShift, false);
|
50666 | },
|
50667 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
50668 | return algorithm13(x, y, leftShift);
|
50669 | },
|
50670 | 'Array, Array': function ArrayArray(x, y) {
|
50671 | // use matrix implementation
|
50672 | return leftShift(matrix(x), matrix(y)).valueOf();
|
50673 | },
|
50674 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
50675 | // use matrix implementation
|
50676 | return leftShift(matrix(x), y);
|
50677 | },
|
50678 | 'Matrix, Array': function MatrixArray(x, y) {
|
50679 | // use matrix implementation
|
50680 | return leftShift(x, matrix(y));
|
50681 | },
|
50682 | 'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
50683 | // check scalar
|
50684 | if (equalScalar(y, 0)) {
|
50685 | return x.clone();
|
50686 | }
|
50687 |
|
50688 | return algorithm11(x, y, leftShift, false);
|
50689 | },
|
50690 | 'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
50691 | // check scalar
|
50692 | if (equalScalar(y, 0)) {
|
50693 | return x.clone();
|
50694 | }
|
50695 |
|
50696 | return algorithm14(x, y, leftShift, false);
|
50697 | },
|
50698 | 'number | BigNumber, SparseMatrix': function numberBigNumberSparseMatrix(x, y) {
|
50699 | // check scalar
|
50700 | if (equalScalar(x, 0)) {
|
50701 | return zeros(y.size(), y.storage());
|
50702 | }
|
50703 |
|
50704 | return algorithm10(y, x, leftShift, true);
|
50705 | },
|
50706 | 'number | BigNumber, DenseMatrix': function numberBigNumberDenseMatrix(x, y) {
|
50707 | // check scalar
|
50708 | if (equalScalar(x, 0)) {
|
50709 | return zeros(y.size(), y.storage());
|
50710 | }
|
50711 |
|
50712 | return algorithm14(y, x, leftShift, true);
|
50713 | },
|
50714 | 'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
|
50715 | // use matrix implementation
|
50716 | return leftShift(matrix(x), y).valueOf();
|
50717 | },
|
50718 | 'number | BigNumber, Array': function numberBigNumberArray(x, y) {
|
50719 | // use matrix implementation
|
50720 | return leftShift(x, matrix(y)).valueOf();
|
50721 | }
|
50722 | });
|
50723 | leftShift.toTex = {
|
50724 | 2: "\\left(${args[0]}".concat(latex.operators['leftShift'], "${args[1]}\\right)")
|
50725 | };
|
50726 | return leftShift;
|
50727 | }
|
50728 |
|
50729 | exports.name = 'leftShift';
|
50730 | exports.factory = factory;
|
50731 |
|
50732 | /***/ }),
|
50733 | /* 254 */
|
50734 | /***/ (function(module, exports, __webpack_require__) {
|
50735 |
|
50736 | "use strict";
|
50737 |
|
50738 | /**
|
50739 | * Bitwise left shift
|
50740 | *
|
50741 | * Special Cases:
|
50742 | * n << -n = N
|
50743 | * n << N = N
|
50744 | * N << n = N
|
50745 | * n << 0 = n
|
50746 | * 0 << n = 0
|
50747 | * I << I = N
|
50748 | * I << n = I
|
50749 | * n << I = I
|
50750 | *
|
50751 | * @param {BigNumber} x
|
50752 | * @param {BigNumber} y
|
50753 | * @return {BigNumber} Result of `x` << `y`
|
50754 | *
|
50755 | */
|
50756 |
|
50757 | module.exports = function leftShift(x, y) {
|
50758 | if (x.isFinite() && !x.isInteger() || y.isFinite() && !y.isInteger()) {
|
50759 | throw new Error('Integers expected in function leftShift');
|
50760 | }
|
50761 |
|
50762 | var BigNumber = x.constructor;
|
50763 |
|
50764 | if (x.isNaN() || y.isNaN() || y.isNegative() && !y.isZero()) {
|
50765 | return new BigNumber(NaN);
|
50766 | }
|
50767 |
|
50768 | if (x.isZero() || y.isZero()) {
|
50769 | return x;
|
50770 | }
|
50771 |
|
50772 | if (!x.isFinite() && !y.isFinite()) {
|
50773 | return new BigNumber(NaN);
|
50774 | } // Math.pow(2, y) is fully precise for y < 55, and fast
|
50775 |
|
50776 |
|
50777 | if (y.lt(55)) {
|
50778 | return x.times(Math.pow(2, y.toNumber()) + '');
|
50779 | }
|
50780 |
|
50781 | return x.times(new BigNumber(2).pow(y));
|
50782 | };
|
50783 |
|
50784 | /***/ }),
|
50785 | /* 255 */
|
50786 | /***/ (function(module, exports, __webpack_require__) {
|
50787 |
|
50788 | "use strict";
|
50789 |
|
50790 |
|
50791 | var isInteger = __webpack_require__(3).isInteger;
|
50792 |
|
50793 | var bigRightArithShift = __webpack_require__(256);
|
50794 |
|
50795 | function factory(type, config, load, typed) {
|
50796 | var latex = __webpack_require__(4);
|
50797 |
|
50798 | var matrix = load(__webpack_require__(0));
|
50799 | var equalScalar = load(__webpack_require__(11));
|
50800 | var zeros = load(__webpack_require__(43));
|
50801 | var algorithm01 = load(__webpack_require__(37));
|
50802 | var algorithm02 = load(__webpack_require__(27));
|
50803 | var algorithm08 = load(__webpack_require__(94));
|
50804 | var algorithm10 = load(__webpack_require__(41));
|
50805 | var algorithm11 = load(__webpack_require__(20));
|
50806 | var algorithm13 = load(__webpack_require__(7));
|
50807 | var algorithm14 = load(__webpack_require__(6));
|
50808 | /**
|
50809 | * Bitwise right arithmetic shift of a value x by y number of bits, `x >> y`.
|
50810 | * For matrices, the function is evaluated element wise.
|
50811 | * For units, the function is evaluated on the best prefix base.
|
50812 | *
|
50813 | * Syntax:
|
50814 | *
|
50815 | * math.rightArithShift(x, y)
|
50816 | *
|
50817 | * Examples:
|
50818 | *
|
50819 | * math.rightArithShift(4, 2) // returns number 1
|
50820 | *
|
50821 | * math.rightArithShift([16, -32, 64], 4) // returns Array [1, -2, 3]
|
50822 | *
|
50823 | * See also:
|
50824 | *
|
50825 | * bitAnd, bitNot, bitOr, bitXor, rightArithShift, rightLogShift
|
50826 | *
|
50827 | * @param {number | BigNumber | Array | Matrix} x Value to be shifted
|
50828 | * @param {number | BigNumber} y Amount of shifts
|
50829 | * @return {number | BigNumber | Array | Matrix} `x` sign-filled shifted right `y` times
|
50830 | */
|
50831 |
|
50832 | var rightArithShift = typed('rightArithShift', {
|
50833 | 'number, number': function numberNumber(x, y) {
|
50834 | if (!isInteger(x) || !isInteger(y)) {
|
50835 | throw new Error('Integers expected in function rightArithShift');
|
50836 | }
|
50837 |
|
50838 | return x >> y;
|
50839 | },
|
50840 | 'BigNumber, BigNumber': bigRightArithShift,
|
50841 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
50842 | return algorithm08(x, y, rightArithShift, false);
|
50843 | },
|
50844 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
50845 | return algorithm02(y, x, rightArithShift, true);
|
50846 | },
|
50847 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
50848 | return algorithm01(x, y, rightArithShift, false);
|
50849 | },
|
50850 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
50851 | return algorithm13(x, y, rightArithShift);
|
50852 | },
|
50853 | 'Array, Array': function ArrayArray(x, y) {
|
50854 | // use matrix implementation
|
50855 | return rightArithShift(matrix(x), matrix(y)).valueOf();
|
50856 | },
|
50857 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
50858 | // use matrix implementation
|
50859 | return rightArithShift(matrix(x), y);
|
50860 | },
|
50861 | 'Matrix, Array': function MatrixArray(x, y) {
|
50862 | // use matrix implementation
|
50863 | return rightArithShift(x, matrix(y));
|
50864 | },
|
50865 | 'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
50866 | // check scalar
|
50867 | if (equalScalar(y, 0)) {
|
50868 | return x.clone();
|
50869 | }
|
50870 |
|
50871 | return algorithm11(x, y, rightArithShift, false);
|
50872 | },
|
50873 | 'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
50874 | // check scalar
|
50875 | if (equalScalar(y, 0)) {
|
50876 | return x.clone();
|
50877 | }
|
50878 |
|
50879 | return algorithm14(x, y, rightArithShift, false);
|
50880 | },
|
50881 | 'number | BigNumber, SparseMatrix': function numberBigNumberSparseMatrix(x, y) {
|
50882 | // check scalar
|
50883 | if (equalScalar(x, 0)) {
|
50884 | return zeros(y.size(), y.storage());
|
50885 | }
|
50886 |
|
50887 | return algorithm10(y, x, rightArithShift, true);
|
50888 | },
|
50889 | 'number | BigNumber, DenseMatrix': function numberBigNumberDenseMatrix(x, y) {
|
50890 | // check scalar
|
50891 | if (equalScalar(x, 0)) {
|
50892 | return zeros(y.size(), y.storage());
|
50893 | }
|
50894 |
|
50895 | return algorithm14(y, x, rightArithShift, true);
|
50896 | },
|
50897 | 'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
|
50898 | // use matrix implementation
|
50899 | return rightArithShift(matrix(x), y).valueOf();
|
50900 | },
|
50901 | 'number | BigNumber, Array': function numberBigNumberArray(x, y) {
|
50902 | // use matrix implementation
|
50903 | return rightArithShift(x, matrix(y)).valueOf();
|
50904 | }
|
50905 | });
|
50906 | rightArithShift.toTex = {
|
50907 | 2: "\\left(${args[0]}".concat(latex.operators['rightArithShift'], "${args[1]}\\right)")
|
50908 | };
|
50909 | return rightArithShift;
|
50910 | }
|
50911 |
|
50912 | exports.name = 'rightArithShift';
|
50913 | exports.factory = factory;
|
50914 |
|
50915 | /***/ }),
|
50916 | /* 256 */
|
50917 | /***/ (function(module, exports, __webpack_require__) {
|
50918 |
|
50919 | "use strict";
|
50920 |
|
50921 | /*
|
50922 | * Special Cases:
|
50923 | * n >> -n = N
|
50924 | * n >> N = N
|
50925 | * N >> n = N
|
50926 | * I >> I = N
|
50927 | * n >> 0 = n
|
50928 | * I >> n = I
|
50929 | * -I >> n = -I
|
50930 | * -I >> I = -I
|
50931 | * n >> I = I
|
50932 | * -n >> I = -1
|
50933 | * 0 >> n = 0
|
50934 | *
|
50935 | * @param {BigNumber} value
|
50936 | * @param {BigNumber} value
|
50937 | * @return {BigNumber} Result of `x` >> `y`
|
50938 | *
|
50939 | */
|
50940 |
|
50941 | module.exports = function rightArithShift(x, y) {
|
50942 | if (x.isFinite() && !x.isInteger() || y.isFinite() && !y.isInteger()) {
|
50943 | throw new Error('Integers expected in function rightArithShift');
|
50944 | }
|
50945 |
|
50946 | var BigNumber = x.constructor;
|
50947 |
|
50948 | if (x.isNaN() || y.isNaN() || y.isNegative() && !y.isZero()) {
|
50949 | return new BigNumber(NaN);
|
50950 | }
|
50951 |
|
50952 | if (x.isZero() || y.isZero()) {
|
50953 | return x;
|
50954 | }
|
50955 |
|
50956 | if (!y.isFinite()) {
|
50957 | if (x.isNegative()) {
|
50958 | return new BigNumber(-1);
|
50959 | }
|
50960 |
|
50961 | if (!x.isFinite()) {
|
50962 | return new BigNumber(NaN);
|
50963 | }
|
50964 |
|
50965 | return new BigNumber(0);
|
50966 | } // Math.pow(2, y) is fully precise for y < 55, and fast
|
50967 |
|
50968 |
|
50969 | if (y.lt(55)) {
|
50970 | return x.div(Math.pow(2, y.toNumber()) + '').floor();
|
50971 | }
|
50972 |
|
50973 | return x.div(new BigNumber(2).pow(y)).floor();
|
50974 | };
|
50975 |
|
50976 | /***/ }),
|
50977 | /* 257 */
|
50978 | /***/ (function(module, exports, __webpack_require__) {
|
50979 |
|
50980 | "use strict";
|
50981 |
|
50982 |
|
50983 | var isInteger = __webpack_require__(3).isInteger;
|
50984 |
|
50985 | function factory(type, config, load, typed) {
|
50986 | var latex = __webpack_require__(4);
|
50987 |
|
50988 | var matrix = load(__webpack_require__(0));
|
50989 | var equalScalar = load(__webpack_require__(11));
|
50990 | var zeros = load(__webpack_require__(43));
|
50991 | var algorithm01 = load(__webpack_require__(37));
|
50992 | var algorithm02 = load(__webpack_require__(27));
|
50993 | var algorithm08 = load(__webpack_require__(94));
|
50994 | var algorithm10 = load(__webpack_require__(41));
|
50995 | var algorithm11 = load(__webpack_require__(20));
|
50996 | var algorithm13 = load(__webpack_require__(7));
|
50997 | var algorithm14 = load(__webpack_require__(6));
|
50998 | /**
|
50999 | * Bitwise right logical shift of value x by y number of bits, `x >>> y`.
|
51000 | * For matrices, the function is evaluated element wise.
|
51001 | * For units, the function is evaluated on the best prefix base.
|
51002 | *
|
51003 | * Syntax:
|
51004 | *
|
51005 | * math.rightLogShift(x, y)
|
51006 | *
|
51007 | * Examples:
|
51008 | *
|
51009 | * math.rightLogShift(4, 2) // returns number 1
|
51010 | *
|
51011 | * math.rightLogShift([16, -32, 64], 4) // returns Array [1, 2, 3]
|
51012 | *
|
51013 | * See also:
|
51014 | *
|
51015 | * bitAnd, bitNot, bitOr, bitXor, leftShift, rightLogShift
|
51016 | *
|
51017 | * @param {number | Array | Matrix} x Value to be shifted
|
51018 | * @param {number} y Amount of shifts
|
51019 | * @return {number | Array | Matrix} `x` zero-filled shifted right `y` times
|
51020 | */
|
51021 |
|
51022 | var rightLogShift = typed('rightLogShift', {
|
51023 | 'number, number': function numberNumber(x, y) {
|
51024 | if (!isInteger(x) || !isInteger(y)) {
|
51025 | throw new Error('Integers expected in function rightLogShift');
|
51026 | }
|
51027 |
|
51028 | return x >>> y;
|
51029 | },
|
51030 | // 'BigNumber, BigNumber': ..., // TODO: implement BigNumber support for rightLogShift
|
51031 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
51032 | return algorithm08(x, y, rightLogShift, false);
|
51033 | },
|
51034 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
51035 | return algorithm02(y, x, rightLogShift, true);
|
51036 | },
|
51037 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
51038 | return algorithm01(x, y, rightLogShift, false);
|
51039 | },
|
51040 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
51041 | return algorithm13(x, y, rightLogShift);
|
51042 | },
|
51043 | 'Array, Array': function ArrayArray(x, y) {
|
51044 | // use matrix implementation
|
51045 | return rightLogShift(matrix(x), matrix(y)).valueOf();
|
51046 | },
|
51047 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
51048 | // use matrix implementation
|
51049 | return rightLogShift(matrix(x), y);
|
51050 | },
|
51051 | 'Matrix, Array': function MatrixArray(x, y) {
|
51052 | // use matrix implementation
|
51053 | return rightLogShift(x, matrix(y));
|
51054 | },
|
51055 | 'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
51056 | // check scalar
|
51057 | if (equalScalar(y, 0)) {
|
51058 | return x.clone();
|
51059 | }
|
51060 |
|
51061 | return algorithm11(x, y, rightLogShift, false);
|
51062 | },
|
51063 | 'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
51064 | // check scalar
|
51065 | if (equalScalar(y, 0)) {
|
51066 | return x.clone();
|
51067 | }
|
51068 |
|
51069 | return algorithm14(x, y, rightLogShift, false);
|
51070 | },
|
51071 | 'number | BigNumber, SparseMatrix': function numberBigNumberSparseMatrix(x, y) {
|
51072 | // check scalar
|
51073 | if (equalScalar(x, 0)) {
|
51074 | return zeros(y.size(), y.storage());
|
51075 | }
|
51076 |
|
51077 | return algorithm10(y, x, rightLogShift, true);
|
51078 | },
|
51079 | 'number | BigNumber, DenseMatrix': function numberBigNumberDenseMatrix(x, y) {
|
51080 | // check scalar
|
51081 | if (equalScalar(x, 0)) {
|
51082 | return zeros(y.size(), y.storage());
|
51083 | }
|
51084 |
|
51085 | return algorithm14(y, x, rightLogShift, true);
|
51086 | },
|
51087 | 'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
|
51088 | // use matrix implementation
|
51089 | return rightLogShift(matrix(x), y).valueOf();
|
51090 | },
|
51091 | 'number | BigNumber, Array': function numberBigNumberArray(x, y) {
|
51092 | // use matrix implementation
|
51093 | return rightLogShift(x, matrix(y)).valueOf();
|
51094 | }
|
51095 | });
|
51096 | rightLogShift.toTex = {
|
51097 | 2: "\\left(${args[0]}".concat(latex.operators['rightLogShift'], "${args[1]}\\right)")
|
51098 | };
|
51099 | return rightLogShift;
|
51100 | }
|
51101 |
|
51102 | exports.name = 'rightLogShift';
|
51103 | exports.factory = factory;
|
51104 |
|
51105 | /***/ }),
|
51106 | /* 258 */
|
51107 | /***/ (function(module, exports, __webpack_require__) {
|
51108 |
|
51109 | "use strict";
|
51110 |
|
51111 |
|
51112 | module.exports = [__webpack_require__(259), __webpack_require__(260), __webpack_require__(140), __webpack_require__(261)];
|
51113 |
|
51114 | /***/ }),
|
51115 | /* 259 */
|
51116 | /***/ (function(module, exports, __webpack_require__) {
|
51117 |
|
51118 | "use strict";
|
51119 |
|
51120 |
|
51121 | function factory(type, config, load, typed) {
|
51122 | var add = load(__webpack_require__(14));
|
51123 | var stirlingS2 = load(__webpack_require__(140));
|
51124 | var isNegative = load(__webpack_require__(61));
|
51125 | var isInteger = load(__webpack_require__(34));
|
51126 | /**
|
51127 | * The Bell Numbers count the number of partitions of a set. A partition is a pairwise disjoint subset of S whose union is S.
|
51128 | * bellNumbers only takes integer arguments.
|
51129 | * The following condition must be enforced: n >= 0
|
51130 | *
|
51131 | * Syntax:
|
51132 | *
|
51133 | * math.bellNumbers(n)
|
51134 | *
|
51135 | * Examples:
|
51136 | *
|
51137 | * math.bellNumbers(3) // returns 5
|
51138 | * math.bellNumbers(8) // returns 4140
|
51139 | *
|
51140 | * See also:
|
51141 | *
|
51142 | * stirlingS2
|
51143 | *
|
51144 | * @param {Number | BigNumber} n Total number of objects in the set
|
51145 | * @return {Number | BigNumber} B(n)
|
51146 | */
|
51147 |
|
51148 | var bellNumbers = typed('bellNumbers', {
|
51149 | 'number | BigNumber': function numberBigNumber(n) {
|
51150 | if (!isInteger(n) || isNegative(n)) {
|
51151 | throw new TypeError('Non-negative integer value expected in function bellNumbers');
|
51152 | } // Sum (k=0, n) S(n,k).
|
51153 |
|
51154 |
|
51155 | var result = 0;
|
51156 |
|
51157 | for (var i = 0; i <= n; i++) {
|
51158 | result = add(result, stirlingS2(n, i));
|
51159 | }
|
51160 |
|
51161 | return result;
|
51162 | }
|
51163 | });
|
51164 | bellNumbers.toTex = {
|
51165 | 1: "\\mathrm{B}_{${args[0]}}"
|
51166 | };
|
51167 | return bellNumbers;
|
51168 | }
|
51169 |
|
51170 | exports.name = 'bellNumbers';
|
51171 | exports.factory = factory;
|
51172 |
|
51173 | /***/ }),
|
51174 | /* 260 */
|
51175 | /***/ (function(module, exports, __webpack_require__) {
|
51176 |
|
51177 | "use strict";
|
51178 |
|
51179 |
|
51180 | function factory(type, config, load, typed) {
|
51181 | var combinations = load(__webpack_require__(76));
|
51182 | var add = load(__webpack_require__(17));
|
51183 | var isPositive = load(__webpack_require__(73));
|
51184 | var isInteger = load(__webpack_require__(34));
|
51185 | var larger = load(__webpack_require__(33));
|
51186 | /**
|
51187 | * The composition counts of n into k parts.
|
51188 | *
|
51189 | * composition only takes integer arguments.
|
51190 | * The following condition must be enforced: k <= n.
|
51191 | *
|
51192 | * Syntax:
|
51193 | *
|
51194 | * math.composition(n, k)
|
51195 | *
|
51196 | * Examples:
|
51197 | *
|
51198 | * math.composition(5, 3) // returns 6
|
51199 | *
|
51200 | * See also:
|
51201 | *
|
51202 | * combinations
|
51203 | *
|
51204 | * @param {Number | BigNumber} n Total number of objects in the set
|
51205 | * @param {Number | BigNumber} k Number of objects in the subset
|
51206 | * @return {Number | BigNumber} Returns the composition counts of n into k parts.
|
51207 | */
|
51208 |
|
51209 | var composition = typed('composition', {
|
51210 | 'number | BigNumber, number | BigNumber': function numberBigNumberNumberBigNumber(n, k) {
|
51211 | if (!isInteger(n) || !isPositive(n) || !isInteger(k) || !isPositive(k)) {
|
51212 | throw new TypeError('Positive integer value expected in function composition');
|
51213 | } else if (larger(k, n)) {
|
51214 | throw new TypeError('k must be less than or equal to n in function composition');
|
51215 | }
|
51216 |
|
51217 | return combinations(add(n, -1), add(k, -1));
|
51218 | }
|
51219 | });
|
51220 | composition.toTex = undefined; // use default template
|
51221 |
|
51222 | return composition;
|
51223 | }
|
51224 |
|
51225 | exports.name = 'composition';
|
51226 | exports.factory = factory;
|
51227 |
|
51228 | /***/ }),
|
51229 | /* 261 */
|
51230 | /***/ (function(module, exports, __webpack_require__) {
|
51231 |
|
51232 | "use strict";
|
51233 |
|
51234 |
|
51235 | function factory(type, config, load, typed) {
|
51236 | var add = load(__webpack_require__(14));
|
51237 | var divide = load(__webpack_require__(45));
|
51238 | var multiply = load(__webpack_require__(10));
|
51239 | var combinations = load(__webpack_require__(76));
|
51240 | var isNegative = load(__webpack_require__(61));
|
51241 | var isInteger = load(__webpack_require__(34));
|
51242 | /**
|
51243 | * The Catalan Numbers enumerate combinatorial structures of many different types.
|
51244 | * catalan only takes integer arguments.
|
51245 | * The following condition must be enforced: n >= 0
|
51246 | *
|
51247 | * Syntax:
|
51248 | *
|
51249 | * math.catalan(n)
|
51250 | *
|
51251 | * Examples:
|
51252 | *
|
51253 | * math.catalan(3) // returns 5
|
51254 | * math.catalan(8) // returns 1430
|
51255 | *
|
51256 | * See also:
|
51257 | *
|
51258 | * bellNumbers
|
51259 | *
|
51260 | * @param {Number | BigNumber} n nth Catalan number
|
51261 | * @return {Number | BigNumber} Cn(n)
|
51262 | */
|
51263 |
|
51264 | var catalan = typed('catalan', {
|
51265 | 'number | BigNumber': function numberBigNumber(n) {
|
51266 | if (!isInteger(n) || isNegative(n)) {
|
51267 | throw new TypeError('Non-negative integer value expected in function catalan');
|
51268 | }
|
51269 |
|
51270 | return divide(combinations(multiply(n, 2), n), add(n, 1));
|
51271 | }
|
51272 | });
|
51273 | catalan.toTex = {
|
51274 | 1: "\\mathrm{C}_{${args[0]}}"
|
51275 | };
|
51276 | return catalan;
|
51277 | }
|
51278 |
|
51279 | exports.name = 'catalan';
|
51280 | exports.factory = factory;
|
51281 |
|
51282 | /***/ }),
|
51283 | /* 262 */
|
51284 | /***/ (function(module, exports, __webpack_require__) {
|
51285 |
|
51286 | "use strict";
|
51287 |
|
51288 |
|
51289 | module.exports = [__webpack_require__(263), __webpack_require__(71), __webpack_require__(264), __webpack_require__(265)];
|
51290 |
|
51291 | /***/ }),
|
51292 | /* 263 */
|
51293 | /***/ (function(module, exports, __webpack_require__) {
|
51294 |
|
51295 | "use strict";
|
51296 |
|
51297 |
|
51298 | var deepMap = __webpack_require__(1);
|
51299 |
|
51300 | function factory(type, config, load, typed) {
|
51301 | /**
|
51302 | * Compute the argument of a complex value.
|
51303 | * For a complex number `a + bi`, the argument is computed as `atan2(b, a)`.
|
51304 | *
|
51305 | * For matrices, the function is evaluated element wise.
|
51306 | *
|
51307 | * Syntax:
|
51308 | *
|
51309 | * math.arg(x)
|
51310 | *
|
51311 | * Examples:
|
51312 | *
|
51313 | * const a = math.complex(2, 2)
|
51314 | * math.arg(a) / math.pi // returns number 0.25
|
51315 | *
|
51316 | * const b = math.complex('2 + 3i')
|
51317 | * math.arg(b) // returns number 0.982793723247329
|
51318 | * math.atan2(3, 2) // returns number 0.982793723247329
|
51319 | *
|
51320 | * See also:
|
51321 | *
|
51322 | * re, im, conj, abs
|
51323 | *
|
51324 | * @param {number | BigNumber | Complex | Array | Matrix} x
|
51325 | * A complex number or array with complex numbers
|
51326 | * @return {number | BigNumber | Array | Matrix} The argument of x
|
51327 | */
|
51328 | var arg = typed('arg', {
|
51329 | 'number': function number(x) {
|
51330 | return Math.atan2(0, x);
|
51331 | },
|
51332 | 'BigNumber': function BigNumber(x) {
|
51333 | return type.BigNumber.atan2(0, x);
|
51334 | },
|
51335 | 'Complex': function Complex(x) {
|
51336 | return x.arg();
|
51337 | },
|
51338 | // TODO: implement BigNumber support for function arg
|
51339 | 'Array | Matrix': function ArrayMatrix(x) {
|
51340 | return deepMap(x, arg);
|
51341 | }
|
51342 | });
|
51343 | arg.toTex = {
|
51344 | 1: "\\arg\\left(${args[0]}\\right)"
|
51345 | };
|
51346 | return arg;
|
51347 | }
|
51348 |
|
51349 | exports.name = 'arg';
|
51350 | exports.factory = factory;
|
51351 |
|
51352 | /***/ }),
|
51353 | /* 264 */
|
51354 | /***/ (function(module, exports, __webpack_require__) {
|
51355 |
|
51356 | "use strict";
|
51357 |
|
51358 |
|
51359 | var deepMap = __webpack_require__(1);
|
51360 |
|
51361 | function factory(type, config, load, typed) {
|
51362 | /**
|
51363 | * Get the imaginary part of a complex number.
|
51364 | * For a complex number `a + bi`, the function returns `b`.
|
51365 | *
|
51366 | * For matrices, the function is evaluated element wise.
|
51367 | *
|
51368 | * Syntax:
|
51369 | *
|
51370 | * math.im(x)
|
51371 | *
|
51372 | * Examples:
|
51373 | *
|
51374 | * const a = math.complex(2, 3)
|
51375 | * math.re(a) // returns number 2
|
51376 | * math.im(a) // returns number 3
|
51377 | *
|
51378 | * math.re(math.complex('-5.2i')) // returns number -5.2
|
51379 | * math.re(math.complex(2.4)) // returns number 0
|
51380 | *
|
51381 | * See also:
|
51382 | *
|
51383 | * re, conj, abs, arg
|
51384 | *
|
51385 | * @param {number | BigNumber | Complex | Array | Matrix} x
|
51386 | * A complex number or array with complex numbers
|
51387 | * @return {number | BigNumber | Array | Matrix} The imaginary part of x
|
51388 | */
|
51389 | var im = typed('im', {
|
51390 | 'number': function number(x) {
|
51391 | return 0;
|
51392 | },
|
51393 | 'BigNumber': function BigNumber(x) {
|
51394 | return new type.BigNumber(0);
|
51395 | },
|
51396 | 'Complex': function Complex(x) {
|
51397 | return x.im;
|
51398 | },
|
51399 | 'Array | Matrix': function ArrayMatrix(x) {
|
51400 | return deepMap(x, im);
|
51401 | }
|
51402 | });
|
51403 | im.toTex = {
|
51404 | 1: "\\Im\\left\\lbrace${args[0]}\\right\\rbrace"
|
51405 | };
|
51406 | return im;
|
51407 | }
|
51408 |
|
51409 | exports.name = 'im';
|
51410 | exports.factory = factory;
|
51411 |
|
51412 | /***/ }),
|
51413 | /* 265 */
|
51414 | /***/ (function(module, exports, __webpack_require__) {
|
51415 |
|
51416 | "use strict";
|
51417 |
|
51418 |
|
51419 | var deepMap = __webpack_require__(1);
|
51420 |
|
51421 | function factory(type, config, load, typed) {
|
51422 | /**
|
51423 | * Get the real part of a complex number.
|
51424 | * For a complex number `a + bi`, the function returns `a`.
|
51425 | *
|
51426 | * For matrices, the function is evaluated element wise.
|
51427 | *
|
51428 | * Syntax:
|
51429 | *
|
51430 | * math.re(x)
|
51431 | *
|
51432 | * Examples:
|
51433 | *
|
51434 | * const a = math.complex(2, 3)
|
51435 | * math.re(a) // returns number 2
|
51436 | * math.im(a) // returns number 3
|
51437 | *
|
51438 | * math.re(math.complex('-5.2i')) // returns number 0
|
51439 | * math.re(math.complex(2.4)) // returns number 2.4
|
51440 | *
|
51441 | * See also:
|
51442 | *
|
51443 | * im, conj, abs, arg
|
51444 | *
|
51445 | * @param {number | BigNumber | Complex | Array | Matrix} x
|
51446 | * A complex number or array with complex numbers
|
51447 | * @return {number | BigNumber | Array | Matrix} The real part of x
|
51448 | */
|
51449 | var re = typed('re', {
|
51450 | 'number': function number(x) {
|
51451 | return x;
|
51452 | },
|
51453 | 'BigNumber': function BigNumber(x) {
|
51454 | return x;
|
51455 | },
|
51456 | 'Complex': function Complex(x) {
|
51457 | return x.re;
|
51458 | },
|
51459 | 'Array | Matrix': function ArrayMatrix(x) {
|
51460 | return deepMap(x, re);
|
51461 | }
|
51462 | });
|
51463 | re.toTex = {
|
51464 | 1: "\\Re\\left\\lbrace${args[0]}\\right\\rbrace"
|
51465 | };
|
51466 | return re;
|
51467 | }
|
51468 |
|
51469 | exports.name = 're';
|
51470 | exports.factory = factory;
|
51471 |
|
51472 | /***/ }),
|
51473 | /* 266 */
|
51474 | /***/ (function(module, exports, __webpack_require__) {
|
51475 |
|
51476 | "use strict";
|
51477 |
|
51478 |
|
51479 | module.exports = [__webpack_require__(267), __webpack_require__(268)];
|
51480 |
|
51481 | /***/ }),
|
51482 | /* 267 */
|
51483 | /***/ (function(module, exports, __webpack_require__) {
|
51484 |
|
51485 | "use strict";
|
51486 |
|
51487 |
|
51488 | function factory(type, config, load, typed) {
|
51489 | var abs = load(__webpack_require__(25));
|
51490 | var add = load(__webpack_require__(14));
|
51491 | var addScalar = load(__webpack_require__(17));
|
51492 | var matrix = load(__webpack_require__(0));
|
51493 | var multiply = load(__webpack_require__(10));
|
51494 | var multiplyScalar = load(__webpack_require__(21));
|
51495 | var divideScalar = load(__webpack_require__(12));
|
51496 | var subtract = load(__webpack_require__(15));
|
51497 | var smaller = load(__webpack_require__(38));
|
51498 | var equalScalar = load(__webpack_require__(11));
|
51499 | /**
|
51500 | * Calculates the point of intersection of two lines in two or three dimensions
|
51501 | * and of a line and a plane in three dimensions. The inputs are in the form of
|
51502 | * arrays or 1 dimensional matrices. The line intersection functions return null
|
51503 | * if the lines do not meet.
|
51504 | *
|
51505 | * Note: Fill the plane coefficients as `x + y + z = c` and not as `x + y + z + c = 0`.
|
51506 | *
|
51507 | * Syntax:
|
51508 | *
|
51509 | * math.intersect(endPoint1Line1, endPoint2Line1, endPoint1Line2, endPoint2Line2)
|
51510 | * math.intersect(endPoint1, endPoint2, planeCoefficients)
|
51511 | *
|
51512 | * Examples:
|
51513 | *
|
51514 | * math.intersect([0, 0], [10, 10], [10, 0], [0, 10]) // Returns [5, 5]
|
51515 | * math.intersect([0, 0, 0], [10, 10, 0], [10, 0, 0], [0, 10, 0]) // Returns [5, 5, 0]
|
51516 | * math.intersect([1, 0, 1], [4, -2, 2], [1, 1, 1, 6]) // Returns [7, -4, 3]
|
51517 | *
|
51518 | * @param {Array | Matrix} w Co-ordinates of first end-point of first line
|
51519 | * @param {Array | Matrix} x Co-ordinates of second end-point of first line
|
51520 | * @param {Array | Matrix} y Co-ordinates of first end-point of second line
|
51521 | * OR Co-efficients of the plane's equation
|
51522 | * @param {Array | Matrix} z Co-ordinates of second end-point of second line
|
51523 | * OR null if the calculation is for line and plane
|
51524 | * @return {Array} Returns the point of intersection of lines/lines-planes
|
51525 | */
|
51526 |
|
51527 | var intersect = typed('intersect', {
|
51528 | 'Array, Array, Array': function ArrayArrayArray(x, y, plane) {
|
51529 | if (!_3d(x)) {
|
51530 | throw new TypeError('Array with 3 numbers or BigNumbers expected for first argument');
|
51531 | }
|
51532 |
|
51533 | if (!_3d(y)) {
|
51534 | throw new TypeError('Array with 3 numbers or BigNumbers expected for second argument');
|
51535 | }
|
51536 |
|
51537 | if (!_4d(plane)) {
|
51538 | throw new TypeError('Array with 4 numbers expected as third argument');
|
51539 | }
|
51540 |
|
51541 | return _intersectLinePlane(x[0], x[1], x[2], y[0], y[1], y[2], plane[0], plane[1], plane[2], plane[3]);
|
51542 | },
|
51543 | 'Array, Array, Array, Array': function ArrayArrayArrayArray(w, x, y, z) {
|
51544 | if (w.length === 2) {
|
51545 | if (!_2d(w)) {
|
51546 | throw new TypeError('Array with 2 numbers or BigNumbers expected for first argument');
|
51547 | }
|
51548 |
|
51549 | if (!_2d(x)) {
|
51550 | throw new TypeError('Array with 2 numbers or BigNumbers expected for second argument');
|
51551 | }
|
51552 |
|
51553 | if (!_2d(y)) {
|
51554 | throw new TypeError('Array with 2 numbers or BigNumbers expected for third argument');
|
51555 | }
|
51556 |
|
51557 | if (!_2d(z)) {
|
51558 | throw new TypeError('Array with 2 numbers or BigNumbers expected for fourth argument');
|
51559 | }
|
51560 |
|
51561 | return _intersect2d(w, x, y, z);
|
51562 | } else if (w.length === 3) {
|
51563 | if (!_3d(w)) {
|
51564 | throw new TypeError('Array with 3 numbers or BigNumbers expected for first argument');
|
51565 | }
|
51566 |
|
51567 | if (!_3d(x)) {
|
51568 | throw new TypeError('Array with 3 numbers or BigNumbers expected for second argument');
|
51569 | }
|
51570 |
|
51571 | if (!_3d(y)) {
|
51572 | throw new TypeError('Array with 3 numbers or BigNumbers expected for third argument');
|
51573 | }
|
51574 |
|
51575 | if (!_3d(z)) {
|
51576 | throw new TypeError('Array with 3 numbers or BigNumbers expected for fourth argument');
|
51577 | }
|
51578 |
|
51579 | return _intersect3d(w[0], w[1], w[2], x[0], x[1], x[2], y[0], y[1], y[2], z[0], z[1], z[2]);
|
51580 | } else {
|
51581 | throw new TypeError('Arrays with two or thee dimensional points expected');
|
51582 | }
|
51583 | },
|
51584 | 'Matrix, Matrix, Matrix': function MatrixMatrixMatrix(x, y, plane) {
|
51585 | return matrix(intersect(x.valueOf(), y.valueOf(), plane.valueOf()));
|
51586 | },
|
51587 | 'Matrix, Matrix, Matrix, Matrix': function MatrixMatrixMatrixMatrix(w, x, y, z) {
|
51588 | // TODO: output matrix type should match input matrix type
|
51589 | return matrix(intersect(w.valueOf(), x.valueOf(), y.valueOf(), z.valueOf()));
|
51590 | }
|
51591 | });
|
51592 |
|
51593 | function _isNumber(a) {
|
51594 | // intersect supports numbers and bignumbers
|
51595 | return typeof a === 'number' || type.isBigNumber(a);
|
51596 | }
|
51597 |
|
51598 | function _2d(x) {
|
51599 | return x.length === 2 && _isNumber(x[0]) && _isNumber(x[1]);
|
51600 | }
|
51601 |
|
51602 | function _3d(x) {
|
51603 | return x.length === 3 && _isNumber(x[0]) && _isNumber(x[1]) && _isNumber(x[2]);
|
51604 | }
|
51605 |
|
51606 | function _4d(x) {
|
51607 | return x.length === 4 && _isNumber(x[0]) && _isNumber(x[1]) && _isNumber(x[2]) && _isNumber(x[3]);
|
51608 | }
|
51609 |
|
51610 | function _intersect2d(p1a, p1b, p2a, p2b) {
|
51611 | var o1 = p1a;
|
51612 | var o2 = p2a;
|
51613 | var d1 = subtract(o1, p1b);
|
51614 | var d2 = subtract(o2, p2b);
|
51615 | var det = subtract(multiplyScalar(d1[0], d2[1]), multiplyScalar(d2[0], d1[1]));
|
51616 |
|
51617 | if (smaller(abs(det), config.epsilon)) {
|
51618 | return null;
|
51619 | }
|
51620 |
|
51621 | var d20o11 = multiplyScalar(d2[0], o1[1]);
|
51622 | var d21o10 = multiplyScalar(d2[1], o1[0]);
|
51623 | var d20o21 = multiplyScalar(d2[0], o2[1]);
|
51624 | var d21o20 = multiplyScalar(d2[1], o2[0]);
|
51625 | var t = divideScalar(addScalar(subtract(subtract(d20o11, d21o10), d20o21), d21o20), det);
|
51626 | return add(multiply(d1, t), o1);
|
51627 | }
|
51628 |
|
51629 | function _intersect3dHelper(a, b, c, d, e, f, g, h, i, j, k, l) {
|
51630 | // (a - b)*(c - d) + (e - f)*(g - h) + (i - j)*(k - l)
|
51631 | var add1 = multiplyScalar(subtract(a, b), subtract(c, d));
|
51632 | var add2 = multiplyScalar(subtract(e, f), subtract(g, h));
|
51633 | var add3 = multiplyScalar(subtract(i, j), subtract(k, l));
|
51634 | return addScalar(addScalar(add1, add2), add3);
|
51635 | }
|
51636 |
|
51637 | function _intersect3d(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4) {
|
51638 | var d1343 = _intersect3dHelper(x1, x3, x4, x3, y1, y3, y4, y3, z1, z3, z4, z3);
|
51639 |
|
51640 | var d4321 = _intersect3dHelper(x4, x3, x2, x1, y4, y3, y2, y1, z4, z3, z2, z1);
|
51641 |
|
51642 | var d1321 = _intersect3dHelper(x1, x3, x2, x1, y1, y3, y2, y1, z1, z3, z2, z1);
|
51643 |
|
51644 | var d4343 = _intersect3dHelper(x4, x3, x4, x3, y4, y3, y4, y3, z4, z3, z4, z3);
|
51645 |
|
51646 | var d2121 = _intersect3dHelper(x2, x1, x2, x1, y2, y1, y2, y1, z2, z1, z2, z1);
|
51647 |
|
51648 | var ta = divideScalar(subtract(multiplyScalar(d1343, d4321), multiplyScalar(d1321, d4343)), subtract(multiplyScalar(d2121, d4343), multiplyScalar(d4321, d4321)));
|
51649 | var tb = divideScalar(addScalar(d1343, multiplyScalar(ta, d4321)), d4343);
|
51650 | var pax = addScalar(x1, multiplyScalar(ta, subtract(x2, x1)));
|
51651 | var pay = addScalar(y1, multiplyScalar(ta, subtract(y2, y1)));
|
51652 | var paz = addScalar(z1, multiplyScalar(ta, subtract(z2, z1)));
|
51653 | var pbx = addScalar(x3, multiplyScalar(tb, subtract(x4, x3)));
|
51654 | var pby = addScalar(y3, multiplyScalar(tb, subtract(y4, y3)));
|
51655 | var pbz = addScalar(z3, multiplyScalar(tb, subtract(z4, z3)));
|
51656 |
|
51657 | if (equalScalar(pax, pbx) && equalScalar(pay, pby) && equalScalar(paz, pbz)) {
|
51658 | return [pax, pay, paz];
|
51659 | } else {
|
51660 | return null;
|
51661 | }
|
51662 | }
|
51663 |
|
51664 | function _intersectLinePlane(x1, y1, z1, x2, y2, z2, x, y, z, c) {
|
51665 | var x1x = multiplyScalar(x1, x);
|
51666 | var x2x = multiplyScalar(x2, x);
|
51667 | var y1y = multiplyScalar(y1, y);
|
51668 | var y2y = multiplyScalar(y2, y);
|
51669 | var z1z = multiplyScalar(z1, z);
|
51670 | var z2z = multiplyScalar(z2, z);
|
51671 | var t = divideScalar(subtract(subtract(subtract(c, x1x), y1y), z1z), subtract(subtract(subtract(addScalar(addScalar(x2x, y2y), z2z), x1x), y1y), z1z));
|
51672 | var px = addScalar(x1, multiplyScalar(t, subtract(x2, x1)));
|
51673 | var py = addScalar(y1, multiplyScalar(t, subtract(y2, y1)));
|
51674 | var pz = addScalar(z1, multiplyScalar(t, subtract(z2, z1)));
|
51675 | return [px, py, pz]; // TODO: Add cases when line is parallel to the plane:
|
51676 | // (a) no intersection,
|
51677 | // (b) line contained in plane
|
51678 | }
|
51679 |
|
51680 | return intersect;
|
51681 | }
|
51682 |
|
51683 | exports.name = 'intersect';
|
51684 | exports.factory = factory;
|
51685 |
|
51686 | /***/ }),
|
51687 | /* 268 */
|
51688 | /***/ (function(module, exports, __webpack_require__) {
|
51689 |
|
51690 | "use strict";
|
51691 |
|
51692 |
|
51693 | function factory(type, config, load, typed) {
|
51694 | var add = load(__webpack_require__(17));
|
51695 | var subtract = load(__webpack_require__(15));
|
51696 | var multiply = load(__webpack_require__(21));
|
51697 | var divide = load(__webpack_require__(12));
|
51698 | var negate = load(__webpack_require__(39));
|
51699 | var sqrt = load(__webpack_require__(46));
|
51700 | var abs = load(__webpack_require__(25));
|
51701 | /**
|
51702 | * Calculates:
|
51703 | * The eucledian distance between two points in 2 and 3 dimensional spaces.
|
51704 | * Distance between point and a line in 2 and 3 dimensional spaces.
|
51705 | * Pairwise distance between a set of 2D or 3D points
|
51706 | * NOTE:
|
51707 | * When substituting coefficients of a line(a, b and c), use ax + by + c = 0 instead of ax + by = c
|
51708 | * For parametric equation of a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b, c)
|
51709 | *
|
51710 | * Syntax:
|
51711 | * math.distance([x1, y1], [x2, y2])
|
51712 | *- math.distance({pointOneX: 4, pointOneY: 5}, {pointTwoX: 2, pointTwoY: 7})
|
51713 | * math.distance([x1, y1, z1], [x2, y2, z2])
|
51714 | * math.distance({pointOneX: 4, pointOneY: 5, pointOneZ: 8}, {pointTwoX: 2, pointTwoY: 7, pointTwoZ: 9})
|
51715 | * math.distance([[A], [B], [C]...])
|
51716 | * math.distance([x1, y1], [LinePtX1, LinePtY1], [LinePtX2, LinePtY2])
|
51717 | * math.distance({pointX: 1, pointY: 4}, {lineOnePtX: 6, lineOnePtY: 3}, {lineTwoPtX: 2, lineTwoPtY: 8})
|
51718 | * math.distance([x1, y1, z1], [LinePtX1, LinePtY1, LinePtZ1], [LinePtX2, LinePtY2, LinePtZ2])
|
51719 | * math.distance({pointX: 1, pointY: 4, pointZ: 7}, {lineOnePtX: 6, lineOnePtY: 3, lineOnePtZ: 4}, {lineTwoPtX: 2, lineTwoPtY: 8, lineTwoPtZ: 5})
|
51720 | * math.distance([x1, y1], [xCoeffLine, yCoeffLine, constant])
|
51721 | * math.distance({pointX: 10, pointY: 10}, {xCoeffLine: 8, yCoeffLine: 1, constant: 3})
|
51722 | * math.distance([x1, y1, z1], [x0, y0, z0, a-tCoeff, b-tCoeff, c-tCoeff]) point and parametric equation of 3D line
|
51723 | * math.distance([x, y, z], [x0, y0, z0, a, b, c])
|
51724 | * math.distance({pointX: 2, pointY: 5, pointZ: 9}, {x0: 4, y0: 6, z0: 3, a: 4, b: 2, c: 0})
|
51725 | *
|
51726 | * Examples:
|
51727 | * math.distance([0,0], [4,4]) // Returns 5.6569
|
51728 | * math.distance(
|
51729 | * {pointOneX: 0, pointOneY: 0},
|
51730 | * {pointTwoX: 10, pointTwoY: 10}) // Returns 14.142135623730951
|
51731 | * math.distance([1, 0, 1], [4, -2, 2]) // Returns 3.74166
|
51732 | * math.distance(
|
51733 | * {pointOneX: 4, pointOneY: 5, pointOneZ: 8},
|
51734 | * {pointTwoX: 2, pointTwoY: 7, pointTwoZ: 9}) // Returns 3
|
51735 | * math.distance([[1, 2], [1, 2], [1, 3]]) // Returns [0, 1, 1]
|
51736 | * math.distance([[1,2,4], [1,2,6], [8,1,3]]) // Returns [2, 7.14142842854285, 7.681145747868608]
|
51737 | * math.distance([10, 10], [8, 1, 3]) // Returns 11.535230316796387
|
51738 | * math.distance([10, 10], [2, 3], [-8, 0]) // Returns 8.759953130362847
|
51739 | * math.distance(
|
51740 | * {pointX: 1, pointY: 4},
|
51741 | * {lineOnePtX: 6, lineOnePtY: 3},
|
51742 | * {lineTwoPtX: 2, lineTwoPtY: 8}) // Returns 2.720549372624744
|
51743 | * math.distance([2, 3, 1], [1, 1, 2, 5, 0, 1]) // Returns 2.3204774044612857
|
51744 | * math.distance(
|
51745 | * {pointX: 2, pointY: 3, pointZ: 1},
|
51746 | * {x0: 1, y0: 1, z0: 2, a: 5, b: 0, c: 1} // Returns 2.3204774044612857
|
51747 | *
|
51748 | * @param {Array | Matrix | Object} x Co-ordinates of first point
|
51749 | * @param {Array | Matrix | Object} y Co-ordinates of second point
|
51750 | * @return {Number | BigNumber} Returns the distance from two/three points
|
51751 | */
|
51752 |
|
51753 | var distance = typed('distance', {
|
51754 | 'Array, Array, Array': function ArrayArrayArray(x, y, z) {
|
51755 | // Point to Line 2D (x=Point, y=LinePoint1, z=LinePoint2)
|
51756 | if (x.length === 2 && y.length === 2 && z.length === 2) {
|
51757 | if (!_2d(x)) {
|
51758 | throw new TypeError('Array with 2 numbers or BigNumbers expected for first argument');
|
51759 | }
|
51760 |
|
51761 | if (!_2d(y)) {
|
51762 | throw new TypeError('Array with 2 numbers or BigNumbers expected for second argument');
|
51763 | }
|
51764 |
|
51765 | if (!_2d(z)) {
|
51766 | throw new TypeError('Array with 2 numbers or BigNumbers expected for third argument');
|
51767 | }
|
51768 |
|
51769 | var m = divide(subtract(z[1], z[0]), subtract(y[1], y[0]));
|
51770 | var xCoeff = multiply(multiply(m, m), y[0]);
|
51771 | var yCoeff = negate(multiply(m, y[0]));
|
51772 | var constant = x[1];
|
51773 | return _distancePointLine2D(x[0], x[1], xCoeff, yCoeff, constant);
|
51774 | } else {
|
51775 | throw new TypeError('Invalid Arguments: Try again');
|
51776 | }
|
51777 | },
|
51778 | 'Object, Object, Object': function ObjectObjectObject(x, y, z) {
|
51779 | if (Object.keys(x).length === 2 && Object.keys(y).length === 2 && Object.keys(z).length === 2) {
|
51780 | if (!_2d(x)) {
|
51781 | throw new TypeError('Values of pointX and pointY should be numbers or BigNumbers');
|
51782 | }
|
51783 |
|
51784 | if (!_2d(y)) {
|
51785 | throw new TypeError('Values of lineOnePtX and lineOnePtY should be numbers or BigNumbers');
|
51786 | }
|
51787 |
|
51788 | if (!_2d(z)) {
|
51789 | throw new TypeError('Values of lineTwoPtX and lineTwoPtY should be numbers or BigNumbers');
|
51790 | }
|
51791 |
|
51792 | if (x.hasOwnProperty('pointX') && x.hasOwnProperty('pointY') && y.hasOwnProperty('lineOnePtX') && y.hasOwnProperty('lineOnePtY') && z.hasOwnProperty('lineTwoPtX') && z.hasOwnProperty('lineTwoPtY')) {
|
51793 | var m = divide(subtract(z.lineTwoPtY, z.lineTwoPtX), subtract(y.lineOnePtY, y.lineOnePtX));
|
51794 | var xCoeff = multiply(multiply(m, m), y.lineOnePtX);
|
51795 | var yCoeff = negate(multiply(m, y.lineOnePtX));
|
51796 | var constant = x.pointX;
|
51797 | return _distancePointLine2D(x.pointX, x.pointY, xCoeff, yCoeff, constant);
|
51798 | } else {
|
51799 | throw new TypeError('Key names do not match');
|
51800 | }
|
51801 | } else {
|
51802 | throw new TypeError('Invalid Arguments: Try again');
|
51803 | }
|
51804 | },
|
51805 | 'Array, Array': function ArrayArray(x, y) {
|
51806 | // Point to Line 2D (x=[pointX, pointY], y=[x-coeff, y-coeff, const])
|
51807 | if (x.length === 2 && y.length === 3) {
|
51808 | if (!_2d(x)) {
|
51809 | throw new TypeError('Array with 2 numbers or BigNumbers expected for first argument');
|
51810 | }
|
51811 |
|
51812 | if (!_3d(y)) {
|
51813 | throw new TypeError('Array with 3 numbers or BigNumbers expected for second argument');
|
51814 | }
|
51815 |
|
51816 | return _distancePointLine2D(x[0], x[1], y[0], y[1], y[2]);
|
51817 | } else if (x.length === 3 && y.length === 6) {
|
51818 | // Point to Line 3D
|
51819 | if (!_3d(x)) {
|
51820 | throw new TypeError('Array with 3 numbers or BigNumbers expected for first argument');
|
51821 | }
|
51822 |
|
51823 | if (!_parametricLine(y)) {
|
51824 | throw new TypeError('Array with 6 numbers or BigNumbers expected for second argument');
|
51825 | }
|
51826 |
|
51827 | return _distancePointLine3D(x[0], x[1], x[2], y[0], y[1], y[2], y[3], y[4], y[5]);
|
51828 | } else if (x.length === 2 && y.length === 2) {
|
51829 | // Point to Point 2D
|
51830 | if (!_2d(x)) {
|
51831 | throw new TypeError('Array with 2 numbers or BigNumbers expected for first argument');
|
51832 | }
|
51833 |
|
51834 | if (!_2d(y)) {
|
51835 | throw new TypeError('Array with 2 numbers or BigNumbers expected for second argument');
|
51836 | }
|
51837 |
|
51838 | return _distance2d(x[0], x[1], y[0], y[1]);
|
51839 | } else if (x.length === 3 && y.length === 3) {
|
51840 | // Point to Point 3D
|
51841 | if (!_3d(x)) {
|
51842 | throw new TypeError('Array with 3 numbers or BigNumbers expected for first argument');
|
51843 | }
|
51844 |
|
51845 | if (!_3d(y)) {
|
51846 | throw new TypeError('Array with 3 numbers or BigNumbers expected for second argument');
|
51847 | }
|
51848 |
|
51849 | return _distance3d(x[0], x[1], x[2], y[0], y[1], y[2]);
|
51850 | } else {
|
51851 | throw new TypeError('Invalid Arguments: Try again');
|
51852 | }
|
51853 | },
|
51854 | 'Object, Object': function ObjectObject(x, y) {
|
51855 | if (Object.keys(x).length === 2 && Object.keys(y).length === 3) {
|
51856 | if (!_2d(x)) {
|
51857 | throw new TypeError('Values of pointX and pointY should be numbers or BigNumbers');
|
51858 | }
|
51859 |
|
51860 | if (!_3d(y)) {
|
51861 | throw new TypeError('Values of xCoeffLine, yCoeffLine and constant should be numbers or BigNumbers');
|
51862 | }
|
51863 |
|
51864 | if (x.hasOwnProperty('pointX') && x.hasOwnProperty('pointY') && y.hasOwnProperty('xCoeffLine') && y.hasOwnProperty('yCoeffLine') && y.hasOwnProperty('constant')) {
|
51865 | return _distancePointLine2D(x.pointX, x.pointY, y.xCoeffLine, y.yCoeffLine, y.constant);
|
51866 | } else {
|
51867 | throw new TypeError('Key names do not match');
|
51868 | }
|
51869 | } else if (Object.keys(x).length === 3 && Object.keys(y).length === 6) {
|
51870 | // Point to Line 3D
|
51871 | if (!_3d(x)) {
|
51872 | throw new TypeError('Values of pointX, pointY and pointZ should be numbers or BigNumbers');
|
51873 | }
|
51874 |
|
51875 | if (!_parametricLine(y)) {
|
51876 | throw new TypeError('Values of x0, y0, z0, a, b and c should be numbers or BigNumbers');
|
51877 | }
|
51878 |
|
51879 | if (x.hasOwnProperty('pointX') && x.hasOwnProperty('pointY') && y.hasOwnProperty('x0') && y.hasOwnProperty('y0') && y.hasOwnProperty('z0') && y.hasOwnProperty('a') && y.hasOwnProperty('b') && y.hasOwnProperty('c')) {
|
51880 | return _distancePointLine3D(x.pointX, x.pointY, x.pointZ, y.x0, y.y0, y.z0, y.a, y.b, y.c);
|
51881 | } else {
|
51882 | throw new TypeError('Key names do not match');
|
51883 | }
|
51884 | } else if (Object.keys(x).length === 2 && Object.keys(y).length === 2) {
|
51885 | // Point to Point 2D
|
51886 | if (!_2d(x)) {
|
51887 | throw new TypeError('Values of pointOneX and pointOneY should be numbers or BigNumbers');
|
51888 | }
|
51889 |
|
51890 | if (!_2d(y)) {
|
51891 | throw new TypeError('Values of pointTwoX and pointTwoY should be numbers or BigNumbers');
|
51892 | }
|
51893 |
|
51894 | if (x.hasOwnProperty('pointOneX') && x.hasOwnProperty('pointOneY') && y.hasOwnProperty('pointTwoX') && y.hasOwnProperty('pointTwoY')) {
|
51895 | return _distance2d(x.pointOneX, x.pointOneY, y.pointTwoX, y.pointTwoY);
|
51896 | } else {
|
51897 | throw new TypeError('Key names do not match');
|
51898 | }
|
51899 | } else if (Object.keys(x).length === 3 && Object.keys(y).length === 3) {
|
51900 | // Point to Point 3D
|
51901 | if (!_3d(x)) {
|
51902 | throw new TypeError('Values of pointOneX, pointOneY and pointOneZ should be numbers or BigNumbers');
|
51903 | }
|
51904 |
|
51905 | if (!_3d(y)) {
|
51906 | throw new TypeError('Values of pointTwoX, pointTwoY and pointTwoZ should be numbers or BigNumbers');
|
51907 | }
|
51908 |
|
51909 | if (x.hasOwnProperty('pointOneX') && x.hasOwnProperty('pointOneY') && x.hasOwnProperty('pointOneZ') && y.hasOwnProperty('pointTwoX') && y.hasOwnProperty('pointTwoY') && y.hasOwnProperty('pointTwoZ')) {
|
51910 | return _distance3d(x.pointOneX, x.pointOneY, x.pointOneZ, y.pointTwoX, y.pointTwoY, y.pointTwoZ);
|
51911 | } else {
|
51912 | throw new TypeError('Key names do not match');
|
51913 | }
|
51914 | } else {
|
51915 | throw new TypeError('Invalid Arguments: Try again');
|
51916 | }
|
51917 | },
|
51918 | 'Array': function Array(arr) {
|
51919 | if (!_pairwise(arr)) {
|
51920 | throw new TypeError('Incorrect array format entered for pairwise distance calculation');
|
51921 | }
|
51922 |
|
51923 | return _distancePairwise(arr);
|
51924 | }
|
51925 | });
|
51926 |
|
51927 | function _isNumber(a) {
|
51928 | // distance supports numbers and bignumbers
|
51929 | return typeof a === 'number' || type.isBigNumber(a);
|
51930 | }
|
51931 |
|
51932 | function _2d(a) {
|
51933 | // checks if the number of arguments are correct in count and are valid (should be numbers)
|
51934 | if (a.constructor !== Array) {
|
51935 | a = _objectToArray(a);
|
51936 | }
|
51937 |
|
51938 | return _isNumber(a[0]) && _isNumber(a[1]);
|
51939 | }
|
51940 |
|
51941 | function _3d(a) {
|
51942 | // checks if the number of arguments are correct in count and are valid (should be numbers)
|
51943 | if (a.constructor !== Array) {
|
51944 | a = _objectToArray(a);
|
51945 | }
|
51946 |
|
51947 | return _isNumber(a[0]) && _isNumber(a[1]) && _isNumber(a[2]);
|
51948 | }
|
51949 |
|
51950 | function _parametricLine(a) {
|
51951 | if (a.constructor !== Array) {
|
51952 | a = _objectToArray(a);
|
51953 | }
|
51954 |
|
51955 | return _isNumber(a[0]) && _isNumber(a[1]) && _isNumber(a[2]) && _isNumber(a[3]) && _isNumber(a[4]) && _isNumber(a[5]);
|
51956 | }
|
51957 |
|
51958 | function _objectToArray(o) {
|
51959 | var keys = Object.keys(o);
|
51960 | var a = [];
|
51961 |
|
51962 | for (var i = 0; i < keys.length; i++) {
|
51963 | a.push(o[keys[i]]);
|
51964 | }
|
51965 |
|
51966 | return a;
|
51967 | }
|
51968 |
|
51969 | function _pairwise(a) {
|
51970 | // checks for valid arguments passed to _distancePairwise(Array)
|
51971 | if (a[0].length === 2 && _isNumber(a[0][0]) && _isNumber(a[0][1])) {
|
51972 | for (var i in a) {
|
51973 | if (a[i].length !== 2 || !_isNumber(a[i][0]) || !_isNumber(a[i][1])) {
|
51974 | return false;
|
51975 | }
|
51976 | }
|
51977 | } else if (a[0].length === 3 && _isNumber(a[0][0]) && _isNumber(a[0][1]) && _isNumber(a[0][2])) {
|
51978 | for (var _i in a) {
|
51979 | if (a[_i].length !== 3 || !_isNumber(a[_i][0]) || !_isNumber(a[_i][1]) || !_isNumber(a[_i][2])) {
|
51980 | return false;
|
51981 | }
|
51982 | }
|
51983 | } else {
|
51984 | return false;
|
51985 | }
|
51986 |
|
51987 | return true;
|
51988 | }
|
51989 |
|
51990 | function _distancePointLine2D(x, y, a, b, c) {
|
51991 | var num = abs(add(add(multiply(a, x), multiply(b, y)), c));
|
51992 | var den = sqrt(add(multiply(a, a), multiply(b, b)));
|
51993 | var result = divide(num, den);
|
51994 | return result;
|
51995 | }
|
51996 |
|
51997 | function _distancePointLine3D(x, y, z, x0, y0, z0, a, b, c) {
|
51998 | var num = [subtract(multiply(subtract(y0, y), c), multiply(subtract(z0, z), b)), subtract(multiply(subtract(z0, z), a), multiply(subtract(x0, x), c)), subtract(multiply(subtract(x0, x), b), multiply(subtract(y0, y), a))];
|
51999 | num = sqrt(add(add(multiply(num[0], num[0]), multiply(num[1], num[1])), multiply(num[2], num[2])));
|
52000 | var den = sqrt(add(add(multiply(a, a), multiply(b, b)), multiply(c, c)));
|
52001 | var result = divide(num, den);
|
52002 | return result;
|
52003 | }
|
52004 |
|
52005 | function _distance2d(x1, y1, x2, y2) {
|
52006 | var yDiff = subtract(y2, y1);
|
52007 | var xDiff = subtract(x2, x1);
|
52008 | var radicant = add(multiply(yDiff, yDiff), multiply(xDiff, xDiff));
|
52009 | var result = sqrt(radicant);
|
52010 | return result;
|
52011 | }
|
52012 |
|
52013 | function _distance3d(x1, y1, z1, x2, y2, z2) {
|
52014 | var zDiff = subtract(z2, z1);
|
52015 | var yDiff = subtract(y2, y1);
|
52016 | var xDiff = subtract(x2, x1);
|
52017 | var radicant = add(add(multiply(zDiff, zDiff), multiply(yDiff, yDiff)), multiply(xDiff, xDiff));
|
52018 | var result = sqrt(radicant);
|
52019 | return result;
|
52020 | }
|
52021 |
|
52022 | function _distancePairwise(a) {
|
52023 | var result = [];
|
52024 |
|
52025 | for (var i = 0; i < a.length - 1; i++) {
|
52026 | for (var j = i + 1; j < a.length; j++) {
|
52027 | if (a[0].length === 2) {
|
52028 | result.push(_distance2d(a[i][0], a[i][1], a[j][0], a[j][1]));
|
52029 | } else if (a[0].length === 3) {
|
52030 | result.push(_distance3d(a[i][0], a[i][1], a[i][2], a[j][0], a[j][1], a[j][2]));
|
52031 | }
|
52032 | }
|
52033 | }
|
52034 |
|
52035 | return result;
|
52036 | }
|
52037 |
|
52038 | return distance;
|
52039 | }
|
52040 |
|
52041 | exports.name = 'distance';
|
52042 | exports.factory = factory;
|
52043 |
|
52044 | /***/ }),
|
52045 | /* 269 */
|
52046 | /***/ (function(module, exports, __webpack_require__) {
|
52047 |
|
52048 | "use strict";
|
52049 |
|
52050 |
|
52051 | module.exports = [__webpack_require__(270), __webpack_require__(142), __webpack_require__(271), __webpack_require__(272)];
|
52052 |
|
52053 | /***/ }),
|
52054 | /* 270 */
|
52055 | /***/ (function(module, exports, __webpack_require__) {
|
52056 |
|
52057 | "use strict";
|
52058 |
|
52059 |
|
52060 | function factory(type, config, load, typed) {
|
52061 | var latex = __webpack_require__(4);
|
52062 |
|
52063 | var matrix = load(__webpack_require__(0));
|
52064 | var zeros = load(__webpack_require__(43));
|
52065 | var not = load(__webpack_require__(142));
|
52066 | var algorithm02 = load(__webpack_require__(27));
|
52067 | var algorithm06 = load(__webpack_require__(74));
|
52068 | var algorithm11 = load(__webpack_require__(20));
|
52069 | var algorithm13 = load(__webpack_require__(7));
|
52070 | var algorithm14 = load(__webpack_require__(6));
|
52071 | /**
|
52072 | * Logical `and`. Test whether two values are both defined with a nonzero/nonempty value.
|
52073 | * For matrices, the function is evaluated element wise.
|
52074 | *
|
52075 | * Syntax:
|
52076 | *
|
52077 | * math.and(x, y)
|
52078 | *
|
52079 | * Examples:
|
52080 | *
|
52081 | * math.and(2, 4) // returns true
|
52082 | *
|
52083 | * a = [2, 0, 0]
|
52084 | * b = [3, 7, 0]
|
52085 | * c = 0
|
52086 | *
|
52087 | * math.and(a, b) // returns [true, false, false]
|
52088 | * math.and(a, c) // returns [false, false, false]
|
52089 | *
|
52090 | * See also:
|
52091 | *
|
52092 | * not, or, xor
|
52093 | *
|
52094 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x First value to check
|
52095 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} y Second value to check
|
52096 | * @return {boolean | Array | Matrix}
|
52097 | * Returns true when both inputs are defined with a nonzero/nonempty value.
|
52098 | */
|
52099 |
|
52100 | var and = typed('and', {
|
52101 | 'number, number': function numberNumber(x, y) {
|
52102 | return !!(x && y);
|
52103 | },
|
52104 | 'Complex, Complex': function ComplexComplex(x, y) {
|
52105 | return (x.re !== 0 || x.im !== 0) && (y.re !== 0 || y.im !== 0);
|
52106 | },
|
52107 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
52108 | return !x.isZero() && !y.isZero() && !x.isNaN() && !y.isNaN();
|
52109 | },
|
52110 | 'Unit, Unit': function UnitUnit(x, y) {
|
52111 | return and(x.value || 0, y.value || 0);
|
52112 | },
|
52113 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
52114 | return algorithm06(x, y, and, false);
|
52115 | },
|
52116 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
52117 | return algorithm02(y, x, and, true);
|
52118 | },
|
52119 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
52120 | return algorithm02(x, y, and, false);
|
52121 | },
|
52122 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
52123 | return algorithm13(x, y, and);
|
52124 | },
|
52125 | 'Array, Array': function ArrayArray(x, y) {
|
52126 | // use matrix implementation
|
52127 | return and(matrix(x), matrix(y)).valueOf();
|
52128 | },
|
52129 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
52130 | // use matrix implementation
|
52131 | return and(matrix(x), y);
|
52132 | },
|
52133 | 'Matrix, Array': function MatrixArray(x, y) {
|
52134 | // use matrix implementation
|
52135 | return and(x, matrix(y));
|
52136 | },
|
52137 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
52138 | // check scalar
|
52139 | if (not(y)) {
|
52140 | // return zero matrix
|
52141 | return zeros(x.size(), x.storage());
|
52142 | }
|
52143 |
|
52144 | return algorithm11(x, y, and, false);
|
52145 | },
|
52146 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
52147 | // check scalar
|
52148 | if (not(y)) {
|
52149 | // return zero matrix
|
52150 | return zeros(x.size(), x.storage());
|
52151 | }
|
52152 |
|
52153 | return algorithm14(x, y, and, false);
|
52154 | },
|
52155 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
52156 | // check scalar
|
52157 | if (not(x)) {
|
52158 | // return zero matrix
|
52159 | return zeros(x.size(), x.storage());
|
52160 | }
|
52161 |
|
52162 | return algorithm11(y, x, and, true);
|
52163 | },
|
52164 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
52165 | // check scalar
|
52166 | if (not(x)) {
|
52167 | // return zero matrix
|
52168 | return zeros(x.size(), x.storage());
|
52169 | }
|
52170 |
|
52171 | return algorithm14(y, x, and, true);
|
52172 | },
|
52173 | 'Array, any': function ArrayAny(x, y) {
|
52174 | // use matrix implementation
|
52175 | return and(matrix(x), y).valueOf();
|
52176 | },
|
52177 | 'any, Array': function anyArray(x, y) {
|
52178 | // use matrix implementation
|
52179 | return and(x, matrix(y)).valueOf();
|
52180 | }
|
52181 | });
|
52182 | and.toTex = {
|
52183 | 2: "\\left(${args[0]}".concat(latex.operators['and'], "${args[1]}\\right)")
|
52184 | };
|
52185 | return and;
|
52186 | }
|
52187 |
|
52188 | exports.name = 'and';
|
52189 | exports.factory = factory;
|
52190 |
|
52191 | /***/ }),
|
52192 | /* 271 */
|
52193 | /***/ (function(module, exports, __webpack_require__) {
|
52194 |
|
52195 | "use strict";
|
52196 |
|
52197 |
|
52198 | function factory(type, config, load, typed) {
|
52199 | var latex = __webpack_require__(4);
|
52200 |
|
52201 | var matrix = load(__webpack_require__(0));
|
52202 | var algorithm03 = load(__webpack_require__(18));
|
52203 | var algorithm05 = load(__webpack_require__(66));
|
52204 | var algorithm12 = load(__webpack_require__(19));
|
52205 | var algorithm13 = load(__webpack_require__(7));
|
52206 | var algorithm14 = load(__webpack_require__(6));
|
52207 | /**
|
52208 | * Logical `or`. Test if at least one value is defined with a nonzero/nonempty value.
|
52209 | * For matrices, the function is evaluated element wise.
|
52210 | *
|
52211 | * Syntax:
|
52212 | *
|
52213 | * math.or(x, y)
|
52214 | *
|
52215 | * Examples:
|
52216 | *
|
52217 | * math.or(2, 4) // returns true
|
52218 | *
|
52219 | * a = [2, 5, 0]
|
52220 | * b = [0, 22, 0]
|
52221 | * c = 0
|
52222 | *
|
52223 | * math.or(a, b) // returns [true, true, false]
|
52224 | * math.or(b, c) // returns [false, true, false]
|
52225 | *
|
52226 | * See also:
|
52227 | *
|
52228 | * and, not, xor
|
52229 | *
|
52230 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x First value to check
|
52231 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} y Second value to check
|
52232 | * @return {boolean | Array | Matrix}
|
52233 | * Returns true when one of the inputs is defined with a nonzero/nonempty value.
|
52234 | */
|
52235 |
|
52236 | var or = typed('or', {
|
52237 | 'number, number': function numberNumber(x, y) {
|
52238 | return !!(x || y);
|
52239 | },
|
52240 | 'Complex, Complex': function ComplexComplex(x, y) {
|
52241 | return x.re !== 0 || x.im !== 0 || y.re !== 0 || y.im !== 0;
|
52242 | },
|
52243 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
52244 | return !x.isZero() && !x.isNaN() || !y.isZero() && !y.isNaN();
|
52245 | },
|
52246 | 'Unit, Unit': function UnitUnit(x, y) {
|
52247 | return or(x.value || 0, y.value || 0);
|
52248 | },
|
52249 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
52250 | return algorithm05(x, y, or);
|
52251 | },
|
52252 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
52253 | return algorithm03(y, x, or, true);
|
52254 | },
|
52255 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
52256 | return algorithm03(x, y, or, false);
|
52257 | },
|
52258 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
52259 | return algorithm13(x, y, or);
|
52260 | },
|
52261 | 'Array, Array': function ArrayArray(x, y) {
|
52262 | // use matrix implementation
|
52263 | return or(matrix(x), matrix(y)).valueOf();
|
52264 | },
|
52265 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
52266 | // use matrix implementation
|
52267 | return or(matrix(x), y);
|
52268 | },
|
52269 | 'Matrix, Array': function MatrixArray(x, y) {
|
52270 | // use matrix implementation
|
52271 | return or(x, matrix(y));
|
52272 | },
|
52273 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
52274 | return algorithm12(x, y, or, false);
|
52275 | },
|
52276 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
52277 | return algorithm14(x, y, or, false);
|
52278 | },
|
52279 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
52280 | return algorithm12(y, x, or, true);
|
52281 | },
|
52282 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
52283 | return algorithm14(y, x, or, true);
|
52284 | },
|
52285 | 'Array, any': function ArrayAny(x, y) {
|
52286 | // use matrix implementation
|
52287 | return algorithm14(matrix(x), y, or, false).valueOf();
|
52288 | },
|
52289 | 'any, Array': function anyArray(x, y) {
|
52290 | // use matrix implementation
|
52291 | return algorithm14(matrix(y), x, or, true).valueOf();
|
52292 | }
|
52293 | });
|
52294 | or.toTex = {
|
52295 | 2: "\\left(${args[0]}".concat(latex.operators['or'], "${args[1]}\\right)")
|
52296 | };
|
52297 | return or;
|
52298 | }
|
52299 |
|
52300 | exports.name = 'or';
|
52301 | exports.factory = factory;
|
52302 |
|
52303 | /***/ }),
|
52304 | /* 272 */
|
52305 | /***/ (function(module, exports, __webpack_require__) {
|
52306 |
|
52307 | "use strict";
|
52308 |
|
52309 |
|
52310 | function factory(type, config, load, typed) {
|
52311 | var latex = __webpack_require__(4);
|
52312 |
|
52313 | var matrix = load(__webpack_require__(0));
|
52314 | var algorithm03 = load(__webpack_require__(18));
|
52315 | var algorithm07 = load(__webpack_require__(29));
|
52316 | var algorithm12 = load(__webpack_require__(19));
|
52317 | var algorithm13 = load(__webpack_require__(7));
|
52318 | var algorithm14 = load(__webpack_require__(6));
|
52319 | /**
|
52320 | * Logical `xor`. Test whether one and only one value is defined with a nonzero/nonempty value.
|
52321 | * For matrices, the function is evaluated element wise.
|
52322 | *
|
52323 | * Syntax:
|
52324 | *
|
52325 | * math.xor(x, y)
|
52326 | *
|
52327 | * Examples:
|
52328 | *
|
52329 | * math.xor(2, 4) // returns false
|
52330 | *
|
52331 | * a = [2, 0, 0]
|
52332 | * b = [2, 7, 0]
|
52333 | * c = 0
|
52334 | *
|
52335 | * math.xor(a, b) // returns [false, true, false]
|
52336 | * math.xor(a, c) // returns [true, false, false]
|
52337 | *
|
52338 | * See also:
|
52339 | *
|
52340 | * and, not, or
|
52341 | *
|
52342 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x First value to check
|
52343 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} y Second value to check
|
52344 | * @return {boolean | Array | Matrix}
|
52345 | * Returns true when one and only one input is defined with a nonzero/nonempty value.
|
52346 | */
|
52347 |
|
52348 | var xor = typed('xor', {
|
52349 | 'number, number': function numberNumber(x, y) {
|
52350 | return !!x !== !!y;
|
52351 | },
|
52352 | 'Complex, Complex': function ComplexComplex(x, y) {
|
52353 | return (x.re !== 0 || x.im !== 0) !== (y.re !== 0 || y.im !== 0);
|
52354 | },
|
52355 | 'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
52356 | return (!x.isZero() && !x.isNaN()) !== (!y.isZero() && !y.isNaN());
|
52357 | },
|
52358 | 'Unit, Unit': function UnitUnit(x, y) {
|
52359 | return xor(x.value || 0, y.value || 0);
|
52360 | },
|
52361 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
52362 | return algorithm07(x, y, xor);
|
52363 | },
|
52364 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
52365 | return algorithm03(y, x, xor, true);
|
52366 | },
|
52367 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
52368 | return algorithm03(x, y, xor, false);
|
52369 | },
|
52370 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
52371 | return algorithm13(x, y, xor);
|
52372 | },
|
52373 | 'Array, Array': function ArrayArray(x, y) {
|
52374 | // use matrix implementation
|
52375 | return xor(matrix(x), matrix(y)).valueOf();
|
52376 | },
|
52377 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
52378 | // use matrix implementation
|
52379 | return xor(matrix(x), y);
|
52380 | },
|
52381 | 'Matrix, Array': function MatrixArray(x, y) {
|
52382 | // use matrix implementation
|
52383 | return xor(x, matrix(y));
|
52384 | },
|
52385 | 'SparseMatrix, any': function SparseMatrixAny(x, y) {
|
52386 | return algorithm12(x, y, xor, false);
|
52387 | },
|
52388 | 'DenseMatrix, any': function DenseMatrixAny(x, y) {
|
52389 | return algorithm14(x, y, xor, false);
|
52390 | },
|
52391 | 'any, SparseMatrix': function anySparseMatrix(x, y) {
|
52392 | return algorithm12(y, x, xor, true);
|
52393 | },
|
52394 | 'any, DenseMatrix': function anyDenseMatrix(x, y) {
|
52395 | return algorithm14(y, x, xor, true);
|
52396 | },
|
52397 | 'Array, any': function ArrayAny(x, y) {
|
52398 | // use matrix implementation
|
52399 | return algorithm14(matrix(x), y, xor, false).valueOf();
|
52400 | },
|
52401 | 'any, Array': function anyArray(x, y) {
|
52402 | // use matrix implementation
|
52403 | return algorithm14(matrix(y), x, xor, true).valueOf();
|
52404 | }
|
52405 | });
|
52406 | xor.toTex = {
|
52407 | 2: "\\left(${args[0]}".concat(latex.operators['xor'], "${args[1]}\\right)")
|
52408 | };
|
52409 | return xor;
|
52410 | }
|
52411 |
|
52412 | exports.name = 'xor';
|
52413 | exports.factory = factory;
|
52414 |
|
52415 | /***/ }),
|
52416 | /* 273 */
|
52417 | /***/ (function(module, exports, __webpack_require__) {
|
52418 |
|
52419 | "use strict";
|
52420 |
|
52421 |
|
52422 | module.exports = [__webpack_require__(96), __webpack_require__(143), __webpack_require__(78), __webpack_require__(274), __webpack_require__(275), __webpack_require__(128), __webpack_require__(276), __webpack_require__(277), __webpack_require__(278), __webpack_require__(279), __webpack_require__(280), __webpack_require__(281), __webpack_require__(282), __webpack_require__(50), __webpack_require__(70), __webpack_require__(283), __webpack_require__(145), __webpack_require__(284), __webpack_require__(97), __webpack_require__(77), __webpack_require__(285), __webpack_require__(286), __webpack_require__(146), __webpack_require__(28), __webpack_require__(287), __webpack_require__(289), __webpack_require__(290), __webpack_require__(23), __webpack_require__(291), __webpack_require__(72), __webpack_require__(43), __webpack_require__(292)];
|
52423 |
|
52424 | /***/ }),
|
52425 | /* 274 */
|
52426 | /***/ (function(module, exports, __webpack_require__) {
|
52427 |
|
52428 | "use strict";
|
52429 |
|
52430 |
|
52431 | var array = __webpack_require__(2);
|
52432 |
|
52433 | function factory(type, config, load, typed) {
|
52434 | var matrix = load(__webpack_require__(0));
|
52435 | var subtract = load(__webpack_require__(15));
|
52436 | var multiply = load(__webpack_require__(10));
|
52437 | /**
|
52438 | * Calculate the cross product for two vectors in three dimensional space.
|
52439 | * The cross product of `A = [a1, a2, a3]` and `B = [b1, b2, b3]` is defined
|
52440 | * as:
|
52441 | *
|
52442 | * cross(A, B) = [
|
52443 | * a2 * b3 - a3 * b2,
|
52444 | * a3 * b1 - a1 * b3,
|
52445 | * a1 * b2 - a2 * b1
|
52446 | * ]
|
52447 | *
|
52448 | * If one of the input vectors has a dimension greater than 1, the output
|
52449 | * vector will be a 1x3 (2-dimensional) matrix.
|
52450 | *
|
52451 | * Syntax:
|
52452 | *
|
52453 | * math.cross(x, y)
|
52454 | *
|
52455 | * Examples:
|
52456 | *
|
52457 | * math.cross([1, 1, 0], [0, 1, 1]) // Returns [1, -1, 1]
|
52458 | * math.cross([3, -3, 1], [4, 9, 2]) // Returns [-15, -2, 39]
|
52459 | * math.cross([2, 3, 4], [5, 6, 7]) // Returns [-3, 6, -3]
|
52460 | * math.cross([[1, 2, 3]], [[4], [5], [6]]) // Returns [[-3, 6, -3]]
|
52461 | *
|
52462 | * See also:
|
52463 | *
|
52464 | * dot, multiply
|
52465 | *
|
52466 | * @param {Array | Matrix} x First vector
|
52467 | * @param {Array | Matrix} y Second vector
|
52468 | * @return {Array | Matrix} Returns the cross product of `x` and `y`
|
52469 | */
|
52470 |
|
52471 | var cross = typed('cross', {
|
52472 | 'Matrix, Matrix': function MatrixMatrix(x, y) {
|
52473 | return matrix(_cross(x.toArray(), y.toArray()));
|
52474 | },
|
52475 | 'Matrix, Array': function MatrixArray(x, y) {
|
52476 | return matrix(_cross(x.toArray(), y));
|
52477 | },
|
52478 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
52479 | return matrix(_cross(x, y.toArray()));
|
52480 | },
|
52481 | 'Array, Array': _cross
|
52482 | });
|
52483 | cross.toTex = {
|
52484 | 2: "\\left(${args[0]}\\right)\\times\\left(${args[1]}\\right)"
|
52485 | };
|
52486 | return cross;
|
52487 | /**
|
52488 | * Calculate the cross product for two arrays
|
52489 | * @param {Array} x First vector
|
52490 | * @param {Array} y Second vector
|
52491 | * @returns {Array} Returns the cross product of x and y
|
52492 | * @private
|
52493 | */
|
52494 |
|
52495 | function _cross(x, y) {
|
52496 | var highestDimension = Math.max(array.size(x).length, array.size(y).length);
|
52497 | x = array.squeeze(x);
|
52498 | y = array.squeeze(y);
|
52499 | var xSize = array.size(x);
|
52500 | var ySize = array.size(y);
|
52501 |
|
52502 | if (xSize.length !== 1 || ySize.length !== 1 || xSize[0] !== 3 || ySize[0] !== 3) {
|
52503 | throw new RangeError('Vectors with length 3 expected ' + '(Size A = [' + xSize.join(', ') + '], B = [' + ySize.join(', ') + '])');
|
52504 | }
|
52505 |
|
52506 | var product = [subtract(multiply(x[1], y[2]), multiply(x[2], y[1])), subtract(multiply(x[2], y[0]), multiply(x[0], y[2])), subtract(multiply(x[0], y[1]), multiply(x[1], y[0]))];
|
52507 |
|
52508 | if (highestDimension > 1) {
|
52509 | return [product];
|
52510 | } else {
|
52511 | return product;
|
52512 | }
|
52513 | }
|
52514 | }
|
52515 |
|
52516 | exports.name = 'cross';
|
52517 | exports.factory = factory;
|
52518 |
|
52519 | /***/ }),
|
52520 | /* 275 */
|
52521 | /***/ (function(module, exports, __webpack_require__) {
|
52522 |
|
52523 | "use strict";
|
52524 |
|
52525 |
|
52526 | function factory(type, config, load, typed) {
|
52527 | var transpose = load(__webpack_require__(72));
|
52528 | var conj = load(__webpack_require__(71));
|
52529 |
|
52530 | var latex = __webpack_require__(4);
|
52531 | /**
|
52532 | * Transpose and complex conjugate a matrix. All values of the matrix are
|
52533 | * reflected over its main diagonal and then the complex conjugate is
|
52534 | * taken. This is equivalent to complex conjugation for scalars and
|
52535 | * vectors.
|
52536 | *
|
52537 | * Syntax:
|
52538 | *
|
52539 | * math.ctranspose(x)
|
52540 | *
|
52541 | * Examples:
|
52542 | *
|
52543 | * const A = [[1, 2, 3], [4, 5, math.complex(6,7)]]
|
52544 | * math.ctranspose(A) // returns [[1, 4], [2, 5], [3, {re:6,im:7}]]
|
52545 | *
|
52546 | * See also:
|
52547 | *
|
52548 | * transpose, diag, inv, subset, squeeze
|
52549 | *
|
52550 | * @param {Array | Matrix} x Matrix to be ctransposed
|
52551 | * @return {Array | Matrix} The ctransposed matrix
|
52552 | */
|
52553 |
|
52554 |
|
52555 | var ctranspose = typed('ctranspose', {
|
52556 | 'any': function any(x) {
|
52557 | return conj(transpose(x));
|
52558 | }
|
52559 | });
|
52560 | ctranspose.toTex = {
|
52561 | 1: "\\left(${args[0]}\\right)".concat(latex.operators['ctranspose'])
|
52562 | };
|
52563 | return ctranspose;
|
52564 | }
|
52565 |
|
52566 | exports.name = 'ctranspose';
|
52567 | exports.factory = factory;
|
52568 |
|
52569 | /***/ }),
|
52570 | /* 276 */
|
52571 | /***/ (function(module, exports, __webpack_require__) {
|
52572 |
|
52573 | "use strict";
|
52574 |
|
52575 |
|
52576 | var array = __webpack_require__(2);
|
52577 |
|
52578 | var isInteger = __webpack_require__(3).isInteger;
|
52579 |
|
52580 | function factory(type, config, load, typed) {
|
52581 | var matrix = load(__webpack_require__(0));
|
52582 | /**
|
52583 | * Create a diagonal matrix or retrieve the diagonal of a matrix
|
52584 | *
|
52585 | * When `x` is a vector, a matrix with vector `x` on the diagonal will be returned.
|
52586 | * When `x` is a two dimensional matrix, the matrixes `k`th diagonal will be returned as vector.
|
52587 | * When k is positive, the values are placed on the super diagonal.
|
52588 | * When k is negative, the values are placed on the sub diagonal.
|
52589 | *
|
52590 | * Syntax:
|
52591 | *
|
52592 | * math.diag(X)
|
52593 | * math.diag(X, format)
|
52594 | * math.diag(X, k)
|
52595 | * math.diag(X, k, format)
|
52596 | *
|
52597 | * Examples:
|
52598 | *
|
52599 | * // create a diagonal matrix
|
52600 | * math.diag([1, 2, 3]) // returns [[1, 0, 0], [0, 2, 0], [0, 0, 3]]
|
52601 | * math.diag([1, 2, 3], 1) // returns [[0, 1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 3]]
|
52602 | * math.diag([1, 2, 3], -1) // returns [[0, 0, 0], [1, 0, 0], [0, 2, 0], [0, 0, 3]]
|
52603 | *
|
52604 | * // retrieve the diagonal from a matrix
|
52605 | * const a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
52606 | * math.diag(a) // returns [1, 5, 9]
|
52607 | *
|
52608 | * See also:
|
52609 | *
|
52610 | * ones, zeros, identity
|
52611 | *
|
52612 | * @param {Matrix | Array} x A two dimensional matrix or a vector
|
52613 | * @param {number | BigNumber} [k=0] The diagonal where the vector will be filled
|
52614 | * in or retrieved.
|
52615 | * @param {string} [format='dense'] The matrix storage format.
|
52616 | *
|
52617 | * @returns {Matrix | Array} Diagonal matrix from input vector, or diagonal from input matrix.
|
52618 | */
|
52619 |
|
52620 | var diag = typed('diag', {
|
52621 | // FIXME: simplify this huge amount of signatures as soon as typed-function supports optional arguments
|
52622 | 'Array': function Array(x) {
|
52623 | return _diag(x, 0, array.size(x), null);
|
52624 | },
|
52625 | 'Array, number': function ArrayNumber(x, k) {
|
52626 | return _diag(x, k, array.size(x), null);
|
52627 | },
|
52628 | 'Array, BigNumber': function ArrayBigNumber(x, k) {
|
52629 | return _diag(x, k.toNumber(), array.size(x), null);
|
52630 | },
|
52631 | 'Array, string': function ArrayString(x, format) {
|
52632 | return _diag(x, 0, array.size(x), format);
|
52633 | },
|
52634 | 'Array, number, string': function ArrayNumberString(x, k, format) {
|
52635 | return _diag(x, k, array.size(x), format);
|
52636 | },
|
52637 | 'Array, BigNumber, string': function ArrayBigNumberString(x, k, format) {
|
52638 | return _diag(x, k.toNumber(), array.size(x), format);
|
52639 | },
|
52640 | 'Matrix': function Matrix(x) {
|
52641 | return _diag(x, 0, x.size(), x.storage());
|
52642 | },
|
52643 | 'Matrix, number': function MatrixNumber(x, k) {
|
52644 | return _diag(x, k, x.size(), x.storage());
|
52645 | },
|
52646 | 'Matrix, BigNumber': function MatrixBigNumber(x, k) {
|
52647 | return _diag(x, k.toNumber(), x.size(), x.storage());
|
52648 | },
|
52649 | 'Matrix, string': function MatrixString(x, format) {
|
52650 | return _diag(x, 0, x.size(), format);
|
52651 | },
|
52652 | 'Matrix, number, string': function MatrixNumberString(x, k, format) {
|
52653 | return _diag(x, k, x.size(), format);
|
52654 | },
|
52655 | 'Matrix, BigNumber, string': function MatrixBigNumberString(x, k, format) {
|
52656 | return _diag(x, k.toNumber(), x.size(), format);
|
52657 | }
|
52658 | });
|
52659 | diag.toTex = undefined; // use default template
|
52660 |
|
52661 | return diag;
|
52662 | /**
|
52663 | * Creeate diagonal matrix from a vector or vice versa
|
52664 | * @param {Array | Matrix} x
|
52665 | * @param {number} k
|
52666 | * @param {string} format Storage format for matrix. If null,
|
52667 | * an Array is returned
|
52668 | * @returns {Array | Matrix}
|
52669 | * @private
|
52670 | */
|
52671 |
|
52672 | function _diag(x, k, size, format) {
|
52673 | if (!isInteger(k)) {
|
52674 | throw new TypeError('Second parameter in function diag must be an integer');
|
52675 | }
|
52676 |
|
52677 | var kSuper = k > 0 ? k : 0;
|
52678 | var kSub = k < 0 ? -k : 0; // check dimensions
|
52679 |
|
52680 | switch (size.length) {
|
52681 | case 1:
|
52682 | return _createDiagonalMatrix(x, k, format, size[0], kSub, kSuper);
|
52683 |
|
52684 | case 2:
|
52685 | return _getDiagonal(x, k, format, size, kSub, kSuper);
|
52686 | }
|
52687 |
|
52688 | throw new RangeError('Matrix for function diag must be 2 dimensional');
|
52689 | }
|
52690 |
|
52691 | function _createDiagonalMatrix(x, k, format, l, kSub, kSuper) {
|
52692 | // matrix size
|
52693 | var ms = [l + kSub, l + kSuper]; // get matrix constructor
|
52694 |
|
52695 | var F = type.Matrix.storage(format || 'dense'); // create diagonal matrix
|
52696 |
|
52697 | var m = F.diagonal(ms, x, k); // check we need to return a matrix
|
52698 |
|
52699 | return format !== null ? m : m.valueOf();
|
52700 | }
|
52701 |
|
52702 | function _getDiagonal(x, k, format, s, kSub, kSuper) {
|
52703 | // check x is a Matrix
|
52704 | if (type.isMatrix(x)) {
|
52705 | // get diagonal matrix
|
52706 | var dm = x.diagonal(k); // check we need to return a matrix
|
52707 |
|
52708 | if (format !== null) {
|
52709 | // check we need to change matrix format
|
52710 | if (format !== dm.storage()) {
|
52711 | return matrix(dm, format);
|
52712 | }
|
52713 |
|
52714 | return dm;
|
52715 | }
|
52716 |
|
52717 | return dm.valueOf();
|
52718 | } // vector size
|
52719 |
|
52720 |
|
52721 | var n = Math.min(s[0] - kSub, s[1] - kSuper); // diagonal values
|
52722 |
|
52723 | var vector = []; // loop diagonal
|
52724 |
|
52725 | for (var i = 0; i < n; i++) {
|
52726 | vector[i] = x[i + kSub][i + kSuper];
|
52727 | } // check we need to return a matrix
|
52728 |
|
52729 |
|
52730 | return format !== null ? matrix(vector) : vector;
|
52731 | }
|
52732 | }
|
52733 |
|
52734 | exports.name = 'diag';
|
52735 | exports.factory = factory;
|
52736 |
|
52737 | /***/ }),
|
52738 | /* 277 */
|
52739 | /***/ (function(module, exports, __webpack_require__) {
|
52740 |
|
52741 | "use strict";
|
52742 |
|
52743 |
|
52744 | var size = __webpack_require__(2).size;
|
52745 |
|
52746 | function factory(type, config, load, typed) {
|
52747 | var add = load(__webpack_require__(14));
|
52748 | var multiply = load(__webpack_require__(10));
|
52749 | /**
|
52750 | * Calculate the dot product of two vectors. The dot product of
|
52751 | * `A = [a1, a2, a3, ..., an]` and `B = [b1, b2, b3, ..., bn]` is defined as:
|
52752 | *
|
52753 | * dot(A, B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn
|
52754 | *
|
52755 | * Syntax:
|
52756 | *
|
52757 | * math.dot(x, y)
|
52758 | *
|
52759 | * Examples:
|
52760 | *
|
52761 | * math.dot([2, 4, 1], [2, 2, 3]) // returns number 15
|
52762 | * math.multiply([2, 4, 1], [2, 2, 3]) // returns number 15
|
52763 | *
|
52764 | * See also:
|
52765 | *
|
52766 | * multiply, cross
|
52767 | *
|
52768 | * @param {Array | Matrix} x First vector
|
52769 | * @param {Array | Matrix} y Second vector
|
52770 | * @return {number} Returns the dot product of `x` and `y`
|
52771 | */
|
52772 |
|
52773 | var dot = typed('dot', {
|
52774 | 'Matrix, Matrix': function MatrixMatrix(x, y) {
|
52775 | return _dot(x.toArray(), y.toArray());
|
52776 | },
|
52777 | 'Matrix, Array': function MatrixArray(x, y) {
|
52778 | return _dot(x.toArray(), y);
|
52779 | },
|
52780 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
52781 | return _dot(x, y.toArray());
|
52782 | },
|
52783 | 'Array, Array': _dot
|
52784 | });
|
52785 | dot.toTex = {
|
52786 | 2: "\\left(${args[0]}\\cdot${args[1]}\\right)"
|
52787 | };
|
52788 | return dot;
|
52789 | /**
|
52790 | * Calculate the dot product for two arrays
|
52791 | * @param {Array} x First vector
|
52792 | * @param {Array} y Second vector
|
52793 | * @returns {number} Returns the dot product of x and y
|
52794 | * @private
|
52795 | */
|
52796 | // TODO: double code with math.multiply
|
52797 |
|
52798 | function _dot(x, y) {
|
52799 | var xSize = size(x);
|
52800 | var ySize = size(y);
|
52801 | var len = xSize[0];
|
52802 | if (xSize.length !== 1 || ySize.length !== 1) throw new RangeError('Vector expected'); // TODO: better error message
|
52803 |
|
52804 | if (xSize[0] !== ySize[0]) throw new RangeError('Vectors must have equal length (' + xSize[0] + ' != ' + ySize[0] + ')');
|
52805 | if (len === 0) throw new RangeError('Cannot calculate the dot product of empty vectors');
|
52806 | var prod = 0;
|
52807 |
|
52808 | for (var i = 0; i < len; i++) {
|
52809 | prod = add(prod, multiply(x[i], y[i]));
|
52810 | }
|
52811 |
|
52812 | return prod;
|
52813 | }
|
52814 | }
|
52815 |
|
52816 | exports.name = 'dot';
|
52817 | exports.factory = factory;
|
52818 |
|
52819 | /***/ }),
|
52820 | /* 278 */
|
52821 | /***/ (function(module, exports, __webpack_require__) {
|
52822 |
|
52823 | "use strict";
|
52824 | // TODO: function eye is removed since v5.0.0 (June 2018). Remove it some day.
|
52825 |
|
52826 | function factory(type, config, load, typed) {
|
52827 | return function eye() {
|
52828 | throw new Error('Function "eye" is renamed to "identity" since mathjs version 5.0.0. ' + 'To keep eye working, create an alias for it using "math.import({eye: math.identity}, {override: true})"');
|
52829 | };
|
52830 | }
|
52831 |
|
52832 | exports.name = 'eye';
|
52833 | exports.factory = factory;
|
52834 |
|
52835 | /***/ }),
|
52836 | /* 279 */
|
52837 | /***/ (function(module, exports, __webpack_require__) {
|
52838 |
|
52839 | "use strict";
|
52840 |
|
52841 |
|
52842 | var format = __webpack_require__(9).format;
|
52843 |
|
52844 | function factory(type, config, load, typed) {
|
52845 | var abs = load(__webpack_require__(25));
|
52846 | var add = load(__webpack_require__(14));
|
52847 | var identity = load(__webpack_require__(50));
|
52848 | var inv = load(__webpack_require__(70));
|
52849 | var multiply = load(__webpack_require__(10));
|
52850 | var SparseMatrix = type.SparseMatrix;
|
52851 | /**
|
52852 | * Compute the matrix exponential, expm(A) = e^A. The matrix must be square.
|
52853 | * Not to be confused with exp(a), which performs element-wise
|
52854 | * exponentiation.
|
52855 | *
|
52856 | * The exponential is calculated using the Padé approximant with scaling and
|
52857 | * squaring; see "Nineteen Dubious Ways to Compute the Exponential of a
|
52858 | * Matrix," by Moler and Van Loan.
|
52859 | *
|
52860 | * Syntax:
|
52861 | *
|
52862 | * math.expm(x)
|
52863 | *
|
52864 | * Examples:
|
52865 | *
|
52866 | * const A = [[0,2],[0,0]]
|
52867 | * math.expm(A) // returns [[1,2],[0,1]]
|
52868 | *
|
52869 | * See also:
|
52870 | *
|
52871 | * exp
|
52872 | *
|
52873 | * @param {Matrix} x A square Matrix
|
52874 | * @return {Matrix} The exponential of x
|
52875 | */
|
52876 |
|
52877 | var expm = typed('expm', {
|
52878 | 'Matrix': function Matrix(A) {
|
52879 | // Check matrix size
|
52880 | var size = A.size();
|
52881 |
|
52882 | if (size.length !== 2 || size[0] !== size[1]) {
|
52883 | throw new RangeError('Matrix must be square ' + '(size: ' + format(size) + ')');
|
52884 | }
|
52885 |
|
52886 | var n = size[0]; // Desired accuracy of the approximant (The actual accuracy
|
52887 | // will be affected by round-off error)
|
52888 |
|
52889 | var eps = 1e-15; // The Padé approximant is not so accurate when the values of A
|
52890 | // are "large", so scale A by powers of two. Then compute the
|
52891 | // exponential, and square the result repeatedly according to
|
52892 | // the identity e^A = (e^(A/m))^m
|
52893 | // Compute infinity-norm of A, ||A||, to see how "big" it is
|
52894 |
|
52895 | var infNorm = infinityNorm(A); // Find the optimal scaling factor and number of terms in the
|
52896 | // Padé approximant to reach the desired accuracy
|
52897 |
|
52898 | var params = findParams(infNorm, eps);
|
52899 | var q = params.q;
|
52900 | var j = params.j; // The Pade approximation to e^A is:
|
52901 | // Rqq(A) = Dqq(A) ^ -1 * Nqq(A)
|
52902 | // where
|
52903 | // Nqq(A) = sum(i=0, q, (2q-i)!p! / [ (2q)!i!(q-i)! ] A^i
|
52904 | // Dqq(A) = sum(i=0, q, (2q-i)!q! / [ (2q)!i!(q-i)! ] (-A)^i
|
52905 | // Scale A by 1 / 2^j
|
52906 |
|
52907 | var Apos = multiply(A, Math.pow(2, -j)); // The i=0 term is just the identity matrix
|
52908 |
|
52909 | var N = identity(n);
|
52910 | var D = identity(n); // Initialization (i=0)
|
52911 |
|
52912 | var factor = 1; // Initialization (i=1)
|
52913 |
|
52914 | var AposToI = Apos; // Cloning not necessary
|
52915 |
|
52916 | var alternate = -1;
|
52917 |
|
52918 | for (var i = 1; i <= q; i++) {
|
52919 | if (i > 1) {
|
52920 | AposToI = multiply(AposToI, Apos);
|
52921 | alternate = -alternate;
|
52922 | }
|
52923 |
|
52924 | factor = factor * (q - i + 1) / ((2 * q - i + 1) * i);
|
52925 | N = add(N, multiply(factor, AposToI));
|
52926 | D = add(D, multiply(factor * alternate, AposToI));
|
52927 | }
|
52928 |
|
52929 | var R = multiply(inv(D), N); // Square j times
|
52930 |
|
52931 | for (var _i = 0; _i < j; _i++) {
|
52932 | R = multiply(R, R);
|
52933 | }
|
52934 |
|
52935 | return type.isSparseMatrix(A) ? new SparseMatrix(R) : R;
|
52936 | }
|
52937 | });
|
52938 |
|
52939 | function infinityNorm(A) {
|
52940 | var n = A.size()[0];
|
52941 | var infNorm = 0;
|
52942 |
|
52943 | for (var i = 0; i < n; i++) {
|
52944 | var rowSum = 0;
|
52945 |
|
52946 | for (var j = 0; j < n; j++) {
|
52947 | rowSum += abs(A.get([i, j]));
|
52948 | }
|
52949 |
|
52950 | infNorm = Math.max(rowSum, infNorm);
|
52951 | }
|
52952 |
|
52953 | return infNorm;
|
52954 | }
|
52955 | /**
|
52956 | * Find the best parameters for the Pade approximant given
|
52957 | * the matrix norm and desired accuracy. Returns the first acceptable
|
52958 | * combination in order of increasing computational load.
|
52959 | */
|
52960 |
|
52961 |
|
52962 | function findParams(infNorm, eps) {
|
52963 | var maxSearchSize = 30;
|
52964 |
|
52965 | for (var k = 0; k < maxSearchSize; k++) {
|
52966 | for (var q = 0; q <= k; q++) {
|
52967 | var j = k - q;
|
52968 |
|
52969 | if (errorEstimate(infNorm, q, j) < eps) {
|
52970 | return {
|
52971 | q: q,
|
52972 | j: j
|
52973 | };
|
52974 | }
|
52975 | }
|
52976 | }
|
52977 |
|
52978 | throw new Error('Could not find acceptable parameters to compute the matrix exponential (try increasing maxSearchSize in expm.js)');
|
52979 | }
|
52980 | /**
|
52981 | * Returns the estimated error of the Pade approximant for the given
|
52982 | * parameters.
|
52983 | */
|
52984 |
|
52985 |
|
52986 | function errorEstimate(infNorm, q, j) {
|
52987 | var qfac = 1;
|
52988 |
|
52989 | for (var i = 2; i <= q; i++) {
|
52990 | qfac *= i;
|
52991 | }
|
52992 |
|
52993 | var twoqfac = qfac;
|
52994 |
|
52995 | for (var _i2 = q + 1; _i2 <= 2 * q; _i2++) {
|
52996 | twoqfac *= _i2;
|
52997 | }
|
52998 |
|
52999 | var twoqp1fac = twoqfac * (2 * q + 1);
|
53000 | return 8.0 * Math.pow(infNorm / Math.pow(2, j), 2 * q) * qfac * qfac / (twoqfac * twoqp1fac);
|
53001 | }
|
53002 |
|
53003 | expm.toTex = {
|
53004 | 1: "\\exp\\left(${args[0]}\\right)"
|
53005 | };
|
53006 | return expm;
|
53007 | }
|
53008 |
|
53009 | exports.name = 'expm';
|
53010 | exports.factory = factory;
|
53011 |
|
53012 | /***/ }),
|
53013 | /* 280 */
|
53014 | /***/ (function(module, exports, __webpack_require__) {
|
53015 |
|
53016 | "use strict";
|
53017 |
|
53018 |
|
53019 | var filter = __webpack_require__(2).filter;
|
53020 |
|
53021 | var filterRegExp = __webpack_require__(2).filterRegExp;
|
53022 |
|
53023 | var maxArgumentCount = __webpack_require__(36).maxArgumentCount;
|
53024 |
|
53025 | function factory(type, config, load, typed) {
|
53026 | var matrix = load(__webpack_require__(0));
|
53027 | /**
|
53028 | * Filter the items in an array or one dimensional matrix.
|
53029 | *
|
53030 | * Syntax:
|
53031 | *
|
53032 | * math.filter(x, test)
|
53033 | *
|
53034 | * Examples:
|
53035 | *
|
53036 | * function isPositive (x) {
|
53037 | * return x > 0
|
53038 | * }
|
53039 | * math.filter([6, -2, -1, 4, 3], isPositive) // returns [6, 4, 3]
|
53040 | *
|
53041 | * math.filter(["23", "foo", "100", "55", "bar"], /[0-9]+/) // returns ["23", "100", "55"]
|
53042 | *
|
53043 | * See also:
|
53044 | *
|
53045 | * forEach, map, sort
|
53046 | *
|
53047 | * @param {Matrix | Array} x A one dimensional matrix or array to filter
|
53048 | * @param {Function | RegExp} test
|
53049 | * A function or regular expression to test items.
|
53050 | * All entries for which `test` returns true are returned.
|
53051 | * When `test` is a function, it is invoked with three parameters:
|
53052 | * the value of the element, the index of the element, and the
|
53053 | * matrix/array being traversed. The function must return a boolean.
|
53054 | * @return {Matrix | Array} Returns the filtered matrix.
|
53055 | */
|
53056 |
|
53057 | var filter = typed('filter', {
|
53058 | 'Array, function': _filterCallback,
|
53059 | 'Matrix, function': function MatrixFunction(x, test) {
|
53060 | return matrix(_filterCallback(x.toArray(), test));
|
53061 | },
|
53062 | 'Array, RegExp': filterRegExp,
|
53063 | 'Matrix, RegExp': function MatrixRegExp(x, test) {
|
53064 | return matrix(filterRegExp(x.toArray(), test));
|
53065 | }
|
53066 | });
|
53067 | filter.toTex = undefined; // use default template
|
53068 |
|
53069 | return filter;
|
53070 | }
|
53071 | /**
|
53072 | * Filter values in a callback given a callback function
|
53073 | * @param {Array} x
|
53074 | * @param {Function} callback
|
53075 | * @return {Array} Returns the filtered array
|
53076 | * @private
|
53077 | */
|
53078 |
|
53079 |
|
53080 | function _filterCallback(x, callback) {
|
53081 | // figure out what number of arguments the callback function expects
|
53082 | var args = maxArgumentCount(callback);
|
53083 | return filter(x, function (value, index, array) {
|
53084 | // invoke the callback function with the right number of arguments
|
53085 | if (args === 1) {
|
53086 | return callback(value);
|
53087 | } else if (args === 2) {
|
53088 | return callback(value, [index]);
|
53089 | } else {
|
53090 | // 3 or -1
|
53091 | return callback(value, [index], array);
|
53092 | }
|
53093 | });
|
53094 | }
|
53095 |
|
53096 | exports.name = 'filter';
|
53097 | exports.factory = factory;
|
53098 |
|
53099 | /***/ }),
|
53100 | /* 281 */
|
53101 | /***/ (function(module, exports, __webpack_require__) {
|
53102 |
|
53103 | "use strict";
|
53104 |
|
53105 |
|
53106 | var clone = __webpack_require__(5).clone;
|
53107 |
|
53108 | var _flatten = __webpack_require__(2).flatten;
|
53109 |
|
53110 | function factory(type, config, load, typed) {
|
53111 | var matrix = load(__webpack_require__(0));
|
53112 | /**
|
53113 | * Flatten a multi dimensional matrix into a single dimensional matrix.
|
53114 | *
|
53115 | * Syntax:
|
53116 | *
|
53117 | * math.flatten(x)
|
53118 | *
|
53119 | * Examples:
|
53120 | *
|
53121 | * math.flatten([[1,2], [3,4]]) // returns [1, 2, 3, 4]
|
53122 | *
|
53123 | * See also:
|
53124 | *
|
53125 | * concat, resize, size, squeeze
|
53126 | *
|
53127 | * @param {Matrix | Array} x Matrix to be flattened
|
53128 | * @return {Matrix | Array} Returns the flattened matrix
|
53129 | */
|
53130 |
|
53131 | var flatten = typed('flatten', {
|
53132 | 'Array': function Array(x) {
|
53133 | return _flatten(clone(x));
|
53134 | },
|
53135 | 'Matrix': function Matrix(x) {
|
53136 | var flat = _flatten(clone(x.toArray())); // TODO: return the same matrix type as x
|
53137 |
|
53138 |
|
53139 | return matrix(flat);
|
53140 | }
|
53141 | });
|
53142 | flatten.toTex = undefined; // use default template
|
53143 |
|
53144 | return flatten;
|
53145 | }
|
53146 |
|
53147 | exports.name = 'flatten';
|
53148 | exports.factory = factory;
|
53149 |
|
53150 | /***/ }),
|
53151 | /* 282 */
|
53152 | /***/ (function(module, exports, __webpack_require__) {
|
53153 |
|
53154 | "use strict";
|
53155 |
|
53156 |
|
53157 | var maxArgumentCount = __webpack_require__(36).maxArgumentCount;
|
53158 |
|
53159 | var forEach = __webpack_require__(2).forEach;
|
53160 |
|
53161 | function factory(type, config, load, typed) {
|
53162 | /**
|
53163 | * Iterate over all elements of a matrix/array, and executes the given callback function.
|
53164 | *
|
53165 | * Syntax:
|
53166 | *
|
53167 | * math.forEach(x, callback)
|
53168 | *
|
53169 | * Examples:
|
53170 | *
|
53171 | * math.forEach([1, 2, 3], function(value) {
|
53172 | * console.log(value)
|
53173 | * })
|
53174 | * // outputs 1, 2, 3
|
53175 | *
|
53176 | * See also:
|
53177 | *
|
53178 | * filter, map, sort
|
53179 | *
|
53180 | * @param {Matrix | Array} x The matrix to iterate on.
|
53181 | * @param {Function} callback The callback function is invoked with three
|
53182 | * parameters: the value of the element, the index
|
53183 | * of the element, and the Matrix/array being traversed.
|
53184 | */
|
53185 | var forEach = typed('forEach', {
|
53186 | 'Array, function': _forEach,
|
53187 | 'Matrix, function': function MatrixFunction(x, callback) {
|
53188 | return x.forEach(callback);
|
53189 | }
|
53190 | });
|
53191 | forEach.toTex = undefined; // use default template
|
53192 |
|
53193 | return forEach;
|
53194 | }
|
53195 | /**
|
53196 | * forEach for a multi dimensional array
|
53197 | * @param {Array} array
|
53198 | * @param {Function} callback
|
53199 | * @private
|
53200 | */
|
53201 |
|
53202 |
|
53203 | function _forEach(array, callback) {
|
53204 | // figure out what number of arguments the callback function expects
|
53205 | var args = maxArgumentCount(callback);
|
53206 |
|
53207 | var recurse = function recurse(value, index) {
|
53208 | if (Array.isArray(value)) {
|
53209 | forEach(value, function (child, i) {
|
53210 | // we create a copy of the index array and append the new index value
|
53211 | recurse(child, index.concat(i));
|
53212 | });
|
53213 | } else {
|
53214 | // invoke the callback function with the right number of arguments
|
53215 | if (args === 1) {
|
53216 | callback(value);
|
53217 | } else if (args === 2) {
|
53218 | callback(value, index);
|
53219 | } else {
|
53220 | // 3 or -1
|
53221 | callback(value, index, array);
|
53222 | }
|
53223 | }
|
53224 | };
|
53225 |
|
53226 | recurse(array, []);
|
53227 | }
|
53228 |
|
53229 | exports.name = 'forEach';
|
53230 | exports.factory = factory;
|
53231 |
|
53232 | /***/ }),
|
53233 | /* 283 */
|
53234 | /***/ (function(module, exports, __webpack_require__) {
|
53235 |
|
53236 | "use strict";
|
53237 |
|
53238 |
|
53239 | var size = __webpack_require__(2).size;
|
53240 |
|
53241 | function factory(type, config, load, typed) {
|
53242 | var matrix = load(__webpack_require__(0));
|
53243 | var multiplyScalar = load(__webpack_require__(21));
|
53244 | /**
|
53245 | * Calculates the kronecker product of 2 matrices or vectors.
|
53246 | *
|
53247 | * NOTE: If a one dimensional vector / matrix is given, it will be
|
53248 | * wrapped so its two dimensions.
|
53249 | * See the examples.
|
53250 | *
|
53251 | * Syntax:
|
53252 | *
|
53253 | * math.kron(x, y)
|
53254 | *
|
53255 | * Examples:
|
53256 | *
|
53257 | * math.kron([[1, 0], [0, 1]], [[1, 2], [3, 4]])
|
53258 | * // returns [ [ 1, 2, 0, 0 ], [ 3, 4, 0, 0 ], [ 0, 0, 1, 2 ], [ 0, 0, 3, 4 ] ]
|
53259 | *
|
53260 | * math.kron([1,1], [2,3,4])
|
53261 | * // returns [ [ 2, 3, 4, 2, 3, 4 ] ]
|
53262 | *
|
53263 | * See also:
|
53264 | *
|
53265 | * multiply, dot, cross
|
53266 | *
|
53267 | * @param {Array | Matrix} x First vector
|
53268 | * @param {Array | Matrix} y Second vector
|
53269 | * @return {Array | Matrix} Returns the kronecker product of `x` and `y`
|
53270 | */
|
53271 |
|
53272 | var kron = typed('kron', {
|
53273 | 'Matrix, Matrix': function MatrixMatrix(x, y) {
|
53274 | return matrix(_kron(x.toArray(), y.toArray()));
|
53275 | },
|
53276 | 'Matrix, Array': function MatrixArray(x, y) {
|
53277 | return matrix(_kron(x.toArray(), y));
|
53278 | },
|
53279 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
53280 | return matrix(_kron(x, y.toArray()));
|
53281 | },
|
53282 | 'Array, Array': _kron
|
53283 | });
|
53284 | return kron;
|
53285 | /**
|
53286 | * Calculate the kronecker product of two matrices / vectors
|
53287 | * @param {Array} a First vector
|
53288 | * @param {Array} b Second vector
|
53289 | * @returns {Array} Returns the kronecker product of x and y
|
53290 | * @private
|
53291 | */
|
53292 |
|
53293 | function _kron(a, b) {
|
53294 | // Deal with the dimensions of the matricies.
|
53295 | if (size(a).length === 1) {
|
53296 | // Wrap it in a 2D Matrix
|
53297 | a = [a];
|
53298 | }
|
53299 |
|
53300 | if (size(b).length === 1) {
|
53301 | // Wrap it in a 2D Matrix
|
53302 | b = [b];
|
53303 | }
|
53304 |
|
53305 | if (size(a).length > 2 || size(b).length > 2) {
|
53306 | throw new RangeError('Vectors with dimensions greater then 2 are not supported expected ' + '(Size x = ' + JSON.stringify(a.length) + ', y = ' + JSON.stringify(b.length) + ')');
|
53307 | }
|
53308 |
|
53309 | var t = [];
|
53310 | var r = [];
|
53311 | return a.map(function (a) {
|
53312 | return b.map(function (b) {
|
53313 | r = [];
|
53314 | t.push(r);
|
53315 | return a.map(function (y) {
|
53316 | return b.map(function (x) {
|
53317 | return r.push(multiplyScalar(y, x));
|
53318 | });
|
53319 | });
|
53320 | });
|
53321 | }) && t;
|
53322 | }
|
53323 | }
|
53324 |
|
53325 | exports.name = 'kron';
|
53326 | exports.factory = factory;
|
53327 |
|
53328 | /***/ }),
|
53329 | /* 284 */
|
53330 | /***/ (function(module, exports, __webpack_require__) {
|
53331 |
|
53332 | "use strict";
|
53333 |
|
53334 |
|
53335 | var isInteger = __webpack_require__(3).isInteger;
|
53336 |
|
53337 | var resize = __webpack_require__(2).resize;
|
53338 |
|
53339 | function factory(type, config, load, typed) {
|
53340 | var matrix = load(__webpack_require__(0));
|
53341 | /**
|
53342 | * Create a matrix filled with ones. The created matrix can have one or
|
53343 | * multiple dimensions.
|
53344 | *
|
53345 | * Syntax:
|
53346 | *
|
53347 | * math.ones(m)
|
53348 | * math.ones(m, format)
|
53349 | * math.ones(m, n)
|
53350 | * math.ones(m, n, format)
|
53351 | * math.ones([m, n])
|
53352 | * math.ones([m, n], format)
|
53353 | * math.ones([m, n, p, ...])
|
53354 | * math.ones([m, n, p, ...], format)
|
53355 | *
|
53356 | * Examples:
|
53357 | *
|
53358 | * math.ones(3) // returns [1, 1, 1]
|
53359 | * math.ones(3, 2) // returns [[1, 1], [1, 1], [1, 1]]
|
53360 | * math.ones(3, 2, 'dense') // returns Dense Matrix [[1, 1], [1, 1], [1, 1]]
|
53361 | *
|
53362 | * const A = [[1, 2, 3], [4, 5, 6]]
|
53363 | * math.ones(math.size(A)) // returns [[1, 1, 1], [1, 1, 1]]
|
53364 | *
|
53365 | * See also:
|
53366 | *
|
53367 | * zeros, identity, size, range
|
53368 | *
|
53369 | * @param {...number | Array} size The size of each dimension of the matrix
|
53370 | * @param {string} [format] The Matrix storage format
|
53371 | *
|
53372 | * @return {Array | Matrix | number} A matrix filled with ones
|
53373 | */
|
53374 |
|
53375 | var ones = typed('ones', {
|
53376 | '': function _() {
|
53377 | return config.matrix === 'Array' ? _ones([]) : _ones([], 'default');
|
53378 | },
|
53379 | // math.ones(m, n, p, ..., format)
|
53380 | // TODO: more accurate signature '...number | BigNumber, string' as soon as typed-function supports this
|
53381 | '...number | BigNumber | string': function numberBigNumberString(size) {
|
53382 | var last = size[size.length - 1];
|
53383 |
|
53384 | if (typeof last === 'string') {
|
53385 | var format = size.pop();
|
53386 | return _ones(size, format);
|
53387 | } else if (config.matrix === 'Array') {
|
53388 | return _ones(size);
|
53389 | } else {
|
53390 | return _ones(size, 'default');
|
53391 | }
|
53392 | },
|
53393 | 'Array': _ones,
|
53394 | 'Matrix': function Matrix(size) {
|
53395 | var format = size.storage();
|
53396 | return _ones(size.valueOf(), format);
|
53397 | },
|
53398 | 'Array | Matrix, string': function ArrayMatrixString(size, format) {
|
53399 | return _ones(size.valueOf(), format);
|
53400 | }
|
53401 | });
|
53402 | ones.toTex = undefined; // use default template
|
53403 |
|
53404 | return ones;
|
53405 | /**
|
53406 | * Create an Array or Matrix with ones
|
53407 | * @param {Array} size
|
53408 | * @param {string} [format='default']
|
53409 | * @return {Array | Matrix}
|
53410 | * @private
|
53411 | */
|
53412 |
|
53413 | function _ones(size, format) {
|
53414 | var hasBigNumbers = _normalize(size);
|
53415 |
|
53416 | var defaultValue = hasBigNumbers ? new type.BigNumber(1) : 1;
|
53417 |
|
53418 | _validate(size);
|
53419 |
|
53420 | if (format) {
|
53421 | // return a matrix
|
53422 | var m = matrix(format);
|
53423 |
|
53424 | if (size.length > 0) {
|
53425 | return m.resize(size, defaultValue);
|
53426 | }
|
53427 |
|
53428 | return m;
|
53429 | } else {
|
53430 | // return an Array
|
53431 | var arr = [];
|
53432 |
|
53433 | if (size.length > 0) {
|
53434 | return resize(arr, size, defaultValue);
|
53435 | }
|
53436 |
|
53437 | return arr;
|
53438 | }
|
53439 | } // replace BigNumbers with numbers, returns true if size contained BigNumbers
|
53440 |
|
53441 |
|
53442 | function _normalize(size) {
|
53443 | var hasBigNumbers = false;
|
53444 | size.forEach(function (value, index, arr) {
|
53445 | if (type.isBigNumber(value)) {
|
53446 | hasBigNumbers = true;
|
53447 | arr[index] = value.toNumber();
|
53448 | }
|
53449 | });
|
53450 | return hasBigNumbers;
|
53451 | } // validate arguments
|
53452 |
|
53453 |
|
53454 | function _validate(size) {
|
53455 | size.forEach(function (value) {
|
53456 | if (typeof value !== 'number' || !isInteger(value) || value < 0) {
|
53457 | throw new Error('Parameters in function ones must be positive integers');
|
53458 | }
|
53459 | });
|
53460 | }
|
53461 | }
|
53462 |
|
53463 | exports.name = 'ones';
|
53464 | exports.factory = factory;
|
53465 |
|
53466 | /***/ }),
|
53467 | /* 285 */
|
53468 | /***/ (function(module, exports, __webpack_require__) {
|
53469 |
|
53470 | "use strict";
|
53471 |
|
53472 |
|
53473 | var array = __webpack_require__(2);
|
53474 |
|
53475 | function factory(type, config, load, typed) {
|
53476 | var matrix = load(__webpack_require__(0));
|
53477 | var isInteger = load(__webpack_require__(34));
|
53478 | /**
|
53479 | * Reshape a multi dimensional array to fit the specified dimensions
|
53480 | *
|
53481 | * Syntax:
|
53482 | *
|
53483 | * math.reshape(x, sizes)
|
53484 | *
|
53485 | * Examples:
|
53486 | *
|
53487 | * math.reshape([1, 2, 3, 4, 5, 6], [2, 3])
|
53488 | * // returns Array [[1, 2, 3], [4, 5, 6]]
|
53489 | *
|
53490 | * math.reshape([[1, 2], [3, 4]], [1, 4])
|
53491 | * // returns Array [[1, 2, 3, 4]]
|
53492 | *
|
53493 | * math.reshape([[1, 2], [3, 4]], [4])
|
53494 | * // returns Array [1, 2, 3, 4]
|
53495 | *
|
53496 | * const x = math.matrix([1, 2, 3, 4, 5, 6, 7, 8])
|
53497 | * math.reshape(x, [2, 2, 2])
|
53498 | * // returns Matrix [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
|
53499 | *
|
53500 | * See also:
|
53501 | *
|
53502 | * size, squeeze, resize
|
53503 | *
|
53504 | * @param {Array | Matrix | *} x Matrix to be reshaped
|
53505 | * @param {number[]} sizes One dimensional array with integral sizes for
|
53506 | * each dimension
|
53507 | *
|
53508 | * @return {* | Array | Matrix} A reshaped clone of matrix `x`
|
53509 | *
|
53510 | * @throws {TypeError} If `sizes` does not contain solely integers
|
53511 | * @throws {DimensionError} If the product of the new dimension sizes does
|
53512 | * not equal that of the old ones
|
53513 | */
|
53514 |
|
53515 | var reshape = typed('reshape', {
|
53516 | 'Matrix, Array': function MatrixArray(x, sizes) {
|
53517 | if (x.reshape) {
|
53518 | return x.reshape(sizes);
|
53519 | } else {
|
53520 | return matrix(array.reshape(x.valueOf(), sizes));
|
53521 | }
|
53522 | },
|
53523 | 'Array, Array': function ArrayArray(x, sizes) {
|
53524 | sizes.forEach(function (size) {
|
53525 | if (!isInteger(size)) {
|
53526 | throw new TypeError('Invalid size for dimension: ' + size);
|
53527 | }
|
53528 | });
|
53529 | return array.reshape(x, sizes);
|
53530 | }
|
53531 | });
|
53532 | reshape.toTex = undefined; // use default template
|
53533 |
|
53534 | return reshape;
|
53535 | }
|
53536 |
|
53537 | exports.name = 'reshape';
|
53538 | exports.factory = factory;
|
53539 |
|
53540 | /***/ }),
|
53541 | /* 286 */
|
53542 | /***/ (function(module, exports, __webpack_require__) {
|
53543 |
|
53544 | "use strict";
|
53545 |
|
53546 |
|
53547 | var DimensionError = __webpack_require__(8);
|
53548 |
|
53549 | var ArgumentsError = __webpack_require__(57);
|
53550 |
|
53551 | var isInteger = __webpack_require__(3).isInteger;
|
53552 |
|
53553 | var format = __webpack_require__(9).format;
|
53554 |
|
53555 | var clone = __webpack_require__(5).clone;
|
53556 |
|
53557 | var array = __webpack_require__(2);
|
53558 |
|
53559 | function factory(type, config, load, typed) {
|
53560 | var matrix = load(__webpack_require__(0));
|
53561 | /**
|
53562 | * Resize a matrix
|
53563 | *
|
53564 | * Syntax:
|
53565 | *
|
53566 | * math.resize(x, size)
|
53567 | * math.resize(x, size, defaultValue)
|
53568 | *
|
53569 | * Examples:
|
53570 | *
|
53571 | * math.resize([1, 2, 3, 4, 5], [3]) // returns Array [1, 2, 3]
|
53572 | * math.resize([1, 2, 3], [5], 0) // returns Array [1, 2, 3, 0, 0]
|
53573 | * math.resize(2, [2, 3], 0) // returns Matrix [[2, 0, 0], [0, 0, 0]]
|
53574 | * math.resize("hello", [8], "!") // returns string 'hello!!!'
|
53575 | *
|
53576 | * See also:
|
53577 | *
|
53578 | * size, squeeze, subset, reshape
|
53579 | *
|
53580 | * @param {Array | Matrix | *} x Matrix to be resized
|
53581 | * @param {Array | Matrix} size One dimensional array with numbers
|
53582 | * @param {number | string} [defaultValue=0] Zero by default, except in
|
53583 | * case of a string, in that case
|
53584 | * defaultValue = ' '
|
53585 | * @return {* | Array | Matrix} A resized clone of matrix `x`
|
53586 | */
|
53587 | // TODO: rework resize to a typed-function
|
53588 |
|
53589 | var resize = function resize(x, size, defaultValue) {
|
53590 | if (arguments.length !== 2 && arguments.length !== 3) {
|
53591 | throw new ArgumentsError('resize', arguments.length, 2, 3);
|
53592 | }
|
53593 |
|
53594 | if (type.isMatrix(size)) {
|
53595 | size = size.valueOf(); // get Array
|
53596 | }
|
53597 |
|
53598 | if (type.isBigNumber(size[0])) {
|
53599 | // convert bignumbers to numbers
|
53600 | size = size.map(function (value) {
|
53601 | return type.isBigNumber(value) ? value.toNumber() : value;
|
53602 | });
|
53603 | } // check x is a Matrix
|
53604 |
|
53605 |
|
53606 | if (type.isMatrix(x)) {
|
53607 | // use optimized matrix implementation, return copy
|
53608 | return x.resize(size, defaultValue, true);
|
53609 | }
|
53610 |
|
53611 | if (typeof x === 'string') {
|
53612 | // resize string
|
53613 | return _resizeString(x, size, defaultValue);
|
53614 | } // check result should be a matrix
|
53615 |
|
53616 |
|
53617 | var asMatrix = Array.isArray(x) ? false : config.matrix !== 'Array';
|
53618 |
|
53619 | if (size.length === 0) {
|
53620 | // output a scalar
|
53621 | while (Array.isArray(x)) {
|
53622 | x = x[0];
|
53623 | }
|
53624 |
|
53625 | return clone(x);
|
53626 | } else {
|
53627 | // output an array/matrix
|
53628 | if (!Array.isArray(x)) {
|
53629 | x = [x];
|
53630 | }
|
53631 |
|
53632 | x = clone(x);
|
53633 | var res = array.resize(x, size, defaultValue);
|
53634 | return asMatrix ? matrix(res) : res;
|
53635 | }
|
53636 | };
|
53637 |
|
53638 | resize.toTex = undefined; // use default template
|
53639 |
|
53640 | return resize;
|
53641 | /**
|
53642 | * Resize a string
|
53643 | * @param {string} str
|
53644 | * @param {number[]} size
|
53645 | * @param {string} [defaultChar=' ']
|
53646 | * @private
|
53647 | */
|
53648 |
|
53649 | function _resizeString(str, size, defaultChar) {
|
53650 | if (defaultChar !== undefined) {
|
53651 | if (typeof defaultChar !== 'string' || defaultChar.length !== 1) {
|
53652 | throw new TypeError('Single character expected as defaultValue');
|
53653 | }
|
53654 | } else {
|
53655 | defaultChar = ' ';
|
53656 | }
|
53657 |
|
53658 | if (size.length !== 1) {
|
53659 | throw new DimensionError(size.length, 1);
|
53660 | }
|
53661 |
|
53662 | var len = size[0];
|
53663 |
|
53664 | if (typeof len !== 'number' || !isInteger(len)) {
|
53665 | throw new TypeError('Invalid size, must contain positive integers ' + '(size: ' + format(size) + ')');
|
53666 | }
|
53667 |
|
53668 | if (str.length > len) {
|
53669 | return str.substring(0, len);
|
53670 | } else if (str.length < len) {
|
53671 | var res = str;
|
53672 |
|
53673 | for (var i = 0, ii = len - str.length; i < ii; i++) {
|
53674 | res += defaultChar;
|
53675 | }
|
53676 |
|
53677 | return res;
|
53678 | } else {
|
53679 | return str;
|
53680 | }
|
53681 | }
|
53682 | }
|
53683 |
|
53684 | exports.name = 'resize';
|
53685 | exports.factory = factory;
|
53686 |
|
53687 | /***/ }),
|
53688 | /* 287 */
|
53689 | /***/ (function(module, exports, __webpack_require__) {
|
53690 |
|
53691 | "use strict";
|
53692 |
|
53693 |
|
53694 | var size = __webpack_require__(2).size;
|
53695 |
|
53696 | function factory(type, config, load, typed) {
|
53697 | var matrix = load(__webpack_require__(0));
|
53698 | var compareAsc = load(__webpack_require__(55));
|
53699 |
|
53700 | var compareDesc = function compareDesc(a, b) {
|
53701 | return -compareAsc(a, b);
|
53702 | };
|
53703 |
|
53704 | var compareNatural = load(__webpack_require__(30));
|
53705 | /**
|
53706 | * Sort the items in a matrix.
|
53707 | *
|
53708 | * Syntax:
|
53709 | *
|
53710 | * math.sort(x)
|
53711 | * math.sort(x, compare)
|
53712 | *
|
53713 | * Examples:
|
53714 | *
|
53715 | * math.sort([5, 10, 1]) // returns [1, 5, 10]
|
53716 | * math.sort(['C', 'B', 'A', 'D'], math.compareNatural)
|
53717 | * // returns ['A', 'B', 'C', 'D']
|
53718 | *
|
53719 | * function sortByLength (a, b) {
|
53720 | * return a.length - b.length
|
53721 | * }
|
53722 | * math.sort(['Langdon', 'Tom', 'Sara'], sortByLength)
|
53723 | * // returns ['Tom', 'Sara', 'Langdon']
|
53724 | *
|
53725 | * See also:
|
53726 | *
|
53727 | * filter, forEach, map, compare, compareNatural
|
53728 | *
|
53729 | * @param {Matrix | Array} x A one dimensional matrix or array to sort
|
53730 | * @param {Function | 'asc' | 'desc' | 'natural'} [compare='asc']
|
53731 | * An optional _comparator function or name. The function is called as
|
53732 | * `compare(a, b)`, and must return 1 when a > b, -1 when a < b,
|
53733 | * and 0 when a == b.
|
53734 | * @return {Matrix | Array} Returns the sorted matrix.
|
53735 | */
|
53736 |
|
53737 | var sort = typed('sort', {
|
53738 | 'Array': function Array(x) {
|
53739 | _arrayIsVector(x);
|
53740 |
|
53741 | return x.sort(compareAsc);
|
53742 | },
|
53743 | 'Matrix': function Matrix(x) {
|
53744 | _matrixIsVector(x);
|
53745 |
|
53746 | return matrix(x.toArray().sort(compareAsc), x.storage());
|
53747 | },
|
53748 | 'Array, function': function ArrayFunction(x, _comparator) {
|
53749 | _arrayIsVector(x);
|
53750 |
|
53751 | return x.sort(_comparator);
|
53752 | },
|
53753 | 'Matrix, function': function MatrixFunction(x, _comparator) {
|
53754 | _matrixIsVector(x);
|
53755 |
|
53756 | return matrix(x.toArray().sort(_comparator), x.storage());
|
53757 | },
|
53758 | 'Array, string': function ArrayString(x, order) {
|
53759 | _arrayIsVector(x);
|
53760 |
|
53761 | return x.sort(_comparator(order));
|
53762 | },
|
53763 | 'Matrix, string': function MatrixString(x, order) {
|
53764 | _matrixIsVector(x);
|
53765 |
|
53766 | return matrix(x.toArray().sort(_comparator(order)), x.storage());
|
53767 | }
|
53768 | });
|
53769 | sort.toTex = undefined; // use default template
|
53770 |
|
53771 | /**
|
53772 | * Get the comparator for given order ('asc', 'desc', 'natural')
|
53773 | * @param {'asc' | 'desc' | 'natural'} order
|
53774 | * @return {Function} Returns a _comparator function
|
53775 | */
|
53776 |
|
53777 | function _comparator(order) {
|
53778 | if (order === 'asc') {
|
53779 | return compareAsc;
|
53780 | } else if (order === 'desc') {
|
53781 | return compareDesc;
|
53782 | } else if (order === 'natural') {
|
53783 | return compareNatural;
|
53784 | } else {
|
53785 | throw new Error('String "asc", "desc", or "natural" expected');
|
53786 | }
|
53787 | }
|
53788 | /**
|
53789 | * Validate whether an array is one dimensional
|
53790 | * Throws an error when this is not the case
|
53791 | * @param {Array} array
|
53792 | * @private
|
53793 | */
|
53794 |
|
53795 |
|
53796 | function _arrayIsVector(array) {
|
53797 | if (size(array).length !== 1) {
|
53798 | throw new Error('One dimensional array expected');
|
53799 | }
|
53800 | }
|
53801 | /**
|
53802 | * Validate whether a matrix is one dimensional
|
53803 | * Throws an error when this is not the case
|
53804 | * @param {Matrix} matrix
|
53805 | * @private
|
53806 | */
|
53807 |
|
53808 |
|
53809 | function _matrixIsVector(matrix) {
|
53810 | if (matrix.size().length !== 1) {
|
53811 | throw new Error('One dimensional matrix expected');
|
53812 | }
|
53813 | }
|
53814 |
|
53815 | return sort;
|
53816 | }
|
53817 |
|
53818 | exports.name = 'sort';
|
53819 | exports.factory = factory;
|
53820 |
|
53821 | /***/ }),
|
53822 | /* 288 */
|
53823 | /***/ (function(module, exports) {
|
53824 |
|
53825 | /*
|
53826 | * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
|
53827 | * Author: Jim Palmer (based on chunking idea from Dave Koelle)
|
53828 | */
|
53829 | /*jshint unused:false */
|
53830 | module.exports = function naturalSort (a, b) {
|
53831 | "use strict";
|
53832 | var re = /(^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/gi,
|
53833 | sre = /(^[ ]*|[ ]*$)/g,
|
53834 | dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
|
53835 | hre = /^0x[0-9a-f]+$/i,
|
53836 | ore = /^0/,
|
53837 | i = function(s) { return naturalSort.insensitive && ('' + s).toLowerCase() || '' + s; },
|
53838 | // convert all to strings strip whitespace
|
53839 | x = i(a).replace(sre, '') || '',
|
53840 | y = i(b).replace(sre, '') || '',
|
53841 | // chunk/tokenize
|
53842 | xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
|
53843 | yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
|
53844 | // numeric, hex or date detection
|
53845 | xD = parseInt(x.match(hre), 16) || (xN.length !== 1 && x.match(dre) && Date.parse(x)),
|
53846 | yD = parseInt(y.match(hre), 16) || xD && y.match(dre) && Date.parse(y) || null,
|
53847 | oFxNcL, oFyNcL;
|
53848 | // first try and sort Hex codes or Dates
|
53849 | if (yD) {
|
53850 | if ( xD < yD ) { return -1; }
|
53851 | else if ( xD > yD ) { return 1; }
|
53852 | }
|
53853 | // natural sorting through split numeric strings and default strings
|
53854 | for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
|
53855 | // find floats not starting with '0', string or 0 if not defined (Clint Priest)
|
53856 | oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
|
53857 | oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
|
53858 | // handle numeric vs string comparison - number < string - (Kyle Adams)
|
53859 | if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { return (isNaN(oFxNcL)) ? 1 : -1; }
|
53860 | // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
|
53861 | else if (typeof oFxNcL !== typeof oFyNcL) {
|
53862 | oFxNcL += '';
|
53863 | oFyNcL += '';
|
53864 | }
|
53865 | if (oFxNcL < oFyNcL) { return -1; }
|
53866 | if (oFxNcL > oFyNcL) { return 1; }
|
53867 | }
|
53868 | return 0;
|
53869 | };
|
53870 |
|
53871 |
|
53872 | /***/ }),
|
53873 | /* 289 */
|
53874 | /***/ (function(module, exports, __webpack_require__) {
|
53875 |
|
53876 | "use strict";
|
53877 |
|
53878 |
|
53879 | var array = __webpack_require__(2);
|
53880 |
|
53881 | var latex = __webpack_require__(4);
|
53882 |
|
53883 | var string = __webpack_require__(9);
|
53884 |
|
53885 | function factory(type, config, load, typed) {
|
53886 | var abs = load(__webpack_require__(25));
|
53887 | var add = load(__webpack_require__(14));
|
53888 | var multiply = load(__webpack_require__(10));
|
53889 | var sqrt = load(__webpack_require__(46));
|
53890 | var subtract = load(__webpack_require__(15));
|
53891 | var inv = load(__webpack_require__(70));
|
53892 | var size = load(__webpack_require__(28));
|
53893 | var max = load(__webpack_require__(98));
|
53894 | var identity = load(__webpack_require__(50));
|
53895 | /**
|
53896 | * Calculate the principal square root of a square matrix.
|
53897 | * The principal square root matrix `X` of another matrix `A` is such that `X * X = A`.
|
53898 | *
|
53899 | * https://en.wikipedia.org/wiki/Square_root_of_a_matrix
|
53900 | *
|
53901 | * Syntax:
|
53902 | *
|
53903 | * X = math.sqrtm(A)
|
53904 | *
|
53905 | * Examples:
|
53906 | *
|
53907 | * math.sqrtm([[1, 2], [3, 4]]) // returns [[-2, 1], [1.5, -0.5]]
|
53908 | *
|
53909 | * See also:
|
53910 | *
|
53911 | * sqrt, pow
|
53912 | *
|
53913 | * @param {Array | Matrix} A The square matrix `A`
|
53914 | * @return {Array | Matrix} The principal square root of matrix `A`
|
53915 | */
|
53916 |
|
53917 | var sqrtm = typed('sqrtm', {
|
53918 | 'Array | Matrix': function ArrayMatrix(A) {
|
53919 | var size = type.isMatrix(A) ? A.size() : array.size(A);
|
53920 |
|
53921 | switch (size.length) {
|
53922 | case 1:
|
53923 | // Single element Array | Matrix
|
53924 | if (size[0] === 1) {
|
53925 | return sqrt(A);
|
53926 | } else {
|
53927 | throw new RangeError('Matrix must be square ' + '(size: ' + string.format(size) + ')');
|
53928 | }
|
53929 |
|
53930 | case 2:
|
53931 | // Two-dimensional Array | Matrix
|
53932 | var rows = size[0];
|
53933 | var cols = size[1];
|
53934 |
|
53935 | if (rows === cols) {
|
53936 | return _denmanBeavers(A);
|
53937 | } else {
|
53938 | throw new RangeError('Matrix must be square ' + '(size: ' + string.format(size) + ')');
|
53939 | }
|
53940 |
|
53941 | }
|
53942 | }
|
53943 | });
|
53944 | var _maxIterations = 1e3;
|
53945 | var _tolerance = 1e-6;
|
53946 | /**
|
53947 | * Calculate the principal square root matrix using the Denman–Beavers iterative method
|
53948 | *
|
53949 | * https://en.wikipedia.org/wiki/Square_root_of_a_matrix#By_Denman–Beavers_iteration
|
53950 | *
|
53951 | * @param {Array | Matrix} A The square matrix `A`
|
53952 | * @return {Array | Matrix} The principal square root of matrix `A`
|
53953 | * @private
|
53954 | */
|
53955 |
|
53956 | function _denmanBeavers(A) {
|
53957 | var error;
|
53958 | var iterations = 0;
|
53959 | var Y = A;
|
53960 | var Z = identity(size(A));
|
53961 |
|
53962 | do {
|
53963 | var Yk = Y;
|
53964 | Y = multiply(0.5, add(Yk, inv(Z)));
|
53965 | Z = multiply(0.5, add(Z, inv(Yk)));
|
53966 | error = max(abs(subtract(Y, Yk)));
|
53967 |
|
53968 | if (error > _tolerance && ++iterations > _maxIterations) {
|
53969 | throw new Error('computing square root of matrix: iterative method could not converge');
|
53970 | }
|
53971 | } while (error > _tolerance);
|
53972 |
|
53973 | return Y;
|
53974 | }
|
53975 |
|
53976 | sqrtm.toTex = {
|
53977 | 1: "{${args[0]}}".concat(latex.operators['pow'], "{\\frac{1}{2}}")
|
53978 | };
|
53979 | return sqrtm;
|
53980 | }
|
53981 |
|
53982 | exports.name = 'sqrtm';
|
53983 | exports.factory = factory;
|
53984 |
|
53985 | /***/ }),
|
53986 | /* 290 */
|
53987 | /***/ (function(module, exports, __webpack_require__) {
|
53988 |
|
53989 | "use strict";
|
53990 |
|
53991 |
|
53992 | var object = __webpack_require__(5);
|
53993 |
|
53994 | var array = __webpack_require__(2);
|
53995 |
|
53996 | function factory(type, config, load, typed) {
|
53997 | var matrix = load(__webpack_require__(0));
|
53998 | /**
|
53999 | * Squeeze a matrix, remove inner and outer singleton dimensions from a matrix.
|
54000 | *
|
54001 | * Syntax:
|
54002 | *
|
54003 | * math.squeeze(x)
|
54004 | *
|
54005 | * Examples:
|
54006 | *
|
54007 | * math.squeeze([3]) // returns 3
|
54008 | * math.squeeze([[3]]) // returns 3
|
54009 | *
|
54010 | * const A = math.zeros(3, 1) // returns [[0], [0], [0]] (size 3x1)
|
54011 | * math.squeeze(A) // returns [0, 0, 0] (size 3)
|
54012 | *
|
54013 | * const B = math.zeros(1, 3) // returns [[0, 0, 0]] (size 1x3)
|
54014 | * math.squeeze(B) // returns [0, 0, 0] (size 3)
|
54015 | *
|
54016 | * // only inner and outer dimensions are removed
|
54017 | * const C = math.zeros(2, 1, 3) // returns [[[0, 0, 0]], [[0, 0, 0]]] (size 2x1x3)
|
54018 | * math.squeeze(C) // returns [[[0, 0, 0]], [[0, 0, 0]]] (size 2x1x3)
|
54019 | *
|
54020 | * See also:
|
54021 | *
|
54022 | * subset
|
54023 | *
|
54024 | * @param {Matrix | Array} x Matrix to be squeezed
|
54025 | * @return {Matrix | Array} Squeezed matrix
|
54026 | */
|
54027 |
|
54028 | var squeeze = typed('squeeze', {
|
54029 | 'Array': function Array(x) {
|
54030 | return array.squeeze(object.clone(x));
|
54031 | },
|
54032 | 'Matrix': function Matrix(x) {
|
54033 | var res = array.squeeze(x.toArray()); // FIXME: return the same type of matrix as the input
|
54034 |
|
54035 | return Array.isArray(res) ? matrix(res) : res;
|
54036 | },
|
54037 | 'any': function any(x) {
|
54038 | // scalar
|
54039 | return object.clone(x);
|
54040 | }
|
54041 | });
|
54042 | squeeze.toTex = undefined; // use default template
|
54043 |
|
54044 | return squeeze;
|
54045 | }
|
54046 |
|
54047 | exports.name = 'squeeze';
|
54048 | exports.factory = factory;
|
54049 |
|
54050 | /***/ }),
|
54051 | /* 291 */
|
54052 | /***/ (function(module, exports, __webpack_require__) {
|
54053 |
|
54054 | "use strict";
|
54055 |
|
54056 |
|
54057 | var clone = __webpack_require__(5).clone;
|
54058 |
|
54059 | var format = __webpack_require__(9).format;
|
54060 |
|
54061 | function factory(type, config, load, typed) {
|
54062 | var matrix = load(__webpack_require__(0));
|
54063 | var add = load(__webpack_require__(14));
|
54064 | /**
|
54065 | * Calculate the trace of a matrix: the sum of the elements on the main
|
54066 | * diagonal of a square matrix.
|
54067 | *
|
54068 | * Syntax:
|
54069 | *
|
54070 | * math.trace(x)
|
54071 | *
|
54072 | * Examples:
|
54073 | *
|
54074 | * math.trace([[1, 2], [3, 4]]) // returns 5
|
54075 | *
|
54076 | * const A = [
|
54077 | * [1, 2, 3],
|
54078 | * [-1, 2, 3],
|
54079 | * [2, 0, 3]
|
54080 | * ]
|
54081 | * math.trace(A) // returns 6
|
54082 | *
|
54083 | * See also:
|
54084 | *
|
54085 | * diag
|
54086 | *
|
54087 | * @param {Array | Matrix} x A matrix
|
54088 | *
|
54089 | * @return {number} The trace of `x`
|
54090 | */
|
54091 |
|
54092 | var trace = typed('trace', {
|
54093 | 'Array': function _arrayTrace(x) {
|
54094 | // use dense matrix implementation
|
54095 | return _denseTrace(matrix(x));
|
54096 | },
|
54097 | 'SparseMatrix': _sparseTrace,
|
54098 | 'DenseMatrix': _denseTrace,
|
54099 | 'any': clone
|
54100 | });
|
54101 |
|
54102 | function _denseTrace(m) {
|
54103 | // matrix size & data
|
54104 | var size = m._size;
|
54105 | var data = m._data; // process dimensions
|
54106 |
|
54107 | switch (size.length) {
|
54108 | case 1:
|
54109 | // vector
|
54110 | if (size[0] === 1) {
|
54111 | // return data[0]
|
54112 | return clone(data[0]);
|
54113 | }
|
54114 |
|
54115 | throw new RangeError('Matrix must be square (size: ' + format(size) + ')');
|
54116 |
|
54117 | case 2:
|
54118 | // two dimensional
|
54119 | var rows = size[0];
|
54120 | var cols = size[1];
|
54121 |
|
54122 | if (rows === cols) {
|
54123 | // calulate sum
|
54124 | var sum = 0; // loop diagonal
|
54125 |
|
54126 | for (var i = 0; i < rows; i++) {
|
54127 | sum = add(sum, data[i][i]);
|
54128 | } // return trace
|
54129 |
|
54130 |
|
54131 | return sum;
|
54132 | }
|
54133 |
|
54134 | throw new RangeError('Matrix must be square (size: ' + format(size) + ')');
|
54135 |
|
54136 | default:
|
54137 | // multi dimensional
|
54138 | throw new RangeError('Matrix must be two dimensional (size: ' + format(size) + ')');
|
54139 | }
|
54140 | }
|
54141 |
|
54142 | function _sparseTrace(m) {
|
54143 | // matrix arrays
|
54144 | var values = m._values;
|
54145 | var index = m._index;
|
54146 | var ptr = m._ptr;
|
54147 | var size = m._size; // check dimensions
|
54148 |
|
54149 | var rows = size[0];
|
54150 | var columns = size[1]; // matrix must be square
|
54151 |
|
54152 | if (rows === columns) {
|
54153 | // calulate sum
|
54154 | var sum = 0; // check we have data (avoid looping columns)
|
54155 |
|
54156 | if (values.length > 0) {
|
54157 | // loop columns
|
54158 | for (var j = 0; j < columns; j++) {
|
54159 | // k0 <= k < k1 where k0 = _ptr[j] && k1 = _ptr[j+1]
|
54160 | var k0 = ptr[j];
|
54161 | var k1 = ptr[j + 1]; // loop k within [k0, k1[
|
54162 |
|
54163 | for (var k = k0; k < k1; k++) {
|
54164 | // row index
|
54165 | var i = index[k]; // check row
|
54166 |
|
54167 | if (i === j) {
|
54168 | // accumulate value
|
54169 | sum = add(sum, values[k]); // exit loop
|
54170 |
|
54171 | break;
|
54172 | }
|
54173 |
|
54174 | if (i > j) {
|
54175 | // exit loop, no value on the diagonal for column j
|
54176 | break;
|
54177 | }
|
54178 | }
|
54179 | }
|
54180 | } // return trace
|
54181 |
|
54182 |
|
54183 | return sum;
|
54184 | }
|
54185 |
|
54186 | throw new RangeError('Matrix must be square (size: ' + format(size) + ')');
|
54187 | }
|
54188 |
|
54189 | trace.toTex = {
|
54190 | 1: "\\mathrm{tr}\\left(${args[0]}\\right)"
|
54191 | };
|
54192 | return trace;
|
54193 | }
|
54194 |
|
54195 | exports.name = 'trace';
|
54196 | exports.factory = factory;
|
54197 |
|
54198 | /***/ }),
|
54199 | /* 292 */
|
54200 | /***/ (function(module, exports, __webpack_require__) {
|
54201 |
|
54202 | "use strict";
|
54203 |
|
54204 |
|
54205 | function factory(type, config, load, typed) {
|
54206 | var getArrayDataType = load(__webpack_require__(63));
|
54207 | /**
|
54208 | * Find the data type of all elements in a matrix or array,
|
54209 | * for example 'number' if all items are a number and 'Complex' if all values
|
54210 | * are complex numbers.
|
54211 | * If a matrix contains more than one data type, it will return 'mixed'.
|
54212 | *
|
54213 | * Syntax:
|
54214 | *
|
54215 | * math.getMatrixDataType(x)
|
54216 | *
|
54217 | * Examples:
|
54218 | *
|
54219 | * const x = [ [1, 2, 3], [4, 5, 6] ]
|
54220 | * const mixedX = [ [1, true], [2, 3] ]
|
54221 | * const fractionX = [ [math.fraction(1, 3)], [math.fraction(1, 3] ]
|
54222 | * const unitX = [ [math.unit('5cm')], [math.unit('5cm')] ]
|
54223 | * const bigNumberX = [ [math.bignumber(1)], [math.bignumber(0)] ]
|
54224 | * const sparse = math.sparse(x)
|
54225 | * const dense = math.matrix(x)
|
54226 | * math.getMatrixDataType(x) // returns 'number'
|
54227 | * math.getMatrixDataType(sparse) // returns 'number'
|
54228 | * math.getMatrixDataType(dense) // returns 'number'
|
54229 | * math.getMatrixDataType(mixedX) // returns 'mixed'
|
54230 | * math.getMatrixDataType(fractionX) // returns 'Fraction'
|
54231 | * math.getMatrixDataType(unitX) // returns 'Unit'
|
54232 | * math.getMatrixDataType(bigNumberX) // return 'BigNumber'
|
54233 | *
|
54234 | * See also:
|
54235 | * SparseMatrix, DenseMatrix
|
54236 | *
|
54237 | * @param {...Matrix | Array} x The Matrix with values.
|
54238 | *
|
54239 | * @return {string} A string representation of the matrix type
|
54240 | */
|
54241 |
|
54242 | var getMatrixDataType = typed('getMatrixDataType', {
|
54243 | 'Array': function Array(x) {
|
54244 | return getArrayDataType(x);
|
54245 | },
|
54246 | 'Matrix': function Matrix(x) {
|
54247 | return x.getDataType();
|
54248 | }
|
54249 | });
|
54250 | return getMatrixDataType;
|
54251 | }
|
54252 |
|
54253 | exports.name = 'getMatrixDataType';
|
54254 | exports.factory = factory;
|
54255 |
|
54256 | /***/ }),
|
54257 | /* 293 */
|
54258 | /***/ (function(module, exports, __webpack_require__) {
|
54259 |
|
54260 | "use strict";
|
54261 |
|
54262 |
|
54263 | module.exports = [// require('./distribution'), // TODO: rethink math.distribution
|
54264 | __webpack_require__(76), __webpack_require__(75), __webpack_require__(141), __webpack_require__(294), __webpack_require__(295), __webpack_require__(296), __webpack_require__(297), __webpack_require__(301), __webpack_require__(302)];
|
54265 |
|
54266 | /***/ }),
|
54267 | /* 294 */
|
54268 | /***/ (function(module, exports, __webpack_require__) {
|
54269 |
|
54270 | "use strict";
|
54271 |
|
54272 |
|
54273 | function factory(type, config, load, typed) {
|
54274 | var matrix = load(__webpack_require__(0));
|
54275 | var divide = load(__webpack_require__(45));
|
54276 | var sum = load(__webpack_require__(99));
|
54277 | var multiply = load(__webpack_require__(10));
|
54278 | var dotDivide = load(__webpack_require__(138));
|
54279 | var log = load(__webpack_require__(91));
|
54280 | var isNumeric = load(__webpack_require__(52));
|
54281 | /**
|
54282 | * Calculate the Kullback-Leibler (KL) divergence between two distributions
|
54283 | *
|
54284 | * Syntax:
|
54285 | *
|
54286 | * math.kldivergence(x, y)
|
54287 | *
|
54288 | * Examples:
|
54289 | *
|
54290 | * math.kldivergence([0.7,0.5,0.4], [0.2,0.9,0.5]) //returns 0.24376698773121153
|
54291 | *
|
54292 | *
|
54293 | * @param {Array | Matrix} q First vector
|
54294 | * @param {Array | Matrix} p Second vector
|
54295 | * @return {number} Returns distance between q and p
|
54296 | */
|
54297 |
|
54298 | var kldivergence = typed('kldivergence', {
|
54299 | 'Array, Array': function ArrayArray(q, p) {
|
54300 | return _kldiv(matrix(q), matrix(p));
|
54301 | },
|
54302 | 'Matrix, Array': function MatrixArray(q, p) {
|
54303 | return _kldiv(q, matrix(p));
|
54304 | },
|
54305 | 'Array, Matrix': function ArrayMatrix(q, p) {
|
54306 | return _kldiv(matrix(q), p);
|
54307 | },
|
54308 | 'Matrix, Matrix': function MatrixMatrix(q, p) {
|
54309 | return _kldiv(q, p);
|
54310 | }
|
54311 | });
|
54312 |
|
54313 | function _kldiv(q, p) {
|
54314 | var plength = p.size().length;
|
54315 | var qlength = q.size().length;
|
54316 |
|
54317 | if (plength > 1) {
|
54318 | throw new Error('first object must be one dimensional');
|
54319 | }
|
54320 |
|
54321 | if (qlength > 1) {
|
54322 | throw new Error('second object must be one dimensional');
|
54323 | }
|
54324 |
|
54325 | if (plength !== qlength) {
|
54326 | throw new Error('Length of two vectors must be equal');
|
54327 | } // Before calculation, apply normalization
|
54328 |
|
54329 |
|
54330 | var sumq = sum(q);
|
54331 |
|
54332 | if (sumq === 0) {
|
54333 | throw new Error('Sum of elements in first object must be non zero');
|
54334 | }
|
54335 |
|
54336 | var sump = sum(p);
|
54337 |
|
54338 | if (sump === 0) {
|
54339 | throw new Error('Sum of elements in second object must be non zero');
|
54340 | }
|
54341 |
|
54342 | var qnorm = divide(q, sum(q));
|
54343 | var pnorm = divide(p, sum(p));
|
54344 | var result = sum(multiply(qnorm, log(dotDivide(qnorm, pnorm))));
|
54345 |
|
54346 | if (isNumeric(result)) {
|
54347 | return result;
|
54348 | } else {
|
54349 | return Number.NaN;
|
54350 | }
|
54351 | }
|
54352 |
|
54353 | return kldivergence;
|
54354 | }
|
54355 |
|
54356 | exports.name = 'kldivergence';
|
54357 | exports.factory = factory;
|
54358 |
|
54359 | /***/ }),
|
54360 | /* 295 */
|
54361 | /***/ (function(module, exports, __webpack_require__) {
|
54362 |
|
54363 | "use strict";
|
54364 |
|
54365 |
|
54366 | var deepForEach = __webpack_require__(47);
|
54367 |
|
54368 | function factory(type, config, load, typed) {
|
54369 | var add = load(__webpack_require__(14));
|
54370 | var multiply = load(__webpack_require__(10));
|
54371 | var divide = load(__webpack_require__(45));
|
54372 | var factorial = load(__webpack_require__(75));
|
54373 | var isInteger = load(__webpack_require__(34));
|
54374 | var isPositive = load(__webpack_require__(73));
|
54375 | /**
|
54376 | * Multinomial Coefficients compute the number of ways of picking a1, a2, ..., ai unordered outcomes from `n` possibilities.
|
54377 | *
|
54378 | * multinomial takes one array of integers as an argument.
|
54379 | * The following condition must be enforced: every ai <= 0
|
54380 | *
|
54381 | * Syntax:
|
54382 | *
|
54383 | * math.multinomial(a) // a is an array type
|
54384 | *
|
54385 | * Examples:
|
54386 | *
|
54387 | * math.multinomial([1,2,1]) // returns 12
|
54388 | *
|
54389 | * See also:
|
54390 | *
|
54391 | * combinations, factorial
|
54392 | *
|
54393 | * @param {number[] | BigNumber[]} a Integer numbers of objects in the subset
|
54394 | * @return {Number | BigNumber} Multinomial coefficient.
|
54395 | */
|
54396 |
|
54397 | return typed('multinomial', {
|
54398 | 'Array | Matrix': function ArrayMatrix(a) {
|
54399 | var sum = 0;
|
54400 | var denom = 1;
|
54401 | deepForEach(a, function (ai) {
|
54402 | if (!isInteger(ai) || !isPositive(ai)) {
|
54403 | throw new TypeError('Positive integer value expected in function multinomial');
|
54404 | }
|
54405 |
|
54406 | sum = add(sum, ai);
|
54407 | denom = multiply(denom, factorial(ai));
|
54408 | });
|
54409 | return divide(factorial(sum), denom);
|
54410 | }
|
54411 | });
|
54412 | }
|
54413 |
|
54414 | exports.name = 'multinomial';
|
54415 | exports.factory = factory;
|
54416 |
|
54417 | /***/ }),
|
54418 | /* 296 */
|
54419 | /***/ (function(module, exports, __webpack_require__) {
|
54420 |
|
54421 | "use strict";
|
54422 |
|
54423 |
|
54424 | var isInteger = __webpack_require__(3).isInteger;
|
54425 |
|
54426 | function factory(type, config, load, typed) {
|
54427 | var factorial = load(__webpack_require__(75));
|
54428 |
|
54429 | var product = __webpack_require__(95);
|
54430 | /**
|
54431 | * Compute the number of ways of obtaining an ordered subset of `k` elements
|
54432 | * from a set of `n` elements.
|
54433 | *
|
54434 | * Permutations only takes integer arguments.
|
54435 | * The following condition must be enforced: k <= n.
|
54436 | *
|
54437 | * Syntax:
|
54438 | *
|
54439 | * math.permutations(n)
|
54440 | * math.permutations(n, k)
|
54441 | *
|
54442 | * Examples:
|
54443 | *
|
54444 | * math.permutations(5) // 120
|
54445 | * math.permutations(5, 3) // 60
|
54446 | *
|
54447 | * See also:
|
54448 | *
|
54449 | * combinations, factorial
|
54450 | *
|
54451 | * @param {number | BigNumber} n The number of objects in total
|
54452 | * @param {number | BigNumber} [k] The number of objects in the subset
|
54453 | * @return {number | BigNumber} The number of permutations
|
54454 | */
|
54455 |
|
54456 |
|
54457 | var permutations = typed('permutations', {
|
54458 | 'number | BigNumber': factorial,
|
54459 | 'number, number': function numberNumber(n, k) {
|
54460 | if (!isInteger(n) || n < 0) {
|
54461 | throw new TypeError('Positive integer value expected in function permutations');
|
54462 | }
|
54463 |
|
54464 | if (!isInteger(k) || k < 0) {
|
54465 | throw new TypeError('Positive integer value expected in function permutations');
|
54466 | }
|
54467 |
|
54468 | if (k > n) {
|
54469 | throw new TypeError('second argument k must be less than or equal to first argument n');
|
54470 | } // Permute n objects, k at a time
|
54471 |
|
54472 |
|
54473 | return product(n - k + 1, n);
|
54474 | },
|
54475 | 'BigNumber, BigNumber': function BigNumberBigNumber(n, k) {
|
54476 | var result, i;
|
54477 |
|
54478 | if (!isPositiveInteger(n) || !isPositiveInteger(k)) {
|
54479 | throw new TypeError('Positive integer value expected in function permutations');
|
54480 | }
|
54481 |
|
54482 | if (k.gt(n)) {
|
54483 | throw new TypeError('second argument k must be less than or equal to first argument n');
|
54484 | }
|
54485 |
|
54486 | result = new type.BigNumber(1);
|
54487 |
|
54488 | for (i = n.minus(k).plus(1); i.lte(n); i = i.plus(1)) {
|
54489 | result = result.times(i);
|
54490 | }
|
54491 |
|
54492 | return result;
|
54493 | } // TODO: implement support for collection in permutations
|
54494 |
|
54495 | });
|
54496 | permutations.toTex = undefined; // use default template
|
54497 |
|
54498 | return permutations;
|
54499 | }
|
54500 | /**
|
54501 | * Test whether BigNumber n is a positive integer
|
54502 | * @param {BigNumber} n
|
54503 | * @returns {boolean} isPositiveInteger
|
54504 | */
|
54505 |
|
54506 |
|
54507 | function isPositiveInteger(n) {
|
54508 | return n.isInteger() && n.gte(0);
|
54509 | }
|
54510 |
|
54511 | exports.name = 'permutations';
|
54512 | exports.factory = factory;
|
54513 |
|
54514 | /***/ }),
|
54515 | /* 297 */
|
54516 | /***/ (function(module, exports, __webpack_require__) {
|
54517 |
|
54518 | "use strict";
|
54519 |
|
54520 |
|
54521 | function factory(type, config, load, typed) {
|
54522 | var distribution = load(__webpack_require__(100));
|
54523 | /**
|
54524 | * Random pick one or more values from a one dimensional array.
|
54525 | * Array elements are picked using a random function with uniform or weighted distribution.
|
54526 | *
|
54527 | * Syntax:
|
54528 | *
|
54529 | * math.pickRandom(array)
|
54530 | * math.pickRandom(array, number)
|
54531 | * math.pickRandom(array, weights)
|
54532 | * math.pickRandom(array, number, weights)
|
54533 | * math.pickRandom(array, weights, number)
|
54534 | *
|
54535 | * Examples:
|
54536 | *
|
54537 | * math.pickRandom([3, 6, 12, 2]) // returns one of the values in the array
|
54538 | * math.pickRandom([3, 6, 12, 2], 2) // returns an array of two of the values in the array
|
54539 | * math.pickRandom([3, 6, 12, 2], [1, 3, 2, 1]) // returns one of the values in the array with weighted distribution
|
54540 | * math.pickRandom([3, 6, 12, 2], 2, [1, 3, 2, 1]) // returns an array of two of the values in the array with weighted distribution
|
54541 | * math.pickRandom([3, 6, 12, 2], [1, 3, 2, 1], 2) // returns an array of two of the values in the array with weighted distribution
|
54542 | *
|
54543 | * See also:
|
54544 | *
|
54545 | * random, randomInt
|
54546 | *
|
54547 | * @param {Array} array A one dimensional array
|
54548 | * @param {Int} number An int or float
|
54549 | * @param {Array} weights An array of ints or floats
|
54550 | * @return {number | Array} Returns a single random value from array when number is 1 or undefined.
|
54551 | * Returns an array with the configured number of elements when number is > 1.
|
54552 | */
|
54553 | // TODO: rework pickRandom to a typed-function
|
54554 |
|
54555 | var pickRandom = distribution('uniform').pickRandom;
|
54556 | pickRandom.toTex = undefined; // use default template
|
54557 |
|
54558 | return pickRandom;
|
54559 | }
|
54560 |
|
54561 | exports.name = 'pickRandom';
|
54562 | exports.factory = factory;
|
54563 |
|
54564 | /***/ }),
|
54565 | /* 298 */
|
54566 | /***/ (function(module, exports, __webpack_require__) {
|
54567 |
|
54568 | "use strict";
|
54569 |
|
54570 |
|
54571 | var seedrandom = __webpack_require__(299); // create a random seed here to prevent an infinite loop from seed-random
|
54572 | // inside the factory. Reason is that math.random is defined as a getter/setter
|
54573 | // and seed-random generates a seed from the local entropy by reading every
|
54574 | // defined object including `math` itself. That means that whilst getting
|
54575 | // math.random, it tries to get math.random, etc... an infinite loop.
|
54576 | // See https://github.com/ForbesLindesay/seed-random/issues/6
|
54577 |
|
54578 |
|
54579 | var singletonRandom = seedrandom();
|
54580 |
|
54581 | function factory(type, config, load, typed, math) {
|
54582 | var random; // create a new random generator with given seed
|
54583 |
|
54584 | function setSeed(seed) {
|
54585 | random = seed === null ? singletonRandom : seedrandom(String(seed));
|
54586 | } // initialize a seeded pseudo random number generator with config's random seed
|
54587 |
|
54588 |
|
54589 | setSeed(config.randomSeed); // wrapper function so the rng can be updated via generator
|
54590 |
|
54591 | function rng() {
|
54592 | return random();
|
54593 | } // updates generator with a new instance of a seeded pseudo random number generator
|
54594 |
|
54595 |
|
54596 | math.on('config', function (curr, prev, changes) {
|
54597 | // if the user specified a randomSeed
|
54598 | if (changes.randomSeed !== undefined) {
|
54599 | // update generator with a new instance of a seeded pseudo random number generator
|
54600 | setSeed(curr.randomSeed);
|
54601 | }
|
54602 | });
|
54603 | return rng;
|
54604 | }
|
54605 |
|
54606 | exports.factory = factory;
|
54607 | exports.math = true;
|
54608 |
|
54609 | /***/ }),
|
54610 | /* 299 */
|
54611 | /***/ (function(module, exports, __webpack_require__) {
|
54612 |
|
54613 | "use strict";
|
54614 | /* WEBPACK VAR INJECTION */(function(global) {
|
54615 |
|
54616 | var width = 256;// each RC4 output is 0 <= x < 256
|
54617 | var chunks = 6;// at least six RC4 outputs for each double
|
54618 | var digits = 52;// there are 52 significant digits in a double
|
54619 | var pool = [];// pool: entropy pool starts empty
|
54620 | var GLOBAL = typeof global === 'undefined' ? window : global;
|
54621 |
|
54622 | //
|
54623 | // The following constants are related to IEEE 754 limits.
|
54624 | //
|
54625 | var startdenom = Math.pow(width, chunks),
|
54626 | significance = Math.pow(2, digits),
|
54627 | overflow = significance * 2,
|
54628 | mask = width - 1;
|
54629 |
|
54630 |
|
54631 | var oldRandom = Math.random;
|
54632 |
|
54633 | //
|
54634 | // seedrandom()
|
54635 | // This is the seedrandom function described above.
|
54636 | //
|
54637 | module.exports = function(seed, options) {
|
54638 | if (options && options.global === true) {
|
54639 | options.global = false;
|
54640 | Math.random = module.exports(seed, options);
|
54641 | options.global = true;
|
54642 | return Math.random;
|
54643 | }
|
54644 | var use_entropy = (options && options.entropy) || false;
|
54645 | var key = [];
|
54646 |
|
54647 | // Flatten the seed string or build one from local entropy if needed.
|
54648 | var shortseed = mixkey(flatten(
|
54649 | use_entropy ? [seed, tostring(pool)] :
|
54650 | 0 in arguments ? seed : autoseed(), 3), key);
|
54651 |
|
54652 | // Use the seed to initialize an ARC4 generator.
|
54653 | var arc4 = new ARC4(key);
|
54654 |
|
54655 | // Mix the randomness into accumulated entropy.
|
54656 | mixkey(tostring(arc4.S), pool);
|
54657 |
|
54658 | // Override Math.random
|
54659 |
|
54660 | // This function returns a random double in [0, 1) that contains
|
54661 | // randomness in every bit of the mantissa of the IEEE 754 value.
|
54662 |
|
54663 | return function() { // Closure to return a random double:
|
54664 | var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48
|
54665 | d = startdenom, // and denominator d = 2 ^ 48.
|
54666 | x = 0; // and no 'extra last byte'.
|
54667 | while (n < significance) { // Fill up all significant digits by
|
54668 | n = (n + x) * width; // shifting numerator and
|
54669 | d *= width; // denominator and generating a
|
54670 | x = arc4.g(1); // new least-significant-byte.
|
54671 | }
|
54672 | while (n >= overflow) { // To avoid rounding up, before adding
|
54673 | n /= 2; // last byte, shift everything
|
54674 | d /= 2; // right using integer Math until
|
54675 | x >>>= 1; // we have exactly the desired bits.
|
54676 | }
|
54677 | return (n + x) / d; // Form the number within [0, 1).
|
54678 | };
|
54679 | };
|
54680 |
|
54681 | module.exports.resetGlobal = function () {
|
54682 | Math.random = oldRandom;
|
54683 | };
|
54684 |
|
54685 | //
|
54686 | // ARC4
|
54687 | //
|
54688 | // An ARC4 implementation. The constructor takes a key in the form of
|
54689 | // an array of at most (width) integers that should be 0 <= x < (width).
|
54690 | //
|
54691 | // The g(count) method returns a pseudorandom integer that concatenates
|
54692 | // the next (count) outputs from ARC4. Its return value is a number x
|
54693 | // that is in the range 0 <= x < (width ^ count).
|
54694 | //
|
54695 | /** @constructor */
|
54696 | function ARC4(key) {
|
54697 | var t, keylen = key.length,
|
54698 | me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];
|
54699 |
|
54700 | // The empty key [] is treated as [0].
|
54701 | if (!keylen) { key = [keylen++]; }
|
54702 |
|
54703 | // Set up S using the standard key scheduling algorithm.
|
54704 | while (i < width) {
|
54705 | s[i] = i++;
|
54706 | }
|
54707 | for (i = 0; i < width; i++) {
|
54708 | s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];
|
54709 | s[j] = t;
|
54710 | }
|
54711 |
|
54712 | // The "g" method returns the next (count) outputs as one number.
|
54713 | (me.g = function(count) {
|
54714 | // Using instance members instead of closure state nearly doubles speed.
|
54715 | var t, r = 0,
|
54716 | i = me.i, j = me.j, s = me.S;
|
54717 | while (count--) {
|
54718 | t = s[i = mask & (i + 1)];
|
54719 | r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];
|
54720 | }
|
54721 | me.i = i; me.j = j;
|
54722 | return r;
|
54723 | // For robust unpredictability discard an initial batch of values.
|
54724 | // See http://www.rsa.com/rsalabs/node.asp?id=2009
|
54725 | })(width);
|
54726 | }
|
54727 |
|
54728 | //
|
54729 | // flatten()
|
54730 | // Converts an object tree to nested arrays of strings.
|
54731 | //
|
54732 | function flatten(obj, depth) {
|
54733 | var result = [], typ = (typeof obj)[0], prop;
|
54734 | if (depth && typ == 'o') {
|
54735 | for (prop in obj) {
|
54736 | try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
|
54737 | }
|
54738 | }
|
54739 | return (result.length ? result : typ == 's' ? obj : obj + '\0');
|
54740 | }
|
54741 |
|
54742 | //
|
54743 | // mixkey()
|
54744 | // Mixes a string seed into a key that is an array of integers, and
|
54745 | // returns a shortened string seed that is equivalent to the result key.
|
54746 | //
|
54747 | function mixkey(seed, key) {
|
54748 | var stringseed = seed + '', smear, j = 0;
|
54749 | while (j < stringseed.length) {
|
54750 | key[mask & j] =
|
54751 | mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));
|
54752 | }
|
54753 | return tostring(key);
|
54754 | }
|
54755 |
|
54756 | //
|
54757 | // autoseed()
|
54758 | // Returns an object for autoseeding, using window.crypto if available.
|
54759 | //
|
54760 | /** @param {Uint8Array=} seed */
|
54761 | function autoseed(seed) {
|
54762 | try {
|
54763 | GLOBAL.crypto.getRandomValues(seed = new Uint8Array(width));
|
54764 | return tostring(seed);
|
54765 | } catch (e) {
|
54766 | return [+new Date, GLOBAL, GLOBAL.navigator && GLOBAL.navigator.plugins,
|
54767 | GLOBAL.screen, tostring(pool)];
|
54768 | }
|
54769 | }
|
54770 |
|
54771 | //
|
54772 | // tostring()
|
54773 | // Converts an array of charcodes to a string
|
54774 | //
|
54775 | function tostring(a) {
|
54776 | return String.fromCharCode.apply(0, a);
|
54777 | }
|
54778 |
|
54779 | //
|
54780 | // When seedrandom.js is loaded, we immediately mix a few bits
|
54781 | // from the built-in RNG into the entropy pool. Because we do
|
54782 | // not want to intefere with determinstic PRNG state later,
|
54783 | // seedrandom will not call Math.random on its own again after
|
54784 | // initialization.
|
54785 | //
|
54786 | mixkey(Math.random(), pool);
|
54787 |
|
54788 | /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(300)))
|
54789 |
|
54790 | /***/ }),
|
54791 | /* 300 */
|
54792 | /***/ (function(module, exports) {
|
54793 |
|
54794 | var g;
|
54795 |
|
54796 | // This works in non-strict mode
|
54797 | g = (function() {
|
54798 | return this;
|
54799 | })();
|
54800 |
|
54801 | try {
|
54802 | // This works if eval is allowed (see CSP)
|
54803 | g = g || new Function("return this")();
|
54804 | } catch (e) {
|
54805 | // This works if the window reference is available
|
54806 | if (typeof window === "object") g = window;
|
54807 | }
|
54808 |
|
54809 | // g can still be undefined, but nothing to do about it...
|
54810 | // We return undefined, instead of nothing here, so it's
|
54811 | // easier to handle this case. if(!global) { ...}
|
54812 |
|
54813 | module.exports = g;
|
54814 |
|
54815 |
|
54816 | /***/ }),
|
54817 | /* 301 */
|
54818 | /***/ (function(module, exports, __webpack_require__) {
|
54819 |
|
54820 | "use strict";
|
54821 |
|
54822 |
|
54823 | function factory(type, config, load, typed) {
|
54824 | var distribution = load(__webpack_require__(100));
|
54825 | /**
|
54826 | * Return a random number larger or equal to `min` and smaller than `max`
|
54827 | * using a uniform distribution.
|
54828 | *
|
54829 | * Syntax:
|
54830 | *
|
54831 | * math.random() // generate a random number between 0 and 1
|
54832 | * math.random(max) // generate a random number between 0 and max
|
54833 | * math.random(min, max) // generate a random number between min and max
|
54834 | * math.random(size) // generate a matrix with random numbers between 0 and 1
|
54835 | * math.random(size, max) // generate a matrix with random numbers between 0 and max
|
54836 | * math.random(size, min, max) // generate a matrix with random numbers between min and max
|
54837 | *
|
54838 | * Examples:
|
54839 | *
|
54840 | * math.random() // returns a random number between 0 and 1
|
54841 | * math.random(100) // returns a random number between 0 and 100
|
54842 | * math.random(30, 40) // returns a random number between 30 and 40
|
54843 | * math.random([2, 3]) // returns a 2x3 matrix with random numbers between 0 and 1
|
54844 | *
|
54845 | * See also:
|
54846 | *
|
54847 | * randomInt, pickRandom
|
54848 | *
|
54849 | * @param {Array | Matrix} [size] If provided, an array or matrix with given
|
54850 | * size and filled with random values is returned
|
54851 | * @param {number} [min] Minimum boundary for the random value, included
|
54852 | * @param {number} [max] Maximum boundary for the random value, excluded
|
54853 | * @return {number | Array | Matrix} A random number
|
54854 | */
|
54855 | // TODO: rework random to a typed-function
|
54856 |
|
54857 | var random = distribution('uniform').random;
|
54858 | random.toTex = undefined; // use default template
|
54859 |
|
54860 | return random;
|
54861 | }
|
54862 |
|
54863 | exports.name = 'random';
|
54864 | exports.factory = factory;
|
54865 |
|
54866 | /***/ }),
|
54867 | /* 302 */
|
54868 | /***/ (function(module, exports, __webpack_require__) {
|
54869 |
|
54870 | "use strict";
|
54871 |
|
54872 |
|
54873 | function factory(type, config, load, typed) {
|
54874 | var distribution = load(__webpack_require__(100));
|
54875 | /**
|
54876 | * Return a random integer number larger or equal to `min` and smaller than `max`
|
54877 | * using a uniform distribution.
|
54878 | *
|
54879 | * Syntax:
|
54880 | *
|
54881 | * math.randomInt(max) // generate a random integer between 0 and max
|
54882 | * math.randomInt(min, max) // generate a random integer between min and max
|
54883 | * math.randomInt(size) // generate a matrix with random integer between 0 and 1
|
54884 | * math.randomInt(size, max) // generate a matrix with random integer between 0 and max
|
54885 | * math.randomInt(size, min, max) // generate a matrix with random integer between min and max
|
54886 | *
|
54887 | * Examples:
|
54888 | *
|
54889 | * math.randomInt(100) // returns a random integer between 0 and 100
|
54890 | * math.randomInt(30, 40) // returns a random integer between 30 and 40
|
54891 | * math.randomInt([2, 3]) // returns a 2x3 matrix with random integers between 0 and 1
|
54892 | *
|
54893 | * See also:
|
54894 | *
|
54895 | * random, pickRandom
|
54896 | *
|
54897 | * @param {Array | Matrix} [size] If provided, an array or matrix with given
|
54898 | * size and filled with random values is returned
|
54899 | * @param {number} [min] Minimum boundary for the random value, included
|
54900 | * @param {number} [max] Maximum boundary for the random value, excluded
|
54901 | * @return {number | Array | Matrix} A random integer value
|
54902 | */
|
54903 | // TODO: rework randomInt to a typed-function
|
54904 |
|
54905 | var randomInt = distribution('uniform').randomInt;
|
54906 | randomInt.toTex = undefined; // use default template
|
54907 |
|
54908 | return randomInt;
|
54909 | }
|
54910 |
|
54911 | exports.name = 'randomInt';
|
54912 | exports.factory = factory;
|
54913 |
|
54914 | /***/ }),
|
54915 | /* 303 */
|
54916 | /***/ (function(module, exports, __webpack_require__) {
|
54917 |
|
54918 | "use strict";
|
54919 |
|
54920 |
|
54921 | module.exports = [__webpack_require__(55), __webpack_require__(30), __webpack_require__(147), __webpack_require__(304), __webpack_require__(51), __webpack_require__(305), __webpack_require__(33), __webpack_require__(89), __webpack_require__(38), __webpack_require__(144), __webpack_require__(130)];
|
54922 |
|
54923 | /***/ }),
|
54924 | /* 304 */
|
54925 | /***/ (function(module, exports, __webpack_require__) {
|
54926 |
|
54927 | "use strict";
|
54928 |
|
54929 |
|
54930 | function factory(type, config, load, typed) {
|
54931 | var equal = load(__webpack_require__(51));
|
54932 | /**
|
54933 | * Test element wise whether two matrices are equal.
|
54934 | * The function accepts both matrices and scalar values.
|
54935 | *
|
54936 | * Strings are compared by their numerical value.
|
54937 | *
|
54938 | * Syntax:
|
54939 | *
|
54940 | * math.deepEqual(x, y)
|
54941 | *
|
54942 | * Examples:
|
54943 | *
|
54944 | * math.deepEqual(2, 4) // returns false
|
54945 | *
|
54946 | * a = [2, 5, 1]
|
54947 | * b = [2, 7, 1]
|
54948 | *
|
54949 | * math.deepEqual(a, b) // returns false
|
54950 | * math.equal(a, b) // returns [true, false, true]
|
54951 | *
|
54952 | * See also:
|
54953 | *
|
54954 | * equal, unequal
|
54955 | *
|
54956 | * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x First matrix to compare
|
54957 | * @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} y Second matrix to compare
|
54958 | * @return {number | BigNumber | Fraction | Complex | Unit | Array | Matrix}
|
54959 | * Returns true when the input matrices have the same size and each of their elements is equal.
|
54960 | */
|
54961 |
|
54962 | var deepEqual = typed('deepEqual', {
|
54963 | 'any, any': function anyAny(x, y) {
|
54964 | return _deepEqual(x.valueOf(), y.valueOf());
|
54965 | }
|
54966 | });
|
54967 | deepEqual.toTex = undefined; // use default template
|
54968 |
|
54969 | return deepEqual;
|
54970 | /**
|
54971 | * Test whether two arrays have the same size and all elements are equal
|
54972 | * @param {Array | *} x
|
54973 | * @param {Array | *} y
|
54974 | * @return {boolean} Returns true if both arrays are deep equal
|
54975 | */
|
54976 |
|
54977 | function _deepEqual(x, y) {
|
54978 | if (Array.isArray(x)) {
|
54979 | if (Array.isArray(y)) {
|
54980 | var len = x.length;
|
54981 |
|
54982 | if (len !== y.length) {
|
54983 | return false;
|
54984 | }
|
54985 |
|
54986 | for (var i = 0; i < len; i++) {
|
54987 | if (!_deepEqual(x[i], y[i])) {
|
54988 | return false;
|
54989 | }
|
54990 | }
|
54991 |
|
54992 | return true;
|
54993 | } else {
|
54994 | return false;
|
54995 | }
|
54996 | } else {
|
54997 | if (Array.isArray(y)) {
|
54998 | return false;
|
54999 | } else {
|
55000 | return equal(x, y);
|
55001 | }
|
55002 | }
|
55003 | }
|
55004 | }
|
55005 |
|
55006 | exports.name = 'deepEqual';
|
55007 | exports.factory = factory;
|
55008 |
|
55009 | /***/ }),
|
55010 | /* 305 */
|
55011 | /***/ (function(module, exports, __webpack_require__) {
|
55012 |
|
55013 | "use strict";
|
55014 |
|
55015 |
|
55016 | function factory(type, config, load, typed) {
|
55017 | var compareText = load(__webpack_require__(147));
|
55018 | var isZero = load(__webpack_require__(60));
|
55019 | /**
|
55020 | * Check equality of two strings. Comparison is case sensitive.
|
55021 | *
|
55022 | * For matrices, the function is evaluated element wise.
|
55023 | *
|
55024 | * Syntax:
|
55025 | *
|
55026 | * math.equalText(x, y)
|
55027 | *
|
55028 | * Examples:
|
55029 | *
|
55030 | * math.equalText('Hello', 'Hello') // returns true
|
55031 | * math.equalText('a', 'A') // returns false
|
55032 | * math.equal('2e3', '2000') // returns true
|
55033 | * math.equalText('2e3', '2000') // returns false
|
55034 | *
|
55035 | * math.equalText('B', ['A', 'B', 'C']) // returns [false, true, false]
|
55036 | *
|
55037 | * See also:
|
55038 | *
|
55039 | * equal, compareText, compare, compareNatural
|
55040 | *
|
55041 | * @param {string | Array | DenseMatrix} x First string to compare
|
55042 | * @param {string | Array | DenseMatrix} y Second string to compare
|
55043 | * @return {number | Array | DenseMatrix} Returns true if the values are equal, and false if not.
|
55044 | */
|
55045 |
|
55046 | var equalText = typed('equalText', {
|
55047 | 'any, any': function anyAny(x, y) {
|
55048 | return isZero(compareText(x, y));
|
55049 | }
|
55050 | });
|
55051 | equalText.toTex = undefined; // use default template
|
55052 |
|
55053 | return equalText;
|
55054 | }
|
55055 |
|
55056 | exports.name = 'equalText';
|
55057 | exports.factory = factory;
|
55058 |
|
55059 | /***/ }),
|
55060 | /* 306 */
|
55061 | /***/ (function(module, exports, __webpack_require__) {
|
55062 |
|
55063 | "use strict";
|
55064 |
|
55065 |
|
55066 | module.exports = [__webpack_require__(307), __webpack_require__(148), __webpack_require__(308), __webpack_require__(149), __webpack_require__(309), __webpack_require__(310), __webpack_require__(311), __webpack_require__(312), __webpack_require__(150), __webpack_require__(313)];
|
55067 |
|
55068 | /***/ }),
|
55069 | /* 307 */
|
55070 | /***/ (function(module, exports, __webpack_require__) {
|
55071 |
|
55072 | "use strict";
|
55073 |
|
55074 |
|
55075 | var flatten = __webpack_require__(2).flatten;
|
55076 |
|
55077 | function factory(type, config, load, typed) {
|
55078 | var MatrixIndex = load(__webpack_require__(24));
|
55079 | var DenseMatrix = load(__webpack_require__(49));
|
55080 | var size = load(__webpack_require__(28));
|
55081 | var subset = load(__webpack_require__(23));
|
55082 | var compareNatural = load(__webpack_require__(30));
|
55083 | /**
|
55084 | * Create the cartesian product of two (multi)sets.
|
55085 | * Multi-dimension arrays will be converted to single-dimension arrays before the operation.
|
55086 | *
|
55087 | * Syntax:
|
55088 | *
|
55089 | * math.setCartesian(set1, set2)
|
55090 | *
|
55091 | * Examples:
|
55092 | *
|
55093 | * math.setCartesian([1, 2], [3, 4]) // returns [[1, 3], [1, 4], [2, 3], [2, 4]]
|
55094 | *
|
55095 | * See also:
|
55096 | *
|
55097 | * setUnion, setIntersect, setDifference, setPowerset
|
55098 | *
|
55099 | * @param {Array | Matrix} a1 A (multi)set
|
55100 | * @param {Array | Matrix} a2 A (multi)set
|
55101 | * @return {Array | Matrix} The cartesian product of two (multi)sets
|
55102 | */
|
55103 |
|
55104 | var setCartesian = typed('setCartesian', {
|
55105 | 'Array | Matrix, Array | Matrix': function ArrayMatrixArrayMatrix(a1, a2) {
|
55106 | var result = [];
|
55107 |
|
55108 | if (subset(size(a1), new MatrixIndex(0)) !== 0 && subset(size(a2), new MatrixIndex(0)) !== 0) {
|
55109 | // if any of them is empty, return empty
|
55110 | var b1 = flatten(Array.isArray(a1) ? a1 : a1.toArray()).sort(compareNatural);
|
55111 | var b2 = flatten(Array.isArray(a2) ? a2 : a2.toArray()).sort(compareNatural);
|
55112 | result = [];
|
55113 |
|
55114 | for (var i = 0; i < b1.length; i++) {
|
55115 | for (var j = 0; j < b2.length; j++) {
|
55116 | result.push([b1[i], b2[j]]);
|
55117 | }
|
55118 | }
|
55119 | } // return an array, if both inputs were arrays
|
55120 |
|
55121 |
|
55122 | if (Array.isArray(a1) && Array.isArray(a2)) {
|
55123 | return result;
|
55124 | } // return a matrix otherwise
|
55125 |
|
55126 |
|
55127 | return new DenseMatrix(result);
|
55128 | }
|
55129 | });
|
55130 | return setCartesian;
|
55131 | }
|
55132 |
|
55133 | exports.name = 'setCartesian';
|
55134 | exports.factory = factory;
|
55135 |
|
55136 | /***/ }),
|
55137 | /* 308 */
|
55138 | /***/ (function(module, exports, __webpack_require__) {
|
55139 |
|
55140 | "use strict";
|
55141 |
|
55142 |
|
55143 | var flatten = __webpack_require__(2).flatten;
|
55144 |
|
55145 | function factory(type, config, load, typed) {
|
55146 | var MatrixIndex = load(__webpack_require__(24));
|
55147 | var DenseMatrix = load(__webpack_require__(49));
|
55148 | var size = load(__webpack_require__(28));
|
55149 | var subset = load(__webpack_require__(23));
|
55150 | var compareNatural = load(__webpack_require__(30));
|
55151 | /**
|
55152 | * Collect the distinct elements of a multiset.
|
55153 | * A multi-dimension array will be converted to a single-dimension array before the operation.
|
55154 | *
|
55155 | * Syntax:
|
55156 | *
|
55157 | * math.setDistinct(set)
|
55158 | *
|
55159 | * Examples:
|
55160 | *
|
55161 | * math.setDistinct([1, 1, 1, 2, 2, 3]) // returns [1, 2, 3]
|
55162 | *
|
55163 | * See also:
|
55164 | *
|
55165 | * setMultiplicity
|
55166 | *
|
55167 | * @param {Array | Matrix} a A multiset
|
55168 | * @return {Array | Matrix} A set containing the distinc elements of the multiset
|
55169 | */
|
55170 |
|
55171 | var setDistinct = typed('setDistinct', {
|
55172 | 'Array | Matrix': function ArrayMatrix(a) {
|
55173 | var result;
|
55174 |
|
55175 | if (subset(size(a), new MatrixIndex(0)) === 0) {
|
55176 | // if empty, return empty
|
55177 | result = [];
|
55178 | } else {
|
55179 | var b = flatten(Array.isArray(a) ? a : a.toArray()).sort(compareNatural);
|
55180 | result = [];
|
55181 | result.push(b[0]);
|
55182 |
|
55183 | for (var i = 1; i < b.length; i++) {
|
55184 | if (compareNatural(b[i], b[i - 1]) !== 0) {
|
55185 | result.push(b[i]);
|
55186 | }
|
55187 | }
|
55188 | } // return an array, if the input was an array
|
55189 |
|
55190 |
|
55191 | if (Array.isArray(a)) {
|
55192 | return result;
|
55193 | } // return a matrix otherwise
|
55194 |
|
55195 |
|
55196 | return new DenseMatrix(result);
|
55197 | }
|
55198 | });
|
55199 | return setDistinct;
|
55200 | }
|
55201 |
|
55202 | exports.name = 'setDistinct';
|
55203 | exports.factory = factory;
|
55204 |
|
55205 | /***/ }),
|
55206 | /* 309 */
|
55207 | /***/ (function(module, exports, __webpack_require__) {
|
55208 |
|
55209 | "use strict";
|
55210 |
|
55211 |
|
55212 | var flatten = __webpack_require__(2).flatten;
|
55213 |
|
55214 | var identify = __webpack_require__(2).identify;
|
55215 |
|
55216 | function factory(type, config, load, typed) {
|
55217 | var MatrixIndex = load(__webpack_require__(24));
|
55218 | var size = load(__webpack_require__(28));
|
55219 | var subset = load(__webpack_require__(23));
|
55220 | var compareNatural = load(__webpack_require__(30));
|
55221 | /**
|
55222 | * Check whether a (multi)set is a subset of another (multi)set. (Every element of set1 is the element of set2.)
|
55223 | * Multi-dimension arrays will be converted to single-dimension arrays before the operation.
|
55224 | *
|
55225 | * Syntax:
|
55226 | *
|
55227 | * math.setIsSubset(set1, set2)
|
55228 | *
|
55229 | * Examples:
|
55230 | *
|
55231 | * math.setIsSubset([1, 2], [3, 4, 5, 6]) // returns false
|
55232 | * math.setIsSubset([3, 4], [3, 4, 5, 6]) // returns true
|
55233 | *
|
55234 | * See also:
|
55235 | *
|
55236 | * setUnion, setIntersect, setDifference
|
55237 | *
|
55238 | * @param {Array | Matrix} a1 A (multi)set
|
55239 | * @param {Array | Matrix} a2 A (multi)set
|
55240 | * @return {boolean} true | false
|
55241 | */
|
55242 |
|
55243 | var setIsSubset = typed('setIsSubset', {
|
55244 | 'Array | Matrix, Array | Matrix': function ArrayMatrixArrayMatrix(a1, a2) {
|
55245 | if (subset(size(a1), new MatrixIndex(0)) === 0) {
|
55246 | // empty is a subset of anything
|
55247 | return true;
|
55248 | } else if (subset(size(a2), new MatrixIndex(0)) === 0) {
|
55249 | // anything is not a subset of empty
|
55250 | return false;
|
55251 | }
|
55252 |
|
55253 | var b1 = identify(flatten(Array.isArray(a1) ? a1 : a1.toArray()).sort(compareNatural));
|
55254 | var b2 = identify(flatten(Array.isArray(a2) ? a2 : a2.toArray()).sort(compareNatural));
|
55255 | var inb2;
|
55256 |
|
55257 | for (var i = 0; i < b1.length; i++) {
|
55258 | inb2 = false;
|
55259 |
|
55260 | for (var j = 0; j < b2.length; j++) {
|
55261 | if (compareNatural(b1[i].value, b2[j].value) === 0 && b1[i].identifier === b2[j].identifier) {
|
55262 | // the identifier is always a decimal int
|
55263 | inb2 = true;
|
55264 | break;
|
55265 | }
|
55266 | }
|
55267 |
|
55268 | if (inb2 === false) {
|
55269 | return false;
|
55270 | }
|
55271 | }
|
55272 |
|
55273 | return true;
|
55274 | }
|
55275 | });
|
55276 | return setIsSubset;
|
55277 | }
|
55278 |
|
55279 | exports.name = 'setIsSubset';
|
55280 | exports.factory = factory;
|
55281 |
|
55282 | /***/ }),
|
55283 | /* 310 */
|
55284 | /***/ (function(module, exports, __webpack_require__) {
|
55285 |
|
55286 | "use strict";
|
55287 |
|
55288 |
|
55289 | var flatten = __webpack_require__(2).flatten;
|
55290 |
|
55291 | function factory(type, config, load, typed) {
|
55292 | var compareNatural = load(__webpack_require__(30));
|
55293 | var MatrixIndex = load(__webpack_require__(24));
|
55294 | var size = load(__webpack_require__(28));
|
55295 | var subset = load(__webpack_require__(23));
|
55296 | /**
|
55297 | * Count the multiplicity of an element in a multiset.
|
55298 | * A multi-dimension array will be converted to a single-dimension array before the operation.
|
55299 | *
|
55300 | * Syntax:
|
55301 | *
|
55302 | * math.setMultiplicity(element, set)
|
55303 | *
|
55304 | * Examples:
|
55305 | *
|
55306 | * math.setMultiplicity(1, [1, 2, 2, 4]) // returns 1
|
55307 | * math.setMultiplicity(2, [1, 2, 2, 4]) // returns 2
|
55308 | *
|
55309 | * See also:
|
55310 | *
|
55311 | * setDistinct, setSize
|
55312 | *
|
55313 | * @param {number | BigNumber | Fraction | Complex} e An element in the multiset
|
55314 | * @param {Array | Matrix} a A multiset
|
55315 | * @return {number} The number of how many times the multiset contains the element
|
55316 | */
|
55317 |
|
55318 | var setMultiplicity = typed('setMultiplicity', {
|
55319 | 'number | BigNumber | Fraction | Complex, Array | Matrix': function numberBigNumberFractionComplexArrayMatrix(e, a) {
|
55320 | if (subset(size(a), new MatrixIndex(0)) === 0) {
|
55321 | // if empty, return 0
|
55322 | return 0;
|
55323 | }
|
55324 |
|
55325 | var b = flatten(Array.isArray(a) ? a : a.toArray());
|
55326 | var count = 0;
|
55327 |
|
55328 | for (var i = 0; i < b.length; i++) {
|
55329 | if (compareNatural(b[i], e) === 0) {
|
55330 | count++;
|
55331 | }
|
55332 | }
|
55333 |
|
55334 | return count;
|
55335 | }
|
55336 | });
|
55337 | return setMultiplicity;
|
55338 | }
|
55339 |
|
55340 | exports.name = 'setMultiplicity';
|
55341 | exports.factory = factory;
|
55342 |
|
55343 | /***/ }),
|
55344 | /* 311 */
|
55345 | /***/ (function(module, exports, __webpack_require__) {
|
55346 |
|
55347 | "use strict";
|
55348 |
|
55349 |
|
55350 | var flatten = __webpack_require__(2).flatten;
|
55351 |
|
55352 | function factory(type, config, load, typed) {
|
55353 | var MatrixIndex = load(__webpack_require__(24));
|
55354 | var size = load(__webpack_require__(28));
|
55355 | var subset = load(__webpack_require__(23));
|
55356 | var compareNatural = load(__webpack_require__(30));
|
55357 | /**
|
55358 | * Create the powerset of a (multi)set. (The powerset contains very possible subsets of a (multi)set.)
|
55359 | * A multi-dimension array will be converted to a single-dimension array before the operation.
|
55360 | *
|
55361 | * Syntax:
|
55362 | *
|
55363 | * math.setPowerset(set)
|
55364 | *
|
55365 | * Examples:
|
55366 | *
|
55367 | * math.setPowerset([1, 2, 3]) // returns [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
|
55368 | *
|
55369 | * See also:
|
55370 | *
|
55371 | * setCartesian
|
55372 | *
|
55373 | * @param {Array | Matrix} a A (multi)set
|
55374 | * @return {Array} The powerset of the (multi)set
|
55375 | */
|
55376 |
|
55377 | var setPowerset = typed('setPowerset', {
|
55378 | 'Array | Matrix': function ArrayMatrix(a) {
|
55379 | if (subset(size(a), new MatrixIndex(0)) === 0) {
|
55380 | // if empty, return empty
|
55381 | return [];
|
55382 | }
|
55383 |
|
55384 | var b = flatten(Array.isArray(a) ? a : a.toArray()).sort(compareNatural);
|
55385 | var result = [];
|
55386 | var number = 0;
|
55387 |
|
55388 | while (number.toString(2).length <= b.length) {
|
55389 | result.push(_subset(b, number.toString(2).split('').reverse()));
|
55390 | number++;
|
55391 | } // can not return a matrix, because of the different size of the subarrays
|
55392 |
|
55393 |
|
55394 | return _sort(result);
|
55395 | }
|
55396 | });
|
55397 | return setPowerset; // create subset
|
55398 |
|
55399 | function _subset(array, bitarray) {
|
55400 | var result = [];
|
55401 |
|
55402 | for (var i = 0; i < bitarray.length; i++) {
|
55403 | if (bitarray[i] === '1') {
|
55404 | result.push(array[i]);
|
55405 | }
|
55406 | }
|
55407 |
|
55408 | return result;
|
55409 | } // sort subsests by length
|
55410 |
|
55411 |
|
55412 | function _sort(array) {
|
55413 | var temp = [];
|
55414 |
|
55415 | for (var i = array.length - 1; i > 0; i--) {
|
55416 | for (var j = 0; j < i; j++) {
|
55417 | if (array[j].length > array[j + 1].length) {
|
55418 | temp = array[j];
|
55419 | array[j] = array[j + 1];
|
55420 | array[j + 1] = temp;
|
55421 | }
|
55422 | }
|
55423 | }
|
55424 |
|
55425 | return array;
|
55426 | }
|
55427 | }
|
55428 |
|
55429 | exports.name = 'setPowerset';
|
55430 | exports.factory = factory;
|
55431 |
|
55432 | /***/ }),
|
55433 | /* 312 */
|
55434 | /***/ (function(module, exports, __webpack_require__) {
|
55435 |
|
55436 | "use strict";
|
55437 |
|
55438 |
|
55439 | var flatten = __webpack_require__(2).flatten;
|
55440 |
|
55441 | function factory(type, config, load, typed) {
|
55442 | var compareNatural = load(__webpack_require__(30));
|
55443 | /**
|
55444 | * Count the number of elements of a (multi)set. When a second parameter is 'true', count only the unique values.
|
55445 | * A multi-dimension array will be converted to a single-dimension array before the operation.
|
55446 | *
|
55447 | * Syntax:
|
55448 | *
|
55449 | * math.setSize(set)
|
55450 | * math.setSize(set, unique)
|
55451 | *
|
55452 | * Examples:
|
55453 | *
|
55454 | * math.setSize([1, 2, 2, 4]) // returns 4
|
55455 | * math.setSize([1, 2, 2, 4], true) // returns 3
|
55456 | *
|
55457 | * See also:
|
55458 | *
|
55459 | * setUnion, setIntersect, setDifference
|
55460 | *
|
55461 | * @param {Array | Matrix} a A multiset
|
55462 | * @return {number} The number of elements of the (multi)set
|
55463 | */
|
55464 |
|
55465 | var setSize = typed('setSize', {
|
55466 | 'Array | Matrix': function ArrayMatrix(a) {
|
55467 | return Array.isArray(a) ? flatten(a).length : flatten(a.toArray()).length;
|
55468 | },
|
55469 | 'Array | Matrix, boolean': function ArrayMatrixBoolean(a, unique) {
|
55470 | if (unique === false || a.length === 0) {
|
55471 | return Array.isArray(a) ? flatten(a).length : flatten(a.toArray()).length;
|
55472 | } else {
|
55473 | var b = flatten(Array.isArray(a) ? a : a.toArray()).sort(compareNatural);
|
55474 | var count = 1;
|
55475 |
|
55476 | for (var i = 1; i < b.length; i++) {
|
55477 | if (compareNatural(b[i], b[i - 1]) !== 0) {
|
55478 | count++;
|
55479 | }
|
55480 | }
|
55481 |
|
55482 | return count;
|
55483 | }
|
55484 | }
|
55485 | });
|
55486 | return setSize;
|
55487 | }
|
55488 |
|
55489 | exports.name = 'setSize';
|
55490 | exports.factory = factory;
|
55491 |
|
55492 | /***/ }),
|
55493 | /* 313 */
|
55494 | /***/ (function(module, exports, __webpack_require__) {
|
55495 |
|
55496 | "use strict";
|
55497 |
|
55498 |
|
55499 | var flatten = __webpack_require__(2).flatten;
|
55500 |
|
55501 | function factory(type, config, load, typed) {
|
55502 | var MatrixIndex = load(__webpack_require__(24));
|
55503 | var concat = load(__webpack_require__(78));
|
55504 | var size = load(__webpack_require__(28));
|
55505 | var subset = load(__webpack_require__(23));
|
55506 | var setIntersect = load(__webpack_require__(149));
|
55507 | var setSymDifference = load(__webpack_require__(150));
|
55508 | /**
|
55509 | * Create the union of two (multi)sets.
|
55510 | * Multi-dimension arrays will be converted to single-dimension arrays before the operation.
|
55511 | *
|
55512 | * Syntax:
|
55513 | *
|
55514 | * math.setUnion(set1, set2)
|
55515 | *
|
55516 | * Examples:
|
55517 | *
|
55518 | * math.setUnion([1, 2, 3, 4], [3, 4, 5, 6]) // returns [1, 2, 3, 4, 5, 6]
|
55519 | * math.setUnion([[1, 2], [3, 4]], [[3, 4], [5, 6]]) // returns [1, 2, 3, 4, 5, 6]
|
55520 | *
|
55521 | * See also:
|
55522 | *
|
55523 | * setIntersect, setDifference
|
55524 | *
|
55525 | * @param {Array | Matrix} a1 A (multi)set
|
55526 | * @param {Array | Matrix} a2 A (multi)set
|
55527 | * @return {Array | Matrix} The union of two (multi)sets
|
55528 | */
|
55529 |
|
55530 | var setUnion = typed('setUnion', {
|
55531 | 'Array | Matrix, Array | Matrix': function ArrayMatrixArrayMatrix(a1, a2) {
|
55532 | if (subset(size(a1), new MatrixIndex(0)) === 0) {
|
55533 | // if any of them is empty, return the other one
|
55534 | return flatten(a2);
|
55535 | } else if (subset(size(a2), new MatrixIndex(0)) === 0) {
|
55536 | return flatten(a1);
|
55537 | }
|
55538 |
|
55539 | var b1 = flatten(a1);
|
55540 | var b2 = flatten(a2);
|
55541 | return concat(setSymDifference(b1, b2), setIntersect(b1, b2));
|
55542 | }
|
55543 | });
|
55544 | return setUnion;
|
55545 | }
|
55546 |
|
55547 | exports.name = 'setUnion';
|
55548 | exports.factory = factory;
|
55549 |
|
55550 | /***/ }),
|
55551 | /* 314 */
|
55552 | /***/ (function(module, exports, __webpack_require__) {
|
55553 |
|
55554 | "use strict";
|
55555 |
|
55556 |
|
55557 | module.exports = [__webpack_require__(315)];
|
55558 |
|
55559 | /***/ }),
|
55560 | /* 315 */
|
55561 | /***/ (function(module, exports, __webpack_require__) {
|
55562 |
|
55563 | "use strict";
|
55564 |
|
55565 |
|
55566 | var deepMap = __webpack_require__(1);
|
55567 |
|
55568 | var sign = __webpack_require__(3).sign;
|
55569 |
|
55570 | function factory(type, config, load, typed) {
|
55571 | /**
|
55572 | * Compute the erf function of a value using a rational Chebyshev
|
55573 | * approximations for different intervals of x.
|
55574 | *
|
55575 | * This is a translation of W. J. Cody's Fortran implementation from 1987
|
55576 | * ( https://www.netlib.org/specfun/erf ). See the AMS publication
|
55577 | * "Rational Chebyshev Approximations for the Error Function" by W. J. Cody
|
55578 | * for an explanation of this process.
|
55579 | *
|
55580 | * For matrices, the function is evaluated element wise.
|
55581 | *
|
55582 | * Syntax:
|
55583 | *
|
55584 | * math.erf(x)
|
55585 | *
|
55586 | * Examples:
|
55587 | *
|
55588 | * math.erf(0.2) // returns 0.22270258921047847
|
55589 | * math.erf(-0.5) // returns -0.5204998778130465
|
55590 | * math.erf(4) // returns 0.9999999845827421
|
55591 | *
|
55592 | * @param {number | Array | Matrix} x A real number
|
55593 | * @return {number | Array | Matrix} The erf of `x`
|
55594 | */
|
55595 | var erf = typed('erf', {
|
55596 | 'number': function number(x) {
|
55597 | var y = Math.abs(x);
|
55598 |
|
55599 | if (y >= MAX_NUM) {
|
55600 | return sign(x);
|
55601 | }
|
55602 |
|
55603 | if (y <= THRESH) {
|
55604 | return sign(x) * erf1(y);
|
55605 | }
|
55606 |
|
55607 | if (y <= 4.0) {
|
55608 | return sign(x) * (1 - erfc2(y));
|
55609 | }
|
55610 |
|
55611 | return sign(x) * (1 - erfc3(y));
|
55612 | },
|
55613 | // TODO: Not sure if there's a way to guarantee some degree of accuracy here.
|
55614 | // Perhaps it would be best to set the precision of the number to that which
|
55615 | // is guaranteed by erf()
|
55616 | 'BigNumber': function BigNumber(n) {
|
55617 | return new type.BigNumber(erf(n.toNumber()));
|
55618 | },
|
55619 | 'Array | Matrix': function ArrayMatrix(n) {
|
55620 | return deepMap(n, erf);
|
55621 | } // TODO: For complex numbers, use the approximation for the Faddeeva function
|
55622 | // from "More Efficient Computation of the Complex Error Function" (AMS)
|
55623 |
|
55624 | });
|
55625 | /**
|
55626 | * Approximates the error function erf() for x <= 0.46875 using this function:
|
55627 | * n
|
55628 | * erf(x) = x * sum (p_j * x^(2j)) / (q_j * x^(2j))
|
55629 | * j=0
|
55630 | */
|
55631 |
|
55632 | function erf1(y) {
|
55633 | var ysq = y * y;
|
55634 | var xnum = P[0][4] * ysq;
|
55635 | var xden = ysq;
|
55636 | var i;
|
55637 |
|
55638 | for (i = 0; i < 3; i += 1) {
|
55639 | xnum = (xnum + P[0][i]) * ysq;
|
55640 | xden = (xden + Q[0][i]) * ysq;
|
55641 | }
|
55642 |
|
55643 | return y * (xnum + P[0][3]) / (xden + Q[0][3]);
|
55644 | }
|
55645 | /**
|
55646 | * Approximates the complement of the error function erfc() for
|
55647 | * 0.46875 <= x <= 4.0 using this function:
|
55648 | * n
|
55649 | * erfc(x) = e^(-x^2) * sum (p_j * x^j) / (q_j * x^j)
|
55650 | * j=0
|
55651 | */
|
55652 |
|
55653 |
|
55654 | function erfc2(y) {
|
55655 | var xnum = P[1][8] * y;
|
55656 | var xden = y;
|
55657 | var i;
|
55658 |
|
55659 | for (i = 0; i < 7; i += 1) {
|
55660 | xnum = (xnum + P[1][i]) * y;
|
55661 | xden = (xden + Q[1][i]) * y;
|
55662 | }
|
55663 |
|
55664 | var result = (xnum + P[1][7]) / (xden + Q[1][7]);
|
55665 | var ysq = parseInt(y * 16) / 16;
|
55666 | var del = (y - ysq) * (y + ysq);
|
55667 | return Math.exp(-ysq * ysq) * Math.exp(-del) * result;
|
55668 | }
|
55669 | /**
|
55670 | * Approximates the complement of the error function erfc() for x > 4.0 using
|
55671 | * this function:
|
55672 | *
|
55673 | * erfc(x) = (e^(-x^2) / x) * [ 1/sqrt(pi) +
|
55674 | * n
|
55675 | * 1/(x^2) * sum (p_j * x^(-2j)) / (q_j * x^(-2j)) ]
|
55676 | * j=0
|
55677 | */
|
55678 |
|
55679 |
|
55680 | function erfc3(y) {
|
55681 | var ysq = 1 / (y * y);
|
55682 | var xnum = P[2][5] * ysq;
|
55683 | var xden = ysq;
|
55684 | var i;
|
55685 |
|
55686 | for (i = 0; i < 4; i += 1) {
|
55687 | xnum = (xnum + P[2][i]) * ysq;
|
55688 | xden = (xden + Q[2][i]) * ysq;
|
55689 | }
|
55690 |
|
55691 | var result = ysq * (xnum + P[2][4]) / (xden + Q[2][4]);
|
55692 | result = (SQRPI - result) / y;
|
55693 | ysq = parseInt(y * 16) / 16;
|
55694 | var del = (y - ysq) * (y + ysq);
|
55695 | return Math.exp(-ysq * ysq) * Math.exp(-del) * result;
|
55696 | }
|
55697 |
|
55698 | erf.toTex = {
|
55699 | 1: "erf\\left(${args[0]}\\right)"
|
55700 | };
|
55701 | return erf;
|
55702 | }
|
55703 | /**
|
55704 | * Upper bound for the first approximation interval, 0 <= x <= THRESH
|
55705 | * @constant
|
55706 | */
|
55707 |
|
55708 |
|
55709 | var THRESH = 0.46875;
|
55710 | /**
|
55711 | * Constant used by W. J. Cody's Fortran77 implementation to denote sqrt(pi)
|
55712 | * @constant
|
55713 | */
|
55714 |
|
55715 | var SQRPI = 5.6418958354775628695e-1;
|
55716 | /**
|
55717 | * Coefficients for each term of the numerator sum (p_j) for each approximation
|
55718 | * interval (see W. J. Cody's paper for more details)
|
55719 | * @constant
|
55720 | */
|
55721 |
|
55722 | var P = [[3.16112374387056560e00, 1.13864154151050156e02, 3.77485237685302021e02, 3.20937758913846947e03, 1.85777706184603153e-1], [5.64188496988670089e-1, 8.88314979438837594e00, 6.61191906371416295e01, 2.98635138197400131e02, 8.81952221241769090e02, 1.71204761263407058e03, 2.05107837782607147e03, 1.23033935479799725e03, 2.15311535474403846e-8], [3.05326634961232344e-1, 3.60344899949804439e-1, 1.25781726111229246e-1, 1.60837851487422766e-2, 6.58749161529837803e-4, 1.63153871373020978e-2]];
|
55723 | /**
|
55724 | * Coefficients for each term of the denominator sum (q_j) for each approximation
|
55725 | * interval (see W. J. Cody's paper for more details)
|
55726 | * @constant
|
55727 | */
|
55728 |
|
55729 | var Q = [[2.36012909523441209e01, 2.44024637934444173e02, 1.28261652607737228e03, 2.84423683343917062e03], [1.57449261107098347e01, 1.17693950891312499e02, 5.37181101862009858e02, 1.62138957456669019e03, 3.29079923573345963e03, 4.36261909014324716e03, 3.43936767414372164e03, 1.23033935480374942e03], [2.56852019228982242e00, 1.87295284992346047e00, 5.27905102951428412e-1, 6.05183413124413191e-2, 2.33520497626869185e-3]];
|
55730 | /**
|
55731 | * Maximum/minimum safe numbers to input to erf() (in ES6+, this number is
|
55732 | * Number.[MAX|MIN]_SAFE_INTEGER). erf() for all numbers beyond this limit will
|
55733 | * return 1
|
55734 | */
|
55735 |
|
55736 | var MAX_NUM = Math.pow(2, 53);
|
55737 | exports.name = 'erf';
|
55738 | exports.factory = factory;
|
55739 |
|
55740 | /***/ }),
|
55741 | /* 316 */
|
55742 | /***/ (function(module, exports, __webpack_require__) {
|
55743 |
|
55744 | "use strict";
|
55745 |
|
55746 |
|
55747 | module.exports = [__webpack_require__(317), __webpack_require__(98), __webpack_require__(152), __webpack_require__(151), __webpack_require__(153), __webpack_require__(318), __webpack_require__(319), __webpack_require__(320), __webpack_require__(154), __webpack_require__(99), __webpack_require__(101)];
|
55748 |
|
55749 | /***/ }),
|
55750 | /* 317 */
|
55751 | /***/ (function(module, exports, __webpack_require__) {
|
55752 |
|
55753 | "use strict";
|
55754 |
|
55755 |
|
55756 | var flatten = __webpack_require__(2).flatten;
|
55757 |
|
55758 | function factory(type, config, load, typed) {
|
55759 | var abs = load(__webpack_require__(25));
|
55760 | var map = load(__webpack_require__(145));
|
55761 | var median = load(__webpack_require__(151));
|
55762 | var subtract = load(__webpack_require__(15));
|
55763 | var improveErrorMessage = load(__webpack_require__(40));
|
55764 | /**
|
55765 | * Compute the median absolute deviation of a matrix or a list with values.
|
55766 | * The median absolute deviation is defined as the median of the absolute
|
55767 | * deviations from the median.
|
55768 | *
|
55769 | * Syntax:
|
55770 | *
|
55771 | * math.mad(a, b, c, ...)
|
55772 | * math.mad(A)
|
55773 | *
|
55774 | * Examples:
|
55775 | *
|
55776 | * math.mad(10, 20, 30) // returns 10
|
55777 | * math.mad([1, 2, 3]) // returns 1
|
55778 | * math.mad([[1, 2, 3], [4, 5, 6]]) // returns 1.5
|
55779 | *
|
55780 | * See also:
|
55781 | *
|
55782 | * median, mean, std, abs
|
55783 | *
|
55784 | * @param {Array | Matrix} array
|
55785 | * A single matrix or multiple scalar values.
|
55786 | * @return {*} The median absolute deviation.
|
55787 | */
|
55788 |
|
55789 | var mad = typed('mad', {
|
55790 | // mad([a, b, c, d, ...])
|
55791 | 'Array | Matrix': _mad,
|
55792 | // mad(a, b, c, d, ...)
|
55793 | '...': function _(args) {
|
55794 | return _mad(args);
|
55795 | }
|
55796 | });
|
55797 | mad.toTex = undefined; // use default template
|
55798 |
|
55799 | return mad;
|
55800 |
|
55801 | function _mad(array) {
|
55802 | array = flatten(array.valueOf());
|
55803 |
|
55804 | if (array.length === 0) {
|
55805 | throw new Error('Cannot calculate median absolute deviation (mad) of an empty array');
|
55806 | }
|
55807 |
|
55808 | try {
|
55809 | var med = median(array);
|
55810 | return median(map(array, function (value) {
|
55811 | return abs(subtract(value, med));
|
55812 | }));
|
55813 | } catch (err) {
|
55814 | if (err instanceof TypeError && err.message.indexOf('median') !== -1) {
|
55815 | throw new TypeError(err.message.replace('median', 'mad'));
|
55816 | } else {
|
55817 | throw improveErrorMessage(err, 'mad');
|
55818 | }
|
55819 | }
|
55820 | }
|
55821 | }
|
55822 |
|
55823 | exports.name = 'mad';
|
55824 | exports.factory = factory;
|
55825 |
|
55826 | /***/ }),
|
55827 | /* 318 */
|
55828 | /***/ (function(module, exports, __webpack_require__) {
|
55829 |
|
55830 | "use strict";
|
55831 |
|
55832 |
|
55833 | var flatten = __webpack_require__(2).flatten;
|
55834 |
|
55835 | function factory(type, config, load, typed) {
|
55836 | var isNaN = load(__webpack_require__(79));
|
55837 | var isNumeric = load(__webpack_require__(52));
|
55838 | /**
|
55839 | * Computes the mode of a set of numbers or a list with values(numbers or characters).
|
55840 | * If there are more than one modes, it returns a list of those values.
|
55841 | *
|
55842 | * Syntax:
|
55843 | *
|
55844 | * math.mode(a, b, c, ...)
|
55845 | * math.mode(A)
|
55846 | *
|
55847 | * Examples:
|
55848 | *
|
55849 | * math.mode(2, 1, 4, 3, 1) // returns [1]
|
55850 | * math.mode([1, 2.7, 3.2, 4, 2.7]) // returns [2.7]
|
55851 | * math.mode(1, 4, 6, 1, 6) // returns [1, 6]
|
55852 | * math.mode('a','a','b','c') // returns ["a"]
|
55853 | * math.mode(1, 1.5, 'abc') // returns [1, 1.5, "abc"]
|
55854 | *
|
55855 | * See also:
|
55856 | *
|
55857 | * median,
|
55858 | * mean
|
55859 | *
|
55860 | * @param {... *} args A single matrix
|
55861 | * @return {*} The mode of all values
|
55862 | */
|
55863 |
|
55864 | var mode = typed('mode', {
|
55865 | 'Array | Matrix': _mode,
|
55866 | '...': function _(args) {
|
55867 | return _mode(args);
|
55868 | }
|
55869 | });
|
55870 | return mode;
|
55871 | /**
|
55872 | * Calculates the mode in an 1-dimensional array
|
55873 | * @param {Array} values
|
55874 | * @return {Array} mode
|
55875 | * @private
|
55876 | */
|
55877 |
|
55878 | function _mode(values) {
|
55879 | values = flatten(values.valueOf());
|
55880 | var num = values.length;
|
55881 |
|
55882 | if (num === 0) {
|
55883 | throw new Error('Cannot calculate mode of an empty array');
|
55884 | }
|
55885 |
|
55886 | var count = {};
|
55887 | var mode = [];
|
55888 | var max = 0;
|
55889 |
|
55890 | for (var i = 0; i < values.length; i++) {
|
55891 | var value = values[i];
|
55892 |
|
55893 | if (isNumeric(value) && isNaN(value)) {
|
55894 | throw new Error('Cannot calculate mode of an array containing NaN values');
|
55895 | }
|
55896 |
|
55897 | if (!(value in count)) {
|
55898 | count[value] = 0;
|
55899 | }
|
55900 |
|
55901 | count[value]++;
|
55902 |
|
55903 | if (count[value] === max) {
|
55904 | mode.push(value);
|
55905 | } else if (count[value] > max) {
|
55906 | max = count[value];
|
55907 | mode = [value];
|
55908 | }
|
55909 | }
|
55910 |
|
55911 | return mode;
|
55912 | }
|
55913 | }
|
55914 |
|
55915 | exports.name = 'mode';
|
55916 | exports.factory = factory;
|
55917 |
|
55918 | /***/ }),
|
55919 | /* 319 */
|
55920 | /***/ (function(module, exports, __webpack_require__) {
|
55921 |
|
55922 | "use strict";
|
55923 |
|
55924 |
|
55925 | var deepForEach = __webpack_require__(47);
|
55926 |
|
55927 | function factory(type, config, load, typed) {
|
55928 | var multiply = load(__webpack_require__(21));
|
55929 | var improveErrorMessage = load(__webpack_require__(40));
|
55930 | /**
|
55931 | * Compute the product of a matrix or a list with values.
|
55932 | * In case of a (multi dimensional) array or matrix, the sum of all
|
55933 | * elements will be calculated.
|
55934 | *
|
55935 | * Syntax:
|
55936 | *
|
55937 | * math.prod(a, b, c, ...)
|
55938 | * math.prod(A)
|
55939 | *
|
55940 | * Examples:
|
55941 | *
|
55942 | * math.multiply(2, 3) // returns 6
|
55943 | * math.prod(2, 3) // returns 6
|
55944 | * math.prod(2, 3, 4) // returns 24
|
55945 | * math.prod([2, 3, 4]) // returns 24
|
55946 | * math.prod([[2, 5], [4, 3]]) // returns 120
|
55947 | *
|
55948 | * See also:
|
55949 | *
|
55950 | * mean, median, min, max, sum, std, var
|
55951 | *
|
55952 | * @param {... *} args A single matrix or or multiple scalar values
|
55953 | * @return {*} The product of all values
|
55954 | */
|
55955 |
|
55956 | var prod = typed('prod', {
|
55957 | // prod([a, b, c, d, ...])
|
55958 | 'Array | Matrix': _prod,
|
55959 | // prod([a, b, c, d, ...], dim)
|
55960 | 'Array | Matrix, number | BigNumber': function ArrayMatrixNumberBigNumber(array, dim) {
|
55961 | // TODO: implement prod(A, dim)
|
55962 | throw new Error('prod(A, dim) is not yet supported'); // return reduce(arguments[0], arguments[1], math.prod)
|
55963 | },
|
55964 | // prod(a, b, c, d, ...)
|
55965 | '...': function _(args) {
|
55966 | return _prod(args);
|
55967 | }
|
55968 | });
|
55969 | prod.toTex = undefined; // use default template
|
55970 |
|
55971 | return prod;
|
55972 | /**
|
55973 | * Recursively calculate the product of an n-dimensional array
|
55974 | * @param {Array} array
|
55975 | * @return {number} prod
|
55976 | * @private
|
55977 | */
|
55978 |
|
55979 | function _prod(array) {
|
55980 | var prod;
|
55981 | deepForEach(array, function (value) {
|
55982 | try {
|
55983 | prod = prod === undefined ? value : multiply(prod, value);
|
55984 | } catch (err) {
|
55985 | throw improveErrorMessage(err, 'prod', value);
|
55986 | }
|
55987 | });
|
55988 |
|
55989 | if (prod === undefined) {
|
55990 | throw new Error('Cannot calculate prod of an empty array');
|
55991 | }
|
55992 |
|
55993 | return prod;
|
55994 | }
|
55995 | }
|
55996 |
|
55997 | exports.name = 'prod';
|
55998 | exports.factory = factory;
|
55999 |
|
56000 | /***/ }),
|
56001 | /* 320 */
|
56002 | /***/ (function(module, exports, __webpack_require__) {
|
56003 |
|
56004 | "use strict";
|
56005 |
|
56006 |
|
56007 | var isInteger = __webpack_require__(3).isInteger;
|
56008 |
|
56009 | var isNumber = __webpack_require__(3).isNumber;
|
56010 |
|
56011 | var flatten = __webpack_require__(2).flatten;
|
56012 |
|
56013 | var isCollection = __webpack_require__(35);
|
56014 |
|
56015 | function factory(type, config, load, typed) {
|
56016 | var add = load(__webpack_require__(14));
|
56017 | var multiply = load(__webpack_require__(10));
|
56018 | var partitionSelect = load(__webpack_require__(97));
|
56019 | var compare = load(__webpack_require__(55));
|
56020 | /**
|
56021 | * Compute the prob order quantile of a matrix or a list with values.
|
56022 | * The sequence is sorted and the middle value is returned.
|
56023 | * Supported types of sequence values are: Number, BigNumber, Unit
|
56024 | * Supported types of probability are: Number, BigNumber
|
56025 | *
|
56026 | * In case of a (multi dimensional) array or matrix, the prob order quantile
|
56027 | * of all elements will be calculated.
|
56028 | *
|
56029 | * Syntax:
|
56030 | *
|
56031 | * math.quantileSeq(A, prob[, sorted])
|
56032 | * math.quantileSeq(A, [prob1, prob2, ...][, sorted])
|
56033 | * math.quantileSeq(A, N[, sorted])
|
56034 | *
|
56035 | * Examples:
|
56036 | *
|
56037 | * math.quantileSeq([3, -1, 5, 7], 0.5) // returns 4
|
56038 | * math.quantileSeq([3, -1, 5, 7], [1/3, 2/3]) // returns [3, 5]
|
56039 | * math.quantileSeq([3, -1, 5, 7], 2) // returns [3, 5]
|
56040 | * math.quantileSeq([-1, 3, 5, 7], 0.5, true) // returns 4
|
56041 | *
|
56042 | * See also:
|
56043 | *
|
56044 | * median, mean, min, max, sum, prod, std, var
|
56045 | *
|
56046 | * @param {Array, Matrix} data A single matrix or Array
|
56047 | * @param {Number, BigNumber, Array} probOrN prob is the order of the quantile, while N is
|
56048 | * the amount of evenly distributed steps of
|
56049 | * probabilities; only one of these options can
|
56050 | * be provided
|
56051 | * @param {Boolean} sorted=false is data sorted in ascending order
|
56052 | * @return {Number, BigNumber, Unit, Array} Quantile(s)
|
56053 | */
|
56054 |
|
56055 | function quantileSeq(data, probOrN, sorted) {
|
56056 | var probArr, dataArr, one;
|
56057 |
|
56058 | if (arguments.length < 2 || arguments.length > 3) {
|
56059 | throw new SyntaxError('Function quantileSeq requires two or three parameters');
|
56060 | }
|
56061 |
|
56062 | if (isCollection(data)) {
|
56063 | sorted = sorted || false;
|
56064 |
|
56065 | if (typeof sorted === 'boolean') {
|
56066 | dataArr = data.valueOf();
|
56067 |
|
56068 | if (isNumber(probOrN)) {
|
56069 | if (probOrN < 0) {
|
56070 | throw new Error('N/prob must be non-negative');
|
56071 | }
|
56072 |
|
56073 | if (probOrN <= 1) {
|
56074 | // quantileSeq([a, b, c, d, ...], prob[,sorted])
|
56075 | return _quantileSeq(dataArr, probOrN, sorted);
|
56076 | }
|
56077 |
|
56078 | if (probOrN > 1) {
|
56079 | // quantileSeq([a, b, c, d, ...], N[,sorted])
|
56080 | if (!isInteger(probOrN)) {
|
56081 | throw new Error('N must be a positive integer');
|
56082 | }
|
56083 |
|
56084 | var nPlusOne = probOrN + 1;
|
56085 | probArr = new Array(probOrN);
|
56086 |
|
56087 | for (var i = 0; i < probOrN;) {
|
56088 | probArr[i] = _quantileSeq(dataArr, ++i / nPlusOne, sorted);
|
56089 | }
|
56090 |
|
56091 | return probArr;
|
56092 | }
|
56093 | }
|
56094 |
|
56095 | if (type.isBigNumber(probOrN)) {
|
56096 | if (probOrN.isNegative()) {
|
56097 | throw new Error('N/prob must be non-negative');
|
56098 | }
|
56099 |
|
56100 | one = new probOrN.constructor(1);
|
56101 |
|
56102 | if (probOrN.lte(one)) {
|
56103 | // quantileSeq([a, b, c, d, ...], prob[,sorted])
|
56104 | return new type.BigNumber(_quantileSeq(dataArr, probOrN, sorted));
|
56105 | }
|
56106 |
|
56107 | if (probOrN.gt(one)) {
|
56108 | // quantileSeq([a, b, c, d, ...], N[,sorted])
|
56109 | if (!probOrN.isInteger()) {
|
56110 | throw new Error('N must be a positive integer');
|
56111 | } // largest possible Array length is 2^32-1
|
56112 | // 2^32 < 10^15, thus safe conversion guaranteed
|
56113 |
|
56114 |
|
56115 | var intN = probOrN.toNumber();
|
56116 |
|
56117 | if (intN > 4294967295) {
|
56118 | throw new Error('N must be less than or equal to 2^32-1, as that is the maximum length of an Array');
|
56119 | }
|
56120 |
|
56121 | var _nPlusOne = new type.BigNumber(intN + 1);
|
56122 |
|
56123 | probArr = new Array(intN);
|
56124 |
|
56125 | for (var _i = 0; _i < intN;) {
|
56126 | probArr[_i] = new type.BigNumber(_quantileSeq(dataArr, new type.BigNumber(++_i).div(_nPlusOne), sorted));
|
56127 | }
|
56128 |
|
56129 | return probArr;
|
56130 | }
|
56131 | }
|
56132 |
|
56133 | if (Array.isArray(probOrN)) {
|
56134 | // quantileSeq([a, b, c, d, ...], [prob1, prob2, ...][,sorted])
|
56135 | probArr = new Array(probOrN.length);
|
56136 |
|
56137 | for (var _i2 = 0; _i2 < probArr.length; ++_i2) {
|
56138 | var currProb = probOrN[_i2];
|
56139 |
|
56140 | if (isNumber(currProb)) {
|
56141 | if (currProb < 0 || currProb > 1) {
|
56142 | throw new Error('Probability must be between 0 and 1, inclusive');
|
56143 | }
|
56144 | } else if (type.isBigNumber(currProb)) {
|
56145 | one = new currProb.constructor(1);
|
56146 |
|
56147 | if (currProb.isNegative() || currProb.gt(one)) {
|
56148 | throw new Error('Probability must be between 0 and 1, inclusive');
|
56149 | }
|
56150 | } else {
|
56151 | throw new TypeError('Unexpected type of argument in function quantileSeq'); // FIXME: becomes redundant when converted to typed-function
|
56152 | }
|
56153 |
|
56154 | probArr[_i2] = _quantileSeq(dataArr, currProb, sorted);
|
56155 | }
|
56156 |
|
56157 | return probArr;
|
56158 | }
|
56159 |
|
56160 | throw new TypeError('Unexpected type of argument in function quantileSeq'); // FIXME: becomes redundant when converted to typed-function
|
56161 | }
|
56162 |
|
56163 | throw new TypeError('Unexpected type of argument in function quantileSeq'); // FIXME: becomes redundant when converted to typed-function
|
56164 | }
|
56165 |
|
56166 | throw new TypeError('Unexpected type of argument in function quantileSeq'); // FIXME: becomes redundant when converted to typed-function
|
56167 | }
|
56168 | /**
|
56169 | * Calculate the prob order quantile of an n-dimensional array.
|
56170 | *
|
56171 | * @param {Array} array
|
56172 | * @param {Number, BigNumber} prob
|
56173 | * @param {Boolean} sorted
|
56174 | * @return {Number, BigNumber, Unit} prob order quantile
|
56175 | * @private
|
56176 | */
|
56177 |
|
56178 |
|
56179 | function _quantileSeq(array, prob, sorted) {
|
56180 | var flat = flatten(array);
|
56181 | var len = flat.length;
|
56182 |
|
56183 | if (len === 0) {
|
56184 | throw new Error('Cannot calculate quantile of an empty sequence');
|
56185 | }
|
56186 |
|
56187 | if (isNumber(prob)) {
|
56188 | var _index = prob * (len - 1);
|
56189 |
|
56190 | var _fracPart = _index % 1;
|
56191 |
|
56192 | if (_fracPart === 0) {
|
56193 | var value = sorted ? flat[_index] : partitionSelect(flat, _index);
|
56194 | validate(value);
|
56195 | return value;
|
56196 | }
|
56197 |
|
56198 | var _integerPart = Math.floor(_index);
|
56199 |
|
56200 | var _left;
|
56201 |
|
56202 | var _right;
|
56203 |
|
56204 | if (sorted) {
|
56205 | _left = flat[_integerPart];
|
56206 | _right = flat[_integerPart + 1];
|
56207 | } else {
|
56208 | _right = partitionSelect(flat, _integerPart + 1); // max of partition is kth largest
|
56209 |
|
56210 | _left = flat[_integerPart];
|
56211 |
|
56212 | for (var i = 0; i < _integerPart; ++i) {
|
56213 | if (compare(flat[i], _left) > 0) {
|
56214 | _left = flat[i];
|
56215 | }
|
56216 | }
|
56217 | }
|
56218 |
|
56219 | validate(_left);
|
56220 | validate(_right); // Q(prob) = (1-f)*A[floor(index)] + f*A[floor(index)+1]
|
56221 |
|
56222 | return add(multiply(_left, 1 - _fracPart), multiply(_right, _fracPart));
|
56223 | } // If prob is a BigNumber
|
56224 |
|
56225 |
|
56226 | var index = prob.times(len - 1);
|
56227 |
|
56228 | if (index.isInteger()) {
|
56229 | index = index.toNumber();
|
56230 |
|
56231 | var _value = sorted ? flat[index] : partitionSelect(flat, index);
|
56232 |
|
56233 | validate(_value);
|
56234 | return _value;
|
56235 | }
|
56236 |
|
56237 | var integerPart = index.floor();
|
56238 | var fracPart = index.minus(integerPart);
|
56239 | var integerPartNumber = integerPart.toNumber();
|
56240 | var left;
|
56241 | var right;
|
56242 |
|
56243 | if (sorted) {
|
56244 | left = flat[integerPartNumber];
|
56245 | right = flat[integerPartNumber + 1];
|
56246 | } else {
|
56247 | right = partitionSelect(flat, integerPartNumber + 1); // max of partition is kth largest
|
56248 |
|
56249 | left = flat[integerPartNumber];
|
56250 |
|
56251 | for (var _i3 = 0; _i3 < integerPartNumber; ++_i3) {
|
56252 | if (compare(flat[_i3], left) > 0) {
|
56253 | left = flat[_i3];
|
56254 | }
|
56255 | }
|
56256 | }
|
56257 |
|
56258 | validate(left);
|
56259 | validate(right); // Q(prob) = (1-f)*A[floor(index)] + f*A[floor(index)+1]
|
56260 |
|
56261 | var one = new fracPart.constructor(1);
|
56262 | return add(multiply(left, one.minus(fracPart)), multiply(right, fracPart));
|
56263 | }
|
56264 | /**
|
56265 | * Check if array value types are valid, throw error otherwise.
|
56266 | * @param {number | BigNumber | Unit} x
|
56267 | * @param {number | BigNumber | Unit} x
|
56268 | * @private
|
56269 | */
|
56270 |
|
56271 |
|
56272 | var validate = typed({
|
56273 | 'number | BigNumber | Unit': function numberBigNumberUnit(x) {
|
56274 | return x;
|
56275 | }
|
56276 | });
|
56277 | return quantileSeq;
|
56278 | }
|
56279 |
|
56280 | exports.name = 'quantileSeq';
|
56281 | exports.factory = factory;
|
56282 |
|
56283 | /***/ }),
|
56284 | /* 321 */
|
56285 | /***/ (function(module, exports, __webpack_require__) {
|
56286 |
|
56287 | "use strict";
|
56288 |
|
56289 |
|
56290 | module.exports = [__webpack_require__(112), __webpack_require__(322)];
|
56291 |
|
56292 | /***/ }),
|
56293 | /* 322 */
|
56294 | /***/ (function(module, exports, __webpack_require__) {
|
56295 |
|
56296 | "use strict";
|
56297 |
|
56298 |
|
56299 | var isString = __webpack_require__(9).isString;
|
56300 |
|
56301 | var format = __webpack_require__(9).format;
|
56302 |
|
56303 | function factory(type, config, load, typed) {
|
56304 | /**
|
56305 | * Interpolate values into a string template.
|
56306 | *
|
56307 | * Syntax:
|
56308 | *
|
56309 | * math.print(template, values)
|
56310 | * math.print(template, values, precision)
|
56311 | * math.print(template, values, options)
|
56312 | *
|
56313 | * Example usage:
|
56314 | *
|
56315 | * // the following outputs: 'Lucy is 5 years old'
|
56316 | * math.print('Lucy is $age years old', {age: 5})
|
56317 | *
|
56318 | * // the following outputs: 'The value of pi is 3.141592654'
|
56319 | * math.print('The value of pi is $pi', {pi: math.pi}, 10)
|
56320 | *
|
56321 | * // the following outputs: 'hello Mary! The date is 2013-03-23'
|
56322 | * math.print('Hello $user.name! The date is $date', {
|
56323 | * user: {
|
56324 | * name: 'Mary',
|
56325 | * },
|
56326 | * date: new Date(2013, 2, 23).toISOString().substring(0, 10)
|
56327 | * })
|
56328 | *
|
56329 | * // the following outputs: 'My favorite fruits are apples and bananas !'
|
56330 | * math.print('My favorite fruits are $0 and $1 !', [
|
56331 | * 'apples',
|
56332 | * 'bananas'
|
56333 | * ])
|
56334 | *
|
56335 | * See also:
|
56336 | *
|
56337 | * format
|
56338 | *
|
56339 | * @param {string} template A string containing variable placeholders.
|
56340 | * @param {Object | Array | Matrix} values An object or array containing variables
|
56341 | * which will be filled in in the template.
|
56342 | * @param {number | Object} [options] Formatting options,
|
56343 | * or the number of digits to format numbers.
|
56344 | * See function math.format for a description
|
56345 | * of all options.
|
56346 | * @return {string} Interpolated string
|
56347 | */
|
56348 | var print = typed('print', {
|
56349 | // note: Matrix will be converted automatically to an Array
|
56350 | 'string, Object | Array': _print,
|
56351 | 'string, Object | Array, number | Object': _print
|
56352 | });
|
56353 | print.toTex = undefined; // use default template
|
56354 |
|
56355 | return print;
|
56356 | }
|
56357 | /**
|
56358 | * Interpolate values into a string template.
|
56359 | * @param {string} template
|
56360 | * @param {Object} values
|
56361 | * @param {number | Object} [options]
|
56362 | * @returns {string} Interpolated string
|
56363 | * @private
|
56364 | */
|
56365 |
|
56366 |
|
56367 | function _print(template, values, options) {
|
56368 | return template.replace(/\$([\w.]+)/g, function (original, key) {
|
56369 | var keys = key.split('.');
|
56370 | var value = values[keys.shift()];
|
56371 |
|
56372 | while (keys.length && value !== undefined) {
|
56373 | var k = keys.shift();
|
56374 | value = k ? value[k] : value + '.';
|
56375 | }
|
56376 |
|
56377 | if (value !== undefined) {
|
56378 | if (!isString(value)) {
|
56379 | return format(value, options);
|
56380 | } else {
|
56381 | return value;
|
56382 | }
|
56383 | }
|
56384 |
|
56385 | return original;
|
56386 | });
|
56387 | }
|
56388 |
|
56389 | exports.name = 'print';
|
56390 | exports.factory = factory;
|
56391 |
|
56392 | /***/ }),
|
56393 | /* 323 */
|
56394 | /***/ (function(module, exports, __webpack_require__) {
|
56395 |
|
56396 | "use strict";
|
56397 |
|
56398 |
|
56399 | module.exports = [__webpack_require__(324), __webpack_require__(325), __webpack_require__(326), __webpack_require__(327), __webpack_require__(328), __webpack_require__(329), __webpack_require__(330), __webpack_require__(331), __webpack_require__(332), __webpack_require__(333), __webpack_require__(334), __webpack_require__(335), __webpack_require__(336), __webpack_require__(337), __webpack_require__(338), __webpack_require__(339), __webpack_require__(340), __webpack_require__(341), __webpack_require__(342), __webpack_require__(343), __webpack_require__(344), __webpack_require__(345), __webpack_require__(346), __webpack_require__(347), __webpack_require__(348)];
|
56400 |
|
56401 | /***/ }),
|
56402 | /* 324 */
|
56403 | /***/ (function(module, exports, __webpack_require__) {
|
56404 |
|
56405 | "use strict";
|
56406 |
|
56407 |
|
56408 | var deepMap = __webpack_require__(1);
|
56409 |
|
56410 | function factory(type, config, load, typed) {
|
56411 | /**
|
56412 | * Calculate the inverse cosine of a value.
|
56413 | *
|
56414 | * For matrices, the function is evaluated element wise.
|
56415 | *
|
56416 | * Syntax:
|
56417 | *
|
56418 | * math.acos(x)
|
56419 | *
|
56420 | * Examples:
|
56421 | *
|
56422 | * math.acos(0.5) // returns number 1.0471975511965979
|
56423 | * math.acos(math.cos(1.5)) // returns number 1.5
|
56424 | *
|
56425 | * math.acos(2) // returns Complex 0 + 1.3169578969248166 i
|
56426 | *
|
56427 | * See also:
|
56428 | *
|
56429 | * cos, atan, asin
|
56430 | *
|
56431 | * @param {number | BigNumber | Complex | Array | Matrix} x Function input
|
56432 | * @return {number | BigNumber | Complex | Array | Matrix} The arc cosine of x
|
56433 | */
|
56434 | var acos = typed('acos', {
|
56435 | 'number': function number(x) {
|
56436 | if (x >= -1 && x <= 1 || config.predictable) {
|
56437 | return Math.acos(x);
|
56438 | } else {
|
56439 | return new type.Complex(x, 0).acos();
|
56440 | }
|
56441 | },
|
56442 | 'Complex': function Complex(x) {
|
56443 | return x.acos();
|
56444 | },
|
56445 | 'BigNumber': function BigNumber(x) {
|
56446 | return x.acos();
|
56447 | },
|
56448 | 'Array | Matrix': function ArrayMatrix(x) {
|
56449 | return deepMap(x, acos);
|
56450 | }
|
56451 | });
|
56452 | acos.toTex = {
|
56453 | 1: "\\cos^{-1}\\left(${args[0]}\\right)"
|
56454 | };
|
56455 | return acos;
|
56456 | }
|
56457 |
|
56458 | exports.name = 'acos';
|
56459 | exports.factory = factory;
|
56460 |
|
56461 | /***/ }),
|
56462 | /* 325 */
|
56463 | /***/ (function(module, exports, __webpack_require__) {
|
56464 |
|
56465 | "use strict";
|
56466 |
|
56467 |
|
56468 | var deepMap = __webpack_require__(1);
|
56469 |
|
56470 | function factory(type, config, load, typed) {
|
56471 | /**
|
56472 | * Calculate the hyperbolic arccos of a value,
|
56473 | * defined as `acosh(x) = ln(sqrt(x^2 - 1) + x)`.
|
56474 | *
|
56475 | * For matrices, the function is evaluated element wise.
|
56476 | *
|
56477 | * Syntax:
|
56478 | *
|
56479 | * math.acosh(x)
|
56480 | *
|
56481 | * Examples:
|
56482 | *
|
56483 | * math.acosh(1.5) // returns 0.9624236501192069
|
56484 | *
|
56485 | * See also:
|
56486 | *
|
56487 | * cosh, asinh, atanh
|
56488 | *
|
56489 | * @param {number | Complex | Unit | Array | Matrix} x Function input
|
56490 | * @return {number | Complex | Array | Matrix} Hyperbolic arccosine of x
|
56491 | */
|
56492 | var acosh = typed('acosh', {
|
56493 | 'number': function number(x) {
|
56494 | if (x >= 1 || config.predictable) {
|
56495 | return _acosh(x);
|
56496 | }
|
56497 |
|
56498 | if (x <= -1) {
|
56499 | return new type.Complex(Math.log(Math.sqrt(x * x - 1) - x), Math.PI);
|
56500 | }
|
56501 |
|
56502 | return new type.Complex(x, 0).acosh();
|
56503 | },
|
56504 | 'Complex': function Complex(x) {
|
56505 | return x.acosh();
|
56506 | },
|
56507 | 'BigNumber': function BigNumber(x) {
|
56508 | return x.acosh();
|
56509 | },
|
56510 | 'Array | Matrix': function ArrayMatrix(x) {
|
56511 | return deepMap(x, acosh);
|
56512 | }
|
56513 | });
|
56514 | acosh.toTex = {
|
56515 | 1: "\\cosh^{-1}\\left(${args[0]}\\right)"
|
56516 | };
|
56517 | return acosh;
|
56518 | }
|
56519 | /**
|
56520 | * Calculate the hyperbolic arccos of a number
|
56521 | * @param {number} x
|
56522 | * @return {number}
|
56523 | * @private
|
56524 | */
|
56525 |
|
56526 |
|
56527 | var _acosh = Math.acosh || function (x) {
|
56528 | return Math.log(Math.sqrt(x * x - 1) + x);
|
56529 | };
|
56530 |
|
56531 | exports.name = 'acosh';
|
56532 | exports.factory = factory;
|
56533 |
|
56534 | /***/ }),
|
56535 | /* 326 */
|
56536 | /***/ (function(module, exports, __webpack_require__) {
|
56537 |
|
56538 | "use strict";
|
56539 |
|
56540 |
|
56541 | var deepMap = __webpack_require__(1);
|
56542 |
|
56543 | function factory(type, config, load, typed) {
|
56544 | /**
|
56545 | * Calculate the inverse cotangent of a value, defined as `acot(x) = atan(1/x)`.
|
56546 | *
|
56547 | * For matrices, the function is evaluated element wise.
|
56548 | *
|
56549 | * Syntax:
|
56550 | *
|
56551 | * math.acot(x)
|
56552 | *
|
56553 | * Examples:
|
56554 | *
|
56555 | * math.acot(0.5) // returns number 0.4636476090008061
|
56556 | * math.acot(math.cot(1.5)) // returns number 1.5
|
56557 | *
|
56558 | * math.acot(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
|
56559 | *
|
56560 | * See also:
|
56561 | *
|
56562 | * cot, atan
|
56563 | *
|
56564 | * @param {number | Complex | Array | Matrix} x Function input
|
56565 | * @return {number | Complex | Array | Matrix} The arc cotangent of x
|
56566 | */
|
56567 | var acot = typed('acot', {
|
56568 | 'number': function number(x) {
|
56569 | return Math.atan(1 / x);
|
56570 | },
|
56571 | 'Complex': function Complex(x) {
|
56572 | return x.acot();
|
56573 | },
|
56574 | 'BigNumber': function BigNumber(x) {
|
56575 | return new type.BigNumber(1).div(x).atan();
|
56576 | },
|
56577 | 'Array | Matrix': function ArrayMatrix(x) {
|
56578 | return deepMap(x, acot);
|
56579 | }
|
56580 | });
|
56581 | acot.toTex = {
|
56582 | 1: "\\cot^{-1}\\left(${args[0]}\\right)"
|
56583 | };
|
56584 | return acot;
|
56585 | }
|
56586 |
|
56587 | exports.name = 'acot';
|
56588 | exports.factory = factory;
|
56589 |
|
56590 | /***/ }),
|
56591 | /* 327 */
|
56592 | /***/ (function(module, exports, __webpack_require__) {
|
56593 |
|
56594 | "use strict";
|
56595 |
|
56596 |
|
56597 | var deepMap = __webpack_require__(1);
|
56598 |
|
56599 | function factory(type, config, load, typed) {
|
56600 | /**
|
56601 | * Calculate the hyperbolic arccotangent of a value,
|
56602 | * defined as `acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.
|
56603 | *
|
56604 | * For matrices, the function is evaluated element wise.
|
56605 | *
|
56606 | * Syntax:
|
56607 | *
|
56608 | * math.acoth(x)
|
56609 | *
|
56610 | * Examples:
|
56611 | *
|
56612 | * math.acoth(0.5) // returns 0.8047189562170503
|
56613 | *
|
56614 | * See also:
|
56615 | *
|
56616 | * acsch, asech
|
56617 | *
|
56618 | * @param {number | Complex | Array | Matrix} x Function input
|
56619 | * @return {number | Complex | Array | Matrix} Hyperbolic arccotangent of x
|
56620 | */
|
56621 | var acoth = typed('acoth', {
|
56622 | 'number': function number(x) {
|
56623 | if (x >= 1 || x <= -1 || config.predictable) {
|
56624 | return isFinite(x) ? (Math.log((x + 1) / x) + Math.log(x / (x - 1))) / 2 : 0;
|
56625 | }
|
56626 |
|
56627 | return new type.Complex(x, 0).acoth();
|
56628 | },
|
56629 | 'Complex': function Complex(x) {
|
56630 | return x.acoth();
|
56631 | },
|
56632 | 'BigNumber': function BigNumber(x) {
|
56633 | return new type.BigNumber(1).div(x).atanh();
|
56634 | },
|
56635 | 'Array | Matrix': function ArrayMatrix(x) {
|
56636 | return deepMap(x, acoth);
|
56637 | }
|
56638 | });
|
56639 | acoth.toTex = {
|
56640 | 1: "\\coth^{-1}\\left(${args[0]}\\right)"
|
56641 | };
|
56642 | return acoth;
|
56643 | }
|
56644 |
|
56645 | exports.name = 'acoth';
|
56646 | exports.factory = factory;
|
56647 |
|
56648 | /***/ }),
|
56649 | /* 328 */
|
56650 | /***/ (function(module, exports, __webpack_require__) {
|
56651 |
|
56652 | "use strict";
|
56653 |
|
56654 |
|
56655 | var deepMap = __webpack_require__(1);
|
56656 |
|
56657 | function factory(type, config, load, typed) {
|
56658 | /**
|
56659 | * Calculate the inverse cosecant of a value, defined as `acsc(x) = asin(1/x)`.
|
56660 | *
|
56661 | * For matrices, the function is evaluated element wise.
|
56662 | *
|
56663 | * Syntax:
|
56664 | *
|
56665 | * math.acsc(x)
|
56666 | *
|
56667 | * Examples:
|
56668 | *
|
56669 | * math.acsc(0.5) // returns number 0.5235987755982989
|
56670 | * math.acsc(math.csc(1.5)) // returns number ~1.5
|
56671 | *
|
56672 | * math.acsc(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
|
56673 | *
|
56674 | * See also:
|
56675 | *
|
56676 | * csc, asin, asec
|
56677 | *
|
56678 | * @param {number | Complex | Array | Matrix} x Function input
|
56679 | * @return {number | Complex | Array | Matrix} The arc cosecant of x
|
56680 | */
|
56681 | var acsc = typed('acsc', {
|
56682 | 'number': function number(x) {
|
56683 | if (x <= -1 || x >= 1 || config.predictable) {
|
56684 | return Math.asin(1 / x);
|
56685 | }
|
56686 |
|
56687 | return new type.Complex(x, 0).acsc();
|
56688 | },
|
56689 | 'Complex': function Complex(x) {
|
56690 | return x.acsc();
|
56691 | },
|
56692 | 'BigNumber': function BigNumber(x) {
|
56693 | return new type.BigNumber(1).div(x).asin();
|
56694 | },
|
56695 | 'Array | Matrix': function ArrayMatrix(x) {
|
56696 | return deepMap(x, acsc);
|
56697 | }
|
56698 | });
|
56699 | acsc.toTex = {
|
56700 | 1: "\\csc^{-1}\\left(${args[0]}\\right)"
|
56701 | };
|
56702 | return acsc;
|
56703 | }
|
56704 |
|
56705 | exports.name = 'acsc';
|
56706 | exports.factory = factory;
|
56707 |
|
56708 | /***/ }),
|
56709 | /* 329 */
|
56710 | /***/ (function(module, exports, __webpack_require__) {
|
56711 |
|
56712 | "use strict";
|
56713 |
|
56714 |
|
56715 | var deepMap = __webpack_require__(1);
|
56716 |
|
56717 | function factory(type, config, load, typed) {
|
56718 | /**
|
56719 | * Calculate the hyperbolic arccosecant of a value,
|
56720 | * defined as `acsch(x) = asinh(1/x) = ln(1/x + sqrt(1/x^2 + 1))`.
|
56721 | *
|
56722 | * For matrices, the function is evaluated element wise.
|
56723 | *
|
56724 | * Syntax:
|
56725 | *
|
56726 | * math.acsch(x)
|
56727 | *
|
56728 | * Examples:
|
56729 | *
|
56730 | * math.acsch(0.5) // returns 1.4436354751788103
|
56731 | *
|
56732 | * See also:
|
56733 | *
|
56734 | * asech, acoth
|
56735 | *
|
56736 | * @param {number | Complex | Array | Matrix} x Function input
|
56737 | * @return {number | Complex | Array | Matrix} Hyperbolic arccosecant of x
|
56738 | */
|
56739 | var acsch = typed('acsch', {
|
56740 | 'number': function number(x) {
|
56741 | x = 1 / x;
|
56742 | return Math.log(x + Math.sqrt(x * x + 1));
|
56743 | },
|
56744 | 'Complex': function Complex(x) {
|
56745 | return x.acsch();
|
56746 | },
|
56747 | 'BigNumber': function BigNumber(x) {
|
56748 | return new type.BigNumber(1).div(x).asinh();
|
56749 | },
|
56750 | 'Array | Matrix': function ArrayMatrix(x) {
|
56751 | return deepMap(x, acsch);
|
56752 | }
|
56753 | });
|
56754 | acsch.toTex = {
|
56755 | 1: "\\mathrm{csch}^{-1}\\left(${args[0]}\\right)"
|
56756 | };
|
56757 | return acsch;
|
56758 | }
|
56759 |
|
56760 | exports.name = 'acsch';
|
56761 | exports.factory = factory;
|
56762 |
|
56763 | /***/ }),
|
56764 | /* 330 */
|
56765 | /***/ (function(module, exports, __webpack_require__) {
|
56766 |
|
56767 | "use strict";
|
56768 |
|
56769 |
|
56770 | var deepMap = __webpack_require__(1);
|
56771 |
|
56772 | function factory(type, config, load, typed) {
|
56773 | /**
|
56774 | * Calculate the inverse secant of a value. Defined as `asec(x) = acos(1/x)`.
|
56775 | *
|
56776 | * For matrices, the function is evaluated element wise.
|
56777 | *
|
56778 | * Syntax:
|
56779 | *
|
56780 | * math.asec(x)
|
56781 | *
|
56782 | * Examples:
|
56783 | *
|
56784 | * math.asec(0.5) // returns 1.0471975511965979
|
56785 | * math.asec(math.sec(1.5)) // returns 1.5
|
56786 | *
|
56787 | * math.asec(2) // returns 0 + 1.3169578969248166 i
|
56788 | *
|
56789 | * See also:
|
56790 | *
|
56791 | * acos, acot, acsc
|
56792 | *
|
56793 | * @param {number | Complex | Array | Matrix} x Function input
|
56794 | * @return {number | Complex | Array | Matrix} The arc secant of x
|
56795 | */
|
56796 | var asec = typed('asec', {
|
56797 | 'number': function number(x) {
|
56798 | if (x <= -1 || x >= 1 || config.predictable) {
|
56799 | return Math.acos(1 / x);
|
56800 | }
|
56801 |
|
56802 | return new type.Complex(x, 0).asec();
|
56803 | },
|
56804 | 'Complex': function Complex(x) {
|
56805 | return x.asec();
|
56806 | },
|
56807 | 'BigNumber': function BigNumber(x) {
|
56808 | return new type.BigNumber(1).div(x).acos();
|
56809 | },
|
56810 | 'Array | Matrix': function ArrayMatrix(x) {
|
56811 | return deepMap(x, asec);
|
56812 | }
|
56813 | });
|
56814 | asec.toTex = {
|
56815 | 1: "\\sec^{-1}\\left(${args[0]}\\right)"
|
56816 | };
|
56817 | return asec;
|
56818 | }
|
56819 |
|
56820 | exports.name = 'asec';
|
56821 | exports.factory = factory;
|
56822 |
|
56823 | /***/ }),
|
56824 | /* 331 */
|
56825 | /***/ (function(module, exports, __webpack_require__) {
|
56826 |
|
56827 | "use strict";
|
56828 |
|
56829 |
|
56830 | var deepMap = __webpack_require__(1);
|
56831 |
|
56832 | function factory(type, config, load, typed) {
|
56833 | /**
|
56834 | * Calculate the hyperbolic arcsecant of a value,
|
56835 | * defined as `asech(x) = acosh(1/x) = ln(sqrt(1/x^2 - 1) + 1/x)`.
|
56836 | *
|
56837 | * For matrices, the function is evaluated element wise.
|
56838 | *
|
56839 | * Syntax:
|
56840 | *
|
56841 | * math.asech(x)
|
56842 | *
|
56843 | * Examples:
|
56844 | *
|
56845 | * math.asech(0.5) // returns 1.3169578969248166
|
56846 | *
|
56847 | * See also:
|
56848 | *
|
56849 | * acsch, acoth
|
56850 | *
|
56851 | * @param {number | Complex | Array | Matrix} x Function input
|
56852 | * @return {number | Complex | Array | Matrix} Hyperbolic arcsecant of x
|
56853 | */
|
56854 | var asech = typed('asech', {
|
56855 | 'number': function number(x) {
|
56856 | if (x <= 1 && x >= -1 || config.predictable) {
|
56857 | x = 1 / x;
|
56858 | var ret = Math.sqrt(x * x - 1);
|
56859 |
|
56860 | if (x > 0 || config.predictable) {
|
56861 | return Math.log(ret + x);
|
56862 | }
|
56863 |
|
56864 | return new type.Complex(Math.log(ret - x), Math.PI);
|
56865 | }
|
56866 |
|
56867 | return new type.Complex(x, 0).asech();
|
56868 | },
|
56869 | 'Complex': function Complex(x) {
|
56870 | return x.asech();
|
56871 | },
|
56872 | 'BigNumber': function BigNumber(x) {
|
56873 | return new type.BigNumber(1).div(x).acosh();
|
56874 | },
|
56875 | 'Array | Matrix': function ArrayMatrix(x) {
|
56876 | return deepMap(x, asech);
|
56877 | }
|
56878 | });
|
56879 | asech.toTex = {
|
56880 | 1: "\\mathrm{sech}^{-1}\\left(${args[0]}\\right)"
|
56881 | };
|
56882 | return asech;
|
56883 | }
|
56884 |
|
56885 | exports.name = 'asech';
|
56886 | exports.factory = factory;
|
56887 |
|
56888 | /***/ }),
|
56889 | /* 332 */
|
56890 | /***/ (function(module, exports, __webpack_require__) {
|
56891 |
|
56892 | "use strict";
|
56893 |
|
56894 |
|
56895 | var deepMap = __webpack_require__(1);
|
56896 |
|
56897 | function factory(type, config, load, typed) {
|
56898 | /**
|
56899 | * Calculate the inverse sine of a value.
|
56900 | *
|
56901 | * For matrices, the function is evaluated element wise.
|
56902 | *
|
56903 | * Syntax:
|
56904 | *
|
56905 | * math.asin(x)
|
56906 | *
|
56907 | * Examples:
|
56908 | *
|
56909 | * math.asin(0.5) // returns number 0.5235987755982989
|
56910 | * math.asin(math.sin(1.5)) // returns number ~1.5
|
56911 | *
|
56912 | * math.asin(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
|
56913 | *
|
56914 | * See also:
|
56915 | *
|
56916 | * sin, atan, acos
|
56917 | *
|
56918 | * @param {number | BigNumber | Complex | Array | Matrix} x Function input
|
56919 | * @return {number | BigNumber | Complex | Array | Matrix} The arc sine of x
|
56920 | */
|
56921 | var asin = typed('asin', {
|
56922 | 'number': function number(x) {
|
56923 | if (x >= -1 && x <= 1 || config.predictable) {
|
56924 | return Math.asin(x);
|
56925 | } else {
|
56926 | return new type.Complex(x, 0).asin();
|
56927 | }
|
56928 | },
|
56929 | 'Complex': function Complex(x) {
|
56930 | return x.asin();
|
56931 | },
|
56932 | 'BigNumber': function BigNumber(x) {
|
56933 | return x.asin();
|
56934 | },
|
56935 | 'Array | Matrix': function ArrayMatrix(x) {
|
56936 | // deep map collection, skip zeros since asin(0) = 0
|
56937 | return deepMap(x, asin, true);
|
56938 | }
|
56939 | });
|
56940 | asin.toTex = {
|
56941 | 1: "\\sin^{-1}\\left(${args[0]}\\right)"
|
56942 | };
|
56943 | return asin;
|
56944 | }
|
56945 |
|
56946 | exports.name = 'asin';
|
56947 | exports.factory = factory;
|
56948 |
|
56949 | /***/ }),
|
56950 | /* 333 */
|
56951 | /***/ (function(module, exports, __webpack_require__) {
|
56952 |
|
56953 | "use strict";
|
56954 |
|
56955 |
|
56956 | var deepMap = __webpack_require__(1);
|
56957 |
|
56958 | function factory(type, config, load, typed) {
|
56959 | /**
|
56960 | * Calculate the hyperbolic arcsine of a value,
|
56961 | * defined as `asinh(x) = ln(x + sqrt(x^2 + 1))`.
|
56962 | *
|
56963 | * For matrices, the function is evaluated element wise.
|
56964 | *
|
56965 | * Syntax:
|
56966 | *
|
56967 | * math.asinh(x)
|
56968 | *
|
56969 | * Examples:
|
56970 | *
|
56971 | * math.asinh(0.5) // returns 0.48121182505960347
|
56972 | *
|
56973 | * See also:
|
56974 | *
|
56975 | * acosh, atanh
|
56976 | *
|
56977 | * @param {number | Complex | Array | Matrix} x Function input
|
56978 | * @return {number | Complex | Array | Matrix} Hyperbolic arcsine of x
|
56979 | */
|
56980 | var asinh = typed('asinh', {
|
56981 | 'number': Math.asinh || function (x) {
|
56982 | return Math.log(Math.sqrt(x * x + 1) + x);
|
56983 | },
|
56984 | 'Complex': function Complex(x) {
|
56985 | return x.asinh();
|
56986 | },
|
56987 | 'BigNumber': function BigNumber(x) {
|
56988 | return x.asinh();
|
56989 | },
|
56990 | 'Array | Matrix': function ArrayMatrix(x) {
|
56991 | // deep map collection, skip zeros since asinh(0) = 0
|
56992 | return deepMap(x, asinh, true);
|
56993 | }
|
56994 | });
|
56995 | asinh.toTex = {
|
56996 | 1: "\\sinh^{-1}\\left(${args[0]}\\right)"
|
56997 | };
|
56998 | return asinh;
|
56999 | }
|
57000 |
|
57001 | exports.name = 'asinh';
|
57002 | exports.factory = factory;
|
57003 |
|
57004 | /***/ }),
|
57005 | /* 334 */
|
57006 | /***/ (function(module, exports, __webpack_require__) {
|
57007 |
|
57008 | "use strict";
|
57009 |
|
57010 |
|
57011 | var deepMap = __webpack_require__(1);
|
57012 |
|
57013 | function factory(type, config, load, typed) {
|
57014 | /**
|
57015 | * Calculate the inverse tangent of a value.
|
57016 | *
|
57017 | * For matrices, the function is evaluated element wise.
|
57018 | *
|
57019 | * Syntax:
|
57020 | *
|
57021 | * math.atan(x)
|
57022 | *
|
57023 | * Examples:
|
57024 | *
|
57025 | * math.atan(0.5) // returns number 0.4636476090008061
|
57026 | * math.atan(math.tan(1.5)) // returns number 1.5
|
57027 | *
|
57028 | * math.atan(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
|
57029 | *
|
57030 | * See also:
|
57031 | *
|
57032 | * tan, asin, acos
|
57033 | *
|
57034 | * @param {number | BigNumber | Complex | Array | Matrix} x Function input
|
57035 | * @return {number | BigNumber | Complex | Array | Matrix} The arc tangent of x
|
57036 | */
|
57037 | var atan = typed('atan', {
|
57038 | 'number': function number(x) {
|
57039 | return Math.atan(x);
|
57040 | },
|
57041 | 'Complex': function Complex(x) {
|
57042 | return x.atan();
|
57043 | },
|
57044 | 'BigNumber': function BigNumber(x) {
|
57045 | return x.atan();
|
57046 | },
|
57047 | 'Array | Matrix': function ArrayMatrix(x) {
|
57048 | // deep map collection, skip zeros since atan(0) = 0
|
57049 | return deepMap(x, atan, true);
|
57050 | }
|
57051 | });
|
57052 | atan.toTex = {
|
57053 | 1: "\\tan^{-1}\\left(${args[0]}\\right)"
|
57054 | };
|
57055 | return atan;
|
57056 | }
|
57057 |
|
57058 | exports.name = 'atan';
|
57059 | exports.factory = factory;
|
57060 |
|
57061 | /***/ }),
|
57062 | /* 335 */
|
57063 | /***/ (function(module, exports, __webpack_require__) {
|
57064 |
|
57065 | "use strict";
|
57066 |
|
57067 |
|
57068 | function factory(type, config, load, typed) {
|
57069 | var matrix = load(__webpack_require__(0));
|
57070 | var algorithm02 = load(__webpack_require__(27));
|
57071 | var algorithm03 = load(__webpack_require__(18));
|
57072 | var algorithm09 = load(__webpack_require__(139));
|
57073 | var algorithm11 = load(__webpack_require__(20));
|
57074 | var algorithm12 = load(__webpack_require__(19));
|
57075 | var algorithm13 = load(__webpack_require__(7));
|
57076 | var algorithm14 = load(__webpack_require__(6));
|
57077 | /**
|
57078 | * Calculate the inverse tangent function with two arguments, y/x.
|
57079 | * By providing two arguments, the right quadrant of the computed angle can be
|
57080 | * determined.
|
57081 | *
|
57082 | * For matrices, the function is evaluated element wise.
|
57083 | *
|
57084 | * Syntax:
|
57085 | *
|
57086 | * math.atan2(y, x)
|
57087 | *
|
57088 | * Examples:
|
57089 | *
|
57090 | * math.atan2(2, 2) / math.pi // returns number 0.25
|
57091 | *
|
57092 | * const angle = math.unit(60, 'deg') // returns Unit 60 deg
|
57093 | * const x = math.cos(angle)
|
57094 | * const y = math.sin(angle)
|
57095 | *
|
57096 | * math.atan(2) // returns Complex 1.5707963267948966 -1.3169578969248166 i
|
57097 | *
|
57098 | * See also:
|
57099 | *
|
57100 | * tan, atan, sin, cos
|
57101 | *
|
57102 | * @param {number | Array | Matrix} y Second dimension
|
57103 | * @param {number | Array | Matrix} x First dimension
|
57104 | * @return {number | Array | Matrix} Four-quadrant inverse tangent
|
57105 | */
|
57106 |
|
57107 | var atan2 = typed('atan2', {
|
57108 | 'number, number': Math.atan2,
|
57109 | // Complex numbers doesn't seem to have a reasonable implementation of
|
57110 | // atan2(). Even Matlab removed the support, after they only calculated
|
57111 | // the atan only on base of the real part of the numbers and ignored the imaginary.
|
57112 | 'BigNumber, BigNumber': function BigNumberBigNumber(y, x) {
|
57113 | return type.BigNumber.atan2(y, x);
|
57114 | },
|
57115 | 'SparseMatrix, SparseMatrix': function SparseMatrixSparseMatrix(x, y) {
|
57116 | return algorithm09(x, y, atan2, false);
|
57117 | },
|
57118 | 'SparseMatrix, DenseMatrix': function SparseMatrixDenseMatrix(x, y) {
|
57119 | // mind the order of y and x!
|
57120 | return algorithm02(y, x, atan2, true);
|
57121 | },
|
57122 | 'DenseMatrix, SparseMatrix': function DenseMatrixSparseMatrix(x, y) {
|
57123 | return algorithm03(x, y, atan2, false);
|
57124 | },
|
57125 | 'DenseMatrix, DenseMatrix': function DenseMatrixDenseMatrix(x, y) {
|
57126 | return algorithm13(x, y, atan2);
|
57127 | },
|
57128 | 'Array, Array': function ArrayArray(x, y) {
|
57129 | return atan2(matrix(x), matrix(y)).valueOf();
|
57130 | },
|
57131 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
57132 | return atan2(matrix(x), y);
|
57133 | },
|
57134 | 'Matrix, Array': function MatrixArray(x, y) {
|
57135 | return atan2(x, matrix(y));
|
57136 | },
|
57137 | 'SparseMatrix, number | BigNumber': function SparseMatrixNumberBigNumber(x, y) {
|
57138 | return algorithm11(x, y, atan2, false);
|
57139 | },
|
57140 | 'DenseMatrix, number | BigNumber': function DenseMatrixNumberBigNumber(x, y) {
|
57141 | return algorithm14(x, y, atan2, false);
|
57142 | },
|
57143 | 'number | BigNumber, SparseMatrix': function numberBigNumberSparseMatrix(x, y) {
|
57144 | // mind the order of y and x
|
57145 | return algorithm12(y, x, atan2, true);
|
57146 | },
|
57147 | 'number | BigNumber, DenseMatrix': function numberBigNumberDenseMatrix(x, y) {
|
57148 | // mind the order of y and x
|
57149 | return algorithm14(y, x, atan2, true);
|
57150 | },
|
57151 | 'Array, number | BigNumber': function ArrayNumberBigNumber(x, y) {
|
57152 | return algorithm14(matrix(x), y, atan2, false).valueOf();
|
57153 | },
|
57154 | 'number | BigNumber, Array': function numberBigNumberArray(x, y) {
|
57155 | return algorithm14(matrix(y), x, atan2, true).valueOf();
|
57156 | }
|
57157 | });
|
57158 | atan2.toTex = {
|
57159 | 2: "\\mathrm{atan2}\\left(${args}\\right)"
|
57160 | };
|
57161 | return atan2;
|
57162 | }
|
57163 |
|
57164 | exports.name = 'atan2';
|
57165 | exports.factory = factory;
|
57166 |
|
57167 | /***/ }),
|
57168 | /* 336 */
|
57169 | /***/ (function(module, exports, __webpack_require__) {
|
57170 |
|
57171 | "use strict";
|
57172 |
|
57173 |
|
57174 | var deepMap = __webpack_require__(1);
|
57175 |
|
57176 | function factory(type, config, load, typed) {
|
57177 | /**
|
57178 | * Calculate the hyperbolic arctangent of a value,
|
57179 | * defined as `atanh(x) = ln((1 + x)/(1 - x)) / 2`.
|
57180 | *
|
57181 | * For matrices, the function is evaluated element wise.
|
57182 | *
|
57183 | * Syntax:
|
57184 | *
|
57185 | * math.atanh(x)
|
57186 | *
|
57187 | * Examples:
|
57188 | *
|
57189 | * math.atanh(0.5) // returns 0.5493061443340549
|
57190 | *
|
57191 | * See also:
|
57192 | *
|
57193 | * acosh, asinh
|
57194 | *
|
57195 | * @param {number | Complex | Array | Matrix} x Function input
|
57196 | * @return {number | Complex | Array | Matrix} Hyperbolic arctangent of x
|
57197 | */
|
57198 | var atanh = typed('atanh', {
|
57199 | 'number': function number(x) {
|
57200 | if (x <= 1 && x >= -1 || config.predictable) {
|
57201 | return _atanh(x);
|
57202 | }
|
57203 |
|
57204 | return new type.Complex(x, 0).atanh();
|
57205 | },
|
57206 | 'Complex': function Complex(x) {
|
57207 | return x.atanh();
|
57208 | },
|
57209 | 'BigNumber': function BigNumber(x) {
|
57210 | return x.atanh();
|
57211 | },
|
57212 | 'Array | Matrix': function ArrayMatrix(x) {
|
57213 | // deep map collection, skip zeros since atanh(0) = 0
|
57214 | return deepMap(x, atanh, true);
|
57215 | }
|
57216 | });
|
57217 | atanh.toTex = {
|
57218 | 1: "\\tanh^{-1}\\left(${args[0]}\\right)"
|
57219 | };
|
57220 | return atanh;
|
57221 | }
|
57222 | /**
|
57223 | * Calculate the hyperbolic arctangent of a number
|
57224 | * @param {number} x
|
57225 | * @return {number}
|
57226 | * @private
|
57227 | */
|
57228 |
|
57229 |
|
57230 | var _atanh = Math.atanh || function (x) {
|
57231 | return Math.log((1 + x) / (1 - x)) / 2;
|
57232 | };
|
57233 |
|
57234 | exports.name = 'atanh';
|
57235 | exports.factory = factory;
|
57236 |
|
57237 | /***/ }),
|
57238 | /* 337 */
|
57239 | /***/ (function(module, exports, __webpack_require__) {
|
57240 |
|
57241 | "use strict";
|
57242 |
|
57243 |
|
57244 | var deepMap = __webpack_require__(1);
|
57245 |
|
57246 | function factory(type, config, load, typed) {
|
57247 | /**
|
57248 | * Calculate the cosine of a value.
|
57249 | *
|
57250 | * For matrices, the function is evaluated element wise.
|
57251 | *
|
57252 | * Syntax:
|
57253 | *
|
57254 | * math.cos(x)
|
57255 | *
|
57256 | * Examples:
|
57257 | *
|
57258 | * math.cos(2) // returns number -0.4161468365471422
|
57259 | * math.cos(math.pi / 4) // returns number 0.7071067811865475
|
57260 | * math.cos(math.unit(180, 'deg')) // returns number -1
|
57261 | * math.cos(math.unit(60, 'deg')) // returns number 0.5
|
57262 | *
|
57263 | * const angle = 0.2
|
57264 | * math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number ~1
|
57265 | *
|
57266 | * See also:
|
57267 | *
|
57268 | * cos, tan
|
57269 | *
|
57270 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x Function input
|
57271 | * @return {number | BigNumber | Complex | Array | Matrix} Cosine of x
|
57272 | */
|
57273 | var cos = typed('cos', {
|
57274 | 'number': Math.cos,
|
57275 | 'Complex': function Complex(x) {
|
57276 | return x.cos();
|
57277 | },
|
57278 | 'BigNumber': function BigNumber(x) {
|
57279 | return x.cos();
|
57280 | },
|
57281 | 'Unit': function Unit(x) {
|
57282 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
57283 | throw new TypeError('Unit in function cos is no angle');
|
57284 | }
|
57285 |
|
57286 | return cos(x.value);
|
57287 | },
|
57288 | 'Array | Matrix': function ArrayMatrix(x) {
|
57289 | return deepMap(x, cos);
|
57290 | }
|
57291 | });
|
57292 | cos.toTex = {
|
57293 | 1: "\\cos\\left(${args[0]}\\right)"
|
57294 | };
|
57295 | return cos;
|
57296 | }
|
57297 |
|
57298 | exports.name = 'cos';
|
57299 | exports.factory = factory;
|
57300 |
|
57301 | /***/ }),
|
57302 | /* 338 */
|
57303 | /***/ (function(module, exports, __webpack_require__) {
|
57304 |
|
57305 | "use strict";
|
57306 |
|
57307 |
|
57308 | var deepMap = __webpack_require__(1);
|
57309 |
|
57310 | function factory(type, config, load, typed) {
|
57311 | /**
|
57312 | * Calculate the hyperbolic cosine of a value,
|
57313 | * defined as `cosh(x) = 1/2 * (exp(x) + exp(-x))`.
|
57314 | *
|
57315 | * For matrices, the function is evaluated element wise.
|
57316 | *
|
57317 | * Syntax:
|
57318 | *
|
57319 | * math.cosh(x)
|
57320 | *
|
57321 | * Examples:
|
57322 | *
|
57323 | * math.cosh(0.5) // returns number 1.1276259652063807
|
57324 | *
|
57325 | * See also:
|
57326 | *
|
57327 | * sinh, tanh
|
57328 | *
|
57329 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x Function input
|
57330 | * @return {number | BigNumber | Complex | Array | Matrix} Hyperbolic cosine of x
|
57331 | */
|
57332 | var cosh = typed('cosh', {
|
57333 | 'number': _cosh,
|
57334 | 'Complex': function Complex(x) {
|
57335 | return x.cosh();
|
57336 | },
|
57337 | 'BigNumber': function BigNumber(x) {
|
57338 | return x.cosh();
|
57339 | },
|
57340 | 'Unit': function Unit(x) {
|
57341 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
57342 | throw new TypeError('Unit in function cosh is no angle');
|
57343 | }
|
57344 |
|
57345 | return cosh(x.value);
|
57346 | },
|
57347 | 'Array | Matrix': function ArrayMatrix(x) {
|
57348 | return deepMap(x, cosh);
|
57349 | }
|
57350 | });
|
57351 | cosh.toTex = {
|
57352 | 1: "\\cosh\\left(${args[0]}\\right)"
|
57353 | };
|
57354 | return cosh;
|
57355 | }
|
57356 | /**
|
57357 | * Calculate the hyperbolic cosine of a number
|
57358 | * @param {number} x
|
57359 | * @returns {number}
|
57360 | * @private
|
57361 | */
|
57362 |
|
57363 |
|
57364 | var _cosh = Math.cosh || function (x) {
|
57365 | return (Math.exp(x) + Math.exp(-x)) / 2;
|
57366 | };
|
57367 |
|
57368 | exports.name = 'cosh';
|
57369 | exports.factory = factory;
|
57370 |
|
57371 | /***/ }),
|
57372 | /* 339 */
|
57373 | /***/ (function(module, exports, __webpack_require__) {
|
57374 |
|
57375 | "use strict";
|
57376 |
|
57377 |
|
57378 | var deepMap = __webpack_require__(1);
|
57379 |
|
57380 | function factory(type, config, load, typed) {
|
57381 | /**
|
57382 | * Calculate the cotangent of a value. Defined as `cot(x) = 1 / tan(x)`.
|
57383 | *
|
57384 | * For matrices, the function is evaluated element wise.
|
57385 | *
|
57386 | * Syntax:
|
57387 | *
|
57388 | * math.cot(x)
|
57389 | *
|
57390 | * Examples:
|
57391 | *
|
57392 | * math.cot(2) // returns number -0.45765755436028577
|
57393 | * 1 / math.tan(2) // returns number -0.45765755436028577
|
57394 | *
|
57395 | * See also:
|
57396 | *
|
57397 | * tan, sec, csc
|
57398 | *
|
57399 | * @param {number | Complex | Unit | Array | Matrix} x Function input
|
57400 | * @return {number | Complex | Array | Matrix} Cotangent of x
|
57401 | */
|
57402 | var cot = typed('cot', {
|
57403 | 'number': function number(x) {
|
57404 | return 1 / Math.tan(x);
|
57405 | },
|
57406 | 'Complex': function Complex(x) {
|
57407 | return x.cot();
|
57408 | },
|
57409 | 'BigNumber': function BigNumber(x) {
|
57410 | return new type.BigNumber(1).div(x.tan());
|
57411 | },
|
57412 | 'Unit': function Unit(x) {
|
57413 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
57414 | throw new TypeError('Unit in function cot is no angle');
|
57415 | }
|
57416 |
|
57417 | return cot(x.value);
|
57418 | },
|
57419 | 'Array | Matrix': function ArrayMatrix(x) {
|
57420 | return deepMap(x, cot);
|
57421 | }
|
57422 | });
|
57423 | cot.toTex = {
|
57424 | 1: "\\cot\\left(${args[0]}\\right)"
|
57425 | };
|
57426 | return cot;
|
57427 | }
|
57428 |
|
57429 | exports.name = 'cot';
|
57430 | exports.factory = factory;
|
57431 |
|
57432 | /***/ }),
|
57433 | /* 340 */
|
57434 | /***/ (function(module, exports, __webpack_require__) {
|
57435 |
|
57436 | "use strict";
|
57437 |
|
57438 |
|
57439 | var deepMap = __webpack_require__(1);
|
57440 |
|
57441 | function factory(type, config, load, typed) {
|
57442 | /**
|
57443 | * Calculate the hyperbolic cotangent of a value,
|
57444 | * defined as `coth(x) = 1 / tanh(x)`.
|
57445 | *
|
57446 | * For matrices, the function is evaluated element wise.
|
57447 | *
|
57448 | * Syntax:
|
57449 | *
|
57450 | * math.coth(x)
|
57451 | *
|
57452 | * Examples:
|
57453 | *
|
57454 | * // coth(x) = 1 / tanh(x)
|
57455 | * math.coth(2) // returns 1.0373147207275482
|
57456 | * 1 / math.tanh(2) // returns 1.0373147207275482
|
57457 | *
|
57458 | * See also:
|
57459 | *
|
57460 | * sinh, tanh, cosh
|
57461 | *
|
57462 | * @param {number | Complex | Unit | Array | Matrix} x Function input
|
57463 | * @return {number | Complex | Array | Matrix} Hyperbolic cotangent of x
|
57464 | */
|
57465 | var coth = typed('coth', {
|
57466 | 'number': _coth,
|
57467 | 'Complex': function Complex(x) {
|
57468 | return x.coth();
|
57469 | },
|
57470 | 'BigNumber': function BigNumber(x) {
|
57471 | return new type.BigNumber(1).div(x.tanh());
|
57472 | },
|
57473 | 'Unit': function Unit(x) {
|
57474 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
57475 | throw new TypeError('Unit in function coth is no angle');
|
57476 | }
|
57477 |
|
57478 | return coth(x.value);
|
57479 | },
|
57480 | 'Array | Matrix': function ArrayMatrix(x) {
|
57481 | return deepMap(x, coth);
|
57482 | }
|
57483 | });
|
57484 | coth.toTex = {
|
57485 | 1: "\\coth\\left(${args[0]}\\right)"
|
57486 | };
|
57487 | return coth;
|
57488 | }
|
57489 | /**
|
57490 | * Calculate the hyperbolic cosine of a number
|
57491 | * @param {number} x
|
57492 | * @returns {number}
|
57493 | * @private
|
57494 | */
|
57495 |
|
57496 |
|
57497 | function _coth(x) {
|
57498 | var e = Math.exp(2 * x);
|
57499 | return (e + 1) / (e - 1);
|
57500 | }
|
57501 |
|
57502 | exports.name = 'coth';
|
57503 | exports.factory = factory;
|
57504 |
|
57505 | /***/ }),
|
57506 | /* 341 */
|
57507 | /***/ (function(module, exports, __webpack_require__) {
|
57508 |
|
57509 | "use strict";
|
57510 |
|
57511 |
|
57512 | var deepMap = __webpack_require__(1);
|
57513 |
|
57514 | function factory(type, config, load, typed) {
|
57515 | /**
|
57516 | * Calculate the cosecant of a value, defined as `csc(x) = 1/sin(x)`.
|
57517 | *
|
57518 | * For matrices, the function is evaluated element wise.
|
57519 | *
|
57520 | * Syntax:
|
57521 | *
|
57522 | * math.csc(x)
|
57523 | *
|
57524 | * Examples:
|
57525 | *
|
57526 | * math.csc(2) // returns number 1.099750170294617
|
57527 | * 1 / math.sin(2) // returns number 1.099750170294617
|
57528 | *
|
57529 | * See also:
|
57530 | *
|
57531 | * sin, sec, cot
|
57532 | *
|
57533 | * @param {number | Complex | Unit | Array | Matrix} x Function input
|
57534 | * @return {number | Complex | Array | Matrix} Cosecant of x
|
57535 | */
|
57536 | var csc = typed('csc', {
|
57537 | 'number': function number(x) {
|
57538 | return 1 / Math.sin(x);
|
57539 | },
|
57540 | 'Complex': function Complex(x) {
|
57541 | return x.csc();
|
57542 | },
|
57543 | 'BigNumber': function BigNumber(x) {
|
57544 | return new type.BigNumber(1).div(x.sin());
|
57545 | },
|
57546 | 'Unit': function Unit(x) {
|
57547 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
57548 | throw new TypeError('Unit in function csc is no angle');
|
57549 | }
|
57550 |
|
57551 | return csc(x.value);
|
57552 | },
|
57553 | 'Array | Matrix': function ArrayMatrix(x) {
|
57554 | return deepMap(x, csc);
|
57555 | }
|
57556 | });
|
57557 | csc.toTex = {
|
57558 | 1: "\\csc\\left(${args[0]}\\right)"
|
57559 | };
|
57560 | return csc;
|
57561 | }
|
57562 |
|
57563 | exports.name = 'csc';
|
57564 | exports.factory = factory;
|
57565 |
|
57566 | /***/ }),
|
57567 | /* 342 */
|
57568 | /***/ (function(module, exports, __webpack_require__) {
|
57569 |
|
57570 | "use strict";
|
57571 |
|
57572 |
|
57573 | var deepMap = __webpack_require__(1);
|
57574 |
|
57575 | var sign = __webpack_require__(3).sign;
|
57576 |
|
57577 | function factory(type, config, load, typed) {
|
57578 | /**
|
57579 | * Calculate the hyperbolic cosecant of a value,
|
57580 | * defined as `csch(x) = 1 / sinh(x)`.
|
57581 | *
|
57582 | * For matrices, the function is evaluated element wise.
|
57583 | *
|
57584 | * Syntax:
|
57585 | *
|
57586 | * math.csch(x)
|
57587 | *
|
57588 | * Examples:
|
57589 | *
|
57590 | * // csch(x) = 1/ sinh(x)
|
57591 | * math.csch(0.5) // returns 1.9190347513349437
|
57592 | * 1 / math.sinh(0.5) // returns 1.9190347513349437
|
57593 | *
|
57594 | * See also:
|
57595 | *
|
57596 | * sinh, sech, coth
|
57597 | *
|
57598 | * @param {number | Complex | Unit | Array | Matrix} x Function input
|
57599 | * @return {number | Complex | Array | Matrix} Hyperbolic cosecant of x
|
57600 | */
|
57601 | var csch = typed('csch', {
|
57602 | 'number': _csch,
|
57603 | 'Complex': function Complex(x) {
|
57604 | return x.csch();
|
57605 | },
|
57606 | 'BigNumber': function BigNumber(x) {
|
57607 | return new type.BigNumber(1).div(x.sinh());
|
57608 | },
|
57609 | 'Unit': function Unit(x) {
|
57610 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
57611 | throw new TypeError('Unit in function csch is no angle');
|
57612 | }
|
57613 |
|
57614 | return csch(x.value);
|
57615 | },
|
57616 | 'Array | Matrix': function ArrayMatrix(x) {
|
57617 | return deepMap(x, csch);
|
57618 | }
|
57619 | });
|
57620 | csch.toTex = {
|
57621 | 1: "\\mathrm{csch}\\left(${args[0]}\\right)"
|
57622 | };
|
57623 | return csch;
|
57624 | }
|
57625 | /**
|
57626 | * Calculate the hyperbolic cosecant of a number
|
57627 | * @param {number} x
|
57628 | * @returns {number}
|
57629 | * @private
|
57630 | */
|
57631 |
|
57632 |
|
57633 | function _csch(x) {
|
57634 | // consider values close to zero (+/-)
|
57635 | if (x === 0) {
|
57636 | return Number.POSITIVE_INFINITY;
|
57637 | } else {
|
57638 | return Math.abs(2 / (Math.exp(x) - Math.exp(-x))) * sign(x);
|
57639 | }
|
57640 | }
|
57641 |
|
57642 | exports.name = 'csch';
|
57643 | exports.factory = factory;
|
57644 |
|
57645 | /***/ }),
|
57646 | /* 343 */
|
57647 | /***/ (function(module, exports, __webpack_require__) {
|
57648 |
|
57649 | "use strict";
|
57650 |
|
57651 |
|
57652 | var deepMap = __webpack_require__(1);
|
57653 |
|
57654 | function factory(type, config, load, typed) {
|
57655 | /**
|
57656 | * Calculate the secant of a value, defined as `sec(x) = 1/cos(x)`.
|
57657 | *
|
57658 | * For matrices, the function is evaluated element wise.
|
57659 | *
|
57660 | * Syntax:
|
57661 | *
|
57662 | * math.sec(x)
|
57663 | *
|
57664 | * Examples:
|
57665 | *
|
57666 | * math.sec(2) // returns number -2.4029979617223822
|
57667 | * 1 / math.cos(2) // returns number -2.4029979617223822
|
57668 | *
|
57669 | * See also:
|
57670 | *
|
57671 | * cos, csc, cot
|
57672 | *
|
57673 | * @param {number | Complex | Unit | Array | Matrix} x Function input
|
57674 | * @return {number | Complex | Array | Matrix} Secant of x
|
57675 | */
|
57676 | var sec = typed('sec', {
|
57677 | 'number': function number(x) {
|
57678 | return 1 / Math.cos(x);
|
57679 | },
|
57680 | 'Complex': function Complex(x) {
|
57681 | return x.sec();
|
57682 | },
|
57683 | 'BigNumber': function BigNumber(x) {
|
57684 | return new type.BigNumber(1).div(x.cos());
|
57685 | },
|
57686 | 'Unit': function Unit(x) {
|
57687 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
57688 | throw new TypeError('Unit in function sec is no angle');
|
57689 | }
|
57690 |
|
57691 | return sec(x.value);
|
57692 | },
|
57693 | 'Array | Matrix': function ArrayMatrix(x) {
|
57694 | return deepMap(x, sec);
|
57695 | }
|
57696 | });
|
57697 | sec.toTex = {
|
57698 | 1: "\\sec\\left(${args[0]}\\right)"
|
57699 | };
|
57700 | return sec;
|
57701 | }
|
57702 |
|
57703 | exports.name = 'sec';
|
57704 | exports.factory = factory;
|
57705 |
|
57706 | /***/ }),
|
57707 | /* 344 */
|
57708 | /***/ (function(module, exports, __webpack_require__) {
|
57709 |
|
57710 | "use strict";
|
57711 |
|
57712 |
|
57713 | var deepMap = __webpack_require__(1);
|
57714 |
|
57715 | function factory(type, config, load, typed) {
|
57716 | /**
|
57717 | * Calculate the hyperbolic secant of a value,
|
57718 | * defined as `sech(x) = 1 / cosh(x)`.
|
57719 | *
|
57720 | * For matrices, the function is evaluated element wise.
|
57721 | *
|
57722 | * Syntax:
|
57723 | *
|
57724 | * math.sech(x)
|
57725 | *
|
57726 | * Examples:
|
57727 | *
|
57728 | * // sech(x) = 1/ cosh(x)
|
57729 | * math.sech(0.5) // returns 0.886818883970074
|
57730 | * 1 / math.cosh(0.5) // returns 0.886818883970074
|
57731 | *
|
57732 | * See also:
|
57733 | *
|
57734 | * cosh, csch, coth
|
57735 | *
|
57736 | * @param {number | Complex | Unit | Array | Matrix} x Function input
|
57737 | * @return {number | Complex | Array | Matrix} Hyperbolic secant of x
|
57738 | */
|
57739 | var sech = typed('sech', {
|
57740 | 'number': _sech,
|
57741 | 'Complex': function Complex(x) {
|
57742 | return x.sech();
|
57743 | },
|
57744 | 'BigNumber': function BigNumber(x) {
|
57745 | return new type.BigNumber(1).div(x.cosh());
|
57746 | },
|
57747 | 'Unit': function Unit(x) {
|
57748 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
57749 | throw new TypeError('Unit in function sech is no angle');
|
57750 | }
|
57751 |
|
57752 | return sech(x.value);
|
57753 | },
|
57754 | 'Array | Matrix': function ArrayMatrix(x) {
|
57755 | return deepMap(x, sech);
|
57756 | }
|
57757 | });
|
57758 | sech.toTex = {
|
57759 | 1: "\\mathrm{sech}\\left(${args[0]}\\right)"
|
57760 | };
|
57761 | return sech;
|
57762 | }
|
57763 | /**
|
57764 | * Calculate the hyperbolic secant of a number
|
57765 | * @param {number} x
|
57766 | * @returns {number}
|
57767 | * @private
|
57768 | */
|
57769 |
|
57770 |
|
57771 | function _sech(x) {
|
57772 | return 2 / (Math.exp(x) + Math.exp(-x));
|
57773 | }
|
57774 |
|
57775 | exports.name = 'sech';
|
57776 | exports.factory = factory;
|
57777 |
|
57778 | /***/ }),
|
57779 | /* 345 */
|
57780 | /***/ (function(module, exports, __webpack_require__) {
|
57781 |
|
57782 | "use strict";
|
57783 |
|
57784 |
|
57785 | var deepMap = __webpack_require__(1);
|
57786 |
|
57787 | function factory(type, config, load, typed) {
|
57788 | /**
|
57789 | * Calculate the sine of a value.
|
57790 | *
|
57791 | * For matrices, the function is evaluated element wise.
|
57792 | *
|
57793 | * Syntax:
|
57794 | *
|
57795 | * math.sin(x)
|
57796 | *
|
57797 | * Examples:
|
57798 | *
|
57799 | * math.sin(2) // returns number 0.9092974268256813
|
57800 | * math.sin(math.pi / 4) // returns number 0.7071067811865475
|
57801 | * math.sin(math.unit(90, 'deg')) // returns number 1
|
57802 | * math.sin(math.unit(30, 'deg')) // returns number 0.5
|
57803 | *
|
57804 | * const angle = 0.2
|
57805 | * math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2) // returns number ~1
|
57806 | *
|
57807 | * See also:
|
57808 | *
|
57809 | * cos, tan
|
57810 | *
|
57811 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x Function input
|
57812 | * @return {number | BigNumber | Complex | Array | Matrix} Sine of x
|
57813 | */
|
57814 | var sin = typed('sin', {
|
57815 | 'number': Math.sin,
|
57816 | 'Complex': function Complex(x) {
|
57817 | return x.sin();
|
57818 | },
|
57819 | 'BigNumber': function BigNumber(x) {
|
57820 | return x.sin();
|
57821 | },
|
57822 | 'Unit': function Unit(x) {
|
57823 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
57824 | throw new TypeError('Unit in function sin is no angle');
|
57825 | }
|
57826 |
|
57827 | return sin(x.value);
|
57828 | },
|
57829 | 'Array | Matrix': function ArrayMatrix(x) {
|
57830 | // deep map collection, skip zeros since sin(0) = 0
|
57831 | return deepMap(x, sin, true);
|
57832 | }
|
57833 | });
|
57834 | sin.toTex = {
|
57835 | 1: "\\sin\\left(${args[0]}\\right)"
|
57836 | };
|
57837 | return sin;
|
57838 | }
|
57839 |
|
57840 | exports.name = 'sin';
|
57841 | exports.factory = factory;
|
57842 |
|
57843 | /***/ }),
|
57844 | /* 346 */
|
57845 | /***/ (function(module, exports, __webpack_require__) {
|
57846 |
|
57847 | "use strict";
|
57848 |
|
57849 |
|
57850 | var deepMap = __webpack_require__(1);
|
57851 |
|
57852 | function factory(type, config, load, typed) {
|
57853 | /**
|
57854 | * Calculate the hyperbolic sine of a value,
|
57855 | * defined as `sinh(x) = 1/2 * (exp(x) - exp(-x))`.
|
57856 | *
|
57857 | * For matrices, the function is evaluated element wise.
|
57858 | *
|
57859 | * Syntax:
|
57860 | *
|
57861 | * math.sinh(x)
|
57862 | *
|
57863 | * Examples:
|
57864 | *
|
57865 | * math.sinh(0.5) // returns number 0.5210953054937474
|
57866 | *
|
57867 | * See also:
|
57868 | *
|
57869 | * cosh, tanh
|
57870 | *
|
57871 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x Function input
|
57872 | * @return {number | BigNumber | Complex | Array | Matrix} Hyperbolic sine of x
|
57873 | */
|
57874 | var sinh = typed('sinh', {
|
57875 | 'number': _sinh,
|
57876 | 'Complex': function Complex(x) {
|
57877 | return x.sinh();
|
57878 | },
|
57879 | 'BigNumber': function BigNumber(x) {
|
57880 | return x.sinh();
|
57881 | },
|
57882 | 'Unit': function Unit(x) {
|
57883 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
57884 | throw new TypeError('Unit in function sinh is no angle');
|
57885 | }
|
57886 |
|
57887 | return sinh(x.value);
|
57888 | },
|
57889 | 'Array | Matrix': function ArrayMatrix(x) {
|
57890 | // deep map collection, skip zeros since sinh(0) = 0
|
57891 | return deepMap(x, sinh, true);
|
57892 | }
|
57893 | });
|
57894 | sinh.toTex = {
|
57895 | 1: "\\sinh\\left(${args[0]}\\right)"
|
57896 | };
|
57897 | return sinh;
|
57898 | }
|
57899 | /**
|
57900 | * Calculate the hyperbolic sine of a number
|
57901 | * @param {number} x
|
57902 | * @returns {number}
|
57903 | * @private
|
57904 | */
|
57905 |
|
57906 |
|
57907 | var _sinh = Math.sinh || function (x) {
|
57908 | return (Math.exp(x) - Math.exp(-x)) / 2;
|
57909 | };
|
57910 |
|
57911 | exports.name = 'sinh';
|
57912 | exports.factory = factory;
|
57913 |
|
57914 | /***/ }),
|
57915 | /* 347 */
|
57916 | /***/ (function(module, exports, __webpack_require__) {
|
57917 |
|
57918 | "use strict";
|
57919 |
|
57920 |
|
57921 | var deepMap = __webpack_require__(1);
|
57922 |
|
57923 | function factory(type, config, load, typed) {
|
57924 | /**
|
57925 | * Calculate the tangent of a value. `tan(x)` is equal to `sin(x) / cos(x)`.
|
57926 | *
|
57927 | * For matrices, the function is evaluated element wise.
|
57928 | *
|
57929 | * Syntax:
|
57930 | *
|
57931 | * math.tan(x)
|
57932 | *
|
57933 | * Examples:
|
57934 | *
|
57935 | * math.tan(0.5) // returns number 0.5463024898437905
|
57936 | * math.sin(0.5) / math.cos(0.5) // returns number 0.5463024898437905
|
57937 | * math.tan(math.pi / 4) // returns number 1
|
57938 | * math.tan(math.unit(45, 'deg')) // returns number 1
|
57939 | *
|
57940 | * See also:
|
57941 | *
|
57942 | * atan, sin, cos
|
57943 | *
|
57944 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x Function input
|
57945 | * @return {number | BigNumber | Complex | Array | Matrix} Tangent of x
|
57946 | */
|
57947 | var tan = typed('tan', {
|
57948 | 'number': Math.tan,
|
57949 | 'Complex': function Complex(x) {
|
57950 | return x.tan();
|
57951 | },
|
57952 | 'BigNumber': function BigNumber(x) {
|
57953 | return x.tan();
|
57954 | },
|
57955 | 'Unit': function Unit(x) {
|
57956 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
57957 | throw new TypeError('Unit in function tan is no angle');
|
57958 | }
|
57959 |
|
57960 | return tan(x.value);
|
57961 | },
|
57962 | 'Array | Matrix': function ArrayMatrix(x) {
|
57963 | // deep map collection, skip zeros since tan(0) = 0
|
57964 | return deepMap(x, tan, true);
|
57965 | }
|
57966 | });
|
57967 | tan.toTex = {
|
57968 | 1: "\\tan\\left(${args[0]}\\right)"
|
57969 | };
|
57970 | return tan;
|
57971 | }
|
57972 |
|
57973 | exports.name = 'tan';
|
57974 | exports.factory = factory;
|
57975 |
|
57976 | /***/ }),
|
57977 | /* 348 */
|
57978 | /***/ (function(module, exports, __webpack_require__) {
|
57979 |
|
57980 | "use strict";
|
57981 |
|
57982 |
|
57983 | var deepMap = __webpack_require__(1);
|
57984 |
|
57985 | function factory(type, config, load, typed) {
|
57986 | /**
|
57987 | * Calculate the hyperbolic tangent of a value,
|
57988 | * defined as `tanh(x) = (exp(2 * x) - 1) / (exp(2 * x) + 1)`.
|
57989 | *
|
57990 | * For matrices, the function is evaluated element wise.
|
57991 | *
|
57992 | * Syntax:
|
57993 | *
|
57994 | * math.tanh(x)
|
57995 | *
|
57996 | * Examples:
|
57997 | *
|
57998 | * // tanh(x) = sinh(x) / cosh(x) = 1 / coth(x)
|
57999 | * math.tanh(0.5) // returns 0.46211715726000974
|
58000 | * math.sinh(0.5) / math.cosh(0.5) // returns 0.46211715726000974
|
58001 | * 1 / math.coth(0.5) // returns 0.46211715726000974
|
58002 | *
|
58003 | * See also:
|
58004 | *
|
58005 | * sinh, cosh, coth
|
58006 | *
|
58007 | * @param {number | BigNumber | Complex | Unit | Array | Matrix} x Function input
|
58008 | * @return {number | BigNumber | Complex | Array | Matrix} Hyperbolic tangent of x
|
58009 | */
|
58010 | var tanh = typed('tanh', {
|
58011 | 'number': _tanh,
|
58012 | 'Complex': function Complex(x) {
|
58013 | return x.tanh();
|
58014 | },
|
58015 | 'BigNumber': function BigNumber(x) {
|
58016 | return x.tanh();
|
58017 | },
|
58018 | 'Unit': function Unit(x) {
|
58019 | if (!x.hasBase(type.Unit.BASE_UNITS.ANGLE)) {
|
58020 | throw new TypeError('Unit in function tanh is no angle');
|
58021 | }
|
58022 |
|
58023 | return tanh(x.value);
|
58024 | },
|
58025 | 'Array | Matrix': function ArrayMatrix(x) {
|
58026 | // deep map collection, skip zeros since tanh(0) = 0
|
58027 | return deepMap(x, tanh, true);
|
58028 | }
|
58029 | });
|
58030 | tanh.toTex = {
|
58031 | 1: "\\tanh\\left(${args[0]}\\right)"
|
58032 | };
|
58033 | return tanh;
|
58034 | }
|
58035 | /**
|
58036 | * Calculate the hyperbolic tangent of a number
|
58037 | * @param {number} x
|
58038 | * @returns {number}
|
58039 | * @private
|
58040 | */
|
58041 |
|
58042 |
|
58043 | var _tanh = Math.tanh || function (x) {
|
58044 | var e = Math.exp(2 * x);
|
58045 | return (e - 1) / (e + 1);
|
58046 | };
|
58047 |
|
58048 | exports.name = 'tanh';
|
58049 | exports.factory = factory;
|
58050 |
|
58051 | /***/ }),
|
58052 | /* 349 */
|
58053 | /***/ (function(module, exports, __webpack_require__) {
|
58054 |
|
58055 | "use strict";
|
58056 |
|
58057 |
|
58058 | module.exports = [__webpack_require__(350)];
|
58059 |
|
58060 | /***/ }),
|
58061 | /* 350 */
|
58062 | /***/ (function(module, exports, __webpack_require__) {
|
58063 |
|
58064 | "use strict";
|
58065 |
|
58066 |
|
58067 | function factory(type, config, load, typed) {
|
58068 | var latex = __webpack_require__(4);
|
58069 |
|
58070 | var matrix = load(__webpack_require__(0));
|
58071 | var algorithm13 = load(__webpack_require__(7));
|
58072 | var algorithm14 = load(__webpack_require__(6));
|
58073 | /**
|
58074 | * Change the unit of a value.
|
58075 | *
|
58076 | * For matrices, the function is evaluated element wise.
|
58077 | *
|
58078 | * Syntax:
|
58079 | *
|
58080 | * math.to(x, unit)
|
58081 | *
|
58082 | * Examples:
|
58083 | *
|
58084 | * math.to(math.unit('2 inch'), 'cm') // returns Unit 5.08 cm
|
58085 | * math.to(math.unit('2 inch'), math.unit(null, 'cm')) // returns Unit 5.08 cm
|
58086 | * math.to(math.unit(16, 'bytes'), 'bits') // returns Unit 128 bits
|
58087 | *
|
58088 | * See also:
|
58089 | *
|
58090 | * unit
|
58091 | *
|
58092 | * @param {Unit | Array | Matrix} x The unit to be converted.
|
58093 | * @param {Unit | Array | Matrix} unit New unit. Can be a string like "cm"
|
58094 | * or a unit without value.
|
58095 | * @return {Unit | Array | Matrix} value with changed, fixed unit.
|
58096 | */
|
58097 |
|
58098 | var to = typed('to', {
|
58099 | 'Unit, Unit | string': function UnitUnitString(x, unit) {
|
58100 | return x.to(unit);
|
58101 | },
|
58102 | 'Matrix, Matrix': function MatrixMatrix(x, y) {
|
58103 | // SparseMatrix does not support Units
|
58104 | return algorithm13(x, y, to);
|
58105 | },
|
58106 | 'Array, Array': function ArrayArray(x, y) {
|
58107 | // use matrix implementation
|
58108 | return to(matrix(x), matrix(y)).valueOf();
|
58109 | },
|
58110 | 'Array, Matrix': function ArrayMatrix(x, y) {
|
58111 | // use matrix implementation
|
58112 | return to(matrix(x), y);
|
58113 | },
|
58114 | 'Matrix, Array': function MatrixArray(x, y) {
|
58115 | // use matrix implementation
|
58116 | return to(x, matrix(y));
|
58117 | },
|
58118 | 'Matrix, any': function MatrixAny(x, y) {
|
58119 | // SparseMatrix does not support Units
|
58120 | return algorithm14(x, y, to, false);
|
58121 | },
|
58122 | 'any, Matrix': function anyMatrix(x, y) {
|
58123 | // SparseMatrix does not support Units
|
58124 | return algorithm14(y, x, to, true);
|
58125 | },
|
58126 | 'Array, any': function ArrayAny(x, y) {
|
58127 | // use matrix implementation
|
58128 | return algorithm14(matrix(x), y, to, false).valueOf();
|
58129 | },
|
58130 | 'any, Array': function anyArray(x, y) {
|
58131 | // use matrix implementation
|
58132 | return algorithm14(matrix(y), x, to, true).valueOf();
|
58133 | }
|
58134 | });
|
58135 | to.toTex = {
|
58136 | 2: "\\left(${args[0]}".concat(latex.operators['to'], "${args[1]}\\right)")
|
58137 | };
|
58138 | return to;
|
58139 | }
|
58140 |
|
58141 | exports.name = 'to';
|
58142 | exports.factory = factory;
|
58143 |
|
58144 | /***/ }),
|
58145 | /* 351 */
|
58146 | /***/ (function(module, exports, __webpack_require__) {
|
58147 |
|
58148 | "use strict";
|
58149 |
|
58150 |
|
58151 | module.exports = [__webpack_require__(352), __webpack_require__(34), __webpack_require__(61), __webpack_require__(52), __webpack_require__(353), __webpack_require__(73), __webpack_require__(354), __webpack_require__(60), __webpack_require__(79), __webpack_require__(26)];
|
58152 |
|
58153 | /***/ }),
|
58154 | /* 352 */
|
58155 | /***/ (function(module, exports, __webpack_require__) {
|
58156 |
|
58157 | "use strict";
|
58158 |
|
58159 |
|
58160 | var object = __webpack_require__(5);
|
58161 |
|
58162 | function factory(type, config, load, typed) {
|
58163 | /**
|
58164 | * Clone an object.
|
58165 | *
|
58166 | * Syntax:
|
58167 | *
|
58168 | * math.clone(x)
|
58169 | *
|
58170 | * Examples:
|
58171 | *
|
58172 | * math.clone(3.5) // returns number 3.5
|
58173 | * math.clone(math.complex('2-4i') // returns Complex 2 - 4i
|
58174 | * math.clone(math.unit(45, 'deg')) // returns Unit 45 deg
|
58175 | * math.clone([[1, 2], [3, 4]]) // returns Array [[1, 2], [3, 4]]
|
58176 | * math.clone("hello world") // returns string "hello world"
|
58177 | *
|
58178 | * @param {*} x Object to be cloned
|
58179 | * @return {*} A clone of object x
|
58180 | */
|
58181 | var clone = typed('clone', {
|
58182 | 'any': object.clone
|
58183 | });
|
58184 | clone.toTex = undefined; // use default template
|
58185 |
|
58186 | return clone;
|
58187 | }
|
58188 |
|
58189 | exports.name = 'clone';
|
58190 | exports.factory = factory;
|
58191 |
|
58192 | /***/ }),
|
58193 | /* 353 */
|
58194 | /***/ (function(module, exports, __webpack_require__) {
|
58195 |
|
58196 | "use strict";
|
58197 |
|
58198 |
|
58199 | function factory(type, config, load, typed) {
|
58200 | var isNumeric = load(__webpack_require__(52));
|
58201 | /**
|
58202 | * Test whether a value is an numeric value.
|
58203 | *
|
58204 | * In case of a string, true is returned if the string contains a numeric value.
|
58205 | *
|
58206 | * Syntax:
|
58207 | *
|
58208 | * math.hasNumericValue(x)
|
58209 | *
|
58210 | * Examples:
|
58211 | *
|
58212 | * math.hasNumericValue(2) // returns true
|
58213 | * math.hasNumericValue('2') // returns true
|
58214 | * math.isNumeric('2') // returns false
|
58215 | * math.hasNumericValue(0) // returns true
|
58216 | * math.hasNumericValue(math.bignumber(500)) // returns true
|
58217 | * math.hasNumericValue(math.fraction(4)) // returns true
|
58218 | * math.hasNumericValue(math.complex('2-4i') // returns false
|
58219 | * math.hasNumericValue([2.3, 'foo', false]) // returns [true, false, true]
|
58220 | *
|
58221 | * See also:
|
58222 | *
|
58223 | * isZero, isPositive, isNegative, isInteger, isNumeric
|
58224 | *
|
58225 | * @param {*} x Value to be tested
|
58226 | * @return {boolean} Returns true when `x` is a `number`, `BigNumber`,
|
58227 | * `Fraction`, `Boolean`, or a `String` containing number. Returns false for other types.
|
58228 | * Throws an error in case of unknown types.
|
58229 | */
|
58230 |
|
58231 | var hasNumericValue = typed('hasNumericValue', {
|
58232 | 'string': function string(x) {
|
58233 | return x.trim().length > 0 && !isNaN(Number(x));
|
58234 | },
|
58235 | 'any': function any(x) {
|
58236 | return isNumeric(x);
|
58237 | }
|
58238 | });
|
58239 | return hasNumericValue;
|
58240 | }
|
58241 |
|
58242 | exports.name = 'hasNumericValue';
|
58243 | exports.factory = factory;
|
58244 |
|
58245 | /***/ }),
|
58246 | /* 354 */
|
58247 | /***/ (function(module, exports, __webpack_require__) {
|
58248 |
|
58249 | "use strict";
|
58250 |
|
58251 |
|
58252 | var deepMap = __webpack_require__(1);
|
58253 |
|
58254 | function factory(type, config, load, typed) {
|
58255 | /**
|
58256 | * Test whether a value is prime: has no divisors other than itself and one.
|
58257 | * The function supports type `number`, `bignumber`.
|
58258 | *
|
58259 | * The function is evaluated element-wise in case of Array or Matrix input.
|
58260 | *
|
58261 | * Syntax:
|
58262 | *
|
58263 | * math.isPrime(x)
|
58264 | *
|
58265 | * Examples:
|
58266 | *
|
58267 | * math.isPrime(3) // returns true
|
58268 | * math.isPrime(-2) // returns false
|
58269 | * math.isPrime(0) // returns false
|
58270 | * math.isPrime(-0) // returns false
|
58271 | * math.isPrime(0.5) // returns false
|
58272 | * math.isPrime('2') // returns true
|
58273 | * math.isPrime([2, 17, 100]) // returns [true, true, false]
|
58274 | *
|
58275 | * See also:
|
58276 | *
|
58277 | * isNumeric, isZero, isNegative, isInteger
|
58278 | *
|
58279 | * @param {number | BigNumber | Array | Matrix} x Value to be tested
|
58280 | * @return {boolean} Returns true when `x` is larger than zero.
|
58281 | * Throws an error in case of an unknown data type.
|
58282 | */
|
58283 | var isPrime = typed('isPrime', {
|
58284 | 'number': function number(x) {
|
58285 | if (x < 2) {
|
58286 | return false;
|
58287 | }
|
58288 |
|
58289 | if (x === 2) {
|
58290 | return true;
|
58291 | }
|
58292 |
|
58293 | if (x % 2 === 0) {
|
58294 | return false;
|
58295 | }
|
58296 |
|
58297 | for (var i = 3; i * i <= x; i += 2) {
|
58298 | if (x % i === 0) {
|
58299 | return false;
|
58300 | }
|
58301 | }
|
58302 |
|
58303 | return true;
|
58304 | },
|
58305 | 'BigNumber': function BigNumber(x) {
|
58306 | if (x.lt(2)) {
|
58307 | return false;
|
58308 | }
|
58309 |
|
58310 | if (x.equals(2)) {
|
58311 | return true;
|
58312 | }
|
58313 |
|
58314 | if (x.mod(2).isZero()) {
|
58315 | return false;
|
58316 | }
|
58317 |
|
58318 | for (var i = type.BigNumber(3); i.times(i).lte(x); i = i.plus(1)) {
|
58319 | if (x.mod(i).isZero()) {
|
58320 | return false;
|
58321 | }
|
58322 | }
|
58323 |
|
58324 | return true;
|
58325 | },
|
58326 | 'Array | Matrix': function ArrayMatrix(x) {
|
58327 | return deepMap(x, isPrime);
|
58328 | }
|
58329 | });
|
58330 | return isPrime;
|
58331 | }
|
58332 |
|
58333 | exports.name = 'isPrime';
|
58334 | exports.factory = factory;
|
58335 |
|
58336 | /***/ }),
|
58337 | /* 355 */
|
58338 | /***/ (function(module, exports, __webpack_require__) {
|
58339 |
|
58340 | "use strict";
|
58341 |
|
58342 |
|
58343 | module.exports = [// Note that the docs folder is called "embeddedDocs" and not "docs" to prevent issues
|
58344 | // with yarn autoclean. See https://github.com/josdejong/mathjs/issues/969
|
58345 | __webpack_require__(155), __webpack_require__(561), __webpack_require__(565), __webpack_require__(567), __webpack_require__(584), __webpack_require__(44), __webpack_require__(159)];
|
58346 |
|
58347 | /***/ }),
|
58348 | /* 356 */
|
58349 | /***/ (function(module, exports) {
|
58350 |
|
58351 | module.exports = {
|
58352 | 'name': 'bignumber',
|
58353 | 'category': 'Construction',
|
58354 | 'syntax': ['bignumber(x)'],
|
58355 | 'description': 'Create a big number from a number or string.',
|
58356 | 'examples': ['0.1 + 0.2', 'bignumber(0.1) + bignumber(0.2)', 'bignumber("7.2")', 'bignumber("7.2e500")', 'bignumber([0.1, 0.2, 0.3])'],
|
58357 | 'seealso': ['boolean', 'complex', 'fraction', 'index', 'matrix', 'string', 'unit']
|
58358 | };
|
58359 |
|
58360 | /***/ }),
|
58361 | /* 357 */
|
58362 | /***/ (function(module, exports) {
|
58363 |
|
58364 | module.exports = {
|
58365 | 'name': 'boolean',
|
58366 | 'category': 'Construction',
|
58367 | 'syntax': ['x', 'boolean(x)'],
|
58368 | 'description': 'Convert a string or number into a boolean.',
|
58369 | 'examples': ['boolean(0)', 'boolean(1)', 'boolean(3)', 'boolean("true")', 'boolean("false")', 'boolean([1, 0, 1, 1])'],
|
58370 | 'seealso': ['bignumber', 'complex', 'index', 'matrix', 'number', 'string', 'unit']
|
58371 | };
|
58372 |
|
58373 | /***/ }),
|
58374 | /* 358 */
|
58375 | /***/ (function(module, exports) {
|
58376 |
|
58377 | module.exports = {
|
58378 | 'name': 'complex',
|
58379 | 'category': 'Construction',
|
58380 | 'syntax': ['complex()', 'complex(re, im)', 'complex(string)'],
|
58381 | 'description': 'Create a complex number.',
|
58382 | 'examples': ['complex()', 'complex(2, 3)', 'complex("7 - 2i")'],
|
58383 | 'seealso': ['bignumber', 'boolean', 'index', 'matrix', 'number', 'string', 'unit']
|
58384 | };
|
58385 |
|
58386 | /***/ }),
|
58387 | /* 359 */
|
58388 | /***/ (function(module, exports) {
|
58389 |
|
58390 | module.exports = {
|
58391 | 'name': 'createUnit',
|
58392 | 'category': 'Construction',
|
58393 | 'syntax': ['createUnit(definitions)', 'createUnit(name, definition)'],
|
58394 | 'description': 'Create a user-defined unit and register it with the Unit type.',
|
58395 | 'examples': ['createUnit("foo")', 'createUnit("knot", {definition: "0.514444444 m/s", aliases: ["knots", "kt", "kts"]})', 'createUnit("mph", "1 mile/hour")'],
|
58396 | 'seealso': ['unit', 'splitUnit']
|
58397 | };
|
58398 |
|
58399 | /***/ }),
|
58400 | /* 360 */
|
58401 | /***/ (function(module, exports) {
|
58402 |
|
58403 | module.exports = {
|
58404 | 'name': 'fraction',
|
58405 | 'category': 'Construction',
|
58406 | 'syntax': ['fraction(num)', 'fraction(num,den)'],
|
58407 | 'description': 'Create a fraction from a number or from a numerator and denominator.',
|
58408 | 'examples': ['fraction(0.125)', 'fraction(1, 3) + fraction(2, 5)'],
|
58409 | 'seealso': ['bignumber', 'boolean', 'complex', 'index', 'matrix', 'string', 'unit']
|
58410 | };
|
58411 |
|
58412 | /***/ }),
|
58413 | /* 361 */
|
58414 | /***/ (function(module, exports) {
|
58415 |
|
58416 | module.exports = {
|
58417 | 'name': 'index',
|
58418 | 'category': 'Construction',
|
58419 | 'syntax': ['[start]', '[start:end]', '[start:step:end]', '[start1, start 2, ...]', '[start1:end1, start2:end2, ...]', '[start1:step1:end1, start2:step2:end2, ...]'],
|
58420 | 'description': 'Create an index to get or replace a subset of a matrix',
|
58421 | 'examples': ['[]', '[1, 2, 3]', 'A = [1, 2, 3; 4, 5, 6]', 'A[1, :]', 'A[1, 2] = 50', 'A[0:2, 0:2] = ones(2, 2)'],
|
58422 | 'seealso': ['bignumber', 'boolean', 'complex', 'matrix,', 'number', 'range', 'string', 'unit']
|
58423 | };
|
58424 |
|
58425 | /***/ }),
|
58426 | /* 362 */
|
58427 | /***/ (function(module, exports) {
|
58428 |
|
58429 | module.exports = {
|
58430 | 'name': 'matrix',
|
58431 | 'category': 'Construction',
|
58432 | 'syntax': ['[]', '[a1, b1, ...; a2, b2, ...]', 'matrix()', 'matrix("dense")', 'matrix([...])'],
|
58433 | 'description': 'Create a matrix.',
|
58434 | 'examples': ['[]', '[1, 2, 3]', '[1, 2, 3; 4, 5, 6]', 'matrix()', 'matrix([3, 4])', 'matrix([3, 4; 5, 6], "sparse")', 'matrix([3, 4; 5, 6], "sparse", "number")'],
|
58435 | 'seealso': ['bignumber', 'boolean', 'complex', 'index', 'number', 'string', 'unit', 'sparse']
|
58436 | };
|
58437 |
|
58438 | /***/ }),
|
58439 | /* 363 */
|
58440 | /***/ (function(module, exports) {
|
58441 |
|
58442 | module.exports = {
|
58443 | 'name': 'number',
|
58444 | 'category': 'Construction',
|
58445 | 'syntax': ['x', 'number(x)', 'number(unit, valuelessUnit)'],
|
58446 | 'description': 'Create a number or convert a string or boolean into a number.',
|
58447 | 'examples': ['2', '2e3', '4.05', 'number(2)', 'number("7.2")', 'number(true)', 'number([true, false, true, true])', 'number(unit("52cm"), "m")'],
|
58448 | 'seealso': ['bignumber', 'boolean', 'complex', 'fraction', 'index', 'matrix', 'string', 'unit']
|
58449 | };
|
58450 |
|
58451 | /***/ }),
|
58452 | /* 364 */
|
58453 | /***/ (function(module, exports) {
|
58454 |
|
58455 | module.exports = {
|
58456 | 'name': 'sparse',
|
58457 | 'category': 'Construction',
|
58458 | 'syntax': ['sparse()', 'sparse([a1, b1, ...; a1, b2, ...])', 'sparse([a1, b1, ...; a1, b2, ...], "number")'],
|
58459 | 'description': 'Create a sparse matrix.',
|
58460 | 'examples': ['sparse()', 'sparse([3, 4; 5, 6])', 'sparse([3, 0; 5, 0], "number")'],
|
58461 | 'seealso': ['bignumber', 'boolean', 'complex', 'index', 'number', 'string', 'unit', 'matrix']
|
58462 | };
|
58463 |
|
58464 | /***/ }),
|
58465 | /* 365 */
|
58466 | /***/ (function(module, exports) {
|
58467 |
|
58468 | module.exports = {
|
58469 | 'name': 'splitUnit',
|
58470 | 'category': 'Construction',
|
58471 | 'syntax': ['splitUnit(unit: Unit, parts: Unit[])'],
|
58472 | 'description': 'Split a unit in an array of units whose sum is equal to the original unit.',
|
58473 | 'examples': ['splitUnit(1 m, ["feet", "inch"])'],
|
58474 | 'seealso': ['unit', 'createUnit']
|
58475 | };
|
58476 |
|
58477 | /***/ }),
|
58478 | /* 366 */
|
58479 | /***/ (function(module, exports) {
|
58480 |
|
58481 | module.exports = {
|
58482 | 'name': 'string',
|
58483 | 'category': 'Construction',
|
58484 | 'syntax': ['"text"', 'string(x)'],
|
58485 | 'description': 'Create a string or convert a value to a string',
|
58486 | 'examples': ['"Hello World!"', 'string(4.2)', 'string(3 + 2i)'],
|
58487 | 'seealso': ['bignumber', 'boolean', 'complex', 'index', 'matrix', 'number', 'unit']
|
58488 | };
|
58489 |
|
58490 | /***/ }),
|
58491 | /* 367 */
|
58492 | /***/ (function(module, exports) {
|
58493 |
|
58494 | module.exports = {
|
58495 | 'name': 'unit',
|
58496 | 'category': 'Construction',
|
58497 | 'syntax': ['value unit', 'unit(value, unit)', 'unit(string)'],
|
58498 | 'description': 'Create a unit.',
|
58499 | 'examples': ['5.5 mm', '3 inch', 'unit(7.1, "kilogram")', 'unit("23 deg")'],
|
58500 | 'seealso': ['bignumber', 'boolean', 'complex', 'index', 'matrix', 'number', 'string']
|
58501 | };
|
58502 |
|
58503 | /***/ }),
|
58504 | /* 368 */
|
58505 | /***/ (function(module, exports) {
|
58506 |
|
58507 | module.exports = {
|
58508 | 'name': 'false',
|
58509 | 'category': 'Constants',
|
58510 | 'syntax': ['false'],
|
58511 | 'description': 'Boolean value false',
|
58512 | 'examples': ['false'],
|
58513 | 'seealso': ['true']
|
58514 | };
|
58515 |
|
58516 | /***/ }),
|
58517 | /* 369 */
|
58518 | /***/ (function(module, exports) {
|
58519 |
|
58520 | module.exports = {
|
58521 | 'name': 'i',
|
58522 | 'category': 'Constants',
|
58523 | 'syntax': ['i'],
|
58524 | 'description': 'Imaginary unit, defined as i*i=-1. A complex number is described as a + b*i, where a is the real part, and b is the imaginary part.',
|
58525 | 'examples': ['i', 'i * i', 'sqrt(-1)'],
|
58526 | 'seealso': []
|
58527 | };
|
58528 |
|
58529 | /***/ }),
|
58530 | /* 370 */
|
58531 | /***/ (function(module, exports) {
|
58532 |
|
58533 | module.exports = {
|
58534 | 'name': 'Infinity',
|
58535 | 'category': 'Constants',
|
58536 | 'syntax': ['Infinity'],
|
58537 | 'description': 'Infinity, a number which is larger than the maximum number that can be handled by a floating point number.',
|
58538 | 'examples': ['Infinity', '1 / 0'],
|
58539 | 'seealso': []
|
58540 | };
|
58541 |
|
58542 | /***/ }),
|
58543 | /* 371 */
|
58544 | /***/ (function(module, exports) {
|
58545 |
|
58546 | module.exports = {
|
58547 | 'name': 'LN2',
|
58548 | 'category': 'Constants',
|
58549 | 'syntax': ['LN2'],
|
58550 | 'description': 'Returns the natural logarithm of 2, approximately equal to 0.693',
|
58551 | 'examples': ['LN2', 'log(2)'],
|
58552 | 'seealso': []
|
58553 | };
|
58554 |
|
58555 | /***/ }),
|
58556 | /* 372 */
|
58557 | /***/ (function(module, exports) {
|
58558 |
|
58559 | module.exports = {
|
58560 | 'name': 'LN10',
|
58561 | 'category': 'Constants',
|
58562 | 'syntax': ['LN10'],
|
58563 | 'description': 'Returns the natural logarithm of 10, approximately equal to 2.302',
|
58564 | 'examples': ['LN10', 'log(10)'],
|
58565 | 'seealso': []
|
58566 | };
|
58567 |
|
58568 | /***/ }),
|
58569 | /* 373 */
|
58570 | /***/ (function(module, exports) {
|
58571 |
|
58572 | module.exports = {
|
58573 | 'name': 'LOG2E',
|
58574 | 'category': 'Constants',
|
58575 | 'syntax': ['LOG2E'],
|
58576 | 'description': 'Returns the base-2 logarithm of E, approximately equal to 1.442',
|
58577 | 'examples': ['LOG2E', 'log(e, 2)'],
|
58578 | 'seealso': []
|
58579 | };
|
58580 |
|
58581 | /***/ }),
|
58582 | /* 374 */
|
58583 | /***/ (function(module, exports) {
|
58584 |
|
58585 | module.exports = {
|
58586 | 'name': 'LOG10E',
|
58587 | 'category': 'Constants',
|
58588 | 'syntax': ['LOG10E'],
|
58589 | 'description': 'Returns the base-10 logarithm of E, approximately equal to 0.434',
|
58590 | 'examples': ['LOG10E', 'log(e, 10)'],
|
58591 | 'seealso': []
|
58592 | };
|
58593 |
|
58594 | /***/ }),
|
58595 | /* 375 */
|
58596 | /***/ (function(module, exports) {
|
58597 |
|
58598 | module.exports = {
|
58599 | 'name': 'NaN',
|
58600 | 'category': 'Constants',
|
58601 | 'syntax': ['NaN'],
|
58602 | 'description': 'Not a number',
|
58603 | 'examples': ['NaN', '0 / 0'],
|
58604 | 'seealso': []
|
58605 | };
|
58606 |
|
58607 | /***/ }),
|
58608 | /* 376 */
|
58609 | /***/ (function(module, exports) {
|
58610 |
|
58611 | module.exports = {
|
58612 | 'name': 'null',
|
58613 | 'category': 'Constants',
|
58614 | 'syntax': ['null'],
|
58615 | 'description': 'Value null',
|
58616 | 'examples': ['null'],
|
58617 | 'seealso': ['true', 'false']
|
58618 | };
|
58619 |
|
58620 | /***/ }),
|
58621 | /* 377 */
|
58622 | /***/ (function(module, exports) {
|
58623 |
|
58624 | module.exports = {
|
58625 | 'name': 'phi',
|
58626 | 'category': 'Constants',
|
58627 | 'syntax': ['phi'],
|
58628 | 'description': 'Phi is the golden ratio. Two quantities are in the golden ratio if their ratio is the same as the ratio of their sum to the larger of the two quantities. Phi is defined as `(1 + sqrt(5)) / 2` and is approximately 1.618034...',
|
58629 | 'examples': ['phi'],
|
58630 | 'seealso': []
|
58631 | };
|
58632 |
|
58633 | /***/ }),
|
58634 | /* 378 */
|
58635 | /***/ (function(module, exports) {
|
58636 |
|
58637 | module.exports = {
|
58638 | 'name': 'SQRT1_2',
|
58639 | 'category': 'Constants',
|
58640 | 'syntax': ['SQRT1_2'],
|
58641 | 'description': 'Returns the square root of 1/2, approximately equal to 0.707',
|
58642 | 'examples': ['SQRT1_2', 'sqrt(1/2)'],
|
58643 | 'seealso': []
|
58644 | };
|
58645 |
|
58646 | /***/ }),
|
58647 | /* 379 */
|
58648 | /***/ (function(module, exports) {
|
58649 |
|
58650 | module.exports = {
|
58651 | 'name': 'SQRT2',
|
58652 | 'category': 'Constants',
|
58653 | 'syntax': ['SQRT2'],
|
58654 | 'description': 'Returns the square root of 2, approximately equal to 1.414',
|
58655 | 'examples': ['SQRT2', 'sqrt(2)'],
|
58656 | 'seealso': []
|
58657 | };
|
58658 |
|
58659 | /***/ }),
|
58660 | /* 380 */
|
58661 | /***/ (function(module, exports) {
|
58662 |
|
58663 | module.exports = {
|
58664 | 'name': 'tau',
|
58665 | 'category': 'Constants',
|
58666 | 'syntax': ['tau'],
|
58667 | 'description': 'Tau is the ratio constant of a circle\'s circumference to radius, equal to 2 * pi, approximately 6.2832.',
|
58668 | 'examples': ['tau', '2 * pi'],
|
58669 | 'seealso': ['pi']
|
58670 | };
|
58671 |
|
58672 | /***/ }),
|
58673 | /* 381 */
|
58674 | /***/ (function(module, exports) {
|
58675 |
|
58676 | module.exports = {
|
58677 | 'name': 'true',
|
58678 | 'category': 'Constants',
|
58679 | 'syntax': ['true'],
|
58680 | 'description': 'Boolean value true',
|
58681 | 'examples': ['true'],
|
58682 | 'seealso': ['false']
|
58683 | };
|
58684 |
|
58685 | /***/ }),
|
58686 | /* 382 */
|
58687 | /***/ (function(module, exports) {
|
58688 |
|
58689 | module.exports = {
|
58690 | 'name': 'version',
|
58691 | 'category': 'Constants',
|
58692 | 'syntax': ['version'],
|
58693 | 'description': 'A string with the version number of math.js',
|
58694 | 'examples': ['version'],
|
58695 | 'seealso': []
|
58696 | };
|
58697 |
|
58698 | /***/ }),
|
58699 | /* 383 */
|
58700 | /***/ (function(module, exports) {
|
58701 |
|
58702 | module.exports = {
|
58703 | 'name': 'derivative',
|
58704 | 'category': 'Algebra',
|
58705 | 'syntax': ['derivative(expr, variable)', 'derivative(expr, variable, {simplify: boolean})'],
|
58706 | 'description': 'Takes the derivative of an expression expressed in parser Nodes. The derivative will be taken over the supplied variable in the second parameter. If there are multiple variables in the expression, it will return a partial derivative.',
|
58707 | 'examples': ['derivative("2x^3", "x")', 'derivative("2x^3", "x", {simplify: false})', 'derivative("2x^2 + 3x + 4", "x")', 'derivative("sin(2x)", "x")', 'f = parse("x^2 + x")', 'x = parse("x")', 'df = derivative(f, x)', 'df.eval({x: 3})'],
|
58708 | 'seealso': ['simplify', 'parse', 'eval']
|
58709 | };
|
58710 |
|
58711 | /***/ }),
|
58712 | /* 384 */
|
58713 | /***/ (function(module, exports) {
|
58714 |
|
58715 | module.exports = {
|
58716 | 'name': 'lsolve',
|
58717 | 'category': 'Algebra',
|
58718 | 'syntax': ['x=lsolve(L, b)'],
|
58719 | 'description': 'Solves the linear system L * x = b where L is an [n x n] lower triangular matrix and b is a [n] column vector.',
|
58720 | 'examples': ['a = [-2, 3; 2, 1]', 'b = [11, 9]', 'x = lsolve(a, b)'],
|
58721 | 'seealso': ['lup', 'lusolve', 'usolve', 'matrix', 'sparse']
|
58722 | };
|
58723 |
|
58724 | /***/ }),
|
58725 | /* 385 */
|
58726 | /***/ (function(module, exports) {
|
58727 |
|
58728 | module.exports = {
|
58729 | 'name': 'lup',
|
58730 | 'category': 'Algebra',
|
58731 | 'syntax': ['lup(m)'],
|
58732 | 'description': 'Calculate the Matrix LU decomposition with partial pivoting. Matrix A is decomposed in three matrices (L, U, P) where P * A = L * U',
|
58733 | 'examples': ['lup([[2, 1], [1, 4]])', 'lup(matrix([[2, 1], [1, 4]]))', 'lup(sparse([[2, 1], [1, 4]]))'],
|
58734 | 'seealso': ['lusolve', 'lsolve', 'usolve', 'matrix', 'sparse', 'slu', 'qr']
|
58735 | };
|
58736 |
|
58737 | /***/ }),
|
58738 | /* 386 */
|
58739 | /***/ (function(module, exports) {
|
58740 |
|
58741 | module.exports = {
|
58742 | 'name': 'lusolve',
|
58743 | 'category': 'Algebra',
|
58744 | 'syntax': ['x=lusolve(A, b)', 'x=lusolve(lu, b)'],
|
58745 | 'description': 'Solves the linear system A * x = b where A is an [n x n] matrix and b is a [n] column vector.',
|
58746 | 'examples': ['a = [-2, 3; 2, 1]', 'b = [11, 9]', 'x = lusolve(a, b)'],
|
58747 | 'seealso': ['lup', 'slu', 'lsolve', 'usolve', 'matrix', 'sparse']
|
58748 | };
|
58749 |
|
58750 | /***/ }),
|
58751 | /* 387 */
|
58752 | /***/ (function(module, exports) {
|
58753 |
|
58754 | module.exports = {
|
58755 | 'name': 'simplify',
|
58756 | 'category': 'Algebra',
|
58757 | 'syntax': ['simplify(expr)', 'simplify(expr, rules)'],
|
58758 | 'description': 'Simplify an expression tree.',
|
58759 | 'examples': ['simplify("3 + 2 / 4")', 'simplify("2x + x")', 'f = parse("x * (x + 2 + x)")', 'simplified = simplify(f)', 'simplified.eval({x: 2})'],
|
58760 | 'seealso': ['derivative', 'parse', 'eval']
|
58761 | };
|
58762 |
|
58763 | /***/ }),
|
58764 | /* 388 */
|
58765 | /***/ (function(module, exports) {
|
58766 |
|
58767 | module.exports = {
|
58768 | 'name': 'rationalize',
|
58769 | 'category': 'Algebra',
|
58770 | 'syntax': ['rationalize(expr)', 'rationalize(expr, scope)', 'rationalize(expr, scope, detailed)'],
|
58771 | 'description': 'Transform a rationalizable expression in a rational fraction. If rational fraction is one variable polynomial then converts the numerator and denominator in canonical form, with decreasing exponents, returning the coefficients of numerator.',
|
58772 | 'examples': ['rationalize("2x/y - y/(x+1)")', 'rationalize("2x/y - y/(x+1)", true)'],
|
58773 | 'seealso': ['simplify']
|
58774 | };
|
58775 |
|
58776 | /***/ }),
|
58777 | /* 389 */
|
58778 | /***/ (function(module, exports) {
|
58779 |
|
58780 | module.exports = {
|
58781 | 'name': 'slu',
|
58782 | 'category': 'Algebra',
|
58783 | 'syntax': ['slu(A, order, threshold)'],
|
58784 | 'description': 'Calculate the Matrix LU decomposition with full pivoting. Matrix A is decomposed in two matrices (L, U) and two permutation vectors (pinv, q) where P * A * Q = L * U',
|
58785 | 'examples': ['slu(sparse([4.5, 0, 3.2, 0; 3.1, 2.9, 0, 0.9; 0, 1.7, 3, 0; 3.5, 0.4, 0, 1]), 1, 0.001)'],
|
58786 | 'seealso': ['lusolve', 'lsolve', 'usolve', 'matrix', 'sparse', 'lup', 'qr']
|
58787 | };
|
58788 |
|
58789 | /***/ }),
|
58790 | /* 390 */
|
58791 | /***/ (function(module, exports) {
|
58792 |
|
58793 | module.exports = {
|
58794 | 'name': 'usolve',
|
58795 | 'category': 'Algebra',
|
58796 | 'syntax': ['x=usolve(U, b)'],
|
58797 | 'description': 'Solves the linear system U * x = b where U is an [n x n] upper triangular matrix and b is a [n] column vector.',
|
58798 | 'examples': ['x=usolve(sparse([1, 1, 1, 1; 0, 1, 1, 1; 0, 0, 1, 1; 0, 0, 0, 1]), [1; 2; 3; 4])'],
|
58799 | 'seealso': ['lup', 'lusolve', 'lsolve', 'matrix', 'sparse']
|
58800 | };
|
58801 |
|
58802 | /***/ }),
|
58803 | /* 391 */
|
58804 | /***/ (function(module, exports) {
|
58805 |
|
58806 | module.exports = {
|
58807 | 'name': 'qr',
|
58808 | 'category': 'Algebra',
|
58809 | 'syntax': ['qr(A)'],
|
58810 | 'description': 'Calculates the Matrix QR decomposition. Matrix `A` is decomposed in two matrices (`Q`, `R`) where `Q` is an orthogonal matrix and `R` is an upper triangular matrix.',
|
58811 | 'examples': ['qr([[1, -1, 4], [1, 4, -2], [1, 4, 2], [1, -1, 0]])'],
|
58812 | 'seealso': ['lup', 'slu', 'matrix']
|
58813 | };
|
58814 |
|
58815 | /***/ }),
|
58816 | /* 392 */
|
58817 | /***/ (function(module, exports) {
|
58818 |
|
58819 | module.exports = {
|
58820 | 'name': 'abs',
|
58821 | 'category': 'Arithmetic',
|
58822 | 'syntax': ['abs(x)'],
|
58823 | 'description': 'Compute the absolute value.',
|
58824 | 'examples': ['abs(3.5)', 'abs(-4.2)'],
|
58825 | 'seealso': ['sign']
|
58826 | };
|
58827 |
|
58828 | /***/ }),
|
58829 | /* 393 */
|
58830 | /***/ (function(module, exports) {
|
58831 |
|
58832 | module.exports = {
|
58833 | 'name': 'add',
|
58834 | 'category': 'Operators',
|
58835 | 'syntax': ['x + y', 'add(x, y)'],
|
58836 | 'description': 'Add two values.',
|
58837 | 'examples': ['a = 2.1 + 3.6', 'a - 3.6', '3 + 2i', '3 cm + 2 inch', '"2.3" + "4"'],
|
58838 | 'seealso': ['subtract']
|
58839 | };
|
58840 |
|
58841 | /***/ }),
|
58842 | /* 394 */
|
58843 | /***/ (function(module, exports) {
|
58844 |
|
58845 | module.exports = {
|
58846 | 'name': 'cbrt',
|
58847 | 'category': 'Arithmetic',
|
58848 | 'syntax': ['cbrt(x)', 'cbrt(x, allRoots)'],
|
58849 | 'description': 'Compute the cubic root value. If x = y * y * y, then y is the cubic root of x. When `x` is a number or complex number, an optional second argument `allRoots` can be provided to return all three cubic roots. If not provided, the principal root is returned',
|
58850 | 'examples': ['cbrt(64)', 'cube(4)', 'cbrt(-8)', 'cbrt(2 + 3i)', 'cbrt(8i)', 'cbrt(8i, true)', 'cbrt(27 m^3)'],
|
58851 | 'seealso': ['square', 'sqrt', 'cube', 'multiply']
|
58852 | };
|
58853 |
|
58854 | /***/ }),
|
58855 | /* 395 */
|
58856 | /***/ (function(module, exports) {
|
58857 |
|
58858 | module.exports = {
|
58859 | 'name': 'ceil',
|
58860 | 'category': 'Arithmetic',
|
58861 | 'syntax': ['ceil(x)'],
|
58862 | 'description': 'Round a value towards plus infinity. If x is complex, both real and imaginary part are rounded towards plus infinity.',
|
58863 | 'examples': ['ceil(3.2)', 'ceil(3.8)', 'ceil(-4.2)'],
|
58864 | 'seealso': ['floor', 'fix', 'round']
|
58865 | };
|
58866 |
|
58867 | /***/ }),
|
58868 | /* 396 */
|
58869 | /***/ (function(module, exports) {
|
58870 |
|
58871 | module.exports = {
|
58872 | 'name': 'cube',
|
58873 | 'category': 'Arithmetic',
|
58874 | 'syntax': ['cube(x)'],
|
58875 | 'description': 'Compute the cube of a value. The cube of x is x * x * x.',
|
58876 | 'examples': ['cube(2)', '2^3', '2 * 2 * 2'],
|
58877 | 'seealso': ['multiply', 'square', 'pow']
|
58878 | };
|
58879 |
|
58880 | /***/ }),
|
58881 | /* 397 */
|
58882 | /***/ (function(module, exports) {
|
58883 |
|
58884 | module.exports = {
|
58885 | 'name': 'divide',
|
58886 | 'category': 'Operators',
|
58887 | 'syntax': ['x / y', 'divide(x, y)'],
|
58888 | 'description': 'Divide two values.',
|
58889 | 'examples': ['a = 2 / 3', 'a * 3', '4.5 / 2', '3 + 4 / 2', '(3 + 4) / 2', '18 km / 4.5'],
|
58890 | 'seealso': ['multiply']
|
58891 | };
|
58892 |
|
58893 | /***/ }),
|
58894 | /* 398 */
|
58895 | /***/ (function(module, exports) {
|
58896 |
|
58897 | module.exports = {
|
58898 | 'name': 'dotDivide',
|
58899 | 'category': 'Operators',
|
58900 | 'syntax': ['x ./ y', 'dotDivide(x, y)'],
|
58901 | 'description': 'Divide two values element wise.',
|
58902 | 'examples': ['a = [1, 2, 3; 4, 5, 6]', 'b = [2, 1, 1; 3, 2, 5]', 'a ./ b'],
|
58903 | 'seealso': ['multiply', 'dotMultiply', 'divide']
|
58904 | };
|
58905 |
|
58906 | /***/ }),
|
58907 | /* 399 */
|
58908 | /***/ (function(module, exports) {
|
58909 |
|
58910 | module.exports = {
|
58911 | 'name': 'dotMultiply',
|
58912 | 'category': 'Operators',
|
58913 | 'syntax': ['x .* y', 'dotMultiply(x, y)'],
|
58914 | 'description': 'Multiply two values element wise.',
|
58915 | 'examples': ['a = [1, 2, 3; 4, 5, 6]', 'b = [2, 1, 1; 3, 2, 5]', 'a .* b'],
|
58916 | 'seealso': ['multiply', 'divide', 'dotDivide']
|
58917 | };
|
58918 |
|
58919 | /***/ }),
|
58920 | /* 400 */
|
58921 | /***/ (function(module, exports) {
|
58922 |
|
58923 | module.exports = {
|
58924 | 'name': 'dotpow',
|
58925 | 'category': 'Operators',
|
58926 | 'syntax': ['x .^ y', 'dotpow(x, y)'],
|
58927 | 'description': 'Calculates the power of x to y element wise.',
|
58928 | 'examples': ['a = [1, 2, 3; 4, 5, 6]', 'a .^ 2'],
|
58929 | 'seealso': ['pow']
|
58930 | };
|
58931 |
|
58932 | /***/ }),
|
58933 | /* 401 */
|
58934 | /***/ (function(module, exports) {
|
58935 |
|
58936 | module.exports = {
|
58937 | 'name': 'exp',
|
58938 | 'category': 'Arithmetic',
|
58939 | 'syntax': ['exp(x)'],
|
58940 | 'description': 'Calculate the exponent of a value.',
|
58941 | 'examples': ['exp(1.3)', 'e ^ 1.3', 'log(exp(1.3))', 'x = 2.4', '(exp(i*x) == cos(x) + i*sin(x)) # Euler\'s formula'],
|
58942 | 'seealso': ['expm', 'expm1', 'pow', 'log']
|
58943 | };
|
58944 |
|
58945 | /***/ }),
|
58946 | /* 402 */
|
58947 | /***/ (function(module, exports) {
|
58948 |
|
58949 | module.exports = {
|
58950 | 'name': 'expm',
|
58951 | 'category': 'Arithmetic',
|
58952 | 'syntax': ['exp(x)'],
|
58953 | 'description': 'Compute the matrix exponential, expm(A) = e^A. ' + 'The matrix must be square. ' + 'Not to be confused with exp(a), which performs element-wise exponentiation.',
|
58954 | 'examples': ['expm([[0,2],[0,0]])'],
|
58955 | 'seealso': ['exp']
|
58956 | };
|
58957 |
|
58958 | /***/ }),
|
58959 | /* 403 */
|
58960 | /***/ (function(module, exports) {
|
58961 |
|
58962 | module.exports = {
|
58963 | 'name': 'expm1',
|
58964 | 'category': 'Arithmetic',
|
58965 | 'syntax': ['expm1(x)'],
|
58966 | 'description': 'Calculate the value of subtracting 1 from the exponential value.',
|
58967 | 'examples': ['expm1(2)', 'pow(e, 2) - 1', 'log(expm1(2) + 1)'],
|
58968 | 'seealso': ['exp', 'pow', 'log']
|
58969 | };
|
58970 |
|
58971 | /***/ }),
|
58972 | /* 404 */
|
58973 | /***/ (function(module, exports) {
|
58974 |
|
58975 | module.exports = {
|
58976 | 'name': 'fix',
|
58977 | 'category': 'Arithmetic',
|
58978 | 'syntax': ['fix(x)'],
|
58979 | 'description': 'Round a value towards zero. If x is complex, both real and imaginary part are rounded towards zero.',
|
58980 | 'examples': ['fix(3.2)', 'fix(3.8)', 'fix(-4.2)', 'fix(-4.8)'],
|
58981 | 'seealso': ['ceil', 'floor', 'round']
|
58982 | };
|
58983 |
|
58984 | /***/ }),
|
58985 | /* 405 */
|
58986 | /***/ (function(module, exports) {
|
58987 |
|
58988 | module.exports = {
|
58989 | 'name': 'floor',
|
58990 | 'category': 'Arithmetic',
|
58991 | 'syntax': ['floor(x)'],
|
58992 | 'description': 'Round a value towards minus infinity.If x is complex, both real and imaginary part are rounded towards minus infinity.',
|
58993 | 'examples': ['floor(3.2)', 'floor(3.8)', 'floor(-4.2)'],
|
58994 | 'seealso': ['ceil', 'fix', 'round']
|
58995 | };
|
58996 |
|
58997 | /***/ }),
|
58998 | /* 406 */
|
58999 | /***/ (function(module, exports) {
|
59000 |
|
59001 | module.exports = {
|
59002 | 'name': 'gcd',
|
59003 | 'category': 'Arithmetic',
|
59004 | 'syntax': ['gcd(a, b)', 'gcd(a, b, c, ...)'],
|
59005 | 'description': 'Compute the greatest common divisor.',
|
59006 | 'examples': ['gcd(8, 12)', 'gcd(-4, 6)', 'gcd(25, 15, -10)'],
|
59007 | 'seealso': ['lcm', 'xgcd']
|
59008 | };
|
59009 |
|
59010 | /***/ }),
|
59011 | /* 407 */
|
59012 | /***/ (function(module, exports) {
|
59013 |
|
59014 | module.exports = {
|
59015 | 'name': 'hypot',
|
59016 | 'category': 'Arithmetic',
|
59017 | 'syntax': ['hypot(a, b, c, ...)', 'hypot([a, b, c, ...])'],
|
59018 | 'description': 'Calculate the hypotenusa of a list with values. ',
|
59019 | 'examples': ['hypot(3, 4)', 'sqrt(3^2 + 4^2)', 'hypot(-2)', 'hypot([3, 4, 5])'],
|
59020 | 'seealso': ['abs', 'norm']
|
59021 | };
|
59022 |
|
59023 | /***/ }),
|
59024 | /* 408 */
|
59025 | /***/ (function(module, exports) {
|
59026 |
|
59027 | module.exports = {
|
59028 | 'name': 'lcm',
|
59029 | 'category': 'Arithmetic',
|
59030 | 'syntax': ['lcm(x, y)'],
|
59031 | 'description': 'Compute the least common multiple.',
|
59032 | 'examples': ['lcm(4, 6)', 'lcm(6, 21)', 'lcm(6, 21, 5)'],
|
59033 | 'seealso': ['gcd']
|
59034 | };
|
59035 |
|
59036 | /***/ }),
|
59037 | /* 409 */
|
59038 | /***/ (function(module, exports) {
|
59039 |
|
59040 | module.exports = {
|
59041 | 'name': 'log',
|
59042 | 'category': 'Arithmetic',
|
59043 | 'syntax': ['log(x)', 'log(x, base)'],
|
59044 | 'description': 'Compute the logarithm of a value. If no base is provided, the natural logarithm of x is calculated. If base if provided, the logarithm is calculated for the specified base. log(x, base) is defined as log(x) / log(base).',
|
59045 | 'examples': ['log(3.5)', 'a = log(2.4)', 'exp(a)', '10 ^ 4', 'log(10000, 10)', 'log(10000) / log(10)', 'b = log(1024, 2)', '2 ^ b'],
|
59046 | 'seealso': ['exp', 'log1p', 'log2', 'log10']
|
59047 | };
|
59048 |
|
59049 | /***/ }),
|
59050 | /* 410 */
|
59051 | /***/ (function(module, exports) {
|
59052 |
|
59053 | module.exports = {
|
59054 | 'name': 'log2',
|
59055 | 'category': 'Arithmetic',
|
59056 | 'syntax': ['log2(x)'],
|
59057 | 'description': 'Calculate the 2-base of a value. This is the same as calculating `log(x, 2)`.',
|
59058 | 'examples': ['log2(0.03125)', 'log2(16)', 'log2(16) / log2(2)', 'pow(2, 4)'],
|
59059 | 'seealso': ['exp', 'log1p', 'log', 'log10']
|
59060 | };
|
59061 |
|
59062 | /***/ }),
|
59063 | /* 411 */
|
59064 | /***/ (function(module, exports) {
|
59065 |
|
59066 | module.exports = {
|
59067 | 'name': 'log1p',
|
59068 | 'category': 'Arithmetic',
|
59069 | 'syntax': ['log1p(x)', 'log1p(x, base)'],
|
59070 | 'description': 'Calculate the logarithm of a `value+1`',
|
59071 | 'examples': ['log1p(2.5)', 'exp(log1p(1.4))', 'pow(10, 4)', 'log1p(9999, 10)', 'log1p(9999) / log(10)'],
|
59072 | 'seealso': ['exp', 'log', 'log2', 'log10']
|
59073 | };
|
59074 |
|
59075 | /***/ }),
|
59076 | /* 412 */
|
59077 | /***/ (function(module, exports) {
|
59078 |
|
59079 | module.exports = {
|
59080 | 'name': 'log10',
|
59081 | 'category': 'Arithmetic',
|
59082 | 'syntax': ['log10(x)'],
|
59083 | 'description': 'Compute the 10-base logarithm of a value.',
|
59084 | 'examples': ['log10(0.00001)', 'log10(10000)', '10 ^ 4', 'log(10000) / log(10)', 'log(10000, 10)'],
|
59085 | 'seealso': ['exp', 'log']
|
59086 | };
|
59087 |
|
59088 | /***/ }),
|
59089 | /* 413 */
|
59090 | /***/ (function(module, exports) {
|
59091 |
|
59092 | module.exports = {
|
59093 | 'name': 'mod',
|
59094 | 'category': 'Operators',
|
59095 | 'syntax': ['x % y', 'x mod y', 'mod(x, y)'],
|
59096 | 'description': 'Calculates the modulus, the remainder of an integer division.',
|
59097 | 'examples': ['7 % 3', '11 % 2', '10 mod 4', 'isOdd(x) = x % 2', 'isOdd(2)', 'isOdd(3)'],
|
59098 | 'seealso': ['divide']
|
59099 | };
|
59100 |
|
59101 | /***/ }),
|
59102 | /* 414 */
|
59103 | /***/ (function(module, exports) {
|
59104 |
|
59105 | module.exports = {
|
59106 | 'name': 'multiply',
|
59107 | 'category': 'Operators',
|
59108 | 'syntax': ['x * y', 'multiply(x, y)'],
|
59109 | 'description': 'multiply two values.',
|
59110 | 'examples': ['a = 2.1 * 3.4', 'a / 3.4', '2 * 3 + 4', '2 * (3 + 4)', '3 * 2.1 km'],
|
59111 | 'seealso': ['divide']
|
59112 | };
|
59113 |
|
59114 | /***/ }),
|
59115 | /* 415 */
|
59116 | /***/ (function(module, exports) {
|
59117 |
|
59118 | module.exports = {
|
59119 | 'name': 'norm',
|
59120 | 'category': 'Arithmetic',
|
59121 | 'syntax': ['norm(x)', 'norm(x, p)'],
|
59122 | 'description': 'Calculate the norm of a number, vector or matrix.',
|
59123 | 'examples': ['abs(-3.5)', 'norm(-3.5)', 'norm(3 - 4i)', 'norm([1, 2, -3], Infinity)', 'norm([1, 2, -3], -Infinity)', 'norm([3, 4], 2)', 'norm([[1, 2], [3, 4]], 1)', 'norm([[1, 2], [3, 4]], "inf")', 'norm([[1, 2], [3, 4]], "fro")']
|
59124 | };
|
59125 |
|
59126 | /***/ }),
|
59127 | /* 416 */
|
59128 | /***/ (function(module, exports) {
|
59129 |
|
59130 | module.exports = {
|
59131 | 'name': 'nthRoot',
|
59132 | 'category': 'Arithmetic',
|
59133 | 'syntax': ['nthRoot(a)', 'nthRoot(a, root)'],
|
59134 | 'description': 'Calculate the nth root of a value. ' + 'The principal nth root of a positive real number A, ' + 'is the positive real solution of the equation "x^root = A".',
|
59135 | 'examples': ['4 ^ 3', 'nthRoot(64, 3)', 'nthRoot(9, 2)', 'sqrt(9)'],
|
59136 | 'seealso': ['nthRoots', 'pow', 'sqrt']
|
59137 | };
|
59138 |
|
59139 | /***/ }),
|
59140 | /* 417 */
|
59141 | /***/ (function(module, exports) {
|
59142 |
|
59143 | module.exports = {
|
59144 | 'name': 'nthRoots',
|
59145 | 'category': 'Arithmetic',
|
59146 | 'syntax': ['nthRoots(A)', 'nthRoots(A, root)'],
|
59147 | 'description': '' + 'Calculate the nth roots of a value. ' + 'An nth root of a positive real number A, ' + 'is a positive real solution of the equation "x^root = A". ' + 'This function returns an array of complex values.',
|
59148 | 'examples': ['nthRoots(1)', 'nthRoots(1, 3)'],
|
59149 | 'seealso': ['sqrt', 'pow', 'nthRoot']
|
59150 | };
|
59151 |
|
59152 | /***/ }),
|
59153 | /* 418 */
|
59154 | /***/ (function(module, exports) {
|
59155 |
|
59156 | module.exports = {
|
59157 | 'name': 'pow',
|
59158 | 'category': 'Operators',
|
59159 | 'syntax': ['x ^ y', 'pow(x, y)'],
|
59160 | 'description': 'Calculates the power of x to y, x^y.',
|
59161 | 'examples': ['2^3', '2*2*2', '1 + e ^ (pi * i)'],
|
59162 | 'seealso': ['multiply', 'nthRoot', 'nthRoots', 'sqrt']
|
59163 | };
|
59164 |
|
59165 | /***/ }),
|
59166 | /* 419 */
|
59167 | /***/ (function(module, exports) {
|
59168 |
|
59169 | module.exports = {
|
59170 | 'name': 'round',
|
59171 | 'category': 'Arithmetic',
|
59172 | 'syntax': ['round(x)', 'round(x, n)'],
|
59173 | 'description': 'round a value towards the nearest integer.If x is complex, both real and imaginary part are rounded towards the nearest integer. When n is specified, the value is rounded to n decimals.',
|
59174 | 'examples': ['round(3.2)', 'round(3.8)', 'round(-4.2)', 'round(-4.8)', 'round(pi, 3)', 'round(123.45678, 2)'],
|
59175 | 'seealso': ['ceil', 'floor', 'fix']
|
59176 | };
|
59177 |
|
59178 | /***/ }),
|
59179 | /* 420 */
|
59180 | /***/ (function(module, exports) {
|
59181 |
|
59182 | module.exports = {
|
59183 | 'name': 'sign',
|
59184 | 'category': 'Arithmetic',
|
59185 | 'syntax': ['sign(x)'],
|
59186 | 'description': 'Compute the sign of a value. The sign of a value x is 1 when x>1, -1 when x<0, and 0 when x=0.',
|
59187 | 'examples': ['sign(3.5)', 'sign(-4.2)', 'sign(0)'],
|
59188 | 'seealso': ['abs']
|
59189 | };
|
59190 |
|
59191 | /***/ }),
|
59192 | /* 421 */
|
59193 | /***/ (function(module, exports) {
|
59194 |
|
59195 | module.exports = {
|
59196 | 'name': 'sqrt',
|
59197 | 'category': 'Arithmetic',
|
59198 | 'syntax': ['sqrt(x)'],
|
59199 | 'description': 'Compute the square root value. If x = y * y, then y is the square root of x.',
|
59200 | 'examples': ['sqrt(25)', '5 * 5', 'sqrt(-1)'],
|
59201 | 'seealso': ['square', 'sqrtm', 'multiply', 'nthRoot', 'nthRoots', 'pow']
|
59202 | };
|
59203 |
|
59204 | /***/ }),
|
59205 | /* 422 */
|
59206 | /***/ (function(module, exports) {
|
59207 |
|
59208 | module.exports = {
|
59209 | 'name': 'sqrtm',
|
59210 | 'category': 'Arithmetic',
|
59211 | 'syntax': ['sqrtm(x)'],
|
59212 | 'description': 'Calculate the principal square root of a square matrix. The principal square root matrix `X` of another matrix `A` is such that `X * X = A`.',
|
59213 | 'examples': ['sqrtm([[1, 2], [3, 4]])'],
|
59214 | 'seealso': ['sqrt', 'abs', 'square', 'multiply']
|
59215 | };
|
59216 |
|
59217 | /***/ }),
|
59218 | /* 423 */
|
59219 | /***/ (function(module, exports) {
|
59220 |
|
59221 | module.exports = {
|
59222 | 'name': 'square',
|
59223 | 'category': 'Arithmetic',
|
59224 | 'syntax': ['square(x)'],
|
59225 | 'description': 'Compute the square of a value. The square of x is x * x.',
|
59226 | 'examples': ['square(3)', 'sqrt(9)', '3^2', '3 * 3'],
|
59227 | 'seealso': ['multiply', 'pow', 'sqrt', 'cube']
|
59228 | };
|
59229 |
|
59230 | /***/ }),
|
59231 | /* 424 */
|
59232 | /***/ (function(module, exports) {
|
59233 |
|
59234 | module.exports = {
|
59235 | 'name': 'subtract',
|
59236 | 'category': 'Operators',
|
59237 | 'syntax': ['x - y', 'subtract(x, y)'],
|
59238 | 'description': 'subtract two values.',
|
59239 | 'examples': ['a = 5.3 - 2', 'a + 2', '2/3 - 1/6', '2 * 3 - 3', '2.1 km - 500m'],
|
59240 | 'seealso': ['add']
|
59241 | };
|
59242 |
|
59243 | /***/ }),
|
59244 | /* 425 */
|
59245 | /***/ (function(module, exports) {
|
59246 |
|
59247 | module.exports = {
|
59248 | 'name': 'unaryMinus',
|
59249 | 'category': 'Operators',
|
59250 | 'syntax': ['-x', 'unaryMinus(x)'],
|
59251 | 'description': 'Inverse the sign of a value. Converts booleans and strings to numbers.',
|
59252 | 'examples': ['-4.5', '-(-5.6)', '-"22"'],
|
59253 | 'seealso': ['add', 'subtract', 'unaryPlus']
|
59254 | };
|
59255 |
|
59256 | /***/ }),
|
59257 | /* 426 */
|
59258 | /***/ (function(module, exports) {
|
59259 |
|
59260 | module.exports = {
|
59261 | 'name': 'unaryPlus',
|
59262 | 'category': 'Operators',
|
59263 | 'syntax': ['+x', 'unaryPlus(x)'],
|
59264 | 'description': 'Converts booleans and strings to numbers.',
|
59265 | 'examples': ['+true', '+"2"'],
|
59266 | 'seealso': ['add', 'subtract', 'unaryMinus']
|
59267 | };
|
59268 |
|
59269 | /***/ }),
|
59270 | /* 427 */
|
59271 | /***/ (function(module, exports) {
|
59272 |
|
59273 | module.exports = {
|
59274 | 'name': 'xgcd',
|
59275 | 'category': 'Arithmetic',
|
59276 | 'syntax': ['xgcd(a, b)'],
|
59277 | 'description': 'Calculate the extended greatest common divisor for two values. The result is an array [d, x, y] with 3 entries, where d is the greatest common divisor, and d = x * a + y * b.',
|
59278 | 'examples': ['xgcd(8, 12)', 'gcd(8, 12)', 'xgcd(36163, 21199)'],
|
59279 | 'seealso': ['gcd', 'lcm']
|
59280 | };
|
59281 |
|
59282 | /***/ }),
|
59283 | /* 428 */
|
59284 | /***/ (function(module, exports) {
|
59285 |
|
59286 | module.exports = {
|
59287 | 'name': 'bitAnd',
|
59288 | 'category': 'Bitwise',
|
59289 | 'syntax': ['x & y', 'bitAnd(x, y)'],
|
59290 | 'description': 'Bitwise AND operation. Performs the logical AND operation on each pair of the corresponding bits of the two given values by multiplying them. If both bits in the compared position are 1, the bit in the resulting binary representation is 1, otherwise, the result is 0',
|
59291 | 'examples': ['5 & 3', 'bitAnd(53, 131)', '[1, 12, 31] & 42'],
|
59292 | 'seealso': ['bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift']
|
59293 | };
|
59294 |
|
59295 | /***/ }),
|
59296 | /* 429 */
|
59297 | /***/ (function(module, exports) {
|
59298 |
|
59299 | module.exports = {
|
59300 | 'name': 'bitNot',
|
59301 | 'category': 'Bitwise',
|
59302 | 'syntax': ['~x', 'bitNot(x)'],
|
59303 | 'description': 'Bitwise NOT operation. Performs a logical negation on each bit of the given value. Bits that are 0 become 1, and those that are 1 become 0.',
|
59304 | 'examples': ['~1', '~2', 'bitNot([2, -3, 4])'],
|
59305 | 'seealso': ['bitAnd', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift']
|
59306 | };
|
59307 |
|
59308 | /***/ }),
|
59309 | /* 430 */
|
59310 | /***/ (function(module, exports) {
|
59311 |
|
59312 | module.exports = {
|
59313 | 'name': 'bitOr',
|
59314 | 'category': 'Bitwise',
|
59315 | 'syntax': ['x | y', 'bitOr(x, y)'],
|
59316 | 'description': 'Bitwise OR operation. Performs the logical inclusive OR operation on each pair of corresponding bits of the two given values. The result in each position is 1 if the first bit is 1 or the second bit is 1 or both bits are 1, otherwise, the result is 0.',
|
59317 | 'examples': ['5 | 3', 'bitOr([1, 2, 3], 4)'],
|
59318 | 'seealso': ['bitAnd', 'bitNot', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift']
|
59319 | };
|
59320 |
|
59321 | /***/ }),
|
59322 | /* 431 */
|
59323 | /***/ (function(module, exports) {
|
59324 |
|
59325 | module.exports = {
|
59326 | 'name': 'bitXor',
|
59327 | 'category': 'Bitwise',
|
59328 | 'syntax': ['bitXor(x, y)'],
|
59329 | 'description': 'Bitwise XOR operation, exclusive OR. Performs the logical exclusive OR operation on each pair of corresponding bits of the two given values. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1.',
|
59330 | 'examples': ['bitOr(1, 2)', 'bitXor([2, 3, 4], 4)'],
|
59331 | 'seealso': ['bitAnd', 'bitNot', 'bitOr', 'leftShift', 'rightArithShift', 'rightLogShift']
|
59332 | };
|
59333 |
|
59334 | /***/ }),
|
59335 | /* 432 */
|
59336 | /***/ (function(module, exports) {
|
59337 |
|
59338 | module.exports = {
|
59339 | 'name': 'leftShift',
|
59340 | 'category': 'Bitwise',
|
59341 | 'syntax': ['x << y', 'leftShift(x, y)'],
|
59342 | 'description': 'Bitwise left logical shift of a value x by y number of bits.',
|
59343 | 'examples': ['4 << 1', '8 >> 1'],
|
59344 | 'seealso': ['bitAnd', 'bitNot', 'bitOr', 'bitXor', 'rightArithShift', 'rightLogShift']
|
59345 | };
|
59346 |
|
59347 | /***/ }),
|
59348 | /* 433 */
|
59349 | /***/ (function(module, exports) {
|
59350 |
|
59351 | module.exports = {
|
59352 | 'name': 'rightArithShift',
|
59353 | 'category': 'Bitwise',
|
59354 | 'syntax': ['x >> y', 'rightArithShift(x, y)'],
|
59355 | 'description': 'Bitwise right arithmetic shift of a value x by y number of bits.',
|
59356 | 'examples': ['8 >> 1', '4 << 1', '-12 >> 2'],
|
59357 | 'seealso': ['bitAnd', 'bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightLogShift']
|
59358 | };
|
59359 |
|
59360 | /***/ }),
|
59361 | /* 434 */
|
59362 | /***/ (function(module, exports) {
|
59363 |
|
59364 | module.exports = {
|
59365 | 'name': 'rightLogShift',
|
59366 | 'category': 'Bitwise',
|
59367 | 'syntax': ['x >>> y', 'rightLogShift(x, y)'],
|
59368 | 'description': 'Bitwise right logical shift of a value x by y number of bits.',
|
59369 | 'examples': ['8 >>> 1', '4 << 1', '-12 >>> 2'],
|
59370 | 'seealso': ['bitAnd', 'bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift']
|
59371 | };
|
59372 |
|
59373 | /***/ }),
|
59374 | /* 435 */
|
59375 | /***/ (function(module, exports) {
|
59376 |
|
59377 | module.exports = {
|
59378 | 'name': 'bellNumbers',
|
59379 | 'category': 'Combinatorics',
|
59380 | 'syntax': ['bellNumbers(n)'],
|
59381 | 'description': 'The Bell Numbers count the number of partitions of a set. A partition is a pairwise disjoint subset of S whose union is S. `bellNumbers` only takes integer arguments. The following condition must be enforced: n >= 0.',
|
59382 | 'examples': ['bellNumbers(3)', 'bellNumbers(8)'],
|
59383 | 'seealso': ['stirlingS2']
|
59384 | };
|
59385 |
|
59386 | /***/ }),
|
59387 | /* 436 */
|
59388 | /***/ (function(module, exports) {
|
59389 |
|
59390 | module.exports = {
|
59391 | 'name': 'catalan',
|
59392 | 'category': 'Combinatorics',
|
59393 | 'syntax': ['catalan(n)'],
|
59394 | 'description': 'The Catalan Numbers enumerate combinatorial structures of many different types. catalan only takes integer arguments. The following condition must be enforced: n >= 0.',
|
59395 | 'examples': ['catalan(3)', 'catalan(8)'],
|
59396 | 'seealso': ['bellNumbers']
|
59397 | };
|
59398 |
|
59399 | /***/ }),
|
59400 | /* 437 */
|
59401 | /***/ (function(module, exports) {
|
59402 |
|
59403 | module.exports = {
|
59404 | 'name': 'composition',
|
59405 | 'category': 'Combinatorics',
|
59406 | 'syntax': ['composition(n, k)'],
|
59407 | 'description': 'The composition counts of n into k parts. composition only takes integer arguments. The following condition must be enforced: k <= n.',
|
59408 | 'examples': ['composition(5, 3)'],
|
59409 | 'seealso': ['combinations']
|
59410 | };
|
59411 |
|
59412 | /***/ }),
|
59413 | /* 438 */
|
59414 | /***/ (function(module, exports) {
|
59415 |
|
59416 | module.exports = {
|
59417 | 'name': 'stirlingS2',
|
59418 | 'category': 'Combinatorics',
|
59419 | 'syntax': ['stirlingS2(n, k)'],
|
59420 | 'description': 'he Stirling numbers of the second kind, counts the number of ways to partition a set of n labelled objects into k nonempty unlabelled subsets. `stirlingS2` only takes integer arguments. The following condition must be enforced: k <= n. If n = k or k = 1, then s(n,k) = 1.',
|
59421 | 'examples': ['stirlingS2(5, 3)'],
|
59422 | 'seealso': ['bellNumbers']
|
59423 | };
|
59424 |
|
59425 | /***/ }),
|
59426 | /* 439 */
|
59427 | /***/ (function(module, exports) {
|
59428 |
|
59429 | module.exports = {
|
59430 | 'name': 'config',
|
59431 | 'category': 'Core',
|
59432 | 'syntax': ['config()', 'config(options)'],
|
59433 | 'description': 'Get configuration or change configuration.',
|
59434 | 'examples': ['config()', '1/3 + 1/4', 'config({number: "Fraction"})', '1/3 + 1/4'],
|
59435 | 'seealso': []
|
59436 | };
|
59437 |
|
59438 | /***/ }),
|
59439 | /* 440 */
|
59440 | /***/ (function(module, exports) {
|
59441 |
|
59442 | module.exports = {
|
59443 | 'name': 'import',
|
59444 | 'category': 'Core',
|
59445 | 'syntax': ['import(functions)', 'import(functions, options)'],
|
59446 | 'description': 'Import functions or constants from an object.',
|
59447 | 'examples': ['import({myFn: f(x)=x^2, myConstant: 32 })', 'myFn(2)', 'myConstant'],
|
59448 | 'seealso': []
|
59449 | };
|
59450 |
|
59451 | /***/ }),
|
59452 | /* 441 */
|
59453 | /***/ (function(module, exports) {
|
59454 |
|
59455 | module.exports = {
|
59456 | 'name': 'typed',
|
59457 | 'category': 'Core',
|
59458 | 'syntax': ['typed(signatures)', 'typed(name, signatures)'],
|
59459 | 'description': 'Create a typed function.',
|
59460 | 'examples': ['double = typed({ "number, number": f(x)=x+x })', 'double(2)', 'double("hello")'],
|
59461 | 'seealso': []
|
59462 | };
|
59463 |
|
59464 | /***/ }),
|
59465 | /* 442 */
|
59466 | /***/ (function(module, exports) {
|
59467 |
|
59468 | module.exports = {
|
59469 | 'name': 'arg',
|
59470 | 'category': 'Complex',
|
59471 | 'syntax': ['arg(x)'],
|
59472 | 'description': 'Compute the argument of a complex value. If x = a+bi, the argument is computed as atan2(b, a).',
|
59473 | 'examples': ['arg(2 + 2i)', 'atan2(3, 2)', 'arg(2 + 3i)'],
|
59474 | 'seealso': ['re', 'im', 'conj', 'abs']
|
59475 | };
|
59476 |
|
59477 | /***/ }),
|
59478 | /* 443 */
|
59479 | /***/ (function(module, exports) {
|
59480 |
|
59481 | module.exports = {
|
59482 | 'name': 'conj',
|
59483 | 'category': 'Complex',
|
59484 | 'syntax': ['conj(x)'],
|
59485 | 'description': 'Compute the complex conjugate of a complex value. If x = a+bi, the complex conjugate is a-bi.',
|
59486 | 'examples': ['conj(2 + 3i)', 'conj(2 - 3i)', 'conj(-5.2i)'],
|
59487 | 'seealso': ['re', 'im', 'abs', 'arg']
|
59488 | };
|
59489 |
|
59490 | /***/ }),
|
59491 | /* 444 */
|
59492 | /***/ (function(module, exports) {
|
59493 |
|
59494 | module.exports = {
|
59495 | 'name': 're',
|
59496 | 'category': 'Complex',
|
59497 | 'syntax': ['re(x)'],
|
59498 | 'description': 'Get the real part of a complex number.',
|
59499 | 'examples': ['re(2 + 3i)', 'im(2 + 3i)', 're(-5.2i)', 're(2.4)'],
|
59500 | 'seealso': ['im', 'conj', 'abs', 'arg']
|
59501 | };
|
59502 |
|
59503 | /***/ }),
|
59504 | /* 445 */
|
59505 | /***/ (function(module, exports) {
|
59506 |
|
59507 | module.exports = {
|
59508 | 'name': 'im',
|
59509 | 'category': 'Complex',
|
59510 | 'syntax': ['im(x)'],
|
59511 | 'description': 'Get the imaginary part of a complex number.',
|
59512 | 'examples': ['im(2 + 3i)', 're(2 + 3i)', 'im(-5.2i)', 'im(2.4)'],
|
59513 | 'seealso': ['re', 'conj', 'abs', 'arg']
|
59514 | };
|
59515 |
|
59516 | /***/ }),
|
59517 | /* 446 */
|
59518 | /***/ (function(module, exports) {
|
59519 |
|
59520 | module.exports = {
|
59521 | 'name': 'eval',
|
59522 | 'category': 'Expression',
|
59523 | 'syntax': ['eval(expression)', 'eval([expr1, expr2, expr3, ...])'],
|
59524 | 'description': 'Evaluate an expression or an array with expressions.',
|
59525 | 'examples': ['eval("2 + 3")', 'eval("sqrt(" + 4 + ")")'],
|
59526 | 'seealso': []
|
59527 | };
|
59528 |
|
59529 | /***/ }),
|
59530 | /* 447 */
|
59531 | /***/ (function(module, exports) {
|
59532 |
|
59533 | module.exports = {
|
59534 | 'name': 'help',
|
59535 | 'category': 'Expression',
|
59536 | 'syntax': ['help(object)', 'help(string)'],
|
59537 | 'description': 'Display documentation on a function or data type.',
|
59538 | 'examples': ['help(sqrt)', 'help("complex")'],
|
59539 | 'seealso': []
|
59540 | };
|
59541 |
|
59542 | /***/ }),
|
59543 | /* 448 */
|
59544 | /***/ (function(module, exports) {
|
59545 |
|
59546 | module.exports = {
|
59547 | 'name': 'distance',
|
59548 | 'category': 'Geometry',
|
59549 | 'syntax': ['distance([x1, y1], [x2, y2])', 'distance([[x1, y1], [x2, y2])'],
|
59550 | 'description': 'Calculates the Euclidean distance between two points.',
|
59551 | 'examples': ['distance([0,0], [4,4])', 'distance([[0,0], [4,4]])'],
|
59552 | 'seealso': []
|
59553 | };
|
59554 |
|
59555 | /***/ }),
|
59556 | /* 449 */
|
59557 | /***/ (function(module, exports) {
|
59558 |
|
59559 | module.exports = {
|
59560 | 'name': 'intersect',
|
59561 | 'category': 'Geometry',
|
59562 | 'syntax': ['intersect(expr1, expr2, expr3, expr4)', 'intersect(expr1, expr2, expr3)'],
|
59563 | 'description': 'Computes the intersection point of lines and/or planes.',
|
59564 | 'examples': ['intersect([0, 0], [10, 10], [10, 0], [0, 10])', 'intersect([1, 0, 1], [4, -2, 2], [1, 1, 1, 6])'],
|
59565 | 'seealso': []
|
59566 | };
|
59567 |
|
59568 | /***/ }),
|
59569 | /* 450 */
|
59570 | /***/ (function(module, exports) {
|
59571 |
|
59572 | module.exports = {
|
59573 | 'name': 'and',
|
59574 | 'category': 'Logical',
|
59575 | 'syntax': ['x and y', 'and(x, y)'],
|
59576 | 'description': 'Logical and. Test whether two values are both defined with a nonzero/nonempty value.',
|
59577 | 'examples': ['true and false', 'true and true', '2 and 4'],
|
59578 | 'seealso': ['not', 'or', 'xor']
|
59579 | };
|
59580 |
|
59581 | /***/ }),
|
59582 | /* 451 */
|
59583 | /***/ (function(module, exports) {
|
59584 |
|
59585 | module.exports = {
|
59586 | 'name': 'not',
|
59587 | 'category': 'Logical',
|
59588 | 'syntax': ['not x', 'not(x)'],
|
59589 | 'description': 'Logical not. Flips the boolean value of given argument.',
|
59590 | 'examples': ['not true', 'not false', 'not 2', 'not 0'],
|
59591 | 'seealso': ['and', 'or', 'xor']
|
59592 | };
|
59593 |
|
59594 | /***/ }),
|
59595 | /* 452 */
|
59596 | /***/ (function(module, exports) {
|
59597 |
|
59598 | module.exports = {
|
59599 | 'name': 'or',
|
59600 | 'category': 'Logical',
|
59601 | 'syntax': ['x or y', 'or(x, y)'],
|
59602 | 'description': 'Logical or. Test if at least one value is defined with a nonzero/nonempty value.',
|
59603 | 'examples': ['true or false', 'false or false', '0 or 4'],
|
59604 | 'seealso': ['not', 'and', 'xor']
|
59605 | };
|
59606 |
|
59607 | /***/ }),
|
59608 | /* 453 */
|
59609 | /***/ (function(module, exports) {
|
59610 |
|
59611 | module.exports = {
|
59612 | 'name': 'xor',
|
59613 | 'category': 'Logical',
|
59614 | 'syntax': ['x xor y', 'xor(x, y)'],
|
59615 | 'description': 'Logical exclusive or, xor. Test whether one and only one value is defined with a nonzero/nonempty value.',
|
59616 | 'examples': ['true xor false', 'false xor false', 'true xor true', '0 xor 4'],
|
59617 | 'seealso': ['not', 'and', 'or']
|
59618 | };
|
59619 |
|
59620 | /***/ }),
|
59621 | /* 454 */
|
59622 | /***/ (function(module, exports) {
|
59623 |
|
59624 | module.exports = {
|
59625 | 'name': 'column',
|
59626 | 'category': 'Matrix',
|
59627 | 'syntax': ['column(x, index)'],
|
59628 | 'description': 'Return a column from a matrix or array. Index is zero-based.',
|
59629 | 'examples': ['column([[1, 2], [3, 4]], 1)'],
|
59630 | 'seealso': ['row']
|
59631 | };
|
59632 |
|
59633 | /***/ }),
|
59634 | /* 455 */
|
59635 | /***/ (function(module, exports) {
|
59636 |
|
59637 | module.exports = {
|
59638 | 'name': 'concat',
|
59639 | 'category': 'Matrix',
|
59640 | 'syntax': ['concat(A, B, C, ...)', 'concat(A, B, C, ..., dim)'],
|
59641 | 'description': 'Concatenate matrices. By default, the matrices are concatenated by the last dimension. The dimension on which to concatenate can be provided as last argument.',
|
59642 | 'examples': ['A = [1, 2; 5, 6]', 'B = [3, 4; 7, 8]', 'concat(A, B)', 'concat(A, B, 1)', 'concat(A, B, 2)'],
|
59643 | 'seealso': ['det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros']
|
59644 | };
|
59645 |
|
59646 | /***/ }),
|
59647 | /* 456 */
|
59648 | /***/ (function(module, exports) {
|
59649 |
|
59650 | module.exports = {
|
59651 | 'name': 'cross',
|
59652 | 'category': 'Matrix',
|
59653 | 'syntax': ['cross(A, B)'],
|
59654 | 'description': 'Calculate the cross product for two vectors in three dimensional space.',
|
59655 | 'examples': ['cross([1, 1, 0], [0, 1, 1])', 'cross([3, -3, 1], [4, 9, 2])', 'cross([2, 3, 4], [5, 6, 7])'],
|
59656 | 'seealso': ['multiply', 'dot']
|
59657 | };
|
59658 |
|
59659 | /***/ }),
|
59660 | /* 457 */
|
59661 | /***/ (function(module, exports) {
|
59662 |
|
59663 | module.exports = {
|
59664 | 'name': 'transpose',
|
59665 | 'category': 'Matrix',
|
59666 | 'syntax': ['x\'', 'ctranspose(x)'],
|
59667 | 'description': 'Complex Conjugate and Transpose a matrix',
|
59668 | 'examples': ['a = [1, 2, 3; 4, 5, 6]', 'a\'', 'ctranspose(a)'],
|
59669 | 'seealso': ['concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'zeros']
|
59670 | };
|
59671 |
|
59672 | /***/ }),
|
59673 | /* 458 */
|
59674 | /***/ (function(module, exports) {
|
59675 |
|
59676 | module.exports = {
|
59677 | 'name': 'det',
|
59678 | 'category': 'Matrix',
|
59679 | 'syntax': ['det(x)'],
|
59680 | 'description': 'Calculate the determinant of a matrix',
|
59681 | 'examples': ['det([1, 2; 3, 4])', 'det([-2, 2, 3; -1, 1, 3; 2, 0, -1])'],
|
59682 | 'seealso': ['concat', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros']
|
59683 | };
|
59684 |
|
59685 | /***/ }),
|
59686 | /* 459 */
|
59687 | /***/ (function(module, exports) {
|
59688 |
|
59689 | module.exports = {
|
59690 | 'name': 'diag',
|
59691 | 'category': 'Matrix',
|
59692 | 'syntax': ['diag(x)', 'diag(x, k)'],
|
59693 | 'description': 'Create a diagonal matrix or retrieve the diagonal of a matrix. When x is a vector, a matrix with the vector values on the diagonal will be returned. When x is a matrix, a vector with the diagonal values of the matrix is returned. When k is provided, the k-th diagonal will be filled in or retrieved, if k is positive, the values are placed on the super diagonal. When k is negative, the values are placed on the sub diagonal.',
|
59694 | 'examples': ['diag(1:3)', 'diag(1:3, 1)', 'a = [1, 2, 3; 4, 5, 6; 7, 8, 9]', 'diag(a)'],
|
59695 | 'seealso': ['concat', 'det', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros']
|
59696 | };
|
59697 |
|
59698 | /***/ }),
|
59699 | /* 460 */
|
59700 | /***/ (function(module, exports) {
|
59701 |
|
59702 | module.exports = {
|
59703 | 'name': 'dot',
|
59704 | 'category': 'Matrix',
|
59705 | 'syntax': ['dot(A, B)', 'A * B'],
|
59706 | 'description': 'Calculate the dot product of two vectors. ' + 'The dot product of A = [a1, a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] ' + 'is defined as dot(A, B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn',
|
59707 | 'examples': ['dot([2, 4, 1], [2, 2, 3])', '[2, 4, 1] * [2, 2, 3]'],
|
59708 | 'seealso': ['multiply', 'cross']
|
59709 | };
|
59710 |
|
59711 | /***/ }),
|
59712 | /* 461 */
|
59713 | /***/ (function(module, exports) {
|
59714 |
|
59715 | module.exports = {
|
59716 | 'name': 'getMatrixDataType',
|
59717 | 'category': 'Matrix',
|
59718 | 'syntax': ['getMatrixDataType(x)'],
|
59719 | 'description': 'Find the data type of all elements in a matrix or array, ' + 'for example "number" if all items are a number ' + 'and "Complex" if all values are complex numbers. ' + 'If a matrix contains more than one data type, it will return "mixed".',
|
59720 | 'examples': ['getMatrixDataType([1, 2, 3])', 'getMatrixDataType([[5 cm], [2 inch]])', 'getMatrixDataType([1, "text"])', 'getMatrixDataType([1, bignumber(4)])'],
|
59721 | 'seealso': ['matrix', 'sparse', 'typeof']
|
59722 | };
|
59723 |
|
59724 | /***/ }),
|
59725 | /* 462 */
|
59726 | /***/ (function(module, exports) {
|
59727 |
|
59728 | module.exports = {
|
59729 | 'name': 'identity',
|
59730 | 'category': 'Matrix',
|
59731 | 'syntax': ['identity(n)', 'identity(m, n)', 'identity([m, n])'],
|
59732 | 'description': 'Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.',
|
59733 | 'examples': ['identity(3)', 'identity(3, 5)', 'a = [1, 2, 3; 4, 5, 6]', 'identity(size(a))'],
|
59734 | 'seealso': ['concat', 'det', 'diag', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros']
|
59735 | };
|
59736 |
|
59737 | /***/ }),
|
59738 | /* 463 */
|
59739 | /***/ (function(module, exports) {
|
59740 |
|
59741 | module.exports = {
|
59742 | 'name': 'filter',
|
59743 | 'category': 'Matrix',
|
59744 | 'syntax': ['filter(x, test)'],
|
59745 | 'description': 'Filter items in a matrix.',
|
59746 | 'examples': ['isPositive(x) = x > 0', 'filter([6, -2, -1, 4, 3], isPositive)', 'filter([6, -2, 0, 1, 0], x != 0)'],
|
59747 | 'seealso': ['sort', 'map', 'forEach']
|
59748 | };
|
59749 |
|
59750 | /***/ }),
|
59751 | /* 464 */
|
59752 | /***/ (function(module, exports) {
|
59753 |
|
59754 | module.exports = {
|
59755 | 'name': 'flatten',
|
59756 | 'category': 'Matrix',
|
59757 | 'syntax': ['flatten(x)'],
|
59758 | 'description': 'Flatten a multi dimensional matrix into a single dimensional matrix.',
|
59759 | 'examples': ['a = [1, 2, 3; 4, 5, 6]', 'size(a)', 'b = flatten(a)', 'size(b)'],
|
59760 | 'seealso': ['concat', 'resize', 'size', 'squeeze']
|
59761 | };
|
59762 |
|
59763 | /***/ }),
|
59764 | /* 465 */
|
59765 | /***/ (function(module, exports) {
|
59766 |
|
59767 | module.exports = {
|
59768 | 'name': 'forEach',
|
59769 | 'category': 'Matrix',
|
59770 | 'syntax': ['forEach(x, callback)'],
|
59771 | 'description': 'Iterates over all elements of a matrix/array, and executes the given callback function.',
|
59772 | 'examples': ['forEach([1, 2, 3], function(val) { console.log(val) })'],
|
59773 | 'seealso': ['map', 'sort', 'filter']
|
59774 | };
|
59775 |
|
59776 | /***/ }),
|
59777 | /* 466 */
|
59778 | /***/ (function(module, exports) {
|
59779 |
|
59780 | module.exports = {
|
59781 | 'name': 'inv',
|
59782 | 'category': 'Matrix',
|
59783 | 'syntax': ['inv(x)'],
|
59784 | 'description': 'Calculate the inverse of a matrix',
|
59785 | 'examples': ['inv([1, 2; 3, 4])', 'inv(4)', '1 / 4'],
|
59786 | 'seealso': ['concat', 'det', 'diag', 'identity', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros']
|
59787 | };
|
59788 |
|
59789 | /***/ }),
|
59790 | /* 467 */
|
59791 | /***/ (function(module, exports) {
|
59792 |
|
59793 | module.exports = {
|
59794 | 'name': 'kron',
|
59795 | 'category': 'Matrix',
|
59796 | 'syntax': ['kron(x, y)'],
|
59797 | 'description': 'Calculates the kronecker product of 2 matrices or vectors.',
|
59798 | 'examples': ['kron([[1, 0], [0, 1]], [[1, 2], [3, 4]])', 'kron([1,1], [2,3,4])'],
|
59799 | 'seealso': ['multiply', 'dot', 'cross']
|
59800 | };
|
59801 |
|
59802 | /***/ }),
|
59803 | /* 468 */
|
59804 | /***/ (function(module, exports) {
|
59805 |
|
59806 | module.exports = {
|
59807 | 'name': 'map',
|
59808 | 'category': 'Matrix',
|
59809 | 'syntax': ['map(x, callback)'],
|
59810 | 'description': 'Create a new matrix or array with the results of the callback function executed on each entry of the matrix/array.',
|
59811 | 'examples': ['map([1, 2, 3], square)'],
|
59812 | 'seealso': ['filter', 'forEach']
|
59813 | };
|
59814 |
|
59815 | /***/ }),
|
59816 | /* 469 */
|
59817 | /***/ (function(module, exports) {
|
59818 |
|
59819 | module.exports = {
|
59820 | 'name': 'ones',
|
59821 | 'category': 'Matrix',
|
59822 | 'syntax': ['ones(m)', 'ones(m, n)', 'ones(m, n, p, ...)', 'ones([m])', 'ones([m, n])', 'ones([m, n, p, ...])'],
|
59823 | 'description': 'Create a matrix containing ones.',
|
59824 | 'examples': ['ones(3)', 'ones(3, 5)', 'ones([2,3]) * 4.5', 'a = [1, 2, 3; 4, 5, 6]', 'ones(size(a))'],
|
59825 | 'seealso': ['concat', 'det', 'diag', 'identity', 'inv', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros']
|
59826 | };
|
59827 |
|
59828 | /***/ }),
|
59829 | /* 470 */
|
59830 | /***/ (function(module, exports) {
|
59831 |
|
59832 | module.exports = {
|
59833 | 'name': 'partitionSelect',
|
59834 | 'category': 'Matrix',
|
59835 | 'syntax': ['partitionSelect(x, k)', 'partitionSelect(x, k, compare)'],
|
59836 | 'description': 'Partition-based selection of an array or 1D matrix. Will find the kth smallest value, and mutates the input array. Uses Quickselect.',
|
59837 | 'examples': ['partitionSelect([5, 10, 1], 2)', 'partitionSelect(["C", "B", "A", "D"], 1)'],
|
59838 | 'seealso': ['sort']
|
59839 | };
|
59840 |
|
59841 | /***/ }),
|
59842 | /* 471 */
|
59843 | /***/ (function(module, exports) {
|
59844 |
|
59845 | module.exports = {
|
59846 | 'name': 'range',
|
59847 | 'category': 'Type',
|
59848 | 'syntax': ['start:end', 'start:step:end', 'range(start, end)', 'range(start, end, step)', 'range(string)'],
|
59849 | 'description': 'Create a range. Lower bound of the range is included, upper bound is excluded.',
|
59850 | 'examples': ['1:5', '3:-1:-3', 'range(3, 7)', 'range(0, 12, 2)', 'range("4:10")', 'a = [1, 2, 3, 4; 5, 6, 7, 8]', 'a[1:2, 1:2]'],
|
59851 | 'seealso': ['concat', 'det', 'diag', 'identity', 'inv', 'ones', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros']
|
59852 | };
|
59853 |
|
59854 | /***/ }),
|
59855 | /* 472 */
|
59856 | /***/ (function(module, exports) {
|
59857 |
|
59858 | module.exports = {
|
59859 | 'name': 'resize',
|
59860 | 'category': 'Matrix',
|
59861 | 'syntax': ['resize(x, size)', 'resize(x, size, defaultValue)'],
|
59862 | 'description': 'Resize a matrix.',
|
59863 | 'examples': ['resize([1,2,3,4,5], [3])', 'resize([1,2,3], [5])', 'resize([1,2,3], [5], -1)', 'resize(2, [2, 3])', 'resize("hello", [8], "!")'],
|
59864 | 'seealso': ['size', 'subset', 'squeeze', 'reshape']
|
59865 | };
|
59866 |
|
59867 | /***/ }),
|
59868 | /* 473 */
|
59869 | /***/ (function(module, exports) {
|
59870 |
|
59871 | module.exports = {
|
59872 | 'name': 'reshape',
|
59873 | 'category': 'Matrix',
|
59874 | 'syntax': ['reshape(x, sizes)'],
|
59875 | 'description': 'Reshape a multi dimensional array to fit the specified dimensions.',
|
59876 | 'examples': ['reshape([1, 2, 3, 4, 5, 6], [2, 3])', 'reshape([[1, 2], [3, 4]], [1, 4])', 'reshape([[1, 2], [3, 4]], [4])'],
|
59877 | 'seealso': ['size', 'squeeze', 'resize']
|
59878 | };
|
59879 |
|
59880 | /***/ }),
|
59881 | /* 474 */
|
59882 | /***/ (function(module, exports) {
|
59883 |
|
59884 | module.exports = {
|
59885 | 'name': 'row',
|
59886 | 'category': 'Matrix',
|
59887 | 'syntax': ['row(x, index)'],
|
59888 | 'description': 'Return a row from a matrix or array. Index is zero-based.',
|
59889 | 'examples': ['row([[1, 2], [3, 4]], 1)'],
|
59890 | 'seealso': ['column']
|
59891 | };
|
59892 |
|
59893 | /***/ }),
|
59894 | /* 475 */
|
59895 | /***/ (function(module, exports) {
|
59896 |
|
59897 | module.exports = {
|
59898 | 'name': 'size',
|
59899 | 'category': 'Matrix',
|
59900 | 'syntax': ['size(x)'],
|
59901 | 'description': 'Calculate the size of a matrix.',
|
59902 | 'examples': ['size(2.3)', 'size("hello world")', 'a = [1, 2; 3, 4; 5, 6]', 'size(a)', 'size(1:6)'],
|
59903 | 'seealso': ['concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'squeeze', 'subset', 'trace', 'transpose', 'zeros']
|
59904 | };
|
59905 |
|
59906 | /***/ }),
|
59907 | /* 476 */
|
59908 | /***/ (function(module, exports) {
|
59909 |
|
59910 | module.exports = {
|
59911 | 'name': 'sort',
|
59912 | 'category': 'Matrix',
|
59913 | 'syntax': ['sort(x)', 'sort(x, compare)'],
|
59914 | 'description': 'Sort the items in a matrix. Compare can be a string "asc", "desc", "natural", or a custom sort function.',
|
59915 | 'examples': ['sort([5, 10, 1])', 'sort(["C", "B", "A", "D"])', 'sortByLength(a, b) = size(a)[1] - size(b)[1]', 'sort(["Langdon", "Tom", "Sara"], sortByLength)', 'sort(["10", "1", "2"], "natural")'],
|
59916 | 'seealso': ['map', 'filter', 'forEach']
|
59917 | };
|
59918 |
|
59919 | /***/ }),
|
59920 | /* 477 */
|
59921 | /***/ (function(module, exports) {
|
59922 |
|
59923 | module.exports = {
|
59924 | 'name': 'squeeze',
|
59925 | 'category': 'Matrix',
|
59926 | 'syntax': ['squeeze(x)'],
|
59927 | 'description': 'Remove inner and outer singleton dimensions from a matrix.',
|
59928 | 'examples': ['a = zeros(3,2,1)', 'size(squeeze(a))', 'b = zeros(1,1,3)', 'size(squeeze(b))'],
|
59929 | 'seealso': ['concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'subset', 'trace', 'transpose', 'zeros']
|
59930 | };
|
59931 |
|
59932 | /***/ }),
|
59933 | /* 478 */
|
59934 | /***/ (function(module, exports) {
|
59935 |
|
59936 | module.exports = {
|
59937 | 'name': 'subset',
|
59938 | 'category': 'Matrix',
|
59939 | 'syntax': ['value(index)', 'value(index) = replacement', 'subset(value, [index])', 'subset(value, [index], replacement)'],
|
59940 | 'description': 'Get or set a subset of a matrix or string. ' + 'Indexes are one-based. ' + 'Both the ranges lower-bound and upper-bound are included.',
|
59941 | 'examples': ['d = [1, 2; 3, 4]', 'e = []', 'e[1, 1:2] = [5, 6]', 'e[2, :] = [7, 8]', 'f = d * e', 'f[2, 1]', 'f[:, 1]'],
|
59942 | 'seealso': ['concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'trace', 'transpose', 'zeros']
|
59943 | };
|
59944 |
|
59945 | /***/ }),
|
59946 | /* 479 */
|
59947 | /***/ (function(module, exports) {
|
59948 |
|
59949 | module.exports = {
|
59950 | 'name': 'trace',
|
59951 | 'category': 'Matrix',
|
59952 | 'syntax': ['trace(A)'],
|
59953 | 'description': 'Calculate the trace of a matrix: the sum of the elements on the main diagonal of a square matrix.',
|
59954 | 'examples': ['A = [1, 2, 3; -1, 2, 3; 2, 0, 3]', 'trace(A)'],
|
59955 | 'seealso': ['concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros']
|
59956 | };
|
59957 |
|
59958 | /***/ }),
|
59959 | /* 480 */
|
59960 | /***/ (function(module, exports) {
|
59961 |
|
59962 | module.exports = {
|
59963 | 'name': 'transpose',
|
59964 | 'category': 'Matrix',
|
59965 | 'syntax': ['x\'', 'transpose(x)'],
|
59966 | 'description': 'Transpose a matrix',
|
59967 | 'examples': ['a = [1, 2, 3; 4, 5, 6]', 'a\'', 'transpose(a)'],
|
59968 | 'seealso': ['concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'zeros']
|
59969 | };
|
59970 |
|
59971 | /***/ }),
|
59972 | /* 481 */
|
59973 | /***/ (function(module, exports) {
|
59974 |
|
59975 | module.exports = {
|
59976 | 'name': 'zeros',
|
59977 | 'category': 'Matrix',
|
59978 | 'syntax': ['zeros(m)', 'zeros(m, n)', 'zeros(m, n, p, ...)', 'zeros([m])', 'zeros([m, n])', 'zeros([m, n, p, ...])'],
|
59979 | 'description': 'Create a matrix containing zeros.',
|
59980 | 'examples': ['zeros(3)', 'zeros(3, 5)', 'a = [1, 2, 3; 4, 5, 6]', 'zeros(size(a))'],
|
59981 | 'seealso': ['concat', 'det', 'diag', 'identity', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose']
|
59982 | };
|
59983 |
|
59984 | /***/ }),
|
59985 | /* 482 */
|
59986 | /***/ (function(module, exports) {
|
59987 |
|
59988 | module.exports = {
|
59989 | 'name': 'combinations',
|
59990 | 'category': 'Probability',
|
59991 | 'syntax': ['combinations(n, k)'],
|
59992 | 'description': 'Compute the number of combinations of n items taken k at a time',
|
59993 | 'examples': ['combinations(7, 5)'],
|
59994 | 'seealso': ['permutations', 'factorial']
|
59995 | };
|
59996 |
|
59997 | /***/ }),
|
59998 | /* 483 */
|
59999 | /***/ (function(module, exports) {
|
60000 |
|
60001 | module.exports = {
|
60002 | 'name': 'factorial',
|
60003 | 'category': 'Probability',
|
60004 | 'syntax': ['n!', 'factorial(n)'],
|
60005 | 'description': 'Compute the factorial of a value',
|
60006 | 'examples': ['5!', '5 * 4 * 3 * 2 * 1', '3!'],
|
60007 | 'seealso': ['combinations', 'permutations', 'gamma']
|
60008 | };
|
60009 |
|
60010 | /***/ }),
|
60011 | /* 484 */
|
60012 | /***/ (function(module, exports) {
|
60013 |
|
60014 | module.exports = {
|
60015 | 'name': 'gamma',
|
60016 | 'category': 'Probability',
|
60017 | 'syntax': ['gamma(n)'],
|
60018 | 'description': 'Compute the gamma function. For small values, the Lanczos approximation is used, and for large values the extended Stirling approximation.',
|
60019 | 'examples': ['gamma(4)', '3!', 'gamma(1/2)', 'sqrt(pi)'],
|
60020 | 'seealso': ['factorial']
|
60021 | };
|
60022 |
|
60023 | /***/ }),
|
60024 | /* 485 */
|
60025 | /***/ (function(module, exports) {
|
60026 |
|
60027 | module.exports = {
|
60028 | 'name': 'kldivergence',
|
60029 | 'category': 'Probability',
|
60030 | 'syntax': ['kldivergence(x, y)'],
|
60031 | 'description': 'Calculate the Kullback-Leibler (KL) divergence between two distributions.',
|
60032 | 'examples': ['kldivergence([0.7,0.5,0.4], [0.2,0.9,0.5])'],
|
60033 | 'seealso': []
|
60034 | };
|
60035 |
|
60036 | /***/ }),
|
60037 | /* 486 */
|
60038 | /***/ (function(module, exports) {
|
60039 |
|
60040 | module.exports = {
|
60041 | 'name': 'multinomial',
|
60042 | 'category': 'Probability',
|
60043 | 'syntax': ['multinomial(A)'],
|
60044 | 'description': 'Multinomial Coefficients compute the number of ways of picking a1, a2, ..., ai unordered outcomes from `n` possibilities. multinomial takes one array of integers as an argument. The following condition must be enforced: every ai > 0.',
|
60045 | 'examples': ['multinomial([1, 2, 1])'],
|
60046 | 'seealso': ['combinations', 'factorial']
|
60047 | };
|
60048 |
|
60049 | /***/ }),
|
60050 | /* 487 */
|
60051 | /***/ (function(module, exports) {
|
60052 |
|
60053 | module.exports = {
|
60054 | 'name': 'permutations',
|
60055 | 'category': 'Probability',
|
60056 | 'syntax': ['permutations(n)', 'permutations(n, k)'],
|
60057 | 'description': 'Compute the number of permutations of n items taken k at a time',
|
60058 | 'examples': ['permutations(5)', 'permutations(5, 3)'],
|
60059 | 'seealso': ['combinations', 'factorial']
|
60060 | };
|
60061 |
|
60062 | /***/ }),
|
60063 | /* 488 */
|
60064 | /***/ (function(module, exports) {
|
60065 |
|
60066 | module.exports = {
|
60067 | 'name': 'pickRandom',
|
60068 | 'category': 'Probability',
|
60069 | 'syntax': ['pickRandom(array)', 'pickRandom(array, number)', 'pickRandom(array, weights)', 'pickRandom(array, number, weights)', 'pickRandom(array, weights, number)'],
|
60070 | 'description': 'Pick a random entry from a given array.',
|
60071 | 'examples': ['pickRandom(0:10)', 'pickRandom([1, 3, 1, 6])', 'pickRandom([1, 3, 1, 6], 2)', 'pickRandom([1, 3, 1, 6], [2, 3, 2, 1])', 'pickRandom([1, 3, 1, 6], 2, [2, 3, 2, 1])', 'pickRandom([1, 3, 1, 6], [2, 3, 2, 1], 2)'],
|
60072 | 'seealso': ['random', 'randomInt']
|
60073 | };
|
60074 |
|
60075 | /***/ }),
|
60076 | /* 489 */
|
60077 | /***/ (function(module, exports) {
|
60078 |
|
60079 | module.exports = {
|
60080 | 'name': 'random',
|
60081 | 'category': 'Probability',
|
60082 | 'syntax': ['random()', 'random(max)', 'random(min, max)', 'random(size)', 'random(size, max)', 'random(size, min, max)'],
|
60083 | 'description': 'Return a random number.',
|
60084 | 'examples': ['random()', 'random(10, 20)', 'random([2, 3])'],
|
60085 | 'seealso': ['pickRandom', 'randomInt']
|
60086 | };
|
60087 |
|
60088 | /***/ }),
|
60089 | /* 490 */
|
60090 | /***/ (function(module, exports) {
|
60091 |
|
60092 | module.exports = {
|
60093 | 'name': 'randomInt',
|
60094 | 'category': 'Probability',
|
60095 | 'syntax': ['randomInt(max)', 'randomInt(min, max)', 'randomInt(size)', 'randomInt(size, max)', 'randomInt(size, min, max)'],
|
60096 | 'description': 'Return a random integer number',
|
60097 | 'examples': ['randomInt(10, 20)', 'randomInt([2, 3], 10)'],
|
60098 | 'seealso': ['pickRandom', 'random']
|
60099 | };
|
60100 |
|
60101 | /***/ }),
|
60102 | /* 491 */
|
60103 | /***/ (function(module, exports) {
|
60104 |
|
60105 | module.exports = {
|
60106 | 'name': 'compare',
|
60107 | 'category': 'Relational',
|
60108 | 'syntax': ['compare(x, y)'],
|
60109 | 'description': 'Compare two values. ' + 'Returns 1 when x > y, -1 when x < y, and 0 when x == y.',
|
60110 | 'examples': ['compare(2, 3)', 'compare(3, 2)', 'compare(2, 2)', 'compare(5cm, 40mm)', 'compare(2, [1, 2, 3])'],
|
60111 | 'seealso': ['equal', 'unequal', 'smaller', 'smallerEq', 'largerEq', 'compareNatural', 'compareText']
|
60112 | };
|
60113 |
|
60114 | /***/ }),
|
60115 | /* 492 */
|
60116 | /***/ (function(module, exports) {
|
60117 |
|
60118 | module.exports = {
|
60119 | 'name': 'compareNatural',
|
60120 | 'category': 'Relational',
|
60121 | 'syntax': ['compareNatural(x, y)'],
|
60122 | 'description': 'Compare two values of any type in a deterministic, natural way. ' + 'Returns 1 when x > y, -1 when x < y, and 0 when x == y.',
|
60123 | 'examples': ['compareNatural(2, 3)', 'compareNatural(3, 2)', 'compareNatural(2, 2)', 'compareNatural(5cm, 40mm)', 'compareNatural("2", "10")', 'compareNatural(2 + 3i, 2 + 4i)', 'compareNatural([1, 2, 4], [1, 2, 3])', 'compareNatural([1, 5], [1, 2, 3])', 'compareNatural([1, 2], [1, 2])', 'compareNatural({a: 2}, {a: 4})'],
|
60124 | 'seealso': ['equal', 'unequal', 'smaller', 'smallerEq', 'largerEq', 'compare', 'compareText']
|
60125 | };
|
60126 |
|
60127 | /***/ }),
|
60128 | /* 493 */
|
60129 | /***/ (function(module, exports) {
|
60130 |
|
60131 | module.exports = {
|
60132 | 'name': 'compareText',
|
60133 | 'category': 'Relational',
|
60134 | 'syntax': ['compareText(x, y)'],
|
60135 | 'description': 'Compare two strings lexically. Comparison is case sensitive. ' + 'Returns 1 when x > y, -1 when x < y, and 0 when x == y.',
|
60136 | 'examples': ['compareText("B", "A")', 'compareText("A", "B")', 'compareText("A", "A")', 'compareText("2", "10")', 'compare("2", "10")', 'compare(2, 10)', 'compareNatural("2", "10")', 'compareText("B", ["A", "B", "C"])'],
|
60137 | 'seealso': ['compare', 'compareNatural']
|
60138 | };
|
60139 |
|
60140 | /***/ }),
|
60141 | /* 494 */
|
60142 | /***/ (function(module, exports) {
|
60143 |
|
60144 | module.exports = {
|
60145 | 'name': 'deepEqual',
|
60146 | 'category': 'Relational',
|
60147 | 'syntax': ['deepEqual(x, y)'],
|
60148 | 'description': 'Check equality of two matrices element wise. Returns true if the size of both matrices is equal and when and each of the elements are equal.',
|
60149 | 'examples': ['deepEqual([1,3,4], [1,3,4])', 'deepEqual([1,3,4], [1,3])'],
|
60150 | 'seealso': ['equal', 'unequal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare']
|
60151 | };
|
60152 |
|
60153 | /***/ }),
|
60154 | /* 495 */
|
60155 | /***/ (function(module, exports) {
|
60156 |
|
60157 | module.exports = {
|
60158 | 'name': 'equal',
|
60159 | 'category': 'Relational',
|
60160 | 'syntax': ['x == y', 'equal(x, y)'],
|
60161 | 'description': 'Check equality of two values. Returns true if the values are equal, and false if not.',
|
60162 | 'examples': ['2+2 == 3', '2+2 == 4', 'a = 3.2', 'b = 6-2.8', 'a == b', '50cm == 0.5m'],
|
60163 | 'seealso': ['unequal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare', 'deepEqual', 'equalText']
|
60164 | };
|
60165 |
|
60166 | /***/ }),
|
60167 | /* 496 */
|
60168 | /***/ (function(module, exports) {
|
60169 |
|
60170 | module.exports = {
|
60171 | 'name': 'equalText',
|
60172 | 'category': 'Relational',
|
60173 | 'syntax': ['equalText(x, y)'],
|
60174 | 'description': 'Check equality of two strings. Comparison is case sensitive. Returns true if the values are equal, and false if not.',
|
60175 | 'examples': ['equalText("Hello", "Hello")', 'equalText("a", "A")', 'equal("2e3", "2000")', 'equalText("2e3", "2000")', 'equalText("B", ["A", "B", "C"])'],
|
60176 | 'seealso': ['compare', 'compareNatural', 'compareText', 'equal']
|
60177 | };
|
60178 |
|
60179 | /***/ }),
|
60180 | /* 497 */
|
60181 | /***/ (function(module, exports) {
|
60182 |
|
60183 | module.exports = {
|
60184 | 'name': 'larger',
|
60185 | 'category': 'Relational',
|
60186 | 'syntax': ['x > y', 'larger(x, y)'],
|
60187 | 'description': 'Check if value x is larger than y. Returns true if x is larger than y, and false if not.',
|
60188 | 'examples': ['2 > 3', '5 > 2*2', 'a = 3.3', 'b = 6-2.8', '(a > b)', '(b < a)', '5 cm > 2 inch'],
|
60189 | 'seealso': ['equal', 'unequal', 'smaller', 'smallerEq', 'largerEq', 'compare']
|
60190 | };
|
60191 |
|
60192 | /***/ }),
|
60193 | /* 498 */
|
60194 | /***/ (function(module, exports) {
|
60195 |
|
60196 | module.exports = {
|
60197 | 'name': 'largerEq',
|
60198 | 'category': 'Relational',
|
60199 | 'syntax': ['x >= y', 'largerEq(x, y)'],
|
60200 | 'description': 'Check if value x is larger or equal to y. Returns true if x is larger or equal to y, and false if not.',
|
60201 | 'examples': ['2 >= 1+1', '2 > 1+1', 'a = 3.2', 'b = 6-2.8', '(a >= b)'],
|
60202 | 'seealso': ['equal', 'unequal', 'smallerEq', 'smaller', 'compare']
|
60203 | };
|
60204 |
|
60205 | /***/ }),
|
60206 | /* 499 */
|
60207 | /***/ (function(module, exports) {
|
60208 |
|
60209 | module.exports = {
|
60210 | 'name': 'smaller',
|
60211 | 'category': 'Relational',
|
60212 | 'syntax': ['x < y', 'smaller(x, y)'],
|
60213 | 'description': 'Check if value x is smaller than value y. Returns true if x is smaller than y, and false if not.',
|
60214 | 'examples': ['2 < 3', '5 < 2*2', 'a = 3.3', 'b = 6-2.8', '(a < b)', '5 cm < 2 inch'],
|
60215 | 'seealso': ['equal', 'unequal', 'larger', 'smallerEq', 'largerEq', 'compare']
|
60216 | };
|
60217 |
|
60218 | /***/ }),
|
60219 | /* 500 */
|
60220 | /***/ (function(module, exports) {
|
60221 |
|
60222 | module.exports = {
|
60223 | 'name': 'smallerEq',
|
60224 | 'category': 'Relational',
|
60225 | 'syntax': ['x <= y', 'smallerEq(x, y)'],
|
60226 | 'description': 'Check if value x is smaller or equal to value y. Returns true if x is smaller than y, and false if not.',
|
60227 | 'examples': ['2 <= 1+1', '2 < 1+1', 'a = 3.2', 'b = 6-2.8', '(a <= b)'],
|
60228 | 'seealso': ['equal', 'unequal', 'larger', 'smaller', 'largerEq', 'compare']
|
60229 | };
|
60230 |
|
60231 | /***/ }),
|
60232 | /* 501 */
|
60233 | /***/ (function(module, exports) {
|
60234 |
|
60235 | module.exports = {
|
60236 | 'name': 'unequal',
|
60237 | 'category': 'Relational',
|
60238 | 'syntax': ['x != y', 'unequal(x, y)'],
|
60239 | 'description': 'Check unequality of two values. Returns true if the values are unequal, and false if they are equal.',
|
60240 | 'examples': ['2+2 != 3', '2+2 != 4', 'a = 3.2', 'b = 6-2.8', 'a != b', '50cm != 0.5m', '5 cm != 2 inch'],
|
60241 | 'seealso': ['equal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare', 'deepEqual']
|
60242 | };
|
60243 |
|
60244 | /***/ }),
|
60245 | /* 502 */
|
60246 | /***/ (function(module, exports) {
|
60247 |
|
60248 | module.exports = {
|
60249 | 'name': 'setCartesian',
|
60250 | 'category': 'Set',
|
60251 | 'syntax': ['setCartesian(set1, set2)'],
|
60252 | 'description': 'Create the cartesian product of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.',
|
60253 | 'examples': ['setCartesian([1, 2], [3, 4])'],
|
60254 | 'seealso': ['setUnion', 'setIntersect', 'setDifference', 'setPowerset']
|
60255 | };
|
60256 |
|
60257 | /***/ }),
|
60258 | /* 503 */
|
60259 | /***/ (function(module, exports) {
|
60260 |
|
60261 | module.exports = {
|
60262 | 'name': 'setDifference',
|
60263 | 'category': 'Set',
|
60264 | 'syntax': ['setDifference(set1, set2)'],
|
60265 | 'description': 'Create the difference of two (multi)sets: every element of set1, that is not the element of set2. Multi-dimension arrays will be converted to single-dimension arrays before the operation.',
|
60266 | 'examples': ['setDifference([1, 2, 3, 4], [3, 4, 5, 6])', 'setDifference([[1, 2], [3, 4]], [[3, 4], [5, 6]])'],
|
60267 | 'seealso': ['setUnion', 'setIntersect', 'setSymDifference']
|
60268 | };
|
60269 |
|
60270 | /***/ }),
|
60271 | /* 504 */
|
60272 | /***/ (function(module, exports) {
|
60273 |
|
60274 | module.exports = {
|
60275 | 'name': 'setDistinct',
|
60276 | 'category': 'Set',
|
60277 | 'syntax': ['setDistinct(set)'],
|
60278 | 'description': 'Collect the distinct elements of a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.',
|
60279 | 'examples': ['setDistinct([1, 1, 1, 2, 2, 3])'],
|
60280 | 'seealso': ['setMultiplicity']
|
60281 | };
|
60282 |
|
60283 | /***/ }),
|
60284 | /* 505 */
|
60285 | /***/ (function(module, exports) {
|
60286 |
|
60287 | module.exports = {
|
60288 | 'name': 'setIntersect',
|
60289 | 'category': 'Set',
|
60290 | 'syntax': ['setIntersect(set1, set2)'],
|
60291 | 'description': 'Create the intersection of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.',
|
60292 | 'examples': ['setIntersect([1, 2, 3, 4], [3, 4, 5, 6])', 'setIntersect([[1, 2], [3, 4]], [[3, 4], [5, 6]])'],
|
60293 | 'seealso': ['setUnion', 'setDifference']
|
60294 | };
|
60295 |
|
60296 | /***/ }),
|
60297 | /* 506 */
|
60298 | /***/ (function(module, exports) {
|
60299 |
|
60300 | module.exports = {
|
60301 | 'name': 'setIsSubset',
|
60302 | 'category': 'Set',
|
60303 | 'syntax': ['setIsSubset(set1, set2)'],
|
60304 | 'description': 'Check whether a (multi)set is a subset of another (multi)set: every element of set1 is the element of set2. Multi-dimension arrays will be converted to single-dimension arrays before the operation.',
|
60305 | 'examples': ['setIsSubset([1, 2], [3, 4, 5, 6])', 'setIsSubset([3, 4], [3, 4, 5, 6])'],
|
60306 | 'seealso': ['setUnion', 'setIntersect', 'setDifference']
|
60307 | };
|
60308 |
|
60309 | /***/ }),
|
60310 | /* 507 */
|
60311 | /***/ (function(module, exports) {
|
60312 |
|
60313 | module.exports = {
|
60314 | 'name': 'setMultiplicity',
|
60315 | 'category': 'Set',
|
60316 | 'syntax': ['setMultiplicity(element, set)'],
|
60317 | 'description': 'Count the multiplicity of an element in a multiset. A multi-dimension array will be converted to a single-dimension array before the operation.',
|
60318 | 'examples': ['setMultiplicity(1, [1, 2, 2, 4])', 'setMultiplicity(2, [1, 2, 2, 4])'],
|
60319 | 'seealso': ['setDistinct', 'setSize']
|
60320 | };
|
60321 |
|
60322 | /***/ }),
|
60323 | /* 508 */
|
60324 | /***/ (function(module, exports) {
|
60325 |
|
60326 | module.exports = {
|
60327 | 'name': 'setPowerset',
|
60328 | 'category': 'Set',
|
60329 | 'syntax': ['setPowerset(set)'],
|
60330 | 'description': 'Create the powerset of a (multi)set: the powerset contains very possible subsets of a (multi)set. A multi-dimension array will be converted to a single-dimension array before the operation.',
|
60331 | 'examples': ['setPowerset([1, 2, 3])'],
|
60332 | 'seealso': ['setCartesian']
|
60333 | };
|
60334 |
|
60335 | /***/ }),
|
60336 | /* 509 */
|
60337 | /***/ (function(module, exports) {
|
60338 |
|
60339 | module.exports = {
|
60340 | 'name': 'setSize',
|
60341 | 'category': 'Set',
|
60342 | 'syntax': ['setSize(set)', 'setSize(set, unique)'],
|
60343 | 'description': 'Count the number of elements of a (multi)set. When the second parameter "unique" is true, count only the unique values. A multi-dimension array will be converted to a single-dimension array before the operation.',
|
60344 | 'examples': ['setSize([1, 2, 2, 4])', 'setSize([1, 2, 2, 4], true)'],
|
60345 | 'seealso': ['setUnion', 'setIntersect', 'setDifference']
|
60346 | };
|
60347 |
|
60348 | /***/ }),
|
60349 | /* 510 */
|
60350 | /***/ (function(module, exports) {
|
60351 |
|
60352 | module.exports = {
|
60353 | 'name': 'setSymDifference',
|
60354 | 'category': 'Set',
|
60355 | 'syntax': ['setSymDifference(set1, set2)'],
|
60356 | 'description': 'Create the symmetric difference of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.',
|
60357 | 'examples': ['setSymDifference([1, 2, 3, 4], [3, 4, 5, 6])', 'setSymDifference([[1, 2], [3, 4]], [[3, 4], [5, 6]])'],
|
60358 | 'seealso': ['setUnion', 'setIntersect', 'setDifference']
|
60359 | };
|
60360 |
|
60361 | /***/ }),
|
60362 | /* 511 */
|
60363 | /***/ (function(module, exports) {
|
60364 |
|
60365 | module.exports = {
|
60366 | 'name': 'setUnion',
|
60367 | 'category': 'Set',
|
60368 | 'syntax': ['setUnion(set1, set2)'],
|
60369 | 'description': 'Create the union of two (multi)sets. Multi-dimension arrays will be converted to single-dimension arrays before the operation.',
|
60370 | 'examples': ['setUnion([1, 2, 3, 4], [3, 4, 5, 6])', 'setUnion([[1, 2], [3, 4]], [[3, 4], [5, 6]])'],
|
60371 | 'seealso': ['setIntersect', 'setDifference']
|
60372 | };
|
60373 |
|
60374 | /***/ }),
|
60375 | /* 512 */
|
60376 | /***/ (function(module, exports) {
|
60377 |
|
60378 | module.exports = {
|
60379 | 'name': 'erf',
|
60380 | 'category': 'Special',
|
60381 | 'syntax': ['erf(x)'],
|
60382 | 'description': 'Compute the erf function of a value using a rational Chebyshev approximations for different intervals of x',
|
60383 | 'examples': ['erf(0.2)', 'erf(-0.5)', 'erf(4)'],
|
60384 | 'seealso': []
|
60385 | };
|
60386 |
|
60387 | /***/ }),
|
60388 | /* 513 */
|
60389 | /***/ (function(module, exports) {
|
60390 |
|
60391 | module.exports = {
|
60392 | 'name': 'mad',
|
60393 | 'category': 'Statistics',
|
60394 | 'syntax': ['mad(a, b, c, ...)', 'mad(A)'],
|
60395 | 'description': 'Compute the median absolute deviation of a matrix or a list with values. The median absolute deviation is defined as the median of the absolute deviations from the median.',
|
60396 | 'examples': ['mad(10, 20, 30)', 'mad([1, 2, 3])'],
|
60397 | 'seealso': ['mean', 'median', 'std', 'abs']
|
60398 | };
|
60399 |
|
60400 | /***/ }),
|
60401 | /* 514 */
|
60402 | /***/ (function(module, exports) {
|
60403 |
|
60404 | module.exports = {
|
60405 | 'name': 'max',
|
60406 | 'category': 'Statistics',
|
60407 | 'syntax': ['max(a, b, c, ...)', 'max(A)', 'max(A, dim)'],
|
60408 | 'description': 'Compute the maximum value of a list of values.',
|
60409 | 'examples': ['max(2, 3, 4, 1)', 'max([2, 3, 4, 1])', 'max([2, 5; 4, 3])', 'max([2, 5; 4, 3], 1)', 'max([2, 5; 4, 3], 2)', 'max(2.7, 7.1, -4.5, 2.0, 4.1)', 'min(2.7, 7.1, -4.5, 2.0, 4.1)'],
|
60410 | 'seealso': ['mean', 'median', 'min', 'prod', 'std', 'sum', 'var']
|
60411 | };
|
60412 |
|
60413 | /***/ }),
|
60414 | /* 515 */
|
60415 | /***/ (function(module, exports) {
|
60416 |
|
60417 | module.exports = {
|
60418 | 'name': 'mean',
|
60419 | 'category': 'Statistics',
|
60420 | 'syntax': ['mean(a, b, c, ...)', 'mean(A)', 'mean(A, dim)'],
|
60421 | 'description': 'Compute the arithmetic mean of a list of values.',
|
60422 | 'examples': ['mean(2, 3, 4, 1)', 'mean([2, 3, 4, 1])', 'mean([2, 5; 4, 3])', 'mean([2, 5; 4, 3], 1)', 'mean([2, 5; 4, 3], 2)', 'mean([1.0, 2.7, 3.2, 4.0])'],
|
60423 | 'seealso': ['max', 'median', 'min', 'prod', 'std', 'sum', 'var']
|
60424 | };
|
60425 |
|
60426 | /***/ }),
|
60427 | /* 516 */
|
60428 | /***/ (function(module, exports) {
|
60429 |
|
60430 | module.exports = {
|
60431 | 'name': 'median',
|
60432 | 'category': 'Statistics',
|
60433 | 'syntax': ['median(a, b, c, ...)', 'median(A)'],
|
60434 | 'description': 'Compute the median of all values. The values are sorted and the middle value is returned. In case of an even number of values, the average of the two middle values is returned.',
|
60435 | 'examples': ['median(5, 2, 7)', 'median([3, -1, 5, 7])'],
|
60436 | 'seealso': ['max', 'mean', 'min', 'prod', 'std', 'sum', 'var', 'quantileSeq']
|
60437 | };
|
60438 |
|
60439 | /***/ }),
|
60440 | /* 517 */
|
60441 | /***/ (function(module, exports) {
|
60442 |
|
60443 | module.exports = {
|
60444 | 'name': 'min',
|
60445 | 'category': 'Statistics',
|
60446 | 'syntax': ['min(a, b, c, ...)', 'min(A)', 'min(A, dim)'],
|
60447 | 'description': 'Compute the minimum value of a list of values.',
|
60448 | 'examples': ['min(2, 3, 4, 1)', 'min([2, 3, 4, 1])', 'min([2, 5; 4, 3])', 'min([2, 5; 4, 3], 1)', 'min([2, 5; 4, 3], 2)', 'min(2.7, 7.1, -4.5, 2.0, 4.1)', 'max(2.7, 7.1, -4.5, 2.0, 4.1)'],
|
60449 | 'seealso': ['max', 'mean', 'median', 'prod', 'std', 'sum', 'var']
|
60450 | };
|
60451 |
|
60452 | /***/ }),
|
60453 | /* 518 */
|
60454 | /***/ (function(module, exports) {
|
60455 |
|
60456 | module.exports = {
|
60457 | 'name': 'mode',
|
60458 | 'category': 'Statistics',
|
60459 | 'syntax': ['mode(a, b, c, ...)', 'mode(A)', 'mode(A, a, b, B, c, ...)'],
|
60460 | 'description': 'Computes the mode of all values as an array. In case mode being more than one, multiple values are returned in an array.',
|
60461 | 'examples': ['mode(2, 1, 4, 3, 1)', 'mode([1, 2.7, 3.2, 4, 2.7])', 'mode(1, 4, 6, 1, 6)'],
|
60462 | 'seealso': ['max', 'mean', 'min', 'median', 'prod', 'std', 'sum', 'var']
|
60463 | };
|
60464 |
|
60465 | /***/ }),
|
60466 | /* 519 */
|
60467 | /***/ (function(module, exports) {
|
60468 |
|
60469 | module.exports = {
|
60470 | 'name': 'prod',
|
60471 | 'category': 'Statistics',
|
60472 | 'syntax': ['prod(a, b, c, ...)', 'prod(A)'],
|
60473 | 'description': 'Compute the product of all values.',
|
60474 | 'examples': ['prod(2, 3, 4)', 'prod([2, 3, 4])', 'prod([2, 5; 4, 3])'],
|
60475 | 'seealso': ['max', 'mean', 'min', 'median', 'min', 'std', 'sum', 'var']
|
60476 | };
|
60477 |
|
60478 | /***/ }),
|
60479 | /* 520 */
|
60480 | /***/ (function(module, exports) {
|
60481 |
|
60482 | module.exports = {
|
60483 | 'name': 'quantileSeq',
|
60484 | 'category': 'Statistics',
|
60485 | 'syntax': ['quantileSeq(A, prob[, sorted])', 'quantileSeq(A, [prob1, prob2, ...][, sorted])', 'quantileSeq(A, N[, sorted])'],
|
60486 | 'description': 'Compute the prob order quantile of a matrix or a list with values. The sequence is sorted and the middle value is returned. Supported types of sequence values are: Number, BigNumber, Unit Supported types of probablity are: Number, BigNumber. \n\nIn case of a (multi dimensional) array or matrix, the prob order quantile of all elements will be calculated.',
|
60487 | 'examples': ['quantileSeq([3, -1, 5, 7], 0.5)', 'quantileSeq([3, -1, 5, 7], [1/3, 2/3])', 'quantileSeq([3, -1, 5, 7], 2)', 'quantileSeq([-1, 3, 5, 7], 0.5, true)'],
|
60488 | 'seealso': ['mean', 'median', 'min', 'max', 'prod', 'std', 'sum', 'var']
|
60489 | };
|
60490 |
|
60491 | /***/ }),
|
60492 | /* 521 */
|
60493 | /***/ (function(module, exports) {
|
60494 |
|
60495 | module.exports = {
|
60496 | 'name': 'std',
|
60497 | 'category': 'Statistics',
|
60498 | 'syntax': ['std(a, b, c, ...)', 'std(A)', 'std(A, normalization)'],
|
60499 | 'description': 'Compute the standard deviation of all values, defined as std(A) = sqrt(var(A)). Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',
|
60500 | 'examples': ['std(2, 4, 6)', 'std([2, 4, 6, 8])', 'std([2, 4, 6, 8], "uncorrected")', 'std([2, 4, 6, 8], "biased")', 'std([1, 2, 3; 4, 5, 6])'],
|
60501 | 'seealso': ['max', 'mean', 'min', 'median', 'min', 'prod', 'sum', 'var']
|
60502 | };
|
60503 |
|
60504 | /***/ }),
|
60505 | /* 522 */
|
60506 | /***/ (function(module, exports) {
|
60507 |
|
60508 | module.exports = {
|
60509 | 'name': 'sum',
|
60510 | 'category': 'Statistics',
|
60511 | 'syntax': ['sum(a, b, c, ...)', 'sum(A)'],
|
60512 | 'description': 'Compute the sum of all values.',
|
60513 | 'examples': ['sum(2, 3, 4, 1)', 'sum([2, 3, 4, 1])', 'sum([2, 5; 4, 3])'],
|
60514 | 'seealso': ['max', 'mean', 'median', 'min', 'prod', 'std', 'sum', 'var']
|
60515 | };
|
60516 |
|
60517 | /***/ }),
|
60518 | /* 523 */
|
60519 | /***/ (function(module, exports) {
|
60520 |
|
60521 | module.exports = {
|
60522 | 'name': 'var',
|
60523 | 'category': 'Statistics',
|
60524 | 'syntax': ['var(a, b, c, ...)', 'var(A)', 'var(A, normalization)'],
|
60525 | 'description': 'Compute the variance of all values. Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',
|
60526 | 'examples': ['var(2, 4, 6)', 'var([2, 4, 6, 8])', 'var([2, 4, 6, 8], "uncorrected")', 'var([2, 4, 6, 8], "biased")', 'var([1, 2, 3; 4, 5, 6])'],
|
60527 | 'seealso': ['max', 'mean', 'min', 'median', 'min', 'prod', 'std', 'sum']
|
60528 | };
|
60529 |
|
60530 | /***/ }),
|
60531 | /* 524 */
|
60532 | /***/ (function(module, exports) {
|
60533 |
|
60534 | module.exports = {
|
60535 | 'name': 'acos',
|
60536 | 'category': 'Trigonometry',
|
60537 | 'syntax': ['acos(x)'],
|
60538 | 'description': 'Compute the inverse cosine of a value in radians.',
|
60539 | 'examples': ['acos(0.5)', 'acos(cos(2.3))'],
|
60540 | 'seealso': ['cos', 'atan', 'asin']
|
60541 | };
|
60542 |
|
60543 | /***/ }),
|
60544 | /* 525 */
|
60545 | /***/ (function(module, exports) {
|
60546 |
|
60547 | module.exports = {
|
60548 | 'name': 'acosh',
|
60549 | 'category': 'Trigonometry',
|
60550 | 'syntax': ['acosh(x)'],
|
60551 | 'description': 'Calculate the hyperbolic arccos of a value, defined as `acosh(x) = ln(sqrt(x^2 - 1) + x)`.',
|
60552 | 'examples': ['acosh(1.5)'],
|
60553 | 'seealso': ['cosh', 'asinh', 'atanh']
|
60554 | };
|
60555 |
|
60556 | /***/ }),
|
60557 | /* 526 */
|
60558 | /***/ (function(module, exports) {
|
60559 |
|
60560 | module.exports = {
|
60561 | 'name': 'acot',
|
60562 | 'category': 'Trigonometry',
|
60563 | 'syntax': ['acot(x)'],
|
60564 | 'description': 'Calculate the inverse cotangent of a value.',
|
60565 | 'examples': ['acot(0.5)', 'acot(cot(0.5))', 'acot(2)'],
|
60566 | 'seealso': ['cot', 'atan']
|
60567 | };
|
60568 |
|
60569 | /***/ }),
|
60570 | /* 527 */
|
60571 | /***/ (function(module, exports) {
|
60572 |
|
60573 | module.exports = {
|
60574 | 'name': 'acoth',
|
60575 | 'category': 'Trigonometry',
|
60576 | 'syntax': ['acoth(x)'],
|
60577 | 'description': 'Calculate the hyperbolic arccotangent of a value, defined as `acoth(x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.',
|
60578 | 'examples': ['acoth(2)', 'acoth(0.5)'],
|
60579 | 'seealso': ['acsch', 'asech']
|
60580 | };
|
60581 |
|
60582 | /***/ }),
|
60583 | /* 528 */
|
60584 | /***/ (function(module, exports) {
|
60585 |
|
60586 | module.exports = {
|
60587 | 'name': 'acsc',
|
60588 | 'category': 'Trigonometry',
|
60589 | 'syntax': ['acsc(x)'],
|
60590 | 'description': 'Calculate the inverse cotangent of a value.',
|
60591 | 'examples': ['acsc(2)', 'acsc(csc(0.5))', 'acsc(0.5)'],
|
60592 | 'seealso': ['csc', 'asin', 'asec']
|
60593 | };
|
60594 |
|
60595 | /***/ }),
|
60596 | /* 529 */
|
60597 | /***/ (function(module, exports) {
|
60598 |
|
60599 | module.exports = {
|
60600 | 'name': 'acsch',
|
60601 | 'category': 'Trigonometry',
|
60602 | 'syntax': ['acsch(x)'],
|
60603 | 'description': 'Calculate the hyperbolic arccosecant of a value, defined as `acsch(x) = ln(1/x + sqrt(1/x^2 + 1))`.',
|
60604 | 'examples': ['acsch(0.5)'],
|
60605 | 'seealso': ['asech', 'acoth']
|
60606 | };
|
60607 |
|
60608 | /***/ }),
|
60609 | /* 530 */
|
60610 | /***/ (function(module, exports) {
|
60611 |
|
60612 | module.exports = {
|
60613 | 'name': 'asec',
|
60614 | 'category': 'Trigonometry',
|
60615 | 'syntax': ['asec(x)'],
|
60616 | 'description': 'Calculate the inverse secant of a value.',
|
60617 | 'examples': ['asec(0.5)', 'asec(sec(0.5))', 'asec(2)'],
|
60618 | 'seealso': ['acos', 'acot', 'acsc']
|
60619 | };
|
60620 |
|
60621 | /***/ }),
|
60622 | /* 531 */
|
60623 | /***/ (function(module, exports) {
|
60624 |
|
60625 | module.exports = {
|
60626 | 'name': 'asech',
|
60627 | 'category': 'Trigonometry',
|
60628 | 'syntax': ['asech(x)'],
|
60629 | 'description': 'Calculate the inverse secant of a value.',
|
60630 | 'examples': ['asech(0.5)'],
|
60631 | 'seealso': ['acsch', 'acoth']
|
60632 | };
|
60633 |
|
60634 | /***/ }),
|
60635 | /* 532 */
|
60636 | /***/ (function(module, exports) {
|
60637 |
|
60638 | module.exports = {
|
60639 | 'name': 'asin',
|
60640 | 'category': 'Trigonometry',
|
60641 | 'syntax': ['asin(x)'],
|
60642 | 'description': 'Compute the inverse sine of a value in radians.',
|
60643 | 'examples': ['asin(0.5)', 'asin(sin(0.5))'],
|
60644 | 'seealso': ['sin', 'acos', 'atan']
|
60645 | };
|
60646 |
|
60647 | /***/ }),
|
60648 | /* 533 */
|
60649 | /***/ (function(module, exports) {
|
60650 |
|
60651 | module.exports = {
|
60652 | 'name': 'asinh',
|
60653 | 'category': 'Trigonometry',
|
60654 | 'syntax': ['asinh(x)'],
|
60655 | 'description': 'Calculate the hyperbolic arcsine of a value, defined as `asinh(x) = ln(x + sqrt(x^2 + 1))`.',
|
60656 | 'examples': ['asinh(0.5)'],
|
60657 | 'seealso': ['acosh', 'atanh']
|
60658 | };
|
60659 |
|
60660 | /***/ }),
|
60661 | /* 534 */
|
60662 | /***/ (function(module, exports) {
|
60663 |
|
60664 | module.exports = {
|
60665 | 'name': 'atan',
|
60666 | 'category': 'Trigonometry',
|
60667 | 'syntax': ['atan(x)'],
|
60668 | 'description': 'Compute the inverse tangent of a value in radians.',
|
60669 | 'examples': ['atan(0.5)', 'atan(tan(0.5))'],
|
60670 | 'seealso': ['tan', 'acos', 'asin']
|
60671 | };
|
60672 |
|
60673 | /***/ }),
|
60674 | /* 535 */
|
60675 | /***/ (function(module, exports) {
|
60676 |
|
60677 | module.exports = {
|
60678 | 'name': 'atanh',
|
60679 | 'category': 'Trigonometry',
|
60680 | 'syntax': ['atanh(x)'],
|
60681 | 'description': 'Calculate the hyperbolic arctangent of a value, defined as `atanh(x) = ln((1 + x)/(1 - x)) / 2`.',
|
60682 | 'examples': ['atanh(0.5)'],
|
60683 | 'seealso': ['acosh', 'asinh']
|
60684 | };
|
60685 |
|
60686 | /***/ }),
|
60687 | /* 536 */
|
60688 | /***/ (function(module, exports) {
|
60689 |
|
60690 | module.exports = {
|
60691 | 'name': 'atan2',
|
60692 | 'category': 'Trigonometry',
|
60693 | 'syntax': ['atan2(y, x)'],
|
60694 | 'description': 'Computes the principal value of the arc tangent of y/x in radians.',
|
60695 | 'examples': ['atan2(2, 2) / pi', 'angle = 60 deg in rad', 'x = cos(angle)', 'y = sin(angle)', 'atan2(y, x)'],
|
60696 | 'seealso': ['sin', 'cos', 'tan']
|
60697 | };
|
60698 |
|
60699 | /***/ }),
|
60700 | /* 537 */
|
60701 | /***/ (function(module, exports) {
|
60702 |
|
60703 | module.exports = {
|
60704 | 'name': 'cos',
|
60705 | 'category': 'Trigonometry',
|
60706 | 'syntax': ['cos(x)'],
|
60707 | 'description': 'Compute the cosine of x in radians.',
|
60708 | 'examples': ['cos(2)', 'cos(pi / 4) ^ 2', 'cos(180 deg)', 'cos(60 deg)', 'sin(0.2)^2 + cos(0.2)^2'],
|
60709 | 'seealso': ['acos', 'sin', 'tan']
|
60710 | };
|
60711 |
|
60712 | /***/ }),
|
60713 | /* 538 */
|
60714 | /***/ (function(module, exports) {
|
60715 |
|
60716 | module.exports = {
|
60717 | 'name': 'cosh',
|
60718 | 'category': 'Trigonometry',
|
60719 | 'syntax': ['cosh(x)'],
|
60720 | 'description': 'Compute the hyperbolic cosine of x in radians.',
|
60721 | 'examples': ['cosh(0.5)'],
|
60722 | 'seealso': ['sinh', 'tanh', 'coth']
|
60723 | };
|
60724 |
|
60725 | /***/ }),
|
60726 | /* 539 */
|
60727 | /***/ (function(module, exports) {
|
60728 |
|
60729 | module.exports = {
|
60730 | 'name': 'cot',
|
60731 | 'category': 'Trigonometry',
|
60732 | 'syntax': ['cot(x)'],
|
60733 | 'description': 'Compute the cotangent of x in radians. Defined as 1/tan(x)',
|
60734 | 'examples': ['cot(2)', '1 / tan(2)'],
|
60735 | 'seealso': ['sec', 'csc', 'tan']
|
60736 | };
|
60737 |
|
60738 | /***/ }),
|
60739 | /* 540 */
|
60740 | /***/ (function(module, exports) {
|
60741 |
|
60742 | module.exports = {
|
60743 | 'name': 'coth',
|
60744 | 'category': 'Trigonometry',
|
60745 | 'syntax': ['coth(x)'],
|
60746 | 'description': 'Compute the hyperbolic cotangent of x in radians.',
|
60747 | 'examples': ['coth(2)', '1 / tanh(2)'],
|
60748 | 'seealso': ['sech', 'csch', 'tanh']
|
60749 | };
|
60750 |
|
60751 | /***/ }),
|
60752 | /* 541 */
|
60753 | /***/ (function(module, exports) {
|
60754 |
|
60755 | module.exports = {
|
60756 | 'name': 'csc',
|
60757 | 'category': 'Trigonometry',
|
60758 | 'syntax': ['csc(x)'],
|
60759 | 'description': 'Compute the cosecant of x in radians. Defined as 1/sin(x)',
|
60760 | 'examples': ['csc(2)', '1 / sin(2)'],
|
60761 | 'seealso': ['sec', 'cot', 'sin']
|
60762 | };
|
60763 |
|
60764 | /***/ }),
|
60765 | /* 542 */
|
60766 | /***/ (function(module, exports) {
|
60767 |
|
60768 | module.exports = {
|
60769 | 'name': 'csch',
|
60770 | 'category': 'Trigonometry',
|
60771 | 'syntax': ['csch(x)'],
|
60772 | 'description': 'Compute the hyperbolic cosecant of x in radians. Defined as 1/sinh(x)',
|
60773 | 'examples': ['csch(2)', '1 / sinh(2)'],
|
60774 | 'seealso': ['sech', 'coth', 'sinh']
|
60775 | };
|
60776 |
|
60777 | /***/ }),
|
60778 | /* 543 */
|
60779 | /***/ (function(module, exports) {
|
60780 |
|
60781 | module.exports = {
|
60782 | 'name': 'sec',
|
60783 | 'category': 'Trigonometry',
|
60784 | 'syntax': ['sec(x)'],
|
60785 | 'description': 'Compute the secant of x in radians. Defined as 1/cos(x)',
|
60786 | 'examples': ['sec(2)', '1 / cos(2)'],
|
60787 | 'seealso': ['cot', 'csc', 'cos']
|
60788 | };
|
60789 |
|
60790 | /***/ }),
|
60791 | /* 544 */
|
60792 | /***/ (function(module, exports) {
|
60793 |
|
60794 | module.exports = {
|
60795 | 'name': 'sech',
|
60796 | 'category': 'Trigonometry',
|
60797 | 'syntax': ['sech(x)'],
|
60798 | 'description': 'Compute the hyperbolic secant of x in radians. Defined as 1/cosh(x)',
|
60799 | 'examples': ['sech(2)', '1 / cosh(2)'],
|
60800 | 'seealso': ['coth', 'csch', 'cosh']
|
60801 | };
|
60802 |
|
60803 | /***/ }),
|
60804 | /* 545 */
|
60805 | /***/ (function(module, exports) {
|
60806 |
|
60807 | module.exports = {
|
60808 | 'name': 'sin',
|
60809 | 'category': 'Trigonometry',
|
60810 | 'syntax': ['sin(x)'],
|
60811 | 'description': 'Compute the sine of x in radians.',
|
60812 | 'examples': ['sin(2)', 'sin(pi / 4) ^ 2', 'sin(90 deg)', 'sin(30 deg)', 'sin(0.2)^2 + cos(0.2)^2'],
|
60813 | 'seealso': ['asin', 'cos', 'tan']
|
60814 | };
|
60815 |
|
60816 | /***/ }),
|
60817 | /* 546 */
|
60818 | /***/ (function(module, exports) {
|
60819 |
|
60820 | module.exports = {
|
60821 | 'name': 'sinh',
|
60822 | 'category': 'Trigonometry',
|
60823 | 'syntax': ['sinh(x)'],
|
60824 | 'description': 'Compute the hyperbolic sine of x in radians.',
|
60825 | 'examples': ['sinh(0.5)'],
|
60826 | 'seealso': ['cosh', 'tanh']
|
60827 | };
|
60828 |
|
60829 | /***/ }),
|
60830 | /* 547 */
|
60831 | /***/ (function(module, exports) {
|
60832 |
|
60833 | module.exports = {
|
60834 | 'name': 'tan',
|
60835 | 'category': 'Trigonometry',
|
60836 | 'syntax': ['tan(x)'],
|
60837 | 'description': 'Compute the tangent of x in radians.',
|
60838 | 'examples': ['tan(0.5)', 'sin(0.5) / cos(0.5)', 'tan(pi / 4)', 'tan(45 deg)'],
|
60839 | 'seealso': ['atan', 'sin', 'cos']
|
60840 | };
|
60841 |
|
60842 | /***/ }),
|
60843 | /* 548 */
|
60844 | /***/ (function(module, exports) {
|
60845 |
|
60846 | module.exports = {
|
60847 | 'name': 'tanh',
|
60848 | 'category': 'Trigonometry',
|
60849 | 'syntax': ['tanh(x)'],
|
60850 | 'description': 'Compute the hyperbolic tangent of x in radians.',
|
60851 | 'examples': ['tanh(0.5)', 'sinh(0.5) / cosh(0.5)'],
|
60852 | 'seealso': ['sinh', 'cosh']
|
60853 | };
|
60854 |
|
60855 | /***/ }),
|
60856 | /* 549 */
|
60857 | /***/ (function(module, exports) {
|
60858 |
|
60859 | module.exports = {
|
60860 | 'name': 'to',
|
60861 | 'category': 'Units',
|
60862 | 'syntax': ['x to unit', 'to(x, unit)'],
|
60863 | 'description': 'Change the unit of a value.',
|
60864 | 'examples': ['5 inch to cm', '3.2kg to g', '16 bytes in bits'],
|
60865 | 'seealso': []
|
60866 | };
|
60867 |
|
60868 | /***/ }),
|
60869 | /* 550 */
|
60870 | /***/ (function(module, exports) {
|
60871 |
|
60872 | module.exports = {
|
60873 | 'name': 'clone',
|
60874 | 'category': 'Utils',
|
60875 | 'syntax': ['clone(x)'],
|
60876 | 'description': 'Clone a variable. Creates a copy of primitive variables,and a deep copy of matrices',
|
60877 | 'examples': ['clone(3.5)', 'clone(2 - 4i)', 'clone(45 deg)', 'clone([1, 2; 3, 4])', 'clone("hello world")'],
|
60878 | 'seealso': []
|
60879 | };
|
60880 |
|
60881 | /***/ }),
|
60882 | /* 551 */
|
60883 | /***/ (function(module, exports) {
|
60884 |
|
60885 | module.exports = {
|
60886 | 'name': 'format',
|
60887 | 'category': 'Utils',
|
60888 | 'syntax': ['format(value)', 'format(value, precision)'],
|
60889 | 'description': 'Format a value of any type as string.',
|
60890 | 'examples': ['format(2.3)', 'format(3 - 4i)', 'format([])', 'format(pi, 3)'],
|
60891 | 'seealso': ['print']
|
60892 | };
|
60893 |
|
60894 | /***/ }),
|
60895 | /* 552 */
|
60896 | /***/ (function(module, exports) {
|
60897 |
|
60898 | module.exports = {
|
60899 | 'name': 'isNaN',
|
60900 | 'category': 'Utils',
|
60901 | 'syntax': ['isNaN(x)'],
|
60902 | 'description': 'Test whether a value is NaN (not a number)',
|
60903 | 'examples': ['isNaN(2)', 'isNaN(0 / 0)', 'isNaN(NaN)', 'isNaN(Infinity)'],
|
60904 | 'seealso': ['isNegative', 'isNumeric', 'isPositive', 'isZero']
|
60905 | };
|
60906 |
|
60907 | /***/ }),
|
60908 | /* 553 */
|
60909 | /***/ (function(module, exports) {
|
60910 |
|
60911 | module.exports = {
|
60912 | 'name': 'isInteger',
|
60913 | 'category': 'Utils',
|
60914 | 'syntax': ['isInteger(x)'],
|
60915 | 'description': 'Test whether a value is an integer number.',
|
60916 | 'examples': ['isInteger(2)', 'isInteger(3.5)', 'isInteger([3, 0.5, -2])'],
|
60917 | 'seealso': ['isNegative', 'isNumeric', 'isPositive', 'isZero']
|
60918 | };
|
60919 |
|
60920 | /***/ }),
|
60921 | /* 554 */
|
60922 | /***/ (function(module, exports) {
|
60923 |
|
60924 | module.exports = {
|
60925 | 'name': 'isNegative',
|
60926 | 'category': 'Utils',
|
60927 | 'syntax': ['isNegative(x)'],
|
60928 | 'description': 'Test whether a value is negative: smaller than zero.',
|
60929 | 'examples': ['isNegative(2)', 'isNegative(0)', 'isNegative(-4)', 'isNegative([3, 0.5, -2])'],
|
60930 | 'seealso': ['isInteger', 'isNumeric', 'isPositive', 'isZero']
|
60931 | };
|
60932 |
|
60933 | /***/ }),
|
60934 | /* 555 */
|
60935 | /***/ (function(module, exports) {
|
60936 |
|
60937 | module.exports = {
|
60938 | 'name': 'isNumeric',
|
60939 | 'category': 'Utils',
|
60940 | 'syntax': ['isNumeric(x)'],
|
60941 | 'description': 'Test whether a value is a numeric value. ' + 'Returns true when the input is a number, BigNumber, Fraction, or boolean.',
|
60942 | 'examples': ['isNumeric(2)', 'isNumeric("2")', 'hasNumericValue("2")', 'isNumeric(0)', 'isNumeric(bignumber(500))', 'isNumeric(fraction(0.125))', 'isNumeric(2 + 3i)', 'isNumeric([2.3, "foo", false])'],
|
60943 | 'seealso': ['isInteger', 'isZero', 'isNegative', 'isPositive', 'isNaN', 'hasNumericValue']
|
60944 | };
|
60945 |
|
60946 | /***/ }),
|
60947 | /* 556 */
|
60948 | /***/ (function(module, exports) {
|
60949 |
|
60950 | module.exports = {
|
60951 | 'name': 'hasNumericValue',
|
60952 | 'category': 'Utils',
|
60953 | 'syntax': ['hasNumericValue(x)'],
|
60954 | 'description': 'Test whether a value is an numeric value. ' + 'In case of a string, true is returned if the string contains a numeric value.',
|
60955 | 'examples': ['hasNumericValue(2)', 'hasNumericValue("2")', 'isNumeric("2")', 'hasNumericValue(0)', 'hasNumericValue(bignumber(500))', 'hasNumericValue(fraction(0.125))', 'hasNumericValue(2 + 3i)', 'hasNumericValue([2.3, "foo", false])'],
|
60956 | 'seealso': ['isInteger', 'isZero', 'isNegative', 'isPositive', 'isNaN', 'isNumeric']
|
60957 | };
|
60958 |
|
60959 | /***/ }),
|
60960 | /* 557 */
|
60961 | /***/ (function(module, exports) {
|
60962 |
|
60963 | module.exports = {
|
60964 | 'name': 'isPositive',
|
60965 | 'category': 'Utils',
|
60966 | 'syntax': ['isPositive(x)'],
|
60967 | 'description': 'Test whether a value is positive: larger than zero.',
|
60968 | 'examples': ['isPositive(2)', 'isPositive(0)', 'isPositive(-4)', 'isPositive([3, 0.5, -2])'],
|
60969 | 'seealso': ['isInteger', 'isNumeric', 'isNegative', 'isZero']
|
60970 | };
|
60971 |
|
60972 | /***/ }),
|
60973 | /* 558 */
|
60974 | /***/ (function(module, exports) {
|
60975 |
|
60976 | module.exports = {
|
60977 | 'name': 'isPrime',
|
60978 | 'category': 'Utils',
|
60979 | 'syntax': ['isPrime(x)'],
|
60980 | 'description': 'Test whether a value is prime: has no divisors other than itself and one.',
|
60981 | 'examples': ['isPrime(3)', 'isPrime(-2)', 'isPrime([2, 17, 100])'],
|
60982 | 'seealso': ['isInteger', 'isNumeric', 'isNegative', 'isZero']
|
60983 | };
|
60984 |
|
60985 | /***/ }),
|
60986 | /* 559 */
|
60987 | /***/ (function(module, exports) {
|
60988 |
|
60989 | module.exports = {
|
60990 | 'name': 'isZero',
|
60991 | 'category': 'Utils',
|
60992 | 'syntax': ['isZero(x)'],
|
60993 | 'description': 'Test whether a value is zero.',
|
60994 | 'examples': ['isZero(2)', 'isZero(0)', 'isZero(-4)', 'isZero([3, 0, -2, 0])'],
|
60995 | 'seealso': ['isInteger', 'isNumeric', 'isNegative', 'isPositive']
|
60996 | };
|
60997 |
|
60998 | /***/ }),
|
60999 | /* 560 */
|
61000 | /***/ (function(module, exports) {
|
61001 |
|
61002 | module.exports = {
|
61003 | 'name': 'typeof',
|
61004 | 'category': 'Utils',
|
61005 | 'syntax': ['typeof(x)'],
|
61006 | 'description': 'Get the type of a variable.',
|
61007 | 'examples': ['typeof(3.5)', 'typeof(2 - 4i)', 'typeof(45 deg)', 'typeof("hello world")'],
|
61008 | 'seealso': ['getMatrixDataType']
|
61009 | };
|
61010 |
|
61011 | /***/ }),
|
61012 | /* 561 */
|
61013 | /***/ (function(module, exports, __webpack_require__) {
|
61014 |
|
61015 | "use strict";
|
61016 |
|
61017 |
|
61018 | module.exports = [__webpack_require__(562), __webpack_require__(563), __webpack_require__(564), __webpack_require__(129), __webpack_require__(158)];
|
61019 |
|
61020 | /***/ }),
|
61021 | /* 562 */
|
61022 | /***/ (function(module, exports, __webpack_require__) {
|
61023 |
|
61024 | "use strict";
|
61025 |
|
61026 |
|
61027 | var deepMap = __webpack_require__(1);
|
61028 |
|
61029 | function factory(type, config, load, typed) {
|
61030 | var parse = load(__webpack_require__(44));
|
61031 | /**
|
61032 | * Parse and compile an expression.
|
61033 | * Returns a an object with a function `eval([scope])` to evaluate the
|
61034 | * compiled expression.
|
61035 | *
|
61036 | * Syntax:
|
61037 | *
|
61038 | * math.compile(expr) // returns one node
|
61039 | * math.compile([expr1, expr2, expr3, ...]) // returns an array with nodes
|
61040 | *
|
61041 | * Examples:
|
61042 | *
|
61043 | * const code1 = math.compile('sqrt(3^2 + 4^2)')
|
61044 | * code1.eval() // 5
|
61045 | *
|
61046 | * let scope = {a: 3, b: 4}
|
61047 | * const code2 = math.compile('a * b') // 12
|
61048 | * code2.eval(scope) // 12
|
61049 | * scope.a = 5
|
61050 | * code2.eval(scope) // 20
|
61051 | *
|
61052 | * const nodes = math.compile(['a = 3', 'b = 4', 'a * b'])
|
61053 | * nodes[2].eval() // 12
|
61054 | *
|
61055 | * See also:
|
61056 | *
|
61057 | * parse, eval
|
61058 | *
|
61059 | * @param {string | string[] | Array | Matrix} expr
|
61060 | * The expression to be compiled
|
61061 | * @return {{eval: Function} | Array.<{eval: Function}>} code
|
61062 | * An object with the compiled expression
|
61063 | * @throws {Error}
|
61064 | */
|
61065 |
|
61066 | return typed('compile', {
|
61067 | 'string': function string(expr) {
|
61068 | return parse(expr).compile();
|
61069 | },
|
61070 | 'Array | Matrix': function ArrayMatrix(expr) {
|
61071 | return deepMap(expr, function (entry) {
|
61072 | return parse(entry).compile();
|
61073 | });
|
61074 | }
|
61075 | });
|
61076 | }
|
61077 |
|
61078 | exports.name = 'compile';
|
61079 | exports.factory = factory;
|
61080 |
|
61081 | /***/ }),
|
61082 | /* 563 */
|
61083 | /***/ (function(module, exports, __webpack_require__) {
|
61084 |
|
61085 | "use strict";
|
61086 |
|
61087 |
|
61088 | var deepMap = __webpack_require__(1);
|
61089 |
|
61090 | function factory(type, config, load, typed) {
|
61091 | var parse = load(__webpack_require__(44));
|
61092 | /**
|
61093 | * Evaluate an expression.
|
61094 | *
|
61095 | * Note the evaluating arbitrary expressions may involve security risks,
|
61096 | * see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information.
|
61097 | *
|
61098 | * Syntax:
|
61099 | *
|
61100 | * math.eval(expr)
|
61101 | * math.eval(expr, scope)
|
61102 | * math.eval([expr1, expr2, expr3, ...])
|
61103 | * math.eval([expr1, expr2, expr3, ...], scope)
|
61104 | *
|
61105 | * Example:
|
61106 | *
|
61107 | * math.eval('(2+3)/4') // 1.25
|
61108 | * math.eval('sqrt(3^2 + 4^2)') // 5
|
61109 | * math.eval('sqrt(-4)') // 2i
|
61110 | * math.eval(['a=3', 'b=4', 'a*b']) // [3, 4, 12]
|
61111 | *
|
61112 | * let scope = {a:3, b:4}
|
61113 | * math.eval('a * b', scope) // 12
|
61114 | *
|
61115 | * See also:
|
61116 | *
|
61117 | * parse, compile
|
61118 | *
|
61119 | * @param {string | string[] | Matrix} expr The expression to be evaluated
|
61120 | * @param {Object} [scope] Scope to read/write variables
|
61121 | * @return {*} The result of the expression
|
61122 | * @throws {Error}
|
61123 | */
|
61124 |
|
61125 | return typed('compile', {
|
61126 | 'string': function string(expr) {
|
61127 | var scope = {};
|
61128 | return parse(expr).compile().eval(scope);
|
61129 | },
|
61130 | 'string, Object': function stringObject(expr, scope) {
|
61131 | return parse(expr).compile().eval(scope);
|
61132 | },
|
61133 | 'Array | Matrix': function ArrayMatrix(expr) {
|
61134 | var scope = {};
|
61135 | return deepMap(expr, function (entry) {
|
61136 | return parse(entry).compile().eval(scope);
|
61137 | });
|
61138 | },
|
61139 | 'Array | Matrix, Object': function ArrayMatrixObject(expr, scope) {
|
61140 | return deepMap(expr, function (entry) {
|
61141 | return parse(entry).compile().eval(scope);
|
61142 | });
|
61143 | }
|
61144 | });
|
61145 | }
|
61146 |
|
61147 | exports.name = 'eval';
|
61148 | exports.factory = factory;
|
61149 |
|
61150 | /***/ }),
|
61151 | /* 564 */
|
61152 | /***/ (function(module, exports, __webpack_require__) {
|
61153 |
|
61154 | "use strict";
|
61155 |
|
61156 |
|
61157 | var getSafeProperty = __webpack_require__(13).getSafeProperty;
|
61158 |
|
61159 | function factory(type, config, load, typed, math) {
|
61160 | var docs = load(__webpack_require__(155));
|
61161 | /**
|
61162 | * Retrieve help on a function or data type.
|
61163 | * Help files are retrieved from the documentation in math.expression.docs.
|
61164 | *
|
61165 | * Syntax:
|
61166 | *
|
61167 | * math.help(search)
|
61168 | *
|
61169 | * Examples:
|
61170 | *
|
61171 | * console.log(math.help('sin').toString())
|
61172 | * console.log(math.help(math.add).toString())
|
61173 | * console.log(math.help(math.add).toJSON())
|
61174 | *
|
61175 | * @param {Function | string | Object} search A function or function name
|
61176 | * for which to get help
|
61177 | * @return {Help} A help object
|
61178 | */
|
61179 |
|
61180 | return typed('help', {
|
61181 | 'any': function any(search) {
|
61182 | var prop;
|
61183 | var name = search;
|
61184 |
|
61185 | if (typeof search !== 'string') {
|
61186 | for (prop in math) {
|
61187 | // search in functions and constants
|
61188 | if (math.hasOwnProperty(prop) && search === math[prop]) {
|
61189 | name = prop;
|
61190 | break;
|
61191 | }
|
61192 | }
|
61193 | /* TODO: implement help for data types
|
61194 | if (!text) {
|
61195 | // search data type
|
61196 | for (prop in math.type) {
|
61197 | if (math.type.hasOwnProperty(prop)) {
|
61198 | if (search === math.type[prop]) {
|
61199 | text = prop
|
61200 | break
|
61201 | }
|
61202 | }
|
61203 | }
|
61204 | }
|
61205 | */
|
61206 |
|
61207 | }
|
61208 |
|
61209 | var doc = getSafeProperty(docs, name);
|
61210 |
|
61211 | if (!doc) {
|
61212 | throw new Error('No documentation found on "' + name + '"');
|
61213 | }
|
61214 |
|
61215 | return new type.Help(doc);
|
61216 | }
|
61217 | });
|
61218 | }
|
61219 |
|
61220 | exports.math = true; // request access to the math namespace as 5th argument of the factory function
|
61221 |
|
61222 | exports.name = 'help';
|
61223 | exports.factory = factory;
|
61224 |
|
61225 | /***/ }),
|
61226 | /* 565 */
|
61227 | /***/ (function(module, exports, __webpack_require__) {
|
61228 |
|
61229 | "use strict";
|
61230 |
|
61231 |
|
61232 | module.exports = [__webpack_require__(113), __webpack_require__(116), __webpack_require__(117), __webpack_require__(118), __webpack_require__(119), __webpack_require__(58), __webpack_require__(121), __webpack_require__(120), __webpack_require__(69), __webpack_require__(16), __webpack_require__(122), __webpack_require__(59), __webpack_require__(68), __webpack_require__(123), __webpack_require__(124), __webpack_require__(54), __webpack_require__(566)];
|
61233 |
|
61234 | /***/ }),
|
61235 | /* 566 */
|
61236 | /***/ (function(module, exports, __webpack_require__) {
|
61237 |
|
61238 | "use strict";
|
61239 |
|
61240 |
|
61241 | function factory(type, config, load, typed) {
|
61242 | /**
|
61243 | * @constructor UpdateNode
|
61244 | */
|
61245 | function UpdateNode() {
|
61246 | // TODO: deprecated since v3. Cleanup some day
|
61247 | throw new Error('UpdateNode is deprecated. Use AssignmentNode instead.');
|
61248 | }
|
61249 |
|
61250 | return UpdateNode;
|
61251 | }
|
61252 |
|
61253 | exports.name = 'UpdateNode';
|
61254 | exports.path = 'expression.node';
|
61255 | exports.factory = factory;
|
61256 |
|
61257 | /***/ }),
|
61258 | /* 567 */
|
61259 | /***/ (function(module, exports, __webpack_require__) {
|
61260 |
|
61261 | "use strict";
|
61262 |
|
61263 |
|
61264 | module.exports = [__webpack_require__(568), __webpack_require__(569), __webpack_require__(570), __webpack_require__(571), __webpack_require__(572), __webpack_require__(573), __webpack_require__(574), __webpack_require__(575), __webpack_require__(576), __webpack_require__(577), __webpack_require__(578), __webpack_require__(579), __webpack_require__(580), __webpack_require__(581), __webpack_require__(582), __webpack_require__(583)];
|
61265 |
|
61266 | /***/ }),
|
61267 | /* 568 */
|
61268 | /***/ (function(module, exports, __webpack_require__) {
|
61269 |
|
61270 | "use strict";
|
61271 |
|
61272 |
|
61273 | var errorTransform = __webpack_require__(22).transform;
|
61274 | /**
|
61275 | * Attach a transform function to math.apply
|
61276 | * Adds a property transform containing the transform function.
|
61277 | *
|
61278 | * This transform changed the last `dim` parameter of function apply
|
61279 | * from one-based to zero based
|
61280 | */
|
61281 |
|
61282 |
|
61283 | function factory(type, config, load, typed) {
|
61284 | var apply = load(__webpack_require__(96)); // @see: comment of concat itself
|
61285 |
|
61286 | return typed('apply', {
|
61287 | '...any': function any(args) {
|
61288 | // change dim from one-based to zero-based
|
61289 | var dim = args[1];
|
61290 |
|
61291 | if (type.isNumber(dim)) {
|
61292 | args[1] = dim - 1;
|
61293 | } else if (type.isBigNumber(dim)) {
|
61294 | args[1] = dim.minus(1);
|
61295 | }
|
61296 |
|
61297 | try {
|
61298 | return apply.apply(null, args);
|
61299 | } catch (err) {
|
61300 | throw errorTransform(err);
|
61301 | }
|
61302 | }
|
61303 | });
|
61304 | }
|
61305 |
|
61306 | exports.name = 'apply';
|
61307 | exports.path = 'expression.transform';
|
61308 | exports.factory = factory;
|
61309 |
|
61310 | /***/ }),
|
61311 | /* 569 */
|
61312 | /***/ (function(module, exports, __webpack_require__) {
|
61313 |
|
61314 | "use strict";
|
61315 |
|
61316 |
|
61317 | var errorTransform = __webpack_require__(22).transform;
|
61318 | /**
|
61319 | * Attach a transform function to matrix.column
|
61320 | * Adds a property transform containing the transform function.
|
61321 | *
|
61322 | * This transform changed the last `index` parameter of function column
|
61323 | * from zero-based to one-based
|
61324 | */
|
61325 |
|
61326 |
|
61327 | function factory(type, config, load, typed) {
|
61328 | var column = load(__webpack_require__(143)); // @see: comment of column itself
|
61329 |
|
61330 | return typed('column', {
|
61331 | '...any': function any(args) {
|
61332 | // change last argument from zero-based to one-based
|
61333 | var lastIndex = args.length - 1;
|
61334 | var last = args[lastIndex];
|
61335 |
|
61336 | if (type.isNumber(last)) {
|
61337 | args[lastIndex] = last - 1;
|
61338 | }
|
61339 |
|
61340 | try {
|
61341 | return column.apply(null, args);
|
61342 | } catch (err) {
|
61343 | throw errorTransform(err);
|
61344 | }
|
61345 | }
|
61346 | });
|
61347 | }
|
61348 |
|
61349 | exports.name = 'column';
|
61350 | exports.path = 'expression.transform';
|
61351 | exports.factory = factory;
|
61352 |
|
61353 | /***/ }),
|
61354 | /* 570 */
|
61355 | /***/ (function(module, exports, __webpack_require__) {
|
61356 |
|
61357 | "use strict";
|
61358 |
|
61359 |
|
61360 | var errorTransform = __webpack_require__(22).transform;
|
61361 | /**
|
61362 | * Attach a transform function to math.range
|
61363 | * Adds a property transform containing the transform function.
|
61364 | *
|
61365 | * This transform changed the last `dim` parameter of function concat
|
61366 | * from one-based to zero based
|
61367 | */
|
61368 |
|
61369 |
|
61370 | function factory(type, config, load, typed) {
|
61371 | var concat = load(__webpack_require__(78)); // @see: comment of concat itself
|
61372 |
|
61373 | return typed('concat', {
|
61374 | '...any': function any(args) {
|
61375 | // change last argument from one-based to zero-based
|
61376 | var lastIndex = args.length - 1;
|
61377 | var last = args[lastIndex];
|
61378 |
|
61379 | if (type.isNumber(last)) {
|
61380 | args[lastIndex] = last - 1;
|
61381 | } else if (type.isBigNumber(last)) {
|
61382 | args[lastIndex] = last.minus(1);
|
61383 | }
|
61384 |
|
61385 | try {
|
61386 | return concat.apply(null, args);
|
61387 | } catch (err) {
|
61388 | throw errorTransform(err);
|
61389 | }
|
61390 | }
|
61391 | });
|
61392 | }
|
61393 |
|
61394 | exports.name = 'concat';
|
61395 | exports.path = 'expression.transform';
|
61396 | exports.factory = factory;
|
61397 |
|
61398 | /***/ }),
|
61399 | /* 571 */
|
61400 | /***/ (function(module, exports, __webpack_require__) {
|
61401 |
|
61402 | "use strict";
|
61403 |
|
61404 |
|
61405 | var filter = __webpack_require__(2).filter;
|
61406 |
|
61407 | var filterRegExp = __webpack_require__(2).filterRegExp;
|
61408 |
|
61409 | var maxArgumentCount = __webpack_require__(36).maxArgumentCount;
|
61410 | /**
|
61411 | * Attach a transform function to math.filter
|
61412 | * Adds a property transform containing the transform function.
|
61413 | *
|
61414 | * This transform adds support for equations as test function for math.filter,
|
61415 | * so you can do something like 'filter([3, -2, 5], x > 0)'.
|
61416 | */
|
61417 |
|
61418 |
|
61419 | function factory(type, config, load, typed) {
|
61420 | var compileInlineExpression = load(__webpack_require__(102));
|
61421 | var matrix = load(__webpack_require__(0));
|
61422 |
|
61423 | function filterTransform(args, math, scope) {
|
61424 | var x, callback;
|
61425 |
|
61426 | if (args[0]) {
|
61427 | x = args[0].compile().eval(scope);
|
61428 | }
|
61429 |
|
61430 | if (args[1]) {
|
61431 | if (type.isSymbolNode(args[1]) || type.isFunctionAssignmentNode(args[1])) {
|
61432 | // a function pointer, like filter([3, -2, 5], myTestFunction)
|
61433 | callback = args[1].compile().eval(scope);
|
61434 | } else {
|
61435 | // an expression like filter([3, -2, 5], x > 0)
|
61436 | callback = compileInlineExpression(args[1], math, scope);
|
61437 | }
|
61438 | }
|
61439 |
|
61440 | return filter(x, callback);
|
61441 | }
|
61442 |
|
61443 | filterTransform.rawArgs = true; // one based version of function filter
|
61444 |
|
61445 | var filter = typed('filter', {
|
61446 | 'Array, function': _filter,
|
61447 | 'Matrix, function': function MatrixFunction(x, test) {
|
61448 | return matrix(_filter(x.toArray(), test));
|
61449 | },
|
61450 | 'Array, RegExp': filterRegExp,
|
61451 | 'Matrix, RegExp': function MatrixRegExp(x, test) {
|
61452 | return matrix(filterRegExp(x.toArray(), test));
|
61453 | }
|
61454 | });
|
61455 | filter.toTex = undefined; // use default template
|
61456 |
|
61457 | return filterTransform;
|
61458 | }
|
61459 | /**
|
61460 | * Filter values in a callback given a callback function
|
61461 | *
|
61462 | * !!! Passes a one-based index !!!
|
61463 | *
|
61464 | * @param {Array} x
|
61465 | * @param {Function} callback
|
61466 | * @return {Array} Returns the filtered array
|
61467 | * @private
|
61468 | */
|
61469 |
|
61470 |
|
61471 | function _filter(x, callback) {
|
61472 | // figure out what number of arguments the callback function expects
|
61473 | var args = maxArgumentCount(callback);
|
61474 | return filter(x, function (value, index, array) {
|
61475 | // invoke the callback function with the right number of arguments
|
61476 | if (args === 1) {
|
61477 | return callback(value);
|
61478 | } else if (args === 2) {
|
61479 | return callback(value, [index + 1]);
|
61480 | } else {
|
61481 | // 3 or -1
|
61482 | return callback(value, [index + 1], array);
|
61483 | }
|
61484 | });
|
61485 | }
|
61486 |
|
61487 | exports.name = 'filter';
|
61488 | exports.path = 'expression.transform';
|
61489 | exports.factory = factory;
|
61490 |
|
61491 | /***/ }),
|
61492 | /* 572 */
|
61493 | /***/ (function(module, exports, __webpack_require__) {
|
61494 |
|
61495 | "use strict";
|
61496 |
|
61497 |
|
61498 | var maxArgumentCount = __webpack_require__(36).maxArgumentCount;
|
61499 |
|
61500 | var forEach = __webpack_require__(2).forEach;
|
61501 | /**
|
61502 | * Attach a transform function to math.forEach
|
61503 | * Adds a property transform containing the transform function.
|
61504 | *
|
61505 | * This transform creates a one-based index instead of a zero-based index
|
61506 | */
|
61507 |
|
61508 |
|
61509 | function factory(type, config, load, typed) {
|
61510 | var compileInlineExpression = load(__webpack_require__(102));
|
61511 |
|
61512 | function forEachTransform(args, math, scope) {
|
61513 | var x, callback;
|
61514 |
|
61515 | if (args[0]) {
|
61516 | x = args[0].compile().eval(scope);
|
61517 | }
|
61518 |
|
61519 | if (args[1]) {
|
61520 | if (type.isSymbolNode(args[1]) || type.isFunctionAssignmentNode(args[1])) {
|
61521 | // a function pointer, like forEach([3, -2, 5], myTestFunction)
|
61522 | callback = args[1].compile().eval(scope);
|
61523 | } else {
|
61524 | // an expression like forEach([3, -2, 5], x > 0 ? callback1(x) : callback2(x) )
|
61525 | callback = compileInlineExpression(args[1], math, scope);
|
61526 | }
|
61527 | }
|
61528 |
|
61529 | return _forEach(x, callback);
|
61530 | }
|
61531 |
|
61532 | forEachTransform.rawArgs = true; // one-based version of forEach
|
61533 |
|
61534 | var _forEach = typed('forEach', {
|
61535 | 'Array | Matrix, function': function ArrayMatrixFunction(array, callback) {
|
61536 | // figure out what number of arguments the callback function expects
|
61537 | var args = maxArgumentCount(callback);
|
61538 |
|
61539 | var recurse = function recurse(value, index) {
|
61540 | if (Array.isArray(value)) {
|
61541 | forEach(value, function (child, i) {
|
61542 | // we create a copy of the index array and append the new index value
|
61543 | recurse(child, index.concat(i + 1)); // one based index, hence i+1
|
61544 | });
|
61545 | } else {
|
61546 | // invoke the callback function with the right number of arguments
|
61547 | if (args === 1) {
|
61548 | callback(value);
|
61549 | } else if (args === 2) {
|
61550 | callback(value, index);
|
61551 | } else {
|
61552 | // 3 or -1
|
61553 | callback(value, index, array);
|
61554 | }
|
61555 | }
|
61556 | };
|
61557 |
|
61558 | recurse(array.valueOf(), []); // pass Array
|
61559 | }
|
61560 | });
|
61561 |
|
61562 | return forEachTransform;
|
61563 | }
|
61564 |
|
61565 | exports.name = 'forEach';
|
61566 | exports.path = 'expression.transform';
|
61567 | exports.factory = factory;
|
61568 |
|
61569 | /***/ }),
|
61570 | /* 573 */
|
61571 | /***/ (function(module, exports, __webpack_require__) {
|
61572 |
|
61573 | "use strict";
|
61574 |
|
61575 | /**
|
61576 | * Attach a transform function to math.index
|
61577 | * Adds a property transform containing the transform function.
|
61578 | *
|
61579 | * This transform creates a one-based index instead of a zero-based index
|
61580 | */
|
61581 |
|
61582 | function factory(type, config, load) {
|
61583 | return function indexTransform() {
|
61584 | var args = [];
|
61585 |
|
61586 | for (var i = 0, ii = arguments.length; i < ii; i++) {
|
61587 | var arg = arguments[i]; // change from one-based to zero based, and convert BigNumber to number
|
61588 |
|
61589 | if (type.isRange(arg)) {
|
61590 | arg.start--;
|
61591 | arg.end -= arg.step > 0 ? 0 : 2;
|
61592 | } else if (arg && arg.isSet === true) {
|
61593 | arg = arg.map(function (v) {
|
61594 | return v - 1;
|
61595 | });
|
61596 | } else if (type.isArray(arg) || type.isMatrix(arg)) {
|
61597 | arg = arg.map(function (v) {
|
61598 | return v - 1;
|
61599 | });
|
61600 | } else if (type.isNumber(arg)) {
|
61601 | arg--;
|
61602 | } else if (type.isBigNumber(arg)) {
|
61603 | arg = arg.toNumber() - 1;
|
61604 | } else if (typeof arg === 'string') {// leave as is
|
61605 | } else {
|
61606 | throw new TypeError('Dimension must be an Array, Matrix, number, string, or Range');
|
61607 | }
|
61608 |
|
61609 | args[i] = arg;
|
61610 | }
|
61611 |
|
61612 | var res = new type.Index();
|
61613 | type.Index.apply(res, args);
|
61614 | return res;
|
61615 | };
|
61616 | }
|
61617 |
|
61618 | exports.name = 'index';
|
61619 | exports.path = 'expression.transform';
|
61620 | exports.factory = factory;
|
61621 |
|
61622 | /***/ }),
|
61623 | /* 574 */
|
61624 | /***/ (function(module, exports, __webpack_require__) {
|
61625 |
|
61626 | "use strict";
|
61627 |
|
61628 |
|
61629 | var maxArgumentCount = __webpack_require__(36).maxArgumentCount;
|
61630 |
|
61631 | var map = __webpack_require__(2).map;
|
61632 | /**
|
61633 | * Attach a transform function to math.map
|
61634 | * Adds a property transform containing the transform function.
|
61635 | *
|
61636 | * This transform creates a one-based index instead of a zero-based index
|
61637 | */
|
61638 |
|
61639 |
|
61640 | function factory(type, config, load, typed) {
|
61641 | var compileInlineExpression = load(__webpack_require__(102));
|
61642 | var matrix = load(__webpack_require__(0));
|
61643 |
|
61644 | function mapTransform(args, math, scope) {
|
61645 | var x, callback;
|
61646 |
|
61647 | if (args[0]) {
|
61648 | x = args[0].compile().eval(scope);
|
61649 | }
|
61650 |
|
61651 | if (args[1]) {
|
61652 | if (type.isSymbolNode(args[1]) || type.isFunctionAssignmentNode(args[1])) {
|
61653 | // a function pointer, like filter([3, -2, 5], myTestFunction)
|
61654 | callback = args[1].compile().eval(scope);
|
61655 | } else {
|
61656 | // an expression like filter([3, -2, 5], x > 0)
|
61657 | callback = compileInlineExpression(args[1], math, scope);
|
61658 | }
|
61659 | }
|
61660 |
|
61661 | return map(x, callback);
|
61662 | }
|
61663 |
|
61664 | mapTransform.rawArgs = true; // one-based version of map function
|
61665 |
|
61666 | var map = typed('map', {
|
61667 | 'Array, function': function ArrayFunction(x, callback) {
|
61668 | return _map(x, callback, x);
|
61669 | },
|
61670 | 'Matrix, function': function MatrixFunction(x, callback) {
|
61671 | return matrix(_map(x.valueOf(), callback, x));
|
61672 | }
|
61673 | });
|
61674 | return mapTransform;
|
61675 | }
|
61676 | /**
|
61677 | * Map for a multi dimensional array. One-based indexes
|
61678 | * @param {Array} array
|
61679 | * @param {function} callback
|
61680 | * @param {Array} orig
|
61681 | * @return {Array}
|
61682 | * @private
|
61683 | */
|
61684 |
|
61685 |
|
61686 | function _map(array, callback, orig) {
|
61687 | // figure out what number of arguments the callback function expects
|
61688 | var argsCount = maxArgumentCount(callback);
|
61689 |
|
61690 | function recurse(value, index) {
|
61691 | if (Array.isArray(value)) {
|
61692 | return map(value, function (child, i) {
|
61693 | // we create a copy of the index array and append the new index value
|
61694 | return recurse(child, index.concat(i + 1)); // one based index, hence i + 1
|
61695 | });
|
61696 | } else {
|
61697 | // invoke the (typed) callback function with the right number of arguments
|
61698 | if (argsCount === 1) {
|
61699 | return callback(value);
|
61700 | } else if (argsCount === 2) {
|
61701 | return callback(value, index);
|
61702 | } else {
|
61703 | // 3 or -1
|
61704 | return callback(value, index, orig);
|
61705 | }
|
61706 | }
|
61707 | }
|
61708 |
|
61709 | return recurse(array, []);
|
61710 | }
|
61711 |
|
61712 | exports.name = 'map';
|
61713 | exports.path = 'expression.transform';
|
61714 | exports.factory = factory;
|
61715 |
|
61716 | /***/ }),
|
61717 | /* 575 */
|
61718 | /***/ (function(module, exports, __webpack_require__) {
|
61719 |
|
61720 | "use strict";
|
61721 |
|
61722 |
|
61723 | var errorTransform = __webpack_require__(22).transform;
|
61724 |
|
61725 | var isCollection = __webpack_require__(35);
|
61726 | /**
|
61727 | * Attach a transform function to math.max
|
61728 | * Adds a property transform containing the transform function.
|
61729 | *
|
61730 | * This transform changed the last `dim` parameter of function max
|
61731 | * from one-based to zero based
|
61732 | */
|
61733 |
|
61734 |
|
61735 | function factory(type, config, load, typed) {
|
61736 | var max = load(__webpack_require__(98));
|
61737 | return typed('max', {
|
61738 | '...any': function any(args) {
|
61739 | // change last argument dim from one-based to zero-based
|
61740 | if (args.length === 2 && isCollection(args[0])) {
|
61741 | var dim = args[1];
|
61742 |
|
61743 | if (type.isNumber(dim)) {
|
61744 | args[1] = dim - 1;
|
61745 | } else if (type.isBigNumber(dim)) {
|
61746 | args[1] = dim.minus(1);
|
61747 | }
|
61748 | }
|
61749 |
|
61750 | try {
|
61751 | return max.apply(null, args);
|
61752 | } catch (err) {
|
61753 | throw errorTransform(err);
|
61754 | }
|
61755 | }
|
61756 | });
|
61757 | }
|
61758 |
|
61759 | exports.name = 'max';
|
61760 | exports.path = 'expression.transform';
|
61761 | exports.factory = factory;
|
61762 |
|
61763 | /***/ }),
|
61764 | /* 576 */
|
61765 | /***/ (function(module, exports, __webpack_require__) {
|
61766 |
|
61767 | "use strict";
|
61768 |
|
61769 |
|
61770 | var errorTransform = __webpack_require__(22).transform;
|
61771 |
|
61772 | var isCollection = __webpack_require__(35);
|
61773 | /**
|
61774 | * Attach a transform function to math.mean
|
61775 | * Adds a property transform containing the transform function.
|
61776 | *
|
61777 | * This transform changed the last `dim` parameter of function mean
|
61778 | * from one-based to zero based
|
61779 | */
|
61780 |
|
61781 |
|
61782 | function factory(type, config, load, typed) {
|
61783 | var mean = load(__webpack_require__(152));
|
61784 | return typed('mean', {
|
61785 | '...any': function any(args) {
|
61786 | // change last argument dim from one-based to zero-based
|
61787 | if (args.length === 2 && isCollection(args[0])) {
|
61788 | var dim = args[1];
|
61789 |
|
61790 | if (type.isNumber(dim)) {
|
61791 | args[1] = dim - 1;
|
61792 | } else if (type.isBigNumber(dim)) {
|
61793 | args[1] = dim.minus(1);
|
61794 | }
|
61795 | }
|
61796 |
|
61797 | try {
|
61798 | return mean.apply(null, args);
|
61799 | } catch (err) {
|
61800 | throw errorTransform(err);
|
61801 | }
|
61802 | }
|
61803 | });
|
61804 | }
|
61805 |
|
61806 | exports.name = 'mean';
|
61807 | exports.path = 'expression.transform';
|
61808 | exports.factory = factory;
|
61809 |
|
61810 | /***/ }),
|
61811 | /* 577 */
|
61812 | /***/ (function(module, exports, __webpack_require__) {
|
61813 |
|
61814 | "use strict";
|
61815 |
|
61816 |
|
61817 | var errorTransform = __webpack_require__(22).transform;
|
61818 |
|
61819 | var isCollection = __webpack_require__(35);
|
61820 | /**
|
61821 | * Attach a transform function to math.min
|
61822 | * Adds a property transform containing the transform function.
|
61823 | *
|
61824 | * This transform changed the last `dim` parameter of function min
|
61825 | * from one-based to zero based
|
61826 | */
|
61827 |
|
61828 |
|
61829 | function factory(type, config, load, typed) {
|
61830 | var min = load(__webpack_require__(153));
|
61831 | return typed('min', {
|
61832 | '...any': function any(args) {
|
61833 | // change last argument dim from one-based to zero-based
|
61834 | if (args.length === 2 && isCollection(args[0])) {
|
61835 | var dim = args[1];
|
61836 |
|
61837 | if (type.isNumber(dim)) {
|
61838 | args[1] = dim - 1;
|
61839 | } else if (type.isBigNumber(dim)) {
|
61840 | args[1] = dim.minus(1);
|
61841 | }
|
61842 | }
|
61843 |
|
61844 | try {
|
61845 | return min.apply(null, args);
|
61846 | } catch (err) {
|
61847 | throw errorTransform(err);
|
61848 | }
|
61849 | }
|
61850 | });
|
61851 | }
|
61852 |
|
61853 | exports.name = 'min';
|
61854 | exports.path = 'expression.transform';
|
61855 | exports.factory = factory;
|
61856 |
|
61857 | /***/ }),
|
61858 | /* 578 */
|
61859 | /***/ (function(module, exports, __webpack_require__) {
|
61860 |
|
61861 | "use strict";
|
61862 |
|
61863 | /**
|
61864 | * Attach a transform function to math.range
|
61865 | * Adds a property transform containing the transform function.
|
61866 | *
|
61867 | * This transform creates a range which includes the end value
|
61868 | */
|
61869 |
|
61870 | function factory(type, config, load, typed) {
|
61871 | var range = load(__webpack_require__(77));
|
61872 | return typed('range', {
|
61873 | '...any': function any(args) {
|
61874 | var lastIndex = args.length - 1;
|
61875 | var last = args[lastIndex];
|
61876 |
|
61877 | if (typeof last !== 'boolean') {
|
61878 | // append a parameter includeEnd=true
|
61879 | args.push(true);
|
61880 | }
|
61881 |
|
61882 | return range.apply(null, args);
|
61883 | }
|
61884 | });
|
61885 | }
|
61886 |
|
61887 | exports.name = 'range';
|
61888 | exports.path = 'expression.transform';
|
61889 | exports.factory = factory;
|
61890 |
|
61891 | /***/ }),
|
61892 | /* 579 */
|
61893 | /***/ (function(module, exports, __webpack_require__) {
|
61894 |
|
61895 | "use strict";
|
61896 |
|
61897 |
|
61898 | var errorTransform = __webpack_require__(22).transform;
|
61899 |
|
61900 | var isCollection = __webpack_require__(35);
|
61901 | /**
|
61902 | * Attach a transform function to math.std
|
61903 | * Adds a property transform containing the transform function.
|
61904 | *
|
61905 | * This transform changed the `dim` parameter of function std
|
61906 | * from one-based to zero based
|
61907 | */
|
61908 |
|
61909 |
|
61910 | function factory(type, config, load, typed) {
|
61911 | var std = load(__webpack_require__(154));
|
61912 | return typed('std', {
|
61913 | '...any': function any(args) {
|
61914 | // change last argument dim from one-based to zero-based
|
61915 | if (args.length >= 2 && isCollection(args[0])) {
|
61916 | var dim = args[1];
|
61917 |
|
61918 | if (type.isNumber(dim)) {
|
61919 | args[1] = dim - 1;
|
61920 | } else if (type.isBigNumber(dim)) {
|
61921 | args[1] = dim.minus(1);
|
61922 | }
|
61923 | }
|
61924 |
|
61925 | try {
|
61926 | return std.apply(null, args);
|
61927 | } catch (err) {
|
61928 | throw errorTransform(err);
|
61929 | }
|
61930 | }
|
61931 | });
|
61932 | }
|
61933 |
|
61934 | exports.name = 'std';
|
61935 | exports.path = 'expression.transform';
|
61936 | exports.factory = factory;
|
61937 |
|
61938 | /***/ }),
|
61939 | /* 580 */
|
61940 | /***/ (function(module, exports, __webpack_require__) {
|
61941 |
|
61942 | "use strict";
|
61943 |
|
61944 |
|
61945 | var errorTransform = __webpack_require__(22).transform;
|
61946 | /**
|
61947 | * Attach a transform function to matrix.row
|
61948 | * Adds a property transform containing the transform function.
|
61949 | *
|
61950 | * This transform changed the last `index` parameter of function row
|
61951 | * from zero-based to one-based
|
61952 | */
|
61953 |
|
61954 |
|
61955 | function factory(type, config, load, typed) {
|
61956 | var row = load(__webpack_require__(146)); // @see: comment of row itself
|
61957 |
|
61958 | return typed('row', {
|
61959 | '...any': function any(args) {
|
61960 | // change last argument from zero-based to one-based
|
61961 | var lastIndex = args.length - 1;
|
61962 | var last = args[lastIndex];
|
61963 |
|
61964 | if (type.isNumber(last)) {
|
61965 | args[lastIndex] = last - 1;
|
61966 | }
|
61967 |
|
61968 | try {
|
61969 | return row.apply(null, args);
|
61970 | } catch (err) {
|
61971 | throw errorTransform(err);
|
61972 | }
|
61973 | }
|
61974 | });
|
61975 | }
|
61976 |
|
61977 | exports.name = 'row';
|
61978 | exports.path = 'expression.transform';
|
61979 | exports.factory = factory;
|
61980 |
|
61981 | /***/ }),
|
61982 | /* 581 */
|
61983 | /***/ (function(module, exports, __webpack_require__) {
|
61984 |
|
61985 | "use strict";
|
61986 |
|
61987 |
|
61988 | var errorTransform = __webpack_require__(22).transform;
|
61989 | /**
|
61990 | * Attach a transform function to math.subset
|
61991 | * Adds a property transform containing the transform function.
|
61992 | *
|
61993 | * This transform creates a range which includes the end value
|
61994 | */
|
61995 |
|
61996 |
|
61997 | function factory(type, config, load, typed) {
|
61998 | var subset = load(__webpack_require__(23));
|
61999 | return typed('subset', {
|
62000 | '...any': function any(args) {
|
62001 | try {
|
62002 | return subset.apply(null, args);
|
62003 | } catch (err) {
|
62004 | throw errorTransform(err);
|
62005 | }
|
62006 | }
|
62007 | });
|
62008 | }
|
62009 |
|
62010 | exports.name = 'subset';
|
62011 | exports.path = 'expression.transform';
|
62012 | exports.factory = factory;
|
62013 |
|
62014 | /***/ }),
|
62015 | /* 582 */
|
62016 | /***/ (function(module, exports, __webpack_require__) {
|
62017 |
|
62018 | "use strict";
|
62019 |
|
62020 |
|
62021 | var errorTransform = __webpack_require__(22).transform;
|
62022 |
|
62023 | var isCollection = __webpack_require__(35);
|
62024 | /**
|
62025 | * Attach a transform function to math.sum
|
62026 | * Adds a property transform containing the transform function.
|
62027 | *
|
62028 | * This transform changed the last `dim` parameter of function mean
|
62029 | * from one-based to zero based
|
62030 | */
|
62031 |
|
62032 |
|
62033 | function factory(type, config, load, typed) {
|
62034 | var sum = load(__webpack_require__(99));
|
62035 | return typed('sum', {
|
62036 | '...any': function any(args) {
|
62037 | // change last argument dim from one-based to zero-based
|
62038 | if (args.length === 2 && isCollection(args[0])) {
|
62039 | var dim = args[1];
|
62040 |
|
62041 | if (type.isNumber(dim)) {
|
62042 | args[1] = dim - 1;
|
62043 | } else if (type.isBigNumber(dim)) {
|
62044 | args[1] = dim.minus(1);
|
62045 | }
|
62046 | }
|
62047 |
|
62048 | try {
|
62049 | return sum.apply(null, args);
|
62050 | } catch (err) {
|
62051 | throw errorTransform(err);
|
62052 | }
|
62053 | }
|
62054 | });
|
62055 | }
|
62056 |
|
62057 | exports.name = 'sum';
|
62058 | exports.path = 'expression.transform';
|
62059 | exports.factory = factory;
|
62060 |
|
62061 | /***/ }),
|
62062 | /* 583 */
|
62063 | /***/ (function(module, exports, __webpack_require__) {
|
62064 |
|
62065 | "use strict";
|
62066 |
|
62067 |
|
62068 | var errorTransform = __webpack_require__(22).transform;
|
62069 |
|
62070 | var isCollection = __webpack_require__(35);
|
62071 | /**
|
62072 | * Attach a transform function to math.var
|
62073 | * Adds a property transform containing the transform function.
|
62074 | *
|
62075 | * This transform changed the `dim` parameter of function var
|
62076 | * from one-based to zero based
|
62077 | */
|
62078 |
|
62079 |
|
62080 | function factory(type, config, load, typed) {
|
62081 | var variance = load(__webpack_require__(101));
|
62082 | return typed('var', {
|
62083 | '...any': function any(args) {
|
62084 | // change last argument dim from one-based to zero-based
|
62085 | if (args.length >= 2 && isCollection(args[0])) {
|
62086 | var dim = args[1];
|
62087 |
|
62088 | if (type.isNumber(dim)) {
|
62089 | args[1] = dim - 1;
|
62090 | } else if (type.isBigNumber(dim)) {
|
62091 | args[1] = dim.minus(1);
|
62092 | }
|
62093 | }
|
62094 |
|
62095 | try {
|
62096 | return variance.apply(null, args);
|
62097 | } catch (err) {
|
62098 | throw errorTransform(err);
|
62099 | }
|
62100 | }
|
62101 | });
|
62102 | }
|
62103 |
|
62104 | exports.name = 'var';
|
62105 | exports.path = 'expression.transform';
|
62106 | exports.factory = factory;
|
62107 |
|
62108 | /***/ }),
|
62109 | /* 584 */
|
62110 | /***/ (function(module, exports, __webpack_require__) {
|
62111 |
|
62112 | "use strict";
|
62113 |
|
62114 |
|
62115 | var object = __webpack_require__(5);
|
62116 |
|
62117 | var string = __webpack_require__(9);
|
62118 |
|
62119 | function factory(type, config, load, typed) {
|
62120 | var parser = load(__webpack_require__(158))();
|
62121 | /**
|
62122 | * Documentation object
|
62123 | * @param {Object} doc Object containing properties:
|
62124 | * {string} name
|
62125 | * {string} category
|
62126 | * {string} description
|
62127 | * {string[]} syntax
|
62128 | * {string[]} examples
|
62129 | * {string[]} seealso
|
62130 | * @constructor
|
62131 | */
|
62132 |
|
62133 | function Help(doc) {
|
62134 | if (!(this instanceof Help)) {
|
62135 | throw new SyntaxError('Constructor must be called with the new operator');
|
62136 | }
|
62137 |
|
62138 | if (!doc) throw new Error('Argument "doc" missing');
|
62139 | this.doc = doc;
|
62140 | }
|
62141 | /**
|
62142 | * Attach type information
|
62143 | */
|
62144 |
|
62145 |
|
62146 | Help.prototype.type = 'Help';
|
62147 | Help.prototype.isHelp = true;
|
62148 | /**
|
62149 | * Generate a string representation of the Help object
|
62150 | * @return {string} Returns a string
|
62151 | * @private
|
62152 | */
|
62153 |
|
62154 | Help.prototype.toString = function () {
|
62155 | var doc = this.doc || {};
|
62156 | var desc = '\n';
|
62157 |
|
62158 | if (doc.name) {
|
62159 | desc += 'Name: ' + doc.name + '\n\n';
|
62160 | }
|
62161 |
|
62162 | if (doc.category) {
|
62163 | desc += 'Category: ' + doc.category + '\n\n';
|
62164 | }
|
62165 |
|
62166 | if (doc.description) {
|
62167 | desc += 'Description:\n ' + doc.description + '\n\n';
|
62168 | }
|
62169 |
|
62170 | if (doc.syntax) {
|
62171 | desc += 'Syntax:\n ' + doc.syntax.join('\n ') + '\n\n';
|
62172 | }
|
62173 |
|
62174 | if (doc.examples) {
|
62175 | desc += 'Examples:\n';
|
62176 |
|
62177 | for (var i = 0; i < doc.examples.length; i++) {
|
62178 | var expr = doc.examples[i];
|
62179 | desc += ' ' + expr + '\n';
|
62180 | var res = void 0;
|
62181 |
|
62182 | try {
|
62183 | // note: res can be undefined when `expr` is an empty string
|
62184 | res = parser.eval(expr);
|
62185 | } catch (e) {
|
62186 | res = e;
|
62187 | }
|
62188 |
|
62189 | if (res !== undefined && !type.isHelp(res)) {
|
62190 | desc += ' ' + string.format(res, {
|
62191 | precision: 14
|
62192 | }) + '\n';
|
62193 | }
|
62194 | }
|
62195 |
|
62196 | desc += '\n';
|
62197 | }
|
62198 |
|
62199 | if (doc.seealso && doc.seealso.length) {
|
62200 | desc += 'See also: ' + doc.seealso.join(', ') + '\n';
|
62201 | }
|
62202 |
|
62203 | return desc;
|
62204 | };
|
62205 | /**
|
62206 | * Export the help object to JSON
|
62207 | */
|
62208 |
|
62209 |
|
62210 | Help.prototype.toJSON = function () {
|
62211 | var obj = object.clone(this.doc);
|
62212 | obj.mathjs = 'Help';
|
62213 | return obj;
|
62214 | };
|
62215 | /**
|
62216 | * Instantiate a Help object from a JSON object
|
62217 | * @param {Object} json
|
62218 | * @returns {Help} Returns a new Help object
|
62219 | */
|
62220 |
|
62221 |
|
62222 | Help.fromJSON = function (json) {
|
62223 | var doc = {};
|
62224 |
|
62225 | for (var prop in json) {
|
62226 | if (prop !== 'mathjs') {
|
62227 | // ignore mathjs field
|
62228 | doc[prop] = json[prop];
|
62229 | }
|
62230 | }
|
62231 |
|
62232 | return new Help(doc);
|
62233 | };
|
62234 | /**
|
62235 | * Returns a string representation of the Help object
|
62236 | */
|
62237 |
|
62238 |
|
62239 | Help.prototype.valueOf = Help.prototype.toString;
|
62240 | return Help;
|
62241 | }
|
62242 |
|
62243 | exports.name = 'Help';
|
62244 | exports.path = 'type';
|
62245 | exports.factory = factory;
|
62246 |
|
62247 | /***/ }),
|
62248 | /* 585 */
|
62249 | /***/ (function(module, exports, __webpack_require__) {
|
62250 |
|
62251 | "use strict";
|
62252 |
|
62253 |
|
62254 | module.exports = [__webpack_require__(586)];
|
62255 |
|
62256 | /***/ }),
|
62257 | /* 586 */
|
62258 | /***/ (function(module, exports, __webpack_require__) {
|
62259 |
|
62260 | "use strict";
|
62261 |
|
62262 |
|
62263 | function factory(type, config, load, typed, math) {
|
62264 | /**
|
62265 | * Instantiate mathjs data types from their JSON representation
|
62266 | * @param {string} key
|
62267 | * @param {*} value
|
62268 | * @returns {*} Returns the revived object
|
62269 | */
|
62270 | return function reviver(key, value) {
|
62271 | var constructor = type[value && value.mathjs] || math.expression && math.expression.node[value && value.mathjs]; // TODO: instead of checking math.expression.node, expose all Node classes on math.type too
|
62272 |
|
62273 | if (constructor && typeof constructor.fromJSON === 'function') {
|
62274 | return constructor.fromJSON(value);
|
62275 | }
|
62276 |
|
62277 | return value;
|
62278 | };
|
62279 | }
|
62280 |
|
62281 | exports.name = 'reviver';
|
62282 | exports.path = 'json';
|
62283 | exports.factory = factory;
|
62284 | exports.math = true; // request the math namespace as fifth argument
|
62285 |
|
62286 | /***/ }),
|
62287 | /* 587 */
|
62288 | /***/ (function(module, exports, __webpack_require__) {
|
62289 |
|
62290 | "use strict";
|
62291 |
|
62292 |
|
62293 | var ArgumentsError = __webpack_require__(57);
|
62294 |
|
62295 | var DimensionError = __webpack_require__(8);
|
62296 |
|
62297 | var IndexError = __webpack_require__(48);
|
62298 |
|
62299 | module.exports = [{
|
62300 | name: 'ArgumentsError',
|
62301 | path: 'error',
|
62302 | factory: function factory() {
|
62303 | return ArgumentsError;
|
62304 | }
|
62305 | }, {
|
62306 | name: 'DimensionError',
|
62307 | path: 'error',
|
62308 | factory: function factory() {
|
62309 | return DimensionError;
|
62310 | }
|
62311 | }, {
|
62312 | name: 'IndexError',
|
62313 | path: 'error',
|
62314 | factory: function factory() {
|
62315 | return IndexError;
|
62316 | }
|
62317 | }]; // TODO: implement an InvalidValueError?
|
62318 |
|
62319 | /***/ })
|
62320 | /******/ ]);
|
62321 | }); |
\ | No newline at end of file |