What Are Numbers, Really? A Gentle Dive into Number Theory, Mathematics with Python

Mathematics with Python

Numbers are everywhere. From managing finances to analyzing data, we constantly interact with them. But what exactly are numbers?

In this post, we’ll explore the beautiful journey of numbers through number theory, and bring it all together with a Python program that showcases each type of number in action.

The Evolution of Numbers

Natural Numbers

Natural numbers are the first we learn: 1, 2, 3…

0️⃣ Whole Numbers

Add zero to natural numbers and you get whole numbers.

➕➖ Integers

Integers include negative numbers, zero, and positive numbers.

Rational and Irrational Numbers

➗ Rational Numbers

Rational numbers can be expressed as fractions or finite decimals.

Irrational Numbers

These cannot be expressed exactly as fractions.

Real, Complex, and Imaginary Numbers

Real Numbers

Real numbers include both rational and irrational numbers.

Complex and Imaginary Numbers

Python can handle imaginary numbers using j as the imaginary unit.

Full Code Summary

Here’s the entire code block you can run in any Python environment:

Understanding Order of Operations and Variables in Python

When working with math or code, knowing how expressions are evaluated and how to use variables is crucial. In this post, we’ll walk through these two foundational ideas with real examples in Python. Whether you’re a beginner or brushing up, you’ll walk away with a clearer understanding.

Order of Operations (PEMDAS)

Remember PEMDAS?

Parentheses → Exponents → Multiplication → Division → Addition → Subtraction

This is the standard way to evaluate mathematical expressions. Python follows this order too!

Example:

Let’s evaluate this expression step-by-step:

Step-by-step breakdown:

  1. Parentheses: (3 + 2)5

  2. Exponents: 5**225

  3. Multiplication: 2 * 2550

  4. Division: 50 / 510.0

  5. Subtraction: 10.0 - 46.0

✅ Python Code Example 1:

Use Parentheses for Clarity

Even if Python follows PEMDAS, using extra parentheses makes your code easier to read and maintain.

✅ Python Code Example 2 (clearer):

Pro Tip: When in doubt, use parentheses to group parts of your expression clearly!

What Are Variables?

A variable is a name that stores a value. It could be a number, a word, or even a list. In math, we often use letters like x, y, or z. In Python, you can name your variables almost anything—just follow the rules!

✅ Example: Getting user input and using a variable

If you input 5, Python multiplies it by 3 and prints:

Naming Variables in Python

Some math variables have Greek names like θ (theta) or β (beta). Since Python doesn’t support Greek characters easily, we name them like this:

✅ Example:

Subscripted Variables (x₁, x₂, x₃)

In math, you might see variables with subscripts (e.g. x₁, x₂, x₃). In Python, you can use underscores for that:

✅ Example:

Output:

Wrapping Up

Understanding order of operations and how to use variables are foundational in both math and Python. Here’s the combined final example with everything we discussed:

✅ Final All-in-One Python Code:

What is a Function?

A function defines a relationship between input variables (independent variables) and an output variable (dependent variable).
Mathematically, this is often written as:

Working with Functions in Python

Linear Function Example

This prints:

Continuous Functions

Unlike using only whole numbers (0, 1, 2, …), real functions allow infinitely many inputs (e.g., 0.1, 0.01, 0.001), making the function continuous.
For example:

x y = 2x + 1
0.0 1
0.5 2
1.0 3
1.5 4
2.0 5

Visualizing Functions (Graphing)

We can use SymPy, a symbolic math library in Python, to plot functions.

Linear Function

Exponential Function (Parabola)

This creates a curve, not a straight line. Curves like these are called curvilinear functions.

Functions with Two Variables

You can define functions of two independent variables, like:

This requires 3D plotting:

Key Concepts

Concept Meaning
Function A rule that maps input(s) to a single output.
Independent variable Input variable (like `x`)
Dependent variable Output (like `y` or `f(x)`)
Continuous function A function where you can plug in infinitely small steps.
Curvilinear function A continuous but non-linear function (e.g., parabolas)
SymPy A Python library for symbolic math and graphing.

What Is a Summation?

A summation is a mathematical operation represented by the Greek letter sigma (Σ). It tells you to add a bunch of terms together.

Basic Summation Using a Loop in Python

Let’s say you want to multiply each number from 1 to 5 by 2, and add all the results:

  • range(1, 6) gives numbers 1 through 5 (6 is not included).

  • Each number i is multiplied by 2.

  • sum() adds them all together.

Summing List Values After Multiplying Each by 10

Suppose you have a list of numbers:

You want to multiply each number by 10, then sum the result:

  • Loop through each value in the list x.

  • Multiply it by 10.

  • Add all results using sum().

Using Indexes (0-based like Python usually does)

If you need to use indexes explicitly:

Using SymPy for Symbolic Summation

Install SymPy if you don’t have it:

