
(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 7 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 -6.4e+35)
x
(if (<= z 2.3e-187)
(/ y z)
(if (<= z 2.95e-40)
t_0
(if (<= z 2.6e-18) (/ y z) (if (<= z 1.0) t_0 x)))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -6.4e+35) {
tmp = x;
} else if (z <= 2.3e-187) {
tmp = y / z;
} else if (z <= 2.95e-40) {
tmp = t_0;
} else if (z <= 2.6e-18) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = t_0;
} 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 <= (-6.4d+35)) then
tmp = x
else if (z <= 2.3d-187) then
tmp = y / z
else if (z <= 2.95d-40) then
tmp = t_0
else if (z <= 2.6d-18) then
tmp = y / z
else if (z <= 1.0d0) then
tmp = t_0
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 <= -6.4e+35) {
tmp = x;
} else if (z <= 2.3e-187) {
tmp = y / z;
} else if (z <= 2.95e-40) {
tmp = t_0;
} else if (z <= 2.6e-18) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -6.4e+35: tmp = x elif z <= 2.3e-187: tmp = y / z elif z <= 2.95e-40: tmp = t_0 elif z <= 2.6e-18: tmp = y / z elif z <= 1.0: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -6.4e+35) tmp = x; elseif (z <= 2.3e-187) tmp = Float64(y / z); elseif (z <= 2.95e-40) tmp = t_0; elseif (z <= 2.6e-18) tmp = Float64(y / z); elseif (z <= 1.0) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x / z; tmp = 0.0; if (z <= -6.4e+35) tmp = x; elseif (z <= 2.3e-187) tmp = y / z; elseif (z <= 2.95e-40) tmp = t_0; elseif (z <= 2.6e-18) tmp = y / z; elseif (z <= 1.0) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / z), $MachinePrecision]}, If[LessEqual[z, -6.4e+35], x, If[LessEqual[z, 2.3e-187], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.95e-40], t$95$0, If[LessEqual[z, 2.6e-18], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], t$95$0, x]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -6.4 \cdot 10^{+35}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-187}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.95 \cdot 10^{-40}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 2.6 \cdot 10^{-18}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.39999999999999965e35 or 1 < z Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 77.6%
if -6.39999999999999965e35 < z < 2.29999999999999998e-187 or 2.94999999999999983e-40 < z < 2.6e-18Initial program 99.9%
remove-double-neg99.9%
neg-sub099.9%
neg-sub099.9%
remove-double-neg99.9%
--rgt-identity99.9%
associate-+l-99.9%
div099.9%
div-sub99.9%
associate-+l-99.9%
neg-sub099.9%
+-commutative99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in x around 0 57.6%
if 2.29999999999999998e-187 < z < 2.94999999999999983e-40 or 2.6e-18 < z < 1Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 71.4%
Taylor expanded in z around 0 69.7%
mul-1-neg69.7%
distribute-frac-neg69.7%
Simplified69.7%
Final simplification68.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.4e-21) (not (<= y 2.85e-30))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.4e-21) || !(y <= 2.85e-30)) {
tmp = x + (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 <= (-5.4d-21)) .or. (.not. (y <= 2.85d-30))) then
tmp = x + (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 <= -5.4e-21) || !(y <= 2.85e-30)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.4e-21) or not (y <= 2.85e-30): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.4e-21) || !(y <= 2.85e-30)) tmp = Float64(x + 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 <= -5.4e-21) || ~((y <= 2.85e-30))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.4e-21], N[Not[LessEqual[y, 2.85e-30]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{-21} \lor \neg \left(y \leq 2.85 \cdot 10^{-30}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -5.4000000000000002e-21 or 2.84999999999999989e-30 < y Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 87.8%
neg-mul-187.8%
distribute-neg-frac87.8%
Simplified87.8%
sub-neg87.8%
distribute-frac-neg87.8%
remove-double-neg87.8%
+-commutative87.8%
Applied egg-rr87.8%
if -5.4000000000000002e-21 < y < 2.84999999999999989e-30Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 90.2%
Final simplification89.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
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 <= 1.0): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) tmp = Float64(x + 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 <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 98.8%
neg-mul-198.8%
distribute-neg-frac98.8%
Simplified98.8%
sub-neg98.8%
distribute-frac-neg98.8%
remove-double-neg98.8%
+-commutative98.8%
Applied egg-rr98.8%
if -1 < z < 1Initial program 99.9%
remove-double-neg99.9%
neg-sub099.9%
neg-sub099.9%
remove-double-neg99.9%
--rgt-identity99.9%
associate-+l-99.9%
div099.9%
div-sub99.9%
associate-+l-99.9%
neg-sub099.9%
+-commutative99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in z around 0 99.0%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.9e+34) x (if (<= z 1600000.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.9e+34) {
tmp = x;
} else if (z <= 1600000.0) {
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 <= (-1.9d+34)) then
tmp = x
else if (z <= 1600000.0d0) 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 <= -1.9e+34) {
tmp = x;
} else if (z <= 1600000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.9e+34: tmp = x elif z <= 1600000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.9e+34) tmp = x; elseif (z <= 1600000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.9e+34) tmp = x; elseif (z <= 1600000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.9e+34], x, If[LessEqual[z, 1600000.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{+34}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1600000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.9000000000000001e34 or 1.6e6 < z Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 78.2%
if -1.9000000000000001e34 < z < 1.6e6Initial program 99.9%
remove-double-neg99.9%
neg-sub099.9%
neg-sub099.9%
remove-double-neg99.9%
--rgt-identity99.9%
associate-+l-99.9%
div099.9%
div-sub99.9%
associate-+l-99.9%
neg-sub099.9%
+-commutative99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in x around 0 50.6%
Final simplification63.9%
(FPCore (x y z) :precision binary64 (if (<= x -1.22e+238) (/ (- x) z) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.22e+238) {
tmp = -x / z;
} else {
tmp = x + (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 <= (-1.22d+238)) then
tmp = -x / z
else
tmp = x + (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.22e+238) {
tmp = -x / z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.22e+238: tmp = -x / z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.22e+238) tmp = Float64(Float64(-x) / z); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.22e+238) tmp = -x / z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.22e+238], N[((-x) / z), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.22 \cdot 10^{+238}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.2200000000000001e238Initial program 99.9%
remove-double-neg99.9%
neg-sub099.9%
neg-sub099.9%
remove-double-neg99.9%
--rgt-identity99.9%
associate-+l-99.9%
div099.9%
div-sub99.9%
associate-+l-99.9%
neg-sub099.9%
+-commutative99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in x around inf 99.9%
Taylor expanded in z around 0 75.0%
mul-1-neg75.0%
distribute-frac-neg75.0%
Simplified75.0%
if -1.2200000000000001e238 < x Initial program 100.0%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 76.8%
neg-mul-176.8%
distribute-neg-frac76.8%
Simplified76.8%
sub-neg76.8%
distribute-frac-neg76.8%
remove-double-neg76.8%
+-commutative76.8%
Applied egg-rr76.8%
Final simplification76.7%
(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%
remove-double-neg100.0%
neg-sub0100.0%
neg-sub0100.0%
remove-double-neg100.0%
--rgt-identity100.0%
associate-+l-100.0%
div0100.0%
div-sub100.0%
associate-+l-100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 39.5%
Final simplification39.5%
herbie shell --seed 2023310
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))