TITLE: If Spec Z is like a Riemann surface, what's the analogue of integration along a contour?
QUESTION [35 upvotes]: Rings of functions on a nonsingular algebraic curve (which, over $\mathbb{C}$, are holomorphic functions on a compact Riemann surface) and rings of integers in number fields are both examples of Dedekind domains, and I've been trying to understand the classical analogy between the two.  As I understand it, $\operatorname{Spec} \mathcal{O}_k$ should be thought of as the curve / Riemann surface itself.  Is there a good notion of integration in this setting?  Is there any hope of recovering an analogue of the Cauchy integral formula?
(If I am misunderstanding the point of the analogy or stretching it too far, please let me know.)

REPLY [33 votes]: For a variety $X$ over a finite field, I guess one can take $\ell$-adic sheaves to replace differential forms. Then the local integral around a closed point $x$ (like integral over a little loop around that point) is the trace of the local Frobenius $\operatorname{Frob}_x$ on the stalk of sheaf, the so-called naive local term. Note that $\operatorname{Frob}_x$ can be regarded as an element (or conjugacy class) in $\pi_1(X)$, "a loop around $x$". The global integral would be the global trace map 
$$
H^{2d}_c(X,\mathbf{Q}_{\ell})\to\mathbf{Q}_{\ell}(-d),
$$
and the Tate twist is responsible for the Hodge structure in Betti cohomology (or the $(2\pi i)^d$ one has to divide by). The Lefschetz trace formula might be the analog of the residue theorem in complex analysis on Riemann surfaces.
For the case of number fields, each closed point $v$ in $\operatorname{Spec} O_k$ still defines a "loop" $\operatorname{Frob}_v$ in $\pi_1(\operatorname{Spec} k)$ (let's allow ramified covers. One can take the image of $\operatorname{Frob}_v$ under $\pi_1(\operatorname{Spec} k)\to\pi_1(\operatorname{Spec} O_k)$, but the target group doesn't seem to be big enough). For global integral, there's the Artin-Verdier trace map $H^3(Spec\ O_k,\mathbb G_m)\to\mathbb{Q/Z}$ and a "Poincaré duality" in this setting, but I don't know if there is a trace formula. The fact that 3 is odd always makes me excited and confused.
So basically I think of trace maps (both local and global) as counterpart of integrals. Correct me if I was wrong.