Skip to content

Commit

Permalink
fix(trailing-zeros): Skip LaTeX-to-AST and AST-to-MathJS conversions …
Browse files Browse the repository at this point in the history
…for numeric equality checks PD-4410
  • Loading branch information
CarlaCostea committed Dec 12, 2024
1 parent ee03a6f commit 20e1725
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/latex-equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const lta = new LatexToAst();
const atm = new AstToMathJs();

export const latexEqual = (a: Latex, b: Latex, opts: Opts) => {
const isNumeric = (str: string): boolean => /^-?\d+(\.\d+)?$/.test(str);

if (!a || !b) {
return false;
}
Expand All @@ -25,6 +27,16 @@ export const latexEqual = (a: Latex, b: Latex, opts: Opts) => {
return true;
}

if (opts.mode === "symbolic" && isNumeric(a) && isNumeric(b)) {
const numA = parseFloat(a);
const numB = parseFloat(b);

if (numA === numB) {
console.log(numA, numB, "equals");
return true;
}
}

const al = lta.convert(a);
const bl = lta.convert(b);

Expand Down
12 changes: 2 additions & 10 deletions src/symbolic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,7 @@ export const simplify = (v) => {
};

const normalize = (a: string | MathNode | any) => {

let r: string | MathNode | any;
if (a.fn && a.fn.name == 'tzn'){
r = a.args[0]
} else {
r = a;
}


let r: string | MathNode | any = a;
let onlyConstant = true;
let containsFunctionNode = false;
let containsArrayNode = false;
Expand Down Expand Up @@ -138,7 +130,7 @@ const normalize = (a: string | MathNode | any) => {
if (r.fn !== "equal") {
try {
onlyConstant = false;
r = rationalize(r, {}, true).expression;
r = rationalize(r, {}, true).expression;
} catch {}
}

Expand Down

0 comments on commit 20e1725

Please sign in to comment.