Calculating number of lines and planes in affine space over finite field

Consider a finite field $F_p$ with $p$ elements; how would one calculate the number of lines and the number of planes in the affine space $F^3_p$?

If one knew the number of lines through a particular point, the number of planes could then be calculated by multiplying the number of lines through the origin by the number of points on any line.

-

There are $p$ points on every line. The lines through a given point can go through every other point, and two distinct ones have only that point in common, so there are $$\frac{p^{3} - 1}{p-1} = 1 + p + p^{2}$$ lines through a point.

If you count the number of lines as $$\text{number of points} \cdot \text{number of lines through each point} = p^{3} \cdot (1 + p + p^{2}),$$ then you are counting each line $p$ times, one for each of its points, so the number of lines is $$p^{2} \cdot (1 + p + p^{2}).$$

Gerry Myerson (thanks!) made me notice that I had forgotten to count planes.

One way is the following. Count first the triples of distinct, non-collinear points. Their number is $$p^{3} (p^{3} -1) (p^{3} - p).$$ To count planes, we have to divide by the number of triples of distinct, non collinear points on a given plane, that is $$p^{2} (p^{2} -1) (p^{2} - p).$$ The net result is $$\frac{p^{3} (p^{3} -1) (p^{3} - p)}{p^{2} (p^{2} -1) (p^{2} - p)} = p (p^{2} + p + 1).$$ The same method allows for an easier counting of the lines, as $$\frac{p^{3} (p^{3} - 1)}{p (p-1)} = p^{2} (p^{2} + p + 1).$$

-
And the number of planes? – Gerry Myerson Jun 11 '14 at 9:28
@GerryMyerson, you're right, I missed that one. – Andreas Caranti Jun 11 '14 at 10:34
@GerryMyerson, added, thanks a lot. – Andreas Caranti Jun 11 '14 at 16:02
For the number of planes we can add a hyperplane at infinity to obtain a projective space, in which the number of hyperplanes is equal to the number of points. So, the number of planes in $F_p^3$ is equal to the number of points in the projective space $PG(3, p)$ minus $1$, which is equal to $p^3 + p^2 + p + 1 - 1 = p^3 + p^2 + p$. – Anurag Feb 29 at 16:37

Let us solve the more general problem of finding the total number of $k$-dimensional affine subspaces of $\mathbb{F}_q^n$.

The starting point is the easy to prove fact that the number of $k$-dimensional (vector) subspaces of a the vector space $\mathbb{F}_q^n$ is the Gaussian coefficient $${n \brack k}_q = \frac{(q^n - 1)(q^n - q)\cdots(q^n - q^{k-1})}{(q^k - 1)(q^k - q)\cdots(q^k - q^{k-1})}.$$

Now the $k$-dimensional affine subspaces are precisely the cosets of the form $x + U$ where $x \in \mathbb{F}_q^n$ and $U$ is a $k$-dimensional subspace of $\mathbb{F}_q^n$. But $x + U = y + U$ if and only if $x - y \in U$. Therefore, as $x$ goes through all the $q^n$ elements of $\mathbb{F}_q^n$, each coset $k$-dimensional coset corresponding to the vector subspace $U$ is counted $q^k$ times. And thus the total number of $k$-dimensional affine subspaces is equal to $$q^{n - k}{n \brack k}_q.$$

-