Mercurial > hg > Gears > GearsAgda
annotate logic.agda @ 609:79418701a283
add test and speciication
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 04 Nov 2021 16:35:11 +0900 |
parents | 2075785a124a |
children | 0b791ae19543 |
rev | line source |
---|---|
579 | 1 module logic where |
2 | |
3 open import Level | |
4 open import Relation.Nullary | |
604 | 5 open import Relation.Binary hiding (_⇔_) |
586
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
6 open import Relation.Binary.PropositionalEquality |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
7 |
579 | 8 open import Data.Empty |
586
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
9 open import Data.Nat hiding (_⊔_) |
579 | 10 |
11 | |
12 data Bool : Set where | |
13 true : Bool | |
14 false : Bool | |
15 | |
16 record _∧_ {n m : Level} (A : Set n) ( B : Set m ) : Set (n ⊔ m) where | |
609
79418701a283
add test and speciication
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
604
diff
changeset
|
17 constructor ⟪_,_⟫ |
579 | 18 field |
19 proj1 : A | |
20 proj2 : B | |
21 | |
22 data _∨_ {n m : Level} (A : Set n) ( B : Set m ) : Set (n ⊔ m) where | |
23 case1 : A → A ∨ B | |
24 case2 : B → A ∨ B | |
25 | |
26 _⇔_ : {n m : Level } → ( A : Set n ) ( B : Set m ) → Set (n ⊔ m) | |
27 _⇔_ A B = ( A → B ) ∧ ( B → A ) | |
28 | |
29 contra-position : {n m : Level } {A : Set n} {B : Set m} → (A → B) → ¬ B → ¬ A | |
30 contra-position {n} {m} {A} {B} f ¬b a = ¬b ( f a ) | |
31 | |
32 double-neg : {n : Level } {A : Set n} → A → ¬ ¬ A | |
33 double-neg A notnot = notnot A | |
34 | |
35 double-neg2 : {n : Level } {A : Set n} → ¬ ¬ ¬ A → ¬ A | |
36 double-neg2 notnot A = notnot ( double-neg A ) | |
37 | |
38 de-morgan : {n : Level } {A B : Set n} → A ∧ B → ¬ ( (¬ A ) ∨ (¬ B ) ) | |
39 de-morgan {n} {A} {B} and (case1 ¬A) = ⊥-elim ( ¬A ( _∧_.proj1 and )) | |
40 de-morgan {n} {A} {B} and (case2 ¬B) = ⊥-elim ( ¬B ( _∧_.proj2 and )) | |
41 | |
42 dont-or : {n m : Level} {A : Set n} { B : Set m } → A ∨ B → ¬ A → B | |
43 dont-or {A} {B} (case1 a) ¬A = ⊥-elim ( ¬A a ) | |
44 dont-or {A} {B} (case2 b) ¬A = b | |
45 | |
46 dont-orb : {n m : Level} {A : Set n} { B : Set m } → A ∨ B → ¬ B → A | |
47 dont-orb {A} {B} (case2 b) ¬B = ⊥-elim ( ¬B b ) | |
48 dont-orb {A} {B} (case1 a) ¬B = a | |
49 | |
50 | |
51 infixr 130 _∧_ | |
52 infixr 140 _∨_ | |
53 infixr 150 _⇔_ | |
54 | |
55 _/\_ : Bool → Bool → Bool | |
56 true /\ true = true | |
57 _ /\ _ = false | |
58 | |
586
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
59 _<B?_ : ℕ → ℕ → Bool |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
60 ℕ.zero <B? x = true |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
61 ℕ.suc x <B? ℕ.zero = false |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
62 ℕ.suc x <B? ℕ.suc xx = x <B? xx |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
63 |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
64 -- _<BT_ : ℕ → ℕ → Set |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
65 -- ℕ.zero <BT ℕ.zero = ⊤ |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
66 -- ℕ.zero <BT ℕ.suc b = ⊤ |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
67 -- ℕ.suc a <BT ℕ.zero = ⊥ |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
68 -- ℕ.suc a <BT ℕ.suc b = a <BT b |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
69 |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
70 |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
71 _≟B_ : Decidable {A = Bool} _≡_ |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
72 true ≟B true = yes refl |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
73 false ≟B false = yes refl |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
74 true ≟B false = no λ() |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
75 false ≟B true = no λ() |
0ddfa505d612
isolate search function problem, and add hoareBinaryTree.agda.
ryokka
parents:
579
diff
changeset
|
76 |
579 | 77 _\/_ : Bool → Bool → Bool |
78 false \/ false = false | |
79 _ \/ _ = true | |
80 | |
81 not_ : Bool → Bool | |
82 not true = false | |
83 not false = true | |
84 | |
85 _<=>_ : Bool → Bool → Bool | |
86 true <=> true = true | |
87 false <=> false = true | |
88 _ <=> _ = false | |
89 | |
90 infixr 130 _\/_ | |
91 infixr 140 _/\_ |