cortex-js / compute-engine

An engine for symbolic manipulation and numeric evaluation of math formulas expressed with MathJSON
https://cortexjs.io
MIT License
375 stars 47 forks source link

Substituting a variable value replaces unrelated variables too #62

Closed aniketkotal closed 1 year ago

aniketkotal commented 1 year ago

@cortex-js/compute-engine: v0.8.0 from npm vue: v3.2.40 Minimal Stackblitz demo: https://stackblitz.com/edit/vue-5kqpdv?file=src/App.vue

What's happening

Substituting any variable, say V, replaces V in unrelated variables such as V_1, V_N

What should happen

Only the substituted variable should be affected

Steps to Reproduce

  1. Create a new ComputeEngine
  2. Parse an equation which has multiple variables with one part same. (ex: V-V_a)
  3. Substitute the variable V with a value.
  4. Evaluate and check the output

Quick Demonstration

Equation: V-V_a Variables: V: 6, V_a: 4 Expected Output: 2 Actual Output: Evaluation: 2-2_{a}

arnog commented 1 year ago

That should be fixed in the main branch.