
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (- x) z)))
(if (<= z -31.0)
x
(if (<= z 2.6e-199)
(/ y z)
(if (<= z 1.12e-122)
t_0
(if (<= z 5.5e-83)
(/ y z)
(if (<= z 3.5e-31) t_0 (if (<= z 3.9e+58) (/ y z) x))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -31.0) {
tmp = x;
} else if (z <= 2.6e-199) {
tmp = y / z;
} else if (z <= 1.12e-122) {
tmp = t_0;
} else if (z <= 5.5e-83) {
tmp = y / z;
} else if (z <= 3.5e-31) {
tmp = t_0;
} else if (z <= 3.9e+58) {
tmp = y / z;
} else {
tmp = x;
}
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 (z <= (-31.0d0)) then
tmp = x
else if (z <= 2.6d-199) then
tmp = y / z
else if (z <= 1.12d-122) then
tmp = t_0
else if (z <= 5.5d-83) then
tmp = y / z
else if (z <= 3.5d-31) then
tmp = t_0
else if (z <= 3.9d+58) then
tmp = y / z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -31.0) {
tmp = x;
} else if (z <= 2.6e-199) {
tmp = y / z;
} else if (z <= 1.12e-122) {
tmp = t_0;
} else if (z <= 5.5e-83) {
tmp = y / z;
} else if (z <= 3.5e-31) {
tmp = t_0;
} else if (z <= 3.9e+58) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -31.0: tmp = x elif z <= 2.6e-199: tmp = y / z elif z <= 1.12e-122: tmp = t_0 elif z <= 5.5e-83: tmp = y / z elif z <= 3.5e-31: tmp = t_0 elif z <= 3.9e+58: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -31.0) tmp = x; elseif (z <= 2.6e-199) tmp = Float64(y / z); elseif (z <= 1.12e-122) tmp = t_0; elseif (z <= 5.5e-83) tmp = Float64(y / z); elseif (z <= 3.5e-31) tmp = t_0; elseif (z <= 3.9e+58) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x / z; tmp = 0.0; if (z <= -31.0) tmp = x; elseif (z <= 2.6e-199) tmp = y / z; elseif (z <= 1.12e-122) tmp = t_0; elseif (z <= 5.5e-83) tmp = y / z; elseif (z <= 3.5e-31) tmp = t_0; elseif (z <= 3.9e+58) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -31.0], x, If[LessEqual[z, 2.6e-199], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.12e-122], t$95$0, If[LessEqual[z, 5.5e-83], N[(y / z), $MachinePrecision], If[LessEqual[z, 3.5e-31], t$95$0, If[LessEqual[z, 3.9e+58], N[(y / z), $MachinePrecision], x]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -31:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.6 \cdot 10^{-199}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1.12 \cdot 10^{-122}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-83}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{-31}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 3.9 \cdot 10^{+58}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -31 or 3.9000000000000001e58 < z Initial program 100.0%
Taylor expanded in z around inf 75.0%
if -31 < z < 2.6000000000000001e-199 or 1.12e-122 < z < 5.49999999999999964e-83 or 3.49999999999999985e-31 < z < 3.9000000000000001e58Initial program 100.0%
Taylor expanded in x around 0 64.6%
if 2.6000000000000001e-199 < z < 1.12e-122 or 5.49999999999999964e-83 < z < 3.49999999999999985e-31Initial program 100.0%
Taylor expanded in x around inf 78.3%
sub-neg78.3%
distribute-neg-frac78.3%
metadata-eval78.3%
metadata-eval78.3%
associate-/r*78.3%
neg-mul-178.3%
distribute-lft-out78.3%
*-rgt-identity78.3%
associate-*r/78.6%
neg-mul-178.6%
*-commutative78.6%
times-frac78.6%
metadata-eval78.6%
*-commutative78.6%
neg-mul-178.6%
sub-neg78.6%
Simplified78.6%
Taylor expanded in z around 0 78.6%
mul-1-neg78.6%
distribute-frac-neg78.6%
Simplified78.6%
Final simplification70.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.5e-120) (not (<= x 2.8e+26))) (- x (/ x z)) (/ y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.5e-120) || !(x <= 2.8e+26)) {
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 <= (-3.5d-120)) .or. (.not. (x <= 2.8d+26))) 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 <= -3.5e-120) || !(x <= 2.8e+26)) {
tmp = x - (x / z);
} else {
tmp = y / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.5e-120) or not (x <= 2.8e+26): tmp = x - (x / z) else: tmp = y / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.5e-120) || !(x <= 2.8e+26)) 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 <= -3.5e-120) || ~((x <= 2.8e+26))) tmp = x - (x / z); else tmp = y / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.5e-120], N[Not[LessEqual[x, 2.8e+26]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(y / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{-120} \lor \neg \left(x \leq 2.8 \cdot 10^{+26}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{z}\\
\end{array}
\end{array}
if x < -3.5e-120 or 2.8e26 < x Initial program 100.0%
Taylor expanded in x around inf 82.7%
sub-neg82.7%
distribute-neg-frac82.7%
metadata-eval82.7%
metadata-eval82.7%
associate-/r*82.7%
neg-mul-182.7%
distribute-lft-out82.7%
*-rgt-identity82.7%
associate-*r/82.8%
neg-mul-182.8%
*-commutative82.8%
times-frac82.8%
metadata-eval82.8%
*-commutative82.8%
neg-mul-182.8%
sub-neg82.8%
Simplified82.8%
if -3.5e-120 < x < 2.8e26Initial program 100.0%
Taylor expanded in x around 0 72.6%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (<= z -0.45) (- x (/ x z)) (if (<= z 8.5e+58) (/ (- y x) z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -0.45) {
tmp = x - (x / z);
} else if (z <= 8.5e+58) {
tmp = (y - x) / z;
} else {
tmp = x;
}
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 <= (-0.45d0)) then
tmp = x - (x / z)
else if (z <= 8.5d+58) then
tmp = (y - x) / z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -0.45) {
tmp = x - (x / z);
} else if (z <= 8.5e+58) {
tmp = (y - x) / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -0.45: tmp = x - (x / z) elif z <= 8.5e+58: tmp = (y - x) / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -0.45) tmp = Float64(x - Float64(x / z)); elseif (z <= 8.5e+58) tmp = Float64(Float64(y - x) / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -0.45) tmp = x - (x / z); elseif (z <= 8.5e+58) tmp = (y - x) / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -0.45], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 8.5e+58], N[(N[(y - x), $MachinePrecision] / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.45:\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{+58}:\\
\;\;\;\;\frac{y - x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -0.450000000000000011Initial program 100.0%
Taylor expanded in x around inf 75.2%
sub-neg75.2%
distribute-neg-frac75.2%
metadata-eval75.2%
metadata-eval75.2%
associate-/r*75.2%
neg-mul-175.2%
distribute-lft-out75.2%
*-rgt-identity75.2%
associate-*r/75.2%
neg-mul-175.2%
*-commutative75.2%
times-frac75.2%
metadata-eval75.2%
*-commutative75.2%
neg-mul-175.2%
sub-neg75.2%
Simplified75.2%
if -0.450000000000000011 < z < 8.50000000000000015e58Initial program 100.0%
Taylor expanded in z around 0 95.4%
if 8.50000000000000015e58 < z Initial program 100.0%
Taylor expanded in z around inf 76.1%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (if (<= z -31.0) x (if (<= z 3.6e+60) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -31.0) {
tmp = x;
} else if (z <= 3.6e+60) {
tmp = y / z;
} else {
tmp = x;
}
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 <= (-31.0d0)) then
tmp = x
else if (z <= 3.6d+60) then
tmp = y / z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -31.0) {
tmp = x;
} else if (z <= 3.6e+60) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -31.0: tmp = x elif z <= 3.6e+60: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -31.0) tmp = x; elseif (z <= 3.6e+60) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -31.0) tmp = x; elseif (z <= 3.6e+60) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -31.0], x, If[LessEqual[z, 3.6e+60], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -31:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+60}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -31 or 3.59999999999999968e60 < z Initial program 100.0%
Taylor expanded in z around inf 75.0%
if -31 < z < 3.59999999999999968e60Initial program 100.0%
Taylor expanded in x around 0 58.2%
Final simplification65.9%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 38.0%
Final simplification38.0%
herbie shell --seed 2023322
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))