Documentation

PnP2023.Lec_01_04.Intro

Welcome to the course #

We start with a quick tour, where we:

We will then see

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.

Instances For

    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

    Instances For
      def cube (n : ) :

      Cube a natural number

      Instances For
        #eval cube (add_two 3) -- 125
        
        def cube' (n : ) :

        Cube a natural number

        Instances For
          def cube'' :

          Cube a natural number

          Instances For

            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

            Instances For
              #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

              Instances For