
(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 6 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}
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
:precision binary64
(*
y_s
(if (<= y_m 1.32e+154)
(* 0.5 (/ (fma x x (- (* y_m y_m) (* z z))) y_m))
(* y_m 0.5))))y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
double tmp;
if (y_m <= 1.32e+154) {
tmp = 0.5 * (fma(x, x, ((y_m * y_m) - (z * z))) / y_m);
} else {
tmp = y_m * 0.5;
}
return y_s * tmp;
}
y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z) tmp = 0.0 if (y_m <= 1.32e+154) tmp = Float64(0.5 * Float64(fma(x, x, Float64(Float64(y_m * y_m) - Float64(z * z))) / y_m)); else tmp = Float64(y_m * 0.5); end return Float64(y_s * tmp) end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[y$95$m, 1.32e+154], N[(0.5 * N[(N[(x * x + N[(N[(y$95$m * y$95$m), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision], N[(y$95$m * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 1.32 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, y\_m \cdot y\_m - z \cdot z\right)}{y\_m}\\
\mathbf{else}:\\
\;\;\;\;y\_m \cdot 0.5\\
\end{array}
\end{array}
if y < 1.31999999999999998e154Initial program 72.9%
remove-double-neg72.9%
distribute-lft-neg-out72.9%
distribute-frac-neg272.9%
distribute-frac-neg72.9%
neg-mul-172.9%
distribute-lft-neg-out72.9%
*-commutative72.9%
distribute-lft-neg-in72.9%
times-frac72.9%
metadata-eval72.9%
metadata-eval72.9%
associate--l+72.9%
fma-define75.7%
Simplified75.7%
if 1.31999999999999998e154 < y Initial program 7.2%
remove-double-neg7.2%
distribute-lft-neg-out7.2%
distribute-frac-neg27.2%
distribute-frac-neg7.2%
neg-mul-17.2%
distribute-lft-neg-out7.2%
*-commutative7.2%
distribute-lft-neg-in7.2%
times-frac7.2%
metadata-eval7.2%
metadata-eval7.2%
associate--l+7.2%
fma-define7.2%
Simplified7.2%
Taylor expanded in y around inf 83.7%
Final simplification76.9%
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
:precision binary64
(*
y_s
(if (<= y_m 1.32e+154)
(/ (- (+ (* y_m y_m) (* x x)) (* z z)) (* y_m 2.0))
(* y_m 0.5))))y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
double tmp;
if (y_m <= 1.32e+154) {
tmp = (((y_m * y_m) + (x * x)) - (z * z)) / (y_m * 2.0);
} else {
tmp = y_m * 0.5;
}
return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8) :: tmp
if (y_m <= 1.32d+154) then
tmp = (((y_m * y_m) + (x * x)) - (z * z)) / (y_m * 2.0d0)
else
tmp = y_m * 0.5d0
end if
code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
double tmp;
if (y_m <= 1.32e+154) {
tmp = (((y_m * y_m) + (x * x)) - (z * z)) / (y_m * 2.0);
} else {
tmp = y_m * 0.5;
}
return y_s * tmp;
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z): tmp = 0 if y_m <= 1.32e+154: tmp = (((y_m * y_m) + (x * x)) - (z * z)) / (y_m * 2.0) else: tmp = y_m * 0.5 return y_s * tmp
y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z) tmp = 0.0 if (y_m <= 1.32e+154) tmp = Float64(Float64(Float64(Float64(y_m * y_m) + Float64(x * x)) - Float64(z * z)) / Float64(y_m * 2.0)); else tmp = Float64(y_m * 0.5); end return Float64(y_s * tmp) end
y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z) tmp = 0.0; if (y_m <= 1.32e+154) tmp = (((y_m * y_m) + (x * x)) - (z * z)) / (y_m * 2.0); else tmp = y_m * 0.5; end tmp_2 = y_s * tmp; end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[y$95$m, 1.32e+154], N[(N[(N[(N[(y$95$m * y$95$m), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision], N[(y$95$m * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 1.32 \cdot 10^{+154}:\\
\;\;\;\;\frac{\left(y\_m \cdot y\_m + x \cdot x\right) - z \cdot z}{y\_m \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;y\_m \cdot 0.5\\
\end{array}
\end{array}
if y < 1.31999999999999998e154Initial program 72.9%
if 1.31999999999999998e154 < y Initial program 7.2%
remove-double-neg7.2%
distribute-lft-neg-out7.2%
distribute-frac-neg27.2%
distribute-frac-neg7.2%
neg-mul-17.2%
distribute-lft-neg-out7.2%
*-commutative7.2%
distribute-lft-neg-in7.2%
times-frac7.2%
metadata-eval7.2%
metadata-eval7.2%
associate--l+7.2%
fma-define7.2%
Simplified7.2%
Taylor expanded in y around inf 83.7%
Final simplification74.5%
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
:precision binary64
(*
y_s
(if (<= y_m 6.5e-66)
(* x (* x (/ 0.5 y_m)))
(if (<= y_m 1.85e+65) (* (* z z) (/ -0.5 y_m)) (* y_m 0.5)))))y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
double tmp;
if (y_m <= 6.5e-66) {
tmp = x * (x * (0.5 / y_m));
} else if (y_m <= 1.85e+65) {
tmp = (z * z) * (-0.5 / y_m);
} else {
tmp = y_m * 0.5;
}
return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8) :: tmp
if (y_m <= 6.5d-66) then
tmp = x * (x * (0.5d0 / y_m))
else if (y_m <= 1.85d+65) then
tmp = (z * z) * ((-0.5d0) / y_m)
else
tmp = y_m * 0.5d0
end if
code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
double tmp;
if (y_m <= 6.5e-66) {
tmp = x * (x * (0.5 / y_m));
} else if (y_m <= 1.85e+65) {
tmp = (z * z) * (-0.5 / y_m);
} else {
tmp = y_m * 0.5;
}
return y_s * tmp;
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z): tmp = 0 if y_m <= 6.5e-66: tmp = x * (x * (0.5 / y_m)) elif y_m <= 1.85e+65: tmp = (z * z) * (-0.5 / y_m) else: tmp = y_m * 0.5 return y_s * tmp
y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z) tmp = 0.0 if (y_m <= 6.5e-66) tmp = Float64(x * Float64(x * Float64(0.5 / y_m))); elseif (y_m <= 1.85e+65) tmp = Float64(Float64(z * z) * Float64(-0.5 / y_m)); else tmp = Float64(y_m * 0.5); end return Float64(y_s * tmp) end
y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z) tmp = 0.0; if (y_m <= 6.5e-66) tmp = x * (x * (0.5 / y_m)); elseif (y_m <= 1.85e+65) tmp = (z * z) * (-0.5 / y_m); else tmp = y_m * 0.5; end tmp_2 = y_s * tmp; end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[y$95$m, 6.5e-66], N[(x * N[(x * N[(0.5 / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$95$m, 1.85e+65], N[(N[(z * z), $MachinePrecision] * N[(-0.5 / y$95$m), $MachinePrecision]), $MachinePrecision], N[(y$95$m * 0.5), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 6.5 \cdot 10^{-66}:\\
\;\;\;\;x \cdot \left(x \cdot \frac{0.5}{y\_m}\right)\\
\mathbf{elif}\;y\_m \leq 1.85 \cdot 10^{+65}:\\
\;\;\;\;\left(z \cdot z\right) \cdot \frac{-0.5}{y\_m}\\
\mathbf{else}:\\
\;\;\;\;y\_m \cdot 0.5\\
\end{array}
\end{array}
if y < 6.50000000000000024e-66Initial program 70.5%
remove-double-neg70.5%
distribute-lft-neg-out70.5%
distribute-frac-neg270.5%
distribute-frac-neg70.5%
neg-mul-170.5%
distribute-lft-neg-out70.5%
*-commutative70.5%
distribute-lft-neg-in70.5%
times-frac70.5%
metadata-eval70.5%
metadata-eval70.5%
associate--l+70.5%
fma-define73.2%
Simplified73.2%
clear-num73.1%
un-div-inv73.1%
fma-undefine70.4%
associate--l+70.4%
add-sqr-sqrt70.4%
pow270.4%
hypot-define70.4%
pow270.4%
Applied egg-rr70.4%
Taylor expanded in x around inf 36.4%
pow236.4%
associate-/r/36.3%
associate-*r*39.0%
Applied egg-rr39.0%
if 6.50000000000000024e-66 < y < 1.84999999999999997e65Initial program 88.6%
remove-double-neg88.6%
distribute-lft-neg-out88.6%
distribute-frac-neg288.6%
distribute-frac-neg88.6%
neg-mul-188.6%
distribute-lft-neg-out88.6%
*-commutative88.6%
distribute-lft-neg-in88.6%
times-frac88.6%
metadata-eval88.6%
metadata-eval88.6%
associate--l+88.6%
fma-define94.2%
Simplified94.2%
clear-num94.1%
un-div-inv94.1%
fma-undefine88.5%
associate--l+88.5%
add-sqr-sqrt88.5%
pow288.5%
hypot-define88.5%
pow288.5%
Applied egg-rr88.5%
Taylor expanded in z around inf 61.3%
associate-*r/61.3%
metadata-eval61.3%
associate-*r*61.3%
neg-mul-161.3%
associate-*l/61.5%
*-commutative61.5%
metadata-eval61.5%
distribute-neg-frac61.5%
neg-mul-161.5%
associate-*r*61.5%
distribute-lft-neg-in61.5%
*-commutative61.5%
neg-mul-161.5%
remove-double-neg61.5%
Simplified61.5%
unpow261.5%
Applied egg-rr61.5%
if 1.84999999999999997e65 < y Initial program 26.8%
remove-double-neg26.8%
distribute-lft-neg-out26.8%
distribute-frac-neg226.8%
distribute-frac-neg26.8%
neg-mul-126.8%
distribute-lft-neg-out26.8%
*-commutative26.8%
distribute-lft-neg-in26.8%
times-frac26.8%
metadata-eval26.8%
metadata-eval26.8%
associate--l+26.8%
fma-define26.8%
Simplified26.8%
Taylor expanded in y around inf 76.9%
Final simplification48.2%
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z)
:precision binary64
(*
y_s
(if (<= y_m 1.75e-66)
(* (* x x) (/ 0.5 y_m))
(if (<= y_m 7.8e+65) (* (* z z) (/ -0.5 y_m)) (* y_m 0.5)))))y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
double tmp;
if (y_m <= 1.75e-66) {
tmp = (x * x) * (0.5 / y_m);
} else if (y_m <= 7.8e+65) {
tmp = (z * z) * (-0.5 / y_m);
} else {
tmp = y_m * 0.5;
}
return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8) :: tmp
if (y_m <= 1.75d-66) then
tmp = (x * x) * (0.5d0 / y_m)
else if (y_m <= 7.8d+65) then
tmp = (z * z) * ((-0.5d0) / y_m)
else
tmp = y_m * 0.5d0
end if
code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
double tmp;
if (y_m <= 1.75e-66) {
tmp = (x * x) * (0.5 / y_m);
} else if (y_m <= 7.8e+65) {
tmp = (z * z) * (-0.5 / y_m);
} else {
tmp = y_m * 0.5;
}
return y_s * tmp;
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z): tmp = 0 if y_m <= 1.75e-66: tmp = (x * x) * (0.5 / y_m) elif y_m <= 7.8e+65: tmp = (z * z) * (-0.5 / y_m) else: tmp = y_m * 0.5 return y_s * tmp
y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z) tmp = 0.0 if (y_m <= 1.75e-66) tmp = Float64(Float64(x * x) * Float64(0.5 / y_m)); elseif (y_m <= 7.8e+65) tmp = Float64(Float64(z * z) * Float64(-0.5 / y_m)); else tmp = Float64(y_m * 0.5); end return Float64(y_s * tmp) end
y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z) tmp = 0.0; if (y_m <= 1.75e-66) tmp = (x * x) * (0.5 / y_m); elseif (y_m <= 7.8e+65) tmp = (z * z) * (-0.5 / y_m); else tmp = y_m * 0.5; end tmp_2 = y_s * tmp; end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[y$95$m, 1.75e-66], N[(N[(x * x), $MachinePrecision] * N[(0.5 / y$95$m), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$95$m, 7.8e+65], N[(N[(z * z), $MachinePrecision] * N[(-0.5 / y$95$m), $MachinePrecision]), $MachinePrecision], N[(y$95$m * 0.5), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 1.75 \cdot 10^{-66}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \frac{0.5}{y\_m}\\
\mathbf{elif}\;y\_m \leq 7.8 \cdot 10^{+65}:\\
\;\;\;\;\left(z \cdot z\right) \cdot \frac{-0.5}{y\_m}\\
\mathbf{else}:\\
\;\;\;\;y\_m \cdot 0.5\\
\end{array}
\end{array}
if y < 1.75e-66Initial program 70.5%
remove-double-neg70.5%
distribute-lft-neg-out70.5%
distribute-frac-neg270.5%
distribute-frac-neg70.5%
neg-mul-170.5%
distribute-lft-neg-out70.5%
*-commutative70.5%
distribute-lft-neg-in70.5%
times-frac70.5%
metadata-eval70.5%
metadata-eval70.5%
associate--l+70.5%
fma-define73.2%
Simplified73.2%
Taylor expanded in x around inf 36.4%
*-commutative36.4%
associate-*l/36.4%
associate-*r/36.3%
Simplified36.3%
pow236.3%
Applied egg-rr36.3%
if 1.75e-66 < y < 7.7999999999999996e65Initial program 88.6%
remove-double-neg88.6%
distribute-lft-neg-out88.6%
distribute-frac-neg288.6%
distribute-frac-neg88.6%
neg-mul-188.6%
distribute-lft-neg-out88.6%
*-commutative88.6%
distribute-lft-neg-in88.6%
times-frac88.6%
metadata-eval88.6%
metadata-eval88.6%
associate--l+88.6%
fma-define94.2%
Simplified94.2%
clear-num94.1%
un-div-inv94.1%
fma-undefine88.5%
associate--l+88.5%
add-sqr-sqrt88.5%
pow288.5%
hypot-define88.5%
pow288.5%
Applied egg-rr88.5%
Taylor expanded in z around inf 61.3%
associate-*r/61.3%
metadata-eval61.3%
associate-*r*61.3%
neg-mul-161.3%
associate-*l/61.5%
*-commutative61.5%
metadata-eval61.5%
distribute-neg-frac61.5%
neg-mul-161.5%
associate-*r*61.5%
distribute-lft-neg-in61.5%
*-commutative61.5%
neg-mul-161.5%
remove-double-neg61.5%
Simplified61.5%
unpow261.5%
Applied egg-rr61.5%
if 7.7999999999999996e65 < y Initial program 26.8%
remove-double-neg26.8%
distribute-lft-neg-out26.8%
distribute-frac-neg226.8%
distribute-frac-neg26.8%
neg-mul-126.8%
distribute-lft-neg-out26.8%
*-commutative26.8%
distribute-lft-neg-in26.8%
times-frac26.8%
metadata-eval26.8%
metadata-eval26.8%
associate--l+26.8%
fma-define26.8%
Simplified26.8%
Taylor expanded in y around inf 76.9%
Final simplification46.3%
y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) (FPCore (y_s x y_m z) :precision binary64 (* y_s (if (<= y_m 1.9e+66) (* (* x x) (/ 0.5 y_m)) (* y_m 0.5))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
double tmp;
if (y_m <= 1.9e+66) {
tmp = (x * x) * (0.5 / y_m);
} else {
tmp = y_m * 0.5;
}
return y_s * tmp;
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
real(8) :: tmp
if (y_m <= 1.9d+66) then
tmp = (x * x) * (0.5d0 / y_m)
else
tmp = y_m * 0.5d0
end if
code = y_s * tmp
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
double tmp;
if (y_m <= 1.9e+66) {
tmp = (x * x) * (0.5 / y_m);
} else {
tmp = y_m * 0.5;
}
return y_s * tmp;
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z): tmp = 0 if y_m <= 1.9e+66: tmp = (x * x) * (0.5 / y_m) else: tmp = y_m * 0.5 return y_s * tmp
y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z) tmp = 0.0 if (y_m <= 1.9e+66) tmp = Float64(Float64(x * x) * Float64(0.5 / y_m)); else tmp = Float64(y_m * 0.5); end return Float64(y_s * tmp) end
y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z) tmp = 0.0; if (y_m <= 1.9e+66) tmp = (x * x) * (0.5 / y_m); else tmp = y_m * 0.5; end tmp_2 = y_s * tmp; end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * If[LessEqual[y$95$m, 1.9e+66], N[(N[(x * x), $MachinePrecision] * N[(0.5 / y$95$m), $MachinePrecision]), $MachinePrecision], N[(y$95$m * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 1.9 \cdot 10^{+66}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \frac{0.5}{y\_m}\\
\mathbf{else}:\\
\;\;\;\;y\_m \cdot 0.5\\
\end{array}
\end{array}
if y < 1.9000000000000001e66Initial 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-define75.0%
Simplified75.0%
Taylor expanded in x around inf 36.2%
*-commutative36.2%
associate-*l/36.2%
associate-*r/36.1%
Simplified36.1%
pow236.1%
Applied egg-rr36.1%
if 1.9000000000000001e66 < y Initial program 26.8%
remove-double-neg26.8%
distribute-lft-neg-out26.8%
distribute-frac-neg226.8%
distribute-frac-neg26.8%
neg-mul-126.8%
distribute-lft-neg-out26.8%
*-commutative26.8%
distribute-lft-neg-in26.8%
times-frac26.8%
metadata-eval26.8%
metadata-eval26.8%
associate--l+26.8%
fma-define26.8%
Simplified26.8%
Taylor expanded in y around inf 76.9%
Final simplification44.4%
y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) (FPCore (y_s x y_m z) :precision binary64 (* y_s (* y_m 0.5)))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
return y_s * (y_m * 0.5);
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z
code = y_s * (y_m * 0.5d0)
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
public static double code(double y_s, double x, double y_m, double z) {
return y_s * (y_m * 0.5);
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z): return y_s * (y_m * 0.5)
y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z) return Float64(y_s * Float64(y_m * 0.5)) end
y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp = code(y_s, x, y_m, z) tmp = y_s * (y_m * 0.5); end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[y$95$s_, x_, y$95$m_, z_] := N[(y$95$s * N[(y$95$m * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \left(y\_m \cdot 0.5\right)
\end{array}
Initial program 62.9%
remove-double-neg62.9%
distribute-lft-neg-out62.9%
distribute-frac-neg262.9%
distribute-frac-neg62.9%
neg-mul-162.9%
distribute-lft-neg-out62.9%
*-commutative62.9%
distribute-lft-neg-in62.9%
times-frac62.9%
metadata-eval62.9%
metadata-eval62.9%
associate--l+62.9%
fma-define65.2%
Simplified65.2%
Taylor expanded in y around inf 37.2%
Final simplification37.2%
(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 2024146
(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)))