189 Commits

Author SHA1 Message Date
Jos de Jong
d1ecf44e2f fix: #3253 cannot use identifiers containing special characters in function derivative 2024-09-04 12:19:46 +02:00
David Contreras
bcf0da46f0
feat: support multiple inputs in function map (#3228) 2024-08-22 13:35:21 +02:00
David Contreras
459ae13725
docs: spelling fixes in the embedded docs (#3252)
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-08-21 14:30:40 +02:00
David Contreras
c8e4bbd573
fix: function map not always working with matrices (#3242)
* Removed maxArgumentCount in favor of applyCallback

* Making a pure _recurse function

* Added cbrt tests, removed unnecesary changes in functions.

* Fixed main bottleneck

* Restored back function before unintended change

* Fix format

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-08-01 15:54:20 +02:00
David Contreras
cf24943d4c
feat: add matrix datatypes in more cases (#3235) 2024-07-30 19:48:19 +02:00
Vistinum
975d1ba800
fix: use exact values for US liquid volume units (#3229)
1 US gallon is defined as 231 cubic inches, which is exactly 3.785411784 L (since 1 inch is defined as 25.4 mm). Other units are defined against the gallon.

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-07-11 13:16:46 +02:00
David Contreras
5785cb95f1
Broadcast refactor (#3220) 2024-06-19 18:51:37 +02:00
Jos de Jong
ab3461d484
feat: implement support for bigint (#3207, #2737) 2024-05-31 12:43:09 +02:00
Jos de Jong
1f05a35d68
chore: convert CJS files to ESM (#3204) 2024-05-22 08:46:14 +02:00
Jos de Jong
31b68ced13 chore: adjust isPositive, isNegative, and isZero to the new relTol and absTol 2024-05-15 11:12:19 +02:00
David Contreras
eded7e1dc3
feat: nearly equal with relative and absolute tolerance (#3152)
* nearlyEqual with absolute and relative tolerances

* Format

* nearlyEqual for bigNumber

* Added skip for NaN

* Reduce diff a bit

* Issue with examples in jsdcos

* Updated all calls for nearlyEqual

* Fixed failing tests

* Changed epsilon to relTol, absTol

* Changed references to epsilon in docs and tests

* Added warning for config.epsilon

* Fix warning in zeta.test

* Added config test

* Added sinon to test console.warn

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-05-15 10:56:11 +02:00
Jos de Jong
5ee9f6f8d6 Merge branch 'refs/heads/develop' into v13 2024-05-15 10:51:15 +02:00
Laurent Gérin
81d2e71445
fix #3192: function isNaN returns false for NaN units in a matrix or array
* Use referToSelf() to recursively check if various types are NaN in an array or matrix

* fix array test description from isNegative to isNaN

* Add test for units in a matrix

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-04-24 09:31:06 +02:00
Jos de Jong
a41def8360 fix: #3172 simplify "true and true" 2024-03-13 14:25:56 +01:00
Jos de Jong
f37d4154ad Merge branch 'develop' into v13 2024-02-22 17:19:48 +01:00
Jos de Jong
f504ffe1d3 chore: update devDependencies (most notably eslint) 2024-02-22 16:27:24 +01:00
Brian Fugate
85b65da6cb
Fix: #3100 function round not handling round-off errors (#3136)
* Fixing rounding bug from issue 3100

* Corrected syntax and converted if...else to logic using ternary operator

* Removing nearlyEqual comparison because a false
return value was mathematically impossible by
user input.

Adding dynamic epsilon logic to cover cases when
a user requests to round a number to a higher
precision than epsilon in the config file.

Also adding tests to cover dynamic epsilon cases.

* Removing dynamic epsilon and adding test for changing config.epsilon during runtime

* Reintroducing nearly equal verification for
round function.

Adding test case for changing epsilon at runtime.

Both tests for changing epsilon at runtime also
verify the false nearlyEqual scenario.

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-02-22 16:17:05 +01:00
David Contreras
e1817baa0b
Determinant with small numbers fix (#3139) 2024-02-14 17:49:07 +01:00
Jos de Jong
c60f637a60 fix: #3142 support BigNumber values for the options of function format: precision, wordSize, lowerExp, upperExp 2024-01-31 10:58:42 +01:00
Carl Osterwisch
f89e3cbbff
Unitless quantity conversion bug (#3117)
* Add test for conversion to unitless quantity

* Avoid access to missing array index

* Also check that other.units is not empty

* Add test for abs of dimensionless unit

* Fix: avoid access to missing units array index

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2024-01-10 17:53:18 +01:00
Jos de Jong
b9346720d6
feat: extend function round with support for units (#3095)
* fix #2761: implement support for units in function `round` (WIP)

* fix #2761: extend function `round` with support for units

* docs: describe all signatures in the docs of function round

* chore: fix linting issue

* chore: remove less-useful signatures for round with units and matrices
2023-11-17 10:15:17 +01:00
Jos de Jong
a1f3b7c6bf fix #3094: function derivative mutates the input expression when it fails 2023-11-15 12:39:04 +01:00
Jos de Jong
3d84b5b594 fix #3092: a typo in an error message when converting a string into a number 2023-11-09 09:25:43 +01:00
Jos de Jong
8679c07617 fix #3087: extend function mod with support for negative divisors in when using BigNumber or Fraction 2023-11-08 11:29:48 +01:00
Jos de Jong
3030c6b23f Merge branch 'develop' into v12
# Conflicts:
#	HISTORY.md
2023-10-26 10:50:07 +02:00
Vrushaket Chaudhari
8f8e506166
feat: implement subtractScalar (#3081, #2643)
* added subtractScaler

* added subtractScaler missing entries

* added test cases for 2 or more parameters, test for subtractScalar instead fo subtract

* replaced subtract with subtractScalar whereever possible

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-10-25 13:46:58 +02:00
Glen Whitney
fba5baff5e
feat: Add option to eigs() to turn off eigenvector computation (#3057)
* feat: Add option to eigs() to turn off eigenvector computation

  For large matrices, the eigenvector computation can be noticeably expensive
  and so it's worthwhile to have a way to turn it off if the eigenvectors
  will not be used.
  Resolves #2180.

* fix: Add test for precision in options arg of eigs

  And also a fix for a small bug that the new test uncovered.

* test: check eigs with matrix and options

* refactor: remove dead code from complexEigs.js

* fix: add new signatures of eigs to typescript

* test: ensure eigenvectors property not present with eigenvectors: false option

* fix: correct balancing code in complexEigs
2023-10-20 14:04:23 +02:00
Jos de Jong
1fb50b1163 Merge branch 'develop' into v12
# Conflicts:
#	HISTORY.md
2023-10-11 15:30:06 +02:00
Jos de Jong
7b9defb9ff fix: #3074 improve error message when using function max in derivative 2023-10-11 11:42:20 +02:00
Glen Whitney
b54aefb3f3
fix: Find eigenvectors of defective matrices (#3037)
* fix: Find eigenvectors of defective matrices

  Previously, attempting to take the `eigs` of any defective matrix
  was doomed to fail in an attempt to solve a singular linear system.
  This PR detects the situation (as best as it can given the
  inherent numerical instability of the current methods used) and
  handles it. Note that in such cases, it's not possible to return
  a square matrix whose columns are the eigenvectors corresponding to
  the returned eigenvalues. In light of that fact and issue #3014, this
  PR also changes the return value of `eigs` so that the eigenvectors
  are passed back in a property `eigenvectors` which is an array of
  plain objects `{value: e, vector: v}`.

  Note that this PR makes the ancillary changes of correcting the
  spelling of the filename which was "realSymetric.js," and replacing
  the now-unnecessary auxiliary function "createArray" therein with
  `Array(size).fill(element)`. The rationale for performing these
  changes not strictly related to the issues at hand is that this
  file is rarely touched and with the level of maintenance hours we have
  at hand, it's more efficient to do these small refactorings in parallel
  with the actual bugfixes, which are orthogonal and so will not be
  obfuscated by this refactor. Note `git diff` does properly track the
  file name change.

  However, it also makes a potentially more pervasive change: in order for
  the numerically-sensitive algorithm to work, it changes the condition
  on when two very close (double) numbers are "nearlyEqual" from differing by
  less than DBL_EPSILON to differing by less than or equal to DBL_EPSILON.
  Although this may change other behaviors than the ones primarily being
  addressed, I believe it is an acceptable change because

  (a) It preserves all tests.
  (b) DBL_EPSILON is well below the standard config.epsilon anyway
  (c) I believe there are extant issues noting the odd/inconsistent
      behavior of nearlyEqual near 0 anyway, so I believe this will
      be overhauled in the future in any case. If so, the eigenvector
      computation will make a good test that a future nearlyEqual
      algorithm is working well.

  To be clear, the direct motivation for the change is that there are
  multiple cases in the eigenvector computation in which a coefficient
  that is "supposed" to be zero comes out to precisely DBL_EPSILON, which
  is fairly unsurprising given that these coefficients are produced by
  subtracting an eigenvalue from a diagonal entry of a matrix, which is
  likely to be essentially equal to that eigenvalue.

  As many tests of defective matrices as I could readily find by web
  searching have been added as unit tests (and one more in the typescript
  type testing). An additional case I found still fails, but in the
  _eigenvalue_ computation rather than the _eigenvector_ search, so that
  was deemed beyond the scope of this PR and has been filed as issue #3036.

  Resolves #2879.
  Resolves #2927.
  Resolves #3014.

* refactor: remove comma that lint now doesn't like

* test: add a test for eigs with a precision argument

* feat: Use simple shifts in QR eigenvalue iterations that improve convergence

  Although we might want to use better shifts in the future, we might just
  use a library instead. But for now I think this:
  Resolves #2178.

  Also responds to the review feedback provided in PR #3037.
2023-10-05 11:24:51 +02:00
Vrushaket Chaudhari
abf9c9fade
fixed matrix issue in correlation function + error handling (#3030)
* fixed matrix issue in correlation function + error handling

* fixed syntax error in correlation function documentation

* changed error to syntax error

* added test cases for error handling

* added test cases for error handling v2

* fixed issue in test cases for error handling v2

* fixed issue in test cases for error handling v2.1

* fixed issue in test cases for error handling v2.2

* removed math.matrix examples

* removed redundant code
2023-09-20 11:26:37 +02:00
Praise Nnamonu
1465ac7bbb
Fix round-off errors in mod() (#3011)
* changes made to the following files:

- mod.js

- gcd.js

* updated BigNumber implementation and added validating tests

* added validating test cases

* updated test cases

* formatted code

* Made updates according to requirement

used mathjs floor in mod.js

imported mod in gcd.js

made mod work for negative divisors

wrote and updated tests to validate new behavior

* updated mod in arithmetic.js

* added tests for modNumber function

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-09-20 09:24:17 +02:00
David Contreras
c35a8019ee
Print one based in the parser (#3009)
* broadcasting

* Simplified broadcasting

* Updated for broadcasting

* Changed to camel case

* Camel case and auto formating

* Added comments

* Skip if matrices have the same size

* Fixed issue with undefined variable

missing dot  in `A._size`

* Implemented broadcasting in all functions

* Added helper functions

* Added function to check for broadcasting rules

* Tests for broadcasted arithmetic

* Fixed issue with matrix the size of a vector

* Documented and updated broadcasting

* Included broadcast.test

* Included math to syntax when missing

* Added print transform and tests

* Simplify conditional

* Included regex in an util

---------

Co-authored-by: David Contreras <david.contreras@guentner.com>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-09-06 11:21:59 +02:00
Vrushaket Chaudhari
1ee8733832
added correlation function to statistics (#3015)
* added correlation function to statistics

* added implemenation for signature Matrix, Matrix and support for BigNumbers

* reverted changes to default for version numbers of devDepenencies

* reverted changes to default for version numbers of devDepenencies in package-lock.json

* change variable name from xArray, yArray to x and y

* added Matrix as param in index.d.ts

* corrected the file and function names for correlation function

* renamed createCorrelation to createCorr in factoriesNumber.js

* fixed failing test case for matrix and added params and return in corr
2023-09-01 13:38:49 +02:00
Jos de Jong
e36f90e1a8
Implement function Riemann Zeta (#2975, #2950)
* Riemann Zeta Function

* Big Number zeta and added docs

* Original algorithm paper credited

* Update index.d.ts

* Update riemannZeta.js

* Update index.d.ts

* Renamed files to reflect zeta

* chore: make all the tests pass

* chore: refactor `zeta` (WIP)

* chore: reuse the validation logic of both number and BigNumber

* fix: type definitions of `zeta`

* fix: test the accuracy with numbers and BigNumbers (WIP)

* chore: make linter happy

* docs: fix example outputs

* docs: update history

* docs: update history

* docs: describe the limited precision of `zeta`

---------

Co-authored-by: BuildTools <anikpatel1322@gmail.com>
Co-authored-by: Anik Patel <74193405+Bobingstern@users.noreply.github.com>
2023-08-23 15:50:11 +02:00
David Contreras
3ab9bc1ea3
Extend quantileSeq with support for a dimension (#3002)
* Included math to syntax when missing

* Included solveODE

* renamed initialStep as firstStep

* Included tests for solveODE

* Test the full state instead of the final state

* Fixed issue with tolerance

* Added unit signature for y0

* Included units test also for y0

* Included embedded docs and more tests

* Included error for tspan

* It works with bignumbers

* reduced calling bignumber

* extended the search for bignumbers

* The jsdocs is less ambiguous

* included tests for step options

* Allowed for 0 minStep

* Optimization to avoid checking the sign every step

* added dim to quantile

* Included transform

* Removed modification of the docs

I made an unwanted modification

---------

Co-authored-by: David Contreras <david.contreras@guentner.com>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-08-23 12:36:54 +02:00
David Contreras
49c793ba5a
feat: Indexing with an array of booleans (#2994)
* Included math to syntax when missing

* Included solveODE

* renamed initialStep as firstStep

* Included tests for solveODE

* Test the full state instead of the final state

* Fixed issue with tolerance

* Indexing with an array of booleans

* Indexing with booleans and with empty

* Changed index embedded docs

* removed solveODE

* typos on tests

* included config.predictable

* Throws an error if the size doesn't match

* Included config predictable to get subset

* Can do replacement by broadcasting

* DenseMatrix set can broadcast first

* Added tests for broadcasted subset in the parser

* Faster cloning of deep arrays

* Included docs and better test coverage

* Test coverage for `subset`

* Removed config predictable from subset

* Removed config from index and sparseMatrix

* Redaction and typos

* Cleanup unnecesary changes

* fixed issue when there is no need to broadcast

* Inline ifs

* Included specific broadcasting test

* Reduced repetition

---------

Co-authored-by: David Contreras <david.contreras@guentner.com>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-07-28 09:30:04 +02:00
Jos de Jong
a30d1f8ce6
fix: #2990 DenseMatrix can mutate input arrays (#2991)
* fix: #2990 DenseMatrix can mutate input arrays

* chore: simplify internal function `preprocess`

* chore: document ugly workaround of using `matrix.subset` to mutate a nested Array

* chore: better solution for `assign`

* chore: fix linting issue

* chore: add a unit test for `multiply` testing whether the operation is immutable

* chore: fix linting issue

---------

Co-authored-by: Glen Whitney <glen@studioinfinity.org>
2023-07-27 11:42:36 +02:00
David Contreras
8fe5e517d6
feat: support units in range (#2997)
* reange refactoring

* update authors

* Made _range to work also for _bigNumbers

* Range with units

* Included some Unit type in _range

* Included TypeScript types for function range

* Formatting

---------

Co-authored-by: David Contreras <david.contreras@guentner.com>
2023-07-19 11:55:53 +02:00
Aly Khaled
8475ab997b
zpk2tf and freqz functions implementation (#2988)
* Add Zpk2tf function

* Add zpk2tf function documentation

* Fix

* Add freqz function implementation

* Fix format

* Add freqz function documentation

* Fix

* Fix format

* Update index.d.ts

* Fix Dependency error

* Fix

* Fix index.d.ts

* Fix Documentation

* Fix Lint

* Fix index.d.ts

* Fix The Matrix parameter support and index.d.ts

* Fix Format

* Add Unit Tests for Matrix cases

* Fix Docs and Lint

* Add tests for coverage

* Fix Format

* Update AUTHORS

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-07-13 17:23:50 +02:00
David Contreras
1aed900cc0
feat: implement solveODE (#2958)
* Included math to syntax when missing

* Included solveODE

* renamed initialStep as firstStep

* Included tests for solveODE

* Test the full state instead of the final state

* Fixed issue with tolerance

* Added unit signature for y0

* Included units test also for y0

* Included embedded docs and more tests

* Included error for tspan

* It works with bignumbers

* reduced calling bignumber

* extended the search for bignumbers

* The jsdocs is less ambiguous

* included tests for step options

* Allowed for 0 minStep

* Optimization to avoid checking the sign every step

---------

Co-authored-by: David Contreras <david.contreras@guentner.com>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-07-12 14:28:10 +02:00
MaybePixem
aa819fac6a
fix: #2974 Simplify puts plus and minus signs next to eachother (#2981)
* adjust simplify rules

* fix formatting

* move rule back

* move rule
2023-07-05 13:54:01 +02:00
Kiku
1b06ec4b81
fix #2964: distance from point to line (#2965)
some additional unit tests, types and doc fix for distance function

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-06-13 11:02:57 +02:00
Michael Greminger
6fa589057e
Big Number Format Fixes (#2956)
* test: format bignumber to engineering bug

Add tests for correctly handling starting with more then 3 sig figs and targeting 1 or 2 sig figs

* lint:

* lint: reduce number literal sig figs

* fix: engineering notation for bignumber input

Corrects handling of cases where the input has 3 or more sig figs and the output is set to 1 or 2 sig figs.

* test: add negative format bignumber precision test

* fix: use BigNumber for all branches in toEngineering

Also, remove string type option from JSDoc for toEngineering since string does support the required interface for the function (the .e property, .mul member function, and the .constructor property would not be correct after this change)

* fix: precision 0 for fixed notation and bignumber

This fix differentiates precision === 0 and precision === undefined to.
After fix, format bignumber for precision 0 matches format number for precision 0.

Tests added as well

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-06-13 10:39:44 +02:00
Jos de Jong
3c59d1a9ca
fix: #2880 not possible to map cube root cbrt (#2966)
* fix: #2880 not possible to map cube root `cbrt`

* fix: bind signature, add comments
2023-06-08 10:04:29 +02:00
Jakub Riegel
3b89324111
#2567: accept array as parameter for gcd() (#2878)
* #2567: accept array as parameter for gcd()

* #2567: accept 1d matrix as gcd() argument

* #2567: support nested 1d array in gcd

* #2567: simplify matrix signature

* [fix] intersect method parameter type (#2897)

* Update history and authors (see #2897)

* feat: added chirp-z transform to calculate non-power-of-2 fft (#2900)

* added chirp-z transform to calculate non-power-of-2 fft

* simplify/remove _ifft function inside _czt function

* chore: remove an unused dependency from `simplifyConstant`

* fix: quantileSeq not accepting a matrix as second argument `prob` (see #2902)

* fix a broken example of function `to`

* fix a typo in the examples functions `distance`, `getMatrixDataType`, `subset`, and `max` (see #2902)

* fix linting issue

* Broadcasting (#2895)

* broadcasting

* Simplified broadcasting

* Updated for broadcasting

* Changed to camel case

* Camel case and auto formating

* Added comments

* Skip if matrices have the same size

* Fixed issue with undefined variable

missing dot  in `A._size`

* Implemented broadcasting in all functions

* Added helper functions

* Added function to check for broadcasting rules

* Tests for broadcasted arithmetic

* Fixed issue with matrix the size of a vector

* Documented and updated broadcasting

* Included broadcast.test

---------

Co-authored-by: David Contreras <david.contreras@guentner.com>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>

* Update history and authors

* Update devDependencies

* publish v11.6.0

* fix #2906: improve description of the behavior of `subset` for scalar values in the docs

* fix #2907: determinant of empty matrix should be 1

* chore: add a few more unit tests to `det`

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
Co-authored-by: Jaeu Jeong <wodndb@gmail.com>
Co-authored-by: cyavictor88 <100557319+cyavictor88@users.noreply.github.com>
Co-authored-by: David Contreras <dvd.cnt@gmail.com>
Co-authored-by: David Contreras <david.contreras@guentner.com>
2023-03-09 10:56:18 +01:00
Jos de Jong
0e777bf619 chore: add a few more unit tests to det 2023-02-28 10:02:24 +01:00
Jos de Jong
00cee87597 fix #2907: determinant of empty matrix should be 1 2023-02-28 10:00:37 +01:00
David Contreras
f8013cc99a
Broadcasting (#2895)
* broadcasting

* Simplified broadcasting

* Updated for broadcasting

* Changed to camel case

* Camel case and auto formating

* Added comments

* Skip if matrices have the same size

* Fixed issue with undefined variable

missing dot  in `A._size`

* Implemented broadcasting in all functions

* Added helper functions

* Added function to check for broadcasting rules

* Tests for broadcasted arithmetic

* Fixed issue with matrix the size of a vector

* Documented and updated broadcasting

* Included broadcast.test

---------

Co-authored-by: David Contreras <david.contreras@guentner.com>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-02-23 19:24:55 +01:00
Jos de Jong
99829d311b fix linting issue 2023-02-23 17:08:48 +01:00