
(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 (if (or (<= z -1.0) (not (<= z 1.0))) (+ (/ y z) x) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = (y / z) + x;
} 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 = (y / z) + x
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 = (y / z) + x;
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = (y / z) + x else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) tmp = Float64(Float64(y / z) + x); 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 = (y / z) + x; 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[(N[(y / z), $MachinePrecision] + x), $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):\\
\;\;\;\;\frac{y}{z} + x\\
\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
lower-/.f6499.8
Applied rewrites99.8%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6498.0
Applied rewrites98.0%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.8e-10) (not (<= z 1.95e+30))) (- x (/ x z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-10) || !(z <= 1.95e+30)) {
tmp = x - (x / 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 <= (-2.8d-10)) .or. (.not. (z <= 1.95d+30))) then
tmp = x - (x / 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 <= -2.8e-10) || !(z <= 1.95e+30)) {
tmp = x - (x / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.8e-10) or not (z <= 1.95e+30): tmp = x - (x / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.8e-10) || !(z <= 1.95e+30)) tmp = Float64(x - Float64(x / z)); else tmp = Float64(Float64(y - x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.8e-10) || ~((z <= 1.95e+30))) tmp = x - (x / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.8e-10], N[Not[LessEqual[z, 1.95e+30]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-10} \lor \neg \left(z \leq 1.95 \cdot 10^{+30}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -2.80000000000000015e-10 or 1.95000000000000005e30 < z Initial program 100.0%
Taylor expanded in y around 0
lower--.f64N/A
lower-/.f6476.9
Applied rewrites76.9%
if -2.80000000000000015e-10 < z < 1.95000000000000005e30Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6498.7
Applied rewrites98.7%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.5e-39) (not (<= x 5.2e-125))) (- x (/ x z)) (/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.5e-39) || !(x <= 5.2e-125)) {
tmp = x - (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 ((x <= (-2.5d-39)) .or. (.not. (x <= 5.2d-125))) then
tmp = x - (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 ((x <= -2.5e-39) || !(x <= 5.2e-125)) {
tmp = x - (x / z);
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.5e-39) or not (x <= 5.2e-125): tmp = x - (x / z) else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.5e-39) || !(x <= 5.2e-125)) tmp = Float64(x - Float64(x / z)); else tmp = Float64(y / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.5e-39) || ~((x <= 5.2e-125))) tmp = x - (x / z); else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.5e-39], N[Not[LessEqual[x, 5.2e-125]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-39} \lor \neg \left(x \leq 5.2 \cdot 10^{-125}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -2.4999999999999999e-39 or 5.20000000000000011e-125 < x Initial program 100.0%
Taylor expanded in y around 0
lower--.f64N/A
lower-/.f6483.3
Applied rewrites83.3%
if -2.4999999999999999e-39 < x < 5.20000000000000011e-125Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6473.4
Applied rewrites73.4%
Final simplification79.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.7e-63) (not (<= y 1.55e+75))) (/ y z) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.7e-63) || !(y <= 1.55e+75)) {
tmp = 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 ((y <= (-4.7d-63)) .or. (.not. (y <= 1.55d+75))) then
tmp = 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 ((y <= -4.7e-63) || !(y <= 1.55e+75)) {
tmp = y / z;
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.7e-63) or not (y <= 1.55e+75): tmp = y / z else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.7e-63) || !(y <= 1.55e+75)) tmp = Float64(y / z); else tmp = Float64(Float64(-x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.7e-63) || ~((y <= 1.55e+75))) tmp = y / z; else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.7e-63], N[Not[LessEqual[y, 1.55e+75]], $MachinePrecision]], N[(y / z), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.7 \cdot 10^{-63} \lor \neg \left(y \leq 1.55 \cdot 10^{+75}\right):\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if y < -4.7000000000000001e-63 or 1.5500000000000001e75 < y Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6464.8
Applied rewrites64.8%
if -4.7000000000000001e-63 < y < 1.5500000000000001e75Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6452.0
Applied rewrites52.0%
Taylor expanded in y around 0
Applied rewrites40.9%
Final simplification52.8%
(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-/.f6439.3
Applied rewrites39.3%
herbie shell --seed 2024271
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))