
(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 6 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 (/ y z)))) (if (<= z -1.0) t_0 (if (<= z 5e-9) (/ (- y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 5e-9) {
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 <= (-1.0d0)) then
tmp = t_0
else if (z <= 5d-9) 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 <= -1.0) {
tmp = t_0;
} else if (z <= 5e-9) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 5e-9: 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 <= -1.0) tmp = t_0; elseif (z <= 5e-9) 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 <= -1.0) tmp = t_0; elseif (z <= 5e-9) 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, -1.0], t$95$0, If[LessEqual[z, 5e-9], 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 -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 5 \cdot 10^{-9}:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 5.0000000000000001e-9 < z Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6498.8
Simplified98.8%
if -1 < z < 5.0000000000000001e-9Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6498.6
Simplified98.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (/ x z)))) (if (<= x -1.45e+44) t_0 (if (<= x 2.5e+108) (+ x (/ y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (x <= -1.45e+44) {
tmp = t_0;
} else if (x <= 2.5e+108) {
tmp = x + (y / 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 - (x / z)
if (x <= (-1.45d+44)) then
tmp = t_0
else if (x <= 2.5d+108) then
tmp = x + (y / 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 - (x / z);
double tmp;
if (x <= -1.45e+44) {
tmp = t_0;
} else if (x <= 2.5e+108) {
tmp = x + (y / z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x / z) tmp = 0 if x <= -1.45e+44: tmp = t_0 elif x <= 2.5e+108: tmp = x + (y / z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x - Float64(x / z)) tmp = 0.0 if (x <= -1.45e+44) tmp = t_0; elseif (x <= 2.5e+108) tmp = Float64(x + Float64(y / z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x - (x / z); tmp = 0.0; if (x <= -1.45e+44) tmp = t_0; elseif (x <= 2.5e+108) tmp = x + (y / z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.45e+44], t$95$0, If[LessEqual[x, 2.5e+108], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{x}{z}\\
\mathbf{if}\;x \leq -1.45 \cdot 10^{+44}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{+108}:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.4500000000000001e44 or 2.49999999999999995e108 < x Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6490.4
Simplified90.4%
if -1.4500000000000001e44 < x < 2.49999999999999995e108Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6488.9
Simplified88.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (/ y z)))) (if (<= z -2.8e-36) t_0 (if (<= z -2.6e-255) (- (/ x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double tmp;
if (z <= -2.8e-36) {
tmp = t_0;
} else if (z <= -2.6e-255) {
tmp = -(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 <= (-2.8d-36)) then
tmp = t_0
else if (z <= (-2.6d-255)) then
tmp = -(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 <= -2.8e-36) {
tmp = t_0;
} else if (z <= -2.6e-255) {
tmp = -(x / z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) tmp = 0 if z <= -2.8e-36: tmp = t_0 elif z <= -2.6e-255: tmp = -(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 <= -2.8e-36) tmp = t_0; elseif (z <= -2.6e-255) tmp = Float64(-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 (z <= -2.8e-36) tmp = t_0; elseif (z <= -2.6e-255) tmp = -(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, -2.8e-36], t$95$0, If[LessEqual[z, -2.6e-255], (-N[(x / z), $MachinePrecision]), t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
\mathbf{if}\;z \leq -2.8 \cdot 10^{-36}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.6 \cdot 10^{-255}:\\
\;\;\;\;-\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.8000000000000001e-36 or -2.60000000000000021e-255 < z Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6484.5
Simplified84.5%
if -2.8000000000000001e-36 < z < -2.60000000000000021e-255Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6462.0
Simplified62.0%
Taylor expanded in z around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6462.0
Simplified62.0%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (/ x z)))) (if (<= x -1.56e+28) t_0 (if (<= x 5.2e+112) (/ y z) t_0))))
double code(double x, double y, double z) {
double t_0 = -(x / z);
double tmp;
if (x <= -1.56e+28) {
tmp = t_0;
} else if (x <= 5.2e+112) {
tmp = y / 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 / z)
if (x <= (-1.56d+28)) then
tmp = t_0
else if (x <= 5.2d+112) then
tmp = y / 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 / z);
double tmp;
if (x <= -1.56e+28) {
tmp = t_0;
} else if (x <= 5.2e+112) {
tmp = y / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(x / z) tmp = 0 if x <= -1.56e+28: tmp = t_0 elif x <= 5.2e+112: tmp = y / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(x / z)) tmp = 0.0 if (x <= -1.56e+28) tmp = t_0; elseif (x <= 5.2e+112) tmp = Float64(y / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -(x / z); tmp = 0.0; if (x <= -1.56e+28) tmp = t_0; elseif (x <= 5.2e+112) tmp = y / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(x / z), $MachinePrecision])}, If[LessEqual[x, -1.56e+28], t$95$0, If[LessEqual[x, 5.2e+112], N[(y / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\frac{x}{z}\\
\mathbf{if}\;x \leq -1.56 \cdot 10^{+28}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{+112}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.5599999999999999e28 or 5.2000000000000001e112 < x Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
associate-*r/N/A
*-rgt-identityN/A
lower--.f64N/A
lower-/.f6490.4
Simplified90.4%
Taylor expanded in z around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6444.3
Simplified44.3%
if -1.5599999999999999e28 < x < 5.2000000000000001e112Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6454.4
Simplified54.4%
Final simplification50.4%
(FPCore (x y z) :precision binary64 (/ y z))
double code(double x, double y, double z) {
return y / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y / z
end function
public static double code(double x, double y, double z) {
return y / z;
}
def code(x, y, z): return y / z
function code(x, y, z) return Float64(y / z) end
function tmp = code(x, y, z) tmp = y / z; end
code[x_, y_, z_] := N[(y / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{z}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6438.8
Simplified38.8%
herbie shell --seed 2024208
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))