
(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}
(FPCore (x y z) :precision binary64 (* x (- (/ y z) -1.0)))
double code(double x, double y, double z) {
return x * ((y / z) - -1.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 * ((y / z) - (-1.0d0))
end function
public static double code(double x, double y, double z) {
return x * ((y / z) - -1.0);
}
def code(x, y, z): return x * ((y / z) - -1.0)
function code(x, y, z) return Float64(x * Float64(Float64(y / z) - -1.0)) end
function tmp = code(x, y, z) tmp = x * ((y / z) - -1.0); end
code[x_, y_, z_] := N[(x * N[(N[(y / z), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\frac{y}{z} - -1\right)
\end{array}
Initial program 79.7%
associate-/l*98.4%
remove-double-neg98.4%
distribute-frac-neg298.4%
neg-sub098.4%
remove-double-neg98.4%
unsub-neg98.4%
div-sub98.4%
*-inverses98.4%
metadata-eval98.4%
associate--r-98.4%
neg-sub098.4%
distribute-frac-neg298.4%
remove-double-neg98.4%
sub-neg98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x y z)
:precision binary64
(if (<= z -1.95e+126)
x
(if (or (<= z -5.2e+107) (and (not (<= z -3.2e-27)) (<= z 1.5e+64)))
(* x (/ y z))
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e+126) {
tmp = x;
} else if ((z <= -5.2e+107) || (!(z <= -3.2e-27) && (z <= 1.5e+64))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.95d+126)) then
tmp = x
else if ((z <= (-5.2d+107)) .or. (.not. (z <= (-3.2d-27))) .and. (z <= 1.5d+64)) then
tmp = x * (y / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e+126) {
tmp = x;
} else if ((z <= -5.2e+107) || (!(z <= -3.2e-27) && (z <= 1.5e+64))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.95e+126: tmp = x elif (z <= -5.2e+107) or (not (z <= -3.2e-27) and (z <= 1.5e+64)): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.95e+126) tmp = x; elseif ((z <= -5.2e+107) || (!(z <= -3.2e-27) && (z <= 1.5e+64))) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.95e+126) tmp = x; elseif ((z <= -5.2e+107) || (~((z <= -3.2e-27)) && (z <= 1.5e+64))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.95e+126], x, If[Or[LessEqual[z, -5.2e+107], And[N[Not[LessEqual[z, -3.2e-27]], $MachinePrecision], LessEqual[z, 1.5e+64]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{+126}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -5.2 \cdot 10^{+107} \lor \neg \left(z \leq -3.2 \cdot 10^{-27}\right) \land z \leq 1.5 \cdot 10^{+64}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.94999999999999997e126 or -5.2000000000000002e107 < z < -3.19999999999999991e-27 or 1.5000000000000001e64 < z Initial program 69.7%
associate-/l*99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
neg-sub099.9%
remove-double-neg99.9%
unsub-neg99.9%
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 81.5%
if -1.94999999999999997e126 < z < -5.2000000000000002e107 or -3.19999999999999991e-27 < z < 1.5000000000000001e64Initial program 88.7%
associate-/l*97.0%
remove-double-neg97.0%
distribute-frac-neg297.0%
neg-sub097.0%
remove-double-neg97.0%
unsub-neg97.0%
div-sub97.0%
*-inverses97.0%
metadata-eval97.0%
associate--r-97.0%
neg-sub097.0%
distribute-frac-neg297.0%
remove-double-neg97.0%
sub-neg97.0%
Simplified97.0%
Taylor expanded in y around inf 70.4%
associate-/l*73.8%
*-commutative73.8%
Applied egg-rr73.8%
Final simplification77.4%
(FPCore (x y z)
:precision binary64
(if (<= z -1.95e+126)
x
(if (<= z -5e+107)
(* x (/ y z))
(if (<= z -9.5e-27) x (if (<= z 1.5e+62) (/ x (/ z y)) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e+126) {
tmp = x;
} else if (z <= -5e+107) {
tmp = x * (y / z);
} else if (z <= -9.5e-27) {
tmp = x;
} else if (z <= 1.5e+62) {
tmp = x / (z / y);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.95d+126)) then
tmp = x
else if (z <= (-5d+107)) then
tmp = x * (y / z)
else if (z <= (-9.5d-27)) then
tmp = x
else if (z <= 1.5d+62) then
tmp = x / (z / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e+126) {
tmp = x;
} else if (z <= -5e+107) {
tmp = x * (y / z);
} else if (z <= -9.5e-27) {
tmp = x;
} else if (z <= 1.5e+62) {
tmp = x / (z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.95e+126: tmp = x elif z <= -5e+107: tmp = x * (y / z) elif z <= -9.5e-27: tmp = x elif z <= 1.5e+62: tmp = x / (z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.95e+126) tmp = x; elseif (z <= -5e+107) tmp = Float64(x * Float64(y / z)); elseif (z <= -9.5e-27) tmp = x; elseif (z <= 1.5e+62) tmp = Float64(x / Float64(z / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.95e+126) tmp = x; elseif (z <= -5e+107) tmp = x * (y / z); elseif (z <= -9.5e-27) tmp = x; elseif (z <= 1.5e+62) tmp = x / (z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.95e+126], x, If[LessEqual[z, -5e+107], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, -9.5e-27], x, If[LessEqual[z, 1.5e+62], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{+126}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -5 \cdot 10^{+107}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;z \leq -9.5 \cdot 10^{-27}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+62}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.94999999999999997e126 or -5.0000000000000002e107 < z < -9.50000000000000037e-27 or 1.5e62 < z Initial program 69.7%
associate-/l*99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
neg-sub099.9%
remove-double-neg99.9%
unsub-neg99.9%
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 81.5%
if -1.94999999999999997e126 < z < -5.0000000000000002e107Initial program 86.7%
associate-/l*99.6%
remove-double-neg99.6%
distribute-frac-neg299.6%
neg-sub099.6%
remove-double-neg99.6%
unsub-neg99.6%
div-sub99.6%
*-inverses99.6%
metadata-eval99.6%
associate--r-99.6%
neg-sub099.6%
distribute-frac-neg299.6%
remove-double-neg99.6%
sub-neg99.6%
Simplified99.6%
Taylor expanded in y around inf 64.6%
associate-/l*77.6%
*-commutative77.6%
Applied egg-rr77.6%
if -9.50000000000000037e-27 < z < 1.5e62Initial program 88.8%
associate-/l*96.9%
remove-double-neg96.9%
distribute-frac-neg296.9%
neg-sub096.9%
remove-double-neg96.9%
unsub-neg96.9%
div-sub96.9%
*-inverses96.9%
metadata-eval96.9%
associate--r-96.9%
neg-sub096.9%
distribute-frac-neg296.9%
remove-double-neg96.9%
sub-neg96.9%
Simplified96.9%
Taylor expanded in y around inf 70.7%
associate-/l*73.6%
*-commutative73.6%
Applied egg-rr73.6%
*-commutative73.6%
clear-num73.6%
un-div-inv74.3%
Applied egg-rr74.3%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (if (<= z -1.9e-29) x (if (<= z 3.7e-6) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.9e-29) {
tmp = x;
} else if (z <= 3.7e-6) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-1.9d-29)) then
tmp = x
else if (z <= 3.7d-6) then
tmp = y * (x / z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.9e-29) {
tmp = x;
} else if (z <= 3.7e-6) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.9e-29: tmp = x elif z <= 3.7e-6: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.9e-29) tmp = x; elseif (z <= 3.7e-6) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.9e-29) tmp = x; elseif (z <= 3.7e-6) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.9e-29], x, If[LessEqual[z, 3.7e-6], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{-29}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.7 \cdot 10^{-6}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.89999999999999988e-29 or 3.7000000000000002e-6 < z Initial program 72.5%
associate-/l*99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
neg-sub099.9%
remove-double-neg99.9%
unsub-neg99.9%
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 75.1%
if -1.89999999999999988e-29 < z < 3.7000000000000002e-6Initial program 88.4%
associate-/l*96.6%
remove-double-neg96.6%
distribute-frac-neg296.6%
neg-sub096.6%
remove-double-neg96.6%
unsub-neg96.6%
div-sub96.6%
*-inverses96.6%
metadata-eval96.6%
associate--r-96.6%
neg-sub096.6%
distribute-frac-neg296.6%
remove-double-neg96.6%
sub-neg96.6%
Simplified96.6%
Taylor expanded in y around inf 73.4%
associate-*l/76.1%
*-commutative76.1%
Simplified76.1%
Final simplification75.6%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 79.7%
associate-/l*98.4%
remove-double-neg98.4%
distribute-frac-neg298.4%
neg-sub098.4%
remove-double-neg98.4%
unsub-neg98.4%
div-sub98.4%
*-inverses98.4%
metadata-eval98.4%
associate--r-98.4%
neg-sub098.4%
distribute-frac-neg298.4%
remove-double-neg98.4%
sub-neg98.4%
Simplified98.4%
Taylor expanded in y around 0 51.6%
Final simplification51.6%
(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 2024076
(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))