├── .circleci └── config.yml ├── .gitignore ├── LICENSE ├── README.md ├── src ├── Bools.agda ├── Equality.agda ├── Groups │ └── Symm │ │ └── S3.agda ├── Ints.agda ├── Ints │ ├── Add │ │ ├── Assoc.agda │ │ ├── Comm.agda │ │ └── Invert.agda │ ├── Properties │ └── Properties.agda ├── Isos │ ├── Isomorphism.agda │ ├── NatLike.agda │ └── TreeLike.agda ├── Lists.agda ├── Lists │ └── Reverse.agda ├── Logics │ ├── And.agda │ ├── Not.agda │ └── Or.agda ├── Nats.agda ├── Nats │ ├── Add │ │ ├── Assoc.agda │ │ ├── Comm.agda │ │ └── Invert.agda │ └── Multiply │ │ ├── Assoc.agda │ │ ├── Comm.agda │ │ └── Distrib.agda ├── PosNat.agda ├── Rationals.agda ├── Rationals │ ├── Add │ │ ├── Assoc.agda │ │ └── Comm.agda │ ├── Multiply │ │ └── Comm.agda │ └── Properties.agda ├── Trees.agda ├── Tuples.agda ├── Vecs.agda ├── Vecs │ └── Reverse.agda └── index.agda └── theorems.agda-lib /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | # terrorjack's awesome docker image 6 | # - image: terrorjack/rakuen:ghc-8.2.1.20171108 7 | # - image: terrorjack/meikyu:ghc-8.2.1.20171108 8 | # - image: terrorjack/meikyu:nightly-2017-12-05 9 | - image: terrorjack/pixie 10 | 11 | steps: 12 | - run: 13 | name: Initialize nix environment 14 | command: | 15 | nix-env -iA nixpkgs.haskellPackages.Agda nixpkgs.gitMinimal nixpkgs.openssh 16 | agda --version 17 | 18 | - checkout 19 | 20 | # - run: 21 | # name: Install Agda 22 | # command: | 23 | # stack --resolver nightly install alex cpphs happy Agda 24 | # agda --version 25 | # no_output_timeout: 1.2h 26 | 27 | - run: 28 | name: Install the Agda Standard lib 29 | command: | 30 | git clone https://github.com/agda/agda-stdlib.git ~/agda-stdlib/ 31 | mkdir ~/.agda 32 | echo "~/agda-stdlib/standard-library.agda-lib" >> ~/.agda/libraries 33 | echo "standard-library" >> ~/.agda/defaults 34 | 35 | - run: 36 | name: Build theorems 37 | command: agda src/index.agda 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Agda compiled 2 | *.agdai 3 | 4 | ## Agda generated 5 | html 6 | 7 | .idea 8 | 9 | ## local scripts 10 | push 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Theorems 2 | 3 | 4 | [![CircleCI](https://circleci.com/gh/ice1000/Theorems.svg?style=svg)](https://circleci.com/gh/ice1000/Theorems) 5 | [![GitHub top language](https://img.shields.io/github/languages/top/ice1000/Theorems.svg)](https://github.com/ice1000/Theorems) 6 | 7 | Theorems proving codes, written in Agda. 8 | 9 | Each proof is put into separate files, except those very very short ones. 10 | 11 | This library depends on [the Agda standard library](https://github.com/agda/agda-stdlib/). 12 | 13 | ## All Proofs 14 | 15 | You can either: 16 | 17 | + View all proves [online](http://ice1000.coding.me/Theorems/) 18 | 19 | + See [index.agda](./src/index.agda) 20 | 21 | ## File structure 22 | 23 | ```agda 24 | module Meow where -- module definition 25 | 26 | open import Data.Meow -- imports 27 | 28 | ------------------------------------------------------------------------ 29 | -- definitions 30 | 31 | meow~ : Meow -- some basic function definitions here 32 | 33 | ------------------------------------------------------------------------ 34 | -- internal stuffs 35 | 36 | private 37 | 38 | ⌈meow≶meow⌉ : Meow ≡ Meow -- proofs here, with strange but readable naming 39 | -- you'll never know how I type those characters 40 | 41 | ------------------------------------------------------------------------ 42 | -- public aliases 43 | 44 | meow-meow : Meow ≡ Meow 45 | meow-meow = ⌈meow≶meow⌉ -- regulated aliases, using ascii characters 46 | ``` 47 | -------------------------------------------------------------------------------- /src/Bools.agda: -------------------------------------------------------------------------------- 1 | module Bools where 2 | 3 | open import Agda.Builtin.Bool public 4 | renaming (Bool to 𝔹) 5 | 6 | not : 𝔹 → 𝔹 7 | not true = false 8 | not false = true 9 | 10 | -- T : 𝔹 → Set 11 | -- T true = ⊤ 12 | -- T false = ⊥ 13 | 14 | if_then_else_ : ∀ {a} {A : Set a} → 𝔹 → A → A → A 15 | if true then t else _ = t 16 | if false then _ else f = f 17 | 18 | _∧_ : 𝔹 → 𝔹 → 𝔹 19 | true ∧ b = b 20 | false ∧ _ = false 21 | 22 | _∨_ : 𝔹 → 𝔹 → 𝔹 23 | true ∨ _ = true 24 | false ∨ b = b 25 | 26 | _xor_ : 𝔹 → 𝔹 → 𝔹 27 | true xor b = not b 28 | false xor b = b 29 | -------------------------------------------------------------------------------- /src/Equality.agda: -------------------------------------------------------------------------------- 1 | module Equality where 2 | 3 | open import Agda.Builtin.Equality public 4 | open import Relation.Nullary 5 | 6 | infix 4 _≅_ _≢_ 7 | infixr 2 _≡⟨_⟩_ 8 | infix 3 _QED 9 | 10 | data _≅_ {ℓ} {A : Set ℓ} (x : A) : {B : Set ℓ} → B → Set ℓ where 11 | refl : x ≅ x 12 | 13 | ≡→≅ : ∀ {ℓ} {A : Set ℓ} {a b : A} → a ≡ b → a ≅ b 14 | ≡→≅ refl = refl 15 | 16 | sym : ∀ {ℓ} {A : Set ℓ} {a b : A} → a ≡ b → b ≡ a 17 | sym refl = refl 18 | 19 | sym′ : ∀ {ℓ} {A B : Set ℓ} {a : A} {b : B} → a ≅ b → b ≅ a 20 | sym′ refl = refl 21 | 22 | subst₂ : ∀ {a b p} {A : Set a} {B : Set b} (P : A → B → Set p) 23 | {x₁ x₂ y₁ y₂} → x₁ ≡ x₂ → y₁ ≡ y₂ → P x₁ y₁ → P x₂ y₂ 24 | subst₂ P refl refl p = p 25 | 26 | cong : ∀ {a b} {A : Set a} {B : Set b} 27 | (f : A → B) {x y} → x ≡ y → f x ≡ f y 28 | cong f refl = refl 29 | 30 | cong-app : ∀ {a b} {A : Set a} {B : A → Set b} {f g : (x : A) → B x} → 31 | f ≡ g → (x : A) → f x ≡ g x 32 | cong-app refl x = refl 33 | 34 | cong₂ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} 35 | (f : A → B → C) {x y u v} → x ≡ y → u ≡ v → f x u ≡ f y v 36 | cong₂ f refl refl = refl 37 | 38 | _≢_ : ∀ {a} {A : Set a} → A → A → Set a 39 | x ≢ y = ¬ x ≡ y 40 | 41 | _≡⟨_⟩_ : ∀ {A : Set} (x : A) {y z : A} 42 | → x ≡ y → y ≡ z → x ≡ z 43 | x ≡⟨ refl ⟩ refl = refl 44 | 45 | _QED : ∀ {A : Set} (x : A) → x ≡ x 46 | x QED = refl 47 | -------------------------------------------------------------------------------- /src/Groups/Symm/S3.agda: -------------------------------------------------------------------------------- 1 | module Groups.Symm.S3 where 2 | 3 | open import Equality 4 | 5 | ------------------------------------------------------------------------ 6 | -- definitions 7 | 8 | bin-op : ∀ {a} (A : Set a) → Set a 9 | bin-op A = A → A → A 10 | 11 | ------------------------------------------------------------------------ 12 | -- internal stuffs 13 | 14 | private 15 | 16 | record S₃ {a} (A : Set a) : Set a where 17 | constructor ⟨_,_,_⟩-⟨_,_,_⟩-⟨_,_,_⟩ 18 | infixl 5 _×_ 19 | field 20 | x y {e} : A 21 | _×_ : bin-op A 22 | assoc : ∀ a b c → a × b × c ≡ a × (b × c) 23 | idₗ : ∀ n → n × e ≡ n 24 | idᵣ : ∀ n → e × n ≡ n 25 | law-xxx=e : x × x × x ≡ e 26 | law-yy=e : y × y ≡ e 27 | law-yx=xxy : y × x ≡ x × x × y 28 | 29 | law-xyx=y : Set a 30 | law-xyx=y = x × y × x ≡ y 31 | 32 | xyx=y : law-xyx=y 33 | xyx=y 34 | rewrite assoc x y x 35 | | law-yx=xxy 36 | | sym (assoc x (x × x) y) 37 | | sym (assoc x x x) 38 | | law-xxx=e 39 | = idᵣ y 40 | 41 | ------------------------------------------------------------------------ 42 | -- public aliases 43 | 44 | s3-property-1 : ∀ {a} (A : S₃ (Set a)) → S₃.law-xyx=y A 45 | s3-property-1 = S₃.xyx=y 46 | -------------------------------------------------------------------------------- /src/Ints.agda: -------------------------------------------------------------------------------- 1 | module Ints where 2 | 3 | open import Nats public 4 | using (ℕ; zero; _∸_) 5 | renaming (suc to nsuc; _+_ to _:+:_; _*_ to _:*:_) 6 | open import Agda.Builtin.Int public 7 | renaming (Int to ℤ; negsuc to -[1+_]; pos to +_) 8 | 9 | infix 8 -_ 10 | -- infixl 7 _*_ _⊓_ 11 | infixl 6 _+_ _-_ _⊖_ 12 | 13 | ∣_∣ : ℤ → ℕ 14 | ∣ + n ∣ = n 15 | ∣ -[1+ n ] ∣ = nsuc n 16 | 17 | -_ : ℤ → ℤ 18 | - (+ nsuc n) = -[1+ n ] 19 | - (+ zero) = + zero 20 | - -[1+ n ] = + nsuc n 21 | 22 | _⊖_ : ℕ → ℕ → ℤ 23 | m ⊖ zero = + m 24 | zero ⊖ nsuc n = -[1+ n ] 25 | nsuc m ⊖ nsuc n = m ⊖ n 26 | 27 | _+_ : ℤ → ℤ → ℤ 28 | -[1+ m ] + -[1+ n ] = -[1+ nsuc (m :+: n) ] 29 | -[1+ m ] + + n = n ⊖ nsuc m 30 | + m + -[1+ n ] = m ⊖ nsuc n 31 | + m + + n = + (m :+: n) 32 | 33 | _-_ : ℤ → ℤ → ℤ 34 | i - j = i + - j 35 | 36 | suc : ℤ → ℤ 37 | suc i = + 1 + i 38 | 39 | -------------------------------------------------------------------------------- /src/Ints/Add/Assoc.agda: -------------------------------------------------------------------------------- 1 | module Ints.Add.Assoc where 2 | 3 | open import Ints 4 | open import Nats renaming (suc to nsuc; _+_ to _:+:_) 5 | 6 | open import Nats.Add.Assoc 7 | open import Nats.Add.Comm 8 | 9 | open import Ints.Add.Comm 10 | 11 | open import Equality 12 | open import Function 13 | 14 | ------------------------------------------------------------------------ 15 | -- internal stuffs 16 | 17 | private 18 | 19 | 0+a=a : ∀ a → + 0 + a ≡ a 20 | 0+a=a (+ n ) = refl 21 | 0+a=a (-[1+ n ]) = refl 22 | 23 | a+0=a : ∀ a → a + + 0 ≡ a 24 | a+0=a a rewrite int-add-comm a (+ 0) | 0+a=a a = refl 25 | 26 | z+/b+c/=/z+b/+c : ∀ b c → + 0 + (b + c) ≡ (+ 0 + b) + c 27 | z+/b+c/=/z+b/+c (+ a ) (+ b ) = refl 28 | z+/b+c/=/z+b/+c (-[1+ a ]) (-[1+ b ]) = refl 29 | z+/b+c/=/z+b/+c (+ a ) (-[1+ b ]) 30 | rewrite 0+a=a (a ⊖ nsuc b) = refl 31 | z+/b+c/=/z+b/+c (-[1+ a ]) (+ b ) 32 | rewrite 0+a=a (b ⊖ nsuc a) = refl 33 | 34 | a+b=a--b : ∀ a b → a + b ≡ a - (- b) 35 | a+b=a--b a (+ zero ) = refl 36 | a+b=a--b a (+ nsuc n) 37 | rewrite a+b=a--b a (+ n) = refl 38 | a+b=a--b a (-[1+ n ]) = refl 39 | 40 | a-b+c=a+c-b : ∀ a b c → a ⊖ b + + c ≡ a :+: c ⊖ b 41 | a-b+c=a+c-b zero zero _ = refl 42 | a-b+c=a+c-b zero (nsuc _) _ = refl 43 | a-b+c=a+c-b (nsuc _) zero _ = refl 44 | a-b+c=a+c-b (nsuc a) (nsuc b) c = a-b+c=a+c-b a b c 45 | 46 | a+/b-c/=a+b-c : ∀ a b c → + a + (b ⊖ c) ≡ a :+: b ⊖ c 47 | a+/b-c/=a+b-c a b c 48 | rewrite int-add-comm (+ a) $ b ⊖ c 49 | | a-b+c=a+c-b b c a 50 | | nat-add-comm a b 51 | = refl 52 | 53 | b-c-a=b-/c+a/ : ∀ a b c → b ⊖ c + -[1+ a ] ≡ b ⊖ (nsuc c :+: a) 54 | b-c-a=b-/c+a/ _ zero zero = refl 55 | b-c-a=b-/c+a/ _ zero (nsuc _) = refl 56 | b-c-a=b-/c+a/ _ (nsuc _) zero = refl 57 | b-c-a=b-/c+a/ a (nsuc b) (nsuc c) = b-c-a=b-/c+a/ a b c 58 | 59 | -a+/b-c/=b-/a+c/ : ∀ a b c → -[1+ a ] + (b ⊖ c) ≡ b ⊖ (nsuc a :+: c) 60 | -a+/b-c/=b-/a+c/ a b c 61 | rewrite int-add-comm -[1+ a ] $ b ⊖ c 62 | | b-c-a=b-/c+a/ a b c 63 | | nat-add-comm a c 64 | = refl 65 | 66 | a+/b+c/=/a+b/+c : ∀ a b c → a + (b + c) ≡ a + b + c 67 | a+/b+c/=/a+b/+c (+ zero) b c rewrite 0+a=a (b + c) | 0+a=a b = refl 68 | a+/b+c/=/a+b/+c a (+ zero) c rewrite 0+a=a c | a+0=a a = refl 69 | a+/b+c/=/a+b/+c a b (+ zero) rewrite a+0=a b | a+0=a (a + b) = refl 70 | a+/b+c/=/a+b/+c (+ a) (+ b) (+ c) 71 | rewrite nat-add-assoc a b c = refl 72 | a+/b+c/=/a+b/+c -[1+ a ] -[1+ b ] (+ nsuc c) 73 | rewrite -a+/b-c/=b-/a+c/ a c b = refl 74 | a+/b+c/=/a+b/+c -[1+ a ] (+ nsuc b) -[1+ c ] 75 | rewrite -a+/b-c/=b-/a+c/ a b c 76 | | b-c-a=b-/c+a/ c b a 77 | = refl 78 | a+/b+c/=/a+b/+c (+ nsuc a) -[1+ b ] -[1+ c ] 79 | rewrite b-c-a=b-/c+a/ c a b = refl 80 | a+/b+c/=/a+b/+c (+ nsuc a) -[1+ b ] (+ nsuc c) 81 | rewrite a-b+c=a+c-b a b $ nsuc c 82 | | a+/b-c/=a+b-c (nsuc a) c b 83 | | sym $ nat-add-assoc a 1 c 84 | | nat-add-comm a 1 85 | = refl 86 | a+/b+c/=/a+b/+c -[1+ a ] (+ nsuc b) (+ nsuc c) 87 | rewrite a-b+c=a+c-b b a (nsuc c) = refl 88 | a+/b+c/=/a+b/+c -[1+ a ] -[1+ b ] -[1+ c ] 89 | rewrite nat-add-comm a $ nsuc $ b :+: c 90 | | nat-add-comm (b :+: c) a 91 | | nat-add-assoc a b c 92 | = refl 93 | a+/b+c/=/a+b/+c (+ nsuc a) (+ nsuc b) -[1+ c ] 94 | rewrite a+/b-c/=a+b-c (nsuc a) b c 95 | | sym $ nat-add-assoc a 1 b 96 | | nat-add-comm a 1 97 | = refl 98 | 99 | ------------------------------------------------------------------------ 100 | -- public aliases 101 | 102 | int-add-assoc : ∀ a b c → a + (b + c) ≡ a + b + c 103 | int-add-assoc = a+/b+c/=/a+b/+c 104 | -------------------------------------------------------------------------------- /src/Ints/Add/Comm.agda: -------------------------------------------------------------------------------- 1 | module Ints.Add.Comm where 2 | 3 | open import Ints 4 | open import Nats.Add.Comm 5 | 6 | open import Equality 7 | 8 | ------------------------------------------------------------------------ 9 | -- internal stuffs 10 | 11 | private 12 | 13 | a+b=b+a : ∀ a b → a + b ≡ b + a 14 | a+b=b+a (+ a) (+ b) = + (a :+: b) 15 | ≡⟨ cong +_ (nat-add-comm a b) ⟩ + (b :+: a) QED 16 | a+b=b+a (+ a ) (-[1+ b ]) 17 | rewrite nat-add-comm a b = refl 18 | a+b=b+a (-[1+ a ]) (+ b ) 19 | rewrite nat-add-comm a b = refl 20 | a+b=b+a (-[1+ a ]) (-[1+ b ]) 21 | rewrite nat-add-comm a b = refl 22 | 23 | ------------------------------------------------------------------------ 24 | -- public aliases 25 | 26 | int-add-comm : ∀ a b → a + b ≡ b + a 27 | int-add-comm = a+b=b+a 28 | -------------------------------------------------------------------------------- /src/Ints/Add/Invert.agda: -------------------------------------------------------------------------------- 1 | module Ints.Add.Invert where 2 | 3 | open import Ints 4 | open import Ints.Properties 5 | open import Ints.Add.Comm 6 | open import Nats.Add.Invert 7 | 8 | open import Data.Empty 9 | open import Relation.Nullary 10 | 11 | open import Equality 12 | open import Function 13 | 14 | ------------------------------------------------------------------------ 15 | -- internal stuffs 16 | 17 | private 18 | 19 | nat→int′ : ∀ a b → -[1+ nsuc $ a :+: a ] ≡ -[1+ nsuc $ b :+: b ] → a ≡ b 20 | nat→int′ a b = nat-add-invert a b ∘ nat-add-invert-1 (a :+: a) (b :+: b) ∘ eq-neg-int-to-nat 21 | 22 | impossible : ∀ a b → ¬ (+ a + + a ≡ -[1+ b ] + -[1+ b ]) 23 | impossible a b () 24 | 25 | +-invert : ∀ a b → (a + a ≡ b + b) → a ≡ b 26 | +-invert (+ a ) (+ b ) = eq-nat-to-int ∘ nat-add-invert a b ∘ eq-int-to-nat 27 | +-invert (+ a ) -[1+ b ] = ⊥-elim ∘ impossible a b 28 | +-invert -[1+ a ] (+ b ) = ⊥-elim ∘ impossible b a ∘ sym 29 | +-invert -[1+ a ] -[1+ b ] = eq-neg-nat-to-int ∘ nat→int′ a b 30 | 31 | ------------------------------------------------------------------------ 32 | -- public aliases 33 | 34 | int-add-invert : ∀ a b → (a + a ≡ b + b) → a ≡ b 35 | int-add-invert = +-invert 36 | 37 | -------------------------------------------------------------------------------- /src/Ints/Properties: -------------------------------------------------------------------------------- 1 | module Ints.Properties where -------------------------------------------------------------------------------- /src/Ints/Properties.agda: -------------------------------------------------------------------------------- 1 | module Ints.Properties where 2 | 3 | open import Ints 4 | open import Equality 5 | 6 | ------------------------------------------------------------------------ 7 | -- internal stuffs 8 | 9 | private 10 | ≡→≡ : ∀ {a b} → (+ a ≡ + b) → a ≡ b 11 | ≡→≡ refl = refl 12 | 13 | ≡→≡′ : ∀ {a b} → (-[1+ a ] ≡ -[1+ b ]) → a ≡ b 14 | ≡→≡′ refl = refl 15 | 16 | ≡←≡ : ∀ {a b} → a ≡ b → (+ a ≡ + b) 17 | ≡←≡ refl = refl 18 | 19 | ≡←≡′ : ∀ {a b} → a ≡ b → (-[1+ a ] ≡ -[1+ b ]) 20 | ≡←≡′ refl = refl 21 | 22 | ------------------------------------------------------------------------ 23 | -- public aliases 24 | 25 | eq-int-to-nat : ∀ {a b} → (+ a ≡ + b) → a ≡ b 26 | eq-int-to-nat = ≡→≡ 27 | 28 | eq-neg-int-to-nat : ∀ {a b} → (-[1+ a ] ≡ -[1+ b ]) → a ≡ b 29 | eq-neg-int-to-nat = ≡→≡′ 30 | 31 | eq-nat-to-int : ∀ {a b} → a ≡ b → (+ a ≡ + b) 32 | eq-nat-to-int = ≡←≡ 33 | 34 | eq-neg-nat-to-int : ∀ {a b} → a ≡ b → (-[1+ a ] ≡ -[1+ b ]) 35 | eq-neg-nat-to-int = ≡←≡′ 36 | -------------------------------------------------------------------------------- /src/Isos/Isomorphism.agda: -------------------------------------------------------------------------------- 1 | module Isos.Isomorphism where 2 | 3 | open import Logics.And public 4 | -------------------------------------------------------------------------------- /src/Isos/NatLike.agda: -------------------------------------------------------------------------------- 1 | module Isos.NatLike where 2 | 3 | open import Isos.Isomorphism 4 | 5 | open import Nats 6 | open import Data.Product 7 | 8 | open import Equality 9 | open import Data.Unit 10 | 11 | ------------------------------------------------------------------------ 12 | -- internal stuffs 13 | 14 | private 15 | 16 | module WithList where 17 | 18 | open import Lists 19 | 20 | list→ℕ : List ⊤ → ℕ 21 | list→ℕ [] = zero 22 | list→ℕ (tt ∷ a) = suc (list→ℕ a) 23 | 24 | ℕ→list : ℕ → List ⊤ 25 | ℕ→list zero = [] 26 | ℕ→list (suc a) = tt ∷ ℕ→list a 27 | 28 | proofListL : ∀ n → list→ℕ (ℕ→list n) ≡ n 29 | proofListL zero = refl 30 | proofListL (suc n) rewrite proofListL n = refl 31 | 32 | proofListR : ∀ n → ℕ→list (list→ℕ n) ≡ n 33 | proofListR [] = refl 34 | proofListR (tt ∷ l) rewrite proofListR l = refl 35 | 36 | module WithVec where 37 | 38 | open import Vecs 39 | 40 | vec→ℕ′ : ∀ {n} → Vec ⊤ n → ℕ 41 | vec→ℕ′ {n} [] = n 42 | vec→ℕ′ {n} (tt ∷ a) = n 43 | 44 | vec→ℕ : ∀ {n} → Vec ⊤ n → ∃ (λ m → n ≡ m) 45 | vec→ℕ [] = zero , refl 46 | vec→ℕ (tt ∷ a) with vec→ℕ a 47 | ... | m , refl = suc m , refl 48 | 49 | ℕ→vec : ∀ {n} → ∃ (λ m → n ≡ m) → Vec ⊤ n 50 | ℕ→vec (zero , refl) = [] 51 | ℕ→vec ((suc a) , refl) = tt ∷ ℕ→vec (a , refl) 52 | 53 | proofVecL : ∀ {n} (m : ∃ (λ m → n ≡ m)) → vec→ℕ (ℕ→vec m) ≡ m 54 | proofVecL (zero , refl) = refl 55 | proofVecL (suc a , refl) rewrite proofVecL (a , refl) = refl 56 | 57 | -- how to prove? 58 | -- proofVecR : ∀ n → ℕ→vec (vec→ℕ n) ≡ n 59 | 60 | ------------------------------------------------------------------------ 61 | -- public aliases 62 | 63 | iso-nat-list : ℕ ⇔ List ⊤ 64 | iso-nat-list = ∧-intro ℕ→list list→ℕ 65 | 66 | iso-nat-vec : ∀ {n} → ∃ (λ m → n ≡ m) ⇔ Vec ⊤ n 67 | iso-nat-vec = ∧-intro ℕ→vec vec→ℕ 68 | -------------------------------------------------------------------------------- /src/Isos/TreeLike.agda: -------------------------------------------------------------------------------- 1 | module Isos.TreeLike where 2 | 3 | open import Isos.Isomorphism 4 | 5 | open import Trees 6 | open import Tuples 7 | open import Equality 8 | 9 | open import Data.Product 10 | open import Data.Unit 11 | 12 | ------------------------------------------------------------------------ 13 | -- internal stuffs 14 | 15 | private 16 | 17 | pattern ∅ = Empty tt 18 | ∅′ : BareBinTree 19 | ∅′ = Empty tt 20 | _,,_ : BareBinTree → BareBinTree → BareBinTree 21 | _,,_ = Node tt 22 | infixl 4 _,,_ 23 | pattern [_,_] a b = Node tt a b 24 | 25 | tree⁷->tree : BareBinTree ⁷ → BareBinTree 26 | tree⁷->tree (∅ , ∅ , ∅ , ∅ , ∅ , ∅ , [ [ [ [ a , b ] , c ] , d ] , e ]) 27 | = ∅′ ,, a ,, b ,, c ,, d ,, e 28 | tree⁷->tree (∅ , ∅ , ∅ , ∅ , ∅ , ∅ , a) = a 29 | tree⁷->tree (∅ , ∅ , ∅ , ∅ , ∅ , t₅ , t₆) 30 | = t₅ ,, t₆ ,, ∅′ ,, ∅′ ,, ∅′ ,, ∅′ ,, ∅′ 31 | tree⁷->tree (∅ , ∅ , ∅ , ∅ , [ a , b ] , t₅ , t₆) 32 | = ∅′ ,, t₆ ,, t₅ ,, a ,, b 33 | tree⁷->tree (t₀ , t₁ , t₂ , t₃ , t₄ , t₅ , t₆) 34 | = t₆ ,, t₅ ,, t₄ ,, t₃ ,, t₂ ,, t₁ ,, t₀ 35 | 36 | tree->tree⁷ : BareBinTree → BareBinTree ⁷ 37 | tree->tree⁷ [ [ [ [ [ ∅ , a ] , b ] , c ] , d ] , e ] 38 | = ∅ , ∅ , ∅ , ∅ , ∅ , ∅ , (a ,, b ,, c ,, d ,, e) 39 | tree->tree⁷ [ [ [ [ [ t₆ , t₅ ] , ∅ ] , ∅ ] , ∅ ] , ∅ ] 40 | = ∅ , ∅ , ∅ , ∅ , ∅ , t₅ , t₆ 41 | tree->tree⁷ [ [ [ [ ∅ , t₆ ] , t₅ ] , a ] , b ] 42 | = ∅ , ∅ , ∅ , ∅ , (a ,, b) , t₅ , t₆ 43 | tree->tree⁷ [ [ [ [ [ [ t₆ , t₅ ] , t₄ ] , t₃ ] , t₂ ] , t₁ ] , t₀ ] 44 | = t₀ , t₁ , t₂ , t₃ , t₄ , t₅ , t₆ 45 | tree->tree⁷ a = ∅ , ∅ , ∅ , ∅ , ∅ , ∅ , a 46 | 47 | tree⁷<=>tree : BareBinTree ⁷ ⇔ BareBinTree 48 | tree⁷<=>tree = ∧-intro tree⁷->tree tree->tree⁷ 49 | 50 | -- too hard 51 | -- proofL : ∀ tree → tree⁷->tree (tree->tree⁷ tree) ≡ tree 52 | -- proofL [ [ [ [ [ ∅ , a ] , b ] , c ] , d ] , e ] 53 | -- = refl 54 | -- proofL [ [ [ [ [ Node x t₆ t7 , t₅ ] , ∅ ] , ∅ ] , ∅ ] , ∅ ] 55 | -- = {!!} 56 | -- proofL [ [ [ [ ∅ , t₆ ] , t₅ ] , a ] , b ] 57 | -- = refl 58 | -- proofL [ [ [ [ [ [ t₆ , t₅ ] , t₄ ] , t₃ ] , t₂ ] , t₁ ] , t₀ ] 59 | -- = {!!} 60 | -- proofL _ = {!!} 61 | 62 | ------------------------------------------------------------------------ 63 | -- public aliases 64 | 65 | iso-seven-tree-in-one : BareBinTree ⁷ ⇔ BareBinTree 66 | iso-seven-tree-in-one = tree⁷<=>tree 67 | 68 | -------------------------------------------------------------------------------- /src/Lists.agda: -------------------------------------------------------------------------------- 1 | module Lists where 2 | 3 | open import Nats 4 | open import Bools 5 | 6 | open import Agda.Builtin.List public 7 | using (List; []; _∷_) 8 | 9 | infixr 5 _++_ _∷ʳ_ 10 | 11 | [_] : ∀ {a} {A : Set a} → A → List A 12 | [ x ] = x ∷ [] 13 | 14 | _++_ : ∀ {a} {A : Set a} → List A → List A → List A 15 | [] ++ ys = ys 16 | (x ∷ xs) ++ ys = x ∷ (xs ++ ys) 17 | 18 | _∷ʳ_ : ∀ {a} {A : Set a} → List A → A → List A 19 | xs ∷ʳ x = xs ++ [ x ] 20 | 21 | null : ∀ {a} {A : Set a} → List A → 𝔹 22 | null [] = true 23 | null (x ∷ xs) = false 24 | 25 | reverse : ∀ {a} {A : Set a} → List A → List A 26 | reverse [] = [] 27 | reverse (x ∷ xs) = reverse xs ∷ʳ x 28 | 29 | replicate : ∀ {a} {A : Set a} → (n : ℕ) → A → List A 30 | replicate zero x = [] 31 | replicate (suc n) x = x ∷ replicate n x 32 | -------------------------------------------------------------------------------- /src/Lists/Reverse.agda: -------------------------------------------------------------------------------- 1 | module Lists.Reverse where 2 | 3 | open import Lists 4 | open import Nats 5 | open import Equality 6 | open import Function 7 | 8 | ------------------------------------------------------------------------ 9 | -- internal stuffs 10 | 11 | private 12 | 13 | -- rev$v:a=a:rev$v : ∀ {n m} {A : Set n} (a : A) (v : List A m) → 14 | -- rev (v ∷ʳ a) ≡ a ∷ rev v 15 | -- rev$v:a=a:rev$v _ [] = refl 16 | -- rev$v:a=a:rev$v a (_ ∷ xs) with rev (xs ∷ʳ a) | rev$v:a=a:rev$v a xs 17 | -- ... | .(a ∷ rev xs) | refl = refl 18 | 19 | rev$v:a=a:rev$v : ∀ {n} {A : Set n} (a : A) (v : List A) → 20 | reverse (v ∷ʳ a) ≡ a ∷ reverse v 21 | rev$v:a=a:rev$v _ [] = refl 22 | rev$v:a=a:rev$v a (_ ∷ xs) 23 | rewrite rev$v:a=a:rev$v a xs 24 | = refl 25 | 26 | rev∘rev=id : ∀ {n} {A : Set n} (v : List A) → reverse (reverse v) ≡ v 27 | rev∘rev=id [] = refl 28 | rev∘rev=id (x ∷ xs) 29 | rewrite rev$v:a=a:rev$v x $ reverse xs 30 | | rev∘rev=id xs 31 | = refl 32 | 33 | ------------------------------------------------------------------------ 34 | -- public aliases 35 | 36 | list-rev-rev-id : ∀ {n} {A : Set n} (v : List A) → reverse (reverse v) ≡ v 37 | list-rev-rev-id = rev∘rev=id 38 | -------------------------------------------------------------------------------- /src/Logics/And.agda: -------------------------------------------------------------------------------- 1 | module Logics.And where 2 | 3 | open import Function 4 | 5 | ------------------------------------------------------------------------ 6 | -- definitions 7 | 8 | infixl 5 _∧_ 9 | infixl 4 _⇔_ 10 | 11 | data _∧_ (P Q : Set) : Set where 12 | ∧-intro : P → Q → P ∧ Q 13 | 14 | _⇔_ : (P Q : Set) → Set 15 | p ⇔ q = (p → q) ∧ (q → p) 16 | 17 | ------------------------------------------------------------------------ 18 | -- internal stuffs 19 | 20 | private 21 | 22 | ∧-comm′ : ∀ {P Q} → (P ∧ Q) → (Q ∧ P) 23 | ∧-comm′ (∧-intro p q) = ∧-intro q p 24 | 25 | ∧-assoc₀ : ∀ {P Q R} → ((P ∧ Q) ∧ R) → (P ∧ (Q ∧ R)) 26 | ∧-assoc₀ (∧-intro (∧-intro p q) r) = ∧-intro p $ ∧-intro q r 27 | 28 | ∧-assoc₁ : ∀ {P Q R} → (P ∧ (Q ∧ R)) → ((P ∧ Q) ∧ R) 29 | ∧-assoc₁ (∧-intro p (∧-intro q r)) = ∧-intro (∧-intro p q) r 30 | 31 | ∧-comm : ∀ {P Q} → (P ∧ Q) ⇔ (Q ∧ P) 32 | ∧-comm = ∧-intro ∧-comm′ ∧-comm′ 33 | 34 | ∧-assoc : ∀ {P Q R} → (P ∧ (Q ∧ R)) ⇔ ((P ∧ Q) ∧ R) 35 | ∧-assoc = ∧-intro ∧-assoc₁ ∧-assoc₀ 36 | 37 | ------------------------------------------------------------------------ 38 | -- public aliases 39 | 40 | and-comm : ∀ {P Q} → (P ∧ Q) ⇔ (Q ∧ P) 41 | and-comm = ∧-comm 42 | 43 | and-assoc : ∀ {P Q R} → (P ∧ (Q ∧ R)) ⇔ ((P ∧ Q) ∧ R) 44 | and-assoc = ∧-assoc 45 | 46 | -------------------------------------------------------------------------------- /src/Logics/Not.agda: -------------------------------------------------------------------------------- 1 | module Logics.Not where 2 | 3 | open import Function 4 | open import Relation.Nullary 5 | 6 | ------------------------------------------------------------------------ 7 | -- internal stuffs 8 | 9 | private 10 | 11 | a=¬∘¬a : ∀ {a} {A : Set a} → A → ¬ (¬ A) 12 | a=¬∘¬a a z = z a 13 | 14 | /p→q/→¬/p→¬q/ : ∀ {p q} {P : Set p} {Q : Set q} → (P → Q) → (¬ Q → ¬ P) 15 | /p→q/→¬/p→¬q/ p→q ¬q p = ¬q $ p→q p 16 | 17 | ------------------------------------------------------------------------ 18 | -- public aliases 19 | 20 | not-not : ∀ {ℓ} {A : Set ℓ} → A → ¬ (¬ A) 21 | not-not = a=¬∘¬a 22 | 23 | contrapositive : ∀ {p q} {P : Set p} {Q : Set q} → (P → Q) → (¬ Q → ¬ P) 24 | contrapositive = /p→q/→¬/p→¬q/ 25 | -------------------------------------------------------------------------------- /src/Logics/Or.agda: -------------------------------------------------------------------------------- 1 | module Logics.Or where 2 | 3 | open import Function 4 | open import Logics.And 5 | 6 | ------------------------------------------------------------------------ 7 | -- definitions 8 | 9 | infixl 4 _∨_ 10 | 11 | data _∨_ (P Q : Set) : Set where 12 | ∨-intro₀ : P → P ∨ Q 13 | ∨-intro₁ : Q → P ∨ Q 14 | 15 | ------------------------------------------------------------------------ 16 | -- internal stuffs 17 | 18 | private 19 | 20 | p→r+q→r+p∨q=r : ∀ {P Q n} {R : Set n} → (P → R) → (Q → R) → (P ∨ Q) → R 21 | p→r+q→r+p∨q=r pr _ (∨-intro₀ p) = pr p 22 | p→r+q→r+p∨q=r _ qr (∨-intro₁ q) = qr q 23 | 24 | ∨-comm′ : ∀ {P Q} → (P ∨ Q) → (Q ∨ P) 25 | ∨-comm′ (∨-intro₀ p) = ∨-intro₁ p 26 | ∨-comm′ (∨-intro₁ q) = ∨-intro₀ q 27 | 28 | ∨-assoc₀ : ∀ {P Q R} → ((P ∨ Q) ∨ R) → (P ∨ (Q ∨ R)) 29 | ∨-assoc₀ (∨-intro₀ (∨-intro₀ x)) = ∨-intro₀ x 30 | ∨-assoc₀ (∨-intro₀ (∨-intro₁ x)) = ∨-intro₁ $ ∨-intro₀ x 31 | ∨-assoc₀ (∨-intro₁ x) = ∨-intro₁ $ ∨-intro₁ x 32 | 33 | ∨-assoc₁ : ∀ {P Q R} → (P ∨ (Q ∨ R)) → ((P ∨ Q) ∨ R) 34 | ∨-assoc₁ (∨-intro₀ x) = ∨-intro₀ $ ∨-intro₀ x 35 | ∨-assoc₁ (∨-intro₁ (∨-intro₀ x)) = ∨-intro₀ $ ∨-intro₁ x 36 | ∨-assoc₁ (∨-intro₁ (∨-intro₁ x)) = ∨-intro₁ x 37 | 38 | ∨-elim : ∀ {P Q n} {R : Set n} → (P → R) → (Q → R) → (P ∨ Q) → R 39 | ∨-elim = p→r+q→r+p∨q=r 40 | 41 | ∨-comm : ∀ {P Q} → (P ∨ Q) ⇔ (Q ∨ P) 42 | ∨-comm = ∧-intro ∨-comm′ ∨-comm′ 43 | 44 | ∨-assoc : ∀ {P Q R} → (P ∨ (Q ∨ R)) ⇔ ((P ∨ Q) ∨ R) 45 | ∨-assoc = ∧-intro ∨-assoc₁ ∨-assoc₀ 46 | 47 | ------------------------------------------------------------------------ 48 | -- public aliases 49 | 50 | or-elim : ∀ {P Q n} {R : Set n} → (P → R) → (Q → R) → (P ∨ Q) → R 51 | or-elim = ∨-elim 52 | 53 | or-comm : ∀ {P Q} → (P ∨ Q) ⇔ (Q ∨ P) 54 | or-comm = ∨-comm 55 | 56 | or-assoc : ∀ {P Q R} → (P ∨ (Q ∨ R)) ⇔ ((P ∨ Q) ∨ R) 57 | or-assoc = ∨-assoc 58 | -------------------------------------------------------------------------------- /src/Nats.agda: -------------------------------------------------------------------------------- 1 | module Nats where 2 | 3 | open import Agda.Builtin.Nat public 4 | renaming (Nat to ℕ; _-_ to _∸_) 5 | -------------------------------------------------------------------------------- /src/Nats/Add/Assoc.agda: -------------------------------------------------------------------------------- 1 | module Nats.Add.Assoc where 2 | 3 | open import Equality 4 | open import Nats 5 | open import Function 6 | 7 | ------------------------------------------------------------------------ 8 | -- internal stuffs 9 | 10 | private 11 | 12 | a+/b+c/=/a+b/+c : ∀ a b c → a + b + c ≡ a + (b + c) 13 | a+/b+c/=/a+b/+c zero b c = refl 14 | a+/b+c/=/a+b/+c (suc a) b c = cong suc $ a+/b+c/=/a+b/+c a b c 15 | 16 | ------------------------------------------------------------------------ 17 | -- public aliases 18 | 19 | nat-add-assoc : ∀ a b c → a + b + c ≡ a + (b + c) 20 | nat-add-assoc = a+/b+c/=/a+b/+c 21 | 22 | -------------------------------------------------------------------------------- /src/Nats/Add/Comm.agda: -------------------------------------------------------------------------------- 1 | module Nats.Add.Comm where 2 | 3 | open import Equality 4 | open import Nats 5 | open import Function 6 | 7 | ------------------------------------------------------------------------ 8 | -- internal stuffs 9 | 10 | private 11 | 12 | a+0=0+a : ∀ a → a + 0 ≡ a 13 | a+0=0+a zero = refl 14 | a+0=0+a (suc a) = cong suc $ a+0=0+a a 15 | 16 | ++a+b=a+b++ : ∀ a b → suc (a + b) ≡ a + suc b 17 | ++a+b=a+b++ zero b = refl 18 | ++a+b=a+b++ (suc a) b = cong suc $ ++a+b=a+b++ a b 19 | 20 | a+b=b+a : ∀ a b → a + b ≡ b + a 21 | a+b=b+a zero b = sym (a+0=0+a b) 22 | a+b=b+a (suc a) b = suc (a + b) ≡⟨ cong suc (a+b=b+a a b) ⟩ ++a+b=a+b++ b a 23 | 24 | ------------------------------------------------------------------------ 25 | -- public aliases 26 | 27 | nat-add-comm : ∀ a b → a + b ≡ b + a 28 | nat-add-comm = a+b=b+a 29 | -------------------------------------------------------------------------------- /src/Nats/Add/Invert.agda: -------------------------------------------------------------------------------- 1 | module Nats.Add.Invert where 2 | 3 | open import Equality 4 | open import Nats 5 | open import Nats.Add.Comm 6 | open import Function 7 | 8 | ------------------------------------------------------------------------ 9 | -- internal stuffs 10 | 11 | private 12 | 13 | lemma′ : ∀ a b → (suc a ≡ suc b) → (a ≡ b) 14 | lemma′ _ _ refl = refl 15 | 16 | lemma : ∀ a b → (suc (a + suc a) ≡ suc (b + suc b)) → (a + a ≡ b + b) 17 | lemma a b 18 | rewrite nat-add-comm a $ suc a 19 | | nat-add-comm b $ suc b 20 | = lemma′ (a + a) (b + b) ∘ lemma′ (suc $ a + a) (suc $ b + b) 21 | 22 | +-invert : ∀ a b → (a + a ≡ b + b) → a ≡ b 23 | +-invert zero zero ev = refl 24 | +-invert zero (suc b) () 25 | +-invert (suc a) zero () 26 | +-invert (suc a) (suc b) = cong suc ∘ +-invert a b ∘ lemma a b 27 | 28 | ------------------------------------------------------------------------ 29 | -- public aliases 30 | 31 | nat-add-invert : ∀ a b → (a + a ≡ b + b) → a ≡ b 32 | nat-add-invert = +-invert 33 | 34 | nat-add-invert-1 : ∀ a b → (suc a ≡ suc b) → (a ≡ b) 35 | nat-add-invert-1 = lemma′ 36 | -------------------------------------------------------------------------------- /src/Nats/Multiply/Assoc.agda: -------------------------------------------------------------------------------- 1 | module Nats.Multiply.Assoc where 2 | 3 | open import Nats 4 | open import Equality 5 | open import Function 6 | 7 | open import Nats.Multiply.Comm 8 | open import Nats.Multiply.Distrib 9 | 10 | ------------------------------------------------------------------------ 11 | -- internal stuffs 12 | 13 | private 14 | 15 | a*1+b=a+a*b : ∀ a b → a * suc b ≡ a + a * b 16 | a*1+b=a+a*b a b 17 | rewrite nat-multiply-comm a $ suc b 18 | | nat-multiply-comm a b 19 | = refl 20 | 21 | a*/b*c/=/a*b/*c : ∀ a b c → a * b * c ≡ a * (b * c) 22 | a*/b*c/=/a*b/*c zero b c = refl 23 | a*/b*c/=/a*b/*c (suc a) b c 24 | rewrite a*/b*c/=/a*b/*c a b c 25 | | nat-multiply-comm a b 26 | | sym $ nat-multiply-distrib b (b * a) c 27 | | sym $ a*/b*c/=/a*b/*c a b c 28 | | nat-multiply-comm a b 29 | = refl 30 | 31 | ------------------------------------------------------------------------ 32 | -- public aliases 33 | 34 | nat-multiply-assoc : ∀ a b c → a * b * c ≡ a * (b * c) 35 | nat-multiply-assoc = a*/b*c/=/a*b/*c 36 | -------------------------------------------------------------------------------- /src/Nats/Multiply/Comm.agda: -------------------------------------------------------------------------------- 1 | module Nats.Multiply.Comm where 2 | 3 | open import Nats 4 | open import Equality 5 | open import Function 6 | 7 | open import Nats.Add.Comm 8 | open import Nats.Add.Assoc 9 | 10 | ------------------------------------------------------------------------ 11 | -- internal stuffs 12 | 13 | private 14 | 15 | a*0=0*a : ∀ a → a * 0 ≡ 0 16 | a*0=0*a zero = refl 17 | a*0=0*a (suc a) = a*0=0*a a 18 | 19 | a+a*b=a*++b : ∀ a b → a + a * b ≡ a * suc b 20 | a+a*b=a*++b zero _ = refl 21 | a+a*b=a*++b (suc a) b 22 | rewrite nat-add-comm b $ a * suc b 23 | | nat-add-comm b $ a * b 24 | | sym $ nat-add-assoc a (a * b) b 25 | | a+a*b=a*++b a b 26 | = refl 27 | 28 | a*b=b*a : ∀ a b → a * b ≡ b * a 29 | a*b=b*a zero b 30 | rewrite a*0=0*a b = refl 31 | a*b=b*a (suc a) b 32 | rewrite a*b=b*a a b 33 | | a+a*b=a*++b b a 34 | = refl 35 | 36 | ------------------------------------------------------------------------ 37 | -- public aliases 38 | 39 | nat-multiply-comm : ∀ a b → a * b ≡ b * a 40 | nat-multiply-comm = a*b=b*a 41 | -------------------------------------------------------------------------------- /src/Nats/Multiply/Distrib.agda: -------------------------------------------------------------------------------- 1 | module Nats.Multiply.Distrib where 2 | 3 | open import Nats 4 | open import Equality 5 | open import Function 6 | 7 | open import Nats.Multiply.Comm 8 | open import Nats.Add.Assoc 9 | open import Nats.Add.Comm 10 | 11 | ------------------------------------------------------------------------ 12 | -- internal stuffs 13 | 14 | private 15 | 16 | a*1+b=a+a*b : ∀ a b → a * suc b ≡ a + a * b 17 | a*1+b=a+a*b a b 18 | rewrite nat-multiply-comm a $ suc b 19 | | nat-multiply-comm a b 20 | = refl 21 | 22 | a*c+b*c=/a+b/*c : ∀ a b c → a * c + b * c ≡ (a + b) * c 23 | a*c+b*c=/a+b/*c a b zero 24 | rewrite nat-multiply-comm a 0 25 | | nat-multiply-comm b 0 26 | | nat-multiply-comm (a + b) 0 27 | = refl 28 | a*c+b*c=/a+b/*c a b sc@(suc c) 29 | rewrite nat-add-comm a b 30 | | a*1+b=a+a*b a c 31 | | nat-add-assoc a (a * c) (b * sc) 32 | | nat-add-comm a $ a * c + b * sc 33 | | a*1+b=a+a*b b c 34 | | nat-multiply-comm (b + a) sc 35 | | nat-add-assoc b a $ c * (b + a) 36 | | nat-add-comm a $ c * (b + a) 37 | | sym $ nat-add-assoc b (c * (b + a)) a 38 | | nat-multiply-comm c $ b + a 39 | | sym $ a*c+b*c=/a+b/*c b a c 40 | | sym $ nat-add-assoc (a * c) b (b * c) 41 | | nat-add-comm (b * c) (a * c) 42 | | sym $ nat-add-assoc b (b * c) (a * c) 43 | | sym $ nat-add-assoc b (a * c) (b * c) 44 | | nat-add-comm b $ a * c 45 | = refl 46 | 47 | ------------------------------------------------------------------------ 48 | -- public aliases 49 | 50 | nat-multiply-distrib : ∀ a b c → a * c + b * c ≡ (a + b) * c 51 | nat-multiply-distrib = a*c+b*c=/a+b/*c 52 | 53 | -------------------------------------------------------------------------------- /src/PosNat.agda: -------------------------------------------------------------------------------- 1 | module PosNat where 2 | 3 | open import Nats 4 | open import Data.Product 5 | open import Equality 6 | 7 | data ℕ⁺ : Set where 8 | psuc : ℕ → ℕ⁺ 9 | 10 | _→ℕ : ℕ⁺ → ℕ 11 | psuc zero →ℕ = suc zero 12 | psuc (suc x) →ℕ = suc (psuc x →ℕ) 13 | 14 | _⟨_⟩→ℕ⁺ : (a : ℕ) → ∃ (λ x → a ≡ suc x) → ℕ⁺ 15 | .(suc x) ⟨ x , refl ⟩→ℕ⁺ = psuc x 16 | -------------------------------------------------------------------------------- /src/Rationals.agda: -------------------------------------------------------------------------------- 1 | module Rationals where 2 | 3 | open import Nats renaming (_+_ to _:+:_; _*_ to _:*:_) 4 | open import Equality 5 | open import Data.Product 6 | open import Agda.Builtin.TrustMe 7 | 8 | infixl 7 _÷_ 9 | infixr 5 _→ℕ 10 | infixr 7 _÷_↓_ 11 | infixr 7 _÷_↑_ 12 | infixl 6 _+_ 13 | 14 | data ℚ : Set where 15 | _÷_ : (a b : ℕ) → ℚ 16 | 17 | _→ℕ : {a : ℕ} → ℚ → ∃ (λ m → m ≡ a) 18 | _→ℕ {a} _ = a , refl 19 | 20 | -- of course. 21 | _÷_↓_ : ∀ a b n → (a :*: n ÷ (b :*: n)) ≡ a ÷ b 22 | _ ÷ _ ↓ _ = primTrustMe 23 | 24 | _÷_↑_ : ∀ a b n → a ÷ b ≡ (a :*: n ÷ (b :*: n)) 25 | a ÷ b ↑ n = sym (a ÷ b ↓ n) 26 | 27 | _+_ : ℚ → ℚ → ℚ 28 | a ÷ c + b ÷ d = (a :*: d :+: b :*: c) ÷ (c :*: d) 29 | 30 | _*_ : ℚ → ℚ → ℚ 31 | (a ÷ c) * (b ÷ d) = a :*: b ÷ (c :*: d) 32 | 33 | _/_ : ℚ → ℚ → ℚ 34 | (a ÷ c) / (b ÷ d) = a :*: d ÷ (c :*: b) 35 | -------------------------------------------------------------------------------- /src/Rationals/Add/Assoc.agda: -------------------------------------------------------------------------------- 1 | module Rationals.Add.Assoc where 2 | 3 | open import Equality 4 | open import Function 5 | 6 | open import Nats using (zero; ℕ) 7 | renaming (suc to s; _+_ to _:+:_; _*_ to _:*:_) 8 | open import Rationals 9 | open import Rationals.Properties 10 | open import Nats.Add.Comm 11 | open import Nats.Add.Assoc 12 | open import Nats.Multiply.Distrib 13 | open import Nats.Multiply.Assoc 14 | open import Nats.Multiply.Comm 15 | 16 | ------------------------------------------------------------------------ 17 | -- internal stuffs 18 | 19 | private 20 | 21 | a+b+c=a+/b+c/ : ∀ a b c → a + (b + c) ≡ (a + b) + c 22 | a+b+c=a+/b+c/ (ax ÷ ay) (bx ÷ by) (cx ÷ cy) 23 | rewrite ax ÷ ay ↑ (by :*: cy) 24 | | bx ÷ by ↑ (ay :*: cy) 25 | | cx ÷ cy ↑ (ay :*: by) 26 | | nat-multiply-assoc ay by cy 27 | | sym $ nat-multiply-distrib (bx :*: cy) (cx :*: by) ay 28 | | sym $ nat-multiply-distrib (ax :*: by) (bx :*: ay) cy 29 | | sym $ nat-add-assoc (ax :*: (by :*: cy)) 30 | (bx :*: cy :*: ay) (cx :*: by :*: ay) 31 | | nat-multiply-assoc ax by cy 32 | | nat-multiply-comm ay by 33 | | nat-multiply-assoc cx by ay 34 | | nat-multiply-assoc bx cy ay 35 | | nat-multiply-assoc bx ay cy 36 | | nat-multiply-comm cy ay 37 | = refl 38 | 39 | rational-add-assoc : ∀ a b c → a + (b + c) ≡ (a + b) + c 40 | rational-add-assoc = a+b+c=a+/b+c/ 41 | -------------------------------------------------------------------------------- /src/Rationals/Add/Comm.agda: -------------------------------------------------------------------------------- 1 | module Rationals.Add.Comm where 2 | 3 | open import Equality 4 | open import Function 5 | 6 | open import Nats using (zero; ℕ) 7 | renaming (suc to s; _+_ to _:+:_; _*_ to _:*:_) 8 | open import Rationals 9 | open import Rationals.Properties 10 | open import Nats.Add.Comm 11 | open import Nats.Multiply.Distrib 12 | open import Nats.Multiply.Comm 13 | 14 | ------------------------------------------------------------------------ 15 | -- internal stuffs 16 | 17 | private 18 | 19 | a/c+b/c=a*b/c : ∀ a b c → a ÷ c + b ÷ c ≡ (a :+: b) ÷ c 20 | a/c+b/c=a*b/c a b c 21 | rewrite (a :+: b) ÷ c ↑ c 22 | | sym $ nat-multiply-distrib a b c 23 | = refl 24 | 25 | a+b=b+a : ∀ x y → x + y ≡ y + x 26 | a+b=b+a (a ÷ c) (b ÷ d) 27 | rewrite a ÷ c ↑ d 28 | | b ÷ d ↑ c 29 | | a/c+b/c=a*b/c (a :*: d) (b :*: c) $ d :*: c 30 | | nat-add-comm (a :*: d) $ b :*: c 31 | | nat-multiply-comm c d 32 | = refl 33 | 34 | ------------------------------------------------------------------------ 35 | -- public aliases 36 | 37 | rational-add-comm : ∀ x y → x + y ≡ y + x 38 | rational-add-comm = a+b=b+a 39 | -------------------------------------------------------------------------------- /src/Rationals/Multiply/Comm.agda: -------------------------------------------------------------------------------- 1 | module Rationals.Multiply.Comm where 2 | 3 | open import Equality 4 | open import Rationals 5 | open import Nats.Multiply.Comm 6 | 7 | ------------------------------------------------------------------------ 8 | -- internal stuffs 9 | 10 | private 11 | 12 | a*b=b*a : ∀ x y → x * y ≡ y * x 13 | a*b=b*a (a ÷ c) (b ÷ d) 14 | rewrite nat-multiply-comm a b 15 | | nat-multiply-comm c d 16 | = refl 17 | 18 | ------------------------------------------------------------------------ 19 | -- public aliases 20 | 21 | rational-multiply-comm : ∀ x y → x * y ≡ y * x 22 | rational-multiply-comm = a*b=b*a 23 | -------------------------------------------------------------------------------- /src/Rationals/Properties.agda: -------------------------------------------------------------------------------- 1 | module Rationals.Properties where 2 | 3 | open import Nats renaming (_*_ to _:*:_) 4 | open import Rationals 5 | open import Data.Empty 6 | open import Data.Product 7 | open import Equality 8 | 9 | ------------------------------------------------------------------------ 10 | -- internal stuffs 11 | 12 | private 13 | 14 | a*b÷b=a : ∀ a b → a :*: b ÷ b →ℕ ≡ (a , refl) 15 | a*b÷b=a _ _ = refl 16 | 17 | ------------------------------------------------------------------------ 18 | -- public aliases 19 | 20 | times-div-id : ∀ a b → a :*: b ÷ b →ℕ ≡ (a , refl) 21 | times-div-id = a*b÷b=a 22 | -------------------------------------------------------------------------------- /src/Trees.agda: -------------------------------------------------------------------------------- 1 | module Trees where 2 | 3 | open import Data.Unit using (⊤) 4 | 5 | data BinTree {a} (A : Set a) : Set a where 6 | Empty : A → BinTree A 7 | Node : A → BinTree A → BinTree A → BinTree A 8 | 9 | BareBinTree : Set 10 | BareBinTree = BinTree ⊤ 11 | 12 | -------------------------------------------------------------------------------- /src/Tuples.agda: -------------------------------------------------------------------------------- 1 | module Tuples where 2 | 3 | open import Data.Product 4 | 5 | _² : ∀ {a} (A : Set a) → Set a 6 | A ² = A × A 7 | 8 | _³ : ∀ {a} (A : Set a) → Set a 9 | A ³ = A × A ² 10 | 11 | _⁴ : ∀ {a} (A : Set a) → Set a 12 | A ⁴ = A × A ³ 13 | 14 | _⁵ : ∀ {a} (A : Set a) → Set a 15 | A ⁵ = A × A ⁴ 16 | 17 | _⁶ : ∀ {a} (A : Set a) → Set a 18 | A ⁶ = A × A ⁵ 19 | 20 | _⁷ : ∀ {a} (A : Set a) → Set a 21 | A ⁷ = A × A ⁶ 22 | 23 | -------------------------------------------------------------------------------- /src/Vecs.agda: -------------------------------------------------------------------------------- 1 | module Vecs where 2 | 3 | open import Nats 4 | 5 | infixr 5 _∷_ _++_ _∷ʳ_ 6 | infix 4 _∈_ _⊛_ 7 | 8 | data Vec {a} (A : Set a) : ℕ → Set a where 9 | [] : Vec A zero 10 | _∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n) 11 | 12 | data _∈_ {a} {A : Set a} : A → {n : ℕ} → Vec A n → Set a where 13 | here : ∀ {n} {x} {xs : Vec A n} → x ∈ x ∷ xs 14 | there : ∀ {n} {x y} {xs : Vec A n} (x∈xs : x ∈ xs) → x ∈ y ∷ xs 15 | 16 | head : ∀ {a n} {A : Set a} → Vec A (suc n) → A 17 | head (x ∷ xs) = x 18 | 19 | tail : ∀ {a n} {A : Set a} → Vec A (suc n) → Vec A n 20 | tail (x ∷ xs) = xs 21 | 22 | [_] : ∀ {a} {A : Set a} → A → Vec A 1 23 | [ x ] = x ∷ [] 24 | 25 | _++_ : ∀ {a m n} {A : Set a} → Vec A m → Vec A n → Vec A (m + n) 26 | [] ++ ys = ys 27 | (x ∷ xs) ++ ys = x ∷ (xs ++ ys) 28 | 29 | _⊛_ : ∀ {a b n} {A : Set a} {B : Set b} → 30 | Vec (A → B) n → Vec A n → Vec B n 31 | [] ⊛ _ = [] 32 | (f ∷ fs) ⊛ (x ∷ xs) = f x ∷ (fs ⊛ xs) 33 | 34 | replicate : ∀ {a n} {A : Set a} → A → Vec A n 35 | replicate {n = zero} x = [] 36 | replicate {n = suc n} x = x ∷ replicate x 37 | 38 | _∷ʳ_ : ∀ {a n} {A : Set a} → Vec A n → A → Vec A (suc n) 39 | [] ∷ʳ y = [ y ] 40 | (x ∷ xs) ∷ʳ y = x ∷ (xs ∷ʳ y) 41 | 42 | reverse : ∀ {n m} {A : Set n} → Vec A m → Vec A m 43 | reverse [] = [] 44 | reverse (x ∷ xs) = reverse xs ∷ʳ x 45 | -------------------------------------------------------------------------------- /src/Vecs/Reverse.agda: -------------------------------------------------------------------------------- 1 | module Vecs.Reverse where 2 | 3 | open import Vecs 4 | open import Nats 5 | open import Equality 6 | open import Function 7 | 8 | ------------------------------------------------------------------------ 9 | -- internal stuffs 10 | 11 | private 12 | 13 | -- rev$v:a=a:rev$v : ∀ {n m} {A : Set n} (a : A) (v : Vec A m) → 14 | -- rev (v ∷ʳ a) ≡ a ∷ rev v 15 | -- rev$v:a=a:rev$v _ [] = refl 16 | -- rev$v:a=a:rev$v a (_ ∷ xs) with rev (xs ∷ʳ a) | rev$v:a=a:rev$v a xs 17 | -- ... | .(a ∷ rev xs) | refl = refl 18 | 19 | rev$v:a=a:rev$v : ∀ {n m} {A : Set n} (a : A) (v : Vec A m) → 20 | reverse (v ∷ʳ a) ≡ a ∷ reverse v 21 | rev$v:a=a:rev$v _ [] = refl 22 | rev$v:a=a:rev$v a (_ ∷ xs) 23 | rewrite rev$v:a=a:rev$v a xs 24 | = refl 25 | 26 | rev∘rev=id : ∀ {n m} {A : Set n} (v : Vec A m) → reverse (reverse v) ≡ v 27 | rev∘rev=id [] = refl 28 | rev∘rev=id (x ∷ xs) 29 | rewrite rev$v:a=a:rev$v x $ reverse xs 30 | | rev∘rev=id xs 31 | = refl 32 | 33 | ------------------------------------------------------------------------ 34 | -- public aliases 35 | 36 | vec-rev-rev-id : ∀ {n m} {A : Set n} (v : Vec A m) → reverse (reverse v) ≡ v 37 | vec-rev-rev-id = rev∘rev=id 38 | -------------------------------------------------------------------------------- /src/index.agda: -------------------------------------------------------------------------------- 1 | module index where 2 | 3 | -- natural numbers 4 | --- additions 5 | import Nats.Add.Assoc 6 | using (nat-add-assoc) -- associative law 7 | import Nats.Add.Comm 8 | using (nat-add-comm) -- commutative law 9 | import Nats.Add.Invert 10 | using (nat-add-invert) -- a + a == b + b implies a == b 11 | using (nat-add-invert-1) -- a + 1 == b + 1 implies a == b 12 | 13 | --- multiplications 14 | import Nats.Multiply.Comm 15 | using (nat-multiply-comm) -- commutative law 16 | import Nats.Multiply.Distrib 17 | using (nat-multiply-distrib) -- distributive law 18 | import Nats.Multiply.Assoc 19 | using (nat-multiply-assoc) -- associative law 20 | 21 | -- integers 22 | --- some properties 23 | import Ints.Properties 24 | using (eq-int-to-nat) -- for natrual number a, + a == + a implis a == a 25 | using (eq-neg-int-to-nat) -- for natrual number a, - a == - a implis a == a 26 | using (eq-nat-to-int) -- for natrual number a, a == a implis + a == + a 27 | using (eq-neg-nat-to-int) -- for natrual number a, a == a implis - a == - a 28 | 29 | --- additions 30 | import Ints.Add.Comm 31 | using (int-add-comm) -- commutative law 32 | import Ints.Add.Assoc 33 | using (int-add-assoc) -- associative law 34 | import Ints.Add.Invert 35 | using (int-add-invert) -- a + a == b + b implis a == b 36 | 37 | -- non-negative rationals 38 | --- some properties 39 | import Rationals.Properties 40 | -- if b is not zero, n times b div b is the original number 41 | using (times-div-id) 42 | 43 | -- additions 44 | import Rationals.Add.Comm 45 | using (rational-add-comm) -- commutative law 46 | import Rationals.Add.Assoc 47 | using (rational-add-assoc) -- associative law 48 | 49 | -- multiplications 50 | import Rationals.Multiply.Comm 51 | using (rational-multiply-comm) -- commutative law 52 | 53 | -- logics 54 | --- the "and" relations 55 | import Logics.And 56 | using (and-comm) -- commutative law 57 | using (and-assoc) -- associative law 58 | 59 | --- the "or" relations 60 | import Logics.Or 61 | using (or-comm) -- commutative law 62 | using (or-assoc) -- associative law 63 | using (or-elim) -- elimination rule 64 | 65 | --- negations 66 | import Logics.Not 67 | -- law that negative twice will make a positive 68 | using (not-not) 69 | using (contrapositive) -- contrapositive 70 | 71 | -- vectors 72 | --- reverse twice gives the original vector 73 | import Vecs.Reverse 74 | using (vec-rev-rev-id) 75 | 76 | -- lists 77 | --- reverse twice gives the original vector 78 | import Lists.Reverse 79 | using (list-rev-rev-id) 80 | 81 | -- isomorphisms 82 | --- natrual numbers and others 83 | import Isos.NatLike 84 | using (iso-nat-vec) -- with vector 85 | using (iso-nat-list) -- with list 86 | 87 | --- trees 88 | import Isos.TreeLike 89 | using (iso-seven-tree-in-one) -- seven trees in one 90 | 91 | -- groups 92 | --- s3 group, xxx=e, yy=e, yx=xxy 93 | import Groups.Symm.S3 94 | using (s3-property-1) -- given s3, prove xyx≡y 95 | -------------------------------------------------------------------------------- /theorems.agda-lib: -------------------------------------------------------------------------------- 1 | name: theorems 2 | depend: standard-library 3 | include: src 4 | --------------------------------------------------------------------------------