
(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+109)
x
(if (<= z -1.9e-9)
(/ y z)
(if (<= z -4.2e-69)
t_0
(if (<= z -4.4e-129)
(/ y z)
(if (<= z -1.1e-164)
t_0
(if (<= z 4.9e-174) (/ y z) (if (<= z 0.42) t_0 x)))))))))
double code(double x, double y, double z) {
double t_0 = -x / z;
double tmp;
if (z <= -5.5e+109) {
tmp = x;
} else if (z <= -1.9e-9) {
tmp = y / z;
} else if (z <= -4.2e-69) {
tmp = t_0;
} else if (z <= -4.4e-129) {
tmp = y / z;
} else if (z <= -1.1e-164) {
tmp = t_0;
} else if (z <= 4.9e-174) {
tmp = y / z;
} else if (z <= 0.42) {
tmp = t_0;
} 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+109)) then
tmp = x
else if (z <= (-1.9d-9)) then
tmp = y / z
else if (z <= (-4.2d-69)) then
tmp = t_0
else if (z <= (-4.4d-129)) then
tmp = y / z
else if (z <= (-1.1d-164)) then
tmp = t_0
else if (z <= 4.9d-174) then
tmp = y / z
else if (z <= 0.42d0) then
tmp = t_0
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+109) {
tmp = x;
} else if (z <= -1.9e-9) {
tmp = y / z;
} else if (z <= -4.2e-69) {
tmp = t_0;
} else if (z <= -4.4e-129) {
tmp = y / z;
} else if (z <= -1.1e-164) {
tmp = t_0;
} else if (z <= 4.9e-174) {
tmp = y / z;
} else if (z <= 0.42) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = -x / z tmp = 0 if z <= -5.5e+109: tmp = x elif z <= -1.9e-9: tmp = y / z elif z <= -4.2e-69: tmp = t_0 elif z <= -4.4e-129: tmp = y / z elif z <= -1.1e-164: tmp = t_0 elif z <= 4.9e-174: tmp = y / z elif z <= 0.42: tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / z) tmp = 0.0 if (z <= -5.5e+109) tmp = x; elseif (z <= -1.9e-9) tmp = Float64(y / z); elseif (z <= -4.2e-69) tmp = t_0; elseif (z <= -4.4e-129) tmp = Float64(y / z); elseif (z <= -1.1e-164) tmp = t_0; elseif (z <= 4.9e-174) tmp = Float64(y / z); elseif (z <= 0.42) tmp = t_0; 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+109) tmp = x; elseif (z <= -1.9e-9) tmp = y / z; elseif (z <= -4.2e-69) tmp = t_0; elseif (z <= -4.4e-129) tmp = y / z; elseif (z <= -1.1e-164) tmp = t_0; elseif (z <= 4.9e-174) tmp = y / z; elseif (z <= 0.42) tmp = t_0; 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+109], x, If[LessEqual[z, -1.9e-9], N[(y / z), $MachinePrecision], If[LessEqual[z, -4.2e-69], t$95$0, If[LessEqual[z, -4.4e-129], N[(y / z), $MachinePrecision], If[LessEqual[z, -1.1e-164], t$95$0, If[LessEqual[z, 4.9e-174], N[(y / z), $MachinePrecision], If[LessEqual[z, 0.42], t$95$0, x]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{z}\\
\mathbf{if}\;z \leq -5.5 \cdot 10^{+109}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.9 \cdot 10^{-9}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -4.2 \cdot 10^{-69}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.4 \cdot 10^{-129}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq -1.1 \cdot 10^{-164}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 4.9 \cdot 10^{-174}:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{elif}\;z \leq 0.42:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.4999999999999998e109 or 0.419999999999999984 < 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 70.1%
if -5.4999999999999998e109 < z < -1.90000000000000006e-9 or -4.1999999999999999e-69 < z < -4.40000000000000006e-129 or -1.09999999999999994e-164 < z < 4.90000000000000009e-174Initial 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 x around 0 72.3%
if -1.90000000000000006e-9 < z < -4.1999999999999999e-69 or -4.40000000000000006e-129 < z < -1.09999999999999994e-164 or 4.90000000000000009e-174 < z < 0.419999999999999984Initial program 100.0%
div-sub93.2%
associate-+r-93.2%
remove-double-neg93.2%
distribute-frac-neg93.2%
unsub-neg93.2%
associate--r+93.2%
+-commutative93.2%
distribute-frac-neg93.2%
sub-neg93.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 69.3%
Taylor expanded in z around 0 67.5%
mul-1-neg67.5%
distribute-frac-neg67.5%
Simplified67.5%
Final simplification70.3%
(FPCore (x y z) :precision binary64 (if (or (<= x 1.8e+222) (not (<= x 1.2e+283))) (+ x (/ y z)) (/ (- x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= 1.8e+222) || !(x <= 1.2e+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 ((x <= 1.8d+222) .or. (.not. (x <= 1.2d+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 ((x <= 1.8e+222) || !(x <= 1.2e+283)) {
tmp = x + (y / z);
} else {
tmp = -x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= 1.8e+222) or not (x <= 1.2e+283): tmp = x + (y / z) else: tmp = -x / z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= 1.8e+222) || !(x <= 1.2e+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 ((x <= 1.8e+222) || ~((x <= 1.2e+283))) tmp = x + (y / z); else tmp = -x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, 1.8e+222], N[Not[LessEqual[x, 1.2e+283]], $MachinePrecision]], N[(x + N[(y / z), $MachinePrecision]), $MachinePrecision], N[((-x) / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.8 \cdot 10^{+222} \lor \neg \left(x \leq 1.2 \cdot 10^{+283}\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{z}\\
\end{array}
\end{array}
if x < 1.8000000000000001e222 or 1.19999999999999999e283 < x Initial program 100.0%
div-sub96.2%
associate-+r-96.2%
remove-double-neg96.2%
distribute-frac-neg96.2%
unsub-neg96.2%
associate--r+96.2%
+-commutative96.2%
distribute-frac-neg96.2%
sub-neg96.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 79.3%
neg-mul-179.3%
distribute-neg-frac79.3%
Simplified79.3%
sub-neg79.3%
distribute-frac-neg79.3%
remove-double-neg79.3%
+-commutative79.3%
Applied egg-rr79.3%
if 1.8000000000000001e222 < x < 1.19999999999999999e283Initial program 99.9%
div-sub87.3%
associate-+r-87.3%
remove-double-neg87.3%
distribute-frac-neg87.3%
unsub-neg87.3%
associate--r+87.3%
+-commutative87.3%
distribute-frac-neg87.3%
sub-neg87.3%
div-sub99.9%
Simplified99.9%
Taylor expanded in x around inf 94.3%
Taylor expanded in z around 0 69.2%
mul-1-neg69.2%
distribute-frac-neg69.2%
Simplified69.2%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.3e+69) (not (<= x 7e+96))) (- x (/ x z)) (+ x (/ y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.3e+69) || !(x <= 7e+96)) {
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.3d+69)) .or. (.not. (x <= 7d+96))) 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.3e+69) || !(x <= 7e+96)) {
tmp = x - (x / z);
} else {
tmp = x + (y / z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.3e+69) or not (x <= 7e+96): tmp = x - (x / z) else: tmp = x + (y / z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.3e+69) || !(x <= 7e+96)) 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.3e+69) || ~((x <= 7e+96))) tmp = x - (x / z); else tmp = x + (y / z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.3e+69], N[Not[LessEqual[x, 7e+96]], $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.3 \cdot 10^{+69} \lor \neg \left(x \leq 7 \cdot 10^{+96}\right):\\
\;\;\;\;x - \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{z}\\
\end{array}
\end{array}
if x < -1.3000000000000001e69 or 6.9999999999999998e96 < x Initial program 100.0%
div-sub91.5%
associate-+r-91.5%
remove-double-neg91.5%
distribute-frac-neg91.5%
unsub-neg91.5%
associate--r+91.5%
+-commutative91.5%
distribute-frac-neg91.5%
sub-neg91.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 91.1%
if -1.3000000000000001e69 < x < 6.9999999999999998e96Initial program 100.0%
div-sub98.7%
associate-+r-98.6%
remove-double-neg98.6%
distribute-frac-neg98.6%
unsub-neg98.6%
associate--r+98.7%
+-commutative98.7%
distribute-frac-neg98.7%
sub-neg98.7%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 85.9%
neg-mul-185.9%
distribute-neg-frac85.9%
Simplified85.9%
sub-neg85.9%
distribute-frac-neg85.9%
remove-double-neg85.9%
+-commutative85.9%
Applied egg-rr85.9%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 0.42))) (+ x (/ y z)) (/ (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 0.42)) {
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 <= 0.42d0))) 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 <= 0.42)) {
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 <= 0.42): tmp = x + (y / z) else: tmp = (y - x) / z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 0.42)) 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 <= 0.42))) 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, 0.42]], $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 0.42\right):\\
\;\;\;\;x + \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{y - x}{z}\\
\end{array}
\end{array}
if z < -1 or 0.419999999999999984 < 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 96.3%
neg-mul-196.3%
distribute-neg-frac96.3%
Simplified96.3%
sub-neg96.3%
distribute-frac-neg96.3%
remove-double-neg96.3%
+-commutative96.3%
Applied egg-rr96.3%
if -1 < z < 0.419999999999999984Initial program 100.0%
div-sub91.2%
associate-+r-91.2%
remove-double-neg91.2%
distribute-frac-neg91.2%
unsub-neg91.2%
associate--r+91.2%
+-commutative91.2%
distribute-frac-neg91.2%
sub-neg91.2%
div-sub100.0%
Simplified100.0%
Taylor expanded in z around 0 98.6%
Final simplification97.4%
(FPCore (x y z) :precision binary64 (if (<= z -6.6e+116) x (if (<= z 2.2) (/ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.6e+116) {
tmp = x;
} else if (z <= 2.2) {
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 <= (-6.6d+116)) then
tmp = x
else if (z <= 2.2d0) 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 <= -6.6e+116) {
tmp = x;
} else if (z <= 2.2) {
tmp = y / z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.6e+116: tmp = x elif z <= 2.2: tmp = y / z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.6e+116) tmp = x; elseif (z <= 2.2) tmp = Float64(y / z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.6e+116) tmp = x; elseif (z <= 2.2) tmp = y / z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.6e+116], x, If[LessEqual[z, 2.2], N[(y / z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{+116}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.2:\\
\;\;\;\;\frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.5999999999999996e116 or 2.2000000000000002 < 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 70.7%
if -6.5999999999999996e116 < z < 2.2000000000000002Initial program 100.0%
div-sub92.5%
associate-+r-92.5%
remove-double-neg92.5%
distribute-frac-neg92.5%
unsub-neg92.5%
associate--r+92.5%
+-commutative92.5%
distribute-frac-neg92.5%
sub-neg92.5%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 56.4%
Final simplification62.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-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 34.4%
Final simplification34.4%
herbie shell --seed 2024021
(FPCore (x y z)
:name "Statistics.Sample:$swelfordMean from math-functions-0.1.5.2"
:precision binary64
(+ x (/ (- y x) z)))