
(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 -4.2e+82)
x
(if (<= z -3.5e-183)
(/ y z)
(if (<= z 2.3e-216) (/ (- x) z) (if (<= z 3700000.0) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.2e+82) {
tmp = x;
} else if (z <= -3.5e-183) {
tmp = y / z;
} else if (z <= 2.3e-216) {
tmp = -x / z;
} else if (z <= 3700000.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 <= (-4.2d+82)) then
tmp = x
else if (z <= (-3.5d-183)) then
tmp = y / z
else if (z <= 2.3d-216) then
tmp = -x / z
else if (z <= 3700000.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 <= -4.2e+82) {
tmp = x;
} else if (z <= -3.5e-183) {
tmp = y / z;
} else if (z <= 2.3e-216) {
tmp = -x / z;
} else if (z <= 3700000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.2e+82: tmp = x elif z <= -3.5e-183: tmp = y / z elif z <= 2.3e-216: tmp = -x / z elif z <= 3700000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.2e+82) tmp = x; elseif (z <= -3.5e-183) tmp = Float64(y / z); elseif (z <= 2.3e-216) tmp = Float64(Float64(-x) / z); elseif (z <= 3700000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.2e+82) tmp = x; elseif (z <= -3.5e-183) tmp = y / z; elseif (z <= 2.3e-216) tmp = -x / z; elseif (z <= 3700000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.2e+82], x, If[LessEqual[z, -3.5e-183], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.3e-216], N[((-x) / z), $MachinePrecision], If[LessEqual[z, 3700000.0], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+82}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -3.5 \cdot 10^{-183}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-216}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 3700000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.2e82 or 3.7e6 < 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 77.5%
if -4.2e82 < z < -3.49999999999999991e-183 or 2.29999999999999997e-216 < z < 3.7e6Initial program 100.0%
div-sub96.9%
sub-neg96.9%
distribute-frac-neg96.9%
+-commutative96.9%
associate-+r+96.9%
distribute-frac-neg96.9%
sub-neg96.9%
associate--r-96.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 59.2%
if -3.49999999999999991e-183 < z < 2.29999999999999997e-216Initial program 100.0%
div-sub90.5%
sub-neg90.5%
distribute-frac-neg90.5%
+-commutative90.5%
associate-+r+90.5%
distribute-frac-neg90.5%
sub-neg90.5%
associate--r-90.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 74.2%
distribute-lft-out--74.2%
*-rgt-identity74.2%
associate-*r/74.3%
*-rgt-identity74.3%
Simplified74.3%
Taylor expanded in z around 0 74.3%
mul-1-neg74.3%
distribute-frac-neg74.3%
Simplified74.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.5e+21) (not (<= z 1.0))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.5e+21) || !(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 <= (-3.5d+21)) .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 <= -3.5e+21) || !(z <= 1.0)) {
tmp = x + (y / z);
} else {
tmp = (y - x) / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.5e+21) 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 <= -3.5e+21) || !(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 <= -3.5e+21) || ~((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, -3.5e+21], 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 -3.5 \cdot 10^{+21} \lor \neg \left(z \leq 1\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -3.5e21 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 99.2%
neg-mul-199.2%
Simplified99.2%
Taylor expanded in x around 0 99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
*-lft-identity99.2%
+-commutative99.2%
Simplified99.2%
if -3.5e21 < z < 1Initial program 100.0%
div-sub94.3%
sub-neg94.3%
distribute-frac-neg94.3%
+-commutative94.3%
associate-+r+94.3%
distribute-frac-neg94.3%
sub-neg94.3%
associate--r-94.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.3%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.55e-101) (not (<= y 1.35e-27))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.55e-101) || !(y <= 1.35e-27)) {
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.55d-101)) .or. (.not. (y <= 1.35d-27))) 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.55e-101) || !(y <= 1.35e-27)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.55e-101) or not (y <= 1.35e-27): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.55e-101) || !(y <= 1.35e-27)) 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.55e-101) || ~((y <= 1.35e-27))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.55e-101], N[Not[LessEqual[y, 1.35e-27]], $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.55 \cdot 10^{-101} \lor \neg \left(y \leq 1.35 \cdot 10^{-27}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -1.54999999999999987e-101 or 1.34999999999999994e-27 < y Initial program 100.0%
div-sub95.5%
sub-neg95.5%
distribute-frac-neg95.5%
+-commutative95.5%
associate-+r+95.5%
distribute-frac-neg95.5%
sub-neg95.5%
associate--r-95.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 90.4%
neg-mul-190.4%
Simplified90.4%
Taylor expanded in x around 0 90.4%
cancel-sign-sub-inv90.4%
metadata-eval90.4%
*-lft-identity90.4%
+-commutative90.4%
Simplified90.4%
if -1.54999999999999987e-101 < y < 1.34999999999999994e-27Initial 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 93.2%
distribute-lft-out--93.2%
*-rgt-identity93.2%
associate-*r/93.3%
*-rgt-identity93.3%
Simplified93.3%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.2e-183) (not (<= z 1.85e-216))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e-183) || !(z <= 1.85e-216)) {
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 <= (-3.2d-183)) .or. (.not. (z <= 1.85d-216))) 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 <= -3.2e-183) || !(z <= 1.85e-216)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.2e-183) or not (z <= 1.85e-216): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.2e-183) || !(z <= 1.85e-216)) 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 <= -3.2e-183) || ~((z <= 1.85e-216))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.2e-183], N[Not[LessEqual[z, 1.85e-216]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{-183} \lor \neg \left(z \leq 1.85 \cdot 10^{-216}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < -3.2000000000000002e-183 or 1.84999999999999998e-216 < z Initial program 100.0%
div-sub98.6%
sub-neg98.6%
distribute-frac-neg98.6%
+-commutative98.6%
associate-+r+98.6%
distribute-frac-neg98.6%
sub-neg98.6%
associate--r-98.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 84.7%
neg-mul-184.7%
Simplified84.7%
Taylor expanded in x around 0 84.7%
cancel-sign-sub-inv84.7%
metadata-eval84.7%
*-lft-identity84.7%
+-commutative84.7%
Simplified84.7%
if -3.2000000000000002e-183 < z < 1.84999999999999998e-216Initial program 100.0%
div-sub90.5%
sub-neg90.5%
distribute-frac-neg90.5%
+-commutative90.5%
associate-+r+90.5%
distribute-frac-neg90.5%
sub-neg90.5%
associate--r-90.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 74.2%
distribute-lft-out--74.2%
*-rgt-identity74.2%
associate-*r/74.3%
*-rgt-identity74.3%
Simplified74.3%
Taylor expanded in z around 0 74.3%
mul-1-neg74.3%
distribute-frac-neg74.3%
Simplified74.3%
Final simplification83.0%
(FPCore (x y z) :precision binary64 (if (<= z -4.2e+82) x (if (<= z 3600000.0) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.2e+82) {
tmp = x;
} else if (z <= 3600000.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 <= (-4.2d+82)) then
tmp = x
else if (z <= 3600000.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 <= -4.2e+82) {
tmp = x;
} else if (z <= 3600000.0) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.2e+82: tmp = x elif z <= 3600000.0: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.2e+82) tmp = x; elseif (z <= 3600000.0) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.2e+82) tmp = x; elseif (z <= 3600000.0) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.2e+82], x, If[LessEqual[z, 3600000.0], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{+82}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3600000:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.2e82 or 3.6e6 < 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 77.5%
if -4.2e82 < z < 3.6e6Initial program 100.0%
div-sub95.0%
sub-neg95.0%
distribute-frac-neg95.0%
+-commutative95.0%
associate-+r+95.0%
distribute-frac-neg95.0%
sub-neg95.0%
associate--r-95.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 51.4%
(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.3%
sub-neg97.3%
distribute-frac-neg97.3%
+-commutative97.3%
associate-+r+97.3%
distribute-frac-neg97.3%
sub-neg97.3%
associate--r-97.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 39.7%
herbie shell --seed 2024170
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))