Universal Language for Mathematics (ULM)

⚠️ DRAFT

1Overview

ULM is a language for describing both the semantics and presentation of mathematical expressions.

Here is a simple expression written in ULMScript:

Example № 1+(2, 2)

That’s just 2 + 2.

Here is a more complicated expression:

Example № 2=(
  -(
    245.5,
    ÷(11, 2, { division-style: "fraction" })
  ),
  *(
    +(100, 20),
    2,
    { color: "blue" }
  )
)

Which could be displayed like this:

example

2Source

SourceChar
/[\u0009\u000A\u000D\u0020-\uFFFF]/
UnicodeBOM
Byte Order Mark (U+FEFF)
WhiteSpace
Horizontal Tab (U+0009)
Space (U+0020)
LineTerminator
New Line (U+000A)
Carriage Return (U+000D)New Line (U+000A)
Carriage Return (U+000D)New Line (U+000A)
SeparatorChar
,
;
Sign
-+
Digit
0123456789_
TrueDigit
LeadingDigit
IdentifierChar
Square brackets ([ and ]) are not currently used in the language, but have been reserved to represent lists in the future.
LeadingIdentifierChar
EscapedUnicode
/[0-9A-Fa-f]{4}/
EscapedChar
"\/bfnrt
StringChar
CommentChar

3Tokens

3.1Separator

3.2Comment

Example № 3// This is a comment! 😃

3.3LeftParen

3.4RightParen

3.5LeftCurly

3.6RightCurly

3.7Colon

3.8NaturalNumberLiteral

A positive integer ({ 1, 2, 3, … }).

An natural number literal must always have an n suffix:

Example № 41n
Example № 534n

Underscores may be used to make large numbers easier to read:

Example № 66_935n

Zero is not a natural number:

Counter Example № 70n

Natural number literals cannot have leading underscores:

Counter Example № 8_42n

3.9IntegerNumberLiteral

An integer number literal must always have an i suffix:

Example № 90i
Example № 1052i
Example № 11500i
Counter Example № 12-2

Underscores may be used to make large numbers easier to read:

Example № 135_000i

Integer number literal can be prefixed with either a positive or negative sign:

Example № 14-0i
Example № 15-52i
Example № 16-500i
Example № 17-5_000i
Example № 18+0i
Example № 19+52i
Example № 20+500i
Example № 21+5_000i

Integer number literals cannot have leading zeros or underscores:

Counter Example № 22042i
Counter Example № 23-042i
Counter Example № 24_42i

3.10RationalNumberLiteral

Example № 250
Example № 2612
Example № 270.4
Example № 280.50
Example № 2940.145
Example № 305_542.1_11
Example № 310/1
Example № 320/1_000
Example № 331/1
Example № 341_243/1000
Example № 35-0
Example № 36-12
Example № 37-0.4
Example № 38-0.50
Example № 39-40.145
Example № 40-5_542.1_11
Example № 41-0/1
Example № 42-0/1_000
Example № 43-1/1
Example № 44-1_243/1000
Example № 45+0
Example № 46+12
Example № 47+0.4
Example № 48+0.50
Example № 49+40.145
Example № 50+5_542.1_11
Example № 51+0/1
Example № 52+0/1_000
Example № 53+1/1
Example № 54+1_243/1000

3.11StringLiteral

Example № 55"This is a string"

3.12Identifier

The TRUE and FALSE identifiers are not currently used in the language, but have been reserved to represent boolean literals in the future.
Example № 56+
Example № 57^
Example № 58**
Example № 59atan2
Example № 60PascalCase
Example № 61snake_case
Example № 62-kebab-case-
Example № 63__this_is_valid!__

This is not a comment because there is no separator between foo and //:

Example № 64foo//bar

4Syntax

4.1Ignored

Comment:

Example № 65// Hello, this is a comment.

Separator:

Example № 66,
  ;

4.2Value

Example № 675n
Example № 68-48i
Example № 69-48/7
Example № 700.53
Example № 71"Hello"

4.3NamedValue

Example № 72foo:5n
Example № 73foo : 5n

4.4Operand

