
(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 -1.6e+40)
x
(if (<= z -1.7e-286)
(/ y z)
(if (<= z 2.3e-228) (/ x (- z)) (if (<= z 250000000000.0) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.6e+40) {
tmp = x;
} else if (z <= -1.7e-286) {
tmp = y / z;
} else if (z <= 2.3e-228) {
tmp = x / -z;
} else if (z <= 250000000000.0) {
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 <= (-1.6d+40)) then
tmp = x
else if (z <= (-1.7d-286)) then
tmp = y / z
else if (z <= 2.3d-228) then
tmp = x / -z
else if (z <= 250000000000.0d0) 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 <= -1.6e+40) {
tmp = x;
} else if (z <= -1.7e-286) {
tmp = y / z;
} else if (z <= 2.3e-228) {
tmp = x / -z;
} else if (z <= 250000000000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.6e+40: tmp = x elif z <= -1.7e-286: tmp = y / z elif z <= 2.3e-228: tmp = x / -z elif z <= 250000000000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.6e+40) tmp = x; elseif (z <= -1.7e-286) tmp = Float64(y / z); elseif (z <= 2.3e-228) tmp = Float64(x / Float64(-z)); elseif (z <= 250000000000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.6e+40) tmp = x; elseif (z <= -1.7e-286) tmp = y / z; elseif (z <= 2.3e-228) tmp = x / -z; elseif (z <= 250000000000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.6e+40], x, If[LessEqual[z, -1.7e-286], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.3e-228], N[(x / (-z)), $MachinePrecision], If[LessEqual[z, 250000000000.0], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.6 \cdot 10^{+40}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.7 \cdot 10^{-286}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-228}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{elif}\;z \leq 250000000000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.5999999999999999e40 or 2.5e11 < 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.1%
if -1.5999999999999999e40 < z < -1.7000000000000001e-286 or 2.2999999999999999e-228 < z < 2.5e11Initial program 100.0%
div-sub98.2%
sub-neg98.2%
distribute-frac-neg98.2%
+-commutative98.2%
associate-+r+98.2%
distribute-frac-neg98.2%
sub-neg98.2%
associate--r-98.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 59.4%
if -1.7000000000000001e-286 < z < 2.2999999999999999e-228Initial program 100.0%
div-sub93.8%
sub-neg93.8%
distribute-frac-neg93.8%
+-commutative93.8%
associate-+r+93.8%
distribute-frac-neg93.8%
sub-neg93.8%
associate--r-93.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 87.7%
distribute-lft-out--87.7%
*-rgt-identity87.7%
associate-*r/87.9%
*-rgt-identity87.9%
Simplified87.9%
Taylor expanded in z around 0 87.9%
mul-1-neg87.9%
distribute-frac-neg87.9%
Simplified87.9%
Final simplification67.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1e+17) (not (<= z 1.2e-20))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e+17) || !(z <= 1.2e-20)) {
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 <= (-1d+17)) .or. (.not. (z <= 1.2d-20))) 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 <= -1e+17) || !(z <= 1.2e-20)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e+17) or not (z <= 1.2e-20): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e+17) || !(z <= 1.2e-20)) 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 <= -1e+17) || ~((z <= 1.2e-20))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e+17], N[Not[LessEqual[z, 1.2e-20]], $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 \cdot 10^{+17} \lor \neg \left(z \leq 1.2 \cdot 10^{-20}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1e17 or 1.19999999999999996e-20 < 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.6%
neg-mul-199.6%
Simplified99.6%
Taylor expanded in x around 0 99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
Simplified99.6%
if -1e17 < z < 1.19999999999999996e-20Initial program 100.0%
div-sub97.4%
sub-neg97.4%
distribute-frac-neg97.4%
+-commutative97.4%
associate-+r+97.4%
distribute-frac-neg97.4%
sub-neg97.4%
associate--r-97.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 100.0%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3e+75) (not (<= x 1.9e+57))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3e+75) || !(x <= 1.9e+57)) {
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 <= (-3d+75)) .or. (.not. (x <= 1.9d+57))) 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 <= -3e+75) || !(x <= 1.9e+57)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3e+75) or not (x <= 1.9e+57): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3e+75) || !(x <= 1.9e+57)) 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 <= -3e+75) || ~((x <= 1.9e+57))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3e+75], N[Not[LessEqual[x, 1.9e+57]], $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 -3 \cdot 10^{+75} \lor \neg \left(x \leq 1.9 \cdot 10^{+57}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -3e75 or 1.8999999999999999e57 < x Initial program 100.0%
div-sub96.8%
sub-neg96.8%
distribute-frac-neg96.8%
+-commutative96.8%
associate-+r+96.8%
distribute-frac-neg96.8%
sub-neg96.8%
associate--r-96.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 93.1%
distribute-lft-out--93.1%
*-rgt-identity93.1%
associate-*r/93.1%
*-rgt-identity93.1%
Simplified93.1%
if -3e75 < x < 1.8999999999999999e57Initial 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 87.8%
neg-mul-187.8%
Simplified87.8%
Taylor expanded in x around 0 87.8%
cancel-sign-sub-inv87.8%
metadata-eval87.8%
*-lft-identity87.8%
+-commutative87.8%
Simplified87.8%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -7e-280) (not (<= z 6.8e-234))) (+ x (/ y z)) (/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7e-280) || !(z <= 6.8e-234)) {
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 <= (-7d-280)) .or. (.not. (z <= 6.8d-234))) 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 <= -7e-280) || !(z <= 6.8e-234)) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7e-280) or not (z <= 6.8e-234): tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7e-280) || !(z <= 6.8e-234)) 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 <= -7e-280) || ~((z <= 6.8e-234))) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7e-280], N[Not[LessEqual[z, 6.8e-234]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{-280} \lor \neg \left(z \leq 6.8 \cdot 10^{-234}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if z < -7.0000000000000002e-280 or 6.79999999999999971e-234 < z Initial program 100.0%
div-sub99.1%
sub-neg99.1%
distribute-frac-neg99.1%
+-commutative99.1%
associate-+r+99.1%
distribute-frac-neg99.1%
sub-neg99.1%
associate--r-99.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 82.7%
neg-mul-182.7%
Simplified82.7%
Taylor expanded in x around 0 82.7%
cancel-sign-sub-inv82.7%
metadata-eval82.7%
*-lft-identity82.7%
+-commutative82.7%
Simplified82.7%
if -7.0000000000000002e-280 < z < 6.79999999999999971e-234Initial program 100.0%
div-sub93.8%
sub-neg93.8%
distribute-frac-neg93.8%
+-commutative93.8%
associate-+r+93.8%
distribute-frac-neg93.8%
sub-neg93.8%
associate--r-93.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 87.7%
distribute-lft-out--87.7%
*-rgt-identity87.7%
associate-*r/87.9%
*-rgt-identity87.9%
Simplified87.9%
Taylor expanded in z around 0 87.9%
mul-1-neg87.9%
distribute-frac-neg87.9%
Simplified87.9%
Final simplification83.0%
(FPCore (x y z) :precision binary64 (if (<= z -1.4e+38) x (if (<= z 15500000000000.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e+38) {
tmp = x;
} else if (z <= 15500000000000.0) {
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 <= (-1.4d+38)) then
tmp = x
else if (z <= 15500000000000.0d0) 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 <= -1.4e+38) {
tmp = x;
} else if (z <= 15500000000000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.4e+38: tmp = x elif z <= 15500000000000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.4e+38) tmp = x; elseif (z <= 15500000000000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.4e+38) tmp = x; elseif (z <= 15500000000000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.4e+38], x, If[LessEqual[z, 15500000000000.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{+38}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 15500000000000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.4e38 or 1.55e13 < 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.1%
if -1.4e38 < z < 1.55e13Initial 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 55.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 38.2%
herbie shell --seed 2024130
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))