2

Can some one please help me how can I make the following equation in latex?

enter image description here

I have used

\begin{equation} \label{eq24}
\begin{split}
V^{\pi}(s) = {\sum_{a}\pi(s,a)}
\sum_{s^'} \mathcal{P}{{^a}_{{ss}^'}}  \bigg[{\mathcal{R}{{^a}_{{ss}^'}}} 
      + \gamma {V^{\pi}}(s^') \bigg] 
\end{split}
\end{equation}

But latex does not compile as it says error

Mico
  • 506,678
Priya
  • 143

3 Answers3

6

Generally ' doesnot require ^, hence this character already in superscript position in all font by default, if you need ^ then you have to use \prime instead of ', refer the below tags:

\documentclass{book}
\usepackage{mathtools}

\begin{document}

\begin{equation} \label{eq24}
V^{\pi}(s) = \sum_{a}\pi(s,a)
\sum_{s^{\prime}} \mathcal{P}{{^a}_{{ss}^{\prime}}}
\biggl[{\mathcal{R}{{^a}_{{ss}^{\prime}}}} + \gamma
{V^{\pi}}(s^{\prime}) \biggr] 
\end{equation}
\end{document}

PS: No need to use split environment in this case...

MadyYuvi
  • 13,693
  • this is a bit misleading as s' in TeX does not use a superscript because ' is in superscript position in the font but because the latex (and plain tex) macros convert ' in math mode to ^{\prime} . So you never need to use ^{\prime} it is just a long way of writing '. Also you have several errors copied from the code in the question \bigg should be \biggl etc, see the comment egreg made under the question. – David Carlisle Sep 23 '19 at 11:17
6

Writing f' is the same as writing f^{\prime}; for double primes, it is f'' and so on. The code ^' is wrong.

Besides, there are also wrong (not just useless) braces in your code:

\begin{equation} \label{eq:Vpi(s)}
V^{\pi}(s) = \sum_{a}\pi(s,a) \sum_{s'} 
  \mathcal{P}^{a}_{ss'}  \bigl[\mathcal{R}^{a}_{ss'} + \gamma V^{\pi}(s') \bigr] 
\end{equation}

Use \biggl[ and \biggr] instead of the unqualified \bigg in order to give the brackets their correct nature of delimiters. However, the size is too big: \bigl[ and \bigr] are sufficient.

It's also better to use semantic names for the labels, rather than eq24 as the number might change during preparation of the document. If you use \label{eq:Vpi(s)} (or whatever you prefer), the references will not depend on the actual number.

See the code below if you really want staggered subscripts and superscripts.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tensor}

\begin{document}

Your formula (with the main fixes)
\begin{equation} \label{eq24}
\begin{split}
V^{\pi}(s) = {\sum_{a}\pi(s,a)}
\sum_{s'} \mathcal{P}{{^a}_{{ss}'}}  \bigg[{\mathcal{R}{{^a}_{{ss}'}}} + \gamma {V^{\pi}}(s') \bigg] 
\end{split}
\end{equation}

The same with the suggested fixes
\begin{equation} \label{eq:Vpi(s)}
V^{\pi}(s) = \sum_{a}\pi(s,a) \sum_{s'} 
  \mathcal{P}^{a}_{ss'}  \bigl[\mathcal{R}^{a}_{ss'} + \gamma V^{\pi}(s') \bigr] 
\end{equation}

If you want staggered superscripts and subscripts, it's better to use tensor
\begin{equation} \label{eq:Vpi(s)mod}
V^{\pi}(s) = \sum_{a}\pi(s,a) \sum_{s'} 
  \tensor{\mathcal{P}}{^{a}_{ss'}}
  \bigl[\tensor{\mathcal{R}}{^{a}_{ss'}} + \gamma V^{\pi}(s') \bigr] 
\end{equation}

\end{document}

enter image description here

egreg
  • 1,121,712
2

The rule is we write X_{subscript}^{superscript}, but braces around a single character, or a single command that functions for this purpose as a single character, are unnecessary. As this includes the case where X is the summation operator, we don't need any more braces (except around the arguments of non-nullary commands such as \mathcal). One can thus use

V^\pi\left(s\right)=\sum_a\pi\left(s,\,a\right)\sum_{s^\prime}\mathcal{P}_{ss^\prime}^a\left[\mathcal{R}_{ss^\prime}^a+\gamma V^\pi\left(s^\prime\right)\right]

where I have used \left and \right in front of parentheses to resize them according to their contents, and \, for a space between the \pi function's arguments. You can preview the result here.

I say one can do that, but the square brackets look a little smaller that way than in your original image. I'm torn between whether \left[ and \right] should be respectively replaced with \big[ and \big], or \bigg[ and \bigg], or even these. (Using \Big or \Bigg leads to still larger brackets, far beyond what you wanted, but this is worth knowing for other use cases.) You're welcome to also experiment with removing the \left and \right in front of some pairs of round brackets altogether, but in the case of s^\prime you'd probably regret it.

J.G.
  • 237