remark-agda/test/Simple.lagda.md
2024-09-12 19:43:27 -05:00

50 lines
No EOL
874 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Commutativity of addition
This document shows how to prove commutativity of addition on natural numbers.
<details>
<summary>Imports</summary>
```
module Simple where
open import Agda.Primitive
open import Relation.Binary.PropositionalEquality.Core
variable
l : Level
```
</details>
Declare our data structures:
```
data : Set where
zero :
suc :
```
Define addition:
```
_+_ :
zero + b = b
suc a + b = suc (a + b)
```
Prove commutativity:
```
+-comm : (m n : ) → m + n ≡ n + m
+-comm zero n = lemma n where
lemma : (n : ) → n ≡ n + zero
lemma zero = refl
lemma (suc n) = cong suc (lemma n)
+-comm (suc m) n = trans (cong suc (+-comm m n)) (sym (lemma n m)) where
lemma : (m n : ) → m + suc n ≡ suc (m + n)
lemma zero n = refl
lemma (suc m) n = cong suc (lemma m n)
```
That's it!