feat:node-modules

This commit is contained in:
houjunxiang
2025-11-24 10:26:18 +08:00
parent 753766893b
commit 8a3e48d856
8825 changed files with 567399 additions and 1 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,70 @@
import { factory } from '../../../utils/factory.js';
var name = 'schur';
var dependencies = ['typed', 'matrix', 'identity', 'multiply', 'qr', 'norm', 'subtract'];
export var createSchur = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
matrix,
identity,
multiply,
qr,
norm,
subtract
} = _ref;
/**
*
* Performs a real Schur decomposition of the real matrix A = UTU' where U is orthogonal
* and T is upper quasi-triangular.
* https://en.wikipedia.org/wiki/Schur_decomposition
*
* Syntax:
*
* math.schur(A)
*
* Examples:
*
* const A = [[1, 0], [-4, 3]]
* math.schur(A) // returns {T: [[3, 4], [0, 1]], R: [[0, 1], [-1, 0]]}
*
* See also:
*
* sylvester, lyap, qr
*
* @param {Array | Matrix} A Matrix A
* @return {{U: Array | Matrix, T: Array | Matrix}} Object containing both matrix U and T of the Schur Decomposition A=UTU'
*/
return typed(name, {
Array: function Array(X) {
var r = _schur(matrix(X));
return {
U: r.U.valueOf(),
T: r.T.valueOf()
};
},
Matrix: function Matrix(X) {
return _schur(X);
}
});
function _schur(X) {
var n = X.size()[0];
var A = X;
var U = identity(n);
var k = 0;
var A0;
do {
A0 = A;
var QR = qr(A);
var Q = QR.Q;
var R = QR.R;
A = multiply(R, Q);
U = multiply(U, Q);
if (k++ > 100) {
break;
}
} while (norm(subtract(A, A0)) > 1e-4);
return {
U,
T: A
};
}
});

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,54 @@
import { factory } from '../../utils/factory.js';
var name = 'leafCount';
var dependencies = ['parse', 'typed'];
export var createLeafCount = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
parse,
typed
} = _ref;
// This does the real work, but we don't have to recurse through
// a typed call if we separate it out
function countLeaves(node) {
var count = 0;
node.forEach(n => {
count += countLeaves(n);
});
return count || 1;
}
/**
* Gives the number of "leaf nodes" in the parse tree of the given expression
* A leaf node is one that has no subexpressions, essentially either a
* symbol or a constant. Note that `5!` has just one leaf, the '5'; the
* unary factorial operator does not add a leaf. On the other hand,
* function symbols do add leaves, so `sin(x)/cos(x)` has four leaves.
*
* The `simplify()` function should generally not increase the `leafCount()`
* of an expression, although currently there is no guarantee that it never
* does so. In many cases, `simplify()` reduces the leaf count.
*
* Syntax:
*
* math.leafCount(expr)
*
* Examples:
*
* math.leafCount('x') // 1
* math.leafCount(math.parse('a*d-b*c')) // 4
* math.leafCount('[a,b;c,d][0,1]') // 6
*
* See also:
*
* simplify
*
* @param {Node|string} expr The expression to count the leaves of
*
* @return {number} The number of leaves of `expr`
*
*/
return typed(name, {
Node: function Node(expr) {
return countLeaves(expr);
}
});
});

52
node_modules/mathjs/lib/esm/function/algebra/lyap.js generated vendored Normal file
View File

