
(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:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* b (/ a_m x-scale))))
(if (<= a_m 2.25e-189)
(* -4.0 (/ t_0 (* y-scale (/ y-scale t_0))))
(* -4.0 (pow (* a_m (/ (/ b x-scale) y-scale)) 2.0)))))a_m = fabs(a);
double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = b * (a_m / x_45_scale);
double tmp;
if (a_m <= 2.25e-189) {
tmp = -4.0 * (t_0 / (y_45_scale * (y_45_scale / t_0)));
} else {
tmp = -4.0 * pow((a_m * ((b / x_45_scale) / y_45_scale)), 2.0);
}
return tmp;
}
a_m = abs(a)
real(8) function code(a_m, b, angle, x_45scale, y_45scale)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
real(8), intent (in) :: angle
real(8), intent (in) :: x_45scale
real(8), intent (in) :: y_45scale
real(8) :: t_0
real(8) :: tmp
t_0 = b * (a_m / x_45scale)
if (a_m <= 2.25d-189) then
tmp = (-4.0d0) * (t_0 / (y_45scale * (y_45scale / t_0)))
else
tmp = (-4.0d0) * ((a_m * ((b / x_45scale) / y_45scale)) ** 2.0d0)
end if
code = tmp
end function
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = b * (a_m / x_45_scale);
double tmp;
if (a_m <= 2.25e-189) {
tmp = -4.0 * (t_0 / (y_45_scale * (y_45_scale / t_0)));
} else {
tmp = -4.0 * Math.pow((a_m * ((b / x_45_scale) / y_45_scale)), 2.0);
}
return tmp;
}
a_m = math.fabs(a) def code(a_m, b, angle, x_45_scale, y_45_scale): t_0 = b * (a_m / x_45_scale) tmp = 0 if a_m <= 2.25e-189: tmp = -4.0 * (t_0 / (y_45_scale * (y_45_scale / t_0))) else: tmp = -4.0 * math.pow((a_m * ((b / x_45_scale) / y_45_scale)), 2.0) return tmp
a_m = abs(a) function code(a_m, b, angle, x_45_scale, y_45_scale) t_0 = Float64(b * Float64(a_m / x_45_scale)) tmp = 0.0 if (a_m <= 2.25e-189) tmp = Float64(-4.0 * Float64(t_0 / Float64(y_45_scale * Float64(y_45_scale / t_0)))); else tmp = Float64(-4.0 * (Float64(a_m * Float64(Float64(b / x_45_scale) / y_45_scale)) ^ 2.0)); end return tmp end
a_m = abs(a); function tmp_2 = code(a_m, b, angle, x_45_scale, y_45_scale) t_0 = b * (a_m / x_45_scale); tmp = 0.0; if (a_m <= 2.25e-189) tmp = -4.0 * (t_0 / (y_45_scale * (y_45_scale / t_0))); else tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) ^ 2.0); end tmp_2 = tmp; end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(b * N[(a$95$m / x$45$scale), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a$95$m, 2.25e-189], N[(-4.0 * N[(t$95$0 / N[(y$45$scale * N[(y$45$scale / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[Power[N[(a$95$m * N[(N[(b / x$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := b \cdot \frac{a_m}{x-scale}\\
\mathbf{if}\;a_m \leq 2.25 \cdot 10^{-189}:\\
\;\;\;\;-4 \cdot \frac{t_0}{y-scale \cdot \frac{y-scale}{t_0}}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot {\left(a_m \cdot \frac{\frac{b}{x-scale}}{y-scale}\right)}^{2}\\
\end{array}
\end{array}
if a < 2.2499999999999998e-189Initial program 32.5%
Simplified28.9%
Taylor expanded in angle around 0 49.6%
*-commutative49.6%
associate-/l*51.0%
Simplified51.0%
associate-/l*49.6%
div-inv49.6%
pow-prod-down66.1%
pow-prod-down79.1%
Applied egg-rr79.1%
associate-*r/79.1%
associate-*l/79.1%
*-rgt-identity79.1%
*-commutative79.1%
Simplified79.1%
add-sqr-sqrt79.1%
unpow279.1%
times-frac81.3%
*-commutative81.3%
sqrt-pow165.4%
metadata-eval65.4%
pow165.4%
*-commutative65.4%
sqrt-pow192.4%
metadata-eval92.4%
pow192.4%
Applied egg-rr92.4%
clear-num92.4%
associate-/r*91.8%
frac-times91.3%
*-un-lft-identity91.3%
*-un-lft-identity91.3%
times-frac88.8%
/-rgt-identity88.8%
*-commutative88.8%
associate-/l*91.4%
*-un-lft-identity91.4%
times-frac95.9%
/-rgt-identity95.9%
Applied egg-rr95.9%
if 2.2499999999999998e-189 < a Initial program 18.8%
Simplified16.9%
Taylor expanded in angle around 0 44.1%
*-commutative44.1%
associate-/l*46.8%
Simplified46.8%
associate-/l*44.1%
div-inv44.1%
pow-prod-down59.5%
pow-prod-down76.6%
Applied egg-rr76.6%
associate-*r/76.6%
associate-*l/76.6%
*-rgt-identity76.6%
*-commutative76.6%
Simplified76.6%
add-sqr-sqrt76.6%
unpow276.6%
times-frac83.0%
*-commutative83.0%
sqrt-pow156.8%
metadata-eval56.8%
pow156.8%
*-commutative56.8%
sqrt-pow193.9%
metadata-eval93.9%
pow193.9%
Applied egg-rr93.9%
frac-times76.6%
unpow276.6%
unpow276.6%
clear-num76.6%
unpow-prod-down55.2%
associate-/l/57.8%
unpow-prod-down46.8%
unpow246.8%
frac-times51.3%
*-commutative51.3%
clear-num51.3%
frac-times46.8%
*-commutative46.8%
unpow-prod-down57.8%
unpow257.8%
associate-/l*55.2%
Applied egg-rr95.6%
remove-double-div95.6%
associate-*r/93.9%
associate-*l/93.9%
*-commutative93.9%
associate-/r*93.6%
Simplified93.6%
Final simplification94.9%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(if (<= x-scale 1.2e-127)
(*
-4.0
(* (/ (* a_m b) (* x-scale y-scale)) (/ b (/ (* x-scale y-scale) a_m))))
(*
-4.0
(* (* a_m (/ (/ b x-scale) y-scale)) (* (/ b x-scale) (/ a_m y-scale))))))a_m = fabs(a);
double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (x_45_scale <= 1.2e-127) {
tmp = -4.0 * (((a_m * b) / (x_45_scale * y_45_scale)) * (b / ((x_45_scale * y_45_scale) / a_m)));
} else {
tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale)));
}
return tmp;
}
a_m = abs(a)
real(8) function code(a_m, b, angle, x_45scale, y_45scale)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
real(8), intent (in) :: angle
real(8), intent (in) :: x_45scale
real(8), intent (in) :: y_45scale
real(8) :: tmp
if (x_45scale <= 1.2d-127) then
tmp = (-4.0d0) * (((a_m * b) / (x_45scale * y_45scale)) * (b / ((x_45scale * y_45scale) / a_m)))
else
tmp = (-4.0d0) * ((a_m * ((b / x_45scale) / y_45scale)) * ((b / x_45scale) * (a_m / y_45scale)))
end if
code = tmp
end function
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (x_45_scale <= 1.2e-127) {
tmp = -4.0 * (((a_m * b) / (x_45_scale * y_45_scale)) * (b / ((x_45_scale * y_45_scale) / a_m)));
} else {
tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale)));
}
return tmp;
}
a_m = math.fabs(a) def code(a_m, b, angle, x_45_scale, y_45_scale): tmp = 0 if x_45_scale <= 1.2e-127: tmp = -4.0 * (((a_m * b) / (x_45_scale * y_45_scale)) * (b / ((x_45_scale * y_45_scale) / a_m))) else: tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale))) return tmp
a_m = abs(a) function code(a_m, b, angle, x_45_scale, y_45_scale) tmp = 0.0 if (x_45_scale <= 1.2e-127) tmp = Float64(-4.0 * Float64(Float64(Float64(a_m * b) / Float64(x_45_scale * y_45_scale)) * Float64(b / Float64(Float64(x_45_scale * y_45_scale) / a_m)))); else tmp = Float64(-4.0 * Float64(Float64(a_m * Float64(Float64(b / x_45_scale) / y_45_scale)) * Float64(Float64(b / x_45_scale) * Float64(a_m / y_45_scale)))); end return tmp end
a_m = abs(a); function tmp_2 = code(a_m, b, angle, x_45_scale, y_45_scale) tmp = 0.0; if (x_45_scale <= 1.2e-127) tmp = -4.0 * (((a_m * b) / (x_45_scale * y_45_scale)) * (b / ((x_45_scale * y_45_scale) / a_m))); else tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale))); end tmp_2 = tmp; end
a_m = N[Abs[a], $MachinePrecision] code[a$95$m_, b_, angle_, x$45$scale_, y$45$scale_] := If[LessEqual[x$45$scale, 1.2e-127], N[(-4.0 * N[(N[(N[(a$95$m * b), $MachinePrecision] / N[(x$45$scale * y$45$scale), $MachinePrecision]), $MachinePrecision] * N[(b / N[(N[(x$45$scale * y$45$scale), $MachinePrecision] / a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(N[(a$95$m * N[(N[(b / x$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision] * N[(N[(b / x$45$scale), $MachinePrecision] * N[(a$95$m / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
\mathbf{if}\;x-scale \leq 1.2 \cdot 10^{-127}:\\
\;\;\;\;-4 \cdot \left(\frac{a_m \cdot b}{x-scale \cdot y-scale} \cdot \frac{b}{\frac{x-scale \cdot y-scale}{a_m}}\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(\left(a_m \cdot \frac{\frac{b}{x-scale}}{y-scale}\right) \cdot \left(\frac{b}{x-scale} \cdot \frac{a_m}{y-scale}\right)\right)\\
\end{array}
\end{array}
if x-scale < 1.19999999999999991e-127Initial program 21.3%
Simplified16.6%
Taylor expanded in angle around 0 41.8%
*-commutative41.8%
associate-/l*43.1%
Simplified43.1%
associate-/l*41.8%
div-inv41.8%
pow-prod-down57.6%
pow-prod-down77.5%
Applied egg-rr77.5%
associate-*r/77.5%
associate-*l/77.5%
*-rgt-identity77.5%
*-commutative77.5%
Simplified77.5%
add-sqr-sqrt77.5%
unpow277.5%
times-frac80.9%
*-commutative80.9%
sqrt-pow158.1%
metadata-eval58.1%
pow158.1%
*-commutative58.1%
sqrt-pow194.3%
metadata-eval94.3%
pow194.3%
Applied egg-rr94.3%
associate-/l*93.2%
div-inv93.1%
*-commutative93.1%
*-un-lft-identity93.1%
times-frac88.3%
/-rgt-identity88.3%
Applied egg-rr88.3%
associate-*r/88.3%
*-rgt-identity88.3%
associate-*r/93.2%
*-commutative93.2%
Simplified93.2%
if 1.19999999999999991e-127 < x-scale Initial program 34.6%
Simplified34.6%
Taylor expanded in angle around 0 55.4%
*-commutative55.4%
associate-/l*58.3%
Simplified58.3%
associate-/l*55.4%
*-un-lft-identity55.4%
add-sqr-sqrt55.3%
times-frac55.3%
pow-prod-down55.4%
pow-prod-down71.7%
pow-prod-down78.7%
Applied egg-rr78.7%
*-commutative78.7%
times-frac78.7%
*-un-lft-identity78.7%
unpow278.7%
add-sqr-sqrt78.7%
associate-/l*83.8%
*-commutative83.8%
*-commutative83.8%
Applied egg-rr83.8%
associate-/l*78.7%
unpow278.7%
frac-times91.2%
times-frac87.4%
associate-*l*85.5%
*-un-lft-identity85.5%
times-frac86.8%
/-rgt-identity86.8%
Applied egg-rr86.8%
associate-*r*88.8%
associate-*r/87.4%
associate-*l/88.8%
*-commutative88.8%
associate-/r*94.6%
Simplified94.6%
Final simplification93.7%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (/ (* a_m b) (* x-scale y-scale))))
(if (<= x-scale 1.04e-13)
(* -4.0 (* t_0 t_0))
(*
-4.0
(*
(* a_m (/ (/ b x-scale) y-scale))
(* (/ b x-scale) (/ a_m y-scale)))))))a_m = fabs(a);
double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (a_m * b) / (x_45_scale * y_45_scale);
double tmp;
if (x_45_scale <= 1.04e-13) {
tmp = -4.0 * (t_0 * t_0);
} else {
tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale)));
}
return tmp;
}
a_m = abs(a)
real(8) function code(a_m, b, angle, x_45scale, y_45scale)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
real(8), intent (in) :: angle
real(8), intent (in) :: x_45scale
real(8), intent (in) :: y_45scale
real(8) :: t_0
real(8) :: tmp
t_0 = (a_m * b) / (x_45scale * y_45scale)
if (x_45scale <= 1.04d-13) then
tmp = (-4.0d0) * (t_0 * t_0)
else
tmp = (-4.0d0) * ((a_m * ((b / x_45scale) / y_45scale)) * ((b / x_45scale) * (a_m / y_45scale)))
end if
code = tmp
end function
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (a_m * b) / (x_45_scale * y_45_scale);
double tmp;
if (x_45_scale <= 1.04e-13) {
tmp = -4.0 * (t_0 * t_0);
} else {
tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale)));
}
return tmp;
}
a_m = math.fabs(a) def code(a_m, b, angle, x_45_scale, y_45_scale): t_0 = (a_m * b) / (x_45_scale * y_45_scale) tmp = 0 if x_45_scale <= 1.04e-13: tmp = -4.0 * (t_0 * t_0) else: tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale))) return tmp
a_m = abs(a) function code(a_m, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(a_m * b) / Float64(x_45_scale * y_45_scale)) tmp = 0.0 if (x_45_scale <= 1.04e-13) tmp = Float64(-4.0 * Float64(t_0 * t_0)); else tmp = Float64(-4.0 * Float64(Float64(a_m * Float64(Float64(b / x_45_scale) / y_45_scale)) * Float64(Float64(b / x_45_scale) * Float64(a_m / y_45_scale)))); end return tmp end
a_m = abs(a); function tmp_2 = code(a_m, b, angle, x_45_scale, y_45_scale) t_0 = (a_m * b) / (x_45_scale * y_45_scale); tmp = 0.0; if (x_45_scale <= 1.04e-13) tmp = -4.0 * (t_0 * t_0); else tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale))); end tmp_2 = tmp; end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(a$95$m * b), $MachinePrecision] / N[(x$45$scale * y$45$scale), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$45$scale, 1.04e-13], N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(N[(a$95$m * N[(N[(b / x$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision] * N[(N[(b / x$45$scale), $MachinePrecision] * N[(a$95$m / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := \frac{a_m \cdot b}{x-scale \cdot y-scale}\\
\mathbf{if}\;x-scale \leq 1.04 \cdot 10^{-13}:\\
\;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(\left(a_m \cdot \frac{\frac{b}{x-scale}}{y-scale}\right) \cdot \left(\frac{b}{x-scale} \cdot \frac{a_m}{y-scale}\right)\right)\\
\end{array}
\end{array}
if x-scale < 1.03999999999999999e-13Initial program 22.7%
Simplified18.0%
Taylor expanded in angle around 0 43.6%
*-commutative43.6%
associate-/l*45.2%
Simplified45.2%
associate-/l*43.6%
div-inv43.6%
pow-prod-down60.2%
pow-prod-down78.1%
Applied egg-rr78.1%
associate-*r/78.2%
associate-*l/78.2%
*-rgt-identity78.2%
*-commutative78.2%
Simplified78.2%
add-sqr-sqrt78.2%
unpow278.2%
times-frac81.7%
*-commutative81.7%
sqrt-pow158.3%
metadata-eval58.3%
pow158.3%
*-commutative58.3%
sqrt-pow193.9%
metadata-eval93.9%
pow193.9%
Applied egg-rr93.9%
if 1.03999999999999999e-13 < x-scale Initial program 35.2%
Simplified36.4%
Taylor expanded in angle around 0 55.3%
*-commutative55.3%
associate-/l*57.8%
Simplified57.8%
associate-/l*55.3%
*-un-lft-identity55.3%
add-sqr-sqrt55.3%
times-frac55.3%
pow-prod-down55.3%
pow-prod-down69.9%
pow-prod-down77.7%
Applied egg-rr77.7%
*-commutative77.7%
times-frac77.6%
*-un-lft-identity77.6%
unpow277.6%
add-sqr-sqrt77.6%
associate-/l*83.0%
*-commutative83.0%
*-commutative83.0%
Applied egg-rr83.0%
associate-/l*77.6%
unpow277.6%
frac-times91.2%
times-frac87.6%
associate-*l*86.4%
*-un-lft-identity86.4%
times-frac87.7%
/-rgt-identity87.7%
Applied egg-rr87.7%
associate-*r*88.9%
associate-*r/87.6%
associate-*l/88.9%
*-commutative88.9%
associate-/r*95.5%
Simplified95.5%
Final simplification94.4%
a_m = (fabs.f64 a)
(FPCore (a_m b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* b (/ a_m x-scale))))
(if (<= a_m 2e-190)
(* -4.0 (/ t_0 (* y-scale (/ y-scale t_0))))
(*
-4.0
(*
(* a_m (/ (/ b x-scale) y-scale))
(* (/ b x-scale) (/ a_m y-scale)))))))a_m = fabs(a);
double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = b * (a_m / x_45_scale);
double tmp;
if (a_m <= 2e-190) {
tmp = -4.0 * (t_0 / (y_45_scale * (y_45_scale / t_0)));
} else {
tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale)));
}
return tmp;
}
a_m = abs(a)
real(8) function code(a_m, b, angle, x_45scale, y_45scale)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
real(8), intent (in) :: angle
real(8), intent (in) :: x_45scale
real(8), intent (in) :: y_45scale
real(8) :: t_0
real(8) :: tmp
t_0 = b * (a_m / x_45scale)
if (a_m <= 2d-190) then
tmp = (-4.0d0) * (t_0 / (y_45scale * (y_45scale / t_0)))
else
tmp = (-4.0d0) * ((a_m * ((b / x_45scale) / y_45scale)) * ((b / x_45scale) * (a_m / y_45scale)))
end if
code = tmp
end function
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = b * (a_m / x_45_scale);
double tmp;
if (a_m <= 2e-190) {
tmp = -4.0 * (t_0 / (y_45_scale * (y_45_scale / t_0)));
} else {
tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale)));
}
return tmp;
}
a_m = math.fabs(a) def code(a_m, b, angle, x_45_scale, y_45_scale): t_0 = b * (a_m / x_45_scale) tmp = 0 if a_m <= 2e-190: tmp = -4.0 * (t_0 / (y_45_scale * (y_45_scale / t_0))) else: tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale))) return tmp
a_m = abs(a) function code(a_m, b, angle, x_45_scale, y_45_scale) t_0 = Float64(b * Float64(a_m / x_45_scale)) tmp = 0.0 if (a_m <= 2e-190) tmp = Float64(-4.0 * Float64(t_0 / Float64(y_45_scale * Float64(y_45_scale / t_0)))); else tmp = Float64(-4.0 * Float64(Float64(a_m * Float64(Float64(b / x_45_scale) / y_45_scale)) * Float64(Float64(b / x_45_scale) * Float64(a_m / y_45_scale)))); end return tmp end
a_m = abs(a); function tmp_2 = code(a_m, b, angle, x_45_scale, y_45_scale) t_0 = b * (a_m / x_45_scale); tmp = 0.0; if (a_m <= 2e-190) tmp = -4.0 * (t_0 / (y_45_scale * (y_45_scale / t_0))); else tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale))); end tmp_2 = tmp; end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(b * N[(a$95$m / x$45$scale), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a$95$m, 2e-190], N[(-4.0 * N[(t$95$0 / N[(y$45$scale * N[(y$45$scale / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(N[(a$95$m * N[(N[(b / x$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision] * N[(N[(b / x$45$scale), $MachinePrecision] * N[(a$95$m / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
a_m = \left|a\right|
\\
\begin{array}{l}
t_0 := b \cdot \frac{a_m}{x-scale}\\
\mathbf{if}\;a_m \leq 2 \cdot 10^{-190}:\\
\;\;\;\;-4 \cdot \frac{t_0}{y-scale \cdot \frac{y-scale}{t_0}}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(\left(a_m \cdot \frac{\frac{b}{x-scale}}{y-scale}\right) \cdot \left(\frac{b}{x-scale} \cdot \frac{a_m}{y-scale}\right)\right)\\
\end{array}
\end{array}
if a < 2e-190Initial program 32.5%
Simplified28.9%
Taylor expanded in angle around 0 49.6%
*-commutative49.6%
associate-/l*51.0%
Simplified51.0%
associate-/l*49.6%
div-inv49.6%
pow-prod-down66.1%
pow-prod-down79.1%
Applied egg-rr79.1%
associate-*r/79.1%
associate-*l/79.1%
*-rgt-identity79.1%
*-commutative79.1%
Simplified79.1%
add-sqr-sqrt79.1%
unpow279.1%
times-frac81.3%
*-commutative81.3%
sqrt-pow165.4%
metadata-eval65.4%
pow165.4%
*-commutative65.4%
sqrt-pow192.4%
metadata-eval92.4%
pow192.4%
Applied egg-rr92.4%
clear-num92.4%
associate-/r*91.8%
frac-times91.3%
*-un-lft-identity91.3%
*-un-lft-identity91.3%
times-frac88.8%
/-rgt-identity88.8%
*-commutative88.8%
associate-/l*91.4%
*-un-lft-identity91.4%
times-frac95.9%
/-rgt-identity95.9%
Applied egg-rr95.9%
if 2e-190 < a Initial program 18.8%
Simplified16.9%
Taylor expanded in angle around 0 44.1%
*-commutative44.1%
associate-/l*46.8%
Simplified46.8%
associate-/l*44.1%
*-un-lft-identity44.1%
add-sqr-sqrt44.0%
times-frac44.0%
pow-prod-down44.1%
pow-prod-down59.4%
pow-prod-down76.6%
Applied egg-rr76.6%
*-commutative76.6%
times-frac76.6%
*-un-lft-identity76.6%
unpow276.6%
add-sqr-sqrt76.6%
associate-/l*83.0%
*-commutative83.0%
*-commutative83.0%
Applied egg-rr83.0%
associate-/l*76.6%
unpow276.6%
frac-times93.9%
times-frac89.7%
associate-*l*87.1%
*-un-lft-identity87.1%
times-frac88.8%
/-rgt-identity88.8%
Applied egg-rr88.8%
associate-*r*91.4%
associate-*r/89.7%
associate-*l/89.7%
*-commutative89.7%
associate-/r*92.8%
Simplified92.8%
Final simplification94.5%
a_m = (fabs.f64 a) (FPCore (a_m b angle x-scale y-scale) :precision binary64 (* -4.0 (* (* a_m (/ (/ b x-scale) y-scale)) (* (/ b x-scale) (/ a_m y-scale)))))
a_m = fabs(a);
double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
return -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale)));
}
a_m = abs(a)
real(8) function code(a_m, b, angle, x_45scale, y_45scale)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
real(8), intent (in) :: angle
real(8), intent (in) :: x_45scale
real(8), intent (in) :: y_45scale
code = (-4.0d0) * ((a_m * ((b / x_45scale) / y_45scale)) * ((b / x_45scale) * (a_m / y_45scale)))
end function
a_m = Math.abs(a);
public static double code(double a_m, double b, double angle, double x_45_scale, double y_45_scale) {
return -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale)));
}
a_m = math.fabs(a) def code(a_m, b, angle, x_45_scale, y_45_scale): return -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale)))
a_m = abs(a) function code(a_m, b, angle, x_45_scale, y_45_scale) return Float64(-4.0 * Float64(Float64(a_m * Float64(Float64(b / x_45_scale) / y_45_scale)) * Float64(Float64(b / x_45_scale) * Float64(a_m / y_45_scale)))) end
a_m = abs(a); function tmp = code(a_m, b, angle, x_45_scale, y_45_scale) tmp = -4.0 * ((a_m * ((b / x_45_scale) / y_45_scale)) * ((b / x_45_scale) * (a_m / y_45_scale))); end
a_m = N[Abs[a], $MachinePrecision] code[a$95$m_, b_, angle_, x$45$scale_, y$45$scale_] := N[(-4.0 * N[(N[(a$95$m * N[(N[(b / x$45$scale), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision] * N[(N[(b / x$45$scale), $MachinePrecision] * N[(a$95$m / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
-4 \cdot \left(\left(a_m \cdot \frac{\frac{b}{x-scale}}{y-scale}\right) \cdot \left(\frac{b}{x-scale} \cdot \frac{a_m}{y-scale}\right)\right)
\end{array}
Initial program 26.6%
Simplified23.7%
Taylor expanded in angle around 0 47.2%
*-commutative47.2%
associate-/l*49.2%
Simplified49.2%
associate-/l*47.2%
*-un-lft-identity47.2%
add-sqr-sqrt47.2%
times-frac47.2%
pow-prod-down47.2%
pow-prod-down63.2%
pow-prod-down78.0%
Applied egg-rr78.0%
*-commutative78.0%
times-frac78.0%
*-un-lft-identity78.0%
unpow278.0%
add-sqr-sqrt78.0%
associate-/l*82.0%
*-commutative82.0%
*-commutative82.0%
Applied egg-rr82.0%
associate-/l*78.0%
unpow278.0%
frac-times93.1%
times-frac88.3%
associate-*l*86.4%
*-un-lft-identity86.4%
times-frac87.2%
/-rgt-identity87.2%
Applied egg-rr87.2%
associate-*r*88.7%
associate-*r/88.3%
associate-*l/89.0%
*-commutative89.0%
associate-/r*92.5%
Simplified92.5%
Final simplification92.5%
herbie shell --seed 2023336
(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))))