\frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)}{x-scale}}{y-scale} \cdot \frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)}{x-scale}}{y-scale} - \left(4 \cdot \frac{\frac{{\left(a \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2} + {\left(b \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2}}{x-scale}}{x-scale}\right) \cdot \frac{\frac{{\left(a \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2} + {\left(b \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2}}{y-scale}}{y-scale}
\begin{array}{l}
t_0 := \frac{a}{y-scale} \cdot \frac{b}{x-scale}\\
\mathbf{if}\;\frac{angle}{180} \leq -8.107673630762209 \cdot 10^{+244}:\\
\;\;\;\;\frac{-4 \cdot \left(\left|\frac{a}{y-scale} \cdot b\right| \cdot \left|t_0\right|\right)}{\left|x-scale\right|}\\
\mathbf{elif}\;\frac{angle}{180} \leq -0.00033619766571942186:\\
\;\;\;\;-4 \cdot {\left(\left|\frac{a \cdot b}{y-scale \cdot x-scale}\right|\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\
\end{array}
(FPCore (a b angle x-scale y-scale)
:precision binary64
(-
(*
(/
(/
(*
(* (* 2.0 (- (pow b 2.0) (pow a 2.0))) (sin (* (/ angle 180.0) PI)))
(cos (* (/ angle 180.0) PI)))
x-scale)
y-scale)
(/
(/
(*
(* (* 2.0 (- (pow b 2.0) (pow a 2.0))) (sin (* (/ angle 180.0) PI)))
(cos (* (/ angle 180.0) PI)))
x-scale)
y-scale))
(*
(*
4.0
(/
(/
(+
(pow (* a (sin (* (/ angle 180.0) PI))) 2.0)
(pow (* b (cos (* (/ angle 180.0) PI))) 2.0))
x-scale)
x-scale))
(/
(/
(+
(pow (* a (cos (* (/ angle 180.0) PI))) 2.0)
(pow (* b (sin (* (/ angle 180.0) PI))) 2.0))
y-scale)
y-scale))))(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ a y-scale) (/ b x-scale))))
(if (<= (/ angle 180.0) -8.107673630762209e+244)
(/ (* -4.0 (* (fabs (* (/ a y-scale) b)) (fabs t_0))) (fabs x-scale))
(if (<= (/ angle 180.0) -0.00033619766571942186)
(* -4.0 (pow (fabs (/ (* a b) (* y-scale x-scale))) 2.0))
(* -4.0 (* t_0 t_0))))))double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((((((2.0 * (pow(b, 2.0) - pow(a, 2.0))) * sin((angle / 180.0) * ((double) M_PI))) * cos((angle / 180.0) * ((double) M_PI))) / x_45_scale) / y_45_scale) * (((((2.0 * (pow(b, 2.0) - pow(a, 2.0))) * sin((angle / 180.0) * ((double) M_PI))) * cos((angle / 180.0) * ((double) M_PI))) / x_45_scale) / y_45_scale)) - ((4.0 * (((pow((a * sin((angle / 180.0) * ((double) M_PI))), 2.0) + pow((b * cos((angle / 180.0) * ((double) M_PI))), 2.0)) / x_45_scale) / x_45_scale)) * (((pow((a * cos((angle / 180.0) * ((double) M_PI))), 2.0) + pow((b * sin((angle / 180.0) * ((double) M_PI))), 2.0)) / y_45_scale) / y_45_scale));
}
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (a / y_45_scale) * (b / x_45_scale);
double tmp;
if ((angle / 180.0) <= -8.107673630762209e+244) {
tmp = (-4.0 * (fabs((a / y_45_scale) * b) * fabs(t_0))) / fabs(x_45_scale);
} else if ((angle / 180.0) <= -0.00033619766571942186) {
tmp = -4.0 * pow(fabs((a * b) / (y_45_scale * x_45_scale)), 2.0);
} else {
tmp = -4.0 * (t_0 * t_0);
}
return tmp;
}



Bits error versus a



Bits error versus b



Bits error versus angle



Bits error versus x-scale



Bits error versus y-scale
Results
if (/.f64 angle 180) < -8.107673630762209e244Initial program 49.7
Taylor expanded in angle around 0 30.5
Applied pow-prod-down_binary6424.1
Applied add-sqr-sqrt_binary6424.1
Simplified24.2
Simplified3.4
Applied associate-*r/_binary644.4
Applied fabs-div_binary644.4
Applied associate-*l/_binary645.2
Applied associate-*r/_binary645.2
if -8.107673630762209e244 < (/.f64 angle 180) < -3.3619766571942186e-4Initial program 50.5
Taylor expanded in angle around 0 33.7
Applied pow-prod-down_binary6424.7
Applied add-sqr-sqrt_binary6424.7
Simplified25.5
Simplified4.3
Taylor expanded in a around 0 3.8
if -3.3619766571942186e-4 < (/.f64 angle 180) Initial program 47.2
Taylor expanded in angle around 0 34.0
Applied pow-prod-down_binary6426.1
Applied add-sqr-sqrt_binary6426.1
Simplified26.6
Simplified3.7
Applied sqr-abs_binary643.7
Final simplification3.8
herbie shell --seed 2022088
(FPCore (a b angle x-scale y-scale)
:name "Simplification of discriminant from scale-rotated-ellipse"
:precision binary64
(- (* (/ (/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) (sin (* (/ angle 180.0) PI))) (cos (* (/ angle 180.0) PI))) x-scale) y-scale) (/ (/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) (sin (* (/ angle 180.0) PI))) (cos (* (/ angle 180.0) PI))) x-scale) y-scale)) (* (* 4.0 (/ (/ (+ (pow (* a (sin (* (/ angle 180.0) PI))) 2.0) (pow (* b (cos (* (/ angle 180.0) PI))) 2.0)) x-scale) x-scale)) (/ (/ (+ (pow (* a (cos (* (/ angle 180.0) PI))) 2.0) (pow (* b (sin (* (/ angle 180.0) PI))) 2.0)) y-scale) y-scale))))