
(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 6 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 (/ 1.0 (/ (/ z (+ z y)) x)))
double code(double x, double y, double z) {
return 1.0 / ((z / (z + y)) / x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 / ((z / (z + y)) / x)
end function
public static double code(double x, double y, double z) {
return 1.0 / ((z / (z + y)) / x);
}
def code(x, y, z): return 1.0 / ((z / (z + y)) / x)
function code(x, y, z) return Float64(1.0 / Float64(Float64(z / Float64(z + y)) / x)) end
function tmp = code(x, y, z) tmp = 1.0 / ((z / (z + y)) / x); end
code[x_, y_, z_] := N[(1.0 / N[(N[(z / N[(z + y), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{\frac{z}{z + y}}{x}}
\end{array}
Initial program 73.6%
*-commutative73.6%
associate-/l*87.3%
Simplified87.3%
add-cube-cbrt86.1%
pow386.1%
Applied egg-rr86.1%
rem-cube-cbrt87.3%
clear-num87.1%
div-inv87.7%
div-inv87.5%
associate-/r*96.4%
+-commutative96.4%
Applied egg-rr96.4%
clear-num96.4%
inv-pow96.4%
div-inv96.3%
clear-num96.6%
Applied egg-rr96.6%
unpow-196.6%
associate-*l/96.6%
*-lft-identity96.6%
+-commutative96.6%
Simplified96.6%
Final simplification96.6%
(FPCore (x y z) :precision binary64 (if (<= z -2.25e-10) x (if (<= z 170000.0) (/ y (/ z x)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.25e-10) {
tmp = x;
} else if (z <= 170000.0) {
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 <= (-2.25d-10)) then
tmp = x
else if (z <= 170000.0d0) 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 <= -2.25e-10) {
tmp = x;
} else if (z <= 170000.0) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.25e-10: tmp = x elif z <= 170000.0: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.25e-10) tmp = x; elseif (z <= 170000.0) 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 <= -2.25e-10) tmp = x; elseif (z <= 170000.0) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.25e-10], x, If[LessEqual[z, 170000.0], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.25 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 170000:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.25e-10 or 1.7e5 < z Initial program 59.1%
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 83.5%
if -2.25e-10 < z < 1.7e5Initial program 87.1%
associate-/l*93.4%
remove-double-neg93.4%
unsub-neg93.4%
div-sub93.4%
remove-double-neg93.4%
distribute-frac-neg293.4%
*-inverses93.4%
metadata-eval93.4%
Simplified93.4%
Taylor expanded in y around inf 67.7%
associate-*l/71.2%
*-commutative71.2%
Simplified71.2%
clear-num71.1%
un-div-inv71.3%
Applied egg-rr71.3%
(FPCore (x y z) :precision binary64 (if (<= z -7.5e-11) x (if (<= z 25000.0) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.5e-11) {
tmp = x;
} else if (z <= 25000.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 (z <= (-7.5d-11)) then
tmp = x
else if (z <= 25000.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 (z <= -7.5e-11) {
tmp = x;
} else if (z <= 25000.0) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.5e-11: tmp = x elif z <= 25000.0: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.5e-11) tmp = x; elseif (z <= 25000.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 (z <= -7.5e-11) tmp = x; elseif (z <= 25000.0) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.5e-11], x, If[LessEqual[z, 25000.0], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{-11}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 25000:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.5e-11 or 25000 < z Initial program 59.1%
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 83.5%
if -7.5e-11 < z < 25000Initial program 87.1%
associate-/l*93.4%
remove-double-neg93.4%
unsub-neg93.4%
div-sub93.4%
remove-double-neg93.4%
distribute-frac-neg293.4%
*-inverses93.4%
metadata-eval93.4%
Simplified93.4%
Taylor expanded in y around inf 67.7%
associate-*l/71.2%
*-commutative71.2%
Simplified71.2%
(FPCore (x y z) :precision binary64 (if (<= z -2.4e-10) x (if (<= z 30000000.0) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e-10) {
tmp = x;
} else if (z <= 30000000.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 (z <= (-2.4d-10)) then
tmp = x
else if (z <= 30000000.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 (z <= -2.4e-10) {
tmp = x;
} else if (z <= 30000000.0) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.4e-10: tmp = x elif z <= 30000000.0: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.4e-10) tmp = x; elseif (z <= 30000000.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 (z <= -2.4e-10) tmp = x; elseif (z <= 30000000.0) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.4e-10], x, If[LessEqual[z, 30000000.0], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 30000000:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.4e-10 or 3e7 < z Initial program 59.1%
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 83.5%
if -2.4e-10 < z < 3e7Initial program 87.1%
associate-/l*93.4%
remove-double-neg93.4%
unsub-neg93.4%
div-sub93.4%
remove-double-neg93.4%
distribute-frac-neg293.4%
*-inverses93.4%
metadata-eval93.4%
Simplified93.4%
Taylor expanded in y around inf 67.0%
(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 73.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 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 73.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 54.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 2024181
(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))