Plurimath

Plurimath now supports MathML intent

Author’s picture Suleman Uzair Author’s picture Ronald Tse on 18 Sep 2024

The art of math representation

MathML, OMML, LaTeX math, AsciiMath, and UnicodeMath are commonly used math representation languages used to encode math in digital form. Each of these systems has its own syntax and conventions for representing mathematical expressions.

Consider the representation of math itself to be two separate but related problems:

  • Visual representation: How math looks when rendered on a screen or paper.

  • Semantic representation: What math means, and how it can be interpreted by software. i.e. how math can be understood and processed by machines.

The common usage today is focused on the former — presenting mathematical expressions visually.

Semantic math

Purpose

Semantic math is the method of encoding mathematical expressions to reflect their meaning and structure, not just how they look.

This means that instead of just seeing symbols and numbers, software can understand what those symbols and numbers represent. In effect, it allows software to interpret and process mathematical expressions and content.

There are several reasons why semantic math is important:

  • Disambiguation: Understanding the meaning behind an expression avoids ambiguity and misinterpretation of math content.

  • Accessibility: Screen readers and other assistive technologies can read math out loud with the correct meaning to visually impaired users.

  • Interoperability: Software can exchange and process math content with preserved meaning.

Represented meaning behind symbols

The greek symbol "eta" (η) is commonly used to represent in physics:

  • efficiency, which is a dimensionless value

  • dynamic viscosity, which has a unit of Pa·s or N·s/m²

Given a mathematical expression like "η = 0.85":

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mi>η</mi>
  <mo>=</mo>
  <mn>0.85</mn>
</math>

It is unclear whether it represents:

  • "η = 0.85": efficiency is 0.85

  • "η = 0.85": dynamic viscosity is 0.85

Semantic math can encode the specific meaning behind the symbol.

Differentiated operators and variables

Given this MathML encoding of "ΔH":

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mi>Δ</mi>
  <mi>H</mi>
</math>

It is unclear whether it represents:

  • "ΔH": a change in enthalpy (in thermodynamics)

  • "Δ · H": area of a triangle with base Δ and height H

Presentation MathML is unable to differentiate between these two meanings, but semantic math can encode the specific meaning behind the symbol.

MathML 4 and semantic math

Introduction

MathML is the W3C standard for representing mathematical content on the web. MathML 3, published in 2014, provides two forms of math representation, namely Presentation MathML and Content MathML.

Content MathML is MathML’s answer to semantic encoding. In particular, "Strict Content MathML" is designed to be an implementation of OpenMath (hence compatible).

OpenMath is a standard developed by the OpenMath Society for representing formal mathematical objects and semantics through the use of extensible Content Dictionaries.

Content MathML is meant to be used in "Parallel Markup" with Presentation MathML, which is to say that Content MathML is to be used alongside Presentation MathML to provide both visual and semantic representation of math.

Unfortunately, the complexity and verbosity of Content MathML and OpenMath have limited their adoption — it is already difficult enough to encode expressions for visual presentation, requiring an additional content encoding increases the burden significantly.

Due to a similar history, other math representation languages have also been solely focused on visual representation, with little emphasis on semantic understanding.

MathML 4 and intent

MathML 4 revamps this situation with the new focus on semantic math by introducing the intent attribute to Presentation MathML, a way to bridge with Content MathML to clarify the meaning of different parts of a math expression.

Think of it as adding a descriptive note to a math symbol to indicate what it represents. This is particularly useful for tools that need to interpret math, such as screen readers for visually impaired users or search engines.

By using the intent attribute in MathML 4, you can provide explanatory notes for symbols that represent specific mathematical functions. This ensures that anyone (or any software) reading the MathML can understand the exact purpose of each symbol.

For example:

Example 1. Using intent in MathML 4 to represent the absolute value of "x"
<mrow intent="absolute-value($x)">
  <mo>|</mo>
  <mi arg="x">x</mi>
  <mo>|</mo>
</mrow>

In this example, the intent attribute is used to specify that the expression represents the absolute value of "x". Without it, it would be difficult for the reader (or the software) to understand the specific meaning of the expression, potentially leading to misinterpretation or loss of context.

Tip
For detailed information about the intent attribute, visit the MathML 4 intent-explainer page.

Intent operators

MathML 4 introduces a standardized set of intent operators that can be used to encode semantic math expressions. These operators are used to indicate the intent of the expression, providing additional context and meaning to the math symbols.

The full list of intent operators can be found at the MathML 4 intent-explainer page.

UnicodeMath and semantic math

Introduction

UnicodeMath is a plain text representation of mathematical notation that leverages Unicode characters to encode mathematical symbols and structures. Plurimath has supported UnicodeMath in all releases since April 2024.

The creator of UnicodeMath, Murray Sargent III, is a member of the MathML Working Group and has been involved in the development of MathML 4. He has extended UnicodeMath to work with MathML 4, in particular support for the intent attribute.

MathML, being an XML format, is today primarily used as a canonical representation of a math expression, instead of an input format. Economical math representation languages, such as UnicodeMath and AsciiMath, are used as input formats for math expressions for translation into MathML.

