Socket
Socket
Sign inDemoInstall

@mathigon/hilbert

Package Overview
Dependencies
2
Maintainers
0
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.16 to 1.1.17

4

dist/expression.d.ts

@@ -10,5 +10,5 @@ import { ExprElement } from './elements';

parse: (str: string, collapse?: boolean | undefined, context?: {
variables?: string[] | undefined;
} | undefined) => ExprElement;
variables?: string[];
} | undefined) => NonNullable<ExprElement>;
};
export {};

@@ -294,4 +294,3 @@ "use strict";

const varList = Object.keys(vars);
if (!this.unknowns.filter((v) => varList.includes(v)).length)
return this;
if (!this.unknowns.filter((v) => varList.includes(v)).length) return this;
return this.substitute(vars).recursiveSubstitute(vars);

@@ -336,12 +335,8 @@ }

let value = (_a = vars[name]) != null ? _a : CONSTANTS[name];
if (value === void 0)
throw ExprError.undefinedVariable(name);
if (value === void 0) throw ExprError.undefinedVariable(name);
if (typeof value === "string" || value instanceof ExprElement) {
if (!nested)
LOOP_DETECTION.clear();
if (LOOP_DETECTION.has(name))
throw ExprError.evalLoop(name);
if (!nested) LOOP_DETECTION.clear();
if (LOOP_DETECTION.has(name)) throw ExprError.evalLoop(name);
LOOP_DETECTION.add(name);
if (typeof value === "string")
value = Expression.parse(value);
if (typeof value === "string") value = Expression.parse(value);
return value.evaluate(vars, true);

@@ -397,6 +392,4 @@ } else if (typeof value === "function") {

toVoice() {
if (this.i in VOICE_STRINGS)
return VOICE_STRINGS[this.i];
if (this.i.length === 1)
return `_${this.i}_`;
if (this.i in VOICE_STRINGS) return VOICE_STRINGS[this.i];
if (this.i.length === 1) return `_${this.i}_`;
return this.i;

@@ -511,4 +504,3 @@ }

if (a[0] > 0) {
if (b[0] >= 0)
return int(a[0] ** b[0], a[1] ** b[1]);
if (b[0] >= 0) return int(a[0] ** b[0], a[1] ** b[1]);
return range(a[0] ** b[0], a[0] ** b[1], a[1] ** b[0], a[1] ** b[1]);

@@ -518,8 +510,5 @@ }

if (Number.isInteger(k) && k === b[1]) {
if (k === 0)
return [hasZero(a) ? 0 : 1, 1];
if (k % 2)
return int(a[0] ** k, a[1] ** k);
if (hasZero(a))
return [0, Math.max(a[0] ** k, a[1] ** k)];
if (k === 0) return [hasZero(a) ? 0 : 1, 1];
if (k % 2) return int(a[0] ** k, a[1] ** k);
if (hasZero(a)) return [0, Math.max(a[0] ** k, a[1] ** k)];
return range(a[1] ** k, a[0] ** k);

@@ -537,4 +526,3 @@ }

mul: (a, ...b) => {
if (b.length > 1)
b = [interval.mul(...b)];
if (b.length > 1) b = [interval.mul(...b)];
return range(a[0] * b[0][0], a[0] * b[0][1], a[1] * b[0][0], a[1] * b[0][1]);

@@ -544,4 +532,3 @@ },

abs: (a) => {
if (hasZero(a))
return int(0, Math.max(-a[0], a[1]));
if (hasZero(a)) return int(0, Math.max(-a[0], a[1]));
return range(Math.abs(a[0]), Math.abs(a[1]));

@@ -555,4 +542,3 @@ },

mod: (a, b) => {
if (isEmpty(a) || isEmpty(b))
return EMPTY;
if (isEmpty(a) || isEmpty(b)) return EMPTY;
let n = a[0] / (a[0] < 0 ? b[0] : b[1]);

@@ -569,4 +555,3 @@ n = n < 0 ? Math.ceil(n) : Math.floor(n);

log: (a, b) => {
if (b !== void 0)
interval.div(interval.log(a), interval.log(b));
if (b !== void 0) interval.div(interval.log(a), interval.log(b));
return int(a[0] <= 0 ? -Infinity : Math.log(a[0]), Math.log(a[1]));

@@ -580,23 +565,15 @@ },

cos: (a) => {
if (isEmpty(a) || isInfinite(a))
return EMPTY;
if (width(a) >= TWO_PI - Number.EPSILON)
return [-1, 1];
if (isEmpty(a) || isInfinite(a)) return EMPTY;
if (width(a) >= TWO_PI - Number.EPSILON) return [-1, 1];
a = intervalMod(a);
if (a[0] > Math.PI + Number.EPSILON)
return interval.sub(interval.cos(interval.sub(a, [Math.PI, Math.PI])));
if (a[1] < Math.PI - Number.EPSILON)
return int(Math.cos(a[1]), Math.cos(a[0]));
if (a[1] < TWO_PI - Number.EPSILON)
return int(-1, Math.max(Math.cos(a[1]), Math.cos(a[0])));
if (a[0] > Math.PI + Number.EPSILON) return interval.sub(interval.cos(interval.sub(a, [Math.PI, Math.PI])));
if (a[1] < Math.PI - Number.EPSILON) return int(Math.cos(a[1]), Math.cos(a[0]));
if (a[1] < TWO_PI - Number.EPSILON) return int(-1, Math.max(Math.cos(a[1]), Math.cos(a[0])));
return int(-1, 1);
},
tan: (a) => {
if (isEmpty(a) || isInfinite(a))
return EMPTY;
if (isEmpty(a) || isInfinite(a)) return EMPTY;
a = intervalMod(a, Math.PI);
if (a[0] > HALF_PI + Number.EPSILON)
a = interval.sub(a, [Math.PI, Math.PI]);
if (a[0] < -HALF_PI + Number.EPSILON || a[1] > HALF_PI - Number.EPSILON)
return WHOLE;
if (a[0] > HALF_PI + Number.EPSILON) a = interval.sub(a, [Math.PI, Math.PI]);
if (a[0] < -HALF_PI + Number.EPSILON || a[1] > HALF_PI - Number.EPSILON) return WHOLE;
return int(Math.tan(a[0]), Math.tan(a[1]));

@@ -610,9 +587,7 @@ },

arcsin: (a) => {
if (isEmpty(a) || a[1] < -1 || a[0] > 1)
return EMPTY;
if (isEmpty(a) || a[1] < -1 || a[0] > 1) return EMPTY;
return int(a[0] <= -1 ? -HALF_PI : Math.asin(a[0]), a[1] >= 1 ? HALF_PI : Math.asin(a[1]));
},
arccos: (a) => {
if (isEmpty(a) || a[1] < -1 || a[0] > 1)
return EMPTY;
if (isEmpty(a) || a[1] < -1 || a[0] > 1) return EMPTY;
return int(a[1] >= 1 ? 0 : Math.acos(a[1]), a[0] <= -1 ? Math.PI : Math.acos(a[0]));

@@ -623,6 +598,4 @@ },

cosh: (a) => {
if (a[1] < 0)
return int(Math.cosh(a[1]), Math.cosh(a[0]));
if (a[0] > 0)
return int(Math.cosh(a[0]), Math.cosh(a[1]));
if (a[1] < 0) return int(Math.cosh(a[1]), Math.cosh(a[0]));
if (a[0] > 0) return int(Math.cosh(a[0]), Math.cosh(a[1]));
return int(1, Math.cosh(Math.max(-a[0], a[1])));

@@ -642,12 +615,7 @@ },

function needsBrackets(expr, parentFn) {
if (!PRECEDENCE.includes(parentFn))
return false;
if (expr instanceof ExprTerm)
return true;
if (!(expr instanceof ExprFunction))
return false;
if (!PRECEDENCE.includes(expr.fn))
return false;
if (SUBSUP.includes(expr.fn) && SUBSUP.includes(parentFn))
return true;
if (!PRECEDENCE.includes(parentFn)) return false;
if (expr instanceof ExprTerm) return true;
if (!(expr instanceof ExprFunction)) return false;
if (!PRECEDENCE.includes(expr.fn)) return false;
if (SUBSUP.includes(expr.fn) && SUBSUP.includes(parentFn)) return true;
return PRECEDENCE.indexOf(parentFn) > PRECEDENCE.indexOf(expr.fn);

@@ -675,22 +643,13 @@ }

const fn = vars[this.fn];
if (typeof fn === "function")
return fn(...args);
if (typeof fn === "number" && args.length === 1)
return evaluate.mul(fn, args[0]);
if (typeof fn === "function") return fn(...args);
if (typeof fn === "number" && args.length === 1) return evaluate.mul(fn, args[0]);
throw ExprError.uncallableExpression(this.fn);
}
if (this.fn === "+")
return evaluate.add(...args);
if (this.fn === "\u2212")
return evaluate.sub(...args);
if (["*", "\xB7", "\xD7"].includes(this.fn))
return evaluate.mul(...args);
if (this.fn === "/")
return evaluate.div(...args);
if (this.fn === "sup")
return evaluate.sup(...args);
if (isSpecialFunction(this.fn))
return evaluate[this.fn](...args);
if (this.fn === "(")
return args[0];
if (this.fn === "+") return evaluate.add(...args);
if (this.fn === "\u2212") return evaluate.sub(...args);
if (["*", "\xB7", "\xD7"].includes(this.fn)) return evaluate.mul(...args);
if (this.fn === "/") return evaluate.div(...args);
if (this.fn === "sup") return evaluate.sup(...args);
if (isSpecialFunction(this.fn)) return evaluate[this.fn](...args);
if (this.fn === "(") return args[0];
throw ExprError.undefinedFunction(this.fn);

@@ -702,24 +661,14 @@ }

