Muutke küpsiste eelistusi

Learn Physics with Functional Programming: A Hands-on Guide to Exploring Physics with Haskell [Pehme köide]

  • Formaat: Paperback / softback, 648 pages, kõrgus x laius: 234x177 mm
  • Ilmumisaeg: 31-Jan-2023
  • Kirjastus: No Starch Press,US
  • ISBN-10: 1718501668
  • ISBN-13: 9781718501669
Teised raamatud teemal:
  • Formaat: Paperback / softback, 648 pages, kõrgus x laius: 234x177 mm
  • Ilmumisaeg: 31-Jan-2023
  • Kirjastus: No Starch Press,US
  • ISBN-10: 1718501668
  • ISBN-13: 9781718501669
Teised raamatud teemal:
"This book shows how to solve physics problems using Haskell, a functional programming language. Source code, equations, and diagrams throughout demonstrate how physics enthusiasts and functional programmers can use Haskell and its mathematical structures to solve problems from Newtonian mechanics and electromagnetics"--

Deepen your understanding of physics by learning to use the Haskell functional programming language.

This book teaches you to solve physics problems using the functional programming paradigm. Ideal for first-time programmers and science aficionados alike, it introduces the Haskell programming language and encourages the writing of beautiful code to match the elegant ideas of theoretical physics. 

