A term in my log-likelihood can only be numerically approximated. To approximate this term, Brent’s root-finding method (which corresponds to function `uniroot`

in base R) needs to be used. Since the Stan Math library does not have the counterpart of `uniroot`

, I am planning to use an external C++ function that is not in the Stan Math library to perform the root-finding step.

My questions are :

a. Would numerical approximation of the term using a root-finding method prevent the autodifferentiation of Stan from working?

b. How should I import the external C++ function that is not in the Stan Math library? Do I simply follow the steps in interfacing with external C++ code (https://cran.r-project.org/web/packages/rstan/vignettes/external.html)?

Thank you!