
(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 (<= y -3.4e+53) (/ (* x (+ y z)) z) (+ x (* x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.4e+53) {
tmp = (x * (y + z)) / 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 (y <= (-3.4d+53)) then
tmp = (x * (y + z)) / 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 (y <= -3.4e+53) {
tmp = (x * (y + z)) / z;
} else {
tmp = x + (x * (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.4e+53: tmp = (x * (y + z)) / z else: tmp = x + (x * (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.4e+53) tmp = Float64(Float64(x * Float64(y + z)) / 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 (y <= -3.4e+53) tmp = (x * (y + z)) / z; else tmp = x + (x * (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.4e+53], N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+53}:\\
\;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if y < -3.39999999999999998e53Initial program 95.4%
if -3.39999999999999998e53 < y Initial program 80.5%
associate-/l*97.7%
remove-double-neg97.7%
distribute-frac-neg297.7%
neg-sub097.7%
remove-double-neg97.7%
unsub-neg97.7%
div-sub97.7%
*-inverses97.7%
metadata-eval97.7%
associate--r-97.7%
neg-sub097.7%
distribute-frac-neg297.7%
remove-double-neg97.7%
sub-neg97.7%
Simplified97.7%
sub-neg97.7%
metadata-eval97.7%
distribute-rgt-in97.7%
*-un-lft-identity97.7%
Applied egg-rr97.7%
Final simplification97.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -9e+53) (not (<= y 8e-88))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9e+53) || !(y <= 8e-88)) {
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 <= (-9d+53)) .or. (.not. (y <= 8d-88))) 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 <= -9e+53) || !(y <= 8e-88)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9e+53) or not (y <= 8e-88): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9e+53) || !(y <= 8e-88)) 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 <= -9e+53) || ~((y <= 8e-88))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9e+53], N[Not[LessEqual[y, 8e-88]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{+53} \lor \neg \left(y \leq 8 \cdot 10^{-88}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -9.0000000000000004e53 or 7.99999999999999947e-88 < y Initial program 87.7%
associate-/l*91.0%
remove-double-neg91.0%
distribute-frac-neg291.0%
neg-sub091.0%
remove-double-neg91.0%
unsub-neg91.0%
div-sub91.0%
*-inverses91.0%
metadata-eval91.0%
associate--r-91.0%
neg-sub091.0%
distribute-frac-neg291.0%
remove-double-neg91.0%
sub-neg91.0%
Simplified91.0%
Taylor expanded in y around inf 72.2%
associate-*l/74.3%
*-commutative74.3%
Simplified74.3%
if -9.0000000000000004e53 < y < 7.99999999999999947e-88Initial program 78.4%
associate-/l*99.2%
remove-double-neg99.2%
distribute-frac-neg299.2%
neg-sub099.2%
remove-double-neg99.2%
unsub-neg99.2%
div-sub99.2%
*-inverses99.2%
metadata-eval99.2%
associate--r-99.2%
neg-sub099.2%
distribute-frac-neg299.2%
remove-double-neg99.2%
sub-neg99.2%
Simplified99.2%
Taylor expanded in y around 0 78.2%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e+65) (not (<= y 3.2e-91))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e+65) || !(y <= 3.2e-91)) {
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.5d+65)) .or. (.not. (y <= 3.2d-91))) 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.5e+65) || !(y <= 3.2e-91)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e+65) or not (y <= 3.2e-91): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e+65) || !(y <= 3.2e-91)) 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.5e+65) || ~((y <= 3.2e-91))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e+65], N[Not[LessEqual[y, 3.2e-91]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+65} \lor \neg \left(y \leq 3.2 \cdot 10^{-91}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.49999999999999986e65 or 3.19999999999999996e-91 < y Initial program 87.0%
associate-/l*91.2%
remove-double-neg91.2%
distribute-frac-neg291.2%
neg-sub091.2%
remove-double-neg91.2%
unsub-neg91.2%
div-sub91.2%
*-inverses91.2%
metadata-eval91.2%
associate--r-91.2%
neg-sub091.2%
distribute-frac-neg291.2%
remove-double-neg91.2%
sub-neg91.2%
Simplified91.2%
Taylor expanded in y around inf 69.9%
if -2.49999999999999986e65 < y < 3.19999999999999996e-91Initial program 79.7%
associate-/l*98.5%
remove-double-neg98.5%
distribute-frac-neg298.5%
neg-sub098.5%
remove-double-neg98.5%
unsub-neg98.5%
div-sub98.5%
*-inverses98.5%
metadata-eval98.5%
associate--r-98.5%
neg-sub098.5%
distribute-frac-neg298.5%
remove-double-neg98.5%
sub-neg98.5%
Simplified98.5%
Taylor expanded in y around 0 76.2%
Final simplification73.2%
(FPCore (x y z) :precision binary64 (if (<= y -5.5e+47) (/ (* y x) z) (if (<= y 8e-88) x (* y (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.5e+47) {
tmp = (y * x) / z;
} else if (y <= 8e-88) {
tmp = x;
} else {
tmp = y * (x / 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 (y <= (-5.5d+47)) then
tmp = (y * x) / z
else if (y <= 8d-88) then
tmp = x
else
tmp = y * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.5e+47) {
tmp = (y * x) / z;
} else if (y <= 8e-88) {
tmp = x;
} else {
tmp = y * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.5e+47: tmp = (y * x) / z elif y <= 8e-88: tmp = x else: tmp = y * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.5e+47) tmp = Float64(Float64(y * x) / z); elseif (y <= 8e-88) tmp = x; else tmp = Float64(y * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.5e+47) tmp = (y * x) / z; elseif (y <= 8e-88) tmp = x; else tmp = y * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.5e+47], N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 8e-88], x, N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+47}:\\
\;\;\;\;\frac{y \cdot x}{z}\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-88}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -5.4999999999999998e47Initial program 95.4%
Taylor expanded in y around inf 82.3%
*-commutative82.3%
Simplified82.3%
if -5.4999999999999998e47 < y < 7.99999999999999947e-88Initial program 78.4%
associate-/l*99.2%
remove-double-neg99.2%
distribute-frac-neg299.2%
neg-sub099.2%
remove-double-neg99.2%
unsub-neg99.2%
div-sub99.2%
*-inverses99.2%
metadata-eval99.2%
associate--r-99.2%
neg-sub099.2%
distribute-frac-neg299.2%
remove-double-neg99.2%
sub-neg99.2%
Simplified99.2%
Taylor expanded in y around 0 78.2%
if 7.99999999999999947e-88 < y Initial program 83.7%
associate-/l*95.4%
remove-double-neg95.4%
distribute-frac-neg295.4%
neg-sub095.4%
remove-double-neg95.4%
unsub-neg95.4%
div-sub95.4%
*-inverses95.4%
metadata-eval95.4%
associate--r-95.4%
neg-sub095.4%
distribute-frac-neg295.4%
remove-double-neg95.4%
sub-neg95.4%
Simplified95.4%
Taylor expanded in y around inf 66.9%
associate-*l/71.3%
*-commutative71.3%
Simplified71.3%
(FPCore (x y z) :precision binary64 (if (<= y -4.8e+83) (* (+ y z) (/ x z)) (+ x (* x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.8e+83) {
tmp = (y + z) * (x / 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 (y <= (-4.8d+83)) then
tmp = (y + z) * (x / 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 (y <= -4.8e+83) {
tmp = (y + z) * (x / z);
} else {
tmp = x + (x * (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.8e+83: tmp = (y + z) * (x / z) else: tmp = x + (x * (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.8e+83) tmp = Float64(Float64(y + z) * Float64(x / 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 (y <= -4.8e+83) tmp = (y + z) * (x / z); else tmp = x + (x * (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.8e+83], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{+83}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if y < -4.79999999999999982e83Initial program 93.5%
*-commutative93.5%
associate-/l*93.5%
Simplified93.5%
if -4.79999999999999982e83 < y Initial program 81.7%
associate-/l*97.4%
remove-double-neg97.4%
distribute-frac-neg297.4%
neg-sub097.4%
remove-double-neg97.4%
unsub-neg97.4%
div-sub97.4%
*-inverses97.4%
metadata-eval97.4%
associate--r-97.4%
neg-sub097.4%
distribute-frac-neg297.4%
remove-double-neg97.4%
sub-neg97.4%
Simplified97.4%
sub-neg97.4%
metadata-eval97.4%
distribute-rgt-in97.4%
*-un-lft-identity97.4%
Applied egg-rr97.4%
Final simplification97.0%
(FPCore (x y z) :precision binary64 (if (<= y -3.8e+83) (* (+ y z) (/ x z)) (* x (- (/ y z) -1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e+83) {
tmp = (y + z) * (x / z);
} else {
tmp = x * ((y / z) - -1.0);
}
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 <= (-3.8d+83)) then
tmp = (y + z) * (x / z)
else
tmp = x * ((y / z) - (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e+83) {
tmp = (y + z) * (x / z);
} else {
tmp = x * ((y / z) - -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.8e+83: tmp = (y + z) * (x / z) else: tmp = x * ((y / z) - -1.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.8e+83) tmp = Float64(Float64(y + z) * Float64(x / z)); else tmp = Float64(x * Float64(Float64(y / z) - -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.8e+83) tmp = (y + z) * (x / z); else tmp = x * ((y / z) - -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.8e+83], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(y / z), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+83}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\frac{y}{z} - -1\right)\\
\end{array}
\end{array}
if y < -3.8000000000000002e83Initial program 93.5%
*-commutative93.5%
associate-/l*93.5%
Simplified93.5%
if -3.8000000000000002e83 < y Initial program 81.7%
associate-/l*97.4%
remove-double-neg97.4%
distribute-frac-neg297.4%
neg-sub097.4%
remove-double-neg97.4%
unsub-neg97.4%
div-sub97.4%
*-inverses97.4%
metadata-eval97.4%
associate--r-97.4%
neg-sub097.4%
distribute-frac-neg297.4%
remove-double-neg97.4%
sub-neg97.4%
Simplified97.4%
(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 83.1%
associate-/l*95.1%
remove-double-neg95.1%
distribute-frac-neg295.1%
neg-sub095.1%
remove-double-neg95.1%
unsub-neg95.1%
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%
(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 83.1%
associate-/l*95.1%
remove-double-neg95.1%
distribute-frac-neg295.1%
neg-sub095.1%
remove-double-neg95.1%
unsub-neg95.1%
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 0 51.8%
(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 2024145
(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))