
(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 (+ (/ (- y x) z) x))
double code(double x, double y, double z) {
return ((y - x) / z) + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = ((y - x) / z) + x
end function
public static double code(double x, double y, double z) {
return ((y - x) / z) + x;
}
def code(x, y, z): return ((y - x) / z) + x
function code(x, y, z) return Float64(Float64(Float64(y - x) / z) + x) end
function tmp = code(x, y, z) tmp = ((y - x) / z) + x; end
code[x_, y_, z_] := N[(N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\frac{y - x}{z} + x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ (/ y z) x))) (if (<= z -8200000000000.0) t_0 (if (<= z 1.0) (/ (- y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = (y / z) + x;
double tmp;
if (z <= -8200000000000.0) {
tmp = t_0;
} else if (z <= 1.0) {
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 = (y / z) + x
if (z <= (-8200000000000.0d0)) then
tmp = t_0
else if (z <= 1.0d0) 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 = (y / z) + x;
double tmp;
if (z <= -8200000000000.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y / z) + x tmp = 0 if z <= -8200000000000.0: tmp = t_0 elif z <= 1.0: tmp = (y - x) / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y / z) + x) tmp = 0.0 if (z <= -8200000000000.0) tmp = t_0; elseif (z <= 1.0) tmp = Float64(Float64(y - x) / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y / z) + x; tmp = 0.0; if (z <= -8200000000000.0) tmp = t_0; elseif (z <= 1.0) tmp = (y - x) / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y / z), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[z, -8200000000000.0], t$95$0, If[LessEqual[z, 1.0], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{z} + x\\
\mathbf{if}\;z \leq -8200000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -8.2e12 or 1 < z Initial program 100.0%
Taylor expanded in y around inf
lower-/.f64100.0
Applied rewrites100.0%
if -8.2e12 < z < 1Initial program 99.9%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6499.4
Applied rewrites99.4%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (/ x z)))) (if (<= z -4.4e+17) t_0 (if (<= z 1.1e+29) (/ (- y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (z <= -4.4e+17) {
tmp = t_0;
} else if (z <= 1.1e+29) {
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 - (x / z)
if (z <= (-4.4d+17)) then
tmp = t_0
else if (z <= 1.1d+29) 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 - (x / z);
double tmp;
if (z <= -4.4e+17) {
tmp = t_0;
} else if (z <= 1.1e+29) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x / z) tmp = 0 if z <= -4.4e+17: tmp = t_0 elif z <= 1.1e+29: tmp = (y - x) / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x - Float64(x / z)) tmp = 0.0 if (z <= -4.4e+17) tmp = t_0; elseif (z <= 1.1e+29) tmp = Float64(Float64(y - x) / 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 (z <= -4.4e+17) tmp = t_0; elseif (z <= 1.1e+29) tmp = (y - x) / 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[z, -4.4e+17], t$95$0, If[LessEqual[z, 1.1e+29], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{x}{z}\\
\mathbf{if}\;z \leq -4.4 \cdot 10^{+17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{+29}:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -4.4e17 or 1.1000000000000001e29 < z Initial program 100.0%
Taylor expanded in y around 0
lower--.f64N/A
lower-/.f6468.6
Applied rewrites68.6%
if -4.4e17 < z < 1.1000000000000001e29Initial program 99.9%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6498.7
Applied rewrites98.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (/ x z)))) (if (<= x -9.8e-130) t_0 (if (<= x 6e+28) (/ y z) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (x <= -9.8e-130) {
tmp = t_0;
} else if (x <= 6e+28) {
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 - (x / z)
if (x <= (-9.8d-130)) then
tmp = t_0
else if (x <= 6d+28) 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 - (x / z);
double tmp;
if (x <= -9.8e-130) {
tmp = t_0;
} else if (x <= 6e+28) {
tmp = y / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x / z) tmp = 0 if x <= -9.8e-130: tmp = t_0 elif x <= 6e+28: tmp = 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 <= -9.8e-130) tmp = t_0; elseif (x <= 6e+28) tmp = 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 <= -9.8e-130) tmp = t_0; elseif (x <= 6e+28) tmp = 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, -9.8e-130], t$95$0, If[LessEqual[x, 6e+28], N[(y / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{x}{z}\\
\mathbf{if}\;x \leq -9.8 \cdot 10^{-130}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 6 \cdot 10^{+28}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.80000000000000036e-130 or 6.0000000000000002e28 < x Initial program 100.0%
Taylor expanded in y around 0
lower--.f64N/A
lower-/.f6480.2
Applied rewrites80.2%
if -9.80000000000000036e-130 < x < 6.0000000000000002e28Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6473.6
Applied rewrites73.6%
(FPCore (x y z) :precision binary64 (if (<= y -3e-83) (/ y z) (if (<= y 1.02e-75) (/ (- x) z) (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3e-83) {
tmp = y / z;
} else if (y <= 1.02e-75) {
tmp = -x / z;
} else {
tmp = y / 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 <= (-3d-83)) then
tmp = y / z
else if (y <= 1.02d-75) then
tmp = -x / z
else
tmp = y / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3e-83) {
tmp = y / z;
} else if (y <= 1.02e-75) {
tmp = -x / z;
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3e-83: tmp = y / z elif y <= 1.02e-75: tmp = -x / z else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3e-83) tmp = Float64(y / z); elseif (y <= 1.02e-75) tmp = Float64(Float64(-x) / z); else tmp = Float64(y / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3e-83) tmp = y / z; elseif (y <= 1.02e-75) tmp = -x / z; else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3e-83], N[(y / z), $MachinePrecision], If[LessEqual[y, 1.02e-75], N[((-x) / z), $MachinePrecision], N[(y / z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{-83}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;y \leq 1.02 \cdot 10^{-75}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if y < -3.0000000000000001e-83 or 1.01999999999999997e-75 < y Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6463.6
Applied rewrites63.6%
if -3.0000000000000001e-83 < y < 1.01999999999999997e-75Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6463.5
Applied rewrites63.5%
Taylor expanded in y around 0
Applied rewrites51.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 y around inf
lower-/.f6446.1
Applied rewrites46.1%
herbie shell --seed 2024255
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))