We have a matrix made up of $m$ by $n$ dots. Can you give a function that counts the number of squares that can be found by joining any $4$ dots in it?
For every $m\ge n$ (otherwise just swap $m$ and $n$) the number of squares $N$ is:
Where $(n-i)\times(m-i)$ counts all squares of sidelength $i$ and sides parallel to the rows and columns and multiplies it by the amount of squares we get when we slide their corners along those sides($\times i$).
Example: squares size 3 in a 5 by 5 matrix:
++++* *++++ +**+* *+**+ +**+* *+**+ ++++* *++++ ***** ***** ***** ***** ++++* *++++ +**+* *+**+ +**+* *+**+ ++++* *++++
squares by sliding along the edges of one size 3 square:
++++ +**+ +**+ ++++ *+** *+++ +++* **+* **+* +++* *+++ *+**
(i know its ugly but i couldn't do better)