
(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 -5.5e+87) x (if (<= z 2.3e-118) (/ y z) (if (<= z 1.0) (/ x (- z)) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e+87) {
tmp = x;
} else if (z <= 2.3e-118) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = x / -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.5d+87)) then
tmp = x
else if (z <= 2.3d-118) then
tmp = y / z
else if (z <= 1.0d0) then
tmp = x / -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.5e+87) {
tmp = x;
} else if (z <= 2.3e-118) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = x / -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.5e+87: tmp = x elif z <= 2.3e-118: tmp = y / z elif z <= 1.0: tmp = x / -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.5e+87) tmp = x; elseif (z <= 2.3e-118) tmp = Float64(y / z); elseif (z <= 1.0) tmp = Float64(x / Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.5e+87) tmp = x; elseif (z <= 2.3e-118) tmp = y / z; elseif (z <= 1.0) tmp = x / -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.5e+87], x, If[LessEqual[z, 2.3e-118], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], N[(x / (-z)), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{+87}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-118}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.50000000000000022e87 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 z around inf 76.7%
if -5.50000000000000022e87 < z < 2.30000000000000021e-118Initial program 100.0%
div-sub96.3%
sub-neg96.3%
distribute-frac-neg96.3%
+-commutative96.3%
associate-+r+96.3%
distribute-frac-neg96.3%
sub-neg96.3%
associate--r-96.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 68.0%
if 2.30000000000000021e-118 < z < 1Initial 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 75.5%
distribute-lft-out--75.5%
*-rgt-identity75.5%
associate-*r/75.6%
*-rgt-identity75.6%
Simplified75.6%
Taylor expanded in z around 0 70.9%
associate-*r/70.9%
neg-mul-170.9%
Simplified70.9%
Final simplification71.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -90000000000.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -90000000000.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 <= (-90000000000.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 <= -90000000000.0) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -90000000000.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 <= -90000000000.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 <= -90000000000.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, -90000000000.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 -90000000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -9e10 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 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 -9e10 < z < 1Initial program 100.0%
div-sub96.4%
sub-neg96.4%
distribute-frac-neg96.4%
+-commutative96.4%
associate-+r+96.4%
distribute-frac-neg96.4%
sub-neg96.4%
associate--r-96.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.9%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.6e+194) (not (<= x 1.65e+63))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.6e+194) || !(x <= 1.65e+63)) {
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 <= (-5.6d+194)) .or. (.not. (x <= 1.65d+63))) 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 <= -5.6e+194) || !(x <= 1.65e+63)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.6e+194) or not (x <= 1.65e+63): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.6e+194) || !(x <= 1.65e+63)) 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 <= -5.6e+194) || ~((x <= 1.65e+63))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.6e+194], N[Not[LessEqual[x, 1.65e+63]], $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 -5.6 \cdot 10^{+194} \lor \neg \left(x \leq 1.65 \cdot 10^{+63}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -5.60000000000000021e194 or 1.6500000000000001e63 < x Initial program 100.0%
div-sub93.6%
sub-neg93.6%
distribute-frac-neg93.6%
+-commutative93.6%
associate-+r+93.6%
distribute-frac-neg93.6%
sub-neg93.6%
associate--r-93.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 93.7%
distribute-lft-out--93.7%
*-rgt-identity93.7%
associate-*r/93.8%
*-rgt-identity93.8%
Simplified93.8%
if -5.60000000000000021e194 < x < 1.6500000000000001e63Initial 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 89.6%
neg-mul-189.6%
Simplified89.6%
Taylor expanded in x around 0 89.6%
cancel-sign-sub-inv89.6%
metadata-eval89.6%
*-lft-identity89.6%
+-commutative89.6%
Simplified89.6%
Final simplification90.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.04e+197) (not (<= x 9.5e+223))) (/ x (- z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.04e+197) || !(x <= 9.5e+223)) {
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.04d+197)) .or. (.not. (x <= 9.5d+223))) 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.04e+197) || !(x <= 9.5e+223)) {
tmp = x / -z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.04e+197) or not (x <= 9.5e+223): tmp = x / -z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.04e+197) || !(x <= 9.5e+223)) 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.04e+197) || ~((x <= 9.5e+223))) tmp = x / -z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.04e+197], N[Not[LessEqual[x, 9.5e+223]], $MachinePrecision]], N[(x / (-z)), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.04 \cdot 10^{+197} \lor \neg \left(x \leq 9.5 \cdot 10^{+223}\right):\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.04000000000000005e197 or 9.50000000000000064e223 < x Initial program 100.0%
div-sub90.2%
sub-neg90.2%
distribute-frac-neg90.2%
+-commutative90.2%
associate-+r+90.2%
distribute-frac-neg90.2%
sub-neg90.2%
associate--r-90.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
associate-*r/100.0%
*-rgt-identity100.0%
Simplified100.0%
Taylor expanded in z around 0 69.1%
associate-*r/69.1%
neg-mul-169.1%
Simplified69.1%
if -1.04000000000000005e197 < x < 9.50000000000000064e223Initial 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 87.3%
neg-mul-187.3%
Simplified87.3%
Taylor expanded in x around 0 87.3%
cancel-sign-sub-inv87.3%
metadata-eval87.3%
*-lft-identity87.3%
+-commutative87.3%
Simplified87.3%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (<= z -6.7e+87) x (if (<= z 3.8e+80) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.7e+87) {
tmp = x;
} else if (z <= 3.8e+80) {
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 <= (-6.7d+87)) then
tmp = x
else if (z <= 3.8d+80) 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 <= -6.7e+87) {
tmp = x;
} else if (z <= 3.8e+80) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.7e+87: tmp = x elif z <= 3.8e+80: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.7e+87) tmp = x; elseif (z <= 3.8e+80) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.7e+87) tmp = x; elseif (z <= 3.8e+80) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.7e+87], x, If[LessEqual[z, 3.8e+80], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.7 \cdot 10^{+87}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{+80}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.7000000000000003e87 or 3.79999999999999997e80 < 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 83.1%
if -6.7000000000000003e87 < z < 3.79999999999999997e80Initial program 100.0%
div-sub97.0%
sub-neg97.0%
distribute-frac-neg97.0%
+-commutative97.0%
associate-+r+97.0%
distribute-frac-neg97.0%
sub-neg97.0%
associate--r-97.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 62.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-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 34.6%
herbie shell --seed 2024185
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))