
(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 6 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 -2e+17)
x
(if (<= z -4.4e-95)
(/ y z)
(if (<= z -2.9e-205) (/ (- x) z) (if (<= z 340000000.0) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2e+17) {
tmp = x;
} else if (z <= -4.4e-95) {
tmp = y / z;
} else if (z <= -2.9e-205) {
tmp = -x / z;
} else if (z <= 340000000.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 <= (-2d+17)) then
tmp = x
else if (z <= (-4.4d-95)) then
tmp = y / z
else if (z <= (-2.9d-205)) then
tmp = -x / z
else if (z <= 340000000.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 <= -2e+17) {
tmp = x;
} else if (z <= -4.4e-95) {
tmp = y / z;
} else if (z <= -2.9e-205) {
tmp = -x / z;
} else if (z <= 340000000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2e+17: tmp = x elif z <= -4.4e-95: tmp = y / z elif z <= -2.9e-205: tmp = -x / z elif z <= 340000000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2e+17) tmp = x; elseif (z <= -4.4e-95) tmp = Float64(y / z); elseif (z <= -2.9e-205) tmp = Float64(Float64(-x) / z); elseif (z <= 340000000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2e+17) tmp = x; elseif (z <= -4.4e-95) tmp = y / z; elseif (z <= -2.9e-205) tmp = -x / z; elseif (z <= 340000000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2e+17], x, If[LessEqual[z, -4.4e-95], N[(y / z), $MachinePrecision], If[LessEqual[z, -2.9e-205], N[((-x) / z), $MachinePrecision], If[LessEqual[z, 340000000.0], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{+17}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -4.4 \cdot 10^{-95}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -2.9 \cdot 10^{-205}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 340000000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2e17 or 3.4e8 < 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 72.6%
if -2e17 < z < -4.3999999999999998e-95 or -2.90000000000000018e-205 < z < 3.4e8Initial 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 59.5%
if -4.3999999999999998e-95 < z < -2.90000000000000018e-205Initial program 100.0%
div-sub92.9%
sub-neg92.9%
distribute-frac-neg92.9%
+-commutative92.9%
associate-+r+92.9%
distribute-frac-neg92.9%
sub-neg92.9%
associate--r-92.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 68.4%
distribute-lft-out--68.4%
*-rgt-identity68.4%
associate-*r/68.7%
*-rgt-identity68.7%
Simplified68.7%
Taylor expanded in z around 0 68.7%
associate-*r/68.7%
neg-mul-168.7%
Simplified68.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.5e-70) (not (<= y 2.35e-26))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.5e-70) || !(y <= 2.35e-26)) {
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 <= (-1.5d-70)) .or. (.not. (y <= 2.35d-26))) 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 <= -1.5e-70) || !(y <= 2.35e-26)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.5e-70) or not (y <= 2.35e-26): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.5e-70) || !(y <= 2.35e-26)) 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 <= -1.5e-70) || ~((y <= 2.35e-26))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.5e-70], N[Not[LessEqual[y, 2.35e-26]], $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 -1.5 \cdot 10^{-70} \lor \neg \left(y \leq 2.35 \cdot 10^{-26}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.5000000000000001e-70 or 2.34999999999999995e-26 < y Initial program 100.0%
div-sub96.7%
sub-neg96.7%
distribute-frac-neg96.7%
+-commutative96.7%
associate-+r+96.7%
distribute-frac-neg96.7%
sub-neg96.7%
associate--r-96.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 90.8%
neg-mul-190.8%
Simplified90.8%
Taylor expanded in x around 0 90.8%
cancel-sign-sub-inv90.8%
metadata-eval90.8%
*-lft-identity90.8%
+-commutative90.8%
Simplified90.8%
if -1.5000000000000001e-70 < y < 2.34999999999999995e-26Initial 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 90.6%
distribute-lft-out--90.6%
*-rgt-identity90.6%
associate-*r/90.8%
*-rgt-identity90.8%
Simplified90.8%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.6e-95) (not (<= z -9e-206))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.6e-95) || !(z <= -9e-206)) {
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 ((z <= (-5.6d-95)) .or. (.not. (z <= (-9d-206)))) 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 ((z <= -5.6e-95) || !(z <= -9e-206)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.6e-95) or not (z <= -9e-206): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.6e-95) || !(z <= -9e-206)) tmp = Float64(x + Float64(y / z)); else tmp = Float64(Float64(-x) / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.6e-95) || ~((z <= -9e-206))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.6e-95], N[Not[LessEqual[z, -9e-206]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.6 \cdot 10^{-95} \lor \neg \left(z \leq -9 \cdot 10^{-206}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < -5.5999999999999998e-95 or -8.9999999999999996e-206 < z Initial program 100.0%
div-sub98.7%
sub-neg98.7%
distribute-frac-neg98.7%
+-commutative98.7%
associate-+r+98.7%
distribute-frac-neg98.7%
sub-neg98.7%
associate--r-98.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 81.1%
neg-mul-181.1%
Simplified81.1%
Taylor expanded in x around 0 81.1%
cancel-sign-sub-inv81.1%
metadata-eval81.1%
*-lft-identity81.1%
+-commutative81.1%
Simplified81.1%
if -5.5999999999999998e-95 < z < -8.9999999999999996e-206Initial program 100.0%
div-sub92.9%
sub-neg92.9%
distribute-frac-neg92.9%
+-commutative92.9%
associate-+r+92.9%
distribute-frac-neg92.9%
sub-neg92.9%
associate--r-92.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 68.4%
distribute-lft-out--68.4%
*-rgt-identity68.4%
associate-*r/68.7%
*-rgt-identity68.7%
Simplified68.7%
Taylor expanded in z around 0 68.7%
associate-*r/68.7%
neg-mul-168.7%
Simplified68.7%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.75e+21) x (if (<= z 215000000.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.75e+21) {
tmp = x;
} else if (z <= 215000000.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.75d+21)) then
tmp = x
else if (z <= 215000000.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.75e+21) {
tmp = x;
} else if (z <= 215000000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.75e+21: tmp = x elif z <= 215000000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.75e+21) tmp = x; elseif (z <= 215000000.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.75e+21) tmp = x; elseif (z <= 215000000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.75e+21], x, If[LessEqual[z, 215000000.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{+21}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 215000000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.75e21 or 2.15e8 < 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 72.6%
if -1.75e21 < z < 2.15e8Initial program 100.0%
div-sub96.3%
sub-neg96.3%
distribute-frac-neg96.3%
+-commutative96.3%
associate-+r+96.3%
distribute-frac-neg96.3%
sub-neg96.3%
associate--r-96.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 55.0%
(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 36.0%
herbie shell --seed 2024135
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))