The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V01. The language of Mathlib

Mathlib.Util.Superscript

34 declarations. Mathlib docs · Source

A parser for superscripts and subscripts

This is intended for use in local notations. Basic usage is:

local syntax:arg term:max superscript(term) : term
local macro_rules | `($a:term $b:superscript) => `($a ^ $b)

where superscript(term) indicates that it will parse a superscript, and the $b:superscript antiquotation binds the term argument of the superscript. Given a notation like this, the expression 2⁶⁴ parses and expands to 2 ^ 64.

The superscript body is considered to be the longest contiguous sequence of superscript tokens and whitespace, so no additional bracketing is required (unless you want to separate two superscripts). However, note that Unicode has a rather restricted character set for superscripts and subscripts (see Mapping.superscript and Mapping.subscript in this file), so you should not use this parser for complex expressions.

def Mathlib.Tactic.subscriptTerm.formatter E1 #

Lean.PrettyPrinter.Formatter

def Mathlib.Tactic.superscriptTerm.formatter E1 #

Lean.PrettyPrinter.Formatter

theorem Mathlib.Tactic.Superscript.Mapping.mk.inj E1 #

∀ {toNormal toSpecial toNormal_1 toSpecial_1 : Std.HashMap Char Char},
  { toNormal := toNormal, toSpecial := toSpecial } = { toNormal := toNormal_1, toSpecial := toSpecial_1 } →
    toNormal = toNormal_1 ∧ toSpecial = toSpecial_1

theorem Mathlib.Tactic.Superscript.Mapping.mk.injEq E0 #

∀ (toNormal toSpecial toNormal_1 toSpecial_1 : Std.HashMap Char Char),
  ({ toNormal := toNormal, toSpecial := toSpecial } = { toNormal := toNormal_1, toSpecial := toSpecial_1 }) =
    (toNormal = toNormal_1 ∧ toSpecial = toSpecial_1)

def Mathlib.Tactic.subscriptTerm.parenthesizer E1 #

Lean.PrettyPrinter.Parenthesizer

def Mathlib.Tactic.Superscript.Mapping.ctorIdx E1 #

Mathlib.Tactic.Superscript.Mapping → ℕ

def Mathlib.Tactic.Superscript.instInhabitedMapping.default E1 #

Mathlib.Tactic.Superscript.Mapping

def Mathlib.Tactic.superscriptTerm.parenthesizer E1 #

Lean.PrettyPrinter.Parenthesizer

instance Mathlib.Tactic.Superscript.instHashableChar_mathlib E0 #

Hashable Char

structure Mathlib.Tactic.Superscript.Mapping E1 #

Type

A bidirectional character mapping.

ctor Mathlib.Tactic.Superscript.Mapping.mk E0 #

Std.HashMap Char Char → Std.HashMap Char Char → Mathlib.Tactic.Superscript.Mapping

abbrev Mathlib.Tactic.Superscript.Mapping.toNormal E1 #

Mathlib.Tactic.Superscript.Mapping → Std.HashMap Char Char

Map from "special" (e.g. superscript) characters to "normal" characters.

abbrev Mathlib.Tactic.Superscript.Mapping.toSpecial E1 #

Mathlib.Tactic.Superscript.Mapping → Std.HashMap Char Char

Map from "normal" text to "special" (e.g. superscript) characters.

instance Mathlib.Tactic.Superscript.instInhabitedMapping E0 #

Inhabited Mathlib.Tactic.Superscript.Mapping

def Mathlib.Tactic.Superscript.mkMapping E1 #

String → String → Mathlib.Tactic.Superscript.Mapping

Constructs a mapping (intended for compile time use). Panics on violated invariants.

def Mathlib.Tactic.Superscript.Mapping.superscript E1 #

Mathlib.Tactic.Superscript.Mapping

A mapping from superscripts to and from regular text.

def Mathlib.Tactic.Superscript.Mapping.subscript E1 #

Mathlib.Tactic.Superscript.Mapping

A mapping from subscripts to and from regular text.

def Mathlib.Tactic.Superscript.satisfyTokensFn E1 #

(Char → Bool) →
  String →
    optParam Bool true →
      (Array (String.Pos.Raw × String.Pos.Raw × String.Pos.Raw) → Lean.Parser.ParserState → Lean.Parser.ParserState) →
        Lean.Parser.ParserFn

Collects runs of text satisfying p followed by whitespace. Fails if the first character does not satisfy p. If many is true, it will parse 1 or more many whitespace-separated runs, otherwise it will parse only 1. If successful, it passes the result to k as an array (a, b, c) where a..b is a token and b..c is whitespace.

def Mathlib.Tactic.Superscript.partitionPoint E1 #

{α : Type u} → [Inhabited α] → (as : Array α) → (α → Bool) → optParam ℕ 0 → optParam ℕ as.size → ℕ

Given a predicate leftOfPartition which is true for indexes < i and false for ≥ i, returns i, by binary search.

def Mathlib.Tactic.Superscript.scriptFnNoAntiquot E1 #

Mathlib.Tactic.Superscript.Mapping → String → Lean.Parser.ParserFn → optParam Bool true → Lean.Parser.ParserFn

