You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@cortex-js/compute-engine

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cortex-js/compute-engine - npm Package Versions

12456

0.20.1

Diff
a
arnog
published 0.20.1 •

Changelog

Source

0.20.1 2023-10-31

Issues Resolved

  • Fixed evaluation of functions with multiple arguments
  • Fixed compilation of some function assignments
  • Improved serialization of function assignment
a
arnog
published 0.20.0 •

Changelog

Source

0.20.0 2023-10-30

Breaking Changes

  • Architectural changes: the invisible operator is used to represent the multiplication of two adjacent symbols, i.e. 2x. It was previously handled during parsing, but it is now handled during canonicalization. This allows more complex syntactic structures to be handled correctly, for example f(x) := 2x: previously, the left-hand-side argument would have been parsed as a function application, while in this case it should be interpreted as a function definition.

    A new InvisibleOperator function has been added to support this.

    The applyInvisibleOperator parsing option has been removed. To support custom invisible operators, use the InvisibleOperator function.

Issues Resolved

  • #25 Correctly parse chained relational operators, i.e. a < b <= c
  • #126 Logic operators only accepted up to two arguments.
  • #127 Correctly compile Log with bases other than 10.
  • Correctly parse numbers with repeating patterns but no fractional digits, i.e. 0.(1234)
  • Correctly parse |1+|a|+2|

New Features and Improvements

  • Function assignment can now be done with this syntax: f(x) := 2x+1. This syntax is equivalent to f := x -> 2x+1.
  • Implement the Mod and Congruent function.
  • Correctly parse 11 \bmod 5 (Mod) and 26\equiv 11 \pmod5 (Congruent)
  • Better handle empty argument lists, i.e. f()
  • When a function is used before being declared, infer that the symbol is a function, e.g. f(12) will infer that f is a function (and not a variable f multiplied by 12)
  • When a constant is followed by some parentheses, don't assume this is a function application, e.g. \pi(3+n) is now parsed as ["Multiply", "Pi", ["Add", 3, "n"]] instead of ["Pi", ["Add", 3, "n"]]
  • Improved parsing of nested lists, sequences and sets.
  • Improved error messages when syntax errors are encountered during LaTeX parsing.
  • When parsing with the canonical option set to false, preserve more closely the original LaTeX syntax.
  • When parsing text strings, convert some LaTeX commands to Unicode, including spacing commands. As a result, ce.parse("\\text{dead\;beef}_{16}") correctly gets evaluated to 3,735,928,559.
a
arnog
published 0.19.1 •

Changelog

Source

0.19.1 2023-10-26

Issues Resolved

  • Assigning a function to an indentifier works correctly now, i.e.
ce.parse("\\operatorname{f} := x \\mapsto 2x").evaluate();
a
arnog
published 0.19.0 •

Changelog

Source

0.19.0 2023-10-25

Breaking Changes

  • The domain property of the function definition signature is deprecated and replaced with the params, optParams, restParam and result properties instead. The domain property is still supported for backward compatibility, but will be removed in a future version.

Issues Resolved

  • When invoking a declared function in a numeric operation, correctly infer the result type.
["Assign", "f", ["Add", "_", 1]]
["Add", ["f", 1], 1]
// -> 3

Previously a domain error was returned, now f is inferred to have a numeric return type.

  • Fixed a runtime error when inverting a fraction, i.e. \frac{3}{4}^{-1}
  • The tangent of π/2 now correctly returns ComplexInfinity.
  • The exact values of some constructible trigonometric operations (e.g. \tan 18\degree = \frac{\sqrt{25-10\sqrt5}}{5}) returned incorrect results. The unit test case was incorrect and did not detect the problem. The unit test case has been fixed and the returned values are now correct.

New Features

  • Implemented Union and Intersection of collections, for example:
["Intersection", ["List", 3, 5, 7], ["List", 2, 5, 9]]
// -> ["Set", 5]

