
(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 -1.35e+43)
x
(if (<= z -1.8e-15)
(/ y z)
(if (<= z 3e-140) (/ (- x) z) (if (<= z 8e+72) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.35e+43) {
tmp = x;
} else if (z <= -1.8e-15) {
tmp = y / z;
} else if (z <= 3e-140) {
tmp = -x / z;
} else if (z <= 8e+72) {
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.35d+43)) then
tmp = x
else if (z <= (-1.8d-15)) then
tmp = y / z
else if (z <= 3d-140) then
tmp = -x / z
else if (z <= 8d+72) 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.35e+43) {
tmp = x;
} else if (z <= -1.8e-15) {
tmp = y / z;
} else if (z <= 3e-140) {
tmp = -x / z;
} else if (z <= 8e+72) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.35e+43: tmp = x elif z <= -1.8e-15: tmp = y / z elif z <= 3e-140: tmp = -x / z elif z <= 8e+72: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.35e+43) tmp = x; elseif (z <= -1.8e-15) tmp = Float64(y / z); elseif (z <= 3e-140) tmp = Float64(Float64(-x) / z); elseif (z <= 8e+72) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.35e+43) tmp = x; elseif (z <= -1.8e-15) tmp = y / z; elseif (z <= 3e-140) tmp = -x / z; elseif (z <= 8e+72) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.35e+43], x, If[LessEqual[z, -1.8e-15], N[(y / z), $MachinePrecision], If[LessEqual[z, 3e-140], N[((-x) / z), $MachinePrecision], If[LessEqual[z, 8e+72], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{+43}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.8 \cdot 10^{-15}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 3 \cdot 10^{-140}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 8 \cdot 10^{+72}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.3500000000000001e43 or 7.99999999999999955e72 < 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 78.1%
if -1.3500000000000001e43 < z < -1.8000000000000001e-15 or 3.00000000000000018e-140 < z < 7.99999999999999955e72Initial 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 64.8%
if -1.8000000000000001e-15 < z < 3.00000000000000018e-140Initial program 100.0%
div-sub95.6%
sub-neg95.6%
distribute-frac-neg95.6%
+-commutative95.6%
associate-+r+95.6%
distribute-frac-neg95.6%
sub-neg95.6%
associate--r-95.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 66.2%
Taylor expanded in z around 0 66.2%
associate-*r/66.2%
neg-mul-166.2%
Simplified66.2%
Final simplification71.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.66e-15) (not (<= z 8.5e-144))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.66e-15) || !(z <= 8.5e-144)) {
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 <= (-1.66d-15)) .or. (.not. (z <= 8.5d-144))) 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 <= -1.66e-15) || !(z <= 8.5e-144)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.66e-15) or not (z <= 8.5e-144): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.66e-15) || !(z <= 8.5e-144)) 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 ((z <= -1.66e-15) || ~((z <= 8.5e-144))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.66e-15], N[Not[LessEqual[z, 8.5e-144]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.66 \cdot 10^{-15} \lor \neg \left(z \leq 8.5 \cdot 10^{-144}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < -1.65999999999999996e-15 or 8.49999999999999958e-144 < 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 92.0%
neg-mul-192.0%
distribute-neg-frac292.0%
Simplified92.0%
sub-neg92.0%
+-commutative92.0%
distribute-frac-neg292.0%
remove-double-neg92.0%
Applied egg-rr92.0%
if -1.65999999999999996e-15 < z < 8.49999999999999958e-144Initial program 100.0%
div-sub95.6%
sub-neg95.6%
distribute-frac-neg95.6%
+-commutative95.6%
associate-+r+95.6%
distribute-frac-neg95.6%
sub-neg95.6%
associate--r-95.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 66.2%
Taylor expanded in z around 0 66.2%
associate-*r/66.2%
neg-mul-166.2%
Simplified66.2%
Final simplification82.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -2e-59) (not (<= y 1.1e+140))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2e-59) || !(y <= 1.1e+140)) {
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 <= (-2d-59)) .or. (.not. (y <= 1.1d+140))) 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 <= -2e-59) || !(y <= 1.1e+140)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2e-59) or not (y <= 1.1e+140): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2e-59) || !(y <= 1.1e+140)) 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 <= -2e-59) || ~((y <= 1.1e+140))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2e-59], N[Not[LessEqual[y, 1.1e+140]], $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 -2 \cdot 10^{-59} \lor \neg \left(y \leq 1.1 \cdot 10^{+140}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.0000000000000001e-59 or 1.0999999999999999e140 < y Initial program 100.0%
div-sub97.0%
sub-neg97.0%
distribute-frac-neg97.0%
+-commutative97.0%
associate-+r+97.0%
distribute-frac-neg97.0%
sub-neg97.0%
associate--r-97.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 93.3%
neg-mul-193.3%
distribute-neg-frac293.3%
Simplified93.3%
sub-neg93.3%
+-commutative93.3%
distribute-frac-neg293.3%
remove-double-neg93.3%
Applied egg-rr93.3%
if -2.0000000000000001e-59 < y < 1.0999999999999999e140Initial program 100.0%
div-sub99.3%
sub-neg99.3%
distribute-frac-neg99.3%
+-commutative99.3%
associate-+r+99.3%
distribute-frac-neg99.3%
sub-neg99.3%
associate--r-99.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 87.2%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -4e+20) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4e+20) || !(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 <= (-4d+20)) .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 <= -4e+20) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4e+20) 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 <= -4e+20) || !(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 <= -4e+20) || ~((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, -4e+20], 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 -4 \cdot 10^{+20} \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -4e20 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 99.4%
neg-mul-199.4%
distribute-neg-frac299.4%
Simplified99.4%
sub-neg99.4%
+-commutative99.4%
distribute-frac-neg299.4%
remove-double-neg99.4%
Applied egg-rr99.4%
if -4e20 < z < 1Initial program 100.0%
div-sub96.8%
sub-neg96.8%
distribute-frac-neg96.8%
+-commutative96.8%
associate-+r+96.8%
distribute-frac-neg96.8%
sub-neg96.8%
associate--r-96.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 97.9%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (<= z -2.75e+45) x (if (<= z 1.56e+69) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.75e+45) {
tmp = x;
} else if (z <= 1.56e+69) {
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.75d+45)) then
tmp = x
else if (z <= 1.56d+69) 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.75e+45) {
tmp = x;
} else if (z <= 1.56e+69) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.75e+45: tmp = x elif z <= 1.56e+69: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.75e+45) tmp = x; elseif (z <= 1.56e+69) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.75e+45) tmp = x; elseif (z <= 1.56e+69) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.75e+45], x, If[LessEqual[z, 1.56e+69], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.75 \cdot 10^{+45}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.56 \cdot 10^{+69}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.75e45 or 1.56000000000000007e69 < 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 78.1%
if -2.75e45 < z < 1.56000000000000007e69Initial program 100.0%
div-sub97.1%
sub-neg97.1%
distribute-frac-neg97.1%
+-commutative97.1%
associate-+r+97.1%
distribute-frac-neg97.1%
sub-neg97.1%
associate--r-97.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 47.5%
Final simplification61.6%
(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.4%
sub-neg98.4%
distribute-frac-neg98.4%
+-commutative98.4%
associate-+r+98.4%
distribute-frac-neg98.4%
sub-neg98.4%
associate--r-98.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 39.0%
Final simplification39.0%
herbie shell --seed 2024071
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))