const fn = vars[this.fn];
if (typeof fn === "function")
return (0, import_core2.repeat)(fn(...args.map((a) => a[0])), 2);
if (typeof fn === "number" && args.length === 1)
return interval.mul([fn, fn], args[0]);
if (Array.isArray(fn) && args.length === 1)
return interval.mul(fn, args[0]);
if (typeof fn === "function") return (0, import_core2.repeat)(fn(...args.map((a) => a[0])), 2);
if (typeof fn === "number" && args.length === 1) return interval.mul([fn, fn], args[0]);
if (Array.isArray(fn) && args.length === 1) return interval.mul(fn, args[0]);
throw ExprError.uncallableExpression(this.fn);
}
if (this.fn === "+")
return interval.add(...args);
if (this.fn === "\u2212")
return interval.sub(...args);
if (["*", "\xB7", "\xD7"].includes(this.fn))
return interval.mul(...args);
if (this.fn === "/")
return interval.div(...args);
if (this.fn === "sup")
return interval.sup(...args);
if (isSpecialFunction(this.fn))
return interval[this.fn](...args);
if (this.fn === "(")
return args[0];
if (this.fn === "+") return interval.add(...args);
if (this.fn === "\u2212") return interval.sub(...args);
if (["*", "\xB7", "\xD7"].includes(this.fn)) return interval.mul(...args);
if (this.fn === "/") return interval.div(...args);
if (this.fn === "sup") return interval.sup(...args);
if (isSpecialFunction(this.fn)) return interval[this.fn](...args);
if (this.fn === "(") return args[0];
throw ExprError.undefinedFunction(this.fn);

