Symbolic Operation Ability

In previous chapters, we learned various rules and concepts. In this chapter, we will examine yourproficiency, and see whether you can derive the formulas yourself.

This ability directly determines whether you can follow the derivations in a paper, rather than getting stuck where the author skips steps. Every knowledge point is accompanied by interactive demonstrations, especially the geometric split animation of (a+b)², which makes it clear in one viewing where the "cross term 2ab" comes from.


Why "Symbolic Operation Ability" Matters

When reading papers, you often encounter this situation: the author writes "after simplification, we obtain...", skipping three to five steps in between.

If your symbolic manipulation is not fluent enough, these skipped steps will directly keep you out of the door.

If you are fluent, you can fill in these steps yourself and truly "keep up with" the author's reasoning, rather than passively accepting the conclusion.

For the same rule, "knowing it" and "being able to use it fluently with your eyes closed" are two levels of ability. This chapter trains the latter.


From (a+b)² to Multivariate Expansion

The Most Basic Identity

Geometric Perspective: Why There's an Extra "2ab"

holdThink of it as "the area of a square with side length a+b", and cut this square into 4 pieces:

RegionShapeArea
Top-left cornerSquare with side length a
Top-right cornerRectangle with length b and width a
Bottom-left cornerRectangle with length a and width b
Bottom-right cornerSquare with side length b

Adding up the four areas。

This "2ab" doesn't appear out of thin air; it comes from the two crossed rectangles. Click the "Expand" button below to see how the four areas separate.

Interactive demo: geometric dissection of (a+b)²
Drag the slider to change the ratio of a and b (total side length fixed to 4), click "Expand" to see the square cut into four parts, then click "Restore" to put it back together.
The separation animation in the expanded state is driven by CSS transition. a² ab ab b² Side length labela = 2.5 b = 1.5 Large square with side length (a+b) Cut into 4 pieces: a² + ab + ab + b² The cross term 2ab comes from two green rectangles.

Generalizing to Three Variables

According to the rule that "every pair of variables produces a cross term", you can directly write:

Derivation logic: treatas, and multiply each term with each term pairwise when expanding.

Multiplying identical variables gives the square term (), multiplying different variables occurs twice (e.g.,and), after combining we get。

Generalizing to Vectors

This rule repeatedly appears in vector operations in another form, e.g., computing the squared norm of the difference of two vectors:

The essence is to replace the"numbers" inside with "vectors", and "multiplication" with "dot product".

When you see a similar expansion in a paper, you can directly recall the rule learned here—new formulas are often old rules in a new guise. This is exactly how "symbolic manipulation ability" helps you "see through" new formulas.

Examples

# Numerical verification of identities: a good habit for checking whether you have misremembered a formula
# Idea: plug in a few random numbers and see if both sides of the equation are equal.

for a, b in [(2, 3), (5, 1), (0.5, 2.5), (-1, 4)]:
    lhs = (a + b) ** 2                 # Left side: (a+b)²
    rhs = a ** 2 + 2 * a * b + b ** 2  # Right side: a² + 2ab + b²
    print(a, b, abs(lhs - rhs) < 1e-12)

# Also verify the vector version: ‖x - y‖² = ‖x‖² - 2x·y + ‖y‖²
import math
x, y = (3, 4), (1, 2)
lhs = (x[0]-y[0])**2 + (x[1]-y[1])**2
rhs = (x[0]**2 + x[1]**2) - 2*(x[0]*y[0] + x[1]*y[1]) + (y[0]**2 + y[1]**2)
print(abs(lhs - rhs) < 1e-12)

Running the above code outputs:

2 3 True
5 1 True
0.5 2.5 True
-1 4 True
True

This "random substitution verification" method is very practical: when you forget formula details, plugging in a few numbers can confirm whether the version you remember is correct.

Exercise: expandand。

Click to see the answer

Separately substituteandintoand you're done.


Simplification, Transformation, Completing the Square

Completing the Square: Turning the General Form into "Vertex Form"

The goal of completing the square is to turnthis kind of "missing a piece" expression into a complete square:

Example: complete the square forto get。

Verification: expand, they are indeed equal.

Two typical uses of completing the square:

UseMethodExample
Find the vertex of a quadratic functionSee the vertex (-3, -7) directly, no need to graph or differentiate
Complete the square to simplify the derivationTurn a complex polynomial into a square term by completing the squareIntermediate steps in least squares and maximum likelihood estimation for the normal distribution
Interactive demonstration: completing the square and the vertex
Drag the slider to change b, observe how the vertex of the parabola y = x² + bx moves, and how the x-coordinate of the vertex is always equal to -b/2.