@@ -0,0 +1,52 @@
import { factory } from '../../utils/factory.js';
var name = 'lyap';
var dependencies = ['typed', 'matrix', 'sylvester', 'multiply', 'transpose'];
export var createLyap = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
matrix,
sylvester,
multiply,
transpose
} = _ref;
/**
*
* Solves the Continuous-time Lyapunov equation AP+PA'+Q=0 for P, where
* Q is an input matrix. When Q is symmetric, P is also symmetric. Notice
* that different equivalent definitions exist for the Continuous-time
* Lyapunov equation.
* https://en.wikipedia.org/wiki/Lyapunov_equation
*
* Syntax:
*
* math.lyap(A, Q)
*
* Examples:
*
* const A = [[-2, 0], [1, -4]]
* const Q = [[3, 1], [1, 3]]
* const P = math.lyap(A, Q)
*
* See also:
*
* sylvester, schur
*
* @param {Matrix | Array} A Matrix A
* @param {Matrix | Array} Q Matrix Q
* @return {Matrix | Array} Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q
*/
return typed(name, {
'Matrix, Matrix': function Matrix_Matrix(A, Q) {
return sylvester(A, transpose(A), multiply(-1, Q));
},
'Array, Matrix': function Array_Matrix(A, Q) {
return sylvester(matrix(A), transpose(matrix(A)), multiply(-1, Q));
},
'Matrix, Array': function Matrix_Array(A, Q) {
return sylvester(A, transpose(matrix(A)), matrix(multiply(-1, Q)));
},
'Array, Array': function Array_Array(A, Q) {
return sylvester(matrix(A), transpose(matrix(A)), matrix(multiply(-1, Q))).toArray();
}
});
});

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,97 @@
import { createMap } from '../../utils/map.js';
import { isFunctionNode, isNode, isOperatorNode, isParenthesisNode, isSymbolNode } from '../../utils/is.js';
import { factory } from '../../utils/factory.js';
var name = 'resolve';
var dependencies = ['typed', 'parse', 'ConstantNode', 'FunctionNode', 'OperatorNode', 'ParenthesisNode'];
export var createResolve = /* #__PURE__ */factory(name, dependencies, _ref => {
var {
typed,
parse,
ConstantNode,
FunctionNode,
OperatorNode,
ParenthesisNode
} = _ref;
/**
* resolve(expr, scope) replaces variable nodes with their scoped values
*
* Syntax:
*
* math.resolve(expr, scope)
*
* Examples:
*
* math.resolve('x + y', {x:1, y:2}) // Node '1 + 2'
* math.resolve(math.parse('x+y'), {x:1, y:2}) // Node '1 + 2'
* math.simplify('x+y', {x:2, y: math.parse('x+x')}).toString() // "6"
*
* See also:
*
* simplify, evaluate
*
* @param {Node | Node[]} node
* The expression tree (or trees) to be simplified
* @param {Object} scope
* Scope specifying variables to be resolved
* @return {Node | Node[]} Returns `node` with variables recursively substituted.
* @throws {ReferenceError}
* If there is a cyclic dependency among the variables in `scope`,
* resolution is impossible and a ReferenceError is thrown.
*/
function _resolve(node, scope) {
var within = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Set();
// note `within`:
// `within` is not documented, since it is for internal cycle
// detection only
if (!scope) {
return node;
}
if (isSymbolNode(node)) {
if (within.has(node.name)) {
var variables = Array.from(within).join(', ');
throw new ReferenceError("recursive loop of variable definitions among {".concat(variables, "}"));
}
var value = scope.get(node.name);
if (isNode(value)) {
var nextWithin = new Set(within);
nextWithin.add(node.name);
return _resolve(value, scope, nextWithin);
} else if (typeof value === 'number') {
return parse(String(value));
} else if (value !== undefined) {
return new ConstantNode(value);
} else {
return node;
}
} else if (isOperatorNode(node)) {
var args = node.args.map(function (arg) {
return _resolve(arg, scope, within);
});
return new OperatorNode(node.op, node.fn, args, node.implicit);
} else if (isParenthesisNode(node)) {
return new ParenthesisNode(_resolve(node.content, scope, within));
} else if (isFunctionNode(node)) {
var _args = node.args.map(function (arg) {
return _resolve(arg, scope, within);
});
return new FunctionNode(node.name, _args);
}
// Otherwise just recursively resolve any children (might also work
// for some of the above special cases)
return node.map(child => _resolve(child, scope, within));
}
return typed('resolve', {
Node: _resolve,
'Node, Map | null | undefined': _resolve,
'Node, Object': (n, scope) => _resolve(n, createMap(scope)),
// For arrays and matrices, we map `self` rather than `_resolve`
// because resolve is fairly expensive anyway, and this way
// we get nice error messages if one entry in the array has wrong type.
'Array | Matrix': typed.referToSelf(self => A => A.map(n => self(n))),
'Array | Matrix, null | undefined': typed.referToSelf(self => A => A.map(n => self(n))),
'Array, Object': typed.referTo('Array,Map', selfAM => (A, scope) => selfAM(A, createMap(scope))),
'Matrix, Object': typed.referTo('Matrix,Map', selfMM => (A, scope) => selfMM(A, createMap(scope))),
'Array | Matrix, Map': typed.referToSelf(self => (A, scope) => A.map(n => self(n, scope)))
});
});

Some files were not shown because too many files have changed in this diff Show More