josdejong / josdejong/mathjs

feat: add notation for array simplification rules

Open
#2,390 4 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
JavaScript
Stars
15.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Although #1913 is closed, the discussion there raised the possibility of extending array simplification to handle something like `x*[3/x, 7]` simplifying to `[3, 7x]`. One ingredient for this was a complexity measure to guide the application of a rule (see #2389), but in addition to have such rules there would need to be some notation for rules that handle matrices.

For example, right now one could try using a rule `[n3*n1, n3*n2] -> n3*[n1,n2]` and might reasonably expect it to rewrite `[x*y, x*z]` to `x*[y, z]` but whatever the details of rule application are right now, it doesn't have any effect. And that particular point aside, it would be impossible to specify not only this but `[n4*n1, n4*n2, n4*n3] -> n4*[n1,n2,n3]` and `[n3*n1; n3*n2] -> n3*[n1; n2]` and so on for every possible shape of array.

Hence some notation that can express rules for arbitrarily shaped arrays would be needed to extend the existing array simplification rules (which are primarily incorporated into the simplifyConstant function). One can imagine it could look something like `[n*a_i] -> n*[a_i]` where "a" is a special letter, like the existing "n", "c", and "v", standing for an array entry, with the convention that each entry of the array can separately match a symbol starting with "a" (whereas there must be only one distinct match to "n" as usual). We might also want to be able to write something like `[a1_i] + [a2_i] -> [a1_i + a2_i]`. This is not a fully fleshed-out proposal, and any suggestions on how to make it more complete and concrete would be very welcome.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.