Simplification of discriminant from scale-rotated-ellipse

Percentage Accurate: 23.4% → 94.2%
Time: 1.8min
Alternatives: 7
Speedup: 2485.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 7 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: 23.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, 21.4× speedup?

\[\begin{array}{l} b = |b|\\ \\ \begin{array}{l} t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\ \mathbf{if}\;b \leq 1.7 \cdot 10^{-5}:\\ \;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \frac{1}{\frac{1}{{\left(\frac{a}{y-scale} \cdot \frac{b}{x-scale}\right)}^{2}}}\\ \end{array} \end{array} \]
NOTE: b should be positive before calling this function
(FPCore (a b angle x-scale y-scale)
 :precision binary64
 (let* ((t_0 (/ (* b a) (* y-scale x-scale))))
   (if (<= b 1.7e-5)
     (* -4.0 (* t_0 t_0))
     (* -4.0 (/ 1.0 (/ 1.0 (pow (* (/ a y-scale) (/ b x-scale)) 2.0)))))))
b = abs(b);
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
	double t_0 = (b * a) / (y_45_scale * x_45_scale);
	double tmp;
	if (b <= 1.7e-5) {
		tmp = -4.0 * (t_0 * t_0);
	} else {
		tmp = -4.0 * (1.0 / (1.0 / pow(((a / y_45_scale) * (b / x_45_scale)), 2.0)));
	}
	return tmp;
}
NOTE: b should be positive before calling this function
real(8) function code(a, b, angle, x_45scale, y_45scale)
    real(8), intent (in) :: a
    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
    real(8) :: tmp
    t_0 = (b * a) / (y_45scale * x_45scale)
    if (b <= 1.7d-5) then
        tmp = (-4.0d0) * (t_0 * t_0)
    else
        tmp = (-4.0d0) * (1.0d0 / (1.0d0 / (((a / y_45scale) * (b / x_45scale)) ** 2.0d0)))
    end if
    code = tmp
end function
b = Math.abs(b);
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
	double t_0 = (b * a) / (y_45_scale * x_45_scale);
	double tmp;
	if (b <= 1.7e-5) {
		tmp = -4.0 * (t_0 * t_0);
	} else {
		tmp = -4.0 * (1.0 / (1.0 / Math.pow(((a / y_45_scale) * (b / x_45_scale)), 2.0)));
	}
	return tmp;
}
b = abs(b)
def code(a, b, angle, x_45_scale, y_45_scale):
	t_0 = (b * a) / (y_45_scale * x_45_scale)
	tmp = 0
	if b <= 1.7e-5:
		tmp = -4.0 * (t_0 * t_0)
	else:
		tmp = -4.0 * (1.0 / (1.0 / math.pow(((a / y_45_scale) * (b / x_45_scale)), 2.0)))
	return tmp
b = abs(b)
function code(a, b, angle, x_45_scale, y_45_scale)
	t_0 = Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale))
	tmp = 0.0
	if (b <= 1.7e-5)
		tmp = Float64(-4.0 * Float64(t_0 * t_0));
	else
		tmp = Float64(-4.0 * Float64(1.0 / Float64(1.0 / (Float64(Float64(a / y_45_scale) * Float64(b / x_45_scale)) ^ 2.0))));
	end
	return tmp
end
b = abs(b)
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale)
	t_0 = (b * a) / (y_45_scale * x_45_scale);
	tmp = 0.0;
	if (b <= 1.7e-5)
		tmp = -4.0 * (t_0 * t_0);
	else
		tmp = -4.0 * (1.0 / (1.0 / (((a / y_45_scale) * (b / x_45_scale)) ^ 2.0)));
	end
	tmp_2 = tmp;
