
(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 85.3%
associate-/l*96.2%
remove-double-neg96.2%
distribute-frac-neg296.2%
neg-sub096.2%
remove-double-neg96.2%
unsub-neg96.2%
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 simplification96.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.6e-109) (not (<= y 3.2e+36))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.6e-109) || !(y <= 3.2e+36)) {
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.6d-109)) .or. (.not. (y <= 3.2d+36))) 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.6e-109) || !(y <= 3.2e+36)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.6e-109) or not (y <= 3.2e+36): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.6e-109) || !(y <= 3.2e+36)) 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.6e-109) || ~((y <= 3.2e+36))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.6e-109], N[Not[LessEqual[y, 3.2e+36]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{-109} \lor \neg \left(y \leq 3.2 \cdot 10^{+36}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.5999999999999998e-109 or 3.1999999999999999e36 < y Initial program 88.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 75.5%
associate-*r/72.0%
Simplified72.0%
if -2.5999999999999998e-109 < y < 3.1999999999999999e36Initial program 81.8%
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.7%
Final simplification76.6%
(FPCore (x y z) :precision binary64 (if (<= y -2.9e-109) (* x (/ y z)) (if (<= y 3e+38) x (* y (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.9e-109) {
tmp = x * (y / z);
} else if (y <= 3e+38) {
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 <= (-2.9d-109)) then
tmp = x * (y / z)
else if (y <= 3d+38) 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 <= -2.9e-109) {
tmp = x * (y / z);
} else if (y <= 3e+38) {
tmp = x;
} else {
tmp = y * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.9e-109: tmp = x * (y / z) elif y <= 3e+38: tmp = x else: tmp = y * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.9e-109) tmp = Float64(x * Float64(y / z)); elseif (y <= 3e+38) 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 <= -2.9e-109) tmp = x * (y / z); elseif (y <= 3e+38) tmp = x; else tmp = y * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.9e-109], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3e+38], x, N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{-109}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+38}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.9e-109Initial program 86.6%
associate-/l*96.4%
remove-double-neg96.4%
distribute-frac-neg296.4%
neg-sub096.4%
remove-double-neg96.4%
unsub-neg96.4%
div-sub96.4%
*-inverses96.4%
metadata-eval96.4%
associate--r-96.4%
neg-sub096.4%
distribute-frac-neg296.4%
remove-double-neg96.4%
sub-neg96.4%
Simplified96.4%
Taylor expanded in y around inf 70.7%
associate-*r/69.7%
Simplified69.7%
if -2.9e-109 < y < 3.0000000000000001e38Initial program 81.8%
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.7%
if 3.0000000000000001e38 < y Initial program 91.2%
associate-/l*87.4%
remove-double-neg87.4%
distribute-frac-neg287.4%
neg-sub087.4%
remove-double-neg87.4%
unsub-neg87.4%
div-sub87.4%
*-inverses87.4%
metadata-eval87.4%
associate--r-87.4%
neg-sub087.4%
distribute-frac-neg287.4%
remove-double-neg87.4%
sub-neg87.4%
Simplified87.4%
Taylor expanded in y around inf 82.5%
associate-*l/83.8%
*-commutative83.8%
Simplified83.8%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (<= y -2.8e-109) (/ x (/ z y)) (if (<= y 8.5e+36) x (* y (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.8e-109) {
tmp = x / (z / y);
} else if (y <= 8.5e+36) {
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 <= (-2.8d-109)) then
tmp = x / (z / y)
else if (y <= 8.5d+36) 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 <= -2.8e-109) {
tmp = x / (z / y);
} else if (y <= 8.5e+36) {
tmp = x;
} else {
tmp = y * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.8e-109: tmp = x / (z / y) elif y <= 8.5e+36: tmp = x else: tmp = y * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.8e-109) tmp = Float64(x / Float64(z / y)); elseif (y <= 8.5e+36) 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 <= -2.8e-109) tmp = x / (z / y); elseif (y <= 8.5e+36) tmp = x; else tmp = y * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.8e-109], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 8.5e+36], x, N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{-109}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+36}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.79999999999999979e-109Initial program 86.6%
associate-/l*96.4%
remove-double-neg96.4%
distribute-frac-neg296.4%
neg-sub096.4%
remove-double-neg96.4%
unsub-neg96.4%
div-sub96.4%
*-inverses96.4%
metadata-eval96.4%
associate--r-96.4%
neg-sub096.4%
distribute-frac-neg296.4%
remove-double-neg96.4%
sub-neg96.4%
Simplified96.4%
Taylor expanded in y around inf 70.7%
associate-*r/69.7%
Simplified69.7%
clear-num69.6%
un-div-inv70.9%
Applied egg-rr70.9%
if -2.79999999999999979e-109 < y < 8.50000000000000014e36Initial program 81.8%
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.7%
if 8.50000000000000014e36 < y Initial program 91.2%
associate-/l*87.4%
remove-double-neg87.4%
distribute-frac-neg287.4%
neg-sub087.4%
remove-double-neg87.4%
unsub-neg87.4%
div-sub87.4%
*-inverses87.4%
metadata-eval87.4%
associate--r-87.4%
neg-sub087.4%
distribute-frac-neg287.4%
remove-double-neg87.4%
sub-neg87.4%
Simplified87.4%
Taylor expanded in y around inf 82.5%
associate-*l/83.8%
*-commutative83.8%
Simplified83.8%
Final simplification78.8%
(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 85.3%
associate-/l*96.2%
remove-double-neg96.2%
distribute-frac-neg296.2%
neg-sub096.2%
remove-double-neg96.2%
unsub-neg96.2%
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%
Taylor expanded in y around 0 51.7%
Final simplification51.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 2024067
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))