English
Definition of the number of internal nodes: 0 for the empty tree; for a node, left and right subtrees contribute their counts plus one.
Русский
Определение числа внутренних узлов: для пустого дерева равно 0; для узла сумма чисел внутренних узлов левого и правого поддеревьев плюс 1.
LaTeX
$$$ \mathrm{numNodes}(\mathrm{nil}) = 0, \quad \mathrm{numNodes}(\mathrm{node}(v,a,b)) = \mathrm{numNodes}(a) + \mathrm{numNodes}(b) + 1. $$$
Lean4
/-- The number of internal nodes (i.e. not including leaves) of a binary tree -/
@[simp]
def numNodes : Tree α → ℕ
| nil => 0
| node _ a b => a.numNodes + b.numNodes + 1