112 lines
No EOL
2.5 KiB
Agda
112 lines
No EOL
2.5 KiB
Agda
open import Agda.Primitive
|
||
|
||
private
|
||
variable
|
||
l : Level
|
||
|
||
data _≡_ {A : Set l} : A → A → Set l where
|
||
refl : {x : A} → x ≡ x
|
||
|
||
data ⊥ : Set where
|
||
data ⊤ : Set where
|
||
tt : ⊤
|
||
|
||
result2 : (B : Set) → ((A : Set) → (B → A) → A) → B
|
||
result2 B x =
|
||
let
|
||
y = x B λ x → x
|
||
in y
|
||
|
||
data N : Set where
|
||
zero : N
|
||
suc : N -> N
|
||
{-# BUILTIN NATURAL N #-}
|
||
|
||
data Bool : Set where
|
||
true : Bool
|
||
false : Bool
|
||
|
||
ifbool : {A : Set} (x y : A) -> Bool -> A
|
||
ifbool {A} x y true = x
|
||
ifbool {A} x y false = y
|
||
|
||
negbool : Bool -> Bool
|
||
negbool true = false
|
||
negbool false = true
|
||
|
||
pred : N -> N
|
||
pred zero = zero
|
||
pred (suc x) = x
|
||
|
||
isZero : N -> Bool
|
||
isZero zero = true
|
||
isZero (suc x) = false
|
||
|
||
iter : (A : Set) (a : A) (f : A -> A) -> N -> A
|
||
iter A a f zero = a
|
||
iter A a f (suc x) = iter A (f a) f x
|
||
|
||
_^_ : {A : Set} → (A → A) → N → A → A
|
||
_^_ = λ f n → (λ x → iter _ x f n)
|
||
|
||
sub : N -> N -> N
|
||
sub x y = (pred ^ y) x
|
||
|
||
lt1 : N -> N -> Bool
|
||
lt1 m n = negbool (isZero (sub m n))
|
||
|
||
lt2 : N -> N -> Bool
|
||
lt2 m n = isZero (sub (suc m) n)
|
||
|
||
postulate
|
||
funExt : {A : Set} {B : A → Set} {f g : (x : A) → B x}
|
||
→ ((x : A) → f x ≡ g x) → f ≡ g
|
||
|
||
ap : {A B : Set l} (f : A → B) {x y : A} (p : x ≡ y) → f x ≡ f y
|
||
ap f refl = refl
|
||
|
||
trans : {A : Set l} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
|
||
trans refl refl = refl
|
||
|
||
module ≡-Reasoning where
|
||
infix 1 begin_
|
||
begin_ : {l : Level} {A : Set l} {x y : A} → (x ≡ y) → (x ≡ y)
|
||
begin x = x
|
||
|
||
_≡⟨⟩_ : {l : Level} {A : Set l} (x {y} : A) → x ≡ y → x ≡ y
|
||
_ ≡⟨⟩ x≡y = x≡y
|
||
|
||
infixr 2 _≡⟨⟩_ step-≡
|
||
step-≡ : {l : Level} {A : Set l} (x {y z} : A) → y ≡ z → x ≡ y → x ≡ z
|
||
step-≡ _ y≡z x≡y = trans x≡y y≡z
|
||
syntax step-≡ x y≡z x≡y = x ≡⟨ x≡y ⟩ y≡z
|
||
|
||
infix 3 _∎
|
||
_∎ : {l : Level} {A : Set l} (x : A) → (x ≡ x)
|
||
_ ∎ = refl
|
||
open ≡-Reasoning
|
||
|
||
---
|
||
|
||
sub-zero-zero : (y : N) -> sub zero y ≡ zero
|
||
sub-zero-zero zero = refl
|
||
sub-zero-zero (suc y) = sub-zero-zero y
|
||
-- sub zero (suc y) ≡⟨⟩
|
||
-- (pred ^ (suc y)) zero ≡⟨⟩
|
||
-- iter _ zero pred (suc y) ≡⟨⟩
|
||
-- iter _ (pred zero) pred y ≡⟨⟩
|
||
-- iter _ zero pred y ≡⟨⟩
|
||
-- (pred ^ y) zero ≡⟨⟩
|
||
-- sub zero y ≡⟨ sub-zero-zero y ⟩
|
||
-- zero ∎
|
||
|
||
f : (x y : N) -> lt1 x y ≡ lt2 x y
|
||
f zero zero = refl
|
||
f zero (suc y) =
|
||
lt1 zero (suc y) ≡⟨⟩
|
||
negbool (isZero (sub zero (suc y))) ≡⟨ {! !} ⟩
|
||
lt2 zero (suc y) ∎
|
||
f (suc x) y = {! !}
|
||
|
||
prop : lt1 ≡ lt2
|
||
prop = funExt λ x → funExt λ y → f x y |