
(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 7 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 (* (/ -4.0 x-scale) (/ b x-scale)))
(t_1 (sqrt (/ (pow (* b a) 2.0) (pow (* x-scale y-scale) 2.0)))))
(if (<= x-scale -1.6e-86)
(* t_0 (/ (* a (/ b y-scale)) (/ y-scale a)))
(if (<= x-scale 5.8e-157)
(* -4.0 (* t_1 t_1))
(* t_0 (/ (* a (/ (* b a) y-scale)) y-scale))))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (-4.0 / x_45_scale) * (b / x_45_scale);
double t_1 = sqrt((pow((b * a), 2.0) / pow((x_45_scale * y_45_scale), 2.0)));
double tmp;
if (x_45_scale <= -1.6e-86) {
tmp = t_0 * ((a * (b / y_45_scale)) / (y_45_scale / a));
} else if (x_45_scale <= 5.8e-157) {
tmp = -4.0 * (t_1 * t_1);
} else {
tmp = t_0 * ((a * ((b * a) / y_45_scale)) / 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) :: tmp
t_0 = ((-4.0d0) / x_45scale) * (b / x_45scale)
t_1 = sqrt((((b * a) ** 2.0d0) / ((x_45scale * y_45scale) ** 2.0d0)))
if (x_45scale <= (-1.6d-86)) then
tmp = t_0 * ((a * (b / y_45scale)) / (y_45scale / a))
else if (x_45scale <= 5.8d-157) then
tmp = (-4.0d0) * (t_1 * t_1)
else
tmp = t_0 * ((a * ((b * a) / y_45scale)) / 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 = (-4.0 / x_45_scale) * (b / x_45_scale);
double t_1 = Math.sqrt((Math.pow((b * a), 2.0) / Math.pow((x_45_scale * y_45_scale), 2.0)));
double tmp;
if (x_45_scale <= -1.6e-86) {
tmp = t_0 * ((a * (b / y_45_scale)) / (y_45_scale / a));
} else if (x_45_scale <= 5.8e-157) {
tmp = -4.0 * (t_1 * t_1);
} else {
tmp = t_0 * ((a * ((b * a) / y_45_scale)) / y_45_scale);
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (-4.0 / x_45_scale) * (b / x_45_scale) t_1 = math.sqrt((math.pow((b * a), 2.0) / math.pow((x_45_scale * y_45_scale), 2.0))) tmp = 0 if x_45_scale <= -1.6e-86: tmp = t_0 * ((a * (b / y_45_scale)) / (y_45_scale / a)) elif x_45_scale <= 5.8e-157: tmp = -4.0 * (t_1 * t_1) else: tmp = t_0 * ((a * ((b * a) / y_45_scale)) / y_45_scale) return tmp
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(-4.0 / x_45_scale) * Float64(b / x_45_scale)) t_1 = sqrt(Float64((Float64(b * a) ^ 2.0) / (Float64(x_45_scale * y_45_scale) ^ 2.0))) tmp = 0.0 if (x_45_scale <= -1.6e-86) tmp = Float64(t_0 * Float64(Float64(a * Float64(b / y_45_scale)) / Float64(y_45_scale / a))); elseif (x_45_scale <= 5.8e-157) tmp = Float64(-4.0 * Float64(t_1 * t_1)); else tmp = Float64(t_0 * Float64(Float64(a * Float64(Float64(b * a) / y_45_scale)) / y_45_scale)); end return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (-4.0 / x_45_scale) * (b / x_45_scale); t_1 = sqrt((((b * a) ^ 2.0) / ((x_45_scale * y_45_scale) ^ 2.0))); tmp = 0.0; if (x_45_scale <= -1.6e-86) tmp = t_0 * ((a * (b / y_45_scale)) / (y_45_scale / a)); elseif (x_45_scale <= 5.8e-157) tmp = -4.0 * (t_1 * t_1); else tmp = t_0 * ((a * ((b * a) / y_45_scale)) / y_45_scale); end tmp_2 = tmp; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(-4.0 / x$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[Power[N[(b * a), $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[(x$45$scale * y$45$scale), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x$45$scale, -1.6e-86], N[(t$95$0 * N[(N[(a * N[(b / y$45$scale), $MachinePrecision]), $MachinePrecision] / N[(y$45$scale / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$45$scale, 5.8e-157], N[(-4.0 * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(N[(a * N[(N[(b * a), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-4}{x-scale} \cdot \frac{b}{x-scale}\\
t_1 := \sqrt{\frac{{\left(b \cdot a\right)}^{2}}{{\left(x-scale \cdot y-scale\right)}^{2}}}\\
\mathbf{if}\;x-scale \leq -1.6 \cdot 10^{-86}:\\
\;\;\;\;t_0 \cdot \frac{a \cdot \frac{b}{y-scale}}{\frac{y-scale}{a}}\\
\mathbf{elif}\;x-scale \leq 5.8 \cdot 10^{-157}:\\
\;\;\;\;-4 \cdot \left(t_1 \cdot t_1\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{a \cdot \frac{b \cdot a}{y-scale}}{y-scale}\\
\end{array}
\end{array}
if x-scale < -1.60000000000000003e-86Initial program 38.5%
Simplified34.2%
Taylor expanded in angle around 0 51.8%
associate-/l*53.8%
associate-*r/53.8%
unpow253.8%
unpow253.8%
times-frac55.1%
unpow255.1%
unpow255.1%
Simplified55.1%
times-frac56.2%
associate-/l*58.3%
associate-/l*65.6%
Applied egg-rr65.6%
unpow265.6%
associate-/r/65.6%
associate-/r/72.8%
unpow272.8%
Simplified72.8%
Taylor expanded in a around 0 72.8%
unpow272.8%
associate-*l/81.1%
*-commutative81.1%
Simplified81.1%
*-commutative81.1%
associate-/r/81.1%
associate-*l/84.5%
Applied egg-rr84.5%
if -1.60000000000000003e-86 < x-scale < 5.79999999999999977e-157Initial program 17.8%
Simplified7.1%
Taylor expanded in angle around 0 47.7%
associate-/l*47.7%
associate-*r/47.7%
unpow247.7%
unpow247.7%
times-frac51.4%
unpow251.4%
unpow251.4%
Simplified51.4%
Taylor expanded in a around 0 47.7%
unpow247.7%
unpow247.7%
swap-sqr54.5%
unpow254.5%
unpow254.5%
unpow254.5%
swap-sqr91.6%
unpow291.6%
Simplified91.6%
add-sqr-sqrt91.6%
Applied egg-rr91.6%
if 5.79999999999999977e-157 < x-scale Initial program 32.4%
Simplified31.4%
Taylor expanded in angle around 0 57.0%
associate-/l*57.3%
associate-*r/57.3%
unpow257.3%
unpow257.3%
times-frac61.7%
unpow261.7%
unpow261.7%
Simplified61.7%
times-frac61.7%
associate-/l*65.8%
associate-/l*68.8%
Applied egg-rr68.8%
unpow268.8%
associate-/r/68.8%
associate-/r/72.0%
unpow272.0%
Simplified72.0%
associate-*r/72.1%
associate-/l*81.8%
Applied egg-rr81.8%
Taylor expanded in a around 0 70.6%
*-commutative70.6%
associate-/l*73.0%
associate-/r/73.8%
unpow273.8%
associate-*l*82.2%
*-commutative82.2%
*-commutative82.2%
associate-*r/86.0%
Simplified86.0%
Final simplification86.8%
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ -4.0 x-scale) (/ b x-scale))))
(if (<= x-scale -1.32e-86)
(* t_0 (/ (* a (/ b y-scale)) (/ y-scale a)))
(if (<= x-scale 2.25e-157)
(*
-4.0
(/ (pow (* b a) 2.0) (* (* x-scale y-scale) (* x-scale y-scale))))
(* t_0 (/ (* a (/ (* b a) y-scale)) y-scale))))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (-4.0 / x_45_scale) * (b / x_45_scale);
double tmp;
if (x_45_scale <= -1.32e-86) {
tmp = t_0 * ((a * (b / y_45_scale)) / (y_45_scale / a));
} else if (x_45_scale <= 2.25e-157) {
tmp = -4.0 * (pow((b * a), 2.0) / ((x_45_scale * y_45_scale) * (x_45_scale * y_45_scale)));
} else {
tmp = t_0 * ((a * ((b * a) / y_45_scale)) / 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 = ((-4.0d0) / x_45scale) * (b / x_45scale)
if (x_45scale <= (-1.32d-86)) then
tmp = t_0 * ((a * (b / y_45scale)) / (y_45scale / a))
else if (x_45scale <= 2.25d-157) then
tmp = (-4.0d0) * (((b * a) ** 2.0d0) / ((x_45scale * y_45scale) * (x_45scale * y_45scale)))
else
tmp = t_0 * ((a * ((b * a) / y_45scale)) / 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 = (-4.0 / x_45_scale) * (b / x_45_scale);
double tmp;
if (x_45_scale <= -1.32e-86) {
tmp = t_0 * ((a * (b / y_45_scale)) / (y_45_scale / a));
} else if (x_45_scale <= 2.25e-157) {
tmp = -4.0 * (Math.pow((b * a), 2.0) / ((x_45_scale * y_45_scale) * (x_45_scale * y_45_scale)));
} else {
tmp = t_0 * ((a * ((b * a) / y_45_scale)) / y_45_scale);
}
return tmp;
}
def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (-4.0 / x_45_scale) * (b / x_45_scale) tmp = 0 if x_45_scale <= -1.32e-86: tmp = t_0 * ((a * (b / y_45_scale)) / (y_45_scale / a)) elif x_45_scale <= 2.25e-157: tmp = -4.0 * (math.pow((b * a), 2.0) / ((x_45_scale * y_45_scale) * (x_45_scale * y_45_scale))) else: tmp = t_0 * ((a * ((b * a) / y_45_scale)) / y_45_scale) return tmp
function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(-4.0 / x_45_scale) * Float64(b / x_45_scale)) tmp = 0.0 if (x_45_scale <= -1.32e-86) tmp = Float64(t_0 * Float64(Float64(a * Float64(b / y_45_scale)) / Float64(y_45_scale / a))); elseif (x_45_scale <= 2.25e-157) tmp = Float64(-4.0 * Float64((Float64(b * a) ^ 2.0) / Float64(Float64(x_45_scale * y_45_scale) * Float64(x_45_scale * y_45_scale)))); else tmp = Float64(t_0 * Float64(Float64(a * Float64(Float64(b * a) / y_45_scale)) / y_45_scale)); end return tmp end
function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (-4.0 / x_45_scale) * (b / x_45_scale); tmp = 0.0; if (x_45_scale <= -1.32e-86) tmp = t_0 * ((a * (b / y_45_scale)) / (y_45_scale / a)); elseif (x_45_scale <= 2.25e-157) tmp = -4.0 * (((b * a) ^ 2.0) / ((x_45_scale * y_45_scale) * (x_45_scale * y_45_scale))); else tmp = t_0 * ((a * ((b * a) / y_45_scale)) / y_45_scale); end tmp_2 = tmp; end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(-4.0 / x$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$45$scale, -1.32e-86], N[(t$95$0 * N[(N[(a * N[(b / y$45$scale), $MachinePrecision]), $MachinePrecision] / N[(y$45$scale / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$45$scale, 2.25e-157], N[(-4.0 * N[(N[Power[N[(b * a), $MachinePrecision], 2.0], $MachinePrecision] / N[(N[(x$45$scale * y$45$scale), $MachinePrecision] * N[(x$45$scale * y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(N[(a * N[(N[(b * a), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-4}{x-scale} \cdot \frac{b}{x-scale}\\
\mathbf{if}\;x-scale \leq -1.32 \cdot 10^{-86}:\\
\;\;\;\;t_0 \cdot \frac{a \cdot \frac{b}{y-scale}}{\frac{y-scale}{a}}\\
\mathbf{elif}\;x-scale \leq 2.25 \cdot 10^{-157}:\\
\;\;\;\;-4 \cdot \frac{{\left(b \cdot a\right)}^{2}}{\left(x-scale \cdot y-scale\right) \cdot \left(x-scale \cdot y-scale\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{a \cdot \frac{b \cdot a}{y-scale}}{y-scale}\\
\end{array}
\end{array}
if x-scale < -1.32e-86Initial program 38.5%
Simplified34.2%
Taylor expanded in angle around 0 51.8%
associate-/l*53.8%
associate-*r/53.8%
unpow253.8%
unpow253.8%
times-frac55.1%
unpow255.1%
unpow255.1%
Simplified55.1%
times-frac56.2%
associate-/l*58.3%
associate-/l*65.6%
Applied egg-rr65.6%
unpow265.6%
associate-/r/65.6%
associate-/r/72.8%
unpow272.8%
Simplified72.8%
Taylor expanded in a around 0 72.8%
unpow272.8%
associate-*l/81.1%
*-commutative81.1%
Simplified81.1%
*-commutative81.1%
associate-/r/81.1%
associate-*l/84.5%
Applied egg-rr84.5%
if -1.32e-86 < x-scale < 2.24999999999999999e-157Initial program 17.8%
Simplified7.1%
Taylor expanded in angle around 0 47.7%
associate-/l*47.7%
associate-*r/47.7%
unpow247.7%
unpow247.7%
times-frac51.4%
unpow251.4%
unpow251.4%
Simplified51.4%
Taylor expanded in a around 0 47.7%
unpow247.7%
unpow247.7%
swap-sqr54.5%
unpow254.5%
unpow254.5%
unpow254.5%
swap-sqr91.6%
unpow291.6%
Simplified91.6%
unpow291.6%
Applied egg-rr91.6%
if 2.24999999999999999e-157 < x-scale Initial program 32.4%
Simplified31.4%
Taylor expanded in angle around 0 57.0%
associate-/l*57.3%
associate-*r/57.3%
unpow257.3%
unpow257.3%
times-frac61.7%
unpow261.7%
unpow261.7%
Simplified61.7%
times-frac61.7%
associate-/l*65.8%
associate-/l*68.8%
Applied egg-rr68.8%
unpow268.8%
associate-/r/68.8%
associate-/r/72.0%
unpow272.0%
Simplified72.0%
associate-*r/72.1%
associate-/l*81.8%
Applied egg-rr81.8%
Taylor expanded in a around 0 70.6%
*-commutative70.6%
associate-/l*73.0%
associate-/r/73.8%
unpow273.8%
associate-*l*82.2%
*-commutative82.2%
*-commutative82.2%
associate-*r/86.0%
Simplified86.0%
Final simplification86.8%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* (* (/ -4.0 x-scale) (/ b x-scale)) (* a (* (/ b y-scale) (/ a y-scale)))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((-4.0 / x_45_scale) * (b / x_45_scale)) * (a * ((b / y_45_scale) * (a / 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) / x_45scale) * (b / x_45scale)) * (a * ((b / y_45scale) * (a / 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 / x_45_scale) * (b / x_45_scale)) * (a * ((b / y_45_scale) * (a / y_45_scale)));
}
def code(a, b, angle, x_45_scale, y_45_scale): return ((-4.0 / x_45_scale) * (b / x_45_scale)) * (a * ((b / y_45_scale) * (a / y_45_scale)))
function code(a, b, angle, x_45_scale, y_45_scale) return Float64(Float64(Float64(-4.0 / x_45_scale) * Float64(b / x_45_scale)) * Float64(a * Float64(Float64(b / y_45_scale) * Float64(a / y_45_scale)))) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = ((-4.0 / x_45_scale) * (b / x_45_scale)) * (a * ((b / y_45_scale) * (a / y_45_scale))); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(N[(N[(-4.0 / x$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision] * N[(a * N[(N[(b / y$45$scale), $MachinePrecision] * N[(a / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{-4}{x-scale} \cdot \frac{b}{x-scale}\right) \cdot \left(a \cdot \left(\frac{b}{y-scale} \cdot \frac{a}{y-scale}\right)\right)
\end{array}
Initial program 31.2%
Simplified26.6%
Taylor expanded in angle around 0 52.9%
associate-/l*53.7%
associate-*r/53.7%
unpow253.7%
unpow253.7%
times-frac56.8%
unpow256.8%
unpow256.8%
Simplified56.8%
times-frac57.2%
associate-/l*61.7%
associate-/l*65.6%
Applied egg-rr65.6%
unpow265.6%
associate-/r/65.6%
associate-/r/70.7%
unpow270.7%
Simplified70.7%
associate-*r/71.3%
associate-/l*80.0%
Applied egg-rr80.0%
associate-/r/80.0%
*-commutative80.0%
associate-*r/77.9%
associate-*l*79.9%
Applied egg-rr79.9%
Final simplification79.9%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* (* (/ -4.0 x-scale) (/ b x-scale)) (/ (* a (/ b y-scale)) (/ y-scale a))))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((-4.0 / x_45_scale) * (b / x_45_scale)) * ((a * (b / y_45_scale)) / (y_45_scale / a));
}
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) / x_45scale) * (b / x_45scale)) * ((a * (b / y_45scale)) / (y_45scale / a))
end function
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((-4.0 / x_45_scale) * (b / x_45_scale)) * ((a * (b / y_45_scale)) / (y_45_scale / a));
}
def code(a, b, angle, x_45_scale, y_45_scale): return ((-4.0 / x_45_scale) * (b / x_45_scale)) * ((a * (b / y_45_scale)) / (y_45_scale / a))
function code(a, b, angle, x_45_scale, y_45_scale) return Float64(Float64(Float64(-4.0 / x_45_scale) * Float64(b / x_45_scale)) * Float64(Float64(a * Float64(b / y_45_scale)) / Float64(y_45_scale / a))) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = ((-4.0 / x_45_scale) * (b / x_45_scale)) * ((a * (b / y_45_scale)) / (y_45_scale / a)); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(N[(N[(-4.0 / x$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision] * N[(N[(a * N[(b / y$45$scale), $MachinePrecision]), $MachinePrecision] / N[(y$45$scale / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{-4}{x-scale} \cdot \frac{b}{x-scale}\right) \cdot \frac{a \cdot \frac{b}{y-scale}}{\frac{y-scale}{a}}
\end{array}
Initial program 31.2%
Simplified26.6%
Taylor expanded in angle around 0 52.9%
associate-/l*53.7%
associate-*r/53.7%
unpow253.7%
unpow253.7%
times-frac56.8%
unpow256.8%
unpow256.8%
Simplified56.8%
times-frac57.2%
associate-/l*61.7%
associate-/l*65.6%
Applied egg-rr65.6%
unpow265.6%
associate-/r/65.6%
associate-/r/70.7%
unpow270.7%
Simplified70.7%
Taylor expanded in a around 0 70.7%
unpow270.7%
associate-*l/77.9%
*-commutative77.9%
Simplified77.9%
*-commutative77.9%
associate-/r/77.9%
associate-*l/81.8%
Applied egg-rr81.8%
Final simplification81.8%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* (* (/ -4.0 x-scale) (/ b x-scale)) (/ (* a (/ (* b a) y-scale)) y-scale)))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((-4.0 / x_45_scale) * (b / x_45_scale)) * ((a * ((b * a) / y_45_scale)) / 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) / x_45scale) * (b / x_45scale)) * ((a * ((b * a) / y_45scale)) / 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 / x_45_scale) * (b / x_45_scale)) * ((a * ((b * a) / y_45_scale)) / y_45_scale);
}
def code(a, b, angle, x_45_scale, y_45_scale): return ((-4.0 / x_45_scale) * (b / x_45_scale)) * ((a * ((b * a) / y_45_scale)) / y_45_scale)
function code(a, b, angle, x_45_scale, y_45_scale) return Float64(Float64(Float64(-4.0 / x_45_scale) * Float64(b / x_45_scale)) * Float64(Float64(a * Float64(Float64(b * a) / y_45_scale)) / y_45_scale)) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = ((-4.0 / x_45_scale) * (b / x_45_scale)) * ((a * ((b * a) / y_45_scale)) / y_45_scale); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(N[(N[(-4.0 / x$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision] * N[(N[(a * N[(N[(b * a), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{-4}{x-scale} \cdot \frac{b}{x-scale}\right) \cdot \frac{a \cdot \frac{b \cdot a}{y-scale}}{y-scale}
\end{array}
Initial program 31.2%
Simplified26.6%
Taylor expanded in angle around 0 52.9%
associate-/l*53.7%
associate-*r/53.7%
unpow253.7%
unpow253.7%
times-frac56.8%
unpow256.8%
unpow256.8%
Simplified56.8%
times-frac57.2%
associate-/l*61.7%
associate-/l*65.6%
Applied egg-rr65.6%
unpow265.6%
associate-/r/65.6%
associate-/r/70.7%
unpow270.7%
Simplified70.7%
associate-*r/71.3%
associate-/l*80.0%
Applied egg-rr80.0%
Taylor expanded in a around 0 68.6%
*-commutative68.6%
associate-/l*71.3%
associate-/r/71.5%
unpow271.5%
associate-*l*78.8%
*-commutative78.8%
*-commutative78.8%
associate-*r/82.7%
Simplified82.7%
Final simplification82.7%
(FPCore (a b angle x-scale y-scale) :precision binary64 (* (* (/ -4.0 x-scale) (/ b x-scale)) (/ (/ (* b a) (/ y-scale a)) y-scale)))
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return ((-4.0 / x_45_scale) * (b / x_45_scale)) * (((b * a) / (y_45_scale / a)) / 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) / x_45scale) * (b / x_45scale)) * (((b * a) / (y_45scale / a)) / 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 / x_45_scale) * (b / x_45_scale)) * (((b * a) / (y_45_scale / a)) / y_45_scale);
}
def code(a, b, angle, x_45_scale, y_45_scale): return ((-4.0 / x_45_scale) * (b / x_45_scale)) * (((b * a) / (y_45_scale / a)) / y_45_scale)
function code(a, b, angle, x_45_scale, y_45_scale) return Float64(Float64(Float64(-4.0 / x_45_scale) * Float64(b / x_45_scale)) * Float64(Float64(Float64(b * a) / Float64(y_45_scale / a)) / y_45_scale)) end
function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = ((-4.0 / x_45_scale) * (b / x_45_scale)) * (((b * a) / (y_45_scale / a)) / y_45_scale); end
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(N[(N[(-4.0 / x$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(b * a), $MachinePrecision] / N[(y$45$scale / a), $MachinePrecision]), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{-4}{x-scale} \cdot \frac{b}{x-scale}\right) \cdot \frac{\frac{b \cdot a}{\frac{y-scale}{a}}}{y-scale}
\end{array}
Initial program 31.2%
Simplified26.6%
Taylor expanded in angle around 0 52.9%
associate-/l*53.7%
associate-*r/53.7%
unpow253.7%
unpow253.7%
times-frac56.8%
unpow256.8%
unpow256.8%
Simplified56.8%
times-frac57.2%
associate-/l*61.7%
associate-/l*65.6%
Applied egg-rr65.6%
unpow265.6%
associate-/r/65.6%
associate-/r/70.7%
unpow270.7%
Simplified70.7%
associate-*r/71.3%
associate-/l*80.0%
Applied egg-rr80.0%
associate-*l/82.8%
*-commutative82.8%
Applied egg-rr82.8%
Final simplification82.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 31.2%
Simplified27.8%
Taylor expanded in b around 0 27.6%
distribute-rgt-out27.6%
metadata-eval27.6%
mul0-rgt41.0%
Simplified41.0%
Final simplification41.0%
herbie shell --seed 2023293
(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))))