
(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 7 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 (/ x (/ z y))))
double code(double x, double y, double z) {
return x + (x / (z / y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (x / (z / y))
end function
public static double code(double x, double y, double z) {
return x + (x / (z / y));
}
def code(x, y, z): return x + (x / (z / y))
function code(x, y, z) return Float64(x + Float64(x / Float64(z / y))) end
function tmp = code(x, y, z) tmp = x + (x / (z / y)); end
code[x_, y_, z_] := N[(x + N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{x}{\frac{z}{y}}
\end{array}
Initial program 82.7%
associate-/l*97.2%
remove-double-neg97.2%
distribute-frac-neg297.2%
neg-sub097.2%
remove-double-neg97.2%
unsub-neg97.2%
div-sub97.3%
*-inverses97.3%
metadata-eval97.3%
associate--r-97.3%
neg-sub097.3%
distribute-frac-neg297.3%
remove-double-neg97.3%
sub-neg97.3%
Simplified97.3%
sub-neg97.3%
metadata-eval97.3%
distribute-rgt-in97.2%
*-commutative97.2%
*-un-lft-identity97.2%
Applied egg-rr97.2%
clear-num97.2%
un-div-inv97.6%
Applied egg-rr97.6%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (<= z -1.7e+43) x (if (<= z 1.8e+29) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e+43) {
tmp = x;
} else if (z <= 1.8e+29) {
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.7d+43)) then
tmp = x
else if (z <= 1.8d+29) 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.7e+43) {
tmp = x;
} else if (z <= 1.8e+29) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.7e+43: tmp = x elif z <= 1.8e+29: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.7e+43) tmp = x; elseif (z <= 1.8e+29) 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.7e+43) tmp = x; elseif (z <= 1.8e+29) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.7e+43], x, If[LessEqual[z, 1.8e+29], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+43}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+29}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.70000000000000006e43 or 1.79999999999999988e29 < z Initial program 67.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 76.0%
if -1.70000000000000006e43 < z < 1.79999999999999988e29Initial program 95.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 inf 74.6%
Final simplification75.2%
(FPCore (x y z) :precision binary64 (if (<= z -1.1e+28) x (if (<= z 1.4e+25) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.1e+28) {
tmp = x;
} else if (z <= 1.4e+25) {
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.1d+28)) then
tmp = x
else if (z <= 1.4d+25) 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.1e+28) {
tmp = x;
} else if (z <= 1.4e+25) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.1e+28: tmp = x elif z <= 1.4e+25: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.1e+28) tmp = x; elseif (z <= 1.4e+25) 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.1e+28) tmp = x; elseif (z <= 1.4e+25) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.1e+28], x, If[LessEqual[z, 1.4e+25], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{+28}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+25}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.09999999999999993e28 or 1.4000000000000001e25 < z Initial program 68.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 75.3%
if -1.09999999999999993e28 < z < 1.4000000000000001e25Initial program 95.0%
associate-/l*94.9%
remove-double-neg94.9%
distribute-frac-neg294.9%
neg-sub094.9%
remove-double-neg94.9%
unsub-neg94.9%
div-sub94.9%
*-inverses94.9%
metadata-eval94.9%
associate--r-94.9%
neg-sub094.9%
distribute-frac-neg294.9%
remove-double-neg94.9%
sub-neg94.9%
Simplified94.9%
Taylor expanded in y around inf 78.0%
associate-*l/75.3%
*-commutative75.3%
Simplified75.3%
Final simplification75.3%
(FPCore (x y z) :precision binary64 (if (<= z -2e+40) x (if (<= z 3.6e+28) (/ x (/ z y)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2e+40) {
tmp = x;
} else if (z <= 3.6e+28) {
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 <= (-2d+40)) then
tmp = x
else if (z <= 3.6d+28) 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 <= -2e+40) {
tmp = x;
} else if (z <= 3.6e+28) {
tmp = x / (z / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2e+40: tmp = x elif z <= 3.6e+28: tmp = x / (z / y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2e+40) tmp = x; elseif (z <= 3.6e+28) 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 <= -2e+40) tmp = x; elseif (z <= 3.6e+28) tmp = x / (z / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2e+40], x, If[LessEqual[z, 3.6e+28], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{+40}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+28}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.00000000000000006e40 or 3.5999999999999999e28 < z Initial program 67.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 76.0%
if -2.00000000000000006e40 < z < 3.5999999999999999e28Initial program 95.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 inf 74.6%
clear-num95.0%
un-div-inv95.7%
Applied egg-rr75.2%
Final simplification75.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.9e+46) x (if (<= z 7.8e+28) (/ (* x y) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.9e+46) {
tmp = x;
} else if (z <= 7.8e+28) {
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.9d+46)) then
tmp = x
else if (z <= 7.8d+28) 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.9e+46) {
tmp = x;
} else if (z <= 7.8e+28) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.9e+46: tmp = x elif z <= 7.8e+28: tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.9e+46) tmp = x; elseif (z <= 7.8e+28) tmp = Float64(Float64(x * y) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.9e+46) tmp = x; elseif (z <= 7.8e+28) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.9e+46], x, If[LessEqual[z, 7.8e+28], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{+46}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7.8 \cdot 10^{+28}:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.9e46 or 7.7999999999999997e28 < z Initial program 67.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 76.0%
if -1.9e46 < z < 7.7999999999999997e28Initial program 95.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 inf 77.3%
Final simplification76.7%
(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 82.7%
associate-/l*97.2%
remove-double-neg97.2%
distribute-frac-neg297.2%
neg-sub097.2%
remove-double-neg97.2%
unsub-neg97.2%
div-sub97.3%
*-inverses97.3%
metadata-eval97.3%
associate--r-97.3%
neg-sub097.3%
distribute-frac-neg297.3%
remove-double-neg97.3%
sub-neg97.3%
Simplified97.3%
Final simplification97.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 82.7%
associate-/l*97.2%
remove-double-neg97.2%
distribute-frac-neg297.2%
neg-sub097.2%
remove-double-neg97.2%
unsub-neg97.2%
div-sub97.3%
*-inverses97.3%
metadata-eval97.3%
associate--r-97.3%
neg-sub097.3%
distribute-frac-neg297.3%
remove-double-neg97.3%
sub-neg97.3%
Simplified97.3%
Taylor expanded in y around 0 47.1%
Final simplification47.1%
(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 2024052
(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))