Average Error: 41.3 → 6.5
Time: 56.7s
Precision: binary64
\[\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} \mathbf{if}\;b \leq -6.1587270237545874 \cdot 10^{+231} \lor \neg \left(b \leq -5.990122747829383 \cdot 10^{+177}\right):\\ \;\;\;\;-4 \cdot \left(\left(\frac{a}{x-scale} \cdot \frac{b}{y-scale}\right) \cdot \left(\frac{a}{x-scale} \cdot \frac{b}{y-scale}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \frac{{\left(b \cdot a\right)}^{2}}{\left(x-scale \cdot y-scale\right) \cdot \left(x-scale \cdot y-scale\right)}\\ \end{array}\]
\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}
\mathbf{if}\;b \leq -6.1587270237545874 \cdot 10^{+231} \lor \neg \left(b \leq -5.990122747829383 \cdot 10^{+177}\right):\\
\;\;\;\;-4 \cdot \left(\left(\frac{a}{x-scale} \cdot \frac{b}{y-scale}\right) \cdot \left(\frac{a}{x-scale} \cdot \frac{b}{y-scale}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;-4 \cdot \frac{{\left(b \cdot a\right)}^{2}}{\left(x-scale \cdot y-scale\right) \cdot \left(x-scale \cdot y-scale\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
 (if (or (<= b -6.1587270237545874e+231) (not (<= b -5.990122747829383e+177)))
   (* -4.0 (* (* (/ a x-scale) (/ b y-scale)) (* (/ a x-scale) (/ b y-scale))))
   (* -4.0 (/ (pow (* b a) 2.0) (* (* x-scale y-scale) (* x-scale y-scale))))))
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 tmp;
	if ((b <= -6.1587270237545874e+231) || !(b <= -5.990122747829383e+177)) {
		tmp = -4.0 * (((a / x_45_scale) * (b / y_45_scale)) * ((a / x_45_scale) * (b / y_45_scale)));
	} else {
		tmp = -4.0 * (pow((b * a), 2.0) / ((x_45_scale * y_45_scale) * (x_45_scale * y_45_scale)));
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus angle

Bits error versus x-scale

Bits error versus y-scale

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if b < -6.15872702375458742e231 or -5.9901227478293832e177 < b

    1. Initial program 40.5

      \[\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}\]
    2. Taylor expanded around 0 39.0

      \[\leadsto \color{blue}{-4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}}\]
    3. Simplified36.0

      \[\leadsto \color{blue}{-4 \cdot \frac{\left(b \cdot b\right) \cdot \left(a \cdot a\right)}{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}}\]
    4. Using strategy rm
    5. Applied pow2_binary64_186436.0

      \[\leadsto -4 \cdot \frac{\left(b \cdot b\right) \cdot \color{blue}{{a}^{2}}}{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}\]
    6. Applied pow2_binary64_186436.0

      \[\leadsto -4 \cdot \frac{\color{blue}{{b}^{2}} \cdot {a}^{2}}{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}\]
    7. Applied pow-prod-down_binary64_185426.9

      \[\leadsto -4 \cdot \frac{\color{blue}{{\left(b \cdot a\right)}^{2}}}{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}\]
    8. Using strategy rm
    9. Applied add-sqr-sqrt_binary64_180526.9

      \[\leadsto -4 \cdot \color{blue}{\left(\sqrt{\frac{{\left(b \cdot a\right)}^{2}}{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}} \cdot \sqrt{\frac{{\left(b \cdot a\right)}^{2}}{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}}\right)}\]
    10. Simplified28.4

      \[\leadsto -4 \cdot \left(\color{blue}{\left|\frac{a}{x-scale} \cdot \frac{b}{y-scale}\right|} \cdot \sqrt{\frac{{\left(b \cdot a\right)}^{2}}{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}}\right)\]
    11. Simplified5.9

      \[\leadsto -4 \cdot \left(\left|\frac{a}{x-scale} \cdot \frac{b}{y-scale}\right| \cdot \color{blue}{\left|\frac{a}{x-scale} \cdot \frac{b}{y-scale}\right|}\right)\]

    if -6.15872702375458742e231 < b < -5.9901227478293832e177

    1. Initial program 64.0

      \[\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}\]
    2. Taylor expanded around 0 64.0

      \[\leadsto \color{blue}{-4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}}\]
    3. Simplified64.0

      \[\leadsto \color{blue}{-4 \cdot \frac{\left(b \cdot b\right) \cdot \left(a \cdot a\right)}{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}}\]
    4. Using strategy rm
    5. Applied pow2_binary64_186464.0

      \[\leadsto -4 \cdot \frac{\left(b \cdot b\right) \cdot \color{blue}{{a}^{2}}}{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}\]
    6. Applied pow2_binary64_186464.0

      \[\leadsto -4 \cdot \frac{\color{blue}{{b}^{2}} \cdot {a}^{2}}{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}\]
    7. Applied pow-prod-down_binary64_185434.2

      \[\leadsto -4 \cdot \frac{\color{blue}{{\left(b \cdot a\right)}^{2}}}{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}\]
    8. Using strategy rm
    9. Applied add-sqr-sqrt_binary64_180534.2

      \[\leadsto -4 \cdot \frac{{\left(b \cdot a\right)}^{2}}{\color{blue}{\sqrt{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)} \cdot \sqrt{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}}}\]
    10. Simplified34.2

      \[\leadsto -4 \cdot \frac{{\left(b \cdot a\right)}^{2}}{\color{blue}{\left|x-scale \cdot y-scale\right|} \cdot \sqrt{x-scale \cdot \left(x-scale \cdot \left(y-scale \cdot y-scale\right)\right)}}\]
    11. Simplified25.1

      \[\leadsto -4 \cdot \frac{{\left(b \cdot a\right)}^{2}}{\left|x-scale \cdot y-scale\right| \cdot \color{blue}{\left|x-scale \cdot y-scale\right|}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification6.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -6.1587270237545874 \cdot 10^{+231} \lor \neg \left(b \leq -5.990122747829383 \cdot 10^{+177}\right):\\ \;\;\;\;-4 \cdot \left(\left(\frac{a}{x-scale} \cdot \frac{b}{y-scale}\right) \cdot \left(\frac{a}{x-scale} \cdot \frac{b}{y-scale}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \frac{{\left(b \cdot a\right)}^{2}}{\left(x-scale \cdot y-scale\right) \cdot \left(x-scale \cdot y-scale\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2020358 
(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))))