compute genus of sphere and torus I am learning differential geometry by programming them and seeing their shapes. But topology is absolutely mysterious to me. For example, a sphere
$$
x^2+y^2+z^2=r^2
$$
has genus 0 (no holes).
and a torus 
$$
\left(R- \sqrt{x^2+y^2}  \right)^2+z^2=r^2
$$
has genus 1 (with one hole).
But is there a formula than can actually derive the number 0, and 1 from the above equations? In other words, how to compute the genus of an algebraic surface?
p.s. Most functions I know return a real number (e.g. $\sin$, $\cos$, $\exp$, etc), so I am very curious about how a function transform a surface representation into an integer. Or, Does "a surface has genus 1.5 " make any sense? 

It isn't possible to provide a general formula that computes genus of surface from its coordinate equations since genus is the topological (not just geometric) invariant and parametrization may vary under homeomorphisms.
