
(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 (* b (/ b y-scale)))
(t_1 (* (/ a x-scale) (/ a x-scale)))
(t_2 (/ a (/ y-scale b)))
(t_3 (* -4.0 (/ (* t_2 t_2) (* x-scale x-scale)))))
(if (<= x-scale -1.8e+181)
(* -4.0 (/ (* (pow (/ a x-scale) 2.0) t_0) y-scale))
(if (<= x-scale -1.14e-160)
t_3
(if (<= x-scale 6e-160)
(* -4.0 (* t_1 (/ t_0 y-scale)))
(if (<= x-scale 1.05e+122)
t_3
(* -4.0 (* t_1 (* (/ b y-scale) (/ b y-scale))))))))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = b * (b / y_45_scale);
double t_1 = (a / x_45_scale) * (a / x_45_scale);
double t_2 = a / (y_45_scale / b);
double t_3 = -4.0 * ((t_2 * t_2) / (x_45_scale * x_45_scale));
double tmp;
if (x_45_scale <= -1.8e+181) {
tmp = -4.0 * ((pow((a / x_45_scale), 2.0) * t_0) / y_45_scale);
} else if (x_45_scale <= -1.14e-160) {
tmp = t_3;
} else if (x_45_scale <= 6e-160) {
tmp = -4.0 * (t_1 * (t_0 / y_45_scale));
} else if (x_45_scale <= 1.05e+122) {
tmp = t_3;
} else {
tmp = -4.0 * (t_1 * ((b / y_45_scale) * (b / y_45_scale)));
}
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) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = b * (b / y_45scale)
t_1 = (a / x_45scale) * (a / x_45scale)
t_2 = a / (y_45scale / b)
t_3 = (-4.0d0) * ((t_2 * t_2) / (x_45scale * x_45scale))
if (x_45scale <= (-1.8d+181)) then
tmp = (-4.0d0) * ((((a / x_45scale) ** 2.0d0) * t_0) / y_45scale)
else if (x_45scale <= (-1.14d-160)) then
tmp = t_3
else if (x_45scale <= 6d-160) then
tmp = (-4.0d0) * (t_1 * (t_0 / y_45scale))
else if (x_45scale <= 1.05d+122) then
tmp = t_3
else
tmp = (-4.0d0) * (t_1 * ((b / y_45scale) * (b / y_45scale)))
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 = b * (b / y_45_scale);
double t_1 = (a / x_45_scale) * (a / x_45_scale);
double t_2 = a / (y_45_scale / b);
double t_3 = -4.0 * ((t_2 * t_2) / (x_45_scale * x_45_scale));
double tmp;
if (x_45_scale <= -1.8e+181) {
tmp = -4.0 * ((Math.pow((a / x_45_scale), 2.0) * t_0) / y_45_scale);
} else if (x_45_scale <= -1.14e-160) {
tmp = t_3;
} else if (x_45_scale <= 6e-160) {
tmp = -4.0 * (t_1 * (t_0 / y_45_scale));
} else if (x_45_scale <= 1.05e+122) {
tmp = t_3;
} else {
tmp = -4.0 * (t_1 * ((b / y_45_scale) * (b / y_45_scale)));
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = b * (b / y_45_scale) t_1 = (a / x_45_scale) * (a / x_45_scale) t_2 = a / (y_45_scale / b) t_3 = -4.0 * ((t_2 * t_2) / (x_45_scale * x_45_scale)) tmp = 0 if x_45_scale <= -1.8e+181: tmp = -4.0 * ((math.pow((a / x_45_scale), 2.0) * t_0) / y_45_scale) elif x_45_scale <= -1.14e-160: tmp = t_3 elif x_45_scale <= 6e-160: tmp = -4.0 * (t_1 * (t_0 / y_45_scale)) elif x_45_scale <= 1.05e+122: tmp = t_3 else: tmp = -4.0 * (t_1 * ((b / y_45_scale) * (b / y_45_scale))) return tmp
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(b * Float64(b / y_45_scale)) t_1 = Float64(Float64(a / x_45_scale) * Float64(a / x_45_scale)) t_2 = Float64(a / Float64(y_45_scale / b)) t_3 = Float64(-4.0 * Float64(Float64(t_2 * t_2) / Float64(x_45_scale * x_45_scale))) tmp = 0.0 if (x_45_scale <= -1.8e+181) tmp = Float64(-4.0 * Float64(Float64((Float64(a / x_45_scale) ^ 2.0) * t_0) / y_45_scale)); elseif (x_45_scale <= -1.14e-160) tmp = t_3; elseif (x_45_scale <= 6e-160) tmp = Float64(-4.0 * Float64(t_1 * Float64(t_0 / y_45_scale))); elseif (x_45_scale <= 1.05e+122) tmp = t_3; else tmp = Float64(-4.0 * Float64(t_1 * Float64(Float64(b / y_45_scale) * Float64(b / y_45_scale)))); end return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = b * (b / y_45_scale); t_1 = (a / x_45_scale) * (a / x_45_scale); t_2 = a / (y_45_scale / b); t_3 = -4.0 * ((t_2 * t_2) / (x_45_scale * x_45_scale)); tmp = 0.0; if (x_45_scale <= -1.8e+181) tmp = -4.0 * ((((a / x_45_scale) ^ 2.0) * t_0) / y_45_scale); elseif (x_45_scale <= -1.14e-160) tmp = t_3; elseif (x_45_scale <= 6e-160) tmp = -4.0 * (t_1 * (t_0 / y_45_scale)); elseif (x_45_scale <= 1.05e+122) tmp = t_3; else tmp = -4.0 * (t_1 * ((b / y_45_scale) * (b / y_45_scale))); end tmp_2 = tmp; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(b * N[(b / y$45$scale), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / x$45$scale), $MachinePrecision] * N[(a / x$45$scale), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(a / N[(y$45$scale / b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(-4.0 * N[(N[(t$95$2 * t$95$2), $MachinePrecision] / N[(x$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$45$scale, -1.8e+181], N[(-4.0 * N[(N[(N[Power[N[(a / x$45$scale), $MachinePrecision], 2.0], $MachinePrecision] * t$95$0), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$45$scale, -1.14e-160], t$95$3, If[LessEqual[x$45$scale, 6e-160], N[(-4.0 * N[(t$95$1 * N[(t$95$0 / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$45$scale, 1.05e+122], t$95$3, N[(-4.0 * N[(t$95$1 * N[(N[(b / y$45$scale), $MachinePrecision] * N[(b / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \frac{b}{y-scale}\\
t_1 := \frac{a}{x-scale} \cdot \frac{a}{x-scale}\\
t_2 := \frac{a}{\frac{y-scale}{b}}\\
t_3 := -4 \cdot \frac{t_2 \cdot t_2}{x-scale \cdot x-scale}\\
\mathbf{if}\;x-scale \leq -1.8 \cdot 10^{+181}:\\
\;\;\;\;-4 \cdot \frac{{\left(\frac{a}{x-scale}\right)}^{2} \cdot t_0}{y-scale}\\
\mathbf{elif}\;x-scale \leq -1.14 \cdot 10^{-160}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;x-scale \leq 6 \cdot 10^{-160}:\\
\;\;\;\;-4 \cdot \left(t_1 \cdot \frac{t_0}{y-scale}\right)\\
\mathbf{elif}\;x-scale \leq 1.05 \cdot 10^{+122}:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t_1 \cdot \left(\frac{b}{y-scale} \cdot \frac{b}{y-scale}\right)\right)\\
\end{array}
\end{array}
if x-scale < -1.79999999999999992e181Initial program 34.8%
Taylor expanded in angle around 0 34.6%
*-commutative34.6%
times-frac30.9%
unpow230.9%
unpow230.9%
unpow230.9%
unpow230.9%
Simplified30.9%
pow130.9%
times-frac55.3%
times-frac62.8%
Applied egg-rr62.8%
associate-*r/62.8%
Applied egg-rr62.8%
associate-*r/76.7%
pow276.7%
*-commutative76.7%
Applied egg-rr76.7%
if -1.79999999999999992e181 < x-scale < -1.14000000000000004e-160 or 5.99999999999999993e-160 < x-scale < 1.05000000000000008e122Initial program 23.0%
Taylor expanded in angle around 0 54.1%
*-commutative54.1%
times-frac53.4%
unpow253.4%
unpow253.4%
unpow253.4%
unpow253.4%
Simplified53.4%
associate-*l/54.7%
times-frac72.4%
Applied egg-rr72.4%
Taylor expanded in a around 0 55.5%
unpow255.5%
unpow255.5%
unpow255.5%
associate-/l*54.7%
times-frac72.4%
Simplified72.4%
times-frac90.2%
Applied egg-rr90.2%
if -1.14000000000000004e-160 < x-scale < 5.99999999999999993e-160Initial program 13.7%
Taylor expanded in angle around 0 40.5%
*-commutative40.5%
times-frac40.6%
unpow240.6%
unpow240.6%
unpow240.6%
unpow240.6%
Simplified40.6%
*-un-lft-identity40.6%
times-frac62.8%
Applied egg-rr62.8%
*-lft-identity62.8%
Simplified62.8%
*-un-lft-identity62.8%
times-frac83.3%
Applied egg-rr83.3%
*-lft-identity83.3%
Simplified83.3%
associate-*r/83.3%
Applied egg-rr83.3%
if 1.05000000000000008e122 < x-scale Initial program 34.2%
Taylor expanded in angle around 0 44.6%
*-commutative44.6%
times-frac44.6%
unpow244.6%
unpow244.6%
unpow244.6%
unpow244.6%
Simplified44.6%
*-un-lft-identity44.6%
times-frac61.5%
Applied egg-rr61.5%
*-lft-identity61.5%
Simplified61.5%
*-un-lft-identity61.5%
times-frac86.2%
Applied egg-rr86.2%
*-lft-identity86.2%
Simplified86.2%
Final simplification86.7%
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (/ a (/ y-scale b))))
(if (<= a 4.4e-117)
(* -4.0 (/ (* t_0 t_0) (* x-scale x-scale)))
(if (<= a 1e+116)
(* -4.0 (* (/ (* a a) x-scale) (/ (pow (/ b y-scale) 2.0) x-scale)))
(*
-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) {
double t_0 = a / (y_45_scale / b);
double tmp;
if (a <= 4.4e-117) {
tmp = -4.0 * ((t_0 * t_0) / (x_45_scale * x_45_scale));
} else if (a <= 1e+116) {
tmp = -4.0 * (((a * a) / x_45_scale) * (pow((b / y_45_scale), 2.0) / x_45_scale));
} else {
tmp = -4.0 * (((a / x_45_scale) * (a / x_45_scale)) * ((b / y_45_scale) * (b / y_45_scale)));
}
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 / (y_45scale / b)
if (a <= 4.4d-117) then
tmp = (-4.0d0) * ((t_0 * t_0) / (x_45scale * x_45scale))
else if (a <= 1d+116) then
tmp = (-4.0d0) * (((a * a) / x_45scale) * (((b / y_45scale) ** 2.0d0) / x_45scale))
else
tmp = (-4.0d0) * (((a / x_45scale) * (a / x_45scale)) * ((b / y_45scale) * (b / y_45scale)))
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 / (y_45_scale / b);
double tmp;
if (a <= 4.4e-117) {
tmp = -4.0 * ((t_0 * t_0) / (x_45_scale * x_45_scale));
} else if (a <= 1e+116) {
tmp = -4.0 * (((a * a) / x_45_scale) * (Math.pow((b / y_45_scale), 2.0) / x_45_scale));
} else {
tmp = -4.0 * (((a / x_45_scale) * (a / x_45_scale)) * ((b / y_45_scale) * (b / y_45_scale)));
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = a / (y_45_scale / b) tmp = 0 if a <= 4.4e-117: tmp = -4.0 * ((t_0 * t_0) / (x_45_scale * x_45_scale)) elif a <= 1e+116: tmp = -4.0 * (((a * a) / x_45_scale) * (math.pow((b / y_45_scale), 2.0) / x_45_scale)) else: tmp = -4.0 * (((a / x_45_scale) * (a / x_45_scale)) * ((b / y_45_scale) * (b / y_45_scale))) return tmp
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(a / Float64(y_45_scale / b)) tmp = 0.0 if (a <= 4.4e-117) tmp = Float64(-4.0 * Float64(Float64(t_0 * t_0) / Float64(x_45_scale * x_45_scale))); elseif (a <= 1e+116) tmp = Float64(-4.0 * Float64(Float64(Float64(a * a) / x_45_scale) * Float64((Float64(b / y_45_scale) ^ 2.0) / x_45_scale))); else tmp = 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 return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = a / (y_45_scale / b); tmp = 0.0; if (a <= 4.4e-117) tmp = -4.0 * ((t_0 * t_0) / (x_45_scale * x_45_scale)); elseif (a <= 1e+116) tmp = -4.0 * (((a * a) / x_45_scale) * (((b / y_45_scale) ^ 2.0) / x_45_scale)); else tmp = -4.0 * (((a / x_45_scale) * (a / x_45_scale)) * ((b / y_45_scale) * (b / y_45_scale))); end tmp_2 = tmp; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(a / N[(y$45$scale / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, 4.4e-117], N[(-4.0 * N[(N[(t$95$0 * t$95$0), $MachinePrecision] / N[(x$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1e+116], N[(-4.0 * N[(N[(N[(a * a), $MachinePrecision] / x$45$scale), $MachinePrecision] * N[(N[Power[N[(b / y$45$scale), $MachinePrecision], 2.0], $MachinePrecision] / x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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}
\\
\begin{array}{l}
t_0 := \frac{a}{\frac{y-scale}{b}}\\
\mathbf{if}\;a \leq 4.4 \cdot 10^{-117}:\\
\;\;\;\;-4 \cdot \frac{t_0 \cdot t_0}{x-scale \cdot x-scale}\\
\mathbf{elif}\;a \leq 10^{+116}:\\
\;\;\;\;-4 \cdot \left(\frac{a \cdot a}{x-scale} \cdot \frac{{\left(\frac{b}{y-scale}\right)}^{2}}{x-scale}\right)\\
\mathbf{else}:\\
\;\;\;\;-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}
\end{array}
if a < 4.4000000000000002e-117Initial program 23.8%
Taylor expanded in angle around 0 45.4%
*-commutative45.4%
times-frac45.8%
unpow245.8%
unpow245.8%
unpow245.8%
unpow245.8%
Simplified45.8%
associate-*l/44.7%
times-frac58.5%
Applied egg-rr58.5%
Taylor expanded in a around 0 46.0%
unpow246.0%
unpow246.0%
unpow246.0%
associate-/l*44.6%
times-frac58.4%
Simplified58.4%
times-frac77.3%
Applied egg-rr77.3%
if 4.4000000000000002e-117 < a < 1.00000000000000002e116Initial program 37.0%
Taylor expanded in angle around 0 55.3%
*-commutative55.3%
times-frac50.9%
unpow250.9%
unpow250.9%
unpow250.9%
unpow250.9%
Simplified50.9%
associate-*l/55.4%
times-frac71.4%
Applied egg-rr71.4%
times-frac87.9%
pow287.9%
Applied egg-rr87.9%
if 1.00000000000000002e116 < a Initial program 4.8%
Taylor expanded in angle around 0 45.7%
*-commutative45.7%
times-frac45.7%
unpow245.7%
unpow245.7%
unpow245.7%
unpow245.7%
Simplified45.7%
*-un-lft-identity45.7%
times-frac60.5%
Applied egg-rr60.5%
*-lft-identity60.5%
Simplified60.5%
*-un-lft-identity60.5%
times-frac79.4%
Applied egg-rr79.4%
*-lft-identity79.4%
Simplified79.4%
Final simplification80.0%
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ a x-scale) (/ a x-scale)))
(t_1 (* -4.0 (* t_0 (* (/ b y-scale) (/ b y-scale)))))
(t_2 (/ a (/ y-scale b)))
(t_3 (* -4.0 (/ (* t_2 t_2) (* x-scale x-scale)))))
(if (<= x-scale -1.6e+206)
t_1
(if (<= x-scale -3.7e-161)
t_3
(if (<= x-scale 5.2e-161)
(* -4.0 (* t_0 (/ (* b (/ b y-scale)) y-scale)))
(if (<= x-scale 9e+116) t_3 t_1))))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (a / x_45_scale) * (a / x_45_scale);
double t_1 = -4.0 * (t_0 * ((b / y_45_scale) * (b / y_45_scale)));
double t_2 = a / (y_45_scale / b);
double t_3 = -4.0 * ((t_2 * t_2) / (x_45_scale * x_45_scale));
double tmp;
if (x_45_scale <= -1.6e+206) {
tmp = t_1;
} else if (x_45_scale <= -3.7e-161) {
tmp = t_3;
} else if (x_45_scale <= 5.2e-161) {
tmp = -4.0 * (t_0 * ((b * (b / y_45_scale)) / y_45_scale));
} else if (x_45_scale <= 9e+116) {
tmp = t_3;
} else {
tmp = t_1;
}
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) :: t_2
real(8) :: t_3
real(8) :: tmp
t_0 = (a / x_45scale) * (a / x_45scale)
t_1 = (-4.0d0) * (t_0 * ((b / y_45scale) * (b / y_45scale)))
t_2 = a / (y_45scale / b)
t_3 = (-4.0d0) * ((t_2 * t_2) / (x_45scale * x_45scale))
if (x_45scale <= (-1.6d+206)) then
tmp = t_1
else if (x_45scale <= (-3.7d-161)) then
tmp = t_3
else if (x_45scale <= 5.2d-161) then
tmp = (-4.0d0) * (t_0 * ((b * (b / y_45scale)) / y_45scale))
else if (x_45scale <= 9d+116) then
tmp = t_3
else
tmp = t_1
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) * (a / x_45_scale);
double t_1 = -4.0 * (t_0 * ((b / y_45_scale) * (b / y_45_scale)));
double t_2 = a / (y_45_scale / b);
double t_3 = -4.0 * ((t_2 * t_2) / (x_45_scale * x_45_scale));
double tmp;
if (x_45_scale <= -1.6e+206) {
tmp = t_1;
} else if (x_45_scale <= -3.7e-161) {
tmp = t_3;
} else if (x_45_scale <= 5.2e-161) {
tmp = -4.0 * (t_0 * ((b * (b / y_45_scale)) / y_45_scale));
} else if (x_45_scale <= 9e+116) {
tmp = t_3;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (a / x_45_scale) * (a / x_45_scale) t_1 = -4.0 * (t_0 * ((b / y_45_scale) * (b / y_45_scale))) t_2 = a / (y_45_scale / b) t_3 = -4.0 * ((t_2 * t_2) / (x_45_scale * x_45_scale)) tmp = 0 if x_45_scale <= -1.6e+206: tmp = t_1 elif x_45_scale <= -3.7e-161: tmp = t_3 elif x_45_scale <= 5.2e-161: tmp = -4.0 * (t_0 * ((b * (b / y_45_scale)) / y_45_scale)) elif x_45_scale <= 9e+116: tmp = t_3 else: tmp = t_1 return tmp
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(a / x_45_scale) * Float64(a / x_45_scale)) t_1 = Float64(-4.0 * Float64(t_0 * Float64(Float64(b / y_45_scale) * Float64(b / y_45_scale)))) t_2 = Float64(a / Float64(y_45_scale / b)) t_3 = Float64(-4.0 * Float64(Float64(t_2 * t_2) / Float64(x_45_scale * x_45_scale))) tmp = 0.0 if (x_45_scale <= -1.6e+206) tmp = t_1; elseif (x_45_scale <= -3.7e-161) tmp = t_3; elseif (x_45_scale <= 5.2e-161) tmp = Float64(-4.0 * Float64(t_0 * Float64(Float64(b * Float64(b / y_45_scale)) / y_45_scale))); elseif (x_45_scale <= 9e+116) tmp = t_3; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (a / x_45_scale) * (a / x_45_scale); t_1 = -4.0 * (t_0 * ((b / y_45_scale) * (b / y_45_scale))); t_2 = a / (y_45_scale / b); t_3 = -4.0 * ((t_2 * t_2) / (x_45_scale * x_45_scale)); tmp = 0.0; if (x_45_scale <= -1.6e+206) tmp = t_1; elseif (x_45_scale <= -3.7e-161) tmp = t_3; elseif (x_45_scale <= 5.2e-161) tmp = -4.0 * (t_0 * ((b * (b / y_45_scale)) / y_45_scale)); elseif (x_45_scale <= 9e+116) tmp = t_3; else tmp = t_1; 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[(a / x$45$scale), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-4.0 * N[(t$95$0 * N[(N[(b / y$45$scale), $MachinePrecision] * N[(b / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(a / N[(y$45$scale / b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(-4.0 * N[(N[(t$95$2 * t$95$2), $MachinePrecision] / N[(x$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$45$scale, -1.6e+206], t$95$1, If[LessEqual[x$45$scale, -3.7e-161], t$95$3, If[LessEqual[x$45$scale, 5.2e-161], N[(-4.0 * N[(t$95$0 * N[(N[(b * N[(b / y$45$scale), $MachinePrecision]), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$45$scale, 9e+116], t$95$3, t$95$1]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a}{x-scale} \cdot \frac{a}{x-scale}\\
t_1 := -4 \cdot \left(t_0 \cdot \left(\frac{b}{y-scale} \cdot \frac{b}{y-scale}\right)\right)\\
t_2 := \frac{a}{\frac{y-scale}{b}}\\
t_3 := -4 \cdot \frac{t_2 \cdot t_2}{x-scale \cdot x-scale}\\
\mathbf{if}\;x-scale \leq -1.6 \cdot 10^{+206}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;x-scale \leq -3.7 \cdot 10^{-161}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;x-scale \leq 5.2 \cdot 10^{-161}:\\
\;\;\;\;-4 \cdot \left(t_0 \cdot \frac{b \cdot \frac{b}{y-scale}}{y-scale}\right)\\
\mathbf{elif}\;x-scale \leq 9 \cdot 10^{+116}:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if x-scale < -1.60000000000000003e206 or 9.00000000000000032e116 < x-scale Initial program 35.7%
Taylor expanded in angle around 0 42.2%
*-commutative42.2%
times-frac40.5%
unpow240.5%
unpow240.5%
unpow240.5%
unpow240.5%
Simplified40.5%
*-un-lft-identity40.5%
times-frac61.8%
Applied egg-rr61.8%
*-lft-identity61.8%
Simplified61.8%
*-un-lft-identity61.8%
times-frac80.9%
Applied egg-rr80.9%
*-lft-identity80.9%
Simplified80.9%
if -1.60000000000000003e206 < x-scale < -3.6999999999999998e-161 or 5.19999999999999991e-161 < x-scale < 9.00000000000000032e116Initial program 22.9%
Taylor expanded in angle around 0 52.9%
*-commutative52.9%
times-frac52.2%
unpow252.2%
unpow252.2%
unpow252.2%
unpow252.2%
Simplified52.2%
associate-*l/53.5%
times-frac70.5%
Applied egg-rr70.5%
Taylor expanded in a around 0 54.3%
unpow254.3%
unpow254.3%
unpow254.3%
associate-/l*53.4%
times-frac70.5%
Simplified70.5%
times-frac88.6%
Applied egg-rr88.6%
if -3.6999999999999998e-161 < x-scale < 5.19999999999999991e-161Initial program 13.7%
Taylor expanded in angle around 0 40.5%
*-commutative40.5%
times-frac40.6%
unpow240.6%
unpow240.6%
unpow240.6%
unpow240.6%
Simplified40.6%
*-un-lft-identity40.6%
times-frac62.8%
Applied egg-rr62.8%
*-lft-identity62.8%
Simplified62.8%
*-un-lft-identity62.8%
times-frac83.3%
Applied egg-rr83.3%
*-lft-identity83.3%
Simplified83.3%
associate-*r/83.3%
Applied egg-rr83.3%
Final simplification85.7%
(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 23.6%
Taylor expanded in angle around 0 47.6%
*-commutative47.6%
times-frac46.9%
unpow246.9%
unpow246.9%
unpow246.9%
unpow246.9%
Simplified46.9%
*-un-lft-identity46.9%
times-frac58.9%
Applied egg-rr58.9%
*-lft-identity58.9%
Simplified58.9%
*-un-lft-identity58.9%
times-frac76.9%
Applied egg-rr76.9%
*-lft-identity76.9%
Simplified76.9%
Final simplification76.9%
(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 23.6%
fma-neg24.9%
Simplified19.0%
Taylor expanded in b around 0 22.4%
*-commutative22.4%
*-commutative22.4%
*-commutative22.4%
distribute-lft-out22.4%
Simplified34.7%
Final simplification34.7%
herbie shell --seed 2023257
(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))))