
(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%
(FPCore (x y z)
:precision binary64
(if (<= z -5.5e-10)
x
(if (<= z 4.1e-214)
(/ y z)
(if (<= z 4.6e-80) (/ x (- z)) (if (<= z 175000000.0) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e-10) {
tmp = x;
} else if (z <= 4.1e-214) {
tmp = y / z;
} else if (z <= 4.6e-80) {
tmp = x / -z;
} else if (z <= 175000000.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 <= (-5.5d-10)) then
tmp = x
else if (z <= 4.1d-214) then
tmp = y / z
else if (z <= 4.6d-80) then
tmp = x / -z
else if (z <= 175000000.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 <= -5.5e-10) {
tmp = x;
} else if (z <= 4.1e-214) {
tmp = y / z;
} else if (z <= 4.6e-80) {
tmp = x / -z;
} else if (z <= 175000000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.5e-10: tmp = x elif z <= 4.1e-214: tmp = y / z elif z <= 4.6e-80: tmp = x / -z elif z <= 175000000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.5e-10) tmp = x; elseif (z <= 4.1e-214) tmp = Float64(y / z); elseif (z <= 4.6e-80) tmp = Float64(x / Float64(-z)); elseif (z <= 175000000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.5e-10) tmp = x; elseif (z <= 4.1e-214) tmp = y / z; elseif (z <= 4.6e-80) tmp = x / -z; elseif (z <= 175000000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.5e-10], x, If[LessEqual[z, 4.1e-214], N[(y / z), $MachinePrecision], If[LessEqual[z, 4.6e-80], N[(x / (-z)), $MachinePrecision], If[LessEqual[z, 175000000.0], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.1 \cdot 10^{-214}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 4.6 \cdot 10^{-80}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{elif}\;z \leq 175000000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.4999999999999996e-10 or 1.75e8 < 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 73.7%
if -5.4999999999999996e-10 < z < 4.0999999999999997e-214 or 4.5999999999999996e-80 < z < 1.75e8Initial 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 58.7%
if 4.0999999999999997e-214 < z < 4.5999999999999996e-80Initial 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 61.2%
Taylor expanded in z around 0 61.2%
mul-1-neg61.2%
distribute-frac-neg261.2%
Simplified61.2%
(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%
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.8%
neg-mul-198.8%
distribute-neg-frac298.8%
Simplified98.8%
Taylor expanded in x around 0 98.8%
cancel-sign-sub-inv98.8%
metadata-eval98.8%
*-lft-identity98.8%
+-commutative98.8%
Simplified98.8%
if -1 < z < 1Initial program 100.0%
div-sub96.1%
sub-neg96.1%
distribute-frac-neg96.1%
+-commutative96.1%
associate-+r+96.1%
distribute-frac-neg96.1%
sub-neg96.1%
associate--r-96.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.4%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.8e+67) (not (<= x 0.0146))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.8e+67) || !(x <= 0.0146)) {
tmp = x - (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 <= (-4.8d+67)) .or. (.not. (x <= 0.0146d0))) then
tmp = x - (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 <= -4.8e+67) || !(x <= 0.0146)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.8e+67) or not (x <= 0.0146): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.8e+67) || !(x <= 0.0146)) tmp = Float64(x - 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 <= -4.8e+67) || ~((x <= 0.0146))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e+67], N[Not[LessEqual[x, 0.0146]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{+67} \lor \neg \left(x \leq 0.0146\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -4.80000000000000004e67 or 0.0146000000000000001 < x Initial program 100.0%
div-sub96.5%
sub-neg96.5%
distribute-frac-neg96.5%
+-commutative96.5%
associate-+r+96.5%
distribute-frac-neg96.5%
sub-neg96.5%
associate--r-96.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 91.1%
if -4.80000000000000004e67 < x < 0.0146000000000000001Initial program 100.0%
div-sub99.3%
sub-neg99.3%
distribute-frac-neg99.3%
+-commutative99.3%
associate-+r+99.3%
distribute-frac-neg99.3%
sub-neg99.3%
associate--r-99.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 88.4%
neg-mul-188.4%
distribute-neg-frac288.4%
Simplified88.4%
Taylor expanded in x around 0 88.4%
cancel-sign-sub-inv88.4%
metadata-eval88.4%
*-lft-identity88.4%
+-commutative88.4%
Simplified88.4%
Final simplification89.6%
(FPCore (x y z) :precision binary64 (if (<= z -5.5e-10) x (if (<= z 21500000.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e-10) {
tmp = x;
} else if (z <= 21500000.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 <= (-5.5d-10)) then
tmp = x
else if (z <= 21500000.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 <= -5.5e-10) {
tmp = x;
} else if (z <= 21500000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.5e-10: tmp = x elif z <= 21500000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.5e-10) tmp = x; elseif (z <= 21500000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.5e-10) tmp = x; elseif (z <= 21500000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.5e-10], x, If[LessEqual[z, 21500000.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 21500000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.4999999999999996e-10 or 2.15e7 < 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 73.7%
if -5.4999999999999996e-10 < z < 2.15e7Initial program 100.0%
div-sub96.0%
sub-neg96.0%
distribute-frac-neg96.0%
+-commutative96.0%
associate-+r+96.0%
distribute-frac-neg96.0%
sub-neg96.0%
associate--r-96.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 54.5%
(FPCore (x y z) :precision binary64 (if (<= x -3.3e+227) (/ x (- z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.3e+227) {
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 <= (-3.3d+227)) 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 <= -3.3e+227) {
tmp = x / -z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.3e+227: tmp = x / -z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.3e+227) tmp = Float64(x / Float64(-z)); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.3e+227) tmp = x / -z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.3e+227], N[(x / (-z)), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{+227}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -3.2999999999999999e227Initial program 100.0%
div-sub93.3%
sub-neg93.3%
distribute-frac-neg93.3%
+-commutative93.3%
associate-+r+93.3%
distribute-frac-neg93.3%
sub-neg93.3%
associate--r-93.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in z around 0 74.0%
mul-1-neg74.0%
distribute-frac-neg274.0%
Simplified74.0%
if -3.2999999999999999e227 < x Initial program 100.0%
div-sub98.3%
sub-neg98.3%
distribute-frac-neg98.3%
+-commutative98.3%
associate-+r+98.3%
distribute-frac-neg98.3%
sub-neg98.3%
associate--r-98.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 78.8%
neg-mul-178.8%
distribute-neg-frac278.8%
Simplified78.8%
Taylor expanded in x around 0 78.8%
cancel-sign-sub-inv78.8%
metadata-eval78.8%
*-lft-identity78.8%
+-commutative78.8%
Simplified78.8%
Final simplification78.6%
(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-sub98.0%
sub-neg98.0%
distribute-frac-neg98.0%
+-commutative98.0%
associate-+r+98.0%
distribute-frac-neg98.0%
sub-neg98.0%
associate--r-98.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 39.1%
herbie shell --seed 2024091
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))