Operand
Operator
Example № 745n
Example № 75foo()

4.5Presentation

Example № 76{ color: "red" }
Example № 77{ color: "red"; number-format: "fraction"; }

4.6Expression

Example № 78foo()
Example № 79foo(bar())
Example № 80foo(bar() abc:"xyz")
Example № 81foo(bar() abc:"xyz" {color:"red"})
Example № 82foo ( bar() abc:"xyz" {color:"red"} )
Example № 83foo(bar(), abc: "xyz", { color: "red" })

4.7Document

Example № 84// Foo
foo()

// Bar
bar()

5Expressions

5.1Group

A group has no semantic meaning, but can be used to apply presentation rules to expressions or values.

Example № 85Group(25, +(1, 16))
Example № 86g(25, +(1, 16), { color: "red" })

5.2AmbiguousSymbol

Example № 87AmbiguousSymbol("x")
Example № 88$("x")
Example № 89=($("x"), 25) // x = 25

5.3AmbiguousPlaceholder

Example № 90AmbiguousPlaceholder()
Example № 91?({ color: "red" })

5.4AmbiguousAdditionOperation

Example № 92AmbiguousAdditionOperation(11, 31)
Example № 93+(5, 5, { color: "red" })

5.5AmbiguousSubtractionOperation

5.6AmbiguousMultiplicationOperation

5.7AmbiguousDivisionOperation

5.8AmbiguousEqualRelation

5.9AmbiguousNotEqualRelation

5.10NumericAdditionOperation

5.11NumericSubtractionOperation

5.12NumericMultiplicationOperation

5.13NumericDivisionOperation

5.14NumericEqualRelation

5.15NumericNotEqualRelation

6Presentation

§Index

  1. Colon
  2. Comment
  3. CommentChar
  4. Digit
  5. DocPart
  6. Document
  7. EscapedChar
  8. EscapedUnicode
  9. Expression
  10. ExpressionArgs
  11. Identifier
  12. IdentifierChar
  13. Ignored
  14. IntegerNumberLiteral
  15. LeadingDigit
  16. LeadingIdentifierChar
  17. LeftCurly
  18. LeftParen
  19. LineTerminator
  20. NamedValue
  21. NamedValue_list
  22. NaturalNumberLiteral
  23. Operand
  24. Operand_list
  25. Presentation
  26. RationalNumberLiteral
  27. RightCurly
  28. RightParen
  29. Separator
  30. SeparatorChar
  31. Sign
  32. SourceChar
  33. StringChar
  34. StringLiteral
  35. TrueDigit
  36. UnicodeBOM
  37. Value
  38. WhiteSpace
  1. 1Overview
  2. 2Source
  3. 3Tokens
    1. 3.1Separator
    2. 3.2Comment
    3. 3.3LeftParen
    4. 3.4RightParen
    5. 3.5LeftCurly
    6. 3.6RightCurly
    7. 3.7Colon
    8. 3.8NaturalNumberLiteral
    9. 3.9IntegerNumberLiteral
    10. 3.10RationalNumberLiteral
    11. 3.11StringLiteral
    12. 3.12Identifier
  4. 4Syntax
    1. 4.1Ignored
    2. 4.2Value
    3. 4.3NamedValue
    4. 4.4Operand
    5. 4.5Presentation
    6. 4.6Expression
    7. 4.7Document
  5. 5Expressions
    1. 5.1Group
    2. 5.2AmbiguousSymbol
    3. 5.3AmbiguousPlaceholder
    4. 5.4AmbiguousAdditionOperation
    5. 5.5AmbiguousSubtractionOperation
    6. 5.6AmbiguousMultiplicationOperation
    7. 5.7AmbiguousDivisionOperation
    8. 5.8AmbiguousEqualRelation
    9. 5.9AmbiguousNotEqualRelation
    10. 5.10NumericAdditionOperation
    11. 5.11NumericSubtractionOperation
    12. 5.12NumericMultiplicationOperation
    13. 5.13NumericDivisionOperation
    14. 5.14NumericEqualRelation
    15. 5.15NumericNotEqualRelation
  6. 6Presentation
  7. §Index