end
NOTE: b should be positive before calling this function
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.7e-5], N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(1.0 / N[(1.0 / N[Power[N[(N[(a / y$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
b = |b|\\
\\
\begin{array}{l}
t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\
\mathbf{if}\;b \leq 1.7 \cdot 10^{-5}:\\
\;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < 1.7e-5

    1. Initial program 33.9%

      \[\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. Step-by-step derivation
      1. Simplified27.2%

        \[\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} - \left(4 \cdot \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}}\right) \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}}} \]
      2. Taylor expanded in angle around 0 51.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 1.7e-5 < b

      1. Initial program 4.1%

        \[\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. Step-by-step derivation
        1. Simplified2.3%

          \[\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} - \left(4 \cdot \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}}\right) \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}}} \]
        2. Taylor expanded in angle around 0 39.9%

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

            \[\leadsto -4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{\color{blue}{{y-scale}^{2} \cdot {x-scale}^{2}}} \]
          2. times-frac41.8%

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

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

            \[\leadsto -4 \cdot \color{blue}{\frac{{a}^{2} \cdot {b}^{2}}{{y-scale}^{2} \cdot {x-scale}^{2}}} \]
          2. *-commutative39.9%

            \[\leadsto -4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{\color{blue}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
          3. clear-num39.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto -4 \cdot \frac{1}{{\left({\left(\frac{\color{blue}{\sqrt{a \cdot b} \cdot \sqrt{a \cdot b}}}{\sqrt{{\left(y-scale \cdot x-scale\right)}^{2}}}\right)}^{2}\right)}^{-1}} \]
          10. add-sqr-sqrt81.0%

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

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

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

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

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

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

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

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

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

      Alternative 2: 94.2% accurate, 22.2× speedup?

      \[\begin{array}{l} b = |b|\\ \\ \begin{array}{l} t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\ \mathbf{if}\;b \leq 10^{-5}:\\ \;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot {\left(\frac{a}{y-scale} \cdot \frac{b}{x-scale}\right)}^{2}\\ \end{array} \end{array} \]
      NOTE: b should be positive before calling this function
      (FPCore (a b angle x-scale y-scale)
       :precision binary64
       (let* ((t_0 (/ (* b a) (* y-scale x-scale))))
         (if (<= b 1e-5)
           (* -4.0 (* t_0 t_0))
           (* -4.0 (pow (* (/ a y-scale) (/ b x-scale)) 2.0)))))
      b = abs(b);
      double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
      	double t_0 = (b * a) / (y_45_scale * x_45_scale);
      	double tmp;
      	if (b <= 1e-5) {
      		tmp = -4.0 * (t_0 * t_0);
      	} else {
      		tmp = -4.0 * pow(((a / y_45_scale) * (b / x_45_scale)), 2.0);
      	}
      	return tmp;
      }
      
      NOTE: b should be positive before calling this function
      real(8) function code(a, b, angle, x_45scale, y_45scale)
          real(8), intent (in) :: a
          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
          real(8) :: tmp
          t_0 = (b * a) / (y_45scale * x_45scale)
          if (b <= 1d-5) then
              tmp = (-4.0d0) * (t_0 * t_0)
          else
              tmp = (-4.0d0) * (((a / y_45scale) * (b / x_45scale)) ** 2.0d0)
          end if
          code = tmp
      end function
      
      b = Math.abs(b);
      public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
      	double t_0 = (b * a) / (y_45_scale * x_45_scale);
      	double tmp;
      	if (b <= 1e-5) {
      		tmp = -4.0 * (t_0 * t_0);
      	} else {
      		tmp = -4.0 * Math.pow(((a / y_45_scale) * (b / x_45_scale)), 2.0);
      	}
      	return tmp;
      }
      
      b = abs(b)
      def code(a, b, angle, x_45_scale, y_45_scale):
      	t_0 = (b * a) / (y_45_scale * x_45_scale)
      	tmp = 0
      	if b <= 1e-5:
      		tmp = -4.0 * (t_0 * t_0)
      	else:
      		tmp = -4.0 * math.pow(((a / y_45_scale) * (b / x_45_scale)), 2.0)
      	return tmp
      
      b = abs(b)
      function code(a, b, angle, x_45_scale, y_45_scale)
      	t_0 = Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale))
      	tmp = 0.0
      	if (b <= 1e-5)
      		tmp = Float64(-4.0 * Float64(t_0 * t_0));
      	else
      		tmp = Float64(-4.0 * (Float64(Float64(a / y_45_scale) * Float64(b / x_45_scale)) ^ 2.0));
      	end
      	return tmp
      end
      
      b = abs(b)
      function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale)
      	t_0 = (b * a) / (y_45_scale * x_45_scale);
      	tmp = 0.0;
      	if (b <= 1e-5)
      		tmp = -4.0 * (t_0 * t_0);
      	else
      		tmp = -4.0 * (((a / y_45_scale) * (b / x_45_scale)) ^ 2.0);
      	end
      	tmp_2 = tmp;
      end
      
      NOTE: b should be positive before calling this function
      code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1e-5], N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[Power[N[(N[(a / y$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]
      
      \begin{array}{l}
      b = |b|\\
      \\
      \begin{array}{l}
      t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\
      \mathbf{if}\;b \leq 10^{-5}:\\
      \;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;-4 \cdot {\left(\frac{a}{y-scale} \cdot \frac{b}{x-scale}\right)}^{2}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if b < 1.00000000000000008e-5

        1. Initial program 33.9%

          \[\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. Step-by-step derivation
          1. Simplified27.2%

            \[\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} - \left(4 \cdot \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}}\right) \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}}} \]
          2. Taylor expanded in angle around 0 51.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          if 1.00000000000000008e-5 < b

          1. Initial program 4.1%

            \[\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. Step-by-step derivation
            1. Simplified2.3%

              \[\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} - \left(4 \cdot \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}}\right) \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}}} \]
            2. Taylor expanded in angle around 0 39.9%

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

                \[\leadsto -4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{\color{blue}{{y-scale}^{2} \cdot {x-scale}^{2}}} \]
              2. times-frac41.8%

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

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

                \[\leadsto -4 \cdot \color{blue}{\frac{{a}^{2} \cdot {b}^{2}}{{y-scale}^{2} \cdot {x-scale}^{2}}} \]
              2. *-commutative39.9%

                \[\leadsto -4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{\color{blue}{{x-scale}^{2} \cdot {y-scale}^{2}}} \]
              3. clear-num39.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 3: 94.2% accurate, 22.2× speedup?

          \[\begin{array}{l} b = |b|\\ \\ \begin{array}{l} t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\ \mathbf{if}\;b \leq 35000:\\ \;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot {\left(\frac{y-scale}{a} \cdot \frac{x-scale}{b}\right)}^{-2}\\ \end{array} \end{array} \]
          NOTE: b should be positive before calling this function
          (FPCore (a b angle x-scale y-scale)
           :precision binary64
           (let* ((t_0 (/ (* b a) (* y-scale x-scale))))
             (if (<= b 35000.0)
               (* -4.0 (* t_0 t_0))
               (* -4.0 (pow (* (/ y-scale a) (/ x-scale b)) -2.0)))))
          b = abs(b);
          double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
          	double t_0 = (b * a) / (y_45_scale * x_45_scale);
          	double tmp;
          	if (b <= 35000.0) {
          		tmp = -4.0 * (t_0 * t_0);
          	} else {
          		tmp = -4.0 * pow(((y_45_scale / a) * (x_45_scale / b)), -2.0);
          	}
          	return tmp;
          }
          
          NOTE: b should be positive before calling this function
          real(8) function code(a, b, angle, x_45scale, y_45scale)
              real(8), intent (in) :: a
              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
              real(8) :: tmp
              t_0 = (b * a) / (y_45scale * x_45scale)
              if (b <= 35000.0d0) then
                  tmp = (-4.0d0) * (t_0 * t_0)
              else
                  tmp = (-4.0d0) * (((y_45scale / a) * (x_45scale / b)) ** (-2.0d0))
              end if
              code = tmp
          end function
          
          b = Math.abs(b);
          public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
          	double t_0 = (b * a) / (y_45_scale * x_45_scale);
          	double tmp;
          	if (b <= 35000.0) {
          		tmp = -4.0 * (t_0 * t_0);
          	} else {
          		tmp = -4.0 * Math.pow(((y_45_scale / a) * (x_45_scale / b)), -2.0);
          	}
          	return tmp;
          }
          
          b = abs(b)
          def code(a, b, angle, x_45_scale, y_45_scale):
          	t_0 = (b * a) / (y_45_scale * x_45_scale)
          	tmp = 0
          	if b <= 35000.0:
          		tmp = -4.0 * (t_0 * t_0)
          	else:
          		tmp = -4.0 * math.pow(((y_45_scale / a) * (x_45_scale / b)), -2.0)
          	return tmp
          
          b = abs(b)
          function code(a, b, angle, x_45_scale, y_45_scale)
          	t_0 = Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale))
          	tmp = 0.0
          	if (b <= 35000.0)
          		tmp = Float64(-4.0 * Float64(t_0 * t_0));
          	else
          		tmp = Float64(-4.0 * (Float64(Float64(y_45_scale / a) * Float64(x_45_scale / b)) ^ -2.0));
          	end
          	return tmp
          end
          
          b = abs(b)
          function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale)
          	t_0 = (b * a) / (y_45_scale * x_45_scale);
          	tmp = 0.0;
          	if (b <= 35000.0)
          		tmp = -4.0 * (t_0 * t_0);
          	else
          		tmp = -4.0 * (((y_45_scale / a) * (x_45_scale / b)) ^ -2.0);
          	end
          	tmp_2 = tmp;
          end
          
          NOTE: b should be positive before calling this function
          code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 35000.0], N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[Power[N[(N[(y$45$scale / a), $MachinePrecision] * N[(x$45$scale / b), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]]]
          
          \begin{array}{l}
          b = |b|\\
          \\
          \begin{array}{l}
          t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\
          \mathbf{if}\;b \leq 35000:\\
          \;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;-4 \cdot {\left(\frac{y-scale}{a} \cdot \frac{x-scale}{b}\right)}^{-2}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if b < 35000

            1. Initial program 34.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. Step-by-step derivation
              1. Simplified27.5%

                \[\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} - \left(4 \cdot \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}}\right) \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}}} \]
              2. Taylor expanded in angle around 0 51.6%

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

                  \[\leadsto -4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{\color{blue}{{y-scale}^{2} \cdot {x-scale}^{2}}} \]
                2. times-frac52.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if 35000 < b

              1. Initial program 2.4%

                \[\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. Step-by-step derivation
                1. Simplified0.6%

                  \[\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} - \left(4 \cdot \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}}\right) \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}}} \]
                2. Taylor expanded in angle around 0 38.9%

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

                    \[\leadsto -4 \cdot \frac{{a}^{2} \cdot {b}^{2}}{\color{blue}{{y-scale}^{2} \cdot {x-scale}^{2}}} \]
                  2. times-frac40.8%

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

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

                    \[\leadsto -4 \cdot \color{blue}{\frac{{a}^{2} \cdot {b}^{2}}{{y-scale}^{2} \cdot {x-scale}^{2}}} \]
                  2. *-commutative38.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto -4 \cdot \left({\left(\frac{y-scale \cdot x-scale}{\color{blue}{\sqrt{a \cdot b} \cdot \sqrt{a \cdot b}}}\right)}^{-1} \cdot {\left(\sqrt{\frac{{\left(y-scale \cdot x-scale\right)}^{2}}{{a}^{2} \cdot {b}^{2}}}\right)}^{-1}\right) \]
                  12. add-sqr-sqrt32.3%

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

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

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

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

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

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

                \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 35000:\\ \;\;\;\;-4 \cdot \left(\frac{b \cdot a}{y-scale \cdot x-scale} \cdot \frac{b \cdot a}{y-scale \cdot x-scale}\right)\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot {\left(\frac{y-scale}{a} \cdot \frac{x-scale}{b}\right)}^{-2}\\ \end{array} \]

              Alternative 4: 90.3% accurate, 146.2× speedup?

              \[\begin{array}{l} b = |b|\\ \\ -4 \cdot \left(\frac{a}{y-scale} \cdot \left(\frac{b}{x-scale} \cdot \frac{\frac{a}{\frac{x-scale}{b}}}{y-scale}\right)\right) \end{array} \]
              NOTE: b should be positive before calling this function
              (FPCore (a b angle x-scale y-scale)
               :precision binary64
               (* -4.0 (* (/ a y-scale) (* (/ b x-scale) (/ (/ a (/ x-scale b)) y-scale)))))
              b = abs(b);
              double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
              	return -4.0 * ((a / y_45_scale) * ((b / x_45_scale) * ((a / (x_45_scale / b)) / y_45_scale)));
              }
              
              NOTE: b should be positive before calling this function
              real(8) function code(a, b, angle, x_45scale, y_45scale)
                  real(8), intent (in) :: a
                  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 / y_45scale) * ((b / x_45scale) * ((a / (x_45scale / b)) / y_45scale)))
              end function
              
              b = Math.abs(b);
              public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
              	return -4.0 * ((a / y_45_scale) * ((b / x_45_scale) * ((a / (x_45_scale / b)) / y_45_scale)));
              }
              
              b = abs(b)
              def code(a, b, angle, x_45_scale, y_45_scale):
              	return -4.0 * ((a / y_45_scale) * ((b / x_45_scale) * ((a / (x_45_scale / b)) / y_45_scale)))
              
              b = abs(b)
              function code(a, b, angle, x_45_scale, y_45_scale)
              	return Float64(-4.0 * Float64(Float64(a / y_45_scale) * Float64(Float64(b / x_45_scale) * Float64(Float64(a / Float64(x_45_scale / b)) / y_45_scale))))
              end
              
              b = abs(b)
              function tmp = code(a, b, angle, x_45_scale, y_45_scale)
              	tmp = -4.0 * ((a / y_45_scale) * ((b / x_45_scale) * ((a / (x_45_scale / b)) / y_45_scale)));
              end
              
              NOTE: b should be positive before calling this function
              code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(-4.0 * N[(N[(a / y$45$scale), $MachinePrecision] * N[(N[(b / x$45$scale), $MachinePrecision] * N[(N[(a / N[(x$45$scale / b), $MachinePrecision]), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
              
              \begin{array}{l}
              b = |b|\\
              \\
              -4 \cdot \left(\frac{a}{y-scale} \cdot \left(\frac{b}{x-scale} \cdot \frac{\frac{a}{\frac{x-scale}{b}}}{y-scale}\right)\right)
              \end{array}
              
              Derivation
              1. Initial program 27.1%

                \[\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. Step-by-step derivation
                1. Simplified21.6%

                  \[\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} - \left(4 \cdot \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}}\right) \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}}} \]
                2. Taylor expanded in angle around 0 48.8%

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

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

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

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

                    \[\leadsto -4 \cdot \color{blue}{\frac{{a}^{2} \cdot {b}^{2}}{{y-scale}^{2} \cdot {x-scale}^{2}}} \]
                  2. *-commutative48.8%

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

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

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

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

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

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

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

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

                    \[\leadsto -4 \cdot \frac{1}{\color{blue}{\frac{y-scale \cdot x-scale}{a \cdot b} \cdot \frac{y-scale \cdot x-scale}{a \cdot b}}} \]
                8. Applied egg-rr94.7%

                  \[\leadsto -4 \cdot \frac{1}{\color{blue}{\frac{y-scale \cdot x-scale}{a \cdot b} \cdot \frac{y-scale \cdot x-scale}{a \cdot b}}} \]
                9. Step-by-step derivation
                  1. metadata-eval94.7%

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

                    \[\leadsto -4 \cdot \color{blue}{\left(\frac{1}{\frac{y-scale \cdot x-scale}{a \cdot b}} \cdot \frac{1}{\frac{y-scale \cdot x-scale}{a \cdot b}}\right)} \]
                  3. clear-num94.8%

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

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

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

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

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

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

                    \[\leadsto -4 \cdot \left(\frac{a}{y-scale} \cdot \left(\frac{b}{x-scale} \cdot \frac{a \cdot \color{blue}{\frac{1}{\frac{x-scale}{b}}}}{y-scale}\right)\right) \]
                  10. un-div-inv90.0%

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

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

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

                Alternative 5: 92.5% accurate, 146.2× speedup?

                \[\begin{array}{l} b = |b|\\ \\ -4 \cdot \left(\frac{b \cdot a}{y-scale \cdot x-scale} \cdot \left(a \cdot \frac{b}{y-scale \cdot x-scale}\right)\right) \end{array} \]
                NOTE: b should be positive before calling this function
                (FPCore (a b angle x-scale y-scale)
                 :precision binary64
                 (* -4.0 (* (/ (* b a) (* y-scale x-scale)) (* a (/ b (* y-scale x-scale))))))
                b = abs(b);
                double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
                	return -4.0 * (((b * a) / (y_45_scale * x_45_scale)) * (a * (b / (y_45_scale * x_45_scale))));
                }
                
                NOTE: b should be positive before calling this function
                real(8) function code(a, b, angle, x_45scale, y_45scale)
                    real(8), intent (in) :: a
                    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) * (((b * a) / (y_45scale * x_45scale)) * (a * (b / (y_45scale * x_45scale))))
                end function
                
                b = Math.abs(b);
                public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
                	return -4.0 * (((b * a) / (y_45_scale * x_45_scale)) * (a * (b / (y_45_scale * x_45_scale))));
                }
                
                b = abs(b)
                def code(a, b, angle, x_45_scale, y_45_scale):
                	return -4.0 * (((b * a) / (y_45_scale * x_45_scale)) * (a * (b / (y_45_scale * x_45_scale))))
                
                b = abs(b)
                function code(a, b, angle, x_45_scale, y_45_scale)
                	return Float64(-4.0 * Float64(Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale)) * Float64(a * Float64(b / Float64(y_45_scale * x_45_scale)))))
                end
                
                b = abs(b)
                function tmp = code(a, b, angle, x_45_scale, y_45_scale)
                	tmp = -4.0 * (((b * a) / (y_45_scale * x_45_scale)) * (a * (b / (y_45_scale * x_45_scale))));
                end
                
                NOTE: b should be positive before calling this function
                code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(-4.0 * N[(N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision] * N[(a * N[(b / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
                
                \begin{array}{l}
                b = |b|\\
                \\
                -4 \cdot \left(\frac{b \cdot a}{y-scale \cdot x-scale} \cdot \left(a \cdot \frac{b}{y-scale \cdot x-scale}\right)\right)
                \end{array}
                
                Derivation
                1. Initial program 27.1%

                  \[\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. Step-by-step derivation
                  1. Simplified21.6%

                    \[\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} - \left(4 \cdot \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}}\right) \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}}} \]
                  2. Taylor expanded in angle around 0 48.8%

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

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

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

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

                      \[\leadsto -4 \cdot \color{blue}{\frac{{a}^{2} \cdot {b}^{2}}{{y-scale}^{2} \cdot {x-scale}^{2}}} \]
                    2. *-commutative48.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto -4 \cdot \left(\frac{a \cdot b}{y-scale \cdot x-scale} \cdot \color{blue}{\frac{a \cdot b}{x-scale \cdot y-scale}}\right) \]
                  10. Step-by-step derivation
                    1. *-commutative94.7%

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

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

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

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

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

                  Alternative 6: 94.0% accurate, 146.2× speedup?

                  \[\begin{array}{l} b = |b|\\ \\ \begin{array}{l} t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\ -4 \cdot \left(t_0 \cdot t_0\right) \end{array} \end{array} \]
                  NOTE: b should be positive before calling this function
                  (FPCore (a b angle x-scale y-scale)
                   :precision binary64
                   (let* ((t_0 (/ (* b a) (* y-scale x-scale)))) (* -4.0 (* t_0 t_0))))
                  b = abs(b);
                  double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
                  	double t_0 = (b * a) / (y_45_scale * x_45_scale);
                  	return -4.0 * (t_0 * t_0);
                  }
                  
                  NOTE: b should be positive before calling this function
                  real(8) function code(a, b, angle, x_45scale, y_45scale)
                      real(8), intent (in) :: a
                      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 = (b * a) / (y_45scale * x_45scale)
                      code = (-4.0d0) * (t_0 * t_0)
                  end function
                  
                  b = Math.abs(b);
                  public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
                  	double t_0 = (b * a) / (y_45_scale * x_45_scale);
                  	return -4.0 * (t_0 * t_0);
                  }
                  
                  b = abs(b)
                  def code(a, b, angle, x_45_scale, y_45_scale):
                  	t_0 = (b * a) / (y_45_scale * x_45_scale)
                  	return -4.0 * (t_0 * t_0)
                  
                  b = abs(b)
                  function code(a, b, angle, x_45_scale, y_45_scale)
                  	t_0 = Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale))
                  	return Float64(-4.0 * Float64(t_0 * t_0))
                  end
                  
                  b = abs(b)
                  function tmp = code(a, b, angle, x_45_scale, y_45_scale)
                  	t_0 = (b * a) / (y_45_scale * x_45_scale);
                  	tmp = -4.0 * (t_0 * t_0);
                  end
                  
                  NOTE: b should be positive before calling this function
                  code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]}, N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
                  
                  \begin{array}{l}
                  b = |b|\\
                  \\
                  \begin{array}{l}
                  t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\
                  -4 \cdot \left(t_0 \cdot t_0\right)
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Initial program 27.1%

                    \[\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. Step-by-step derivation
                    1. Simplified21.6%

                      \[\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} - \left(4 \cdot \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}}\right) \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}}} \]
                    2. Taylor expanded in angle around 0 48.8%

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

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

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

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

                        \[\leadsto -4 \cdot \color{blue}{\frac{{a}^{2} \cdot {b}^{2}}{{y-scale}^{2} \cdot {x-scale}^{2}}} \]
                      2. *-commutative48.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    Alternative 7: 34.1% accurate, 2485.0× speedup?

                    \[\begin{array}{l} b = |b|\\ \\ 0 \end{array} \]
                    NOTE: b should be positive before calling this function
                    (FPCore (a b angle x-scale y-scale) :precision binary64 0.0)
                    b = abs(b);
                    double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
                    	return 0.0;
                    }
                    
                    NOTE: b should be positive before calling this function
                    real(8) function code(a, b, angle, x_45scale, y_45scale)
                        real(8), intent (in) :: a
                        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
                    
                    b = Math.abs(b);
                    public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
                    	return 0.0;
                    }
                    
                    b = abs(b)
                    def code(a, b, angle, x_45_scale, y_45_scale):
                    	return 0.0
                    
                    b = abs(b)
                    function code(a, b, angle, x_45_scale, y_45_scale)
                    	return 0.0
                    end
                    
                    b = abs(b)
                    function tmp = code(a, b, angle, x_45_scale, y_45_scale)
                    	tmp = 0.0;
                    end
                    
                    NOTE: b should be positive before calling this function
                    code[a_, b_, angle_, x$45$scale_, y$45$scale_] := 0.0
                    
                    \begin{array}{l}
                    b = |b|\\
                    \\
                    0
                    \end{array}
                    
                    Derivation
                    1. Initial program 27.1%

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

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

                      \[\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}}} \]
                    4. Step-by-step derivation
                      1. distribute-rgt-out23.8%

                        \[\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-eval23.8%

                        \[\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-rgt35.4%

                        \[\leadsto \color{blue}{0} \]
                    5. Simplified35.4%

                      \[\leadsto \color{blue}{0} \]
                    6. Final simplification35.4%

                      \[\leadsto 0 \]

                    Reproduce

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