
(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 5 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 -2.3e-9) (not (<= z 360000.0))) (- x (/ x z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.3e-9) || !(z <= 360000.0)) {
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.3d-9)) .or. (.not. (z <= 360000.0d0))) 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.3e-9) || !(z <= 360000.0)) {
tmp = x - (x / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.3e-9) or not (z <= 360000.0): tmp = x - (x / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.3e-9) || !(z <= 360000.0)) 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.3e-9) || ~((z <= 360000.0))) tmp = x - (x / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.3e-9], N[Not[LessEqual[z, 360000.0]], $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.3 \cdot 10^{-9} \lor \neg \left(z \leq 360000\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -2.2999999999999999e-9 or 3.6e5 < 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-/.f6469.6
Applied rewrites69.6%
if -2.2999999999999999e-9 < z < 3.6e5Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6499.8
Applied rewrites99.8%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1300000000000.0) (not (<= x 2.6e-94))) (- x (/ x z)) (/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1300000000000.0) || !(x <= 2.6e-94)) {
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 <= (-1300000000000.0d0)) .or. (.not. (x <= 2.6d-94))) 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 <= -1300000000000.0) || !(x <= 2.6e-94)) {
tmp = x - (x / z);
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1300000000000.0) or not (x <= 2.6e-94): tmp = x - (x / z) else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1300000000000.0) || !(x <= 2.6e-94)) 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 <= -1300000000000.0) || ~((x <= 2.6e-94))) tmp = x - (x / z); else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1300000000000.0], N[Not[LessEqual[x, 2.6e-94]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1300000000000 \lor \neg \left(x \leq 2.6 \cdot 10^{-94}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -1.3e12 or 2.59999999999999994e-94 < 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.0
Applied rewrites90.0%
if -1.3e12 < x < 2.59999999999999994e-94Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6466.5
Applied rewrites66.5%
Final simplification79.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e+49) (not (<= x 5.5e-75))) (/ (- x) z) (/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e+49) || !(x <= 5.5e-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 ((x <= (-9d+49)) .or. (.not. (x <= 5.5d-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 ((x <= -9e+49) || !(x <= 5.5e-75)) {
tmp = -x / z;
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e+49) or not (x <= 5.5e-75): tmp = -x / z else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e+49) || !(x <= 5.5e-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 ((x <= -9e+49) || ~((x <= 5.5e-75))) tmp = -x / z; else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e+49], N[Not[LessEqual[x, 5.5e-75]], $MachinePrecision]], N[((-x) / z), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{+49} \lor \neg \left(x \leq 5.5 \cdot 10^{-75}\right):\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -8.99999999999999965e49 or 5.50000000000000026e-75 < x Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6454.9
Applied rewrites54.9%
Taylor expanded in x around inf
Applied rewrites47.1%
if -8.99999999999999965e49 < x < 5.50000000000000026e-75Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6462.9
Applied rewrites62.9%
Final simplification54.9%
(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.5
Applied rewrites38.5%
herbie shell --seed 2024326
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))