# Documentation

PnP2023.Lec_01_04.Intro

# Welcome to the course #

• Use Lean as a calculator
• Define some functions and call them.
• Look at some types.
• Look at some proofs.

We will then see

• A glimpse of AI.
• A detailed example with programs and proofs.

## Lean as a calculator. #

We begin by using Lean as a calculator. We can use #eval to evaluate expressions.

#eval 1 + 2 -- 3

#eval "Hello " ++ "world!" -- "Hello world!"


An arbitrary number.

Equations

We next evaluate an expression involving a definition.

#eval some_number + 23 -- 65


## Defining functions #

We next define some functions. These are defined in terms of previously defined functions.

def add_two (n : ) :

Add 2 to a natural number

Equations
def cube (n : ) :

Cube a natural number

Equations
#eval cube (add_two 3) -- 125

def cube' (n : ) :

Cube a natural number

Equations
def cube'' :

Cube a natural number

Equations

## Types #

Terms in Lean, including functions, have types, which can be seen using #check

#check 1 + 2 -- ℕ

#check "Hello " ++ "world!" -- String

#check add_two -- ℕ → ℕ
#check cube   -- ℕ → ℕ

#check ℕ -- Type
#check Type -- Type 1
#check ℕ → ℕ -- Type


We next define a function of two arguments, and look at its type. We see that this is defined as a function from ℕ to a function from ℕ to ℕ.

def sum_of_squares (x : ) (y : ) :

Sum of squares of natural numbers x and y

Equations
#check sum_of_squares -- ℕ → ℕ → ℕ

#check sum_of_squares 3 -- ℕ → ℕ


We can also define this in a way that makes the type clearer.

def sum_of_squares' :

Sum of squares of natural numbers x and y

Equations