["Union", ["List", 3, 5, 7], ["List", 2, 5, 9]]
// -> ["Set", 3, 5, 7, 2, 9]
  • Parse ranges, for example 1..5 or 1, 3..10. Ranges are collections and can be used anywhere collections can be used.

  • The functions Sum, Product, Min, Max, and the statistics functions (Mean, Median, Variance, etc...) now handle collection arguments: collections:

    • ["Range"], ["Interval"], ["Linspace"] expressions
    • ["List"] or ["Set"] expressions
    • ["Tuple"], ["Pair"], ["Pair"], ["Triple"] expressions
    • ["Sequence"] expressions
  • Most mathematical functions are now threadable, that is their arguments can be collections, for example:

["Sin", ["List", 0, 1, 5]]
// -> ["List", 0, 0.8414709848078965, -0.9589242746631385]

["Add", ["List", 1, 2], ["List", 3, 4]]
// -> ["List", 4, 6]
  • Added GCD and LCM functions
["GCD", 10, 5, 15]
// -> 5

["LCM", 10, 5, 15]
// -> 30
  • Added Numerator, Denominator, NumeratorDenominator functions. These functions can be used on non-canonical expressions.

  • Added Head and Tail functions which can be used on non-canonical expressions.

  • Added display-quotient and inline-quotient style for formatting of division expressions in LaTeX.

Improvements

  • Improved parsing of \degree command
ce.parse("30\\degree)
// -> ["Divide", "Pi", 6]
  • Improved interoperability with JavaScript: expr.value will return a JavaScript primitive (number, boolean, string, etc...) when possible. This is a more succinct version of expr.N().valueOf().
a
arnog
published 0.18.1 •

Changelog

Source

0.18.1 2023-10-16

Issues Resolved

  • Parsing of whole numbers while in rational mode would return incorrect results.
  • The ND function to evaluate derivatives numerically now return correct values.
ce.parse("\\mathrm{ND}(x \\mapsto 3x^2+5x+7, 2)").N();
// -> 17.000000000001

Improvements

  • Speed up NIntegrate by temporarily switching the numeric mode to machine while computing the Monte Carlo approximation.
a
arnog
published 0.18.0 •

Changelog

Source

0.18.0 2023-10-16

New Features

  • Expanded LaTeX dictionary with \max, \min, \sup, \inf and \lim functions
  • Added Supremum and Infimum functions
  • Compilation of Block expressions, local variables, return statements and conditionals If.
  • Added numerical evaluation of limits with Limit functions and NLimit functions, using a Richardson Extrapolation.
console.info(ce.parse("\\lim_{x\\to0} \\frac{\\sin x}{x}").N().json);
// -> 1

console.info(
  ce.box(["NLimit", ["Divide", ["Sin", "_"], "_"], 0]).evaluate().json
);
// -> 1

console.info(ce.parse("\\lim_{x\\to \\infty} \\cos \\frac{1}{x}").N().json);
// -> 1
  • Added Assign and Declare functions to assign values to symbols and declare symbols with a domain.

  • Block evaluations with local variables work now. For example:

ce.box(["Block", ["Assign", "c", 5], ["Multiply", "c", 2]]).evaluate().json;
// -> 10
  • When decimal numbers are parsed they are interpreted as inexact numbers by default, i.e. "1.2" -> {num: "1.2"}. To force the number to be interpreted as a rational number, set ce.latexOptions.parseNumbers = "rational". In that case, "1.2" -> ["Rational", 12, 10], an exact number.

    While regular decimals are considered "inexact" numbers (i.e. they are assumed to be an approximation), rationals are assumed to be exact. In most cases, the safest thing to do is to consider decimal numbers as inexact to avoid introducing errors in calculations. If you know that the decimal numbers you parse are exact, you can use this option to consider them as exact numbers.

Improvements

  • LaTeX parser: empty superscripts are now ignored, e.g. 4^{} is interpreted as 4.
a
arnog
published 0.17.0 •

Changelog

Source

0.17.0 2023-10-12

Breaking Changes

  • The Nothing domain has been renamed to NothingDomain
  • The Functions, Maybe, Sequence, Dictionary, List and Tuple domain constructors have been renamed to FunctionOf, OptArg, VarArg, DictionaryOf, ListOf and TupleOf, respectively.
  • Domains no longer require a ["Domain"] expression wrapper, so for example ce.box("Pi").domain returns "TranscendentalNumbers" instead of ["Domain", "TranscendentalNumbers"].
  • The VarArg domain constructor now indicates the presence of 0 or more arguments, instead of 1 or more arguments.
  • The MaybeBooleans domain has been dropped. Use ["Union", "Booleans", "NothingDomain"] instead.
  • The ce.defaultDomain has been dropped. The domain of a symbol is now determined by the context in which it is used, or by the ce.assume() method. In some circumstances, the domain of a symbol can be undefined.

New Features

  • Symbolic derivatives of expressions can be calculated using the D function. For example, ce.box(["D", ce.parse("x^2 + 3x + 1"), "x"]).evaluate().latex returns "2x + 3".

Improvements

  • Some frequently used expressions are now available as predefined constants, for example ce.Pi, ce.True and ce.Numbers.
  • Improved type checking and inference, especially for functions with complicated or non-numeric signatures.

Bugs Fixed

  • Invoking a function repeatedly would invoke the function in the original scope rather than using a new scope for each invocation.
a
arnog
published 0.16.0 •

Changelog

Source

0.16.0 2023-09-29

Breaking Changes

  • The methods ce.let() and ce.set() have been renamed to ce.declare() and ce.assign() respectively.
  • The method ce.assume() requires a predicate.
  • The signatures of ce.assume() and ce.ask() have been simplified.
  • The signature of ce.pushScope() has been simplified.
  • The expr.freeVars property has been renamed to expr.unknowns. It returns the identifiers used in the expression that do not have a value associated with them. The expr.freeVariables property now return the identifiers used in the expression that are defined outside of the local scope and are not arguments of the function, if a function.

New Features

  • Domain Inference when the domain of a symbol is not set explicitly (for example with ce.declare()), the domain is inferred from the value of the symbol or from the context of its usage.

  • Added Assume, Identity, Which, Parse, N, Evaluate, Simplify, Domain.

  • Assignments in LaTeX: x \\coloneq 42 produce ["Assign", "x", 42]

  • Added ErfInv (inverse error function)

  • Added Factorial2 (double factorial)

Functions

  • Functions can now be defined:

    • using ce.assign() or ce.declare()
    • evaluating LaTeX: (x, y) \mapsto x^2 + y^2
    • evaluating MathJSON: ["Function", ["Add", ["Power", "x", 2], ["Power", "y", 2]]], "x", "y"]
  • Function can be applied using \operatorname{apply} or the operators \rhd and \lhd:

    • \operatorname{apply}(f, x)
    • f \rhd x
    • x \lhd f

