
(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.2e+61)
x
(if (<= z -1.02e-132)
(/ y z)
(if (<= z -3.45e-217)
t_0
(if (<= z -7e-268)
(/ y z)
(if (<= z 4.4e-262)
t_0
(if (<= z 1.05e-229)
(/ y z)
(if (<= z 1.2e-215) t_0 (if (<= z 4.7e+47) (/ y z) x))))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -1.2e+61) {
tmp = x;
} else if (z <= -1.02e-132) {
tmp = y / z;
} else if (z <= -3.45e-217) {
tmp = t_0;
} else if (z <= -7e-268) {
tmp = y / z;
} else if (z <= 4.4e-262) {
tmp = t_0;
} else if (z <= 1.05e-229) {
tmp = y / z;
} else if (z <= 1.2e-215) {
tmp = t_0;
} else if (z <= 4.7e+47) {
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.2d+61)) then
tmp = x
else if (z <= (-1.02d-132)) then
tmp = y / z
else if (z <= (-3.45d-217)) then
tmp = t_0
else if (z <= (-7d-268)) then
tmp = y / z
else if (z <= 4.4d-262) then
tmp = t_0
else if (z <= 1.05d-229) then
tmp = y / z
else if (z <= 1.2d-215) then
tmp = t_0
else if (z <= 4.7d+47) 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.2e+61) {
tmp = x;
} else if (z <= -1.02e-132) {
tmp = y / z;
} else if (z <= -3.45e-217) {
tmp = t_0;
} else if (z <= -7e-268) {
tmp = y / z;
} else if (z <= 4.4e-262) {
tmp = t_0;
} else if (z <= 1.05e-229) {
tmp = y / z;
} else if (z <= 1.2e-215) {
tmp = t_0;
} else if (z <= 4.7e+47) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -1.2e+61: tmp = x elif z <= -1.02e-132: tmp = y / z elif z <= -3.45e-217: tmp = t_0 elif z <= -7e-268: tmp = y / z elif z <= 4.4e-262: tmp = t_0 elif z <= 1.05e-229: tmp = y / z elif z <= 1.2e-215: tmp = t_0 elif z <= 4.7e+47: 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.2e+61) tmp = x; elseif (z <= -1.02e-132) tmp = Float64(y / z); elseif (z <= -3.45e-217) tmp = t_0; elseif (z <= -7e-268) tmp = Float64(y / z); elseif (z <= 4.4e-262) tmp = t_0; elseif (z <= 1.05e-229) tmp = Float64(y / z); elseif (z <= 1.2e-215) tmp = t_0; elseif (z <= 4.7e+47) 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.2e+61) tmp = x; elseif (z <= -1.02e-132) tmp = y / z; elseif (z <= -3.45e-217) tmp = t_0; elseif (z <= -7e-268) tmp = y / z; elseif (z <= 4.4e-262) tmp = t_0; elseif (z <= 1.05e-229) tmp = y / z; elseif (z <= 1.2e-215) tmp = t_0; elseif (z <= 4.7e+47) 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.2e+61], x, If[LessEqual[z, -1.02e-132], N[(y / z), $MachinePrecision], If[LessEqual[z, -3.45e-217], t$95$0, If[LessEqual[z, -7e-268], N[(y / z), $MachinePrecision], If[LessEqual[z, 4.4e-262], t$95$0, If[LessEqual[z, 1.05e-229], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.2e-215], t$95$0, If[LessEqual[z, 4.7e+47], N[(y / z), $MachinePrecision], x]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -1.2 \cdot 10^{+61}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.02 \cdot 10^{-132}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -3.45 \cdot 10^{-217}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -7 \cdot 10^{-268}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 4.4 \cdot 10^{-262}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{-229}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{-215}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.7 \cdot 10^{+47}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.1999999999999999e61 or 4.69999999999999964e47 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 81.2%
if -1.1999999999999999e61 < z < -1.01999999999999998e-132 or -3.44999999999999987e-217 < z < -7.00000000000000011e-268 or 4.39999999999999977e-262 < z < 1.04999999999999992e-229 or 1.20000000000000005e-215 < z < 4.69999999999999964e47Initial program 100.0%
div-sub99.1%
associate-+r-99.1%
remove-double-neg99.1%
distribute-frac-neg99.1%
unsub-neg99.1%
associate--r+99.1%
+-commutative99.1%
distribute-frac-neg99.1%
sub-neg99.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 64.4%
if -1.01999999999999998e-132 < z < -3.44999999999999987e-217 or -7.00000000000000011e-268 < z < 4.39999999999999977e-262 or 1.04999999999999992e-229 < z < 1.20000000000000005e-215Initial program 100.0%
div-sub94.6%
associate-+r-94.6%
remove-double-neg94.6%
distribute-frac-neg94.6%
unsub-neg94.6%
associate--r+94.6%
+-commutative94.6%
distribute-frac-neg94.6%
sub-neg94.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 77.9%
Taylor expanded in z around 0 77.9%
associate-*r/77.9%
mul-1-neg77.9%
Simplified77.9%
Final simplification73.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.1e-67) (not (<= y 2.2e+19))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.1e-67) || !(y <= 2.2e+19)) {
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.1d-67)) .or. (.not. (y <= 2.2d+19))) 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.1e-67) || !(y <= 2.2e+19)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.1e-67) or not (y <= 2.2e+19): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.1e-67) || !(y <= 2.2e+19)) 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.1e-67) || ~((y <= 2.2e+19))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.1e-67], N[Not[LessEqual[y, 2.2e+19]], $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.1 \cdot 10^{-67} \lor \neg \left(y \leq 2.2 \cdot 10^{+19}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -4.0999999999999997e-67 or 2.2e19 < y Initial program 100.0%
div-sub97.8%
associate-+r-97.8%
remove-double-neg97.8%
distribute-frac-neg97.8%
unsub-neg97.8%
associate--r+97.8%
+-commutative97.8%
distribute-frac-neg97.8%
sub-neg97.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 90.3%
neg-mul-190.3%
distribute-neg-frac90.3%
Simplified90.3%
Taylor expanded in x around 0 90.3%
+-commutative90.3%
Simplified90.3%
if -4.0999999999999997e-67 < y < 2.2e19Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 90.4%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -22000000000.0) (not (<= z 4.5e-19))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -22000000000.0) || !(z <= 4.5e-19)) {
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 <= (-22000000000.0d0)) .or. (.not. (z <= 4.5d-19))) 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 <= -22000000000.0) || !(z <= 4.5e-19)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -22000000000.0) or not (z <= 4.5e-19): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -22000000000.0) || !(z <= 4.5e-19)) 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 <= -22000000000.0) || ~((z <= 4.5e-19))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -22000000000.0], N[Not[LessEqual[z, 4.5e-19]], $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 -22000000000 \lor \neg \left(z \leq 4.5 \cdot 10^{-19}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -2.2e10 or 4.50000000000000013e-19 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 99.8%
neg-mul-199.8%
distribute-neg-frac99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
+-commutative99.8%
Simplified99.8%
if -2.2e10 < z < 4.50000000000000013e-19Initial program 100.0%
div-sub97.6%
associate-+r-97.6%
remove-double-neg97.6%
distribute-frac-neg97.6%
unsub-neg97.6%
associate--r+97.6%
+-commutative97.6%
distribute-frac-neg97.6%
sub-neg97.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.5%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.2e+61) x (if (<= z 5.5e+42) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.2e+61) {
tmp = x;
} else if (z <= 5.5e+42) {
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 <= (-1.2d+61)) then
tmp = x
else if (z <= 5.5d+42) 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 <= -1.2e+61) {
tmp = x;
} else if (z <= 5.5e+42) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.2e+61: tmp = x elif z <= 5.5e+42: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.2e+61) tmp = x; elseif (z <= 5.5e+42) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.2e+61) tmp = x; elseif (z <= 5.5e+42) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.2e+61], x, If[LessEqual[z, 5.5e+42], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{+61}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{+42}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.1999999999999999e61 or 5.50000000000000001e42 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 81.2%
if -1.1999999999999999e61 < z < 5.50000000000000001e42Initial program 100.0%
div-sub98.0%
associate-+r-98.0%
remove-double-neg98.0%
distribute-frac-neg98.0%
unsub-neg98.0%
associate--r+98.0%
+-commutative98.0%
distribute-frac-neg98.0%
sub-neg98.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 56.3%
Final simplification66.8%
(FPCore (x y z) :precision binary64 (+ x (/ y z)))
double code(double x, double y, double z) {
return x + (y / 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 / z)
end function
public static double code(double x, double y, double z) {
return x + (y / z);
}
def code(x, y, z): return x + (y / z)
function code(x, y, z) return Float64(x + Float64(y / z)) end
function tmp = code(x, y, z) tmp = x + (y / z); end
code[x_, y_, z_] := N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{z}
\end{array}
Initial program 100.0%
div-sub98.8%
associate-+r-98.8%
remove-double-neg98.8%
distribute-frac-neg98.8%
unsub-neg98.8%
associate--r+98.8%
+-commutative98.8%
distribute-frac-neg98.8%
sub-neg98.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 77.6%
neg-mul-177.6%
distribute-neg-frac77.6%
Simplified77.6%
Taylor expanded in x around 0 77.6%
+-commutative77.6%
Simplified77.6%
Final simplification77.6%
(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%
div-sub98.8%
associate-+r-98.8%
remove-double-neg98.8%
distribute-frac-neg98.8%
unsub-neg98.8%
associate--r+98.8%
+-commutative98.8%
distribute-frac-neg98.8%
sub-neg98.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 38.5%
Final simplification38.5%
herbie shell --seed 2024031
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))