
(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}
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 (<= (/ (- (+ (* x x) (* y_m y_m)) (* z z)) (* y_m 2.0)) -2e-56)
(* (pow (/ z (cbrt y_m)) 2.0) (/ -0.5 (cbrt y_m)))
(* 0.5 (+ y_m (* x (/ x y_m)))))))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 (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -2e-56) {
tmp = pow((z / cbrt(y_m)), 2.0) * (-0.5 / cbrt(y_m));
} else {
tmp = 0.5 * (y_m + (x * (x / y_m)));
}
return y_s * tmp;
}
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 (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -2e-56) {
tmp = Math.pow((z / Math.cbrt(y_m)), 2.0) * (-0.5 / Math.cbrt(y_m));
} else {
tmp = 0.5 * (y_m + (x * (x / y_m)));
}
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 (Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z * z)) / Float64(y_m * 2.0)) <= -2e-56) tmp = Float64((Float64(z / cbrt(y_m)) ^ 2.0) * Float64(-0.5 / cbrt(y_m))); else tmp = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m)))); 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[N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision], -2e-56], N[(N[Power[N[(z / N[Power[y$95$m, 1/3], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.5 / N[Power[y$95$m, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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}\;\frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2} \leq -2 \cdot 10^{-56}:\\
\;\;\;\;{\left(\frac{z}{\sqrt[3]{y\_m}}\right)}^{2} \cdot \frac{-0.5}{\sqrt[3]{y\_m}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{y\_m}\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < -2.0000000000000001e-56Initial program 73.6%
Taylor expanded in z around inf 26.4%
associate-*r/26.4%
metadata-eval26.4%
distribute-lft-neg-in26.4%
*-commutative26.4%
distribute-neg-frac26.4%
associate-*r/26.4%
distribute-rgt-neg-in26.4%
distribute-neg-frac26.4%
metadata-eval26.4%
Simplified26.4%
associate-*r/26.4%
clear-num26.4%
Applied egg-rr26.4%
clear-num26.4%
add-cube-cbrt26.3%
times-frac26.3%
pow226.3%
Applied egg-rr26.3%
*-un-lft-identity26.3%
add-sqr-sqrt26.3%
pow226.3%
sqrt-div26.3%
sqrt-pow127.2%
metadata-eval27.2%
pow127.2%
sqrt-pow127.2%
metadata-eval27.2%
pow127.2%
Applied egg-rr27.2%
*-lft-identity27.2%
Simplified27.2%
if -2.0000000000000001e-56 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) Initial program 59.8%
remove-double-neg59.8%
distribute-lft-neg-out59.8%
distribute-frac-neg259.8%
distribute-frac-neg59.8%
neg-mul-159.8%
distribute-lft-neg-out59.8%
*-commutative59.8%
distribute-lft-neg-in59.8%
times-frac59.8%
metadata-eval59.8%
metadata-eval59.8%
associate--l+59.8%
fma-define65.0%
Simplified65.0%
Taylor expanded in z around 0 46.3%
rem-square-sqrt46.3%
unpow246.3%
unpow246.3%
hypot-undefine46.3%
unpow246.3%
unpow246.3%
hypot-undefine46.3%
unpow246.3%
hypot-undefine46.3%
unpow246.3%
unpow246.3%
+-commutative46.3%
unpow246.3%
unpow246.3%
hypot-define46.3%
Simplified46.3%
Taylor expanded in x around 0 67.1%
unpow267.1%
associate-/l*70.1%
Applied egg-rr70.1%
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 (<= (/ (- (+ (* x x) (* y_m y_m)) (* z z)) (* y_m 2.0)) -2e-56)
(* (pow z 2.0) (/ -0.5 y_m))
(* 0.5 (+ y_m (* x (/ x y_m)))))))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 (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -2e-56) {
tmp = pow(z, 2.0) * (-0.5 / y_m);
} else {
tmp = 0.5 * (y_m + (x * (x / y_m)));
}
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 (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0d0)) <= (-2d-56)) then
tmp = (z ** 2.0d0) * ((-0.5d0) / y_m)
else
tmp = 0.5d0 * (y_m + (x * (x / y_m)))
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 (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -2e-56) {
tmp = Math.pow(z, 2.0) * (-0.5 / y_m);
} else {
tmp = 0.5 * (y_m + (x * (x / y_m)));
}
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 ((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -2e-56: tmp = math.pow(z, 2.0) * (-0.5 / y_m) else: tmp = 0.5 * (y_m + (x * (x / y_m))) 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 (Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z * z)) / Float64(y_m * 2.0)) <= -2e-56) tmp = Float64((z ^ 2.0) * Float64(-0.5 / y_m)); else tmp = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m)))); 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 (((((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0)) <= -2e-56) tmp = (z ^ 2.0) * (-0.5 / y_m); else tmp = 0.5 * (y_m + (x * (x / y_m))); 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[N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision], -2e-56], N[(N[Power[z, 2.0], $MachinePrecision] * N[(-0.5 / y$95$m), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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}\;\frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2} \leq -2 \cdot 10^{-56}:\\
\;\;\;\;{z}^{2} \cdot \frac{-0.5}{y\_m}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{y\_m}\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < -2.0000000000000001e-56Initial program 73.6%
Taylor expanded in z around inf 26.4%
associate-*r/26.4%
metadata-eval26.4%
distribute-lft-neg-in26.4%
*-commutative26.4%
distribute-neg-frac26.4%
associate-*r/26.4%
distribute-rgt-neg-in26.4%
distribute-neg-frac26.4%
metadata-eval26.4%
Simplified26.4%
if -2.0000000000000001e-56 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) Initial program 59.8%
remove-double-neg59.8%
distribute-lft-neg-out59.8%
distribute-frac-neg259.8%
distribute-frac-neg59.8%
neg-mul-159.8%
distribute-lft-neg-out59.8%
*-commutative59.8%
distribute-lft-neg-in59.8%
times-frac59.8%
metadata-eval59.8%
metadata-eval59.8%
associate--l+59.8%
fma-define65.0%
Simplified65.0%
Taylor expanded in z around 0 46.3%
rem-square-sqrt46.3%
unpow246.3%
unpow246.3%
hypot-undefine46.3%
unpow246.3%
unpow246.3%
hypot-undefine46.3%
unpow246.3%
hypot-undefine46.3%
unpow246.3%
unpow246.3%
+-commutative46.3%
unpow246.3%
unpow246.3%
hypot-define46.3%
Simplified46.3%
Taylor expanded in x around 0 67.1%
unpow267.1%
associate-/l*70.1%
Applied egg-rr70.1%
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 5.8e+143)
(* 0.5 (/ (fma x x (- (* y_m y_m) (* z z))) y_m))
(* 0.5 (+ y_m (* x (/ x y_m)))))))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 <= 5.8e+143) {
tmp = 0.5 * (fma(x, x, ((y_m * y_m) - (z * z))) / y_m);
} else {
tmp = 0.5 * (y_m + (x * (x / y_m)));
}
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 <= 5.8e+143) tmp = Float64(0.5 * Float64(fma(x, x, Float64(Float64(y_m * y_m) - Float64(z * z))) / y_m)); else tmp = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m)))); 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, 5.8e+143], 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[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 5.8 \cdot 10^{+143}:\\
\;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, y\_m \cdot y\_m - z \cdot z\right)}{y\_m}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{y\_m}\right)\\
\end{array}
\end{array}
if y < 5.7999999999999996e143Initial program 75.8%
remove-double-neg75.8%
distribute-lft-neg-out75.8%
distribute-frac-neg275.8%
distribute-frac-neg75.8%
neg-mul-175.8%
distribute-lft-neg-out75.8%
*-commutative75.8%
distribute-lft-neg-in75.8%
times-frac75.8%
metadata-eval75.8%
metadata-eval75.8%
associate--l+75.8%
fma-define79.5%
Simplified79.5%
if 5.7999999999999996e143 < y Initial program 9.0%
remove-double-neg9.0%
distribute-lft-neg-out9.0%
distribute-frac-neg29.0%
distribute-frac-neg9.0%
neg-mul-19.0%
distribute-lft-neg-out9.0%
*-commutative9.0%
distribute-lft-neg-in9.0%
times-frac9.0%
metadata-eval9.0%
metadata-eval9.0%
associate--l+9.0%
fma-define9.0%
Simplified9.0%
Taylor expanded in z around 0 12.7%
rem-square-sqrt12.7%
unpow212.7%
unpow212.7%
hypot-undefine12.7%
unpow212.7%
unpow212.7%
hypot-undefine12.7%
unpow212.7%
hypot-undefine12.7%
unpow212.7%
unpow212.7%
+-commutative12.7%
unpow212.7%
unpow212.7%
hypot-define12.7%
Simplified12.7%
Taylor expanded in x around 0 78.4%
unpow278.4%
associate-/l*87.5%
Applied egg-rr87.5%
y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) (FPCore (y_s x y_m z) :precision binary64 (let* ((t_0 (/ (- (+ (* x x) (* y_m y_m)) (* z z)) (* y_m 2.0)))) (* y_s (if (<= t_0 -2e-56) t_0 (* 0.5 (+ y_m (* x (/ x y_m))))))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z) {
double t_0 = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0);
double tmp;
if (t_0 <= -2e-56) {
tmp = t_0;
} else {
tmp = 0.5 * (y_m + (x * (x / y_m)));
}
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) :: t_0
real(8) :: tmp
t_0 = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0d0)
if (t_0 <= (-2d-56)) then
tmp = t_0
else
tmp = 0.5d0 * (y_m + (x * (x / y_m)))
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 t_0 = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0);
double tmp;
if (t_0 <= -2e-56) {
tmp = t_0;
} else {
tmp = 0.5 * (y_m + (x * (x / y_m)));
}
return y_s * tmp;
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z): t_0 = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0) tmp = 0 if t_0 <= -2e-56: tmp = t_0 else: tmp = 0.5 * (y_m + (x * (x / y_m))) return y_s * tmp
y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z) t_0 = Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z * z)) / Float64(y_m * 2.0)) tmp = 0.0 if (t_0 <= -2e-56) tmp = t_0; else tmp = Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m)))); 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) t_0 = (((x * x) + (y_m * y_m)) - (z * z)) / (y_m * 2.0); tmp = 0.0; if (t_0 <= -2e-56) tmp = t_0; else tmp = 0.5 * (y_m + (x * (x / y_m))); 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_] := Block[{t$95$0 = N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(y$95$s * If[LessEqual[t$95$0, -2e-56], t$95$0, N[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
\begin{array}{l}
t_0 := \frac{\left(x \cdot x + y\_m \cdot y\_m\right) - z \cdot z}{y\_m \cdot 2}\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-56}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(y\_m + x \cdot \frac{x}{y\_m}\right)\\
\end{array}
\end{array}
\end{array}
if (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < -2.0000000000000001e-56Initial program 73.6%
if -2.0000000000000001e-56 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) Initial program 59.8%
remove-double-neg59.8%
distribute-lft-neg-out59.8%
distribute-frac-neg259.8%
distribute-frac-neg59.8%
neg-mul-159.8%
distribute-lft-neg-out59.8%
*-commutative59.8%
distribute-lft-neg-in59.8%
times-frac59.8%
metadata-eval59.8%
metadata-eval59.8%
associate--l+59.8%
fma-define65.0%
Simplified65.0%
Taylor expanded in z around 0 46.3%
rem-square-sqrt46.3%
unpow246.3%
unpow246.3%
hypot-undefine46.3%
unpow246.3%
unpow246.3%
hypot-undefine46.3%
unpow246.3%
hypot-undefine46.3%
unpow246.3%
unpow246.3%
+-commutative46.3%
unpow246.3%
unpow246.3%
hypot-define46.3%
Simplified46.3%
Taylor expanded in x around 0 67.1%
unpow267.1%
associate-/l*70.1%
Applied egg-rr70.1%
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 (<= x 550000.0) (* y_m 0.5) (* 0.5 (* x (/ x y_m))))))
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 (x <= 550000.0) {
tmp = y_m * 0.5;
} else {
tmp = 0.5 * (x * (x / y_m));
}
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 (x <= 550000.0d0) then
tmp = y_m * 0.5d0
else
tmp = 0.5d0 * (x * (x / y_m))
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 (x <= 550000.0) {
tmp = y_m * 0.5;
} else {
tmp = 0.5 * (x * (x / y_m));
}
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 x <= 550000.0: tmp = y_m * 0.5 else: tmp = 0.5 * (x * (x / y_m)) 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 (x <= 550000.0) tmp = Float64(y_m * 0.5); else tmp = Float64(0.5 * Float64(x * Float64(x / y_m))); 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 (x <= 550000.0) tmp = y_m * 0.5; else tmp = 0.5 * (x * (x / y_m)); 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[x, 550000.0], N[(y$95$m * 0.5), $MachinePrecision], N[(0.5 * N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $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}\;x \leq 550000:\\
\;\;\;\;y\_m \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x \cdot \frac{x}{y\_m}\right)\\
\end{array}
\end{array}
if x < 5.5e5Initial program 65.3%
Taylor expanded in y around inf 45.5%
*-commutative45.5%
Simplified45.5%
if 5.5e5 < x Initial program 65.6%
remove-double-neg65.6%
distribute-lft-neg-out65.6%
distribute-frac-neg265.6%
distribute-frac-neg65.6%
neg-mul-165.6%
distribute-lft-neg-out65.6%
*-commutative65.6%
distribute-lft-neg-in65.6%
times-frac65.6%
metadata-eval65.6%
metadata-eval65.6%
associate--l+65.6%
fma-define73.4%
Simplified73.4%
Taylor expanded in z around 0 59.7%
rem-square-sqrt59.6%
unpow259.6%
unpow259.6%
hypot-undefine59.6%
unpow259.6%
unpow259.6%
hypot-undefine59.6%
unpow259.6%
hypot-undefine59.6%
unpow259.6%
unpow259.6%
+-commutative59.6%
unpow259.6%
unpow259.6%
hypot-define59.6%
Simplified59.6%
unpow259.6%
add-sqr-sqrt33.6%
times-frac42.0%
Applied egg-rr42.0%
unpow242.0%
Simplified42.0%
Taylor expanded in y around 0 34.6%
unpow234.6%
frac-times32.0%
add-sqr-sqrt57.0%
associate-*l/62.5%
Applied egg-rr62.5%
Final simplification49.7%
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 (* 0.5 (+ y_m (* x (/ x y_m))))))
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 * (0.5 * (y_m + (x * (x / y_m))));
}
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 * (0.5d0 * (y_m + (x * (x / y_m))))
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 * (0.5 * (y_m + (x * (x / y_m))));
}
y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z): return y_s * (0.5 * (y_m + (x * (x / y_m))))
y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z) return Float64(y_s * Float64(0.5 * Float64(y_m + Float64(x * Float64(x / y_m))))) end
y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp = code(y_s, x, y_m, z) tmp = y_s * (0.5 * (y_m + (x * (x / y_m)))); 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[(0.5 * N[(y$95$m + N[(x * N[(x / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \left(0.5 \cdot \left(y\_m + x \cdot \frac{x}{y\_m}\right)\right)
\end{array}
Initial program 65.4%
remove-double-neg65.4%
distribute-lft-neg-out65.4%
distribute-frac-neg265.4%
distribute-frac-neg65.4%
neg-mul-165.4%
distribute-lft-neg-out65.4%
*-commutative65.4%
distribute-lft-neg-in65.4%
times-frac65.4%
metadata-eval65.4%
metadata-eval65.4%
associate--l+65.4%
fma-define68.5%
Simplified68.5%
Taylor expanded in z around 0 47.2%
rem-square-sqrt47.2%
unpow247.2%
unpow247.2%
hypot-undefine47.2%
unpow247.2%
unpow247.2%
hypot-undefine47.2%
unpow247.2%
hypot-undefine47.2%
unpow247.2%
unpow247.2%
+-commutative47.2%
unpow247.2%
unpow247.2%
hypot-define47.2%
Simplified47.2%
Taylor expanded in x around 0 67.7%
unpow267.7%
associate-/l*71.6%
Applied egg-rr71.6%
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 65.4%
Taylor expanded in y around inf 39.1%
*-commutative39.1%
Simplified39.1%
(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 2024089
(FPCore (x y z)
:name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
:precision binary64
:alt
(- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))
(/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))