
(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
(if (<= z -4.5e+106)
x
(if (<= z -4.5e-75)
(/ y z)
(if (<= z 3.8e-73) (/ x (- z)) (if (<= z 1.35e+17) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.5e+106) {
tmp = x;
} else if (z <= -4.5e-75) {
tmp = y / z;
} else if (z <= 3.8e-73) {
tmp = x / -z;
} else if (z <= 1.35e+17) {
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 <= (-4.5d+106)) then
tmp = x
else if (z <= (-4.5d-75)) then
tmp = y / z
else if (z <= 3.8d-73) then
tmp = x / -z
else if (z <= 1.35d+17) 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 <= -4.5e+106) {
tmp = x;
} else if (z <= -4.5e-75) {
tmp = y / z;
} else if (z <= 3.8e-73) {
tmp = x / -z;
} else if (z <= 1.35e+17) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.5e+106: tmp = x elif z <= -4.5e-75: tmp = y / z elif z <= 3.8e-73: tmp = x / -z elif z <= 1.35e+17: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.5e+106) tmp = x; elseif (z <= -4.5e-75) tmp = Float64(y / z); elseif (z <= 3.8e-73) tmp = Float64(x / Float64(-z)); elseif (z <= 1.35e+17) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.5e+106) tmp = x; elseif (z <= -4.5e-75) tmp = y / z; elseif (z <= 3.8e-73) tmp = x / -z; elseif (z <= 1.35e+17) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.5e+106], x, If[LessEqual[z, -4.5e-75], N[(y / z), $MachinePrecision], If[LessEqual[z, 3.8e-73], N[(x / (-z)), $MachinePrecision], If[LessEqual[z, 1.35e+17], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{+106}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -4.5 \cdot 10^{-75}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-73}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{+17}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.4999999999999997e106 or 1.35e17 < 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.1%
if -4.4999999999999997e106 < z < -4.5000000000000003e-75 or 3.8000000000000003e-73 < z < 1.35e17Initial 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 66.2%
if -4.5000000000000003e-75 < z < 3.8000000000000003e-73Initial 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 z around 0 100.0%
Taylor expanded in y around 0 64.1%
neg-mul-164.1%
Simplified64.1%
Final simplification69.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.65) (not (<= z 6.8e-22))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.65) || !(z <= 6.8e-22)) {
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.65d0)) .or. (.not. (z <= 6.8d-22))) 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.65) || !(z <= 6.8e-22)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.65) or not (z <= 6.8e-22): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.65) || !(z <= 6.8e-22)) 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.65) || ~((z <= 6.8e-22))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.65], N[Not[LessEqual[z, 6.8e-22]], $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.65 \lor \neg \left(z \leq 6.8 \cdot 10^{-22}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1.6499999999999999 or 6.7999999999999997e-22 < 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.0%
neg-mul-199.0%
Simplified99.0%
Taylor expanded in x around 0 99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
*-lft-identity99.0%
+-commutative99.0%
Simplified99.0%
if -1.6499999999999999 < z < 6.7999999999999997e-22Initial program 100.0%
div-sub92.7%
sub-neg92.7%
distribute-frac-neg92.7%
+-commutative92.7%
associate-+r+92.7%
distribute-frac-neg92.7%
sub-neg92.7%
associate--r-92.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.6%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.6e+47) (not (<= x 1.6e+65))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e+47) || !(x <= 1.6e+65)) {
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 <= (-1.6d+47)) .or. (.not. (x <= 1.6d+65))) 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 <= -1.6e+47) || !(x <= 1.6e+65)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.6e+47) or not (x <= 1.6e+65): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e+47) || !(x <= 1.6e+65)) 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 <= -1.6e+47) || ~((x <= 1.6e+65))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e+47], N[Not[LessEqual[x, 1.6e+65]], $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 -1.6 \cdot 10^{+47} \lor \neg \left(x \leq 1.6 \cdot 10^{+65}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.6e47 or 1.60000000000000003e65 < x Initial program 100.0%
div-sub93.0%
sub-neg93.0%
distribute-frac-neg93.0%
+-commutative93.0%
associate-+r+93.0%
distribute-frac-neg93.0%
sub-neg93.0%
associate--r-93.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 94.0%
distribute-lft-out--94.0%
*-rgt-identity94.0%
associate-*r/94.1%
*-rgt-identity94.1%
Simplified94.1%
if -1.6e47 < x < 1.60000000000000003e65Initial 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 91.2%
neg-mul-191.2%
Simplified91.2%
Taylor expanded in x around 0 91.2%
cancel-sign-sub-inv91.2%
metadata-eval91.2%
*-lft-identity91.2%
+-commutative91.2%
Simplified91.2%
Final simplification92.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.4e-68) (not (<= z 4.5e-73))) (+ x (/ y z)) (/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e-68) || !(z <= 4.5e-73)) {
tmp = x + (y / z);
} else {
tmp = 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 <= (-2.4d-68)) .or. (.not. (z <= 4.5d-73))) then
tmp = x + (y / z)
else
tmp = x / -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e-68) || !(z <= 4.5e-73)) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.4e-68) or not (z <= 4.5e-73): tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.4e-68) || !(z <= 4.5e-73)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x / Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.4e-68) || ~((z <= 4.5e-73))) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.4e-68], N[Not[LessEqual[z, 4.5e-73]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-68} \lor \neg \left(z \leq 4.5 \cdot 10^{-73}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if z < -2.39999999999999991e-68 or 4.5e-73 < z Initial 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 94.9%
neg-mul-194.9%
Simplified94.9%
Taylor expanded in x around 0 94.9%
cancel-sign-sub-inv94.9%
metadata-eval94.9%
*-lft-identity94.9%
+-commutative94.9%
Simplified94.9%
if -2.39999999999999991e-68 < z < 4.5e-73Initial 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 z around 0 100.0%
Taylor expanded in y around 0 64.1%
neg-mul-164.1%
Simplified64.1%
Final simplification82.6%
(FPCore (x y z) :precision binary64 (if (<= z -5.2e+106) x (if (<= z 1.3e+17) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.2e+106) {
tmp = x;
} else if (z <= 1.3e+17) {
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 <= (-5.2d+106)) then
tmp = x
else if (z <= 1.3d+17) 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 <= -5.2e+106) {
tmp = x;
} else if (z <= 1.3e+17) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.2e+106: tmp = x elif z <= 1.3e+17: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.2e+106) tmp = x; elseif (z <= 1.3e+17) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.2e+106) tmp = x; elseif (z <= 1.3e+17) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.2e+106], x, If[LessEqual[z, 1.3e+17], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+106}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{+17}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.20000000000000039e106 or 1.3e17 < 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.1%
if -5.20000000000000039e106 < z < 1.3e17Initial 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 x around 0 49.4%
(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.5%
sub-neg96.5%
distribute-frac-neg96.5%
+-commutative96.5%
associate-+r+96.5%
distribute-frac-neg96.5%
sub-neg96.5%
associate--r-96.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 35.7%
herbie shell --seed 2024146
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))