
(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 83.6%
associate-/l*96.5%
remove-double-neg96.5%
unsub-neg96.5%
div-sub96.5%
remove-double-neg96.5%
distribute-frac-neg296.5%
*-inverses96.5%
metadata-eval96.5%
Simplified96.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.2e+80) (not (<= y 8200.0))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.2e+80) || !(y <= 8200.0)) {
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 <= (-4.2d+80)) .or. (.not. (y <= 8200.0d0))) 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 <= -4.2e+80) || !(y <= 8200.0)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.2e+80) or not (y <= 8200.0): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.2e+80) || !(y <= 8200.0)) 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 <= -4.2e+80) || ~((y <= 8200.0))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.2e+80], N[Not[LessEqual[y, 8200.0]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+80} \lor \neg \left(y \leq 8200\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.20000000000000003e80 or 8200 < y Initial program 88.6%
associate-/l*91.9%
remove-double-neg91.9%
unsub-neg91.9%
div-sub91.9%
remove-double-neg91.9%
distribute-frac-neg291.9%
*-inverses91.9%
metadata-eval91.9%
Simplified91.9%
Taylor expanded in y around inf 75.4%
associate-*l/79.2%
*-commutative79.2%
Simplified79.2%
if -4.20000000000000003e80 < y < 8200Initial program 80.0%
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 73.9%
Final simplification76.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e+80) (not (<= y 6000.0))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e+80) || !(y <= 6000.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 <= (-5.8d+80)) .or. (.not. (y <= 6000.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 <= -5.8e+80) || !(y <= 6000.0)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e+80) or not (y <= 6000.0): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e+80) || !(y <= 6000.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 <= -5.8e+80) || ~((y <= 6000.0))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e+80], N[Not[LessEqual[y, 6000.0]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{+80} \lor \neg \left(y \leq 6000\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.79999999999999971e80 or 6e3 < y Initial program 88.6%
associate-/l*91.9%
remove-double-neg91.9%
unsub-neg91.9%
div-sub91.9%
remove-double-neg91.9%
distribute-frac-neg291.9%
*-inverses91.9%
metadata-eval91.9%
Simplified91.9%
Taylor expanded in y around inf 73.5%
if -5.79999999999999971e80 < y < 6e3Initial program 80.0%
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 73.9%
Final simplification73.7%
(FPCore (x y z) :precision binary64 (if (<= y -4.4e+80) (* y (/ x z)) (if (<= y 5000.0) x (/ y (/ z x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.4e+80) {
tmp = y * (x / z);
} else if (y <= 5000.0) {
tmp = x;
} else {
tmp = y / (z / 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 <= (-4.4d+80)) then
tmp = y * (x / z)
else if (y <= 5000.0d0) then
tmp = x
else
tmp = y / (z / x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.4e+80) {
tmp = y * (x / z);
} else if (y <= 5000.0) {
tmp = x;
} else {
tmp = y / (z / x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.4e+80: tmp = y * (x / z) elif y <= 5000.0: tmp = x else: tmp = y / (z / x) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.4e+80) tmp = Float64(y * Float64(x / z)); elseif (y <= 5000.0) tmp = x; else tmp = Float64(y / Float64(z / x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.4e+80) tmp = y * (x / z); elseif (y <= 5000.0) tmp = x; else tmp = y / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.4e+80], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5000.0], x, N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+80}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 5000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
\end{array}
if y < -4.40000000000000005e80Initial program 84.8%
associate-/l*91.1%
remove-double-neg91.1%
unsub-neg91.1%
div-sub91.1%
remove-double-neg91.1%
distribute-frac-neg291.1%
*-inverses91.1%
metadata-eval91.1%
Simplified91.1%
Taylor expanded in y around inf 74.3%
associate-*l/79.6%
*-commutative79.6%
Simplified79.6%
if -4.40000000000000005e80 < y < 5e3Initial program 80.0%
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 73.9%
if 5e3 < y Initial program 91.1%
associate-/l*92.4%
remove-double-neg92.4%
unsub-neg92.4%
div-sub92.5%
remove-double-neg92.5%
distribute-frac-neg292.5%
*-inverses92.5%
metadata-eval92.5%
Simplified92.5%
Taylor expanded in y around inf 73.1%
associate-*r/76.1%
associate-*l/78.9%
*-commutative78.9%
clear-num78.8%
un-div-inv79.0%
Applied egg-rr79.0%
(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.6%
associate-/l*96.5%
remove-double-neg96.5%
unsub-neg96.5%
div-sub96.5%
remove-double-neg96.5%
distribute-frac-neg296.5%
*-inverses96.5%
metadata-eval96.5%
Simplified96.5%
Taylor expanded in y around 0 51.3%
(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 2024158
(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))