
(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 -1.06e+20)
x
(if (<= z -1.2e-299)
(/ y z)
(if (<= z 2.7e-298)
t_0
(if (<= z 8.5e-100)
(/ y z)
(if (<= z 0.00055) t_0 (if (<= z 2.35e+29) (/ y z) x))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -1.06e+20) {
tmp = x;
} else if (z <= -1.2e-299) {
tmp = y / z;
} else if (z <= 2.7e-298) {
tmp = t_0;
} else if (z <= 8.5e-100) {
tmp = y / z;
} else if (z <= 0.00055) {
tmp = t_0;
} else if (z <= 2.35e+29) {
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 <= (-1.06d+20)) then
tmp = x
else if (z <= (-1.2d-299)) then
tmp = y / z
else if (z <= 2.7d-298) then
tmp = t_0
else if (z <= 8.5d-100) then
tmp = y / z
else if (z <= 0.00055d0) then
tmp = t_0
else if (z <= 2.35d+29) 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 <= -1.06e+20) {
tmp = x;
} else if (z <= -1.2e-299) {
tmp = y / z;
} else if (z <= 2.7e-298) {
tmp = t_0;
} else if (z <= 8.5e-100) {
tmp = y / z;
} else if (z <= 0.00055) {
tmp = t_0;
} else if (z <= 2.35e+29) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -1.06e+20: tmp = x elif z <= -1.2e-299: tmp = y / z elif z <= 2.7e-298: tmp = t_0 elif z <= 8.5e-100: tmp = y / z elif z <= 0.00055: tmp = t_0 elif z <= 2.35e+29: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -1.06e+20) tmp = x; elseif (z <= -1.2e-299) tmp = Float64(y / z); elseif (z <= 2.7e-298) tmp = t_0; elseif (z <= 8.5e-100) tmp = Float64(y / z); elseif (z <= 0.00055) tmp = t_0; elseif (z <= 2.35e+29) 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 <= -1.06e+20) tmp = x; elseif (z <= -1.2e-299) tmp = y / z; elseif (z <= 2.7e-298) tmp = t_0; elseif (z <= 8.5e-100) tmp = y / z; elseif (z <= 0.00055) tmp = t_0; elseif (z <= 2.35e+29) 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, -1.06e+20], x, If[LessEqual[z, -1.2e-299], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.7e-298], t$95$0, If[LessEqual[z, 8.5e-100], N[(y / z), $MachinePrecision], If[LessEqual[z, 0.00055], t$95$0, If[LessEqual[z, 2.35e+29], N[(y / z), $MachinePrecision], x]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -1.06 \cdot 10^{+20}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.2 \cdot 10^{-299}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{-298}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{-100}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 0.00055:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 2.35 \cdot 10^{+29}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.06e20 or 2.3500000000000001e29 < z Initial program 100.0%
Taylor expanded in z around inf 71.4%
if -1.06e20 < z < -1.2000000000000001e-299 or 2.7000000000000001e-298 < z < 8.50000000000000017e-100 or 5.50000000000000033e-4 < z < 2.3500000000000001e29Initial program 100.0%
Taylor expanded in x around 0 67.9%
if -1.2000000000000001e-299 < z < 2.7000000000000001e-298 or 8.50000000000000017e-100 < z < 5.50000000000000033e-4Initial program 99.7%
Taylor expanded in z around 0 92.3%
Taylor expanded in y around 0 68.5%
neg-mul-168.5%
distribute-neg-frac68.5%
Simplified68.5%
Final simplification69.5%
(FPCore (x y z)
:precision binary64
(if (or (<= y 4.2e-209)
(not
(or (<= y 1.05e-189) (and (not (<= y 1.5e-138)) (<= y 8.1e-115)))))
(+ x (/ y z))
(/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= 4.2e-209) || !((y <= 1.05e-189) || (!(y <= 1.5e-138) && (y <= 8.1e-115)))) {
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 <= 4.2d-209) .or. (.not. (y <= 1.05d-189) .or. (.not. (y <= 1.5d-138)) .and. (y <= 8.1d-115))) 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 <= 4.2e-209) || !((y <= 1.05e-189) || (!(y <= 1.5e-138) && (y <= 8.1e-115)))) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= 4.2e-209) or not ((y <= 1.05e-189) or (not (y <= 1.5e-138) and (y <= 8.1e-115))): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= 4.2e-209) || !((y <= 1.05e-189) || (!(y <= 1.5e-138) && (y <= 8.1e-115)))) 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 <= 4.2e-209) || ~(((y <= 1.05e-189) || (~((y <= 1.5e-138)) && (y <= 8.1e-115))))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, 4.2e-209], N[Not[Or[LessEqual[y, 1.05e-189], And[N[Not[LessEqual[y, 1.5e-138]], $MachinePrecision], LessEqual[y, 8.1e-115]]]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.2 \cdot 10^{-209} \lor \neg \left(y \leq 1.05 \cdot 10^{-189} \lor \neg \left(y \leq 1.5 \cdot 10^{-138}\right) \land y \leq 8.1 \cdot 10^{-115}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if y < 4.19999999999999991e-209 or 1.05000000000000008e-189 < y < 1.5e-138 or 8.0999999999999999e-115 < y Initial program 100.0%
clear-num99.8%
inv-pow99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 82.4%
if 4.19999999999999991e-209 < y < 1.05000000000000008e-189 or 1.5e-138 < y < 8.0999999999999999e-115Initial program 100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in y around 0 100.0%
neg-mul-1100.0%
distribute-neg-frac100.0%
Simplified100.0%
Final simplification83.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.2e-60) (not (<= y 6.5e-85))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.2e-60) || !(y <= 6.5e-85)) {
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 <= (-4.2d-60)) .or. (.not. (y <= 6.5d-85))) 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 <= -4.2e-60) || !(y <= 6.5e-85)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.2e-60) or not (y <= 6.5e-85): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.2e-60) || !(y <= 6.5e-85)) 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 <= -4.2e-60) || ~((y <= 6.5e-85))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.2e-60], N[Not[LessEqual[y, 6.5e-85]], $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 -4.2 \cdot 10^{-60} \lor \neg \left(y \leq 6.5 \cdot 10^{-85}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -4.19999999999999982e-60 or 6.5e-85 < y Initial program 100.0%
clear-num99.8%
inv-pow99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 90.0%
if -4.19999999999999982e-60 < y < 6.5e-85Initial program 99.9%
Taylor expanded in y around 0 85.9%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 0.00135))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 0.00135)) {
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 <= (-1.0d0)) .or. (.not. (z <= 0.00135d0))) 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 <= -1.0) || !(z <= 0.00135)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 0.00135): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 0.00135)) 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 <= -1.0) || ~((z <= 0.00135))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 0.00135]], $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 -1 \lor \neg \left(z \leq 0.00135\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 0.0013500000000000001 < z Initial program 100.0%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
Taylor expanded in y around inf 99.2%
if -1 < z < 0.0013500000000000001Initial program 99.9%
Taylor expanded in z around 0 98.2%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= z -2.2e+20) x (if (<= z 2.9e+30) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.2e+20) {
tmp = x;
} else if (z <= 2.9e+30) {
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 <= (-2.2d+20)) then
tmp = x
else if (z <= 2.9d+30) 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 <= -2.2e+20) {
tmp = x;
} else if (z <= 2.9e+30) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.2e+20: tmp = x elif z <= 2.9e+30: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.2e+20) tmp = x; elseif (z <= 2.9e+30) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.2e+20) tmp = x; elseif (z <= 2.9e+30) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.2e+20], x, If[LessEqual[z, 2.9e+30], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+20}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{+30}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.2e20 or 2.8999999999999998e30 < z Initial program 100.0%
Taylor expanded in z around inf 71.4%
if -2.2e20 < z < 2.8999999999999998e30Initial program 99.9%
Taylor expanded in x around 0 60.6%
Final simplification65.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 33.1%
Final simplification33.1%
herbie shell --seed 2023290
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))