
(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 -1.1e+34)
x
(if (<= z -4.4e-242)
(/ y z)
(if (<= z 2.2e-211)
t_0
(if (<= z 2.8e-56)
(/ y z)
(if (<= z 2.3e-26) t_0 (if (<= z 8.8e+21) (/ y z) x))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -1.1e+34) {
tmp = x;
} else if (z <= -4.4e-242) {
tmp = y / z;
} else if (z <= 2.2e-211) {
tmp = t_0;
} else if (z <= 2.8e-56) {
tmp = y / z;
} else if (z <= 2.3e-26) {
tmp = t_0;
} else if (z <= 8.8e+21) {
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 <= (-1.1d+34)) then
tmp = x
else if (z <= (-4.4d-242)) then
tmp = y / z
else if (z <= 2.2d-211) then
tmp = t_0
else if (z <= 2.8d-56) then
tmp = y / z
else if (z <= 2.3d-26) then
tmp = t_0
else if (z <= 8.8d+21) 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 <= -1.1e+34) {
tmp = x;
} else if (z <= -4.4e-242) {
tmp = y / z;
} else if (z <= 2.2e-211) {
tmp = t_0;
} else if (z <= 2.8e-56) {
tmp = y / z;
} else if (z <= 2.3e-26) {
tmp = t_0;
} else if (z <= 8.8e+21) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -1.1e+34: tmp = x elif z <= -4.4e-242: tmp = y / z elif z <= 2.2e-211: tmp = t_0 elif z <= 2.8e-56: tmp = y / z elif z <= 2.3e-26: tmp = t_0 elif z <= 8.8e+21: tmp = y / z else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -1.1e+34) tmp = x; elseif (z <= -4.4e-242) tmp = Float64(y / z); elseif (z <= 2.2e-211) tmp = t_0; elseif (z <= 2.8e-56) tmp = Float64(y / z); elseif (z <= 2.3e-26) tmp = t_0; elseif (z <= 8.8e+21) 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 <= -1.1e+34) tmp = x; elseif (z <= -4.4e-242) tmp = y / z; elseif (z <= 2.2e-211) tmp = t_0; elseif (z <= 2.8e-56) tmp = y / z; elseif (z <= 2.3e-26) tmp = t_0; elseif (z <= 8.8e+21) 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, -1.1e+34], x, If[LessEqual[z, -4.4e-242], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.2e-211], t$95$0, If[LessEqual[z, 2.8e-56], N[(y / z), $MachinePrecision], If[LessEqual[z, 2.3e-26], t$95$0, If[LessEqual[z, 8.8e+21], N[(y / z), $MachinePrecision], x]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -1.1 \cdot 10^{+34}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -4.4 \cdot 10^{-242}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.2 \cdot 10^{-211}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.8 \cdot 10^{-56}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-26}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 8.8 \cdot 10^{+21}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.1000000000000001e34 or 8.8e21 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 80.0%
if -1.1000000000000001e34 < z < -4.40000000000000003e-242 or 2.19999999999999998e-211 < z < 2.79999999999999993e-56 or 2.30000000000000009e-26 < z < 8.8e21Initial program 100.0%
div-sub95.2%
associate-+r-95.2%
remove-double-neg95.2%
distribute-frac-neg95.2%
unsub-neg95.2%
associate--r+95.2%
+-commutative95.2%
distribute-frac-neg95.2%
sub-neg95.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 63.7%
if -4.40000000000000003e-242 < z < 2.19999999999999998e-211 or 2.79999999999999993e-56 < z < 2.30000000000000009e-26Initial program 100.0%
div-sub86.0%
associate-+r-86.0%
remove-double-neg86.0%
distribute-frac-neg86.0%
unsub-neg86.0%
associate--r+86.0%
+-commutative86.0%
distribute-frac-neg86.0%
sub-neg86.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 76.5%
Taylor expanded in z around 0 76.5%
mul-1-neg76.5%
distribute-frac-neg76.5%
Simplified76.5%
Final simplification72.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -4e+245) (not (<= x 6.5e+211))) (/ (- x) z) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4e+245) || !(x <= 6.5e+211)) {
tmp = -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 <= (-4d+245)) .or. (.not. (x <= 6.5d+211))) then
tmp = -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 <= -4e+245) || !(x <= 6.5e+211)) {
tmp = -x / z;
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4e+245) or not (x <= 6.5e+211): tmp = -x / z else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4e+245) || !(x <= 6.5e+211)) tmp = Float64(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 <= -4e+245) || ~((x <= 6.5e+211))) tmp = -x / z; else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4e+245], N[Not[LessEqual[x, 6.5e+211]], $MachinePrecision]], N[((-x) / z), $MachinePrecision], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+245} \lor \neg \left(x \leq 6.5 \cdot 10^{+211}\right):\\
\;\;\;\;\frac{-x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -4.00000000000000018e245 or 6.4999999999999996e211 < x Initial program 100.0%
div-sub82.5%
associate-+r-82.5%
remove-double-neg82.5%
distribute-frac-neg82.5%
unsub-neg82.5%
associate--r+82.5%
+-commutative82.5%
distribute-frac-neg82.5%
sub-neg82.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 95.0%
Taylor expanded in z around 0 70.8%
mul-1-neg70.8%
distribute-frac-neg70.8%
Simplified70.8%
if -4.00000000000000018e245 < x < 6.4999999999999996e211Initial program 100.0%
div-sub98.1%
associate-+r-98.1%
remove-double-neg98.1%
distribute-frac-neg98.1%
unsub-neg98.1%
associate--r+98.1%
+-commutative98.1%
distribute-frac-neg98.1%
sub-neg98.1%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 80.2%
neg-mul-180.2%
distribute-neg-frac80.2%
Simplified80.2%
sub-neg80.2%
distribute-frac-neg80.2%
remove-double-neg80.2%
+-commutative80.2%
Applied egg-rr80.2%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.2e+117) (not (<= x 0.0032))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e+117) || !(x <= 0.0032)) {
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 <= (-6.2d+117)) .or. (.not. (x <= 0.0032d0))) 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 <= -6.2e+117) || !(x <= 0.0032)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.2e+117) or not (x <= 0.0032): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e+117) || !(x <= 0.0032)) 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 <= -6.2e+117) || ~((x <= 0.0032))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e+117], N[Not[LessEqual[x, 0.0032]], $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 -6.2 \cdot 10^{+117} \lor \neg \left(x \leq 0.0032\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -6.1999999999999995e117 or 0.00320000000000000015 < x Initial program 100.0%
div-sub90.3%
associate-+r-90.3%
remove-double-neg90.3%
distribute-frac-neg90.3%
unsub-neg90.3%
associate--r+90.3%
+-commutative90.3%
distribute-frac-neg90.3%
sub-neg90.3%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 90.1%
if -6.1999999999999995e117 < x < 0.00320000000000000015Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 88.4%
neg-mul-188.4%
distribute-neg-frac88.4%
Simplified88.4%
sub-neg88.4%
distribute-frac-neg88.4%
remove-double-neg88.4%
+-commutative88.4%
Applied egg-rr88.4%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 2.15e-5))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 2.15e-5)) {
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 <= 2.15d-5))) 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 <= 2.15e-5)) {
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 <= 2.15e-5): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 2.15e-5)) 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 <= 2.15e-5))) 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, 2.15e-5]], $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 2.15 \cdot 10^{-5}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 2.1500000000000001e-5 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 98.3%
neg-mul-198.3%
distribute-neg-frac98.3%
Simplified98.3%
sub-neg98.3%
distribute-frac-neg98.3%
remove-double-neg98.3%
+-commutative98.3%
Applied egg-rr98.3%
if -1 < z < 2.1500000000000001e-5Initial program 100.0%
div-sub92.0%
associate-+r-92.0%
remove-double-neg92.0%
distribute-frac-neg92.0%
unsub-neg92.0%
associate--r+92.0%
+-commutative92.0%
distribute-frac-neg92.0%
sub-neg92.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 100.0%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= z -8.5e+33) x (if (<= z 8.5e+24) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.5e+33) {
tmp = x;
} else if (z <= 8.5e+24) {
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.5d+33)) then
tmp = x
else if (z <= 8.5d+24) 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.5e+33) {
tmp = x;
} else if (z <= 8.5e+24) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.5e+33: tmp = x elif z <= 8.5e+24: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.5e+33) tmp = x; elseif (z <= 8.5e+24) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.5e+33) tmp = x; elseif (z <= 8.5e+24) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.5e+33], x, If[LessEqual[z, 8.5e+24], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{+33}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{+24}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.4999999999999998e33 or 8.49999999999999959e24 < z Initial program 100.0%
div-sub100.0%
associate-+r-100.0%
remove-double-neg100.0%
distribute-frac-neg100.0%
unsub-neg100.0%
associate--r+100.0%
+-commutative100.0%
distribute-frac-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 80.0%
if -8.4999999999999998e33 < z < 8.49999999999999959e24Initial program 100.0%
div-sub92.6%
associate-+r-92.6%
remove-double-neg92.6%
distribute-frac-neg92.6%
unsub-neg92.6%
associate--r+92.6%
+-commutative92.6%
distribute-frac-neg92.6%
sub-neg92.6%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 53.6%
Final simplification64.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-sub95.7%
associate-+r-95.7%
remove-double-neg95.7%
distribute-frac-neg95.7%
unsub-neg95.7%
associate--r+95.7%
+-commutative95.7%
distribute-frac-neg95.7%
sub-neg95.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around inf 36.1%
Final simplification36.1%
herbie shell --seed 2024036
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))