Interpreting math syntax

25 views
Skip to first unread message

Jeremy Sylvestre

unread,
Mar 23, 2023, 10:57:27 AM3/23/23
to PreTeXt development
New thread because I don't want to hijack the discussion about sin x vs sin(x).

From David's "new math syntax question" thread:

On Sat, Mar 11, 2023 at 1:34 PM David W. Farmer <far...@aimath.org> wrote:
The specific goal is accessibility.  Being able to easily indicate
that  |A|  means determinant, not cardinality or absolute value.

"Easily" is probably impossible.

Unless you're going to implement some form of NLP to pick up context clues from the surrounding text as a human would, knowing that an isolated piece of math like
<m>|A^T|</m>
means det(transpose(matrix)) and not abs(number^exp) cannot be done without some form of "semantic macros."

But I guess nobody wants to type
<m>\determinant{\transpose{A}}</m>
?
Even though I was there @ the workshop in Texas and expressed interest in this solution, I don't know the history of its failure.

My crazy idea: turn your math syntax into a typed language.

Somewhere in your document preamble, *tell* the document processor that some of the objects you will use will be of "matrix" type.

<math-types>
...
matrix (matrices)
...
</math-types>

Somewhere in your document preamble, *tell* the document processor that |∙| is an overloaded function that accepts a matrix and returns a number, and *tell* the processor how to render it in LaTeX and how to "read" it as a text-to-speech string.

<math-notation>
...
delimiter_pair matrix⇒number "| _ |" "\lvert _ \rvert" "determinant of _"
...
</math-notation>

Then, at the beginning of a chapter (or section or ...), *tell* the document processor what variables you will use:

<math-declare>
...
A :: matrix
...
</math-declare>

Now the processor can reliably turn
<m>|A|</m>
into
\( \lvert A \rvert \)
and can also somehow attach a text-to-speech string
"determinant of matrix A".

You could optionally do type declaration inline for one-off variables too:

<m>|A::matrix|</m>

Want to use the same syntax for norm of a vector but have it produce different math notation?

<math-types>
...
vector
...
</math-types>

<math-notation>
...
type vector "\vec{_}"
delimiter_pair vector⇒number "| _ |" "\lVert _ \rVert" "norm of _"
...
</math-notation>

Then

<math-declare>
u v :: vector
</math-declare>

coupled with

<p>It is only true that <m>|u + v|^2 = |u|^2 + |v|^2</m> if <m>u</m> and <m>v</m> are orthogonal.</p>

magically becomes:

It is only true that \( {\Vert \vec{u} + \vec{v} \rVert}^2 = {\Vert \vec{u} \rVert}^2 + {\Vert \vec{v} \rVert}^2</m> if \(\vec{u}\) and \(\vec{v}\) are orthogonal.

in output, and can also become text-to-speech:

It is only true that "square of norm of sum vector u plus v is equal to square of norm of vector u plus square of norm of vector v" if "vector u" and "vector v" are orthogonal.

(Of course, the system would somehow also need to know or be told that + is an overloaded infix operator for both vector⇒vector⇒vector and number⇒number⇒number, and also not to put an extra \vec{} around the sum.)

This could get quite complicated on the implementation side, but could also be very powerful in terms of solving the accessibility problem you identify.

You might think that authors would balk at having to create the <math-types> and <math-notation> preamble elements. But these could be in standard "packages" distributed with PreTeXt that could then be easily edited by publishers to alter syntax/notation.

But ideas are easy, implementation is hard, and convincing others to adopt a radical "solution" is probably even harder....   The potentially good news is that people in the formalized-mathematics community already know how to create a system of runtime-specified syntax/notation that can be parsed, type-checked, and displayed/presented in other formats.

Cheers,
Jeremy S

David W. Farmer

unread,
Mar 25, 2023, 4:07:17 PM3/25/23
to PreTeXt development

I was heading toward a couple of things Jeremy suggested.

First is that we need both author switches and publisher switches.

One author might want to specify that "G" is (always?) a group.
Another might want to say that "G" is the universal gravitational
constant.

Similarly for specifying that "A" is a matrix.

A publisher might want to specify that "the transpose of a
matrix" is written with superscript T on the left instead of
the right. Or maybe the complex conjugate of z is z^*
instead of \overline{z} . Or specify that the vector v
should be bold instead of having a little arrow on top.
(This is just like using standard macros, and then changing
the definition of those macros.)

Having the appearance independent of the input also makes it
easier to share source material.

I also agree with the "packages" idea, which I interpret as:
I say that I am writing abstract algebra, and that gives me a
bunch of presets, such as [g, h] is a commutator. (If I chose
"number theory", maybe that means lcm.)

Space Math interprets this correctly, meaning that the output
looks right and contains the necessary semantic information:

We have $abs(u+v)^2 <= abs(u)^2 + abs(v)^2$, for all $u,v in CC$,
while $norm(vec u + vec v)^2 = norm(vec u)^2 + norm(vec v)^2$ only
if $vec u perp vec v$.

Currently it typesets "absolute value" and "norm" the same, and it
makes vectors bold (without an arrow on top). Changing publisher
options is much easier that dealing with author options.

I am not optimistic about a processing system which "knows" that,
locally, |.| means "norm". This forces the author to do something
different when they occasionally need absolute value. But, I think
it is possible to have an editing system which knows that locally
it means norm, but it silently converts it to norm(.) . That
preserves the option of sharing the source.

David
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pretext-dev...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-dev/CALMYOnf%3DKcsYBH-Gks26MmjEa4h%2BXfnVh%2B2Yz_gZ4LCZEdQ9ig%40mail.gmail.com.
>
>

David W. Farmer

unread,
Mar 31, 2023, 11:02:33 AM3/31/23
to PreTeXt development

I have made a list of test expressions, either for me to test my code,
or for others to see how I am thinking about the syntax.
More examples are welcome (just add to the doc, or post here for
discussion).

https://docs.google.com/document/d/11v2wej18qkVjng3rw9Gfy9fxzmWu-CYhaJIL_1Voyp4/edit


It is interesting to compare with another new effort:

https://typst.app/docs/reference/math/


Regards,

David

Reply all
Reply to author
Forward
0 new messages