4. Inside definitions and structures

Statements often use named definitions: Function.LeftInverse g f, Function.Injective f, Nat.Prime 17. A name stands for a formula that the statement does not spell out. Definograph can open a small definition one step and read the formula inside, and it can list the fields and laws of a structure. It also says which parts it could not interpret. This lesson shows all three.

A definition Definograph opens by itself

This is Definograph's example Look inside a left inverse:

∀ (A B : Type) (f : A → B) (g : B → A),
  Function.LeftInverse g f

Function.LeftInverse g f is a definition in Lean's library. It says that g undoes f: g (f x) = x for every x in A.

Definograph does not stop at the name. Its Visual sequence opens the definition and reads what is inside. This is the last step:

Recorded Definograph output · Lean 4.28.0 ·

Source

Lean statement, as entered in Definograph

∀ (A B : Type) (f : A → B) (g : B → A),
  Function.LeftInverse g f
In scope∀ A : Type∀ B : Type∀ f : A → B∀ g : B → A∀ x : A
Compare

Compare the expressions with =

Read the = relation between the two expressions within this logical context.

g(f(x)) equals x
=x : Axf : A → Bfg : B → Agg(f(x)) : Ag(f(x))x : Ax=
Compare the outputs of these map paths: they are required to agree.
Inside this expression 2 relations

These are parts of the expression, not separate assertions.

maps tof(x) : Bf(x)g : B → Agg(f(x)) : Ag(f(x))
Application · the map sends its inputs to this output
maps tox : Axf : A → Bff(x) : Bf(x)
Application · the map sends its inputs to this output
Lean fragment and source contextg (f x) = x

Schematics describe the conditions in their logical context. Shapes and spacing carry no unstated geometric meaning.

Reading Function.LeftInverse through its checked definition.See original and details ↗
With automatic inspection on, Definograph reads Function.LeftInverse through its checked definition. Step 4 of 4 compares g (f x) with x.
  • The figure compares the route from x through f and then g with x itself. "Compare the outputs of these map paths: they are required to agree."
  • In scope now includes x, which comes from inside the definition. The statement's own text has no x.

Below the reading, Definograph says what it did: "Reading Function.LeftInverse through its checked definition." In Definograph, the Inspect panel says which definition was opened and that Lean checked the expansion for definitional equality, and it keeps the statement as written under Original statement before inspection.

A definitional-equality check means that Lean confirmed the opened statement and the original are the same statement, differently written. Opening a definition changes what you see, not what is claimed.

The same statement, unopened

Definograph opens a definition automatically only when it is small and opening it leaves less of the statement uninterpreted. You can turn this off: in the Inspect panel, clear Automatically inspect small definitions. The Visual sequence then reads the statement as written:

Recorded Definograph output · Lean 4.28.0 ·

Lean statement, as entered in Definograph

∀ (A B : Type) (f : A → B) (g : B → A),
  Function.LeftInverse g f
In scope∀ A : Type∀ B : Type∀ f : A → B∀ g : B → A
Condition

Read the complete clause

Function.LeftInverse g f

Function.LeftInverse g f
Function.LeftInverseFunction.LeftInverse : {α β : Type} → (β → α) → (α → β) → PropFunction.LeftInverseg : B → Agf : A → Bf
Argument structure only · this predicate has no interpreted geometric meaning
Lean fragment and source contextFunction.LeftInverse g f

Schematics describe the conditions in their logical context. Shapes and spacing carry no unstated geometric meaning.

With inspection off, the definition stays folded: the clause is shown as Function.LeftInverse applied to g and f, with no interpreted meaning.
  • The whole condition is one clause, Function.LeftInverse g f, labeled "Argument structure only · this predicate has no interpreted geometric meaning".
  • Definograph still shows what the definition is applied to, g and f, in that order. It does not say what the definition means.

Both readings are correct readings of the same statement. The second one shows less.

Where interpretation stops

The Inspect panel ends with Interpretation coverage. It counts the parts of the statement that Definograph could interpret, and names the definitions it left folded. This is Definograph's example Geometry inside a larger statement:

∀ (P : ℝ × ℝ) (ε : ℝ),
  P ∈ Metric.ball 0 ε → Nat.Prime 17

ℝ × ℝ is the plane as pairs of real numbers, and Nat.Prime 17 says that 17 is a prime number. Its coverage panel:

Recorded Definograph output · Lean 4.28.0 ·

Source

Lean statement, as entered in Definograph

∀ (P : ℝ × ℝ) (ε : ℝ),
  P ∈ Metric.ball 0 ε → Nat.Prime 17
Interpretation coverage 1 interpreted · 0 partial · 1 structural fragments

