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 Machine Learning at 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 poweredSumulat ng LaTeX gamit ang AI

Pinakamahusay na AI LaTeX Editor, Alternatibo sa Overleaf

Tinutulungan ng Octree ang mga researcher mula sa 15+ na unibersidad na sumulat ng research papers nang mas mabilis gamit ang AI

  • Gumawa ng magagandang TikZ diagrams gamit ang AI
  • Mag-upload ng larawan at i-convert ito sa LaTeX nang walang problema
  • Makakuha ng instant na tulong sa pagsulat at pag-format ng research papers