Comparing version 1.1.9 to 1.1.10
@@ -219,2 +219,3 @@ /** | ||
readonly getItems: typeof MultiArray.getItems; | ||
readonly setItems: typeof MultiArray.setItems; | ||
readonly expandRange: typeof MultiArray.expandRange; | ||
@@ -225,2 +226,3 @@ readonly firstRow: typeof MultiArray.firstRow; | ||
readonly linearize: typeof MultiArray.linearize; | ||
readonly toTensor: typeof MultiArray.number2matrix1x1; | ||
private readonly unparseMLFunctions; | ||
@@ -388,3 +390,3 @@ /** | ||
/** | ||
* Unparse recursively expression tree. | ||
* Unparse recursively expression tree generating MathML representation. | ||
* @param tree Expression tree. | ||
@@ -391,0 +393,0 @@ * @returns String of expression tree unparsed as MathML language. |
@@ -114,3 +114,3 @@ import { ComplexDecimal } from './complex-decimal'; | ||
*/ | ||
static linearize(M: MultiArray): ComplexDecimal[]; | ||
static linearize(M: MultiArray | ComplexDecimal): ComplexDecimal[]; | ||
/** | ||
@@ -127,3 +127,3 @@ * Null matrix (0x0 matrix). | ||
*/ | ||
private static arrayEqual; | ||
static arrayEqual(left: number[], right: number[]): boolean; | ||
/** | ||
@@ -134,3 +134,3 @@ * Convert a ComplexDecimal to 1x1 MultiArray. | ||
*/ | ||
static number2matrix1x1(value: ComplexDecimal | MultiArray): MultiArray | undefined; | ||
static number2matrix1x1(value: ComplexDecimal | MultiArray): MultiArray; | ||
/** | ||
@@ -157,7 +157,25 @@ * Copy of MultiArray. | ||
static map(M: MultiArray, f: Function): MultiArray; | ||
/** | ||
* Expand Matrix dimensions if dimensions in `dim` is greater than dimensions of `M`. | ||
* If a dimension of `M` is greater than corresponding dimension in `dim` it's unchanged. | ||
* The matrix is filled with zeros. | ||
* @param M Matrix. | ||
* @param dim New dimensions. | ||
* @returns Matrix `M` with dimensions expanded. | ||
*/ | ||
static expand(M: MultiArray, dim: number[]): MultiArray; | ||
/** | ||
* Expand range | ||
* @param startNode | ||
* @param stopNode | ||
* @param strideNode | ||
* @returns | ||
*/ | ||
static expandRange(startNode: ComplexDecimal, stopNode: ComplexDecimal, strideNode?: ComplexDecimal | null): MultiArray; | ||
static testIndex(k: ComplexDecimal, bound: number, matrix: MultiArray, input: string): number; | ||
static testIndex(k: ComplexDecimal, input?: string): number; | ||
static testIndexBound(k: ComplexDecimal, bound: number, dim: number[], input?: string): number; | ||
static testDimension(leftDim: number[], rightDim: number[]): boolean; | ||
static firstNonSingleDimmension(M: MultiArray): number; | ||
static oneRowToDim(M: ComplexDecimal[] | MultiArray): number[]; | ||
static setItems(M: MultiArray, id: string, indexList: Array<ComplexDecimal | MultiArray>, value: MultiArray | ComplexDecimal): MultiArray | ComplexDecimal; | ||
static setItems(nameTable: any, id: string, args: any, right: MultiArray): void; | ||
/** | ||
@@ -164,0 +182,0 @@ * Get selected items from MultiArray by linear index or subscripts. |
{ | ||
"name": "mathjslab", | ||
"version": "1.1.9", | ||
"version": "1.1.10", | ||
"description": "MathJSLab - An interpreter with language syntax like MATLAB®/Octave. ISBN 978-65-00-82338-7", | ||
@@ -5,0 +5,0 @@ "main": "lib/mathjslab.js", |
@@ -48,5 +48,3 @@ import { ComplexDecimal } from './complex-decimal'; | ||
for (let n = 0; n < 1000; n++) { | ||
const value = ComplexDecimal.abs( | ||
ComplexDecimal.sin(ComplexDecimal.add(ComplexDecimal.mul(new ComplexDecimal(n), ComplexDecimal.pi()), ComplexDecimal.pidiv2())), | ||
); | ||
const value = ComplexDecimal.abs(ComplexDecimal.sin(ComplexDecimal.add(ComplexDecimal.mul(new ComplexDecimal(n), ComplexDecimal.pi()), ComplexDecimal.pidiv2()))); | ||
result &&= Boolean(ComplexDecimal.eq(value, ComplexDecimal.one()).re.toNumber()); // using ComplexDecimal.eq to comparison. | ||
@@ -53,0 +51,0 @@ } |
@@ -325,6 +325,3 @@ import { Decimal } from 'decimal.js'; | ||
} else if (!value_prec.im.eq(0)) { | ||
return ( | ||
(!value_prec.im.eq(1) ? (!value_prec.im.eq(-1) ? ComplexDecimal.unparseDecimalML(value_prec.im) : '<mo>-</mo>') : '') + | ||
'<mi>i</mi>' | ||
); | ||
return (!value_prec.im.eq(1) ? (!value_prec.im.eq(-1) ? ComplexDecimal.unparseDecimalML(value_prec.im) : '<mo>-</mo>') : '') + '<mi>i</mi>'; | ||
} else { | ||
@@ -432,5 +429,3 @@ return '<mn>0</mn>'; | ||
if (left_abs.eq(right_abs)) { | ||
return ComplexDecimal.toMaxPrecisionDecimal(ComplexDecimal.arg(left).re)[cmp]( | ||
ComplexDecimal.toMaxPrecisionDecimal(ComplexDecimal.arg(right).re), | ||
) | ||
return ComplexDecimal.toMaxPrecisionDecimal(ComplexDecimal.arg(left).re)[cmp](ComplexDecimal.toMaxPrecisionDecimal(ComplexDecimal.arg(right).re)) | ||
? ComplexDecimal.true() | ||
@@ -459,6 +454,3 @@ : ComplexDecimal.false(); | ||
public static minMaxArrayReal(cmp: 'lt' | 'gt', ...args: ComplexDecimal[]): ComplexDecimal { | ||
return args.reduce( | ||
(previous: ComplexDecimal, current: ComplexDecimal): ComplexDecimal => (previous.re[cmp](current.re) ? previous : current), | ||
args[0], | ||
); | ||
return args.reduce((previous: ComplexDecimal, current: ComplexDecimal): ComplexDecimal => (previous.re[cmp](current.re) ? previous : current), args[0]); | ||
} | ||
@@ -606,5 +598,3 @@ | ||
const right_prec = ComplexDecimal.toMaxPrecision(right); | ||
return (left_prec.re.eq(0) && left_prec.im.eq(0)) || (right_prec.re.eq(0) && right_prec.im.eq(0)) | ||
? ComplexDecimal.false() | ||
: ComplexDecimal.true(); | ||
return (left_prec.re.eq(0) && left_prec.im.eq(0)) || (right_prec.re.eq(0) && right_prec.im.eq(0)) ? ComplexDecimal.false() : ComplexDecimal.true(); | ||
} | ||
@@ -621,5 +611,3 @@ | ||
const right_prec = ComplexDecimal.toMaxPrecision(right); | ||
return left_prec.re.eq(0) && left_prec.im.eq(0) && right_prec.re.eq(0) && right_prec.im.eq(0) | ||
? ComplexDecimal.false() | ||
: ComplexDecimal.true(); | ||
return left_prec.re.eq(0) && left_prec.im.eq(0) && right_prec.re.eq(0) && right_prec.im.eq(0) ? ComplexDecimal.false() : ComplexDecimal.true(); | ||
} | ||
@@ -929,5 +917,3 @@ | ||
public static abs(z: ComplexDecimal): ComplexDecimal { | ||
return z.im.eq(0) | ||
? new ComplexDecimal(Decimal.abs(z.re)) | ||
: new ComplexDecimal(Decimal.sqrt(Decimal.add(Decimal.mul(z.re, z.re), Decimal.mul(z.im, z.im)))); | ||
return z.im.eq(0) ? new ComplexDecimal(Decimal.abs(z.re)) : new ComplexDecimal(Decimal.sqrt(Decimal.add(Decimal.mul(z.re, z.re), Decimal.mul(z.im, z.im)))); | ||
} | ||
@@ -1069,6 +1055,3 @@ | ||
const arg_z = Decimal.atan2(z.im.eq(0) ? 0 : z.im, z.re); | ||
return new ComplexDecimal( | ||
Decimal.mul(Decimal.sqrt(mod_z), Decimal.cos(Decimal.div(arg_z, 2))), | ||
Decimal.mul(Decimal.sqrt(mod_z), Decimal.sin(Decimal.div(arg_z, 2))), | ||
); | ||
return new ComplexDecimal(Decimal.mul(Decimal.sqrt(mod_z), Decimal.cos(Decimal.div(arg_z, 2))), Decimal.mul(Decimal.sqrt(mod_z), Decimal.sin(Decimal.div(arg_z, 2)))); | ||
} | ||
@@ -1092,6 +1075,3 @@ | ||
public static log(z: ComplexDecimal): ComplexDecimal { | ||
return new ComplexDecimal( | ||
Decimal.ln(Decimal.sqrt(Decimal.add(Decimal.mul(z.re, z.re), Decimal.mul(z.im, z.im)))), | ||
Decimal.atan2(z.im.eq(0) ? 0 : z.im, z.re), | ||
); | ||
return new ComplexDecimal(Decimal.ln(Decimal.sqrt(Decimal.add(Decimal.mul(z.re, z.re), Decimal.mul(z.im, z.im)))), Decimal.atan2(z.im.eq(0) ? 0 : z.im, z.re)); | ||
} | ||
@@ -1444,5 +1424,3 @@ | ||
public static asinh(z: ComplexDecimal): ComplexDecimal { | ||
return ComplexDecimal.log( | ||
ComplexDecimal.add(ComplexDecimal.sqrt(ComplexDecimal.add(ComplexDecimal.one(), ComplexDecimal.power(z, ComplexDecimal.two()))), z), | ||
); | ||
return ComplexDecimal.log(ComplexDecimal.add(ComplexDecimal.sqrt(ComplexDecimal.add(ComplexDecimal.one(), ComplexDecimal.power(z, ComplexDecimal.two()))), z)); | ||
} | ||
@@ -1456,5 +1434,3 @@ | ||
public static acosh(z: ComplexDecimal): ComplexDecimal { | ||
return ComplexDecimal.log( | ||
ComplexDecimal.add(ComplexDecimal.sqrt(ComplexDecimal.add(ComplexDecimal.minusone(), ComplexDecimal.power(z, ComplexDecimal.two()))), z), | ||
); | ||
return ComplexDecimal.log(ComplexDecimal.add(ComplexDecimal.sqrt(ComplexDecimal.add(ComplexDecimal.minusone(), ComplexDecimal.power(z, ComplexDecimal.two()))), z)); | ||
} | ||
@@ -1531,6 +1507,3 @@ | ||
ComplexDecimal.pi(), | ||
ComplexDecimal.mul( | ||
ComplexDecimal.sin(ComplexDecimal.mul(ComplexDecimal.pi(), z)), | ||
ComplexDecimal.gamma(ComplexDecimal.sub(ComplexDecimal.one(), z)), | ||
), | ||
ComplexDecimal.mul(ComplexDecimal.sin(ComplexDecimal.mul(ComplexDecimal.pi(), z)), ComplexDecimal.gamma(ComplexDecimal.sub(ComplexDecimal.one(), z))), | ||
); | ||
@@ -1537,0 +1510,0 @@ } else { |
@@ -343,2 +343,3 @@ /** | ||
public readonly getItems = MultiArray.getItems; | ||
public readonly setItems = MultiArray.setItems; | ||
public readonly expandRange = MultiArray.expandRange; | ||
@@ -350,2 +351,3 @@ public readonly firstRow = MultiArray.firstRow; | ||
public readonly linearize = MultiArray.linearize; | ||
public readonly toTensor = MultiArray.number2matrix1x1; | ||
@@ -358,4 +360,3 @@ private readonly unparseMLFunctions: Record<string, (tree: any) => string> = { | ||
exp: (tree: any) => '<msup><mi>e</mi><mrow>' + this.unparserML(tree.args[0]) + '</mrow></msup>', | ||
logb: (tree: any) => | ||
'<msub><mi>log</mi><mrow>' + this.unparserML(tree.args[0]) + '</mrow></msub><mrow>' + this.unparserML(tree.args[1]) + '</mrow>', | ||
logb: (tree: any) => '<msub><mi>log</mi><mrow>' + this.unparserML(tree.args[0]) + '</mrow></msub><mrow>' + this.unparserML(tree.args[1]) + '</mrow>', | ||
log2: (tree: any) => '<msub><mi>log</mi><mrow>' + '<mn>2</mn>' + '</mrow></msub><mrow>' + this.unparserML(tree.args[0]) + '</mrow>', | ||
@@ -936,2 +937,13 @@ log10: (tree: any) => '<msub><mi>log</mi><mrow>' + '<mn>10</mn>' + '</mrow></msub><mrow>' + this.unparserML(tree.args[0]) + '</mrow>', | ||
if (this.nameTable[id]) { | ||
/* Matrix indexing refer at left hand side with operator */ | ||
const right = this.toTensor( | ||
this.Evaluator( | ||
this.nodeOp(op, this.getItems(this.nameTable[id].expr, id, args), this.toTensor(this.Evaluator(tree.right, false, fname))), | ||
false, | ||
fname, | ||
), | ||
); | ||
args = args.map((arg: any) => this.linearize(this.Evaluator(arg, false, fname))); | ||
this.setItems(this.nameTable, id, args, right); | ||
return this.nodeOp('=', this.nodeName(id), this.nameTable[id].expr); | ||
} else { | ||
@@ -941,3 +953,3 @@ throw new Error(`in computed assignment ${id}(index) OP= X, ${id} must be defined first.`); | ||
} else { | ||
/* Test function definition. Is a function definition if args is a list of undefined NAME */ | ||
/* Test if is a function definition (test if args is a list of undefined NAME) */ | ||
let isFunction: boolean = true; | ||
@@ -955,19 +967,12 @@ for (let i = 0; i < args.length; i++) { | ||
this.nameTable[id] = { args: args, expr: tree.right }; | ||
return tree; | ||
} else { | ||
console.log('Matrix indexing refer at left hand side'); | ||
console.log('left:', left); | ||
console.log('id:', id); | ||
console.log('aliasTreeName:', aliasTreeName); | ||
console.log('args:', args); | ||
if (this.nameTable[id]) { | ||
console.log('this.nameTable[id] defined'); | ||
console.log(this.nameTable[id]); | ||
} else { | ||
console.log('this.nameTable[id] undefined'); | ||
} | ||
/* Matrix indexing refer at left hand side */ | ||
const right = this.toTensor(this.Evaluator(tree.right, false, fname)); | ||
args = args.map((arg: any) => this.linearize(this.Evaluator(arg, false, fname))); | ||
this.setItems(this.nameTable, id, args, right); | ||
return this.nodeOp('=', this.nodeName(id), this.nameTable[id].expr); | ||
} | ||
return tree; | ||
} | ||
} | ||
break; | ||
case 'NAME': | ||
@@ -988,3 +993,3 @@ if (local && this.localTable[fname] && this.localTable[fname][tree.id]) { | ||
case 'ARG': | ||
const argumentsList: any[] = []; | ||
let argumentsList: any[] = []; | ||
if (typeof tree.expr === 'undefined') { | ||
@@ -1000,6 +1005,3 @@ throw new Error(`'${tree.id}' undefined.`); | ||
/* arguments evaluated */ | ||
for (let i = 0; i < tree.args.length; i++) { | ||
/* Evaluate arguments list */ | ||
argumentsList[i] = this.Evaluator(tree.args[i], local, fname); | ||
} | ||
argumentsList = tree.args.map((arg: any) => this.Evaluator(arg, local, fname)); | ||
if (this.baseFunctionTable[aliasTreeName].mapper && argumentsList.length !== 1) { | ||
@@ -1017,8 +1019,3 @@ /* Error if mapper and #arguments!==1 (Invalid call) */ | ||
/* arguments selectively evaluated */ | ||
for (let i = 0; i < tree.args.length; i++) { | ||
/* Evaluate arguments list selectively */ | ||
argumentsList[i] = (this.baseFunctionTable[aliasTreeName] as any).ev[i] | ||
? this.Evaluator(tree.args[i], local, fname) | ||
: tree.args[i]; | ||
} | ||
argumentsList = tree.args.map((arg: any, i: number) => (this.baseFunctionTable[aliasTreeName].ev[i] ? this.Evaluator(arg, local, fname) : arg)); | ||
return this.baseFunctionTable[aliasTreeName].func(...argumentsList); | ||
@@ -1039,6 +1036,3 @@ } | ||
/* Defined matrix indexing */ | ||
for (let i = 0; i < tree.args.length; i++) { | ||
/* Evaluate index list */ | ||
argumentsList[i] = this.Evaluator(tree.args[i], local, fname); | ||
} | ||
argumentsList = tree.args.map((arg: any) => this.Evaluator(arg, local, fname)); | ||
return this.getItems(temp, tree.expr.id, argumentsList); | ||
@@ -1057,7 +1051,3 @@ } else { | ||
/* Evaluate defined function arguments list */ | ||
this.localTable[tree.expr.id][this.nameTable[tree.expr.id].args[i].id] = this.Evaluator( | ||
tree.args[i], | ||
true, | ||
fname, | ||
); | ||
this.localTable[tree.expr.id][this.nameTable[tree.expr.id].args[i].id] = this.Evaluator(tree.args[i], true, fname); | ||
} | ||
@@ -1074,6 +1064,3 @@ const temp = this.Evaluator(this.nameTable[tree.expr.id].expr, true, tree.expr.id); | ||
/* literal indexing, ex: [1,2;3,4](1,2) */ | ||
for (let i = 0; i < tree.args.length; i++) { | ||
/* Evaluate index list */ | ||
argumentsList[i] = this.Evaluator(tree.args[i], local, fname); | ||
} | ||
argumentsList = tree.args.map((arg: any) => this.Evaluator(arg, local, fname)); | ||
return this.getItems(tree.expr, this.Unparse(tree.expr), argumentsList); | ||
@@ -1232,3 +1219,3 @@ } | ||
/** | ||
* Unparse recursively expression tree. | ||
* Unparse recursively expression tree generating MathML representation. | ||
* @param tree Expression tree. | ||
@@ -1235,0 +1222,0 @@ * @returns String of expression tree unparsed as MathML language. |
@@ -89,11 +89,5 @@ /** | ||
for (let i = 0; i < greekLetters.length; i++) { | ||
regex = new RegExp( | ||
'([^a-zA-Z0-9])([' + greekLetters[i][0] + greekLetters[i][0].toUpperCase() + ']' + greekLetters[i].substring(1) + ')(?![a-zA-Z0-9;])', | ||
'g', | ||
); | ||
regex = new RegExp('([^a-zA-Z0-9])([' + greekLetters[i][0] + greekLetters[i][0].toUpperCase() + ']' + greekLetters[i].substring(1) + ')(?![a-zA-Z0-9;])', 'g'); | ||
id = id.replace(regex, '$1&$2;'); | ||
regex = new RegExp( | ||
'^([' + greekLetters[i][0] + greekLetters[i][0].toUpperCase() + ']' + greekLetters[i].substring(1) + ')(?![a-zA-Z0-9;])', | ||
'g', | ||
); | ||
regex = new RegExp('^([' + greekLetters[i][0] + greekLetters[i][0].toUpperCase() + ']' + greekLetters[i].substring(1) + ')(?![a-zA-Z0-9;])', 'g'); | ||
id = id.replace(regex, '&$1;'); | ||
@@ -100,0 +94,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
442382
6730