
(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.0)
x
(if (<= z -7.2e-197)
t_0
(if (<= z 2.05e-250)
(/ y z)
(if (<= z 1.4e-214) t_0 (if (<= z 1.72e+18) (/ y z) x)))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -1.0) {
tmp = x;
} else if (z <= -7.2e-197) {
tmp = t_0;
} else if (z <= 2.05e-250) {
tmp = y / z;
} else if (z <= 1.4e-214) {
tmp = t_0;
} else if (z <= 1.72e+18) {
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.0d0)) then
tmp = x
else if (z <= (-7.2d-197)) then
tmp = t_0
else if (z <= 2.05d-250) then
tmp = y / z
else if (z <= 1.4d-214) then
tmp = t_0
else if (z <= 1.72d+18) 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.0) {
tmp = x;
} else if (z <= -7.2e-197) {
tmp = t_0;
} else if (z <= 2.05e-250) {
tmp = y / z;
} else if (z <= 1.4e-214) {
tmp = t_0;
} else if (z <= 1.72e+18) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if z <= -1.0: tmp = x elif z <= -7.2e-197: tmp = t_0 elif z <= 2.05e-250: tmp = y / z elif z <= 1.4e-214: tmp = t_0 elif z <= 1.72e+18: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -1.0) tmp = x; elseif (z <= -7.2e-197) tmp = t_0; elseif (z <= 2.05e-250) tmp = Float64(y / z); elseif (z <= 1.4e-214) tmp = t_0; elseif (z <= 1.72e+18) 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.0) tmp = x; elseif (z <= -7.2e-197) tmp = t_0; elseif (z <= 2.05e-250) tmp = y / z; elseif (z <= 1.4e-214) tmp = t_0; elseif (z <= 1.72e+18) 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.0], x, If[LessEqual[z, -7.2e-197], t$95$0, If[LessEqual[z, 2.05e-250], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.4e-214], t$95$0, If[LessEqual[z, 1.72e+18], N[(y / z), $MachinePrecision], x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -7.2 \cdot 10^{-197}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.05 \cdot 10^{-250}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{-214}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.72 \cdot 10^{+18}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 1.72e18 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 72.5%
if -1 < z < -7.1999999999999997e-197 or 2.05000000000000008e-250 < z < 1.4000000000000001e-214Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 71.0%
Taylor expanded in z around 0 67.9%
mul-1-neg67.9%
distribute-frac-neg67.9%
Simplified67.9%
if -7.1999999999999997e-197 < z < 2.05000000000000008e-250 or 1.4000000000000001e-214 < z < 1.72e18Initial program 100.0%
div-sub96.0%
sub-neg96.0%
distribute-frac-neg96.0%
+-commutative96.0%
associate-+r+96.0%
distribute-frac-neg96.0%
sub-neg96.0%
associate--r-96.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 64.8%
Final simplification69.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.5e+110) (not (<= y 2.5e+46))) (/ y z) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e+110) || !(y <= 2.5e+46)) {
tmp = 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 <= (-7.5d+110)) .or. (.not. (y <= 2.5d+46))) then
tmp = 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 <= -7.5e+110) || !(y <= 2.5e+46)) {
tmp = y / z;
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.5e+110) or not (y <= 2.5e+46): tmp = y / z else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.5e+110) || !(y <= 2.5e+46)) tmp = 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 <= -7.5e+110) || ~((y <= 2.5e+46))) tmp = y / z; else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.5e+110], N[Not[LessEqual[y, 2.5e+46]], $MachinePrecision]], N[(y / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+110} \lor \neg \left(y \leq 2.5 \cdot 10^{+46}\right):\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -7.5e110 or 2.5000000000000001e46 < y Initial program 100.0%
div-sub97.7%
sub-neg97.7%
distribute-frac-neg97.7%
+-commutative97.7%
associate-+r+97.7%
distribute-frac-neg97.7%
sub-neg97.7%
associate--r-97.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 77.3%
if -7.5e110 < y < 2.5000000000000001e46Initial program 100.0%
div-sub99.4%
sub-neg99.4%
distribute-frac-neg99.4%
+-commutative99.4%
associate-+r+99.4%
distribute-frac-neg99.4%
sub-neg99.4%
associate--r-99.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 80.8%
Final simplification79.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -52000000000.0) (not (<= z 0.0024))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -52000000000.0) || !(z <= 0.0024)) {
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 <= (-52000000000.0d0)) .or. (.not. (z <= 0.0024d0))) 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 <= -52000000000.0) || !(z <= 0.0024)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -52000000000.0) or not (z <= 0.0024): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -52000000000.0) || !(z <= 0.0024)) 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 <= -52000000000.0) || ~((z <= 0.0024))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -52000000000.0], N[Not[LessEqual[z, 0.0024]], $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 -52000000000 \lor \neg \left(z \leq 0.0024\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -5.2e10 or 0.00239999999999999979 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 99.8%
neg-mul-199.8%
distribute-neg-frac299.8%
Simplified99.8%
if -5.2e10 < z < 0.00239999999999999979Initial program 100.0%
div-sub97.7%
sub-neg97.7%
distribute-frac-neg97.7%
+-commutative97.7%
associate-+r+97.7%
distribute-frac-neg97.7%
sub-neg97.7%
associate--r-97.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.3%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (<= z -9.2e+72) x (if (<= z 1.5e+16) (/ (- y x) z) (- x (/ x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.2e+72) {
tmp = x;
} else if (z <= 1.5e+16) {
tmp = (y - x) / 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 (z <= (-9.2d+72)) then
tmp = x
else if (z <= 1.5d+16) then
tmp = (y - x) / 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 (z <= -9.2e+72) {
tmp = x;
} else if (z <= 1.5e+16) {
tmp = (y - x) / z;
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.2e+72: tmp = x elif z <= 1.5e+16: tmp = (y - x) / z else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.2e+72) tmp = x; elseif (z <= 1.5e+16) tmp = Float64(Float64(y - x) / z); else tmp = Float64(x - Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.2e+72) tmp = x; elseif (z <= 1.5e+16) tmp = (y - x) / z; else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.2e+72], x, If[LessEqual[z, 1.5e+16], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{+72}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+16}:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if z < -9.199999999999999e72Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 75.6%
if -9.199999999999999e72 < z < 1.5e16Initial program 100.0%
div-sub98.0%
sub-neg98.0%
distribute-frac-neg98.0%
+-commutative98.0%
associate-+r+98.0%
distribute-frac-neg98.0%
sub-neg98.0%
associate--r-98.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 95.4%
if 1.5e16 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 77.5%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (<= z -8.5e+72) x (if (<= z 5.8e+14) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.5e+72) {
tmp = x;
} else if (z <= 5.8e+14) {
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 <= (-8.5d+72)) then
tmp = x
else if (z <= 5.8d+14) 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 <= -8.5e+72) {
tmp = x;
} else if (z <= 5.8e+14) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.5e+72: tmp = x elif z <= 5.8e+14: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.5e+72) tmp = x; elseif (z <= 5.8e+14) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.5e+72) tmp = x; elseif (z <= 5.8e+14) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.5e+72], x, If[LessEqual[z, 5.8e+14], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{+72}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{+14}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.5000000000000004e72 or 5.8e14 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 76.6%
if -8.5000000000000004e72 < z < 5.8e14Initial program 100.0%
div-sub98.0%
sub-neg98.0%
distribute-frac-neg98.0%
+-commutative98.0%
associate-+r+98.0%
distribute-frac-neg98.0%
sub-neg98.0%
associate--r-98.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 50.7%
Final simplification61.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%
sub-neg98.8%
distribute-frac-neg98.8%
+-commutative98.8%
associate-+r+98.8%
distribute-frac-neg98.8%
sub-neg98.8%
associate--r-98.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 36.1%
Final simplification36.1%
herbie shell --seed 2024072
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))