General ⇒ vertical bar for conditional expectation
vertical bar for conditional expectation
I'm trying to get something like
E \left( Y \vert X \right)
...the complication is that frequently Y (sometimes X) is a tall expression, like a fraction, and I would like \vert to comform to the size of the taller of Y or X.
I was surprised that I couldn't find anything on the web for this since many people must have run into it. Any suggestions? Or pre-existing commands in amslatex that I'm not aware of? Thanks!
E \left( Y \vert X \right)
...the complication is that frequently Y (sometimes X) is a tall expression, like a fraction, and I would like \vert to comform to the size of the taller of Y or X.
I was surprised that I couldn't find anything on the web for this since many people must have run into it. Any suggestions? Or pre-existing commands in amslatex that I'm not aware of? Thanks!
NEW: TikZ book now 40% off at Amazon.com for a short time.
vertical bar for conditional expectation
With \vert you can use the vertical extensions generated by \left and \right, as the following example suggests:
Code: Select all
E\left(X \left\vert \dfrac{X}{Z} \right. \right)
1,1,2,3,5,8,13,21,34,55,89,144,233,...
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
vertical bar for conditional expectation
I got an idea, but I think this can only serve as a workaround. Like every other delimiter symbol, the \vert can also be scaled automatically. The trick is that you need a pseudo delimiter. This could be done by
but the result is that there is no difference in the height of the \vert. As you mentioned, you want to have fractures in your expression. So the height of the \vert has to be modified to fit the height of the fractures. This is achieved by
This gives you phantom expression with determines the height of the \vert but does not appear in the text. If you need the whole expression several times in your document, it would be useful to declare a new command with at least two arguments in the preamble and name it as you like.
Pay attention to the additional thin space right after the first argument. It is necessary to balance the thin space caused by the right phantom delimiter ("."). Omit that and you will see what I mean.
Test the new command by inserting a normal expression and a fracture or only two normal expressions as arguments. I'm sure there is better method to realise this but for the present it should the job.
Best regards
Thorsten
Code: Select all
\left\vert\right.
Code: Select all
\left\vert\vphantom{\frac{1}{1}}\right.
Code: Select all
\newcommand{\xcmd}[2]{\left(#1\,\left\vert\vphantom{#1#2}\right. #2\right)}
Test the new command by inserting a normal expression and a fracture or only two normal expressions as arguments. I'm sure there is better method to realise this but for the present it should the job.
Best regards
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
vertical bar for conditional expectation
Mi first solution works only if the fraction goes after the vertical bar; in the general case, the \middle command gives the vertical extension without defining new commands:
Code: Select all
E\left(X \middle\vert \dfrac{X}{Z} \right)
E\left( \dfrac{X}{Z} \middle\vert Y \right)
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Re: vertical bar for conditional expectation
Here's a solution, with e-tex's primitive \middle:
$E\left(X\middle\vertY\right)$
That construct is implemented in the braket package, which defines a\Set command. You might do the same to implement an \expectation command, to avoid typing the \left, \right and \middle primitives (or ask the author of braket, Donald Arseneau, to do so and add it to braket).
Regards,
B.A.
$E\left(X\middle\vertY\right)$
That construct is implemented in the braket package, which defines a\Set command. You might do the same to implement an \expectation command, to avoid typing the \left, \right and \middle primitives (or ask the author of braket, Donald Arseneau, to do so and add it to braket).
Regards,
B.A.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
vertical bar for conditional expectation
Very good. Didn't know this \middle command. Thanks for that. Are there any other references to find this TeX primitive described?
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: vertical bar for conditional expectation
\middle command..excellent, works great. Thanks to all for the replies!
vertical bar for conditional expectation
Fine control on the size of delimiters can be obtained through the following command groups which replace the \left - \middle - \right group:
There are many cases in which the above commands should replace the \left - \right ones, mainly when the latter yield too big delimiters and when there are several delimiters together. Just a simple example: I find better this
than any of the following alternatives
There is also a subtle difference between the \XXXm and \middle commands. To start with, compare
with
Clearly, the spacing around the vertical bar is different. That also happens if \middle is replaced by \bigm and like. Once again, compare
with
I prefer this last option.
To be complete, there also exist the commands \big, \Big, \bigg and \Bigg, which can be used before any delimiter. Look at this:
Once more, spacing is different. Observe in this example, however, than \bigg\vert behaves as \middle\vert.
To help typesetting, I propose the following command:
It has an optional argument, whose value is 0 by default, and two mandatory arguments. The optional argument is a non-negative integer that controls the size of delimiters: 0 means minimal size, 4 is maximal size, 5 or greater means automatic choice of size.
Here it is in action:
Of course, if you don't like the spacing which surrounds the vertical bar, you can replace \bigm and like by \big and like.
- \bigl - \bigm - \bigr
- \Bigl - \Bigm - \Bigr
- \biggl - \biggm - \biggr
- \Biggl - \Biggm - \Biggr
There are many cases in which the above commands should replace the \left - \right ones, mainly when the latter yield too big delimiters and when there are several delimiters together. Just a simple example: I find better this
Code: Select all
\[ \lambda \bigl( (x_1,x_2) + (y_1,y_2)\bigr) = \lambda (x_1,x_2) + \lambda (y_1,y_2) \]
Code: Select all
\[ \lambda ( (x_1,x_2) + (y_1,y_2) ) = \lambda (x_1,x_2) + \lambda (y_1,y_2) \]
\[ \lambda \left( (x_1,x_2) + (y_1,y_2)\right) = \lambda (x_1,x_2) + \lambda (y_1,y_2) \]
Code: Select all
\[ E ( X \vert Y ) \]
Code: Select all
\[ E ( X \mid Y ) \]
Code: Select all
\[ E\left( X \middle\vert \dfrac{X}{Z} \right) \quad
E\left( \dfrac{X}{Z} \middle\vert Y \right) \]
Code: Select all
\[ E\biggl( X \biggm\vert \dfrac{X}{Z} \biggr) \quad
E\biggl( \dfrac{X}{Z} \biggm\vert Y \biggr) \]
To be complete, there also exist the commands \big, \Big, \bigg and \Bigg, which can be used before any delimiter. Look at this:
Code: Select all
\[ E\bigg(X \bigg\vert \dfrac{X}{Z} \bigg) \quad
E \bigg( \dfrac{X}{Z} \bigg\vert Y \bigg) \]
To help typesetting, I propose the following command:
Code: Select all
\newcommand{\expectation}[3][0]{%
\ifcase#1
E( #2 \mid #3 )
\or E \bigl( #2 \bigm\vert #3 \bigr)
\or E \Bigl( #2 \Bigm\vert #3 \Bigr)
\or E \biggl( #2 \biggm\vert #3 \biggr)
\or E \Biggl( #2 \Biggm\vert #3 \Biggr)
\else
E \left( #2 \;\middle\vert\; #3 \right)
\fi}
Here it is in action:
Code: Select all
\[ \expectation{X}{Y}\quad \expectation[1]{X}{Y^2} \quad \expectation[2]{X}{\dfrac{Y}{Z}}
\quad \expectation[3]{X}{\dfrac{Y}{Z}}\quad \expectation[5]{X}{\dfrac{Y}{Z}} \]