  We have found analytical expressions (polynomials) of the percolation
probability for site percolation on a square lattice of size $L \times L$ sites
when considering a plane (the crossing probability in a given direction), a
cylinder (spanning probability), and a torus (wrapping probability along one
direction). Since some polynomials are extremely cumbersome, they are presented
as separate files in Supplemental material. The system sizes for which this was
feasible varied up to $L=17$ for a plane, up to $L=16$ for a cylinder, and up
to $L=12$ for a torus. To obtain a percolation probability polynomial, all
possible combinations of occupied and empty sites have to be taken into
account. However, using dynamic programming along with some ideas related to
the topology, we offer an algorithm which allows a significant reduction in the
number of configurations requiring consideration. A rigorous formal description
of the algorithm is presented. Divisibility properties of the polynomials have
been rigorously proved. Reliability of the polynomials obtained have been
confirmed by the divisibility tests. The wrapping probability polynomials on a
torus provide a better estimate of the percolation threshold than that from the
spanning probability polynomials. Surprisingly, even a naive finite size
scaling analysis allows an estimate to be obtained of the percolation threshold
$p_c = 0.59269$.
