How do we define the cotangent space as the quotient of ideals?

This is basically an algebraic construction, that goes as follows: suppose $M$ is a smooth manifold of dimension $n$.

$1).\ $ For fixed $p\in M$, define $m_{p}$ $\subseteq C^{\infty}(M)$ to be the subalgebra of functions such that $f(p)=0.$

$2).\ $ Let $v$ be a derivation in $T_pM$ and define $m_p^2:=\{h\in C^{\infty}(M):h=fg \ \text{for some }\ f,g\in m_p\}.$ Since $v$ is a derivation, it follows easily from $1).$ that $h\in m_p^2\Rightarrow v(h)=0.$

$3).\ $ Define $\Phi_v:m_p/m^2_p \rightarrow \mathbb R$ by $\Phi_{v}(\varphi+fg)=v(\varphi).$ This map is well-defined because $v(fg)=0$ and it is obviously linear. It follows that every $v\in T_pM$ uniquely determines such a linear map $\Phi_v$.

$4).\ $ Now let $\Phi:m_p/m^2_p \rightarrow \mathbb R$ be any linear functional. Define $v:C^{\infty}(M)\to \mathbb R$ by $v(f)=\Phi\circ \pi(f-f(p))$ where $\pi$ is the evident quotient map. It is tedious but routine to show that $v$ is a derivation.

$5).\ 3).\ $ and $4).\ $ combine to show that $(m_p/m_p^2)^*\cong T_pM$ and in particular shows that $\dim m_p/m_p^2=\dim (m_p/m_p^2)^*=\dim T_pM=n.$

$6).\ $ One can also prove finite dimensionality of $m_p/m_p^2$ directly: take local coordinates $(U,x)$ about $p\in M$. Then $x^i(p)=0$ for $1\le i\le n$. If $f\in m_p,$ then $f(x)=0$ at $p$. Now, apply Hadamard's lemma to find $g_i\in C^{\infty}(U)$ such that $f(x)=\sum^n_{k=1} x^kg_k(x)=xg_1(x)+\sum^n_{k=2}x^kg_k(x)$ and since $\sum^n_{k=2}x^kg_k(x)\in m_p^2$ we have that $f\sim xg_1.$ That is, $f(x^1,\cdots,x^n)\sim (x^1,\cdots,x^n)\cdot g_1(x^1,\cdots,x^n)$ and the RHS of this spans a vector space of dimension $n$ as $f$ varies through $C^{\infty}(M).$