|
1 | 1 | ## [Unreleased]
|
2 | 2 |
|
| 3 | +### Breaking Changes |
| 4 | + |
| 5 | +- The canonical form of expressions has changed. It is now more consistent and |
| 6 | + simpler and should produce more predictable results. |
| 7 | + |
| 8 | + For example, previously `ce.parse("1-x^2")` would produce |
| 9 | + `["Subtract", 1, ["Square", "x"]]`. |
| 10 | + |
| 11 | + While this is a readable form, it introduces some complications when |
| 12 | + manipulating the expression: both the `Subtract` and `Square` functions have |
| 13 | + to be handled, in addition to `Add` and `Power`. |
| 14 | + |
| 15 | + The new canonical form of this expression is |
| 16 | + `["Add", 1, ["Negate", ["Power", "x", 2]]]`. It is a bit more verbose, but it |
| 17 | + is simpler to manipulate. |
| 18 | + |
| 19 | +- The `ce.serialize()` method has been replaced with `expr.toLatex()` and |
| 20 | + `expr.toMathJson()`. These methods take an optional serialization option |
| 21 | + object. The `ce.latexOptions` and `ce.jsonSerializationOptions` properties |
| 22 | + have been removed. Use the `options` argument of `toLatex()` and |
| 23 | + `toMathJson()` instead. |
| 24 | + |
| 25 | +- The default JSON serialization of an expression has changed. |
| 26 | + |
| 27 | + Previously, the default JSON serialization, accessed via the `.json` property, |
| 28 | + had some transformations applied to it (sugaring) to make the JSON more human |
| 29 | + readable. |
| 30 | + |
| 31 | + For example, `ce.parse("\\frac12").json` would return the symbol `"Half"` |
| 32 | + instead of `["Divide", 1, 2]`. |
| 33 | + |
| 34 | + However, this could lead to some confusion when manipulating the JSON |
| 35 | + directly. Since the JSON is intended to be used by machine more than humans, |
| 36 | + the transformations have been removed. |
| 37 | + |
| 38 | + The `expr.json` property now returns the JSON representing the expression, |
| 39 | + without any transformations. |
| 40 | + |
| 41 | + Note that the `expr.json` property ignores the settings from |
| 42 | + `ce.jsonSerializationOptions`. |
| 43 | + |
| 44 | + To get a version of JSON with some transformations and shorthands applied use |
| 45 | + the `ce.serialize()` function. You can control the output of `ce.serialize()` |
| 46 | + with `ce.jsonSerializationOptions`. |
| 47 | + |
| 48 | + ```js |
| 49 | + ce.serialize(expr, {format: "json"}) |
| 50 | + ``` |
| 51 | + |
| 52 | + In practice, the impact of both of these changes should be minimal. If you |
| 53 | + were manipulating expressions using `BoxedExpression`, the new canonical form |
| 54 | + should make it easier to manipulate expressions. You can potentially simplify |
| 55 | + your code by removing special cases for functions such as `Square` and |
| 56 | + `Subtract`. |
| 57 | + |
| 58 | + If you were using the JSON serialization directly, you may also be able to |
| 59 | + simplify you code since the default output from `expr.json` is now more |
| 60 | + consistent and simpler. |
| 61 | + |
| 62 | +- The name of some number formatting options has changed. See the |
| 63 | + `NumberFormat` and `NumberSerializationFormat` types. |
| 64 | + |
| 65 | +- The values +infinity, -infinity and NaN are now represented preferably with |
| 66 | + the symbols `PositiveInfinity`, `NegativeInfinity` and `NaN` respectively. |
| 67 | + Previously they were represent with corresponding numeric values, i.e. |
| 68 | + `{num: "+Infinity"}`, `{num: "-Infinity"}` and `{num: "NaN"}`. The numeric |
| 69 | + values are still supported, but the symbols are preferred. |
| 70 | + |
| 71 | +- The method `expr.isNothing` has been removed. Instead, use |
| 72 | + `expr.symbol === "Nothing"`. |
| 73 | + |
3 | 74 | ### New Features
|
4 | 75 |
|
| 76 | +- When serializing to LaTeX, the output can be "prettified". This involves |
| 77 | + modifying the LaTeX output to make it more pleasant to read, for example: |
| 78 | + |
| 79 | + - `a+\\frac{-b}{c}` -> `a-\\frac{b}{c}` |
| 80 | + - `a\\times b^{-1}` -> `\\frac{a}{b}` |
| 81 | + - `\\frac{a}{b}\\frac{c}{d}` -> `\\frac{a\\cdot c}{b\\cdot d}` |
| 82 | + - `--2` -> `2` |
| 83 | + |
| 84 | + This is on by default and can be turned off by setting the `prettify` option |
| 85 | + to `false`. For example: |
| 86 | + |
| 87 | + ```js |
| 88 | + ce.parse("a+\\frac{-b}{c}").toLatex({prettify: true}) |
| 89 | + // -> "a-\\frac{b}{c}" |
| 90 | + ce.parse("a+\\frac{-b}{c}").toLatex({prettify: false}) |
| 91 | + // -> "a+\\frac{-b}{c}" |
| 92 | + ``` |
| 93 | + |
| 94 | +- Numbers can have a different digit group length for the whole and fractional |
| 95 | + part of a number. For example, |
| 96 | + `ce.toLatex(ce.parse("1234.5678"), {digitGroup: [3, 0]})` will return |
| 97 | + `1,234.5678`. |
| 98 | +- Numbers can now be formatted using South-East Asian Numbering System, i.e. |
| 99 | + lakh and crore. For example, |
| 100 | + `ce.toLatex(ce.parse("12345678"), {digitGroup: "lakh"})` will return |
| 101 | + `1,23,45,678`. |
| 102 | +- Expressions with Integrate functions can now be compiled to JavaScript. The |
| 103 | + compiled function can be used to evaluate the integral numerically. For |
| 104 | + example: |
| 105 | + |
| 106 | + ```js |
| 107 | + const f = ce.parse("\\int_0^1 x^2 dx"); |
| 108 | + const compiled = f.compile(); |
| 109 | + console.log(compiled()); // -> 0.33232945619482307 |
| 110 | + ``` |
| 111 | + |
5 | 112 | - **#82** Support for angular units. The default is radians, but degrees can be
|
6 | 113 | used by setting `ce.angularUnit = "deg"`. Other possible values are "grad" and
|
7 | 114 | "turn". This affects how unitless numbers with a trigonometric function are
|
|
15 | 122 |
|
16 | 123 | ### Issues Resolved
|
17 | 124 |
|
| 125 | +- Fixed canonical form of `e^x^2`, and more generally apply power rule in more |
| 126 | + cases. |
| 127 | +- Added missing Sech and Csch functions. |
| 128 | +- The digit grouping serializing would place the separator in the wrong place |
| 129 | + for some numbers. |
| 130 | +- The `avoidExponentsInRange` formating option would not always avoid exponents |
| 131 | + in the specified range. |
| 132 | +- **#173** Parsing `1++2` would result in an expression with a `PreIncrement` |
| 133 | + function. It is now correctly parsed as `["Add", 1, 2]`. |
| 134 | +- **#169** Calculating a constant integral (and integral that did not depend on |
| 135 | + the variable) would result in a runtime error. |
18 | 136 | - **#164** Negative mixed fractions (e.g. `-1\frac23`) are now parsed correctly.
|
19 | 137 | - **#162** Numeric evaluation of expressions with large exponents could result
|
20 | 138 | in machine precision numbers instead of bignum numbers.
|
|
0 commit comments