Imports


module Sets.Propositions where

open import Data.Nat using (; zero; suc)

Proofs as data

It is beneficial to represent proofs as ordinary data; we can manipulate them like natural numbers.
The proofs of each proposition will have a distinct type.

We represent the proofs of the true proposition by the type .
The true proposition has a trivial proof: tt (trivially true).


data  : Set where
  tt : 

We represent the proofs of the false proposition by the type .
The false proposition has no proofs (it cannot be proven).


data  : Set where

We represent the proofs of the conjunction of two propositions A and B by the type A × B.
A × B has proofs of form a , b where a is a proof of A and b is a proof of B.


data _×_ (A B : Set) : Set where
  _,_ : A  B  A × B

infixr 4 _,_
infixr 2 _×_

We represent the proofs of the disjunction of two propositions A and B by the type A ⊎ B.
A ⊎ B has two different kinds of proofs:


data _⊎_ (A B : Set) : Set where
  inj₁ : A  A  B
  inj₂ : B  A  B

infixr 1 _⊎_

Exercises

Construct one proof for each proposition if possible:

Example:


⊤×⊤ :  × 
⊤×⊤ = tt , tt

Remarks

We represent implication, negation, universal and existential quantification later.

_⊎_ represents constructive disjunction, we represent classical disjunction later and compare them.

_≤_: Less-or-equal predicate

We wish to represent proofs of propositions n ≤ m (n, m = 0, 1, ...).
For this we define a set indexed with two natural numbers:


data  _≤_ :     Set where
  z≤n : {n : }                        zero   n
  s≤s : {m : }  {n : }    m  n    suc m  suc n

infix 4 _≤_

This yields the statements

z≤n {0} : 0 ≤ 0
z≤n {1} : 0 ≤ 1
z≤n {2} : 0 ≤ 2
...
s≤s (z≤n {0}) : 1 ≤ 1
s≤s (z≤n {1}) : 1 ≤ 2
s≤s (z≤n {2}) : 1 ≤ 3
...
s≤s (s≤s (z≤n {0})) : 2 ≤ 2
s≤s (s≤s (z≤n {1})) : 2 ≤ 3
s≤s (s≤s (z≤n {2})) : 2 ≤ 4
...
...

which means that the following propositions have proofs:

0 ≤ 0
0 ≤ 1,  1 ≤ 1
0 ≤ 2,  1 ≤ 2,  2 ≤ 2
0 ≤ 3,  1 ≤ 3,  2 ≤ 3,  3 ≤ 3
...                             ...

Notes

Proving non-emptiness

We can prove that a set is non-empty by giving an element
(remember the syntax of constant definition):


0≤1 : 1  10
0≤1 = s≤s z≤n

Exercise: Prove that 3 ≤ 7!

Proving emptiness

How can we prove that a set like 7 ≤ 3 is empty?

  1. If 7 ≤ 3 would be non-empty, all its elements would look like s≤s x where x : 6 ≤ 2.
  2. If 6 ≤ 2 would be non-empty, all its elements would look like s≤s x where x : 5 ≤ 1.
  3. If 5 ≤ 1 would be non-empty, all its elements would look like s≤s x where x : 4 ≤ 0.
  4. 4 ≤ 0 is empty.

Although we will discuss all the details later here we have a look at how can this chain of inference be given in Agda:*


7≰3 : 7  3  
7≰3 (s≤s (s≤s (s≤s ())))

Exercise: prove that 4 ≤ 2 is empty!

We can use an emptiness proof in another emptiness proof:


8≰4 : 8  4  
8≰4 (s≤s x) = 7≰3 x

Question: Guess what kind of code can be generated from emptiness proofs!


*7 ≤ 3 → ⊥ denotes a function from 7 ≤ 3 to so we prove that 7 ≤ 3 is empty by giving a function which maps 7 ≤ 3 to a trivially empty set.
During the function definition we show that 7 ≤ 3 has no element so the function is defined.
We discuss functions in detail later.

Exercises

Alternative representation


data _≤′_ :     Set where
  ≤′-refl : {m : }                        m ≤′ m
  ≤′-step : {m : }  {n : }   m ≤′ n    m ≤′ suc n

infix 4 _≤′_

yields

