
(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.4e-14)
x
(if (<= z -6.1e-58)
(/ y z)
(if (<= z -1.25e-101)
t_0
(if (<= z -9.5e-152)
(/ y z)
(if (<= z -2.25e-271)
t_0
(if (<= z 1.12e-290) (/ y z) (if (<= z 490.0) t_0 x)))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -3.4e-14) {
tmp = x;
} else if (z <= -6.1e-58) {
tmp = y / z;
} else if (z <= -1.25e-101) {
tmp = t_0;
} else if (z <= -9.5e-152) {
tmp = y / z;
} else if (z <= -2.25e-271) {
tmp = t_0;
} else if (z <= 1.12e-290) {
tmp = y / z;
} else if (z <= 490.0) {
tmp = t_0;
} 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.4d-14)) then
tmp = x
else if (z <= (-6.1d-58)) then
tmp = y / z
else if (z <= (-1.25d-101)) then
tmp = t_0
else if (z <= (-9.5d-152)) then
tmp = y / z
else if (z <= (-2.25d-271)) then
tmp = t_0
else if (z <= 1.12d-290) then
tmp = y / z
else if (z <= 490.0d0) then
tmp = t_0
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.4e-14) {
tmp = x;
} else if (z <= -6.1e-58) {
tmp = y / z;
} else if (z <= -1.25e-101) {
tmp = t_0;
} else if (z <= -9.5e-152) {
tmp = y / z;
} else if (z <= -2.25e-271) {
tmp = t_0;
} else if (z <= 1.12e-290) {
tmp = y / z;
} else if (z <= 490.0) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -3.4e-14: tmp = x elif z <= -6.1e-58: tmp = y / z elif z <= -1.25e-101: tmp = t_0 elif z <= -9.5e-152: tmp = y / z elif z <= -2.25e-271: tmp = t_0 elif z <= 1.12e-290: tmp = y / z elif z <= 490.0: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -3.4e-14) tmp = x; elseif (z <= -6.1e-58) tmp = Float64(y / z); elseif (z <= -1.25e-101) tmp = t_0; elseif (z <= -9.5e-152) tmp = Float64(y / z); elseif (z <= -2.25e-271) tmp = t_0; elseif (z <= 1.12e-290) tmp = Float64(y / z); elseif (z <= 490.0) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x / z; tmp = 0.0; if (z <= -3.4e-14) tmp = x; elseif (z <= -6.1e-58) tmp = y / z; elseif (z <= -1.25e-101) tmp = t_0; elseif (z <= -9.5e-152) tmp = y / z; elseif (z <= -2.25e-271) tmp = t_0; elseif (z <= 1.12e-290) tmp = y / z; elseif (z <= 490.0) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -3.4e-14], x, If[LessEqual[z, -6.1e-58], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.25e-101], t$95$0, If[LessEqual[z, -9.5e-152], N[(y / z), $MachinePrecision], If[LessEqual[z, -2.25e-271], t$95$0, If[LessEqual[z, 1.12e-290], N[(y / z), $MachinePrecision], If[LessEqual[z, 490.0], t$95$0, x]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -3.4 \cdot 10^{-14}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -6.1 \cdot 10^{-58}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.25 \cdot 10^{-101}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -9.5 \cdot 10^{-152}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -2.25 \cdot 10^{-271}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.12 \cdot 10^{-290}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 490:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.40000000000000003e-14 or 490 < z Initial program 100.0%
Taylor expanded in z around inf 72.5%
if -3.40000000000000003e-14 < z < -6.1000000000000003e-58 or -1.25e-101 < z < -9.49999999999999925e-152 or -2.2499999999999999e-271 < z < 1.12e-290Initial program 100.0%
Taylor expanded in y around inf 83.5%
Taylor expanded in x around 0 83.3%
if -6.1000000000000003e-58 < z < -1.25e-101 or -9.49999999999999925e-152 < z < -2.2499999999999999e-271 or 1.12e-290 < z < 490Initial program 100.0%
Taylor expanded in x around inf 64.1%
Taylor expanded in z around 0 63.3%
mul-1-neg63.3%
distribute-frac-neg63.3%
Simplified63.3%
Final simplification70.5%
(FPCore (x y z) :precision binary64 (if (<= x -5.4e+110) (- x (/ x z)) (if (<= x 4.6e+64) (+ x (/ y z)) (* x (+ 1.0 (/ -1.0 z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e+110) {
tmp = x - (x / z);
} else if (x <= 4.6e+64) {
tmp = x + (y / z);
} else {
tmp = x * (1.0 + (-1.0 / 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 (x <= (-5.4d+110)) then
tmp = x - (x / z)
else if (x <= 4.6d+64) then
tmp = x + (y / z)
else
tmp = x * (1.0d0 + ((-1.0d0) / z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.4e+110) {
tmp = x - (x / z);
} else if (x <= 4.6e+64) {
tmp = x + (y / z);
} else {
tmp = x * (1.0 + (-1.0 / z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.4e+110: tmp = x - (x / z) elif x <= 4.6e+64: tmp = x + (y / z) else: tmp = x * (1.0 + (-1.0 / z)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.4e+110) tmp = Float64(x - Float64(x / z)); elseif (x <= 4.6e+64) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x * Float64(1.0 + Float64(-1.0 / z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.4e+110) tmp = x - (x / z); elseif (x <= 4.6e+64) tmp = x + (y / z); else tmp = x * (1.0 + (-1.0 / z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.4e+110], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.6e+64], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 + N[(-1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{+110}:\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{+64}:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + \frac{-1}{z}\right)\\
\end{array}
\end{array}
if x < -5.40000000000000019e110Initial program 100.0%
Taylor expanded in y around 0 87.3%
if -5.40000000000000019e110 < x < 4.6e64Initial program 100.0%
Taylor expanded in y around inf 90.9%
if 4.6e64 < x Initial program 100.0%
Taylor expanded in x around inf 94.8%
Final simplification91.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.2e-246) (not (<= y -1.25e-288))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e-246) || !(y <= -1.25e-288)) {
tmp = x + (y / z);
} else {
tmp = -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 <= (-6.2d-246)) .or. (.not. (y <= (-1.25d-288)))) then
tmp = x + (y / z)
else
tmp = -x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.2e-246) || !(y <= -1.25e-288)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.2e-246) or not (y <= -1.25e-288): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.2e-246) || !(y <= -1.25e-288)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(Float64(-x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.2e-246) || ~((y <= -1.25e-288))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.2e-246], N[Not[LessEqual[y, -1.25e-288]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{-246} \lor \neg \left(y \leq -1.25 \cdot 10^{-288}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if y < -6.2000000000000001e-246 or -1.25000000000000003e-288 < y Initial program 100.0%
Taylor expanded in y around inf 79.6%
if -6.2000000000000001e-246 < y < -1.25000000000000003e-288Initial program 100.0%
Taylor expanded in x around inf 99.7%
Taylor expanded in z around 0 76.3%
mul-1-neg76.3%
distribute-frac-neg76.3%
Simplified76.3%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e+112) (not (<= x 1.8e+65))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e+112) || !(x <= 1.8e+65)) {
tmp = x - (x / z);
} else {
tmp = 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 ((x <= (-2d+112)) .or. (.not. (x <= 1.8d+65))) then
tmp = x - (x / z)
else
tmp = x + (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2e+112) || !(x <= 1.8e+65)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e+112) or not (x <= 1.8e+65): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e+112) || !(x <= 1.8e+65)) tmp = Float64(x - Float64(x / z)); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2e+112) || ~((x <= 1.8e+65))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e+112], N[Not[LessEqual[x, 1.8e+65]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+112} \lor \neg \left(x \leq 1.8 \cdot 10^{+65}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.9999999999999999e112 or 1.79999999999999989e65 < x Initial program 100.0%
Taylor expanded in y around 0 91.5%
if -1.9999999999999999e112 < x < 1.79999999999999989e65Initial program 100.0%
Taylor expanded in y around inf 90.9%
Final simplification91.2%
(FPCore (x y z) :precision binary64 (if (<= z -3.4e-14) x (if (<= z 2050.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.4e-14) {
tmp = x;
} else if (z <= 2050.0) {
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.4d-14)) then
tmp = x
else if (z <= 2050.0d0) 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.4e-14) {
tmp = x;
} else if (z <= 2050.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.4e-14: tmp = x elif z <= 2050.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.4e-14) tmp = x; elseif (z <= 2050.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.4e-14) tmp = x; elseif (z <= 2050.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.4e-14], x, If[LessEqual[z, 2050.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{-14}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2050:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.40000000000000003e-14 or 2050 < z Initial program 100.0%
Taylor expanded in z around inf 72.5%
if -3.40000000000000003e-14 < z < 2050Initial program 100.0%
Taylor expanded in y around inf 55.3%
Taylor expanded in x around 0 54.9%
Final simplification63.9%
(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 38.3%
Final simplification38.3%
herbie shell --seed 2023195
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))