annotate negnat.agda @ 454:2f07f4dd9a6d

fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 02 Mar 2017 13:25:05 +0900
parents 3c2ce4474d92
children 4c0580d9dda4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 module negnat where
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
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 open import Data.Nat
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Relation.Nullary
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Data.Empty
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import Data.Unit
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 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
9 open import Relation.Binary.Core
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Relation.Binary.PropositionalEquality
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
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 -- 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
14
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 ℕ-elim : ∀ {p} (P : ℕ → Set p)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 (s : ∀ {n} → P n → P (suc n))
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 (z : P 0) → ∀ n → P n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 ℕ-elim P s z zero = z
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 ℕ-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
21
452
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
22 -- data ⊥ : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
23
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
24 -- record ⊤ : Set where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
25 -- constructor tt
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
26
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 -- peano : ∀ n → suc n ≡ zero → ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 Nope : (m n : ℕ) → Set
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 Nope (suc _) zero = ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 Nope _ _ = ⊤
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 nope : ∀ m n → m ≡ n → Nope m n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 nope zero ._ refl = _
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 nope (suc m) ._ refl = _
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 peano : ∀ n → suc n ≡ zero → ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 peano _ p = nope _ _ p
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
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 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
42 (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
43 J P f x .x refl = f x
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 Fin-elim : ∀ {p} (P : ∀ n → Fin n → Set p)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 (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
47 (z : ∀ {n} → P (suc n) fzero) →
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 ∀ {n} (fn : Fin n) → P n fn
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 Fin-elim P s z fzero = z
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 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
51
452
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
52 Nope1 : ℕ -> Set
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
53 Nope1 zero = ⊥
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
54 Nope1 (suc _) = ⊤
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
453
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
56 Nope0 : ℕ → Set
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
57 Nope0 = ℕ-elim (λ _ → Set) (λ _ → ⊤) ⊥
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
58
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 bad : Fin 0 → ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 bad = Fin-elim (λ n _ → Nope0 n) (λ _ → _) _
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
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 -- 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
64 even : ℕ -> Set
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 even zero = ⊤
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 even (suc zero) = ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 even (suc (suc n)) = even n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 div : (n : ℕ) -> even n -> ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 div zero p = zero
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 div (suc (suc n)) p = suc (div n p)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 div (suc zero) ()
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
452
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 451
diff changeset
74 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
75 proof = refl
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
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 -- ¬_ : Set → Set
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 -- ¬ A = A → ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 --
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 -- data Dec (P : Set) : Set where
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 -- yes : P → Dec P
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 -- no : ¬ P → Dec P
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 EvenDecidable : Set
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 EvenDecidable = ∀ n → Dec (even n)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 isEven : EvenDecidable
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 isEven zero = yes _
453
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
90 isEven (suc zero) = no (λ ())
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 isEven (suc (suc n)) = isEven n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 data Bool : Set where
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 true false : Bool
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 if_then_else_ : {A : Set} → Bool → A → A → A
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 if true then t else _ = t
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 if false then _ else f = f
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 ⌊_⌋ : {P : Set} → Dec P → Bool
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 ⌊ yes _ ⌋ = true
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 ⌊ no _ ⌋ = false
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 bad1 : ∀ n → even n → even (suc n) → ⊥
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 bad1 zero p q = q
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 bad1 (suc zero) p q = p
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 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
108
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 odd : ∀ n → ¬ even n → even (suc n)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 odd zero p = p _
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 odd (suc zero) p = _
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 odd (suc (suc n)) p = odd n p
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 g : ℕ → ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 g n with isEven n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 ... | yes e = div n e
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 ... | no o = div (suc n) (odd n o)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 -- g-bad : ℕ → ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 -- g-bad n = if ⌊ isEven n ⌋
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 -- then (div n {!!})
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 -- else (div (suc n) (odd n {!!}))
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123
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 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
126 if-dec yes p then t else _ = t p
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 if-dec no ¬p then _ else f = f ¬p
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 g' : ℕ → ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 g' n = if-dec isEven n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 then (λ e → div n e)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 else (λ o → div (suc n) (odd n o))
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 if-syntax = if-dec_then_else_
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 syntax if-syntax dec (λ yup → yupCase) (λ nope → nopeCase)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 = if-dec dec then[ yup ] yupCase else[ nope ] nopeCase
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 g'' : ℕ → ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 g'' n = if-dec isEven n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 then[ e ] div n e
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 else[ o ] div (suc n) (odd n o)
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
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 mod : ℕ -> ℕ
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 mod zero = zero
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 mod (suc zero) = suc zero
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 mod (suc (suc N)) = mod N
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 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
151 proof1 zero = refl
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 proof1 (suc zero) = refl
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 proof1 (suc (suc n)) = let open ≡-Reasoning in
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 begin
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 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
156 ≡⟨ 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
157 if ⌊ isEven n ⌋ then zero else suc zero
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 ≡⟨ proof1 n ⟩
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 mod n
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 ≡⟨ sym (lemma1 {n}) ⟩
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 mod (suc (suc n))
453
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
162 ∎ where
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
163 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
164 lemma1 = refl
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
165 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
166 lemma2 = refl
451
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167
3ee32e4df4c7 add negation example
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168
453
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
169
3c2ce4474d92 try incomplete pattern for discrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 452
diff changeset
170