Looking for a Basic ( or "for Dummies" ) Explanation of the Lagrangian - Hamiltonian Relationship. ( Mathematician ) (Mathematician here - first time physics.stack poster).
I'm basically looking for as simple as possible explanation of the Hamiltonian - Lagrangian relationship.
$\textbf{My understanding :}$
$\textbf{The Hamiltonian.}$
Say we have some particle in $\mathbb{R}^d$, with a position $q(t)$ and velocity $\dot{q}(t)$, i.e evolving in time. Exactly how it evolves depends on the system. For a given system we can write down the Hamiltonian $H(q,\dot{q})$, and Hamiltons equations say
$$ \frac{dq}{dt}=\frac{\partial H}{\partial p}, ~~~~\text{and}~~~~ \frac{dp}{dt}=-\frac{\partial H}{\partial q}. $$
e.g if $H=\frac{p^2}{2m}+V(q)$ where ($m$=mass and $V$ is some energy potential) then Hamilton's equations say that the time derivative of position is velocity (i.e Newton's 2nd Law), and the change in momentum is equal to the negative gradient of the potential energy (i.e. the system tries to minimize energy).
$\textbf{The Lagrangian.}$ I understand this object only through "the Principle of Least Action". It is a functional on paths (which I think of as $q(t),\dot{q}(t)$ from above?) $L[q(t),\dot{q}(t)]$, such that
$$\underset{q ~:~ (q,\dot{q})(0)=(x,y),~(q,\dot{q})(h)=(x^*,y^*)}{\text{armin}}  \int_0^h L[q(t),\dot{q}(t)]dt  $$
returns the "most likely" or "cheapest paths", i.e the ones that a physical system would take.
$\textbf{My Questions :}$ (if you can only answer 1 of them that is still greatly appreciated )

*

*What are the most important things missing from my interpretation of $H$ and $L$?


*How (and heuristically why) are these two objects related through the Legendre transform?


*Picking up a Partial Differential Equation e.g :
$$ 
\partial_t \rho_t(x)=-\text{div}\Big(\rho_t(x)\nabla_p H\big(x,-\rho_t^{-1}(x)\nabla P(\rho_t(x))  \big)\Big),
$$
where $\rho$ is the density of a fluid and $P$ is its pressure. Why can we call this a Hamiltonian of the PDE?
Note PDE taken from : this paper by Figalli, Gangbo and Yolcu
 A: H is a function of $q$ and $p$ not $q$ and $\dot q$. The "momentum"  $p$  is not always $\dot x$ but is defined by
$$
p= \frac{\partial L}{\partial \dot q}.
$$
The Legendre transform   is between $\dot q$ and $p$ just as the usual Legendre  transform of a convex function $f(x)$ replaces $f$ by
$$
F(p) = x(p)\left.\frac{df}{dx}\right|_{x=x(p)}- f(x(p))
$$
where $p = f'(x)$ and  the map  $x\to  p$ is invertible because $f$ is convex.
For a more mathematical language: If the configuration space of the mechanical system is a manifold $M$ then Lagrange works in in the tangent bundle $T(M)$ with the fibre coordinate at $q\in M$ being  $\dot q$, and Hamilton works in the cotangent bundle $T^*(M)$  with fibre coordinates $p$.
A: 
What are the most important things missing from my interpretation of H and L?

