-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
index.d.ts
6426 lines (5789 loc) · 229 KB
/
index.d.ts
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
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
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { Decimal } from 'decimal.js'
declare const math: math.MathJsStatic
export as namespace math
export = math
type NoLiteralType<T> = T extends number
? number
: T extends string
? string
: T extends boolean
? boolean
: T
declare namespace math {
type MathNumericType = number | BigNumber | Fraction | Complex
type MathArray = MathNumericType[] | MathNumericType[][]
type MathCollection = MathArray | Matrix
type MathType = MathNumericType | Unit | MathCollection
type MathExpression = string | string[] | MathCollection
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type FactoryFunction<T> = (scope: any) => T
// FactoryFunctionMap can be nested; all nested objects will be flattened
interface FactoryFunctionMap {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: FactoryFunction<any> | FactoryFunctionMap
}
/** Available options for parse */
interface ParseOptions {
/** a set of custom nodes */
nodes?: Record<string, MathNode>
}
/**
* Parse an expression. Returns a node tree, which can be evaluated by
* invoking node.evaluate().
*
* Note the evaluating arbitrary expressions may involve security risks,
* see [https://mathjs.org/docs/expressions/security.html](https://mathjs.org/docs/expressions/security.html) for more information.
*
* Syntax:
*
* math.parse(expr)
* math.parse(expr, options)
* math.parse([expr1, expr2, expr3, ...])
* math.parse([expr1, expr2, expr3, ...], options)
*
* Example:
*
* const node1 = math.parse('sqrt(3^2 + 4^2)')
* node1.compile().evaluate() // 5
*
* let scope = {a:3, b:4}
* const node2 = math.parse('a * b') // 12
* const code2 = node2.compile()
* code2.evaluate(scope) // 12
* scope.a = 5
* code2.evaluate(scope) // 20
*
* const nodes = math.parse(['a = 3', 'b = 4', 'a * b'])
* nodes[2].compile().evaluate() // 12
*
* See also:
*
* evaluate, compile
*/
interface ParseFunction {
/**
* Parse an expression. Returns a node tree, which can be evaluated by
* invoking node.evaluate();
*
* @param expr Expression to be parsed
* @param options Available options
* @returns A node
*/
(expr: MathExpression, options?: ParseOptions): MathNode
/**
* Parse an expression. Returns a node tree, which can be evaluated by
* invoking node.evaluate();
*
* @param exprs Expressions to be parsed
* @param options Available options
* @returns An array of nodes
*/
(exprs: MathExpression[], options?: ParseOptions): MathNode[]
/**
* Checks whether the current character `c` is a valid alpha character:
*
* - A latin letter (upper or lower case) Ascii: a-z, A-Z
* - An underscore Ascii: _
* - A dollar sign Ascii: $
* - A latin letter with accents Unicode: \u00C0 - \u02AF
* - A greek letter Unicode: \u0370 - \u03FF
* - A mathematical alphanumeric symbol Unicode: \u{1D400} - \u{1D7FF} excluding invalid code points
*
* The previous and next characters are needed to determine whether
* this character is part of a unicode surrogate pair.
*
* @param c Current character in the expression
* @param cPrev Previous character
* @param cNext Next character
*/
isAlpha(c: string, cPrev: string, cNext: string): boolean
/**
* Test whether a character is a valid latin, greek, or letter-like character
*
* @param c
*/
isValidLatinOrGreek(c: string): boolean
/**
* Test whether two given 16 bit characters form a surrogate pair of a
* unicode math symbol.
*
* https://unicode-table.com/en/
* https://www.wikiwand.com/en/Mathematical_operators_and_symbols_in_Unicode
*
* Note: In ES6 will be unicode aware:
* https://stackoverflow.com/questions/280712/javascript-unicode-regexes
* https://mathiasbynens.be/notes/es6-unicode-regex
*
* @param high
* @param low
*/
isValidMathSymbol(high: string, low: string): boolean
/**
* Check whether given character c is a white space character: space, tab, or enter
*
* @param c
* @param nestingLevel
*/
isWhitespace(c: string, nestingLevel: number): boolean
/**
* Test whether the character c is a decimal mark (dot).
* This is the case when it's not the start of a delimiter '.*', './', or '.^'
*
* @param c
* @param cNext
*/
isDecimalMark(c: string, cNext: string): boolean
/**
* checks if the given char c is a digit or dot
*
* @param c a string with one character
*/
isDigitDot(c: string): boolean
/**
* checks if the given char c is a digit
*
* @param c a string with one character
*/
isDigit(c: string): boolean
/**
* checks if the given char c is a hex digit
*
* @param c a string with one character
*/
isHexDigit(c: string): boolean
}
interface NodeCtor {
new (): MathNode
}
interface AccessorNode<TObject extends MathNode = MathNode> extends MathNode {
type: 'AccessorNode'
isAccessorNode: true
object: TObject
index: IndexNode
name: string
}
interface AccessorNodeCtor {
new <TObject extends MathNode = MathNode>(
object: TObject,
index: IndexNode
): AccessorNode<TObject>
}
interface ArrayNode<TItems extends MathNode[] = MathNode[]> extends MathNode {
type: 'ArrayNode'
isArrayNode: true
items: TItems
}
interface ArrayNodeCtor {
new <TItems extends MathNode[] = MathNode[]>(
items: MathNode[]
): ArrayNode<TItems>
}
interface AssignmentNode<TValue extends MathNode = MathNode>
extends MathNode {
type: 'AssignmentNode'
isAssignmentNode: true
object: SymbolNode | AccessorNode
index: IndexNode | null
value: TValue
name: string
}
interface AssignmentNodeCtor {
new <TValue extends MathNode = MathNode>(
object: SymbolNode,
value: TValue
): AssignmentNode<TValue>
new <TValue extends MathNode = MathNode>(
object: SymbolNode | AccessorNode,
index: IndexNode,
value: TValue
): AssignmentNode<TValue>
}
interface BlockNode<TNode extends MathNode = MathNode> extends MathNode {
type: 'BlockNode'
isBlockNode: true
blocks: Array<{ node: TNode; visible: boolean }>
}
interface BlockNodeCtor {
new <TNode extends MathNode = MathNode>(
arr: Array<{ node: TNode } | { node: TNode; visible: boolean }>
): BlockNode
}
interface ConditionalNode<
TCond extends MathNode = MathNode,
TTrueNode extends MathNode = MathNode,
TFalseNode extends MathNode = MathNode
> extends MathNode {
type: 'ConditionalNode'
isConditionalNode: boolean
condition: TCond
trueExpr: TTrueNode
falseExpr: TFalseNode
}
interface ConditionalNodeCtor {
new <
TCond extends MathNode = MathNode,
TTrueNode extends MathNode = MathNode,
TFalseNode extends MathNode = MathNode
>(
condition: TCond,
trueExpr: TTrueNode,
falseExpr: TFalseNode
): ConditionalNode
}
interface ConstantNode<TValue extends string | number = number>
extends MathNode {
type: 'ConstantNode'
isConstantNode: true
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: TValue
}
interface ConstantNodeCtor {
new <TValue extends string | number = string>(
value: TValue
): ConstantNode<TValue>
}
interface FunctionAssignmentNode<TExpr extends MathNode = MathNode>
extends MathNode {
type: 'FunctionAssignmentNode'
isFunctionAssignmentNode: true
name: string
params: string[]
expr: TExpr
}
interface FunctionAssignmentNodeCtor {
new <TExpr extends MathNode = MathNode>(
name: string,
params: string[],
expr: TExpr
): FunctionAssignmentNode<TExpr>
}
interface FunctionNode<
TFn = SymbolNode,
TArgs extends MathNode[] = MathNode[]
> extends MathNode {
type: 'FunctionNode'
isFunctionNode: true
fn: TFn
args: TArgs
}
interface FunctionNodeCtor {
new <TFn = SymbolNode, TArgs extends MathNode[] = MathNode[]>(
fn: TFn,
args: TArgs
): FunctionNode<TFn, TArgs>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onUndefinedFunction: (name: string) => any
}
interface IndexNode<TDims extends MathNode[] = MathNode[]> extends MathNode {
type: 'IndexNode'
isIndexNode: true
dimensions: TDims
dotNotation: boolean
}
interface IndexNodeCtor {
new <TDims extends MathNode[] = MathNode[]>(dimensions: TDims): IndexNode
new <TDims extends MathNode[] = MathNode[]>(
dimensions: TDims,
dotNotation: boolean
): IndexNode<TDims>
}
interface ObjectNode<
TProps extends Record<string, MathNode> = Record<string, MathNode>
> extends MathNode {
type: 'ObjectNode'
isObjectNode: true
properties: TProps
}
interface ObjectNodeCtor {
new <TProps extends Record<string, MathNode> = Record<string, MathNode>>(
properties: TProps
): ObjectNode<TProps>
}
type OperatorNodeMap = {
xor: 'xor'
and: 'and'
or: 'or'
bitOr: '|'
bitXor: '^|'
bitAnd: '&'
equal: '=='
unequal: '!='
smaller: '<'
larger: '>'
smallerEq: '<='
largerEq: '>='
leftShift: '<<'
rightArithShift: '>>'
rightLogShift: '>>>'
to: 'to'
add: '+'
subtract: '-'
multiply: '*'
divide: '/'
dotMultiply: '.*'
dotDivide: './'
mod: 'mod'
unaryPlus: '+'
unaryMinus: '-'
bitNot: '~'
not: 'not'
pow: '^'
dotPow: '.^'
factorial: '!'
}
type OperatorNodeOp = OperatorNodeMap[keyof OperatorNodeMap]
type OperatorNodeFn = keyof OperatorNodeMap
interface OperatorNode<
TOp extends OperatorNodeMap[TFn] = never,
TFn extends OperatorNodeFn = never,
TArgs extends MathNode[] = MathNode[]
> extends MathNode {
type: 'OperatorNode'
isOperatorNode: true
op: TOp
fn: TFn
args: TArgs
implicit: boolean
isUnary(): boolean
isBinary(): boolean
}
interface OperatorNodeCtor extends MathNode {
new <
TOp extends OperatorNodeMap[TFn],
TFn extends OperatorNodeFn,
TArgs extends MathNode[]
>(
op: TOp,
fn: TFn,
args: TArgs,
implicit?: boolean
): OperatorNode<TOp, TFn, TArgs>
}
interface ParenthesisNode<TContent extends MathNode = MathNode>
extends MathNode {
type: 'ParenthesisNode'
isParenthesisNode: true
content: TContent
}
interface ParenthesisNodeCtor {
new <TContent extends MathNode>(
content: TContent
): ParenthesisNode<TContent>
}
interface RangeNode<
TStart extends MathNode = MathNode,
TEnd extends MathNode = MathNode,
TStep extends MathNode = MathNode
> extends MathNode {
type: 'RangeNode'
isRangeNode: true
start: TStart
end: TEnd
step: TStep | null
}
interface RangeNodeCtor {
new <
TStart extends MathNode = MathNode,
TEnd extends MathNode = MathNode,
TStep extends MathNode = MathNode
>(
start: TStart,
end: TEnd,
step?: TStep
): RangeNode<TStart, TEnd, TStep>
}
interface RelationalNode<TParams extends MathNode[] = MathNode[]>
extends MathNode {
type: 'RelationalNode'
isRelationalNode: true
conditionals: string[]
params: TParams
}
interface RelationalNodeCtor {
new <TParams extends MathNode[] = MathNode[]>(
conditionals: string[],
params: TParams
): RelationalNode<TParams>
}
interface SymbolNode extends MathNode {
type: 'SymbolNode'
isSymbolNode: true
name: string
}
interface SymbolNodeCtor {
new (name: string): SymbolNode
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onUndefinedSymbol: (name: string) => any
}
/**
* @deprecated since version 11.3. Prefer `MathNode` instead
*/
type MathNodeCommon = MathNode
type MathJsFunctionName = keyof MathJsStatic
interface LUDecomposition {
L: MathCollection
U: MathCollection
p: number[]
}
interface SLUDecomposition extends LUDecomposition {
q: number[]
}
interface QRDecomposition {
Q: MathCollection
R: MathCollection
}
interface SchurDecomposition {
U: MathCollection
T: MathCollection
}
interface FractionDefinition {
a: number
b: number
}
interface MathJsStatic extends FactoryDependencies {
e: number
pi: number
i: number
Infinity: number
LN2: number
LN10: number
LOG2E: number
LOG10E: number
NaN: number
phi: number
SQRT1_2: number
SQRT2: number
tau: number
// Class-like constructors
Node: NodeCtor
AccessorNode: AccessorNodeCtor
ArrayNode: ArrayNodeCtor
AssignmentNode: AssignmentNodeCtor
BlockNode: BlockNodeCtor
ConditionalNode: ConditionalNodeCtor
ConstantNode: ConstantNodeCtor
FunctionAssignmentNode: FunctionAssignmentNodeCtor
FunctionNode: FunctionNodeCtor
IndexNode: IndexNodeCtor
ObjectNode: ObjectNodeCtor
OperatorNode: OperatorNodeCtor
ParenthesisNode: ParenthesisNodeCtor
RangeNode: RangeNodeCtor
RelationalNode: RelationalNodeCtor
SymbolNode: SymbolNodeCtor
Matrix: MatrixCtor
/**
* If null were to be included in this interface, it would be
* auto-suggested as an import in VSCode. This causes issues because
* `null` is not a valid label.
*
* @see https://github.com/josdejong/mathjs/issues/2019
*/
// null: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
uninitialized: any
version: string
expression: MathNode
/**
* Returns reviver function that can be used as reviver in JSON.parse function.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
reviver(): (key: any, value: any) => any
/**
* Returns replacer function that can be used as replacer in JSON.stringify function.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
replacer(): (key: any, value: any) => any
/*************************************************************************
* Core functions
************************************************************************/
/**
* Set configuration options for math.js, and get current options. Will
* emit a ‘config’ event, with arguments (curr, prev, changes).
* @param options Available options: {number} epsilon Minimum relative
* difference between two compared values, used by all comparison
* functions. {string} matrix A string ‘Matrix’ (default) or ‘Array’.
* {string} number A string ‘number’ (default), ‘BigNumber’, or
* ‘Fraction’ {number} precision The number of significant digits for
* BigNumbers. Not applicable for Numbers. {string} parenthesis How to
* display parentheses in LaTeX and string output. {string} randomSeed
* Random seed for seeded pseudo random number generator. Set to null to
* randomly seed.
* @returns Returns the current configuration
*/
config: (options: ConfigOptions) => ConfigOptions
/**
* Create a typed-function which checks the types of the arguments and
* can match them against multiple provided signatures. The
* typed-function automatically converts inputs in order to find a
* matching signature. Typed functions throw informative errors in case
* of wrong input arguments.
* @param name Optional name for the typed-function
* @param signatures Object with one or multiple function signatures
* @returns The created typed-function.
*/
typed: (
name: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
signatures: Record<string, (...args: any[]) => any>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) => (...args: any[]) => any
/*************************************************************************
* Construction functions
************************************************************************/
/**
* Create a BigNumber, which can store numbers with arbitrary precision.
* When a matrix is provided, all elements will be converted to
* BigNumber.
* @param x Value for the big number, 0 by default.
* @returns The created bignumber
*/
bignumber(
x?: number | string | Fraction | BigNumber | boolean | Fraction | null
): BigNumber
bignumber<T extends MathCollection>(x: T): T
/**
* Create a boolean or convert a string or number to a boolean. In case
* of a number, true is returned for non-zero numbers, and false in case
* of zero. Strings can be 'true' or 'false', or can contain a number.
* When value is a matrix, all elements will be converted to boolean.
* @param x A value of any type
* @returns The boolean value
*/
boolean(x: string | number | boolean | null): boolean
boolean(x: MathCollection): MathCollection
/**
* Wrap any value in a chain, allowing to perform chained operations on
* the value. All methods available in the math.js library can be called
* upon the chain, and then will be evaluated with the value itself as
* first argument. The chain can be closed by executing chain.done(),
* which returns the final value. The chain has a number of special
* functions: done() Finalize the chain and return the chain's value.
* valueOf() The same as done() toString() Executes math.format() onto
* the chain's value, returning a string representation of the value.
* @param value A value of any type on which to start a chained
* operation.
* @returns The created chain
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
chain<TValue>(value?: TValue): MathJsChain<TValue>
/**
* Create a complex value or convert a value to a complex value.
* @param args Arguments specifying the real and imaginary part of the
* complex number
* @returns Returns a complex value
*/
complex(arg?: MathNumericType | string | PolarCoordinates): Complex
complex(arg?: MathCollection): MathCollection
/**
* @param re Argument specifying the real part of the complex number
* @param im Argument specifying the imaginary part of the complex
* number
* @returns Returns a complex value
*/
complex(re: number, im: number): Complex
/**
* Create a user-defined unit and register it with the Unit type.
* @param name The name of the new unit. Must be unique. Example: ‘knot’
* @param definition Definition of the unit in terms of existing units.
* For example, ‘0.514444444 m / s’.
* @param options (optional) An object containing any of the following
* properties:</br>- prefixes {string} “none”, “short”, “long”,
* “binary_short”, or “binary_long”. The default is “none”.</br>-
* aliases {Array} Array of strings. Example: [‘knots’, ‘kt’,
* ‘kts’]</br>- offset {Numeric} An offset to apply when converting from
* the unit. For example, the offset for celsius is 273.15. Default is
* 0.
* @returns The new unit
*/
createUnit(
name: string,
definition?: string | UnitDefinition | Unit,
options?: CreateUnitOptions
): Unit
/**
* Create a user-defined unit and register it with the Unit type.
* @param units Definition of the unit
* @param options
* @returns The new unit
*/
createUnit(
units: Record<string, string | UnitDefinition | Unit>,
options?: CreateUnitOptions
): Unit
/**
* Create a fraction convert a value to a fraction.
* @param args Arguments specifying the numerator and denominator of the
* fraction
* @returns Returns a fraction
*/
fraction(
value: number | string | BigNumber | Fraction | FractionDefinition
): Fraction
fraction(values: MathCollection): MathCollection
/**
* @param numerator Argument specifying the numerator of the fraction
* @param denominator Argument specifying the denominator of the
* fraction
* @returns Returns a fraction
*/
fraction(numerator: number, denominator: number): Fraction
/**
* Create an index. An Index can store ranges having start, step, and
* end for multiple dimensions. Matrix.get, Matrix.set, and math.subset
* accept an Index as input.
* @param ranges Zero or more ranges or numbers.
* @returns Returns the created index
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
index(...ranges: any[]): Index
/**
* Create a Matrix. The function creates a new math.type.Matrix object
* from an Array. A Matrix has utility functions to manipulate the data
* in the matrix, like getting the size and getting or setting values in
* the matrix. Supported storage formats are 'dense' and 'sparse'.
* @param format The Matrix storage format
* @returns The created Matrix
*/
matrix(format?: 'sparse' | 'dense'): Matrix
/**
* @param data A multi dimensional array
* @param format The Matrix storage format
* @param dataType The Matrix data type
* @returns The created Matrix
*/
matrix(
data: MathCollection | string[],
format?: 'sparse' | 'dense',
dataType?: string
): Matrix
/**
* Create a number or convert a string, boolean, or unit to a number.
* When value is a matrix, all elements will be converted to number.
* @param value Value to be converted
* @returns The created number
*/
number(
value?: string | number | BigNumber | Fraction | boolean | Unit | null
): number
number(value?: MathCollection): number | MathCollection
/**
* @param value Value to be converted
* @param valuelessUnit A valueless unit, used to convert a unit to a
* number
* @returns The created number
*/
number(unit: Unit, valuelessUnit: Unit | string): number
/**
* Create a Sparse Matrix. The function creates a new math.type.Matrix
* object from an Array. A Matrix has utility functions to manipulate
* the data in the matrix, like getting the size and getting or setting
* values in the matrix.
* @param data A two dimensional array
* @param dataType Sparse Matrix data type
* @returns The created matrix
*/
sparse(data?: MathCollection, dataType?: string): Matrix
/**
* Split a unit in an array of units whose sum is equal to the original
* unit.
* @param unit A unit to be split
* @param parts An array of strings or valueless units
* @returns An array of units
*/
splitUnit(unit: Unit, parts: Unit[]): Unit[]
/**
* Create a string or convert any object into a string. Elements of
* Arrays and Matrices are processed element wise.
* @param value A value to convert to a string
* @returns The created string
*/
string(value: MathNumericType | string | Unit | null): string
string(value: MathCollection): MathCollection
/**
* Create a unit. Depending on the passed arguments, the function will
* create and return a new math.type.Unit object. When a matrix is
* provided, all elements will be converted to units.
* @param unit The unit to be created
* @returns The created unit
*/
unit(unit: string): Unit
/**
* @param unit The unit to be created
* @returns The created unit
*/
unit(unit: Unit): Unit
/**
* @param value The value of the unit to be created
* @param unit The unit to be created
* @returns The created unit
*/
unit(value: MathNumericType, unit: string): Unit
unit(value: MathCollection, unit: string): Unit[]
/*************************************************************************
* Expression functions
************************************************************************/
/**
* Parse and compile an expression. Returns a an object with a function
* evaluate([scope]) to evaluate the compiled expression.
* @param expr The expression to be compiled
* @returns An object with the compiled expression
*/
compile(expr: MathExpression): EvalFunction
/**
* @param exprs The expressions to be compiled
* @returns An array of objects with the compiled expressions
*/
compile(exprs: MathExpression[]): EvalFunction[]
// TODO properly type this
/**
* Evaluate an expression.
* @param expr The expression to be evaluated
* @param scope Scope to read/write variables
* @returns The result of the expression
*/
evaluate(
expr: MathExpression | Matrix,
scope?: object
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): any
evaluate(
expr: MathExpression[],
scope?: object
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): any[]
/**
* Retrieve help on a function or data type. Help files are retrieved
* from the documentation in math.expression.docs.
* @param search A function or function name for which to get help
* @returns A help object
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
help(search: () => any): Help
/**
* Parse an expression. Returns a node tree, which can be evaluated by
* invoking node.evaluate();
*/
parse: ParseFunction
/**
* Create a parser. The function creates a new math.expression.Parser
* object.
* @returns A Parser object
*/
parser(): Parser
/*************************************************************************
* Algebra functions
************************************************************************/
/**
* @param expr The expression to differentiate
* @param variable The variable over which to differentiate
* @param options There is one option available, simplify, which is true
* by default. When false, output will not be simplified.
* @returns The derivative of expr
*/
derivative(
expr: MathNode | string,
variable: MathNode | string,
options?: { simplify: boolean }
): MathNode
/**
* Solves the linear equation system by forwards substitution. Matrix
* must be a lower triangular matrix.
* @param L A N x N matrix or array (L)
* @param b A column vector with the b values
* @returns A column vector with the linear system solution (x)
*/
lsolve(L: Matrix, b: MathCollection): Matrix
lsolve(L: MathArray, b: MathCollection): MathArray
/**
* Calculate the Matrix LU decomposition with partial pivoting. Matrix A
* is decomposed in two matrices (L, U) and a row permutation vector p
* where A[p,:] = L * U
* @param A A two dimensional matrix or array for which to get the LUP
* decomposition.
* @returns The lower triangular matrix, the upper triangular matrix and
* the permutation matrix.
*/
lup(A?: MathCollection): LUDecomposition
/**
* Solves the linear system A * x = b where A is an [n x n] matrix and b
* is a [n] column vector.
* @param A Invertible Matrix or the Matrix LU decomposition
* @param b Column Vector
* @param order The Symbolic Ordering and Analysis order, see slu for
* details. Matrix must be a SparseMatrix
* @param threshold Partial pivoting threshold (1 for partial pivoting),
* see slu for details. Matrix must be a SparseMatrix.
* @returns Column vector with the solution to the linear system A * x =
* b
*/
lusolve(
A: Matrix,
b: MathCollection,
order?: number,
threshold?: number
): Matrix
lusolve(
A: MathArray,
b: MathCollection,
order?: number,
threshold?: number
): MathArray
lusolve(A: LUDecomposition, b: MathCollection): Matrix
/* Finds the roots of a polynomial of degree three or less. Coefficients are given constant first
* followed by linear and higher powers in order; coefficients beyond the degree of the polynomial
* need not be specified.
* @param {number|Complex} constantCoeff
* @param {number|Complex} linearCoeff
* @param {number|Complex} quadraticCoeff
* @param {number|Complex} cubicCoeff
* @returns {Array<number|Complex>} array of roots of specified polynomial
*/
polynomialRoot(
constantCoeff: number | Complex,
linearCoeff: number | Complex,
quadraticCoeff?: number | Complex,
cubicCoeff?: number | Complex
): (number | Complex)[]
/**
* Calculate 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.
* @param A A two dimensional matrix or array for which to get the QR
* decomposition.
* @returns Q: the orthogonal matrix and R: the upper triangular matrix
*/
qr(A: MathCollection): QRDecomposition
rationalize(
expr: MathNode | string,
optional?: object | boolean,
detailed?: false
): MathNode
/**
* 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.
* @param expr The expression to check if is a polynomial expression
* @param optional scope of expression or true for already evaluated
* rational expression at input
* @param detailed optional True if return an object, false if return
* expression node (default)
* @returns The rational polynomial of expr
*/
rationalize(
expr: MathNode | string,
optional?: object | boolean,
detailed?: true
): {
expression: MathNode | string
variables: string[]
coefficients: MathType[]
}
/**
* Simplify an expression tree.
* @param expr The expression to be simplified
* @param [rules] (optional) A list of rules are applied to an expression, repeating
* over the list until no further changes are made. It’s possible to
* pass a custom set of rules to the function as second argument. A rule
* can be specified as an object, string, or function.
* @param [scope] (optional) Scope to variables
* @param [options] (optional) An object with simplify options
* @returns Returns the simplified form of expr
*/
simplify: Simplify
simplifyConstant(
expr: MathNode | string,
options?: SimplifyOptions
): MathNode
simplifyCore(expr: MathNode | string, options?: SimplifyOptions): MathNode
/**
* Replaces variable nodes with their scoped values
* @param node Tree to replace variable nodes in
* @param scope Scope to read/write variables
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
resolve(node: MathNode | string, scope?: Record<string, any>): MathNode
resolve(
node: (MathNode | string)[],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
scope?: Record<string, any>
): MathNode[]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
resolve(node: Matrix, scope?: Record<string, any>): Matrix
/**
* Calculate the Sparse Matrix LU decomposition with full pivoting.
* Sparse Matrix A is decomposed in two matrices (L, U) and two
* permutation vectors (pinv, q) where P * A * Q = L * U
* @param A A two dimensional sparse matrix for which to get the LU
* decomposition.
* @param order The Symbolic Ordering and Analysis order: 0 - Natural
* ordering, no permutation vector q is returned 1 - Matrix must be
* square, symbolic ordering and analisis is performed on M = A + A' 2 -
* Symbolic ordering and analysis is performed on M = A' * A. Dense