
(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 (let* ((t_0 (+ x (/ y z)))) (if (<= z -1.0) t_0 (if (<= z 1.0) (/ (- y x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.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 + (y / z)
if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 1.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 + (y / z);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 1.0) {
tmp = (y - x) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 1.0: tmp = (y - x) / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) tmp = 0.0 if (z <= -1.0) tmp = t_0; elseif (z <= 1.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 + (y / z); tmp = 0.0; if (z <= -1.0) tmp = t_0; elseif (z <= 1.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[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 1.0], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6499.4
Applied rewrites99.4%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6498.4
Applied rewrites98.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- x (/ x z)))) (if (<= x -44000.0) t_0 (if (<= x 3.3e+24) (+ x (/ y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x - (x / z);
double tmp;
if (x <= -44000.0) {
tmp = t_0;
} else if (x <= 3.3e+24) {
tmp = x + (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 <= (-44000.0d0)) then
tmp = t_0
else if (x <= 3.3d+24) then
tmp = x + (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 <= -44000.0) {
tmp = t_0;
} else if (x <= 3.3e+24) {
tmp = x + (y / z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x - (x / z) tmp = 0 if x <= -44000.0: tmp = t_0 elif x <= 3.3e+24: tmp = x + (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 <= -44000.0) tmp = t_0; elseif (x <= 3.3e+24) tmp = Float64(x + 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 <= -44000.0) tmp = t_0; elseif (x <= 3.3e+24) tmp = x + (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, -44000.0], t$95$0, If[LessEqual[x, 3.3e+24], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x - \frac{x}{z}\\
\mathbf{if}\;x \leq -44000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.3 \cdot 10^{+24}:\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -44000 or 3.2999999999999999e24 < 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-/.f6492.2
Applied rewrites92.2%
if -44000 < x < 3.2999999999999999e24Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6489.7
Applied rewrites89.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ x (/ y z)))) (if (<= z -9.7e-23) t_0 (if (<= z 2.1e-267) (/ x (- z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x + (y / z);
double tmp;
if (z <= -9.7e-23) {
tmp = t_0;
} else if (z <= 2.1e-267) {
tmp = 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 + (y / z)
if (z <= (-9.7d-23)) then
tmp = t_0
else if (z <= 2.1d-267) then
tmp = 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 + (y / z);
double tmp;
if (z <= -9.7e-23) {
tmp = t_0;
} else if (z <= 2.1e-267) {
tmp = x / -z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y / z) tmp = 0 if z <= -9.7e-23: tmp = t_0 elif z <= 2.1e-267: tmp = x / -z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y / z)) tmp = 0.0 if (z <= -9.7e-23) tmp = t_0; elseif (z <= 2.1e-267) tmp = Float64(x / Float64(-z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y / z); tmp = 0.0; if (z <= -9.7e-23) tmp = t_0; elseif (z <= 2.1e-267) tmp = x / -z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -9.7e-23], t$95$0, If[LessEqual[z, 2.1e-267], N[(x / (-z)), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \frac{y}{z}\\
\mathbf{if}\;z \leq -9.7 \cdot 10^{-23}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.1 \cdot 10^{-267}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -9.7000000000000003e-23 or 2.1000000000000001e-267 < z Initial program 100.0%
Taylor expanded in y around inf
lower-/.f6484.0
Applied rewrites84.0%
if -9.7000000000000003e-23 < z < 2.1000000000000001e-267Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6475.2
Applied rewrites75.2%
Final simplification81.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ x (- z)))) (if (<= x -6.5e-14) t_0 (if (<= x 5.5e+31) (/ y z) t_0))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (x <= -6.5e-14) {
tmp = t_0;
} else if (x <= 5.5e+31) {
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 <= (-6.5d-14)) then
tmp = t_0
else if (x <= 5.5d+31) 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 <= -6.5e-14) {
tmp = t_0;
} else if (x <= 5.5e+31) {
tmp = y / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if x <= -6.5e-14: tmp = t_0 elif x <= 5.5e+31: tmp = y / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (x <= -6.5e-14) tmp = t_0; elseif (x <= 5.5e+31) 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 <= -6.5e-14) tmp = t_0; elseif (x <= 5.5e+31) 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, -6.5e-14], t$95$0, If[LessEqual[x, 5.5e+31], N[(y / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;x \leq -6.5 \cdot 10^{-14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{+31}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -6.5000000000000001e-14 or 5.50000000000000002e31 < x Initial program 100.0%
Taylor expanded in z around 0
lower-/.f64N/A
lower--.f6457.9
Applied rewrites57.9%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6451.2
Applied rewrites51.2%
if -6.5000000000000001e-14 < x < 5.50000000000000002e31Initial program 100.0%
Taylor expanded in x around 0
lower-/.f6465.3
Applied rewrites65.3%
Final simplification57.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 2024214
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))