Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd557e5

Browse files
committed
arch: changed JSON canonical format, APIs for serialization to LaTeX and MathJSON
1 parent79ce09c commitcd557e5

File tree

124 files changed

+8716
-7250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+8716
-7250
lines changed

‎CHANGELOG.md‎

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,114 @@
11
##[Unreleased]
22

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+
374
###New Features
475

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+
constf=ce.parse("\\int_0^1 x^2 dx");
108+
constcompiled=f.compile();
109+
console.log(compiled());// -> 0.33232945619482307
110+
```
111+
5112
-**#82** Support for angular units. The default is radians, but degrees can be
6113
used by setting`ce.angularUnit = "deg"`. Other possible values are "grad" and
7114
"turn". This affects how unitless numbers with a trigonometric function are
@@ -15,6 +122,17 @@
15122

16123
###Issues Resolved
17124

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.
18136
-**#164** Negative mixed fractions (e.g.`-1\frac23`) are now parsed correctly.
19137
-**#162** Numeric evaluation of expressions with large exponents could result
20138
in machine precision numbers instead of bignum numbers.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp