Evaluate and inspect

Run a calculation with #eval and inspect its type with #check.

12 minBeginner#eval#checkcalculations and claims
0/14 completed in this course

#eval asks Lean to run a calculation and print its answer. For example, #eval 3 * 4 prints 12. You do not need a theorem to try a calculation.

#check asks for a type. #check (3 * 4) reports that the expression has type Nat: it is a natural number. It does not print the result of the multiplication.

These commands answer different questions. Use #eval for “what value does this produce?” and #check for “what kind of expression is this?”. Put each command on its own line.

A printed result is not a proof of a claim. The theorem in the first lesson asked Lean to check evidence for an equality. Here you are exploring expressions; the Output tab shows their answers.

Worked example

#eval 3 * 4
#check (3 * 4)
#eval "Hello, " ++ "Lean"

The first line prints 12. The second reports a Nat. The last joins two strings and prints "Hello, Lean".

Takeaway

Use #eval to compute and #check to inspect a type. Neither command proves a theorem.

Exercise 1 of 3

Evaluate (3 + 4) * 2, then ask Lean for the type of the same expression. Read both answers in Output.

Suggested steps
  1. Evaluate the expression with #eval
  2. Inspect its type with #check

These marks only recognize text. Another correct proof may use different steps; Lean checks whether it works.

Exercise.lean
Loading editor…

This exercise is judged by what Lean prints. Write the commands, press Check, then read the Output tab.

ReadyLn 1, Col 1Lean 4
Draft saved in this browser
Stuck?
Recall and apply

Knowledge check

Answer without looking back, then check your reasoning.

0of 2
correct
Question 1 of 2You want to know the result of (8 - 3) * 2. Which line should you write?
Question 2 of 2What does #check (2 + 2 = 5) do?