
(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 -6.6e+43) x (if (<= z 1.18e-200) (/ y z) (if (<= z 1.0) (/ x (- z)) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.6e+43) {
tmp = x;
} else if (z <= 1.18e-200) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = 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 <= (-6.6d+43)) then
tmp = x
else if (z <= 1.18d-200) then
tmp = y / z
else if (z <= 1.0d0) then
tmp = 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 <= -6.6e+43) {
tmp = x;
} else if (z <= 1.18e-200) {
tmp = y / z;
} else if (z <= 1.0) {
tmp = x / -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.6e+43: tmp = x elif z <= 1.18e-200: tmp = y / z elif z <= 1.0: tmp = x / -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.6e+43) tmp = x; elseif (z <= 1.18e-200) tmp = Float64(y / z); elseif (z <= 1.0) tmp = Float64(x / Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.6e+43) tmp = x; elseif (z <= 1.18e-200) tmp = y / z; elseif (z <= 1.0) tmp = x / -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.6e+43], x, If[LessEqual[z, 1.18e-200], N[(y / z), $MachinePrecision], If[LessEqual[z, 1.0], N[(x / (-z)), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{+43}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.18 \cdot 10^{-200}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.6000000000000003e43 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 z around inf 68.4%
if -6.6000000000000003e43 < z < 1.17999999999999996e-200Initial program 100.0%
div-sub95.3%
sub-neg95.3%
distribute-frac-neg95.3%
+-commutative95.3%
associate-+r+95.3%
distribute-frac-neg95.3%
sub-neg95.3%
associate--r-95.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 62.0%
if 1.17999999999999996e-200 < z < 1Initial program 100.0%
div-sub95.9%
sub-neg95.9%
distribute-frac-neg95.9%
+-commutative95.9%
associate-+r+95.9%
distribute-frac-neg95.9%
sub-neg95.9%
associate--r-95.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 57.9%
distribute-lft-out--57.9%
*-rgt-identity57.9%
associate-*r/58.2%
*-rgt-identity58.2%
Simplified58.2%
Taylor expanded in z around 0 57.8%
mul-1-neg57.8%
distribute-frac-neg57.8%
Simplified57.8%
Final simplification64.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -13.5) (not (<= z 1e-8))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -13.5) || !(z <= 1e-8)) {
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 <= (-13.5d0)) .or. (.not. (z <= 1d-8))) 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 <= -13.5) || !(z <= 1e-8)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -13.5) or not (z <= 1e-8): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -13.5) || !(z <= 1e-8)) 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 <= -13.5) || ~((z <= 1e-8))) tmp = x + (y / z); else tmp = (y - x) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -13.5], N[Not[LessEqual[z, 1e-8]], $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 -13.5 \lor \neg \left(z \leq 10^{-8}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -13.5 or 1e-8 < 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 97.6%
neg-mul-197.6%
Simplified97.6%
Taylor expanded in x around 0 97.6%
cancel-sign-sub-inv97.6%
metadata-eval97.6%
*-lft-identity97.6%
+-commutative97.6%
Simplified97.6%
if -13.5 < z < 1e-8Initial 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 z around 0 99.3%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.7e-36) (not (<= y 2700000.0))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.7e-36) || !(y <= 2700000.0)) {
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 <= (-2.7d-36)) .or. (.not. (y <= 2700000.0d0))) 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 <= -2.7e-36) || !(y <= 2700000.0)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.7e-36) or not (y <= 2700000.0): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.7e-36) || !(y <= 2700000.0)) 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 <= -2.7e-36) || ~((y <= 2700000.0))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.7e-36], N[Not[LessEqual[y, 2700000.0]], $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 -2.7 \cdot 10^{-36} \lor \neg \left(y \leq 2700000\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.70000000000000007e-36 or 2.7e6 < y Initial program 100.0%
div-sub95.3%
sub-neg95.3%
distribute-frac-neg95.3%
+-commutative95.3%
associate-+r+95.3%
distribute-frac-neg95.3%
sub-neg95.3%
associate--r-95.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 90.1%
neg-mul-190.1%
Simplified90.1%
Taylor expanded in x around 0 90.1%
cancel-sign-sub-inv90.1%
metadata-eval90.1%
*-lft-identity90.1%
+-commutative90.1%
Simplified90.1%
if -2.70000000000000007e-36 < y < 2.7e6Initial 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.2%
distribute-lft-out--86.2%
*-rgt-identity86.2%
associate-*r/86.3%
*-rgt-identity86.3%
Simplified86.3%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (or (<= x 9.6e+152) (not (<= x 2.7e+234))) (+ x (/ y z)) (/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= 9.6e+152) || !(x <= 2.7e+234)) {
tmp = x + (y / z);
} else {
tmp = 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 ((x <= 9.6d+152) .or. (.not. (x <= 2.7d+234))) then
tmp = x + (y / z)
else
tmp = x / -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= 9.6e+152) || !(x <= 2.7e+234)) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= 9.6e+152) or not (x <= 2.7e+234): tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= 9.6e+152) || !(x <= 2.7e+234)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(x / Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= 9.6e+152) || ~((x <= 2.7e+234))) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, 9.6e+152], N[Not[LessEqual[x, 2.7e+234]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.6 \cdot 10^{+152} \lor \neg \left(x \leq 2.7 \cdot 10^{+234}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if x < 9.5999999999999997e152 or 2.7000000000000002e234 < x Initial program 100.0%
div-sub97.9%
sub-neg97.9%
distribute-frac-neg97.9%
+-commutative97.9%
associate-+r+97.9%
distribute-frac-neg97.9%
sub-neg97.9%
associate--r-97.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 80.7%
neg-mul-180.7%
Simplified80.7%
Taylor expanded in x around 0 80.7%
cancel-sign-sub-inv80.7%
metadata-eval80.7%
*-lft-identity80.7%
+-commutative80.7%
Simplified80.7%
if 9.5999999999999997e152 < x < 2.7000000000000002e234Initial program 100.0%
div-sub95.2%
sub-neg95.2%
distribute-frac-neg95.2%
+-commutative95.2%
associate-+r+95.2%
distribute-frac-neg95.2%
sub-neg95.2%
associate--r-95.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 89.2%
distribute-lft-out--89.2%
*-rgt-identity89.2%
associate-*r/89.4%
*-rgt-identity89.4%
Simplified89.4%
Taylor expanded in z around 0 78.0%
mul-1-neg78.0%
distribute-frac-neg78.0%
Simplified78.0%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (<= z -5.8e+43) x (if (<= z 8.6e+22) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.8e+43) {
tmp = x;
} else if (z <= 8.6e+22) {
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.8d+43)) then
tmp = x
else if (z <= 8.6d+22) 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.8e+43) {
tmp = x;
} else if (z <= 8.6e+22) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.8e+43: tmp = x elif z <= 8.6e+22: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.8e+43) tmp = x; elseif (z <= 8.6e+22) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.8e+43) tmp = x; elseif (z <= 8.6e+22) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.8e+43], x, If[LessEqual[z, 8.6e+22], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{+43}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8.6 \cdot 10^{+22}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.8000000000000004e43 or 8.6000000000000004e22 < 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 70.7%
if -5.8000000000000004e43 < z < 8.6000000000000004e22Initial program 100.0%
div-sub95.7%
sub-neg95.7%
distribute-frac-neg95.7%
+-commutative95.7%
associate-+r+95.7%
distribute-frac-neg95.7%
sub-neg95.7%
associate--r-95.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 54.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-sub97.6%
sub-neg97.6%
distribute-frac-neg97.6%
+-commutative97.6%
associate-+r+97.6%
distribute-frac-neg97.6%
sub-neg97.6%
associate--r-97.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 34.2%
herbie shell --seed 2024172
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))