See Adding New Definitions and Functions.

Control Structures

  • Added FixedPoint, Block, If, Loop
  • Added Break, Continue and Return statements

See Control Structures

Calculus

  • Added numeric approximation of derivatives, using an 8-th order centered difference approximation, with the ND function.
  • Added numeric approximation of integrals, using a Monte Carlo method with rebasing for improper integrals, with the NIntegrate function
  • Added symbolic calculation of derivatives with the D function.

Collections

Added support for collections such as lists, tuples, ranges, etc...

See Collections

Collections can be used to represent various data structures, such as lists, vectors, matrixes and more.

They can be iterated, sliced, filtered, mapped, etc...

["Length", ["List", 19, 23, 5]]
// -> 3

["IsEmpty", ["Range", 1, 10]]
// -> "False"

["Take", ["Linspace", 0, 100, 50], 4]
// -> ["List", 0, 2, 4, 6]

["Map", ["List", 1, 2, 3], ["Function", "x", ["Power", "x", 2]]]
// -> ["List", 1, 4, 9]

["Exclude", ["List", 33, 45, 12, 89, 65], -2, 2]
// -> ["List", 33, 12, 65]


["First", ["List", 33, 45, 12, 89, 65]]
// -> 33

Improvements

  • The documentation has been significantly rewritten with help from an AI-powered writing assistant.

