
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) / 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 - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) / 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 - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
(FPCore (x y z) :precision binary64 (+ x (/ (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) / 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 - x) / z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) / z);
}
def code(x, y, z): return x + ((y - x) / z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) / z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) / z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y - x}{z}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (- x) z)))
(if (<= z -3.15e+147)
x
(if (<= z -2.4e-209)
(/ y z)
(if (<= z -2.1e-233)
t_0
(if (<= z 8e-210)
(/ y z)
(if (<= z 2.35e-117) t_0 (if (<= z 2.15e+69) (/ y z) x))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -3.15e+147) {
tmp = x;
} else if (z <= -2.4e-209) {
tmp = y / z;
} else if (z <= -2.1e-233) {
tmp = t_0;
} else if (z <= 8e-210) {
tmp = y / z;
} else if (z <= 2.35e-117) {
tmp = t_0;
} else if (z <= 2.15e+69) {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = -x / z
if (z <= (-3.15d+147)) then
tmp = x
else if (z <= (-2.4d-209)) then
tmp = y / z
else if (z <= (-2.1d-233)) then
tmp = t_0
else if (z <= 8d-210) then
tmp = y / z
else if (z <= 2.35d-117) then
tmp = t_0
else if (z <= 2.15d+69) then
tmp = y / z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -3.15e+147) {
tmp = x;
} else if (z <= -2.4e-209) {
tmp = y / z;
} else if (z <= -2.1e-233) {
tmp = t_0;
} else if (z <= 8e-210) {
tmp = y / z;
} else if (z <= 2.35e-117) {
tmp = t_0;
} else if (z <= 2.15e+69) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -3.15e+147: tmp = x elif z <= -2.4e-209: tmp = y / z elif z <= -2.1e-233: tmp = t_0 elif z <= 8e-210: tmp = y / z elif z <= 2.35e-117: tmp = t_0 elif z <= 2.15e+69: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -3.15e+147) tmp = x; elseif (z <= -2.4e-209) tmp = Float64(y / z); elseif (z <= -2.1e-233) tmp = t_0; elseif (z <= 8e-210) tmp = Float64(y / z); elseif (z <= 2.35e-117) tmp = t_0; elseif (z <= 2.15e+69) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x / z; tmp = 0.0; if (z <= -3.15e+147) tmp = x; elseif (z <= -2.4e-209) tmp = y / z; elseif (z <= -2.1e-233) tmp = t_0; elseif (z <= 8e-210) tmp = y / z; elseif (z <= 2.35e-117) tmp = t_0; elseif (z <= 2.15e+69) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -3.15e+147], x, If[LessEqual[z, -2.4e-209], N[(y / z), $MachinePrecision], If[LessEqual[z, -2.1e-233], t$95$0, If[LessEqual[z, 8e-210], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.35e-117], t$95$0, If[LessEqual[z, 2.15e+69], N[(y / z), $MachinePrecision], x]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -3.15 \cdot 10^{+147}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -2.4 \cdot 10^{-209}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -2.1 \cdot 10^{-233}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 8 \cdot 10^{-210}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.35 \cdot 10^{-117}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 2.15 \cdot 10^{+69}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.14999999999999991e147 or 2.14999999999999996e69 < z Initial program 100.0%
Taylor expanded in z around inf 85.2%
if -3.14999999999999991e147 < z < -2.4000000000000001e-209 or -2.0999999999999999e-233 < z < 8.0000000000000004e-210 or 2.35000000000000004e-117 < z < 2.14999999999999996e69Initial program 100.0%
Taylor expanded in x around 0 60.6%
if -2.4000000000000001e-209 < z < -2.0999999999999999e-233 or 8.0000000000000004e-210 < z < 2.35000000000000004e-117Initial program 100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in y around 0 77.6%
neg-mul-177.6%
distribute-neg-frac77.6%
Simplified77.6%
Final simplification70.2%
(FPCore (x y z)
:precision binary64
(if (<= z -3.15e+147)
x
(if (<= z 0.0011)
(/ (- y x) z)
(if (<= z 1e+31) (+ x (* x (/ -1.0 z))) (if (<= z 2.2e+69) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.15e+147) {
tmp = x;
} else if (z <= 0.0011) {
tmp = (y - x) / z;
} else if (z <= 1e+31) {
tmp = x + (x * (-1.0 / z));
} else if (z <= 2.2e+69) {
tmp = 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 <= (-3.15d+147)) then
tmp = x
else if (z <= 0.0011d0) then
tmp = (y - x) / z
else if (z <= 1d+31) then
tmp = x + (x * ((-1.0d0) / z))
else if (z <= 2.2d+69) then
tmp = 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 <= -3.15e+147) {
tmp = x;
} else if (z <= 0.0011) {
tmp = (y - x) / z;
} else if (z <= 1e+31) {
tmp = x + (x * (-1.0 / z));
} else if (z <= 2.2e+69) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.15e+147: tmp = x elif z <= 0.0011: tmp = (y - x) / z elif z <= 1e+31: tmp = x + (x * (-1.0 / z)) elif z <= 2.2e+69: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.15e+147) tmp = x; elseif (z <= 0.0011) tmp = Float64(Float64(y - x) / z); elseif (z <= 1e+31) tmp = Float64(x + Float64(x * Float64(-1.0 / z))); elseif (z <= 2.2e+69) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.15e+147) tmp = x; elseif (z <= 0.0011) tmp = (y - x) / z; elseif (z <= 1e+31) tmp = x + (x * (-1.0 / z)); elseif (z <= 2.2e+69) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.15e+147], x, If[LessEqual[z, 0.0011], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[z, 1e+31], N[(x + N[(x * N[(-1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.2e+69], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.15 \cdot 10^{+147}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 0.0011:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{elif}\;z \leq 10^{+31}:\\
\;\;\;\;x + x \cdot \frac{-1}{z}\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{+69}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.14999999999999991e147 or 2.2000000000000002e69 < z Initial program 100.0%
Taylor expanded in z around inf 85.2%
if -3.14999999999999991e147 < z < 0.00110000000000000007Initial program 100.0%
Taylor expanded in z around 0 95.3%
if 0.00110000000000000007 < z < 9.9999999999999996e30Initial program 99.8%
Taylor expanded in x around inf 86.3%
*-commutative86.3%
sub-neg86.3%
distribute-rgt-in86.3%
*-lft-identity86.3%
distribute-neg-frac86.3%
metadata-eval86.3%
Simplified86.3%
if 9.9999999999999996e30 < z < 2.2000000000000002e69Initial program 100.0%
Taylor expanded in x around 0 79.4%
Final simplification91.4%
(FPCore (x y z)
:precision binary64
(if (<= z -3.15e+147)
x
(if (<= z 0.0012)
(/ (- y x) z)
(if (<= z 1.3e+31) (- x (/ x z)) (if (<= z 1.65e+71) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.15e+147) {
tmp = x;
} else if (z <= 0.0012) {
tmp = (y - x) / z;
} else if (z <= 1.3e+31) {
tmp = x - (x / z);
} else if (z <= 1.65e+71) {
tmp = 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 <= (-3.15d+147)) then
tmp = x
else if (z <= 0.0012d0) then
tmp = (y - x) / z
else if (z <= 1.3d+31) then
tmp = x - (x / z)
else if (z <= 1.65d+71) then
tmp = 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 <= -3.15e+147) {
tmp = x;
} else if (z <= 0.0012) {
tmp = (y - x) / z;
} else if (z <= 1.3e+31) {
tmp = x - (x / z);
} else if (z <= 1.65e+71) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.15e+147: tmp = x elif z <= 0.0012: tmp = (y - x) / z elif z <= 1.3e+31: tmp = x - (x / z) elif z <= 1.65e+71: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.15e+147) tmp = x; elseif (z <= 0.0012) tmp = Float64(Float64(y - x) / z); elseif (z <= 1.3e+31) tmp = Float64(x - Float64(x / z)); elseif (z <= 1.65e+71) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.15e+147) tmp = x; elseif (z <= 0.0012) tmp = (y - x) / z; elseif (z <= 1.3e+31) tmp = x - (x / z); elseif (z <= 1.65e+71) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.15e+147], x, If[LessEqual[z, 0.0012], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[z, 1.3e+31], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.65e+71], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.15 \cdot 10^{+147}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 0.0012:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{+31}:\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{+71}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.14999999999999991e147 or 1.6499999999999999e71 < z Initial program 100.0%
Taylor expanded in z around inf 85.2%
if -3.14999999999999991e147 < z < 0.00119999999999999989Initial program 100.0%
Taylor expanded in z around 0 95.3%
if 0.00119999999999999989 < z < 1.3e31Initial program 99.8%
Taylor expanded in y around 0 86.0%
if 1.3e31 < z < 1.6499999999999999e71Initial program 100.0%
Taylor expanded in x around 0 79.4%
Final simplification91.4%
(FPCore (x y z) :precision binary64 (if (<= y -5.5e+89) (/ y z) (if (<= y 2.6e-17) (- x (/ x z)) (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.5e+89) {
tmp = y / z;
} else if (y <= 2.6e-17) {
tmp = x - (x / z);
} else {
tmp = 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 <= (-5.5d+89)) then
tmp = y / z
else if (y <= 2.6d-17) then
tmp = x - (x / z)
else
tmp = y / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.5e+89) {
tmp = y / z;
} else if (y <= 2.6e-17) {
tmp = x - (x / z);
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.5e+89: tmp = y / z elif y <= 2.6e-17: tmp = x - (x / z) else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.5e+89) tmp = Float64(y / z); elseif (y <= 2.6e-17) tmp = Float64(x - Float64(x / z)); else tmp = Float64(y / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.5e+89) tmp = y / z; elseif (y <= 2.6e-17) tmp = x - (x / z); else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.5e+89], N[(y / z), $MachinePrecision], If[LessEqual[y, 2.6e-17], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+89}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-17}:\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if y < -5.49999999999999976e89 or 2.60000000000000003e-17 < y Initial program 100.0%
Taylor expanded in x around 0 77.3%
if -5.49999999999999976e89 < y < 2.60000000000000003e-17Initial program 100.0%
Taylor expanded in y around 0 81.7%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (if (<= z -3.15e+147) x (if (<= z 2.15e+69) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.15e+147) {
tmp = x;
} else if (z <= 2.15e+69) {
tmp = 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 <= (-3.15d+147)) then
tmp = x
else if (z <= 2.15d+69) then
tmp = 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 <= -3.15e+147) {
tmp = x;
} else if (z <= 2.15e+69) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.15e+147: tmp = x elif z <= 2.15e+69: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.15e+147) tmp = x; elseif (z <= 2.15e+69) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.15e+147) tmp = x; elseif (z <= 2.15e+69) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.15e+147], x, If[LessEqual[z, 2.15e+69], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.15 \cdot 10^{+147}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.15 \cdot 10^{+69}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.14999999999999991e147 or 2.14999999999999996e69 < z Initial program 100.0%
Taylor expanded in z around inf 85.2%
if -3.14999999999999991e147 < z < 2.14999999999999996e69Initial program 100.0%
Taylor expanded in x around 0 55.1%
Final simplification64.4%
(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 100.0%
Taylor expanded in z around inf 33.1%
Final simplification33.1%
herbie shell --seed 2023229
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))