Applied mathematics with Python
Episode Deep Dive
Guests Background
Vince Knight and Geraint Palmer are both lecturers at the School of Mathematics at Cardiff University. Vince has been a guest on the podcast previously, discussing his work on game theory in Python. Geraint earned his PhD under Vince’s supervision and specializes in discrete event simulation and other applied math techniques, often applying open-source libraries to real-world problems. Together, they authored Applied Mathematics with Open Source Software, demonstrating how to use Python (and R) to solve practical math challenges.
What to Know If You're New to Python
Here are some libraries or topics mentioned that will help you follow along and apply the ideas from this episode:
- NumPy: A foundational library for array operations, linear algebra, and more.
- SymPy: Enables symbolic math, letting you solve equations without numeric values.
- CIW (Q): A discrete event simulation library for modeling and analyzing queueing systems.
- Nashpy: A Python library for studying 2-player game theory, e.g., finding Nash equilibria.
Key Points and Takeaways
Power of Applied Math in Real-World Scenarios
Applied mathematics allows you to translate theoretical concepts—like linear algebra, differential equations, or probability—into practical tools for decision-making. This episode highlights examples from barbershops, healthcare, bike repairs, and taxi services to illustrate how data and math models guide real-world outcomes.Markov Chains for Queueing Problems
Markov chains provide a framework to model systems with probabilities driving state changes over time—like people arriving at a barbershop and either waiting or leaving. By representing these transitions in matrices, you can solve for long-term probabilities (e.g., how often the shop is full) with just a few lines of code using NumPy.- Tools & Links:
Discrete Event Simulation with CIW (Q)
When problems grow too large or complex for straightforward Markov chain solutions (e.g., multiple stages of service or nearly infinite wait space), discrete event simulation is a powerful alternative. Vince and Geraint walk through their CIW (Q) Python library to simulate a bike repair shop and measure wait times and bottlenecks efficiently.- Tools & Links:
Symbolic Math with SymPy
SymPy lets you solve symbolic math problems directly, including derivatives and integrals, without numeric approximations. The episode showcases how you can represent an entire differential equation symbolically, add your initial conditions, and then get an exact formula for solutions—no manual steps required.- Tools & Links:
Comparing Python and R Approaches
The book and this episode compare the same math problems solved in both Python and R. Because each ecosystem has unique libraries and idiomatic workflows, sometimes the math must be formulated differently—even when the outcome is identical. This underscores the importance of separating math concepts from software details.- Tools & Links:
Infectious Disease Modeling and Differential Equations
Differential equations can represent how diseases spread or recover within a population. By adjusting key parameters (like recovery rate), you can calculate the cost or benefit of interventions. In the episode, they discuss a simplified model (commonly known as SIR-type approaches) to illustrate how you might decide whether a “cure” is worth the investment.- Tools & Links:
Game Theory with Nash.py
Game theory studies strategic interactions—like two competing taxi companies deciding how many cars to operate. Vince’s Nash.py library makes it easy to define payoff matrices and compute Nash equilibria to see which “rational” strategies the competitors (or players) might settle on.- Tools & Links:
Open-Source vs. Commercial Math Tools
Many academics traditionally use commercial software (e.g., MATLAB) for math, but open-source libraries such as NumPy, SymPy, R, or CIW (Q) can be just as powerful. Vince and Geraint stress the ethical and practical benefits of teaching open-source solutions: it expands accessibility and fosters a deeper understanding of the underlying math.- Tools & Links:
Data-Driven Decisions: Barbershops to Hospitals
The barbershop and bike shop examples in the show are stand-ins for more critical decisions, such as how many beds a hospital should have on standby or how many ambulances to run. Small changes, discovered via simulation or Markov chains, can have massive real-world impacts on cost, wait times, and system performance.- Tools & Links:
The Synergy of Programming and Mathematics
The discussion emphasized how code can demystify math by giving immediate, tangible results. Conversely, math guides code toward more precise, optimized, and interpretable solutions. Vince and Geraint see this synergy as a key way to help students and professionals alike better grasp the power behind modern computations.
- Tools & Links:
Interesting Quotes and Stories
- On Teaching and Ethics: Vince compared relying solely on commercial tools to telling students they can only use a specific brand of pen. They emphasized that the real learning happens when you understand the math well enough to implement it in any language or tool.
- On Simulation vs. Exact Analysis: Geraint pointed out how for more complex queueing systems, “sometimes it’s just simpler to simulate rather than solve an infinite matrix,” underscoring that approximate answers can be more practical than intractable exact models.
Key Definitions and Terms
- Markov Chain: A system of states with probabilities governing transitions from one state to another over time.
- Discrete Event Simulation (DES): A simulation paradigm where the state of the system changes only at specific time points (events).
- Differential Equation: An equation involving an unknown function and its derivatives, used to model phenomena with rates of change.
- Nash Equilibrium: In game theory, a stable state where no player benefits from changing strategy if other players keep theirs unchanged.
- Symbolic Math: Performing algebra, calculus, etc. in symbolic form (e.g.,
x + x = 2y
) rather than numerical approximations.
Learning Resources
- Python for Absolute Beginners
Ideal for newcomers who want a clear, approachable introduction to Python’s core features. - Data Science Jumpstart with 10 Projects
Perfect if you’re exploring data or want practice applying Python and math to numerous mini-projects. - Python Data Visualization
Helpful for learning how to present and interpret analytical results in meaningful visual formats.
Overall Takeaway
Whether modeling a barbershop, simulating a hospital ward, or analyzing dueling taxi fleets, mathematics combined with Python’s open-source libraries reveals insights often missed by guesswork alone. Vince Knight and Geraint Palmer show that even in highly complex or abstract systems, approaching problems with the right balance of math theory and code can unlock powerful, real-world solutions—no expensive tools required.
Links from the show
Book source files: ithub.com
Vince on Twitter: @drvinceknight
Geraint on Twitter: @geraintpalmer
Traces Package: traces.readthedocs.io
A Beautiful Mind: wikipedia.org
Nashpy: github.com
e: The Story of a Number: amazon.com
SymPy episode: talkpython.fm
8451: 8451.com
Stack Overflow Trends: stackoverflow.com
PYCON UK 2017: Python for conducting operational research in healthcare: youtube.com
Ciw package: github.com
Python ternary: github.com
Michael's in-person FastAPI course: maven.com
Reimbursement templates for our courses
Expense a Course at Talk Python: zoho.com
Expense Course Bundle at Talk Python: zoho.com
Expense Cohort Course at Talk Python: zoho.com
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm
--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy