mathjs 10.5.3 → 10.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. package/HISTORY.md +14 -0
  2. package/lib/browser/math.js +5 -5
  3. package/lib/browser/math.js.map +1 -1
  4. package/lib/cjs/entry/dependenciesAny/dependenciesFft.generated.js +41 -0
  5. package/lib/cjs/entry/dependenciesAny/dependenciesIfft.generated.js +29 -0
  6. package/lib/cjs/entry/dependenciesAny.generated.js +16 -0
  7. package/lib/cjs/entry/impureFunctionsAny.generated.js +66 -64
  8. package/lib/cjs/entry/pureFunctionsAny.generated.js +189 -171
  9. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +6 -0
  10. package/lib/cjs/expression/embeddedDocs/function/matrix/fft.js +15 -0
  11. package/lib/cjs/expression/embeddedDocs/function/matrix/ifft.js +15 -0
  12. package/lib/cjs/factoriesAny.js +16 -0
  13. package/lib/cjs/function/algebra/derivative.js +1 -1
  14. package/lib/cjs/function/matrix/fft.js +128 -0
  15. package/lib/cjs/function/matrix/ifft.js +49 -0
  16. package/lib/cjs/header.js +2 -2
  17. package/lib/cjs/version.js +1 -1
  18. package/lib/esm/entry/dependenciesAny/dependenciesFft.generated.js +24 -0
  19. package/lib/esm/entry/dependenciesAny/dependenciesIfft.generated.js +16 -0
  20. package/lib/esm/entry/dependenciesAny.generated.js +2 -0
  21. package/lib/esm/entry/impureFunctionsAny.generated.js +63 -61
  22. package/lib/esm/entry/pureFunctionsAny.generated.js +161 -145
  23. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +4 -0
  24. package/lib/esm/expression/embeddedDocs/function/matrix/fft.js +8 -0
  25. package/lib/esm/expression/embeddedDocs/function/matrix/ifft.js +8 -0
  26. package/lib/esm/factoriesAny.js +2 -0
  27. package/lib/esm/function/algebra/derivative.js +1 -1
  28. package/lib/esm/function/matrix/fft.js +104 -0
  29. package/lib/esm/function/matrix/ifft.js +38 -0
  30. package/lib/esm/version.js +1 -1
  31. package/package.json +4 -1
  32. package/types/index.d.ts +995 -270
  33. package/types/index.ts +694 -6
package/types/index.ts CHANGED
@@ -8,6 +8,23 @@ import {
8
8
  divideDependencies,
9
9
  formatDependencies,
10
10
  MathNode,
11
+ MathJsChain,
12
+ BigNumber,
13
+ MathCollection,
14
+ Complex,
15
+ Unit,
16
+ Fraction,
17
+ MathArray,
18
+ Index,
19
+ Matrix,
20
+ EvalFunction,
21
+ LUDecomposition,
22
+ QRDecomposition,
23
+ SLUDecomposition,
24
+ MathType,
25
+ MathNumericType,
26
+ ConstantNode,
27
+ OperatorNode,
11
28
  } from 'mathjs'
12
29
  import * as assert from 'assert'
13
30
  import { expectTypeOf } from 'expect-type'
@@ -65,6 +82,8 @@ Basic usage examples
65
82
  math.chain(m2by3).variance(0, 'biased')
66
83
  math.chain(m2by3).variance(1, 'uncorrected').variance('unbiased')
67
84
 
85
+ math.variance(math.variance(m2by3, 'uncorrected'))
86
+
68
87
  // expressions
69
88
  math.evaluate('1.2 * (2 + 4.5)')
70
89
 
@@ -151,14 +170,598 @@ Chaining examples
151
170
  )
152
171
 
153
172
  const r = math.chain(-0.483).round([0, 1, 2]).floor().add(0.52).fix(1).done()
173
+
154
174
  assert.deepStrictEqual(r, [0.5, -0.4, -0.4])
155
175
 
