
(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
(let* ((t_0 (/ x (- z))))
(if (<= z -9.8e+95)
x
(if (<= z -1.6e-13)
(/ y z)
(if (<= z 1.2e-262)
t_0
(if (<= z 1.15e-63) (/ y z) (if (<= z 15.2) t_0 x)))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -9.8e+95) {
tmp = x;
} else if (z <= -1.6e-13) {
tmp = y / z;
} else if (z <= 1.2e-262) {
tmp = t_0;
} else if (z <= 1.15e-63) {
tmp = y / z;
} else if (z <= 15.2) {
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 <= (-9.8d+95)) then
tmp = x
else if (z <= (-1.6d-13)) then
tmp = y / z
else if (z <= 1.2d-262) then
tmp = t_0
else if (z <= 1.15d-63) then
tmp = y / z
else if (z <= 15.2d0) 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 <= -9.8e+95) {
tmp = x;
} else if (z <= -1.6e-13) {
tmp = y / z;
} else if (z <= 1.2e-262) {
tmp = t_0;
} else if (z <= 1.15e-63) {
tmp = y / z;
} else if (z <= 15.2) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if z <= -9.8e+95: tmp = x elif z <= -1.6e-13: tmp = y / z elif z <= 1.2e-262: tmp = t_0 elif z <= 1.15e-63: tmp = y / z elif z <= 15.2: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -9.8e+95) tmp = x; elseif (z <= -1.6e-13) tmp = Float64(y / z); elseif (z <= 1.2e-262) tmp = t_0; elseif (z <= 1.15e-63) tmp = Float64(y / z); elseif (z <= 15.2) 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 <= -9.8e+95) tmp = x; elseif (z <= -1.6e-13) tmp = y / z; elseif (z <= 1.2e-262) tmp = t_0; elseif (z <= 1.15e-63) tmp = y / z; elseif (z <= 15.2) 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, -9.8e+95], x, If[LessEqual[z, -1.6e-13], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.2e-262], t$95$0, If[LessEqual[z, 1.15e-63], N[(y / z), $MachinePrecision], If[LessEqual[z, 15.2], t$95$0, x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -9.8 \cdot 10^{+95}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.6 \cdot 10^{-13}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{-262}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-63}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 15.2:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.7999999999999998e95 or 15.199999999999999 < 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 80.6%
if -9.7999999999999998e95 < z < -1.6e-13 or 1.2e-262 < z < 1.15e-63Initial program 100.0%
div-sub94.9%
sub-neg94.9%
distribute-frac-neg94.9%
+-commutative94.9%
associate-+r+94.9%
distribute-frac-neg94.9%
sub-neg94.9%
associate--r-94.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 65.4%
if -1.6e-13 < z < 1.2e-262 or 1.15e-63 < z < 15.199999999999999Initial program 100.0%
div-sub93.9%
sub-neg93.9%
distribute-frac-neg93.9%
+-commutative93.9%
associate-+r+93.9%
distribute-frac-neg93.9%
sub-neg93.9%
associate--r-93.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 67.3%
Taylor expanded in z around 0 64.8%
associate-*r/64.8%
neg-mul-164.8%
Simplified64.8%
Final simplification70.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
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 <= 1.0): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) 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 <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 1 < 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.7%
neg-mul-198.7%
distribute-neg-frac98.7%
Simplified98.7%
sub-neg98.7%
distribute-frac-neg98.7%
remove-double-neg98.7%
+-commutative98.7%
Applied egg-rr98.7%
if -1 < z < 1Initial program 100.0%
div-sub93.3%
sub-neg93.3%
distribute-frac-neg93.3%
+-commutative93.3%
associate-+r+93.3%
distribute-frac-neg93.3%
sub-neg93.3%
associate--r-93.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.5%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.5e+21) (not (<= y 5.4e+25))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.5e+21) || !(y <= 5.4e+25)) {
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 <= (-6.5d+21)) .or. (.not. (y <= 5.4d+25))) 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 <= -6.5e+21) || !(y <= 5.4e+25)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.5e+21) or not (y <= 5.4e+25): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.5e+21) || !(y <= 5.4e+25)) 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 <= -6.5e+21) || ~((y <= 5.4e+25))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.5e+21], N[Not[LessEqual[y, 5.4e+25]], $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 -6.5 \cdot 10^{+21} \lor \neg \left(y \leq 5.4 \cdot 10^{+25}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -6.5e21 or 5.4e25 < y Initial program 100.0%
div-sub93.0%
sub-neg93.0%
distribute-frac-neg93.0%
+-commutative93.0%
associate-+r+93.0%
distribute-frac-neg93.0%
sub-neg93.0%
associate--r-93.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 90.4%
neg-mul-190.4%
distribute-neg-frac90.4%
Simplified90.4%
sub-neg90.4%
distribute-frac-neg90.4%
remove-double-neg90.4%
+-commutative90.4%
Applied egg-rr90.4%
if -6.5e21 < y < 5.4e25Initial 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 87.9%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.2e-15) (not (<= z 6.5e-264))) (+ x (/ y z)) (/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.2e-15) || !(z <= 6.5e-264)) {
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 <= (-8.2d-15)) .or. (.not. (z <= 6.5d-264))) 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 <= -8.2e-15) || !(z <= 6.5e-264)) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.2e-15) or not (z <= 6.5e-264): tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.2e-15) || !(z <= 6.5e-264)) 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 <= -8.2e-15) || ~((z <= 6.5e-264))) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.2e-15], N[Not[LessEqual[z, 6.5e-264]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.2 \cdot 10^{-15} \lor \neg \left(z \leq 6.5 \cdot 10^{-264}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if z < -8.20000000000000072e-15 or 6.5000000000000001e-264 < z Initial program 100.0%
div-sub97.8%
sub-neg97.8%
distribute-frac-neg97.8%
+-commutative97.8%
associate-+r+97.8%
distribute-frac-neg97.8%
sub-neg97.8%
associate--r-97.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 83.8%
neg-mul-183.8%
distribute-neg-frac83.8%
Simplified83.8%
sub-neg83.8%
distribute-frac-neg83.8%
remove-double-neg83.8%
+-commutative83.8%
Applied egg-rr83.8%
if -8.20000000000000072e-15 < z < 6.5000000000000001e-264Initial program 100.0%
div-sub92.8%
sub-neg92.8%
distribute-frac-neg92.8%
+-commutative92.8%
associate-+r+92.8%
distribute-frac-neg92.8%
sub-neg92.8%
associate--r-92.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 64.4%
Taylor expanded in z around 0 64.4%
associate-*r/64.4%
neg-mul-164.4%
Simplified64.4%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.05e+96) x (if (<= z 1.55e+17) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.05e+96) {
tmp = x;
} else if (z <= 1.55e+17) {
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.05d+96)) then
tmp = x
else if (z <= 1.55d+17) 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.05e+96) {
tmp = x;
} else if (z <= 1.55e+17) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.05e+96: tmp = x elif z <= 1.55e+17: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.05e+96) tmp = x; elseif (z <= 1.55e+17) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.05e+96) tmp = x; elseif (z <= 1.55e+17) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.05e+96], x, If[LessEqual[z, 1.55e+17], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.05 \cdot 10^{+96}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.55 \cdot 10^{+17}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.0500000000000001e96 or 1.55e17 < 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 83.5%
if -1.0500000000000001e96 < z < 1.55e17Initial 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 51.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-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 z around inf 35.1%
herbie shell --seed 2024123
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))