This PR is not intended for merging as-is, but serves as an
alternate demonstration (vis-a-vis issue #2437) that essentially all
the ingredients already exist in mathjs for evaluation in which all
undefined variables evaluate to symbols, therefore possibly returning
an expression (Node) rather than a concrete value (while still
evaluating all the way to concrete values when possible).
Moreover, mathematical manipulation of symbolic expressions can be
supported without circularity and without modifying numerous source
files.
This PR does however depend on a small addition to typed-function.js,
see https://github.com/josdejong/typed-function/pull/125.
See (or run) examples/symbolic_evaluation.mjs for further details on this.
* Add overloads for Matrix add and subtract
* Add check for types/index.ts
* Fix type errors in types/index.ts
* Fix a couple execution errors
* Run test:types as part of test:all
* Fix remaining errors
* Replace types/index.ts comments with asserts
* Add tests for narrowed type inference
* Add dual-purpose comment at top of types/index.ts
* Update AUTHORS
* Use Glen's alternate test:types suggestion
* test: Add unit tests for all of the examples in (jsdoc) comments
Uses the existing extraction of examples from tools/docgenerator.js
Hence, for now this is limited to documentation of functions, but
hopefully it can be extended to classes, units (and physical constants),
and constants as well in the future.
Exposes numerous errors in the examples, some of which are bugs; these
are for now put on a known error list to be worked on, so that this
PR does not change a huge number of source files.
Also adds a test to check that all symbols are documented (which
similarly doesn't really pass at the moment, and is patched to a
hopefully temporary warning).
* refactor: Make doc.test.js into a node test
The source code is not available in its layout as in the repository in
the browser tests, so the new doc testing can only occur in the node tests
* Add simplifyCore, symbolicEqual, map, and resolve to the list with functions with known issues in the jsdoc examples
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Resolves#2427.
Also adds tests verifying that creating a fraction from two numbers
requires them both to be integers, and slightly updates documentation.
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
Resolves#1633
Co-authored-by: Hjortur Jonasson <hjorturjonasson@gmail.com>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
* Fix std and variance type definition
* Fix JSDoc and add overload for var/std of chain
* Fix array type and remove duplicate norm type
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* doc(map): Clarify the arguments to the callback
Also make the message when there is a type mismatch more detailed.
Resolves#2436.
* test(map): Add tests relevant to new documentation
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
This change fixes a typing problem in complexEigs.js in which
real-valued norms were inadvertently being typed as complex numbers.
Resolves#2439
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* feat(FunctionNode): allow function parameters to be called
This change is implemented by checking if a function symbol is in
the arg list, and if so delaying its analysis until evaluation time,
at which point it is extracted from the arguments and called as
appropriate depending on its rawArgs property.
Also adds a few tests, documents the new facility, and documents the
handling of free variables in a function definition, which was previously
left undescribed.
Resolves#2441.
Resolves#2442.
* chore: correct lint violations (sorry)
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* fix(simplify): Collect like factors in sums and cancel like terms in sums
Since polynomials like `x*(2x+x^2)` are usually written out as polynomials
`2x^2+x^3`, adds rules to be more eager to move factors into sums to
collect like factors. To complement this, adds a rule extracting
negative powers from a sum. Together, these accomplish canceling
a common factor in numerator and denominator:
(a*k + b*k^2)/k^4 -> k^-4*(a*k + b*k^2) -> a*k^-3 + b*k^-2 -> k^-3*(a + k*b)
-> (a + k*b)/k^3
Resolves#1423.
* fix(simplify): Adjust for #2394
* chore: Rebase and mark rules with assumptions
This commit should update this PR to be fully compatible with the
current development mainline. Will remove 'WIP'.
* chore(simplify): Additional test cases from PR review
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
* docs: Enhance generation to pick up functions with a prefix
For example, prior to this commit, docgenerator.js would miss
simplify.resolve because it is not a direct key of the math
object.
Also incorporates any "throws" attributes in the comments into
the generated documentation, and uses this to document the
new error-case behavior of simplify.resolve to be added in the next
commit.
* fix(resolve): Detect and throw errors for reference loops
Also extends resolve to work inside all node types. Adds tests
for both changes.
* docs: Add embedded docs for simplify.resolve et al.
To support finding the embedded doc from the `math.simplify.resolve`
function itself, required extending the search for objects with
documentation one level deeper in the `help()` function. Added test for
this search.
Also added support for documenting throws in embedded docs.
* refactor(simplify): Move resolve and simplifyCore to top-level
Also reverts changes searching for docs and embedded docs one level
down in the naming hierarchy.
Also splits tests for resolve and simplifyCore into their own files,
reflecting their new top-level status.
* fix(resolve): Remaining changes as requested
Also removed a stray blank line inadvertently introduced in
docgenerator.js
* refactor: Declare resolve and simplifyCore as dependencies of simplify
... rather than explicitly loading them, which is unnecessary now that they
are at top level.
* fix: Add dependencies to factoriesNumber
Also register simplifyCore as a dependency to rationalize
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
Note for this to work in a broad variety of contexts, has to also allow
identical expressions to cancel regardless of whether subtraction is
always defined; but this seems safe in general, that x-x is 0 even if x
does not generally have an additive inverse (for example, when working
in the positive context).
Resolves#1260.
Prior to this change, combinations(42,21) did not return an integer,
despite its value being well below MAX_SAFE_INTEGER. Now the
multiplications and divisions are balanced to try to keep the
intermediate results within the safe range.
Adds a couple of tests for larger values of combinations().
Resolves#2413.
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>