Issues Resolved

  • The LaTeX string returned in ["Error"] expression was incorrectly tagged as Latex instead of LatexString.
a
arnog
published 0.15.0 •

Changelog

Source

0.15.0 2023-09-14

Improvements

  • The ce.serialize() function now takes an optional canonical argument. Set it to false to prevent some transformations that are done to produce more readable LaTeX, but that may not match exactly the MathJSON. For example, by default ce.serialize(["Power", "x", -1]) returns \frac{1}{x} while ce.serialize(["Power", "x", -1], {canonical: false}) returns x^{-1}.
  • Improved parsing of delimiters, i.e. \left(, \right], etc...
  • Added complex functions Real, Imaginary, Arg, Conjugate, AbsArg. See Complex
  • Added parsing and evaluation of \Re, \Im, \arg, ^\star (Conjugate).
  • #104 Added the ["ComplexRoots", x, n] function which returns the nthroot of x.
  • Added parsing and evaluation of statistics functions Mean, Median, StandardDeviation, Variance, Skewness, Kurtosis, Quantile, Quartiles, InterquartileRange, Mode, Count, Erf, Erfc. See Statistics
a
arnog
published 0.14.0 •

Changelog

Source

0.14.0 2023-09-13

Breaking Changes

  • The entries in the LaTeX syntax dictionary can now have LaTeX triggers (latexTrigger) or triggers based on identifiers (symbolTrigger). The former replaces the trigger property. The latter is new. An entry with a triggerIdentifier of average will match \operatorname{average}, \mathrm{average} and other variants.
  • The ce.latexOptions and ce.jsonSerializationOptions properties are more robust. They can be modified directly or one of their properties can be modified.

Improvements

  • Added more functions and symbols supported by expr.compile():

    • Factorial postfix operator 5!
    • Gamma function \Gamma(2)
    • LogGamma function \operatorname{LogGamma}(2)
    • Gcd function \operatorname{gcd}(20, 5)
    • Lcm function \operatorname{lcm}(20, 5)
    • Chop function \operatorname{chop}(0.00000000001)
    • Half constant \frac{1}{2}
    • 'MachineEpsilon' constant
    • GoldenRatio constant
    • CatalanConstant constant
    • EulerGamma constant \gamma
    • Max function \operatorname{max}(1, 2, 3)
    • Min function \operatorname{min}(13, 5, 7)
    • Relational operators: Less, Greater, LessEqual, GreaterEqual, 'Equal', 'NotEqual'
    • Some logical operators and constants: And, Or, Not, True, False
  • More complex identifiers syntax are recognized, including \mathbin{}, \mathord{}, etc... \operatorname{} is the recommended syntax, though: it will display the identifier in upright font and with the propert spacing, and is properly enclosing. Some commands, such as \mathrm{} are not properly enclosing: two adjacent \mathrm{} command could be merged into one.

  • Environments are now parsed and serialized correctly.

  • When parsing LaTeX, function application is properly handled in more cases, including custom functions, e.g. f(x)

  • When parsing LaTeX, multiple arguments are properly handled, e.g. f(x, y)

  • Add LaTeX syntax for logical operators:

    • And: \land, \operatorname{and} (infix or function)
    • Or: \lor, \operatorname{or} (infix or function)
    • Not: \lnot, \operatorname{not} (prefix or function)
    • Xor: \veebar (infix)
    • Nand: \barwedge (infix)
    • Nor: ^^^^22BD (infix)
    • Implies: \implies (infix)
    • Equivalent: \iff (infix)
  • When a postfix operator is defined in the LaTeX syntax dictionary of the form ^ plus a single token, a definition with braces is added automatically so that both forms will be recognized.

  • Extended the LaTeX dictionary with:

    • floor
    • ceil
    • round
    • sgn
    • exp
    • abs
    • gcd
    • lcm
    • apply
  • Properly handle inverse and derivate notations, e.g. \sin^{-1}(x), \sin'(x), \cos''(x), \cos^{(4)}(x)or even\sin^{-1}''(x)`