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.Qq

17 declarations. Mathlib docs · Source

Extra Qq helpers

This file contains some additional functions for using the quote4 library more conveniently.

def Qq.getLevelQ E1 #

Lean.Expr → Lean.MetaM ((u : Lean.Level) × Q(Sort u))

If e has type Sort u for some level u, return u and e : Q(Sort u).

def Qq.getLevelQ' E1 #

Lean.Expr → Lean.MetaM ((u : Lean.Level) × Q(Type u))

If e has type Type u for some level u, return u and e : Q(Type u).

def Qq.inferTypeQ' E1 #

Lean.Expr →
  Lean.MetaM
    ((u : Lean.Level) ×
      (α :
        have u := u;
        Q(Type u)) ×
        Q(«$α»))

Variant of inferTypeQ that yields a type in Type u rather than Sort u. Throws an error if the type is a Prop or if it's otherwise not possible to represent the universe as Type u (for example due to universe level metavariables).

theorem Qq.QuotedDefEq.rfl E1 #

∀ {u : Lean.Level} {α : Q(Sort u)} {a : Q(«$α»)}, «$a» =Q «$a»

def Qq.findLocalDeclWithTypeQ? E1 #

{u : Lean.Level} → (sort : Q(Sort u)) → Lean.MetaM (Option Q(«$sort»))

Return a local declaration whose type is definitionally equal to sort.

This is a Qq version of Lean.Meta.findLocalDeclWithType?

def Qq.mkDecideProofQ E1 #

(p : Q(Prop)) → Lean.MetaM Q(«$p»)

Returns a proof of p : Prop using decide p.

This is a Qq version of Lean.Meta.mkDecideProof.

def Qq.mkSetLiteralQ E1 #

{u v : Lean.Level} →
  {α : Q(Type u)} →
    (β : Q(Type v)) →
      List Q(«$α») →
        autoParam Q(EmptyCollection «$β») Qq.mkSetLiteralQ._auto_1 →
          autoParam Q(Singleton «$α» «$β») Qq.mkSetLiteralQ._auto_3 →
            autoParam Q(Insert «$α» «$β») Qq.mkSetLiteralQ._auto_5 → Q(«$β»)

Join a list of elements of type α into a container β.

Usually β is q(Multiset α) or q(Finset α) or q(Set α).

As an example

mkSetLiteralQ q(Finset ℝ) (List.range 4 |>.map fun n : ℕ ↦ q($n•π))

produces the expression {0 • π, 1 • π, 2 • π, 3 • π} : Finset ℝ.

def Qq.mkNatLitQ E1 #

ℕ → Q(ℕ)

Returns the natural number literal n as used in the frontend. It is a OfNat.ofNat application. Recall that all theorems and definitions containing numeric literals are encoded using OfNat.ofNat applications in the frontend.

This is a Qq version of Lean.mkNatLit.

def Qq.mkIntLitQ E1 #

ℤ → Q(ℤ)

Returns the integer literal n.

This is a Qq version of Lean.mkIntLit.

def Qq.mkIntNumeralQ E1 #

{u : Lean.Level} → (α : Q(Type u)) → ℤ → Lean.MetaM Q(«$α»)

Build the numeral of the integer i in α: mkNumeral on the absolute value, negated if i is negative.

def Qq.mkRatNumeralQ E1 #

{u : Lean.Level} → (α : Q(Type u)) → ℚ → Lean.MetaM Q(«$α»)

Build the numeral of the rational r in α: the integer numeral of r.num if r is an integer, and otherwise p / q on the numerals of |r.num| and r.den, negated if r is negative, which is the form in which norm_num displays rationals.

def Qq.mkFinLitQ E1 #

(n : ℕ) → ℕ → Lean.MetaM Q(Fin «$n»)

Build the numeral i : Fin n.

def Qq.mkListLitQ E1 #

{u : Lean.Level} → {α : Q(Type u)} → List Q(«$α») → Q(List «$α»)

The list literal [a₀, …] of the entries as.

def Qq.dropListLitQ E1 #

{u : Lean.Level} → {α : Q(Type u)} → ℕ → Q(List «$α») → Q(List «$α»)

List.drop n on the list literal l.

def Qq.unconsListLitQ E1 #

{u : Lean.Level} →
  {α : Q(Type u)} → (l : Q(List «$α»)) → Lean.MetaM ((hd : Q(«$α»)) × (tl : Q(List «$α»)) ×' «$l» =Q «$hd» :: «$tl»)

A specialised version of ~q($hd :: $tl).

def Qq.instantiateLevelMVarsQ E1 #

(u : Lean.Level) → Lean.MetaM ((_u' : Lean.Level) ×' _u' =QL u)

Instantiate the level metavariables in u, remembering that the result is defeq to u.

This is a Qq version of Lean.instantiateLevelMVars.

def Qq.instantiateMVarsQ' E1 #

{u : Lean.Level} → {α : Q(Sort u)} → (e : Q(«$α»)) → Lean.MetaM ((e' : Q(«$α»)) ×' «$e'» =Q «$e»)

Instantiate the metavariables in e, remembering that the result is defeq to e.

This is a variant of Qq.instantiateMVarsQ which returns the Qq-fact that the new expression is equal to the previous one.