The latest version of UnicodeMath supports the intent attribute, allowing UnicodeMath to encode semantic math expressions in MathML 4.

Encoding intent

The latest version of UnicodeMath introduces a new "intent" operator (U+24D8) for indicating intent.

Let’s take the example of encoding the absolute value of "x" in UnicodeMath. The MathML intent operator for the math operation of "absolute value" is absolute-value(…​).

To encode this in UnicodeMath, the operator is used to denote the intent of an expression with the following syntax.

UnicodeMath syntax for encoding intent
ⓘ("{mathml-intent-operator-and-function}" {math-expression})

The intent expression is composed of two elements:

  • the intent string;

  • the expression to which the intent is applied.

The following example demonstrates how the absolute value of "x" is encoded in UnicodeMath using the operator.

Example 2. Using intent in UnicodeMath to represent the absolute value of x
ⓘ("absolute-value(x)" |𝑥|)
Note
Currently, Plurimath supports encoding of intent in UnicodeMath via the ⓘ syntax, but not the output of intent-enabled expressions in UnicodeMath with the ⓘ syntax.

Encoding intent in Plurimath

Explicit encoding

There are two ways to explicitly express intent in Plurimath.

  1. via MathML: Plurimath supports the intent attribute when MathML is used as the input for a Formula object.

  2. via UnicodeMath: Plurimath supports the intent operator when UnicodeMath is used as the input for a Formula object.

Example 3. Encoding explicit intent in Plurimath using MathML
xml <~HERE
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mstyle displaystyle="true">
    <mrow intent="absolute-value(x)">
      <mo>|</mo>
      <mi>x</mi>
      <mo>|</mo>
    </mrow>
  </mstyle>
</math>
HERE
formula = Plurimath::Math.parse(xml, :mathml)
formula.to_mathml(intent: true)
# =>
# <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
#   <mstyle displaystyle="true">
#     <mrow intent="absolute-value(x)">
#       <mo>|</mo>
#       <mi>x</mi>
#       <mo>|</mo>
#     </mrow>
#   </mstyle>
# </math>
Example 4. Encoding explicit intent in Plurimath using UnicodeMath
formula = Plurimath::Math.parse('"ⓘ("absolute-value(x)" |𝑥|)"', :mathml)
formula.to_mathml(intent: true)
# =>
# <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
#   <mstyle displaystyle="true">
#     <mrow intent="absolute-value(x)">
#       <mo>|</mo>
#       <mi>x</mi>
#       <mo>|</mo>
#     </mrow>
#   </mstyle>
# </math>

Implicit encoding (automatic intent)

Other than explicitly specifying intent, Plurimath supports semantic notions of math operators, and can automatically provide implicit intent when converting to MathML. Hence the easiest way of encoding intent is to simply trust Plurimath to do it.

Using the math operation of obtaining the absolute value of "x" as an example:

  • Plurimath understands the AsciiMath encoding of the function abs(…​) as the absolute value operation.

  • Plurimath will automatically encode the intent of the operation when converting to MathML.

By default, intent encoding is not enabled in MathML output. You will need to specify the intent: true option when converting to MathML.

For example:

Example 5. Using implicit intent in Plurimath to represent the absolute value of "x"
math = Plurimath::Math.parse("abs(x)", :asciimath)
puts math.to_mathml(intent: true)
> <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
>   <mstyle displaystyle="true">
>     <mrow intent="absolute-value(x)">
>       <mo>|</mo>
>       <mi>x</mi>
>       <mo>|</mo>
>     </mrow>
>   </mstyle>
> </math>

If value of abs exceeds one word, an arg attribute will be used to reference the value of abs.

For example:

Example 6. Using intent in Plurimath to represent the absolute value of an equation
math = Plurimath::Math.parse("abs(xy)", :asciimath)
puts math.to_mathml(intent: true)
> <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
>   <mstyle displaystyle="true">
>     <mrow intent="absolute-value($a)">
>       <mo>|</mo>
>       <mrow arg="a">
>         <mi>x</mi>
>         <mi>y</mi>
>       </mrow>
>       <mo>|</mo>
>     </mrow>
>   </mstyle>
> </math>
Note
The intent option for to_…​ methods is not supported by any language other than MathML.

Operations that support intent encoding

The full list of intent concepts are found at:

The full list of Plurimath classes that support intent encoding are found at:

Support for intent in other math languages

Currently, MathML and UnicodeMath are the only math languages that support intent encoding. OMML, AsciiMath and LaTeX math do not have any syntax available for intent encoding.

The Plurimath team is constantly evaluating the need for intent encoding in other math languages and will consider adding support for intent encoding in other math languages in the future.

Conclusion

Semantic math is the future of digital math representation. With the advent of MathML 4 and the introduction of the intent attribute, it is now possible to encode the meaning and structure of mathematical expressions in a way that can be understood by software.

Plurimath is one of the first math libraries that provide full support for intent encoding, including in the understanding of intent in both MathML and UnicodeMath.

By leveraging the power of semantic math, Plurimath makes math more accessible and understandable for everyone.