Simplification of discriminant from scale-rotated-ellipse

Percentage Accurate: 24.4% → 94.2%
Time: 2.1min
Alternatives: 5
Speedup: 1777.0×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{angle}{180} \cdot \pi\\ t_1 := \sin t_0\\ t_2 := \cos t_0\\ t_3 := \frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t_1\right) \cdot t_2}{x-scale}}{y-scale}\\ t_3 \cdot t_3 - \left(4 \cdot \frac{\frac{{\left(a \cdot t_1\right)}^{2} + {\left(b \cdot t_2\right)}^{2}}{x-scale}}{x-scale}\right) \cdot \frac{\frac{{\left(a \cdot t_2\right)}^{2} + {\left(b \cdot t_1\right)}^{2}}{y-scale}}{y-scale} \end{array} \end{array} \]
(FPCore (a b angle x-scale y-scale)
 :precision binary64
 (let* ((t_0 (* (/ angle 180.0) PI))
        (t_1 (sin t_0))
        (t_2 (cos t_0))
        (t_3
         (/
          (/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) t_1) t_2) x-scale)
          y-scale)))
   (-
    (* t_3 t_3)
    (*
     (*
      4.0
      (/ (/ (+ (pow (* a t_1) 2.0) (pow (* b t_2) 2.0)) x-scale) x-scale))
     (/ (/ (+ (pow (* a t_2) 2.0) (pow (* b t_1) 2.0)) y-scale) y-scale)))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
	double t_0 = (angle / 180.0) * ((double) M_PI);
	double t_1 = sin(t_0);
	double t_2 = cos(t_0);
	double t_3 = ((((2.0 * (pow(b, 2.0) - pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale;
	return (t_3 * t_3) - ((4.0 * (((pow((a * t_1), 2.0) + pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((pow((a * t_2), 2.0) + pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale));
}
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
	double t_0 = (angle / 180.0) * Math.PI;
	double t_1 = Math.sin(t_0);
	double t_2 = Math.cos(t_0);
	double t_3 = ((((2.0 * (Math.pow(b, 2.0) - Math.pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale;
	return (t_3 * t_3) - ((4.0 * (((Math.pow((a * t_1), 2.0) + Math.pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((Math.pow((a * t_2), 2.0) + Math.pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale));
}
def code(a, b, angle, x_45_scale, y_45_scale):
	t_0 = (angle / 180.0) * math.pi
	t_1 = math.sin(t_0)
	t_2 = math.cos(t_0)
	t_3 = ((((2.0 * (math.pow(b, 2.0) - math.pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale
	return (t_3 * t_3) - ((4.0 * (((math.pow((a * t_1), 2.0) + math.pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((math.pow((a * t_2), 2.0) + math.pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale))
function code(a, b, angle, x_45_scale, y_45_scale)
	t_0 = Float64(Float64(angle / 180.0) * pi)
	t_1 = sin(t_0)
	t_2 = cos(t_0)
	t_3 = Float64(Float64(Float64(Float64(Float64(2.0 * Float64((b ^ 2.0) - (a ^ 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale)
	return Float64(Float64(t_3 * t_3) - Float64(Float64(4.0 * Float64(Float64(Float64((Float64(a * t_1) ^ 2.0) + (Float64(b * t_2) ^ 2.0)) / x_45_scale) / x_45_scale)) * Float64(Float64(Float64((Float64(a * t_2) ^ 2.0) + (Float64(b * t_1) ^ 2.0)) / y_45_scale) / y_45_scale)))
end
function tmp = code(a, b, angle, x_45_scale, y_45_scale)
	t_0 = (angle / 180.0) * pi;
	t_1 = sin(t_0);
	t_2 = cos(t_0);
	t_3 = ((((2.0 * ((b ^ 2.0) - (a ^ 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale;
	tmp = (t_3 * t_3) - ((4.0 * (((((a * t_1) ^ 2.0) + ((b * t_2) ^ 2.0)) / x_45_scale) / x_45_scale)) * (((((a * t_2) ^ 2.0) + ((b * t_1) ^ 2.0)) / y_45_scale) / y_45_scale));
end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, Block[{t$95$1 = N[Sin[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Cos[t$95$0], $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[(2.0 * N[(N[Power[b, 2.0], $MachinePrecision] - N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision] * t$95$2), $MachinePrecision] / x$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]}, N[(N[(t$95$3 * t$95$3), $MachinePrecision] - N[(N[(4.0 * N[(N[(N[(N[Power[N[(a * t$95$1), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * t$95$2), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / x$45$scale), $MachinePrecision] / x$45$scale), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[Power[N[(a * t$95$2), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * t$95$1), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / y$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
t_1 := \sin t_0\\
t_2 := \cos t_0\\
t_3 := \frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t_1\right) \cdot t_2}{x-scale}}{y-scale}\\
t_3 \cdot t_3 - \left(4 \cdot \frac{\frac{{\left(a \cdot t_1\right)}^{2} + {\left(b \cdot t_2\right)}^{2}}{x-scale}}{x-scale}\right) \cdot \frac{\frac{{\left(a \cdot t_2\right)}^{2} + {\left(b \cdot t_1\right)}^{2}}{y-scale}}{y-scale}
\end{array}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 24.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{angle}{180} \cdot \pi\\ t_1 := \sin t_0\\ t_2 := \cos t_0\\ t_3 := \frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t_1\right) \cdot t_2}{x-scale}}{y-scale}\\ t_3 \cdot t_3 - \left(4 \cdot \frac{\frac{{\left(a \cdot t_1\right)}^{2} + {\left(b \cdot t_2\right)}^{2}}{x-scale}}{x-scale}\right) \cdot \frac{\frac{{\left(a \cdot t_2\right)}^{2} + {\left(b \cdot t_1\right)}^{2}}{y-scale}}{y-scale} \end{array} \end{array} \]
(FPCore (a b angle x-scale y-scale)
 :precision binary64
 (let* ((t_0 (* (/ angle 180.0) PI))
        (t_1 (sin t_0))
        (t_2 (cos t_0))
        (t_3
         (/
          (/ (* (* (* 2.0 (- (pow b 2.0) (pow a 2.0))) t_1) t_2) x-scale)
          y-scale)))
   (-
    (* t_3 t_3)
    (*
     (*
      4.0
      (/ (/ (+ (pow (* a t_1) 2.0) (pow (* b t_2) 2.0)) x-scale) x-scale))
     (/ (/ (+ (pow (* a t_2) 2.0) (pow (* b t_1) 2.0)) y-scale) y-scale)))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
	double t_0 = (angle / 180.0) * ((double) M_PI);
	double t_1 = sin(t_0);
	double t_2 = cos(t_0);
	double t_3 = ((((2.0 * (pow(b, 2.0) - pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale;
	return (t_3 * t_3) - ((4.0 * (((pow((a * t_1), 2.0) + pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((pow((a * t_2), 2.0) + pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale));
}
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
	double t_0 = (angle / 180.0) * Math.PI;
	double t_1 = Math.sin(t_0);
	double t_2 = Math.cos(t_0);
	double t_3 = ((((2.0 * (Math.pow(b, 2.0) - Math.pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale;
	return (t_3 * t_3) - ((4.0 * (((Math.pow((a * t_1), 2.0) + Math.pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((Math.pow((a * t_2), 2.0) + Math.pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale));
}
def code(a, b, angle, x_45_scale, y_45_scale):
	t_0 = (angle / 180.0) * math.pi
	t_1 = math.sin(t_0)
	t_2 = math.cos(t_0)
	t_3 = ((((2.0 * (math.pow(b, 2.0) - math.pow(a, 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale
	return (t_3 * t_3) - ((4.0 * (((math.pow((a * t_1), 2.0) + math.pow((b * t_2), 2.0)) / x_45_scale) / x_45_scale)) * (((math.pow((a * t_2), 2.0) + math.pow((b * t_1), 2.0)) / y_45_scale) / y_45_scale))
function code(a, b, angle, x_45_scale, y_45_scale)
	t_0 = Float64(Float64(angle / 180.0) * pi)
	t_1 = sin(t_0)
	t_2 = cos(t_0)
	t_3 = Float64(Float64(Float64(Float64(Float64(2.0 * Float64((b ^ 2.0) - (a ^ 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale)
	return Float64(Float64(t_3 * t_3) - Float64(Float64(4.0 * Float64(Float64(Float64((Float64(a * t_1) ^ 2.0) + (Float64(b * t_2) ^ 2.0)) / x_45_scale) / x_45_scale)) * Float64(Float64(Float64((Float64(a * t_2) ^ 2.0) + (Float64(b * t_1) ^ 2.0)) / y_45_scale) / y_45_scale)))
end
function tmp = code(a, b, angle, x_45_scale, y_45_scale)
	t_0 = (angle / 180.0) * pi;
	t_1 = sin(t_0);
	t_2 = cos(t_0);
	t_3 = ((((2.0 * ((b ^ 2.0) - (a ^ 2.0))) * t_1) * t_2) / x_45_scale) / y_45_scale;
	tmp = (t_3 * t_3) - ((4.0 * (((((a * t_1) ^ 2.0) + ((b * t_2) ^ 2.0)) / x_45_scale) / x_45_scale)) * (((((a * t_2) ^ 2.0) + ((b * t_1) ^ 2.0)) / y_45_scale) / y_45_scale));
end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, Block[{t$95$1 = N[Sin[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Cos[t$95$0], $MachinePrecision]}, Block[{t$95$3 = N[(N[(N[(N[(N[(2.0 * N[(N[Power[b, 2.0], $MachinePrecision] - N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision] * t$95$2), $MachinePrecision] / x$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]}, N[(N[(t$95$3 * t$95$3), $MachinePrecision] - N[(N[(4.0 * N[(N[(N[(N[Power[N[(a * t$95$1), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * t$95$2), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / x$45$scale), $MachinePrecision] / x$45$scale), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[Power[N[(a * t$95$2), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * t$95$1), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / y$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
t_1 := \sin t_0\\
t_2 := \cos t_0\\
t_3 := \frac{\frac{\left(\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot t_1\right) \cdot t_2}{x-scale}}{y-scale}\\
t_3 \cdot t_3 - \left(4 \cdot \frac{\frac{{\left(a \cdot t_1\right)}^{2} + {\left(b \cdot t_2\right)}^{2}}{x-scale}}{x-scale}\right) \cdot \frac{\frac{{\left(a \cdot t_2\right)}^{2} + {\left(b \cdot t_1\right)}^{2}}{y-scale}}{y-scale}
\end{array}
\end{array}

Alternative 1: 94.2% accurate, 14.4× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ \begin{array}{l} \mathbf{if}\;a_m \leq 1.2 \cdot 10^{+235}:\\ \;\;\;\;-4 \cdot {\left(\frac{a_m}{x-scale \cdot y-scale} \cdot b\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-4}{{\left(\frac{x-scale}{a_m} \cdot \frac{y-scale}{b}\right)}^{2}}\\ \end{array} \end{array} \]
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
 :precision binary64
 (if (<= a_m 1.2e+235)
   (* -4.0 (pow (* (/ a_m (* x-scale y-scale)) b) 2.0))
   (/ -4.0 (pow (* (/ x-scale a_m) (/ y-scale b)) 2.0))))
a_m = fabs(a);
double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
	double tmp;
	if (a_m <= 1.2e+235) {
		tmp = -4.0 * pow(((a_m / (x_45_scale * y_45_scale)) * b), 2.0);
	} else {
		tmp = -4.0 / pow(((x_45_scale / a_m) * (y_45_scale / b)), 2.0);
	}
	return tmp;
}
a_m = abs(a)
real(8) function code(a_m, b, angle, x_45scale, y_45scale)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b
    real(8), intent (in) :: angle
    real(8), intent (in) :: x_45scale
    real(8), intent (in) :: y_45scale
    real(8) :: tmp
    if (a_m <= 1.2d+235) then
        tmp = (-4.0d0) * (((a_m / (x_45scale * y_45scale)) * b) ** 2.0d0)
    else
        tmp = (-4.0d0) / (((x_45scale / a_m) * (y_45scale / b)) ** 2.0d0)
    end if
    code = tmp
end function
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
	double tmp;
	if (a_m <= 1.2e+235) {
		tmp = -4.0 * Math.pow(((a_m / (x_45_scale * y_45_scale)) * b), 2.0);
	} else {
		tmp = -4.0 / Math.pow(((x_45_scale / a_m) * (y_45_scale / b)), 2.0);
	}
	return tmp;
}
a_m = math.fabs(a)
def code(a_m, b, angle, x_45_scale, y_45_scale):
	tmp = 0
	if a_m <= 1.2e+235:
		tmp = -4.0 * math.pow(((a_m / (x_45_scale * y_45_scale)) * b), 2.0)
	else:
		tmp = -4.0 / math.pow(((x_45_scale / a_m) * (y_45_scale / b)), 2.0)
	return tmp
a_m = abs(a)
function code(a_m, b, angle, x_45_scale, y_45_scale)
	tmp = 0.0
	if (a_m <= 1.2e+235)
		tmp = Float64(-4.0 * (Float64(Float64(a_m / Float64(x_45_scale * y_45_scale)) * b) ^ 2.0));
	else
		tmp = Float64(-4.0 / (Float64(Float64(x_45_scale / a_m) * Float64(y_45_scale / b)) ^ 2.0));
	end
	return tmp
end
a_m = abs(a);
function tmp_2 = code(a_m, b, angle, x_45_scale, y_45_scale)
	tmp = 0.0;
	if (a_m <= 1.2e+235)
		tmp = -4.0 * (((a_m / (x_45_scale * y_45_scale)) * b) ^ 2.0);
	else
		tmp = -4.0 / (((x_45_scale / a_m) * (y_45_scale / b)) ^ 2.0);
	end
	tmp_2 = tmp;
end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_, angle_, x$45$scale_, y$45$scale_] := If[LessEqual[a$95$m, 1.2e+235], N[(-4.0 * N[Power[N[(N[(a$95$m / N[(x$45$scale * y$45$scale), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(-4.0 / N[Power[N[(N[(x$45$scale / a$95$m), $MachinePrecision] * N[(y$45$scale / b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a_m = \left|a\right|

\\
\begin{array}{l}
\mathbf{if}\;a_m \leq 1.2 \cdot 10^{+235}:\\
\;\;\;\;-4 \cdot {\left(\frac{a_m}{x-scale \cdot y-scale} \cdot b\right)}^{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{-4}{{\left(\frac{x-scale}{a_m} \cdot \frac{y-scale}{b}\right)}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 1.2e235

    1. Initial program 26.2%

      \[\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. Simplified24.1%

      \[\leadsto \color{blue}{\frac{\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \left(\sin \left(\frac{angle}{180} \cdot \pi\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}{y-scale \cdot x-scale} \cdot \frac{\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \left(\sin \left(\frac{angle}{180} \cdot \pi\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}{y-scale \cdot x-scale} - 4 \cdot \left(\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}^{2}} \cdot \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}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in angle around 0 47.9%

      \[\leadsto \color{blue}{-4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
    5. Step-by-step derivation
      1. associate-*r/47.9%

        \[\leadsto \color{blue}{\frac{-4 \cdot \left({a}^{2} \cdot {b}^{2}\right)}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
      2. *-commutative47.9%

        \[\leadsto \frac{-4 \cdot \color{blue}{\left({b}^{2} \cdot {a}^{2}\right)}}{{x-scale}^{2} \cdot {y-scale}^{2}} \]
      3. unpow247.9%

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

        \[\leadsto \frac{-4 \cdot \left({b}^{2} \cdot {a}^{2}\right)}{\color{blue}{\left(x-scale \cdot x-scale\right)} \cdot \left(y-scale \cdot y-scale\right)} \]
      5. swap-sqr60.5%

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

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

      \[\leadsto \color{blue}{\frac{-4 \cdot \left({b}^{2} \cdot {a}^{2}\right)}{{\left(x-scale \cdot y-scale\right)}^{2}}} \]
    7. Step-by-step derivation
      1. pow-prod-down47.9%

        \[\leadsto \frac{-4 \cdot \left({b}^{2} \cdot {a}^{2}\right)}{\color{blue}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
      2. associate-*r/47.9%

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-4 \cdot \frac{{b}^{2} \cdot {a}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}\right)\right)} \]
      4. expm1-udef25.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(-4 \cdot \frac{{b}^{2} \cdot {a}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}\right)} - 1} \]
      5. div-inv25.5%

        \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \color{blue}{\left(\left({b}^{2} \cdot {a}^{2}\right) \cdot \frac{1}{{x-scale}^{2} \cdot {y-scale}^{2}}\right)}\right)} - 1 \]
      6. *-commutative25.5%

        \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left(\color{blue}{\left({a}^{2} \cdot {b}^{2}\right)} \cdot \frac{1}{{x-scale}^{2} \cdot {y-scale}^{2}}\right)\right)} - 1 \]
      7. pow-prod-down28.4%

        \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left(\color{blue}{{\left(a \cdot b\right)}^{2}} \cdot \frac{1}{{x-scale}^{2} \cdot {y-scale}^{2}}\right)\right)} - 1 \]
      8. pow-prod-down32.5%

        \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot \frac{1}{\color{blue}{{\left(x-scale \cdot y-scale\right)}^{2}}}\right)\right)} - 1 \]
      9. *-commutative32.5%

        \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot \frac{1}{{\color{blue}{\left(y-scale \cdot x-scale\right)}}^{2}}\right)\right)} - 1 \]
      10. pow-flip32.5%

        \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot \color{blue}{{\left(y-scale \cdot x-scale\right)}^{\left(-2\right)}}\right)\right)} - 1 \]
      11. *-commutative32.5%

        \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot {\color{blue}{\left(x-scale \cdot y-scale\right)}}^{\left(-2\right)}\right)\right)} - 1 \]
      12. metadata-eval32.5%

        \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot {\left(x-scale \cdot y-scale\right)}^{\color{blue}{-2}}\right)\right)} - 1 \]
    8. Applied egg-rr32.5%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot {\left(x-scale \cdot y-scale\right)}^{-2}\right)\right)} - 1} \]
    9. Step-by-step derivation
      1. expm1-def39.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot {\left(x-scale \cdot y-scale\right)}^{-2}\right)\right)\right)} \]
      2. expm1-log1p78.3%

        \[\leadsto \color{blue}{-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot {\left(x-scale \cdot y-scale\right)}^{-2}\right)} \]
      3. *-commutative78.3%

        \[\leadsto \color{blue}{\left({\left(a \cdot b\right)}^{2} \cdot {\left(x-scale \cdot y-scale\right)}^{-2}\right) \cdot -4} \]
      4. associate-*l*78.3%

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

      \[\leadsto \color{blue}{{\left(a \cdot b\right)}^{2} \cdot \left({\left(x-scale \cdot y-scale\right)}^{-2} \cdot -4\right)} \]
    11. Step-by-step derivation
      1. unpow278.3%

        \[\leadsto \color{blue}{\left(\left(a \cdot b\right) \cdot \left(a \cdot b\right)\right)} \cdot \left({\left(x-scale \cdot y-scale\right)}^{-2} \cdot -4\right) \]
    12. Applied egg-rr78.3%

      \[\leadsto \color{blue}{\left(\left(a \cdot b\right) \cdot \left(a \cdot b\right)\right)} \cdot \left({\left(x-scale \cdot y-scale\right)}^{-2} \cdot -4\right) \]
    13. Taylor expanded in a around 0 47.9%

      \[\leadsto \color{blue}{-4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
    14. Step-by-step derivation
      1. unpow247.9%

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

        \[\leadsto -4 \cdot \frac{\left(a \cdot a\right) \cdot \color{blue}{\left(b \cdot b\right)}}{{x-scale}^{2} \cdot {y-scale}^{2}} \]
      3. swap-sqr59.3%

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

        \[\leadsto -4 \cdot \frac{\color{blue}{{\left(a \cdot b\right)}^{2}}}{{x-scale}^{2} \cdot {y-scale}^{2}} \]
      5. associate-*r/59.3%

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

        \[\leadsto \frac{-4 \cdot {\left(a \cdot b\right)}^{2}}{\color{blue}{\left(x-scale \cdot x-scale\right)} \cdot {y-scale}^{2}} \]
      7. unpow259.3%

        \[\leadsto \frac{-4 \cdot {\left(a \cdot b\right)}^{2}}{\left(x-scale \cdot x-scale\right) \cdot \color{blue}{\left(y-scale \cdot y-scale\right)}} \]
      8. swap-sqr78.2%

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

        \[\leadsto \frac{-4 \cdot {\left(a \cdot b\right)}^{2}}{\color{blue}{{\left(x-scale \cdot y-scale\right)}^{2}}} \]
      10. associate-/l*77.9%

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

        \[\leadsto \frac{-4}{\frac{\color{blue}{\left(x-scale \cdot y-scale\right) \cdot \left(x-scale \cdot y-scale\right)}}{{\left(a \cdot b\right)}^{2}}} \]
      12. associate-/l*83.4%

        \[\leadsto \frac{-4}{\color{blue}{\frac{x-scale \cdot y-scale}{\frac{{\left(a \cdot b\right)}^{2}}{x-scale \cdot y-scale}}}} \]
      13. *-rgt-identity83.4%

        \[\leadsto \frac{-4}{\frac{x-scale \cdot y-scale}{\frac{\color{blue}{{\left(a \cdot b\right)}^{2} \cdot 1}}{x-scale \cdot y-scale}}} \]
      14. associate-*r/83.4%

        \[\leadsto \frac{-4}{\frac{x-scale \cdot y-scale}{\color{blue}{{\left(a \cdot b\right)}^{2} \cdot \frac{1}{x-scale \cdot y-scale}}}} \]
      15. associate-/l*83.7%

        \[\leadsto \color{blue}{\frac{-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot \frac{1}{x-scale \cdot y-scale}\right)}{x-scale \cdot y-scale}} \]
    15. Simplified94.4%

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

    if 1.2e235 < a

    1. Initial program 0.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. Simplified0.0%

      \[\leadsto \color{blue}{\frac{\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \left(\sin \left(\frac{angle}{180} \cdot \pi\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}{y-scale \cdot x-scale} \cdot \frac{\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \left(\sin \left(\frac{angle}{180} \cdot \pi\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}{y-scale \cdot x-scale} - 4 \cdot \left(\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}^{2}} \cdot \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}^{2}}\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in angle around 0 50.0%

      \[\leadsto \color{blue}{-4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
    5. Step-by-step derivation
      1. *-commutative50.0%

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

      \[\leadsto \color{blue}{-4 \cdot \frac{{b}^{2} \cdot {a}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
    7. Step-by-step derivation
      1. associate-*r/50.0%

        \[\leadsto \color{blue}{\frac{-4 \cdot \left({b}^{2} \cdot {a}^{2}\right)}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
      2. associate-/l*50.0%

        \[\leadsto \color{blue}{\frac{-4}{\frac{{x-scale}^{2} \cdot {y-scale}^{2}}{{b}^{2} \cdot {a}^{2}}}} \]
      3. pow-prod-down58.7%

        \[\leadsto \frac{-4}{\frac{\color{blue}{{\left(x-scale \cdot y-scale\right)}^{2}}}{{b}^{2} \cdot {a}^{2}}} \]
      4. *-commutative58.7%

        \[\leadsto \frac{-4}{\frac{{\left(x-scale \cdot y-scale\right)}^{2}}{\color{blue}{{a}^{2} \cdot {b}^{2}}}} \]
      5. pow-prod-down75.6%

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

      \[\leadsto \color{blue}{\frac{-4}{\frac{{\left(x-scale \cdot y-scale\right)}^{2}}{{\left(a \cdot b\right)}^{2}}}} \]
    9. Step-by-step derivation
      1. unpow275.6%

        \[\leadsto \color{blue}{\left(\left(a \cdot b\right) \cdot \left(a \cdot b\right)\right)} \cdot \left({\left(x-scale \cdot y-scale\right)}^{-2} \cdot -4\right) \]
    10. Applied egg-rr75.6%

      \[\leadsto \frac{-4}{\frac{{\left(x-scale \cdot y-scale\right)}^{2}}{\color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)}}} \]
    11. Taylor expanded in x-scale around 0 50.0%

      \[\leadsto \frac{-4}{\color{blue}{\frac{{x-scale}^{2} \cdot {y-scale}^{2}}{{a}^{2} \cdot {b}^{2}}}} \]
    12. Step-by-step derivation
      1. unpow250.0%

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

        \[\leadsto \frac{-4}{\frac{\left(x-scale \cdot x-scale\right) \cdot \color{blue}{\left(y-scale \cdot y-scale\right)}}{{a}^{2} \cdot {b}^{2}}} \]
      3. swap-sqr58.7%

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

        \[\leadsto \frac{-4}{\frac{\color{blue}{{\left(x-scale \cdot y-scale\right)}^{2}}}{{a}^{2} \cdot {b}^{2}}} \]
      5. unpow258.7%

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

        \[\leadsto \frac{-4}{\frac{{\left(x-scale \cdot y-scale\right)}^{2}}{\left(a \cdot a\right) \cdot \color{blue}{\left(b \cdot b\right)}}} \]
      7. swap-sqr75.6%

        \[\leadsto \frac{-4}{\frac{{\left(x-scale \cdot y-scale\right)}^{2}}{\color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)}}} \]
      8. associate-/l/83.6%

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

        \[\leadsto \frac{-4}{\frac{\frac{\color{blue}{\left(x-scale \cdot y-scale\right) \cdot \left(x-scale \cdot y-scale\right)}}{a \cdot b}}{a \cdot b}} \]
      10. associate-*r/99.6%

        \[\leadsto \frac{-4}{\frac{\color{blue}{\left(x-scale \cdot y-scale\right) \cdot \frac{x-scale \cdot y-scale}{a \cdot b}}}{a \cdot b}} \]
      11. associate-*l/99.7%

        \[\leadsto \frac{-4}{\color{blue}{\frac{x-scale \cdot y-scale}{a \cdot b} \cdot \frac{x-scale \cdot y-scale}{a \cdot b}}} \]
      12. unpow299.7%

        \[\leadsto \frac{-4}{\color{blue}{{\left(\frac{x-scale \cdot y-scale}{a \cdot b}\right)}^{2}}} \]
      13. times-frac97.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq 1.2 \cdot 10^{+235}:\\ \;\;\;\;-4 \cdot {\left(\frac{a}{x-scale \cdot y-scale} \cdot b\right)}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-4}{{\left(\frac{x-scale}{a} \cdot \frac{y-scale}{b}\right)}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 94.1% accurate, 15.1× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ -4 \cdot {\left(\frac{a_m}{x-scale \cdot y-scale} \cdot b\right)}^{2} \end{array} \]
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
 :precision binary64
 (* -4.0 (pow (* (/ a_m (* x-scale y-scale)) b) 2.0)))
a_m = fabs(a);
double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
	return -4.0 * pow(((a_m / (x_45_scale * y_45_scale)) * b), 2.0);
}
a_m = abs(a)
real(8) function code(a_m, b, angle, x_45scale, y_45scale)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b
    real(8), intent (in) :: angle
    real(8), intent (in) :: x_45scale
    real(8), intent (in) :: y_45scale
    code = (-4.0d0) * (((a_m / (x_45scale * y_45scale)) * b) ** 2.0d0)
end function
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
	return -4.0 * Math.pow(((a_m / (x_45_scale * y_45_scale)) * b), 2.0);
}
a_m = math.fabs(a)
def code(a_m, b, angle, x_45_scale, y_45_scale):
	return -4.0 * math.pow(((a_m / (x_45_scale * y_45_scale)) * b), 2.0)
a_m = abs(a)
function code(a_m, b, angle, x_45_scale, y_45_scale)
	return Float64(-4.0 * (Float64(Float64(a_m / Float64(x_45_scale * y_45_scale)) * b) ^ 2.0))
end
a_m = abs(a);
function tmp = code(a_m, b, angle, x_45_scale, y_45_scale)
	tmp = -4.0 * (((a_m / (x_45_scale * y_45_scale)) * b) ^ 2.0);
end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_, angle_, x$45$scale_, y$45$scale_] := N[(-4.0 * N[Power[N[(N[(a$95$m / N[(x$45$scale * y$45$scale), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|

\\
-4 \cdot {\left(\frac{a_m}{x-scale \cdot y-scale} \cdot b\right)}^{2}
\end{array}
Derivation
  1. Initial program 25.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. Simplified23.0%

    \[\leadsto \color{blue}{\frac{\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \left(\sin \left(\frac{angle}{180} \cdot \pi\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}{y-scale \cdot x-scale} \cdot \frac{\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \left(\sin \left(\frac{angle}{180} \cdot \pi\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}{y-scale \cdot x-scale} - 4 \cdot \left(\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}^{2}} \cdot \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}^{2}}\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in angle around 0 48.0%

    \[\leadsto \color{blue}{-4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
  5. Step-by-step derivation
    1. associate-*r/48.0%

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

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

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

      \[\leadsto \frac{-4 \cdot \left({b}^{2} \cdot {a}^{2}\right)}{\color{blue}{\left(x-scale \cdot x-scale\right)} \cdot \left(y-scale \cdot y-scale\right)} \]
    5. swap-sqr60.4%

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

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

    \[\leadsto \color{blue}{\frac{-4 \cdot \left({b}^{2} \cdot {a}^{2}\right)}{{\left(x-scale \cdot y-scale\right)}^{2}}} \]
  7. Step-by-step derivation
    1. pow-prod-down48.0%

      \[\leadsto \frac{-4 \cdot \left({b}^{2} \cdot {a}^{2}\right)}{\color{blue}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
    2. associate-*r/48.0%

      \[\leadsto \color{blue}{-4 \cdot \frac{{b}^{2} \cdot {a}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
    3. expm1-log1p-u24.8%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-4 \cdot \frac{{b}^{2} \cdot {a}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}\right)\right)} \]
    4. expm1-udef24.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(-4 \cdot \frac{{b}^{2} \cdot {a}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}\right)} - 1} \]
    5. div-inv24.4%

      \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \color{blue}{\left(\left({b}^{2} \cdot {a}^{2}\right) \cdot \frac{1}{{x-scale}^{2} \cdot {y-scale}^{2}}\right)}\right)} - 1 \]
    6. *-commutative24.4%

      \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left(\color{blue}{\left({a}^{2} \cdot {b}^{2}\right)} \cdot \frac{1}{{x-scale}^{2} \cdot {y-scale}^{2}}\right)\right)} - 1 \]
    7. pow-prod-down27.5%

      \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left(\color{blue}{{\left(a \cdot b\right)}^{2}} \cdot \frac{1}{{x-scale}^{2} \cdot {y-scale}^{2}}\right)\right)} - 1 \]
    8. pow-prod-down31.4%

      \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot \frac{1}{\color{blue}{{\left(x-scale \cdot y-scale\right)}^{2}}}\right)\right)} - 1 \]
    9. *-commutative31.4%

      \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot \frac{1}{{\color{blue}{\left(y-scale \cdot x-scale\right)}}^{2}}\right)\right)} - 1 \]
    10. pow-flip31.4%

      \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot \color{blue}{{\left(y-scale \cdot x-scale\right)}^{\left(-2\right)}}\right)\right)} - 1 \]
    11. *-commutative31.4%

      \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot {\color{blue}{\left(x-scale \cdot y-scale\right)}}^{\left(-2\right)}\right)\right)} - 1 \]
    12. metadata-eval31.4%

      \[\leadsto e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot {\left(x-scale \cdot y-scale\right)}^{\color{blue}{-2}}\right)\right)} - 1 \]
  8. Applied egg-rr31.4%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot {\left(x-scale \cdot y-scale\right)}^{-2}\right)\right)} - 1} \]
  9. Step-by-step derivation
    1. expm1-def38.5%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot {\left(x-scale \cdot y-scale\right)}^{-2}\right)\right)\right)} \]
    2. expm1-log1p78.1%

      \[\leadsto \color{blue}{-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot {\left(x-scale \cdot y-scale\right)}^{-2}\right)} \]
    3. *-commutative78.1%

      \[\leadsto \color{blue}{\left({\left(a \cdot b\right)}^{2} \cdot {\left(x-scale \cdot y-scale\right)}^{-2}\right) \cdot -4} \]
    4. associate-*l*78.1%

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

    \[\leadsto \color{blue}{{\left(a \cdot b\right)}^{2} \cdot \left({\left(x-scale \cdot y-scale\right)}^{-2} \cdot -4\right)} \]
  11. Step-by-step derivation
    1. unpow278.1%

      \[\leadsto \color{blue}{\left(\left(a \cdot b\right) \cdot \left(a \cdot b\right)\right)} \cdot \left({\left(x-scale \cdot y-scale\right)}^{-2} \cdot -4\right) \]
  12. Applied egg-rr78.1%

    \[\leadsto \color{blue}{\left(\left(a \cdot b\right) \cdot \left(a \cdot b\right)\right)} \cdot \left({\left(x-scale \cdot y-scale\right)}^{-2} \cdot -4\right) \]
  13. Taylor expanded in a around 0 48.0%

    \[\leadsto \color{blue}{-4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
  14. Step-by-step derivation
    1. unpow248.0%

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

      \[\leadsto -4 \cdot \frac{\left(a \cdot a\right) \cdot \color{blue}{\left(b \cdot b\right)}}{{x-scale}^{2} \cdot {y-scale}^{2}} \]
    3. swap-sqr59.6%

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

      \[\leadsto -4 \cdot \frac{\color{blue}{{\left(a \cdot b\right)}^{2}}}{{x-scale}^{2} \cdot {y-scale}^{2}} \]
    5. associate-*r/59.6%

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

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

      \[\leadsto \frac{-4 \cdot {\left(a \cdot b\right)}^{2}}{\left(x-scale \cdot x-scale\right) \cdot \color{blue}{\left(y-scale \cdot y-scale\right)}} \]
    8. swap-sqr78.0%

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

      \[\leadsto \frac{-4 \cdot {\left(a \cdot b\right)}^{2}}{\color{blue}{{\left(x-scale \cdot y-scale\right)}^{2}}} \]
    10. associate-/l*77.8%

      \[\leadsto \color{blue}{\frac{-4}{\frac{{\left(x-scale \cdot y-scale\right)}^{2}}{{\left(a \cdot b\right)}^{2}}}} \]
    11. unpow277.8%

      \[\leadsto \frac{-4}{\frac{\color{blue}{\left(x-scale \cdot y-scale\right) \cdot \left(x-scale \cdot y-scale\right)}}{{\left(a \cdot b\right)}^{2}}} \]
    12. associate-/l*83.8%

      \[\leadsto \frac{-4}{\color{blue}{\frac{x-scale \cdot y-scale}{\frac{{\left(a \cdot b\right)}^{2}}{x-scale \cdot y-scale}}}} \]
    13. *-rgt-identity83.8%

      \[\leadsto \frac{-4}{\frac{x-scale \cdot y-scale}{\frac{\color{blue}{{\left(a \cdot b\right)}^{2} \cdot 1}}{x-scale \cdot y-scale}}} \]
    14. associate-*r/83.8%

      \[\leadsto \frac{-4}{\frac{x-scale \cdot y-scale}{\color{blue}{{\left(a \cdot b\right)}^{2} \cdot \frac{1}{x-scale \cdot y-scale}}}} \]
    15. associate-/l*84.1%

      \[\leadsto \color{blue}{\frac{-4 \cdot \left({\left(a \cdot b\right)}^{2} \cdot \frac{1}{x-scale \cdot y-scale}\right)}{x-scale \cdot y-scale}} \]
  15. Simplified94.3%

    \[\leadsto \color{blue}{-4 \cdot {\left(\frac{a}{x-scale \cdot y-scale} \cdot b\right)}^{2}} \]
  16. Final simplification94.3%

    \[\leadsto -4 \cdot {\left(\frac{a}{x-scale \cdot y-scale} \cdot b\right)}^{2} \]
  17. Add Preprocessing

Alternative 3: 83.2% accurate, 53.8× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ -4 \cdot \left(\frac{a_m \cdot \left(a_m \cdot b\right)}{x-scale \cdot y-scale} \cdot \frac{b}{x-scale \cdot y-scale}\right) \end{array} \]
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
 :precision binary64
 (*
  -4.0
  (* (/ (* a_m (* a_m b)) (* x-scale y-scale)) (/ b (* x-scale y-scale)))))
a_m = fabs(a);
double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
	return -4.0 * (((a_m * (a_m * b)) / (x_45_scale * y_45_scale)) * (b / (x_45_scale * y_45_scale)));
}
a_m = abs(a)
real(8) function code(a_m, b, angle, x_45scale, y_45scale)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b
    real(8), intent (in) :: angle
    real(8), intent (in) :: x_45scale
    real(8), intent (in) :: y_45scale
    code = (-4.0d0) * (((a_m * (a_m * b)) / (x_45scale * y_45scale)) * (b / (x_45scale * y_45scale)))
end function
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
	return -4.0 * (((a_m * (a_m * b)) / (x_45_scale * y_45_scale)) * (b / (x_45_scale * y_45_scale)));
}
a_m = math.fabs(a)
def code(a_m, b, angle, x_45_scale, y_45_scale):
	return -4.0 * (((a_m * (a_m * b)) / (x_45_scale * y_45_scale)) * (b / (x_45_scale * y_45_scale)))
a_m = abs(a)
function code(a_m, b, angle, x_45_scale, y_45_scale)
	return Float64(-4.0 * Float64(Float64(Float64(a_m * Float64(a_m * b)) / Float64(x_45_scale * y_45_scale)) * Float64(b / Float64(x_45_scale * y_45_scale))))
end
a_m = abs(a);
function tmp = code(a_m, b, angle, x_45_scale, y_45_scale)
	tmp = -4.0 * (((a_m * (a_m * b)) / (x_45_scale * y_45_scale)) * (b / (x_45_scale * y_45_scale)));
end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_, angle_, x$45$scale_, y$45$scale_] := N[(-4.0 * N[(N[(N[(a$95$m * N[(a$95$m * b), $MachinePrecision]), $MachinePrecision] / N[(x$45$scale * y$45$scale), $MachinePrecision]), $MachinePrecision] * N[(b / N[(x$45$scale * y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|

\\
-4 \cdot \left(\frac{a_m \cdot \left(a_m \cdot b\right)}{x-scale \cdot y-scale} \cdot \frac{b}{x-scale \cdot y-scale}\right)
\end{array}
Derivation
  1. Initial program 25.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. Simplified23.0%

    \[\leadsto \color{blue}{\frac{\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \left(\sin \left(\frac{angle}{180} \cdot \pi\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}{y-scale \cdot x-scale} \cdot \frac{\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \left(\sin \left(\frac{angle}{180} \cdot \pi\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}{y-scale \cdot x-scale} - 4 \cdot \left(\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}^{2}} \cdot \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}^{2}}\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in angle around 0 48.0%

    \[\leadsto \color{blue}{-4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
  5. Step-by-step derivation
    1. *-commutative48.0%

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

    \[\leadsto \color{blue}{-4 \cdot \frac{{b}^{2} \cdot {a}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
  7. Step-by-step derivation
    1. pow-prod-down59.6%

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

    \[\leadsto -4 \cdot \frac{\color{blue}{{\left(b \cdot a\right)}^{2}}}{{x-scale}^{2} \cdot {y-scale}^{2}} \]
  9. Step-by-step derivation
    1. *-commutative59.6%

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

      \[\leadsto -4 \cdot \frac{\color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)}}{{x-scale}^{2} \cdot {y-scale}^{2}} \]
    3. associate-*r*57.7%

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

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

      \[\leadsto -4 \cdot \frac{\left(\left(a \cdot b\right) \cdot a\right) \cdot b}{\color{blue}{\left(x-scale \cdot y-scale\right) \cdot \left(x-scale \cdot y-scale\right)}} \]
    6. times-frac83.6%

      \[\leadsto -4 \cdot \color{blue}{\left(\frac{\left(a \cdot b\right) \cdot a}{x-scale \cdot y-scale} \cdot \frac{b}{x-scale \cdot y-scale}\right)} \]
  10. Applied egg-rr83.6%

    \[\leadsto -4 \cdot \color{blue}{\left(\frac{\left(a \cdot b\right) \cdot a}{x-scale \cdot y-scale} \cdot \frac{b}{x-scale \cdot y-scale}\right)} \]
  11. Final simplification83.6%

    \[\leadsto -4 \cdot \left(\frac{a \cdot \left(a \cdot b\right)}{x-scale \cdot y-scale} \cdot \frac{b}{x-scale \cdot y-scale}\right) \]
  12. Add Preprocessing

Alternative 4: 93.8% accurate, 53.8× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ \begin{array}{l} t_0 := \frac{a_m \cdot b}{x-scale \cdot y-scale}\\ t_0 \cdot \left(-4 \cdot t_0\right) \end{array} \end{array} \]
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
 :precision binary64
 (let* ((t_0 (/ (* a_m b) (* x-scale y-scale)))) (* t_0 (* -4.0 t_0))))
a_m = fabs(a);
double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
	double t_0 = (a_m * b) / (x_45_scale * y_45_scale);
	return t_0 * (-4.0 * t_0);
}
a_m = abs(a)
real(8) function code(a_m, b, angle, x_45scale, y_45scale)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b
    real(8), intent (in) :: angle
    real(8), intent (in) :: x_45scale
    real(8), intent (in) :: y_45scale
    real(8) :: t_0
    t_0 = (a_m * b) / (x_45scale * y_45scale)
    code = t_0 * ((-4.0d0) * t_0)
end function
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
	double t_0 = (a_m * b) / (x_45_scale * y_45_scale);
	return t_0 * (-4.0 * t_0);
}
a_m = math.fabs(a)
def code(a_m, b, angle, x_45_scale, y_45_scale):
	t_0 = (a_m * b) / (x_45_scale * y_45_scale)
	return t_0 * (-4.0 * t_0)
a_m = abs(a)
function code(a_m, b, angle, x_45_scale, y_45_scale)
	t_0 = Float64(Float64(a_m * b) / Float64(x_45_scale * y_45_scale))
	return Float64(t_0 * Float64(-4.0 * t_0))
end
a_m = abs(a);
function tmp = code(a_m, b, angle, x_45_scale, y_45_scale)
	t_0 = (a_m * b) / (x_45_scale * y_45_scale);
	tmp = t_0 * (-4.0 * t_0);
end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(a$95$m * b), $MachinePrecision] / N[(x$45$scale * y$45$scale), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * N[(-4.0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a_m = \left|a\right|

\\
\begin{array}{l}
t_0 := \frac{a_m \cdot b}{x-scale \cdot y-scale}\\
t_0 \cdot \left(-4 \cdot t_0\right)
\end{array}
\end{array}
Derivation
  1. Initial program 25.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. Simplified23.0%

    \[\leadsto \color{blue}{\frac{\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \left(\sin \left(\frac{angle}{180} \cdot \pi\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}{y-scale \cdot x-scale} \cdot \frac{\left(2 \cdot \left({b}^{2} - {a}^{2}\right)\right) \cdot \left(\sin \left(\frac{angle}{180} \cdot \pi\right) \cdot \cos \left(\frac{angle}{180} \cdot \pi\right)\right)}{y-scale \cdot x-scale} - 4 \cdot \left(\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}^{2}} \cdot \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}^{2}}\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in angle around 0 48.0%

    \[\leadsto \color{blue}{-4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
  5. Step-by-step derivation
    1. *-commutative48.0%

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

    \[\leadsto \color{blue}{-4 \cdot \frac{{b}^{2} \cdot {a}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
  7. Step-by-step derivation
    1. associate-*r/48.0%

      \[\leadsto \color{blue}{\frac{-4 \cdot \left({b}^{2} \cdot {a}^{2}\right)}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
    2. associate-/l*48.0%

      \[\leadsto \color{blue}{\frac{-4}{\frac{{x-scale}^{2} \cdot {y-scale}^{2}}{{b}^{2} \cdot {a}^{2}}}} \]
    3. pow-prod-down60.4%

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

      \[\leadsto \frac{-4}{\frac{{\left(x-scale \cdot y-scale\right)}^{2}}{\color{blue}{{a}^{2} \cdot {b}^{2}}}} \]
    5. pow-prod-down77.8%

      \[\leadsto \frac{-4}{\frac{{\left(x-scale \cdot y-scale\right)}^{2}}{\color{blue}{{\left(a \cdot b\right)}^{2}}}} \]
  8. Applied egg-rr77.8%

    \[\leadsto \color{blue}{\frac{-4}{\frac{{\left(x-scale \cdot y-scale\right)}^{2}}{{\left(a \cdot b\right)}^{2}}}} \]
  9. Step-by-step derivation
    1. unpow278.1%

      \[\leadsto \color{blue}{\left(\left(a \cdot b\right) \cdot \left(a \cdot b\right)\right)} \cdot \left({\left(x-scale \cdot y-scale\right)}^{-2} \cdot -4\right) \]
  10. Applied egg-rr77.8%

    \[\leadsto \frac{-4}{\frac{{\left(x-scale \cdot y-scale\right)}^{2}}{\color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)}}} \]
  11. Step-by-step derivation
    1. div-inv77.8%

      \[\leadsto \color{blue}{-4 \cdot \frac{1}{\frac{{\left(x-scale \cdot y-scale\right)}^{2}}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)}}} \]
    2. pow-prod-down59.6%

      \[\leadsto -4 \cdot \frac{1}{\frac{\color{blue}{{x-scale}^{2} \cdot {y-scale}^{2}}}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)}} \]
    3. pow259.6%

      \[\leadsto -4 \cdot \frac{1}{\frac{{x-scale}^{2} \cdot {y-scale}^{2}}{\color{blue}{{\left(a \cdot b\right)}^{2}}}} \]
    4. *-commutative59.6%

      \[\leadsto -4 \cdot \frac{1}{\frac{{x-scale}^{2} \cdot {y-scale}^{2}}{{\color{blue}{\left(b \cdot a\right)}}^{2}}} \]
    5. clear-num59.6%

      \[\leadsto -4 \cdot \color{blue}{\frac{{\left(b \cdot a\right)}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
    6. add-sqr-sqrt59.6%

      \[\leadsto -4 \cdot \color{blue}{\left(\sqrt{\frac{{\left(b \cdot a\right)}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}} \cdot \sqrt{\frac{{\left(b \cdot a\right)}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}}\right)} \]
    7. associate-*r*59.6%

      \[\leadsto \color{blue}{\left(-4 \cdot \sqrt{\frac{{\left(b \cdot a\right)}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}}\right) \cdot \sqrt{\frac{{\left(b \cdot a\right)}^{2}}{{x-scale}^{2} \cdot {y-scale}^{2}}}} \]
  12. Applied egg-rr93.8%

    \[\leadsto \color{blue}{\left(-4 \cdot \frac{a \cdot b}{x-scale \cdot y-scale}\right) \cdot \frac{a \cdot b}{x-scale \cdot y-scale}} \]
  13. Final simplification93.8%

    \[\leadsto \frac{a \cdot b}{x-scale \cdot y-scale} \cdot \left(-4 \cdot \frac{a \cdot b}{x-scale \cdot y-scale}\right) \]
  14. Add Preprocessing

Alternative 5: 35.3% accurate, 1777.0× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ 0 \end{array} \]
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale) :precision binary64 0.0)
a_m = fabs(a);
double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
	return 0.0;
}
a_m = abs(a)
real(8) function code(a_m, b, angle, x_45scale, y_45scale)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b
    real(8), intent (in) :: angle
    real(8), intent (in) :: x_45scale
    real(8), intent (in) :: y_45scale
    code = 0.0d0
end function
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
	return 0.0;
}
a_m = math.fabs(a)
def code(a_m, b, angle, x_45_scale, y_45_scale):
	return 0.0
a_m = abs(a)
function code(a_m, b, angle, x_45_scale, y_45_scale)
	return 0.0
end
a_m = abs(a);
function tmp = code(a_m, b, angle, x_45_scale, y_45_scale)
	tmp = 0.0;
end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_, angle_, x$45$scale_, y$45$scale_] := 0.0
\begin{array}{l}
a_m = \left|a\right|

\\
0
\end{array}
Derivation
  1. Initial program 25.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. Simplified24.7%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\cos \left(\frac{angle}{180} \cdot \pi\right)}{y-scale} \cdot \frac{2 \cdot \left(\left({b}^{2} - {a}^{2}\right) \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}{x-scale}, \frac{\cos \left(\frac{angle}{180} \cdot \pi\right)}{y-scale} \cdot \frac{2 \cdot \left(\left({b}^{2} - {a}^{2}\right) \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}{x-scale}, \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}^{2}} \cdot \left(\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}^{2}} \cdot -4\right)\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in b around 0 24.4%

    \[\leadsto \color{blue}{-4 \cdot \frac{{a}^{4} \cdot \left({\cos \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)}^{2} \cdot {\sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)}^{2}\right)}{{x-scale}^{2} \cdot {y-scale}^{2}} + 4 \cdot \frac{{a}^{4} \cdot \left({\cos \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)}^{2} \cdot {\sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)}^{2}\right)}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
  5. Step-by-step derivation
    1. distribute-rgt-out24.4%

      \[\leadsto \color{blue}{\frac{{a}^{4} \cdot \left({\cos \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)}^{2} \cdot {\sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)}^{2}\right)}{{x-scale}^{2} \cdot {y-scale}^{2}} \cdot \left(-4 + 4\right)} \]
    2. metadata-eval24.4%

      \[\leadsto \frac{{a}^{4} \cdot \left({\cos \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)}^{2} \cdot {\sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)}^{2}\right)}{{x-scale}^{2} \cdot {y-scale}^{2}} \cdot \color{blue}{0} \]
    3. mul0-rgt34.8%

      \[\leadsto \color{blue}{0} \]
  6. Simplified34.8%

    \[\leadsto \color{blue}{0} \]
  7. Final simplification34.8%

    \[\leadsto 0 \]
  8. Add Preprocessing

Reproduce

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