You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This limit can be proven using the [unit circle](https://en.wikipedia.org/wiki/Unit_circle) and [squeeze theorem](https://en.wikipedia.org/wiki/Squeeze_theorem)
318
+
319
+
</div>
320
+
</details>
311
321
312
322
Then, the differentiation
313
323
@@ -328,7 +338,11 @@ Again, trivial definition in Haskell
328
338
329
339
> derive Sin=Cos
330
340
331
-
I'll leave the proving of the rest of the implementations as an exercise to you, the reader.
341
+
**Exercise.** Derive the rest of the cases using the definition of the derivative
342
+
343
+
<details>
344
+
<summary>**Solution**</summary>
345
+
<div>
332
346
333
347
> derive Exp=Exp
334
348
> derive Log=Const1:/Id
@@ -338,7 +352,8 @@ I'll leave the proving of the rest of the implementations as an exercise to you,
338
352
> derive (f :- g) = derive f :- derive g
339
353
> derive (f :* g) = derive f :* g :+ f :* derive g
340
354
> derive (f :/ g) = (derive f :* g :- f :* derive g) :/ (g:^(Const2))
Copy file name to clipboardExpand all lines: Physics/src/Dimensions/Quantity.lhs
+50-8Lines changed: 50 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -106,11 +106,16 @@ Note that the `Quantity` data type has both value-level and type-level dimension
106
106
107
107
TODO: What is the purpose (semantics, intended meaning or use) of Quantity'?
108
108
109
-
**Solution.**
109
+
<details>
110
+
<summary>**Solution**</summary>
111
+
<div>
110
112
111
113
< dataQuantity' (d1::T.Dim) (d2::T.Dim) where
112
114
< Quantity'::Rational->Rational->Quantity'd1d2
113
115
116
+
</div>
117
+
</details>
118
+
114
119
A taste of types
115
120
----------------
116
121
@@ -141,7 +146,14 @@ The type has the following interpretation: two values of type `Quantity dx v` is
141
146
142
147
{.float-img-right}
143
148
144
-
**Solution.** Hold on cowboy! Not so fast. We'll come back later to subtraction and division, so check your solution then.
149
+
<details>
150
+
<summary>**Solution**</summary>
151
+
<div>
152
+
153
+
Hold on cowboy! Not so fast. We'll come back later to subtraction and division, so check your solution then.
154
+
155
+
</div>
156
+
</details>
145
157
146
158
Now on to some example values and types.
147
159
@@ -188,7 +200,9 @@ If the dimensions had been value-level only, this error would go undetected unti
188
200
189
201
**Exercise.** What is the volume of a cuboid with sides $1.2\ m$, $0.4\ m$ and $1.9\ m$? Create values for the involved quantities. Use `Float` instead of `Double`.
190
202
191
-
**Solution.**
203
+
<details>
204
+
<summary>**Solution**</summary>
205
+
<div>
192
206
193
207
> side1::QuantityLengthFloat
194
208
> side1 =QuantityV.length1.2
@@ -204,6 +218,9 @@ If the dimensions had been value-level only, this error would go undetected unti
@@ -228,7 +245,9 @@ It's useful to be able to compare quantities. Perhaps one wants to know which of
228
245
229
246
**Exercise.** Make `Quantity` an instance of `Ord`.
230
247
231
-
**Solution.**
248
+
<details>
249
+
<summary>**Solution**</summary>
250
+
<div>
232
251
233
252
> quantityCompare:: (Ordv) =>Quantitydv->
234
253
>Quantitydv->Ordering
@@ -238,6 +257,9 @@ It's useful to be able to compare quantities. Perhaps one wants to know which of
238
257
> instance (Ordv) =>Ord (Quantitydv) where
239
258
>compare= quantityCompare
240
259
260
+
</div>
261
+
</details>
262
+
241
263
We often use `Double` as the value holding type. Doing exact comparsions isn't always possible to due rounding errors. Therefore, we'll create a `~=` function for testing if two quantities are almost equal.
242
264
243
265
>infixl4~=
@@ -326,7 +348,9 @@ However, operations with only scalars (type `One`) has types compatible with `Nu
326
348
327
349
**Exercise.** `Quantity One` has compatible types. Make it an instance of `Num`, `Fractional`, `Floating` and `Functor`.
328
350
329
-
**Solution.**
351
+
<details>
352
+
<summary>**Solution**</summary>
353
+
<div>
330
354
331
355
> instance (Numv) =>Num (QuantityOnev) where
332
356
>(+)=(+#)
@@ -358,6 +382,9 @@ However, operations with only scalars (type `One`) has types compatible with `Nu
358
382
> instanceFunctor (QuantityOne) where
359
383
>fmap= qmap
360
384
385
+
</div>
386
+
</details>
387
+
361
388
Syntactic sugar
362
389
---------------
363
390
@@ -388,7 +415,9 @@ TODO: Please use "1" instead of "0" in all the dimensions. That signifies an amo
388
415
389
416
**Exercise.** Do the rest.
390
417
391
-
**Solution.**
418
+
<details>
419
+
<summary>**Solution**</summary>
420
+
<div>
392
421
393
422
> current:: (Numv) =>QuantityCurrentv
394
423
> current =QuantityV.current 0
@@ -405,6 +434,9 @@ TODO: Please use "1" instead of "0" in all the dimensions. That signifies an amo
405
434
> one:: (Numv) =>QuantityOnev
406
435
> one =QuantityV.one 0
407
436
437
+
</div>
438
+
</details>
439
+
408
440
And now the sugar.
409
441
410
442
TODO: Please multiply the values instead of throwing them away. I'm pretty sure (#) should behave as "scale" of a vector space. So that (x#(y#z)) == ((x*y)#z).
@@ -460,14 +492,19 @@ Just for convenience sake we'll define a bunch of common composite dimensions. E
460
492
461
493
**Exericse.** Define pre-made values for velocity, acceleration, force, momentum and energy.
462
494
463
-
**Solution.**
495
+
<details>
496
+
<summary>**Solution**</summary>
497
+
<div>
464
498
465
499
> velocity =length/# time
466
500
> acceleration = velocity /# time
467
501
> force = mass *# acceleration
468
502
> momentum = force *# time
469
503
> energy = force *#length
470
504
505
+
</div>
506
+
</details>
507
+
471
508
---
472
509
473
510
Alternative sugar with support for units
@@ -481,7 +518,9 @@ Alternative sugar with support for units
481
518
< ghci> distance
482
519
<8046.72 m
483
520
484
-
**Solution.**
521
+
<details>
522
+
<summary>**Solution**</summary>
523
+
<div>
485
524
486
525
> metre =1#length
487
526
> kilometre =1000#length
@@ -504,6 +543,9 @@ Notice how the value is multiplied with the "base value" of the unit. This funct
0 commit comments