Skip to content

fix: pick up math-expressions fix for lost matrix entries of -1 - #1729

Merged
dqnykamp merged 1 commit into
Doenet:mainfrom
dqnykamp:bump-math-expressions-alpha96
Aug 20, 2026
Merged

dqnykamp merged 1 commit into
Doenet:mainfrom
dqnykamp:bump-math-expressions-alpha96

Conversation

@dqnykamp

Copy link
Copy Markdown
Member

Bumps math-expressions from 2.0.0-alpha95 to 2.0.0-alpha96, which fixes wrong answers and a hard failure in matrix, vector, and tuple arithmetic.

The bug

<matrix name="A"><row>-1 5</row><row>-1 -3</row></matrix>
<matrix name="B"><row>-2 -1</row><row>-3 -5</row></matrix>
<matrix name="C"><row>-2 -4</row><row>1 -1</row></matrix>

<math name="ans" simplify>$A + $B - $C</math>
$ans.matrix[2][2]

The (2,2) entry came out as -8 instead of -7. With different numbers — an <answer> checking a student's matrix, say — the same document instead failed with TypeError: Cannot read properties of undefined (reading '0') and rendered nothing.

Both come from one defect in the simplifier. Distributing the minus sign over C's entries turns the -1 entry into the product (-1)(-1); the pass that merges numeric factors omitted a coefficient of 1 from its result, which for a product of nothing but numbers left an empty multiplication that later evaluated to undefined. The entry then vanished from its sum. Which symptom the reader saw depended on how the remaining addends sorted around the missing one: a negative partial sum silently dropped it, a positive one dereferenced it and threw.

Ordinary scalar arithmetic never hit this, since numbers are evaluated before the pass runs. Only products built afterwards — those from distributing a scalar over a matrix, vector, or tuple — could reach it, so entries of -1 in a subtracted matrix were the common trigger.

Fixed upstream in Doenet/math-expressions#89, released as 2.0.0-alpha96.

Verification

Both documents now give [[-1, 8], [-5, -7]] and [[9, 2], [-7, -4]], with $ans.matrix[2][2] reading -7.

matrix, matrixinput, math, and the linearAlgebra suites pass against the new version.

🤖 Generated with Claude Code

Subtracting a matrix with an entry of -1, as in

    <math simplify>$A + $B - $C</math>

either gave a wrong entry or failed with an internal error. Distributing
the minus sign over the entries produced the product (-1)(-1), which
simplified to an empty product rather than to 1, so the entry dropped out
of the sum. Tuples and vectors were affected the same way.

Fixed upstream in math-expressions 2.0.0-alpha96.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01563D3v3KXwuRLmni12AuvU
@dqnykamp
dqnykamp merged commit 35acd91 into Doenet:main Aug 20, 2026
24 checks passed
@dqnykamp
dqnykamp deleted the bump-math-expressions-alpha96 branch August 20, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant