Speaker 1: So I want you to think back to high school
Speaker 1: math for a second. Oh boy, right, just picture it.
Speaker 1: You're sitting at this tiny, uncomfortable desk. You've got a
Speaker 1: yellow number two pencil in your hand, and you're just
Speaker 1: staring down at this massive page of complex equations, endless
Speaker 1: rows of them, exactly, and the expectation was that you'd
Speaker 1: solve them all completely by hand, just grinding through the
Speaker 1: arithmetics step by tedious step.
Speaker 2: Yeah, which is I mean, it's the equivalent of being
Speaker 2: asked to dig the foundation for a brand new house,
Speaker 2: but the only tool you're given is a teaspoon.
Speaker 1: A teaspoon.
Speaker 2: Yeah. You spend so much energy on the sheer physical
Speaker 2: labor of moving the dirt that you completely lose sight
Speaker 2: of the architectural principles behind the house you're trying to build.
Speaker 1: The labor just completely distracts you from the actual architecture.
Speaker 1: And well, that is exactly why A Met SAHA's book
Speaker 1: Doing Math with Python is such a crucial stack of
Speaker 1: source material for us today.
Speaker 2: It really is.
Speaker 1: We're looking at how coding acts as the ultimate shark
Speaker 1: to mathematical fluency. The mission of this deep dive is
Speaker 1: to see what happens when you put down that teaspoon
Speaker 1: and bring in a bulldozer instead.
Speaker 2: I love that analogy.
Speaker 1: Right, You outsource the arithmetic to this eager digital assistant,
Speaker 1: which frees up your cognitive load to build complex simulations
Speaker 1: and uncover hidden patterns.
Speaker 2: It represents a fundamental paradigm shift in how we approach numbers.
Speaker 2: You transition from being a biological calculator, which, let's be honest,
Speaker 2: humans are frankly terrible.
Speaker 1: Are we really are? We make so many tiny mistakes exactly.
Speaker 2: You go from that to being a mathematical director. You're
Speaker 2: orchestrating the logic while the machine handles the brute force.
Speaker 1: But to wield that bulldozer, you know, you have to
Speaker 1: learn how to speak the machine's language first. And Python
Speaker 1: for all its flexibility, well, it requires strict mathematical hygiene.
Speaker 2: Yeah, very strict.
Speaker 1: We aren't just talking about basic arithmetic order of operations
Speaker 1: here like pemdas. We are talking about how the language
Speaker 1: fundamentally categorizes data, right.
Speaker 2: Because to a human mind, and the number three is
Speaker 2: just it's just the concept of three. Sure, whether it's
Speaker 2: written as a single digit or three point zero, or
Speaker 2: as a fraction like three over one. Our brains process
Speaker 2: it is the exact same mathematical value, but Python allocates
Speaker 2: memory and operations differently depending on this specific type of data.
Speaker 1: Python distinguishes really strictly between an integer, which is an
Speaker 1: inlet like three, and a floating point number, so a
Speaker 1: float like three point.
Speaker 2: Zero, right.
Speaker 1: And I think a lot of people initially view this
Speaker 1: as Python just being pedantic. You write a script, you
Speaker 1: expect a whole number, a user inputs a decimal, and
Speaker 1: the whole program just.
Speaker 2: Crashes, It just halts.
Speaker 1: It feels like you are dealing with a highly skilled
Speaker 1: but entirely literal minded chef. Like if a recipe calls
Speaker 1: for a whole egg and integer and you hand them
Speaker 1: a scrambled egg afloat, they won't know what to do
Speaker 1: and they'll just throw a fit.
Speaker 2: That's a great way to put it, And that fit
Speaker 2: Python throws is what we call an exception, right and exception.
Speaker 2: What's fascinating here is that this strict type casting is
Speaker 2: actually a brilliant enforcer of mathematical rigor. Python gets even
Speaker 2: more granular than just integers and floats. Actually, oh really,
Speaker 2: like how well you can work with explicit fractions using
Speaker 2: the format fraction three four, and it even handles complex
Speaker 2: numbers natively.
Speaker 1: Wait, complex numbers like with imaginary parts.
Speaker 2: Yeah, it uses J instead of I, so you'll see
Speaker 2: outputs like two plus three J right there in the console.
Speaker 1: Wow, which is an incredible powerful feature for you know,
Speaker 1: engineering and physics applications.
Speaker 2: Absolutely, But the.
Speaker 1: Friction always happens at the point of user input, doesn't it.
Speaker 1: When you ask a user to type a variable into
Speaker 1: your program, Python reads that input as a string of
Speaker 1: text by.
Speaker 2: Default, right, It sees the character three fight not the
Speaker 2: mathematical value.
Speaker 1: Of three, So the programmer has to explicitly convert that
Speaker 1: text string into the correct mathematical type.
Speaker 2: And if you mismanage that conversion, you trigger one of
Speaker 2: those exceptions. I mean, if the user inputs a fraction
Speaker 2: string like thirty four and your code blindly tries to
Speaker 2: cast that directly into an integer, Python raises value.
Speaker 1: Air it just panics exactly.
Speaker 2: Or if you're annoying formula inadvertently allows a zero to
Speaker 2: slip into the denominator of a calculation, you trigger a
Speaker 2: zero division error.
Speaker 1: I want to look closely at how the source material
Speaker 1: handles this, because using these try accept blocks in Python
Speaker 1: to manage these errors. It isn't just a band aid
Speaker 1: for bad user.
Speaker 2: Input, No, not at all.
Speaker 1: It forces you to rigorously define the mathematical parameters of
Speaker 1: your environment. You're actively building the domain restrictions of your function.
Speaker 2: That is the perfect way to frame it. Anticipating a
Speaker 2: zero division error means you have to deeply understand the
Speaker 2: assymp totes right, and the undefined behavior of the formula
Speaker 2: you're modeling.
Speaker 1: You have to know where the math breaks.
Speaker 2: Yes, you have to teach the computer how to handle
Speaker 2: mathematical impossibilities gracefully. Working through those exceptions builds a structural
Speaker 2: understanding of mathematical rules that is just It's far deeper
Speaker 2: than just skipping over a tricky problem on a paper worksheet.
Speaker 1: So once we've established these strict guard rails and define
Speaker 1: mathematical domains, the real power of the language unlocks. We
Speaker 1: move from executing single isolated commands to automating the.
Speaker 2: Tedium because why do the same thing twice?
Speaker 1: Right. Once you can communicate the logic of a calculation
Speaker 1: to Python perfectly, there is absolutely no reason to ever
Speaker 1: do that calculation by hand again.
Speaker 2: And this is where we start utilizing loops by pairing
Speaker 2: a four loop with a range function, you shift your
Speaker 2: focus from finite problem solving to infinite generation.
Speaker 1: So instead of calculating a single multiplication problem, you just
Speaker 1: instruct Python to generate endless multiplication tables in like a
Speaker 1: fraction of a.
Speaker 2: Second, exactly, you can write a loop that calculates all
Speaker 2: the factors of a massive multi digit integer almost instantly.
Speaker 1: Think about the application for unit conversion two. The text
Speaker 1: uses the example of comparing a temperature of eighty six
Speaker 1: degrees fahrenheit against three zho three point one five kelvin.
Speaker 2: Which is mathematically impossible to analyze in its raw state.
Speaker 1: Right, it's apples and oranges.
Speaker 2: Yeah, I have to mathematically standardize the space before any
Speaker 2: logical comparison can occur. Soe.
Speaker 1: You write a quick Python script that asks the user
Speaker 1: for the value, applies the appropriate conversion formula, and spits
Speaker 1: out the standardized result.
Speaker 2: It does the heavy lifting for you.
Speaker 1: But okay, let's unpack this. The source material spends significant
Speaker 1: time detailing how to program the quadratic formula. We're talking
Speaker 1: about finding the roots for the classic algebra equation x
Speaker 1: squared plus b x plus c equals zero.
Speaker 2: Right, A staple of high school math.
Speaker 1: Yeah, and it breaks down the process systematically, first calculating
Speaker 1: the discriminate ah.
Speaker 2: The D equals B squared minus four x.
Speaker 1: Part yes, that portion of the formula, and then using
Speaker 1: that isolated value to find the two roots.
Speaker 2: And it leverages that native complex number support we mentioned
Speaker 2: earlier too.
Speaker 1: Right, Like if you enter one one in one for
Speaker 1: the A, B, and C variables, Python doesn't panic because
Speaker 1: the discriminant is negative.
Speaker 2: No, it just calmly outputs complex roots like negative point
Speaker 2: five plus point eight sixt six. J.
Speaker 1: It's so cool, But uh, I have to play the
Speaker 1: devil's advocate for a second here. Sure, go for it
Speaker 1: if you're a student, isn't writing a quadratic equation solver
Speaker 1: just a highly engineered way to cheat at your homework?
Speaker 1: I mean, you plug in the variables, the machine gives
Speaker 1: you the answer, and you learn nothing about the actual math.
Speaker 2: Well, if we connect this to the bigger picture, writing
Speaker 2: this solver algorithm requires a significantly higher level of mathematical
Speaker 2: mastery than just executing the formula.
Speaker 1: On paper, because you are building the architecture, not just
Speaker 1: turning the crank.
Speaker 2: Precisely when you solve a single quadratic equation on paper,
Speaker 2: you're just plugging numbers into a pre existing machine. But
Speaker 2: by programming the quadratic formula, you aren't solving a single equation.
Speaker 1: You're solving all of them.
Speaker 2: Yes, you are teaching a machine how to solve every
Speaker 2: quadratic equation in existence. You have to break the formula
Speaker 2: down into his constituent logical components, define the variables, handle
Speaker 2: the discriminate operation separately, and.
Speaker 1: Account for those complex route pathways if the number goes
Speaker 1: negative exactly.
Speaker 2: That requires a level of algorithmic master read that goes
Speaker 2: far beyond just plugging numbers into a test.
Speaker 1: You're stepping out of the role of the calculator and
Speaker 1: into the role of the mathematician. You really are, but
Speaker 1: you know, building an algorithmic engine that can spit out
Speaker 1: thousands of complex roots or endless multiplication tables, it introduces a.
Speaker 2: New problem, beta overload.
Speaker 1: Staring at a terminal window scrolling with thousands of calculated
Speaker 1: integers is completely useless to the human brain. To actually
Speaker 1: understand data at that scale, we have to stop reading
Speaker 1: numbers and start looking at shapes.
Speaker 2: Which brings us to data visualization. Specifically, the map plot
Speaker 2: lib package and Python and its pipe plot module.
Speaker 1: Yes, this is how we map those massive arrays of
Speaker 1: numbers onto a Cartesian coordinate plane.
Speaker 2: The source material uses a brilliant, highly relatable example to
Speaker 2: demonstrate this. Actually, it uses historical temperature data from Central
Speaker 2: Park in New York City.
Speaker 1: Oh right, the data set tracking the average annual temperatures
Speaker 1: between the years twenty twenty twelve.
Speaker 2: Yeah, and it's a relatively small data set, just thirteen
Speaker 2: data points, ranging from a low of fifty three point
Speaker 2: nine degrees to a high of fifty seven point three
Speaker 2: degrees fahrenheit.
Speaker 1: Now, if you just look at that data in a spreadsheet,
Speaker 1: it's just a block of text. It's totally static.
Speaker 2: Just numbers on a screen.
Speaker 1: But when you feed that array into matt plotlib, you
Speaker 1: map the years onto the x axis and the temperatures
Speaker 1: onto the y axis. The text even shows how you
Speaker 1: can layer the monthly temperature data for multiple specific years,
Speaker 1: say two thousand and twenty six and twenty twelve, all
Speaker 1: onto the exact same graph.
Speaker 2: Right. You assign different colors to each tear's line. You
Speaker 2: generate a legend so the viewer knows what they're looking at.
Speaker 1: You define the title and the axis labels.
Speaker 2: And suddenly the deity yields a narrative. You can visually
Speaker 2: identify these distinct sharp peaks occurring every July across all
Speaker 2: three years.
Speaker 1: It immediately transforms raw numbers into a clear story about
Speaker 1: seasonal variance and historical warming trends.
Speaker 2: It's incredibly satisfying to see.
Speaker 1: But here's where it gets really interesting, and the book
Speaker 1: highlights a major trap in data visualization that programmers fall
Speaker 1: into all the time.
Speaker 2: The scaling issue.
Speaker 1: Yes, when you feed that initial annual Central Park data
Speaker 1: into matplot lib and rely on the default settings, the
Speaker 1: resulting graph looks like a violent, dramatic roll and coaster
Speaker 1: of extreme temperature shifts.
Speaker 2: The visual spikes and drops appear massive, almost catastrophic.
Speaker 1: Really, but it's an optical illusion. The software automatically optimizes
Speaker 1: the visual variants by zooming the y axis in incredibly
Speaker 1: tightly around the data.
Speaker 2: Right, it tries to fill the space exactly.
Speaker 1: The bottom boundary of the graph defaults to fifty three
Speaker 1: point zero degrees and the top boundary is set just
Speaker 1: above fifty seven point five degrees. It takes a relatively
Speaker 1: narrow four degree band of variants and stretches it vertically
Speaker 1: to fill the entire visual field.
Speaker 2: This raises an important question about modern data literacy. Honestly,
Speaker 2: when media outlets or social media platforms publish charts, they
Speaker 2: frequently rely on or intentionally exploit these exact default scaling behaviors.
Speaker 1: Happens all the time.
Speaker 2: If you don't understand how a graph is constructed underneath
Speaker 2: the hood, you're entirely at the mercy of the person
Speaker 2: who generated it.
Speaker 1: They can manipulate the axis boundaries to make a minor
Speaker 1: statistical fluctuation look like an unprecedented crisis.
Speaker 2: Or conversely, they can flatten a massive change into a
Speaker 2: straight line by zooming out too far.
Speaker 1: So the defense mechanism here has to be taking manual
Speaker 1: control of those visual boundaries. Does the text use the
Speaker 1: axis function to just pin that y axis down to
Speaker 1: a baseline of zero.
Speaker 2: It does by explicitly coding the parameter i'men equal zero.
Speaker 2: The programmer overrides that default zoom.
Speaker 1: And the roller coaster immediately flattens out exactly.
Speaker 2: The dramatic, terrifying spikes are contextualized against absolute zero, and
Speaker 2: they become a gentle, much more realistic ripple at the
Speaker 2: very top of the graph.
Speaker 1: It proves that learning to code your own graphs is
Speaker 1: a vital active defense against being misled by manipulated statistics
Speaker 1: in the real world.
Speaker 2: You know how the trick is performed, so you can't
Speaker 2: be fooled by the.
Speaker 1: Prestige That is such a critical critical thinking skill. So
Speaker 1: we've successfully modeled static historical data, and we've learned to
Speaker 1: defend against statistical illusions. But the ultimate test of mathematical
Speaker 1: fluency is moving from static numbers to dynamic systems.
Speaker 2: Stepping out of statistics and into the physical laws of
Speaker 2: the universe.
Speaker 1: Yes, modeling physics using mathematical formulas in Python is where
Speaker 1: the language truly acts as a sandbox for reality. A
Speaker 1: foundational example from the text is plotting Newton's law of
Speaker 1: universe gravitation AH.
Speaker 2: The classic formula F equals G times M one times
Speaker 2: m two all divided by R squared right.
Speaker 1: It calculates the gravitational force between two bodies based on
Speaker 1: their masses and the distance between them, and the.
Speaker 2: Script provided in the book generates an array of distances
Speaker 2: iterating from one hundred meters all the way up to
Speaker 2: one thousand meters.
Speaker 1: When you plot that resulting gravitational force against those increasing distances.
Speaker 1: You don't just see a list of decreasing numbers. You
Speaker 1: visually prove the inverse proportional nonlinear relationship.
Speaker 2: The inverse square law.
Speaker 1: Yes, you get this perfect sweeping asymptotic curve on the
Speaker 1: graph that visually demonstrates how rapidly gravity weakens as the
Speaker 1: objects move apart.
Speaker 2: It's a nonlinear decay, and seeing the shape of that
Speaker 2: decay makes the physics intuitive in a way equations sometimes aren't.
Speaker 1: It completely bridges the gap between the algebraic formula and
Speaker 1: the physical reality it describes.
Speaker 2: But the absolute zenith of this modeling conceptually has to
Speaker 2: be the projectile motion simulation.
Speaker 1: Oh I love this part so much. This brings literally
Speaker 1: everything we've talked about algebra, trigonometry, loops, and visualization into
Speaker 1: one single script.
Speaker 2: It's the grand finale picture this.
Speaker 1: You throw a ball with an initial velocity of five
Speaker 1: meters per second, launched at exactly a forty five degree angle.
Speaker 2: Okay, so first you have to use trigonometry, the math
Speaker 2: dot cos and math dot sin functions to break that
Speaker 2: single velocity vector into its horizontal and vertical components.
Speaker 1: Right, because it's moving up and forward at the same time, wow,
Speaker 1: and applying the constant of graph pulling it down at
Speaker 1: an acceleration of nine point eight meters per second squared.
Speaker 1: The basic high school physics formula tells us the total flight.
Speaker 2: Time the ball will hit the ground in exactlyer point
Speaker 2: seven to two one five four seconds.
Speaker 1: But knowing the final destination isn't the goal here. We
Speaker 1: want to map the entire journey.
Speaker 2: We want to see the arc.
Speaker 1: So the script utilizes a wile loop to calculate the
Speaker 1: ball's exact X and y coordinates at microscopic intervals. Specifically,
Speaker 1: every zero point zero zero one seconds of that.
Speaker 2: Flight wow, every millisecond.
Speaker 1: Every millisecond, it calculates the horizontal distance traveled in that millisecond.
Speaker 1: It calculates the vertical drop caused by gravity in that millisecond,
Speaker 1: plots the dot and repeats.
Speaker 2: It runs that calculation hundreds of times until the vertical
Speaker 2: coordinate hits zero.
Speaker 1: It is essentially the exact underlying physics engine for a
Speaker 1: video game like Angry Birds.
Speaker 2: That's a perfect analogy.
Speaker 1: You are creating a digital sandbox where you map out
Speaker 1: exactly where a physical object exists in space millisecond by millisecond.
Speaker 2: What's fascinating. Here is how this loop bridges the continuous
Speaker 2: and the discrete. I mean, in physical reality, the ball's
Speaker 2: flight is a continuous, unbroken arc, but computers can only
Speaker 2: process discrete, quantified steps. By looping the calculation every point
Speaker 2: zero zero one seconds, you're essentially performing rudimentary numerical integration.
Speaker 1: You're slicing continuous time into tiny calculable slivers to approximate
Speaker 1: reality exactly.
Speaker 2: The smaller the time step, the closer your digital simulation
Speaker 2: gets to the true continuous curve of the physical world.
Speaker 1: It's just incredible. I mean, you are predicting the future
Speaker 1: path of an object through space and time using nothing
Speaker 1: but logic loops and high school math.
Speaker 2: It transforms mathematics with an abstract exercise on a chalkboard
Speaker 2: into a tangible mechanism for literally simulating reality. It's a superpower,
Speaker 2: it really is.
Speaker 1: Well, we have covered massive ground today, so let's synthesize
Speaker 1: the journey we just took through Amitsaha's work.
Speaker 2: Let's do it.
Speaker 1: We started by exploring Python's strict mathematical hygiene right learning
Speaker 1: how casting types and defining exceptions like value errors forces
Speaker 1: us to truly understand the boundaries and domains of our formulas.
Speaker 2: We used loops to automate algebraic algorithms, realizing that writing
Speaker 2: a quadratic solver is about architecting logic, not just finding
Speaker 2: a quick answer.
Speaker 1: We expose the visual illusions hidden inside default data visualizations,
Speaker 1: and finally, we sliced continuous time into discrete loops to
Speaker 1: literally simulate the physical laws of the universe.
Speaker 2: And for you listening, whether you're aggressively prepping for a
Speaker 2: highly technical engineering role or you're simply deeply curious about
Speaker 2: the architecture of the digital world, Adopting Python is a
Speaker 2: mathematical tool represents a massive paradigm.
Speaker 1: Shift that acts as a lever.
Speaker 2: Yes, it lifts the exhausting mechanical burden of calculation off
Speaker 2: your shoulders, allowing your intellect to focus entirely on raw innovation,
Speaker 2: pattern recognition, and complex problem solving.
Speaker 1: So what does this all mean? We started this deep
Speaker 1: dive talking about the sheer physical exhaustion of digging a
Speaker 1: foundation with a teaspoon. But if computers can now seamlessly
Speaker 1: handle all the grunt work of executing complex mathematical formulas
Speaker 1: and physics simulations.
Speaker 2: In a fraction of a second, no less right.
Speaker 1: In milliseconds, will the future of human mathematics look less
Speaker 1: and less like tedious calculation and more like pure philosophy
Speaker 1: and art, something for you to maul over next time
Speaker 1: you reach for that yellow number two pencil