I would add two things here. First note that any dynamical system of equations we can always re-write the system as a first order system by the standard trick of defining higher derivatives to be new variables and adding equations to fix the relationships of these new variables to the existing ones. Assuming the initial value problem is well-posed, the system can at least locally be inverted for the first time derivatives, so a system of equations with the form $\dot x=Q(x,t)$ is the most general ODE with unique solution. All such ODEs may be expressed as variational problems by doubling the number of variables is the system:
$$
L=p(\dot x-Q).
$$
This may seem like a silly trick, but nonetheless, it can be viewed as a reason why considering Lagrangians instead of ODEs themselves doesn't represent such a large loss of generality. Though I should also note that, to the best of my knowledge, the existence of a Lagrangian for a given ODE without introducing additional variables remains, in some respects, an open question. Peter Olver has some very nice notes written on this topic and other related topics for those who may be interested.
I would also add that key to the Hamiltonian perspective is the notion of phase space as a manifold and the action of transformations (including time translation) as flows on this manifold which are generated by some vector fields. Further description of this would likely take the answer too far afield, but I will just mention that moving in this direction would take one towards the geometry of symplectic manifolds. A nice introduction to this topic can be found in the final chapter of Quantum Field Theory: A Modern Perspective by V. Parameswaran Nair (there are many sources on this topic, but Nair is a nice one). This chapter may also answer some questions about the relation between the Hamiltonian and Lagrangian formalisms. The second and third chapters of the same book also make some comments on the extension of this formalism to PDEs more generally.
The key take-aways from all this, however, is that whenever we have a Lagrangian, there is a natural anti-symmetric bilinear form $\mathcal{F}\times\mathcal{F}\rightarrow\mathcal{F}$ where $\mathcal{F}$ is the space of scalar functions over the phase space (the (p,q) space) with the special property that if $Q$ is the conserved charge guarenteed by Noether's theorem associated to a continuous 1-parameter group of transformations parametrized by $\alpha$, then for any function $F\in\mathcal{F}$
$$
\frac{d F}{d\alpha}=\{F,Q\}
$$
where the $\alpha$ derivative is understood to mean the derivative of $F$ along the flow generated by the symmetry transformation in question. In more geometrical language, this may be understood as the Lie derivative with respect to the vector field generating the symmetry transformation. This bilinear form, known as the Poisson bracket, can then be used to define in a similar way charges and flows associated to transformations which are not necessarily symmetries (things are just particularly nice and explicit whenever Noether's theorem applies).
In particular then, assuming we can freely transform between $(q,\dot q)$ and $(q,p)$ coordinates, time evolution is equivalent to a flow in $(q,p)$ space, and hence there is some generating vector field, and hence there is some suggestively named function $H$ on the phase space whose Poisson brackets generate this flow (an explicit construction of the Poisson bracket would also show that the brackets $\{p,H\}$ and $\{q,H\}$ do indeed reproduce the Hamilton's equations mentioned in the question). As other answers have pointed out, in the special case of a time-independent Lagrangian the Hamiltonian is indeed the conserved Noether charge, and hence is the object which generates time translation via the Poisson bracket on the phase space. However, this relationship extends even to time-dependent Lagrangians.

How (and heuristically why) are these two objects related through the Legendre transform?

Let be first describe for the how a proof of equivalence. Define the object $H=p\dot q-L$ where $p=\frac{\partial L}{\partial \dot q}$. Then clearly the action may be written in terms of $H$ instead of $L$ by (leaving off the bounds and such because they will not matter for what I would like to say)
$$
S=\int dt(p\dot q-H(q,p))\cong-\int dt(\dot pq+H(q,p)),
$$
the Legendre transformation (assuming it exists) guaranteeing that $H$ is indeed a function of $q$ and $p$ and not a function of $\dot q$ (this can be checked directly using the definition of $p$ and the form of the Legendre transformation). The equality here is up to a boundary term.
Computing the $p$ variation of the first form of the action and the $q$ variation of the second reproduces Hamilton's equations of motion.
Why we should consider the Legendre transformation is a question which I think requires many additional details to answer in a way which (I feel) is satisfying. The details can be found in the final chapter of the book by Nair I mentioned earlier, but for now perhaps I will give a hint of the underlying structure which makes $H$ a natural quantity to define.
For any action $S$, whenever we compute its variation we always perform an integration by parts to change the terms with factors like $\frac{d}{dt}\delta q$ into terms which only have factors of $\delta q$. Indeed this is how the Euler-Lagrange equations are obtained. The total derivative terms that we obtain by these manipulations are always forgotten about with some comment about fixing initial and final conditions (which is fine). But let's actually look at what these boundary terms are for the special case of a Lagrangian which depends only on $q$ and $\dot q$:
$$
\delta L(q,\dot q)=\frac{\partial L}{\partial q}\delta q+\frac{\partial L}{\partial \dot q}\delta\dot q=\left(\frac{\partial L}{\partial q}-\frac{d}{d t}\frac{\partial L}{\partial \dot q}\right)\delta q+\frac{d}{dt}\left(\frac{\partial L}{\partial \dot q}\delta q\right).
$$
Define for a moment $\theta=\frac{\partial L}{\partial \dot q}\delta q=p\delta q$ and note that taking a variation of this object (this can be thought of as expanding to first order, but really should be formalized as a differential on the phase space) we would obtain something known as the symplectic form on the phase space in terms of which the Poisson bracket is ultimately defined. To avoid going into all the details here, I will just note that when we wrote the action in terms of the Hamiltonian, the first term was precisely $p$ times the (time) variation in $q$. This can all be made very precise and concrete, but perhaps this gives some inkling that there is an underlying structure which can be found by sufficiently careful analysis of the action's variation.

Picking up a Partial Differential Equation e.g :
∂tρt(x)=−div(ρ_t(x)∇_pH(x,−ρ^{−1}_t(x)∇P(ρ_t(x)))),
where ρ is the density of a fluid and P is its pressure. Why can we call this a Hamiltonian of the PDE?

While I cannot comment on this specific PDE, I can describe briefly what the generalization of Hamiltonian dynamics to field theory looks like.
For a field theory with fields $\phi$ and conjugate momenta $\pi$, we define the Hamiltonian to be the functional $H=\int d\boldsymbol x\mathcal{H}(\phi,\pi)$ where the integral is understood to run over space but not time. The object $\mathcal{H}$ is known as the Hamiltonian density.
In terms of these objects, the Hamiltonian equations of motion now take the form
$$
\partial_t\phi(t,\boldsymbol x)=\frac{\delta H(t)}{\delta\pi(t,\boldsymbol x)},\ \ \ \ \partial_t\pi(t,\boldsymbol x)=-\frac{\delta H(t)}{\delta \phi(t,\boldsymbol x)}.
$$
So in some vague, hand-waving sense (which may be made more precise in the paper referenced for this PDE, I don't know), any PDE brought into a form with the time derivatives isolated could be thought of as like a Hamiltonian system (though bringing a PDE into this form does not imply that a Hamiltonian exists, see earlier comments about existence of Lagrangians).
A: 
What are the most important things missing from my interpretation of H
and L?

Maybe an important feature is that the Hamiltonian is a conserved quantity of the Lagrangian if the later has no explicit dependence on time. Taking the time derivative of the Lagrangian:
$$\frac{dL}{dt} = \frac{\partial L}{\partial q} \dot q + \frac{\partial L}{\partial \dot q} \frac{\partial \dot q}{\partial t} + \frac{\partial L}{\partial t}$$
When q(t) corresponds to a stationary point of the action, it follows the Euler-Lagrange equations:
$$\frac{\partial L}{\partial q} = \frac{d \left(\frac{\partial L}{\partial \dot q}\right)}{dt}$$
Substituting in the expression of the time derivative:
$$\frac{dL}{dt} = \frac{d\left(\frac{\partial L}{\partial \dot q}\right)}{dt} \dot q + \frac{\partial L}{\partial \dot q} \frac{\partial \dot q}{\partial t} + \frac{\partial L}{\partial t} = \frac{d\left(\frac{\partial L}{\partial \dot q}\dot q\right)}{dt} + \frac{\partial L}{\partial t}$$
Defining: $$p = \frac{\partial L}{\partial \dot q}$$
The quantity: $p\dot q - L$ is conserved when the Lagrangian has no explicit time dependence. This conserved quantity is called Hamiltonian.
A: Jess Riedel writes in a blog post titled Legendre transform that there is a form of representing the Legrendre transform that makes it transparent what that transform entails:

Two convex functions f and g are Legendre transforms of each other
when their first derivatives are inverse functions

$$ g' = (f')^{-1}$$
That is, the Legendre transform is its own inverse.


There is an article Making sense of the Legrendre transform, in which the symmetry of the Legendre transform is discussed, and in what form the Legendre transform is applied in physics.
Let two functions, $F(x)$ and $G(s)$ be related in the following way:
$$ \frac{dG}{ds} = x \qquad \text{and} \qquad \frac{dF}{dx} = s $$
Then:
$$ G(s) + F(x) = sx $$
The authors emphasize that $s$ and $x$ are not independent variables here.
Rearranging:
$$ G(s) = sx - F(x)  $$
