1963 Commits

Author SHA1 Message Date
Jos de Jong
0e9c73764b chore: move plain number tests from node-tests to unit-tests, remove redundant tests (see #3011) 2023-09-20 09:35:12 +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
Jos de Jong
6dcbc6b793 fix: security vulnerability in FunctionNode and SymbolNode allowing arbitrary code execution via math.evaluate 2023-07-24 12:33:28 +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
Jos de Jong
ab409dffeb chore: ignore freqz in the doc test for the time being (see #2988) 2023-07-13 16:48:04 +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
Jos de Jong
f48caf9f50 docs: don't check expected result of an example when we don't know the expected result 2023-07-12 14:15:57 +02:00
Carl Osterwisch
a1e6e9301e
fix: nearly-zero temperature conversion result (#2962)
* Test for roundoff error due to offset

* Set result to exactly 0 if it is within config.epsilon of 0

* Add more offset conversion tests

* Represent degR unit value as a Fraction(5, 9)

* Accurately convert from fraction to bignumber

* Add more tests demonstrating the improved offset conversions

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-07-12 13:21:56 +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
Jos de Jong
29db0fb288 fix: #2971 improve typings of statistics functions min, max, mean, median, mode, std, sum, prod, variance 2023-06-20 11:33:38 +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
Maxim Mazurok
5b53fff681
feat: better min/max return type (#2955) 2023-05-22 21:39:41 +02:00
Jos de Jong
db3e62e5c3
feat: extend functions fraction, bignumber, and number with support for units, see #2918 (#2926)
* feat: extend function `fraction` with support for units (see #2918)

* fix: update the TypeScript definitions with the new `math.fraction(value: Unit)` support

* feat: implement `math.bignumber(value: Unit)`

* feat: update type definitions of function `math.bignumber`

* fix: linting issue

* feat: implement support for `math.number(unit)` (was formerly throwing an exception)
2023-04-03 13:48:24 +02:00
brunoSnoww
079300f183
Fix gcd type (#2922)
* refactor gcd type

* add tests

* just refactor gcd...

* little change on test

* update gcd chain
2023-03-27 09:49:19 +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
Jos de Jong
f865658339 fix: quantileSeq not accepting a matrix as second argument prob (see #2902) 2023-02-23 16:48:56 +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
391677f9e0 fix #2888: update type definitions of function unit to allow creating a unit from a fraction or complex number 2023-02-02 10:32:06 +01:00
brunoSnoww
654e1b7357
Refactor dotMultiply, dotPow and dotDivide types (#2890)
* refactor types

* refactor on chain types

---------

Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
2023-01-31 17:21:36 +01:00
brunoSnoww
0c6e832ab7
Fix: Add "rotationMatrix" function type (#2860)
* fix: add rotation matrix type

* remove mistaken test

* code-review: refactor type and add tests for it
2022-12-09 16:33:58 +01:00
Jos de Jong
0842b75a23 Merge remote-tracking branch 'origin/develop' into develop 2022-12-05 10:40:59 +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
cd4ba30e9f update history 2022-12-05 10:16:37 +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
c51d263d9c chore: update the browser versions tested on browserstack 2022-11-29 15:59:23 +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
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
Alexandre Alves
16cdf66385
Prevent inserting zero values in SparseMatrix (#2836)
* Prevent inserting zero values in SparseMatrix

As discussed in #2830

* Formatting correction

* Lint correction
2022-11-07 10:21:59 +01:00
Jos de Jong
ea991732a5 Fix linting issue 2022-10-25 10:25:06 +02:00
Jos de Jong
65c538dbac Allow prefixes for celsius and fahrenheit and add unit tests for it (see #2821) 2022-10-25 10:20:29 +02:00
Jos de Jong
d27910fa1f
fix #2818: throw an error when a function assignment has duplicate parameter names (#2819)
* fix #2818: throw an error when a function assignment has duplicate parameter names

* fix linting and code issue

* fix broken unit test

* Make linter happy

* Add a test case `['x', { name: 'x' }]`
2022-10-19 08:30:18 +02:00
Jos de Jong
5e439be0a8
Fix #2809: code completion issues in some IDE's (#2812)
* Move types/index.ts to test/typescript-tests/testTypes.ts (WIP)

* Fix the paths for the test:types script

* Move tsconfig.json to the root
2022-10-19 08:23:14 +02:00
Jos de Jong
5754478f16
Fix #2793: math.flatten() clones object values too (#2799)
Resolves #2793.

Co-authored-by: Glen Whitney <glen@studioinfinity>
2022-10-07 23:58:20 -04:00