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