@@ -731,4 +680,3 @@ }

collapse() {
if (this.fn === "(")
return this.args[0].collapse();
if (this.fn === "(") return this.args[0].collapse();
return new _ExprFunction(this.fn, this.args.map((a) => a.collapse()));

@@ -750,8 +698,5 @@ }

}
if (this.fn === "sup")
return args.join("^");
if (this.fn === "sub")
return args.join("_");
if (this.fn === "subsup")
return `${args[0]}_${args[1]}^${args[2]}`;
if (this.fn === "sup") return args.join("^");
if (this.fn === "sub") return args.join("_");
if (this.fn === "subsup") return `${args[0]}_${args[1]}^${args[2]}`;
if ((0, import_core2.words)("+ * \xD7 \xB7 / = < > \u2264 \u2265 \u2248 \u225F \u2260").includes(this.fn)) {

@@ -763,4 +708,3 @@ return args.join(` ${this.fn} `);

}
if ((0, import_core2.isOneOf)(this.fn, "!", "%"))
return args[0] + this.fn;
if ((0, import_core2.isOneOf)(this.fn, "!", "%")) return args[0] + this.fn;
return `${this.fn}(${args.join(", ")})`;

@@ -793,6 +737,4 @@ }

}
if (this.fn === "//")
return argsF.join(`<mo value="/">/</mo>`);
if (this.fn === "sqrt")
return `<msqrt>${argsF[0]}</msqrt>`;
if (this.fn === "//") return argsF.join(`<mo value="/">/</mo>`);
if (this.fn === "sqrt") return `<msqrt>${argsF[0]}</msqrt>`;
if ((0, import_core2.isOneOf)(this.fn, "/", "root")) {

@@ -846,24 +788,13 @@ const el = this.fn === "/" ? "mfrac" : "mroot";

}
if ((0, import_core2.isOneOf)(this.fn, "(", "[", "{"))
return joined;
if (this.fn === "sqrt")
return `square root of ${joined}`;
if (this.fn === "%")
return `${joined} percent`;
if (this.fn === "!")
return `${joined} factorial`;
if (this.fn === "/")
return `${args[0]} over ${args[1]}`;
if (this.fn === "//")
return `${args[0]} divided by ${args[1]}`;
if (this.fn === "sub")
return joined;
if (this.fn === "subsup")
return `${args[0]} ${args[1]} ${supVoice(args[2])}`;
if (this.fn === "sup")
return `${args[0]} ${supVoice(args[1])}`;
if (VOICE_STRINGS[this.fn])
return args.join(` ${VOICE_STRINGS[this.fn]} `);
if (isSpecialFunction(this.fn))
return `${this.fn} ${joined}`;
if ((0, import_core2.isOneOf)(this.fn, "(", "[", "{")) return joined;
if (this.fn === "sqrt") return `square root of ${joined}`;
if (this.fn === "%") return `${joined} percent`;
if (this.fn === "!") return `${joined} factorial`;
if (this.fn === "/") return `${args[0]} over ${args[1]}`;
if (this.fn === "//") return `${args[0]} divided by ${args[1]}`;
if (this.fn === "sub") return joined;
if (this.fn === "subsup") return `${args[0]} ${args[1]} ${supVoice(args[2])}`;
if (this.fn === "sup") return `${args[0]} ${supVoice(args[1])}`;
if (VOICE_STRINGS[this.fn]) return args.join(` ${VOICE_STRINGS[this.fn]} `);
if (isSpecialFunction(this.fn)) return `${this.fn} ${joined}`;
return `${this.fn} of ${joined}`;

@@ -911,11 +842,7 @@ }

