annotate src/negnat.agda @ 1124:f683d96fbc93 default tip

safe fix done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 07 Jul 2024 22:28:50 +0900
parents ac53803b3b2a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1124
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 949
diff changeset
1 {-# OPTIONS --cubical-compatible --safe #-}
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 module negnat where
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Data.Nat
1124
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 949
diff changeset
6 open import Relation.Nullary hiding (proof)
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import Data.Empty
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Data.Unit
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Data.Fin renaming ( suc to fsuc ; zero to fzero ; _+_ to _++_ )
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Relation.Binary.Core
1124
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 949
diff changeset
11 open import Relation.Binary.PropositionalEquality hiding (J)
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 -- http://stackoverflow.com/questions/22580842/non-trivial-negation-in-agda
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 ℕ-elim : ∀ {p} (P : ℕ → Set p)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 (s : ∀ {n} → P n → P (suc n))
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 (z : P 0) → ∀ n → P n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 ℕ-elim P s z zero = z
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 ℕ-elim P s z (suc n) = s (ℕ-elim P s z n)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
452
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
23 -- data ⊥ : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
24
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
25 -- record ⊤ : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
26 -- constructor tt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
27
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 -- peano : ∀ n → suc n ≡ zero → ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 Nope : (m n : ℕ) → Set
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 Nope (suc _) zero = ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 Nope _ _ = ⊤
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 nope : ∀ m n → m ≡ n → Nope m n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 nope zero ._ refl = _
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 nope (suc m) ._ refl = _
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 peano : ∀ n → suc n ≡ zero → ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 peano _ p = nope _ _ p
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 J : ∀ {a p} {A : Set a} (P : ∀ (x : A) y → x ≡ y → Set p)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 (f : ∀ x → P x x refl) → ∀ x y → (p : x ≡ y) → P x y p
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 J P f x .x refl = f x
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 Fin-elim : ∀ {p} (P : ∀ n → Fin n → Set p)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 (s : ∀ {n} {fn : Fin n} → P n fn → P (suc n) (fsuc fn))
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 (z : ∀ {n} → P (suc n) fzero) →
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 ∀ {n} (fn : Fin n) → P n fn
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 Fin-elim P s z fzero = z
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 Fin-elim P s z (fsuc x) = s (Fin-elim P s z x)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
452
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
53 Nope1 : ℕ -> Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
54 Nope1 zero = ⊥
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
55 Nope1 (suc _) = ⊤
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
453
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
57 Nope0 : ℕ → Set
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
58 Nope0 = ℕ-elim (λ _ → Set) (λ _ → ⊤) ⊥
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
59
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 bad : Fin 0 → ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 bad = Fin-elim (λ n _ → Nope0 n) (λ _ → _) _
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 -- http://stackoverflow.com/questions/18347542/agda-how-does-one-obtain-a-value-of-a-dependent-type
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 even : ℕ -> Set
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 even zero = ⊤
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 even (suc zero) = ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 even (suc (suc n)) = even n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 div : (n : ℕ) -> even n -> ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 div zero p = zero
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 div (suc (suc n)) p = suc (div n p)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 div (suc zero) ()
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
452
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
75 proof : 2 + 3 ≡ suc (suc (suc (suc (suc zero))))
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 proof = refl
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 --
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 -- ¬_ : Set → Set
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 -- ¬ A = A → ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 --
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 -- data Dec (P : Set) : Set where
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 -- yes : P → Dec P
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 -- no : ¬ P → Dec P
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 EvenDecidable : Set
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 EvenDecidable = ∀ n → Dec (even n)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 isEven : EvenDecidable
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 isEven zero = yes _
453
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
91 isEven (suc zero) = no (λ ())
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 isEven (suc (suc n)) = isEven n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 data Bool : Set where
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 true false : Bool
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 if_then_else_ : {A : Set} → Bool → A → A → A
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 if true then t else _ = t
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 if false then _ else f = f
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 ⌊_⌋ : {P : Set} → Dec P → Bool
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 ⌊ yes _ ⌋ = true
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 ⌊ no _ ⌋ = false
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 bad1 : ∀ n → even n → even (suc n) → ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 bad1 zero p q = q
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 bad1 (suc zero) p q = p
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 bad1 (suc (suc n)) p q = bad1 n p q
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 odd : ∀ n → ¬ even n → even (suc n)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 odd zero p = p _
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 odd (suc zero) p = _
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 odd (suc (suc n)) p = odd n p
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 g : ℕ → ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 g n with isEven n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 ... | yes e = div n e
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 ... | no o = div (suc n) (odd n o)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 -- g-bad : ℕ → ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 -- g-bad n = if ⌊ isEven n ⌋
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 -- then (div n {!!})
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 -- else (div (suc n) (odd n {!!}))
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 if-dec_then_else_ : {P A : Set} → Dec P → (P → A) → (¬ P → A) → A
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 if-dec yes p then t else _ = t p
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 if-dec no ¬p then _ else f = f ¬p
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 g' : ℕ → ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 g' n = if-dec isEven n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 then (λ e → div n e)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 else (λ o → div (suc n) (odd n o))
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 if-syntax = if-dec_then_else_
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 syntax if-syntax dec (λ yup → yupCase) (λ nope → nopeCase)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 = if-dec dec then[ yup ] yupCase else[ nope ] nopeCase
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 g'' : ℕ → ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 g'' n = if-dec isEven n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 then[ e ] div n e
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 else[ o ] div (suc n) (odd n o)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 mod : ℕ -> ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 mod zero = zero
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 mod (suc zero) = suc zero
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 mod (suc (suc N)) = mod N
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 proof1 : (n : ℕ ) -> ( if ⌊ isEven n ⌋ then zero else (suc zero) ) ≡ ( mod n )
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 proof1 zero = refl
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 proof1 (suc zero) = refl
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 proof1 (suc (suc n)) = let open ≡-Reasoning in
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 begin
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 if ⌊ isEven (suc (suc n)) ⌋ then zero else suc zero
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 ≡⟨ cong ( \x -> (if ⌊ x ⌋ then zero else suc zero)) (lemma2 {n} )⟩
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 if ⌊ isEven n ⌋ then zero else suc zero
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 ≡⟨ proof1 n ⟩
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 mod n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 ≡⟨ sym (lemma1 {n}) ⟩
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 mod (suc (suc n))
453
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
163 ∎ where
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
164 lemma1 : { n : ℕ } -> mod (suc (suc n )) ≡ mod n
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
165 lemma1 = refl
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
166 lemma2 : { n : ℕ } -> isEven (suc (suc n )) ≡ isEven n
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
167 lemma2 = refl
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168
822
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
169 data One : Set where
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
170 * : One
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
171
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
172 lemma1 : ( x y : One ) → x ≡ y
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
173 lemma1 * * = refl
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
174
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
175 lemma2 : {A : Set} ( x : A) → x ≡ x
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
176 lemma2 x = refl
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177
453
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
178
822
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
179 open import Data.Empty
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
180 open import Relation.Nullary
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
181 open import Level
453
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
182
822
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
183 lemma4 : Set (Level.suc Level.zero)
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
184 lemma4 = {A : Set} ( x y : A) → ¬ ( ¬ x ≡ y )
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
185
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
186 data A : Set where
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
187 x y z : A
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
188
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
189 data _==_ : ( a b : A ) → Set where
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
190 x=y : x == y
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
191
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
192 lemma3 : ( a b : A ) → a == b → ¬ a ≡ b
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
193 lemma3 _ _ x=y = λ ()
4c0580d9dda4 from cart to graph, hom equality to set equality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 454
diff changeset
194