
(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 -4500000000000.0)
x
(if (<= z -9e-193)
(/ y z)
(if (<= z -7.8e-296)
t_0
(if (<= z 7.2e-80) (/ y z) (if (<= z 5.2e-24) t_0 x)))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -4500000000000.0) {
tmp = x;
} else if (z <= -9e-193) {
tmp = y / z;
} else if (z <= -7.8e-296) {
tmp = t_0;
} else if (z <= 7.2e-80) {
tmp = y / z;
} else if (z <= 5.2e-24) {
tmp = t_0;
} 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 <= (-4500000000000.0d0)) then
tmp = x
else if (z <= (-9d-193)) then
tmp = y / z
else if (z <= (-7.8d-296)) then
tmp = t_0
else if (z <= 7.2d-80) then
tmp = y / z
else if (z <= 5.2d-24) then
tmp = t_0
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 <= -4500000000000.0) {
tmp = x;
} else if (z <= -9e-193) {
tmp = y / z;
} else if (z <= -7.8e-296) {
tmp = t_0;
} else if (z <= 7.2e-80) {
tmp = y / z;
} else if (z <= 5.2e-24) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -4500000000000.0: tmp = x elif z <= -9e-193: tmp = y / z elif z <= -7.8e-296: tmp = t_0 elif z <= 7.2e-80: tmp = y / z elif z <= 5.2e-24: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -4500000000000.0) tmp = x; elseif (z <= -9e-193) tmp = Float64(y / z); elseif (z <= -7.8e-296) tmp = t_0; elseif (z <= 7.2e-80) tmp = Float64(y / z); elseif (z <= 5.2e-24) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x / z; tmp = 0.0; if (z <= -4500000000000.0) tmp = x; elseif (z <= -9e-193) tmp = y / z; elseif (z <= -7.8e-296) tmp = t_0; elseif (z <= 7.2e-80) tmp = y / z; elseif (z <= 5.2e-24) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -4500000000000.0], x, If[LessEqual[z, -9e-193], N[(y / z), $MachinePrecision], If[LessEqual[z, -7.8e-296], t$95$0, If[LessEqual[z, 7.2e-80], N[(y / z), $MachinePrecision], If[LessEqual[z, 5.2e-24], t$95$0, x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -4500000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -9 \cdot 10^{-193}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -7.8 \cdot 10^{-296}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.2 \cdot 10^{-80}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{-24}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.5e12 or 5.2e-24 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 77.0%
if -4.5e12 < z < -8.9999999999999997e-193 or -7.80000000000000021e-296 < z < 7.2e-80Initial program 100.0%
div-sub97.1%
associate-+r-97.1%
remove-double-neg97.1%
distribute-frac-neg97.1%
unsub-neg97.1%
associate--r+97.1%
+-commutative97.1%
distribute-frac-neg97.1%
sub-neg97.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 65.0%
if -8.9999999999999997e-193 < z < -7.80000000000000021e-296 or 7.2e-80 < z < 5.2e-24Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 100.0%
Taylor expanded in y around 0 76.2%
neg-mul-176.2%
distribute-neg-frac76.2%
Simplified76.2%
Final simplification72.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.15e-165) (not (<= y -8e-278))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.15e-165) || !(y <= -8e-278)) {
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 ((y <= (-1.15d-165)) .or. (.not. (y <= (-8d-278)))) 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 ((y <= -1.15e-165) || !(y <= -8e-278)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.15e-165) or not (y <= -8e-278): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.15e-165) || !(y <= -8e-278)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(Float64(-x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.15e-165) || ~((y <= -8e-278))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.15e-165], N[Not[LessEqual[y, -8e-278]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{-165} \lor \neg \left(y \leq -8 \cdot 10^{-278}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if y < -1.15e-165 or -7.9999999999999995e-278 < y Initial program 100.0%
div-sub98.7%
associate-+r-98.7%
remove-double-neg98.7%
distribute-frac-neg98.7%
unsub-neg98.7%
associate--r+98.7%
+-commutative98.7%
distribute-frac-neg98.7%
sub-neg98.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 82.0%
neg-mul-182.0%
distribute-neg-frac82.0%
Simplified82.0%
div-inv81.9%
cancel-sign-sub81.9%
div-inv82.0%
+-commutative82.0%
Applied egg-rr82.0%
if -1.15e-165 < y < -7.9999999999999995e-278Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 69.9%
Taylor expanded in y around 0 67.5%
neg-mul-167.5%
distribute-neg-frac67.5%
Simplified67.5%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.7e-103) (not (<= y 1.8e-194))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.7e-103) || !(y <= 1.8e-194)) {
tmp = x + (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 <= (-3.7d-103)) .or. (.not. (y <= 1.8d-194))) then
tmp = x + (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 <= -3.7e-103) || !(y <= 1.8e-194)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.7e-103) or not (y <= 1.8e-194): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.7e-103) || !(y <= 1.8e-194)) tmp = Float64(x + 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 <= -3.7e-103) || ~((y <= 1.8e-194))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.7e-103], N[Not[LessEqual[y, 1.8e-194]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{-103} \lor \neg \left(y \leq 1.8 \cdot 10^{-194}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -3.6999999999999999e-103 or 1.8e-194 < y Initial program 100.0%
div-sub98.4%
associate-+r-98.4%
remove-double-neg98.4%
distribute-frac-neg98.4%
unsub-neg98.4%
associate--r+98.4%
+-commutative98.4%
distribute-frac-neg98.4%
sub-neg98.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 87.0%
neg-mul-187.0%
distribute-neg-frac87.0%
Simplified87.0%
div-inv86.9%
cancel-sign-sub86.9%
div-inv87.0%
+-commutative87.0%
Applied egg-rr87.0%
if -3.6999999999999999e-103 < y < 1.8e-194Initial program 99.9%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around inf 91.9%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.1) (not (<= z 5.2e-24))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.1) || !(z <= 5.2e-24)) {
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 <= (-2.1d0)) .or. (.not. (z <= 5.2d-24))) 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 <= -2.1) || !(z <= 5.2e-24)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.1) or not (z <= 5.2e-24): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.1) || !(z <= 5.2e-24)) 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 <= -2.1) || ~((z <= 5.2e-24))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.1], N[Not[LessEqual[z, 5.2e-24]], $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 -2.1 \lor \neg \left(z \leq 5.2 \cdot 10^{-24}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -2.10000000000000009 or 5.2e-24 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 98.7%
neg-mul-198.7%
distribute-neg-frac98.7%
Simplified98.7%
div-inv98.6%
cancel-sign-sub98.6%
div-inv98.7%
+-commutative98.7%
Applied egg-rr98.7%
if -2.10000000000000009 < z < 5.2e-24Initial program 100.0%
div-sub97.8%
associate-+r-97.8%
remove-double-neg97.8%
distribute-frac-neg97.8%
unsub-neg97.8%
associate--r+97.8%
+-commutative97.8%
distribute-frac-neg97.8%
sub-neg97.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 100.0%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (<= z -66000000000000.0) x (if (<= z 55000000000000.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -66000000000000.0) {
tmp = x;
} else if (z <= 55000000000000.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 <= (-66000000000000.0d0)) then
tmp = x
else if (z <= 55000000000000.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 <= -66000000000000.0) {
tmp = x;
} else if (z <= 55000000000000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -66000000000000.0: tmp = x elif z <= 55000000000000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -66000000000000.0) tmp = x; elseif (z <= 55000000000000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -66000000000000.0) tmp = x; elseif (z <= 55000000000000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -66000000000000.0], x, If[LessEqual[z, 55000000000000.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -66000000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 55000000000000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.6e13 or 5.5e13 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 78.3%
if -6.6e13 < z < 5.5e13Initial program 100.0%
div-sub97.9%
associate-+r-97.9%
remove-double-neg97.9%
distribute-frac-neg97.9%
unsub-neg97.9%
associate--r+97.9%
+-commutative97.9%
distribute-frac-neg97.9%
sub-neg97.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 58.1%
Final simplification67.1%
(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%
associate-+r-98.8%
remove-double-neg98.8%
distribute-frac-neg98.8%
unsub-neg98.8%
associate--r+98.8%
+-commutative98.8%
distribute-frac-neg98.8%
sub-neg98.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 37.2%
Final simplification37.2%
herbie shell --seed 2024029
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))