Name generation APIs for to_additive
#
A set of strings of names that end in a capital letter.
- If the string contains a lowercase letter, the string should be split between the first occurrence of a lower-case letter followed by an upper-case letter.
- If multiple strings have the same prefix, they should be grouped by prefix
- In this case, the second list should be prefix-free (no element can be a prefix of a later element)
Todo: automate the translation from String
to an element in this TreeMap
(but this would require having something similar to the rb_lmap
from Lean 3).
Equations
Instances For
This function takes a String and splits it into separate parts based on the following naming conventions.
E.g. #eval "InvHMulLEConjugate₂SMul_ne_top".splitCase
yields
["Inv", "HMul", "LE", "Conjugate₂", "SMul", "_", "ne", "_", "top"]
.
Helper for capitalizeLike
.
Capitalizes s
char-by-char like r
. If s
is longer, it leaves the tail untouched.
Equations
Instances For
Capitalize First element of a list like s
.
Note that we need to capitalize multiple characters in some cases,
in examples like HMul
or hAdd
.
Equations
- ToAdditive.capitalizeFirstLike s (x_1 :: r) = ToAdditive.capitalizeLike s x_1 :: r
- ToAdditive.capitalizeFirstLike s [] = []
Instances For
Turn each element to lower-case, apply the nameDict
and
capitalize the output like the input.
Equations
Instances For
There are a few abbreviations we use. For example "Nonneg" instead of "ZeroLE"
or "addComm" instead of "commAdd".
Note: The input to this function is case sensitive!
Todo: A lot of abbreviations here are manual fixes and there might be room to
improve the naming logic to reduce the size of fixAbbreviation
.
Instances For
Autogenerate additive name. This runs in several steps:
- Split according to capitalisation rule and at
_
. - Apply word-by-word translation rules.
- Fix up abbreviations that are not word-by-word translations, like "addComm" or "Nonneg".
Equations
- ToAdditive.guessName = String.mapTokens '\'' fun (s : String) => String.join (ToAdditive.fixAbbreviation (ToAdditive.applyNameDict s.splitCase))