General Approach to Simplification

When encountering a complex expression, usually try in this order:

OrderTechniqueExplanation
1Combine like termsCombine terms with the same variable exponents
2Factor out common factorsFind the factors common to all terms and pull them out
3Use identitiesApply、such as ready-made formulas
4SubstitutionReplace recurring complex sub-expressions with a new variable

Example of substitution method: Simplify。

令 t = x² + 1
原式 = t² - 3t + 2 = (t-1)(t-2)
代回 t:
     = (x²+1-1)(x²+1-2)
     = x² · (x²-1)
     = x⁴ - x²

Whether You Can Derive Formulas Yourself Is the Watershed

"Understanding" and "Being Able to Derive" Are Two Different Levels of Ability

LevelDescription
Can read and understandWhile looking at the derivation steps, you can understand "why this step is valid"
Can deriveClose the book and you can walk through those steps yourself

Many people get stuck on reading papers, not because of "new knowledge", but because of this level: the formulas use only rules from the first three chapters, but you need to organize the correct sequence of steps yourself without hints.

Complete Derivation Exercise: The Minimum of Mean Squared Error

Problem: Given n data points, find a constant c such that the "sum of squared distances" from all points to cis minimized; find the optimal c.

Derivation process:

设 f(c) = Σᵢ (xᵢ - c)²

展开每一项(用到 (a-b)² 公式):
f(c) = Σᵢ (xᵢ² - 2cxᵢ + c²)
     = Σᵢ xᵢ² - 2c·Σᵢxᵢ + n·c²    (把 Σ 拆到每一项,c 是常数可以提出来)

这是关于 c 的二次函数,开口向上(c² 系数为 n > 0),
顶点(最小值点)在 c = -B/2A,这里 B = -2Σxᵢ,A = n

代入:c = -(-2Σxᵢ) / (2n) = Σxᵢ / n

Conclusion: The optimal c is exactly themean (average) of all data points.。

This derivation uses only knowledge from this chapter and Chapter 1 (expanding squares, Σ summation, and the vertex formula of quadratic functions), yet it yields the important statistical conclusion of "why the mean is the optimal point that minimizes squared error."

Drag the slider and verify by hand: how the sum of squared distances increases when c deviates from the mean.

Interactive demonstration: why the mean minimizes squared error
The 5 data points are fixed at 1, 3, 4, 8, 9 (mean 5). Drag the slider to move c, observe the change in f(c) = Σ(xᵢ-c)²; the error is minimized when c = 5.
The gray dots are data points, the red parabola is f(c), and the blue dot is the current position of c. No matter which direction c deviates, the error is greater than the minimum at c = 5.

Examples

# Numerical verification: the mean is the c that minimizes Σ(xᵢ-c)²
data = [1, 3, 4, 8, 9]
mean = sum(data) / len(data)

def sq_error(c):
    """f(c) = Σ(xᵢ - c)²"""
    return sum((x - c) ** 2 for x in data)

print(mean)            # Mean = 5
print(sq_error(mean))  # Error when c = the mean

# Compare several c values that deviate from the mean: the error is larger in all cases
for c in [0, 3, 5, 7, 10]:
    print(c, sq_error(c))

Running the above code produces the following output:

5.0
46.0
0 171
3 66
5 46
7 66
10 171

Note that the errors for c=3 and c=7 are equal (both 66) -- they are the same distance from the mean of 5, which reflects the parabola's "symmetry about the vertex."

Exercise: Try to independently re-derive the process of "the mean minimizing squared error" without looking at the text above, using only three tools: the square expansion formula, the linearity of Σ, and the vertex formula for quadratic functions.

Click to view the answer

Expand, identify it as a quadratic function opening upward, with vertex, which is the mean.


Chapter Summary

SkillsCore idea in one sentence
(a+b)² expansionGeometrically, it is "cutting a square"; the cross term comes from the product of two directions, and it can be generalized to multiple variables and vectors
Completing the squareTurn an expression "missing a piece" into a perfect square, used for finding the vertex and simplifying derivations
Simplification approachCombine like terms → factor out common factors → apply identities → substitution
Independent derivationBeing able to walk through a derivation again without looking at the answer is the watershed for understanding formulas in papers
Other extensions