484 Commits

Author SHA1 Message Date
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
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
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
76c4811484 fix: #3088 error in the description of the return type of pickRandom 2023-11-01 12:36:15 +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
Jos de Jong
fd5a6f7f17 chore: update history, reorder comment 2023-09-20 09:53:11 +02:00
David Contreras
dcf12c4cec
Quantile-refactor (#3003)
* 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

* refactor

* Typo

* removed unnecesary error

* Fixes conflict with develop

* Merge logic on _quantileSeqProbNumber

* Reduced _quantileSeqProbCollection

* Merged logic of _quantileSeq

* Fixed issue with transform and browser

---------

Co-authored-by: David Contreras <david.contreras@guentner.com>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-09-20 09:48: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
386c280280 docs: define see also sections for erf and zeta 2023-08-30 11:25:48 +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
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
7923d58e2e
Range refactoring (#2995)
* reange refactoring

* update authors

* Made _range to work also for _bigNumbers

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-07-13 17:02:18 +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
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
David Contreras
24a8087499
Included math to syntax when missing (#2941) 2023-05-15 20:01:44 +02:00
TMTron
c97e0be8b7
fixed #2923: [DOC] distance syntax is wrong (#2924)
* fixed #2923: [DOC] distance syntax is wrong

* fixed #2923: [DOC] distance syntax is wrong
* added detailed syntax descriptions
2023-03-29 15:19:51 +02:00
Jos de Jong
151baca0af fix #2908: improve docs and examples of functions partitionSelect, diff, expm1, round, nthRoots, sign, rigthArithShift, setIsSubset, setSize, and the docs about units 2023-03-09 11:54:45 +01: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
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
9669734cb4 fix a typo in the examples functions distance, getMatrixDataType, subset, and max (see #2902) 2023-02-23 17:04:53 +01:00
Jos de Jong
9bacfebd8d fix a broken example of function to 2023-02-23 16:51:34 +01:00
Jos de Jong
f865658339 fix: quantileSeq not accepting a matrix as second argument prob (see #2902) 2023-02-23 16:48:56 +01:00
Jos de Jong
d7ad001550 chore: remove an unused dependency from simplifyConstant 2023-02-23 16:35:08 +01:00
cyavictor88
517187131d
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
2023-02-23 15:40:08 +01:00
Jos de Jong
68b4b503f7 Fix #2891: functions column and row sometimes returning a scalar number 2023-02-02 12:29:52 +01:00
Jos de Jong
a012c1ee25 fix #2883: add missing syntax for statistical functions in docs 2023-01-23 10:55:27 +01:00
Samuel TLG
ec10a90635
Simplify: add rules and restructure tests for noncommutative contexts (#2847)
* Simplify: add two (term collection) noncommutative context std. rules

These additions permit the valid application of rules to exprs
including:
- For new rule 'vd + n*vd -> (1+n)*vd'
'a+2*a' ->  '(1+2)*a'

- And new rule 'cd + cd*n -> cd*(1+n)'
'4+4*b' ->  '4*(1+b)'

* Simplify: add non-commutative context term factoring rule

'n^n1 * n -> n^(n1+1)'

Also updates extant NC-context simplify tests which now apply this rule
successfully

* Add and restructure non-default context simplify tests

In addition to refactoring and splitting current tests into
describe/it blocks, also adds test block:
'should still validly apply (term factoring and collection) rules'

For ensuring simplify rules marked with
'context.[add/multiply].commutative: false' apply; simultaneously
validating that simplifications still occur as expected in these
contexts.

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2022-12-05 10:37:16 +01:00
Jos de Jong
27ffc7887e fix: function reshape mutating the original matrix (see #2854) 2022-12-05 10:15:09 +01:00
Jos de Jong
27a91b369d docs: add code styling consistently in the format docs 2022-11-29 13:43:29 +01:00
Samuel TLG
76c8c6264c
Improve standard simplify rule matches in non-commutative contexts (#2841)
* Improve standard simplify rule matches in non-commutative contexts

Addresses the rule application limitation aspect as highlighted in
issue #2825; such that a broader set of successful standard replacement
rules are applied to multi-arg/associative expressions in
non-commutative contexts.

* Remove 'clone()' operations on expanded simplify rules

since original rule nodes (including expanded variations) are essentially
readonly objects, cloning of expanded rule LHS' is unnecessary during
canonicalization

* Hoist non-commutative context expanded rule app. in simplify (applyRule)

* Add two simplify non-commutative ctx. test cases
2022-11-22 17:15:57 +01:00
Glen Whitney
f6d3e9ea8d
feat: add polynomialRoot function (#2839)
* feat: add polynomialRoot function

  This is intended as a benchmark for general arithmetic/basic algebra
  functionality of mathjs, but was chosen to be something of potential
  independent utility as well, worth adding to mathjs in its own right.

  Currently ol=nly computes the numerical roots for real or complex
  polynomials of degree three or less.

  As usual, adds documentation, embedded documentation, tests, TypeScript
  declaration, and TypeScript tests.

  Also updates doc.test.js to make it easier to specify an array of complex
  numbers as the expected output, and comapres with the appropriate fuzz
  in such cases.

  Finally, adds a benchmark that computes the roots of all cubics with
  nonnegative integer coefficients no larger than five.

* doc: fix typo in polynomialRoot embedded docs

Thanks, SamuelTLG

* style: avoid slightly cryptic Boolean flag stand-in
2022-11-18 15:53:45 +01:00
Jos de Jong
b050d5ed5d Fix the docs and types of forEach, which returns void (see #2840) 2022-11-18 10:18:59 +01:00
Lucas Egidio
a2e85ca698
Added functions: schur, sylvester, and lyap (#2646)
* Added matrix functions `schur`, `sylvester` and  `lyap`

* Added docs for  `schur`, `sylvester` and  `lyap`

* Added unit tests for  `schur`, `sylvester` and  `lyap`

* Fixed lint and tests errors

* fixed typescript and added Matrix + Array tests

* lint fixed

* fixed example in sylvester.js doc

* Fixed docs and ci

* fixed definition of lyap and sylvester

* remark on diff defs for lyap

* rm a trailing space

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2022-11-17 17:16:21 +01:00
thatcomputerguy0101
77f94c4f95
More simplify wildcards (#1915)
* Create wildcards.js and implement basic type detections

* Remove isUnit from isConstantExpression wildcard

isUnit would never be encountered because units are stored as a part of ConstantNodes.

* Add matching for the new wildcard rules

* Add tests for the new wildcard rules

* Remove comment regarding Unit

* Seperate wildcard import into individual imports

* Update comments at top and change '*i' to '*d'

* Seperate Unit Tests

* Update simplify documentation comment

* Add unit test for #1406

* Update imports for new build system

* Update simplify test with new rules syntax

* Fix small documentation errors

* Update simplify rules to use new wildcards

* Add tests for rules updated with new wildcards

* Remove duplicated comment information

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2022-11-15 10:36:08 +01:00
Samuel TLG
49fed5bc25
Improve simplifying operations on constants in non-commutative contexts (#2827)
* Simplify: improve constant op. eval. in non-commutative contexts

Addresses the constant evaluation aspect as discussed in #2825.

Changes in simplifyConstant.js are accredited to @gwhitney

* Add simplifyConstant test for expr. with a non-evaluable constant

(uncomments a pre-existing test suggestion for an 'incomplete'
simplification example, more specifically)

Additionally adds commented TODO tests for additional expr. variations
with current incomplete simplification (non-commutative context)
2022-11-08 15:17:22 +01:00