[Tex/LaTex] switch between left and right alignment in multiline equation

alignalignatalignmentequationshorizontal alignment

I would like to typeset an equation, with multiple equalities and long terms.
Each equals sign should be left-aligned on a new line. But leftover terms that flow to a new line should be right-aligned.
Here's a minimal example, I've used alignment symbols to position the parts of the equation:

\begin{align*}
  &p_{very\;long\;function}(x) =&& \\
  &&\int f_{very \; long \; integral \; terms}(x)&\\
  &&\mathcal{N}(x; 0, \sigma^2) dx&\\
  &= 2&&
\end{align*}

The result looks like this:
align

The alignment pushes the equation apart. It does left- and right- align it, but the individual columns can't overlap. So it's not the same as just flowing the lines left and right.
What I would like to get is this:
edited

In the image above, the equation is as wide as the widest line. And individual lines are left or right-aligned.

I've searched for related questions, on how to configure alignment. There are many similar questions, but none of them seem to answer my problem:

UPDATE:

To clarify my question: The document is in two-column mode. That's why I need a compact way to typeset my equations.
Here is an example equation with 4 lines. The first and last should be left-bound. The second one determines the width of the equation, the third one should be right-bound.
I think the key problem is that align and alignat columns may not overlap.
The code is this:

\begin{align*}
  &p_{long \; function}(x) =\\
  & \int f_{many\; very \; long \; integral \; terms}(x)\\
  &\mathcal{N}(x; 0, \sigma^2) dx\\
  &= 2
\end{align*}

It should look like this:

enter image description here

Best Answer

I supposed you're in two-column mode, and, if I understand well your requirements, they can be satisfied with an aligned environment nested in the outer align* (with a single alignment column). However, I also propose another solution, based on multlined:

\documentclass[twocolumn]{article}
\usepackage{mathtools}

\begin{document}

\begin{align*}
  & p_\text{very\;long\;function}(x) = \\
  & \phantom{{}={}} \begin{aligned}[t]\int f_\text{very long integral terms}(x)\\
 \mathcal{N}(x; 0, \sigma^2)\, dx
 \end{aligned}\\
  & = 2
\end{align*}

\begin{align*}
  & p_\text{very\;long\;function}(x) \\
  & = \begin{multlined}[t]\int f_\text{very long integral terms}(x)\\
 \mathcal{N}(x; 0, \sigma^2)\, dx
 \end{multlined}\\
  & = 2
\end{align*}

\end{document} 

enter image description here

Related Question