
(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.0%
associate-/l*97.3%
remove-double-neg97.3%
distribute-frac-neg297.3%
neg-sub097.3%
remove-double-neg97.3%
unsub-neg97.3%
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%
(FPCore (x y z) :precision binary64 (if (<= z -8e-5) x (if (<= z 1.05e-29) (/ y (/ z x)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8e-5) {
tmp = x;
} else if (z <= 1.05e-29) {
tmp = y / (z / x);
} 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 <= (-8d-5)) then
tmp = x
else if (z <= 1.05d-29) then
tmp = y / (z / x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -8e-5) {
tmp = x;
} else if (z <= 1.05e-29) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8e-5: tmp = x elif z <= 1.05e-29: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8e-5) tmp = x; elseif (z <= 1.05e-29) tmp = Float64(y / Float64(z / x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8e-5) tmp = x; elseif (z <= 1.05e-29) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8e-5], x, If[LessEqual[z, 1.05e-29], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{-29}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.00000000000000065e-5 or 1.04999999999999995e-29 < z Initial program 75.0%
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.9%
if -8.00000000000000065e-5 < z < 1.04999999999999995e-29Initial program 91.7%
associate-/l*94.5%
remove-double-neg94.5%
distribute-frac-neg294.5%
neg-sub094.5%
remove-double-neg94.5%
unsub-neg94.5%
div-sub94.5%
*-inverses94.5%
metadata-eval94.5%
associate--r-94.5%
neg-sub094.5%
distribute-frac-neg294.5%
remove-double-neg94.5%
sub-neg94.5%
Simplified94.5%
Taylor expanded in y around inf 74.7%
associate-*r/76.0%
Simplified76.0%
associate-*r/74.7%
*-commutative74.7%
associate-*r/76.9%
clear-num76.9%
un-div-inv77.6%
Applied egg-rr77.6%
(FPCore (x y z) :precision binary64 (if (<= z -4.6e-5) x (if (<= z 1.35e-34) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.6e-5) {
tmp = x;
} else if (z <= 1.35e-34) {
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 <= (-4.6d-5)) then
tmp = x
else if (z <= 1.35d-34) 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 <= -4.6e-5) {
tmp = x;
} else if (z <= 1.35e-34) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.6e-5: tmp = x elif z <= 1.35e-34: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.6e-5) tmp = x; elseif (z <= 1.35e-34) 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 <= -4.6e-5) tmp = x; elseif (z <= 1.35e-34) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.6e-5], x, If[LessEqual[z, 1.35e-34], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{-34}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.6e-5 or 1.35000000000000008e-34 < z Initial program 75.0%
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.9%
if -4.6e-5 < z < 1.35000000000000008e-34Initial program 91.7%
associate-/l*94.5%
remove-double-neg94.5%
distribute-frac-neg294.5%
neg-sub094.5%
remove-double-neg94.5%
unsub-neg94.5%
div-sub94.5%
*-inverses94.5%
metadata-eval94.5%
associate--r-94.5%
neg-sub094.5%
distribute-frac-neg294.5%
remove-double-neg94.5%
sub-neg94.5%
Simplified94.5%
Taylor expanded in y around inf 74.7%
associate-*l/76.9%
*-commutative76.9%
Simplified76.9%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e-6) x (if (<= z 1.55e-34) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e-6) {
tmp = x;
} else if (z <= 1.55e-34) {
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 <= (-2.2d-6)) then
tmp = x
else if (z <= 1.55d-34) 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 <= -2.2e-6) {
tmp = x;
} else if (z <= 1.55e-34) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e-6: tmp = x elif z <= 1.55e-34: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e-6) tmp = x; elseif (z <= 1.55e-34) 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 <= -2.2e-6) tmp = x; elseif (z <= 1.55e-34) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e-6], x, If[LessEqual[z, 1.55e-34], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.55 \cdot 10^{-34}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.2000000000000001e-6 or 1.5499999999999999e-34 < z Initial program 75.0%
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.9%
if -2.2000000000000001e-6 < z < 1.5499999999999999e-34Initial program 91.7%
associate-/l*94.5%
remove-double-neg94.5%
distribute-frac-neg294.5%
neg-sub094.5%
remove-double-neg94.5%
unsub-neg94.5%
div-sub94.5%
*-inverses94.5%
metadata-eval94.5%
associate--r-94.5%
neg-sub094.5%
distribute-frac-neg294.5%
remove-double-neg94.5%
sub-neg94.5%
Simplified94.5%
Taylor expanded in y around inf 74.7%
associate-*r/76.0%
Simplified76.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.0%
associate-/l*97.3%
remove-double-neg97.3%
distribute-frac-neg297.3%
neg-sub097.3%
remove-double-neg97.3%
unsub-neg97.3%
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 49.6%
(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 2024091
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))