4

Space Math

 2 years ago
source link: https://aimath.org/~farmer/spacemath/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introducing Space Math

Space Math

Mathematical notation can be ambiguous. Does h(c+1) mean the function h evaluated at c+1, or does it mean the quantity h times the quantity c+1? Does |X| refer to absolute value, determinant, cardinality, or length? Is (1,8) an open interval or a point on a coordinate plane? Does A×B refer to cross product, Cartesian product, or ordinary multiplication?

Without context, answers to those questions are only guesses. Even if the guess is correct, only someone knowledgeable in the subject will know how to pronounce the symbols. This is bad for students, because understanding how to talk about the notation is part of learning. And it is bad for anyone listening with a screen reader, because the words they hear could be different than the intended meaning.

The original author of the formula knew what they intended, but current methods of writing mathematics do not provide an easy way to distinguish between common ambiguous expressions. Space Math will provide that facility. The syntax has similarities to LaTeX (without the backslashes) and to AsciiMath (with some new features), with some ideas borrowed from Python. The lowly "space" character does a lot of the work, with intuitive macros mostlly taking care of the remainder. The following examples illustrate the idea.

Space Math syntax incorporates ingredients from LaTeX, AsciiMath, and UnicodeMath. To the extent possible, Space Math is backward compatible with all three of those languages, meaning that the majority of expressions in those systems are parsed correctly when incorporated into Space Math.

The first step in this ambitious project is to develop a formal definition of the language. Once the grammar of the language is specified, it will be possible to write a parser, and then write routines to output as LaTeX for printing and MathML for the Web (perhaps via LaTeXML), with the Web version retaining the semantic information from the original source.

Questions, comments, skeptical remarks, or expressions of interest to David Farmer [email protected]

