
(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.15e+146)
(* 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.15e+146) {
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.15e+146) 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.15e+146], 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.15 \cdot 10^{+146}:\\
\;\;\;\;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.15e146Initial 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%
if 1.15e146 < y Initial program 12.2%
remove-double-neg12.2%
distribute-lft-neg-out12.2%
distribute-frac-neg212.2%
distribute-frac-neg12.2%
neg-mul-112.2%
distribute-lft-neg-out12.2%
*-commutative12.2%
distribute-lft-neg-in12.2%
times-frac12.2%
metadata-eval12.2%
metadata-eval12.2%
associate--l+12.2%
fma-define12.2%
Simplified12.2%
Taylor expanded in y around inf 83.4%
Final simplification81.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 1.15e+146)
(/ (- (+ (* 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.15e+146) {
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.15d+146) 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.15e+146) {
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.15e+146: 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.15e+146) 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.15e+146) 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.15e+146], 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.15 \cdot 10^{+146}:\\
\;\;\;\;\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.15e146Initial program 79.6%
if 1.15e146 < y Initial program 12.2%
remove-double-neg12.2%
distribute-lft-neg-out12.2%
distribute-frac-neg212.2%
distribute-frac-neg12.2%
neg-mul-112.2%
distribute-lft-neg-out12.2%
*-commutative12.2%
distribute-lft-neg-in12.2%
times-frac12.2%
metadata-eval12.2%
metadata-eval12.2%
associate--l+12.2%
fma-define12.2%
Simplified12.2%
Taylor expanded in y around inf 83.4%
Final simplification80.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 4500000000.0)
(* (* x x) (/ 0.5 y_m))
(if (<= y_m 1.5e+69) (/ (* 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 <= 4500000000.0) {
tmp = (x * x) * (0.5 / y_m);
} else if (y_m <= 1.5e+69) {
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 <= 4500000000.0d0) then
tmp = (x * x) * (0.5d0 / y_m)
else if (y_m <= 1.5d+69) 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 <= 4500000000.0) {
tmp = (x * x) * (0.5 / y_m);
} else if (y_m <= 1.5e+69) {
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 <= 4500000000.0: tmp = (x * x) * (0.5 / y_m) elif y_m <= 1.5e+69: 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 <= 4500000000.0) tmp = Float64(Float64(x * x) * Float64(0.5 / y_m)); elseif (y_m <= 1.5e+69) tmp = Float64(Float64(z * Float64(z * -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 <= 4500000000.0) tmp = (x * x) * (0.5 / y_m); elseif (y_m <= 1.5e+69) 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, 4500000000.0], N[(N[(x * x), $MachinePrecision] * N[(0.5 / y$95$m), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$95$m, 1.5e+69], N[(N[(z * N[(z * -0.5), $MachinePrecision]), $MachinePrecision] / y$95$m), $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 4500000000:\\
\;\;\;\;\left(x \cdot x\right) \cdot \frac{0.5}{y\_m}\\
\mathbf{elif}\;y\_m \leq 1.5 \cdot 10^{+69}:\\
\;\;\;\;\frac{z \cdot \left(z \cdot -0.5\right)}{y\_m}\\
\mathbf{else}:\\
\;\;\;\;y\_m \cdot 0.5\\
\end{array}
\end{array}
if y < 4.5e9Initial program 77.5%
remove-double-neg77.5%
distribute-lft-neg-out77.5%
distribute-frac-neg277.5%
distribute-frac-neg77.5%
neg-mul-177.5%
distribute-lft-neg-out77.5%
*-commutative77.5%
distribute-lft-neg-in77.5%
times-frac77.5%
metadata-eval77.5%
metadata-eval77.5%
associate--l+77.5%
fma-define78.6%
Simplified78.6%
Taylor expanded in x around inf 41.2%
*-commutative41.2%
associate-*l/41.2%
associate-*r/41.2%
Simplified41.2%
pow241.2%
Applied egg-rr41.2%
if 4.5e9 < y < 1.49999999999999992e69Initial program 100.0%
remove-double-neg100.0%
distribute-lft-neg-out100.0%
distribute-frac-neg2100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
times-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
associate--l+100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 59.1%
*-commutative59.1%
associate-*l/59.1%
Simplified59.1%
pow259.1%
associate-/l*58.8%
associate-*l*58.9%
Applied egg-rr58.9%
*-commutative58.9%
associate-*r/59.1%
associate-*l/59.1%
Applied egg-rr59.1%
if 1.49999999999999992e69 < y Initial program 32.7%
remove-double-neg32.7%
distribute-lft-neg-out32.7%
distribute-frac-neg232.7%
distribute-frac-neg32.7%
neg-mul-132.7%
distribute-lft-neg-out32.7%
*-commutative32.7%
distribute-lft-neg-in32.7%
times-frac32.7%
metadata-eval32.7%
metadata-eval32.7%
associate--l+32.7%
fma-define32.7%
Simplified32.7%
Taylor expanded in y around inf 75.5%
Final simplification50.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 1.6e+29)
(* (* x x) (/ 0.5 y_m))
(if (<= y_m 6.8e+70) (* 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.6e+29) {
tmp = (x * x) * (0.5 / y_m);
} else if (y_m <= 6.8e+70) {
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.6d+29) then
tmp = (x * x) * (0.5d0 / y_m)
else if (y_m <= 6.8d+70) 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.6e+29) {
tmp = (x * x) * (0.5 / y_m);
} else if (y_m <= 6.8e+70) {
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.6e+29: tmp = (x * x) * (0.5 / y_m) elif y_m <= 6.8e+70: 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.6e+29) tmp = Float64(Float64(x * x) * Float64(0.5 / y_m)); elseif (y_m <= 6.8e+70) tmp = Float64(z * Float64(Float64(z * -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.6e+29) tmp = (x * x) * (0.5 / y_m); elseif (y_m <= 6.8e+70) 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.6e+29], N[(N[(x * x), $MachinePrecision] * N[(0.5 / y$95$m), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$95$m, 6.8e+70], N[(z * N[(N[(z * -0.5), $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.6 \cdot 10^{+29}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \frac{0.5}{y\_m}\\
\mathbf{elif}\;y\_m \leq 6.8 \cdot 10^{+70}:\\
\;\;\;\;z \cdot \frac{z \cdot -0.5}{y\_m}\\
\mathbf{else}:\\
\;\;\;\;y\_m \cdot 0.5\\
\end{array}
\end{array}
if y < 1.59999999999999993e29Initial program 77.6%
remove-double-neg77.6%
distribute-lft-neg-out77.6%
distribute-frac-neg277.6%
distribute-frac-neg77.6%
neg-mul-177.6%
distribute-lft-neg-out77.6%
*-commutative77.6%
distribute-lft-neg-in77.6%
times-frac77.6%
metadata-eval77.6%
metadata-eval77.6%
associate--l+77.6%
fma-define78.7%
Simplified78.7%
Taylor expanded in x around inf 41.5%
*-commutative41.5%
associate-*l/41.5%
associate-*r/41.5%
Simplified41.5%
pow241.5%
Applied egg-rr41.5%
if 1.59999999999999993e29 < y < 6.8000000000000002e70Initial program 100.0%
remove-double-neg100.0%
distribute-lft-neg-out100.0%
distribute-frac-neg2100.0%
distribute-frac-neg100.0%
neg-mul-1100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
times-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
associate--l+100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around inf 64.4%
*-commutative64.4%
associate-*l/64.4%
Simplified64.4%
pow264.4%
associate-/l*64.1%
associate-*l*64.3%
Applied egg-rr64.3%
associate-*r/64.4%
Applied egg-rr64.4%
if 6.8000000000000002e70 < y Initial program 32.7%
remove-double-neg32.7%
distribute-lft-neg-out32.7%
distribute-frac-neg232.7%
distribute-frac-neg32.7%
neg-mul-132.7%
distribute-lft-neg-out32.7%
*-commutative32.7%
distribute-lft-neg-in32.7%
times-frac32.7%
metadata-eval32.7%
metadata-eval32.7%
associate--l+32.7%
fma-define32.7%
Simplified32.7%
Taylor expanded in y around inf 75.5%
Final simplification50.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 5.8e+69) (* 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 <= 5.8e+69) {
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 <= 5.8d+69) 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 <= 5.8e+69) {
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 <= 5.8e+69: 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 <= 5.8e+69) tmp = Float64(z * Float64(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 <= 5.8e+69) 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, 5.8e+69], N[(z * N[(z * N[(-0.5 / y$95$m), $MachinePrecision]), $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 5.8 \cdot 10^{+69}:\\
\;\;\;\;z \cdot \left(z \cdot \frac{-0.5}{y\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;y\_m \cdot 0.5\\
\end{array}
\end{array}
if y < 5.7999999999999997e69Initial program 78.9%
remove-double-neg78.9%
distribute-lft-neg-out78.9%
distribute-frac-neg278.9%
distribute-frac-neg78.9%
neg-mul-178.9%
distribute-lft-neg-out78.9%
*-commutative78.9%
distribute-lft-neg-in78.9%
times-frac78.9%
metadata-eval78.9%
metadata-eval78.9%
associate--l+78.9%
fma-define79.9%
Simplified79.9%
Taylor expanded in z around inf 33.5%
*-commutative33.5%
associate-*l/33.5%
Simplified33.5%
pow233.5%
associate-/l*33.4%
associate-*l*34.4%
Applied egg-rr34.4%
if 5.7999999999999997e69 < y Initial program 32.7%
remove-double-neg32.7%
distribute-lft-neg-out32.7%
distribute-frac-neg232.7%
distribute-frac-neg32.7%
neg-mul-132.7%
distribute-lft-neg-out32.7%
*-commutative32.7%
distribute-lft-neg-in32.7%
times-frac32.7%
metadata-eval32.7%
metadata-eval32.7%
associate--l+32.7%
fma-define32.7%
Simplified32.7%
Taylor expanded in y around inf 75.5%
Final simplification44.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 (* 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 67.5%
remove-double-neg67.5%
distribute-lft-neg-out67.5%
distribute-frac-neg267.5%
distribute-frac-neg67.5%
neg-mul-167.5%
distribute-lft-neg-out67.5%
*-commutative67.5%
distribute-lft-neg-in67.5%
times-frac67.5%
metadata-eval67.5%
metadata-eval67.5%
associate--l+67.5%
fma-define68.3%
Simplified68.3%
Taylor expanded in y around inf 39.4%
Final simplification39.4%
(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 2024135
(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)))