This reports the vocabulary used in the selected fragment. It does not measure understanding or establish the statement.

Interpreted
1
Partly interpreted
0
Structure only
1

Recognized constructions

  • Sets and membership1 relation
  • Metric regions and distance1 relation

Meaning still folded or uninterpreted

Typed objects and surrounding logic remain visible. Looking inside a definition may expose constructions the reader knows.

Nat.Prime1 occurrence · 1 clause

A checked definition body is available for inspection.

Locate in statementLook inside definition
The Interpretation coverage section of the Inspect panel, for a statement with a ball condition and Nat.Prime 17: one fragment interpreted, one kept as structure only, and Nat.Prime listed under meaning still folded.
  • The first line sets the limits: "This reports the vocabulary used in the selected fragment. It does not measure understanding or establish the statement."
  • One clause is interpreted: Definograph recognizes the membership in a ball.
  • One clause is Structure only: Nat.Prime 17. Under Meaning still folded or uninterpreted, the panel says "A checked definition body is available for inspection." and offers Look inside definition, which asks Definograph to open that definition.

Opening a definition yourself

Lesson 2 ended with Definograph's example Functions between arbitrary types:

∀ (α β : Type) (f : α → β),
  Function.Injective f →
  ∀ x y : α, f x = f y → x = y

Definograph recognizes Function.Injective f as a property of f, so it does not open it by itself. To open it yourself, open Inspect, then Look inside a definition. Enter Function.Injective as the Definition name and choose Expand definition ↗. Definograph reads the statement again with that definition opened, and notes that Lean checked the expansion for definitional equality. Return to original structure undoes this.

The outline of the opened statement:

Recorded Definograph output · Lean 4.28.0 ·

Source

Lean statement, as entered in Definograph

∀ (α β : Type) (f : α → β),
  Function.Injective f →
  ∀ x y : α, f x = f y → x = y
The Whole statement outline after Function.Injective f has been opened: the assumption now quantifies over its own two inputs. It is an outline of the statement, not a proof.

The assumption now reads: for every a₁ and a₂, if f(a₁) equals f(a₂), then a₁ equals a₂. The conclusion reads: for every x and y, if f(x) equals f(y), then x equals y. They are the same condition with the variables renamed. Opening the definition shows why the statement is true. Definograph did not prove it; the argument is yours, and it is short.

Fields and laws of a structure

Many definitions in Mathlib are structures: a bundle of data together with laws the data must satisfy. In Lesson 3 you met PartialEquiv A B. In Definograph, the first step of that example's Visual sequence has a collapsed section below the regions figure, Read the underlying fields and laws. The figure below was recorded with it open, and shows what e consists of:

Recorded Definograph output · Lean 4.28.0 ·

Lean statement, as entered in Definograph

∀ (A B : Type) (e : PartialEquiv A B) (x : A),
  x ∈ e.source → e.symm (e x) = x
Objects and choices

For every A, B, e, x

Read these objects as arbitrary choices of their stated types, in the displayed binder order.

Read the underlying fields and laws
Object structure

Inside e

PartialEquiv A B

4 data fields · 3 laws

These fields belong to this object, within the statement’s current quantifiers and assumptions.

What it contains

Map field toFun : A → BtoFunMap field invFun : B → AinvFunCarrier type: AAcarrier typeSet field source in AsourceCarrier type: BBcarrier typeSet field target in Btarget
Field names and declared types
toFun
A → B
invFun
B → A
source
Set A
target
Set B

Arrows show function types. Set frames show membership domains, with no coordinates, shape, size, or chosen elements.

What its fields must satisfy

Read each law in declaration order.

1 / 3
1map_source'2map_target'3left_inv'
map_source'Law of this object
Visual readingSymbolic schematics · no numerical choices
In scopeA : TypeB : Typee : PartialEquiv A B
Objects and choices

For every x

Read these objects as arbitrary choices of their stated types, in the displayed binder order.

x:A
Types and maps
Atype · in scope
x: A
Arrows show declared function types. Named elements retain their types; no coordinates, cardinalities, or additional properties are assigned.
Lean fragment and source context∀ ⦃x : A⦄, x ∈ e.source → ↑e x ∈ e.target
Full visual statement
Parameters
A:Type
B:Type
e:PartialEquiv A B
Types and maps
Atype
Btype
Arrows show declared function types. Named elements retain their types; no coordinates, cardinalities, or additional properties are assigned.
An equivalence between specified regionsAbstract regions and maps
MapebetweenAandB
A : TypeAsource carriersource regione.sourcee.sourcepossibly emptyB : TypeBtarget carriertarget regione.targete.targetpossibly emptye : PartialEquiv A Beee⁻¹e⁻¹inverse on these regionsAbstract containers; no geometry or coordinates are specified.
For every element in the source region
xee(x)e⁻¹x
Back to the same source element
For every element in the target region
ye⁻¹e⁻¹(y)ey
Back to the same target element

