Skip to content

Commit

Permalink
improve equality checks involving tuples, vectors, intervals, and arr…
Browse files Browse the repository at this point in the history
…ays (#270)
  • Loading branch information
dqnykamp authored Dec 11, 2024
1 parent 2a12c5d commit 5374278
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
}
},
"dependencies": {
"math-expressions": "^2.0.0-alpha71",
"math-expressions": "^2.0.0-alpha73",
"react-router-dom": "^6.26.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,22 @@ describe("Math expressions equality tests", async () => {
symbolicSimplifyEqual: false,
symbolicSimplifyExpandEqual: false,
},
{
expr1: "<math createIntervals>(1,2) union (3,4)</math>",
expr2: "<math>(1,2) union (3,4)</math>",
equal: true,
symbolicEqual: true,
symbolicSimplifyEqual: true,
symbolicSimplifyExpandEqual: true,
},
{
expr1: "<math createIntervals>(1,2) union [3,4]</math>",
expr2: "<math>(1,2) union [3,4]</math>",
equal: true,
symbolicEqual: true,
symbolicSimplifyEqual: true,
symbolicSimplifyExpandEqual: true,
},
];

let doenetML = "";
Expand Down
14 changes: 7 additions & 7 deletions packages/doenetml-worker/src/test/tagSpecific/math.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4142,19 +4142,19 @@ describe("Math tag tests", async () => {
"(a,b)+(e,f)",
);
expect(cleanLatex(stateVariables["/t2isumSimp"].stateValues.latex)).eq(
"(e,f)+(a,b)",
"(a,b)+(e,f)",
);
expect(cleanLatex(stateVariables["/v2isum"].stateValues.latex)).eq(
"(c,d)+(e,f)",
);
expect(cleanLatex(stateVariables["/v2isumSimp"].stateValues.latex)).eq(
"(e,f)+(c,d)",
"(c,d)+(e,f)",
);
expect(cleanLatex(stateVariables["/a2isum"].stateValues.latex)).eq(
"\\langlep,q\\rangle+(e,f)",
);
expect(cleanLatex(stateVariables["/a2isumSimp"].stateValues.latex)).eq(
"\\langlep,q\\rangle+(e,f)",
"(e,f)+\\langlep,q\\rangle",
);
expect(cleanLatex(stateVariables["/st2mul"].stateValues.latex)).eq(
"m(a,b)",
Expand Down Expand Up @@ -4517,25 +4517,25 @@ describe("Math tag tests", async () => {
);
expect(
cleanLatex(stateVariables["/m21t2sumSimp"].stateValues.latex),
).eq("\\begin{bmatrix}e\\\\f\\end{bmatrix}+(i,j)");
).eq("(i,j)+\\begin{bmatrix}e\\\\f\\end{bmatrix}");
expect(cleanLatex(stateVariables["/m21v2sum"].stateValues.latex)).eq(
"\\begin{bmatrix}e\\\\f\\end{bmatrix}+(k,l)",
);
expect(
cleanLatex(stateVariables["/m21v2sumSimp"].stateValues.latex),
).eq("\\begin{bmatrix}e\\\\f\\end{bmatrix}+(k,l)");
).eq("(k,l)+\\begin{bmatrix}e\\\\f\\end{bmatrix}");
expect(cleanLatex(stateVariables["/m12t2sum"].stateValues.latex)).eq(
"\\begin{bmatrix}g&h\\end{bmatrix}+(i,j)",
);
expect(
cleanLatex(stateVariables["/m12t2sumSimp"].stateValues.latex),
).eq("\\begin{bmatrix}g&h\\end{bmatrix}+(i,j)");
).eq("(i,j)+\\begin{bmatrix}g&h\\end{bmatrix}");
expect(cleanLatex(stateVariables["/m12v2sum"].stateValues.latex)).eq(
"\\begin{bmatrix}g&h\\end{bmatrix}+(k,l)",
);
expect(
cleanLatex(stateVariables["/m12v2sumSimp"].stateValues.latex),
).eq("\\begin{bmatrix}g&h\\end{bmatrix}+(k,l)");
).eq("(k,l)+\\begin{bmatrix}g&h\\end{bmatrix}");
expect(cleanLatex(stateVariables["/m22m21sum"].stateValues.latex)).eq(
"\\begin{bmatrix}a&b\\\\c&d\\end{bmatrix}+\\begin{bmatrix}e\\\\f\\end{bmatrix}",
);
Expand Down
11 changes: 6 additions & 5 deletions packages/doenetml-worker/src/utils/checkEquality.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ export default function checkEquality({
return { fraction_equal: 0 };
} else if (vectorOperators.includes(object2_operator)) {
// since we can convert tuple to vector
// change object2 to array of selements
// change object2 to array of elements
// (we also allow vectors and altVectors to be equal to each other. Is that OK?)
object2 = object2.tree.slice(1);
} else {
// since can convert singleton to a vector of length 1
Expand All @@ -378,7 +379,7 @@ export default function checkEquality({
return { fraction_equal: 0 };
} else if (object1_operator === "tuple") {
// since can convert tuple to vector
// change object2 to array of elements
// change object1 to array of elements
object1 = object1.tree.slice(1);
} else {
// since can convert singleton to a vector of length 1
Expand Down Expand Up @@ -412,16 +413,16 @@ export default function checkEquality({
return { fraction_equal: 0 };
}
} else if (object2_operator === "array") {
let operands = object2.tree.slice(1);
let operands2 = object2.tree.slice(1);
if (
operands.length === 2 &&
operands2.length === 2 &&
leftClosed === true &&
rightClosed === true
) {
// since can convert array to closed interval
// and object1 is closed interval
// make object2 be array of endpoints
object2 = operands;
object2 = operands2;
} else {
return { fraction_equal: 0 };
}
Expand Down

0 comments on commit 5374278

Please sign in to comment.