function createToken(buffer, type) {
if (type === 2 /* STR */)
return new ExprString(buffer);
if (!buffer || !type)
return;
if (type === 1 /* SPACE */ && buffer.length > 1)
return new ExprSpace();
if (type === 2 /* STR */) return new ExprString(buffer);
if (!buffer || !type) return;
if (type === 1 /* SPACE */ && buffer.length > 1) return new ExprSpace();
if (type === 3 /* NUM */) {
if (isNaN(+buffer))
throw ExprError.invalidExpression();
if (isNaN(+buffer)) throw ExprError.invalidExpression();
return new ExprNumber(+buffer);

@@ -948,4 +875,3 @@ }

const token2 = createToken(buffer, type);
if (token2)
tokens.push(token2);
if (token2) tokens.push(token2);
buffer = "";

@@ -959,8 +885,6 @@ type = newType;

const sType = s.match(/[0-9.]/) ? 3 /* NUM */ : IDENTIFIER_SYMBOLS.includes(s) ? 4 /* VAR */ : OPERATOR_SYMBOLS.includes(s) ? 5 /* OP */ : s.match(/\s/) ? 1 /* SPACE */ : 0 /* UNKNOWN */;
if (!sType)
throw ExprError.invalidCharacter(s);
if (!sType) throw ExprError.invalidCharacter(s);
if (!type || type === 3 /* NUM */ && sType !== 3 /* NUM */ || type === 4 /* VAR */ && sType !== 4 /* VAR */ && sType !== 3 /* NUM */ || type === 5 /* OP */ && !(buffer + s in SPECIAL_OPERATORS) || type === 1 /* SPACE */ && sType !== 1 /* SPACE */) {
const token2 = createToken(buffer, type);
if (token2)
tokens.push(token2);
if (token2) tokens.push(token2);
buffer = "";

@@ -972,11 +896,8 @@ type = sType;

const token = createToken(buffer, type);
if (token)
tokens.push(token);
if (token) tokens.push(token);
return tokens;
}
function makeTerm(items) {
if (items.length > 1)
return new ExprTerm(items);
if (items[0] instanceof ExprOperator)
return new ExprTerm(items);
if (items.length > 1) return new ExprTerm(items);
if (items[0] instanceof ExprOperator) return new ExprTerm(items);
return items[0];

@@ -1002,9 +923,6 @@ }

function findBinaryFunction(tokens, fn) {
if (isOperator(tokens[0], fn))
throw ExprError.startOperator(tokens[0]);
if (isOperator((0, import_core3.last)(tokens), fn))
throw ExprError.endOperator((0, import_core3.last)(tokens));
if (isOperator(tokens[0], fn)) throw ExprError.startOperator(tokens[0]);
if (isOperator((0, import_core3.last)(tokens), fn)) throw ExprError.endOperator((0, import_core3.last)(tokens));
for (let i = 1; i < tokens.length - 1; ++i) {
if (!isOperator(tokens[i], fn))
continue;
if (!isOperator(tokens[i], fn)) continue;
const token = tokens[i];

@@ -1022,7 +940,5 @@ const a = tokens[i - 1];

const c = tokens[i + 3];
if (c instanceof ExprOperator)
throw ExprError.consecutiveOperators(token2.o, c.o);
if (c instanceof ExprOperator) throw ExprError.consecutiveOperators(token2.o, c.o);
const args = [removeBrackets(a), removeBrackets(b), removeBrackets(c)];
if (token.o === "^")
[args[1], args[2]] = [args[2], args[1]];
if (token.o === "^") [args[1], args[2]] = [args[2], args[1]];
tokens.splice(i - 1, 5, new ExprFunction("subsup", args));

@@ -1075,6 +991,4 @@ i -= 4;

function clearBuffer() {
if (lastWasSymbol)
throw ExprError.invalidExpression();
if (!buffer.length)
return;
if (lastWasSymbol) throw ExprError.invalidExpression();
if (!buffer.length) return;
result.push(buffer.length > 1 ? new ExprFunction(symbol[0], buffer) : buffer[0]);

@@ -1085,4 +999,3 @@ buffer = [];

if (isOperator(t, symbol)) {
if (lastWasSymbol || !buffer.length)
throw ExprError.invalidExpression();
if (lastWasSymbol || !buffer.length) throw ExprError.invalidExpression();
lastWasSymbol = true;

@@ -1095,4 +1008,3 @@ } else if (t instanceof ExprOperator) {

const noImplicit = !implicit || t instanceof ExprNumber;
if (buffer.length && !lastWasSymbol && noImplicit)
throw ExprError.invalidExpression();
if (buffer.length && !lastWasSymbol && noImplicit) throw ExprError.invalidExpression();
buffer.push(t);

@@ -1107,9 +1019,6 @@ lastWasSymbol = false;

tokens = tokens.filter((t) => !(t instanceof ExprSpace));
if (!tokens.length)
throw ExprError.invalidExpression();
if (!tokens.length) throw ExprError.invalidExpression();
const comp = tokens.findIndex((t) => isOperator(t, "= < > \u2264 \u2265 \u225F \u2260"));
if (comp === 0)
throw ExprError.startOperator(tokens[0]);
if (comp === tokens.length - 1)
throw ExprError.endOperator(tokens[0]);
if (comp === 0) throw ExprError.startOperator(tokens[0]);
if (comp === tokens.length - 1) throw ExprError.endOperator(tokens[0]);
if (comp > 0) {

@@ -1120,7 +1029,5 @@ const left = collapseTerm(tokens.slice(0, comp));

}
if (isOperator(tokens[0], "%!"))
throw ExprError.startOperator(tokens[0]);
if (isOperator(tokens[0], "%!")) throw ExprError.startOperator(tokens[0]);
for (let i = 0; i < tokens.length; ++i) {
if (!isOperator(tokens[i], "%!"))
continue;
if (!isOperator(tokens[i], "%!")) continue;
tokens.splice(i - 1, 2, new ExprFunction(tokens[i].o, [tokens[i - 1]]));

@@ -1147,7 +1054,5 @@ i -= 1;

findBinaryFunction(tokens, "\u2212 \xB1");
if (isOperator(tokens[0], "+"))
tokens = tokens.slice(1);
if (isOperator(tokens[0], "+")) tokens = tokens.slice(1);
tokens = findAssociativeFunction(tokens, "+");
if (tokens.length > 1)
throw ExprError.invalidExpression();
if (tokens.length > 1) throw ExprError.invalidExpression();
return tokens[0];

@@ -1169,10 +1074,7 @@ }

const substitution = {};
for (const v of vars)
substitution[v] = CONSTANTS[v] || Math.random() * 5;
for (const v of vars) substitution[v] = CONSTANTS[v] || Math.random() * 5;
const a = fn1.evaluate(substitution);
const b = fn2.evaluate(substitution);
if (isNaN(a) || isNaN(b))
continue;
if (!(0, import_fermat2.nearlyEquals)(a, b))
return false;
if (isNaN(a) || isNaN(b)) continue;
if (!(0, import_fermat2.nearlyEquals)(a, b)) return false;
matches += 1;

@@ -1179,0 +1081,0 @@ }

@@ -256,4 +256,3 @@ // src/errors.ts

const varList = Object.keys(vars);
if (!this.unknowns.filter((v) => varList.includes(v)).length)
return this;
if (!this.unknowns.filter((v) => varList.includes(v)).length) return this;
return this.substitute(vars).recursiveSubstitute(vars);

@@ -298,12 +297,8 @@ }

let value = (_a = vars[name]) != null ? _a : CONSTANTS[name];
if (value === void 0)
throw ExprError.undefinedVariable(name);
if (value === void 0) throw ExprError.undefinedVariable(name);
if (typeof value === "string" || value instanceof ExprElement) {
if (!nested)
LOOP_DETECTION.clear();
if (LOOP_DETECTION.has(name))
throw ExprError.evalLoop(name);
if (!nested) LOOP_DETECTION.clear();
if (LOOP_DETECTION.has(name)) throw ExprError.evalLoop(name);
LOOP_DETECTION.add(name);
if (typeof value === "string")
value = Expression.parse(value);
if (typeof value === "string") value = Expression.parse(value);
return value.evaluate(vars, true);

@@ -359,6 +354,4 @@ } else if (typeof value === "function") {

toVoice() {
if (this.i in VOICE_STRINGS)
return VOICE_STRINGS[this.i];
if (this.i.length === 1)
return `_${this.i}_`;
if (this.i in VOICE_STRINGS) return VOICE_STRINGS[this.i];
if (this.i.length === 1) return `_${this.i}_`;
return this.i;

@@ -473,4 +466,3 @@ }

if (a[0] > 0) {
if (b[0] >= 0)
return int(a[0] ** b[0], a[1] ** b[1]);
if (b[0] >= 0) return int(a[0] ** b[0], a[1] ** b[1]);
return range(a[0] ** b[0], a[0] ** b[1], a[1] ** b[0], a[1] ** b[1]);

@@ -480,8 +472,5 @@ }

if (Number.isInteger(k) && k === b[1]) {
if (k === 0)
return [hasZero(a) ? 0 : 1, 1];
if (k % 2)
return int(a[0] ** k, a[1] ** k);
if (hasZero(a))
return [0, Math.max(a[0] ** k, a[1] ** k)];
if (k === 0) return [hasZero(a) ? 0 : 1, 1];
if (k % 2) return int(a[0] ** k, a[1] ** k);
if (hasZero(a)) return [0, Math.max(a[0] ** k, a[1] ** k)];
return range(a[1] ** k, a[0] ** k);

@@ -499,4 +488,3 @@ }

mul: (a, ...b) => {
if (b.length > 1)
b = [interval.mul(...b)];
if (b.length > 1) b = [interval.mul(...b)];
return range(a[0] * b[0][0], a[0] * b[0][1], a[1] * b[0][0], a[1] * b[0][1]);

@@ -506,4 +494,3 @@ },

abs: (a) => {
if (hasZero(a))
return int(0, Math.max(-a[0], a[1]));
if (hasZero(a)) return int(0, Math.max(-a[0], a[1]));
return range(Math.abs(a[0]), Math.abs(a[1]));

@@ -517,4 +504,3 @@ },

mod: (a, b) => {
if (isEmpty(a) || isEmpty(b))
return EMPTY;
if (isEmpty(a) || isEmpty(b)) return EMPTY;
let n = a[0] / (a[0] < 0 ? b[0] : b[1]);

@@ -531,4 +517,3 @@ n = n < 0 ? Math.ceil(n) : Math.floor(n);

log: (a, b) => {
if (b !== void 0)
interval.div(interval.log(a), interval.log(b));
if (b !== void 0) interval.div(interval.log(a), interval.log(b));
return int(a[0] <= 0 ? -Infinity : Math.log(a[0]), Math.log(a[1]));

@@ -542,23 +527,15 @@ },

cos: (a) => {
if (isEmpty(a) || isInfinite(a))
return EMPTY;
if (width(a) >= TWO_PI - Number.EPSILON)
return [-1, 1];
if (isEmpty(a) || isInfinite(a)) return EMPTY;
if (width(a) >= TWO_PI - Number.EPSILON) return [-1, 1];
a = intervalMod(a);
if (a[0] > Math.PI + Number.EPSILON)
return interval.sub(interval.cos(interval.sub(a, [Math.PI, Math.PI])));
if (a[1] < Math.PI - Number.EPSILON)
return int(Math.cos(a[1]), Math.cos(a[0]));
if (a[1] < TWO_PI - Number.EPSILON)
return int(-1, Math.max(Math.cos(a[1]), Math.cos(a[0])));
if (a[0] > Math.PI + Number.EPSILON) return interval.sub(interval.cos(interval.sub(a, [Math.PI, Math.PI])));
if (a[1] < Math.PI - Number.EPSILON) return int(Math.cos(a[1]), Math.cos(a[0]));
if (a[1] < TWO_PI - Number.EPSILON) return int(-1, Math.max(Math.cos(a[1]), Math.cos(a[0])));
return int(-1, 1);
},
tan: (a) => {
if (isEmpty(a) || isInfinite(a))
return EMPTY;
if (isEmpty(a) || isInfinite(a)) return EMPTY;
a = intervalMod(a, Math.PI);
if (a[0] > HALF_PI + Number.EPSILON)
a = interval.sub(a, [Math.PI, Math.PI]);
if (a[0] < -HALF_PI + Number.EPSILON || a[1] > HALF_PI - Number.EPSILON)
return WHOLE;
if (a[0] > HALF_PI + Number.EPSILON) a = interval.sub(a, [Math.PI, Math.PI]);
if (a[0] < -HALF_PI + Number.EPSILON || a[1] > HALF_PI - Number.EPSILON) return WHOLE;
return int(Math.tan(a[0]), Math.tan(a[1]));

@@ -572,9 +549,7 @@ },

arcsin: (a) => {
if (isEmpty(a) || a[1] < -1 || a[0] > 1)
return EMPTY;
if (isEmpty(a) || a[1] < -1 || a[0] > 1) return EMPTY;
return int(a[0] <= -1 ? -HALF_PI : Math.asin(a[0]), a[1] >= 1 ? HALF_PI : Math.asin(a[1]));
},
arccos: (a) => {
if (isEmpty(a) || a[1] < -1 || a[0] > 1)
return EMPTY;
if (isEmpty(a) || a[1] < -1 || a[0] > 1) return EMPTY;
return int(a[1] >= 1 ? 0 : Math.acos(a[1]), a[0] <= -1 ? Math.PI : Math.acos(a[0]));

@@ -585,6 +560,4 @@ },

cosh: (a) => {
if (a[1] < 0)
return int(Math.cosh(a[1]), Math.cosh(a[0]));
if (a[0] > 0)
return int(Math.cosh(a[0]), Math.cosh(a[1]));
if (a[1] < 0) return int(Math.cosh(a[1]), Math.cosh(a[0]));
if (a[0] > 0) return int(Math.cosh(a[0]), Math.cosh(a[1]));
return int(1, Math.cosh(Math.max(-a[0], a[1])));

@@ -604,12 +577,7 @@ },

function needsBrackets(expr, parentFn) {
if (!PRECEDENCE.includes(parentFn))
return false;
if (expr instanceof ExprTerm)
return true;
if (!(expr instanceof ExprFunction))
return false;
if (!PRECEDENCE.includes(expr.fn))
return false;
if (SUBSUP.includes(expr.fn) && SUBSUP.includes(parentFn))
return true;
if (!PRECEDENCE.includes(parentFn)) return false;
if (expr instanceof ExprTerm) return true;
if (!(expr instanceof ExprFunction)) return false;
if (!PRECEDENCE.includes(expr.fn)) return false;
if (SUBSUP.includes(expr.fn) && SUBSUP.includes(parentFn)) return true;
return PRECEDENCE.indexOf(parentFn) > PRECEDENCE.indexOf(expr.fn);

@@ -637,22 +605,13 @@ }

const fn = vars[this.fn];
if (typeof fn === "function")
return fn(...args);
if (typeof fn === "number" && args.length === 1)
return evaluate.mul(fn, args[0]);
if (typeof fn === "function") return fn(...args);
if (typeof fn === "number" && args.length === 1) return evaluate.mul(fn, args[0]);
throw ExprError.uncallableExpression(this.fn);
}
if (this.fn === "+")
return evaluate.add(...args);
if (this.fn === "\u2212")
return evaluate.sub(...args);
if (["*", "\xB7", "\xD7"].includes(this.fn))
return evaluate.mul(...args);
if (this.fn === "/")
return evaluate.div(...args);
if (this.fn === "sup")
return evaluate.sup(...args);
if (isSpecialFunction(this.fn))
return evaluate[this.fn](...args);
if (this.fn === "(")
return args[0];
if (this.fn === "+") return evaluate.add(...args);
if (this.fn === "\u2212") return evaluate.sub(...args);
if (["*", "\xB7", "\xD7"].includes(this.fn)) return evaluate.mul(...args);
if (this.fn === "/") return evaluate.div(...args);
if (this.fn === "sup") return evaluate.sup(...args);
if (isSpecialFunction(this.fn)) return evaluate[this.fn](...args);
if (this.fn === "(") return args[0];
throw ExprError.undefinedFunction(this.fn);

@@ -664,24 +623,14 @@ }

const fn = vars[this.fn];
if (typeof fn === "function")
return repeat(fn(...args.map((a) => a[0])), 2);
if (typeof fn === "number" && args.length === 1)
return interval.mul([fn, fn], args[0]);
if (Array.isArray(fn) && args.length === 1)
return interval.mul(fn, args[0]);
if (typeof fn === "function") return repeat(fn(...args.map((a) => a[0])), 2);
if (typeof fn === "number" && args.length === 1) return interval.mul([fn, fn], args[0]);
if (Array.isArray(fn) && args.length === 1) return interval.mul(fn, args[0]);
throw ExprError.uncallableExpression(this.fn);
}
if (this.fn === "+")
return interval.add(...args);
if (this.fn === "\u2212")
return interval.sub(...args);
if (["*", "\xB7", "\xD7"].includes(this.fn))
return interval.mul(...args);
if (this.fn === "/")
return interval.div(...args);
if (this.fn === "sup")
return interval.sup(...args);
if (isSpecialFunction(this.fn))
return interval[this.fn](...args);
if (this.fn === "(")
return args[0];
if (this.fn === "+") return interval.add(...args);
if (this.fn === "\u2212") return interval.sub(...args);
if (["*", "\xB7", "\xD7"].includes(this.fn)) return interval.mul(...args);
if (this.fn === "/") return interval.div(...args);
if (this.fn === "sup") return interval.sup(...args);
if (isSpecialFunction(this.fn)) return interval[this.fn](...args);
if (this.fn === "(") return args[0];
throw ExprError.undefinedFunction(this.fn);

@@ -693,4 +642,3 @@ }

collapse() {
if (this.fn === "(")
return this.args[0].collapse();
if (this.fn === "(") return this.args[0].collapse();
return new _ExprFunction(this.fn, this.args.map((a) => a.collapse()));

@@ -712,8 +660,5 @@ }

}
if (this.fn === "sup")
return args.join("^");
if (this.fn === "sub")
return args.join("_");
if (this.fn === "subsup")
return `${args[0]}_${args[1]}^${args[2]}`;
if (this.fn === "sup") return args.join("^");
if (this.fn === "sub") return args.join("_");
if (this.fn === "subsup") return `${args[0]}_${args[1]}^${args[2]}`;
if (words("+ * \xD7 \xB7 / = < > \u2264 \u2265 \u2248 \u225F \u2260").includes(this.fn)) {

@@ -725,4 +670,3 @@ return args.join(` ${this.fn} `);

}
if (isOneOf(this.fn, "!", "%"))
return args[0] + this.fn;
if (isOneOf(this.fn, "!", "%")) return args[0] + this.fn;
return `${this.fn}(${args.join(", ")})`;

