
(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 6 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 -8.6e+28)
x
(if (<= z -1.15e-29)
(/ y z)
(if (<= z -1.7e-177)
t_0
(if (<= z 1.5e-222)
(/ y z)
(if (<= z 2.5e-164) t_0 (if (<= z 1.05e+83) (/ y z) x))))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -8.6e+28) {
tmp = x;
} else if (z <= -1.15e-29) {
tmp = y / z;
} else if (z <= -1.7e-177) {
tmp = t_0;
} else if (z <= 1.5e-222) {
tmp = y / z;
} else if (z <= 2.5e-164) {
tmp = t_0;
} else if (z <= 1.05e+83) {
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 <= (-8.6d+28)) then
tmp = x
else if (z <= (-1.15d-29)) then
tmp = y / z
else if (z <= (-1.7d-177)) then
tmp = t_0
else if (z <= 1.5d-222) then
tmp = y / z
else if (z <= 2.5d-164) then
tmp = t_0
else if (z <= 1.05d+83) 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 <= -8.6e+28) {
tmp = x;
} else if (z <= -1.15e-29) {
tmp = y / z;
} else if (z <= -1.7e-177) {
tmp = t_0;
} else if (z <= 1.5e-222) {
tmp = y / z;
} else if (z <= 2.5e-164) {
tmp = t_0;
} else if (z <= 1.05e+83) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if z <= -8.6e+28: tmp = x elif z <= -1.15e-29: tmp = y / z elif z <= -1.7e-177: tmp = t_0 elif z <= 1.5e-222: tmp = y / z elif z <= 2.5e-164: tmp = t_0 elif z <= 1.05e+83: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -8.6e+28) tmp = x; elseif (z <= -1.15e-29) tmp = Float64(y / z); elseif (z <= -1.7e-177) tmp = t_0; elseif (z <= 1.5e-222) tmp = Float64(y / z); elseif (z <= 2.5e-164) tmp = t_0; elseif (z <= 1.05e+83) 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 <= -8.6e+28) tmp = x; elseif (z <= -1.15e-29) tmp = y / z; elseif (z <= -1.7e-177) tmp = t_0; elseif (z <= 1.5e-222) tmp = y / z; elseif (z <= 2.5e-164) tmp = t_0; elseif (z <= 1.05e+83) 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, -8.6e+28], x, If[LessEqual[z, -1.15e-29], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.7e-177], t$95$0, If[LessEqual[z, 1.5e-222], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.5e-164], t$95$0, If[LessEqual[z, 1.05e+83], N[(y / z), $MachinePrecision], x]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -8.6 \cdot 10^{+28}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.15 \cdot 10^{-29}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.7 \cdot 10^{-177}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{-222}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{-164}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{+83}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.59999999999999951e28 or 1.05000000000000001e83 < 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 84.1%
Taylor expanded in z around inf 84.1%
if -8.59999999999999951e28 < z < -1.14999999999999996e-29 or -1.7e-177 < z < 1.50000000000000015e-222 or 2.49999999999999981e-164 < z < 1.05000000000000001e83Initial 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 x around 0 74.9%
neg-mul-174.9%
distribute-neg-frac74.9%
Simplified74.9%
Taylor expanded in x around 0 67.0%
if -1.14999999999999996e-29 < z < -1.7e-177 or 1.50000000000000015e-222 < z < 2.49999999999999981e-164Initial 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 inf 73.7%
Taylor expanded in z around 0 73.7%
mul-1-neg73.7%
distribute-frac-neg273.7%
Simplified73.7%
Final simplification74.7%
(FPCore (x y z)
:precision binary64
(if (or (<= z -3.6e-29)
(and (not (<= z -6.2e-178))
(or (<= z 9.6e-220) (not (<= z 1.2e-164)))))
(+ x (/ y z))
(/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.6e-29) || (!(z <= -6.2e-178) && ((z <= 9.6e-220) || !(z <= 1.2e-164)))) {
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 <= (-3.6d-29)) .or. (.not. (z <= (-6.2d-178))) .and. (z <= 9.6d-220) .or. (.not. (z <= 1.2d-164))) 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 <= -3.6e-29) || (!(z <= -6.2e-178) && ((z <= 9.6e-220) || !(z <= 1.2e-164)))) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.6e-29) or (not (z <= -6.2e-178) and ((z <= 9.6e-220) or not (z <= 1.2e-164))): tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.6e-29) || (!(z <= -6.2e-178) && ((z <= 9.6e-220) || !(z <= 1.2e-164)))) 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 <= -3.6e-29) || (~((z <= -6.2e-178)) && ((z <= 9.6e-220) || ~((z <= 1.2e-164))))) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.6e-29], And[N[Not[LessEqual[z, -6.2e-178]], $MachinePrecision], Or[LessEqual[z, 9.6e-220], N[Not[LessEqual[z, 1.2e-164]], $MachinePrecision]]]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.6 \cdot 10^{-29} \lor \neg \left(z \leq -6.2 \cdot 10^{-178}\right) \land \left(z \leq 9.6 \cdot 10^{-220} \lor \neg \left(z \leq 1.2 \cdot 10^{-164}\right)\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if z < -3.59999999999999974e-29 or -6.1999999999999999e-178 < z < 9.6000000000000006e-220 or 1.19999999999999992e-164 < z Initial program 100.0%
div-sub98.1%
sub-neg98.1%
distribute-frac-neg98.1%
+-commutative98.1%
associate-+r+98.1%
distribute-frac-neg98.1%
sub-neg98.1%
associate--r-98.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 86.5%
neg-mul-186.5%
distribute-neg-frac86.5%
Simplified86.5%
sub-neg86.5%
+-commutative86.5%
distribute-frac-neg86.5%
remove-double-neg86.5%
Applied egg-rr86.5%
if -3.59999999999999974e-29 < z < -6.1999999999999999e-178 or 9.6000000000000006e-220 < z < 1.19999999999999992e-164Initial 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 inf 73.7%
Taylor expanded in z around 0 73.7%
mul-1-neg73.7%
distribute-frac-neg273.7%
Simplified73.7%
Final simplification84.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -10400000.0) (not (<= x 2.6e+116))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -10400000.0) || !(x <= 2.6e+116)) {
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 <= (-10400000.0d0)) .or. (.not. (x <= 2.6d+116))) 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 <= -10400000.0) || !(x <= 2.6e+116)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -10400000.0) or not (x <= 2.6e+116): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -10400000.0) || !(x <= 2.6e+116)) 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 <= -10400000.0) || ~((x <= 2.6e+116))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -10400000.0], N[Not[LessEqual[x, 2.6e+116]], $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 -10400000 \lor \neg \left(x \leq 2.6 \cdot 10^{+116}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.04e7 or 2.59999999999999987e116 < x 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 inf 93.2%
if -1.04e7 < x < 2.59999999999999987e116Initial 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 90.3%
neg-mul-190.3%
distribute-neg-frac90.3%
Simplified90.3%
sub-neg90.3%
+-commutative90.3%
distribute-frac-neg90.3%
remove-double-neg90.3%
Applied egg-rr90.3%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.1e+26) x (if (<= z 7e+81) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.1e+26) {
tmp = x;
} else if (z <= 7e+81) {
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.1d+26)) then
tmp = x
else if (z <= 7d+81) 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.1e+26) {
tmp = x;
} else if (z <= 7e+81) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.1e+26: tmp = x elif z <= 7e+81: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.1e+26) tmp = x; elseif (z <= 7e+81) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.1e+26) tmp = x; elseif (z <= 7e+81) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.1e+26], x, If[LessEqual[z, 7e+81], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.1 \cdot 10^{+26}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+81}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.10000000000000004e26 or 7.0000000000000001e81 < 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 84.1%
Taylor expanded in z around inf 84.1%
if -1.10000000000000004e26 < z < 7.0000000000000001e81Initial program 100.0%
div-sub96.2%
sub-neg96.2%
distribute-frac-neg96.2%
+-commutative96.2%
associate-+r+96.2%
distribute-frac-neg96.2%
sub-neg96.2%
associate--r-96.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 63.0%
neg-mul-163.0%
distribute-neg-frac63.0%
Simplified63.0%
Taylor expanded in x around 0 57.0%
Final simplification67.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-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 inf 61.2%
Taylor expanded in z around inf 37.3%
Final simplification37.3%
herbie shell --seed 2024055
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))