
(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 -6.1e+69)
x
(if (<= z -2.4e-77)
(/ y z)
(if (<= z -1.5e-182)
t_0
(if (<= z -3.3e-235)
(/ y z)
(if (<= z 2.1e-182)
t_0
(if (<= z 2.6e-161)
(/ y z)
(if (<= z 6e-39)
t_0
(if (or (<= z 4e+74)
(and (not (<= z 1.9e+108)) (<= z 3.8e+194)))
(/ y z)
x))))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -6.1e+69) {
tmp = x;
} else if (z <= -2.4e-77) {
tmp = y / z;
} else if (z <= -1.5e-182) {
tmp = t_0;
} else if (z <= -3.3e-235) {
tmp = y / z;
} else if (z <= 2.1e-182) {
tmp = t_0;
} else if (z <= 2.6e-161) {
tmp = y / z;
} else if (z <= 6e-39) {
tmp = t_0;
} else if ((z <= 4e+74) || (!(z <= 1.9e+108) && (z <= 3.8e+194))) {
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 <= (-6.1d+69)) then
tmp = x
else if (z <= (-2.4d-77)) then
tmp = y / z
else if (z <= (-1.5d-182)) then
tmp = t_0
else if (z <= (-3.3d-235)) then
tmp = y / z
else if (z <= 2.1d-182) then
tmp = t_0
else if (z <= 2.6d-161) then
tmp = y / z
else if (z <= 6d-39) then
tmp = t_0
else if ((z <= 4d+74) .or. (.not. (z <= 1.9d+108)) .and. (z <= 3.8d+194)) 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 <= -6.1e+69) {
tmp = x;
} else if (z <= -2.4e-77) {
tmp = y / z;
} else if (z <= -1.5e-182) {
tmp = t_0;
} else if (z <= -3.3e-235) {
tmp = y / z;
} else if (z <= 2.1e-182) {
tmp = t_0;
} else if (z <= 2.6e-161) {
tmp = y / z;
} else if (z <= 6e-39) {
tmp = t_0;
} else if ((z <= 4e+74) || (!(z <= 1.9e+108) && (z <= 3.8e+194))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -6.1e+69: tmp = x elif z <= -2.4e-77: tmp = y / z elif z <= -1.5e-182: tmp = t_0 elif z <= -3.3e-235: tmp = y / z elif z <= 2.1e-182: tmp = t_0 elif z <= 2.6e-161: tmp = y / z elif z <= 6e-39: tmp = t_0 elif (z <= 4e+74) or (not (z <= 1.9e+108) and (z <= 3.8e+194)): tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -6.1e+69) tmp = x; elseif (z <= -2.4e-77) tmp = Float64(y / z); elseif (z <= -1.5e-182) tmp = t_0; elseif (z <= -3.3e-235) tmp = Float64(y / z); elseif (z <= 2.1e-182) tmp = t_0; elseif (z <= 2.6e-161) tmp = Float64(y / z); elseif (z <= 6e-39) tmp = t_0; elseif ((z <= 4e+74) || (!(z <= 1.9e+108) && (z <= 3.8e+194))) 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 <= -6.1e+69) tmp = x; elseif (z <= -2.4e-77) tmp = y / z; elseif (z <= -1.5e-182) tmp = t_0; elseif (z <= -3.3e-235) tmp = y / z; elseif (z <= 2.1e-182) tmp = t_0; elseif (z <= 2.6e-161) tmp = y / z; elseif (z <= 6e-39) tmp = t_0; elseif ((z <= 4e+74) || (~((z <= 1.9e+108)) && (z <= 3.8e+194))) 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, -6.1e+69], x, If[LessEqual[z, -2.4e-77], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.5e-182], t$95$0, If[LessEqual[z, -3.3e-235], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.1e-182], t$95$0, If[LessEqual[z, 2.6e-161], N[(y / z), $MachinePrecision], If[LessEqual[z, 6e-39], t$95$0, If[Or[LessEqual[z, 4e+74], And[N[Not[LessEqual[z, 1.9e+108]], $MachinePrecision], LessEqual[z, 3.8e+194]]], N[(y / z), $MachinePrecision], x]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -6.1 \cdot 10^{+69}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -2.4 \cdot 10^{-77}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.5 \cdot 10^{-182}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -3.3 \cdot 10^{-235}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-182}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 2.6 \cdot 10^{-161}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 6 \cdot 10^{-39}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 4 \cdot 10^{+74} \lor \neg \left(z \leq 1.9 \cdot 10^{+108}\right) \land z \leq 3.8 \cdot 10^{+194}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.1000000000000001e69 or 3.99999999999999981e74 < z < 1.90000000000000004e108 or 3.7999999999999999e194 < z Initial program 100.0%
Taylor expanded in z around inf 86.4%
if -6.1000000000000001e69 < z < -2.3999999999999999e-77 or -1.5000000000000001e-182 < z < -3.30000000000000028e-235 or 2.1e-182 < z < 2.59999999999999995e-161 or 6.00000000000000055e-39 < z < 3.99999999999999981e74 or 1.90000000000000004e108 < z < 3.7999999999999999e194Initial program 100.0%
Taylor expanded in x around 0 67.4%
if -2.3999999999999999e-77 < z < -1.5000000000000001e-182 or -3.30000000000000028e-235 < z < 2.1e-182 or 2.59999999999999995e-161 < z < 6.00000000000000055e-39Initial program 100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in y around 0 67.1%
mul-1-neg67.1%
distribute-neg-frac67.1%
Simplified67.1%
Final simplification72.6%
(FPCore (x y z)
:precision binary64
(if (<= z -9.8e+73)
x
(if (or (<= z 4.05e+74) (and (not (<= z 2e+106)) (<= z 3.8e+194)))
(/ y z)
x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.8e+73) {
tmp = x;
} else if ((z <= 4.05e+74) || (!(z <= 2e+106) && (z <= 3.8e+194))) {
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 <= (-9.8d+73)) then
tmp = x
else if ((z <= 4.05d+74) .or. (.not. (z <= 2d+106)) .and. (z <= 3.8d+194)) 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 <= -9.8e+73) {
tmp = x;
} else if ((z <= 4.05e+74) || (!(z <= 2e+106) && (z <= 3.8e+194))) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.8e+73: tmp = x elif (z <= 4.05e+74) or (not (z <= 2e+106) and (z <= 3.8e+194)): tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.8e+73) tmp = x; elseif ((z <= 4.05e+74) || (!(z <= 2e+106) && (z <= 3.8e+194))) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.8e+73) tmp = x; elseif ((z <= 4.05e+74) || (~((z <= 2e+106)) && (z <= 3.8e+194))) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.8e+73], x, If[Or[LessEqual[z, 4.05e+74], And[N[Not[LessEqual[z, 2e+106]], $MachinePrecision], LessEqual[z, 3.8e+194]]], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.8 \cdot 10^{+73}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.05 \cdot 10^{+74} \lor \neg \left(z \leq 2 \cdot 10^{+106}\right) \land z \leq 3.8 \cdot 10^{+194}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.7999999999999998e73 or 4.0500000000000002e74 < z < 2.00000000000000018e106 or 3.7999999999999999e194 < z Initial program 100.0%
Taylor expanded in z around inf 86.4%
if -9.7999999999999998e73 < z < 4.0500000000000002e74 or 2.00000000000000018e106 < z < 3.7999999999999999e194Initial program 100.0%
Taylor expanded in x around 0 52.3%
Final simplification61.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.3e+128) (not (<= x 4.2e+173))) (/ (- x) z) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e+128) || !(x <= 4.2e+173)) {
tmp = -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 <= (-2.3d+128)) .or. (.not. (x <= 4.2d+173))) then
tmp = -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 <= -2.3e+128) || !(x <= 4.2e+173)) {
tmp = -x / z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.3e+128) or not (x <= 4.2e+173): tmp = -x / z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.3e+128) || !(x <= 4.2e+173)) tmp = Float64(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 <= -2.3e+128) || ~((x <= 4.2e+173))) tmp = -x / z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.3e+128], N[Not[LessEqual[x, 4.2e+173]], $MachinePrecision]], N[((-x) / z), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{+128} \lor \neg \left(x \leq 4.2 \cdot 10^{+173}\right):\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -2.29999999999999998e128 or 4.2e173 < x Initial program 100.0%
Taylor expanded in z around 0 65.8%
Taylor expanded in y around 0 66.0%
mul-1-neg66.0%
distribute-neg-frac66.0%
Simplified66.0%
if -2.29999999999999998e128 < x < 4.2e173Initial program 100.0%
clear-num99.7%
inv-pow99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 83.1%
Final simplification79.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.9e+35) (not (<= x 6.5e+47))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e+35) || !(x <= 6.5e+47)) {
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 <= (-1.9d+35)) .or. (.not. (x <= 6.5d+47))) 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 <= -1.9e+35) || !(x <= 6.5e+47)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.9e+35) or not (x <= 6.5e+47): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.9e+35) || !(x <= 6.5e+47)) 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 <= -1.9e+35) || ~((x <= 6.5e+47))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.9e+35], N[Not[LessEqual[x, 6.5e+47]], $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 -1.9 \cdot 10^{+35} \lor \neg \left(x \leq 6.5 \cdot 10^{+47}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.9e35 or 6.49999999999999988e47 < x Initial program 100.0%
Taylor expanded in x around inf 90.7%
sub-neg90.7%
distribute-rgt-in90.7%
*-lft-identity90.7%
distribute-lft-neg-in90.7%
associate-*l/90.8%
*-lft-identity90.8%
mul-1-neg90.8%
mul-1-neg90.8%
sub-neg90.8%
Simplified90.8%
if -1.9e35 < x < 6.49999999999999988e47Initial program 100.0%
clear-num99.7%
inv-pow99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 87.5%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -13.2) (not (<= z 9.8e-6))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -13.2) || !(z <= 9.8e-6)) {
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 <= (-13.2d0)) .or. (.not. (z <= 9.8d-6))) 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 <= -13.2) || !(z <= 9.8e-6)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -13.2) or not (z <= 9.8e-6): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -13.2) || !(z <= 9.8e-6)) 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 <= -13.2) || ~((z <= 9.8e-6))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -13.2], N[Not[LessEqual[z, 9.8e-6]], $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 -13.2 \lor \neg \left(z \leq 9.8 \cdot 10^{-6}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -13.199999999999999 or 9.79999999999999934e-6 < z Initial program 100.0%
clear-num99.8%
inv-pow99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 98.2%
if -13.199999999999999 < z < 9.79999999999999934e-6Initial program 100.0%
Taylor expanded in z around 0 99.4%
Final simplification98.8%
(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 34.0%
Final simplification34.0%
herbie shell --seed 2023301
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))