Is $f = g$? A numerical answer, a randomized exact one and a symbolic one — and what each of them really guarantees.
Numerically, we evaluate $f$ and $g$ in float64 at $k$ random points. Agreement within the tolerance is evidence, not a proof: the points may “miss” the places where the functions differ (as with $\sqrt{x^2}$ versus $x$ on $[0,5]$), and rounding errors can fake a difference that does not exist (Wilkinson’s polynomial) or hide one that does ($e^{\pi\sqrt{163}}$ differs from an integer by about $7.5\cdot 10^{-13}$, while the gap between neighboring float64 numbers there is $32$).
Randomly, but exactly. For rational expressions we compute exactly modulo the prime $p = 2^{31}-1$. The guarantee comes from the Schwartz–Zippel lemma: if $P \neq 0$ is a polynomial of degree $d$ over a field $F$ and $S\subseteq F$ is finite, then $$\Pr_{r\in S^n}\bigl[P(r) = 0\bigr] \le \frac{d}{|S|}.$$ We apply it to the numerator $P = N$ of the difference $f - g = N/D$. The error is one-sided: a point found with $f(r)\not\equiv g(r)$ proves that $f\neq g$; agreement in $k$ independent trials gives certainty “only” up to an error probability $\le (d/p)^k$. (Strictly speaking, we reason about $N \bmod p$ — if all the coefficients of $N$ were divisible by $p$, the test would not detect it; that is why in practice $p$ is chosen at random as well.)
Symbolically, we bring $f - g$ to the canonical form $N/D$ (expanded polynomials with rational coefficients). $N = 0$ is a proof of the identity of rational functions — assuming that the CAS implementation is correct. For $\sin$ and $\cos$ of a single variable a trick works: the substitution $t = \tan\frac{x}{2}$, $\sin x = \frac{2t}{1+t^2}$, $\cos x = \frac{1-t^2}{1+t^2}$ turns the expression into a rational function of $t$. Outside such classes the method is silent (Richardson’s theorem).
Formal proof. The ring tactic in Lean does the same as “World 3” — it normalizes both sides to canonical form — but in addition it builds
a certificate that is checked independently by the system’s small kernel. Then we do not have to trust the implementation of the tactic itself.
expand_trig.)