
(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 (* (/ a y-scale) (/ b x-scale)))
(t_1 (/ 1.0 (/ (* x-scale y-scale) (* a b)))))
(if (<= b 1.6e-173) (* -4.0 (* t_1 t_1)) (* -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 = (a / y_45_scale) * (b / x_45_scale);
double t_1 = 1.0 / ((x_45_scale * y_45_scale) / (a * b));
double tmp;
if (b <= 1.6e-173) {
tmp = -4.0 * (t_1 * t_1);
} else {
tmp = -4.0 * (t_0 * t_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) :: t_1
real(8) :: tmp
t_0 = (a / y_45scale) * (b / x_45scale)
t_1 = 1.0d0 / ((x_45scale * y_45scale) / (a * b))
if (b <= 1.6d-173) then
tmp = (-4.0d0) * (t_1 * t_1)
else
tmp = (-4.0d0) * (t_0 * t_0)
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 = (a / y_45_scale) * (b / x_45_scale);
double t_1 = 1.0 / ((x_45_scale * y_45_scale) / (a * b));
double tmp;
if (b <= 1.6e-173) {
tmp = -4.0 * (t_1 * t_1);
} else {
tmp = -4.0 * (t_0 * t_0);
}
return tmp;
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (a / y_45_scale) * (b / x_45_scale) t_1 = 1.0 / ((x_45_scale * y_45_scale) / (a * b)) tmp = 0 if b <= 1.6e-173: tmp = -4.0 * (t_1 * t_1) else: tmp = -4.0 * (t_0 * t_0) return tmp
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(a / y_45_scale) * Float64(b / x_45_scale)) t_1 = Float64(1.0 / Float64(Float64(x_45_scale * y_45_scale) / Float64(a * b))) tmp = 0.0 if (b <= 1.6e-173) tmp = Float64(-4.0 * Float64(t_1 * t_1)); else tmp = Float64(-4.0 * Float64(t_0 * t_0)); end return tmp end
b = abs(b) function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (a / y_45_scale) * (b / x_45_scale); t_1 = 1.0 / ((x_45_scale * y_45_scale) / (a * b)); tmp = 0.0; if (b <= 1.6e-173) tmp = -4.0 * (t_1 * t_1); else tmp = -4.0 * (t_0 * t_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[(a / y$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[(N[(x$45$scale * y$45$scale), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.6e-173], N[(-4.0 * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
b = |b|\\
\\
\begin{array}{l}
t_0 := \frac{a}{y-scale} \cdot \frac{b}{x-scale}\\
t_1 := \frac{1}{\frac{x-scale \cdot y-scale}{a \cdot b}}\\
\mathbf{if}\;b \leq 1.6 \cdot 10^{-173}:\\
\;\;\;\;-4 \cdot \left(t_1 \cdot t_1\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\
\end{array}
\end{array}
if b < 1.6e-173Initial program 29.3%
Simplified27.2%
Taylor expanded in angle around 0 51.4%
times-frac49.3%
unpow249.3%
unpow249.3%
unpow249.3%
unpow249.3%
Simplified49.3%
pow249.3%
pow249.3%
frac-times51.4%
pow251.4%
pow251.4%
clear-num51.4%
pow-prod-down59.7%
pow-prod-down81.0%
Applied egg-rr81.0%
add-sqr-sqrt81.0%
sqrt-div81.1%
metadata-eval81.1%
sqrt-div81.1%
unpow281.1%
sqrt-prod42.3%
add-sqr-sqrt59.2%
sqrt-pow159.7%
metadata-eval59.7%
pow159.7%
sqrt-div59.7%
metadata-eval59.7%
sqrt-div59.7%
unpow259.7%
sqrt-prod30.2%
add-sqr-sqrt58.2%
sqrt-pow192.1%
metadata-eval92.1%
pow192.1%
Applied egg-rr92.1%
if 1.6e-173 < b Initial program 18.4%
Simplified15.3%
Taylor expanded in angle around 0 48.9%
pow248.9%
pow248.9%
frac-times50.8%
pow250.8%
times-frac65.7%
pow265.7%
times-frac77.4%
Applied egg-rr77.4%
unswap-sqr95.3%
Simplified95.3%
Final simplification93.3%
NOTE: b should be positive before calling this function (FPCore (a b angle x-scale y-scale) :precision binary64 (* -4.0 (/ 1.0 (/ 1.0 (pow (/ (/ (* x-scale y-scale) a) b) -2.0)))))
b = abs(b);
double code(double a, double b, double angle, double x_45_scale, double y_45_scale) {
return -4.0 * (1.0 / (1.0 / pow((((x_45_scale * y_45_scale) / a) / b), -2.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 = (-4.0d0) * (1.0d0 / (1.0d0 / ((((x_45scale * y_45scale) / a) / b) ** (-2.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 -4.0 * (1.0 / (1.0 / Math.pow((((x_45_scale * y_45_scale) / a) / b), -2.0)));
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): return -4.0 * (1.0 / (1.0 / math.pow((((x_45_scale * y_45_scale) / a) / b), -2.0)))
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) return Float64(-4.0 * Float64(1.0 / Float64(1.0 / (Float64(Float64(Float64(x_45_scale * y_45_scale) / a) / b) ^ -2.0)))) end
b = abs(b) function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = -4.0 * (1.0 / (1.0 / ((((x_45_scale * y_45_scale) / a) / b) ^ -2.0))); end
NOTE: b should be positive before calling this function code[a_, b_, angle_, x$45$scale_, y$45$scale_] := N[(-4.0 * N[(1.0 / N[(1.0 / N[Power[N[(N[(N[(x$45$scale * y$45$scale), $MachinePrecision] / a), $MachinePrecision] / b), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b = |b|\\
\\
-4 \cdot \frac{1}{\frac{1}{{\left(\frac{\frac{x-scale \cdot y-scale}{a}}{b}\right)}^{-2}}}
\end{array}
Initial program 25.3%
Simplified22.9%
Taylor expanded in angle around 0 50.5%
times-frac49.9%
unpow249.9%
unpow249.9%
unpow249.9%
unpow249.9%
Simplified49.9%
pow249.9%
pow249.9%
frac-times50.5%
pow250.5%
pow250.5%
clear-num50.5%
pow-prod-down61.0%
pow-prod-down78.3%
Applied egg-rr78.3%
clear-num78.3%
inv-pow78.3%
unpow278.3%
unpow278.3%
frac-times91.0%
frac-times83.0%
frac-times91.5%
pow291.5%
Applied egg-rr91.5%
Simplified91.7%
*-commutative91.7%
times-frac91.0%
associate-/r*93.5%
*-commutative93.5%
Applied egg-rr93.5%
Final simplification93.5%
NOTE: b should be positive before calling this function
(FPCore (a b angle x-scale y-scale)
:precision binary64
(let* ((t_0 (* (/ a y-scale) (/ b x-scale)))
(t_1 (/ (* x-scale y-scale) (* a b))))
(if (<= b 1e-172) (* -4.0 (/ 1.0 (* t_1 t_1))) (* -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 = (a / y_45_scale) * (b / x_45_scale);
double t_1 = (x_45_scale * y_45_scale) / (a * b);
double tmp;
if (b <= 1e-172) {
tmp = -4.0 * (1.0 / (t_1 * t_1));
} else {
tmp = -4.0 * (t_0 * t_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) :: t_1
real(8) :: tmp
t_0 = (a / y_45scale) * (b / x_45scale)
t_1 = (x_45scale * y_45scale) / (a * b)
if (b <= 1d-172) then
tmp = (-4.0d0) * (1.0d0 / (t_1 * t_1))
else
tmp = (-4.0d0) * (t_0 * t_0)
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 = (a / y_45_scale) * (b / x_45_scale);
double t_1 = (x_45_scale * y_45_scale) / (a * b);
double tmp;
if (b <= 1e-172) {
tmp = -4.0 * (1.0 / (t_1 * t_1));
} else {
tmp = -4.0 * (t_0 * t_0);
}
return tmp;
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (a / y_45_scale) * (b / x_45_scale) t_1 = (x_45_scale * y_45_scale) / (a * b) tmp = 0 if b <= 1e-172: tmp = -4.0 * (1.0 / (t_1 * t_1)) else: tmp = -4.0 * (t_0 * t_0) return tmp
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(a / y_45_scale) * Float64(b / x_45_scale)) t_1 = Float64(Float64(x_45_scale * y_45_scale) / Float64(a * b)) tmp = 0.0 if (b <= 1e-172) tmp = Float64(-4.0 * Float64(1.0 / Float64(t_1 * t_1))); else tmp = Float64(-4.0 * Float64(t_0 * t_0)); end return tmp end
b = abs(b) function tmp_2 = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (a / y_45_scale) * (b / x_45_scale); t_1 = (x_45_scale * y_45_scale) / (a * b); tmp = 0.0; if (b <= 1e-172) tmp = -4.0 * (1.0 / (t_1 * t_1)); else tmp = -4.0 * (t_0 * t_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[(a / y$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x$45$scale * y$45$scale), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1e-172], N[(-4.0 * N[(1.0 / N[(t$95$1 * t$95$1), $MachinePrecision]), $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{a}{y-scale} \cdot \frac{b}{x-scale}\\
t_1 := \frac{x-scale \cdot y-scale}{a \cdot b}\\
\mathbf{if}\;b \leq 10^{-172}:\\
\;\;\;\;-4 \cdot \frac{1}{t_1 \cdot t_1}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t_0 \cdot t_0\right)\\
\end{array}
\end{array}
if b < 1e-172Initial program 29.3%
Simplified27.2%
Taylor expanded in angle around 0 51.4%
times-frac49.3%
unpow249.3%
unpow249.3%
unpow249.3%
unpow249.3%
Simplified49.3%
pow249.3%
pow249.3%
frac-times51.4%
pow251.4%
pow251.4%
clear-num51.4%
pow-prod-down59.7%
pow-prod-down81.0%
Applied egg-rr81.0%
add-sqr-sqrt80.9%
sqrt-div81.0%
unpow281.0%
sqrt-prod42.3%
add-sqr-sqrt59.2%
sqrt-pow159.7%
metadata-eval59.7%
pow159.7%
sqrt-div59.7%
unpow259.7%
sqrt-prod30.2%
add-sqr-sqrt58.2%
sqrt-pow192.0%
metadata-eval92.0%
pow192.0%
Applied egg-rr92.0%
if 1e-172 < b Initial program 18.4%
Simplified15.3%
Taylor expanded in angle around 0 48.9%
pow248.9%
pow248.9%
frac-times50.8%
pow250.8%
times-frac65.7%
pow265.7%
times-frac77.4%
Applied egg-rr77.4%
unswap-sqr95.3%
Simplified95.3%
Final simplification93.2%
NOTE: b should be positive before calling this function (FPCore (a b angle x-scale y-scale) :precision binary64 (let* ((t_0 (* (/ x-scale b) (/ y-scale a)))) (* -4.0 (/ 1.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 = (x_45_scale / b) * (y_45_scale / a);
return -4.0 * (1.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 = (x_45scale / b) * (y_45scale / a)
code = (-4.0d0) * (1.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 = (x_45_scale / b) * (y_45_scale / a);
return -4.0 * (1.0 / (t_0 * t_0));
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): t_0 = (x_45_scale / b) * (y_45_scale / a) return -4.0 * (1.0 / (t_0 * t_0))
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) t_0 = Float64(Float64(x_45_scale / b) * Float64(y_45_scale / a)) return Float64(-4.0 * Float64(1.0 / Float64(t_0 * t_0))) end
b = abs(b) function tmp = code(a, b, angle, x_45_scale, y_45_scale) t_0 = (x_45_scale / b) * (y_45_scale / a); tmp = -4.0 * (1.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[(x$45$scale / b), $MachinePrecision] * N[(y$45$scale / a), $MachinePrecision]), $MachinePrecision]}, N[(-4.0 * N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
b = |b|\\
\\
\begin{array}{l}
t_0 := \frac{x-scale}{b} \cdot \frac{y-scale}{a}\\
-4 \cdot \frac{1}{t_0 \cdot t_0}
\end{array}
\end{array}
Initial program 25.3%
Simplified22.9%
Taylor expanded in angle around 0 50.5%
times-frac49.9%
unpow249.9%
unpow249.9%
unpow249.9%
unpow249.9%
Simplified49.9%
pow249.9%
pow249.9%
frac-times50.5%
pow250.5%
pow250.5%
clear-num50.5%
pow-prod-down61.0%
pow-prod-down78.3%
Applied egg-rr78.3%
clear-num78.3%
inv-pow78.3%
unpow278.3%
unpow278.3%
frac-times91.0%
frac-times83.0%
frac-times91.5%
pow291.5%
Applied egg-rr91.5%
Simplified91.7%
pow-flip91.6%
*-commutative91.6%
times-frac91.0%
metadata-eval91.0%
pow291.0%
times-frac83.2%
*-commutative83.2%
times-frac91.6%
*-commutative91.6%
Applied egg-rr91.6%
Final simplification91.6%
NOTE: b should be positive before calling this function (FPCore (a b angle x-scale y-scale) :precision binary64 (* -4.0 (* (/ b x-scale) (* (/ a y-scale) (* (/ a y-scale) (/ b 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 / x_45_scale) * ((a / y_45_scale) * ((a / y_45_scale) * (b / 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 / x_45scale) * ((a / y_45scale) * ((a / y_45scale) * (b / 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 / x_45_scale) * ((a / y_45_scale) * ((a / y_45_scale) * (b / x_45_scale))));
}
b = abs(b) def code(a, b, angle, x_45_scale, y_45_scale): return -4.0 * ((b / x_45_scale) * ((a / y_45_scale) * ((a / y_45_scale) * (b / x_45_scale))))
b = abs(b) function code(a, b, angle, x_45_scale, y_45_scale) return Float64(-4.0 * Float64(Float64(b / x_45_scale) * Float64(Float64(a / y_45_scale) * Float64(Float64(a / y_45_scale) * Float64(b / x_45_scale))))) end
b = abs(b) function tmp = code(a, b, angle, x_45_scale, y_45_scale) tmp = -4.0 * ((b / x_45_scale) * ((a / y_45_scale) * ((a / y_45_scale) * (b / 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[(b / x$45$scale), $MachinePrecision] * N[(N[(a / y$45$scale), $MachinePrecision] * N[(N[(a / y$45$scale), $MachinePrecision] * N[(b / x$45$scale), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b = |b|\\
\\
-4 \cdot \left(\frac{b}{x-scale} \cdot \left(\frac{a}{y-scale} \cdot \left(\frac{a}{y-scale} \cdot \frac{b}{x-scale}\right)\right)\right)
\end{array}
Initial program 25.3%
Simplified22.9%
Taylor expanded in angle around 0 50.5%
times-frac49.9%
unpow249.9%
unpow249.9%
unpow249.9%
unpow249.9%
Simplified49.9%
pow249.9%
associate-*l/50.8%
pow250.8%
times-frac60.9%
Applied egg-rr60.9%
unswap-sqr74.1%
frac-times91.2%
associate-*l/89.8%
associate-*l/91.5%
associate-*r*89.2%
Applied egg-rr89.2%
Final simplification89.2%
NOTE: b should be positive before calling this function (FPCore (a b angle x-scale y-scale) :precision binary64 (let* ((t_0 (* (/ a y-scale) (/ b 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 = (a / y_45_scale) * (b / 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 = (a / y_45scale) * (b / 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 = (a / y_45_scale) * (b / 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 = (a / y_45_scale) * (b / 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(a / y_45_scale) * Float64(b / 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 = (a / y_45_scale) * (b / 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[(a / y$45$scale), $MachinePrecision] * N[(b / 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{a}{y-scale} \cdot \frac{b}{x-scale}\\
-4 \cdot \left(t_0 \cdot t_0\right)
\end{array}
\end{array}
Initial program 25.3%
Simplified22.9%
Taylor expanded in angle around 0 50.5%
pow250.5%
pow250.5%
frac-times49.9%
pow249.9%
times-frac59.3%
pow259.3%
times-frac74.8%
Applied egg-rr74.8%
unswap-sqr91.5%
Simplified91.5%
Final simplification91.5%
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 25.3%
Simplified24.3%
Taylor expanded in b around 0 23.5%
distribute-rgt-out23.5%
*-commutative23.5%
metadata-eval23.5%
mul0-rgt34.6%
Simplified34.6%
Final simplification34.6%
herbie shell --seed 2023279
(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))))