mathjs 10.5.3 → 10.6.2

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 +29 -0
  2. package/lib/browser/math.js +6 -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 +19 -16
  32. package/types/index.d.ts +1072 -308
  33. package/types/index.ts +763 -7
package/types/index.ts CHANGED
@@ -8,6 +8,27 @@ 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,
28
+ OperatorNodeFn,
29
+ OperatorNodeOp,
30
+ SymbolNode,
31
+ ParenthesisNode,
11
32
  } from 'mathjs'
12
33
  import * as assert from 'assert'
13
34
  import { expectTypeOf } from 'expect-type'
@@ -65,6 +86,8 @@ Basic usage examples
65
86
  math.chain(m2by3).variance(0, 'biased')
66
87
  math.chain(m2by3).variance(1, 'uncorrected').variance('unbiased')
67
88
 
89
+ math.variance(math.variance(m2by3, 'uncorrected'))
90
+
68
91
  // expressions
69
92
  math.evaluate('1.2 * (2 + 4.5)')
70
93
 
@@ -151,14 +174,598 @@ Chaining examples
151
174
  )
152
175
 
153
176
  const r = math.chain(-0.483).round([0, 1, 2]).floor().add(0.52).fix(1).done()
177
+
154
178
  assert.deepStrictEqual(r, [0.5, -0.4, -0.4])
