|
108 | 108 |
|
109 | 109 | * Simple Logic Excercises (but not predicate logic) (prove)
|
110 | 110 | #+BEGIN_SRC scala
|
| 111 | + |
| 112 | + type And[A, B] = (A, B) |
| 113 | + type Or[A, B] = Either[A, B] |
111 | 114 | type /\[A, B] = (A, B)
|
112 | 115 | type \/[A, B] = Either[A, B]
|
113 | 116 | // type =>[A, B] = A => B
|
114 |
| - type <==>[A, B] = A => B /\ B => A |
| 117 | + type <==>[A, B] = (A => B) /\ (B => A) |
115 | 118 | // What could go wrong here?!
|
116 | 119 | type Not[A] = A => Nothing
|
117 | 120 |
|
118 | 121 | // Corrolaries / Universal Constructions
|
119 |
| - def and_1[A, B](n: A /\ B): A = ??? |
120 |
| - def and_2[A, B](n: A /\ B): B = ??? |
121 |
| - def or_1[A, B](a: A): A \/ B = ??? |
122 |
| - def or_2[A, B](b: B): A \/ B = ??? |
123 |
| - def mp[A, B](a: A, f: A => B): B = ??? |
124 |
| - def exp[A, B, C](a: A, g: (A /\ B) => C): B => C = ??? |
125 |
| - def bicond_1[A, B](f: A <==> B): A => B = ??? |
126 |
| - def bicond_2[A, B](f: A <==> B): B => A = ??? |
127 |
| - |
128 |
| - def ex_falso_1[A](n: Nothing): A = ??? |
129 |
| - def ex_falso_2[A](n: Nothing): Not[A] = ??? |
130 |
| - def dist_law[A, B, C](h: A \/ (B \/ C)) = (A \/ B) \/ (A \/ C) = ??? |
131 |
| - def shunting[A, B, C](n: A /\ B => C) = A => B => C = ??? |
| 122 | + def and_1[A, B](n: A /\ B): A = n._1 |
| 123 | + def and_2[A, B](n: A /\ B): B = n._2 |
| 124 | + def or_1[A, B](a: A): A \/ B = Left(a) |
| 125 | + def or_2[A, B](b: B): A \/ B = Right(b) |
| 126 | + def mp[A, B](a: A, f: A => B): B = f(a) |
| 127 | + def exp[A, B, C](a: A, g: (A /\ B) => C): B => C = b => g(a, b) |
| 128 | + def bicond_1[A, B](f: A <==> B): A => B = f._1 |
| 129 | + def bicond_2[A, B](f: A <==> B): B => A = f._2 |
| 130 | + |
| 131 | + def dist_law[A, B, C](h: A \/ (B /\ C)): (A /\ B) \/ (A /\ C) = ??? |
| 132 | + |
| 133 | + def dist_law_2[A, B, C](h: A Or (B And C)): (A Or B) And (A Or C) = |
| 134 | + h |
| 135 | + |
| 136 | + def dist_law_1[A, B, C](h: A And (B Or C)): (A Or B) And (A Or C) = |
| 137 | + ((), ()) |
| 138 | + |
| 139 | + def shunting[A, B, C](n: A /\ B => C): A => B => C = ??? |
| 140 | + |
| 141 | + def ex_falso_1[A](n: Nothing): A = n |
| 142 | + def ex_falso_2[A](n: Nothing): Not[A] = (a) => n |
| 143 | + |
132 | 144 | #+END_SRC
|
133 | 145 |
|
134 | 146 | * Quantifying (ways of leaving the zeroth order logic)
|
|
195 | 207 | 2. Come up with some functions that interact with this domain.
|
196 | 208 | 2.1. Let's calculate the possible number of pure total functions that exist for those function types.
|
197 | 209 | 2.2. Let's think of some propositions.
|
198 |
| - |
| 210 | + |
199 | 211 | ** Possible suggestion: ATM (Automatic Teller Machine)
|
200 | 212 |
|
201 | 213 | 1. Person's Account Balance.
|
202 | 214 | 1. Person's Name, Email and Details.
|
203 | 215 | 1. Transactions between people.
|
204 | 216 | 1. New type of account: Legal Business.
|
205 | 217 | 1. Add minimum transaction ammount and different fee for person and business.
|
206 |
| - |
207 |
| - |
| 218 | + |
| 219 | + |
208 | 220 |
|
209 | 221 | * Extras
|
210 | 222 | ** Optics
|
211 | 223 | *** Did we write any optics?
|
212 |
| - 1. Let's write a library, for what we have written already. This type of code is called Optics. |
213 |
| - |
| 224 | + 1. Let's write a library, for what we have written already. This type of code is called Optics. |
| 225 | + |
214 | 226 | ** Exponent laws, Logic and Cats
|
215 | 227 | [[https://ncatlab.org/nlab/show/relation+between+type+theory+and+category+theory][https://ncatlab.org/nlab/show/relation+between+type+theory+and+category+theory]]
|
216 | 228 | [[https://www.infoq.com/presentations/category-theory-propositions-principle]]
|
|
0 commit comments