The notebook this comes from opens with a confession: "I have a problem with calculating input impedances and transfer functions. I don't trust my own brain when it comes to the algebra." It then uses sympy to expand the input impedance of the standard crystal model and compare the answer against a published one, to settle whether the textbook or the reader is wrong. (Neither, as it turns out — the published version drops a term that barely moves near resonance.)
That expansion is one line, so this page does it directly rather than shipping a computer algebra system to your browser:
Z_in = 1 / ( 1/(R + sL + 1/(sC_F)) + sC_P )
A quartz crystal is a mechanical resonator that happens to be reachable through electrodes. The motional arm — R, L, C_F in series — is the mechanical resonance in electrical clothing, and C_P is the plain capacitance of the electrodes. Because the electromechanical coupling is weak, C_F comes out in femtofarads and L in millihenries: values you could never build from actual components, which is exactly why the Q is in the tens of thousands and why crystals are worth their cost.
Two resonances fall out. At f_s the motional arm's L and C_F cancel and the impedance collapses to R. Slightly above it, the now-inductive motional arm resonates with C_P and the impedance peaks at f_p. Between the two, and only between the two, the crystal looks inductive — and a Pierce oscillator needs it to look inductive. That window is a few kilohertz wide on a ten megahertz part, which is the entire reason crystal oscillators are accurate.
from sympy import symbols,expand,simplify,solve
Gin,Zin, s,Cf,L,Cp,R,Z = symbols("G_{in} Z_{in} s C_F L C_P R Z")
Gin = 1/(R + s*L + 1/(s*Cf)) + s*Cp
Zin = expand(simplify(1/Gin))
Z = Zin.subs({R:50,Cf:5e-15,Cp:5e-12,L:50e-3})
func = lambdify(s, Z,'numpy')
Znum = func(1j*2*np.pi*f)
Source: jupyter/xosc.ipynb.
The notebook finds the peak by np.argmax on a 1000-point grid;
this page uses the closed forms
f_s = 1/(2π√(L·C_F)) and f_p = f_s·√(1 + C_F/C_P)
instead, which do not depend on how finely the curve happens to be sampled.