
(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}
NOTE: b should be positive before calling this function
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (/ (* b a) (* y-scale x-scale))))
(if (<= b 1.7e-5)
(* -4.0 (* t_0 t_0))
(* -4.0 (/ 1.0 (/ 1.0 (pow (* (/ a y-scale) (/ b x-scale)) 2.0)))))))b = abs(b);
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (b * a) / (y_45_scale * x_45_scale);
double tmp;
if (b <= 1.7e-5) {
tmp = -4.0 * (t_0 * t_0);
} else {
tmp = -4.0 * (1.0 / (1.0 / pow(((a / y_45_scale) * (b / x_45_scale)), 2.0)));
}
return tmp;
}
NOTE: b should be positive before calling this function
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 = (b * a) / (y_45scale * x_45scale)
if (b <= 1.7d-5) then
tmp = (-4.0d0) * (t_0 * t_0)
else
tmp = (-4.0d0) * (1.0d0 / (1.0d0 / (((a / y_45scale) * (b / x_45scale)) ** 2.0d0)))
end if
code = tmp
end function
b = Math.abs(b);
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (b * a) / (y_45_scale * x_45_scale);
double tmp;
if (b <= 1.7e-5) {
tmp = -4.0 * (t_0 * t_0);
} else {
tmp = -4.0 * (1.0 / (1.0 / Math.pow(((a / y_45_scale) * (b / x_45_scale)), 2.0)));
}
return tmp;
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (b * a) / (y_45_scale * x_45_scale) tmp = 0 if b <= 1.7e-5: tmp = -4.0 * (t_0 * t_0) else: tmp = -4.0 * (1.0 / (1.0 / math.pow(((a / y_45_scale) * (b / x_45_scale)), 2.0))) return tmp
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale)) tmp = 0.0 if (b <= 1.7e-5) tmp = Float64(-4.0 * Float64(t_0 * t_0)); else tmp = Float64(-4.0 * Float64(1.0 / Float64(1.0 / (Float64(Float64(a / y_45_scale) * Float64(b / x_45_scale)) ^ 2.0)))); end return tmp end
b = abs(b) function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (b * a) / (y_45_scale * x_45_scale); tmp = 0.0; if (b <= 1.7e-5) tmp = -4.0 * (t_0 * t_0); else tmp = -4.0 * (1.0 / (1.0 / (((a / y_45_scale) * (b / x_45_scale)) ^ 2.0))); end tmp_2 = tmp; end
NOTE: b should be positive before calling this function
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.7e-5], N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(1.0 / N[(1.0 / N[Power[N[(N[(a / y$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
b = |b|\\
\\
\begin{array}{l}
t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\
\mathbf{if}\;b \leq 1.7 \cdot 10^{-5}:\\
\;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \frac{1}{\frac{1}{{\left(\frac{a}{y-scale} \cdot \frac{b}{x-scale}\right)}^{2}}}\\
\end{array}
\end{array}
if b < 1.7e-5Initial program 33.9%
Simplified27.2%
Taylor expanded in angle around 0 51.4%
*-commutative51.4%
times-frac52.4%
Simplified52.4%
frac-times51.4%
*-commutative51.4%
clear-num51.4%
pow-prod-down64.2%
*-commutative64.2%
pow-prod-down79.6%
Applied egg-rr79.6%
pow-prod-down64.2%
clear-num64.2%
pow-prod-down79.6%
unpow279.6%
unpow279.6%
times-frac97.2%
Applied egg-rr97.2%
if 1.7e-5 < b Initial program 4.1%
Simplified2.3%
Taylor expanded in angle around 0 39.9%
*-commutative39.9%
times-frac41.8%
Simplified41.8%
frac-times39.9%
*-commutative39.9%
clear-num39.9%
pow-prod-down54.1%
*-commutative54.1%
pow-prod-down79.3%
Applied egg-rr79.3%
pow-prod-down54.1%
clear-num54.1%
inv-pow54.1%
add-sqr-sqrt54.0%
pow254.0%
sqrt-div54.1%
pow-prod-down79.2%
unpow279.2%
sqrt-prod46.3%
add-sqr-sqrt81.0%
sqrt-pow186.2%
metadata-eval86.2%
pow186.2%
Applied egg-rr86.2%
unpow-186.2%
times-frac91.1%
Simplified91.1%
Final simplification95.8%
NOTE: b should be positive before calling this function
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (/ (* b a) (* y-scale x-scale))))
(if (<= b 1e-5)
(* -4.0 (* t_0 t_0))
(* -4.0 (pow (* (/ a y-scale) (/ b x-scale)) 2.0)))))b = abs(b);
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (b * a) / (y_45_scale * x_45_scale);
double tmp;
if (b <= 1e-5) {
tmp = -4.0 * (t_0 * t_0);
} else {
tmp = -4.0 * pow(((a / y_45_scale) * (b / x_45_scale)), 2.0);
}
return tmp;
}
NOTE: b should be positive before calling this function
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 = (b * a) / (y_45scale * x_45scale)
if (b <= 1d-5) then
tmp = (-4.0d0) * (t_0 * t_0)
else
tmp = (-4.0d0) * (((a / y_45scale) * (b / x_45scale)) ** 2.0d0)
end if
code = tmp
end function
b = Math.abs(b);
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (b * a) / (y_45_scale * x_45_scale);
double tmp;
if (b <= 1e-5) {
tmp = -4.0 * (t_0 * t_0);
} else {
tmp = -4.0 * Math.pow(((a / y_45_scale) * (b / x_45_scale)), 2.0);
}
return tmp;
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (b * a) / (y_45_scale * x_45_scale) tmp = 0 if b <= 1e-5: tmp = -4.0 * (t_0 * t_0) else: tmp = -4.0 * math.pow(((a / y_45_scale) * (b / x_45_scale)), 2.0) return tmp
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale)) tmp = 0.0 if (b <= 1e-5) tmp = Float64(-4.0 * Float64(t_0 * t_0)); else tmp = Float64(-4.0 * (Float64(Float64(a / y_45_scale) * Float64(b / x_45_scale)) ^ 2.0)); end return tmp end
b = abs(b) function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (b * a) / (y_45_scale * x_45_scale); tmp = 0.0; if (b <= 1e-5) tmp = -4.0 * (t_0 * t_0); else tmp = -4.0 * (((a / y_45_scale) * (b / x_45_scale)) ^ 2.0); end tmp_2 = tmp; end
NOTE: b should be positive before calling this function
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1e-5], N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[Power[N[(N[(a / y$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
b = |b|\\
\\
\begin{array}{l}
t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\
\mathbf{if}\;b \leq 10^{-5}:\\
\;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot {\left(\frac{a}{y-scale} \cdot \frac{b}{x-scale}\right)}^{2}\\
\end{array}
\end{array}
if b < 1.00000000000000008e-5Initial program 33.9%
Simplified27.2%
Taylor expanded in angle around 0 51.4%
*-commutative51.4%
times-frac52.4%
Simplified52.4%
frac-times51.4%
*-commutative51.4%
clear-num51.4%
pow-prod-down64.2%
*-commutative64.2%
pow-prod-down79.6%
Applied egg-rr79.6%
pow-prod-down64.2%
clear-num64.2%
pow-prod-down79.6%
unpow279.6%
unpow279.6%
times-frac97.2%
Applied egg-rr97.2%
if 1.00000000000000008e-5 < b Initial program 4.1%
Simplified2.3%
Taylor expanded in angle around 0 39.9%
*-commutative39.9%
times-frac41.8%
Simplified41.8%
frac-times39.9%
*-commutative39.9%
clear-num39.9%
pow-prod-down54.1%
*-commutative54.1%
pow-prod-down79.3%
Applied egg-rr79.3%
pow-prod-down54.1%
clear-num54.1%
div-inv54.0%
pow-flip54.0%
metadata-eval54.0%
expm1-log1p-u53.7%
pow-prod-down78.1%
expm1-udef65.2%
Applied egg-rr70.3%
expm1-def84.9%
expm1-log1p86.2%
times-frac91.1%
Simplified91.1%
Final simplification95.8%
NOTE: b should be positive before calling this function
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (/ (* b a) (* y-scale x-scale))))
(if (<= b 35000.0)
(* -4.0 (* t_0 t_0))
(* -4.0 (pow (* (/ y-scale a) (/ x-scale b)) -2.0)))))b = abs(b);
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (b * a) / (y_45_scale * x_45_scale);
double tmp;
if (b <= 35000.0) {
tmp = -4.0 * (t_0 * t_0);
} else {
tmp = -4.0 * pow(((y_45_scale / a) * (x_45_scale / b)), -2.0);
}
return tmp;
}
NOTE: b should be positive before calling this function
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 = (b * a) / (y_45scale * x_45scale)
if (b <= 35000.0d0) then
tmp = (-4.0d0) * (t_0 * t_0)
else
tmp = (-4.0d0) * (((y_45scale / a) * (x_45scale / b)) ** (-2.0d0))
end if
code = tmp
end function
b = Math.abs(b);
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (b * a) / (y_45_scale * x_45_scale);
double tmp;
if (b <= 35000.0) {
tmp = -4.0 * (t_0 * t_0);
} else {
tmp = -4.0 * Math.pow(((y_45_scale / a) * (x_45_scale / b)), -2.0);
}
return tmp;
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (b * a) / (y_45_scale * x_45_scale) tmp = 0 if b <= 35000.0: tmp = -4.0 * (t_0 * t_0) else: tmp = -4.0 * math.pow(((y_45_scale / a) * (x_45_scale / b)), -2.0) return tmp
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale)) tmp = 0.0 if (b <= 35000.0) tmp = Float64(-4.0 * Float64(t_0 * t_0)); else tmp = Float64(-4.0 * (Float64(Float64(y_45_scale / a) * Float64(x_45_scale / b)) ^ -2.0)); end return tmp end
b = abs(b) function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (b * a) / (y_45_scale * x_45_scale); tmp = 0.0; if (b <= 35000.0) tmp = -4.0 * (t_0 * t_0); else tmp = -4.0 * (((y_45_scale / a) * (x_45_scale / b)) ^ -2.0); end tmp_2 = tmp; end
NOTE: b should be positive before calling this function
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 35000.0], N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[Power[N[(N[(y$45$scale / a), $MachinePrecision] * N[(x$45$scale / b), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
b = |b|\\
\\
\begin{array}{l}
t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\
\mathbf{if}\;b \leq 35000:\\
\;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot {\left(\frac{y-scale}{a} \cdot \frac{x-scale}{b}\right)}^{-2}\\
\end{array}
\end{array}
if b < 35000Initial program 34.2%
Simplified27.5%
Taylor expanded in angle around 0 51.6%
*-commutative51.6%
times-frac52.7%
Simplified52.7%
frac-times51.6%
*-commutative51.6%
clear-num51.6%
pow-prod-down64.4%
*-commutative64.4%
pow-prod-down79.7%
Applied egg-rr79.7%
pow-prod-down64.4%
clear-num64.4%
pow-prod-down79.7%
unpow279.7%
unpow279.7%
times-frac97.3%
Applied egg-rr97.3%
if 35000 < b Initial program 2.4%
Simplified0.6%
Taylor expanded in angle around 0 38.9%
*-commutative38.9%
times-frac40.8%
Simplified40.8%
frac-times38.9%
*-commutative38.9%
clear-num38.8%
pow-prod-down53.3%
*-commutative53.3%
pow-prod-down78.9%
Applied egg-rr78.9%
inv-pow78.9%
pow-prod-down53.3%
add-sqr-sqrt53.3%
unpow-prod-down53.3%
sqrt-div53.2%
sqrt-pow130.5%
metadata-eval30.5%
pow130.5%
pow-prod-down30.5%
unpow230.5%
sqrt-prod19.9%
add-sqr-sqrt32.3%
Applied egg-rr85.9%
pow-sqr86.1%
times-frac91.0%
metadata-eval91.0%
Simplified91.0%
Final simplification95.9%
NOTE: b should be positive before calling this function (FPCore (a b angle x-scale y-scale) :precision binary64 (* -4.0 (* (/ a y-scale) (* (/ b x-scale) (/ (/ a (/ x-scale b)) y-scale)))))
b = abs(b);
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return -4.0 * ((a / y_45_scale) * ((b / x_45_scale) * ((a / (x_45_scale / b)) / y_45_scale)));
}
NOTE: b should be positive before calling this function
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 / y_45scale) * ((b / x_45scale) * ((a / (x_45scale / b)) / y_45scale)))
end function
b = Math.abs(b);
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return -4.0 * ((a / y_45_scale) * ((b / x_45_scale) * ((a / (x_45_scale / b)) / y_45_scale)));
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): return -4.0 * ((a / y_45_scale) * ((b / x_45_scale) * ((a / (x_45_scale / b)) / y_45_scale)))
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) return Float64(-4.0 * Float64(Float64(a / y_45_scale) * Float64(Float64(b / x_45_scale) * Float64(Float64(a / Float64(x_45_scale / b)) / y_45_scale)))) end
b = abs(b) function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = -4.0 * ((a / y_45_scale) * ((b / x_45_scale) * ((a / (x_45_scale / b)) / y_45_scale))); end
NOTE: b should be positive before calling this function code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(-4.0 * N[(N[(a / y$45$scale), $MachinePrecision] * N[(N[(b / x$45$scale), $MachinePrecision] * N[(N[(a / N[(x$45$scale / b), $MachinePrecision]), $MachinePrecision] / y$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b = |b|\\
\\
-4 \cdot \left(\frac{a}{y-scale} \cdot \left(\frac{b}{x-scale} \cdot \frac{\frac{a}{\frac{x-scale}{b}}}{y-scale}\right)\right)
\end{array}
Initial program 27.1%
Simplified21.6%
Taylor expanded in angle around 0 48.8%
*-commutative48.8%
times-frac50.0%
Simplified50.0%
frac-times48.8%
*-commutative48.8%
clear-num48.8%
pow-prod-down61.9%
*-commutative61.9%
pow-prod-down79.5%
Applied egg-rr79.5%
unpow279.5%
unpow279.5%
times-frac94.7%
Applied egg-rr94.7%
metadata-eval94.7%
frac-times94.7%
clear-num94.8%
frac-times89.5%
clear-num89.5%
frac-times94.3%
associate-*l*91.8%
associate-*l/90.0%
clear-num90.0%
un-div-inv90.0%
Applied egg-rr90.0%
Final simplification90.0%
NOTE: b should be positive before calling this function (FPCore (a b angle x-scale y-scale) :precision binary64 (* -4.0 (* (/ (* b a) (* y-scale x-scale)) (* a (/ b (* y-scale x-scale))))))
b = abs(b);
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return -4.0 * (((b * a) / (y_45_scale * x_45_scale)) * (a * (b / (y_45_scale * x_45_scale))));
}
NOTE: b should be positive before calling this function
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)) * (a * (b / (y_45scale * x_45scale))))
end function
b = Math.abs(b);
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return -4.0 * (((b * a) / (y_45_scale * x_45_scale)) * (a * (b / (y_45_scale * x_45_scale))));
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): return -4.0 * (((b * a) / (y_45_scale * x_45_scale)) * (a * (b / (y_45_scale * x_45_scale))))
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) return Float64(-4.0 * Float64(Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale)) * Float64(a * Float64(b / Float64(y_45_scale * x_45_scale))))) end
b = abs(b) function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = -4.0 * (((b * a) / (y_45_scale * x_45_scale)) * (a * (b / (y_45_scale * x_45_scale)))); end
NOTE: b should be positive before calling this function code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(-4.0 * N[(N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision] * N[(a * N[(b / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b = |b|\\
\\
-4 \cdot \left(\frac{b \cdot a}{y-scale \cdot x-scale} \cdot \left(a \cdot \frac{b}{y-scale \cdot x-scale}\right)\right)
\end{array}
Initial program 27.1%
Simplified21.6%
Taylor expanded in angle around 0 48.8%
*-commutative48.8%
times-frac50.0%
Simplified50.0%
frac-times48.8%
*-commutative48.8%
clear-num48.8%
pow-prod-down61.9%
*-commutative61.9%
pow-prod-down79.5%
Applied egg-rr79.5%
pow-prod-down61.9%
clear-num61.9%
pow-prod-down79.5%
unpow279.5%
unpow279.5%
times-frac94.7%
Applied egg-rr94.7%
Taylor expanded in a around 0 94.7%
*-commutative94.7%
associate-*r/92.9%
*-commutative92.9%
Simplified92.9%
Final simplification92.9%
NOTE: b should be positive before calling this function (FPCore (a b angle x-scale y-scale) :precision binary64 (let* ((t_0 (/ (* b a) (* y-scale x-scale)))) (* -4.0 (* t_0 t_0))))
b = abs(b);
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (b * a) / (y_45_scale * x_45_scale);
return -4.0 * (t_0 * t_0);
}
NOTE: b should be positive before calling this function
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 = (b * a) / (y_45scale * x_45scale)
code = (-4.0d0) * (t_0 * t_0)
end function
b = Math.abs(b);
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
double t_0 = (b * a) / (y_45_scale * x_45_scale);
return -4.0 * (t_0 * t_0);
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (b * a) / (y_45_scale * x_45_scale) return -4.0 * (t_0 * t_0)
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(b * a) / Float64(y_45_scale * x_45_scale)) return Float64(-4.0 * Float64(t_0 * t_0)) end
b = abs(b) function tmp = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (b * a) / (y_45_scale * x_45_scale); tmp = -4.0 * (t_0 * t_0); end
NOTE: b should be positive before calling this function
code[a_, b_, angle_, x$45$scale_, y$45$scale_] := Block[{t$95$0 = N[(N[(b * a), $MachinePrecision] / N[(y$45$scale * x$45$scale), $MachinePrecision]), $MachinePrecision]}, N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
b = |b|\\
\\
\begin{array}{l}
t_0 := \frac{b \cdot a}{y-scale \cdot x-scale}\\
-4 \cdot \left(t_0 \cdot t_0\right)
\end{array}
\end{array}
Initial program 27.1%
Simplified21.6%
Taylor expanded in angle around 0 48.8%
*-commutative48.8%
times-frac50.0%
Simplified50.0%
frac-times48.8%
*-commutative48.8%
clear-num48.8%
pow-prod-down61.9%
*-commutative61.9%
pow-prod-down79.5%
Applied egg-rr79.5%
pow-prod-down61.9%
clear-num61.9%
pow-prod-down79.5%
unpow279.5%
unpow279.5%
times-frac94.7%
Applied egg-rr94.7%
Final simplification94.7%
NOTE: b should be positive before calling this function (FPCore (a b angle x-scale y-scale) :precision binary64 0.0)
b = abs(b);
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return 0.0;
}
NOTE: b should be positive before calling this function
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
b = Math.abs(b);
public static double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return 0.0;
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): return 0.0
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) return 0.0 end
b = abs(b) function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = 0.0; end
NOTE: b should be positive before calling this function code[a_, b_, angle_, x$45$scale_, y$45$scale_] := 0.0
\begin{array}{l}
b = |b|\\
\\
0
\end{array}
Initial program 27.1%
Simplified24.8%
Taylor expanded in b around 0 23.8%
distribute-rgt-out23.8%
metadata-eval23.8%
mul0-rgt35.4%
Simplified35.4%
Final simplification35.4%
herbie shell --seed 2023308
(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))))