
(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 6 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}
(FPCore (a b angle x-scale y-scale) :precision binary64 (if (<= y-scale 2e-87) (/ -4.0 (pow (* (/ x-scale b) (/ y-scale a)) 2.0)) (* -4.0 (pow (* (* b a) (/ 1.0 (* y-scale x-scale))) 2.0))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (y_45_scale <= 2e-87) {
tmp = -4.0 / pow(((x_45_scale / b) * (y_45_scale / a)), 2.0);
} else {
tmp = -4.0 * pow(((b * a) * (1.0 / (y_45_scale * x_45_scale))), 2.0);
}
return tmp;
}
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) :: tmp
if (y_45scale <= 2d-87) then
tmp = (-4.0d0) / (((x_45scale / b) * (y_45scale / a)) ** 2.0d0)
else
tmp = (-4.0d0) * (((b * a) * (1.0d0 / (y_45scale * x_45scale))) ** 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (y_45_scale <= 2e-87) {
tmp = -4.0 / Math.pow(((x_45_scale / b) * (y_45_scale / a)), 2.0);
} else {
tmp = -4.0 * Math.pow(((b * a) * (1.0 / (y_45_scale * x_45_scale))), 2.0);
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): tmp = 0 if y_45_scale <= 2e-87: tmp = -4.0 / math.pow(((x_45_scale / b) * (y_45_scale / a)), 2.0) else: tmp = -4.0 * math.pow(((b * a) * (1.0 / (y_45_scale * x_45_scale))), 2.0) return tmp
function code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0 if (y_45_scale <= 2e-87) tmp = Float64(-4.0 / (Float64(Float64(x_45_scale / b) * Float64(y_45_scale / a)) ^ 2.0)); else tmp = Float64(-4.0 * (Float64(Float64(b * a) * Float64(1.0 / Float64(y_45_scale * x_45_scale))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0; if (y_45_scale <= 2e-87) tmp = -4.0 / (((x_45_scale / b) * (y_45_scale / a)) ^ 2.0); else tmp = -4.0 * (((b * a) * (1.0 / (y_45_scale * x_45_scale))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := If[LessEqual[y$45$scale, 2e-87], N[(-4.0 / N[Power[N[(N[(x$45$scale / b), $MachinePrecision] * N[(y$45$scale / a), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[Power[N[(N[(b * a), $MachinePrecision] * N[(1.0 / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y-scale \leq 2 \cdot 10^{-87}:\\
\;\;\;\;\frac{-4}{{\left(\frac{x-scale}{b} \cdot \frac{y-scale}{a}\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot {\left(\left(b \cdot a\right) \cdot \frac{1}{y-scale \cdot x-scale}\right)}^{2}\\
\end{array}
\end{array}
if y-scale < 2.00000000000000004e-87Initial program 19.7%
Simplified13.9%
Taylor expanded in angle around 0 40.3%
*-commutative40.3%
unpow240.3%
unpow240.3%
swap-sqr54.1%
unpow254.1%
Simplified54.1%
Taylor expanded in b around 0 40.3%
associate-*r/40.3%
unpow240.3%
unpow240.3%
swap-sqr52.1%
unpow252.1%
*-commutative52.1%
associate-/l*51.8%
unpow251.8%
unpow251.8%
swap-sqr73.0%
unpow273.0%
*-commutative73.0%
Simplified73.0%
unpow273.0%
Applied egg-rr73.0%
Taylor expanded in x-scale around 0 40.3%
unpow240.3%
unpow240.3%
swap-sqr54.1%
unpow254.1%
unpow254.1%
swap-sqr73.0%
times-frac89.2%
unpow289.2%
*-commutative89.2%
times-frac94.6%
Simplified94.6%
if 2.00000000000000004e-87 < y-scale Initial program 47.6%
Simplified43.9%
Taylor expanded in angle around 0 57.1%
*-commutative57.1%
unpow257.1%
unpow257.1%
swap-sqr63.8%
unpow263.8%
Simplified63.8%
*-commutative63.8%
unpow-prod-down57.1%
frac-times59.4%
*-commutative59.4%
div-inv59.4%
pow-flip59.4%
metadata-eval59.4%
div-inv59.4%
pow-flip59.4%
metadata-eval59.4%
Applied egg-rr59.4%
associate-*r*59.3%
*-commutative59.3%
associate-*r*59.5%
unpow259.5%
unpow259.5%
swap-sqr72.2%
unpow272.2%
Simplified72.2%
add-sqr-sqrt72.2%
pow272.2%
pow272.2%
associate-*l*69.8%
pow-prod-down83.8%
*-commutative83.8%
sqrt-prod83.8%
sqrt-prod55.1%
add-sqr-sqrt92.4%
sqrt-pow198.5%
metadata-eval98.5%
unpow-198.5%
Applied egg-rr98.5%
Final simplification95.8%
(FPCore (a b angle x-scale y-scale) :precision binary64 (if (<= b 5.2e+141) (/ -4.0 (pow (* (/ x-scale a) (/ y-scale b)) 2.0)) (* -4.0 (pow (/ (* b a) (* y-scale x-scale)) 2.0))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (b <= 5.2e+141) {
tmp = -4.0 / pow(((x_45_scale / a) * (y_45_scale / b)), 2.0);
} else {
tmp = -4.0 * pow(((b * a) / (y_45_scale * x_45_scale)), 2.0);
}
return tmp;
}
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) :: tmp
if (b <= 5.2d+141) then
tmp = (-4.0d0) / (((x_45scale / a) * (y_45scale / b)) ** 2.0d0)
else
tmp = (-4.0d0) * (((b * a) / (y_45scale * x_45scale)) ** 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (b <= 5.2e+141) {
tmp = -4.0 / Math.pow(((x_45_scale / a) * (y_45_scale / b)), 2.0);
} else {
tmp = -4.0 * Math.pow(((b * a) / (y_45_scale * x_45_scale)), 2.0);
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): tmp = 0 if b <= 5.2e+141: tmp = -4.0 / math.pow(((x_45_scale / a) * (y_45_scale / b)), 2.0) else: tmp = -4.0 * math.pow(((b * a) / (y_45_scale * x_45_scale)), 2.0) return tmp
function code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0 if (b <= 5.2e+141) tmp = Float64(-4.0 / (Float64(Float64(x_45_scale / a) * Float64(y_45_scale / b)) ^ 2.0)); else tmp = Float64(-4.0 * (Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale)) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0; if (b <= 5.2e+141) tmp = -4.0 / (((x_45_scale / a) * (y_45_scale / b)) ^ 2.0); else tmp = -4.0 * (((b * a) / (y_45_scale * x_45_scale)) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := If[LessEqual[b, 5.2e+141], N[(-4.0 / N[Power[N[(N[(x$45$scale / a), $MachinePrecision] * N[(y$45$scale / b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[Power[N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.2 \cdot 10^{+141}:\\
\;\;\;\;\frac{-4}{{\left(\frac{x-scale}{a} \cdot \frac{y-scale}{b}\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot {\left(\frac{b \cdot a}{y-scale \cdot x-scale}\right)}^{2}\\
\end{array}
\end{array}
if b < 5.1999999999999999e141Initial program 31.8%
Simplified26.3%
Taylor expanded in angle around 0 46.8%
*-commutative46.8%
unpow246.8%
unpow246.8%
swap-sqr56.1%
unpow256.1%
Simplified56.1%
Taylor expanded in b around 0 46.8%
associate-*r/46.8%
unpow246.8%
unpow246.8%
swap-sqr57.5%
unpow257.5%
*-commutative57.5%
associate-/l*57.3%
unpow257.3%
unpow257.3%
swap-sqr74.3%
unpow274.3%
*-commutative74.3%
Simplified74.3%
unpow274.3%
Applied egg-rr74.3%
expm1-log1p-u46.9%
expm1-udef40.3%
add-sqr-sqrt40.3%
pow240.3%
sqrt-div40.3%
unpow240.3%
sqrt-prod18.9%
add-sqr-sqrt41.3%
sqrt-prod29.0%
add-sqr-sqrt44.4%
Applied egg-rr44.4%
expm1-def57.4%
expm1-log1p91.0%
times-frac91.1%
Simplified91.1%
if 5.1999999999999999e141 < b Initial program 5.8%
Simplified2.9%
Taylor expanded in angle around 0 37.2%
*-commutative37.2%
unpow237.2%
unpow237.2%
swap-sqr63.0%
unpow263.0%
Simplified63.0%
expm1-log1p-u5.7%
expm1-udef5.7%
*-commutative5.7%
div-inv5.7%
pow-prod-down12.3%
pow-flip12.3%
metadata-eval12.3%
Applied egg-rr12.3%
expm1-def25.5%
expm1-log1p88.3%
associate-*l*88.3%
*-commutative88.3%
Simplified88.3%
unpow288.4%
Applied egg-rr88.3%
Taylor expanded in a around 0 37.2%
unpow237.2%
unpow237.2%
swap-sqr57.3%
unpow257.3%
unpow257.3%
unpow257.3%
swap-sqr88.4%
unpow288.4%
unpow288.4%
unpow288.4%
times-frac97.0%
*-rgt-identity97.0%
associate-*r/97.0%
*-rgt-identity97.0%
associate-*r/96.9%
unpow296.9%
associate-*r/97.0%
*-rgt-identity97.0%
Simplified97.0%
Final simplification91.9%
(FPCore (a b angle x-scale y-scale) :precision binary64 (if (<= y-scale 1.35e-87) (/ -4.0 (pow (* (/ x-scale b) (/ y-scale a)) 2.0)) (* -4.0 (pow (/ (* b a) (* y-scale x-scale)) 2.0))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (y_45_scale <= 1.35e-87) {
tmp = -4.0 / pow(((x_45_scale / b) * (y_45_scale / a)), 2.0);
} else {
tmp = -4.0 * pow(((b * a) / (y_45_scale * x_45_scale)), 2.0);
}
return tmp;
}
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) :: tmp
if (y_45scale <= 1.35d-87) then
tmp = (-4.0d0) / (((x_45scale / b) * (y_45scale / a)) ** 2.0d0)
else
tmp = (-4.0d0) * (((b * a) / (y_45scale * x_45scale)) ** 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double tmp;
if (y_45_scale <= 1.35e-87) {
tmp = -4.0 / Math.pow(((x_45_scale / b) * (y_45_scale / a)), 2.0);
} else {
tmp = -4.0 * Math.pow(((b * a) / (y_45_scale * x_45_scale)), 2.0);
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): tmp = 0 if y_45_scale <= 1.35e-87: tmp = -4.0 / math.pow(((x_45_scale / b) * (y_45_scale / a)), 2.0) else: tmp = -4.0 * math.pow(((b * a) / (y_45_scale * x_45_scale)), 2.0) return tmp
function code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0 if (y_45_scale <= 1.35e-87) tmp = Float64(-4.0 / (Float64(Float64(x_45_scale / b) * Float64(y_45_scale / a)) ^ 2.0)); else tmp = Float64(-4.0 * (Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale)) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0; if (y_45_scale <= 1.35e-87) tmp = -4.0 / (((x_45_scale / b) * (y_45_scale / a)) ^ 2.0); else tmp = -4.0 * (((b * a) / (y_45_scale * x_45_scale)) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := If[LessEqual[y$45$scale, 1.35e-87], N[(-4.0 / N[Power[N[(N[(x$45$scale / b), $MachinePrecision] * N[(y$45$scale / a), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[Power[N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y-scale \leq 1.35 \cdot 10^{-87}:\\
\;\;\;\;\frac{-4}{{\left(\frac{x-scale}{b} \cdot \frac{y-scale}{a}\right)}^{2}}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot {\left(\frac{b \cdot a}{y-scale \cdot x-scale}\right)}^{2}\\
\end{array}
\end{array}
if y-scale < 1.34999999999999992e-87Initial program 19.7%
Simplified13.9%
Taylor expanded in angle around 0 40.3%
*-commutative40.3%
unpow240.3%
unpow240.3%
swap-sqr54.1%
unpow254.1%
Simplified54.1%
Taylor expanded in b around 0 40.3%
associate-*r/40.3%
unpow240.3%
unpow240.3%
swap-sqr52.1%
unpow252.1%
*-commutative52.1%
associate-/l*51.8%
unpow251.8%
unpow251.8%
swap-sqr73.0%
unpow273.0%
*-commutative73.0%
Simplified73.0%
unpow273.0%
Applied egg-rr73.0%
Taylor expanded in x-scale around 0 40.3%
unpow240.3%
unpow240.3%
swap-sqr54.1%
unpow254.1%
unpow254.1%
swap-sqr73.0%
times-frac89.2%
unpow289.2%
*-commutative89.2%
times-frac94.6%
Simplified94.6%
if 1.34999999999999992e-87 < y-scale Initial program 47.6%
Simplified43.9%
Taylor expanded in angle around 0 57.1%
*-commutative57.1%
unpow257.1%
unpow257.1%
swap-sqr63.8%
unpow263.8%
Simplified63.8%
expm1-log1p-u48.0%
expm1-udef46.8%
*-commutative46.8%
div-inv46.8%
pow-prod-down54.6%
pow-flip54.6%
metadata-eval54.6%
Applied egg-rr54.6%
expm1-def63.1%
expm1-log1p83.8%
associate-*l*83.8%
*-commutative83.8%
Simplified83.8%
unpow283.5%
Applied egg-rr83.8%
Taylor expanded in a around 0 57.1%
unpow257.1%
unpow257.1%
swap-sqr69.9%
unpow269.9%
unpow269.9%
unpow269.9%
swap-sqr84.4%
unpow284.4%
unpow284.4%
unpow284.4%
times-frac98.5%
*-rgt-identity98.5%
associate-*r/98.6%
*-rgt-identity98.6%
associate-*r/98.5%
unpow298.5%
associate-*r/98.5%
*-rgt-identity98.5%
Simplified98.5%
Final simplification95.8%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* -4.0 (pow (/ (* b a) (* y-scale x-scale)) 2.0)))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return -4.0 * pow(((b * a) / (y_45_scale * x_45_scale)), 2.0);
}
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)) ** 2.0d0)
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return -4.0 * Math.pow(((b * a) / (y_45_scale * x_45_scale)), 2.0);
}
def code(a, b, angle, x_45_scale, y_45_scale): return -4.0 * math.pow(((b * a) / (y_45_scale * x_45_scale)), 2.0)
function code(a, b, angle, x_45_scale, y_45_scale) return Float64(-4.0 * (Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale)) ^ 2.0)) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = -4.0 * (((b * a) / (y_45_scale * x_45_scale)) ^ 2.0); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(-4.0 * N[Power[N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot {\left(\frac{b \cdot a}{y-scale \cdot x-scale}\right)}^{2}
\end{array}
Initial program 28.2%
Simplified23.1%
Taylor expanded in angle around 0 45.5%
*-commutative45.5%
unpow245.5%
unpow245.5%
swap-sqr57.1%
unpow257.1%
Simplified57.1%
expm1-log1p-u32.6%
expm1-udef30.7%
*-commutative30.7%
div-inv30.7%
pow-prod-down36.4%
pow-flip36.4%
metadata-eval36.4%
Applied egg-rr36.4%
expm1-def44.6%
expm1-log1p77.1%
associate-*l*77.1%
*-commutative77.1%
Simplified77.1%
unpow276.2%
Applied egg-rr77.1%
Taylor expanded in a around 0 45.5%
unpow245.5%
unpow245.5%
swap-sqr57.5%
unpow257.5%
unpow257.5%
unpow257.5%
swap-sqr76.9%
unpow276.9%
unpow276.9%
unpow276.9%
times-frac92.5%
*-rgt-identity92.5%
associate-*r/92.5%
*-rgt-identity92.5%
associate-*r/92.5%
unpow292.5%
associate-*r/92.5%
*-rgt-identity92.5%
Simplified92.5%
Final simplification92.5%
(FPCore (a b angle x-scale y-scale) :precision binary64 (let* ((t_0 (/ (* y-scale x-scale) (* b a)))) (/ -4.0 (* t_0 t_0))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (y_45_scale * x_45_scale) / (b * a);
return -4.0 / (t_0 * t_0);
}
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 = (y_45scale * x_45scale) / (b * a)
code = (-4.0d0) / (t_0 * t_0)
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (y_45_scale * x_45_scale) / (b * a);
return -4.0 / (t_0 * t_0);
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (y_45_scale * x_45_scale) / (b * a) return -4.0 / (t_0 * t_0)
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(y_45_scale * x_45_scale) / Float64(b * a)) return Float64(-4.0 / Float64(t_0 * t_0)) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (y_45_scale * x_45_scale) / (b * a); tmp = -4.0 / (t_0 * t_0); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(y$45$scale * x$45$scale), $MachinePrecision] / N[(b * a), $MachinePrecision]), $MachinePrecision]}, N[(-4.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y-scale \cdot x-scale}{b \cdot a}\\
\frac{-4}{t_0 \cdot t_0}
\end{array}
\end{array}
Initial program 28.2%
Simplified23.1%
Taylor expanded in angle around 0 45.5%
*-commutative45.5%
unpow245.5%
unpow245.5%
swap-sqr57.1%
unpow257.1%
Simplified57.1%
Taylor expanded in b around 0 45.5%
associate-*r/45.5%
unpow245.5%
unpow245.5%
swap-sqr57.5%
unpow257.5%
*-commutative57.5%
associate-/l*57.3%
unpow257.3%
unpow257.3%
swap-sqr76.2%
unpow276.2%
*-commutative76.2%
Simplified76.2%
unpow276.2%
Applied egg-rr76.2%
unpow276.2%
times-frac91.8%
Applied egg-rr91.8%
Final simplification91.8%
(FPCore (a b angle x-scale y-scale) :precision binary64 0.0)
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return 0.0;
}
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
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return 0.0;
}
def code(a, b, angle, x_45_scale, y_45_scale): return 0.0
function code(a, b, angle, x_45_scale, y_45_scale) return 0.0 end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 28.2%
Simplified22.8%
Taylor expanded in b around 0 24.4%
distribute-rgt-out24.4%
metadata-eval24.4%
mul0-rgt40.1%
Simplified40.1%
Final simplification40.1%
herbie shell --seed 2023334
(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))))