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 التعلم الآلي والذكاء الاصطناعي →

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 poweredاكتب LaTeX باستخدام الذكاء الاصطناعي

أفضل محرر LaTeX بالذكاء الاصطناعي، بديل Overleaf

يساعد Octree الباحثين من أكثر من 15 جامعة على كتابة أوراق البحث بشكل أسرع باستخدام الذكاء الاصطناعي

  • أنشئ رسوم TikZ جميلة باستخدام الذكاء الاصطناعي
  • ارفع صورة وحولها إلى LaTeX بسلاسة
  • احصل على مساعدة فورية في كتابة وتنسيق أوراق البحث