## 14 February 2013

### Mathematical expressions as JSON (and phyloreferencing)

For Names on Nodes I did a lot of work with MathML (specifically MathML-Content), an application of XML for representing mathematical concepts. But now, as XML wanes and JSON waxes, I've started to look at ideas for porting Names on Nodes concepts over to JSON.

I've been drawing up a very basic and extensible way to interpret JSON mathematically. Each of the core JSON values translates like so:
• Null, Boolean, and Number values are interpreted as themselves.
• Strings are interpreted as qualified identifiers (if they include `":"`) or local identifiers (otherwise).
• Arrays are interpreted as the application of an operation, where the first element is a string identifying the operation and the remaining elements are arguments.
• Objects are interpreted either as:
• a set of declarations, where each key is a [local] identifier and each value is an evaluable JSON expression (see above), or
• a namespace, where each key is a URI and each value is a series of declarations (see previous).

### Examples

Here's a simple object declaring some mathematical constants (approximately):

```{
"e": 2.718281828459045,
"pi": 3.141592653589793
}
```

Supposing we had declared some operations (only possible in JavaScript, since JSON doesn't have functions) equivalent to those of MathML (whose namespace URI is `"http://www.w3.org/1998/Math/MathML"`), we could do this:

```{
"x":```
`        ["http://www.w3.org/1998/Math/MathML:plus",`
`            1,`
`            2`
```        ],
"y":```
`        ["http://www.w3.org/1998/Math/MathML:sin",`
`            ["http://www.w3.org/1998/Math/MathML:divide",`
`                "http://www.w3.org/1998/Math/MathML:pi",`
`                2`
`            ]`
```        ]
}
```

Once evaluated, `x` would be `3` and `y` would be `1` (or close to it, given that this is floating-point math).

Now for the interesting stuff. Suppose we had declared Names on Nodes operations and some taxa using LSIDs:

```{
"Homo sapiens": "urn:lsid:ubio.org:namebank:109086",
"Ornithorhynchus anatinus": "urn:lsid:ubio.org:namebank:7094675",
"Mammalia":```
`        ["http://namesonnodes.org/ns/math/2013:clade",`
`            ["http://www.w3.org/1998/Math/MathML:union",`
`                "Homo sapiens",`
`                "Ornithorhynchus anatinus"`
`            ]`
`        ]`
```}
```

Voilá, a phylogenetic definition of Mammalia in JSON!

I think this could be pretty useful. My one issue is the repetition of  long URIs. It would be nice to have a mechanism to import them using shorter handles. Maybe something like this?

```{
"mathml":   "http://www.w3.org/1998/Math/MathML:*",
"namebank": "urn:lsid:ubio.org:namebank:*",
"NoN":      "http://namesonnodes.org/ns/math/2013:*",

"Mammalia":```
`        ["NoN:clade",`
`            ["mathml:union",`
`                "namebank:109086",`
`                "namebank:7094675"`
`            ]`
```        ]
}```

Something to ponder. Another thing to ponder: what should I call this? MathON? MaSON?