Now use it in Python:

  • Sum() creates a symbolic summation.

  • .subs(n, 5) sets the upper limit.

  • .doit() evaluates the result.

Mastering Exponents in Algebra with Python

Exponents are a fundamental concept in mathematics, especially in algebra. They represent repeated multiplication and are essential for working with polynomials, equations, and even in advanced topics like calculus and machine learning.

In this post, we’ll explore the core rules of exponents, simplify expressions using Python’s SymPy library, and even deal with fractional and irrational exponents.

What Are Exponents?

An exponent tells you how many times to multiply the base number by itself.

For example:

Output:

 

  • Base: 2

  • Exponent: 3

  • Result: 8

Key Properties of Exponents

Let’s explore the most important exponent rules with both algebraic explanation and Python code.

1. Product Rule:

Algebra:


2. Quotient Rule:

Output:

3. Zero Exponent Rule:

Output:

Explanation:

Any non-zero number raised to the power of 0 is 1.

Python Code:

4. Negative Exponent Rule:

Output:

Python Code:

5. Power of a Power Rule:

Output:

Python Code:

Fractional Exponents = Roots

Fractional exponents represent roots.

Square Root:

Output:

Cube Root:

Output:

Python Code:

Multiplying Roots:

Output:

What About Irrational Exponents?

Even irrational numbers like π can be used as exponents:

Output:

Computers handle irrational numbers like π by approximating them using many decimal places.

Recap of Exponent Rules

Product Rule   $x^a \cdot x^b = x^{a+b}$   $x^2 \cdot x^3 = x^5$
Quotient Rule   $\frac{x^a}{x^b} = x^{a-b}$   $\frac{x^2}{x^5} = x^{-3}$
Zero Exponent   $x^0 = 1$   $5^0 = 1$
Negative Exponent   $x^{-a} = \frac{1}{x^a}$   $x^{-2} = \frac{1}{x^2}$
Power Rule   $(x^a)^b = x^{ab}$   $(2^3)^2 = 2^6$
Fractional Exponent  $x^{1/n} = \sqrt[n]{x}$   $27^{1/3} = 3$

Understanding Logarithms in Python: A Powerful Math Function for Data and Beyond

Logarithms may sound like a topic reserved for dusty math books, but they are incredibly useful—especially in fields like data science, machine learning, cryptography, and even audio processing.

Let’s explore logarithms step by step, including how to use them in Python, and how they relate to exponents.

What Is a Logarithm?

A logarithm answers the question:

“To what power must we raise a number (base) to get another number?”

For example:

What power of 2 gives us 8?

Mathematically:

To solve for x, we rewrite this using logarithm notation:

Since 2³ = 8, the answer is:

General Form of a Logarithm

Where:

  • a is the base

  • b is the result

  • x is the exponent

Calculating Logarithms in Python

Let’s see how to compute logs in Python:

✅ Example 1: Base 2 Logarithm

✅ Example 2: Natural Logarithm (base e)

If no base is provided, Python defaults to base e, known as Euler’s number, common in scientific and statistical calculations.

Key Properties of Logarithms

Understanding how logarithms behave is important for simplifying expressions.

Multiplication (Product Rule)  $x^m \cdot x^n = x^{m+n}$  $\log_b(ab) = \log_b(a) + \log_b(b)$
Division (Quotient Rule) $\frac{x^m}{x^n} = x^{m-n}$  $\log_b\left(\frac{a}{b}\right) = \log_b(a) – \log_b(b)$
Power of Power Rule $(x^m)^n = x^{mn}$  $\log_b(a^n) = n \cdot \log_b(a)$
Zero Power Rule  $x^0 = 1$  $\log_b(1) = 0$
Negative Exponent (Inverse)  $x^{-1} = \frac{1}{x}$  $\log_b\left(\frac{1}{x}\right) = -\log_b(x)$

Using SymPy for Log Simplification

The sympy library is great for algebraic manipulations.

✅ Example: Algebraic simplification

Bonus: Logarithms with Irrational Exponents

What if you wanted to compute something like 8^\pi \approx 687.2913?

Internally, Python uses rational approximations for irrational numbers to compute results like this.

Logarithms Undo Exponents

Logarithms are the inverse of exponentiation.

For example:

Summary

  • Logarithms answer the question: “What power of a base gives a number?”

  • Python uses math.log() for both base-e and base-n logs.

  • The sympy library can symbolically simplify log expressions.

  • Logarithms obey similar rules as exponents: they simplify multiplication, division, and powers.

Real-Life Applications of Logarithms

  • Earthquake magnitude (Richter scale)

  • Sound decibel levels

  • Machine learning models like logistic regression

  • Data transformation (log-normal distributions)

  • Finance for calculating compound interest

Coming Up Next

In the next post, we’ll explore Euler’s number (e) and how it’s used in natural logarithms and exponential growth in machine learning and data science.

Leave a Reply

Your email address will not be published. Required fields are marked *

Home
Courses
Services
Search