
(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 8 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
(let* ((t_0 (/ (* x (+ y z)) z)))
(if (<= t_0 (- INFINITY))
(* x (/ (+ y z) z))
(if (<= t_0 -5e+25) t_0 (/ x (/ z (+ y z)))))))
double code(double x, double y, double z) {
double t_0 = (x * (y + z)) / z;
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = x * ((y + z) / z);
} else if (t_0 <= -5e+25) {
tmp = t_0;
} else {
tmp = x / (z / (y + z));
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = (x * (y + z)) / z;
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = x * ((y + z) / z);
} else if (t_0 <= -5e+25) {
tmp = t_0;
} else {
tmp = x / (z / (y + z));
}
return tmp;
}
def code(x, y, z): t_0 = (x * (y + z)) / z tmp = 0 if t_0 <= -math.inf: tmp = x * ((y + z) / z) elif t_0 <= -5e+25: tmp = t_0 else: tmp = x / (z / (y + z)) return tmp
function code(x, y, z) t_0 = Float64(Float64(x * Float64(y + z)) / z) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(x * Float64(Float64(y + z) / z)); elseif (t_0 <= -5e+25) tmp = t_0; else tmp = Float64(x / Float64(z / Float64(y + z))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * (y + z)) / z; tmp = 0.0; if (t_0 <= -Inf) tmp = x * ((y + z) / z); elseif (t_0 <= -5e+25) tmp = t_0; else tmp = x / (z / (y + z)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -5e+25], t$95$0, N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{+25}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\
\end{array}
\end{array}
if (/.f64 (*.f64 x (+.f64 y z)) z) < -inf.0Initial program 58.9%
associate-*r/100.0%
Simplified100.0%
if -inf.0 < (/.f64 (*.f64 x (+.f64 y z)) z) < -5.00000000000000024e25Initial program 99.6%
if -5.00000000000000024e25 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 85.9%
associate-/l*98.2%
Simplified98.2%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.55e-27) (not (<= y 7.6e+34))) (* x (/ y z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.55e-27) || !(y <= 7.6e+34)) {
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 <= (-1.55d-27)) .or. (.not. (y <= 7.6d+34))) 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 <= -1.55e-27) || !(y <= 7.6e+34)) {
tmp = x * (y / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.55e-27) or not (y <= 7.6e+34): tmp = x * (y / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.55e-27) || !(y <= 7.6e+34)) 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 <= -1.55e-27) || ~((y <= 7.6e+34))) tmp = x * (y / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.55e-27], N[Not[LessEqual[y, 7.6e+34]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.55 \cdot 10^{-27} \lor \neg \left(y \leq 7.6 \cdot 10^{+34}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.5499999999999999e-27 or 7.6000000000000003e34 < y Initial program 90.3%
associate-*r/89.6%
Simplified89.6%
Taylor expanded in y around inf 75.9%
associate-*r/68.2%
Simplified68.2%
if -1.5499999999999999e-27 < y < 7.6000000000000003e34Initial program 78.3%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around 0 83.5%
Final simplification75.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.5e-27) (not (<= y 2.1e+38))) (* y (/ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.5e-27) || !(y <= 2.1e+38)) {
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 ((y <= (-8.5d-27)) .or. (.not. (y <= 2.1d+38))) 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 ((y <= -8.5e-27) || !(y <= 2.1e+38)) {
tmp = y * (x / z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.5e-27) or not (y <= 2.1e+38): tmp = y * (x / z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.5e-27) || !(y <= 2.1e+38)) tmp = Float64(y * Float64(x / z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8.5e-27) || ~((y <= 2.1e+38))) tmp = y * (x / z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.5e-27], N[Not[LessEqual[y, 2.1e+38]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{-27} \lor \neg \left(y \leq 2.1 \cdot 10^{+38}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -8.50000000000000033e-27 or 2.1e38 < y Initial program 90.3%
associate-*r/89.6%
Simplified89.6%
Taylor expanded in y around inf 75.9%
associate-/l*69.7%
Simplified69.7%
associate-/r/71.4%
Applied egg-rr71.4%
if -8.50000000000000033e-27 < y < 2.1e38Initial program 78.3%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around 0 83.5%
Final simplification77.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.1e-26) (not (<= y 2.2e+37))) (/ (* x y) z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.1e-26) || !(y <= 2.2e+37)) {
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 <= (-1.1d-26)) .or. (.not. (y <= 2.2d+37))) 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 <= -1.1e-26) || !(y <= 2.2e+37)) {
tmp = (x * y) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.1e-26) or not (y <= 2.2e+37): tmp = (x * y) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.1e-26) || !(y <= 2.2e+37)) 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 <= -1.1e-26) || ~((y <= 2.2e+37))) tmp = (x * y) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.1e-26], N[Not[LessEqual[y, 2.2e+37]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{-26} \lor \neg \left(y \leq 2.2 \cdot 10^{+37}\right):\\
\;\;\;\;\frac{x \cdot y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.1e-26 or 2.2000000000000001e37 < y Initial program 90.3%
associate-*r/89.6%
Simplified89.6%
Taylor expanded in y around inf 75.9%
if -1.1e-26 < y < 2.2000000000000001e37Initial program 78.3%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around 0 83.5%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (<= y -8.5e-29) (* y (/ x z)) (if (<= y 2.35e+35) x (/ x (/ z y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.5e-29) {
tmp = y * (x / z);
} else if (y <= 2.35e+35) {
tmp = x;
} else {
tmp = x / (z / y);
}
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 <= (-8.5d-29)) then
tmp = y * (x / z)
else if (y <= 2.35d+35) then
tmp = x
else
tmp = x / (z / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8.5e-29) {
tmp = y * (x / z);
} else if (y <= 2.35e+35) {
tmp = x;
} else {
tmp = x / (z / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.5e-29: tmp = y * (x / z) elif y <= 2.35e+35: tmp = x else: tmp = x / (z / y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.5e-29) tmp = Float64(y * Float64(x / z)); elseif (y <= 2.35e+35) tmp = x; else tmp = Float64(x / Float64(z / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.5e-29) tmp = y * (x / z); elseif (y <= 2.35e+35) tmp = x; else tmp = x / (z / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.5e-29], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.35e+35], x, N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{-29}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{elif}\;y \leq 2.35 \cdot 10^{+35}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\end{array}
\end{array}
if y < -8.5000000000000001e-29Initial program 93.0%
associate-*r/89.7%
Simplified89.7%
Taylor expanded in y around inf 74.9%
associate-/l*68.1%
Simplified68.1%
associate-/r/71.4%
Applied egg-rr71.4%
if -8.5000000000000001e-29 < y < 2.35000000000000017e35Initial program 78.3%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around 0 83.5%
if 2.35000000000000017e35 < y Initial program 86.1%
associate-*r/89.5%
Simplified89.5%
Taylor expanded in y around inf 77.3%
associate-/l*72.3%
Simplified72.3%
Final simplification77.2%
(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(x * Float64(Float64(y + z) / z)) end
function tmp = code(x, y, z) tmp = x * ((y + z) / z); end
code[x_, y_, z_] := N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{y + z}{z}
\end{array}
Initial program 84.8%
associate-*r/94.4%
Simplified94.4%
Final simplification94.4%
(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}
Initial program 84.8%
associate-/l*95.2%
Simplified95.2%
Final simplification95.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 84.8%
associate-*r/94.4%
Simplified94.4%
Taylor expanded in y around 0 50.8%
Final simplification50.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 2023297
(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))