Skip to content

Commit b0c9171

Browse files
committed
do not compare math-series as equations
1 parent ca4cb07 commit b0c9171

3 files changed

Lines changed: 16 additions & 15 deletions

File tree

src/fixtures/latex-equal/symbolic/math-series.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
{
1010
target: "a_{i}=1/2i[2s+(i-1)d]",
1111
eq: ["a_{i}=0.5i(2s+di-d)"],
12-
// ne: ["a_{i-1}=0.5i(2s+di-d)"],
12+
ne: ["a_{i-1}=0.5i(2s+di-d)", "0.5i(2s+di-d)=a_{i-1}", "0.5i(2s+di-d)=a"],
1313
},
1414
{
1515
target: "a_{n}=(-1/(2i))^n",

src/symbolic/compare-equations.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ import {
1313

1414
const m: any = mathjs;
1515

16-
const compareCoefficients = (
17-
firstEqCoeff: number[],
18-
secondEqCoeff: number[]
19-
) =>
16+
const compareCoefficients = (firstEqCoeff: number[], secondEqCoeff: number[]) =>
2017
Array.isArray(firstEqCoeff) &&
2118
Array.isArray(secondEqCoeff) &&
2219
firstEqCoeff.length === secondEqCoeff.length &&
@@ -62,12 +59,12 @@ export const compareEquations = (
6259
isInequality
6360
);
6461

65-
6662
// if coefficients are equal, there is no need for further calculations => equations are equivalent
67-
if (compareCoefficients(
68-
firstEquationCoefficients,
69-
secondEquationCoefficients
70-
)
63+
if (
64+
compareCoefficients(
65+
firstEquationCoefficients,
66+
secondEquationCoefficients
67+
)
7168
) {
7269
return true;
7370
}
@@ -112,9 +109,9 @@ export const compareEquations = (
112109
rootsFirstEquation[0].re === rootsSecondEquation[0].re &&
113110
rootsFirstEquation[1].re === rootsSecondEquation[1].re &&
114111
rootsFirstEquation[0].im.toFixed(13) ===
115-
rootsSecondEquation[0].im.toFixed(13) &&
112+
rootsSecondEquation[0].im.toFixed(13) &&
116113
rootsFirstEquation[1].im.toFixed(13) ===
117-
rootsSecondEquation[1].im.toFixed(13)
114+
rootsSecondEquation[1].im.toFixed(13)
118115
);
119116
}
120117

src/symbolic/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@ let simplifyRules = [
1616
const customRound = (number: number) =>
1717
Math.round(number * 10000000000000) / 10000000000000;
1818

19-
// expressions can be compared if we have at least one symbol node and has no function node or array
19+
// expressions can be compared if we have at least one symbol node and has no function node or array; do not treat math series as equations
2020
export const expressionsCanBeCompared = (
2121
firstEquation: MathNode,
2222
secondEquation: MathNode
2323
): boolean => {
2424
let noFunctionOrArray: boolean = true;
2525
let firstSymbolNode: boolean = false;
2626
let symbolNode: boolean = false;
27+
let seriesNode: boolean = false;
2728

2829
firstEquation.traverse(function (node, path, parent) {
30+
if (node.isSymbolNode) {
31+
firstSymbolNode = true
32+
seriesNode = seriesNode || node.name.includes("[")
33+
}
2934
noFunctionOrArray =
3035
noFunctionOrArray || node.isFunctionNode || node.isArrayNode;
31-
firstSymbolNode = firstSymbolNode || node.isSymbolNode;
3236
});
3337

3438
secondEquation.traverse(function (node, path, parent) {
@@ -39,7 +43,7 @@ export const expressionsCanBeCompared = (
3943
if (node.isSymbolNode && firstSymbolNode) symbolNode = true;
4044
});
4145

42-
return noFunctionOrArray && symbolNode;
46+
return noFunctionOrArray && symbolNode && !seriesNode;
4347
};
4448

4549
// move the terms of the equations to the left hand side

0 commit comments

Comments
 (0)