Runoob Tutorial ArchiveEnglish

Algebraic Fundamentals

Algebraic Fundamentals

This chapter introduces the transformation of equations and inequalities, the core concepts of functions, exponential and logarithmic operations, and the summation symbol Σ and series convergence.

The content of this chapter is the common mathematical foundation of sigmoid, softmax, cross-entropy, and information entropy; each knowledge point is accompanied by an interactive image demonstration, and dragging a slider is more intuitive than reading the formula ten times.


Solving and transforming equations and inequalities

Algebraic transformation relies on a single sentence.

If you perform the same operation on both sides of an equation, the equation remains valid.

As long as you treat both sides of an equation "equally" by adding, subtracting, multiplying, or dividing (with a non-zero divisor), or taking the square root (paying attention to signs), the solution of the equation will not change.

Linear Equation

The most basic form is .

Complete steps to solve:

Original prompt (Chinese, left untranslated)



3x + 5 = 20

3x = 20 - 5        ← 两边同减 5(移项)

3x = 15

x = 15 / 3         ← 两边同除以 3

x = 5

There are only two core operations: moving terms (which is essentially subtracting from both sides) and dividing both sides by the same number.

Quadratic Equation and Discriminant

The form is , with two common solution methods.

Method One: Factoring.

Original prompt (Chinese, left untranslated)



x² - 5x + 6 = 0

(x - 2)(x - 3) = 0

→ x = 2 或 x = 3

Solution Two: Quadratic Formula, applicable to all cases but with a larger computational load:

Where $\Delta$ is the discriminant, denoted as $\Delta$, which directly determines the number of roots:

Discriminant Root cases Geometric meaning (parabola and x-axis)
Two distinct real roots The parabola intersects the x-axis at two points
A double root The parabola just touches the x-axis (tangent)
No real roots The parabola is entirely above or below the x-axis

Drag the slider below to change and observe how the parabola's shape and the discriminant are linked.

Interactive demonstration: Discriminant and parabola

Drag the three sliders and observe how the number of intersection points between the parabola and the x-axis changes when the sign of Δ changes.

Substitution of the quadratic formula for solving:

Original prompt (Chinese, left untranslated)



a=1, b=-2, c=-3

Δ = (-2)² - 4×1×(-3) = 4 + 12 = 16

x = (2 ± √16) / 2 = (2 ± 4) / 2

→ x = 3 或 x = -1

Rational equation: Must be checked at the end

First find a common denominator or eliminate the denominator to convert it into a normal equation for solving.

Finally, substitute the solution back into the original equation to verify and ensure the denominator is not 0.

Solutions that make the denominator 0 must be discarded; these are called extraneous roots.

Inequalities: The easiest rule to get wrong.

The rules for transforming inequalities are similar to those for equations, but there is one key difference.

When multiplying (or dividing) both sides of an inequality by a negative number, the direction of the inequality sign must be reversed.

Solution:

Original prompt (Chinese, left untranslated)



-2x > -6       ← 两边同减 6

x < 3          ← 两边同除以 -2(负数,不等号从 > 变成 <)

This rule is very important in machine learning: if the sign is handled incorrectly when deriving the convergence direction of an optimization algorithm or the condition for loss function decrease, the conclusion will be completely reversed.

System of inequalitiesThe solution set must be the intersection of multiple inequality solution sets:

Original prompt (Chinese, left untranslated)



x > 1

x < 5

→ 解集为 1 < x < 5

Common transformation techniques

Technique Method Typical application
Moving terms Moving a term to the other side of the equals sign while changing its sign The fundamental operation for solving all equations
Methods Finding the vertex of a quadratic function and simplifying the loss function derivation
Substitution method Replacing frequently occurring complex subexpressions with a new variable Simplifying structurally complex expressions

Example

Solving a univariate quadratic equation using the discriminant and the quadratic formula

import

math

def

solve_quadratic

(

a

,

b

,

c

)

:

   

"""Solves ax^2 + bx + c = 0, returns all real roots"""

delta

=

b * b -

4

Discriminant Δ = b² - 4ac

   

if

delta

0

:

Δ > 0: two distinct real roots

r

=

math

.

sqrt

(

delta

)

       

return

[

(

-b + r

)

/

(

2

)

,

(

-b - r

)

/

(

2

)

]

   

elif

delta

==

0

:

Δ = 0: a repeated root

       

return

[

-b /

(

2

)

]

   

else

:                      

Δ < 0: No real roots

       

return

[

]

Verify x² - 2x - 3 = 0, the manual calculation result is x = 3 or x = -1

print

(

solve_quadratic

(

1

,

2

,

3

)

)

Case where Δ = 0: x² - 4x + 4 = 0, which is (x-2)² = 0