@@ -755,6 +699,4 @@ }

}
if (this.fn === "//")
return argsF.join(`<mo value="/">/</mo>`);
if (this.fn === "sqrt")
return `<msqrt>${argsF[0]}</msqrt>`;
if (this.fn === "//") return argsF.join(`<mo value="/">/</mo>`);
if (this.fn === "sqrt") return `<msqrt>${argsF[0]}</msqrt>`;
if (isOneOf(this.fn, "/", "root")) {

@@ -808,24 +750,13 @@ const el = this.fn === "/" ? "mfrac" : "mroot";

}
if (isOneOf(this.fn, "(", "[", "{"))
return joined;
if (this.fn === "sqrt")
return `square root of ${joined}`;
if (this.fn === "%")
return `${joined} percent`;
if (this.fn === "!")
return `${joined} factorial`;
if (this.fn === "/")
return `${args[0]} over ${args[1]}`;
if (this.fn === "//")
return `${args[0]} divided by ${args[1]}`;
if (this.fn === "sub")
return joined;
if (this.fn === "subsup")
return `${args[0]} ${args[1]} ${supVoice(args[2])}`;
if (this.fn === "sup")
return `${args[0]} ${supVoice(args[1])}`;
if (VOICE_STRINGS[this.fn])
return args.join(` ${VOICE_STRINGS[this.fn]} `);
if (isSpecialFunction(this.fn))
return `${this.fn} ${joined}`;
if (isOneOf(this.fn, "(", "[", "{")) return joined;
if (this.fn === "sqrt") return `square root of ${joined}`;
if (this.fn === "%") return `${joined} percent`;
if (this.fn === "!") return `${joined} factorial`;
if (this.fn === "/") return `${args[0]} over ${args[1]}`;
if (this.fn === "//") return `${args[0]} divided by ${args[1]}`;
if (this.fn === "sub") return joined;
if (this.fn === "subsup") return `${args[0]} ${args[1]} ${supVoice(args[2])}`;
if (this.fn === "sup") return `${args[0]} ${supVoice(args[1])}`;
if (VOICE_STRINGS[this.fn]) return args.join(` ${VOICE_STRINGS[this.fn]} `);
if (isSpecialFunction(this.fn)) return `${this.fn} ${joined}`;
return `${this.fn} of ${joined}`;

