
(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 8 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 (if (or (<= z -1.28e-245) (not (<= z 9.2e-148))) (+ x (/ x (/ z y))) (/ (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.28e-245) || !(z <= 9.2e-148)) {
tmp = x + (x / (z / y));
} else {
tmp = (x * y) / z;
}
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.28d-245)) .or. (.not. (z <= 9.2d-148))) then
tmp = x + (x / (z / y))
else
tmp = (x * y) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.28e-245) || !(z <= 9.2e-148)) {
tmp = x + (x / (z / y));
} else {
tmp = (x * y) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.28e-245) or not (z <= 9.2e-148): tmp = x + (x / (z / y)) else: tmp = (x * y) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.28e-245) || !(z <= 9.2e-148)) tmp = Float64(x + Float64(x / Float64(z / y))); else tmp = Float64(Float64(x * y) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.28e-245) || ~((z <= 9.2e-148))) tmp = x + (x / (z / y)); else tmp = (x * y) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.28e-245], N[Not[LessEqual[z, 9.2e-148]], $MachinePrecision]], N[(x + N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.28 \cdot 10^{-245} \lor \neg \left(z \leq 9.2 \cdot 10^{-148}\right):\\
\;\;\;\;x + \frac{x}{\frac{z}{y}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\end{array}
\end{array}
if z < -1.28e-245 or 9.1999999999999999e-148 < z Initial program 83.1%
associate-/l*98.1%
remove-double-neg98.1%
unsub-neg98.1%
div-sub98.1%
remove-double-neg98.1%
distribute-frac-neg298.1%
*-inverses98.1%
metadata-eval98.1%
Simplified98.1%
sub-neg98.1%
metadata-eval98.1%
distribute-rgt-in98.1%
*-un-lft-identity98.1%
Applied egg-rr98.1%
*-commutative98.1%
clear-num98.1%
un-div-inv98.2%
Applied egg-rr98.2%
if -1.28e-245 < z < 9.1999999999999999e-148Initial program 98.0%
Taylor expanded in y around inf 98.0%
*-commutative98.0%
Simplified98.0%
Final simplification98.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -8e-246) (not (<= z 1e-147))) (* x (- (/ y z) -1.0)) (/ (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8e-246) || !(z <= 1e-147)) {
tmp = x * ((y / z) - -1.0);
} else {
tmp = (x * y) / z;
}
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 <= (-8d-246)) .or. (.not. (z <= 1d-147))) then
tmp = x * ((y / z) - (-1.0d0))
else
tmp = (x * y) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8e-246) || !(z <= 1e-147)) {
tmp = x * ((y / z) - -1.0);
} else {
tmp = (x * y) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8e-246) or not (z <= 1e-147): tmp = x * ((y / z) - -1.0) else: tmp = (x * y) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8e-246) || !(z <= 1e-147)) tmp = Float64(x * Float64(Float64(y / z) - -1.0)); else tmp = Float64(Float64(x * y) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8e-246) || ~((z <= 1e-147))) tmp = x * ((y / z) - -1.0); else tmp = (x * y) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8e-246], N[Not[LessEqual[z, 1e-147]], $MachinePrecision]], N[(x * N[(N[(y / z), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{-246} \lor \neg \left(z \leq 10^{-147}\right):\\
\;\;\;\;x \cdot \left(\frac{y}{z} - -1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\end{array}
\end{array}
if z < -7.99999999999999965e-246 or 9.9999999999999997e-148 < z Initial program 83.1%
associate-/l*98.1%
remove-double-neg98.1%
unsub-neg98.1%
div-sub98.1%
remove-double-neg98.1%
distribute-frac-neg298.1%
*-inverses98.1%
metadata-eval98.1%
Simplified98.1%
if -7.99999999999999965e-246 < z < 9.9999999999999997e-148Initial program 98.0%
Taylor expanded in y around inf 98.0%
*-commutative98.0%
Simplified98.0%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (if (<= z -1.38e-245) (* x (- (/ y z) -1.0)) (if (<= z 9.2e-148) (/ (* x y) z) (+ x (* x (/ y z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.38e-245) {
tmp = x * ((y / z) - -1.0);
} else if (z <= 9.2e-148) {
tmp = (x * y) / z;
} else {
tmp = x + (x * (y / z));
}
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.38d-245)) then
tmp = x * ((y / z) - (-1.0d0))
else if (z <= 9.2d-148) then
tmp = (x * y) / z
else
tmp = x + (x * (y / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.38e-245) {
tmp = x * ((y / z) - -1.0);
} else if (z <= 9.2e-148) {
tmp = (x * y) / z;
} else {
tmp = x + (x * (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.38e-245: tmp = x * ((y / z) - -1.0) elif z <= 9.2e-148: tmp = (x * y) / z else: tmp = x + (x * (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.38e-245) tmp = Float64(x * Float64(Float64(y / z) - -1.0)); elseif (z <= 9.2e-148) tmp = Float64(Float64(x * y) / z); else tmp = Float64(x + Float64(x * Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.38e-245) tmp = x * ((y / z) - -1.0); elseif (z <= 9.2e-148) tmp = (x * y) / z; else tmp = x + (x * (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.38e-245], N[(x * N[(N[(y / z), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 9.2e-148], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.38 \cdot 10^{-245}:\\
\;\;\;\;x \cdot \left(\frac{y}{z} - -1\right)\\
\mathbf{elif}\;z \leq 9.2 \cdot 10^{-148}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if z < -1.38000000000000006e-245Initial program 80.0%
associate-/l*97.6%
remove-double-neg97.6%
unsub-neg97.6%
div-sub97.7%
remove-double-neg97.7%
distribute-frac-neg297.7%
*-inverses97.7%
metadata-eval97.7%
Simplified97.7%
if -1.38000000000000006e-245 < z < 9.1999999999999999e-148Initial program 98.0%
Taylor expanded in y around inf 98.0%
*-commutative98.0%
Simplified98.0%
if 9.1999999999999999e-148 < z Initial program 88.6%
associate-/l*98.8%
remove-double-neg98.8%
unsub-neg98.8%
div-sub98.8%
remove-double-neg98.8%
distribute-frac-neg298.8%
*-inverses98.8%
metadata-eval98.8%
Simplified98.8%
sub-neg98.8%
metadata-eval98.8%
distribute-rgt-in98.8%
*-un-lft-identity98.8%
Applied egg-rr98.8%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -7e-8) (not (<= y 25.0))) (/ (* x y) z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7e-8) || !(y <= 25.0)) {
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 ((y <= (-7d-8)) .or. (.not. (y <= 25.0d0))) 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 ((y <= -7e-8) || !(y <= 25.0)) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7e-8) or not (y <= 25.0): tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7e-8) || !(y <= 25.0)) tmp = Float64(Float64(x * y) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7e-8) || ~((y <= 25.0))) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7e-8], N[Not[LessEqual[y, 25.0]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{-8} \lor \neg \left(y \leq 25\right):\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -7.00000000000000048e-8 or 25 < y Initial program 90.6%
Taylor expanded in y around inf 76.2%
*-commutative76.2%
Simplified76.2%
if -7.00000000000000048e-8 < y < 25Initial program 80.6%
associate-/l*99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 77.2%
Final simplification76.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.8e-8) (not (<= y 0.196))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e-8) || !(y <= 0.196)) {
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 ((y <= (-1.8d-8)) .or. (.not. (y <= 0.196d0))) 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 ((y <= -1.8e-8) || !(y <= 0.196)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.8e-8) or not (y <= 0.196): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.8e-8) || !(y <= 0.196)) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.8e-8) || ~((y <= 0.196))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.8e-8], N[Not[LessEqual[y, 0.196]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-8} \lor \neg \left(y \leq 0.196\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.79999999999999991e-8 or 0.19600000000000001 < y Initial program 90.6%
associate-/l*90.0%
remove-double-neg90.0%
unsub-neg90.0%
div-sub90.1%
remove-double-neg90.1%
distribute-frac-neg290.1%
*-inverses90.1%
metadata-eval90.1%
Simplified90.1%
Taylor expanded in y around inf 76.2%
associate-*l/75.9%
*-commutative75.9%
Simplified75.9%
if -1.79999999999999991e-8 < y < 0.19600000000000001Initial program 80.6%
associate-/l*99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 77.2%
Final simplification76.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.65e-11) (not (<= y 29.0))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.65e-11) || !(y <= 29.0)) {
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 ((y <= (-2.65d-11)) .or. (.not. (y <= 29.0d0))) 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 ((y <= -2.65e-11) || !(y <= 29.0)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.65e-11) or not (y <= 29.0): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.65e-11) || !(y <= 29.0)) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.65e-11) || ~((y <= 29.0))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.65e-11], N[Not[LessEqual[y, 29.0]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.65 \cdot 10^{-11} \lor \neg \left(y \leq 29\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.6499999999999999e-11 or 29 < y Initial program 90.6%
associate-/l*90.0%
remove-double-neg90.0%
unsub-neg90.0%
div-sub90.1%
remove-double-neg90.1%
distribute-frac-neg290.1%
*-inverses90.1%
metadata-eval90.1%
Simplified90.1%
Taylor expanded in y around inf 69.7%
if -2.6499999999999999e-11 < y < 29Initial program 80.6%
associate-/l*99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 77.2%
Final simplification73.0%
(FPCore (x y z) :precision binary64 (if (<= x 2e-13) (/ (* x (+ y z)) z) (+ x (/ x (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= 2e-13) {
tmp = (x * (y + z)) / z;
} else {
tmp = x + (x / (z / y));
}
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 (x <= 2d-13) then
tmp = (x * (y + z)) / z
else
tmp = x + (x / (z / y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 2e-13) {
tmp = (x * (y + z)) / z;
} else {
tmp = x + (x / (z / y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 2e-13: tmp = (x * (y + z)) / z else: tmp = x + (x / (z / y)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= 2e-13) tmp = Float64(Float64(x * Float64(y + z)) / z); else tmp = Float64(x + Float64(x / Float64(z / y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 2e-13) tmp = (x * (y + z)) / z; else tmp = x + (x / (z / y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 2e-13], N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(x + N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{-13}:\\
\;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{x}{\frac{z}{y}}\\
\end{array}
\end{array}
if x < 2.0000000000000001e-13Initial program 88.8%
if 2.0000000000000001e-13 < x Initial program 76.9%
associate-/l*99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
remove-double-neg99.9%
distribute-frac-neg299.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
sub-neg99.9%
metadata-eval99.9%
distribute-rgt-in99.9%
*-un-lft-identity99.9%
Applied egg-rr99.9%
*-commutative99.9%
clear-num99.9%
un-div-inv99.9%
Applied egg-rr99.9%
Final simplification91.3%
(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 86.2%
associate-/l*94.4%
remove-double-neg94.4%
unsub-neg94.4%
div-sub94.4%
remove-double-neg94.4%
distribute-frac-neg294.4%
*-inverses94.4%
metadata-eval94.4%
Simplified94.4%
Taylor expanded in y around 0 46.0%
(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 2024152
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(! :herbie-platform default (/ x (/ z (+ y z))))
(/ (* x (+ y z)) z))