print

(

solve_quadratic

(

1

,

4

,

4

)

)

Case where Δ < 0: x² + x + 1 = 0

print

(

solve_quadratic

(

1

,

1

,

1

)

)

The output of the above code is:

[3.0, -1.0]

[2.0]

[]

Exercise: Solve the inequality.

Click to view the answer

Subtract 9 from both sides:Divide both sides by -3 (a negative number, so the inequality sign reverses):.


Concept of a function: domain, range, composite function

A function describes a correspondence rule from "input to output":For every input x, there is exactly one corresponding output y..

Written as f(x), read as "y is a function of x".

Domain: the set of all "valid inputs"

Determining the domain is essentially excluding values that make the expression "meaningless":

Expression features Constraint conditions Example
Denominator Cannot be 0
Even root Cannot be negative under the root
Logarithm The real number must be greater than 0

The logarithm is particularly important in AI: wherever log is used (such as in cross-entropy loss), the input must be positive. This is why many code implementations write it as——adding a very small constant ε to preventerrors or the generation of infinity.

Range: The set of all "possible outputs"

The range of is , because the square is always non-negative.

The range of the sigmoid function is the open interval , and will never equal 0 or 1, only approach them infinitely.

This is precisely the mathematical reason it is used to represent "probability": theoretically, probability can approach 0% or 100% infinitely, but never actually equal them.

Composite function: function nested in a function

Writing the output of one function as the input of another function as $f(g(x))$.

The order of calculation isfirst calculate the inner function g(x), then substitute the result into the outer function f$f(g(x))$.

Let $f(x) = x^2$ and $g(x) = 2x+1$, find $f(g(x))$:



f(g(x)) = f(x+1) = (x+1)²

Usually not equal to$g(f(x))$, the order cannot be changed arbitrarily.

Why are composite functions important for AI: Neural networks are essentially a composition of many layers of functions.

A two-layer network can be written as , where is the first layer (linear transformation + activation function), and is the second layer.

The backpropagation algorithm can calculate gradients "layer by layer," relying on the chain rule for differentiation of composite functions (detailed in subsequent calculus courses).

Example

Verification of composite function calculation and "non-commutativity"

def

f

(

x

)

:

   

return

x **

2

         

Outer function f(x) = x²

def

g

(

x

)

:

   

return

x +

1

         

Inner function g(x) = x + 1

f(g(x)): first calculate g(3) = 4, then substitute into f to get 16

print

(

f

(

g

(

3

)

)

)

g(f(x)): first calculate f(3) = 9, then substitute into g to get 10

The two are not equal, which indicates that the order of composition cannot be interchanged

print

(

g

(

f

(

3

)

)

)

The output result of executing the above code is:

16

10

Exercise: Let $a$, $b$, and $c$ be given, find $\sum$ and $\sum$, and compare whether they are the same.

Click to view the answer

The two are different, which means the order of composite functions cannot be interchanged.


Exponential and logarithmic operations

To understand the division of labor of these two functions in one sentence:The exponential function is responsible for "magnifying/compressing the numerical range," and the logarithmic function is responsible for "converting multiplication and division to addition and subtraction, and compressing large-range values into a controllable range.".

They frequently appear in AI loss functions and activation function designs.

AI scenarios Formula Properties used
sigmoid function
softmax function Exponentially amplifies differences, then normalizes into a probability distribution
Cross-entropy loss Logarithm converts "product of probabilities" into "sum of values" to avoid underflow
Information entropy log makes entropy additive

Rules of operations that must be proficient

Exponential operation rules:

Logarithmic operation rules, corresponding one-to-one with exponential rules:

Change of base formula, converting logarithm of any base to natural logarithm:

Exponents and logarithms are mirrors of each other

Exponential function and logarithmic function are inverse functions, and their graphs are symmetric about the line.

Drag the slider to change the base a and observe how the two curves are linked.

Interactive Demonstration: Exponentials and Logarithms as Mirrors

Drag the slider to change the base a; the two curves are always symmetric about the gray dashed line y = x.

Blue is the exponential function y = a^x, green is the logarithmic function y = log_a(x), and the gray dashed line is the axis of symmetry y = x.

Derivation Exercise: Why Cross-Entropy Uses Log

Assume the true label is "cat" (probability of 1), and the model predicts the probability of "cat" as .

If log is not used and we directly use as the loss, when p decreases from 0.5 to 0.1, the loss only increases "linearly," which is not punitive enough.

Use: When (the model is extremely confident but wrong), give extremely severe penalties; when (the judgment is correct), almost no penalty.

This is a direct application of the shape of the logarithmic function "steep near 0 and gentle near 1" in the loss function design; Chapter 2 will specifically demonstrate this curve with an interactive image.

