* fix(simplify): Allow simplify to work in arrays, objects, and indexing
Mostly ArrayNode, ObjectNode, AccessorNode, and IndexNode nodes are
simply transparent to simplification -- they simply allow it to occur
within subexpressions. Then main exception is that if an array or object
is indexed by a constant, the expression can be replaced by the
corresponding subitem, e.g. `[3,4,5][2]` simplifies to `4`.
This at least partially resolves#1913 (see my latest comment there).
* fix(simplify): Resolve operations on constant arrays
This involves allowing ArrayNodes containing only constant entries
to temporarily convert to Matrix type inside of simplifyConstant, so that
function and operator calls can occur on them.
I also had to add a special case for the function `size` because
it can be computed even on symbolic arrays, since the result depends
only on the shape, not the entries.
Deals with additional cases of #1913; unclear if there are remaining
aspects of that issue on which further work is desirable.
* chore: fix alphabetization of dependencies
And restores inadvertent deletion of a blank line.
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
The key is that the rule-matching engine is optimized for finding matches
on the lefts of terms, but the central term-collection rule
`n1*n3 + n2*n3 -> (n1+n2)*n3` was written with the key common term rightmost.
Reversing this rule to `n3*n1 + n3*n2 -> n3*(n1+n2)` therefore does most
of the work of improving like-term collection. It also better corresponds
to typical mathematical presentation: common terms tend to be pulled out
to the left in common practice.
Floating constants to the right of a product initially (before they are
moved back to the left for human-preferred output) and ensuring that
negations are subsumed into constants whenever possible did the rest.
Also, rule context was not being propagated into the simplification
engine; this commit corrects that.
Resolves#1179.
Resolves#1290.
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* fix(simplify): Leave string constants as strings.
Note that because the `size` built-in function called on a string returns
a Matrix, which is represented in math.js expressions as an Array, this
commit has to add ArrayNode as a dependency of `simplify` (and hence
also of `rationalize`).
In addition, it requires changing the handling of ArrayNodes
and AccessorNodes in `simplifyConstant` from "unimplemented" to just a
pass-through (since a full implementation of simplification in Arrays and
indexing seemed beyond the scope of this change, but `simplify` must not
throw an error on `size("foo")`). Hence, this commit also adds skipped unit
tests for some expressions with arrays and indexing that should ultimately
simplify.
It also removes the skip on the test group "should not change the value of
numbers when converting to fractions (3)" since all of those tests already
appear to pass.
Resolves#2152.
Changes the behavior in #1913 from throwing an error to allowing Arrays and
indexes but not simplifying inside them.
* chore: Fix lint and remove explanatory comment
* refactor(gamma function): use lanczos approximation with comments
* tests: additional checks for specific numbers
* tests: check for value close to re(0.5)
* refactored intersect, fixed it not returning null for matrix input
* intersect: improved flattening algorithm, added tests
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* Add support for scopes with get and set methods
* Fix build for node v12
* Fixup cli and parser tests
* Add tests for simplify and evaluate
* Add example for a custom scope object
* Function calls need child scopes
* Transitionary step: Separate Safe and Scope Property calls
* Renamed identifiers in FunctionNode
* Evaluate with ObjectScopeWrapper
* Simplify tests passing
* Assume all scopes are map-like. Except parser
* Remove isMapLike check in customs.*SafeProperty() methods
* Change MapLike to Map
* Move keywords from an Object to a Set
* Move ScopeProperty functions in to scope.js
* Removed deprecation warning
* Rename scope.js to map.js
* Rename ScopeProperty to MapProperty
* Add tests and docs for map.js
* Put back the micro-optimization of function calls
* Use Map in the parser
* Called scope methods directly in cli.js
* Coercing of scope into a Map is done in Node, not evaluate
* Move createSubScope to its own file
* Fixup following self-review
* Add scope docs
* Final self-review changes
* Address reviewer comments
* Remove MapProperty witness marks
* Converted broken benchmark possibly lost in a rebase
* Use bare map as scope in benchmark
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* made dense and sparse matrices iterable, fixed#1184
* added matrixFromFunction, fixes#2153
* added tests for matrixFromFunction
* added matrixFromRows
* added matrixFromColumns
* added rows() and columns() for dense matrix
* improved sparse documentation a tiny bit
* fix linting issues
* added matrixFromRow/Column to seealso of row and column
* removed unnecessary duplication from matrixFromRows/Columns
* added babel runtime
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* split the eigs function into multiple algorithms
* moved checks and coersions to eigs.js, made them more robust
* fix little bugs, make im and re more robust
* Implemented matrix balancing algorithm
* fix typos
* a draft of reduction to Hessenberg matrix
* finished implementation of reduction to Hessenberg
* fix Hessenberg elimination for complex numbers
* implemented non-shifted explicit QR algorithm for real matrices
* implemented vector computation, won't work untill usolve is fixed
* refactored to match yarn lint
* some minor changes
* solve merge conflicts
* refactored and re-fixed #1789
* some old uncommited changes
* fix small problems introduced by merging
* done some polishing
* improved jsdoc description of eigs
* little changes in jsdoc
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* Miller–Rabin primality test
* add tests for some big numbers
* Update isPrime.js
* Update isPrime.js
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* added support for word size suffix in getToken
* start modifying number(string) to support word size suffix for signed integers
* word size suffixes for Number
* initial support for BigNumber
* fix linter issues
* remove unused variable
* start extending bitwise operators for Number for values greater than 32 bits
* Revert "start extending bitwise operators for Number for values greater than 32 bits"
This reverts commit 6fac1a7b10665a221ab5de521c08fa9fcf959eb1.
* add a test for 53 bit literal
* added an optional second argument to bin, oct, and hex to allow formatting signed numbers with custom word size
* removed size checks
* Attempted to extend bin, oct, hex format functions to work with BigNumber, but not working fully.
Apparently Decimal.js toString method doesn't take a base parameter like js number does. I guess I have to do the formatting myself.
* Added n2base function to do formatting for BigNumber.
* Added check for zero in n2base.
* Removed old failing tests.
* Added some tests (failing).
* Extended 'format' function with 'base' and 'wordSize' options and changed 'bin', 'oct', and 'hex' to use 'format' function.
* Fixed lint issues.
* Fixed issues related to the merge.
* Corrected a test.
* Fixed bignumber formatter.
* Added tests for math.format with 'base' and 'wordSize' options.
* Fixed lint issue.
* Changed 'base' option to 'bin', 'oct', and 'hex' values for 'notation' option of 'format' function.
* Added word size suffix to the output of format, bin, oct, and hex.
* Updated documentation.
* Update clone.js with doc about deep copying arrays
Since it was missing, and it is important documentation for anyone using math.clone for arrays of arrays (matrices). The deep copying was inferred from the test case, but it shouldn't have been necessary. Now it will hopefully be shown in the doc on the webpage, too.
* Update description to be more general.
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* emplementing rotate(w, theta)
* will return same type as input
* edge cases arraySize
* rising coverage
* making result type predictable
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>