data _≡_ {A : Set} : A → A → Set where refl : {a : A} → a ≡ a context : {A B : Set} → {a b : A} → (f : A → B) → a ≡ b → f a ≡ f b context f refl = refl trans : {A : Set} → {a b c : A} → a ≡ b → b ≡ c → a ≡ c trans refl refl = refl data ⊥ : Set where ¬ : Set → Set ¬ A = A → ⊥ _≢_ : {A : Set} → A -> A -> Set _≢_ a b = ¬ (a ≡ b) data _∧_ (A B : Set) : Set where _∧ᵢ_ : A → B → A ∧ B infixr 19 _∧_ infixr 19 _∧ᵢ_ data ℕ : Set where zero : ℕ succ : ℕ → ℕ {-# BUILTIN NATURAL ℕ #-} _+_ : ℕ → ℕ → ℕ n + 0 = n n + succ m = succ (n + m) data _<_ : ℕ → ℕ → Set where z 0 ≤ n s≤s : ∀ (n m : ℕ) -> n ≤ m -> succ n ≤ succ m -- Task 2 data ℤ : Set where pos : ℕ → ℤ negsucc : ℕ → ℤ -- -n - 1 alternatively - (n + 1) recN : {A : Set} → ℕ → A → (ℕ → A → A) → A recN 0 d e = d recN (succ x) d e = e x (recN x d e) addℕ : ℕ → ℕ → ℕ addℕ n m = recN m n (λ _ x → succ x) prfadd : (n m : ℕ) → (n + m) ≡ (addℕ n m) prfadd n 0 = refl prfadd n (succ m) = context succ (prfadd n m) -- Task 3 zrec : {A : Set} → ℤ → (ℕ → A) → (ℕ → A) → A zrec (pos n) f _ = f n zrec (negsucc n) _ g = g n addOne : ℤ → ℤ addOne a = zrec a (λ x → pos (succ x)) (λ x → recN x (pos x) (λ n _ → negsucc n)) subOne : ℤ → ℤ subOne a = zrec a (λ x → recN x (negsucc x) (λ n _ → pos n)) (λ x → negsucc (succ x)) prfℤ₁ : (z : ℤ) → subOne (addOne z) ≡ z prfℤ₁ (pos x) = refl prfℤ₁ (negsucc 0) = refl prfℤ₁ (negsucc (succ x)) = refl prfℤ₂ : (z : ℤ) → addOne (subOne z) ≡ z prfℤ₂ (pos 0) = refl prfℤ₂ (pos (succ x)) = refl prfℤ₂ (negsucc x) = refl -- Task 4 data Vec (A : Set) : ℕ → Set where nil : Vec A 0 _,_ : {n : ℕ} → Vec A n → (a : A) → Vec A (succ n) infixl 20 _,_ index : {A : Set} {n : ℕ} → Vec A n → (i : ℕ) → (0 ≤ i ∧ i < n) → A index (xs , a) 0 (z≤n n ∧ᵢ z