For a prime $p$ and $a,b\in\mathbb{Q}_p^\times$, the Hilbert symbol $(a,b)_p$ is defined to be 1 if $ax^2+by^2=1$ has a solution over $\mathbb{Q}_p$, and $-1$ otherwise.
This is equivalent to the existence of a primitive solution to $z^2-ax^2-by^2=0$ over $\mathbb{Z}_p$.
The value of $(a,b)_p$ depends only on the images of $a$ and $b$ in $\mathbb{Q}_p^\times/\mathbb{Q}_p^{\times 2}$.
For $p=2$ the set $S=\{\pm 1, \pm 2, \pm 3, \pm 6\}$ is a complete set of representatives for $\mathbb{Q}_p^\times/\mathbb{Q}_p^{\times 2}$.
For $u\in\mathbb{Z}_2^\times$, define $\epsilon(u)=(u-1)/2$ and $\omega(u)=(u^2-1)/8$. Let $a=2^\alpha u$ and $b=2^\beta v$ with $u,v\in\mathbb{Z}_2^\times$. Then
$$(a,b)_2 = (-1)^{\epsilon(u)\epsilon(v)+\alpha\omega(v)+\beta\omega(u)}.$$
In order to verify this formula, it suffices to verify it for $a,b\in S$. Provided that $a,b\in S$ are not both divisible by 2, the equation $z^2-ax^2-by^2=0$ has a primitive solution over $\mathbb{Z}_2$ if and only if it has a primitive solution over $\mathbb{Z}/8\mathbb{Z}$.
If $a=2u$ and $b=2v$, we can use $(2u,2v)_2=(2u,2v)_2(-2v,2v)_2=(-4uv,2v)_2=(-uv,2v)_2$ to reduce to the case where $a$ and $b$ are not both divisible by 2. Thus it becomes a finite computation over $\mathbb{Z}/8\mathbb{Z}$ to verify the formula above.
{{{id=8| def hilbert(a,b): if (a%2)==0 and (b%2)==0: b = -ZZ(a/2)*ZZ(b/2) for x in Integers(8): for y in Integers(8): for z in Integers(8): if (x%2)==0 and (y%2)==0 and (z%2)==0: continue if z^2-a*x^2-b*y^2==0: return 1 return -1 def epsilon(u): return ZZ((u-1)/2) def omega(u): return ZZ((u^2-1)/8) def formula(a,b): if (a%2)==0: alpha=1; u = ZZ(a/2) else: alpha=0; u = a if (b%2)==0: beta=1; v = ZZ(b/2) else: beta=0; v = b return (-1)^(epsilon(u)*epsilon(v)+alpha*omega(v)+beta*omega(u)) /// }}} {{{id=2| S=[-1,1,-3,3,-2,2,-6,6] for a in S: for b in S: assert hilbert(a,b) == formula(a,b) assert hilbert(a,b) == hilbert_symbol(a,b,2) print "verified!" /// verified! }}} {{{id=5| /// }}}