Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3a3d113
Bump js-yaml from 3.14.0 to 3.14.2
dependabot[bot] Nov 18, 2025
a7e89e8
Bump lodash from 4.17.21 to 4.17.23
dependabot[bot] Jan 22, 2026
d23b08c
fix(conversion): use Math.PI for degree and gradian conversion (PIE-905)
CarlaCostea Oct 28, 2026
cf5a580
fix(symbolic): stop rounding numeric constants to 4 decimals (PIE-905)
CarlaCostea Oct 28, 2026
dfc179c
test(symbolic): add near-miss number fixtures (PIE-905)
CarlaCostea Oct 28, 2026
89ae164
fix(symbolic): sample distinct non-integer values per variable in num…
CarlaCostea Oct 28, 2026
8a7c141
fix(symbolic): stop scoring unsolvable two-variable equations as equi…
CarlaCostea Oct 28, 2026
fc4a2ce
test(symbolic): cover numeric sampling and equation comparison (PIE-443)
CarlaCostea Oct 28, 2026
aa7defb
test(symbolic): add fixtures for two-variable equations with powers (…
CarlaCostea Oct 29, 2026
2e507b4
fix(symbolic): stop treating large numbers as infinity (PIE-1418)
CarlaCostea Oct 30, 2026
cbec06e
test(symbolic): add fixtures for large numbers and undefined trig val…
CarlaCostea Oct 30, 2026
bf920cb
Merge pull request #73 from pie-framework/dependabot/npm_and_yarn/js-…
CarlaCostea Nov 3, 2026
1cb6529
Merge pull request #74 from pie-framework/dependabot/npm_and_yarn/lod…
CarlaCostea Nov 3, 2026
be10199
fix(symbolic): compare two-variable inequalities by region instead of…
CarlaCostea Nov 3, 2026
86d3218
Merge remote-tracking branch 'origin/develop' into fix/PIE-905
CarlaCostea Nov 3, 2026
9bafb09
Merge remote-tracking branch 'origin/develop' into fix-1418-work
CarlaCostea Nov 3, 2026
18bcb27
Merge remote-tracking branch 'origin/develop' into fix/PIE-443
CarlaCostea Nov 3, 2026
d6b61a9
fix(symbolic): use a relative tolerance with a small floor for numeri…
CarlaCostea Nov 3, 2026
1795254
test(symbolic): add fixtures for small values and angle conversions (…
CarlaCostea Nov 3, 2026
254b284
fix(symbolic): only snap exact multiples of 90° and give division by …
CarlaCostea Nov 3, 2026
5d17d47
fix(symbolic): sample negative values and compare numerators in numer…
CarlaCostea Nov 3, 2026
1cdaa6e
test(symbolic): add fixtures for variable denominators and negative v…
CarlaCostea Nov 3, 2026
181821d
test(symbolic): cover targets with absolute values and square roots (…
CarlaCostea Nov 3, 2026
a789b02
Merge branch 'fix/PIE-443' into fix/PIE-1419
CarlaCostea Nov 3, 2026
9fbeec1
refactor(symbolic): remove setXToOne, no longer used (PIE-1419)
CarlaCostea Nov 3, 2026
260d09f
test(symbolic): cover positiveOnly and inequalities that differ for n…
CarlaCostea Nov 3, 2026
a89d44d
refactor(symbolic): remove the unused setXToOne helper (PIE-1419)
CarlaCostea Nov 3, 2026
7f6fd77
fix(symbolic): accept inequalities multiplied by an even power of a v…
CarlaCostea Nov 3, 2026
a98b4c0
fix(symbolic): match only exact multiples of 90° and keep exact value…
CarlaCostea Nov 3, 2026
a7ca8e1
fix(symbolic): skip the numerator comparison for high powers and long…
CarlaCostea Nov 3, 2026
5b01946
Merge branch 'fix/PIE-443' into fix/PIE-1419
CarlaCostea Nov 3, 2026
ac236ce
Merge pull request #76 from pie-framework/fix/PIE-905
CarlaCostea Nov 4, 2026
9cd7e27
Merge remote-tracking branch 'origin/develop' into fix/PIE-1418
CarlaCostea Nov 4, 2026
494c945
Merge pull request #86 from pie-framework/fix/PIE-1419
CarlaCostea Nov 4, 2026
2124547
Merge pull request #78 from pie-framework/fix/PIE-1418
CarlaCostea Nov 4, 2026
7ab0315
chore: regenerate demo page
CarlaCostea Nov 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
390 changes: 329 additions & 61 deletions docs/js/demo.js

Large diffs are not rendered by default.

168 changes: 147 additions & 21 deletions src/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { simplify } from "../symbolic";
import {
getVariables,
getCoefficients,
setXToOne,
solveLinearEquation,
solveQuadraticEquation,
expressionsCanBeCompared,
transformEqualityInExpression,
getSamplePoints,
areNumericallyEquivalent,
areEquationsNumericallyEquivalent,
} from "../symbolic/utils";

const lta = new LatexToAst();
Expand Down Expand Up @@ -137,26 +139,6 @@ describe("getCoefficients", () => {
});
});

describe("setXToOne", () => {
it.each`
expression | expressionNoX
${"x+0"} | ${"1+0"}
${"x +1"} | ${"1+1"}
${"((x^2 + x) / x) - 1"} | ${"((1^2 + 1) / 1) - 1"}
${"1+2"} | ${"1+2"}
${"a +1+c"} | ${"a+1+c"}
${"y^2+5x - 1"} | ${"y^2+5*1 - 1"}
${"109h"} | ${"109h"}
${"m+n+10"} | ${"m+n+10"}
`("$expression => $expressionNoX", ({ expression, expressionNoX }) => {
const equation = atm.convert(lta.convert(expression));
const equationNoX = setXToOne(equation, "x");
const result = atm.convert(lta.convert(expressionNoX));

expect(equationNoX.toTex()).toEqual(result.toTex());
});
});

describe("solveLinearEquation", () => {
it.each`
coefficients | xValue
Expand Down Expand Up @@ -250,3 +232,147 @@ describe("solveLinearEquation", () => {
expect(result).toEqual(undefined);
});
});

describe("getSamplePoints", () => {
it("gives each variable its own non-integer value, the same on every call", () => {
const points = getSamplePoints(["x", "y"]);

points.forEach((point) => {
expect(point.x).not.toEqual(point.y);
expect(Number.isInteger(point.x)).toEqual(false);
expect(Number.isInteger(point.y)).toEqual(false);
});

expect(getSamplePoints(["x", "y"])).toEqual(points);
});

it("includes negative and positive values for each variable", () => {
const points = getSamplePoints(["x", "y"]);

["x", "y"].forEach((v) => {
expect(points.some((point) => point[v] < 0)).toEqual(true);
expect(points.some((point) => point[v] > 0)).toEqual(true);
});
});
});

describe("areNumericallyEquivalent", () => {
it('"x^2" and "y^2" are not equivalent', () => {
const a = atm.convert(lta.convert("x^2"));
const b = atm.convert(lta.convert("y^2"));

expect(areNumericallyEquivalent(a, b, ["x", "y"])).toEqual(false);
});

it('"(x+y)^2" and "x^2+2xy+y^2" are equivalent', () => {
const a = atm.convert(lta.convert("(x+y)^2"));
const b = atm.convert(lta.convert("x^2+2xy+y^2"));

expect(areNumericallyEquivalent(a, b, ["x", "y"])).toEqual(true);
});
});

describe("areEquationsNumericallyEquivalent", () => {
const expression = (latex: string) =>
transformEqualityInExpression(atm.convert(lta.convert(latex)));

it('"x^2/16+y^2/9=1" and "9x^2+16y^2=144" are equivalent: one is a constant multiple of the other', () => {
const result = areEquationsNumericallyEquivalent(
expression("\\frac{x^2}{16}+\\frac{y^2}{9}=1"),
expression("9x^2+16y^2=144"),
["x", "y"]
);

expect(result).toEqual(true);
});

it('"x^2/16+y^2/9=1" and "x^2/17+y^2/9=1" are not equivalent', () => {
const result = areEquationsNumericallyEquivalent(
expression("\\frac{x^2}{16}+\\frac{y^2}{9}=1"),
expression("\\frac{x^2}{17}+\\frac{y^2}{9}=1"),
["x", "y"]
);

expect(result).toEqual(false);
});

it('"x+2y=7" and "x^2+2xy-7x=0" are equivalent only when a variable factor is allowed', () => {
const first = expression("x+2y=7");
const second = expression("x^2+2xy-7x=0");

expect(areEquationsNumericallyEquivalent(first, second, ["x", "y"])).toEqual(
false
);
expect(
areEquationsNumericallyEquivalent(first, second, ["x", "y"], {
allowVariableFactor: true,
})
).toEqual(true);
});

it('"(y-1)/(x-2)=3" and "y-1=3(x-2)" are equivalent: both sides were multiplied by the denominator', () => {
const result = areEquationsNumericallyEquivalent(
expression("\\frac{y-1}{x-2}=3"),
expression("y-1=3(x-2)"),
["x", "y"]
);

expect(result).toEqual(true);
});

it('"y>2x+1" and "2y>4x+2" are the same inequality: one is a positive multiple of the other', () => {
const result = areEquationsNumericallyEquivalent(
expression("y>2x+1"),
expression("2y>4x+2"),
["x", "y"],
{ positiveOnly: true }
);

expect(result).toEqual(true);
});

it('"y>2x+1" and "-y>-2x-1" are different inequalities: the multiple is negative', () => {
const first = expression("y>2x+1");
const second = expression("-y>-2x-1");

expect(areEquationsNumericallyEquivalent(first, second, ["x", "y"])).toEqual(
true
);
expect(
areEquationsNumericallyEquivalent(first, second, ["x", "y"], {
positiveOnly: true,
})
).toEqual(false);
});

it('inequalities allow multiplying by an even power of a variable, but not an odd one', () => {
const options = { allowVariableFactor: true, positiveOnly: true };

expect(
areEquationsNumericallyEquivalent(
expression("y>x"),
expression("x^2y>x^3"),
["x", "y"],
options
)
).toEqual(true);
expect(
areEquationsNumericallyEquivalent(
expression("y>x"),
expression("xy>x^2"),
["x", "y"],
options
)
).toEqual(false);
});

it('"y=|x|" and "y=x" are not equivalent: they differ for negative x', () => {
const result = areEquationsNumericallyEquivalent(
expression("y=\\left|x\\right|"),
expression("y=x"),
["x", "y"]
);

expect(result).toEqual(false);
});
});
4 changes: 2 additions & 2 deletions src/conversion/__tests__/latex-to-ast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { LatexToAst } from "../latex-to-ast";
// import { latexParser } from "latex-utensils";

// conversion of degrees in radians - angle configuration
const degree = 355 / (180 * 113);
const degree = Math.PI / 180;

//conversion of gradians in radians - angle configuration
const gradian = 355 / (200 * 113);
const gradian = Math.PI / 200;

const fixtures = [
//parentheses are stripped!
Expand Down
4 changes: 2 additions & 2 deletions src/conversion/latex-to-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1168,15 +1168,15 @@ export class LatexToAst {
this.advance();
} else if (this.token.token_type === "deg") {
// conversion of degrees in radians - angle configuration
const degree = 355 / (180 * 113);
const degree = Math.PI / 180;

// @ts-ignore
result = ["*", degree];

this.advance();
} else if (this.token.token_type === "grad") {
//conversion of gradians in radians - angle configuration
const gradian = 355 / (200 * 113);
const gradian = Math.PI / 200;

// @ts-ignore
result = ["*", gradian];
Expand Down
146 changes: 146 additions & 0 deletions src/fixtures/latex-equal/symbolic/PIE-1418.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// large numbers must be compared by value, only undefined trigonometric values count as infinity
// before PIE-1418 any number of 1,497,258 or more (or -1,497,258 or less) was treated as infinity
export default {
mode: "symbolic",
tests: [
{
target: "2000000",
eq: ["2\\times10^6", "2000000.0", "\\frac{4000000}{2}"],
ne: ["3000000", "2000001", "1999999", "\\infty", "\\tan(90°)"],
},
{
target: "-2000000",
eq: ["-2\\times10^6", "-\\frac{4000000}{2}"],
ne: ["-3000000", "2000000", "-\\infty"],
},
{
// the old cutoff, values on both sides of it
target: "1497259",
ne: ["1497258", "1497260", "1600000", "\\infty"],
},
{
target: "10^9",
eq: ["1000000000", "10^{9}"],
ne: ["10^{10}", "999999999"],
},
{
label: "large value with a trigonometric function: $target",
target: "2000000\\sin(90°)",
eq: ["2000000"],
ne: ["3000000", "\\infty"],
},
{
target: "\\infty",
eq: [
"\\tan(90°)",
"-\\tan(90°)",
"2\\tan(90°)",
"\\tan(-90°)",
"\\tan(450°)",
"\\tan(3\\pi/2)",
"\\frac{1}{\\cos(90°)}",
"\\frac{1}{\\sin(180°)}",
],
ne: ["2000000", "-\\infty", "\\tan(89°)", "\\tan(45°)"],
},
{
label: "undefined trigonometric value in a sum: $target",
target: "3",
eq: ["\\frac{1}{\\tan(90°)}+3", "3+\\cot(90°)"],
ne: ["\\tan(90°)+3"],
},
{
label: "angles that are only close to a multiple of 90° are not undefined: $target",
target: "\\infty",
eq: ["\\tan(810°)", "\\tan(4590°)", "\\tan(100\\grad)", "\\sqrt{\\tan(90°)}"],
ne: [
"\\tan(1.5708)",
"\\tan(89.9999°)",
"\\tan(89.9995°)",
"\\tan(\\frac{\\pi}{2}+0.00001)",
"\\csc(3.1416)",
],
},
{
target: "\\sin(3.1416)\\cdot10^6",
ne: ["0", "\\infty"],
},
{
label: "angles far from a multiple of 90° are not matched, however large: $target",
target: "\\infty",
ne: ["\\tan(9090.001°)", "\\tan(90089.99°)", "\\tan(1572.367)"],
},
{
target: "0",
ne: ["\\tan(10000000)", "\\tan(3999999)"],
},
{
label: "a replaced zero keeps exact fractions exact: $target",
target: "\\frac{1}{3}",
eq: ["\\sin(0)+\\frac{1}{3}", "\\frac{1+\\sin(0)}{3}"],
ne: ["\\sin(0)+0.3333"],
},
{
target: "-\\frac{1}{3}",
eq: ["\\sin(0)-\\frac{1}{3}"],
},
{
target: "\\frac{5}{6}",
eq: ["\\tan(0°)+\\frac{5}{6}"],
},
{
label: "letters next to a replaced zero are variables, not constants: $target",
target: "\\phi",
eq: ["\\sin(0)+\\phi"],
ne: ["\\sin(0)+1.618"],
},
{
target: "e",
eq: ["\\sin(0)+e"],
},
{
label: "indeterminate results are not equal to each other: $target",
target: "\\tan(90°)-\\tan(90°)",
ne: ["\\tan(90°)-\\tan(90°)+7", "0\\cdot\\tan(90°)"],
},
{
target: "\\frac{\\tan(90°)}{\\tan(90°)}",
ne: ["1", "\\frac{\\tan(90°)}{\\tan(90°)}+5"],
},
{
label: "division by a zero of tan and cot: $target",
target: "\\infty",
eq: [
"\\frac{1}{\\tan(180°)}",
"\\frac{1}{\\tan(\\pi)}",
"\\cot(180°)",
"\\frac{1}{\\cot(90°)}",
],
},
{
target: "0",
eq: ["\\tan(180°)", "\\cot(90°)", "\\cos(90°)\\cdot10^7"],
// indeterminate, not 0
ne: ["\\tan(90°)-\\tan(90°)", "0\\cdot\\tan(90°)"],
},
{
label: "division by zero has no sign: $target",
target: "-\\frac{1}{\\cos(90°)}",
eq: ["\\infty", "-\\sec(90°)", "\\frac{1}{\\cos(90°)}"],
ne: ["-\\infty"],
},
{
target: "\\frac{2}{\\sin(180°)}",
eq: ["\\frac{-2}{\\sin(180°)}", "\\infty"],
},
{
label: "undefined value next to a variable: $target",
target: "x=\\infty",
eq: ["x=\\tan(90°)"],
},
{
target: "x+\\infty",
eq: ["x+\\tan(90°)"],
},
],
};
Loading
Loading