MathorynMathematical Formula Database

Set Theory & Logic

Number of Functions Between Finite Sets

Each of the mm elements of AA can be sent to any of the nn elements of BB, giving nmn^m functions; requiring distinct images gives the injective functions. These counts are used in combinatorics, probability (the birthday problem) and computer science.

#{f:A→B}=nm,#{injective}=n!(n−m)!(∣A∣=m, ∣B∣=n)\#\{f:A\to B\}=n^{m},\qquad \#\{\text{injective}\}=\frac{n!}{(n-m)!}\quad(|A|=m,\ |B|=n)
LaTeX\#\{f:A\to B\}=n^{m},\qquad \#\{\text{injective}\}=\frac{n!}{(n-m)!}\quad(|A|=m,\ |B|=n)

Variables

mm
size of the domain A
nn
size of the codomain B

Example

Count all functions and the injective ones from a 33-element set to a 44-element set.

  1. All functions: 43=644^3=64.
  2. Injective: 4⋅3⋅2=244\cdot3\cdot2=24.

Answer: 6464 functions, 2424 of them injective.

Related formulas