The areas / V34. The tactics of Mathlib
Mathlib.Tactic.Translate.GuessName
22 declarations. Mathlib docs · Source
Name generation APIs for to_additive-like attributes
def Mathlib.Tactic.GuessName.instInhabitedGuessNameData.default E1 #
Mathlib.Tactic.GuessName.GuessNameData
theorem Mathlib.Tactic.GuessName.GuessNameData.mk.inj E1 #
∀ {nameDict : Std.HashMap String (List String)} {abbreviationDict : Std.HashMap String String}
{nameDict_1 : Std.HashMap String (List String)} {abbreviationDict_1 : Std.HashMap String String},
{ nameDict := nameDict, abbreviationDict := abbreviationDict } =
{ nameDict := nameDict_1, abbreviationDict := abbreviationDict_1 } →
nameDict = nameDict_1 ∧ abbreviationDict = abbreviationDict_1
theorem Mathlib.Tactic.GuessName.GuessNameData.mk.injEq E0 #
∀ (nameDict : Std.HashMap String (List String)) (abbreviationDict : Std.HashMap String String)
(nameDict_1 : Std.HashMap String (List String)) (abbreviationDict_1 : Std.HashMap String String),
({ nameDict := nameDict, abbreviationDict := abbreviationDict } =
{ nameDict := nameDict_1, abbreviationDict := abbreviationDict_1 }) =
(nameDict = nameDict_1 ∧ abbreviationDict = abbreviationDict_1)
def Mathlib.Tactic.GuessName.GuessNameData.ctorIdx E1 #
Mathlib.Tactic.GuessName.GuessNameData → ℕ
structure Mathlib.Tactic.GuessName.GuessNameData E1 #
Type
The data that is required to guess the name of a translation.
ctor Mathlib.Tactic.GuessName.GuessNameData.mk E0 #
Std.HashMap String (List String) → Std.HashMap String String → Mathlib.Tactic.GuessName.GuessNameData
abbrev Mathlib.Tactic.GuessName.GuessNameData.nameDict E1 #
Mathlib.Tactic.GuessName.GuessNameData → Std.HashMap String (List String)
Dictionary used by guessName to autogenerate names.
This only transforms single name components, unlike abbreviationDict.
Note: guessName capitalizes the output according to the capitalization of the input.
In order for this to work, the input should always start with a lower case letter, and the output
should always start with an upper case letter.
abbrev Mathlib.Tactic.GuessName.GuessNameData.abbreviationDict E1 #
Mathlib.Tactic.GuessName.GuessNameData → Std.HashMap String String
We need to fix a few abbreviations after applying nameDict, i.e. replacing ZeroLE by Nonneg.
This dictionary contains these fixes.
The input should contain entries that is in lowerCamelCase (e.g. ltzero; the initial sequence
of capital letters should be lower-cased) and the output should be in UpperCamelCase
(e.g. LTZero).
When applying the dictionary, we lower-case the output if the input was also given in lower-case.
instance Mathlib.Tactic.GuessName.instInhabitedGuessNameData E0 #
Inhabited Mathlib.Tactic.GuessName.GuessNameData
def Mathlib.Tactic.GuessName.endCapitalNames E1 #
Std.TreeMap String (List String) compare
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).
opaque Mathlib.Tactic.GuessName.String.splitCase E1 #
String → optParam String.Pos.Raw 0 → optParam (List String) [] → List String
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"].
opaque Mathlib.Tactic.GuessName.String.decapitalizeSeq E1 #
String → optParam String.Pos.Raw 0 → String
Replaces characters in s by lower-casing the first characters until a non-upper-case character
is found.
def Mathlib.Tactic.GuessName.decapitalizeLike E1 #
String → String → String
If r starts with an upper-case letter, return s, otherwise return s with the
initial sequence of upper-case letters lower-cased.
def Mathlib.Tactic.GuessName.decapitalizeFirstLike E1 #
String → List String → List String
Decapitalize the first element of a list if s starts with a lower-case letter.
Note that we need to decapitalize multiple characters in some cases,
in examples like HMul or HAdd.
def Mathlib.Tactic.GuessName.applyNameDict E1 #
Mathlib.Tactic.GuessName.GuessNameData → List String → List String
Apply the nameDict and decapitalize the output like the input.
E.g.
#eval applyNameDict ["Inv", "HMul", "LE", "Conjugate₂", "SMul", "_", "ne", "_", "top"]
yields ["Neg", "HAdd", "LE", "Conjugate₂", "VAdd", "_", "ne", "_", "top"].
def Mathlib.Tactic.GuessName.fixAbbreviationAux E0 #
Mathlib.Tactic.GuessName.GuessNameData → List String → List String → String
Helper for fixAbbreviation.
Note: this function has a quadratic number of recursive calls, but is not a performance
bottleneck.
def Mathlib.Tactic.GuessName.fixAbbreviation E1 #
Mathlib.Tactic.GuessName.GuessNameData → List String → String
Replace substrings according to abbreviationDict, matching the case of the first letter.
Example:
#eval applyNameDict ["Mul", "Support"]
gives the preliminary translation ["Add", "Support"]. Subsequently
#eval fixAbbreviation ["Add", "Support"]
"fixes" this translation and returns Support.
def Mathlib.Tactic.GuessName.guessName E1 #
Mathlib.Tactic.GuessName.GuessNameData → String → String
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".
def Mathlib.Tactic.GuessName.renameBinderNames E1 #
Mathlib.Tactic.GuessName.GuessNameData → Lean.NameMap Lean.Name → Lean.Expr → Lean.Expr
Rename binder names in a pi type.
abbrev Mathlib.Tactic.GuessName.GuessNameExt E1 #
Type
Environment extension used for guessing the translation of a name.
def Mathlib.Tactic.GuessName.registerGuessNameExt E1 #
Mathlib.Tactic.GuessName.GuessNameData → IO Mathlib.Tactic.GuessName.GuessNameExt
Register a new GuessNameExt.
def Mathlib.Tactic.GuessName.GuessNameExt.addTranslation E1 #
Mathlib.Tactic.GuessName.GuessNameExt → Lean.Ident → Lean.Ident → Lean.Elab.Command.CommandElabM Unit
Add the translation src ↦ tgt to the GuessNameExt.
Both src and tgt should be capitalized.
This change persists until the end of the current file, but it does not persist through imports.