
(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 (if (or (<= z -1.0) (not (<= z 6.5e-7))) (- x (/ (- y) z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 6.5e-7)) {
tmp = x - (-y / 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 <= (-1.0d0)) .or. (.not. (z <= 6.5d-7))) then
tmp = x - (-y / 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 <= -1.0) || !(z <= 6.5e-7)) {
tmp = x - (-y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 6.5e-7): tmp = x - (-y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 6.5e-7)) tmp = Float64(x - Float64(Float64(-y) / z)); 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 <= 6.5e-7))) tmp = x - (-y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 6.5e-7]], $MachinePrecision]], N[(x - N[((-y) / z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 6.5 \cdot 10^{-7}\right):\\
\;\;\;\;x - \frac{-y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 6.50000000000000024e-7 < z Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift--.f64N/A
div-subN/A
associate-+l-N/A
lower--.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
associate--l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
distribute-lft-out--N/A
*-commutativeN/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sign-sub-invN/A
distribute-lft-inN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites88.4%
Taylor expanded in x around 0
Applied rewrites96.2%
if -1 < z < 6.50000000000000024e-7Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6499.1
Applied rewrites99.1%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.65e+150) (not (<= z 2e-14))) (- x (/ x z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.65e+150) || !(z <= 2e-14)) {
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.65d+150)) .or. (.not. (z <= 2d-14))) 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.65e+150) || !(z <= 2e-14)) {
tmp = x - (x / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.65e+150) or not (z <= 2e-14): tmp = x - (x / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.65e+150) || !(z <= 2e-14)) 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.65e+150) || ~((z <= 2e-14))) tmp = x - (x / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.65e+150], N[Not[LessEqual[z, 2e-14]], $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.65 \cdot 10^{+150} \lor \neg \left(z \leq 2 \cdot 10^{-14}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -2.65000000000000007e150 or 2e-14 < z 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-/.f6476.7
Applied rewrites76.7%
if -2.65000000000000007e150 < z < 2e-14Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6490.8
Applied rewrites90.8%
Final simplification84.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.2e+126) (not (<= y 5e+149))) (/ y z) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.2e+126) || !(y <= 5e+149)) {
tmp = y / z;
} else {
tmp = x - (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 <= (-2.2d+126)) .or. (.not. (y <= 5d+149))) then
tmp = y / z
else
tmp = x - (x / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.2e+126) || !(y <= 5e+149)) {
tmp = y / z;
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.2e+126) or not (y <= 5e+149): tmp = y / z else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.2e+126) || !(y <= 5e+149)) tmp = Float64(y / z); else tmp = Float64(x - Float64(x / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.2e+126) || ~((y <= 5e+149))) tmp = y / z; else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.2e+126], N[Not[LessEqual[y, 5e+149]], $MachinePrecision]], N[(y / z), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{+126} \lor \neg \left(y \leq 5 \cdot 10^{+149}\right):\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.19999999999999999e126 or 4.9999999999999999e149 < y Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6483.7
Applied rewrites83.7%
if -2.19999999999999999e126 < y < 4.9999999999999999e149Initial 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-/.f6477.2
Applied rewrites77.2%
Final simplification79.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.8e-58) (not (<= y 3e-108))) (/ y z) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e-58) || !(y <= 3e-108)) {
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 <= (-3.8d-58)) .or. (.not. (y <= 3d-108))) 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 <= -3.8e-58) || !(y <= 3e-108)) {
tmp = y / z;
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.8e-58) or not (y <= 3e-108): tmp = y / z else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.8e-58) || !(y <= 3e-108)) 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 <= -3.8e-58) || ~((y <= 3e-108))) tmp = y / z; else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.8e-58], N[Not[LessEqual[y, 3e-108]], $MachinePrecision]], N[(y / z), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-58} \lor \neg \left(y \leq 3 \cdot 10^{-108}\right):\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if y < -3.7999999999999997e-58 or 2.99999999999999993e-108 < y Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6460.9
Applied rewrites60.9%
if -3.7999999999999997e-58 < y < 2.99999999999999993e-108Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6454.2
Applied rewrites54.2%
Taylor expanded in x around inf
Applied rewrites47.4%
Final simplification56.6%
(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-/.f6444.1
Applied rewrites44.1%
Final simplification44.1%
herbie shell --seed 2024339
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))