
(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 -2.6e+45)
x
(if (<= z -7.8e-59)
(/ y z)
(if (<= z -1.08e-184)
t_0
(if (<= z 2.9e-164)
(/ y z)
(if (<= z 2.26e-82) t_0 (if (<= z 7.4e+81) (/ y z) x))))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -2.6e+45) {
tmp = x;
} else if (z <= -7.8e-59) {
tmp = y / z;
} else if (z <= -1.08e-184) {
tmp = t_0;
} else if (z <= 2.9e-164) {
tmp = y / z;
} else if (z <= 2.26e-82) {
tmp = t_0;
} else if (z <= 7.4e+81) {
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 <= (-2.6d+45)) then
tmp = x
else if (z <= (-7.8d-59)) then
tmp = y / z
else if (z <= (-1.08d-184)) then
tmp = t_0
else if (z <= 2.9d-164) then
tmp = y / z
else if (z <= 2.26d-82) then
tmp = t_0
else if (z <= 7.4d+81) 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 <= -2.6e+45) {
tmp = x;
} else if (z <= -7.8e-59) {
tmp = y / z;
} else if (z <= -1.08e-184) {
tmp = t_0;
} else if (z <= 2.9e-164) {
tmp = y / z;
} else if (z <= 2.26e-82) {
tmp = t_0;
} else if (z <= 7.4e+81) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if z <= -2.6e+45: tmp = x elif z <= -7.8e-59: tmp = y / z elif z <= -1.08e-184: tmp = t_0 elif z <= 2.9e-164: tmp = y / z elif z <= 2.26e-82: tmp = t_0 elif z <= 7.4e+81: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -2.6e+45) tmp = x; elseif (z <= -7.8e-59) tmp = Float64(y / z); elseif (z <= -1.08e-184) tmp = t_0; elseif (z <= 2.9e-164) tmp = Float64(y / z); elseif (z <= 2.26e-82) tmp = t_0; elseif (z <= 7.4e+81) 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 <= -2.6e+45) tmp = x; elseif (z <= -7.8e-59) tmp = y / z; elseif (z <= -1.08e-184) tmp = t_0; elseif (z <= 2.9e-164) tmp = y / z; elseif (z <= 2.26e-82) tmp = t_0; elseif (z <= 7.4e+81) 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, -2.6e+45], x, If[LessEqual[z, -7.8e-59], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.08e-184], t$95$0, If[LessEqual[z, 2.9e-164], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.26e-82], t$95$0, If[LessEqual[z, 7.4e+81], N[(y / z), $MachinePrecision], x]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -2.6 \cdot 10^{+45}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -7.8 \cdot 10^{-59}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.08 \cdot 10^{-184}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.9 \cdot 10^{-164}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.26 \cdot 10^{-82}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.4 \cdot 10^{+81}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.60000000000000007e45 or 7.4000000000000001e81 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 76.4%
if -2.60000000000000007e45 < z < -7.80000000000000038e-59 or -1.07999999999999995e-184 < z < 2.9e-164 or 2.26000000000000004e-82 < z < 7.4000000000000001e81Initial program 100.0%
div-sub94.9%
sub-neg94.9%
distribute-frac-neg94.9%
+-commutative94.9%
associate-+r+94.9%
distribute-frac-neg94.9%
sub-neg94.9%
associate--r-94.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 65.7%
if -7.80000000000000038e-59 < z < -1.07999999999999995e-184 or 2.9e-164 < z < 2.26000000000000004e-82Initial program 100.0%
div-sub97.5%
sub-neg97.5%
distribute-frac-neg97.5%
+-commutative97.5%
associate-+r+97.5%
distribute-frac-neg97.5%
sub-neg97.5%
associate--r-97.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 70.0%
Taylor expanded in z around 0 70.0%
mul-1-neg70.0%
distribute-frac-neg270.0%
Simplified70.0%
Final simplification70.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.2e-104) (not (<= y 8.8e-69))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.2e-104) || !(y <= 8.8e-69)) {
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 <= (-9.2d-104)) .or. (.not. (y <= 8.8d-69))) 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 <= -9.2e-104) || !(y <= 8.8e-69)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.2e-104) or not (y <= 8.8e-69): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.2e-104) || !(y <= 8.8e-69)) 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 <= -9.2e-104) || ~((y <= 8.8e-69))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.2e-104], N[Not[LessEqual[y, 8.8e-69]], $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 -9.2 \cdot 10^{-104} \lor \neg \left(y \leq 8.8 \cdot 10^{-69}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -9.1999999999999998e-104 or 8.8000000000000001e-69 < y Initial program 100.0%
div-sub95.4%
sub-neg95.4%
distribute-frac-neg95.4%
+-commutative95.4%
associate-+r+95.4%
distribute-frac-neg95.4%
sub-neg95.4%
associate--r-95.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 88.2%
neg-mul-188.2%
distribute-neg-frac288.2%
Simplified88.2%
sub-neg88.2%
+-commutative88.2%
distribute-frac-neg288.2%
remove-double-neg88.2%
Applied egg-rr88.2%
if -9.1999999999999998e-104 < y < 8.8000000000000001e-69Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 86.4%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -820.0) (not (<= z 0.045))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -820.0) || !(z <= 0.045)) {
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 <= (-820.0d0)) .or. (.not. (z <= 0.045d0))) 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 <= -820.0) || !(z <= 0.045)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -820.0) or not (z <= 0.045): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -820.0) || !(z <= 0.045)) 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 <= -820.0) || ~((z <= 0.045))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -820.0], N[Not[LessEqual[z, 0.045]], $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 -820 \lor \neg \left(z \leq 0.045\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -820 or 0.044999999999999998 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 98.5%
neg-mul-198.5%
distribute-neg-frac298.5%
Simplified98.5%
sub-neg98.5%
+-commutative98.5%
distribute-frac-neg298.5%
remove-double-neg98.5%
Applied egg-rr98.5%
if -820 < z < 0.044999999999999998Initial program 100.0%
div-sub94.5%
sub-neg94.5%
distribute-frac-neg94.5%
+-commutative94.5%
associate-+r+94.5%
distribute-frac-neg94.5%
sub-neg94.5%
associate--r-94.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.4%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (<= z -1.7e+45) x (if (<= z 7.4e+81) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e+45) {
tmp = x;
} else if (z <= 7.4e+81) {
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.7d+45)) then
tmp = x
else if (z <= 7.4d+81) 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.7e+45) {
tmp = x;
} else if (z <= 7.4e+81) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.7e+45: tmp = x elif z <= 7.4e+81: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.7e+45) tmp = x; elseif (z <= 7.4e+81) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.7e+45) tmp = x; elseif (z <= 7.4e+81) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.7e+45], x, If[LessEqual[z, 7.4e+81], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+45}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 7.4 \cdot 10^{+81}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.7e45 or 7.4000000000000001e81 < z Initial program 100.0%
div-sub100.0%
sub-neg100.0%
distribute-frac-neg100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-frac-neg100.0%
sub-neg100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 76.4%
if -1.7e45 < z < 7.4000000000000001e81Initial program 100.0%
div-sub95.6%
sub-neg95.6%
distribute-frac-neg95.6%
+-commutative95.6%
associate-+r+95.6%
distribute-frac-neg95.6%
sub-neg95.6%
associate--r-95.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 57.9%
Final simplification64.9%
(FPCore (x y z) :precision binary64 (+ x (/ y z)))
double code(double x, double y, double z) {
return x + (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 = x + (y / z)
end function
public static double code(double x, double y, double z) {
return x + (y / z);
}
def code(x, y, z): return x + (y / z)
function code(x, y, z) return Float64(x + Float64(y / z)) end
function tmp = code(x, y, z) tmp = x + (y / z); end
code[x_, y_, z_] := N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{z}
\end{array}
Initial program 100.0%
div-sub97.2%
sub-neg97.2%
distribute-frac-neg97.2%
+-commutative97.2%
associate-+r+97.2%
distribute-frac-neg97.2%
sub-neg97.2%
associate--r-97.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 77.2%
neg-mul-177.2%
distribute-neg-frac277.2%
Simplified77.2%
sub-neg77.2%
+-commutative77.2%
distribute-frac-neg277.2%
remove-double-neg77.2%
Applied egg-rr77.2%
Final simplification77.2%
(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%
div-sub97.2%
sub-neg97.2%
distribute-frac-neg97.2%
+-commutative97.2%
associate-+r+97.2%
distribute-frac-neg97.2%
sub-neg97.2%
associate--r-97.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 34.1%
Final simplification34.1%
herbie shell --seed 2024067
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))