
(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}
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ a x-scale) (/ b y-scale))))
(if (<= y-scale -5.5e-229)
(* (pow (/ (* a b) (* y-scale x-scale)) 2.0) -4.0)
(* -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 = (a / x_45_scale) * (b / y_45_scale);
double tmp;
if (y_45_scale <= -5.5e-229) {
tmp = pow(((a * b) / (y_45_scale * x_45_scale)), 2.0) * -4.0;
} else {
tmp = -4.0 * (t_0 * t_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) :: t_0
real(8) :: tmp
t_0 = (a / x_45scale) * (b / y_45scale)
if (y_45scale <= (-5.5d-229)) then
tmp = (((a * b) / (y_45scale * x_45scale)) ** 2.0d0) * (-4.0d0)
else
tmp = (-4.0d0) * (t_0 * t_0)
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 t_0 = (a / x_45_scale) * (b / y_45_scale);
double tmp;
if (y_45_scale <= -5.5e-229) {
tmp = Math.pow(((a * b) / (y_45_scale * x_45_scale)), 2.0) * -4.0;
} else {
tmp = -4.0 * (t_0 * t_0);
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (a / x_45_scale) * (b / y_45_scale) tmp = 0 if y_45_scale <= -5.5e-229: tmp = math.pow(((a * b) / (y_45_scale * x_45_scale)), 2.0) * -4.0 else: tmp = -4.0 * (t_0 * t_0) return tmp
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(a / x_45_scale) * Float64(b / y_45_scale)) tmp = 0.0 if (y_45_scale <= -5.5e-229) tmp = Float64((Float64(Float64(a * b) / Float64(y_45_scale * x_45_scale)) ^ 2.0) * -4.0); else tmp = Float64(-4.0 * Float64(t_0 * t_0)); end return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (a / x_45_scale) * (b / y_45_scale); tmp = 0.0; if (y_45_scale <= -5.5e-229) tmp = (((a * b) / (y_45_scale * x_45_scale)) ^ 2.0) * -4.0; else tmp = -4.0 * (t_0 * t_0); end tmp_2 = tmp; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(a / x$45$scale), $MachinePrecision] * N[(b / y$45$scale), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$45$scale, -5.5e-229], N[(N[Power[N[(N[(a * b), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -4.0), $MachinePrecision], N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{x-scale} \cdot \frac{b}{y-scale}\\
\mathbf{if}\;y-scale \leq -5.5 \cdot 10^{-229}:\\
\;\;\;\;{\left(\frac{a \cdot b}{y-scale \cdot x-scale}\right)}^{2} \cdot -4\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\
\end{array}
\end{array}
if y-scale < -5.5000000000000001e-229Initial program 27.9%
Simplified23.2%
Taylor expanded in angle around 0 54.4%
associate-*r/54.4%
pow-prod-down65.9%
pow-prod-down77.0%
Applied egg-rr77.0%
*-un-lft-identity77.0%
times-frac77.0%
metadata-eval77.0%
pow-prod-down61.3%
pow261.3%
pow261.3%
*-commutative61.3%
unpow-prod-down54.4%
pow254.4%
pow254.4%
frac-times53.9%
frac-times68.3%
*-commutative68.3%
Applied egg-rr92.1%
Taylor expanded in a around 0 97.1%
if -5.5000000000000001e-229 < y-scale Initial program 22.1%
Simplified20.4%
Taylor expanded in angle around 0 48.2%
associate-*r/48.2%
pow-prod-down62.8%
pow-prod-down74.0%
Applied egg-rr74.0%
*-un-lft-identity74.0%
times-frac74.0%
metadata-eval74.0%
pow-prod-down59.1%
pow259.1%
pow259.1%
*-commutative59.1%
unpow-prod-down48.2%
pow248.2%
pow248.2%
frac-times47.4%
frac-times58.9%
*-commutative58.9%
Applied egg-rr96.0%
unpow296.0%
Applied egg-rr96.0%
Final simplification96.5%
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ a x-scale) (/ b y-scale)))
(t_1 (/ (* y-scale x-scale) (* a b))))
(if (<= y-scale -1.3e-228) (/ -4.0 (* t_1 t_1)) (* -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 = (a / x_45_scale) * (b / y_45_scale);
double t_1 = (y_45_scale * x_45_scale) / (a * b);
double tmp;
if (y_45_scale <= -1.3e-228) {
tmp = -4.0 / (t_1 * t_1);
} else {
tmp = -4.0 * (t_0 * t_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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (a / x_45scale) * (b / y_45scale)
t_1 = (y_45scale * x_45scale) / (a * b)
if (y_45scale <= (-1.3d-228)) then
tmp = (-4.0d0) / (t_1 * t_1)
else
tmp = (-4.0d0) * (t_0 * t_0)
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 t_0 = (a / x_45_scale) * (b / y_45_scale);
double t_1 = (y_45_scale * x_45_scale) / (a * b);
double tmp;
if (y_45_scale <= -1.3e-228) {
tmp = -4.0 / (t_1 * t_1);
} else {
tmp = -4.0 * (t_0 * t_0);
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (a / x_45_scale) * (b / y_45_scale) t_1 = (y_45_scale * x_45_scale) / (a * b) tmp = 0 if y_45_scale <= -1.3e-228: tmp = -4.0 / (t_1 * t_1) else: tmp = -4.0 * (t_0 * t_0) return tmp
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(a / x_45_scale) * Float64(b / y_45_scale)) t_1 = Float64(Float64(y_45_scale * x_45_scale) / Float64(a * b)) tmp = 0.0 if (y_45_scale <= -1.3e-228) tmp = Float64(-4.0 / Float64(t_1 * t_1)); else tmp = Float64(-4.0 * Float64(t_0 * t_0)); end return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (a / x_45_scale) * (b / y_45_scale); t_1 = (y_45_scale * x_45_scale) / (a * b); tmp = 0.0; if (y_45_scale <= -1.3e-228) tmp = -4.0 / (t_1 * t_1); else tmp = -4.0 * (t_0 * t_0); end tmp_2 = tmp; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(a / x$45$scale), $MachinePrecision] * N[(b / y$45$scale), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y$45$scale * x$45$scale), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$45$scale, -1.3e-228], N[(-4.0 / N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{x-scale} \cdot \frac{b}{y-scale}\\
t_1 := \frac{y-scale \cdot x-scale}{a \cdot b}\\
\mathbf{if}\;y-scale \leq -1.3 \cdot 10^{-228}:\\
\;\;\;\;\frac{-4}{t_1 \cdot t_1}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\
\end{array}
\end{array}
if y-scale < -1.3e-228Initial program 27.9%
cancel-sign-sub-inv27.9%
fma-def31.5%
Simplified26.9%
Taylor expanded in angle around 0 54.4%
times-frac53.9%
unpow253.9%
unpow253.9%
unpow253.9%
unpow253.9%
Simplified53.9%
Taylor expanded in a around 0 53.9%
unpow253.9%
unpow253.9%
times-frac68.3%
Simplified68.3%
metadata-eval68.3%
frac-times53.9%
frac-times54.4%
pow254.4%
pow254.4%
pow-prod-down65.9%
pow265.9%
pow265.9%
unpow-prod-down77.0%
*-commutative77.0%
times-frac77.0%
*-un-lft-identity77.0%
associate-/l*77.0%
Applied egg-rr77.0%
add-sqr-sqrt77.0%
sqrt-div77.0%
unpow277.0%
sqrt-prod44.7%
add-sqr-sqrt56.8%
*-commutative56.8%
unpow256.8%
sqrt-prod33.1%
add-sqr-sqrt53.4%
sqrt-div53.4%
unpow253.4%
sqrt-prod35.5%
add-sqr-sqrt60.0%
*-commutative60.0%
unpow260.0%
sqrt-prod55.7%
add-sqr-sqrt96.7%
Applied egg-rr96.7%
if -1.3e-228 < y-scale Initial program 22.1%
Simplified20.4%
Taylor expanded in angle around 0 48.2%
associate-*r/48.2%
pow-prod-down62.8%
pow-prod-down74.0%
Applied egg-rr74.0%
*-un-lft-identity74.0%
times-frac74.0%
metadata-eval74.0%
pow-prod-down59.1%
pow259.1%
pow259.1%
*-commutative59.1%
unpow-prod-down48.2%
pow248.2%
pow248.2%
frac-times47.4%
frac-times58.9%
*-commutative58.9%
Applied egg-rr96.0%
unpow296.0%
Applied egg-rr96.0%
Final simplification96.4%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* -4.0 (* (* (/ a x-scale) (/ a x-scale)) (* (/ b y-scale) (/ b y-scale)))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return -4.0 * (((a / x_45_scale) * (a / x_45_scale)) * ((b / y_45_scale) * (b / y_45_scale)));
}
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 / x_45scale) * (a / x_45scale)) * ((b / y_45scale) * (b / y_45scale)))
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return -4.0 * (((a / x_45_scale) * (a / x_45_scale)) * ((b / y_45_scale) * (b / y_45_scale)));
}
def code(a, b, angle, x_45_scale, y_45_scale): return -4.0 * (((a / x_45_scale) * (a / x_45_scale)) * ((b / y_45_scale) * (b / y_45_scale)))
function code(a, b, angle, x_45_scale, y_45_scale) return Float64(-4.0 * Float64(Float64(Float64(a / x_45_scale) * Float64(a / x_45_scale)) * Float64(Float64(b / y_45_scale) * Float64(b / y_45_scale)))) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = -4.0 * (((a / x_45_scale) * (a / x_45_scale)) * ((b / y_45_scale) * (b / y_45_scale))); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(-4.0 * N[(N[(N[(a / x$45$scale), $MachinePrecision] * N[(a / x$45$scale), $MachinePrecision]), $MachinePrecision] * N[(N[(b / y$45$scale), $MachinePrecision] * N[(b / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \left(\left(\frac{a}{x-scale} \cdot \frac{a}{x-scale}\right) \cdot \left(\frac{b}{y-scale} \cdot \frac{b}{y-scale}\right)\right)
\end{array}
Initial program 24.8%
cancel-sign-sub-inv24.8%
fma-def27.9%
Simplified25.2%
Taylor expanded in angle around 0 51.1%
times-frac50.4%
unpow250.4%
unpow250.4%
unpow250.4%
unpow250.4%
Simplified50.4%
Taylor expanded in a around 0 50.4%
unpow250.4%
unpow250.4%
times-frac63.2%
Simplified63.2%
Taylor expanded in b around 0 63.2%
unpow263.2%
unpow263.2%
times-frac78.0%
Simplified78.0%
Final simplification78.0%
(FPCore (a b angle x-scale y-scale) :precision binary64 (let* ((t_0 (* (/ a x-scale) (/ b y-scale)))) (* -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 = (a / x_45_scale) * (b / y_45_scale);
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 = (a / x_45scale) * (b / y_45scale)
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 = (a / x_45_scale) * (b / y_45_scale);
return -4.0 * (t_0 * t_0);
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (a / x_45_scale) * (b / y_45_scale) return -4.0 * (t_0 * t_0)
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(a / x_45_scale) * Float64(b / y_45_scale)) return Float64(-4.0 * Float64(t_0 * t_0)) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (a / x_45_scale) * (b / y_45_scale); tmp = -4.0 * (t_0 * t_0); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(a / x$45$scale), $MachinePrecision] * N[(b / y$45$scale), $MachinePrecision]), $MachinePrecision]}, N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{x-scale} \cdot \frac{b}{y-scale}\\
-4 \cdot \left(t_0 \cdot t_0\right)
\end{array}
\end{array}
Initial program 24.8%
Simplified21.7%
Taylor expanded in angle around 0 51.1%
associate-*r/51.1%
pow-prod-down64.2%
pow-prod-down75.4%
Applied egg-rr75.4%
*-un-lft-identity75.4%
times-frac75.4%
metadata-eval75.4%
pow-prod-down60.1%
pow260.1%
pow260.1%
*-commutative60.1%
unpow-prod-down51.1%
pow251.1%
pow251.1%
frac-times50.4%
frac-times63.2%
*-commutative63.2%
Applied egg-rr94.2%
unpow294.2%
Applied egg-rr94.2%
Final simplification94.2%
(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 24.8%
cancel-sign-sub-inv24.8%
fma-def27.9%
Simplified25.2%
Taylor expanded in b around 0 23.6%
*-commutative23.6%
*-commutative23.6%
*-commutative23.6%
distribute-lft-out23.6%
Simplified36.1%
Final simplification36.1%
herbie shell --seed 2023189
(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))))