
(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 (if (<= y -1.1e+200) (* (+ z y) (/ x z)) (+ x (* x (/ y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e+200) {
tmp = (z + y) * (x / z);
} else {
tmp = x + (x * (y / 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 <= (-1.1d+200)) then
tmp = (z + y) * (x / z)
else
tmp = x + (x * (y / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.1e+200) {
tmp = (z + y) * (x / z);
} else {
tmp = x + (x * (y / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.1e+200: tmp = (z + y) * (x / z) else: tmp = x + (x * (y / z)) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.1e+200) tmp = Float64(Float64(z + y) * Float64(x / z)); else tmp = Float64(x + Float64(x * Float64(y / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.1e+200) tmp = (z + y) * (x / z); else tmp = x + (x * (y / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.1e+200], N[(N[(z + y), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+200}:\\
\;\;\;\;\left(z + y\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\
\end{array}
\end{array}
if y < -1.1e200Initial program 83.7%
associate-*l/97.5%
Simplified97.5%
if -1.1e200 < y Initial program 81.1%
associate-*l/85.7%
distribute-rgt-in81.4%
*-commutative81.4%
associate-/r/95.7%
*-inverses95.7%
/-rgt-identity95.7%
associate-*r/91.0%
*-commutative91.0%
associate-*r/97.9%
fma-def97.9%
Simplified97.9%
fma-udef97.9%
Applied egg-rr97.9%
Final simplification97.8%
(FPCore (x y z) :precision binary64 (if (<= z -2.95e+137) x (if (<= z 2.1e+120) (* (+ z y) (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.95e+137) {
tmp = x;
} else if (z <= 2.1e+120) {
tmp = (z + 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 <= (-2.95d+137)) then
tmp = x
else if (z <= 2.1d+120) then
tmp = (z + 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 <= -2.95e+137) {
tmp = x;
} else if (z <= 2.1e+120) {
tmp = (z + y) * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.95e+137: tmp = x elif z <= 2.1e+120: tmp = (z + y) * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.95e+137) tmp = x; elseif (z <= 2.1e+120) tmp = Float64(Float64(z + y) * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.95e+137) tmp = x; elseif (z <= 2.1e+120) tmp = (z + y) * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.95e+137], x, If[LessEqual[z, 2.1e+120], N[(N[(z + y), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.95 \cdot 10^{+137}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{+120}:\\
\;\;\;\;\left(z + y\right) \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.95000000000000018e137 or 2.1e120 < z Initial program 63.1%
associate-*l/71.1%
Simplified71.1%
Taylor expanded in z around inf 91.3%
if -2.95000000000000018e137 < z < 2.1e120Initial program 89.5%
associate-*l/93.7%
Simplified93.7%
Final simplification93.0%
(FPCore (x y z) :precision binary64 (if (<= z -2e-140) x (if (<= z 42000000000.0) (* x (/ y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2e-140) {
tmp = x;
} else if (z <= 42000000000.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 <= (-2d-140)) then
tmp = x
else if (z <= 42000000000.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 <= -2e-140) {
tmp = x;
} else if (z <= 42000000000.0) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2e-140: tmp = x elif z <= 42000000000.0: tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2e-140) tmp = x; elseif (z <= 42000000000.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 <= -2e-140) tmp = x; elseif (z <= 42000000000.0) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2e-140], x, If[LessEqual[z, 42000000000.0], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{-140}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 42000000000:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2e-140 or 4.2e10 < z Initial program 77.3%
associate-*l/81.4%
Simplified81.4%
Taylor expanded in z around inf 75.9%
if -2e-140 < z < 4.2e10Initial program 87.3%
associate-*l/94.5%
Simplified94.5%
Taylor expanded in z around 0 78.4%
*-commutative78.4%
associate-*r/75.8%
Simplified75.8%
Final simplification75.8%
(FPCore (x y z) :precision binary64 (if (<= z -4.3e-39) x (if (<= z 1250000000000.0) (* y (/ x z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.3e-39) {
tmp = x;
} else if (z <= 1250000000000.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 <= (-4.3d-39)) then
tmp = x
else if (z <= 1250000000000.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 <= -4.3e-39) {
tmp = x;
} else if (z <= 1250000000000.0) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.3e-39: tmp = x elif z <= 1250000000000.0: tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.3e-39) tmp = x; elseif (z <= 1250000000000.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 <= -4.3e-39) tmp = x; elseif (z <= 1250000000000.0) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.3e-39], x, If[LessEqual[z, 1250000000000.0], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.3 \cdot 10^{-39}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1250000000000:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.2999999999999999e-39 or 1.25e12 < z Initial program 76.7%
associate-*l/80.9%
Simplified80.9%
Taylor expanded in z around inf 77.7%
if -4.2999999999999999e-39 < z < 1.25e12Initial program 87.2%
associate-*l/94.1%
Simplified94.1%
Taylor expanded in z around 0 75.9%
associate-*r/79.0%
Simplified79.0%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (/ x (/ z (+ z y))))
double code(double x, double y, double z) {
return x / (z / (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 / (z / (z + y))
end function
public static double code(double x, double y, double z) {
return x / (z / (z + y));
}
def code(x, y, z): return x / (z / (z + y))
function code(x, y, z) return Float64(x / Float64(z / Float64(z + y))) end
function tmp = code(x, y, z) tmp = x / (z / (z + y)); end
code[x_, y_, z_] := N[(x / N[(z / N[(z + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{z + y}}
\end{array}
Initial program 81.4%
associate-*l/86.8%
Simplified86.8%
associate-/r/96.8%
+-commutative96.8%
Applied egg-rr96.8%
Final simplification96.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 81.4%
associate-*l/86.8%
Simplified86.8%
Taylor expanded in z around inf 51.9%
Final simplification51.9%
(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 2023224
(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))