<commit_before>
---
title     : "Basics: Functional Programming in Agda"
layout    : page
permalink : /Basics
---

\begin{code}
open import Data.Nat         using (ℕ; zero; suc)
open import Data.Empty       using (⊥; ⊥-elim)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Relation.Binary.PropositionalEquality
                             using (_≡_; refl; _≢_; trans; sym)
\end{code}

# Addition and its properties

\begin{code}
congruent : ∀ {m n} → m ≡ n → suc m ≡ suc n
congruent refl = refl

injective : ∀ {m n} → suc m ≡ suc n → m ≡ n
injective refl = refl
\end{code}

\begin{code}
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
\end{code}

\begin{code}
+-assoc : ∀ m n p → (m + n) + p ≡ m + (n + p)
+-assoc zero n p = refl
+-assoc (suc m) n p rewrite +-assoc m n p =  refl

+-zero : ∀ m → m + zero ≡ m
+-zero zero = refl
+-zero (suc m) rewrite +-zero m = refl

+-suc : ∀ m n → m + (suc n) ≡ suc (m + n)
+-suc zero n = refl
+-suc (suc m) n rewrite +-suc m n = refl
<commit_msg>a bit more basics of arithmetic<commit_after>
---
title     : "Basics: Functional Programming in Agda"
layout    : page
permalink : /Basics
---

\begin{code}
open import Data.Empty       using (⊥; ⊥-elim)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Relation.Binary.PropositionalEquality
                             using (_≡_; refl; _≢_; trans; sym)
\end{code}

# Natural numbers

\begin{code}
data ℕ : Set where
  zero : ℕ
  suc : ℕ → ℕ
\end{code}

\begin{code}
congruent : ∀ {m n} → m ≡ n → suc m ≡ suc n
congruent refl = refl

injective : ∀ {m n} → suc m ≡ suc n → m ≡ n
injective refl = refl

distinct : ∀ {m} → zero ≢ suc m
distinct ()
\end{code}

# Addition and its properties

\begin{code}
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
\end{code}

\begin{code}
+-assoc : ∀ m n p → (m + n) + p ≡ m + (n + p)
+-assoc zero n p = refl
+-assoc (suc m) n p rewrite +-assoc m n p = refl

+-zero : ∀ m → m + zero ≡ m
+-zero zero = refl
+-zero (suc m) rewrite +-zero m = refl

+-suc : ∀ m n → m + (suc n) ≡ suc (m + n)
+-suc zero n = refl
+-suc (suc m) n rewrite +-suc m n = refl

{'fraction_non_alphanumeric': 0.15689981096408318, 'fraction_numerical': 0.0, 'mean_word_length': 2.420032310177706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2708507', 'n_tokens_mistral': 964, 'n_tokens_neox': 890, 'n_words': 365}