≤′-refl : 0 ≤ 0
≤′-step ≤′-refl : 0 ≤ 1
≤′-step (≤′-step ≤′-refl) : 0 ≤ 2
...
≤′-refl : 1 ≤ 1
≤′-step ≤′-refl : 1 ≤ 2
≤′-step (≤′-step ≤′-refl) : 1 ≤ 3
...
≤′-refl : 2 ≤ 2
≤′-step ≤′-refl : 2 ≤ 3
≤′-step (≤′-step ≤′-refl) : 2 ≤ 4
...
...

As with and ℕ₂,

Syntactic abbreviations

All code on this slide is valid.

Original definition:

data  _≤_ : ℕ → ℕ → Set where
  z≤n : {n : ℕ} →                       zero  ≤ n
  s≤s : {m : ℕ} → {n : ℕ} →   m ≤ n  →  suc m ≤ suc n

The arrows between typed variables are not needed (also in case of round parenthesis):

data  _≤_ : ℕ → ℕ → Set where
  z≤n : {n : ℕ} →                     zero  ≤ n
  s≤s : {m : ℕ} {n : ℕ} →   m ≤ n  →  suc m ≤ suc n

Typed variables with the same type can be contracted (also in case of round parenthesis):

data  _≤_ : ℕ → ℕ → Set where
  z≤n : {n : ℕ} →               zero  ≤ n
  s≤s : {m n : ℕ} →   m ≤ n  →  suc m ≤ suc n

Inferable expressions can be replaced by an underscore:

data  _≤_ : ℕ → ℕ → Set where
  z≤n : {n : _} →               zero  ≤ n
  s≤s : {m n : _} →   m ≤ n  →  suc m ≤ suc n

Variables with inferred types can be introduced by :

data  _≤_ : ℕ → ℕ → Set where
  z≤n : ∀ {n} →               zero  ≤ n
  s≤s : ∀ {m n} →   m ≤ n  →  suc m ≤ suc n

_+_≡_: Addition predicate

We wish to give a definition which yields the infinite set of true propositions

0 + 0 ≡ 0,  1 + 0 ≡ 1,  2 + 0 ≡ 2,  ...
0 + 1 ≡ 1,  1 + 1 ≡ 2,  2 + 1 ≡ 3,  ...
0 + 2 ≡ 2,  1 + 2 ≡ 3,  2 + 2 ≡ 4,  ...
...

The outline of the solution:

(n : ℕ)                        zero  + n ≡ n     -- yields the first column of statements
(m : ℕ) (n : ℕ)  m + n ≡ k  →  suc m + n ≡ suc k -- yields the successive columns of statements

Technical details of the solution
(nothing new but better to repeat):

Definition of _+_≡_

_+_≡_ is an indexed set with three natural number indices and with two constructors:*


data _+_≡_ :       Set where
  znn :  {n}  zero + n  n
  sns :  {m n k}  m + n  k  suc m + n  suc k

which yields the statements

znn : 0 + 0 ≡ 0
znn : 0 + 1 ≡ 1
znn : 0 + 2 ≡ 2
...
sns znn : 1 + 0 ≡ 1
sns znn : 1 + 1 ≡ 2
sns znn : 1 + 2 ≡ 3
...
sns (sns znn) : 2 + 0 ≡ 2
sns (sns znn) : 2 + 1 ≡ 3
sns (sns znn) : 2 + 2 ≡ 4
...
...

Notes


*this is the same as

data _+_≡_ : ℕ → ℕ → ℕ → Set where
  znn : {n : ℕ} → zero + n ≡ n
  sns : {m : ℕ} → {n : ℕ} → m + n ≡ k → suc m + n ≡ suc k

Exercises

Exercises

Definition reuse

Another definition of _≤_:


data _≤″_ :     Set where
  ≤+ :  {m n k}  m + n  k  m ≤″ k

which yields

≤+ znn : 0 ≤″ 0
≤+ znn : 0 ≤″ 1
≤+ znn : 0 ≤″ 2
...
≤+ (sns znn) : 1 ≤″ 1
≤+ (sns znn) : 1 ≤″ 2
≤+ (sns znn) : 1 ≤″ 3
...
≤+ (sns (sns znn)) : 2 ≤″ 2
≤+ (sns (sns znn)) : 2 ≤″ 3
≤+ (sns (sns znn)) : 2 ≤″ 4
...
...

Notes

Exercises


*There are lots of isomorphisms between and ℕ⁺, we mean here the most natural one.