155
179
 
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())
180
+ expectTypeOf(
181
+ math.chain('x + y').parse().resolve({ x: 1 }).done()
182
+ ).toMatchTypeOf<MathNode>()
183
+ expectTypeOf(
184
+ math.chain('x + y').parse().resolve().done()
185
+ ).toMatchTypeOf<MathNode>()
186
+
187
+ // bignum
188
+ expectTypeOf(math.chain(math.bignumber(12))).toMatchTypeOf<
189
+ MathJsChain<BigNumber>
190
+ >()
191
+ expectTypeOf(math.chain(12).bignumber()).toMatchTypeOf<
192
+ MathJsChain<BigNumber>
193
+ >()
194
+ expectTypeOf(math.chain([12, 13, 14]).bignumber()).toMatchTypeOf<
195
+ MathJsChain<MathCollection>
196
+ >()
197
+
198
+ // chain
199
+ expectTypeOf(math.chain(12).bignumber().clone()).toMatchTypeOf<
200
+ MathJsChain<BigNumber>
201
+ >()
202
+
203
+ // boolean
204
+ expectTypeOf(math.chain(math.boolean(true))).toMatchTypeOf<
205
+ MathJsChain<boolean>
206
+ >()
207
+ expectTypeOf(math.chain(true).boolean()).toMatchTypeOf<MathJsChain<boolean>>()
208
+ expectTypeOf(math.chain([12, 13, 14]).boolean()).toMatchTypeOf<
209
+ MathJsChain<MathCollection>
210
+ >()
211
+
212
+ // complex
213
+ expectTypeOf(math.chain(math.complex('123'))).toMatchTypeOf<
214
+ MathJsChain<Complex>
215
+ >()
216
+ expectTypeOf(math.chain('123').complex()).toMatchTypeOf<
217
+ MathJsChain<Complex>
218
+ >()
219
+ expectTypeOf(math.chain('123').complex(1)).toMatchTypeOf<
220
+ MathJsChain<Complex>
221
+ >()
222
+ expectTypeOf(math.chain([12, 13, 14]).complex()).toMatchTypeOf<
223
+ MathJsChain<MathCollection>
224
+ >()
225
+
226
+ // createUnit
227
+ expectTypeOf(math.chain(math.createUnit('furlong'))).toMatchTypeOf<
228
+ MathJsChain<Unit>
229
+ >()
230
+ expectTypeOf(
231
+ math.chain(
232
+ math.createUnit({
233
+ fresnel: '1234',
234
+ })
235
+ )
236
+ ).toMatchTypeOf<MathJsChain<Unit>>()
237
+
238
+ // fraction
239
+ expectTypeOf(math.chain(math.fraction('123'))).toMatchTypeOf<
240
+ MathJsChain<Fraction>
241
+ >()
242
+ expectTypeOf(math.chain('123').fraction()).toMatchTypeOf<
243
+ MathJsChain<Fraction>
244
+ >()
245
+ expectTypeOf(math.chain('123').fraction(2)).toMatchTypeOf<
246
+ MathJsChain<Fraction>
247
+ >()
248
+ expectTypeOf(math.chain([12, 13, 14]).fraction()).toMatchTypeOf<
249
+ MathJsChain<MathCollection>
250
+ >()
251
+ expectTypeOf(math.chain([12, 13, 14]).fraction()).toMatchTypeOf<
252
+ MathJsChain<MathCollection>
253
+ >()
254
+
255
+ // index
256
+ expectTypeOf(math.chain([12, 13, 14]).index()).toMatchTypeOf<
257
+ MathJsChain<Index>
258
+ >()
259
+
260
+ // matrix
261
+ expectTypeOf(math.chain([12, 13, 14, 15]).matrix()).toMatchTypeOf<
262
+ MathJsChain<Matrix>
263
+ >()
264
+
265
+ // number
266
+ expectTypeOf(math.chain('12').number()).toMatchTypeOf<MathJsChain<number>>()
267
+ expectTypeOf(math.chain([12, 13, 14]).number()).toMatchTypeOf<
268
+ MathJsChain<MathCollection>
269
+ >()
270
+
271
+ // sparse
272
+ expectTypeOf(math.chain([12, 13, 14, 15]).sparse()).toMatchTypeOf<
273
+ MathJsChain<Matrix>
274
+ >()
275
+
276
+ // split unit
277
+ expectTypeOf(math.chain(math.unit('furlong')).splitUnit([])).toMatchTypeOf<
278
+ MathJsChain<Unit[]>
279
+ >()
280
+
281
+ // string
282
+ expectTypeOf(math.chain('test').string()).toMatchTypeOf<MathJsChain<string>>()
283
+ expectTypeOf(math.chain([1, 2, 3]).string()).toMatchTypeOf<
284
+ MathJsChain<MathCollection>
285
+ >()
286
+
287
+ // unit
288
+ expectTypeOf(math.chain(12).unit()).toMatchTypeOf<MathJsChain<Unit>>()
289
+ expectTypeOf(math.chain([1, 2, 3]).unit()).toMatchTypeOf<
290
+ MathJsChain<Unit[]>
291
+ >()
292
+
293
+ // compile
294
+ expectTypeOf(math.chain('a + b').compile()).toMatchTypeOf<
295
+ MathJsChain<EvalFunction>
296
+ >()
297
+
298
+ // evaluate
299
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
+ expectTypeOf(math.chain('1 + 1').evaluate()).toMatchTypeOf<MathJsChain<any>>()
301
+ expectTypeOf(math.chain(['1 + 1', '2 + 2']).evaluate()).toMatchTypeOf<
160
302
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
161
- .toMatchTypeOf<any>()
303
+ MathJsChain<any[]>
304
+ >()
305
+
306
+ // parse
307
+ expectTypeOf(math.chain('1 + 1').parse()).toMatchTypeOf<
308
+ MathJsChain<MathNode>
309
+ >()
310
+ expectTypeOf(math.chain(['1 + 1', '2 + 2']).parse()).toMatchTypeOf<
311
+ MathJsChain<MathNode[]>
312
+ >()
313
+
314
+ // resolve
315
+ expectTypeOf(math.chain(math.parse('1 + 1')).resolve({})).toMatchTypeOf<
316
+ MathJsChain<MathNode>
317
+ >()
318
+ expectTypeOf(
319
+ math.chain([math.parse('1 + 1'), math.parse('1 + 1')]).resolve({})
320
+ ).toMatchTypeOf<MathJsChain<MathNode[]>>()
321
+
322
+ // derivative
323
+ expectTypeOf(math.chain(math.parse('x^2')).derivative('x')).toMatchTypeOf<
324
+ MathJsChain<MathNode>
325
+ >()
326
+
327
+ // lsolve
328
+ expectTypeOf(
329
+ math
330
+ .chain([
331
+ [1, 2],
332
+ [3, 4],
333
+ ])
334
+ .lsolve([1, 2])
335
+ ).toMatchTypeOf<MathJsChain<MathArray>>()
336
+ expectTypeOf(
337
+ math
338
+ .chain(
339
+ math.matrix([
340
+ [1, 2],
341
+ [3, 4],
342
+ ])
343
+ )
344
+ .lsolve([1, 2])
345
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
346
+
347
+ // lup
348
+ expectTypeOf(
349
+ math
350
+ .chain([
351
+ [1, 2],
352
+ [3, 4],
353
+ ])
354
+ .lup()
355
+ ).toMatchTypeOf<MathJsChain<LUDecomposition>>()
356
+ expectTypeOf(
357
+ math
358
+ .chain(
359
+ math.matrix([
360
+ [1, 2],
361
+ [3, 4],
362
+ ])
363
+ )
364
+ .lup()
365
+ ).toMatchTypeOf<MathJsChain<LUDecomposition>>()
366
+
367
+ // lusolve
368
+ expectTypeOf(
369
+ math
370
+ .chain(
371
+ math.matrix([
372
+ [1, 2],
373
+ [3, 4],
374
+ ])
375
+ )
376
+ .lusolve(math.matrix([1, 2]))
377
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
378
+
379
+ expectTypeOf(
380
+ math
381
+ .chain(
382
+ math.matrix([
383
+ [1, 2],
384
+ [3, 4],
385
+ ])
386
+ )
387
+ .lusolve([1, 2])
388
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
389
+
390
+ expectTypeOf(
391
+ math
392
+ .chain([
393
+ [1, 2],
394
+ [3, 4],
395
+ ])
396
+ .lusolve(math.matrix([1, 2]))
397
+ ).toMatchTypeOf<MathJsChain<MathArray>>()
398
+
399
+ expectTypeOf(
400
+ math
401
+ .chain([
402
+ [1, 2],
403
+ [3, 4],
404
+ ])
405
+ .lusolve([1, 2])
406
+ ).toMatchTypeOf<MathJsChain<MathArray>>()
407
+
408
+ // qr
409
+ expectTypeOf(
410
+ math
411
+ .chain([
412
+ [1, 2],
413
+ [3, 4],
414
+ ])
415
+ .qr()
416
+ ).toMatchTypeOf<MathJsChain<QRDecomposition>>()
417
+ expectTypeOf(
418
+ math
419
+ .chain(
420
+ math.matrix([
421
+ [1, 2],
422
+ [3, 4],
423
+ ])
424
+ )
425
+ .qr()
426
+ ).toMatchTypeOf<MathJsChain<QRDecomposition>>()
427
+
428
+ // rationalize
429
+ expectTypeOf(math.chain('1.23').rationalize()).toMatchTypeOf<
430
+ MathJsChain<MathNode>
431
+ >()
432
+ expectTypeOf(math.chain(math.parse('1.23')).rationalize()).toMatchTypeOf<
433
+ MathJsChain<MathNode>
434
+ >()
435
+
436
+ // simplify
437
+ expectTypeOf(math.chain('a + a + b').simplify()).toMatchTypeOf<
438
+ MathJsChain<MathNode>
439
+ >()
440
+ expectTypeOf(math.chain(math.parse('a + a + b')).simplify()).toMatchTypeOf<
441
+ MathJsChain<MathNode>
442
+ >()
443
+
444
+ // slu
445
+ expectTypeOf(
446
+ math
447
+ .chain(
448
+ math.sparse([
449
+ [1, 2],
450
+ [3, 4],
451
+ ])
452
+ )
453
+ .slu(2, 0.5)
454
+ ).toMatchTypeOf<MathJsChain<SLUDecomposition>>()
455
+
456
+ // usolve
457
+ expectTypeOf(
458
+ math
459
+ .chain([
460
+ [1, 2],
461
+ [3, 4],
462
+ ])
463
+ .usolve([1, 2])
464
+ ).toMatchTypeOf<MathJsChain<MathArray>>()
465
+ expectTypeOf(
466
+ math
467
+ .chain(
468
+ math.matrix([
469
+ [1, 2],
470
+ [3, 4],
471
+ ])
472
+ )
473
+ .usolve([1, 2])
474
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
475
+
476
+ // abs
477
+ expectTypeOf(math.chain(1).abs()).toMatchTypeOf<MathJsChain<number>>()
478
+ expectTypeOf(math.chain(math.bignumber(1)).abs()).toMatchTypeOf<
479
+ MathJsChain<BigNumber>
480
+ >()
481
+ expectTypeOf(math.chain(math.fraction(1, 2)).abs()).toMatchTypeOf<
482
+ MathJsChain<Fraction>
483
+ >()
484
+ expectTypeOf(math.chain(math.complex(1, 2)).abs()).toMatchTypeOf<
485
+ MathJsChain<Complex>
486
+ >()
487
+ expectTypeOf(math.chain([1, 2]).abs()).toMatchTypeOf<MathJsChain<MathArray>>()
488
+ expectTypeOf(
489
+ math
490
+ .chain(
491
+ math.matrix([
492
+ [1, 2],
493
+ [3, 4],
494
+ ])
495
+ )
496
+ .abs()
497
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
498
+ expectTypeOf(math.chain(math.unit('furlong')).abs()).toMatchTypeOf<
499
+ MathJsChain<Unit>
500
+ >()
501
+
502
+ // add
503
+ expectTypeOf(math.chain(1).add(2)).toMatchTypeOf<MathJsChain<MathType>>()
504
+ expectTypeOf(math.chain([1]).add(2)).toMatchTypeOf<MathJsChain<MathType>>()
505
+ expectTypeOf(
506
+ math.chain(
507
+ math.matrix([
508
+ [1, 2],
509
+ [3, 4],
510
+ ])
511
+ )
512
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
513
+
514
+ // apply
515
+ expectTypeOf(math.chain([1, 2, 3]).apply(0, () => 1)).toMatchTypeOf<
516
+ MathJsChain<number[]>
517
+ >()
518
+
519
+ // cbrt
520
+ expectTypeOf(math.chain(1).cbrt()).toMatchTypeOf<MathJsChain<number>>()
521
+ expectTypeOf(math.chain(math.bignumber(1)).cbrt()).toMatchTypeOf<
522
+ MathJsChain<BigNumber>
523
+ >()
524
+ expectTypeOf(math.chain(math.complex(1, 2)).cbrt()).toMatchTypeOf<
525
+ MathJsChain<Complex>
526
+ >()
527
+ expectTypeOf(math.chain([1, 2]).cbrt()).toMatchTypeOf<
528
+ MathJsChain<MathArray>
529
+ >()
530
+ expectTypeOf(
531
+ math
532
+ .chain(
533
+ math.matrix([
534
+ [1, 2],
535
+ [3, 4],
536
+ ])
537
+ )
538
+ .cbrt()
539
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
540
+
541
+ // cbrt
542
+ expectTypeOf(math.chain(1).ceil()).toMatchTypeOf<
543
+ MathJsChain<MathNumericType>
544
+ >()
545
+ expectTypeOf(math.chain([1]).ceil()).toMatchTypeOf<
546
+ MathJsChain<MathCollection>
547
+ >()
548
+
549
+ // fix
550
+ expectTypeOf(math.chain(1).fix()).toMatchTypeOf<
551
+ MathJsChain<MathNumericType>
552
+ >()
553
+ expectTypeOf(math.chain([1]).fix()).toMatchTypeOf<
554
+ MathJsChain<MathCollection>
555
+ >()
556
+
557
+ // floor
558
+ expectTypeOf(math.chain(1).floor()).toMatchTypeOf<
559
+ MathJsChain<MathNumericType>
560
+ >()
561
+ expectTypeOf(math.chain([1]).floor()).toMatchTypeOf<
562
+ MathJsChain<MathCollection>
563
+ >()
564
+
565
+ // round
566
+ expectTypeOf(math.chain(1).round()).toMatchTypeOf<
567
+ MathJsChain<MathNumericType>
568
+ >()
569
+ expectTypeOf(math.chain([1]).round()).toMatchTypeOf<
570
+ MathJsChain<MathCollection>
571
+ >()
572
+
573
+ // cube
574
+ expectTypeOf(math.chain(1).cube()).toMatchTypeOf<MathJsChain<number>>()
575
+ expectTypeOf(math.chain(math.bignumber(1)).cube()).toMatchTypeOf<
576
+ MathJsChain<BigNumber>
577
+ >()
578
+ expectTypeOf(math.chain(math.fraction(1, 2)).cube()).toMatchTypeOf<
579
+ MathJsChain<Fraction>
580
+ >()
581
+ expectTypeOf(math.chain(math.complex(1, 2)).cube()).toMatchTypeOf<
582
+ MathJsChain<Complex>
583
+ >()
584
+ expectTypeOf(math.chain([1, 2]).cube()).toMatchTypeOf<
585
+ MathJsChain<MathArray>
586
+ >()
587
+ expectTypeOf(
588
+ math
589
+ .chain(
590
+ math.matrix([
591
+ [1, 2],
592
+ [3, 4],
593
+ ])
594
+ )
595
+ .cube()
596
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
597
+ expectTypeOf(math.chain(math.unit('furlong')).cube()).toMatchTypeOf<
598
+ MathJsChain<Unit>
599
+ >()
600
+
601
+ // divide
602
+ expectTypeOf(
603
+ math.chain(math.unit('furlong')).divide(math.unit('femtosecond'))
604
+ ).toMatchTypeOf<MathJsChain<number | Unit>>()
605
+ expectTypeOf(math.chain(math.unit('furlong')).divide(6)).toMatchTypeOf<
606
+ MathJsChain<Unit>
607
+ >()
608
+ expectTypeOf(math.chain(2).divide(6)).toMatchTypeOf<MathJsChain<number>>()
609
+ expectTypeOf(math.chain([1, 2, 3]).divide(6)).toMatchTypeOf<
610
+ MathJsChain<MathType>
611
+ >()
612
+
613
+ // dotDivide
614
+ expectTypeOf(math.chain(1).dotDivide(2)).toMatchTypeOf<
615
+ MathJsChain<MathType>
616
+ >()
617
+ expectTypeOf(
618
+ math
619
+ .chain(
620
+ math.matrix([
621
+ [1, 2],
622
+ [3, 4],
623
+ ])
624
+ )
625
+ .dotDivide(2)
626
+ ).toMatchTypeOf<MathJsChain<MathType>>()
627
+
628
+ // dotMultiply
629
+ expectTypeOf(math.chain(1).dotMultiply(2)).toMatchTypeOf<
630
+ MathJsChain<MathType>
631
+ >()
632
+ expectTypeOf(
633
+ math
634
+ .chain(
635
+ math.matrix([
636
+ [1, 2],
637
+ [3, 4],
638
+ ])
639
+ )
640
+ .dotMultiply(2)
641
+ ).toMatchTypeOf<MathJsChain<MathType>>()
642
+
643
+ // dotPow
644
+ expectTypeOf(math.chain(1).dotPow(2)).toMatchTypeOf<MathJsChain<MathType>>()
645
+ expectTypeOf(
646
+ math
647
+ .chain(
648
+ math.matrix([
649
+ [1, 2],
650
+ [3, 4],
651
+ ])
652
+ )
653
+ .dotPow(2)
654
+ ).toMatchTypeOf<MathJsChain<MathType>>()
655
+
656
+ // exp
657
+ expectTypeOf(math.chain(1).exp()).toMatchTypeOf<MathJsChain<MathType>>()
658
+ expectTypeOf(math.chain([1, 2]).exp()).toMatchTypeOf<MathJsChain<MathArray>>()
659
+ expectTypeOf(
660
+ math
661
+ .chain(
662
+ math.matrix([
663
+ [1, 2],
664
+ [3, 4],
665
+ ])
666
+ )
667
+ .exp()
668
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
669
+
670
+ // expm1
671
+ expectTypeOf(math.chain(1).expm1()).toMatchTypeOf<MathJsChain<MathType>>()
672
+ expectTypeOf(math.chain([1, 2]).expm1()).toMatchTypeOf<
673
+ MathJsChain<MathArray>
674
+ >()
675
+ expectTypeOf(
676
+ math
677
+ .chain(
678
+ math.matrix([
679
+ [1, 2],
680
+ [3, 4],
681
+ ])
682
+ )
683
+ .expm1()
684
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
685
+
686
+ // gcd
687
+ expectTypeOf(math.chain([1, 2]).gcd(3)).toMatchTypeOf<MathJsChain<number>>()
688
+ expectTypeOf(math.chain([1, 2]).gcd(3, 4)).toMatchTypeOf<
689
+ MathJsChain<number>
690
+ >()
691
+ // TODO make gcd() work in the following cases
692
+ // expectTypeOf(math.chain([1, 2]).gcd()).toMatchTypeOf<MathJsChain<number>>()
693
+ // expectTypeOf(math.chain([[1], [2]]).gcd()).toMatchTypeOf<
694
+ // MathJsChain<MathArray>
695
+ // >()
696
+ // expectTypeOf(
697
+ // math.chain([math.bignumber(1), math.bignumber(1)]).gcd()
698
+ // ).toMatchTypeOf<MathJsChain<BigNumber>>()
699
+ // expectTypeOf(
700
+ // math.chain([math.complex(1, 2), math.complex(1, 2)]).gcd()
701
+ // ).toMatchTypeOf<MathJsChain<Complex>>()
702
+ // expectTypeOf(
703
+ // math
704
+ // .chain(
705
+ // math.matrix([
706
+ // [1, 2],
707
+ // [3, 4],
708
+ // ])
709
+ // )
710
+ // .expm1()
711
+ // ).toMatchTypeOf<MathJsChain<Matrix>>()
712
+
713
+ // hypot
714
+ expectTypeOf(math.chain([1, 2]).hypot()).toMatchTypeOf<MathJsChain<number>>()
715
+ expectTypeOf(
716
+ math.chain([math.bignumber(1), math.bignumber(1)]).hypot()
717
+ ).toMatchTypeOf<MathJsChain<BigNumber>>()
718
+
719
+ // lcm
720
+ expectTypeOf(math.chain(1).lcm(2)).toMatchTypeOf<MathJsChain<number>>()
721
+ expectTypeOf(
722
+ math.chain(math.bignumber(1)).lcm(math.bignumber(2))
723
+ ).toMatchTypeOf<MathJsChain<BigNumber>>()
724
+ expectTypeOf(math.chain([1, 2]).lcm([3, 4])).toMatchTypeOf<
725
+ MathJsChain<MathArray>
726
+ >()
727
+ expectTypeOf(
728
+ math
729
+ .chain(
730
+ math.matrix([
731
+ [1, 2],
732
+ [3, 4],
733
+ ])
734
+ )
735
+ .lcm(
736
+ math.matrix([
737
+ [1, 2],
738
+ [3, 4],
739
+ ])
740
+ )
741
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
742
+
743
+ // log
744
+ expectTypeOf(math.chain(1).log(2)).toMatchTypeOf<MathJsChain<number>>()
745
+ expectTypeOf(
746
+ math.chain(math.bignumber(1)).log(math.bignumber(2))
747
+ ).toMatchTypeOf<MathJsChain<BigNumber>>()
748
+
749
+ // log10
750
+ expectTypeOf(math.chain(1).log10()).toMatchTypeOf<MathJsChain<number>>()
751
+ expectTypeOf(math.chain(math.bignumber(1)).log10()).toMatchTypeOf<
752
+ MathJsChain<BigNumber>
753
+ >()
754
+ expectTypeOf(math.chain([1, 2]).log10()).toMatchTypeOf<
755
+ MathJsChain<MathArray>
756
+ >()
757
+ expectTypeOf(
758
+ math
759
+ .chain(
760
+ math.matrix([
761
+ [1, 2],
762
+ [3, 4],
763
+ ])
764
+ )
765
+ .log10()
766
+ ).toMatchTypeOf<MathJsChain<Matrix>>()
767
+
768
+ // TODO complete the rest of these...
162
769
  }
163
770
 
164
771
  /*
@@ -219,6 +826,17 @@ Complex numbers examples
219
826
  }
220
827
  }
221
828
 
829
+ /*
830
+ Parenthesis examples
831
+ */
832
+ {
833
+ const math = create(all, {})
834
+
835
+ expectTypeOf(
836
+ new math.ParenthesisNode(new math.ConstantNode(3))
837
+ ).toMatchTypeOf<ParenthesisNode<ConstantNode>>()
838
+ }
839
+
222
840
  /*
223
841
  Expressions examples
224
842
  */
@@ -318,6 +936,46 @@ Fractions examples
318
936
  const _a = math.fraction('2/3')
319
937
  }
320
938
 
939
+ /*
940
+ Transform examples
941
+ */
942
+ {
943
+ const math = create(all, {})
944
+ {
945
+ const myTransform1 = (node: MathNode): OperatorNode<'+', 'add'> =>
946
+ new OperatorNode('+', 'add', [node, new ConstantNode(1)])
947
+ const myTransform2 = (
948
+ node: OperatorNode<'+', 'add'>
949
+ ): OperatorNode<'-', 'subtract'> =>
950
+ new OperatorNode('-', 'subtract', [node, new ConstantNode(5)])
951
+
952
+ expectTypeOf(
953
+ math.parse('sqrt(3^2 + 4^2)').transform(myTransform1)
954
+ ).toMatchTypeOf<OperatorNode<'+', 'add', MathNode[]>>()
955
+
956
+ assert.deepStrictEqual(
957
+ math.parse('sqrt(3^2 + 4^2)').transform(myTransform1).toString(),
958
+ 'sqrt(3 ^ 2 + 4 ^ 2) + 1'
959
+ )
960
+
961
+ expectTypeOf(
962
+ math
963
+ .parse('sqrt(3^2 + 4^2)')
964
+ .transform(myTransform1)
965
+ .transform(myTransform2)
966
+ ).toMatchTypeOf<OperatorNode<'-', 'subtract', MathNode[]>>()
967
+
968
+ assert.deepStrictEqual(
969
+ math
970
+ .parse('sqrt(3^2 + 4^2)')
971
+ .transform(myTransform1)
972
+ .transform(myTransform2)
973
+ .toString(),
974
+ 'sqrt(3 ^ 2 + 4 ^ 2) + 1 - 5'
975
+ )
976
+ }
977
+ }
978
+
321
979
  /*
322
980
  Matrices examples
323
981
  */
@@ -427,6 +1085,62 @@ Matrices examples
427
1085
  {
428
1086
  assert.strictEqual(math.matrix([1, 2, 3]) instanceof math.Matrix, true)
429
1087
  }
1088
+
1089
+ // Fourier transform and inverse
1090
+ {
1091
+ assert.ok(
1092
+ math.deepEqual(
1093
+ math.fft([
1094
+ [1, 0],
1095
+ [1, 0],
1096
+ ]),
1097
+ [
1098
+ [math.complex(2, 0), math.complex(2, 0)],
1099
+ [math.complex(0, 0), math.complex(0, 0)],
1100
+ ]
1101
+ )
1102
+ )
1103
+ assert.ok(
1104
+ math.deepEqual(
1105
+ math.fft(
1106
+ math.matrix([
1107
+ [1, 0],
1108
+ [1, 0],
1109
+ ])
1110
+ ),
1111
+ math.matrix([
1112
+ [math.complex(2, 0), math.complex(2, 0)],
1113
+ [math.complex(0, 0), math.complex(0, 0)],
1114
+ ])
1115
+ )
1116
+ )
1117
+ assert.ok(
1118
+ math.deepEqual(
1119
+ math.ifft([
1120
+ [2, 2],
1121
+ [0, 0],
1122
+ ]),
1123
+ [
1124
+ [math.complex(1, 0), math.complex(0, 0)],
1125
+ [math.complex(1, 0), math.complex(0, 0)],
1126
+ ]
1127
+ )
1128
+ )
1129
+ assert.ok(
1130
+ math.deepEqual(
1131
+ math.ifft(
1132
+ math.matrix([
1133
+ [2, 2],
1134
+ [0, 0],
1135
+ ])
1136
+ ),
1137
+ math.matrix([
1138
+ [math.complex(1, 0), math.complex(0, 0)],
1139
+ [math.complex(1, 0), math.complex(0, 0)],
1140
+ ])
1141
+ )
1142
+ )
1143
+ }
430
1144
  }
431
1145
 
432
1146
  /*
@@ -863,6 +1577,45 @@ Function round examples
863
1577
  assert.throws(() => math.round([3.21, 3.82], [1, 2]), TypeError)
864
1578
  }
865
1579
 
1580
+ /*
1581
+ Clone examples
1582
+ */
1583
+ {
1584
+ const math = create(all, {})
1585
+ expectTypeOf(
1586
+ new math.OperatorNode('/', 'divide', [
1587
+ new math.ConstantNode(3),
1588
+ new math.SymbolNode('x'),
1589
+ ])
1590
+ ).toMatchTypeOf<OperatorNode<'/', 'divide', (ConstantNode | SymbolNode)[]>>()
1591
+
1592
+ expectTypeOf(new math.ConstantNode(1).clone()).toMatchTypeOf<ConstantNode>()
1593
+ expectTypeOf(
1594
+ new math.OperatorNode('*', 'multiply', [
1595
+ new math.ConstantNode(3),
1596
+ new math.SymbolNode('x'),
1597
+ ]).clone()
1598
+ ).toMatchTypeOf<
1599
+ OperatorNode<'*', 'multiply', (ConstantNode | SymbolNode)[]>
1600
+ >()
1601
+
1602
+ expectTypeOf(
1603
+ new math.ConstantNode(1).cloneDeep()
1604
+ ).toMatchTypeOf<ConstantNode>()
1605
+ expectTypeOf(
1606
+ new math.OperatorNode('+', 'unaryPlus', [
1607
+ new math.ConstantNode(3),
1608
+ new math.SymbolNode('x'),
1609
+ ]).cloneDeep()
1610
+ ).toMatchTypeOf<
1611
+ OperatorNode<'+', 'unaryPlus', (ConstantNode | SymbolNode)[]>
1612
+ >()
1613
+
1614
+ expectTypeOf(
1615
+ math.clone(new math.ConstantNode(1))
1616
+ ).toMatchTypeOf<ConstantNode>()
1617
+ }
1618
+
866
1619
  /*
867
1620
  JSON serialization/deserialization
868
1621
  */
@@ -1213,7 +1966,9 @@ Factory Test
1213
1966
  expectTypeOf(x).toMatchTypeOf<math.ObjectNode>()
1214
1967
  }
1215
1968
  if (math.isOperatorNode(x)) {
1216
- expectTypeOf(x).toMatchTypeOf<math.OperatorNode>()
1969
+ expectTypeOf(x).toMatchTypeOf<
1970
+ OperatorNode<OperatorNodeOp, OperatorNodeFn, MathNode[]>
1971
+ >()
1217
1972
  }
1218
1973
  if (math.isParenthesisNode(x)) {
1219
1974
  expectTypeOf(x).toMatchTypeOf<math.ParenthesisNode>()
@@ -1225,7 +1980,8 @@ Factory Test
1225
1980
  expectTypeOf(x).toMatchTypeOf<math.SymbolNode>()
1226
1981
  }
1227
1982
  if (math.isChain(x)) {
1228
- expectTypeOf(x).toMatchTypeOf<math.MathJsChain>()
1983
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1984
+ expectTypeOf(x).toMatchTypeOf<math.MathJsChain<any>>()
1229
1985
  }
1230
1986
  }
1231
1987