
(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 -2e+25)
x
(if (<= z -5e-62)
(/ y z)
(if (<= z -4.2e-190)
t_0
(if (<= z -3.4e-246)
(/ y z)
(if (<= z 8.8e-222)
t_0
(if (<= z 4.5e-89) (/ y z) (if (<= z 1.0) t_0 x)))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -2e+25) {
tmp = x;
} else if (z <= -5e-62) {
tmp = y / z;
} else if (z <= -4.2e-190) {
tmp = t_0;
} else if (z <= -3.4e-246) {
tmp = y / z;
} else if (z <= 8.8e-222) {
tmp = t_0;
} else if (z <= 4.5e-89) {
tmp = y / z;
} else if (z <= 1.0) {
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 <= (-2d+25)) then
tmp = x
else if (z <= (-5d-62)) then
tmp = y / z
else if (z <= (-4.2d-190)) then
tmp = t_0
else if (z <= (-3.4d-246)) then
tmp = y / z
else if (z <= 8.8d-222) then
tmp = t_0
else if (z <= 4.5d-89) then
tmp = y / z
else if (z <= 1.0d0) 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 <= -2e+25) {
tmp = x;
} else if (z <= -5e-62) {
tmp = y / z;
} else if (z <= -4.2e-190) {
tmp = t_0;
} else if (z <= -3.4e-246) {
tmp = y / z;
} else if (z <= 8.8e-222) {
tmp = t_0;
} else if (z <= 4.5e-89) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -2e+25: tmp = x elif z <= -5e-62: tmp = y / z elif z <= -4.2e-190: tmp = t_0 elif z <= -3.4e-246: tmp = y / z elif z <= 8.8e-222: tmp = t_0 elif z <= 4.5e-89: tmp = y / z elif z <= 1.0: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -2e+25) tmp = x; elseif (z <= -5e-62) tmp = Float64(y / z); elseif (z <= -4.2e-190) tmp = t_0; elseif (z <= -3.4e-246) tmp = Float64(y / z); elseif (z <= 8.8e-222) tmp = t_0; elseif (z <= 4.5e-89) tmp = Float64(y / z); elseif (z <= 1.0) 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 <= -2e+25) tmp = x; elseif (z <= -5e-62) tmp = y / z; elseif (z <= -4.2e-190) tmp = t_0; elseif (z <= -3.4e-246) tmp = y / z; elseif (z <= 8.8e-222) tmp = t_0; elseif (z <= 4.5e-89) tmp = y / z; elseif (z <= 1.0) 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, -2e+25], x, If[LessEqual[z, -5e-62], N[(y / z), $MachinePrecision], If[LessEqual[z, -4.2e-190], t$95$0, If[LessEqual[z, -3.4e-246], N[(y / z), $MachinePrecision], If[LessEqual[z, 8.8e-222], t$95$0, If[LessEqual[z, 4.5e-89], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], t$95$0, x]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -2 \cdot 10^{+25}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -5 \cdot 10^{-62}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -4.2 \cdot 10^{-190}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -3.4 \cdot 10^{-246}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 8.8 \cdot 10^{-222}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{-89}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.00000000000000018e25 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 74.2%
if -2.00000000000000018e25 < z < -5.0000000000000002e-62 or -4.19999999999999983e-190 < z < -3.4000000000000001e-246 or 8.8000000000000001e-222 < z < 4.4999999999999999e-89Initial program 100.0%
+-commutative100.0%
div-sub96.0%
associate-+l-96.0%
Applied egg-rr96.0%
Taylor expanded in y around inf 63.2%
if -5.0000000000000002e-62 < z < -4.19999999999999983e-190 or -3.4000000000000001e-246 < z < 8.8000000000000001e-222 or 4.4999999999999999e-89 < z < 1Initial program 99.9%
Taylor expanded in x around inf 68.7%
Taylor expanded in z around 0 68.5%
mul-1-neg68.5%
distribute-frac-neg68.5%
Simplified68.5%
Final simplification70.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (/ y z))) (t_1 (/ (- x) z)))
(if (<= z -3.5e-61)
t_0
(if (<= z -4.8e-188)
t_1
(if (<= z -2.2e-245)
(/ y z)
(if (<= z 7.6e-227)
t_1
(if (<= z 7e-89) (/ y z) (if (<= z 4.7e-36) t_1 t_0))))))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double t_1 = -x / z;
double tmp;
if (z <= -3.5e-61) {
tmp = t_0;
} else if (z <= -4.8e-188) {
tmp = t_1;
} else if (z <= -2.2e-245) {
tmp = y / z;
} else if (z <= 7.6e-227) {
tmp = t_1;
} else if (z <= 7e-89) {
tmp = y / z;
} else if (z <= 4.7e-36) {
tmp = t_1;
} else {
tmp = t_0;
}
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) :: t_1
real(8) :: tmp
t_0 = x + (y / z)
t_1 = -x / z
if (z <= (-3.5d-61)) then
tmp = t_0
else if (z <= (-4.8d-188)) then
tmp = t_1
else if (z <= (-2.2d-245)) then
tmp = y / z
else if (z <= 7.6d-227) then
tmp = t_1
else if (z <= 7d-89) then
tmp = y / z
else if (z <= 4.7d-36) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (y / z);
double t_1 = -x / z;
double tmp;
if (z <= -3.5e-61) {
tmp = t_0;
} else if (z <= -4.8e-188) {
tmp = t_1;
} else if (z <= -2.2e-245) {
tmp = y / z;
} else if (z <= 7.6e-227) {
tmp = t_1;
} else if (z <= 7e-89) {
tmp = y / z;
} else if (z <= 4.7e-36) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) t_1 = -x / z tmp = 0 if z <= -3.5e-61: tmp = t_0 elif z <= -4.8e-188: tmp = t_1 elif z <= -2.2e-245: tmp = y / z elif z <= 7.6e-227: tmp = t_1 elif z <= 7e-89: tmp = y / z elif z <= 4.7e-36: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) t_1 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -3.5e-61) tmp = t_0; elseif (z <= -4.8e-188) tmp = t_1; elseif (z <= -2.2e-245) tmp = Float64(y / z); elseif (z <= 7.6e-227) tmp = t_1; elseif (z <= 7e-89) tmp = Float64(y / z); elseif (z <= 4.7e-36) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y / z); t_1 = -x / z; tmp = 0.0; if (z <= -3.5e-61) tmp = t_0; elseif (z <= -4.8e-188) tmp = t_1; elseif (z <= -2.2e-245) tmp = y / z; elseif (z <= 7.6e-227) tmp = t_1; elseif (z <= 7e-89) tmp = y / z; elseif (z <= 4.7e-36) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -3.5e-61], t$95$0, If[LessEqual[z, -4.8e-188], t$95$1, If[LessEqual[z, -2.2e-245], N[(y / z), $MachinePrecision], If[LessEqual[z, 7.6e-227], t$95$1, If[LessEqual[z, 7e-89], N[(y / z), $MachinePrecision], If[LessEqual[z, 4.7e-36], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
t_1 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -3.5 \cdot 10^{-61}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.8 \cdot 10^{-188}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq -2.2 \cdot 10^{-245}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 7.6 \cdot 10^{-227}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z \leq 7 \cdot 10^{-89}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 4.7 \cdot 10^{-36}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -3.5000000000000003e-61 or 4.7000000000000003e-36 < z Initial program 100.0%
Taylor expanded in y around inf 93.5%
if -3.5000000000000003e-61 < z < -4.8e-188 or -2.19999999999999993e-245 < z < 7.60000000000000019e-227 or 6.9999999999999994e-89 < z < 4.7000000000000003e-36Initial program 100.0%
Taylor expanded in x around inf 70.9%
Taylor expanded in z around 0 71.1%
mul-1-neg71.1%
distribute-frac-neg71.1%
Simplified71.1%
if -4.8e-188 < z < -2.19999999999999993e-245 or 7.60000000000000019e-227 < z < 6.9999999999999994e-89Initial program 100.0%
+-commutative100.0%
div-sub93.7%
associate-+l-93.7%
Applied egg-rr93.7%
Taylor expanded in y around inf 66.9%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.2e-63) (not (<= y 4.6e-13))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e-63) || !(y <= 4.6e-13)) {
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 <= (-9.2d-63)) .or. (.not. (y <= 4.6d-13))) 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 <= -9.2e-63) || !(y <= 4.6e-13)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.2e-63) or not (y <= 4.6e-13): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.2e-63) || !(y <= 4.6e-13)) 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 <= -9.2e-63) || ~((y <= 4.6e-13))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.2e-63], N[Not[LessEqual[y, 4.6e-13]], $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 -9.2 \cdot 10^{-63} \lor \neg \left(y \leq 4.6 \cdot 10^{-13}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -9.2e-63 or 4.59999999999999958e-13 < y Initial program 100.0%
Taylor expanded in y around inf 89.1%
if -9.2e-63 < y < 4.59999999999999958e-13Initial program 100.0%
Taylor expanded in y around 0 89.4%
Final simplification89.3%
(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%
Taylor expanded in y around inf 98.1%
if -1 < z < 1Initial program 100.0%
+-commutative100.0%
div-sub95.6%
associate-+l-95.6%
Applied egg-rr95.6%
Taylor expanded in z around 0 98.8%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (<= z -3.8e+23) x (if (<= z 3e+44) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.8e+23) {
tmp = x;
} else if (z <= 3e+44) {
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 <= (-3.8d+23)) then
tmp = x
else if (z <= 3d+44) 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 <= -3.8e+23) {
tmp = x;
} else if (z <= 3e+44) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.8e+23: tmp = x elif z <= 3e+44: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.8e+23) tmp = x; elseif (z <= 3e+44) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.8e+23) tmp = x; elseif (z <= 3e+44) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.8e+23], x, If[LessEqual[z, 3e+44], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{+23}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3 \cdot 10^{+44}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.79999999999999975e23 or 2.99999999999999987e44 < z Initial program 100.0%
Taylor expanded in z around inf 77.4%
if -3.79999999999999975e23 < z < 2.99999999999999987e44Initial program 100.0%
+-commutative100.0%
div-sub96.2%
associate-+l-96.2%
Applied egg-rr96.2%
Taylor expanded in y around inf 48.5%
Final simplification62.3%
(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%
Taylor expanded in z around inf 41.0%
Final simplification41.0%
herbie shell --seed 2023196
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))