## Book description

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.

Early chapters cover the basics of coding in Haskell, which has a powerful system of types capable of encoding important mathematical structures in physics, like vectors, derivatives, integrals, scalar fields, vector fields, and differential equations. Later sections of the book explore Newtonian mechanics and electromagnetics—two central pillars of theoretical physics. In addition, you’ll get a deep look into source code, and discover why Haskell’s high-order functions and referential transparency serve physics so well. Along the way, you’ll learn:

•How to write beautiful code that expresses fundamental physical principles
•How to make graphs and animations of interesting situations
•How to program in a language that looks like mathematics
•How types, high order functions, and referential transparency serve physics well

1. Cover Page
2. Title Page
4. Dedication
7. Brief Contents
8. Contents in Detail
9. ACKNOWLEDGMENTS
10. INTRODUCTION
11. PART I A HASKELL PRIMER FOR PHYSICISTS
1. A Kinematics Problem
2. The Interactive Compiler
3. Numeric Functions
4. Operators
5. Functions with Two Arguments
7. Approximate Calculation
8. Errors
9. Getting Help and Quitting
11. Summary
12. Exercises
13. 2 WRITING BASIC FUNCTIONS
14. 3 TYPES AND ENTITIES
1. Basic Types
2. Function Types
3. Summary
4. Exercises
15. 4 DESCRIBING MOTION
16. 5 WORKING WITH LISTS
1. List Basics
2. Type Variables
3. Type Conversion
4. The Length of Lists
5. A String Is a List of Characters
6. List Comprehensions
7. Infinite Lists
8. List Constructors and Pattern Matching
9. Summary
10. Exercises
17. 6 HIGHER-ORDER FUNCTIONS
1. How to Think About Functions with Parameters
2. Mapping a Function Over a List
3. Iteration and Recursion
4. Anonymous Higher-Order Functions
5. Operators as Higher-Order Functions
6. Combinators
7. Predicate-Based Higher-Order Functions
8. Numerical Integration
9. Summary
10. Exercises
18. 7 GRAPHING FUNCTIONS
1. Using Library Modules
2. Plotting
3. Summary
4. Exercises
19. 8 TYPE CLASSES
1. Type Classes and Numbers
2. Type Classes from the Prelude
3. Exponentiation and Type Classes
4. Sections
5. Example of Type Classes and Plotting
6. Summary
7. Exercises
20. 9 TUPLES AND TYPE CONSTRUCTORS
21. 10 DESCRIBING MOTION IN THREE DIMENSIONS
1. Three-Dimensional Vectors
2. Coordinate Systems
3. Kinematics in 3D
4. Making Your Own Data Type
5. Defining a New Data Type for 3D Vectors
6. Summary
7. Exercises
22. 11 CREATING GRAPHS
23. 12 CREATING STAND-ALONE PROGRAMS
1. Using GHC to Make a Stand-Alone Program
2. Using Cabal to Make a Stand-Alone Program
3. Using Stack to Make a Stand-Alone Program
4. Summary
5. Exercises
24. 13 CREATING 2D AND 3D ANIMATIONS
1. 2D Animation
2. 3D Animation
3. Summary
4. Exercises
25. PART II EXPRESSING NEWTONIAN MECHANICS AND SOLVING PROBLEMS
26. 14 NEWTON’S SECOND LAW AND DIFFERENTIAL EQUATIONS
1. Newton’s First Law
2. Newton’s Second Law in One Dimension
3. Second Law with Constant Forces
4. Second Law with Forces That Depend Only on Time
5. Air Resistance
6. Second Law with Forces That Depend Only on Velocity
7. The State of a Physical System
8. Second Law with Forces That Depend on Time and Velocity
9. Example: Pedaling and Coasting with Air Resistance
10. Summary
11. Exercises
27. 15 MECHANICS IN ONE DIMENSION
1. Introductory Code
2. Forces That Depend on Time, Position, and Velocity
3. A Damped Harmonic Oscillator
4. Euler-Cromer Method
5. Solving Differential Equations
6. Summary
7. Exercises
28. 16 MECHANICS IN THREE DIMENSIONS
1. Introductory Code
2. Newton’s Second Law in Three Dimensions
3. The State of One Particle
4. Solving Newton’s Second Law
5. One-Body Forces
6. State Update for One Particle
7. Preparing for Animation
8. Summary
9. Exercises
29. 17 SATELLITE, PROJECTILE, AND PROTON MOTION
1. Satellite Motion
2. Projectile Motion with Air Resistance
3. Proton in a Magnetic Field
4. Summary
5. Exercises
30. 18 A VERY SHORT PRIMER ON RELATIVITY
31. 19 INTERACTING PARTICLES
1. Newton’s Third Law
2. Two-Body Forces
3. Internal and External Forces
4. The State of a Multi-Particle System
5. State Update for Multiple Particles
6. Summary
7. Exercises
32. 20 SPRINGS, BILLIARD BALLS, AND A GUITAR STRING
1. Introductory Code
2. Two Masses and Two Springs
3. A Collision
4. Wave on a Guitar String
5. Summary
6. Exercises
33. PART III EXPRESSING ELECTROMAGNETIC THEORY AND SOLVING PROBLEMS
34. 21 ELECTRICITY
1. Electric Charge
2. Coulomb’s Law
3. Two Charges Interacting
4. Summary
5. Exercises
35. 22 COORDINATE SYSTEMS AND FIELDS
1. Polar Coordinates
2. Cylindrical Coordinates
3. Spherical Coordinates
4. Introductory Code
5. A Type for Position
6. Displacement
7. The Scalar Field
8. The Vector Field
9. Functions for Visualizing Scalar Fields
10. Functions for Visualizing Vector Fields
11. Summary
12. Exercises
36. 23 CURVES, SURFACES, AND VOLUMES
1. Introductory Code
2. Curves
3. Surfaces
4. Volumes
5. Summary
6. Exercises
37. 24 ELECTRIC CHARGE
1. Charge Distributions
2. Introductory Code
3. A Type for Charge Distribution
4. Examples of Charge Distributions
5. Total Charge
6. Electric Dipole Moment
7. Summary
8. Exercises
38. 25 ELECTRIC FIELD
1. What Is an Electric Field?
2. Introductory Code
3. Charge Creates an Electric Field
4. Scalar Integrals
5. Approximating Curves, Surfaces, and Volumes
6. Summary
7. Exercises
39. 26 ELECTRIC CURRENT
40. 27 MAGNETIC FIELD
1. A Simple Magnetic Effect
2. Introductory Code
3. Current Creates Magnetic Field
4. Summary
5. Exercises
41. 28 THE LORENTZ FORCE LAW
1. Introductory Code
2. Statics and Dynamics
3. State of One Particle and Fields
4. Lorentz Force Law
5. Do We Really Need an Electric Field?
6. State Update
7. Animating a Particle in Electric and Magnetic Fields
8. Summary
9. Exercises
42. 29 THE MAXWELL EQUATIONS
1. Introductory Code
2. The Maxwell Equations
3. The FDTD Method
4. Animation
5. Summary
6. Exercises
1. Installing GHC
2. Installing a Text Editor
3. Installing Gnuplot
5. Installing Gloss
6. Installing Diagrams
7. Setting Up Your Coding Environment
8. Summary
44. BIBLIOGRAPHY
45. INDEX

## Product information

• Title: Learn Physics with Functional Programming
• Author(s): Scott N. Walck
• Release date: January 2023
• Publisher(s): No Starch Press
• ISBN: 9781718501669