
(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 (if (<= (+ x (/ (- y x) z)) 2e+305) (+ x (/ y z)) (- (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x + ((y - x) / z)) <= 2e+305) {
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 ((x + ((y - x) / z)) <= 2d+305) 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 ((x + ((y - x) / z)) <= 2e+305) {
tmp = x + (y / z);
} else {
tmp = -(x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + ((y - x) / z)) <= 2e+305: tmp = x + (y / z) else: tmp = -(x / z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + Float64(Float64(y - x) / z)) <= 2e+305) 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 ((x + ((y - x) / z)) <= 2e+305) tmp = x + (y / z); else tmp = -(x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], 2e+305], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], (-N[(x / z), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + \frac{y - x}{z} \leq 2 \cdot 10^{+305}:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;-\frac{x}{z}\\
\end{array}
\end{array}
if (+.f64 x (/.f64 (-.f64 y x) z)) < 1.9999999999999999e305Initial program 100.0%
Taylor expanded in y around inf
/-lowering-/.f6484.2
Simplified84.2%
if 1.9999999999999999e305 < (+.f64 x (/.f64 (-.f64 y x) z)) Initial program 100.0%
Taylor expanded in z around 0
/-lowering-/.f64N/A
--lowering--.f64100.0
Simplified100.0%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6473.7
Simplified73.7%
Final simplification82.7%
(FPCore (x y z)
:precision binary64
(if (<= z -1.5e+57)
x
(if (<= z -9.3e-42)
(/ y z)
(if (<= z -1.9e-205) (- (/ x z)) (if (<= z 1.9e+19) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.5e+57) {
tmp = x;
} else if (z <= -9.3e-42) {
tmp = y / z;
} else if (z <= -1.9e-205) {
tmp = -(x / z);
} else if (z <= 1.9e+19) {
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.5d+57)) then
tmp = x
else if (z <= (-9.3d-42)) then
tmp = y / z
else if (z <= (-1.9d-205)) then
tmp = -(x / z)
else if (z <= 1.9d+19) 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.5e+57) {
tmp = x;
} else if (z <= -9.3e-42) {
tmp = y / z;
} else if (z <= -1.9e-205) {
tmp = -(x / z);
} else if (z <= 1.9e+19) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.5e+57: tmp = x elif z <= -9.3e-42: tmp = y / z elif z <= -1.9e-205: tmp = -(x / z) elif z <= 1.9e+19: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.5e+57) tmp = x; elseif (z <= -9.3e-42) tmp = Float64(y / z); elseif (z <= -1.9e-205) tmp = Float64(-Float64(x / z)); elseif (z <= 1.9e+19) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.5e+57) tmp = x; elseif (z <= -9.3e-42) tmp = y / z; elseif (z <= -1.9e-205) tmp = -(x / z); elseif (z <= 1.9e+19) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.5e+57], x, If[LessEqual[z, -9.3e-42], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.9e-205], (-N[(x / z), $MachinePrecision]), If[LessEqual[z, 1.9e+19], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+57}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -9.3 \cdot 10^{-42}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.9 \cdot 10^{-205}:\\
\;\;\;\;-\frac{x}{z}\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{+19}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.5e57 or 1.9e19 < z Initial program 100.0%
Taylor expanded in z around inf
Simplified81.6%
if -1.5e57 < z < -9.2999999999999995e-42 or -1.89999999999999996e-205 < z < 1.9e19Initial program 100.0%
Taylor expanded in x around 0
/-lowering-/.f6468.3
Simplified68.3%
if -9.2999999999999995e-42 < z < -1.89999999999999996e-205Initial program 100.0%
Taylor expanded in z around 0
/-lowering-/.f64N/A
--lowering--.f64100.0
Simplified100.0%
Taylor expanded in y around 0
mul-1-negN/A
neg-lowering-neg.f6464.5
Simplified64.5%
Final simplification73.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (/ y z)))) (if (<= z -7.5e+17) t_0 (if (<= z 5.8e-13) (/ (- y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double tmp;
if (z <= -7.5e+17) {
tmp = t_0;
} else if (z <= 5.8e-13) {
tmp = (y - x) / z;
} 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) :: tmp
t_0 = x + (y / z)
if (z <= (-7.5d+17)) then
tmp = t_0
else if (z <= 5.8d-13) then
tmp = (y - x) / z
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 tmp;
if (z <= -7.5e+17) {
tmp = t_0;
} else if (z <= 5.8e-13) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) tmp = 0 if z <= -7.5e+17: tmp = t_0 elif z <= 5.8e-13: tmp = (y - x) / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) tmp = 0.0 if (z <= -7.5e+17) tmp = t_0; elseif (z <= 5.8e-13) tmp = Float64(Float64(y - x) / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y / z); tmp = 0.0; if (z <= -7.5e+17) tmp = t_0; elseif (z <= 5.8e-13) tmp = (y - x) / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.5e+17], t$95$0, If[LessEqual[z, 5.8e-13], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
\mathbf{if}\;z \leq -7.5 \cdot 10^{+17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 5.8 \cdot 10^{-13}:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -7.5e17 or 5.7999999999999995e-13 < z Initial program 100.0%
Taylor expanded in y around inf
/-lowering-/.f6499.8
Simplified99.8%
if -7.5e17 < z < 5.7999999999999995e-13Initial program 100.0%
Taylor expanded in z around 0
/-lowering-/.f64N/A
--lowering--.f64100.0
Simplified100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (/ y z)))) (if (<= y -1.36e-71) t_0 (if (<= y 1e-51) (- x (/ x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double tmp;
if (y <= -1.36e-71) {
tmp = t_0;
} else if (y <= 1e-51) {
tmp = x - (x / z);
} 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) :: tmp
t_0 = x + (y / z)
if (y <= (-1.36d-71)) then
tmp = t_0
else if (y <= 1d-51) then
tmp = x - (x / z)
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 tmp;
if (y <= -1.36e-71) {
tmp = t_0;
} else if (y <= 1e-51) {
tmp = x - (x / z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) tmp = 0 if y <= -1.36e-71: tmp = t_0 elif y <= 1e-51: tmp = x - (x / z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) tmp = 0.0 if (y <= -1.36e-71) tmp = t_0; elseif (y <= 1e-51) tmp = Float64(x - Float64(x / z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y / z); tmp = 0.0; if (y <= -1.36e-71) tmp = t_0; elseif (y <= 1e-51) tmp = x - (x / z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.36e-71], t$95$0, If[LessEqual[y, 1e-51], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
\mathbf{if}\;y \leq -1.36 \cdot 10^{-71}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 10^{-51}:\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.3599999999999999e-71 or 1e-51 < y Initial program 100.0%
Taylor expanded in y around inf
/-lowering-/.f6491.5
Simplified91.5%
if -1.3599999999999999e-71 < y < 1e-51Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
--lowering--.f64N/A
/-lowering-/.f6492.0
Simplified92.0%
(FPCore (x y z) :precision binary64 (if (<= z -5.5e+57) x (if (<= z 1.05e+20) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e+57) {
tmp = x;
} else if (z <= 1.05e+20) {
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 <= (-5.5d+57)) then
tmp = x
else if (z <= 1.05d+20) 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 <= -5.5e+57) {
tmp = x;
} else if (z <= 1.05e+20) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.5e+57: tmp = x elif z <= 1.05e+20: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.5e+57) tmp = x; elseif (z <= 1.05e+20) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.5e+57) tmp = x; elseif (z <= 1.05e+20) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.5e+57], x, If[LessEqual[z, 1.05e+20], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{+57}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.05 \cdot 10^{+20}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.5000000000000002e57 or 1.05e20 < z Initial program 100.0%
Taylor expanded in z around inf
Simplified81.6%
if -5.5000000000000002e57 < z < 1.05e20Initial program 100.0%
Taylor expanded in x around 0
/-lowering-/.f6460.5
Simplified60.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%
Taylor expanded in z around inf
Simplified40.1%
herbie shell --seed 2024198
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))