
(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
(if (<= z -2.7e+16)
x
(if (<= z 1.5e-206)
(/ y z)
(if (<= z 1.3e-137) (/ x (- z)) (if (<= z 8e+84) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.7e+16) {
tmp = x;
} else if (z <= 1.5e-206) {
tmp = y / z;
} else if (z <= 1.3e-137) {
tmp = x / -z;
} else if (z <= 8e+84) {
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.7d+16)) then
tmp = x
else if (z <= 1.5d-206) then
tmp = y / z
else if (z <= 1.3d-137) then
tmp = x / -z
else if (z <= 8d+84) 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.7e+16) {
tmp = x;
} else if (z <= 1.5e-206) {
tmp = y / z;
} else if (z <= 1.3e-137) {
tmp = x / -z;
} else if (z <= 8e+84) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.7e+16: tmp = x elif z <= 1.5e-206: tmp = y / z elif z <= 1.3e-137: tmp = x / -z elif z <= 8e+84: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.7e+16) tmp = x; elseif (z <= 1.5e-206) tmp = Float64(y / z); elseif (z <= 1.3e-137) tmp = Float64(x / Float64(-z)); elseif (z <= 8e+84) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.7e+16) tmp = x; elseif (z <= 1.5e-206) tmp = y / z; elseif (z <= 1.3e-137) tmp = x / -z; elseif (z <= 8e+84) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.7e+16], x, If[LessEqual[z, 1.5e-206], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.3e-137], N[(x / (-z)), $MachinePrecision], If[LessEqual[z, 8e+84], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{+16}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{-206}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{-137}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{elif}\;z \leq 8 \cdot 10^{+84}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.7e16 or 8.00000000000000046e84 < 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 73.4%
if -2.7e16 < z < 1.5000000000000001e-206 or 1.3e-137 < z < 8.00000000000000046e84Initial 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 68.6%
if 1.5000000000000001e-206 < z < 1.3e-137Initial program 99.9%
div-sub99.9%
sub-neg99.9%
distribute-frac-neg99.9%
+-commutative99.9%
associate-+r+99.9%
distribute-frac-neg99.9%
sub-neg99.9%
associate--r-99.9%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around inf 74.8%
Taylor expanded in z around 0 74.8%
associate-*r/74.8%
neg-mul-174.8%
Simplified74.8%
Final simplification70.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -6e+110) (not (<= x 1.5e+99))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e+110) || !(x <= 1.5e+99)) {
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 <= (-6d+110)) .or. (.not. (x <= 1.5d+99))) 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 <= -6e+110) || !(x <= 1.5e+99)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e+110) or not (x <= 1.5e+99): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e+110) || !(x <= 1.5e+99)) 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 <= -6e+110) || ~((x <= 1.5e+99))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e+110], N[Not[LessEqual[x, 1.5e+99]], $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 -6 \cdot 10^{+110} \lor \neg \left(x \leq 1.5 \cdot 10^{+99}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -6.00000000000000014e110 or 1.50000000000000007e99 < x Initial program 100.0%
div-sub95.2%
sub-neg95.2%
distribute-frac-neg95.2%
+-commutative95.2%
associate-+r+95.2%
distribute-frac-neg95.2%
sub-neg95.2%
associate--r-95.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 91.8%
if -6.00000000000000014e110 < x < 1.50000000000000007e99Initial 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 x around 0 90.4%
neg-mul-190.4%
distribute-neg-frac290.4%
Simplified90.4%
Taylor expanded in x around 0 90.4%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 7.5e-7))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 7.5e-7)) {
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 <= 7.5d-7))) 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 <= 7.5e-7)) {
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 <= 7.5e-7): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 7.5e-7)) 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 <= 7.5e-7))) 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, 7.5e-7]], $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 7.5 \cdot 10^{-7}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 7.5000000000000002e-7 < 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.7%
neg-mul-199.7%
distribute-neg-frac299.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
if -1 < z < 7.5000000000000002e-7Initial program 100.0%
div-sub95.2%
sub-neg95.2%
distribute-frac-neg95.2%
+-commutative95.2%
associate-+r+95.2%
distribute-frac-neg95.2%
sub-neg95.2%
associate--r-95.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.1%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.8e+16) x (if (<= z 1.35e+78) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.8e+16) {
tmp = x;
} else if (z <= 1.35e+78) {
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.8d+16)) then
tmp = x
else if (z <= 1.35d+78) 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.8e+16) {
tmp = x;
} else if (z <= 1.35e+78) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.8e+16: tmp = x elif z <= 1.35e+78: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.8e+16) tmp = x; elseif (z <= 1.35e+78) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.8e+16) tmp = x; elseif (z <= 1.35e+78) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.8e+16], x, If[LessEqual[z, 1.35e+78], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{+16}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{+78}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.8e16 or 1.35000000000000002e78 < 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 73.4%
if -1.8e16 < z < 1.35000000000000002e78Initial program 100.0%
div-sub96.0%
sub-neg96.0%
distribute-frac-neg96.0%
+-commutative96.0%
associate-+r+96.0%
distribute-frac-neg96.0%
sub-neg96.0%
associate--r-96.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 65.0%
Final simplification68.5%
(FPCore (x y z) :precision binary64 (+ x (/ y z)))
double code(double x, double y, double z) {
return x + (y / 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 / z)
end function
public static double code(double x, double y, double z) {
return x + (y / z);
}
def code(x, y, z): return x + (y / z)
function code(x, y, z) return Float64(x + Float64(y / z)) end
function tmp = code(x, y, z) tmp = x + (y / z); end
code[x_, y_, z_] := N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{z}
\end{array}
Initial program 100.0%
div-sub97.6%
sub-neg97.6%
distribute-frac-neg97.6%
+-commutative97.6%
associate-+r+97.6%
distribute-frac-neg97.6%
sub-neg97.6%
associate--r-97.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 82.5%
neg-mul-182.5%
distribute-neg-frac282.5%
Simplified82.5%
Taylor expanded in x around 0 82.5%
Final simplification82.5%
(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.6%
sub-neg97.6%
distribute-frac-neg97.6%
+-commutative97.6%
associate-+r+97.6%
distribute-frac-neg97.6%
sub-neg97.6%
associate--r-97.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 34.7%
Final simplification34.7%
herbie shell --seed 2024046
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))