
(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 (/ 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 85.0%
associate-*l/83.0%
Simplified83.0%
associate-/r/96.6%
+-commutative96.6%
Applied egg-rr96.6%
Final simplification96.6%
(FPCore (x y z)
:precision binary64
(if (or (<= y -32000000.0)
(and (not (<= y 2.5e-98)) (or (<= y 1.8e-75) (not (<= y 4.1e-7)))))
(* x (/ y z))
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -32000000.0) || (!(y <= 2.5e-98) && ((y <= 1.8e-75) || !(y <= 4.1e-7)))) {
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 ((y <= (-32000000.0d0)) .or. (.not. (y <= 2.5d-98)) .and. (y <= 1.8d-75) .or. (.not. (y <= 4.1d-7))) 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 ((y <= -32000000.0) || (!(y <= 2.5e-98) && ((y <= 1.8e-75) || !(y <= 4.1e-7)))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -32000000.0) or (not (y <= 2.5e-98) and ((y <= 1.8e-75) or not (y <= 4.1e-7))): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -32000000.0) || (!(y <= 2.5e-98) && ((y <= 1.8e-75) || !(y <= 4.1e-7)))) tmp = Float64(x * Float64(y / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -32000000.0) || (~((y <= 2.5e-98)) && ((y <= 1.8e-75) || ~((y <= 4.1e-7))))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -32000000.0], And[N[Not[LessEqual[y, 2.5e-98]], $MachinePrecision], Or[LessEqual[y, 1.8e-75], N[Not[LessEqual[y, 4.1e-7]], $MachinePrecision]]]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -32000000 \lor \neg \left(y \leq 2.5 \cdot 10^{-98}\right) \land \left(y \leq 1.8 \cdot 10^{-75} \lor \neg \left(y \leq 4.1 \cdot 10^{-7}\right)\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.2e7 or 2.50000000000000009e-98 < y < 1.8e-75 or 4.0999999999999999e-7 < y Initial program 84.9%
associate-*l/87.7%
Simplified87.7%
Taylor expanded in z around 0 74.0%
*-commutative74.0%
associate-*r/74.5%
Simplified74.5%
if -3.2e7 < y < 2.50000000000000009e-98 or 1.8e-75 < y < 4.0999999999999999e-7Initial program 85.1%
associate-*l/77.0%
Simplified77.0%
Taylor expanded in z around inf 80.9%
Final simplification77.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (/ x z))))
(if (<= y -29.0)
t_0
(if (<= y 2.5e-98)
x
(if (<= y 7.4e-75) (* x (/ y z)) (if (<= y 2.7e-9) x t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x / z);
double tmp;
if (y <= -29.0) {
tmp = t_0;
} else if (y <= 2.5e-98) {
tmp = x;
} else if (y <= 7.4e-75) {
tmp = x * (y / z);
} else if (y <= 2.7e-9) {
tmp = x;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = y * (x / z)
if (y <= (-29.0d0)) then
tmp = t_0
else if (y <= 2.5d-98) then
tmp = x
else if (y <= 7.4d-75) then
tmp = x * (y / z)
else if (y <= 2.7d-9) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x / z);
double tmp;
if (y <= -29.0) {
tmp = t_0;
} else if (y <= 2.5e-98) {
tmp = x;
} else if (y <= 7.4e-75) {
tmp = x * (y / z);
} else if (y <= 2.7e-9) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x / z) tmp = 0 if y <= -29.0: tmp = t_0 elif y <= 2.5e-98: tmp = x elif y <= 7.4e-75: tmp = x * (y / z) elif y <= 2.7e-9: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x / z)) tmp = 0.0 if (y <= -29.0) tmp = t_0; elseif (y <= 2.5e-98) tmp = x; elseif (y <= 7.4e-75) tmp = Float64(x * Float64(y / z)); elseif (y <= 2.7e-9) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x / z); tmp = 0.0; if (y <= -29.0) tmp = t_0; elseif (y <= 2.5e-98) tmp = x; elseif (y <= 7.4e-75) tmp = x * (y / z); elseif (y <= 2.7e-9) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -29.0], t$95$0, If[LessEqual[y, 2.5e-98], x, If[LessEqual[y, 7.4e-75], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.7e-9], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \frac{x}{z}\\
\mathbf{if}\;y \leq -29:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{-98}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.4 \cdot 10^{-75}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-9}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -29 or 2.7000000000000002e-9 < y Initial program 84.1%
associate-*l/88.4%
Simplified88.4%
Taylor expanded in z around 0 72.7%
associate-*r/75.6%
Simplified75.6%
if -29 < y < 2.50000000000000009e-98 or 7.40000000000000047e-75 < y < 2.7000000000000002e-9Initial program 85.1%
associate-*l/77.0%
Simplified77.0%
Taylor expanded in z around inf 80.9%
if 2.50000000000000009e-98 < y < 7.40000000000000047e-75Initial program 99.6%
associate-*l/73.4%
Simplified73.4%
Taylor expanded in z around 0 99.6%
*-commutative99.6%
associate-*r/99.6%
Simplified99.6%
Final simplification78.5%
(FPCore (x y z)
:precision binary64
(if (<= y -30500.0)
(/ (* x y) z)
(if (<= y 1.25e-98)
x
(if (<= y 7.2e-74) (* x (/ y z)) (if (<= y 2.5e-11) x (* y (/ x z)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -30500.0) {
tmp = (x * y) / z;
} else if (y <= 1.25e-98) {
tmp = x;
} else if (y <= 7.2e-74) {
tmp = x * (y / z);
} else if (y <= 2.5e-11) {
tmp = x;
} else {
tmp = y * (x / 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 <= (-30500.0d0)) then
tmp = (x * y) / z
else if (y <= 1.25d-98) then
tmp = x
else if (y <= 7.2d-74) then
tmp = x * (y / z)
else if (y <= 2.5d-11) then
tmp = x
else
tmp = y * (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -30500.0) {
tmp = (x * y) / z;
} else if (y <= 1.25e-98) {
tmp = x;
} else if (y <= 7.2e-74) {
tmp = x * (y / z);
} else if (y <= 2.5e-11) {
tmp = x;
} else {
tmp = y * (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -30500.0: tmp = (x * y) / z elif y <= 1.25e-98: tmp = x elif y <= 7.2e-74: tmp = x * (y / z) elif y <= 2.5e-11: tmp = x else: tmp = y * (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -30500.0) tmp = Float64(Float64(x * y) / z); elseif (y <= 1.25e-98) tmp = x; elseif (y <= 7.2e-74) tmp = Float64(x * Float64(y / z)); elseif (y <= 2.5e-11) tmp = x; else tmp = Float64(y * Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -30500.0) tmp = (x * y) / z; elseif (y <= 1.25e-98) tmp = x; elseif (y <= 7.2e-74) tmp = x * (y / z); elseif (y <= 2.5e-11) tmp = x; else tmp = y * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -30500.0], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[y, 1.25e-98], x, If[LessEqual[y, 7.2e-74], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.5e-11], x, N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -30500:\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-98}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{-74}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{-11}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\end{array}
\end{array}
if y < -30500Initial program 87.7%
associate-*l/79.1%
Simplified79.1%
Taylor expanded in z around 0 69.8%
if -30500 < y < 1.25000000000000005e-98 or 7.2000000000000005e-74 < y < 2.50000000000000009e-11Initial program 85.1%
associate-*l/77.0%
Simplified77.0%
Taylor expanded in z around inf 80.9%
if 1.25000000000000005e-98 < y < 7.2000000000000005e-74Initial program 99.6%
associate-*l/73.4%
Simplified73.4%
Taylor expanded in z around 0 99.6%
*-commutative99.6%
associate-*r/99.6%
Simplified99.6%
if 2.50000000000000009e-11 < y Initial program 81.8%
associate-*l/94.4%
Simplified94.4%
Taylor expanded in z around 0 74.5%
associate-*r/81.3%
Simplified81.3%
Final simplification79.2%
(FPCore (x y z) :precision binary64 (if (<= z -2.7e+188) x (if (<= z 4.2e+205) (* (/ x z) (+ z y)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+188) {
tmp = x;
} else if (z <= 4.2e+205) {
tmp = (x / z) * (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 <= (-2.7d+188)) then
tmp = x
else if (z <= 4.2d+205) then
tmp = (x / z) * (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 <= -2.7e+188) {
tmp = x;
} else if (z <= 4.2e+205) {
tmp = (x / z) * (z + y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.7e+188: tmp = x elif z <= 4.2e+205: tmp = (x / z) * (z + y) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.7e+188) tmp = x; elseif (z <= 4.2e+205) tmp = Float64(Float64(x / z) * Float64(z + y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.7e+188) tmp = x; elseif (z <= 4.2e+205) tmp = (x / z) * (z + y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.7e+188], x, If[LessEqual[z, 4.2e+205], N[(N[(x / z), $MachinePrecision] * N[(z + y), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+188}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{+205}:\\
\;\;\;\;\frac{x}{z} \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.7e188 or 4.2000000000000001e205 < z Initial program 63.5%
associate-*l/51.2%
Simplified51.2%
Taylor expanded in z around inf 95.9%
if -2.7e188 < z < 4.2000000000000001e205Initial program 90.1%
associate-*l/90.6%
Simplified90.6%
Final simplification91.6%
(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 85.0%
associate-*l/83.0%
Simplified83.0%
Taylor expanded in z around inf 47.8%
Final simplification47.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 2023257
(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))