Examples of Space Math

  1. f of the quantity x+1 plus g times the quantity y+h
    f(x+1) + g (y+h)

    f(x+1)+g(y+h)

  2. Don't require markup which can be inferred from context.

    int_5^20 4 x dx = 2x^2 |_5^20 = 750

    ∫2054xdx=2x2|205=750

    TeX forces the writer to type \, before the dx, or else the spacing looks bad. Space Math recognizes that int and d(something) form a pair, and it does the right thing. Similarly, Space Math automatically resizes the vertical evaluation bar. For those who like their integrals with an upright "d", as in dx, that is a decision concerning the output: the input markup is the same.

    Numbers are numbers, not strings of characters, so x^20 in Space Math is like x^{20} in TeX. Since a number next to a letter automatically means implied multiplication, the space in 4 x is optional.

  3. Don't write |x|. Write abs(x), or card(x), or len(x) or length(x), or det(x), whichever you mean. (In simple cases, the parentheses around the argument of those functions is optional: abs -5 = 5 becomes |−5|=5. )

    abs(x) = cases: x if x > 0, -x when x < 0, 0 otherwise.

    |x|={xif  x>0,−xwhen  x<0,0otherwise.

    Space Math uses a Python-like syntax for multiline constructions (but is not rigid about requiring the exact same indentation on every line). In the cases environment it recognizes several common keywords, as shown above.

  4. Leave space around symbols like < when they are used literally, such as 3 + 5 < 10 - 1. That example happens to work if you omit all the spaces, but in other situations the presence (or absence) of spaces helps clarify the meaning.

    ZZ prod ZZ isom <a, b | a b = b a>

    <u, v> = 0 "if" u perp v

     

    Z×Z≃⟨a,b | ab=ba⟩

    ⟨u,v⟩=0   if   u⊥v

    The space before and lack of space after the <, and vice-versa for >, helps ensure the expressions are interpreted correctly.

    The abbreviations prod, isom, and perp can be written out fully. Replacing prod by cross, times, or by will achieve the same visual appearance, but the operation being performed is the product of groups, and using different markup could cause incorrect interpretation. (We wrote "could", because the software may be clever enough to recognize that Z is a group, and so those other operations either don't make sense, or are less likely. But that is not an argument against writing the markup properly.)

    Under discussion: What is the right way to indicate that u and v in the above example are vectors? Maybe vec u? Who controls whether the vector v is displayed as bold v, or with a little arrow →v, or in some other way?

    The meaning of an expression, and more importantly its pronunciation, can depend on the subject area. What looks like a group presentation in algebra, <a | b>, is bra-ket notation in physics. The accuracy of Space Math is increased when the subject is specified.

  5. Multiline aligned expressions. Consider the system of nonlinear equations and inequalities

    system: 15 x^33 + pi x y = 99

    x <= 2 x + 5y - 7 x^11 + 9y^3

    cos(x y^-1) gt 1 + 2 + ... + 100

    + hat y_j - conj(x^2)

    15x33+πxy=(99x≤(2x+5y−7x11+9y3cos(xy−1)>(1+2+⋯+100+ˆyj−¯x2

    Several principles are illustrated. The system environment recognizes a new math line by a blank line. Default alignment is after the first relation in the line, or before the first symbol in the line. (There also is LaTeX style &-alignment.)

    Decorations, like ˜f, are interpreted as having higher priority than subscripts or superscripts, and so do not require parentheses when applied to a one-letter object. Don't write overline or bar when you intend mean or conj[ugate] or line[segment] or some other specific object/operation.

    The ... were interpreted as \cdots in the above setting, but would be interpreted as \ldots in an expression like $2, 4, 6, 8, ...$. The special words cdots and ldots are available for those who do not trust Space Math to do the right thing.

    The linearsystem variant assumes the system is linear and all the unknowns are on the left side. The output vertically aligns the terms with the same variable, leaving a blank if the coefficient of a term is 0. If you have a system which is linear but you don't want the terms to line up, then just use system.

  6. Trigonometric functions are special. There is a long history of omitting the parentheses around the argument to a trig function in certain situations. For example, sinπ/2=1. Logarithms are also treated that way: log2≈0.694. Not everyone considers this to be good practice, but it is common and Space Math supports it. The implied argument property of "trig-like functions" is formalized in the following way:

    Function application has higher priority than addition and higher priority than multiplication by a function, but lower priority than multiplication involving numbers and variables.

    For example:

    sin 2 pi n alpha = 2sin pi n alpha cos pi n alpha

     

    sin2πnα=2sinπnαcosπnα

    The argument to the trig function on the left is 2πnα, and the argument to each trig function on the right is πnα. Visually, the output looks the same as TeX, but Space Math provides extra information to a screen reader. The multiple spaces before the cos in the source are interpreted the same as one space.

    By default the output shows the parentheses as given in the input, but there is an output option which inserts the implied parentheses.

  7. Iterated subscripts or superscripts prioritize from the right. Use double subscript __ or double superscript ^^ to put symbols on the left.

    e^-x^2 + a_n_i + c_{j k} + F_1__2(a, b; c; z)

     

    e−x2+ani+cjk+2F1(a,b;c;z)

    If you intend to mean (eσ)2 then use parentheses in the source — after all, those are required for clarity in the output. Writing e5x2 or ex2−7 requires grouping in the source. Note that the unary minus in e^-x^2 causes -x^2 to be a group.

    In the expression a_{1 1} the 1 1 is viewed as a double index, not implied multiplication. Writing a_11 does not require brackets, and refers to the j=11 element of the sequence (a_j)_{j=0}^infty.

    Under discussion: does 5 -3 mean "5 times negative 3" or "5 minus 3"? Viewed literally, it looks like multiplication. But it is confusing to typeset that expression with implied multiplication and no parentheses, so it seems unlikely that is what the author intended. Does 1/2pi have the π in the numerator or the denominator? Do the spaces in these versions change the meaning?: 1 / 2 pi or 1/2 pi. If the author really meant π/2, is it likely they would have typed any of those expressions? (Opinion: possibly one of those three options, but definitely not the other two.)

    Space Math is not a programming language: it is a convenient way to type math formulas while capturing the author's intent.

    Space Math allows the author to specify a subject area. This adjusts certain defaults. For example, in chemistry the elements are set in an upright font. The isotope used for radiocarbon dating, 14C can be written C^^14. Under discussion: should Space Math understand the mhchem ch macro?

  8. Any discussion of math markup has to mention the quadratic formula, right? Note that, as usually written in TeX, quantities such as bx and 4ac appear imperfectly because there is no small space between b and x, or between a and c. Multiletter variables are not distinguished from a product of variables. Space Math inserts those very thin spaces automatically, because it interprets the space in the source as implied multiplication. (Note that some people do not like the thin space for implied multiplication. That is a decision made at the output stage: the input markup is the same whether or not those thin spaces are desired. The examples in this document include the very thin spaces in the display math, but generally not in the inline math. Compare the 4ac above and the 4ac below.)

    The motivation for Space Math is not the appearance of the output, which comes from TeX: Space Math is converted to TeX for typesetting. The purpose is to provide an easy way to distinguish between common ambiguous expressions.

    If $a x^2 + b x + c = 0$ then $$ x = (-b +- sqrt(b^2 - 4 a c))/(2a) $$

    If ax2+bx+c=0 then x=−b±√b2−4ac2a

    There are several other ways to write the quadratic formula. Space Math understands most common LaTeX macros, with the backslash omitted, and any of (), [], or {} can be used for grouping. For example: x = frac[-b pm sqrt(b^2 - 4a c)]{2a}.

  1. What problems does Space Math solve?

    Space Math offers two advantages over other methods of typing math formulas.

    a) Expressions like a(x+h), or |X|, or (a,b), are ambiguous. A person using a screen reader (software that reads text out loud, typically to someone who cannot see the words) may hear the formulas pronounced incorrectly, giving the symbols a different meaning than intended. Space Math provides an easy way to resolve the ambiguity.

    b) TeX is a typesetting language, not an authoring language. As a consequence, in LaTeX the writer has to type characters which carry no meaning, and also must worry about fine typographic points. The input int_5^10 7x dx in Space Math produces the same appearance as \int_5^{10} 7x\,dx in TeX. The naive view is that Space Math eliminated 5 characters. The preferred interpretation is that Space Math only required the author to think about the content of the formula, not its appearance.

    Space Math can be viewed either as a way to make mathematics more accessible, or as a convenient shortcut for producing formulas in TeX.

  2. Is Space Math like (La)TeX? "I already know LaTeX and would rather not learn something else."

    Almost everything in LaTeX math mode will work as expected in Space Math, including popular packages such as amssymb. Space Math looks a lot like LaTeX math with all the backslashes and spacing adjustments deleted. But you can leave in the backslashes if you wish.

    To take advantage of the new features of Space Math, insert spaces to indicate implied multiplication instead of a 2-letter variable, or function application instead of implied multiplication: c(t + 1) is the function c evaluated at t + 1, while c (t + 1) is the quantity c times the quantity t + 1. A little space makes all the difference. In TeX, those expressions are typeset identically and a screen reader has to guess how to pronounce them. In Space Math output, there will be a tiny gap to indicate the implied multiplication and a screen reader will pronounce both expressions correctly.

  3. Is Space Math like AsciiMath? "Students find AsciiMath easy to use and I'd rather not have them learn something else."

    Many of the symbol-based expressions in AsciiMath will work as expected in Space Math and almost all AsciiMath keywords are recognized.

    Space Math provides an easy way to write some expressions which are very difficult to do in AsciiMath, such as a multiline system of equations.

    AsciiMath always interprets its keywords as keywords, even when adjacent to other letters. For example, lending in AsciiMath typesets as   ≤nd∈g , while in Space Math is it just the variable 'lending'.

  4. Is the point of Space Math to capture the semantics of the math expressions?

    Space Math is about both more, and less, than the meaning of the formulas. All four of the expressions exp(x+5)          ex+5          e5+x          e(x+5) have the same meaning, but they are pronounced differently. The author of each expression probably had a good reason for choosing that specific form. Space Math allows the writer to create the intended formula, and generally focuses on preserving the information needed to pronounce the expression correctly. When an expression can have multiple meanings, but the pronunciation is the same in all cases, typically Space Math does not attempt to make a distinction.

    For example, the symbol π often means the number which is approximately 3.14159, but it also could appear in a number theory context as π(100)=25. That is pronounced "pi of 100 equals 25" and it means there are 25 prime numbers less than 100.

    In a group theory context, the exact same formula could appear and be pronounced exactly the same, but now it means: the permutation π sends 100 to 25. In both cases, Space Math knows that π is a function because the input was pi(100) = 25 with no space between the pi and the (100), but it does not know anything about that function.

  5. Isn't it confusing and non-obvious to give meaning to spaces, especially in multi-line expressions?

    Using a space for implied multiplication becomes natural fairly quickly, and also makes sense mathematically because function application, multi-letter variables, and multiplication, are fundamentally different.

    In many other cases there are keywords available. For example, interval(3,5), point(3,5), and gcd(3,5) are unambiguous in the source, and it is a choice whether those keywords appear in the output. (Showing "point" or "interval" in the output is an unlikely choice, but that information is hidden in the output so a screen reader can make use of it. In an introductory number theory book the author might want to see gcd(3,5), but in a research paper the letters "gcd" tend not to be shown.)

    After typing "point" or "interval" repeatedly, the author may wish to have an easier way, which is available by appropriate use of spaces. One can also use "French notation" to unambiguously describe intervals on the real line: ]3,5[ is the open interval 3<x<5. The notation used in the output does not have to be the same as in the input.

    The multiline Python-like expressions have an inline form, for those who find that more natural: abs(x) = cases(x if x > 0,; -x when x < 0,; 0 otherwise.). The keyword now looks like a function, and the line ends at the semicolon. That expression can be written across several lines so that the source is easy to read and write, but it is the semicolons, not the newlines, which convey the structure.

  6. What exactly is the difference between LaTeX and Space Math?

    For those who already know LaTeX math, here is one way to think about it:

    a) Leave off all the backslashes and spacing directives like \,. Don't bother with \left or \right or \bigg or \mathstrut because size adjustments are made automatically. (And yes, there is a way to over-ride the automatic resizing.)

    b) Use spaces to make it clear if you mean multi-letter variable, or implied multiplication, or function application. Spaces also clarify a few other ambiguous constructions.

    c) Parentheses, square brackets, and curly brackets all are viewed literally, and also can be used for grouping, with the interpretation depending on context: {x | x^2 > 5} is a set and e^(x+3) is ex+3. If you intended to write e(x+3), then supply the extra parentheses: e^((x+3)) or e^[(x+3)] or e^{(x+3)}.

    d) Numbers exist as a unit: x^15 means x15. If habit makes you insert the brackets in the source, as x^{15}, you still get the same output. For compatibility with longstanding TeX practice, the frac method of creating a fraction interprets numbers as characters: frac12 means 12. That can also be written as 1/2 and you get the upright fraction 12 in the output. (And yes, there is a way to get a slanted 1/2.)

    e) Functions and their arguments exist as a unit: e^f(x) gives ef(x), while e^f (x) gives ef(x),

    f) There are a small number of special constructions which go a long way toward resolving common ambiguities. Never type |x|. Instead, use whichever of these is appropriate: abs(x), card(x), det(x), len(x) or length(x), or norm(x). Is (a,b) a point or an interval? If you can puzzle out which of (a,b) or (a, b) refers to a point and which an open interval, then you are starting to think the Space Math way. Write a times b if that is what you mean -- otherwise write a cross b or a by b, the latter for cases like "chess is played on an 8×8 grid of squares", or "a 5×7 matrix cannot have a two-sided inverse because it is not square".

    g) A few more things, which are under discussion.

  7. How can I use Space Math?

    Space Math is currently under development, with the specification of the language as the first goal.

    The second step is to write a parser, followed by output routines to convert Space Math to TeX or LaTeXML or MathML. This will enable Space Math to be used in PreTeXt. If Space Math is adopted by MathJax, then it can become widely available.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK