
(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 -66000000000000.0) t_0 (if (<= z 1.25e-24) (/ (- y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = (y / z) + x;
double tmp;
if (z <= -66000000000000.0) {
tmp = t_0;
} else if (z <= 1.25e-24) {
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 <= (-66000000000000.0d0)) then
tmp = t_0
else if (z <= 1.25d-24) 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 <= -66000000000000.0) {
tmp = t_0;
} else if (z <= 1.25e-24) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y / z) + x tmp = 0 if z <= -66000000000000.0: tmp = t_0 elif z <= 1.25e-24: 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 <= -66000000000000.0) tmp = t_0; elseif (z <= 1.25e-24) 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 <= -66000000000000.0) tmp = t_0; elseif (z <= 1.25e-24) 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, -66000000000000.0], t$95$0, If[LessEqual[z, 1.25e-24], 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 -66000000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.25 \cdot 10^{-24}:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -6.6e13 or 1.24999999999999995e-24 < z Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6499.9
Applied rewrites99.9%
if -6.6e13 < z < 1.24999999999999995e-24Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6499.4
Applied rewrites99.4%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (/ x z)))) (if (<= z -1e+32) t_0 (if (<= z 235.0) (/ (- y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (z <= -1e+32) {
tmp = t_0;
} else if (z <= 235.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 = x - (x / z)
if (z <= (-1d+32)) then
tmp = t_0
else if (z <= 235.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 = x - (x / z);
double tmp;
if (z <= -1e+32) {
tmp = t_0;
} else if (z <= 235.0) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x / z) tmp = 0 if z <= -1e+32: tmp = t_0 elif z <= 235.0: 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 <= -1e+32) tmp = t_0; elseif (z <= 235.0) 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 <= -1e+32) tmp = t_0; elseif (z <= 235.0) 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, -1e+32], t$95$0, If[LessEqual[z, 235.0], 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 -1 \cdot 10^{+32}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 235:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.00000000000000005e32 or 235 < z Initial program 100.0%
Taylor expanded in y around 0
lower--.f64N/A
lower-/.f6470.8
Applied rewrites70.8%
if -1.00000000000000005e32 < z < 235Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6498.6
Applied rewrites98.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (/ x z)))) (if (<= x -12.6) t_0 (if (<= x 9.2e-42) (/ y z) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (x <= -12.6) {
tmp = t_0;
} else if (x <= 9.2e-42) {
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 <= (-12.6d0)) then
tmp = t_0
else if (x <= 9.2d-42) 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 <= -12.6) {
tmp = t_0;
} else if (x <= 9.2e-42) {
tmp = y / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x / z) tmp = 0 if x <= -12.6: tmp = t_0 elif x <= 9.2e-42: 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 <= -12.6) tmp = t_0; elseif (x <= 9.2e-42) 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 <= -12.6) tmp = t_0; elseif (x <= 9.2e-42) 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, -12.6], t$95$0, If[LessEqual[x, 9.2e-42], N[(y / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{x}{z}\\
\mathbf{if}\;x \leq -12.6:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 9.2 \cdot 10^{-42}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -12.5999999999999996 or 9.20000000000000015e-42 < x Initial program 100.0%
Taylor expanded in y around 0
lower--.f64N/A
lower-/.f6487.5
Applied rewrites87.5%
if -12.5999999999999996 < x < 9.20000000000000015e-42Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6471.9
Applied rewrites71.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ (- x) z))) (if (<= x -8.5e+140) t_0 (if (<= x 1.22e-6) (/ y z) t_0))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (x <= -8.5e+140) {
tmp = t_0;
} else if (x <= 1.22e-6) {
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 <= (-8.5d+140)) then
tmp = t_0
else if (x <= 1.22d-6) 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 <= -8.5e+140) {
tmp = t_0;
} else if (x <= 1.22e-6) {
tmp = y / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if x <= -8.5e+140: tmp = t_0 elif x <= 1.22e-6: 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 <= -8.5e+140) tmp = t_0; elseif (x <= 1.22e-6) 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 <= -8.5e+140) tmp = t_0; elseif (x <= 1.22e-6) 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, -8.5e+140], t$95$0, If[LessEqual[x, 1.22e-6], N[(y / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;x \leq -8.5 \cdot 10^{+140}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.22 \cdot 10^{-6}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -8.4999999999999996e140 or 1.21999999999999997e-6 < x Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6458.3
Applied rewrites58.3%
Taylor expanded in y around 0
Applied rewrites48.4%
if -8.4999999999999996e140 < x < 1.21999999999999997e-6Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6462.2
Applied rewrites62.2%
(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-/.f6444.4
Applied rewrites44.4%
herbie shell --seed 2024277
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))