Example

Use code to verify the logarithmic operation rule: log(mn) = log(m) + log(n)

import

math

m

,

n

=

8

,

4

Left: directly calculate log₂(8×4)

left

=

math

.

log

(

m * n

,

2

)

Right: log₂(8) + log₂(4)

right

=

math

.

log

(

m

,

2

)

math

.

log

(

n

,

2

)

print

(

left

)

 

log₂32 = 5

print

(

right

)

 

3 + 2 = 5, both are equal, the rule holds

print

(

abs

(

left - right

)

<

1e-12

)

The output result of the above code is:

5.0

5.0

True

Exercise: Calculate and simplify into a single logarithm using the logarithm rules.

Click to view the answer


Sequences and Series: Understanding Σ and Convergence

A sequence is a set of numbers arranged in order, denoted as , abbreviated as .

Two most basic types of sequences:

Type Features Example General formula
Arithmetic sequence The difference between consecutive terms is constant (common difference d) 2, 5, 8, 11, ... (d=3)
Geometric sequence The ratio between consecutive terms is constant (common ratio r) 2, 4, 8, 16, ... (r=2)

What does the summation symbol Σ actually calculate?

It means: let the index i change from 1 to n, calculate each one, and then add them all up.

Three-step method for reading a Σ formula: first look atthe summation variablewho it is (the index), then look atthe summation range(from where to where), and finally look atWhat each item looks like.

The symbol Σ can almost always be seen in AI formulas, such as mean squared error loss and the weighted sum of neurons.

Two summation formulas: arithmetic progression and geometric progression ().

Series and convergence

A series is the sum of the "infinite terms" of a sequence, i.e. .

If an infinite number of numbers are added together, will the result be infinity? This is the problem of convergence and divergence:

If the cumulative sum approaches aConvergent finite valuesIf the series converges, it is called convergent; if the sum increases indefinitely or has no fixed trend, it is called divergent.

The most classic example is the geometric series:

It converges when |r| < 1, and the sum is 1/(1-r); it diverges when |r| >= 1.

Click the "Play" button to observe how the partial sums gradually approach the limit value.

Interactive Demonstration: The Convergence Process of a Geometric Series

Drag the slider to change the common ratio r, then click "Play" to observe how the partial sums S₁, S₂, ... approach (or move away from) the limit 1/(1-r).

The red dashed line is the theoretical limit 1/(1-r). When |r| approaches 0.9, convergence slows down significantly; if |r| ≥ 1 (the slider in this demo is limited to within 0.9), the series will diverge.

Why convergence is important for AI

In training neural networks, each step of gradient descent can be viewed as a sequence. Whether the weight updates "converge" to a stable value shares intuition with the logic of series convergence.

Certain optimization algorithms (such as the momentum term in Adam) are essentially a weighted exponential decay sum of historical gradients, which mathematically takes the form of a geometric series with a common ratio less than 1.

In Recurrent Neural Networks (RNNs), if a certain multiplication factor is repeatedly multiplied and its absolute value is less than 1, it leads to "vanishing gradients" (corresponding to the series converging to 0); if it is greater than 1, it leads to "exploding gradients" (corresponding to the series diverging). This is a classic problem in deep learning, and its root lies in the intuition of geometric sequences.

Example

Observe the process of the partial sum of a geometric series approaching the limit: r = 0.5

Theoretical limit: 1 / (1 - 0.5) = 2

r

=

0.5

limit

=

1

/

(

1

)

     

Theoretical limit value 2

s

=

0

                   

Partial sum, accumulate starting from 0

for

i

in

range

(

6

)

:

Cumulative summation: 1 + 0.5 + 0.25 + ...

s +

=

r ** i

   

print

(

i +

1

,

s

)

     

Print the number of items and the current partial sum

print

(

limit

)

           

The theoretical limit, the partial sum gets closer and closer to it

The output result of the code above is:

1 1.0

2 1.5

3 1.75

4 1.875

5 1.9375

6 1.96875

2.0

You can see that with each added term, the gap to the limit is halved—this is the convergence rhythm of a geometric series with a common ratio of 0.5.

Exercise: Determine if a series converges, and if it converges, find its sum.

Click to view the answer

Common ratio, satisfies, converges.


Chapter summary

Topic One-sentence core
Equations and inequalities Perform the same operation on both sides; the inequality sign must be reversed when multiplying/dividing by a negative number
Function concept Domain is "what can be input," range is "what can be output," and composite function is "function nested in a function"
Exponents and logarithms Exponents magnify/compress values, and logarithms convert multiplication/division to addition/subtraction—the core tool of AI loss functions
Sequences and Series Σ is "summing according to a rule"; whether the series converges determines whether model training is stable