\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)\mathsf{hypot}\left(a1, a2\right) \cdot \frac{\mathsf{hypot}\left(a1, a2\right)}{\frac{\sqrt{2}}{\cos th}}double f(double a1, double a2, double th) {
double r89515 = th;
double r89516 = cos(r89515);
double r89517 = 2.0;
double r89518 = sqrt(r89517);
double r89519 = r89516 / r89518;
double r89520 = a1;
double r89521 = r89520 * r89520;
double r89522 = r89519 * r89521;
double r89523 = a2;
double r89524 = r89523 * r89523;
double r89525 = r89519 * r89524;
double r89526 = r89522 + r89525;
return r89526;
}
double f(double a1, double a2, double th) {
double r89527 = a1;
double r89528 = a2;
double r89529 = hypot(r89527, r89528);
double r89530 = 2.0;
double r89531 = sqrt(r89530);
double r89532 = th;
double r89533 = cos(r89532);
double r89534 = r89531 / r89533;
double r89535 = r89529 / r89534;
double r89536 = r89529 * r89535;
return r89536;
}



Bits error versus a1



Bits error versus a2



Bits error versus th
Results
Initial program 0.5
Simplified0.5
rmApplied add-sqr-sqrt0.5
Applied associate-*l*0.5
Simplified0.5
rmApplied fma-udef0.5
Applied hypot-def0.4
Final simplification0.4
herbie shell --seed 2020047 +o rules:numerics
(FPCore (a1 a2 th)
:name "Migdal et al, Equation (64)"
:precision binary64
(+ (* (/ (cos th) (sqrt 2)) (* a1 a1)) (* (/ (cos th) (sqrt 2)) (* a2 a2))))