
(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 -7.8e+114)
t_0
(if (<= x -9.6e-5)
x
(if (<= x 8.6e+23) (/ y z) (if (<= x 3.2e+143) x t_0))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (x <= -7.8e+114) {
tmp = t_0;
} else if (x <= -9.6e-5) {
tmp = x;
} else if (x <= 8.6e+23) {
tmp = y / z;
} else if (x <= 3.2e+143) {
tmp = x;
} 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) :: tmp
t_0 = x / -z
if (x <= (-7.8d+114)) then
tmp = t_0
else if (x <= (-9.6d-5)) then
tmp = x
else if (x <= 8.6d+23) then
tmp = y / z
else if (x <= 3.2d+143) then
tmp = x
else
tmp = t_0
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 <= -7.8e+114) {
tmp = t_0;
} else if (x <= -9.6e-5) {
tmp = x;
} else if (x <= 8.6e+23) {
tmp = y / z;
} else if (x <= 3.2e+143) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if x <= -7.8e+114: tmp = t_0 elif x <= -9.6e-5: tmp = x elif x <= 8.6e+23: tmp = y / z elif x <= 3.2e+143: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (x <= -7.8e+114) tmp = t_0; elseif (x <= -9.6e-5) tmp = x; elseif (x <= 8.6e+23) tmp = Float64(y / z); elseif (x <= 3.2e+143) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x / -z; tmp = 0.0; if (x <= -7.8e+114) tmp = t_0; elseif (x <= -9.6e-5) tmp = x; elseif (x <= 8.6e+23) tmp = y / z; elseif (x <= 3.2e+143) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / (-z)), $MachinePrecision]}, If[LessEqual[x, -7.8e+114], t$95$0, If[LessEqual[x, -9.6e-5], x, If[LessEqual[x, 8.6e+23], N[(y / z), $MachinePrecision], If[LessEqual[x, 3.2e+143], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;x \leq -7.8 \cdot 10^{+114}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -9.6 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 8.6 \cdot 10^{+23}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{+143}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -7.8000000000000001e114 or 3.20000000000000016e143 < x Initial program 100.0%
div-sub92.1%
sub-neg92.1%
distribute-frac-neg92.1%
+-commutative92.1%
associate-+r+92.1%
distribute-frac-neg92.1%
sub-neg92.1%
associate--r-92.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 94.8%
distribute-lft-out--94.7%
*-rgt-identity94.7%
associate-*r/94.8%
*-rgt-identity94.8%
Simplified94.8%
Taylor expanded in z around 0 61.7%
mul-1-neg61.7%
distribute-frac-neg61.7%
Simplified61.7%
if -7.8000000000000001e114 < x < -9.6000000000000002e-5 or 8.5999999999999997e23 < x < 3.20000000000000016e143Initial 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 inf 54.3%
if -9.6000000000000002e-5 < x < 8.5999999999999997e23Initial 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 x around 0 75.6%
Final simplification67.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.7e-9))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.7e-9)) {
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.7d-9))) 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.7e-9)) {
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.7e-9): 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.7e-9)) 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.7e-9))) 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.7e-9]], $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.7 \cdot 10^{-9}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 1.6999999999999999e-9 < 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 98.5%
neg-mul-198.5%
Simplified98.5%
Taylor expanded in x around 0 98.5%
cancel-sign-sub-inv98.5%
metadata-eval98.5%
*-lft-identity98.5%
+-commutative98.5%
Simplified98.5%
if -1 < z < 1.6999999999999999e-9Initial program 100.0%
div-sub94.1%
sub-neg94.1%
distribute-frac-neg94.1%
+-commutative94.1%
associate-+r+94.1%
distribute-frac-neg94.1%
sub-neg94.1%
associate--r-94.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.1%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -0.00122) (not (<= x 3.9e+115))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -0.00122) || !(x <= 3.9e+115)) {
tmp = x - (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 <= (-0.00122d0)) .or. (.not. (x <= 3.9d+115))) then
tmp = x - (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 <= -0.00122) || !(x <= 3.9e+115)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -0.00122) or not (x <= 3.9e+115): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -0.00122) || !(x <= 3.9e+115)) tmp = Float64(x - Float64(x / z)); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -0.00122) || ~((x <= 3.9e+115))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -0.00122], N[Not[LessEqual[x, 3.9e+115]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.00122 \lor \neg \left(x \leq 3.9 \cdot 10^{+115}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -0.00121999999999999995 or 3.90000000000000006e115 < x Initial program 100.0%
div-sub93.4%
sub-neg93.4%
distribute-frac-neg93.4%
+-commutative93.4%
associate-+r+93.4%
distribute-frac-neg93.4%
sub-neg93.4%
associate--r-93.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 92.5%
distribute-lft-out--92.5%
*-rgt-identity92.5%
associate-*r/92.6%
*-rgt-identity92.6%
Simplified92.6%
if -0.00121999999999999995 < x < 3.90000000000000006e115Initial program 100.0%
div-sub99.3%
sub-neg99.3%
distribute-frac-neg99.3%
+-commutative99.3%
associate-+r+99.3%
distribute-frac-neg99.3%
sub-neg99.3%
associate--r-99.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 92.5%
neg-mul-192.5%
Simplified92.5%
Taylor expanded in x around 0 92.5%
cancel-sign-sub-inv92.5%
metadata-eval92.5%
*-lft-identity92.5%
+-commutative92.5%
Simplified92.5%
Final simplification92.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.02e+164) (not (<= x 2e+145))) (/ x (- z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.02e+164) || !(x <= 2e+145)) {
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 <= (-1.02d+164)) .or. (.not. (x <= 2d+145))) 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 <= -1.02e+164) || !(x <= 2e+145)) {
tmp = x / -z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.02e+164) or not (x <= 2e+145): tmp = x / -z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.02e+164) || !(x <= 2e+145)) 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 <= -1.02e+164) || ~((x <= 2e+145))) tmp = x / -z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.02e+164], N[Not[LessEqual[x, 2e+145]], $MachinePrecision]], N[(x / (-z)), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.02 \cdot 10^{+164} \lor \neg \left(x \leq 2 \cdot 10^{+145}\right):\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.02e164 or 2e145 < x Initial program 100.0%
div-sub92.4%
sub-neg92.4%
distribute-frac-neg92.4%
+-commutative92.4%
associate-+r+92.4%
distribute-frac-neg92.4%
sub-neg92.4%
associate--r-92.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 96.9%
distribute-lft-out--96.9%
*-rgt-identity96.9%
associate-*r/96.9%
*-rgt-identity96.9%
Simplified96.9%
Taylor expanded in z around 0 63.2%
mul-1-neg63.2%
distribute-frac-neg63.2%
Simplified63.2%
if -1.02e164 < x < 2e145Initial 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 x around 0 86.5%
neg-mul-186.5%
Simplified86.5%
Taylor expanded in x around 0 86.5%
cancel-sign-sub-inv86.5%
metadata-eval86.5%
*-lft-identity86.5%
+-commutative86.5%
Simplified86.5%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (if (<= z -8e+18) x (if (<= z 1.85e+70) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8e+18) {
tmp = x;
} else if (z <= 1.85e+70) {
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 <= (-8d+18)) then
tmp = x
else if (z <= 1.85d+70) 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 <= -8e+18) {
tmp = x;
} else if (z <= 1.85e+70) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8e+18: tmp = x elif z <= 1.85e+70: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8e+18) tmp = x; elseif (z <= 1.85e+70) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8e+18) tmp = x; elseif (z <= 1.85e+70) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8e+18], x, If[LessEqual[z, 1.85e+70], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{+18}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.85 \cdot 10^{+70}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8e18 or 1.84999999999999994e70 < 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 70.4%
if -8e18 < z < 1.84999999999999994e70Initial program 100.0%
div-sub94.9%
sub-neg94.9%
distribute-frac-neg94.9%
+-commutative94.9%
associate-+r+94.9%
distribute-frac-neg94.9%
sub-neg94.9%
associate--r-94.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 55.2%
(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-sub96.9%
sub-neg96.9%
distribute-frac-neg96.9%
+-commutative96.9%
associate-+r+96.9%
distribute-frac-neg96.9%
sub-neg96.9%
associate--r-96.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 31.0%
herbie shell --seed 2024160
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))