Skip to content

Commit

Permalink
Merge branch 'develop' into v12
Browse files Browse the repository at this point in the history
# Conflicts:
#	HISTORY.md
  • Loading branch information
josdejong committed Oct 26, 2023
2 parents fba5baf + 42f4240 commit 3030c6b
Show file tree
Hide file tree
Showing 34 changed files with 956 additions and 678 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,7 @@ BuildTools <anikpatel1322@gmail.com>
Anik Patel <74193405+Bobingstern@users.noreply.github.com>
Vrushaket Chaudhari <82214275+vrushaket@users.noreply.github.com>
Praise Nnamonu <110940850+praisennamonu1@users.noreply.github.com>
Vincent Tam <VincentTam@users.noreply.github.com>
Juan Pablo Alvarado <63080419+juancodeaudio@users.noreply.github.com>

# Generated by tools/update-authors.js
12 changes: 12 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# History


# not yet published, 12.0.0

Breaking changes:
Expand Down Expand Up @@ -31,6 +32,17 @@ Fixes:
- Find eigenvectors of defective matrices (#3037). Thanks @gwhitney.


# 2023-10-25, 11.12.0

- Implemented function `subtractScalar` (#3081, #2643), thanks @vrushaket.
- Fix #3073: function format not escaping control characters and double
quotes (#3082).
- Fix: function `clone` not throwing an error when passing an unsupported
type like a function.
- Fix: #2960 add type definition of function `symbolicEqual` (#3035),
thanks @juancodeaudio.


# 2023-10-11, 11.11.2

- Fix #3025: improve handling of matrices and error handling
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/custom_evaluate_using_import.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const divide = (a, b) => a / b

// create a mathjs instance with hardly any functions
// there are some functions created which are used internally by evaluate though,
// for example by the Unit class which has dependencies on addScalar, subtract,
// for example by the Unit class which has dependencies on addScalar, subtractScalar,
// multiplyScalar, etc.
const math = create(evaluateDependencies)

Expand Down
2 changes: 1 addition & 1 deletion examples/matrices.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ console.log()
// this will mutate the matrix
console.log('set and get a value')
const p = math.matrix([[1, 2], [3, 4]])
p.set([0, 10], 5)
p.set([0, 1], 5)
print(p) // [[1, 5], [3, 4]]
const p21 = p.get([1, 0])
print(p21) // 3
Expand Down
988 changes: 513 additions & 475 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mathjs",
"version": "11.11.2",
"version": "11.12.0",
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
"homepage": "https://mathjs.org",
Expand All @@ -25,7 +25,7 @@
"unit"
],
"dependencies": {
"@babel/runtime": "^7.23.1",
"@babel/runtime": "^7.23.2",
"complex.js": "^2.1.1",
"decimal.js": "^10.4.3",
"escape-latex": "^1.2.0",
Expand All @@ -36,27 +36,27 @@
"typed-function": "^4.1.1"
},
"devDependencies": {
"@babel/core": "7.23.0",
"@babel/core": "7.23.2",
"@babel/plugin-transform-object-assign": "7.22.5",
"@babel/plugin-transform-runtime": "7.22.15",
"@babel/preset-env": "7.22.20",
"@babel/plugin-transform-runtime": "7.23.2",
"@babel/preset-env": "7.23.2",
"@babel/register": "7.22.15",
"@types/assert": "1.5.7",
"@types/mocha": "10.0.2",
"@typescript-eslint/eslint-plugin": "6.7.5",
"@typescript-eslint/parser": "6.7.5",
"@types/assert": "1.5.8",
"@types/mocha": "10.0.3",
"@typescript-eslint/eslint-plugin": "6.9.0",
"@typescript-eslint/parser": "6.9.0",
"assert": "2.1.0",
"babel-loader": "9.1.3",
"benchmark": "2.1.4",
"c8": "8.0.1",
"codecov": "3.8.3",
"core-js": "3.33.0",
"core-js": "3.33.1",
"del": "6.1.1",
"dtslint": "4.2.1",
"eslint": "8.51.0",
"eslint": "8.52.0",
"eslint-config-prettier": "9.0.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "2.28.1",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-mocha": "10.2.0",
"eslint-plugin-n": "16.2.0",
"eslint-plugin-prettier": "5.0.1",
Expand Down Expand Up @@ -90,7 +90,7 @@
"sylvester": "0.0.21",
"ts-node": "10.9.1",
"typescript": "5.2.2",
"webpack": "5.88.2",
"webpack": "5.89.0",
"zeros": "1.0.0"
},
"type": "module",
Expand Down
125 changes: 49 additions & 76 deletions src/expression/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
'Infinity'
]

const ESCAPE_CHARACTERS = {
'"': '"',
"'": "'",
'\\': '\\',
'/': '/',
b: '\b',
f: '\f',
n: '\n',
r: '\r',
t: '\t'
// note that \u is handled separately in parseStringToken()
}

function initialState () {
return {
extraNodes: {}, // current extra nodes, must be careful not to mutate
Expand Down Expand Up @@ -1339,7 +1352,7 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
return node
}

return parseDoubleQuotesString(state)
return parseString(state)
}

/**
Expand Down Expand Up @@ -1436,15 +1449,15 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
}

/**
* Parse a double quotes string.
* Parse a single or double quoted string.
* @return {Node} node
* @private
*/
function parseDoubleQuotesString (state) {
function parseString (state) {
let node, str

if (state.token === '"') {
str = parseDoubleQuotesStringToken(state)
if (state.token === '"' || state.token === "'") {
str = parseStringToken(state, state.token)

// create constant
node = new ConstantNode(str)
Expand All @@ -1455,92 +1468,54 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
return node
}

return parseSingleQuotesString(state)
return parseMatrix(state)
}

/**
* Parse a string surrounded by double quotes "..."
* Parse a string surrounded by single or double quotes
* @param {Object} state
* @param {"'" | "\""} quote
* @return {string}
*/
function parseDoubleQuotesStringToken (state) {
function parseStringToken (state, quote) {
let str = ''

while (currentCharacter(state) !== '' && currentCharacter(state) !== '"') {
while (currentCharacter(state) !== '' && currentCharacter(state) !== quote) {
if (currentCharacter(state) === '\\') {
// escape character, immediately process the next
// character to prevent stopping at a next '\"'
const cNext = nextCharacter(state)
if (cNext !== "'") {
str += currentCharacter(state)
}
next(state)
}

str += currentCharacter(state)
next(state)
}

getToken(state)
if (state.token !== '"') {
throw createSyntaxError(state, 'End of string " expected')
}
getToken(state)

return JSON.parse('"' + str + '"') // unescape escaped characters
}

/**
* Parse a single quotes string.
* @return {Node} node
* @private
*/
function parseSingleQuotesString (state) {
let node, str

if (state.token === '\'') {
str = parseSingleQuotesStringToken(state)

// create constant
node = new ConstantNode(str)

// parse index parameters
node = parseAccessors(state, node)

return node
}

return parseMatrix(state)
}

/**
* Parse a string surrounded by single quotes '...'
* @return {string}
*/
function parseSingleQuotesStringToken (state) {
let str = ''

while (currentCharacter(state) !== '' && currentCharacter(state) !== '\'') {
if (currentCharacter(state) === '\\') {
// escape character, immediately process the next
// character to prevent stopping at a next '\''
const cNext = nextCharacter(state)
if (cNext !== "'" && cNext !== '"') {
str += currentCharacter(state)
const char = currentCharacter(state)
const escapeChar = ESCAPE_CHARACTERS[char]
if (escapeChar !== undefined) {
// an escaped control character like \" or \n
str += escapeChar
state.index += 1
} else if (char === 'u') {
// escaped unicode character
const unicode = state.expression.slice(state.index + 1, state.index + 5)
if (/^[0-9A-Fa-f]{4}$/.test(unicode)) { // test whether the string holds four hexadecimal values
str += String.fromCharCode(parseInt(unicode, 16))
state.index += 5
} else {
throw createSyntaxError(state, `Invalid unicode character \\u${unicode}`)
}
} else {
throw createSyntaxError(state, `Bad escape character \\${char}`)
}
} else {
// any regular character
str += currentCharacter(state)
next(state)
}

str += currentCharacter(state)
next(state)
}

getToken(state)
if (state.token !== '\'') {
throw createSyntaxError(state, 'End of string \' expected')
if (state.token !== quote) {
throw createSyntaxError(state, `End of string ${quote} expected`)
}
getToken(state)

return JSON.parse('"' + str.replace(/"/g, '\\"') + '"') // unescape escaped characters
return str
}

/**
Expand Down Expand Up @@ -1647,10 +1622,8 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({

if (state.token !== '}') {
// parse key
if (state.token === '"') {
key = parseDoubleQuotesStringToken(state)
} else if (state.token === '\'') {
key = parseSingleQuotesStringToken(state)
if (state.token === '"' || state.token === "'") {
key = parseStringToken(state, state.token)
} else if (state.tokenType === TOKENTYPE.SYMBOL || (state.tokenType === TOKENTYPE.DELIMITER && state.token in NAMED_DELIMITERS)) {
key = state.token
getToken(state)
Expand Down
1 change: 1 addition & 0 deletions src/factoriesAny.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export { createUnaryPlus } from './function/arithmetic/unaryPlus.js'
export { createAbs } from './function/arithmetic/abs.js'
export { createApply } from './function/matrix/apply.js'
export { createAddScalar } from './function/arithmetic/addScalar.js'
export { createSubtractScalar } from './function/arithmetic/subtractScalar.js'
export { createCbrt } from './function/arithmetic/cbrt.js'
export { createCeil } from './function/arithmetic/ceil.js'
export { createCube } from './function/arithmetic/cube.js'
Expand Down
1 change: 1 addition & 0 deletions src/factoriesNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const createUnaryMinus = /* #__PURE__ */ createNumberFactory('unaryMinus'
export const createUnaryPlus = /* #__PURE__ */ createNumberFactory('unaryPlus', unaryPlusNumber)
export const createAbs = /* #__PURE__ */ createNumberFactory('abs', absNumber)
export const createAddScalar = /* #__PURE__ */ createNumberFactory('addScalar', addNumber)
export const createSubtractScalar = /* #__PURE__ */ createNumberFactory('subtractScalar', subtractNumber)
export const createCbrt = /* #__PURE__ */ createNumberFactory('cbrt', cbrtNumber)
export { createCeilNumber as createCeil } from './function/arithmetic/ceil.js'
export const createCube = /* #__PURE__ */ createNumberFactory('cube', cubeNumber)
Expand Down
6 changes: 3 additions & 3 deletions src/function/algebra/decomposition/lup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const dependencies = [
'addScalar',
'divideScalar',
'multiplyScalar',
'subtract',
'subtractScalar',
'larger',
'equalScalar',
'unaryMinus',
Expand All @@ -26,7 +26,7 @@ export const createLup = /* #__PURE__ */ factory(name, dependencies, (
addScalar,
divideScalar,
multiplyScalar,
subtract,
subtractScalar,
larger,
equalScalar,
unaryMinus,
Expand Down Expand Up @@ -119,7 +119,7 @@ export const createLup = /* #__PURE__ */ factory(name, dependencies, (
// s = l[i, k] - data[k, j]
s = addScalar(s, multiplyScalar(data[i][k], data[k][j]))
}
data[i][j] = subtract(data[i][j], s)
data[i][j] = subtractScalar(data[i][j], s)
}
}
// row with larger value in cvector, row >= j
Expand Down
10 changes: 5 additions & 5 deletions src/function/algebra/decomposition/qr.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const dependencies = [
'addScalar',
'divideScalar',
'multiplyScalar',
'subtract',
'subtractScalar',
'complex'
]

Expand All @@ -34,7 +34,7 @@ export const createQr = /* #__PURE__ */ factory(name, dependencies, (
addScalar,
divideScalar,
multiplyScalar,
subtract,
subtractScalar,
complex
}
) => {
Expand Down Expand Up @@ -159,7 +159,7 @@ export const createQr = /* #__PURE__ */ factory(name, dependencies, (

if (!isZero(alpha)) {
// first element in vector u
const u1 = subtract(pivot, alpha)
const u1 = subtractScalar(pivot, alpha)

// w = v * u1 / |u| (only elements k to (rows-1) are used)
w[k] = 1
Expand Down Expand Up @@ -198,7 +198,7 @@ export const createQr = /* #__PURE__ */ factory(name, dependencies, (

for (i = k; i < rows; i++) {
Rdata[i][j] = multiplyScalar(
subtract(Rdata[i][j], multiplyScalar(w[i], s)),
subtractScalar(Rdata[i][j], multiplyScalar(w[i], s)),
conjSgn
)
}
Expand All @@ -223,7 +223,7 @@ export const createQr = /* #__PURE__ */ factory(name, dependencies, (

for (j = k; j < rows; ++j) {
Qdata[i][j] = divideScalar(
subtract(Qdata[i][j], multiplyScalar(s, conj(w[j]))),
subtractScalar(Qdata[i][j], multiplyScalar(s, conj(w[j]))),
conjSgn
)
}
Expand Down

0 comments on commit 3030c6b

Please sign in to comment.