
(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}
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
:precision binary64
(let* ((t_0 (/ (- (+ (* x x) (* y_m y_m)) (* z_m z_m)) (* y_m 2.0))))
(*
y_s
(if (or (<= t_0 0.0) (not (<= t_0 INFINITY)))
(* 0.5 (* (+ y_m z_m) (/ (- y_m z_m) y_m)))
(* 0.5 (/ (hypot x y_m) (/ y_m (hypot x y_m))))))))z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
double t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
double tmp;
if ((t_0 <= 0.0) || !(t_0 <= ((double) INFINITY))) {
tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
} else {
tmp = 0.5 * (hypot(x, y_m) / (y_m / hypot(x, y_m)));
}
return y_s * tmp;
}
z_m = Math.abs(z);
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_m) {
double t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
double tmp;
if ((t_0 <= 0.0) || !(t_0 <= Double.POSITIVE_INFINITY)) {
tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
} else {
tmp = 0.5 * (Math.hypot(x, y_m) / (y_m / Math.hypot(x, y_m)));
}
return y_s * tmp;
}
z_m = math.fabs(z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z_m): t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0) tmp = 0 if (t_0 <= 0.0) or not (t_0 <= math.inf): tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m)) else: tmp = 0.5 * (math.hypot(x, y_m) / (y_m / math.hypot(x, y_m))) return y_s * tmp
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) t_0 = Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z_m * z_m)) / Float64(y_m * 2.0)) tmp = 0.0 if ((t_0 <= 0.0) || !(t_0 <= Inf)) tmp = Float64(0.5 * Float64(Float64(y_m + z_m) * Float64(Float64(y_m - z_m) / y_m))); else tmp = Float64(0.5 * Float64(hypot(x, y_m) / Float64(y_m / hypot(x, y_m)))); end return Float64(y_s * tmp) end
z_m = abs(z); y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z_m) t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0); tmp = 0.0; if ((t_0 <= 0.0) || ~((t_0 <= Inf))) tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m)); else tmp = 0.5 * (hypot(x, y_m) / (y_m / hypot(x, y_m))); end tmp_2 = y_s * tmp; end
z_m = N[Abs[z], $MachinePrecision]
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$95$m_] := Block[{t$95$0 = N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(y$95$s * If[Or[LessEqual[t$95$0, 0.0], N[Not[LessEqual[t$95$0, Infinity]], $MachinePrecision]], N[(0.5 * N[(N[(y$95$m + z$95$m), $MachinePrecision] * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision] / N[(y$95$m / N[Sqrt[x ^ 2 + y$95$m ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
z_m = \left|z\right|
\\
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\_m \cdot z\_m}{y\_m \cdot 2}\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq \infty\right):\\
\;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \frac{y\_m - z\_m}{y\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{\mathsf{hypot}\left(x, y\_m\right)}{\frac{y\_m}{\mathsf{hypot}\left(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))) < 0.0 or +inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) Initial program 61.5%
remove-double-neg61.5%
distribute-lft-neg-out61.5%
distribute-frac-neg261.5%
distribute-frac-neg61.5%
neg-mul-161.5%
distribute-lft-neg-out61.5%
*-commutative61.5%
distribute-lft-neg-in61.5%
times-frac61.5%
metadata-eval61.5%
metadata-eval61.5%
associate--l+61.5%
fma-define66.7%
Simplified66.7%
difference-of-squares70.2%
*-commutative70.2%
Applied egg-rr70.2%
Taylor expanded in x around 0 48.8%
associate-/l*71.2%
Simplified71.2%
if 0.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < +inf.0Initial program 75.1%
remove-double-neg75.1%
distribute-lft-neg-out75.1%
distribute-frac-neg275.1%
distribute-frac-neg75.1%
neg-mul-175.1%
distribute-lft-neg-out75.1%
*-commutative75.1%
distribute-lft-neg-in75.1%
times-frac75.1%
metadata-eval75.1%
metadata-eval75.1%
associate--l+75.1%
fma-define75.1%
Simplified75.1%
Taylor expanded in z around 0 46.7%
+-commutative46.7%
unpow246.7%
fma-undefine46.7%
Simplified46.7%
fma-undefine46.7%
pow246.7%
+-commutative46.7%
add-sqr-sqrt46.4%
sqrt-div46.4%
hypot-define46.4%
sqrt-div46.3%
hypot-define69.3%
Applied egg-rr69.3%
unpow269.3%
hypot-undefine46.3%
unpow246.3%
unpow246.3%
+-commutative46.3%
unpow246.3%
unpow246.3%
hypot-define69.3%
Simplified69.3%
unpow269.3%
clear-num69.2%
frac-times69.3%
*-un-lft-identity69.3%
Applied egg-rr69.3%
hypot-undefine46.3%
unpow246.3%
unpow246.3%
+-commutative46.3%
unpow246.3%
unpow246.3%
hypot-undefine69.3%
associate-*l/69.3%
rem-square-sqrt69.9%
hypot-undefine46.7%
unpow246.7%
unpow246.7%
+-commutative46.7%
unpow246.7%
unpow246.7%
hypot-undefine69.9%
Simplified69.9%
Final simplification70.6%
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
:precision binary64
(*
y_s
(if (<= y_m 3.7e+112)
(* 0.5 (/ (fma x x (* (+ y_m z_m) (- y_m z_m))) y_m))
(* 0.5 (* (+ y_m z_m) (/ (- y_m z_m) y_m))))))z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
double tmp;
if (y_m <= 3.7e+112) {
tmp = 0.5 * (fma(x, x, ((y_m + z_m) * (y_m - z_m))) / y_m);
} else {
tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
}
return y_s * tmp;
}
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) tmp = 0.0 if (y_m <= 3.7e+112) tmp = Float64(0.5 * Float64(fma(x, x, Float64(Float64(y_m + z_m) * Float64(y_m - z_m))) / y_m)); else tmp = Float64(0.5 * Float64(Float64(y_m + z_m) * Float64(Float64(y_m - z_m) / y_m))); end return Float64(y_s * tmp) end
z_m = N[Abs[z], $MachinePrecision]
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$95$m_] := N[(y$95$s * If[LessEqual[y$95$m, 3.7e+112], N[(0.5 * N[(N[(x * x + N[(N[(y$95$m + z$95$m), $MachinePrecision] * N[(y$95$m - z$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(y$95$m + z$95$m), $MachinePrecision] * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 3.7 \cdot 10^{+112}:\\
\;\;\;\;0.5 \cdot \frac{\mathsf{fma}\left(x, x, \left(y\_m + z\_m\right) \cdot \left(y\_m - z\_m\right)\right)}{y\_m}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \frac{y\_m - z\_m}{y\_m}\right)\\
\end{array}
\end{array}
if y < 3.70000000000000004e112Initial program 79.3%
remove-double-neg79.3%
distribute-lft-neg-out79.3%
distribute-frac-neg279.3%
distribute-frac-neg79.3%
neg-mul-179.3%
distribute-lft-neg-out79.3%
*-commutative79.3%
distribute-lft-neg-in79.3%
times-frac79.3%
metadata-eval79.3%
metadata-eval79.3%
associate--l+79.3%
fma-define82.8%
Simplified82.8%
difference-of-squares83.9%
*-commutative83.9%
Applied egg-rr83.9%
if 3.70000000000000004e112 < y Initial program 26.2%
remove-double-neg26.2%
distribute-lft-neg-out26.2%
distribute-frac-neg226.2%
distribute-frac-neg26.2%
neg-mul-126.2%
distribute-lft-neg-out26.2%
*-commutative26.2%
distribute-lft-neg-in26.2%
times-frac26.2%
metadata-eval26.2%
metadata-eval26.2%
associate--l+26.2%
fma-define26.2%
Simplified26.2%
difference-of-squares30.7%
*-commutative30.7%
Applied egg-rr30.7%
Taylor expanded in x around 0 29.0%
associate-/l*87.8%
Simplified87.8%
Final simplification84.8%
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
:precision binary64
(let* ((t_0 (/ (- (+ (* x x) (* y_m y_m)) (* z_m z_m)) (* y_m 2.0))))
(*
y_s
(if (or (<= t_0 0.0) (not (<= t_0 INFINITY)))
(* 0.5 (* (+ y_m z_m) (/ (- y_m z_m) y_m)))
(* 0.5 (+ y_m (/ (* x x) y_m)))))))z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
double t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
double tmp;
if ((t_0 <= 0.0) || !(t_0 <= ((double) INFINITY))) {
tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
} else {
tmp = 0.5 * (y_m + ((x * x) / y_m));
}
return y_s * tmp;
}
z_m = Math.abs(z);
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_m) {
double t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0);
double tmp;
if ((t_0 <= 0.0) || !(t_0 <= Double.POSITIVE_INFINITY)) {
tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m));
} else {
tmp = 0.5 * (y_m + ((x * x) / y_m));
}
return y_s * tmp;
}
z_m = math.fabs(z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z_m): t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0) tmp = 0 if (t_0 <= 0.0) or not (t_0 <= math.inf): tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m)) else: tmp = 0.5 * (y_m + ((x * x) / y_m)) return y_s * tmp
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) t_0 = Float64(Float64(Float64(Float64(x * x) + Float64(y_m * y_m)) - Float64(z_m * z_m)) / Float64(y_m * 2.0)) tmp = 0.0 if ((t_0 <= 0.0) || !(t_0 <= Inf)) tmp = Float64(0.5 * Float64(Float64(y_m + z_m) * Float64(Float64(y_m - z_m) / y_m))); else tmp = Float64(0.5 * Float64(y_m + Float64(Float64(x * x) / y_m))); end return Float64(y_s * tmp) end
z_m = abs(z); y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z_m) t_0 = (((x * x) + (y_m * y_m)) - (z_m * z_m)) / (y_m * 2.0); tmp = 0.0; if ((t_0 <= 0.0) || ~((t_0 <= Inf))) tmp = 0.5 * ((y_m + z_m) * ((y_m - z_m) / y_m)); else tmp = 0.5 * (y_m + ((x * x) / y_m)); end tmp_2 = y_s * tmp; end
z_m = N[Abs[z], $MachinePrecision]
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$95$m_] := Block[{t$95$0 = N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision] - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(y$95$s * If[Or[LessEqual[t$95$0, 0.0], N[Not[LessEqual[t$95$0, Infinity]], $MachinePrecision]], N[(0.5 * N[(N[(y$95$m + z$95$m), $MachinePrecision] * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(y$95$m + N[(N[(x * x), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
z_m = \left|z\right|
\\
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\_m \cdot z\_m}{y\_m \cdot 2}\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq \infty\right):\\
\;\;\;\;0.5 \cdot \left(\left(y\_m + z\_m\right) \cdot \frac{y\_m - z\_m}{y\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(y\_m + \frac{x \cdot 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))) < 0.0 or +inf.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) Initial program 61.5%
remove-double-neg61.5%
distribute-lft-neg-out61.5%
distribute-frac-neg261.5%
distribute-frac-neg61.5%
neg-mul-161.5%
distribute-lft-neg-out61.5%
*-commutative61.5%
distribute-lft-neg-in61.5%
times-frac61.5%
metadata-eval61.5%
metadata-eval61.5%
associate--l+61.5%
fma-define66.7%
Simplified66.7%
difference-of-squares70.2%
*-commutative70.2%
Applied egg-rr70.2%
Taylor expanded in x around 0 48.8%
associate-/l*71.2%
Simplified71.2%
if 0.0 < (/.f64 (-.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) (*.f64 y #s(literal 2 binary64))) < +inf.0Initial program 75.1%
remove-double-neg75.1%
distribute-lft-neg-out75.1%
distribute-frac-neg275.1%
distribute-frac-neg75.1%
neg-mul-175.1%
distribute-lft-neg-out75.1%
*-commutative75.1%
distribute-lft-neg-in75.1%
times-frac75.1%
metadata-eval75.1%
metadata-eval75.1%
associate--l+75.1%
fma-define75.1%
Simplified75.1%
Taylor expanded in z around 0 46.7%
+-commutative46.7%
unpow246.7%
fma-undefine46.7%
Simplified46.7%
Taylor expanded in x around 0 62.3%
distribute-lft-out62.3%
Simplified62.3%
pow262.3%
Applied egg-rr62.3%
Final simplification67.0%
z_m = (fabs.f64 z)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
(FPCore (y_s x y_m z_m)
:precision binary64
(*
y_s
(if (<= z_m 2.1e+141)
(* 0.5 (+ y_m (/ (* x x) y_m)))
(* 0.5 (* z_m (/ (- y_m z_m) y_m))))))z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
double tmp;
if (z_m <= 2.1e+141) {
tmp = 0.5 * (y_m + ((x * x) / y_m));
} else {
tmp = 0.5 * (z_m * ((y_m - z_m) / y_m));
}
return y_s * tmp;
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z_m)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8) :: tmp
if (z_m <= 2.1d+141) then
tmp = 0.5d0 * (y_m + ((x * x) / y_m))
else
tmp = 0.5d0 * (z_m * ((y_m - z_m) / y_m))
end if
code = y_s * tmp
end function
z_m = Math.abs(z);
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_m) {
double tmp;
if (z_m <= 2.1e+141) {
tmp = 0.5 * (y_m + ((x * x) / y_m));
} else {
tmp = 0.5 * (z_m * ((y_m - z_m) / y_m));
}
return y_s * tmp;
}
z_m = math.fabs(z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z_m): tmp = 0 if z_m <= 2.1e+141: tmp = 0.5 * (y_m + ((x * x) / y_m)) else: tmp = 0.5 * (z_m * ((y_m - z_m) / y_m)) return y_s * tmp
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) tmp = 0.0 if (z_m <= 2.1e+141) tmp = Float64(0.5 * Float64(y_m + Float64(Float64(x * x) / y_m))); else tmp = Float64(0.5 * Float64(z_m * Float64(Float64(y_m - z_m) / y_m))); end return Float64(y_s * tmp) end
z_m = abs(z); y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z_m) tmp = 0.0; if (z_m <= 2.1e+141) tmp = 0.5 * (y_m + ((x * x) / y_m)); else tmp = 0.5 * (z_m * ((y_m - z_m) / y_m)); end tmp_2 = y_s * tmp; end
z_m = N[Abs[z], $MachinePrecision]
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$95$m_] := N[(y$95$s * If[LessEqual[z$95$m, 2.1e+141], N[(0.5 * N[(y$95$m + N[(N[(x * x), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(z$95$m * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 2.1 \cdot 10^{+141}:\\
\;\;\;\;0.5 \cdot \left(y\_m + \frac{x \cdot x}{y\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(z\_m \cdot \frac{y\_m - z\_m}{y\_m}\right)\\
\end{array}
\end{array}
if z < 2.0999999999999998e141Initial program 74.0%
remove-double-neg74.0%
distribute-lft-neg-out74.0%
distribute-frac-neg274.0%
distribute-frac-neg74.0%
neg-mul-174.0%
distribute-lft-neg-out74.0%
*-commutative74.0%
distribute-lft-neg-in74.0%
times-frac74.0%
metadata-eval74.0%
metadata-eval74.0%
associate--l+74.0%
fma-define75.4%
Simplified75.4%
Taylor expanded in z around 0 49.8%
+-commutative49.8%
unpow249.8%
fma-undefine49.8%
Simplified49.8%
Taylor expanded in x around 0 65.8%
distribute-lft-out65.8%
Simplified65.8%
pow265.8%
Applied egg-rr65.8%
if 2.0999999999999998e141 < z Initial program 35.4%
remove-double-neg35.4%
distribute-lft-neg-out35.4%
distribute-frac-neg235.4%
distribute-frac-neg35.4%
neg-mul-135.4%
distribute-lft-neg-out35.4%
*-commutative35.4%
distribute-lft-neg-in35.4%
times-frac35.4%
metadata-eval35.4%
metadata-eval35.4%
associate--l+35.4%
fma-define45.3%
Simplified45.3%
difference-of-squares56.4%
*-commutative56.4%
Applied egg-rr56.4%
Taylor expanded in x around 0 56.4%
associate-/l*85.5%
Simplified85.5%
Taylor expanded in y around 0 69.3%
z_m = (fabs.f64 z) y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) (FPCore (y_s x y_m z_m) :precision binary64 (* y_s (if (<= y_m 9.2e+113) (* 0.5 (* z_m (/ (- y_m z_m) y_m))) (* y_m 0.5))))
z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
double tmp;
if (y_m <= 9.2e+113) {
tmp = 0.5 * (z_m * ((y_m - z_m) / y_m));
} else {
tmp = y_m * 0.5;
}
return y_s * tmp;
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z_m)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8) :: tmp
if (y_m <= 9.2d+113) then
tmp = 0.5d0 * (z_m * ((y_m - z_m) / y_m))
else
tmp = y_m * 0.5d0
end if
code = y_s * tmp
end function
z_m = Math.abs(z);
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_m) {
double tmp;
if (y_m <= 9.2e+113) {
tmp = 0.5 * (z_m * ((y_m - z_m) / y_m));
} else {
tmp = y_m * 0.5;
}
return y_s * tmp;
}
z_m = math.fabs(z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z_m): tmp = 0 if y_m <= 9.2e+113: tmp = 0.5 * (z_m * ((y_m - z_m) / y_m)) else: tmp = y_m * 0.5 return y_s * tmp
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) tmp = 0.0 if (y_m <= 9.2e+113) tmp = Float64(0.5 * Float64(z_m * Float64(Float64(y_m - z_m) / y_m))); else tmp = Float64(y_m * 0.5); end return Float64(y_s * tmp) end
z_m = abs(z); y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp_2 = code(y_s, x, y_m, z_m) tmp = 0.0; if (y_m <= 9.2e+113) tmp = 0.5 * (z_m * ((y_m - z_m) / y_m)); else tmp = y_m * 0.5; end tmp_2 = y_s * tmp; end
z_m = N[Abs[z], $MachinePrecision]
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$95$m_] := N[(y$95$s * If[LessEqual[y$95$m, 9.2e+113], N[(0.5 * N[(z$95$m * N[(N[(y$95$m - z$95$m), $MachinePrecision] / y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y$95$m * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
y\_s \cdot \begin{array}{l}
\mathbf{if}\;y\_m \leq 9.2 \cdot 10^{+113}:\\
\;\;\;\;0.5 \cdot \left(z\_m \cdot \frac{y\_m - z\_m}{y\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;y\_m \cdot 0.5\\
\end{array}
\end{array}
if y < 9.19999999999999987e113Initial program 78.6%
remove-double-neg78.6%
distribute-lft-neg-out78.6%
distribute-frac-neg278.6%
distribute-frac-neg78.6%
neg-mul-178.6%
distribute-lft-neg-out78.6%
*-commutative78.6%
distribute-lft-neg-in78.6%
times-frac78.6%
metadata-eval78.6%
metadata-eval78.6%
associate--l+78.6%
fma-define82.0%
Simplified82.0%
difference-of-squares83.2%
*-commutative83.2%
Applied egg-rr83.2%
Taylor expanded in x around 0 55.8%
associate-/l*67.6%
Simplified67.6%
Taylor expanded in y around 0 42.0%
if 9.19999999999999987e113 < 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 74.9%
Final simplification48.8%
z_m = (fabs.f64 z) y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) (FPCore (y_s x y_m z_m) :precision binary64 (* y_s (* y_m 0.5)))
z_m = fabs(z);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
double code(double y_s, double x, double y_m, double z_m) {
return y_s * (y_m * 0.5);
}
z_m = abs(z)
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
real(8) function code(y_s, x, y_m, z_m)
real(8), intent (in) :: y_s
real(8), intent (in) :: x
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
code = y_s * (y_m * 0.5d0)
end function
z_m = Math.abs(z);
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_m) {
return y_s * (y_m * 0.5);
}
z_m = math.fabs(z) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) def code(y_s, x, y_m, z_m): return y_s * (y_m * 0.5)
z_m = abs(z) y\_m = abs(y) y\_s = copysign(1.0, y) function code(y_s, x, y_m, z_m) return Float64(y_s * Float64(y_m * 0.5)) end
z_m = abs(z); y\_m = abs(y); y\_s = sign(y) * abs(1.0); function tmp = code(y_s, x, y_m, z_m) tmp = y_s * (y_m * 0.5); end
z_m = N[Abs[z], $MachinePrecision]
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$95$m_] := N[(y$95$s * N[(y$95$m * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
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 67.9%
remove-double-neg67.9%
distribute-lft-neg-out67.9%
distribute-frac-neg267.9%
distribute-frac-neg67.9%
neg-mul-167.9%
distribute-lft-neg-out67.9%
*-commutative67.9%
distribute-lft-neg-in67.9%
times-frac67.9%
metadata-eval67.9%
metadata-eval67.9%
associate--l+67.9%
fma-define70.6%
Simplified70.6%
Taylor expanded in y around inf 37.0%
Final simplification37.0%
(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 2024160
(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)))