
(FPCore (x y z) :precision binary64 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z): return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)) end
function tmp = code(x, y, z) tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0); end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
public static double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
def code(x, y, z): return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
function code(x, y, z) return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)) end
function tmp = code(x, y, z) tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0); end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\end{array}
x_m = (fabs.f64 x)
(FPCore (x_m y z)
:precision binary64
(if (<= x_m 2.1e+145)
(* 0.5 (+ y (/ (- (pow x_m 2.0) (pow z 2.0)) y)))
(if (<= x_m 4.5e+171)
(*
y
(+
0.5
(fma
x_m
(/ x_m (* 2.0 (pow y 2.0)))
(/ (pow z 2.0) (* (pow y 2.0) -2.0)))))
(* (* (+ x_m z) (- x_m z)) (/ 0.5 y)))))x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (x_m <= 2.1e+145) {
tmp = 0.5 * (y + ((pow(x_m, 2.0) - pow(z, 2.0)) / y));
} else if (x_m <= 4.5e+171) {
tmp = y * (0.5 + fma(x_m, (x_m / (2.0 * pow(y, 2.0))), (pow(z, 2.0) / (pow(y, 2.0) * -2.0))));
} else {
tmp = ((x_m + z) * (x_m - z)) * (0.5 / y);
}
return tmp;
}
x_m = abs(x) function code(x_m, y, z) tmp = 0.0 if (x_m <= 2.1e+145) tmp = Float64(0.5 * Float64(y + Float64(Float64((x_m ^ 2.0) - (z ^ 2.0)) / y))); elseif (x_m <= 4.5e+171) tmp = Float64(y * Float64(0.5 + fma(x_m, Float64(x_m / Float64(2.0 * (y ^ 2.0))), Float64((z ^ 2.0) / Float64((y ^ 2.0) * -2.0))))); else tmp = Float64(Float64(Float64(x_m + z) * Float64(x_m - z)) * Float64(0.5 / y)); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := If[LessEqual[x$95$m, 2.1e+145], N[(0.5 * N[(y + N[(N[(N[Power[x$95$m, 2.0], $MachinePrecision] - N[Power[z, 2.0], $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$95$m, 4.5e+171], N[(y * N[(0.5 + N[(x$95$m * N[(x$95$m / N[(2.0 * N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[z, 2.0], $MachinePrecision] / N[(N[Power[y, 2.0], $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x$95$m + z), $MachinePrecision] * N[(x$95$m - z), $MachinePrecision]), $MachinePrecision] * N[(0.5 / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 2.1 \cdot 10^{+145}:\\
\;\;\;\;0.5 \cdot \left(y + \frac{{x\_m}^{2} - {z}^{2}}{y}\right)\\
\mathbf{elif}\;x\_m \leq 4.5 \cdot 10^{+171}:\\
\;\;\;\;y \cdot \left(0.5 + \mathsf{fma}\left(x\_m, \frac{x\_m}{2 \cdot {y}^{2}}, \frac{{z}^{2}}{{y}^{2} \cdot -2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(x\_m + z\right) \cdot \left(x\_m - z\right)\right) \cdot \frac{0.5}{y}\\
\end{array}
\end{array}
if x < 2.09999999999999989e145Initial program 72.5%
remove-double-neg72.5%
distribute-lft-neg-out72.5%
distribute-frac-neg272.5%
distribute-frac-neg72.5%
neg-mul-172.5%
distribute-lft-neg-out72.5%
*-commutative72.5%
distribute-lft-neg-in72.5%
times-frac72.5%
metadata-eval72.5%
metadata-eval72.5%
associate--l+72.5%
fma-define73.5%
Simplified73.5%
Taylor expanded in x around 0 81.8%
associate--l+81.8%
div-sub85.4%
Simplified85.4%
if 2.09999999999999989e145 < x < 4.49999999999999969e171Initial program 31.0%
add-sqr-sqrt31.0%
pow231.0%
Applied egg-rr31.0%
unpow231.0%
add-sqr-sqrt31.0%
metadata-eval31.0%
div-inv31.0%
clear-num31.0%
Applied egg-rr31.0%
clear-num31.0%
div-inv31.0%
metadata-eval31.0%
add-sqr-sqrt31.0%
unpow231.0%
pow-flip31.0%
metadata-eval31.0%
Applied egg-rr31.0%
Taylor expanded in y around inf 52.0%
associate--l+52.0%
unpow252.0%
rem-square-sqrt52.4%
metadata-eval52.4%
unpow252.4%
unpow252.4%
rem-square-sqrt52.4%
associate-/l*100.0%
fmm-def100.0%
*-commutative100.0%
Simplified100.0%
if 4.49999999999999969e171 < x Initial program 73.7%
remove-double-neg73.7%
distribute-lft-neg-out73.7%
distribute-frac-neg273.7%
distribute-frac-neg73.7%
neg-mul-173.7%
distribute-lft-neg-out73.7%
*-commutative73.7%
distribute-lft-neg-in73.7%
times-frac73.7%
metadata-eval73.7%
metadata-eval73.7%
associate--l+73.7%
fma-define77.1%
Simplified77.1%
Taylor expanded in y around 0 73.7%
associate-*r/73.7%
*-commutative73.7%
associate-/l*73.7%
Simplified73.7%
pow273.7%
Applied egg-rr73.7%
pow273.7%
difference-of-squares84.2%
Applied egg-rr84.2%
Final simplification85.5%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= x_m 9e+157) (* 0.5 (+ y (/ (- (pow x_m 2.0) (pow z 2.0)) y))) (pow (* x_m (sqrt (/ 0.5 y))) 2.0)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (x_m <= 9e+157) {
tmp = 0.5 * (y + ((pow(x_m, 2.0) - pow(z, 2.0)) / y));
} else {
tmp = pow((x_m * sqrt((0.5 / y))), 2.0);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x_m <= 9d+157) then
tmp = 0.5d0 * (y + (((x_m ** 2.0d0) - (z ** 2.0d0)) / y))
else
tmp = (x_m * sqrt((0.5d0 / y))) ** 2.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
double tmp;
if (x_m <= 9e+157) {
tmp = 0.5 * (y + ((Math.pow(x_m, 2.0) - Math.pow(z, 2.0)) / y));
} else {
tmp = Math.pow((x_m * Math.sqrt((0.5 / y))), 2.0);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z): tmp = 0 if x_m <= 9e+157: tmp = 0.5 * (y + ((math.pow(x_m, 2.0) - math.pow(z, 2.0)) / y)) else: tmp = math.pow((x_m * math.sqrt((0.5 / y))), 2.0) return tmp
x_m = abs(x) function code(x_m, y, z) tmp = 0.0 if (x_m <= 9e+157) tmp = Float64(0.5 * Float64(y + Float64(Float64((x_m ^ 2.0) - (z ^ 2.0)) / y))); else tmp = Float64(x_m * sqrt(Float64(0.5 / y))) ^ 2.0; end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z) tmp = 0.0; if (x_m <= 9e+157) tmp = 0.5 * (y + (((x_m ^ 2.0) - (z ^ 2.0)) / y)); else tmp = (x_m * sqrt((0.5 / y))) ^ 2.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := If[LessEqual[x$95$m, 9e+157], N[(0.5 * N[(y + N[(N[(N[Power[x$95$m, 2.0], $MachinePrecision] - N[Power[z, 2.0], $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[(x$95$m * N[Sqrt[N[(0.5 / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 9 \cdot 10^{+157}:\\
\;\;\;\;0.5 \cdot \left(y + \frac{{x\_m}^{2} - {z}^{2}}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(x\_m \cdot \sqrt{\frac{0.5}{y}}\right)}^{2}\\
\end{array}
\end{array}
if x < 8.9999999999999997e157Initial program 72.1%
remove-double-neg72.1%
distribute-lft-neg-out72.1%
distribute-frac-neg272.1%
distribute-frac-neg72.1%
neg-mul-172.1%
distribute-lft-neg-out72.1%
*-commutative72.1%
distribute-lft-neg-in72.1%
times-frac72.1%
metadata-eval72.1%
metadata-eval72.1%
associate--l+72.1%
fma-define73.0%
Simplified73.0%
Taylor expanded in x around 0 81.6%
associate--l+81.6%
div-sub85.2%
Simplified85.2%
if 8.9999999999999997e157 < x Initial program 71.5%
remove-double-neg71.5%
distribute-lft-neg-out71.5%
distribute-frac-neg271.5%
distribute-frac-neg71.5%
neg-mul-171.5%
distribute-lft-neg-out71.5%
*-commutative71.5%
distribute-lft-neg-in71.5%
times-frac71.5%
metadata-eval71.5%
metadata-eval71.5%
associate--l+71.5%
fma-define74.9%
Simplified74.9%
Taylor expanded in x around inf 78.4%
*-commutative78.4%
associate-*l/78.4%
associate-*r/78.4%
Simplified78.4%
add-sqr-sqrt34.4%
pow234.4%
sqrt-prod34.4%
sqrt-pow143.4%
metadata-eval43.4%
pow143.4%
Applied egg-rr43.4%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= y 1.35e+154) (* 0.5 (/ (fma x_m x_m (- (* y y) (* z z))) y)) (* 0.5 y)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (y <= 1.35e+154) {
tmp = 0.5 * (fma(x_m, x_m, ((y * y) - (z * z))) / y);
} else {
tmp = 0.5 * y;
}
return tmp;
}
x_m = abs(x) function code(x_m, y, z) tmp = 0.0 if (y <= 1.35e+154) tmp = Float64(0.5 * Float64(fma(x_m, x_m, Float64(Float64(y * y) - Float64(z * z))) / y)); else tmp = Float64(0.5 * y); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := If[LessEqual[y, 1.35e+154], N[(0.5 * N[(N[(x$95$m * x$95$m + N[(N[(y * y), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x\_m, x\_m, y \cdot y - z \cdot z\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot y\\
\end{array}
\end{array}
if y < 1.35000000000000003e154Initial program 79.8%
remove-double-neg79.8%
distribute-lft-neg-out79.8%
distribute-frac-neg279.8%
distribute-frac-neg79.8%
neg-mul-179.8%
distribute-lft-neg-out79.8%
*-commutative79.8%
distribute-lft-neg-in79.8%
times-frac79.8%
metadata-eval79.8%
metadata-eval79.8%
associate--l+79.8%
fma-define81.2%
Simplified81.2%
if 1.35000000000000003e154 < y Initial program 8.2%
remove-double-neg8.2%
distribute-lft-neg-out8.2%
distribute-frac-neg28.2%
distribute-frac-neg8.2%
neg-mul-18.2%
distribute-lft-neg-out8.2%
*-commutative8.2%
distribute-lft-neg-in8.2%
times-frac8.2%
metadata-eval8.2%
metadata-eval8.2%
associate--l+8.2%
fma-define8.2%
Simplified8.2%
Taylor expanded in y around inf 69.0%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= y 1.35e+154) (/ (- (+ (* y y) (* x_m x_m)) (* z z)) (* y 2.0)) (* 0.5 y)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (y <= 1.35e+154) {
tmp = (((y * y) + (x_m * x_m)) - (z * z)) / (y * 2.0);
} else {
tmp = 0.5 * y;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 1.35d+154) then
tmp = (((y * y) + (x_m * x_m)) - (z * z)) / (y * 2.0d0)
else
tmp = 0.5d0 * y
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
double tmp;
if (y <= 1.35e+154) {
tmp = (((y * y) + (x_m * x_m)) - (z * z)) / (y * 2.0);
} else {
tmp = 0.5 * y;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z): tmp = 0 if y <= 1.35e+154: tmp = (((y * y) + (x_m * x_m)) - (z * z)) / (y * 2.0) else: tmp = 0.5 * y return tmp
x_m = abs(x) function code(x_m, y, z) tmp = 0.0 if (y <= 1.35e+154) tmp = Float64(Float64(Float64(Float64(y * y) + Float64(x_m * x_m)) - Float64(z * z)) / Float64(y * 2.0)); else tmp = Float64(0.5 * y); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z) tmp = 0.0; if (y <= 1.35e+154) tmp = (((y * y) + (x_m * x_m)) - (z * z)) / (y * 2.0); else tmp = 0.5 * y; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := If[LessEqual[y, 1.35e+154], N[(N[(N[(N[(y * y), $MachinePrecision] + N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{\left(y \cdot y + x\_m \cdot x\_m\right) - z \cdot z}{y \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot y\\
\end{array}
\end{array}
if y < 1.35000000000000003e154Initial program 79.8%
if 1.35000000000000003e154 < y Initial program 8.2%
remove-double-neg8.2%
distribute-lft-neg-out8.2%
distribute-frac-neg28.2%
distribute-frac-neg8.2%
neg-mul-18.2%
distribute-lft-neg-out8.2%
*-commutative8.2%
distribute-lft-neg-in8.2%
times-frac8.2%
metadata-eval8.2%
metadata-eval8.2%
associate--l+8.2%
fma-define8.2%
Simplified8.2%
Taylor expanded in y around inf 69.0%
Final simplification78.7%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= y 1.1e+94) (* (* (+ x_m z) (- x_m z)) (/ 0.5 y)) (* 0.5 y)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (y <= 1.1e+94) {
tmp = ((x_m + z) * (x_m - z)) * (0.5 / y);
} else {
tmp = 0.5 * y;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 1.1d+94) then
tmp = ((x_m + z) * (x_m - z)) * (0.5d0 / y)
else
tmp = 0.5d0 * y
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
double tmp;
if (y <= 1.1e+94) {
tmp = ((x_m + z) * (x_m - z)) * (0.5 / y);
} else {
tmp = 0.5 * y;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z): tmp = 0 if y <= 1.1e+94: tmp = ((x_m + z) * (x_m - z)) * (0.5 / y) else: tmp = 0.5 * y return tmp
x_m = abs(x) function code(x_m, y, z) tmp = 0.0 if (y <= 1.1e+94) tmp = Float64(Float64(Float64(x_m + z) * Float64(x_m - z)) * Float64(0.5 / y)); else tmp = Float64(0.5 * y); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z) tmp = 0.0; if (y <= 1.1e+94) tmp = ((x_m + z) * (x_m - z)) * (0.5 / y); else tmp = 0.5 * y; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := If[LessEqual[y, 1.1e+94], N[(N[(N[(x$95$m + z), $MachinePrecision] * N[(x$95$m - z), $MachinePrecision]), $MachinePrecision] * N[(0.5 / y), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.1 \cdot 10^{+94}:\\
\;\;\;\;\left(\left(x\_m + z\right) \cdot \left(x\_m - z\right)\right) \cdot \frac{0.5}{y}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot y\\
\end{array}
\end{array}
if y < 1.10000000000000006e94Initial program 79.7%
remove-double-neg79.7%
distribute-lft-neg-out79.7%
distribute-frac-neg279.7%
distribute-frac-neg79.7%
neg-mul-179.7%
distribute-lft-neg-out79.7%
*-commutative79.7%
distribute-lft-neg-in79.7%
times-frac79.7%
metadata-eval79.7%
metadata-eval79.7%
associate--l+79.7%
fma-define81.1%
Simplified81.1%
Taylor expanded in y around 0 68.9%
associate-*r/68.9%
*-commutative68.9%
associate-/l*68.8%
Simplified68.8%
pow268.8%
Applied egg-rr68.8%
pow268.8%
difference-of-squares74.0%
Applied egg-rr74.0%
if 1.10000000000000006e94 < y Initial program 34.8%
remove-double-neg34.8%
distribute-lft-neg-out34.8%
distribute-frac-neg234.8%
distribute-frac-neg34.8%
neg-mul-134.8%
distribute-lft-neg-out34.8%
*-commutative34.8%
distribute-lft-neg-in34.8%
times-frac34.8%
metadata-eval34.8%
metadata-eval34.8%
associate--l+34.8%
fma-define35.1%
Simplified35.1%
Taylor expanded in y around inf 63.4%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (if (<= y 3.7e+18) (* (/ 0.5 y) (* x_m x_m)) (* 0.5 y)))
x_m = fabs(x);
double code(double x_m, double y, double z) {
double tmp;
if (y <= 3.7e+18) {
tmp = (0.5 / y) * (x_m * x_m);
} else {
tmp = 0.5 * y;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= 3.7d+18) then
tmp = (0.5d0 / y) * (x_m * x_m)
else
tmp = 0.5d0 * y
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
double tmp;
if (y <= 3.7e+18) {
tmp = (0.5 / y) * (x_m * x_m);
} else {
tmp = 0.5 * y;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z): tmp = 0 if y <= 3.7e+18: tmp = (0.5 / y) * (x_m * x_m) else: tmp = 0.5 * y return tmp
x_m = abs(x) function code(x_m, y, z) tmp = 0.0 if (y <= 3.7e+18) tmp = Float64(Float64(0.5 / y) * Float64(x_m * x_m)); else tmp = Float64(0.5 * y); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z) tmp = 0.0; if (y <= 3.7e+18) tmp = (0.5 / y) * (x_m * x_m); else tmp = 0.5 * y; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := If[LessEqual[y, 3.7e+18], N[(N[(0.5 / y), $MachinePrecision] * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision], N[(0.5 * y), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.7 \cdot 10^{+18}:\\
\;\;\;\;\frac{0.5}{y} \cdot \left(x\_m \cdot x\_m\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot y\\
\end{array}
\end{array}
if y < 3.7e18Initial program 79.6%
remove-double-neg79.6%
distribute-lft-neg-out79.6%
distribute-frac-neg279.6%
distribute-frac-neg79.6%
neg-mul-179.6%
distribute-lft-neg-out79.6%
*-commutative79.6%
distribute-lft-neg-in79.6%
times-frac79.6%
metadata-eval79.6%
metadata-eval79.6%
associate--l+79.6%
fma-define80.6%
Simplified80.6%
Taylor expanded in x around inf 39.6%
*-commutative39.6%
associate-*l/39.6%
associate-*r/39.5%
Simplified39.5%
pow239.5%
Applied egg-rr39.5%
if 3.7e18 < y Initial program 47.4%
remove-double-neg47.4%
distribute-lft-neg-out47.4%
distribute-frac-neg247.4%
distribute-frac-neg47.4%
neg-mul-147.4%
distribute-lft-neg-out47.4%
*-commutative47.4%
distribute-lft-neg-in47.4%
times-frac47.4%
metadata-eval47.4%
metadata-eval47.4%
associate--l+47.4%
fma-define49.2%
Simplified49.2%
Taylor expanded in y around inf 58.2%
Final simplification43.9%
x_m = (fabs.f64 x) (FPCore (x_m y z) :precision binary64 (* 0.5 y))
x_m = fabs(x);
double code(double x_m, double y, double z) {
return 0.5 * y;
}
x_m = abs(x)
real(8) function code(x_m, y, z)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.5d0 * y
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z) {
return 0.5 * y;
}
x_m = math.fabs(x) def code(x_m, y, z): return 0.5 * y
x_m = abs(x) function code(x_m, y, z) return Float64(0.5 * y) end
x_m = abs(x); function tmp = code(x_m, y, z) tmp = 0.5 * y; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_] := N[(0.5 * y), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
0.5 \cdot y
\end{array}
Initial program 72.0%
remove-double-neg72.0%
distribute-lft-neg-out72.0%
distribute-frac-neg272.0%
distribute-frac-neg72.0%
neg-mul-172.0%
distribute-lft-neg-out72.0%
*-commutative72.0%
distribute-lft-neg-in72.0%
times-frac72.0%
metadata-eval72.0%
metadata-eval72.0%
associate--l+72.0%
fma-define73.2%
Simplified73.2%
Taylor expanded in y around inf 30.7%
(FPCore (x y z) :precision binary64 (- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x))))
double code(double x, double y, double z) {
return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y * 0.5d0) - (((0.5d0 / y) * (z + x)) * (z - x))
end function
public static double code(double x, double y, double z) {
return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x));
}
def code(x, y, z): return (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x))
function code(x, y, z) return Float64(Float64(y * 0.5) - Float64(Float64(Float64(0.5 / y) * Float64(z + x)) * Float64(z - x))) end
function tmp = code(x, y, z) tmp = (y * 0.5) - (((0.5 / y) * (z + x)) * (z - x)); end
code[x_, y_, z_] := N[(N[(y * 0.5), $MachinePrecision] - N[(N[(N[(0.5 / y), $MachinePrecision] * N[(z + x), $MachinePrecision]), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot 0.5 - \left(\frac{0.5}{y} \cdot \left(z + x\right)\right) \cdot \left(z - x\right)
\end{array}
herbie shell --seed 2024163
(FPCore (x y z)
:name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
:precision binary64
:alt
(! :herbie-platform default (- (* y 1/2) (* (* (/ 1/2 y) (+ z x)) (- z x))))
(/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))