-
#217 Correctly parse LaTeX expressions that include a command followed by
a *
such as \\pi*2
.
-
#217 Correctly calculate the angle of trigonometric expressions with an
expression containing a reference to Pi
, for example \\sin(\\pi^2)
.
-
The Factorial
function will now time out if the argument is too large. The
timeout is signaled by throwing a CancellationError
.
-
When specifying exp.toMathJSON({shorthands:[]})
, i.e., not to use shorthands
in the MathJSON, actually avoid using shorthands.
-
Correctly use custom multiply, plus, etc. for LaTeX serialization.
-
When comparing two numeric values, the tolerance is now used to determine if
the values are equal. The tolerance can be set with the ce.tolerance
property.
-
When comparing two expressions with isEqual()
the values are compared
structurally when necessary, or with a stochastic test when the expressions
are too complex to compare structurally.
-
Correctly serialize nested superscripts, e.g. x^{y^z}
.
-
The result of evaluating a Hold
expression is now the expression itself.
-
To prevent evaluation of an expression temporarily, use the Unevaluated
function. The result of evaluating an Unevaluated
expression is its
argument.
-
The type of a Hold
expression was incorrectly returned as string
. It now
returns the type of its argument.
-
The statistics function (Mean
, Median
, Variance
, StandardDeviation
,
Kurtosis
, Skewness
, Mode
, Quartiles
and InterQuartileRange
) now
accept as argument either a collection or a sequence of values.
ce.parse("\\mathrm{Mean}([7, 2, 11])").evaluate().print();
// -> 20/3
ce.parse("\\mathrm{Mean}(7, 2, 11)").evaluate().print();
// -> 20/3
-
The Variance
and StandardDeviation
functions now have variants for
population statistics, PopulationVariance
and PopulationStandardDeviation
.
The default is to use sample statistics.
ce.parse("\\mathrm{PopulationVariance}([7, 2, 11])").evaluate().print();
// -> 13.555
ce.parse("\\mathrm{Variance}([7, 2, 11])").evaluate().print();
// -> 20.333
-
The statistics function can now be compiled to JavaScript:
const code = ce.parse("\\mathrm{Mean}(7, 2, 11)").compile();
console.log(code());
// -> 13.555
-
The statistics function calculate either using machine numbers or bignums
depending on the precision. The precision can be set with the precision
property of the Compute Engine.
-
The argument of compiled function is now optional.
-
Compiled expressions can now reference external JavaScript functions. For
example:
ce.defineFunction('Foo', {
signature: 'number -> number',
evaluate: ([x]) => ce.box(['Add', x, 1]),
});
const fn = ce.box(['Foo', 3]).compile({
functions: { Foo: (x) => x + 1 },
})!;
console.info(fn());
// -> 4
ce.defineFunction('Foo', {
signature: 'number -> number',
evaluate: ([x]) => ce.box(['Add', x, 1]),
});
function foo(x) {
return x + 1;
}
const fn = ce.box(['Foo', 3]).compile({
functions: { Foo: foo },
})!;
console.info(fn());
// -> 4
Additionally, functions can be implicitly imported (in case they are needed by
other JavaScript functions):
ce.defineFunction('Foo', {
signature: 'number -> number',
evaluate: ([x]) => ce.box(['Add', x, 1]),
});
function bar(x, y) {
return x + y;
}
function foo(x) {
return bar(x, 1);
}
const fn = ce.box(['Foo', 3]).compile({
functions: { Foo: 'foo' },
imports: [foo, bar],
})!;
console.info(fn());
// -> 4
-
Compiled expression can now include an arbitrary preamble (JavaScript source)
that is executed before the compiled function is executed. This can be used to
define additional functions or constants.
ce.defineFunction('Foo', {
signature: 'number -> number',
evaluate: ([x]) => ce.box(['Add', x, 1]),
});
const code = ce.box(['Foo', 3]).compile({
preamble: "function Foo(x) { return x + 1};",
});
-
The hold
function definition flag has been renamed to lazy