The core function for super/subscript parsing. It consists of three stages:

  1. Parse a run of superscripted characters, skipping whitespace and stopping when we hit a non-superscript character.
  2. Un-superscript the text and pass the body to the inner parser (usually term).
  3. Take the resulting Syntax object and align all the positions to fit back into the original text (which as a side effect also rewrites all the substrings to be in subscript text).

If many is false, then whitespace (and comments) are not allowed inside the superscript.

def Mathlib.Tactic.Superscript.scriptParser E1 #

Mathlib.Tactic.Superscript.Mapping →
  String →
    String →
      Lean.Parser.Parser →
        optParam Bool true →
          autoParam Lean.SyntaxNodeKind Mathlib.Tactic.Superscript.scriptParser._auto_1 → Lean.Parser.Parser

The super/subscript parser.

  • m: the character mapping
  • antiquotName: the name to use for antiquotation bindings $a:antiquotName. Note that the actual syntax kind bound will be the body kind (parsed by p), not kind.
  • errorMsg: shown when the parser does not match
  • p: the inner parser (usually term), to be called on the body of the superscript
  • many: if false, whitespace is not allowed inside the superscript
  • kind: the term will be wrapped in a node with this kind; generally this is a name of the parser declaration itself.

def Mathlib.Tactic.Superscript.scriptParser.parenthesizer E1 #

Lean.SyntaxNodeKind → Lean.PrettyPrinter.Parenthesizer → Lean.PrettyPrinter.Parenthesizer

Parenthesizer for the script parser.

def Std.Format.mapStringsM E1 #

{m : Type → Type u_1} → [Monad m] → Std.Format → (String → m String) → m Std.Format

Map over the strings in a Format.

def Mathlib.Tactic.Superscript.scriptParser.formatter E1 #

String →
  Mathlib.Tactic.Superscript.Mapping → Lean.SyntaxNodeKind → Lean.PrettyPrinter.Formatter → Lean.PrettyPrinter.Formatter

Formatter for the script parser.

def Mathlib.Tactic.superscript E1 #

Lean.Parser.Parser → Lean.Parser.Parser

The parser superscript(term) parses a superscript. Basic usage is:

local syntax:arg term:max superscript(term) : term
local macro_rules | `($a:term $b:superscript) => `($a ^ $b)

Given a notation like this, the expression 2⁶⁴ parses and expands to 2 ^ 64.

Note that because of Unicode limitations, not many characters can actually be typed inside the superscript, so this should not be used for complex expressions. Legal superscript characters:

⁰¹²³⁴⁵⁶⁷⁸⁹ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖ𐞥ʳˢᵗᵘᵛʷˣʸᶻᴬᴮᴰᴱᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾꟴᴿᵀᵁⱽᵂᵝᵞᵟᵋᶿᶥᶹᵠᵡ⁺⁻⁼⁽⁾

def Mathlib.Tactic.superscript.parenthesizer E1 #

Lean.PrettyPrinter.Parenthesizer → Lean.PrettyPrinter.Parenthesizer

Formatter for the superscript parser.

def Mathlib.Tactic.superscript.formatter E1 #

Lean.PrettyPrinter.Formatter → Lean.PrettyPrinter.Formatter

Formatter for the superscript parser.

def Mathlib.Tactic.superscriptTerm E1 #

Lean.Parser.Parser

Shorthand for superscript(term).

This is needed because the initializer below does not always run, and if it has not run then downstream parsers using the combinators will crash.

See https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Non-builtin.20parser.20aliases/near/365125476 for some context.

def Mathlib.Tactic.subscript E1 #

Lean.Parser.Parser → Lean.Parser.Parser

The parser subscript(term) parses a subscript. Basic usage is:

local syntax:arg term:max subscript(term) : term
local macro_rules | `($a:term $i:subscript) => `($a $i)

Given a notation like this, the expression (a)ᵢ parses and expands to a i. (Either parentheses or a whitespace as in a ᵢ is required, because aᵢ is considered as an identifier.)

Note that because of Unicode limitations, not many characters can actually be typed inside the subscript, so this should not be used for complex expressions. Legal subscript characters:

₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘꞯʀꜱᴛᴜᴠᴡʏᴢᵦᵧᵨᵩᵪ₊₋₌₍₎

def Mathlib.Tactic.subscript.parenthesizer E1 #

Lean.PrettyPrinter.Parenthesizer → Lean.PrettyPrinter.Parenthesizer

Formatter for the subscript parser.

def Mathlib.Tactic.subscript.formatter E1 #

Lean.PrettyPrinter.Formatter → Lean.PrettyPrinter.Formatter

Formatter for the subscript parser.

def Mathlib.Tactic.subscriptTerm E1 #

Lean.Parser.Parser

Shorthand for subscript(term).

This is needed because the initializer below does not always run, and if it has not run then downstream parsers using the combinators will crash.

See https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Non-builtin.20parser.20aliases/near/365125476 for some context.

def Mathlib.Tactic.delabSuperscript E1 #

Lean.PrettyPrinter.Delaborator.Delab

Successfully delaborates only if the resulting expression can be superscripted.

See Mapping.superscript in this file for legal superscript characters.

def Mathlib.Tactic.delabSubscript E1 #

Lean.PrettyPrinter.Delaborator.Delab

Successfully delaborates only if the resulting expression can be subscripted.

See Mapping.subscript in this file for legal subscript characters.