156
- expectTypeOf(math.chain('x + y').parse().resolve({ x: 1 }).done())
157
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
158
- .toMatchTypeOf<any>()
159
- expectTypeOf(math.chain('x + y').parse().resolve().done())
176
+ expectTypeOf(
177
+ math.chain('x + y').parse().resolve({ x: 1 }).done()
178
+ ).toMatchTypeOf<MathNode>()
179
+ expectTypeOf(
180
+ math.chain('x + y').parse().resolve().done()
181
+ ).toMatchTypeOf<MathNode>()
182
+
183
+ // bignum
184
+ expectTypeOf(math.chain(math.bignumber(12))).toMatchTypeOf<
185
+ MathJsChain<BigNumber>
186
+ >()
187
+ expectTypeOf(math.chain(12).bignumber()).toMatchTypeOf<
188
+ MathJsChain<BigNumber>
189
+ >()
190
+ expectTypeOf(math.chain([12, 13, 14]).bignumber()).toMatchTypeOf<
191
+ MathJsChain<MathCollection>
192
+ >()
193
+
194
+ // chain
195
+ expectTypeOf(math.chain(12).bignumber().clone()).toMatchTypeOf<
196
+ MathJsChain<BigNumber>
197
+ >()
198
+
199
+ // boolean
200
+ expectTypeOf(math.chain(math.boolean(true))).toMatchTypeOf<
201
+ MathJsChain<boolean>
202
+ >()
203
+ expectTypeOf(math.chain(true).boolean()).toMatchTypeOf<MathJsChain<boolean>>()
204
+ expectTypeOf(math.chain([12, 13, 14]).boolean()).toMatchTypeOf<
205
+ MathJsChain<MathCollection>
206
+ >()
207
+
208
+ // complex
209
+ expectTypeOf(math.chain(math.complex('123'))).toMatchTypeOf<
210
+ MathJsChain<Complex>
211
+ >()
212
+ expectTypeOf(math.chain('123').complex()).toMatchTypeOf<
213
+ MathJsChain<Complex>
214
+ >()
215
+ expectTypeOf(math.chain('123').complex(1)).toMatchTypeOf<
216
+ MathJsChain<Complex>
217
+ >()
218
+ expectTypeOf(math.chain([12, 13, 14]).complex()).toMatchTypeOf<
219
+ MathJsChain<MathCollection>
220
+ >()
221
+
222
+ // createUnit
223
+ expectTypeOf(math.chain(math.createUnit('furlong'))).toMatchTypeOf<
224
+ MathJsChain<Unit>
225
+ >()
226
+ expectTypeOf(
227
+ math.chain(
228
+ math.createUnit({
229
+ fresnel: '1234',
230
+ })
231
+ )
232
+ ).toMatchTypeOf<MathJsChain<Unit>>()
233
+
234
+ // fraction
235
+ expectTypeOf(math.chain(math.fraction('123'))).toMatchTypeOf<
236
+ MathJsChain<Fraction>
237
+ >()
238
+ expectTypeOf(math.chain('123').fraction()).toMatchTypeOf<
239
+ MathJsChain<Fraction>
240
+ >()
241
+ expectTypeOf(math.chain('123').fraction(2)).toMatchTypeOf<
242
+ MathJsChain<Fraction>
243
+ >()
244
+ expectTypeOf(math.chain([12, 13, 14]).fraction()).toMatchTypeOf<
245
+ MathJsChain<MathCollection>
246
+ >()
247
+ expectTypeOf(math.chain([12, 13, 14]).fraction()).toMatchTypeOf<
248
+ MathJsChain<MathCollection>
249
+ >()
250
+
251
+ // index
252
+ expectTypeOf(math.chain([12, 13, 14]).index()).toMatchTypeOf<
253
+ MathJsChain<Index>
254
+ >()
255
+
256
+ // matrix
257
+ expectTypeOf(math.chain([12, 13, 14, 15]).matrix()).toMatchTypeOf<
258
+ MathJsChain<Matrix>
259
+ >()
260
+
261
+ // number
262
+ expectTypeOf(math.chain('12').number()).toMatchTypeOf<MathJsChain<number>>()
263
+ expectTypeOf(math.chain([12, 13, 14]).number()).toMatchTypeOf<
264
+ MathJsChain<MathCollection>
265
+ >()
266
+
267
+ // sparse
268
+ expectTypeOf(math.chain([12, 13, 14, 15]).sparse()).toMatchTypeOf<
269
+ MathJsChain<Matrix>
270
+ >()
271
+
272
+ // split unit
273
+ expectTypeOf(math.chain(math.unit('furlong')).splitUnit([])).toMatchTypeOf<
274
+ MathJsChain<Unit[]>
275
+ >()
276
+
277
+ // string
278
+ expectTypeOf(math.chain('test').string()).toMatchTypeOf<MathJsChain<string>>()
279
+ expectTypeOf(math.chain([1, 2, 3]).string()).toMatchTypeOf<
280
+ MathJsChain<MathCollection>
281
+ >()
282
+
283
+ // unit
284
+ expectTypeOf(math.chain(12).unit()).toMatchTypeOf<MathJsChain<Unit>>()
285
+ expectTypeOf(math.chain([1, 2, 3]).unit()).toMatchTypeOf<
286
+ MathJsChain<Unit[]>
287
+ >()
288
+
289
+ // compile
290
+ expectTypeOf(math.chain('a + b').compile()).toMatchTypeOf<
291
+ MathJsChain<EvalFunction>
292
+ >()
293
+
294
+ // evaluate
295
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
296
+ expectTypeOf(math.chain('1 + 1').evaluate()).toMatchTypeOf<MathJsChain<any>>()
297
+ expectTypeOf(math.chain(['1 + 1', '2 + 2']).evaluate()).toMatchTypeOf<
160
298
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
161
- .toMatchTypeOf<any>()
299
+ MathJsChain<any[]>
300
+ >()
301
+
302
+ // parse
303
+ expectTypeOf(math.chain('1 + 1').parse()).toMatchTypeOf<
304
+ MathJsChain<MathNode>
305
+ >()
306
+ expectTypeOf(math.chain(['1 + 1', '2 + 2']).parse()).toMatchTypeOf<
307
+ MathJsChain<MathNode[]>
308
+ >()
309
+
310
+ // resolve
311
+ expectTypeOf(math.chain(math.parse('1 + 1')).resolve({})).toMatchTypeOf<
312
+ MathJsChain<MathNode>
313
+ >()
314
+ expectTypeOf(
315
+ math.chain([math.parse('1 + 1'), math.parse('1 + 1')]).resolve({})
316
+ ).toMatchTypeOf<MathJsChain<MathNode[]>>()
317
+
318
+ // derivative
319
+ expectTypeOf(math.chain(math.parse('x^2')).derivative('x')).toMatchTypeOf<
320
+ MathJsChain<MathNode>
321
+ >()
322
+
323
+ // lsolve
324
+ expectTypeOf(
325
+ math
326
+ .chain([
327
+ [1, 2],
328
+ [3, 4],
329
+ ])
330
+ .lsolve([1, 2])
331
+ ).toMatchTypeOf<MathJsChain<MathArray>>()
332
+ expectTypeOf(
333
+ math
334
+ .chain(
335
+ math.matrix([
336
+ [1, 2],
337
+ [3, 4],
338
+ ])
339
+ )
340
+ .lsolve([1, 2])
341
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
342
+
343
+ // lup
344
+ expectTypeOf(
345
+ math
346
+ .chain([
347
+ [1, 2],
348
+ [3, 4],
349
+ ])
350
+ .lup()
351
+ ).toMatchTypeOf<MathJsChain<LUDecomposition>>()
352
+ expectTypeOf(
353
+ math
354
+ .chain(
355
+ math.matrix([
356
+ [1, 2],
357
+ [3, 4],
358
+ ])
359
+ )
360
+ .lup()
361
+ ).toMatchTypeOf<MathJsChain<LUDecomposition>>()
362
+
363
+ // lusolve
364
+ expectTypeOf(
365
+ math
366
+ .chain(
367
+ math.matrix([
368
+ [1, 2],
369
+ [3, 4],
370
+ ])
371
+ )
372
+ .lusolve(math.matrix([1, 2]))
373
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
374
+
375
+ expectTypeOf(
376
+ math
377
+ .chain(
378
+ math.matrix([
379
+ [1, 2],
380
+ [3, 4],
381
+ ])
382
+ )
383
+ .lusolve([1, 2])
384
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
385
+
386
+ expectTypeOf(
387
+ math
388
+ .chain([
389
+ [1, 2],
390
+ [3, 4],
391
+ ])
392
+ .lusolve(math.matrix([1, 2]))
393
+ ).toMatchTypeOf<MathJsChain<MathArray>>()
394
+
395
+ expectTypeOf(
396
+ math
397
+ .chain([
398
+ [1, 2],
399
+ [3, 4],
400
+ ])
401
+ .lusolve([1, 2])
402
+ ).toMatchTypeOf<MathJsChain<MathArray>>()
403
+
404
+ // qr
405
+ expectTypeOf(
406
+ math
407
+ .chain([
408
+ [1, 2],
409
+ [3, 4],
410
+ ])
411
+ .qr()
412
+ ).toMatchTypeOf<MathJsChain<QRDecomposition>>()
413
+ expectTypeOf(
414
+ math
415
+ .chain(
416
+ math.matrix([
417
+ [1, 2],
418
+ [3, 4],
419
+ ])
420
+ )
421
+ .qr()
422
+ ).toMatchTypeOf<MathJsChain<QRDecomposition>>()
423
+
424
+ // rationalize
425
+ expectTypeOf(math.chain('1.23').rationalize()).toMatchTypeOf<
426
+ MathJsChain<MathNode>
427
+ >()
428
+ expectTypeOf(math.chain(math.parse('1.23')).rationalize()).toMatchTypeOf<
429
+ MathJsChain<MathNode>
430
+ >()
431
+
432
+ // simplify
433
+ expectTypeOf(math.chain('a + a + b').simplify()).toMatchTypeOf<
434
+ MathJsChain<MathNode>
435
+ >()
436
+ expectTypeOf(math.chain(math.parse('a + a + b')).simplify()).toMatchTypeOf<
437
+ MathJsChain<MathNode>
438
+ >()
439
+
440
+ // slu
441
+ expectTypeOf(
442
+ math
443
+ .chain(
444
+ math.sparse([
445
+ [1, 2],
446
+ [3, 4],
447
+ ])
448
+ )
449
+ .slu(2, 0.5)
450
+ ).toMatchTypeOf<MathJsChain<SLUDecomposition>>()
451
+
452
+ // usolve
453
+ expectTypeOf(
454
+ math
455
+ .chain([
456
+ [1, 2],
457
+ [3, 4],
458
+ ])
459
+ .usolve([1, 2])
460
+ ).toMatchTypeOf<MathJsChain<MathArray>>()
461
+ expectTypeOf(
462
+ math
463
+ .chain(
464
+ math.matrix([
465
+ [1, 2],
466
+ [3, 4],
467
+ ])
468
+ )
469
+ .usolve([1, 2])
470
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
471
+
472
+ // abs
473
+ expectTypeOf(math.chain(1).abs()).toMatchTypeOf<MathJsChain<number>>()
474
+ expectTypeOf(math.chain(math.bignumber(1)).abs()).toMatchTypeOf<
475
+ MathJsChain<BigNumber>
476
+ >()
477
+ expectTypeOf(math.chain(math.fraction(1, 2)).abs()).toMatchTypeOf<
478
+ MathJsChain<Fraction>
479
+ >()
480
+ expectTypeOf(math.chain(math.complex(1, 2)).abs()).toMatchTypeOf<
481
+ MathJsChain<Complex>
482
+ >()
483
+ expectTypeOf(math.chain([1, 2]).abs()).toMatchTypeOf<MathJsChain<MathArray>>()
484
+ expectTypeOf(
485
+ math
486
+ .chain(
487
+ math.matrix([
488
+ [1, 2],
489
+ [3, 4],
490
+ ])
491
+ )
492
+ .abs()
493
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
494
+ expectTypeOf(math.chain(math.unit('furlong')).abs()).toMatchTypeOf<
495
+ MathJsChain<Unit>
496
+ >()
497
+
498
+ // add
499
+ expectTypeOf(math.chain(1).add(2)).toMatchTypeOf<MathJsChain<MathType>>()
500
+ expectTypeOf(math.chain([1]).add(2)).toMatchTypeOf<MathJsChain<MathType>>()
501
+ expectTypeOf(
502
+ math.chain(
503
+ math.matrix([
504
+ [1, 2],
505
+ [3, 4],
506
+ ])
507
+ )
508
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
509
+
510
+ // apply
511
+ expectTypeOf(math.chain([1, 2, 3]).apply(0, () => 1)).toMatchTypeOf<
512
+ MathJsChain<number[]>
513
+ >()
514
+
515
+ // cbrt
516
+ expectTypeOf(math.chain(1).cbrt()).toMatchTypeOf<MathJsChain<number>>()
517
+ expectTypeOf(math.chain(math.bignumber(1)).cbrt()).toMatchTypeOf<
518
+ MathJsChain<BigNumber>
519
+ >()
520
+ expectTypeOf(math.chain(math.complex(1, 2)).cbrt()).toMatchTypeOf<
521
+ MathJsChain<Complex>
522
+ >()
523
+ expectTypeOf(math.chain([1, 2]).cbrt()).toMatchTypeOf<
524
+ MathJsChain<MathArray>
525
+ >()
526
+ expectTypeOf(
527
+ math
528
+ .chain(
529
+ math.matrix([
530
+ [1, 2],
531
+ [3, 4],
532
+ ])
533
+ )
534
+ .cbrt()
535
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
536
+
537
+ // cbrt
538
+ expectTypeOf(math.chain(1).ceil()).toMatchTypeOf<
539
+ MathJsChain<MathNumericType>
540
+ >()
541
+ expectTypeOf(math.chain([1]).ceil()).toMatchTypeOf<
542
+ MathJsChain<MathCollection>
543
+ >()
544
+
545
+ // fix
546
+ expectTypeOf(math.chain(1).fix()).toMatchTypeOf<
547
+ MathJsChain<MathNumericType>
548
+ >()
549
+ expectTypeOf(math.chain([1]).fix()).toMatchTypeOf<
550
+ MathJsChain<MathCollection>
551
+ >()
552
+
553
+ // floor
554
+ expectTypeOf(math.chain(1).floor()).toMatchTypeOf<
555
+ MathJsChain<MathNumericType>
556
+ >()
557
+ expectTypeOf(math.chain([1]).floor()).toMatchTypeOf<
558
+ MathJsChain<MathCollection>
559
+ >()
560
+
561
+ // round
562
+ expectTypeOf(math.chain(1).round()).toMatchTypeOf<
563
+ MathJsChain<MathNumericType>
564
+ >()
565
+ expectTypeOf(math.chain([1]).round()).toMatchTypeOf<
566
+ MathJsChain<MathCollection>
567
+ >()
568
+
569
+ // cube
570
+ expectTypeOf(math.chain(1).cube()).toMatchTypeOf<MathJsChain<number>>()
571
+ expectTypeOf(math.chain(math.bignumber(1)).cube()).toMatchTypeOf<
572
+ MathJsChain<BigNumber>
573
+ >()
574
+ expectTypeOf(math.chain(math.fraction(1, 2)).cube()).toMatchTypeOf<
575
+ MathJsChain<Fraction>
576
+ >()
577
+ expectTypeOf(math.chain(math.complex(1, 2)).cube()).toMatchTypeOf<
578
+ MathJsChain<Complex>
579
+ >()
580
+ expectTypeOf(math.chain([1, 2]).cube()).toMatchTypeOf<
581
+ MathJsChain<MathArray>
582
+ >()
583
+ expectTypeOf(
584
+ math
585
+ .chain(
586
+ math.matrix([
587
+ [1, 2],
588
+ [3, 4],
589
+ ])
590
+ )
591
+ .cube()
592
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
593
+ expectTypeOf(math.chain(math.unit('furlong')).cube()).toMatchTypeOf<
594
+ MathJsChain<Unit>
595
+ >()
596
+
597
+ // divide
598
+ expectTypeOf(
599
+ math.chain(math.unit('furlong')).divide(math.unit('femtosecond'))
600
+ ).toMatchTypeOf<MathJsChain<number | Unit>>()
601
+ expectTypeOf(math.chain(math.unit('furlong')).divide(6)).toMatchTypeOf<
602
+ MathJsChain<Unit>
603
+ >()
604
+ expectTypeOf(math.chain(2).divide(6)).toMatchTypeOf<MathJsChain<number>>()
605
+ expectTypeOf(math.chain([1, 2, 3]).divide(6)).toMatchTypeOf<
606
+ MathJsChain<MathType>
607
+ >()
608
+
609
+ // dotDivide
610
+ expectTypeOf(math.chain(1).dotDivide(2)).toMatchTypeOf<
611
+ MathJsChain<MathType>
612
+ >()
613
+ expectTypeOf(
614
+ math
615
+ .chain(
616
+ math.matrix([
617
+ [1, 2],
618
+ [3, 4],
619
+ ])
620
+ )
621
+ .dotDivide(2)
622
+ ).toMatchTypeOf<MathJsChain<MathType>>()
623
+
624
+ // dotMultiply
625
+ expectTypeOf(math.chain(1).dotMultiply(2)).toMatchTypeOf<
626
+ MathJsChain<MathType>
627
+ >()
628
+ expectTypeOf(
629
+ math
630
+ .chain(
631
+ math.matrix([
632
+ [1, 2],
633
+ [3, 4],
634
+ ])
635
+ )
636
+ .dotMultiply(2)
637
+ ).toMatchTypeOf<MathJsChain<MathType>>()
638
+
639
+ // dotPow
640
+ expectTypeOf(math.chain(1).dotPow(2)).toMatchTypeOf<MathJsChain<MathType>>()
641
+ expectTypeOf(
642
+ math
643
+ .chain(
644
+ math.matrix([
645
+ [1, 2],
646
+ [3, 4],
647
+ ])
648
+ )
649
+ .dotPow(2)
650
+ ).toMatchTypeOf<MathJsChain<MathType>>()
651
+
652
+ // exp
653
+ expectTypeOf(math.chain(1).exp()).toMatchTypeOf<MathJsChain<MathType>>()
654
+ expectTypeOf(math.chain([1, 2]).exp()).toMatchTypeOf<MathJsChain<MathArray>>()
655
+ expectTypeOf(
656
+ math
657
+ .chain(
658
+ math.matrix([
659
+ [1, 2],
660
+ [3, 4],
661
+ ])
662
+ )
663
+ .exp()
664
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
665
+
666
+ // expm1
667
+ expectTypeOf(math.chain(1).expm1()).toMatchTypeOf<MathJsChain<MathType>>()
668
+ expectTypeOf(math.chain([1, 2]).expm1()).toMatchTypeOf<
669
+ MathJsChain<MathArray>
670
+ >()
671
+ expectTypeOf(
672
+ math
673
+ .chain(
674
+ math.matrix([
675
+ [1, 2],
676
+ [3, 4],
677
+ ])
678
+ )
679
+ .expm1()
680
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
681
+
682
+ // gcd
683
+ expectTypeOf(math.chain([1, 2]).gcd(3)).toMatchTypeOf<MathJsChain<number>>()
684
+ expectTypeOf(math.chain([1, 2]).gcd(3, 4)).toMatchTypeOf<
685
+ MathJsChain<number>
686
+ >()
687
+ // TODO make gcd() work in the following cases
688
+ // expectTypeOf(math.chain([1, 2]).gcd()).toMatchTypeOf<MathJsChain<number>>()
689
+ // expectTypeOf(math.chain([[1], [2]]).gcd()).toMatchTypeOf<
690
+ // MathJsChain<MathArray>
691
+ // >()
692
+ // expectTypeOf(
693
+ // math.chain([math.bignumber(1), math.bignumber(1)]).gcd()
694
+ // ).toMatchTypeOf<MathJsChain<BigNumber>>()
695
+ // expectTypeOf(
696
+ // math.chain([math.complex(1, 2), math.complex(1, 2)]).gcd()
697
+ // ).toMatchTypeOf<MathJsChain<Complex>>()
698
+ // expectTypeOf(
699
+ // math
700
+ // .chain(
701
+ // math.matrix([
702
+ // [1, 2],
703
+ // [3, 4],
704
+ // ])
705
+ // )
706
+ // .expm1()
707
+ // ).toMatchTypeOf<MathJsChain<Matrix>>()
708
+
709
+ // hypot
710
+ expectTypeOf(math.chain([1, 2]).hypot()).toMatchTypeOf<MathJsChain<number>>()
711
+ expectTypeOf(
712
+ math.chain([math.bignumber(1), math.bignumber(1)]).hypot()
713
+ ).toMatchTypeOf<MathJsChain<BigNumber>>()
714
+
715
+ // lcm
716
+ expectTypeOf(math.chain(1).lcm(2)).toMatchTypeOf<MathJsChain<number>>()
717
+ expectTypeOf(
718
+ math.chain(math.bignumber(1)).lcm(math.bignumber(2))
719
+ ).toMatchTypeOf<MathJsChain<BigNumber>>()
720
+ expectTypeOf(math.chain([1, 2]).lcm([3, 4])).toMatchTypeOf<
721
+ MathJsChain<MathArray>
722
+ >()
723
+ expectTypeOf(
724
+ math
725
+ .chain(
726
+ math.matrix([
727
+ [1, 2],
728
+ [3, 4],
729
+ ])
730
+ )
731
+ .lcm(
732
+ math.matrix([
733
+ [1, 2],
734
+ [3, 4],
735
+ ])
736
+ )
737
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
738
+
739
+ // log
740
+ expectTypeOf(math.chain(1).log(2)).toMatchTypeOf<MathJsChain<number>>()
741
+ expectTypeOf(
742
+ math.chain(math.bignumber(1)).log(math.bignumber(2))
743
+ ).toMatchTypeOf<MathJsChain<BigNumber>>()
744
+
745
+ // log10
746
+ expectTypeOf(math.chain(1).log10()).toMatchTypeOf<MathJsChain<number>>()
747
+ expectTypeOf(math.chain(math.bignumber(1)).log10()).toMatchTypeOf<
748
+ MathJsChain<BigNumber>
749
+ >()
750
+ expectTypeOf(math.chain([1, 2]).log10()).toMatchTypeOf<
751
+ MathJsChain<MathArray>
752
+ >()
753
+ expectTypeOf(
754
+ math
755
+ .chain(
756
+ math.matrix([
757
+ [1, 2],
758
+ [3, 4],
759
+ ])
760
+ )
761
+ .log10()
762
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
763
+
764
+ // TODO complete the rest of these...
162
765
  }
163
766
 
164
767
  /*
@@ -427,6 +1030,62 @@ Matrices examples
427
1030
  {
428
1031
  assert.strictEqual(math.matrix([1, 2, 3]) instanceof math.Matrix, true)
429
1032
  }
1033
+
1034
+ // Fourier transform and inverse
1035
+ {
1036
+ assert.ok(
1037
+ math.deepEqual(
1038
+ math.fft([
1039
+ [1, 0],
1040
+ [1, 0],
1041
+ ]),
1042
+ [
1043
+ [math.complex(2, 0), math.complex(2, 0)],
1044
+ [math.complex(0, 0), math.complex(0, 0)],
1045
+ ]
1046
+ )
1047
+ )
1048
+ assert.ok(
1049
+ math.deepEqual(
1050
+ math.fft(
1051
+ math.matrix([
1052
+ [1, 0],
1053
+ [1, 0],
1054
+ ])
1055
+ ),
1056
+ math.matrix([
1057
+ [math.complex(2, 0), math.complex(2, 0)],
1058
+ [math.complex(0, 0), math.complex(0, 0)],
1059
+ ])
1060
+ )
1061
+ )
1062
+ assert.ok(
1063
+ math.deepEqual(
1064
+ math.ifft([
1065
+ [2, 2],
1066
+ [0, 0],
1067
+ ]),
1068
+ [
1069
+ [math.complex(1, 0), math.complex(0, 0)],
1070
+ [math.complex(1, 0), math.complex(0, 0)],
1071
+ ]
1072
+ )
1073
+ )
1074
+ assert.ok(
1075
+ math.deepEqual(
1076
+ math.ifft(
1077
+ math.matrix([
1078
+ [2, 2],
1079
+ [0, 0],
1080
+ ])
1081
+ ),
1082
+ math.matrix([
1083
+ [math.complex(1, 0), math.complex(0, 0)],
1084
+ [math.complex(1, 0), math.complex(0, 0)],
1085
+ ])
1086
+ )
1087
+ )
1088
+ }
430
1089
  }
431
1090
 
432
1091
  /*
@@ -863,6 +1522,34 @@ Function round examples
863
1522
  assert.throws(() => math.round([3.21, 3.82], [1, 2]), TypeError)
864
1523
  }
865
1524
 
1525
+ /*
1526
+ Clone examples
1527
+ */
1528
+ {
1529
+ const math = create(all, {})
1530
+ expectTypeOf(new math.ConstantNode(1).clone()).toMatchTypeOf<ConstantNode>()
1531
+ expectTypeOf(
1532
+ new math.OperatorNode('*', 'multiply', [
1533
+ new math.ConstantNode(3),
1534
+ new math.SymbolNode('x'),
1535
+ ]).clone()
1536
+ ).toMatchTypeOf<OperatorNode>()
1537
+
1538
+ expectTypeOf(
1539
+ new math.ConstantNode(1).cloneDeep()
1540
+ ).toMatchTypeOf<ConstantNode>()
1541
+ expectTypeOf(
1542
+ new math.OperatorNode('*', 'multiply', [
1543
+ new math.ConstantNode(3),
1544
+ new math.SymbolNode('x'),
1545
+ ]).cloneDeep()
1546
+ ).toMatchTypeOf<OperatorNode>()
1547
+
1548
+ expectTypeOf(
1549
+ math.clone(new math.ConstantNode(1))
1550
+ ).toMatchTypeOf<ConstantNode>()
1551
+ }
1552
+
866
1553
  /*
867
1554
  JSON serialization/deserialization
868
1555
  */
@@ -1225,7 +1912,8 @@ Factory Test
1225
1912
  expectTypeOf(x).toMatchTypeOf<math.SymbolNode>()
1226
1913
  }
1227
1914
  if (math.isChain(x)) {
1228
- expectTypeOf(x).toMatchTypeOf<math.MathJsChain>()
1915
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1916
+ expectTypeOf(x).toMatchTypeOf<math.MathJsChain<any>>()
1229
1917
  }
1230
1918
  }
1231
1919