
(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.2e+47)
x
(if (<= z -6.5e-105)
(/ y z)
(if (<= z -7e-239) (/ x (- z)) (if (<= z 1.18e+14) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.2e+47) {
tmp = x;
} else if (z <= -6.5e-105) {
tmp = y / z;
} else if (z <= -7e-239) {
tmp = x / -z;
} else if (z <= 1.18e+14) {
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.2d+47)) then
tmp = x
else if (z <= (-6.5d-105)) then
tmp = y / z
else if (z <= (-7d-239)) then
tmp = x / -z
else if (z <= 1.18d+14) 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.2e+47) {
tmp = x;
} else if (z <= -6.5e-105) {
tmp = y / z;
} else if (z <= -7e-239) {
tmp = x / -z;
} else if (z <= 1.18e+14) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.2e+47: tmp = x elif z <= -6.5e-105: tmp = y / z elif z <= -7e-239: tmp = x / -z elif z <= 1.18e+14: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.2e+47) tmp = x; elseif (z <= -6.5e-105) tmp = Float64(y / z); elseif (z <= -7e-239) tmp = Float64(x / Float64(-z)); elseif (z <= 1.18e+14) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.2e+47) tmp = x; elseif (z <= -6.5e-105) tmp = y / z; elseif (z <= -7e-239) tmp = x / -z; elseif (z <= 1.18e+14) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.2e+47], x, If[LessEqual[z, -6.5e-105], N[(y / z), $MachinePrecision], If[LessEqual[z, -7e-239], N[(x / (-z)), $MachinePrecision], If[LessEqual[z, 1.18e+14], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+47}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -6.5 \cdot 10^{-105}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -7 \cdot 10^{-239}:\\
\;\;\;\;\frac{x}{-z}\\
\mathbf{elif}\;z \leq 1.18 \cdot 10^{+14}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.20000000000000007e47 or 1.18e14 < 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.2%
if -5.20000000000000007e47 < z < -6.50000000000000006e-105 or -7.00000000000000011e-239 < z < 1.18e14Initial program 100.0%
div-sub97.4%
sub-neg97.4%
distribute-frac-neg97.4%
+-commutative97.4%
associate-+r+97.4%
distribute-frac-neg97.4%
sub-neg97.4%
associate--r-97.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 60.6%
if -6.50000000000000006e-105 < z < -7.00000000000000011e-239Initial 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 63.4%
distribute-rgt-out--63.4%
*-lft-identity63.4%
associate-*l/63.8%
*-lft-identity63.8%
Simplified63.8%
Taylor expanded in z around 0 63.8%
mul-1-neg63.8%
distribute-frac-neg263.8%
Simplified63.8%
(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%
clear-num99.9%
associate-/r/99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 97.6%
associate-*r/97.6%
neg-mul-197.6%
Simplified97.6%
sub-neg97.6%
+-commutative97.6%
distribute-frac-neg97.6%
remove-double-neg97.6%
Applied egg-rr97.6%
if -1 < z < 1Initial program 100.0%
div-sub97.7%
sub-neg97.7%
distribute-frac-neg97.7%
+-commutative97.7%
associate-+r+97.7%
distribute-frac-neg97.7%
sub-neg97.7%
associate--r-97.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.1%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.7e-127) (not (<= y 9e-66))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.7e-127) || !(y <= 9e-66)) {
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-127)) .or. (.not. (y <= 9d-66))) 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-127) || !(y <= 9e-66)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.7e-127) or not (y <= 9e-66): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.7e-127) || !(y <= 9e-66)) 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-127) || ~((y <= 9e-66))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.7e-127], N[Not[LessEqual[y, 9e-66]], $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^{-127} \lor \neg \left(y \leq 9 \cdot 10^{-66}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.7e-127 or 8.9999999999999995e-66 < y Initial program 100.0%
div-sub98.2%
sub-neg98.2%
distribute-frac-neg98.2%
+-commutative98.2%
associate-+r+98.2%
distribute-frac-neg98.2%
sub-neg98.2%
associate--r-98.2%
div-sub100.0%
Simplified100.0%
clear-num99.7%
associate-/r/99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 87.5%
associate-*r/87.5%
neg-mul-187.5%
Simplified87.5%
sub-neg87.5%
+-commutative87.5%
distribute-frac-neg87.5%
remove-double-neg87.5%
Applied egg-rr87.5%
if -2.7e-127 < y < 8.9999999999999995e-66Initial 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 87.4%
distribute-rgt-out--87.4%
*-lft-identity87.4%
associate-*l/87.5%
*-lft-identity87.5%
Simplified87.5%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (<= z -8.8e+49) x (if (<= z 1.65e+17) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.8e+49) {
tmp = x;
} else if (z <= 1.65e+17) {
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 <= (-8.8d+49)) then
tmp = x
else if (z <= 1.65d+17) 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 <= -8.8e+49) {
tmp = x;
} else if (z <= 1.65e+17) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.8e+49: tmp = x elif z <= 1.65e+17: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.8e+49) tmp = x; elseif (z <= 1.65e+17) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.8e+49) tmp = x; elseif (z <= 1.65e+17) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.8e+49], x, If[LessEqual[z, 1.65e+17], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.8 \cdot 10^{+49}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.65 \cdot 10^{+17}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.8000000000000003e49 or 1.65e17 < 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.2%
if -8.8000000000000003e49 < z < 1.65e17Initial program 100.0%
div-sub97.8%
sub-neg97.8%
distribute-frac-neg97.8%
+-commutative97.8%
associate-+r+97.8%
distribute-frac-neg97.8%
sub-neg97.8%
associate--r-97.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 57.0%
(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-sub98.8%
sub-neg98.8%
distribute-frac-neg98.8%
+-commutative98.8%
associate-+r+98.8%
distribute-frac-neg98.8%
sub-neg98.8%
associate--r-98.8%
div-sub100.0%
Simplified100.0%
clear-num99.8%
associate-/r/99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 77.1%
associate-*r/77.1%
neg-mul-177.1%
Simplified77.1%
sub-neg77.1%
+-commutative77.1%
distribute-frac-neg77.1%
remove-double-neg77.1%
Applied egg-rr77.1%
Final simplification77.1%
(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.8%
sub-neg98.8%
distribute-frac-neg98.8%
+-commutative98.8%
associate-+r+98.8%
distribute-frac-neg98.8%
sub-neg98.8%
associate--r-98.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 33.9%
herbie shell --seed 2024089
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))