cortex-js / compute-engine

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

Extending Summation and Product Functionality #137

Closed emily0622 closed 9 months ago

emily0622 commented 9 months ago

Description

Extends the functionality of summations. Before this pr the summation could only handle a single index in the form var=num in the subscript, now it can handle multiple indexes. It can parse summations that include boxed expressions such as 'Element' and 'Unequal', as well as solve numeric equations.

Fixes

This pr addresses the issues discussed in: https://github.com/cortex-js/compute-engine/issues/133

Examples

The following are some examples of test cases added from test/compute-engine/latex-syntax/arithmetic.test.ts

Parsing Examples

  1. $$\sum{n,m} k{n,m}$$ ["Sum", ["Subscript", "k", ["Delimiter", ["Sequence", "n", "m"], "','"]], "n", "m"]

  2. $$\sum_{n=0,m=4}^{4,8}n+m$$ ["Sum", ["Add", "m", "n"], ["Triple", "n", 0, 4], ["Triple", "m", 4, 8]]

  3. $$\sum_{n \in N}K_n$$ ["Sum", "K_n", ["Element", "n", "N"]]

Evaluating Examples

1. $$\sum_{n=0,m=4}^{4,8}{n+m} => 200$$

2. $$\sum{n=0}^{4}\sum{m=4}^{8}{n+m} => 200$$

arnog commented 9 months ago

Great job on this! Thank you so much for the PR. Super useful and I'm sure many people will enjoy it.