-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW14.agda
52 lines (41 loc) · 1.46 KB
/
HW14.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module HW14 where
module problem-1 where
open import Data.List using (List; []; _∷_)
-- we have 'infix 5 _∷_' in 'Data.List'
-- therefore we make _⊆_ slightly less associative
infix 4 _⊆_
data _⊆_ {A : Set} : List A → List A → Set where
stop : [] ⊆ []
drop : ∀ {xs y ys} → xs ⊆ ys → xs ⊆ y ∷ ys
keep : ∀ {x xs ys} → xs ⊆ ys → x ∷ xs ⊆ x ∷ ys
⊆-refl : ∀ {A} {xs : List A} → xs ⊆ xs
⊆-refl {xs = []} = stop
⊆-refl {xs = x ∷ xs} = keep ⊆-refl
⊆-trans : ∀ {A} {xs ys zs : List A} → xs ⊆ ys → ys ⊆ zs → xs ⊆ zs
⊆-trans stop q = q
⊆-trans p (drop q) = drop (⊆-trans p q)
⊆-trans (keep p) (keep q) = keep (⊆-trans p q)
⊆-trans (drop p) (keep q) = drop (⊆-trans p q)
module problem-2 where
open import Data.Nat using (ℕ; zero; suc; _+_)
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; trans; sym; cong; cong-app; subst)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
+-identity : ∀ (m : ℕ) → m + zero ≡ m
+-identity zero = refl
+-identity (suc m) = cong suc (+-identity m)
+-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
+-suc zero n = refl
+-suc (suc m) n = cong suc (+-suc m n)
{-
+-suc (suc m) n =
begin
suc m + suc n
≡⟨⟩
suc (m + suc n)
≡⟨ cong suc (+-suc m n) ⟩
suc (suc (m + n))
≡⟨⟩
suc ((suc m) + n)
∎
-}