When writing in math, do you use a comma or colon preceding an equation?
Solution 1:
Generally, I would treat the equation as if it were any ordinary noun phrase, and use the usual rules for comma, colon, or no punctuation.
A colon is used if the equation is an elaboration, or an item. So, just as you might write
Lips are characterized by the following properties: fleshy, paired, red.
you would write
An ellipse is characterized by the following equation:
$$ \frac{x^2}{a^2}+\frac{y^2}{b^2} = 1 $$
A comma precedes a non-restrictive clause (one that describes rather than identifies the noun phrase), so by analogy with
The line can be assigned to a simpler character, Polonius.
we might write
A line can be described with a simpler equation,
$$ y = mx+b $$
In comparison, with a restrictive clause, we use no comma, so just as we would write
From this, the oiler obtained the formula CH$_3$C$_6$H$_4$C$_2$H$_5$.
we would also write
From this, Euler obtained the formula
$$ e^{i\pi}+1 = 0 $$
I suspect there aren't any hard and fast rules for this, however. Whatever you choose to do, be consistent and reasonable.
ETA: You'll notice that I have no periods at the ends of these equations. The papers I have generally (though not universally) observe this pattern. However, in other fields, equations may have ending punctuation depending on how they occur within a sentence. It may be useful for a writer to consult the publication's style guide, if applicable, or at least examine previous articles within the same publication or outlet.
Solution 2:
Equations should be included as part of the sentence, as in the following.
Consider the Yosida-Hawking-Penrose-Dantzig function $$ f(x) = \frac{1}{2}D_\alpha(x,y). $$
It can also be expressed as $$f(x)=\phi(x,y),$$ where $\phi(x,y)$ is the Demiane functional.
In example B, if you don't want to change the sentence:
In fact, we can express the earlier function using the much simpler expression $$f(x)=\phi(x,y),$$ where $\phi(x,y)$ is the Demiane functional.
I use this style example. Milnor's book, referenced in the comments below, follows the same rules, as do all the references and publications in my bookshelf (Polya's Problems and Theorems in Analysis, Rudin's Real and Complex analysis, etc.)
Standard guides
Knuth's Mathematical Writing.
How to Write Mathematics, by P. Halmos.
Solution 3:
No punctuation should be used between the word "function" and an immediately following expression that defines it, unless "the function" has already been defined and its expression in the text is just a convenient reminder of its definition. Exactly the same applies in ordinary Language. Compare, for example the following two sentences:
My sister Laura lives in London.
My sister, Laura, lives in London.
The second sentence implies that "my sister" has already been defined, perhaps as the only sister or the sister who was previously discussed. In contrast, the first sentence makes no such implication: Laura, as far as we can tell from the sentence, might be any one of many sisters; but the sentence does specify which sister is being considered.
In general, the punctuation of mathematical writing should follow that of the corresponding natural language. In particular, a mathematical expression that ends a sentence should be followed by a full stop.