
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m y z)
:precision binary64
(*
x_s
(if (<= (/ (* x_m (+ y z)) z) -5e+21)
(/ (* x_m y) z)
(* x_m (- (/ y z) -1.0)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (((x_m * (y + z)) / z) <= -5e+21) {
tmp = (x_m * y) / z;
} else {
tmp = x_m * ((y / z) - -1.0);
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (((x_m * (y + z)) / z) <= (-5d+21)) then
tmp = (x_m * y) / z
else
tmp = x_m * ((y / z) - (-1.0d0))
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (((x_m * (y + z)) / z) <= -5e+21) {
tmp = (x_m * y) / z;
} else {
tmp = x_m * ((y / z) - -1.0);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if ((x_m * (y + z)) / z) <= -5e+21: tmp = (x_m * y) / z else: tmp = x_m * ((y / z) - -1.0) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (Float64(Float64(x_m * Float64(y + z)) / z) <= -5e+21) tmp = Float64(Float64(x_m * y) / z); else tmp = Float64(x_m * Float64(Float64(y / z) - -1.0)); end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (((x_m * (y + z)) / z) <= -5e+21) tmp = (x_m * y) / z; else tmp = x_m * ((y / z) - -1.0); end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[N[(N[(x$95$m * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], -5e+21], N[(N[(x$95$m * y), $MachinePrecision] / z), $MachinePrecision], N[(x$95$m * N[(N[(y / z), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{x\_m \cdot \left(y + z\right)}{z} \leq -5 \cdot 10^{+21}:\\
\;\;\;\;\frac{x\_m \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot \left(\frac{y}{z} - -1\right)\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 y z)) z) < -5e21Initial program 82.1%
associate-/l*95.0%
remove-double-neg95.0%
distribute-frac-neg295.0%
neg-sub095.0%
remove-double-neg95.0%
unsub-neg95.0%
div-sub95.1%
*-inverses95.1%
metadata-eval95.1%
associate--r-95.1%
neg-sub095.1%
distribute-frac-neg295.1%
remove-double-neg95.1%
sub-neg95.1%
Simplified95.1%
Taylor expanded in y around inf 61.3%
if -5e21 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 82.5%
associate-/l*96.1%
remove-double-neg96.1%
distribute-frac-neg296.1%
neg-sub096.1%
remove-double-neg96.1%
unsub-neg96.1%
div-sub96.2%
*-inverses96.2%
metadata-eval96.2%
associate--r-96.2%
neg-sub096.2%
distribute-frac-neg296.2%
remove-double-neg96.2%
sub-neg96.2%
Simplified96.2%
Final simplification85.5%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= z -6.6e+51) x_m (if (<= z 2.9e+37) (* y (/ x_m z)) x_m))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (z <= -6.6e+51) {
tmp = x_m;
} else if (z <= 2.9e+37) {
tmp = y * (x_m / z);
} else {
tmp = x_m;
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-6.6d+51)) then
tmp = x_m
else if (z <= 2.9d+37) then
tmp = y * (x_m / z)
else
tmp = x_m
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (z <= -6.6e+51) {
tmp = x_m;
} else if (z <= 2.9e+37) {
tmp = y * (x_m / z);
} else {
tmp = x_m;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if z <= -6.6e+51: tmp = x_m elif z <= 2.9e+37: tmp = y * (x_m / z) else: tmp = x_m return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (z <= -6.6e+51) tmp = x_m; elseif (z <= 2.9e+37) tmp = Float64(y * Float64(x_m / z)); else tmp = x_m; end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (z <= -6.6e+51) tmp = x_m; elseif (z <= 2.9e+37) tmp = y * (x_m / z); else tmp = x_m; end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[z, -6.6e+51], x$95$m, If[LessEqual[z, 2.9e+37], N[(y * N[(x$95$m / z), $MachinePrecision]), $MachinePrecision], x$95$m]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{+51}:\\
\;\;\;\;x\_m\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{+37}:\\
\;\;\;\;y \cdot \frac{x\_m}{z}\\
\mathbf{else}:\\
\;\;\;\;x\_m\\
\end{array}
\end{array}
if z < -6.5999999999999994e51 or 2.89999999999999978e37 < z Initial program 70.7%
associate-/l*99.8%
remove-double-neg99.8%
distribute-frac-neg299.8%
neg-sub099.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.9%
*-inverses99.9%
metadata-eval99.9%
associate--r-99.9%
neg-sub099.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 79.7%
if -6.5999999999999994e51 < z < 2.89999999999999978e37Initial program 91.5%
associate-/l*92.7%
remove-double-neg92.7%
distribute-frac-neg292.7%
neg-sub092.7%
remove-double-neg92.7%
unsub-neg92.7%
div-sub92.7%
*-inverses92.7%
metadata-eval92.7%
associate--r-92.7%
neg-sub092.7%
distribute-frac-neg292.7%
remove-double-neg92.7%
sub-neg92.7%
Simplified92.7%
Taylor expanded in y around inf 71.7%
associate-*l/71.2%
*-commutative71.2%
Simplified71.2%
Final simplification74.9%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= z -4.6e+51) x_m (if (<= z 4e+36) (/ y (/ z x_m)) x_m))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (z <= -4.6e+51) {
tmp = x_m;
} else if (z <= 4e+36) {
tmp = y / (z / x_m);
} else {
tmp = x_m;
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-4.6d+51)) then
tmp = x_m
else if (z <= 4d+36) then
tmp = y / (z / x_m)
else
tmp = x_m
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (z <= -4.6e+51) {
tmp = x_m;
} else if (z <= 4e+36) {
tmp = y / (z / x_m);
} else {
tmp = x_m;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if z <= -4.6e+51: tmp = x_m elif z <= 4e+36: tmp = y / (z / x_m) else: tmp = x_m return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (z <= -4.6e+51) tmp = x_m; elseif (z <= 4e+36) tmp = Float64(y / Float64(z / x_m)); else tmp = x_m; end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (z <= -4.6e+51) tmp = x_m; elseif (z <= 4e+36) tmp = y / (z / x_m); else tmp = x_m; end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[z, -4.6e+51], x$95$m, If[LessEqual[z, 4e+36], N[(y / N[(z / x$95$m), $MachinePrecision]), $MachinePrecision], x$95$m]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+51}:\\
\;\;\;\;x\_m\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+36}:\\
\;\;\;\;\frac{y}{\frac{z}{x\_m}}\\
\mathbf{else}:\\
\;\;\;\;x\_m\\
\end{array}
\end{array}
if z < -4.6000000000000001e51 or 4.00000000000000017e36 < z Initial program 70.7%
associate-/l*99.8%
remove-double-neg99.8%
distribute-frac-neg299.8%
neg-sub099.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.9%
*-inverses99.9%
metadata-eval99.9%
associate--r-99.9%
neg-sub099.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 79.7%
if -4.6000000000000001e51 < z < 4.00000000000000017e36Initial program 91.5%
associate-/l*92.7%
remove-double-neg92.7%
distribute-frac-neg292.7%
neg-sub092.7%
remove-double-neg92.7%
unsub-neg92.7%
div-sub92.7%
*-inverses92.7%
metadata-eval92.7%
associate--r-92.7%
neg-sub092.7%
distribute-frac-neg292.7%
remove-double-neg92.7%
sub-neg92.7%
Simplified92.7%
Taylor expanded in y around inf 71.7%
associate-*l/71.2%
*-commutative71.2%
Simplified71.2%
clear-num71.2%
un-div-inv71.3%
Applied egg-rr71.3%
Final simplification75.0%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s (if (<= z -4.6e+51) x_m (if (<= z 4e+36) (/ (* x_m y) z) x_m))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
double tmp;
if (z <= -4.6e+51) {
tmp = x_m;
} else if (z <= 4e+36) {
tmp = (x_m * y) / z;
} else {
tmp = x_m;
}
return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-4.6d+51)) then
tmp = x_m
else if (z <= 4d+36) then
tmp = (x_m * y) / z
else
tmp = x_m
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
double tmp;
if (z <= -4.6e+51) {
tmp = x_m;
} else if (z <= 4e+36) {
tmp = (x_m * y) / z;
} else {
tmp = x_m;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): tmp = 0 if z <= -4.6e+51: tmp = x_m elif z <= 4e+36: tmp = (x_m * y) / z else: tmp = x_m return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) tmp = 0.0 if (z <= -4.6e+51) tmp = x_m; elseif (z <= 4e+36) tmp = Float64(Float64(x_m * y) / z); else tmp = x_m; end return Float64(x_s * tmp) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m, y, z) tmp = 0.0; if (z <= -4.6e+51) tmp = x_m; elseif (z <= 4e+36) tmp = (x_m * y) / z; else tmp = x_m; end tmp_2 = x_s * tmp; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[z, -4.6e+51], x$95$m, If[LessEqual[z, 4e+36], N[(N[(x$95$m * y), $MachinePrecision] / z), $MachinePrecision], x$95$m]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+51}:\\
\;\;\;\;x\_m\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+36}:\\
\;\;\;\;\frac{x\_m \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\_m\\
\end{array}
\end{array}
if z < -4.6000000000000001e51 or 4.00000000000000017e36 < z Initial program 70.7%
associate-/l*99.8%
remove-double-neg99.8%
distribute-frac-neg299.8%
neg-sub099.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.9%
*-inverses99.9%
metadata-eval99.9%
associate--r-99.9%
neg-sub099.9%
distribute-frac-neg299.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 79.7%
if -4.6000000000000001e51 < z < 4.00000000000000017e36Initial program 91.5%
associate-/l*92.7%
remove-double-neg92.7%
distribute-frac-neg292.7%
neg-sub092.7%
remove-double-neg92.7%
unsub-neg92.7%
div-sub92.7%
*-inverses92.7%
metadata-eval92.7%
associate--r-92.7%
neg-sub092.7%
distribute-frac-neg292.7%
remove-double-neg92.7%
sub-neg92.7%
Simplified92.7%
Taylor expanded in y around inf 71.7%
Final simplification75.2%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m y z) :precision binary64 (* x_s x_m))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m, double y, double z) {
return x_s * x_m;
}
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m, y, z)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x_s * x_m
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m, double y, double z) {
return x_s * x_m;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m, y, z): return x_s * x_m
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m, y, z) return Float64(x_s * x_m) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m, y, z) tmp = x_s * x_m; end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * x$95$m), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot x\_m
\end{array}
Initial program 82.4%
associate-/l*95.8%
remove-double-neg95.8%
distribute-frac-neg295.8%
neg-sub095.8%
remove-double-neg95.8%
unsub-neg95.8%
div-sub95.8%
*-inverses95.8%
metadata-eval95.8%
associate--r-95.8%
neg-sub095.8%
distribute-frac-neg295.8%
remove-double-neg95.8%
sub-neg95.8%
Simplified95.8%
Taylor expanded in y around 0 48.7%
Final simplification48.7%
(FPCore (x y z) :precision binary64 (/ x (/ z (+ y z))))
double code(double x, double y, double z) {
return x / (z / (y + z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x / (z / (y + z))
end function
public static double code(double x, double y, double z) {
return x / (z / (y + z));
}
def code(x, y, z): return x / (z / (y + z))
function code(x, y, z) return Float64(x / Float64(z / Float64(y + z))) end
function tmp = code(x, y, z) tmp = x / (z / (y + z)); end
code[x_, y_, z_] := N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{y + z}}
\end{array}
herbie shell --seed 2024082
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))