Expectation Value in Bra-ket notation 
I've been staring at this problem for quite sometime, but I don't think I understand bra-ket notation in the form $<a | x | a>$. I understand that <a|x> is just an inner product, but I suppose I'm a little confused once we add in that third term. Could someone break this down and perhaps expand the original problem of:
<3| a^2 + a$\mathbf{a}^\intercal$ + $\mathbf{a}^\intercal$a +($\mathbf{a}^\intercal$)^2 | 3> and perhaps show me what they're actually evaluating?
I would have thought that it expanded as:
<3|a^2> + <3 | a$\mathbf{a}^\intercal$> + <3|$\mathbf{a}^\intercal$a> + <3 |($\mathbf{a}^\intercal$)^2> + <a^2| 3> + <a$\mathbf{a}^\intercal$+|3> + <$\mathbf{a}^\intercal$a|3> + <$\mathbf{a}^\intercal$^2|3>, but seems as if they only keep the middle two terms acting on the |3>?
 A: You know that $\langle f|g\rangle$ is the inner product representing $\int f^*(x) g(x) dx$. $\langle f|X|g\rangle$ is just $\int f^*(x) xg(x) dx$.
As to the problem (which looks to be out of Conquering the Physics GRE)
$$\langle3|\hat a^2+\hat a\hat a^\dagger +\hat a^\dagger \hat a + (\hat a^\dagger)^2|3\rangle$$
All you have to do is distribute the bra-ket to each of the inside terms, which results in
$$\langle3|\hat a^2|3\rangle+\langle3|\hat a\hat a^\dagger|3\rangle+\langle3|\hat a^\dagger\hat a|3\rangle+\langle3|(\hat a^\dagger)^2|3\rangle$$
There are a few ways to think about the ladder operators $\hat{a}, \text{and } \hat{a}^\dagger$. In a harmonic oscillator, you can say
$$\hat{a} = (\frac{m\omega}{2 \hbar})^{1/2} X -i(\frac{1}{2 m \omega \hbar})^{1/2}P$$
When doing $\langle n|\hat{a}|n\rangle$ you are getting the answer you'd get by the integral using the above definition of $\hat{a}$, but the beauty of ladder operators is that you can just use
$$\hat{a}^\dagger | n \rangle = \sqrt{n+1}|n+1\rangle$$
$$\hat{a}|n\rangle = \sqrt{n}|n-1\rangle$$
instead of doing the whole integral. So for example
$$\langle 3 | \hat{a}^2 |3 \rangle = \langle 3 | \hat{a} \hat{a}|3 \rangle = \langle 3 | \hat{a} (\hat{a}|3 \rangle)= \langle 3 | \hat{a}(\sqrt{3}|2\rangle) = \sqrt{3}\langle 3 | \hat{a}|2\rangle = \sqrt{3}\langle 3 | (\hat{a}|2\rangle) = \sqrt{3}\langle 3 | \sqrt{2} |1\rangle = \sqrt{6}\langle 3|1\rangle = \sqrt{6} \times0 = 0$$
A: What you have in the case of $\langle\psi|\hat A|\psi\rangle$ is effectively a matrix sandwiched between a vector and a dual vector. If you like, it is a row vector on the left, a matrix in the middle, and a column vector on the right. From here you can use regular matrix multiplication rules.
Where you have attempted to expand the raising/lowering operators in the body of your question you have over-complicated the process. Each individual term is acted on by both the bra and ket:
$$\langle3|\hat a^2+\hat a\hat a^\dagger +\hat a^\dagger \hat a + (\hat a^\dagger)^2|3\rangle=\langle3|\hat a^2|3\rangle+\langle3|\hat a\hat a^\dagger|3\rangle+\langle3|\hat a^\dagger\hat a|3\rangle+\langle3|(\hat a^\dagger)^2|3\rangle$$
It might be helpful to read this part on Wikipedia.
A: I am assuming this is the harmonic oscillator, so we have the relations,
$$a^\dagger | n \rangle = \sqrt{n+1}|n+1\rangle,$$
$$a|n\rangle = \sqrt{n}|n-1\rangle.$$
That is, the operators acting on a state produce a new state, along with a coefficient and $a |0\rangle = 0$ because it is the lowest allowed state. So let's go to your calculation:
$$\langle 3 | (a+a^\dagger)^2 |3\rangle = \langle 3 |a^2 + aa^\dagger + a^\dagger a + (a^\dagger)^2|3 \rangle$$
Recognise that $\langle n | m \rangle =0$ for $m \neq n$, i.e. states are orthogonal. So $\langle 3 | a^2 |3\rangle$ will give us something proportional to $\langle 3 | 1 \rangle = 0$ and similarly for the $(a^\dagger)^2$ term we get zero. So we are left with two terms, namely:
$$\langle 3 | a a^\dagger | 3 \rangle = \sqrt{4}\langle 3| a |4 \rangle = \sqrt{4 \cdot 4} \langle 3 |3\rangle = 4,$$
$$\langle 3 |a^\dagger a |3\rangle = \sqrt{3}\langle 3 | a^\dagger |2\rangle = \sqrt{3 \cdot 3} \langle 3 |3\rangle = 3.$$
Adding these together we find $\langle 3 | (a+a^\dagger)^2 |3\rangle = 7$. Something to note is that $(a^\dagger a) |n \rangle = n |n\rangle$ and so we call $\hat N = a^\dagger a$ the number operator since it allows us to extract the $n$ from any state.
