
(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 7 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 84.4%
associate-*l/83.1%
Simplified83.1%
associate-/r/97.2%
+-commutative97.2%
Applied egg-rr97.2%
Final simplification97.2%
(FPCore (x y z)
:precision binary64
(if (or (<= y -2200000.0)
(not (or (<= y 7.8e+50) (and (not (<= y 1.9e+142)) (<= y 3.6e+176)))))
(* x (/ y z))
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2200000.0) || !((y <= 7.8e+50) || (!(y <= 1.9e+142) && (y <= 3.6e+176)))) {
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 <= (-2200000.0d0)) .or. (.not. (y <= 7.8d+50) .or. (.not. (y <= 1.9d+142)) .and. (y <= 3.6d+176))) 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 <= -2200000.0) || !((y <= 7.8e+50) || (!(y <= 1.9e+142) && (y <= 3.6e+176)))) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2200000.0) or not ((y <= 7.8e+50) or (not (y <= 1.9e+142) and (y <= 3.6e+176))): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2200000.0) || !((y <= 7.8e+50) || (!(y <= 1.9e+142) && (y <= 3.6e+176)))) 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 <= -2200000.0) || ~(((y <= 7.8e+50) || (~((y <= 1.9e+142)) && (y <= 3.6e+176))))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2200000.0], N[Not[Or[LessEqual[y, 7.8e+50], And[N[Not[LessEqual[y, 1.9e+142]], $MachinePrecision], LessEqual[y, 3.6e+176]]]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2200000 \lor \neg \left(y \leq 7.8 \cdot 10^{+50} \lor \neg \left(y \leq 1.9 \cdot 10^{+142}\right) \land y \leq 3.6 \cdot 10^{+176}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.2e6 or 7.79999999999999935e50 < y < 1.89999999999999995e142 or 3.59999999999999991e176 < y Initial program 92.7%
associate-*l/89.8%
Simplified89.8%
Taylor expanded in z around 0 78.9%
associate-*r/72.6%
Simplified72.6%
if -2.2e6 < y < 7.79999999999999935e50 or 1.89999999999999995e142 < y < 3.59999999999999991e176Initial program 78.8%
associate-*l/78.6%
Simplified78.6%
Taylor expanded in z around inf 79.4%
Final simplification76.7%
(FPCore (x y z)
:precision binary64
(if (or (<= y -620000.0)
(not (or (<= y 8.8e+50) (and (not (<= y 6e+149)) (<= y 3.6e+176)))))
(/ (* x y) z)
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -620000.0) || !((y <= 8.8e+50) || (!(y <= 6e+149) && (y <= 3.6e+176)))) {
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 <= (-620000.0d0)) .or. (.not. (y <= 8.8d+50) .or. (.not. (y <= 6d+149)) .and. (y <= 3.6d+176))) 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 <= -620000.0) || !((y <= 8.8e+50) || (!(y <= 6e+149) && (y <= 3.6e+176)))) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -620000.0) or not ((y <= 8.8e+50) or (not (y <= 6e+149) and (y <= 3.6e+176))): tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -620000.0) || !((y <= 8.8e+50) || (!(y <= 6e+149) && (y <= 3.6e+176)))) tmp = Float64(Float64(x * y) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -620000.0) || ~(((y <= 8.8e+50) || (~((y <= 6e+149)) && (y <= 3.6e+176))))) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -620000.0], N[Not[Or[LessEqual[y, 8.8e+50], And[N[Not[LessEqual[y, 6e+149]], $MachinePrecision], LessEqual[y, 3.6e+176]]]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -620000 \lor \neg \left(y \leq 8.8 \cdot 10^{+50} \lor \neg \left(y \leq 6 \cdot 10^{+149}\right) \land y \leq 3.6 \cdot 10^{+176}\right):\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.2e5 or 8.80000000000000067e50 < y < 6.00000000000000007e149 or 3.59999999999999991e176 < y Initial program 92.7%
associate-*l/89.8%
Simplified89.8%
Taylor expanded in z around 0 78.9%
if -6.2e5 < y < 8.80000000000000067e50 or 6.00000000000000007e149 < y < 3.59999999999999991e176Initial program 78.8%
associate-*l/78.6%
Simplified78.6%
Taylor expanded in z around inf 79.4%
Final simplification79.2%
(FPCore (x y z)
:precision binary64
(if (<= z -7.5e-53)
x
(if (or (<= z 8e-105) (and (not (<= z 1.15e-82)) (<= z 1.25e-17)))
(/ y (/ z x))
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.5e-53) {
tmp = x;
} else if ((z <= 8e-105) || (!(z <= 1.15e-82) && (z <= 1.25e-17))) {
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 <= (-7.5d-53)) then
tmp = x
else if ((z <= 8d-105) .or. (.not. (z <= 1.15d-82)) .and. (z <= 1.25d-17)) 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 <= -7.5e-53) {
tmp = x;
} else if ((z <= 8e-105) || (!(z <= 1.15e-82) && (z <= 1.25e-17))) {
tmp = y / (z / x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7.5e-53: tmp = x elif (z <= 8e-105) or (not (z <= 1.15e-82) and (z <= 1.25e-17)): tmp = y / (z / x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7.5e-53) tmp = x; elseif ((z <= 8e-105) || (!(z <= 1.15e-82) && (z <= 1.25e-17))) 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 <= -7.5e-53) tmp = x; elseif ((z <= 8e-105) || (~((z <= 1.15e-82)) && (z <= 1.25e-17))) tmp = y / (z / x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7.5e-53], x, If[Or[LessEqual[z, 8e-105], And[N[Not[LessEqual[z, 1.15e-82]], $MachinePrecision], LessEqual[z, 1.25e-17]]], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{-53}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8 \cdot 10^{-105} \lor \neg \left(z \leq 1.15 \cdot 10^{-82}\right) \land z \leq 1.25 \cdot 10^{-17}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.5000000000000001e-53 or 7.99999999999999972e-105 < z < 1.14999999999999998e-82 or 1.25e-17 < z Initial program 78.4%
associate-*l/76.6%
Simplified76.6%
Taylor expanded in z around inf 80.0%
if -7.5000000000000001e-53 < z < 7.99999999999999972e-105 or 1.14999999999999998e-82 < z < 1.25e-17Initial program 92.7%
associate-*l/92.1%
Simplified92.1%
Taylor expanded in z around 0 74.3%
associate-*r/71.9%
Simplified71.9%
associate-*r/74.3%
*-commutative74.3%
associate-/l*76.7%
Applied egg-rr76.7%
Final simplification78.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ x (/ z y))))
(if (<= y -8000000.0)
t_0
(if (<= y 3.7e+50)
x
(if (<= y 5.8e+149) (* x (/ y z)) (if (<= y 4.1e+176) x t_0))))))
double code(double x, double y, double z) {
double t_0 = x / (z / y);
double tmp;
if (y <= -8000000.0) {
tmp = t_0;
} else if (y <= 3.7e+50) {
tmp = x;
} else if (y <= 5.8e+149) {
tmp = x * (y / z);
} else if (y <= 4.1e+176) {
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 = x / (z / y)
if (y <= (-8000000.0d0)) then
tmp = t_0
else if (y <= 3.7d+50) then
tmp = x
else if (y <= 5.8d+149) then
tmp = x * (y / z)
else if (y <= 4.1d+176) 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 = x / (z / y);
double tmp;
if (y <= -8000000.0) {
tmp = t_0;
} else if (y <= 3.7e+50) {
tmp = x;
} else if (y <= 5.8e+149) {
tmp = x * (y / z);
} else if (y <= 4.1e+176) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x / (z / y) tmp = 0 if y <= -8000000.0: tmp = t_0 elif y <= 3.7e+50: tmp = x elif y <= 5.8e+149: tmp = x * (y / z) elif y <= 4.1e+176: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x / Float64(z / y)) tmp = 0.0 if (y <= -8000000.0) tmp = t_0; elseif (y <= 3.7e+50) tmp = x; elseif (y <= 5.8e+149) tmp = Float64(x * Float64(y / z)); elseif (y <= 4.1e+176) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x / (z / y); tmp = 0.0; if (y <= -8000000.0) tmp = t_0; elseif (y <= 3.7e+50) tmp = x; elseif (y <= 5.8e+149) tmp = x * (y / z); elseif (y <= 4.1e+176) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8000000.0], t$95$0, If[LessEqual[y, 3.7e+50], x, If[LessEqual[y, 5.8e+149], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.1e+176], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{\frac{z}{y}}\\
\mathbf{if}\;y \leq -8000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{+50}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{+149}:\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{+176}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -8e6 or 4.0999999999999999e176 < y Initial program 91.3%
associate-*l/90.0%
Simplified90.0%
associate-/r/94.1%
+-commutative94.1%
Applied egg-rr94.1%
Taylor expanded in z around 0 77.0%
associate-/l*72.4%
Simplified72.4%
if -8e6 < y < 3.7000000000000001e50 or 5.8000000000000004e149 < y < 4.0999999999999999e176Initial program 78.8%
associate-*l/78.6%
Simplified78.6%
Taylor expanded in z around inf 79.4%
if 3.7000000000000001e50 < y < 5.8000000000000004e149Initial program 99.7%
associate-*l/88.6%
Simplified88.6%
Taylor expanded in z around 0 88.5%
associate-*r/77.6%
Simplified77.6%
Final simplification76.9%
(FPCore (x y z) :precision binary64 (* x (+ 1.0 (/ y z))))
double code(double x, double y, double z) {
return x * (1.0 + (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 * (1.0d0 + (y / z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 + (y / z));
}
def code(x, y, z): return x * (1.0 + (y / z))
function code(x, y, z) return Float64(x * Float64(1.0 + Float64(y / z))) end
function tmp = code(x, y, z) tmp = x * (1.0 + (y / z)); end
code[x_, y_, z_] := N[(x * N[(1.0 + N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + \frac{y}{z}\right)
\end{array}
Initial program 84.4%
associate-*r/97.0%
remove-double-neg97.0%
sub-neg97.0%
div-sub97.0%
distribute-frac-neg97.0%
*-inverses97.0%
metadata-eval97.0%
sub-neg97.0%
metadata-eval97.0%
*-inverses97.0%
distribute-lft-out97.0%
*-inverses97.0%
*-rgt-identity97.0%
fma-def97.0%
Simplified97.0%
Taylor expanded in x around 0 97.0%
Final simplification97.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 84.4%
associate-*l/83.1%
Simplified83.1%
Taylor expanded in z around inf 55.7%
Final simplification55.7%
(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 2023310
(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))