Haskell’s powerful system of types is capable of encoding important mathematical structures like vectors, derivatives, integrals, scalar fields, and differential equations. In addition, you’ll explore Newtonian mechanics and electromagnetics, analyze source code, and discover why Haskell’s high-order functions and referential transparency serve physics so well.
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)
A Kinematics Problem
3(1)
The Interactive Compiler
4(1)
Numeric Functions
4(2)
Operators
6(3)
Precedence and Associativity
7(2)
The Application Operator
9(1)
Functions with Two Arguments
9(1)
Numbers in Haskell
10(1)
Negative Numbers in Haskell
10(1)
Decimal Numbers in Haskell
11(1)
Exponential Notation
11(1)
Approximate Calculation
11(1)
Errors
12(1)
Getting Help and Quitting
13(1)
More Information
13(1)
Summary
13(1)
Exercises
14(1)
2 Writing Basic Functions
15(10)
Constants, Functions, and Types
16(3)
How We Talk About Functions
19(1)
Anonymous Functions
20(1)
Composing Functions
21(1)
Variable Not in Scope Error
22(1)
Summary
23(1)
Exercises
23(2)
3 Types and Entities
25(10)
Basic Types
25(5)
The Boolean Type
26(2)
The Character Type
28(1)
The String Type
28(1)
Numeric Types
29(1)
Function Types
30(2)
Summary
32(1)
Exercises
32(3)
4 Describing Motion
35(16)
Position and Velocity on an Air Track
35(2)
Types for Physical Quantities
37(1)
Introducing Derivatives
38(2)
Derivatives in Haskell
40(1)
Modeling the Car's Position and Velocity
41(3)
Modeling Acceleration
44(1)
Approximate Algorithms and Finite Precision
45(2)
Summary
47(1)
Exercises
47(4)
5 Working With Lists
51(18)
List Basics
52(4)
Selecting an Element from a List
52(1)
Concatenating Lists
53(1)
Arithmetic Sequences
54(1)
List Types
55(1)
Functions for Lists of Numbers
55(1)
When Not to Use a List
56(1)
Type Variables
56(1)
Type Conversion
57(1)
The Length of Lists
58(1)
A String Is a List of Characters
59(1)
List Comprehensions
60(1)
Infinite Lists
61(1)
List Constructors and Pattern Matching
62(2)
Summary
64(1)
Exercises
64(5)
6 Higher-Order Functions
69(22)
How to Think About Functions with Parameters
70(3)
Mapping a Function Over a List
73(1)
Iteration and Recursion
74(2)
Anonymous Higher-Order Functions
76(1)
Operators as Higher-Order Functions
77(1)
Combinators
78(1)
Predicate-Based Higher-Order Functions
79(2)
Numerical Integration
81(6)
Introducing Integrators
81(1)
Digital Integration
82(3)
Implementing Antiderivatives
85(2)
Summary
87(1)
Exercises
88(3)
7 Graphing Functions
91(6)
Using Library Modules
91(2)
Standard Library Modules
91(1)
Other Library Modules
92(1)
Plotting
93(2)
Function Only
93(1)
Function and Module
94(1)
Function, Module, and Plot Definition
94(1)
Summary
95(1)
Exercises
95(2)
8 Type Classes
97(16)
Type Classes and Numbers
98(1)
Type Classes from the Prelude
99(5)
The Eq Type Class
99(1)
The Show Type Class
100(1)
The Num Type Class
101(1)
The Integral Type Class
102(1)
The Ord Type Class
102(1)
The Fractional Type Class
103(1)
The Floating Type Class
104(1)
Exponentiation and Type Classes
104(1)
Sections
105(1)
Example of Type Classes and Plotting
106(3)
Summary
109(1)
Exercises
109(4)
9 Tuples and Type Constructors
113(16)
Pairs
113(2)
Currying a Function of Two Variables
115(1)
Triples
116(1)
Comparing Lists and Tuples
117(1)
Maybe Types
117(2)
Lists of Pairs
119(1)
Tuples and List Comprehensions
120(1)
Type Constructors and Kinds
121(3)
Numerical Integration Redux
124(1)
Summary
125(1)
Exercises
125(4)
10 Describing Motion In Three Dimensions
129(36)
Three-Dimensional Vectors
129(7)
Coordinate-Free Vectors
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)
Coordinate Systems
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)
Kinematics in 3D
142(8)
Defining Position, Velocity, and Acceleration
143(2)
Two Components of Acceleration
145(3)
Projectile Motion
148(2)
Making Your Own Data Type
150(4)
Single Data Constructor
150(3)
Multiple Data Constructors
153(1)
Defining a New Data Type for 3D Vectors
154(5)
Possible Implementations
154(1)
Data Type Definition for Vec
155(2)
Vec Functions
157(2)
Summary
159(1)
Exercises
159(6)
11 Creating Graphs
165(10)
Title and Axis Labels
166(2)
Other Labels
168(1)
Plotting Data
169(1)
Multiple Curves on One Set of Axes
170(1)
Controlling the Plot Ranges
171(1)
Making a Key
171(1)
Summary
172(1)
Exercises
172(3)
12 Creating Stand-Alone Programs
175(12)
Using GHC to Make a Stand-Alone Program
176(3)
Hello, World!
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)
Summary
185(1)
Exercises
186(1)
13 Creating 2D and 3D Animations
187(18)
2D Animation
187(8)
Displaying a 2D Picture
188(2)
Making a 2D Animation
190(1)
Making a 2D Simulation
191(4)
3D Animation
195(5)
Displaying a 3D Picture
195(3)
Making a 3D Animation
198(1)
Making a 3D Simulation
198(2)
Summary
200(1)
Exercises
201(4)
PART II EXPRESSING NEWTONIAN MECHANICS AND SOLVING PROBLEMS
14 Newton's Second Law and Differential Equations
205(38)
Newton's First Law
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)
Air Resistance
219(1)
Second Law with Forces That Depend Only on Velocity
220(8)
Euler Method by Hand
225(2)
Euler Method in Haskell
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)
Euler Method by Hand
235(1)
Method 1 Produce a List of States
236(1)
Method 2 Produce a Velocity Function
237(1)
Summary
238(1)
Exercises
238(5)
15 Mechanics In One Dimension
243(36)
Introductory Code
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)
Euler Method by Hand
254(2)
Method 1 Producing a List of States
256(2)
Method 2 Producing Position and Velocity Functions
258(2)
Euler-Cromer Method
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)
Summary
270(1)
Exercises
270(9)
16 Mechanics In Three Dimensions
279(28)
Introductory Code
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)
One-Body Forces
288(4)
Earth Surface Gravity
288(1)
Gravity Produced by the Sun
288(2)
Air Resistance
290(1)
Wind Force
291(1)
Force from Uniform Electric and Magnetic Fields
291(1)
State Update for One Particle
292(4)
Preparing for Animation
296(5)
Two Helpful Animation Functions
296(3)
How the Functions Work
299(2)
Summary
301(1)
Exercises
302(5)
17 Satellite, Projectile, and Proton Motion
307(22)
Satellite Motion
307(5)
State-Update Function
308(1)
Initial State
309(1)
Time-Scale Factor
309(1)
Animation Rate
310(1)
Display Function
311(1)
Projectile Motion with Air Resistance
312(9)
Calculating a Trajectory
313(1)
Finding the Angle for Maximum Range
314(2)
2D Animation
316(4)
3D Animation
320(1)
Proton in a Magnetic Field
321(2)
Summary
323(1)
Exercises
323(6)
18 A Very Short Primer On Relativity
329(10)
A Little Theory
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)
Summary
337(1)
Exercises
338(1)
19 Interacting Particles
339(24)
Newton's Third Law
340(1)
Two-Body Forces
341(7)
Universal Gravity
343(1)
Constant Repulsive Force
344(1)
Linear Spring
345(2)
Central Force
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)
Composite Functions
359(1)
Summary
359(2)
Exercises
361(2)
20 Springs, Billiard Balls, and A Guitar String
363(46)
Introductory Code
364(1)
Two Masses and Two Springs
364(9)
Forces
365(1)
Animation Functions
366(1)
Stand-Alone Animation Program
367(2)
Using Mechanical Energy as a Guide to Numerical Accuracy
369(4)
A Collision
373(17)
Data Representations
373(3)
Spring Constant and Time Step
376(1)
Momentum and Energy Conservation
377(8)
Numerical Issues
385(3)
Animated Results
388(2)
Wave on a Guitar String
390(9)
Forces
391(1)
State-Update Function
392(1)
Initial State
392(2)
Stand-Alone Program
394(3)
Asynchronous Animation
397(2)
Summary
399(1)
Exercises
400(9)
PART III EXPRESSING ELECTROMAGNETIC THEORY AND SOLVING PROBLEMS
21 Electricity
409(12)
Electric Charge
409(2)
Coulomb's Law
411(1)
Two Charges Interacting
412(6)
Looking at Extremes
413(1)
Modeling the Situation in Haskell
414(4)
Summary
418(1)
Exercises
418(3)
22 Coordinate Systems and Fields
421(28)
Polar Coordinates
422(2)
Cylindrical Coordinates
424(1)
Spherical Coordinates
425(1)
Introductory Code
426(1)
A Type for Position
427(4)
Defining the New Type
427(1)
Making a Position
428(2)
Using a Position
430(1)
Displacement
431(1)
The Scalar Field
431(2)
The Vector Field
433(4)
Functions for Visualizing Scalar Fields
437(2)
3D Visualization
437(1)
2D Visualization
438(1)
Functions for Visualizing Vector Fields
439(6)
3D Visualization
439(2)
2D Visualization
441(2)
Gradient Visualization
443(2)
Summary
445(1)
Exercises
446(3)
23 Curves, Surfaces, and Volumes
449(12)
Introductory Code
450(1)
Curves
450(2)
Parameterizing Curves
450(1)
Examples of Curves
451(1)
Surfaces
452(4)
Parameterizing Surfaces
452(2)
Examples of Surfaces
454(1)
Orientation
455(1)
Volumes
456(1)
Summary
457(1)
Exercises
458(3)
24 Electric Charge
461(12)
Charge Distributions
461(2)
Introductory Code
463(1)
A Type for Charge Distribution
464(1)
Examples of Charge Distributions
465(1)
Total Charge
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)
Electric Dipole Moment
469(2)
Summary
471(1)
Exercises
471(2)
25 Electric Field
473(34)
What Is an Electric Field?
474(1)
Introductory Code
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)
Scalar Integrals
494(1)
Scalar Line Integral
494(1)
Scalar Surface Integral
494(1)
Scalar Volume Integral
495(1)
Approximating Curves, Surfaces, and Volumes
495(7)
Approximating a Curve
496(2)
Approximating a Surface
498(1)
Approximating a Volume
499(3)
Summary
502(1)
Exercises
502(5)
26 Electric Current
507(12)
Current Distributions
508(1)
Introductory Code
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)
Magnetic Dipole Moment
514(2)
Summary
516(1)
Exercises
516(3)
27 Magnetic Field
519(16)
A Simple Magnetic Effect
519(1)
Introductory Code
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)
Summary
530(1)
Exercises
531(4)
28 The Lorentz Force Law
535(16)
Introductory Code
536(1)
Statics and Dynamics
536(2)
State of One Particle and Fields
538(3)
Lorentz Force Law
541(1)
Do We Really Need an Electric Field?
541(2)
State Update
543(1)
Animating a Particle in Electric and Magnetic Fields
544(4)
Uniform Fields
546(1)
Classical Hydrogen
547(1)
Summary
548(1)
Exercises
549(2)
29 The Maxwell Equations
551(30)
Introductory Code
552(1)
The Maxwell Equations
552(8)
Relationships Between Electricity and Magnetism
554(1)
Connection to Coulomb's Law and Biot-Savart Law
554(1)
State Update
555(2)
Spatial Derivatives and the Curl
557(1)
A Naive Method
558(2)
The FDTD Method
560(11)
The Yee Cell
562(2)
A Type for State
564(2)
FDTD and the Curl
566(2)
State Update
568(3)
Animation
571(6)
Current Density
571(1)
Grid Boundary
572(1)
Display Function
573(1)
Two Helping Functions
574(2)
Main Program
576(1)
Summary
577(2)
Exercises
579(2)
APPENDIX: INSTALLING HASKELL
581(14)
Installing GHC
581(1)
Installing a Text Editor
582(1)
Installing Gnuplot
582(1)
Installing Haskell Library Packages
583(3)
Using Cabal
584(2)
Using Stack
586(1)
Installing Gloss
586(1)
Installing Diagrams
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)
One Way to Use Stack
590(3)
Summary
593(2)
Bibliography 595(2)
Index 597
Scott Walck has a PhD in Physics from Lehigh University and has been a professor of physics, including computational physics, to undergraduates for over 20 years at Lebanon Valley College. He has also written academic articles and given talks on the use of functional programming in teaching physics.