
(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 (+ (/ (- 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 (- x (/ x z)))) (if (<= z -2.6e+23) t_0 (if (<= z 4.5e+31) (/ (- y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (z <= -2.6e+23) {
tmp = t_0;
} else if (z <= 4.5e+31) {
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 <= (-2.6d+23)) then
tmp = t_0
else if (z <= 4.5d+31) 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 <= -2.6e+23) {
tmp = t_0;
} else if (z <= 4.5e+31) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x / z) tmp = 0 if z <= -2.6e+23: tmp = t_0 elif z <= 4.5e+31: 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 <= -2.6e+23) tmp = t_0; elseif (z <= 4.5e+31) 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 <= -2.6e+23) tmp = t_0; elseif (z <= 4.5e+31) 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, -2.6e+23], t$95$0, If[LessEqual[z, 4.5e+31], 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 -2.6 \cdot 10^{+23}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{+31}:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.59999999999999992e23 or 4.4999999999999996e31 < 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-/.f6477.6
Applied rewrites77.6%
if -2.59999999999999992e23 < z < 4.4999999999999996e31Initial program 99.9%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6496.7
Applied rewrites96.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (/ x z)))) (if (<= x -2.65e-188) t_0 (if (<= x 9.5e-104) (/ y z) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (x <= -2.65e-188) {
tmp = t_0;
} else if (x <= 9.5e-104) {
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 <= (-2.65d-188)) then
tmp = t_0
else if (x <= 9.5d-104) 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 <= -2.65e-188) {
tmp = t_0;
} else if (x <= 9.5e-104) {
tmp = y / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x / z) tmp = 0 if x <= -2.65e-188: tmp = t_0 elif x <= 9.5e-104: 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 <= -2.65e-188) tmp = t_0; elseif (x <= 9.5e-104) 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 <= -2.65e-188) tmp = t_0; elseif (x <= 9.5e-104) 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, -2.65e-188], t$95$0, If[LessEqual[x, 9.5e-104], N[(y / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{x}{z}\\
\mathbf{if}\;x \leq -2.65 \cdot 10^{-188}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{-104}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.65000000000000007e-188 or 9.5000000000000002e-104 < 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-/.f6480.1
Applied rewrites80.1%
if -2.65000000000000007e-188 < x < 9.5000000000000002e-104Initial program 99.9%
Taylor expanded in x around 0
lower-/.f6472.5
Applied rewrites72.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ (- x) z))) (if (<= x -9.2e+18) t_0 (if (<= x 0.0075) (/ y z) t_0))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (x <= -9.2e+18) {
tmp = t_0;
} else if (x <= 0.0075) {
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 <= (-9.2d+18)) then
tmp = t_0
else if (x <= 0.0075d0) 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 <= -9.2e+18) {
tmp = t_0;
} else if (x <= 0.0075) {
tmp = y / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if x <= -9.2e+18: tmp = t_0 elif x <= 0.0075: 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 <= -9.2e+18) tmp = t_0; elseif (x <= 0.0075) 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 <= -9.2e+18) tmp = t_0; elseif (x <= 0.0075) 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, -9.2e+18], t$95$0, If[LessEqual[x, 0.0075], N[(y / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;x \leq -9.2 \cdot 10^{+18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.0075:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -9.2e18 or 0.0074999999999999997 < x Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6455.6
Applied rewrites55.6%
Taylor expanded in x around inf
Applied rewrites44.6%
if -9.2e18 < x < 0.0074999999999999997Initial program 99.9%
Taylor expanded in x around 0
lower-/.f6460.0
Applied rewrites60.0%
(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-/.f6439.3
Applied rewrites39.3%
herbie shell --seed 2024296
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))