TITLE: How do we know our definitions don't lead to contradictions
QUESTION [8 upvotes]: How do we assure ourselves when defining an operation that it does not lead to  contradictions? For example 0! := 1. I understand the practicality of why it is defined this way, but I am wary of what could happen if another such operation is created and defined in a way that leads to future contradictions that were not considered. This often happens when people come up with definitions for division by zero. How do we know it doesn’t happen with other definitions?
Note that I'm not asking about the consistency of our axioms for N or anything like that, but about definitions built upon those axioms.

REPLY [3 votes]: There are actually two different kinds of "definitions" in mathematics, arising from two separate mechanisms:
$
\def\nn{\mathbb{N}}
$

Definition by existential instantiation: When we have an axiom or a deduced sentence asserting the existence of some object, namely "$\exists x\ ( P(x) )$" where $P$ is some predicate, we can instantiate it and name a reference to it, by saying "Let $c$ be such that $P(c)$.". This is far more general than you might think. For example when we define a function $f : \nn \to \nn$ such that $f(0) = 0$ and $f(n+1) = 2f(n)+1$ for every $n \in \nn$, we are invoking a theorem that says "$\exists f : \nn \to \nn\ ( f(0) = 0 \land \forall n\in\nn\ ( f(n+1) = 2f(n)+1 ) )$". Don't laugh! This is not necessarily a trivial theorem, depending on our choice of foundational system for mathematics. The bottom line is, such definitions are only valid if we can prove the existential statement that guarantees the existence of the object that we are giving a name to.
Definitorial expansion: In some foundational systems, we cannot use the above kind of definition, simply because we cannot prove the required existential statement. For example in ZF set theory one can prove that there is no set $S$ whose members are exactly the sets that are not members of themselves. Namely, we can prove $\neg \exists S\ \forall x\ ( x \in S\ \Leftrightarrow \neg x \in x )$. However, we still can define a predicate $R$ where $R(S) \overset{def}\equiv \forall x\ ( x \in S\ \Leftrightarrow \neg x \in x )$ for every set $S$. $R$ is not a set, but we can still talk about sets that satisfy $R$. For example, $R(\{\})$ because the empty-set is not a member of itself. This notion of definition can itself be formally defined as described in this post, and more details about the issue with Russel's paradox can be found in this post. This is also more common than you might think. For example in ZFC set theory, there is no function that maps every set to its cardinality, and so the cardinality notation in "$\#(S)$" or "$|S|$" cannot be defined using the first type of definition. But it can be defined via this type of definition. Similarly, when you define the diameter $diam(G)$ of every finite graph $G$, note that actually $diam$ is not a function in ZFC set theory, because there is no set of all finite graphs! But the notion of "finite graph" and $diam$ are both definable via definitorial expansion, and we can use $diam$ on any finite graph. Things get a bit messy with higher-order things like the family of functions on finite graphs. That cannot even be defined via definitorial expansion, but we can often 'cheat' by using suitable concrete representative. For example we can define even by mere existential instantiation the family of all functions on graphs whose vertices are a subset of $\nn$.

We can show (as a fact about classical logic) that both these two mechanisms will not cause contradiction that did not already exist without it. For existential instantiation, if one can obtain a contradiction from instantiating an existential statement, then the correct judgement would be that the existential statement itself was invalidly assumed/deduced, and not the instantiation step. For definitorial expansion, it yields a conservative extension over the original system, meaning that every statement in the original language can be proven in the expanded system (i.e. with definitorial expansion) can already be proven in the original system.