
(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.65e+70)
x
(if (<= z -2e-5)
(/ y z)
(if (<= z -6e-64)
t_0
(if (<= z -7.5e-88)
(/ y z)
(if (<= z 4.2e-238)
t_0
(if (<= z 3e-160) (/ y z) (if (<= z 1.0) t_0 x)))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -1.65e+70) {
tmp = x;
} else if (z <= -2e-5) {
tmp = y / z;
} else if (z <= -6e-64) {
tmp = t_0;
} else if (z <= -7.5e-88) {
tmp = y / z;
} else if (z <= 4.2e-238) {
tmp = t_0;
} else if (z <= 3e-160) {
tmp = y / z;
} else if (z <= 1.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 <= (-1.65d+70)) then
tmp = x
else if (z <= (-2d-5)) then
tmp = y / z
else if (z <= (-6d-64)) then
tmp = t_0
else if (z <= (-7.5d-88)) then
tmp = y / z
else if (z <= 4.2d-238) then
tmp = t_0
else if (z <= 3d-160) then
tmp = y / z
else if (z <= 1.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 <= -1.65e+70) {
tmp = x;
} else if (z <= -2e-5) {
tmp = y / z;
} else if (z <= -6e-64) {
tmp = t_0;
} else if (z <= -7.5e-88) {
tmp = y / z;
} else if (z <= 4.2e-238) {
tmp = t_0;
} else if (z <= 3e-160) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -1.65e+70: tmp = x elif z <= -2e-5: tmp = y / z elif z <= -6e-64: tmp = t_0 elif z <= -7.5e-88: tmp = y / z elif z <= 4.2e-238: tmp = t_0 elif z <= 3e-160: tmp = y / z elif z <= 1.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 <= -1.65e+70) tmp = x; elseif (z <= -2e-5) tmp = Float64(y / z); elseif (z <= -6e-64) tmp = t_0; elseif (z <= -7.5e-88) tmp = Float64(y / z); elseif (z <= 4.2e-238) tmp = t_0; elseif (z <= 3e-160) tmp = Float64(y / z); elseif (z <= 1.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 <= -1.65e+70) tmp = x; elseif (z <= -2e-5) tmp = y / z; elseif (z <= -6e-64) tmp = t_0; elseif (z <= -7.5e-88) tmp = y / z; elseif (z <= 4.2e-238) tmp = t_0; elseif (z <= 3e-160) tmp = y / z; elseif (z <= 1.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, -1.65e+70], x, If[LessEqual[z, -2e-5], N[(y / z), $MachinePrecision], If[LessEqual[z, -6e-64], t$95$0, If[LessEqual[z, -7.5e-88], N[(y / z), $MachinePrecision], If[LessEqual[z, 4.2e-238], t$95$0, If[LessEqual[z, 3e-160], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], t$95$0, x]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -1.65 \cdot 10^{+70}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -2 \cdot 10^{-5}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -6 \cdot 10^{-64}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -7.5 \cdot 10^{-88}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{-238}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 3 \cdot 10^{-160}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.65000000000000008e70 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 73.6%
if -1.65000000000000008e70 < z < -2.00000000000000016e-5 or -6.0000000000000001e-64 < z < -7.50000000000000041e-88 or 4.2000000000000002e-238 < z < 2.99999999999999997e-160Initial program 100.0%
Taylor expanded in x around 0 73.5%
if -2.00000000000000016e-5 < z < -6.0000000000000001e-64 or -7.50000000000000041e-88 < z < 4.2000000000000002e-238 or 2.99999999999999997e-160 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.9%
Taylor expanded in y around 0 68.2%
neg-mul-168.2%
distribute-neg-frac68.2%
Simplified68.2%
Final simplification71.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (/ y z))) (t_1 (/ (- x) z)))
(if (<= z -3.6e-38)
t_0
(if (<= z -6.5e-64)
t_1
(if (<= z -5.8e-88)
t_0
(if (<= z 1.8e-234)
t_1
(if (<= z 3.6e-160) (/ y z) (if (<= z 1.45e-45) t_1 t_0))))))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double t_1 = -x / z;
double tmp;
if (z <= -3.6e-38) {
tmp = t_0;
} else if (z <= -6.5e-64) {
tmp = t_1;
} else if (z <= -5.8e-88) {
tmp = t_0;
} else if (z <= 1.8e-234) {
tmp = t_1;
} else if (z <= 3.6e-160) {
tmp = y / z;
} else if (z <= 1.45e-45) {
tmp = t_1;
} else {
tmp = t_0;
}
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) :: t_1
real(8) :: tmp
t_0 = x + (y / z)
t_1 = -x / z
if (z <= (-3.6d-38)) then
tmp = t_0
else if (z <= (-6.5d-64)) then
tmp = t_1
else if (z <= (-5.8d-88)) then
tmp = t_0
else if (z <= 1.8d-234) then
tmp = t_1
else if (z <= 3.6d-160) then
tmp = y / z
else if (z <= 1.45d-45) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (y / z);
double t_1 = -x / z;
double tmp;
if (z <= -3.6e-38) {
tmp = t_0;
} else if (z <= -6.5e-64) {
tmp = t_1;
} else if (z <= -5.8e-88) {
tmp = t_0;
} else if (z <= 1.8e-234) {
tmp = t_1;
} else if (z <= 3.6e-160) {
tmp = y / z;
} else if (z <= 1.45e-45) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) t_1 = -x / z tmp = 0 if z <= -3.6e-38: tmp = t_0 elif z <= -6.5e-64: tmp = t_1 elif z <= -5.8e-88: tmp = t_0 elif z <= 1.8e-234: tmp = t_1 elif z <= 3.6e-160: tmp = y / z elif z <= 1.45e-45: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) t_1 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -3.6e-38) tmp = t_0; elseif (z <= -6.5e-64) tmp = t_1; elseif (z <= -5.8e-88) tmp = t_0; elseif (z <= 1.8e-234) tmp = t_1; elseif (z <= 3.6e-160) tmp = Float64(y / z); elseif (z <= 1.45e-45) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y / z); t_1 = -x / z; tmp = 0.0; if (z <= -3.6e-38) tmp = t_0; elseif (z <= -6.5e-64) tmp = t_1; elseif (z <= -5.8e-88) tmp = t_0; elseif (z <= 1.8e-234) tmp = t_1; elseif (z <= 3.6e-160) tmp = y / z; elseif (z <= 1.45e-45) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -3.6e-38], t$95$0, If[LessEqual[z, -6.5e-64], t$95$1, If[LessEqual[z, -5.8e-88], t$95$0, If[LessEqual[z, 1.8e-234], t$95$1, If[LessEqual[z, 3.6e-160], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.45e-45], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
t_1 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -3.6 \cdot 10^{-38}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -6.5 \cdot 10^{-64}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -5.8 \cdot 10^{-88}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{-234}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{-160}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.45 \cdot 10^{-45}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -3.6000000000000001e-38 or -6.5000000000000004e-64 < z < -5.8000000000000003e-88 or 1.45e-45 < z Initial program 100.0%
clear-num99.8%
associate-/r/99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 92.4%
if -3.6000000000000001e-38 < z < -6.5000000000000004e-64 or -5.8000000000000003e-88 < z < 1.7999999999999999e-234 or 3.5999999999999997e-160 < z < 1.45e-45Initial program 100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in y around 0 73.3%
neg-mul-173.3%
distribute-neg-frac73.3%
Simplified73.3%
if 1.7999999999999999e-234 < z < 3.5999999999999997e-160Initial program 100.0%
Taylor expanded in x around 0 74.2%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.8e-61) (not (<= y 5.7e+89))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.8e-61) || !(y <= 5.7e+89)) {
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 <= (-2.8d-61)) .or. (.not. (y <= 5.7d+89))) 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 <= -2.8e-61) || !(y <= 5.7e+89)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.8e-61) or not (y <= 5.7e+89): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.8e-61) || !(y <= 5.7e+89)) 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 <= -2.8e-61) || ~((y <= 5.7e+89))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.8e-61], N[Not[LessEqual[y, 5.7e+89]], $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 -2.8 \cdot 10^{-61} \lor \neg \left(y \leq 5.7 \cdot 10^{+89}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.8000000000000001e-61 or 5.6999999999999995e89 < y Initial program 100.0%
clear-num99.8%
associate-/r/99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 88.9%
if -2.8000000000000001e-61 < y < 5.6999999999999995e89Initial program 100.0%
Taylor expanded in y around 0 86.5%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -2e+28) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2e+28) || !(z <= 1.0)) {
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 <= (-2d+28)) .or. (.not. (z <= 1.0d0))) 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 <= -2e+28) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2e+28) or not (z <= 1.0): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2e+28) || !(z <= 1.0)) 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 <= -2e+28) || ~((z <= 1.0))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2e+28], N[Not[LessEqual[z, 1.0]], $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 -2 \cdot 10^{+28} \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1.99999999999999992e28 or 1 < z Initial program 100.0%
clear-num99.8%
associate-/r/99.9%
Applied egg-rr99.9%
Taylor expanded in y around inf 100.0%
if -1.99999999999999992e28 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.8%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= z -6e+69) x (if (<= z 1600000.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6e+69) {
tmp = x;
} else if (z <= 1600000.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 <= (-6d+69)) then
tmp = x
else if (z <= 1600000.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 <= -6e+69) {
tmp = x;
} else if (z <= 1600000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6e+69: tmp = x elif z <= 1600000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6e+69) tmp = x; elseif (z <= 1600000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6e+69) tmp = x; elseif (z <= 1600000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6e+69], x, If[LessEqual[z, 1600000.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+69}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1600000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.99999999999999967e69 or 1.6e6 < z Initial program 100.0%
Taylor expanded in z around inf 73.6%
if -5.99999999999999967e69 < z < 1.6e6Initial program 100.0%
Taylor expanded in x around 0 47.6%
Final simplification59.0%
(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 35.2%
Final simplification35.2%
herbie shell --seed 2023257
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))