
(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 (+ x (* x (/ y z))))
double code(double x, double y, double z) {
return x + (x * (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 + (x * (y / z))
end function
public static double code(double x, double y, double z) {
return x + (x * (y / z));
}
def code(x, y, z): return x + (x * (y / z))
function code(x, y, z) return Float64(x + Float64(x * Float64(y / z))) end
function tmp = code(x, y, z) tmp = x + (x * (y / z)); end
code[x_, y_, z_] := N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot \frac{y}{z}
\end{array}
Initial program 81.6%
remove-double-neg81.6%
distribute-lft-neg-out81.6%
*-commutative81.6%
distribute-lft-neg-in81.6%
associate-/l*89.7%
distribute-neg-in89.7%
unsub-neg89.7%
div-sub87.0%
distribute-frac-neg87.0%
associate-/r/85.5%
distribute-rgt-neg-out85.5%
remove-double-neg85.5%
associate-/r/96.6%
*-inverses96.6%
*-lft-identity96.6%
*-commutative96.6%
fma-neg96.6%
remove-double-neg96.6%
Simplified96.6%
fma-udef96.6%
Applied egg-rr96.6%
Final simplification96.6%
(FPCore (x y z) :precision binary64 (if (<= z -1.12e-18) x (if (<= z 5.5e-79) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.12e-18) {
tmp = x;
} else if (z <= 5.5e-79) {
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.12d-18)) then
tmp = x
else if (z <= 5.5d-79) 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.12e-18) {
tmp = x;
} else if (z <= 5.5e-79) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.12e-18: tmp = x elif z <= 5.5e-79: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.12e-18) tmp = x; elseif (z <= 5.5e-79) 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.12e-18) tmp = x; elseif (z <= 5.5e-79) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.12e-18], x, If[LessEqual[z, 5.5e-79], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.12 \cdot 10^{-18}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-79}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.12000000000000001e-18 or 5.4999999999999997e-79 < z Initial program 74.3%
associate-*l/87.4%
*-commutative87.4%
Simplified87.4%
Taylor expanded in y around 0 72.7%
if -1.12000000000000001e-18 < z < 5.4999999999999997e-79Initial program 91.9%
associate-*l/90.0%
*-commutative90.0%
Simplified90.0%
Taylor expanded in y around inf 77.8%
associate-*r/75.2%
Simplified75.2%
Final simplification73.7%
(FPCore (x y z) :precision binary64 (if (<= z -5e-15) x (if (<= z 2.3e-78) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5e-15) {
tmp = x;
} else if (z <= 2.3e-78) {
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 <= (-5d-15)) then
tmp = x
else if (z <= 2.3d-78) 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 <= -5e-15) {
tmp = x;
} else if (z <= 2.3e-78) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5e-15: tmp = x elif z <= 2.3e-78: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5e-15) tmp = x; elseif (z <= 2.3e-78) 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 <= -5e-15) tmp = x; elseif (z <= 2.3e-78) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5e-15], x, If[LessEqual[z, 2.3e-78], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{-15}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-78}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.99999999999999999e-15 or 2.3000000000000002e-78 < z Initial program 74.3%
associate-*l/87.4%
*-commutative87.4%
Simplified87.4%
Taylor expanded in y around 0 72.7%
if -4.99999999999999999e-15 < z < 2.3000000000000002e-78Initial program 91.9%
associate-*l/90.0%
*-commutative90.0%
Simplified90.0%
Taylor expanded in y around inf 77.8%
associate-/l*75.1%
associate-/r/79.7%
Applied egg-rr79.7%
Final simplification75.6%
(FPCore (x y z) :precision binary64 (if (<= z -1.72e-19) x (if (<= z 2.1e-78) (/ y (/ z x)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.72e-19) {
tmp = x;
} else if (z <= 2.1e-78) {
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 <= (-1.72d-19)) then
tmp = x
else if (z <= 2.1d-78) 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 <= -1.72e-19) {
tmp = x;
} else if (z <= 2.1e-78) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.72e-19: tmp = x elif z <= 2.1e-78: tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.72e-19) tmp = x; elseif (z <= 2.1e-78) 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 <= -1.72e-19) tmp = x; elseif (z <= 2.1e-78) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.72e-19], x, If[LessEqual[z, 2.1e-78], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.72 \cdot 10^{-19}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-78}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.72000000000000004e-19 or 2.1000000000000001e-78 < z Initial program 74.3%
associate-*l/87.4%
*-commutative87.4%
Simplified87.4%
Taylor expanded in y around 0 72.7%
if -1.72000000000000004e-19 < z < 2.1000000000000001e-78Initial program 91.9%
associate-*l/90.0%
*-commutative90.0%
Simplified90.0%
Taylor expanded in y around inf 77.8%
associate-*r/75.2%
Simplified75.2%
associate-*r/77.8%
*-commutative77.8%
associate-/l*80.7%
Applied egg-rr80.7%
Final simplification76.0%
(FPCore (x y z) :precision binary64 (if (<= z 5.8e+200) (* (+ y z) (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if (z <= 5.8e+200) {
tmp = (y + z) * (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 <= 5.8d+200) then
tmp = (y + z) * (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 <= 5.8e+200) {
tmp = (y + z) * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 5.8e+200: tmp = (y + z) * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= 5.8e+200) tmp = Float64(Float64(y + z) * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 5.8e+200) tmp = (y + z) * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 5.8e+200], N[(N[(y + z), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5.8 \cdot 10^{+200}:\\
\;\;\;\;\left(y + z\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < 5.7999999999999998e200Initial program 85.2%
associate-*l/89.8%
*-commutative89.8%
Simplified89.8%
if 5.7999999999999998e200 < z Initial program 43.9%
associate-*l/74.8%
*-commutative74.8%
Simplified74.8%
Taylor expanded in y around 0 95.1%
Final simplification90.2%
(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 81.6%
associate-*l/88.5%
*-commutative88.5%
Simplified88.5%
Taylor expanded in y around 0 50.5%
Final simplification50.5%
(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 2024018
(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))