
(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 -1.62e+77)
x
(if (<= z -4.4e-176)
(/ y z)
(if (<= z 4.5e-296) (/ (- x) z) (if (<= z 3.2e+22) (/ y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.62e+77) {
tmp = x;
} else if (z <= -4.4e-176) {
tmp = y / z;
} else if (z <= 4.5e-296) {
tmp = -x / z;
} else if (z <= 3.2e+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 <= (-1.62d+77)) then
tmp = x
else if (z <= (-4.4d-176)) then
tmp = y / z
else if (z <= 4.5d-296) then
tmp = -x / z
else if (z <= 3.2d+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 <= -1.62e+77) {
tmp = x;
} else if (z <= -4.4e-176) {
tmp = y / z;
} else if (z <= 4.5e-296) {
tmp = -x / z;
} else if (z <= 3.2e+22) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.62e+77: tmp = x elif z <= -4.4e-176: tmp = y / z elif z <= 4.5e-296: tmp = -x / z elif z <= 3.2e+22: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.62e+77) tmp = x; elseif (z <= -4.4e-176) tmp = Float64(y / z); elseif (z <= 4.5e-296) tmp = Float64(Float64(-x) / z); elseif (z <= 3.2e+22) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.62e+77) tmp = x; elseif (z <= -4.4e-176) tmp = y / z; elseif (z <= 4.5e-296) tmp = -x / z; elseif (z <= 3.2e+22) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.62e+77], x, If[LessEqual[z, -4.4e-176], N[(y / z), $MachinePrecision], If[LessEqual[z, 4.5e-296], N[((-x) / z), $MachinePrecision], If[LessEqual[z, 3.2e+22], N[(y / z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.62 \cdot 10^{+77}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -4.4 \cdot 10^{-176}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{-296}:\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{+22}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.62e77 or 3.2e22 < 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 80.7%
if -1.62e77 < z < -4.3999999999999997e-176 or 4.5000000000000002e-296 < z < 3.2e22Initial program 100.0%
div-sub96.8%
sub-neg96.8%
distribute-frac-neg96.8%
+-commutative96.8%
associate-+r+96.8%
distribute-frac-neg96.8%
sub-neg96.8%
associate--r-96.8%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 58.3%
if -4.3999999999999997e-176 < z < 4.5000000000000002e-296Initial program 100.0%
div-sub99.9%
sub-neg99.9%
distribute-frac-neg99.9%
+-commutative99.9%
associate-+r+99.9%
distribute-frac-neg99.9%
sub-neg99.9%
associate--r-99.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 76.1%
distribute-lft-out--76.1%
*-rgt-identity76.1%
associate-*r/76.2%
*-rgt-identity76.2%
Simplified76.2%
Taylor expanded in z around 0 76.2%
mul-1-neg76.2%
distribute-frac-neg76.2%
Simplified76.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.5%
neg-mul-198.5%
Simplified98.5%
Taylor expanded in x around 0 98.5%
cancel-sign-sub-inv98.5%
metadata-eval98.5%
*-lft-identity98.5%
+-commutative98.5%
Simplified98.5%
if -1 < z < 1Initial 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 z around 0 99.2%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.7e-135) (not (<= y 2.7e-91))) (+ x (/ y z)) (- x (/ x z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.7e-135) || !(y <= 2.7e-91)) {
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-135)) .or. (.not. (y <= 2.7d-91))) 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-135) || !(y <= 2.7e-91)) {
tmp = x + (y / z);
} else {
tmp = x - (x / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.7e-135) or not (y <= 2.7e-91): tmp = x + (y / z) else: tmp = x - (x / z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.7e-135) || !(y <= 2.7e-91)) 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-135) || ~((y <= 2.7e-91))) tmp = x + (y / z); else tmp = x - (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.7e-135], N[Not[LessEqual[y, 2.7e-91]], $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^{-135} \lor \neg \left(y \leq 2.7 \cdot 10^{-91}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{x}{z}\\
\end{array}
\end{array}
if y < -2.69999999999999999e-135 or 2.6999999999999997e-91 < y Initial program 100.0%
div-sub97.5%
sub-neg97.5%
distribute-frac-neg97.5%
+-commutative97.5%
associate-+r+97.5%
distribute-frac-neg97.5%
sub-neg97.5%
associate--r-97.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 87.7%
neg-mul-187.7%
Simplified87.7%
Taylor expanded in x around 0 87.7%
cancel-sign-sub-inv87.7%
metadata-eval87.7%
*-lft-identity87.7%
+-commutative87.7%
Simplified87.7%
if -2.69999999999999999e-135 < y < 2.6999999999999997e-91Initial program 100.0%
div-sub99.9%
sub-neg99.9%
distribute-frac-neg99.9%
+-commutative99.9%
associate-+r+99.9%
distribute-frac-neg99.9%
sub-neg99.9%
associate--r-99.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 93.0%
distribute-lft-out--93.0%
*-rgt-identity93.0%
associate-*r/93.1%
*-rgt-identity93.1%
Simplified93.1%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.2e-175) (not (<= z 7.8e-283))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.2e-175) || !(z <= 7.8e-283)) {
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 <= (-8.2d-175)) .or. (.not. (z <= 7.8d-283))) 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 <= -8.2e-175) || !(z <= 7.8e-283)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.2e-175) or not (z <= 7.8e-283): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.2e-175) || !(z <= 7.8e-283)) 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 <= -8.2e-175) || ~((z <= 7.8e-283))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.2e-175], N[Not[LessEqual[z, 7.8e-283]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.2 \cdot 10^{-175} \lor \neg \left(z \leq 7.8 \cdot 10^{-283}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if z < -8.19999999999999997e-175 or 7.8000000000000004e-283 < z 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%
Taylor expanded in x around 0 81.5%
neg-mul-181.5%
Simplified81.5%
Taylor expanded in x around 0 81.5%
cancel-sign-sub-inv81.5%
metadata-eval81.5%
*-lft-identity81.5%
+-commutative81.5%
Simplified81.5%
if -8.19999999999999997e-175 < z < 7.8000000000000004e-283Initial program 100.0%
div-sub99.9%
sub-neg99.9%
distribute-frac-neg99.9%
+-commutative99.9%
associate-+r+99.9%
distribute-frac-neg99.9%
sub-neg99.9%
associate--r-99.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 76.1%
distribute-lft-out--76.1%
*-rgt-identity76.1%
associate-*r/76.2%
*-rgt-identity76.2%
Simplified76.2%
Taylor expanded in z around 0 76.2%
mul-1-neg76.2%
distribute-frac-neg76.2%
Simplified76.2%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (if (<= z -2.3e+77) x (if (<= z 3.15e+22) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.3e+77) {
tmp = x;
} else if (z <= 3.15e+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 <= (-2.3d+77)) then
tmp = x
else if (z <= 3.15d+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 <= -2.3e+77) {
tmp = x;
} else if (z <= 3.15e+22) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.3e+77: tmp = x elif z <= 3.15e+22: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.3e+77) tmp = x; elseif (z <= 3.15e+22) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.3e+77) tmp = x; elseif (z <= 3.15e+22) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.3e+77], x, If[LessEqual[z, 3.15e+22], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.3 \cdot 10^{+77}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.15 \cdot 10^{+22}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.29999999999999995e77 or 3.1500000000000001e22 < 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 80.7%
if -2.29999999999999995e77 < z < 3.1500000000000001e22Initial 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 x around 0 53.7%
(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.4%
sub-neg98.4%
distribute-frac-neg98.4%
+-commutative98.4%
associate-+r+98.4%
distribute-frac-neg98.4%
sub-neg98.4%
associate--r-98.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 38.2%
herbie shell --seed 2024143
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))