It's maybe easier to think of this along the lines of implementations of the models underlying QuantLib (R interface here: https://cran.r-project.org/web/packages/RQuantLib/RQuantLib.pdf).
So, to give a simplified example: under the Vasicek model for interest rates (https://en.wikipedia.org/wiki/Vasicek_model) we can solve a formula for pricing zero coupon bonds (see Theorem 4.4 here: https://web.mst.edu/~bohner/fim-10/fim-chap4.pdf for more details - struggling to work out how to add formula in this post!).
If we were to implement this bond pricing formula in a function, the question is then how do we go about verifying that the implementation of that formula in code is correct.
Whilst some edge case unit tests could be added relatively easily (in this example we might think about when interest rates rise bond prices tend to zero; as interest rates tend to zero, bond prices tend to 1; as maturity increases bond prices tend to zero) it's not possible to just write down the correct output for some typical set of input parameters without actually re-implementing the formula.
Under 1 in the original question, the implementation would be verified by having someone independently review that the code is correctly implementing the mathematical formula.
Under 2 in the original question, the implementation would be verified by having someone independently implement the mathematical formula and then compare outputs.
As the formula becomes more complex, both 1 and 2 become harder / more costly but both have their pros and cons.
I'd be particularly interested in the experience of anyone from the insurance or banking industries, as this scenario must be a common challenge when giving comfort to both internal and external auditors?