  This paper solves the rational noncommutative analog of Hilbert's 17th
problem: if a noncommutative rational function is positive semidefinite on all
tuples of hermitian matrices in its domain, then it is a sum of hermitian
squares of noncommutative rational functions. This result is a generalization
and culmination of earlier positivity certificates for noncommutative
polynomials or rational functions without hermitian singularities. More
generally, a rational Positivstellensatz for free spectrahedra is given: a
noncommutative rational function is positive semidefinite or undefined at every
matricial solution of a linear matrix inequality $L\succeq0$ if and only if it
belongs to the rational quadratic module generated by $L$. The essential
intermediate step towards this Positivstellensatz for functions with
singularities is an extension theorem for invertible evaluations of linear
matrix pencils.
