
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ x (- z))))
(if (<= z -1.0)
x
(if (<= z -1.12e-250)
t_0
(if (<= z 3.7e-281)
(/ y z)
(if (<= z 9e-192) t_0 (if (<= z 122000.0) (/ y z) x)))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -1.0) {
tmp = x;
} else if (z <= -1.12e-250) {
tmp = t_0;
} else if (z <= 3.7e-281) {
tmp = y / z;
} else if (z <= 9e-192) {
tmp = t_0;
} else if (z <= 122000.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) :: t_0
real(8) :: tmp
t_0 = x / -z
if (z <= (-1.0d0)) then
tmp = x
else if (z <= (-1.12d-250)) then
tmp = t_0
else if (z <= 3.7d-281) then
tmp = y / z
else if (z <= 9d-192) then
tmp = t_0
else if (z <= 122000.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 t_0 = x / -z;
double tmp;
if (z <= -1.0) {
tmp = x;
} else if (z <= -1.12e-250) {
tmp = t_0;
} else if (z <= 3.7e-281) {
tmp = y / z;
} else if (z <= 9e-192) {
tmp = t_0;
} else if (z <= 122000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if z <= -1.0: tmp = x elif z <= -1.12e-250: tmp = t_0 elif z <= 3.7e-281: tmp = y / z elif z <= 9e-192: tmp = t_0 elif z <= 122000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -1.0) tmp = x; elseif (z <= -1.12e-250) tmp = t_0; elseif (z <= 3.7e-281) tmp = Float64(y / z); elseif (z <= 9e-192) tmp = t_0; elseif (z <= 122000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x / -z; tmp = 0.0; if (z <= -1.0) tmp = x; elseif (z <= -1.12e-250) tmp = t_0; elseif (z <= 3.7e-281) tmp = y / z; elseif (z <= 9e-192) tmp = t_0; elseif (z <= 122000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / (-z)), $MachinePrecision]}, If[LessEqual[z, -1.0], x, If[LessEqual[z, -1.12e-250], t$95$0, If[LessEqual[z, 3.7e-281], N[(y / z), $MachinePrecision], If[LessEqual[z, 9e-192], t$95$0, If[LessEqual[z, 122000.0], N[(y / z), $MachinePrecision], x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.12 \cdot 10^{-250}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.7 \cdot 10^{-281}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 9 \cdot 10^{-192}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 122000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1 or 122000 < 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.3%
if -1 < z < -1.11999999999999996e-250 or 3.69999999999999992e-281 < z < 9.00000000000000048e-192Initial program 100.0%
div-sub96.6%
sub-neg96.6%
distribute-frac-neg96.6%
+-commutative96.6%
associate-+r+96.6%
distribute-frac-neg96.6%
sub-neg96.6%
associate--r-96.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 68.7%
Taylor expanded in z around 0 67.9%
mul-1-neg67.9%
distribute-frac-neg67.9%
Simplified67.9%
if -1.11999999999999996e-250 < z < 3.69999999999999992e-281 or 9.00000000000000048e-192 < z < 122000Initial program 100.0%
div-sub94.5%
sub-neg94.5%
distribute-frac-neg94.5%
+-commutative94.5%
associate-+r+94.5%
distribute-frac-neg94.5%
sub-neg94.5%
associate--r-94.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 70.3%
Final simplification72.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.7e+123) (not (<= y 1.9e+77))) (/ y z) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.7e+123) || !(y <= 1.9e+77)) {
tmp = 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 <= (-1.7d+123)) .or. (.not. (y <= 1.9d+77))) then
tmp = 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 <= -1.7e+123) || !(y <= 1.9e+77)) {
tmp = y / z;
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.7e+123) or not (y <= 1.9e+77): tmp = y / z else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.7e+123) || !(y <= 1.9e+77)) tmp = 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 <= -1.7e+123) || ~((y <= 1.9e+77))) tmp = y / z; else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.7e+123], N[Not[LessEqual[y, 1.9e+77]], $MachinePrecision]], N[(y / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{+123} \lor \neg \left(y \leq 1.9 \cdot 10^{+77}\right):\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.70000000000000001e123 or 1.9000000000000001e77 < y Initial program 100.0%
div-sub94.2%
sub-neg94.2%
distribute-frac-neg94.2%
+-commutative94.2%
associate-+r+94.2%
distribute-frac-neg94.2%
sub-neg94.2%
associate--r-94.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 74.6%
if -1.70000000000000001e123 < y < 1.9000000000000001e77Initial program 100.0%
div-sub99.4%
sub-neg99.4%
distribute-frac-neg99.4%
+-commutative99.4%
associate-+r+99.4%
distribute-frac-neg99.4%
sub-neg99.4%
associate--r-99.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 80.1%
Final simplification78.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.85e-6) (not (<= z 75000.0))) (- x (/ x z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.85e-6) || !(z <= 75000.0)) {
tmp = x - (x / 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 <= (-2.85d-6)) .or. (.not. (z <= 75000.0d0))) then
tmp = x - (x / 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 <= -2.85e-6) || !(z <= 75000.0)) {
tmp = x - (x / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.85e-6) or not (z <= 75000.0): tmp = x - (x / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.85e-6) || !(z <= 75000.0)) tmp = Float64(x - Float64(x / z)); else tmp = Float64(Float64(y - x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.85e-6) || ~((z <= 75000.0))) tmp = x - (x / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.85e-6], N[Not[LessEqual[z, 75000.0]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.85 \cdot 10^{-6} \lor \neg \left(z \leq 75000\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -2.8499999999999998e-6 or 75000 < 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 inf 78.1%
if -2.8499999999999998e-6 < z < 75000Initial program 100.0%
div-sub95.5%
sub-neg95.5%
distribute-frac-neg95.5%
+-commutative95.5%
associate-+r+95.5%
distribute-frac-neg95.5%
sub-neg95.5%
associate--r-95.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 100.0%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 4.4e-21))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 4.4e-21)) {
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 <= 4.4d-21))) 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 <= 4.4e-21)) {
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 <= 4.4e-21): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 4.4e-21)) 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 <= 4.4e-21))) 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, 4.4e-21]], $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 4.4 \cdot 10^{-21}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 4.4000000000000001e-21 < 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%
distribute-neg-frac298.5%
Simplified98.5%
if -1 < z < 4.4000000000000001e-21Initial program 100.0%
div-sub95.1%
sub-neg95.1%
distribute-frac-neg95.1%
+-commutative95.1%
associate-+r+95.1%
distribute-frac-neg95.1%
sub-neg95.1%
associate--r-95.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.6%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (<= z -2.85e-6) x (if (<= z 122000.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.85e-6) {
tmp = x;
} else if (z <= 122000.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 <= (-2.85d-6)) then
tmp = x
else if (z <= 122000.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 <= -2.85e-6) {
tmp = x;
} else if (z <= 122000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.85e-6: tmp = x elif z <= 122000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.85e-6) tmp = x; elseif (z <= 122000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.85e-6) tmp = x; elseif (z <= 122000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.85e-6], x, If[LessEqual[z, 122000.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.85 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 122000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.8499999999999998e-6 or 122000 < 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 75.8%
if -2.8499999999999998e-6 < z < 122000Initial program 100.0%
div-sub95.5%
sub-neg95.5%
distribute-frac-neg95.5%
+-commutative95.5%
associate-+r+95.5%
distribute-frac-neg95.5%
sub-neg95.5%
associate--r-95.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 56.4%
Final simplification65.8%
(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-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 z around inf 38.2%
Final simplification38.2%
herbie shell --seed 2024078
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))