You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/compute-engine/50-math-json.md
+26-12Lines changed: 26 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -139,7 +139,7 @@ A MathJSON expression is a combination of **numbers**, **symbols**, **strings**,
139
139
```json example
140
140
"x"
141
141
"Pi"
142
-
{"sym": "🍎"}
142
+
"`🍎`"
143
143
{"sym": "半径"}
144
144
{"sym": "Pi", "wikidata": "Q167"}
145
145
```
@@ -189,9 +189,8 @@ A MathJSON **number** is either:
189
189
190
190
- an object literal with a `"num"` key
191
191
- a JSON number
192
-
- a JSON string starting with `+`, `-` or the digits `0`-`9`. Using a string
193
-
is useful to represent numbers with a higher precision or greater range than
194
-
JSON numbers.
192
+
- a JSON string literal. Using a string is useful to represent numbers with a
193
+
higher precision or greater range than JSON numbers.
195
194
196
195
### Numbers as Object Literals
197
196
@@ -286,14 +285,15 @@ The numeric values below may not be represented as JSON number literals:
286
285
### Numbers as String Literals
287
286
288
287
An alternate representation of a **number** with no extra metadata is as a
289
-
string following the format described above.
288
+
string matching the Regex pattern `/^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/`.
290
289
291
290
This allows for a shorthand representation of numbers with a higher precision or
292
291
greater range than JSON numbers.
293
292
294
293
```json example
295
294
"3.14159265358979323846264338327950288419716"
296
-
"+Infinity"
295
+
"-1.7976931348623157e+308"
296
+
"5.7(317)e-2"
297
297
```
298
298
299
299
## Strings
@@ -303,7 +303,16 @@ A MathJSON **string** is either:
303
303
- an object literal with a `"str"` key
304
304
- a [JSON string](https://tools.ietf.org/html/rfc7159#section-7) that starts and
305
305
ends with **U+0027 `'` APOSTROPHE**.
306
-
- a JSON string that is not an identifier shorthand or a number, that is a
306
+
- a JSON string that is not a symbol shorthand or a number shorthand.
307
+
308
+
That is:
309
+
310
+
-`"Hello World"` is a string (it includes a space character which is not allowed in symbols)
311
+
-`"HelloWorld"` is a symbol (it does not include a space character)
312
+
-`"3.14"` is a number (it is a valid JSON number)
313
+
-`"'3.14'"` is a string (it is wrapped with single quotes)
314
+
-`"🍎"` is a string
315
+
-``"`🍎`"`` is a symbol shorthand (it is wrapped with backticks)
307
316
308
317
MathJSON strings must be [well formed JSON strings](https://tc39.es/proposal-well-formed-stringify/), which means they must escape surrogate codepoints `U+D800` to `U+DFFF`, control characters `U+0000` to `U+001F`, and the characters **U+0022 `'` QUOTATION MARK** and **U+005C `\` REVERSE SOLIDUS** (backslash).
309
318
@@ -450,20 +459,25 @@ A MathJSON **symbol** is either:
450
459
Symbols are JSON strings that represent the names of symbols, variables,
451
460
constants, wildcards and functions.
452
461
462
+
For a JSON string literal to be interpreted as a symbol, it must either
463
+
begin and start with a `` ` `` (`U+0060` GRAVE ACCENT) or be a
464
+
string matching the Regex pattern `/^[a-zA-Z_][a-zA-Z0-9_]*$/`.
465
+
466
+
453
467
Before they are used, JSON escape sequences (such as `\u` sequences, `\\`, etc.)
454
468
are decoded.
455
469
456
470
The symbols are then normalized to the
457
471
[Unicode Normalization Form C (NFC)](https://unicode.org/reports/tr15/). They
458
472
are stored internally and compared using the Unicode NFC.
459
473
460
-
For example, these four JSON strings represent the same symbol:
474
+
For example, these four object literals represent the same symbol:
461
475
462
-
-`"Å"`
463
-
-`"A\u030a"`**U+0041 `A` LATIN CAPITAL LETTER** + **U+030A ` ̊` COMBINING RING
476
+
-`{ "sym": "Å" }`
477
+
-`{ "sym": "A\u030a" }`**U+0041 `A` LATIN CAPITAL LETTER** + **U+030A ` ̊` COMBINING RING
464
478
ABOVE**
465
-
-`"\u00c5"`**U+00C5 `Å` LATIN CAPITAL LETTER A WITH RING ABOVE**
466
-
-`"\u0041\u030a"`**U+0041 `A` LATIN CAPITAL LETTER A** + **U+030A ` ̊` COMBINING RING
479
+
-`{ "sym": "\u00c5" }`**U+00C5 `Å` LATIN CAPITAL LETTER A WITH RING ABOVE**
480
+
-`{ "sym": "\u0041\u030a" }`**U+0041 `A` LATIN CAPITAL LETTER A** + **U+030A ` ̊` COMBINING RING
0 commit comments