Theoretically, this is possible if you are ready to use your own set of mathematical functions and numbers. What you need to do is create a type system that tracks how each function is calculated. Then it will be reflected in the type of expression. Using either the haskell template and the reify function, or using the code of a type class, you can generate the correct code at compile time.
Here is an example of a hacked selection using type classes. It works with sin, cos, constants and addition. It would be a lot of work to implement a full range of operations. In addition, there is a fair bit of duplication in the code, if you plan to use this approach, you should try to fix this problem:
{-
source share