The forward map takes the source region to the target region. The inverse takes the target back to the source, and each undoes the other on its valid region.

The letters in the round trips are schematic bound variables, not chosen points. Region frames indicate containment, not shape, size, dimension, connectedness, or a proper subset. The inverse laws apply on the specified regions; no inverse law is asserted on the whole carriers.
For every
x:A
Types and maps
Atype · in scope
x: A
Arrows show declared function types. Named elements retain their types; no coordinates, cardinalities, or additional properties are assigned.

Given

x belongs to e.source
belongs toe.source : Set Ae.sourcex : Ax
Membership condition · the named element belongs to the region

Then

e.toFun(x) belongs to e.target
belongs toe.target : Set Be.targete.toFun(x) : Be.toFun(x)
Membership condition · the named element belongs to the region

Schematics describe the conditions in their logical context. Shapes and spacing carry no unstated geometric meaning.

1 further field remains in the declared type. Further field readings exceed the optional structure payload budget.

Schematics describe the conditions in their logical context. Shapes and spacing carry no unstated geometric meaning.

Step 1 of 7 opens the declared structure of e: four data fields and three laws, and a closing line saying that one further field is not shown.
  • The heading reads Object structure, Inside e, with the declared type PartialEquiv A B and the count "4 data fields · 3 laws".
  • "These fields belong to this object, within the statement’s current quantifiers and assumptions."
  • What it contains lists the data: toFun : A → B, invFun : B → A, source : Set A and target : Set B. "Arrows show function types. Set frames show membership domains, with no coordinates, shape, size, or chosen elements."
  • What its fields must satisfy lists the laws in the order Mathlib declares them: map_source', map_target' and left_inv'. The primes are part of the names Mathlib gives these fields. The first law is read as a small visual sequence of its own: every x in the source region is sent into the target region.
  • The last line says where the list stops: "1 further field remains in the declared type." Mathlib's PartialEquiv has a fourth law, right_inv'. Definograph did not read it, and says so.

The fields belong to the object they are listed under, here e: e.source is the source region of this e. Another partial equivalence e' between the same types has its own e'.source, and nothing in the figure relates the two.

What these views do not tell you

  • That anything was proved. Opening a definition rewrites the statement into an equal one. It adds no evidence.
  • That a folded definition is wrong or false. "Structure only" is a limit of Definograph's vocabulary, not a verdict on the mathematics.
  • How well the statement is understood. Coverage counts recognized vocabulary. A fully interpreted statement can still be false, as Exercise 4.1 shows.
  • That a structure's laws hold for some particular object, or that its sets have elements. The field list describes what any PartialEquiv A B consists of.

Exercises

Exercise 4.1. Read the opened left-inverse statement. Is it true?

Hint

f and g are arbitrary functions of the right types.

Answer

No. Take A and B to be the natural numbers and let f and g both send every number to 0. Then g (f 1) = 0, not 1. The statement claims that every g undoes every f, which is false. Definograph reads it and draws it all the same, and its coverage panel reports every fragment as interpreted.

Exercise 4.2. In the unopened reading, what does Definograph show about Function.LeftInverse g f? What does opening the definition add?

Answer

Unopened, it shows only the definition's name and its two arguments, g and f, in order. Opened, it shows the condition inside: for every x in A, g (f x) = x, with the route from x through f and g drawn and compared with x.

Exercise 4.3. Is the statement in Geometry inside a larger statement true? Could Definograph have told you?

Hint

The conclusion does not mention P or ε.

Answer

It is true, because 17 is prime; the assumption about P plays no part. Definograph could not have told you. It left Nat.Prime 17 folded, and even an interpreted clause is not a proof. Its coverage panel says as much: "It does not measure understanding or establish the statement."

Exercise 4.4. Which law of PartialEquiv is missing from the figure? What does it say?

Answer

right_inv'. It says that every y in the target region comes back to itself when you apply the inverse map and then the forward map: toFun (invFun y) = y. This is the round trip from the target that Exercise 3.4 relied on.

Exercise 4.5. Suppose e and e' are two partial equivalences from A to B. The figure lists the laws of e. Does left_inv' of e tell you anything about points of e'.source?

Answer

No. The figure says that the fields "belong to this object": left_inv' of e speaks about e.source, e.toFun and e.invFun. To transfer it to e' you would need a separate fact relating e' to e, for example a proof that the two structures are equal.