
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ x (- z))))
(if (<= z -5.5e+215)
x
(if (<= z -1.85e-22)
(/ y z)
(if (<= z -1.35e-61)
t_0
(if (<= z -1.1e-89)
(/ y z)
(if (<= z 0.0019) t_0 (if (<= z 1.6e+86) (/ y z) x))))))))
double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -5.5e+215) {
tmp = x;
} else if (z <= -1.85e-22) {
tmp = y / z;
} else if (z <= -1.35e-61) {
tmp = t_0;
} else if (z <= -1.1e-89) {
tmp = y / z;
} else if (z <= 0.0019) {
tmp = t_0;
} else if (z <= 1.6e+86) {
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) :: t_0
real(8) :: tmp
t_0 = x / -z
if (z <= (-5.5d+215)) then
tmp = x
else if (z <= (-1.85d-22)) then
tmp = y / z
else if (z <= (-1.35d-61)) then
tmp = t_0
else if (z <= (-1.1d-89)) then
tmp = y / z
else if (z <= 0.0019d0) then
tmp = t_0
else if (z <= 1.6d+86) then
tmp = y / z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x / -z;
double tmp;
if (z <= -5.5e+215) {
tmp = x;
} else if (z <= -1.85e-22) {
tmp = y / z;
} else if (z <= -1.35e-61) {
tmp = t_0;
} else if (z <= -1.1e-89) {
tmp = y / z;
} else if (z <= 0.0019) {
tmp = t_0;
} else if (z <= 1.6e+86) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = x / -z tmp = 0 if z <= -5.5e+215: tmp = x elif z <= -1.85e-22: tmp = y / z elif z <= -1.35e-61: tmp = t_0 elif z <= -1.1e-89: tmp = y / z elif z <= 0.0019: tmp = t_0 elif z <= 1.6e+86: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(x / Float64(-z)) tmp = 0.0 if (z <= -5.5e+215) tmp = x; elseif (z <= -1.85e-22) tmp = Float64(y / z); elseif (z <= -1.35e-61) tmp = t_0; elseif (z <= -1.1e-89) tmp = Float64(y / z); elseif (z <= 0.0019) tmp = t_0; elseif (z <= 1.6e+86) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x / -z; tmp = 0.0; if (z <= -5.5e+215) tmp = x; elseif (z <= -1.85e-22) tmp = y / z; elseif (z <= -1.35e-61) tmp = t_0; elseif (z <= -1.1e-89) tmp = y / z; elseif (z <= 0.0019) tmp = t_0; elseif (z <= 1.6e+86) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / (-z)), $MachinePrecision]}, If[LessEqual[z, -5.5e+215], x, If[LessEqual[z, -1.85e-22], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.35e-61], t$95$0, If[LessEqual[z, -1.1e-89], N[(y / z), $MachinePrecision], If[LessEqual[z, 0.0019], t$95$0, If[LessEqual[z, 1.6e+86], N[(y / z), $MachinePrecision], x]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{-z}\\
\mathbf{if}\;z \leq -5.5 \cdot 10^{+215}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.85 \cdot 10^{-22}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.35 \cdot 10^{-61}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.1 \cdot 10^{-89}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 0.0019:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{+86}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.5e215 or 1.6e86 < 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 86.8%
if -5.5e215 < z < -1.85e-22 or -1.34999999999999997e-61 < z < -1.10000000000000006e-89 or 0.0019 < z < 1.6e86Initial program 100.0%
div-sub98.5%
sub-neg98.5%
distribute-frac-neg98.5%
+-commutative98.5%
associate-+r+98.5%
distribute-frac-neg98.5%
sub-neg98.5%
associate--r-98.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 61.2%
if -1.85e-22 < z < -1.34999999999999997e-61 or -1.10000000000000006e-89 < z < 0.0019Initial program 100.0%
div-sub90.2%
sub-neg90.2%
distribute-frac-neg90.2%
+-commutative90.2%
associate-+r+90.2%
distribute-frac-neg90.2%
sub-neg90.2%
associate--r-90.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 62.8%
distribute-rgt-out--62.9%
*-lft-identity62.9%
associate-*l/63.0%
*-lft-identity63.0%
Simplified63.0%
Taylor expanded in z around 0 62.3%
mul-1-neg62.3%
distribute-frac-neg262.3%
Simplified62.3%
Final simplification68.4%
(FPCore (x y z)
:precision binary64
(if (or (<= z -5e-36)
(and (not (<= z -2.3e-60)) (or (<= z -1.42e-92) (not (<= z 0.0046)))))
(+ x (/ y z))
(/ x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5e-36) || (!(z <= -2.3e-60) && ((z <= -1.42e-92) || !(z <= 0.0046)))) {
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 <= (-5d-36)) .or. (.not. (z <= (-2.3d-60))) .and. (z <= (-1.42d-92)) .or. (.not. (z <= 0.0046d0))) 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 <= -5e-36) || (!(z <= -2.3e-60) && ((z <= -1.42e-92) || !(z <= 0.0046)))) {
tmp = x + (y / z);
} else {
tmp = x / -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5e-36) or (not (z <= -2.3e-60) and ((z <= -1.42e-92) or not (z <= 0.0046))): tmp = x + (y / z) else: tmp = x / -z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5e-36) || (!(z <= -2.3e-60) && ((z <= -1.42e-92) || !(z <= 0.0046)))) 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 ((z <= -5e-36) || (~((z <= -2.3e-60)) && ((z <= -1.42e-92) || ~((z <= 0.0046))))) tmp = x + (y / z); else tmp = x / -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5e-36], And[N[Not[LessEqual[z, -2.3e-60]], $MachinePrecision], Or[LessEqual[z, -1.42e-92], N[Not[LessEqual[z, 0.0046]], $MachinePrecision]]]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[(x / (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{-36} \lor \neg \left(z \leq -2.3 \cdot 10^{-60}\right) \land \left(z \leq -1.42 \cdot 10^{-92} \lor \neg \left(z \leq 0.0046\right)\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{-z}\\
\end{array}
\end{array}
if z < -5.00000000000000004e-36 or -2.3000000000000001e-60 < z < -1.42e-92 or 0.0045999999999999999 < z Initial program 100.0%
div-sub99.2%
sub-neg99.2%
distribute-frac-neg99.2%
+-commutative99.2%
associate-+r+99.2%
distribute-frac-neg99.2%
sub-neg99.2%
associate--r-99.2%
div-sub100.0%
Simplified100.0%
clear-num99.9%
associate-/r/99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 95.9%
associate-*r/95.9%
neg-mul-195.9%
Simplified95.9%
Taylor expanded in x around 0 95.9%
cancel-sign-sub-inv95.9%
metadata-eval95.9%
*-lft-identity95.9%
+-commutative95.9%
Simplified95.9%
if -5.00000000000000004e-36 < z < -2.3000000000000001e-60 or -1.42e-92 < z < 0.0045999999999999999Initial program 100.0%
div-sub90.0%
sub-neg90.0%
distribute-frac-neg90.0%
+-commutative90.0%
associate-+r+90.0%
distribute-frac-neg90.0%
sub-neg90.0%
associate--r-90.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 63.0%
distribute-rgt-out--63.0%
*-lft-identity63.0%
associate-*l/63.2%
*-lft-identity63.2%
Simplified63.2%
Taylor expanded in z around 0 62.5%
mul-1-neg62.5%
distribute-frac-neg262.5%
Simplified62.5%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.1e+15) (not (<= x 1.15e-20))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e+15) || !(x <= 1.15e-20)) {
tmp = x - (x / z);
} else {
tmp = x + (y / 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 <= (-1.1d+15)) .or. (.not. (x <= 1.15d-20))) then
tmp = x - (x / z)
else
tmp = x + (y / z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e+15) || !(x <= 1.15e-20)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.1e+15) or not (x <= 1.15e-20): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.1e+15) || !(x <= 1.15e-20)) tmp = Float64(x - Float64(x / z)); else tmp = Float64(x + Float64(y / z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.1e+15) || ~((x <= 1.15e-20))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.1e+15], N[Not[LessEqual[x, 1.15e-20]], $MachinePrecision]], N[(x - N[(x / z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+15} \lor \neg \left(x \leq 1.15 \cdot 10^{-20}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.1e15 or 1.15e-20 < x Initial program 100.0%
div-sub90.3%
sub-neg90.3%
distribute-frac-neg90.3%
+-commutative90.3%
associate-+r+90.3%
distribute-frac-neg90.3%
sub-neg90.3%
associate--r-90.3%
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%
if -1.1e15 < x < 1.15e-20Initial 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.7%
associate-/r/99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 86.7%
associate-*r/86.7%
neg-mul-186.7%
Simplified86.7%
Taylor expanded in x around 0 86.7%
cancel-sign-sub-inv86.7%
metadata-eval86.7%
*-lft-identity86.7%
+-commutative86.7%
Simplified86.7%
Final simplification87.1%
(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.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 98.5%
associate-*r/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-sub90.4%
sub-neg90.4%
distribute-frac-neg90.4%
+-commutative90.4%
associate-+r+90.4%
distribute-frac-neg90.4%
sub-neg90.4%
associate--r-90.4%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 99.4%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (<= z -5.5e+215) x (if (<= z 9.8e+85) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e+215) {
tmp = x;
} else if (z <= 9.8e+85) {
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.5d+215)) then
tmp = x
else if (z <= 9.8d+85) 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.5e+215) {
tmp = x;
} else if (z <= 9.8e+85) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.5e+215: tmp = x elif z <= 9.8e+85: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.5e+215) tmp = x; elseif (z <= 9.8e+85) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.5e+215) tmp = x; elseif (z <= 9.8e+85) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.5e+215], x, If[LessEqual[z, 9.8e+85], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{+215}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 9.8 \cdot 10^{+85}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.5e215 or 9.7999999999999993e85 < 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 86.8%
if -5.5e215 < z < 9.7999999999999993e85Initial program 100.0%
div-sub93.1%
sub-neg93.1%
distribute-frac-neg93.1%
+-commutative93.1%
associate-+r+93.1%
distribute-frac-neg93.1%
sub-neg93.1%
associate--r-93.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 50.9%
Final simplification60.3%
(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-sub94.9%
sub-neg94.9%
distribute-frac-neg94.9%
+-commutative94.9%
associate-+r+94.9%
distribute-frac-neg94.9%
sub-neg94.9%
associate--r-94.9%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 32.7%
Final simplification32.7%
herbie shell --seed 2024077
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))