Skip to content

Commit 41cc40e

Browse files
committed
Changes for the presentation
1 parent 09258e6 commit 41cc40e

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

Physics/src/NewtonianMechanics/SingleParticle.lhs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
> module NewtonianMechanics.SingleParticle where
22

3-
%< import Calculus.SyntaxTree
4-
53
> import Test.QuickCheck
64

75
Laws:
@@ -20,8 +18,8 @@ mathmatical functions in previous chapters we won't spend any time on them here
2018
and instead just import those two modules.
2119

2220
> import Calculus.FunExpr
23-
> import Calculus.DifferentialCalc -- Maybe remove
24-
> import Calculus.IntegralCalc -- Maybe remove
21+
> import Calculus.DifferentialCalc
22+
> import Calculus.IntegralCalc
2523
> import Vector.Vector as V
2624

2725
The mass of a particle is just a scalar value so we'll model it using
@@ -35,11 +33,13 @@ type `VectorE` to signify that it's a vector of expressions.
3533

3634
> type VectorE = Vector3 FunExpr
3735

36+
> type Position = Vector3 FunExpr
37+
3838
Now we are ready to define what the data type for a particle is. As we
39-
previously stated a point particle has a mass, and a position given as a vector
40-
of function expressions. So our data type is simply:
39+
previously stated a point particle has a position given as a vector
40+
of function expressions, and a mass. So our data type is simply:
4141

42-
> data Particle = P { pos :: VectorE -- Position as a function of time, unit m
42+
> data Particle = P { pos :: Position -- Position as a function of time, unit m
4343
> , mass :: Mass -- Mass, unit kg
4444
> } deriving Show
4545

@@ -282,17 +282,14 @@ equal to the change in kinetic energy $E_k$ of the particle:
282282

283283
Let's codify this theorem:
284284

285-
PS: This used to work just fine, but it no longer does since the switch to
286-
FunExpr. Problem probably lies somewhere in SyntaxTree
287-
288-
< prop_WorkEnergyTheorem :: Mass -> VectorE -> VectorE -> IO Bool
289-
< prop_WorkEnergyTheorem m v1 v2 = prettyEqual deltaEnergy (kineticEnergy displacedParticle)
290-
< where
291-
< particle1 = P v1 m -- | Two particles with the same mass
292-
< particle2 = P v2 m -- | But different position vector
293-
< -- | E_k,2 - E_k,1
294-
< deltaEnergy = kineticEnergy particle2 - kineticEnergy particle1
295-
< displacedParticle = P (v2 - v1) m
285+
> prop_WorkEnergyTheorem :: Mass -> Position -> Position -> Bool
286+
> prop_WorkEnergyTheorem m p1 p2 = deltaEnergy == kineticEnergy displacedParticle
287+
> where
288+
> particle1 = P p1 m -- | Two particles with the same mass
289+
> particle2 = P p2 m -- | But different position vector
290+
> -- | E_k,2 - E_k,1
291+
> deltaEnergy = kineticEnergy particle2 - kineticEnergy particle1
292+
> displacedParticle = P (p2 - p1) m
296293

297294
< -- Test values
298295
< v1 = V3 (3 :* Id) (2 :* Id) (1 :* Id)

Physics/src/Vector/Vector.lhs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ hopefully understand where I'm going when reading the examples.
275275
Using this information we can now create a new class for vectors which
276276
implement this functionality:
277277
278-
> class Vector vector where
279-
> vmap :: (num -> num) -> vector num -> vector num
280-
> vzipWith :: (num -> num -> num) -> vector num -> vector num -> vector num
281-
> vfold :: (num -> num -> num) -> vector num -> num
278+
> class Vector vec where
279+
> vmap :: (num -> num) -> vec num -> vec num
280+
> vzipWith :: (num -> num -> num) -> vec num -> vec num -> vec num
281+
> vfold :: (num -> num -> num) -> vec num -> num
282282
283283
Now we have a blueprint for what vector is, so let's implement it for our own
284284
vector datatypes.

0 commit comments

Comments
 (0)