Entropy in LaTeX (H(X))

H(X)H(X)
LaTeX command
H(X)
Package
No package needed: built into LaTeX
Mode
Text and math mode

Where it is used

Shannon entropy of a random variable X: the average uncertainty, or information content, of its outcomes.

Entropy is H(X) = -\sum_x p(x) \log p(x), measured in bits with \log_2 and in nats with \ln. It is maximized by the uniform distribution, where H(X) = \log |\mathcal{X}|, and it appears in decision tree splitting via information gain and in maximum-entropy RL. Related quantities share the letter: conditional entropy H(Y|X), joint entropy H(X, Y), and differential entropy h(X) for continuous variables, usually in lowercase. Some papers write \mathbb{H}[X] to avoid confusion with a Hessian H or a hypothesis class.

Minimal compilable example

Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.

H(X)=−∑x∈Xp(x)log⁡2p(x)H(X) = -\sum_{x \in \mathcal{X}} p(x) \log_2 p(x)
\documentclass{article}
\begin{document}
Entropy: $H(X)$

\[ H(X) = -\sum_{x \in \mathcal{X}} p(x) \log_2 p(x) \]
\end{document}

Related symbols

All 機械学習・AI →

Frequently asked questions

How do I write Entropy in LaTeX?
Type H(X) in math mode, for example $H(X) = -\sum_{x \in \mathcal{X}} p(x) \log_2 p(x)$. It works in plain LaTeX without loading any package.
Which package do I need for H(X)?
None. H(X) is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
Can I use H(X) in text mode, or only in math mode?
Both. H(X) compiles in running text as well as inside $...$; in a formula keep it in math mode so it gets math fonts and spacing.
Math poweredAIでLaTeXを書く

最高のAI LaTeXエディタ、Overleaf代替

Octreeは15以上の大学の研究者がAIを使って論文をより速く書くのを支援

  • AIで美しいTikZダイアグラムを生成
  • 画像をアップロードしてシームレスにLaTeXに変換
  • 論文の執筆とフォーマットに即座にサポートを取得