
(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 -330000.0)
x
(if (<= z -2.3e-55)
(/ y z)
(if (<= z -7.5e-123)
t_0
(if (<= z -1.1e-195)
(/ y z)
(if (<= z 1.25e-289)
t_0
(if (<= z 1.9e-253)
(/ y z)
(if (<= z 1.15e-177)
t_0
(if (<= z 4.4e-85)
(/ y z)
(if (<= z 0.00215)
t_0
(if (<= z 2.4e+25) (/ y z) x))))))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -330000.0) {
tmp = x;
} else if (z <= -2.3e-55) {
tmp = y / z;
} else if (z <= -7.5e-123) {
tmp = t_0;
} else if (z <= -1.1e-195) {
tmp = y / z;
} else if (z <= 1.25e-289) {
tmp = t_0;
} else if (z <= 1.9e-253) {
tmp = y / z;
} else if (z <= 1.15e-177) {
tmp = t_0;
} else if (z <= 4.4e-85) {
tmp = y / z;
} else if (z <= 0.00215) {
tmp = t_0;
} else if (z <= 2.4e+25) {
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 <= (-330000.0d0)) then
tmp = x
else if (z <= (-2.3d-55)) then
tmp = y / z
else if (z <= (-7.5d-123)) then
tmp = t_0
else if (z <= (-1.1d-195)) then
tmp = y / z
else if (z <= 1.25d-289) then
tmp = t_0
else if (z <= 1.9d-253) then
tmp = y / z
else if (z <= 1.15d-177) then
tmp = t_0
else if (z <= 4.4d-85) then
tmp = y / z
else if (z <= 0.00215d0) then
tmp = t_0
else if (z <= 2.4d+25) 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 <= -330000.0) {
tmp = x;
} else if (z <= -2.3e-55) {
tmp = y / z;
} else if (z <= -7.5e-123) {
tmp = t_0;
} else if (z <= -1.1e-195) {
tmp = y / z;
} else if (z <= 1.25e-289) {
tmp = t_0;
} else if (z <= 1.9e-253) {
tmp = y / z;
} else if (z <= 1.15e-177) {
tmp = t_0;
} else if (z <= 4.4e-85) {
tmp = y / z;
} else if (z <= 0.00215) {
tmp = t_0;
} else if (z <= 2.4e+25) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -330000.0: tmp = x elif z <= -2.3e-55: tmp = y / z elif z <= -7.5e-123: tmp = t_0 elif z <= -1.1e-195: tmp = y / z elif z <= 1.25e-289: tmp = t_0 elif z <= 1.9e-253: tmp = y / z elif z <= 1.15e-177: tmp = t_0 elif z <= 4.4e-85: tmp = y / z elif z <= 0.00215: tmp = t_0 elif z <= 2.4e+25: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -330000.0) tmp = x; elseif (z <= -2.3e-55) tmp = Float64(y / z); elseif (z <= -7.5e-123) tmp = t_0; elseif (z <= -1.1e-195) tmp = Float64(y / z); elseif (z <= 1.25e-289) tmp = t_0; elseif (z <= 1.9e-253) tmp = Float64(y / z); elseif (z <= 1.15e-177) tmp = t_0; elseif (z <= 4.4e-85) tmp = Float64(y / z); elseif (z <= 0.00215) tmp = t_0; elseif (z <= 2.4e+25) 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 <= -330000.0) tmp = x; elseif (z <= -2.3e-55) tmp = y / z; elseif (z <= -7.5e-123) tmp = t_0; elseif (z <= -1.1e-195) tmp = y / z; elseif (z <= 1.25e-289) tmp = t_0; elseif (z <= 1.9e-253) tmp = y / z; elseif (z <= 1.15e-177) tmp = t_0; elseif (z <= 4.4e-85) tmp = y / z; elseif (z <= 0.00215) tmp = t_0; elseif (z <= 2.4e+25) 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, -330000.0], x, If[LessEqual[z, -2.3e-55], N[(y / z), $MachinePrecision], If[LessEqual[z, -7.5e-123], t$95$0, If[LessEqual[z, -1.1e-195], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.25e-289], t$95$0, If[LessEqual[z, 1.9e-253], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.15e-177], t$95$0, If[LessEqual[z, 4.4e-85], N[(y / z), $MachinePrecision], If[LessEqual[z, 0.00215], t$95$0, If[LessEqual[z, 2.4e+25], N[(y / z), $MachinePrecision], x]]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -330000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -2.3 \cdot 10^{-55}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -7.5 \cdot 10^{-123}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.1 \cdot 10^{-195}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{-289}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-253}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-177}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 4.4 \cdot 10^{-85}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 0.00215:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{+25}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.3e5 or 2.39999999999999996e25 < z Initial program 100.0%
Taylor expanded in z around inf 72.9%
if -3.3e5 < z < -2.30000000000000011e-55 or -7.50000000000000011e-123 < z < -1.10000000000000003e-195 or 1.25000000000000007e-289 < z < 1.90000000000000006e-253 or 1.15000000000000011e-177 < z < 4.4e-85 or 0.00215 < z < 2.39999999999999996e25Initial program 99.9%
+-commutative99.9%
clear-num99.7%
associate-/r/99.7%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 78.8%
if -2.30000000000000011e-55 < z < -7.50000000000000011e-123 or -1.10000000000000003e-195 < z < 1.25000000000000007e-289 or 1.90000000000000006e-253 < z < 1.15000000000000011e-177 or 4.4e-85 < z < 0.00215Initial program 100.0%
Taylor expanded in y around 0 77.6%
Taylor expanded in z around 0 76.4%
mul-1-neg76.4%
distribute-frac-neg76.4%
Simplified76.4%
Final simplification75.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.7e-92) (not (<= y 2.3e-65))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7e-92) || !(y <= 2.3e-65)) {
tmp = x + (y / z);
} else {
tmp = x - (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 <= (-3.7d-92)) .or. (.not. (y <= 2.3d-65))) then
tmp = x + (y / z)
else
tmp = x - (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7e-92) || !(y <= 2.3e-65)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.7e-92) or not (y <= 2.3e-65): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.7e-92) || !(y <= 2.3e-65)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x - Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.7e-92) || ~((y <= 2.3e-65))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.7e-92], N[Not[LessEqual[y, 2.3e-65]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{-92} \lor \neg \left(y \leq 2.3 \cdot 10^{-65}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -3.69999999999999977e-92 or 2.3e-65 < y Initial program 100.0%
Taylor expanded in y around inf 88.3%
if -3.69999999999999977e-92 < y < 2.3e-65Initial program 100.0%
Taylor expanded in y around 0 96.9%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -110000.0) (not (<= z 0.00215))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -110000.0) || !(z <= 0.00215)) {
tmp = x + (y / z);
} 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 ((z <= (-110000.0d0)) .or. (.not. (z <= 0.00215d0))) then
tmp = x + (y / z)
else
tmp = (y - x) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -110000.0) || !(z <= 0.00215)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -110000.0) or not (z <= 0.00215): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -110000.0) || !(z <= 0.00215)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(Float64(y - x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -110000.0) || ~((z <= 0.00215))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -110000.0], N[Not[LessEqual[z, 0.00215]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -110000 \lor \neg \left(z \leq 0.00215\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1.1e5 or 0.00215 < z Initial program 100.0%
Taylor expanded in y around inf 98.2%
if -1.1e5 < z < 0.00215Initial program 100.0%
+-commutative100.0%
clear-num99.7%
associate-/r/99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 99.1%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= z -220000.0) x (if (<= z 2.4e+25) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -220000.0) {
tmp = x;
} else if (z <= 2.4e+25) {
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 <= (-220000.0d0)) then
tmp = x
else if (z <= 2.4d+25) 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 <= -220000.0) {
tmp = x;
} else if (z <= 2.4e+25) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -220000.0: tmp = x elif z <= 2.4e+25: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -220000.0) tmp = x; elseif (z <= 2.4e+25) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -220000.0) tmp = x; elseif (z <= 2.4e+25) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -220000.0], x, If[LessEqual[z, 2.4e+25], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -220000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{+25}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.2e5 or 2.39999999999999996e25 < z Initial program 100.0%
Taylor expanded in z around inf 72.9%
if -2.2e5 < z < 2.39999999999999996e25Initial program 99.9%
+-commutative99.9%
clear-num99.7%
associate-/r/99.7%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 52.6%
Final simplification62.4%
(FPCore (x y z) :precision binary64 (if (<= x 1.4e+184) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if (x <= 1.4e+184) {
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 (x <= 1.4d+184) 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 (x <= 1.4e+184) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 1.4e+184: tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if (x <= 1.4e+184) 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 (x <= 1.4e+184) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 1.4e+184], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.4 \cdot 10^{+184}:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if x < 1.39999999999999995e184Initial program 100.0%
Taylor expanded in y around inf 79.6%
if 1.39999999999999995e184 < x Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in z around 0 66.9%
mul-1-neg66.9%
distribute-frac-neg66.9%
Simplified66.9%
Final simplification78.3%
(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 37.1%
Final simplification37.1%
herbie shell --seed 2023271
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))