Acknowledgments |
|
xxiii | |
Introduction |
|
xxv | |
Who This Book Is For |
|
xxvi | |
Why Functional Programming, and Why Haskell? |
|
xxvi | |
About This Book |
|
xxvii | |
|
PART I A HASKELL PRIMER FOR PHYSICISTS |
|
|
|
1 Calculating With Haskell |
|
|
3 | (12) |
|
|
3 | (1) |
|
|
4 | (1) |
|
|
4 | (2) |
|
|
6 | (3) |
|
Precedence and Associativity |
|
|
7 | (2) |
|
|
9 | (1) |
|
Functions with Two Arguments |
|
|
9 | (1) |
|
|
10 | (1) |
|
Negative Numbers in Haskell |
|
|
10 | (1) |
|
Decimal Numbers in Haskell |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
12 | (1) |
|
Getting Help and Quitting |
|
|
13 | (1) |
|
|
13 | (1) |
|
|
13 | (1) |
|
|
14 | (1) |
|
2 Writing Basic Functions |
|
|
15 | (10) |
|
Constants, Functions, and Types |
|
|
16 | (3) |
|
How We Talk About Functions |
|
|
19 | (1) |
|
|
20 | (1) |
|
|
21 | (1) |
|
Variable Not in Scope Error |
|
|
22 | (1) |
|
|
23 | (1) |
|
|
23 | (2) |
|
|
25 | (10) |
|
|
25 | (5) |
|
|
26 | (2) |
|
|
28 | (1) |
|
|
28 | (1) |
|
|
29 | (1) |
|
|
30 | (2) |
|
|
32 | (1) |
|
|
32 | (3) |
|
|
35 | (16) |
|
Position and Velocity on an Air Track |
|
|
35 | (2) |
|
Types for Physical Quantities |
|
|
37 | (1) |
|
|
38 | (2) |
|
|
40 | (1) |
|
Modeling the Car's Position and Velocity |
|
|
41 | (3) |
|
|
44 | (1) |
|
Approximate Algorithms and Finite Precision |
|
|
45 | (2) |
|
|
47 | (1) |
|
|
47 | (4) |
|
|
51 | (18) |
|
|
52 | (4) |
|
Selecting an Element from a List |
|
|
52 | (1) |
|
|
53 | (1) |
|
|
54 | (1) |
|
|
55 | (1) |
|
Functions for Lists of Numbers |
|
|
55 | (1) |
|
|
56 | (1) |
|
|
56 | (1) |
|
|
57 | (1) |
|
|
58 | (1) |
|
A String Is a List of Characters |
|
|
59 | (1) |
|
|
60 | (1) |
|
|
61 | (1) |
|
List Constructors and Pattern Matching |
|
|
62 | (2) |
|
|
64 | (1) |
|
|
64 | (5) |
|
|
69 | (22) |
|
How to Think About Functions with Parameters |
|
|
70 | (3) |
|
Mapping a Function Over a List |
|
|
73 | (1) |
|
|
74 | (2) |
|
Anonymous Higher-Order Functions |
|
|
76 | (1) |
|
Operators as Higher-Order Functions |
|
|
77 | (1) |
|
|
78 | (1) |
|
Predicate-Based Higher-Order Functions |
|
|
79 | (2) |
|
|
81 | (6) |
|
|
81 | (1) |
|
|
82 | (3) |
|
Implementing Antiderivatives |
|
|
85 | (2) |
|
|
87 | (1) |
|
|
88 | (3) |
|
|
91 | (6) |
|
|
91 | (2) |
|
|
91 | (1) |
|
|
92 | (1) |
|
|
93 | (2) |
|
|
93 | (1) |
|
|
94 | (1) |
|
Function, Module, and Plot Definition |
|
|
94 | (1) |
|
|
95 | (1) |
|
|
95 | (2) |
|
|
97 | (16) |
|
|
98 | (1) |
|
Type Classes from the Prelude |
|
|
99 | (5) |
|
|
99 | (1) |
|
|
100 | (1) |
|
|
101 | (1) |
|
|
102 | (1) |
|
|
102 | (1) |
|
The Fractional Type Class |
|
|
103 | (1) |
|
|
104 | (1) |
|
Exponentiation and Type Classes |
|
|
104 | (1) |
|
|
105 | (1) |
|
Example of Type Classes and Plotting |
|
|
106 | (3) |
|
|
109 | (1) |
|
|
109 | (4) |
|
9 Tuples and Type Constructors |
|
|
113 | (16) |
|
|
113 | (2) |
|
Currying a Function of Two Variables |
|
|
115 | (1) |
|
|
116 | (1) |
|
Comparing Lists and Tuples |
|
|
117 | (1) |
|
|
117 | (2) |
|
|
119 | (1) |
|
Tuples and List Comprehensions |
|
|
120 | (1) |
|
Type Constructors and Kinds |
|
|
121 | (3) |
|
Numerical Integration Redux |
|
|
124 | (1) |
|
|
125 | (1) |
|
|
125 | (4) |
|
10 Describing Motion In Three Dimensions |
|
|
129 | (36) |
|
Three-Dimensional Vectors |
|
|
129 | (7) |
|
|
131 | (1) |
|
Geometric Definition of Vector Addition |
|
|
131 | (1) |
|
Geometric Definition of Scaling a Vector |
|
|
132 | (1) |
|
Geometric Definition of Vector Subtraction |
|
|
133 | (1) |
|
Geometric Definition of Dot Product |
|
|
134 | (1) |
|
Geometric Definition of Cross Product |
|
|
134 | (1) |
|
Derivative of a Vector-Valued Function |
|
|
135 | (1) |
|
|
136 | (6) |
|
Vector Addition with Coordinate Components |
|
|
138 | (1) |
|
Vector Scaling with Coordinate Components |
|
|
139 | (1) |
|
Vector Subtraction with Coordinate Components |
|
|
139 | (1) |
|
Dot Product with Coordinate Components |
|
|
140 | (1) |
|
Cross Product with Coordinate Components |
|
|
140 | (1) |
|
Derivative with Coordinate Components |
|
|
140 | (2) |
|
|
142 | (8) |
|
Defining Position, Velocity, and Acceleration |
|
|
143 | (2) |
|
Two Components of Acceleration |
|
|
145 | (3) |
|
|
148 | (2) |
|
Making Your Own Data Type |
|
|
150 | (4) |
|
|
150 | (3) |
|
Multiple Data Constructors |
|
|
153 | (1) |
|
Defining a New Data Type for 3D Vectors |
|
|
154 | (5) |
|
|
154 | (1) |
|
Data Type Definition for Vec |
|
|
155 | (2) |
|
|
157 | (2) |
|
|
159 | (1) |
|
|
159 | (6) |
|
|
165 | (10) |
|
|
166 | (2) |
|
|
168 | (1) |
|
|
169 | (1) |
|
Multiple Curves on One Set of Axes |
|
|
170 | (1) |
|
Controlling the Plot Ranges |
|
|
171 | (1) |
|
|
171 | (1) |
|
|
172 | (1) |
|
|
172 | (3) |
|
12 Creating Stand-Alone Programs |
|
|
175 | (12) |
|
Using GHC to Make a Stand-Alone Program |
|
|
176 | (3) |
|
|
176 | (1) |
|
A Program That Imports Modules |
|
|
177 | (2) |
|
Using Cabal to Make a Stand-Alone Program |
|
|
179 | (3) |
|
Using Stack to Make a Stand-Alone Program |
|
|
182 | (3) |
|
|
185 | (1) |
|
|
186 | (1) |
|
13 Creating 2D and 3D Animations |
|
|
187 | (18) |
|
|
187 | (8) |
|
|
188 | (2) |
|
|
190 | (1) |
|
|
191 | (4) |
|
|
195 | (5) |
|
|
195 | (3) |
|
|
198 | (1) |
|
|
198 | (2) |
|
|
200 | (1) |
|
|
201 | (4) |
|
PART II EXPRESSING NEWTONIAN MECHANICS AND SOLVING PROBLEMS |
|
|
|
14 Newton's Second Law and Differential Equations |
|
|
205 | (38) |
|
|
206 | (1) |
|
Newton's Second Law in One Dimension |
|
|
207 | (2) |
|
Second Law with Constant Forces |
|
|
209 | (5) |
|
Second Law with Forces That Depend Only on Time |
|
|
214 | (5) |
|
|
219 | (1) |
|
Second Law with Forces That Depend Only on Velocity |
|
|
220 | (8) |
|
|
225 | (2) |
|
|
227 | (1) |
|
The State of a Physical System |
|
|
228 | (1) |
|
Second Law with Forces That Depend on Time and Velocity |
|
|
229 | (6) |
|
Method 1 Produce a List of States |
|
|
234 | (1) |
|
Method 2 Produce a Velocity Function |
|
|
234 | (1) |
|
Example: Pedaling and Coasting with Air Resistance |
|
|
235 | (3) |
|
|
235 | (1) |
|
Method 1 Produce a List of States |
|
|
236 | (1) |
|
Method 2 Produce a Velocity Function |
|
|
237 | (1) |
|
|
238 | (1) |
|
|
238 | (5) |
|
15 Mechanics In One Dimension |
|
|
243 | (36) |
|
|
244 | (1) |
|
Forces That Depend on Time, Position, and Velocity |
|
|
245 | (8) |
|
A General Strategy for Solving Mechanics Problems |
|
|
247 | (2) |
|
Solving with Euler's Method |
|
|
249 | (2) |
|
Producing a List of States |
|
|
251 | (1) |
|
Position and Velocity Functions |
|
|
252 | (1) |
|
A Damped Harmonic Oscillator |
|
|
253 | (7) |
|
|
254 | (2) |
|
Method 1 Producing a List of States |
|
|
256 | (2) |
|
Method 2 Producing Position and Velocity Functions |
|
|
258 | (2) |
|
|
260 | (2) |
|
Solving Differential Equations |
|
|
262 | (8) |
|
Generalizing the State Space |
|
|
263 | (3) |
|
Type Classes for State Spaces |
|
|
266 | (2) |
|
One More Numerical Method |
|
|
268 | (1) |
|
Comparison of Numerical Methods |
|
|
269 | (1) |
|
|
270 | (1) |
|
|
270 | (9) |
|
16 Mechanics In Three Dimensions |
|
|
279 | (28) |
|
|
280 | (1) |
|
Newton's Second Law in Three Dimensions |
|
|
281 | (2) |
|
The State of One Particle |
|
|
283 | (3) |
|
Solving Newton's Second Law |
|
|
286 | (2) |
|
|
288 | (4) |
|
|
288 | (1) |
|
Gravity Produced by the Sun |
|
|
288 | (2) |
|
|
290 | (1) |
|
|
291 | (1) |
|
Force from Uniform Electric and Magnetic Fields |
|
|
291 | (1) |
|
State Update for One Particle |
|
|
292 | (4) |
|
|
296 | (5) |
|
Two Helpful Animation Functions |
|
|
296 | (3) |
|
|
299 | (2) |
|
|
301 | (1) |
|
|
302 | (5) |
|
17 Satellite, Projectile, and Proton Motion |
|
|
307 | (22) |
|
|
307 | (5) |
|
|
308 | (1) |
|
|
309 | (1) |
|
|
309 | (1) |
|
|
310 | (1) |
|
|
311 | (1) |
|
Projectile Motion with Air Resistance |
|
|
312 | (9) |
|
|
313 | (1) |
|
Finding the Angle for Maximum Range |
|
|
314 | (2) |
|
|
316 | (4) |
|
|
320 | (1) |
|
Proton in a Magnetic Field |
|
|
321 | (2) |
|
|
323 | (1) |
|
|
323 | (6) |
|
18 A Very Short Primer On Relativity |
|
|
329 | (10) |
|
|
330 | (1) |
|
A Replacement for Newton's Second Law |
|
|
331 | (1) |
|
Response to a Constant Force |
|
|
332 | (2) |
|
Proton in a Magnetic Field |
|
|
334 | (3) |
|
|
337 | (1) |
|
|
338 | (1) |
|
|
339 | (24) |
|
|
340 | (1) |
|
|
341 | (7) |
|
|
343 | (1) |
|
|
344 | (1) |
|
|
345 | (2) |
|
|
347 | (1) |
|
Elastic Billiard Interaction |
|
|
348 | (1) |
|
Internal and External Forces |
|
|
348 | (2) |
|
The State of a Multi-Particle System |
|
|
350 | (2) |
|
State Update for Multiple Particles |
|
|
352 | (7) |
|
Implementing Newton's Second Law |
|
|
352 | (6) |
|
Numerical Methods for Multiple Particles |
|
|
358 | (1) |
|
|
359 | (1) |
|
|
359 | (2) |
|
|
361 | (2) |
|
20 Springs, Billiard Balls, and A Guitar String |
|
|
363 | (46) |
|
|
364 | (1) |
|
Two Masses and Two Springs |
|
|
364 | (9) |
|
|
365 | (1) |
|
|
366 | (1) |
|
Stand-Alone Animation Program |
|
|
367 | (2) |
|
Using Mechanical Energy as a Guide to Numerical Accuracy |
|
|
369 | (4) |
|
|
373 | (17) |
|
|
373 | (3) |
|
Spring Constant and Time Step |
|
|
376 | (1) |
|
Momentum and Energy Conservation |
|
|
377 | (8) |
|
|
385 | (3) |
|
|
388 | (2) |
|
|
390 | (9) |
|
|
391 | (1) |
|
|
392 | (1) |
|
|
392 | (2) |
|
|
394 | (3) |
|
|
397 | (2) |
|
|
399 | (1) |
|
|
400 | (9) |
|
PART III EXPRESSING ELECTROMAGNETIC THEORY AND SOLVING PROBLEMS |
|
|
|
|
409 | (12) |
|
|
409 | (2) |
|
|
411 | (1) |
|
|
412 | (6) |
|
|
413 | (1) |
|
Modeling the Situation in Haskell |
|
|
414 | (4) |
|
|
418 | (1) |
|
|
418 | (3) |
|
22 Coordinate Systems and Fields |
|
|
421 | (28) |
|
|
422 | (2) |
|
|
424 | (1) |
|
|
425 | (1) |
|
|
426 | (1) |
|
|
427 | (4) |
|
|
427 | (1) |
|
|
428 | (2) |
|
|
430 | (1) |
|
|
431 | (1) |
|
|
431 | (2) |
|
|
433 | (4) |
|
Functions for Visualizing Scalar Fields |
|
|
437 | (2) |
|
|
437 | (1) |
|
|
438 | (1) |
|
Functions for Visualizing Vector Fields |
|
|
439 | (6) |
|
|
439 | (2) |
|
|
441 | (2) |
|
|
443 | (2) |
|
|
445 | (1) |
|
|
446 | (3) |
|
23 Curves, Surfaces, and Volumes |
|
|
449 | (12) |
|
|
450 | (1) |
|
|
450 | (2) |
|
|
450 | (1) |
|
|
451 | (1) |
|
|
452 | (4) |
|
|
452 | (2) |
|
|
454 | (1) |
|
|
455 | (1) |
|
|
456 | (1) |
|
|
457 | (1) |
|
|
458 | (3) |
|
|
461 | (12) |
|
|
461 | (2) |
|
|
463 | (1) |
|
A Type for Charge Distribution |
|
|
464 | (1) |
|
Examples of Charge Distributions |
|
|
465 | (1) |
|
|
466 | (3) |
|
Total Charge of a Line Charge |
|
|
466 | (1) |
|
Total Charge of a Surface Charge |
|
|
466 | (1) |
|
Total Charge of a Volume Charge |
|
|
467 | (1) |
|
Calculating Total Charge in Haskell |
|
|
467 | (2) |
|
|
469 | (2) |
|
|
471 | (1) |
|
|
471 | (2) |
|
|
473 | (34) |
|
What Is an Electric Field? |
|
|
474 | (1) |
|
|
475 | (1) |
|
Charge Creates an Electric Field |
|
|
475 | (19) |
|
Electric Field Created by a Point Charge |
|
|
476 | (3) |
|
Electric Field Created by Multiple Charges |
|
|
479 | (4) |
|
Electric Field Created by a Line Charge |
|
|
483 | (3) |
|
Electric Field Created by a Surface Charge |
|
|
486 | (5) |
|
Electric Field Created by a Volume Charge |
|
|
491 | (3) |
|
|
494 | (1) |
|
|
494 | (1) |
|
|
494 | (1) |
|
|
495 | (1) |
|
Approximating Curves, Surfaces, and Volumes |
|
|
495 | (7) |
|
|
496 | (2) |
|
|
498 | (1) |
|
|
499 | (3) |
|
|
502 | (1) |
|
|
502 | (5) |
|
|
507 | (12) |
|
|
508 | (1) |
|
|
508 | (1) |
|
A Type for Current Distribution |
|
|
509 | (1) |
|
Examples of Current Distributions |
|
|
510 | (2) |
|
Conservation of Charge and Constraints on Steady Current Distributions |
|
|
512 | (2) |
|
|
514 | (2) |
|
|
516 | (1) |
|
|
516 | (3) |
|
|
519 | (16) |
|
|
519 | (1) |
|
|
520 | (1) |
|
Current Creates Magnetic Field |
|
|
521 | (9) |
|
Magnetic Field Created by a Line Current |
|
|
521 | (8) |
|
Magnetic Field Created by a Surface Current |
|
|
529 | (1) |
|
Magnetic Field Created by a Volume Current |
|
|
530 | (1) |
|
|
530 | (1) |
|
|
531 | (4) |
|
|
535 | (16) |
|
|
536 | (1) |
|
|
536 | (2) |
|
State of One Particle and Fields |
|
|
538 | (3) |
|
|
541 | (1) |
|
Do We Really Need an Electric Field? |
|
|
541 | (2) |
|
|
543 | (1) |
|
Animating a Particle in Electric and Magnetic Fields |
|
|
544 | (4) |
|
|
546 | (1) |
|
|
547 | (1) |
|
|
548 | (1) |
|
|
549 | (2) |
|
|
551 | (30) |
|
|
552 | (1) |
|
|
552 | (8) |
|
Relationships Between Electricity and Magnetism |
|
|
554 | (1) |
|
Connection to Coulomb's Law and Biot-Savart Law |
|
|
554 | (1) |
|
|
555 | (2) |
|
Spatial Derivatives and the Curl |
|
|
557 | (1) |
|
|
558 | (2) |
|
|
560 | (11) |
|
|
562 | (2) |
|
|
564 | (2) |
|
|
566 | (2) |
|
|
568 | (3) |
|
|
571 | (6) |
|
|
571 | (1) |
|
|
572 | (1) |
|
|
573 | (1) |
|
|
574 | (2) |
|
|
576 | (1) |
|
|
577 | (2) |
|
|
579 | (2) |
|
APPENDIX: INSTALLING HASKELL |
|
|
581 | (14) |
|
|
581 | (1) |
|
|
582 | (1) |
|
|
582 | (1) |
|
Installing Haskell Library Packages |
|
|
583 | (3) |
|
|
584 | (2) |
|
|
586 | (1) |
|
|
586 | (1) |
|
|
587 | (1) |
|
Setting Up Your Coding Environment |
|
|
587 | (6) |
|
What We Want in a Coding Environment |
|
|
588 | (1) |
|
All Code in One Directory |
|
|
589 | (1) |
|
|
590 | (3) |
|
|
593 | (2) |
Bibliography |
|
595 | (2) |
Index |
|
597 | |