@@ -873,11 +804,7 @@ }

function createToken(buffer, type) {
if (type === 2 /* STR */)
return new ExprString(buffer);
if (!buffer || !type)
return;
if (type === 1 /* SPACE */ && buffer.length > 1)
return new ExprSpace();
if (type === 2 /* STR */) return new ExprString(buffer);
if (!buffer || !type) return;
if (type === 1 /* SPACE */ && buffer.length > 1) return new ExprSpace();
if (type === 3 /* NUM */) {
if (isNaN(+buffer))
throw ExprError.invalidExpression();
if (isNaN(+buffer)) throw ExprError.invalidExpression();
return new ExprNumber(+buffer);

@@ -910,4 +837,3 @@ }

const token2 = createToken(buffer, type);
if (token2)
tokens.push(token2);
if (token2) tokens.push(token2);
buffer = "";

@@ -921,8 +847,6 @@ type = newType;

const sType = s.match(/[0-9.]/) ? 3 /* NUM */ : IDENTIFIER_SYMBOLS.includes(s) ? 4 /* VAR */ : OPERATOR_SYMBOLS.includes(s) ? 5 /* OP */ : s.match(/\s/) ? 1 /* SPACE */ : 0 /* UNKNOWN */;
if (!sType)
throw ExprError.invalidCharacter(s);
if (!sType) throw ExprError.invalidCharacter(s);
if (!type || type === 3 /* NUM */ && sType !== 3 /* NUM */ || type === 4 /* VAR */ && sType !== 4 /* VAR */ && sType !== 3 /* NUM */ || type === 5 /* OP */ && !(buffer + s in SPECIAL_OPERATORS) || type === 1 /* SPACE */ && sType !== 1 /* SPACE */) {
const token2 = createToken(buffer, type);
if (token2)
tokens.push(token2);
if (token2) tokens.push(token2);
buffer = "";

@@ -934,11 +858,8 @@ type = sType;

const token = createToken(buffer, type);
if (token)
tokens.push(token);
if (token) tokens.push(token);
return tokens;
}
function makeTerm(items) {
if (items.length > 1)
return new ExprTerm(items);
if (items[0] instanceof ExprOperator)
return new ExprTerm(items);
if (items.length > 1) return new ExprTerm(items);
if (items[0] instanceof ExprOperator) return new ExprTerm(items);
return items[0];

@@ -964,9 +885,6 @@ }

function findBinaryFunction(tokens, fn) {
if (isOperator(tokens[0], fn))
throw ExprError.startOperator(tokens[0]);
if (isOperator(last(tokens), fn))
throw ExprError.endOperator(last(tokens));
if (isOperator(tokens[0], fn)) throw ExprError.startOperator(tokens[0]);
if (isOperator(last(tokens), fn)) throw ExprError.endOperator(last(tokens));
for (let i = 1; i < tokens.length - 1; ++i) {
if (!isOperator(tokens[i], fn))
continue;
if (!isOperator(tokens[i], fn)) continue;
const token = tokens[i];

@@ -984,7 +902,5 @@ const a = tokens[i - 1];

const c = tokens[i + 3];
if (c instanceof ExprOperator)
throw ExprError.consecutiveOperators(token2.o, c.o);
if (c instanceof ExprOperator) throw ExprError.consecutiveOperators(token2.o, c.o);
const args = [removeBrackets(a), removeBrackets(b), removeBrackets(c)];
if (token.o === "^")
[args[1], args[2]] = [args[2], args[1]];
if (token.o === "^") [args[1], args[2]] = [args[2], args[1]];
tokens.splice(i - 1, 5, new ExprFunction("subsup", args));

@@ -1037,6 +953,4 @@ i -= 4;

function clearBuffer() {
if (lastWasSymbol)
throw ExprError.invalidExpression();
if (!buffer.length)
return;
if (lastWasSymbol) throw ExprError.invalidExpression();
if (!buffer.length) return;
result.push(buffer.length > 1 ? new ExprFunction(symbol[0], buffer) : buffer[0]);

@@ -1047,4 +961,3 @@ buffer = [];

if (isOperator(t, symbol)) {
if (lastWasSymbol || !buffer.length)
throw ExprError.invalidExpression();
if (lastWasSymbol || !buffer.length) throw ExprError.invalidExpression();
lastWasSymbol = true;

@@ -1057,4 +970,3 @@ } else if (t instanceof ExprOperator) {

const noImplicit = !implicit || t instanceof ExprNumber;
if (buffer.length && !lastWasSymbol && noImplicit)
throw ExprError.invalidExpression();
if (buffer.length && !lastWasSymbol && noImplicit) throw ExprError.invalidExpression();
buffer.push(t);

@@ -1069,9 +981,6 @@ lastWasSymbol = false;

tokens = tokens.filter((t) => !(t instanceof ExprSpace));
if (!tokens.length)
throw ExprError.invalidExpression();
if (!tokens.length) throw ExprError.invalidExpression();
const comp = tokens.findIndex((t) => isOperator(t, "= < > \u2264 \u2265 \u225F \u2260"));
if (comp === 0)
throw ExprError.startOperator(tokens[0]);
if (comp === tokens.length - 1)
throw ExprError.endOperator(tokens[0]);
if (comp === 0) throw ExprError.startOperator(tokens[0]);
if (comp === tokens.length - 1) throw ExprError.endOperator(tokens[0]);
if (comp > 0) {

@@ -1082,7 +991,5 @@ const left = collapseTerm(tokens.slice(0, comp));

}
if (isOperator(tokens[0], "%!"))
throw ExprError.startOperator(tokens[0]);
if (isOperator(tokens[0], "%!")) throw ExprError.startOperator(tokens[0]);
for (let i = 0; i < tokens.length; ++i) {
if (!isOperator(tokens[i], "%!"))
continue;
if (!isOperator(tokens[i], "%!")) continue;
tokens.splice(i - 1, 2, new ExprFunction(tokens[i].o, [tokens[i - 1]]));

@@ -1109,7 +1016,5 @@ i -= 1;

findBinaryFunction(tokens, "\u2212 \xB1");
if (isOperator(tokens[0], "+"))
tokens = tokens.slice(1);
if (isOperator(tokens[0], "+")) tokens = tokens.slice(1);
tokens = findAssociativeFunction(tokens, "+");
if (tokens.length > 1)
throw ExprError.invalidExpression();
if (tokens.length > 1) throw ExprError.invalidExpression();
return tokens[0];

@@ -1131,10 +1036,7 @@ }

const substitution = {};
for (const v of vars)
substitution[v] = CONSTANTS[v] || Math.random() * 5;
for (const v of vars) substitution[v] = CONSTANTS[v] || Math.random() * 5;
const a = fn1.evaluate(substitution);
const b = fn2.evaluate(substitution);
if (isNaN(a) || isNaN(b))
continue;
if (!nearlyEquals(a, b))
return false;
if (isNaN(a) || isNaN(b)) continue;
if (!nearlyEquals(a, b)) return false;
matches += 1;

@@ -1141,0 +1043,0 @@ }

{
"name": "@mathigon/hilbert",
"version": "1.1.16",
"version": "1.1.17",
"license": "MIT",

@@ -39,12 +39,12 @@ "homepage": "https://mathigon.io/hilbert",

"@types/tape": "5.6.4",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"esbuild": "0.20.2",
"@typescript-eslint/eslint-plugin": "7.13.1",
"@typescript-eslint/parser": "7.13.1",
"esbuild": "0.21.5",
"eslint": "8.57.0",
"eslint-plugin-import": "2.29.1",
"tape": "5.7.5",
"tape": "5.8.1",
"ts-node": "10.9.2",
"tslib": "2.6.2",
"typescript": "5.3.3"
"tslib": "2.6.3",
"typescript": "5.5.2"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc