
(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%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ x (- z))))
(if (<= x -4.6e+118)
t_0
(if (<= x -5e-28)
x
(if (<= x 1.9e+24)
(/ y z)
(if (<= x 3.2e+165) x (if (<= x 1.5e+246) t_0 x)))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (x <= -4.6e+118) {
tmp = t_0;
} else if (x <= -5e-28) {
tmp = x;
} else if (x <= 1.9e+24) {
tmp = y / z;
} else if (x <= 3.2e+165) {
tmp = x;
} else if (x <= 1.5e+246) {
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 (x <= (-4.6d+118)) then
tmp = t_0
else if (x <= (-5d-28)) then
tmp = x
else if (x <= 1.9d+24) then
tmp = y / z
else if (x <= 3.2d+165) then
tmp = x
else if (x <= 1.5d+246) 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 (x <= -4.6e+118) {
tmp = t_0;
} else if (x <= -5e-28) {
tmp = x;
} else if (x <= 1.9e+24) {
tmp = y / z;
} else if (x <= 3.2e+165) {
tmp = x;
} else if (x <= 1.5e+246) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if x <= -4.6e+118: tmp = t_0 elif x <= -5e-28: tmp = x elif x <= 1.9e+24: tmp = y / z elif x <= 3.2e+165: tmp = x elif x <= 1.5e+246: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (x <= -4.6e+118) tmp = t_0; elseif (x <= -5e-28) tmp = x; elseif (x <= 1.9e+24) tmp = Float64(y / z); elseif (x <= 3.2e+165) tmp = x; elseif (x <= 1.5e+246) 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 (x <= -4.6e+118) tmp = t_0; elseif (x <= -5e-28) tmp = x; elseif (x <= 1.9e+24) tmp = y / z; elseif (x <= 3.2e+165) tmp = x; elseif (x <= 1.5e+246) 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[x, -4.6e+118], t$95$0, If[LessEqual[x, -5e-28], x, If[LessEqual[x, 1.9e+24], N[(y / z), $MachinePrecision], If[LessEqual[x, 3.2e+165], x, If[LessEqual[x, 1.5e+246], t$95$0, x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;x \leq -4.6 \cdot 10^{+118}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -5 \cdot 10^{-28}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{+24}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{+165}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{+246}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -4.60000000000000032e118 or 3.2e165 < x < 1.5e246Initial program 100.0%
div-sub98.4%
sub-neg98.4%
distribute-frac-neg98.4%
+-commutative98.4%
associate-+r+98.4%
distribute-frac-neg98.4%
sub-neg98.4%
associate--r-98.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 67.8%
Taylor expanded in y around 0 63.9%
neg-mul-163.9%
Simplified63.9%
if -4.60000000000000032e118 < x < -5.0000000000000002e-28 or 1.90000000000000008e24 < x < 3.2e165 or 1.5e246 < x Initial program 100.0%
div-sub98.6%
sub-neg98.6%
distribute-frac-neg98.6%
+-commutative98.6%
associate-+r+98.6%
distribute-frac-neg98.6%
sub-neg98.6%
associate--r-98.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 61.2%
if -5.0000000000000002e-28 < x < 1.90000000000000008e24Initial 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 70.5%
Final simplification66.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(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 <= (-1.0d0)) .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 <= -1.0) || !(z <= 1.0)) {
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 <= 1.0): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(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 <= -1.0) || ~((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, -1.0], 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 -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 1 < 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 97.9%
neg-mul-197.9%
distribute-neg-frac97.9%
Simplified97.9%
sub-neg97.9%
+-commutative97.9%
distribute-frac-neg97.9%
remove-double-neg97.9%
Applied egg-rr97.9%
if -1 < z < 1Initial program 100.0%
div-sub98.4%
sub-neg98.4%
distribute-frac-neg98.4%
+-commutative98.4%
associate-+r+98.4%
distribute-frac-neg98.4%
sub-neg98.4%
associate--r-98.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.5%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.8e-73) (not (<= y 1e-5))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.8e-73) || !(y <= 1e-5)) {
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 <= (-8.8d-73)) .or. (.not. (y <= 1d-5))) 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 <= -8.8e-73) || !(y <= 1e-5)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.8e-73) or not (y <= 1e-5): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.8e-73) || !(y <= 1e-5)) 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 <= -8.8e-73) || ~((y <= 1e-5))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.8e-73], N[Not[LessEqual[y, 1e-5]], $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 -8.8 \cdot 10^{-73} \lor \neg \left(y \leq 10^{-5}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -8.8000000000000001e-73 or 1.00000000000000008e-5 < y Initial program 100.0%
div-sub98.6%
sub-neg98.6%
distribute-frac-neg98.6%
+-commutative98.6%
associate-+r+98.6%
distribute-frac-neg98.6%
sub-neg98.6%
associate--r-98.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 88.1%
neg-mul-188.1%
distribute-neg-frac88.1%
Simplified88.1%
sub-neg88.1%
+-commutative88.1%
distribute-frac-neg88.1%
remove-double-neg88.1%
Applied egg-rr88.1%
if -8.8000000000000001e-73 < y < 1.00000000000000008e-5Initial 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 88.5%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (<= z -0.00048) x (if (<= z 1.46e+72) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.00048) {
tmp = x;
} else if (z <= 1.46e+72) {
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 <= (-0.00048d0)) then
tmp = x
else if (z <= 1.46d+72) 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 <= -0.00048) {
tmp = x;
} else if (z <= 1.46e+72) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.00048: tmp = x elif z <= 1.46e+72: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.00048) tmp = x; elseif (z <= 1.46e+72) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.00048) tmp = x; elseif (z <= 1.46e+72) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.00048], x, If[LessEqual[z, 1.46e+72], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.00048:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.46 \cdot 10^{+72}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.80000000000000012e-4 or 1.45999999999999999e72 < 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 68.8%
if -4.80000000000000012e-4 < z < 1.45999999999999999e72Initial program 100.0%
div-sub98.6%
sub-neg98.6%
distribute-frac-neg98.6%
+-commutative98.6%
associate-+r+98.6%
distribute-frac-neg98.6%
sub-neg98.6%
associate--r-98.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 51.5%
(FPCore (x y z) :precision binary64 (if (<= x -4.3e+120) (/ x (- z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.3e+120) {
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 <= (-4.3d+120)) 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 <= -4.3e+120) {
tmp = x / -z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.3e+120: tmp = x / -z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.3e+120) tmp = Float64(x / Float64(-z)); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.3e+120) tmp = x / -z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.3e+120], N[(x / (-z)), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.3 \cdot 10^{+120}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -4.3000000000000002e120Initial program 100.0%
div-sub97.6%
sub-neg97.6%
distribute-frac-neg97.6%
+-commutative97.6%
associate-+r+97.6%
distribute-frac-neg97.6%
sub-neg97.6%
associate--r-97.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 67.8%
Taylor expanded in y around 0 66.3%
neg-mul-166.3%
Simplified66.3%
if -4.3000000000000002e120 < x Initial program 100.0%
div-sub99.5%
sub-neg99.5%
distribute-frac-neg99.5%
+-commutative99.5%
associate-+r+99.5%
distribute-frac-neg99.5%
sub-neg99.5%
associate--r-99.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 79.7%
neg-mul-179.7%
distribute-neg-frac79.7%
Simplified79.7%
sub-neg79.7%
+-commutative79.7%
distribute-frac-neg79.7%
remove-double-neg79.7%
Applied egg-rr79.7%
Final simplification77.5%
(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-sub99.2%
sub-neg99.2%
distribute-frac-neg99.2%
+-commutative99.2%
associate-+r+99.2%
distribute-frac-neg99.2%
sub-neg99.2%
associate--r-99.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 33.1%
herbie shell --seed 2024110
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))