
(FPCore (f n) :precision binary64 (/ (- (+ f n)) (- f n)))
double code(double f, double n) {
return -(f + n) / (f - n);
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
code = -(f + n) / (f - n)
end function
public static double code(double f, double n) {
return -(f + n) / (f - n);
}
def code(f, n): return -(f + n) / (f - n)
function code(f, n) return Float64(Float64(-Float64(f + n)) / Float64(f - n)) end
function tmp = code(f, n) tmp = -(f + n) / (f - n); end
code[f_, n_] := N[((-N[(f + n), $MachinePrecision]) / N[(f - n), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-\left(f + n\right)}{f - n}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (f n) :precision binary64 (/ (- (+ f n)) (- f n)))
double code(double f, double n) {
return -(f + n) / (f - n);
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
code = -(f + n) / (f - n)
end function
public static double code(double f, double n) {
return -(f + n) / (f - n);
}
def code(f, n): return -(f + n) / (f - n)
function code(f, n) return Float64(Float64(-Float64(f + n)) / Float64(f - n)) end
function tmp = code(f, n) tmp = -(f + n) / (f - n); end
code[f_, n_] := N[((-N[(f + n), $MachinePrecision]) / N[(f - n), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-\left(f + n\right)}{f - n}
\end{array}
(FPCore (f n) :precision binary64 (cbrt (pow (/ (+ f n) (- n f)) 3.0)))
double code(double f, double n) {
return cbrt(pow(((f + n) / (n - f)), 3.0));
}
public static double code(double f, double n) {
return Math.cbrt(Math.pow(((f + n) / (n - f)), 3.0));
}
function code(f, n) return cbrt((Float64(Float64(f + n) / Float64(n - f)) ^ 3.0)) end
code[f_, n_] := N[Power[N[Power[N[(N[(f + n), $MachinePrecision] / N[(n - f), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{{\left(\frac{f + n}{n - f}\right)}^{3}}
\end{array}
Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
add-cbrt-cube99.9%
pow399.9%
Applied egg-rr99.9%
(FPCore (f n) :precision binary64 (if (or (<= f -4.2e+26) (not (<= f 6.5e+37))) (+ (* -2.0 (/ n f)) -1.0) (+ 1.0 (/ (* f 2.0) n))))
double code(double f, double n) {
double tmp;
if ((f <= -4.2e+26) || !(f <= 6.5e+37)) {
tmp = (-2.0 * (n / f)) + -1.0;
} else {
tmp = 1.0 + ((f * 2.0) / n);
}
return tmp;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
real(8) :: tmp
if ((f <= (-4.2d+26)) .or. (.not. (f <= 6.5d+37))) then
tmp = ((-2.0d0) * (n / f)) + (-1.0d0)
else
tmp = 1.0d0 + ((f * 2.0d0) / n)
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if ((f <= -4.2e+26) || !(f <= 6.5e+37)) {
tmp = (-2.0 * (n / f)) + -1.0;
} else {
tmp = 1.0 + ((f * 2.0) / n);
}
return tmp;
}
def code(f, n): tmp = 0 if (f <= -4.2e+26) or not (f <= 6.5e+37): tmp = (-2.0 * (n / f)) + -1.0 else: tmp = 1.0 + ((f * 2.0) / n) return tmp
function code(f, n) tmp = 0.0 if ((f <= -4.2e+26) || !(f <= 6.5e+37)) tmp = Float64(Float64(-2.0 * Float64(n / f)) + -1.0); else tmp = Float64(1.0 + Float64(Float64(f * 2.0) / n)); end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if ((f <= -4.2e+26) || ~((f <= 6.5e+37))) tmp = (-2.0 * (n / f)) + -1.0; else tmp = 1.0 + ((f * 2.0) / n); end tmp_2 = tmp; end
code[f_, n_] := If[Or[LessEqual[f, -4.2e+26], N[Not[LessEqual[f, 6.5e+37]], $MachinePrecision]], N[(N[(-2.0 * N[(n / f), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 + N[(N[(f * 2.0), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq -4.2 \cdot 10^{+26} \lor \neg \left(f \leq 6.5 \cdot 10^{+37}\right):\\
\;\;\;\;-2 \cdot \frac{n}{f} + -1\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{f \cdot 2}{n}\\
\end{array}
\end{array}
if f < -4.2000000000000002e26 or 6.4999999999999998e37 < f Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in n around 0 80.7%
if -4.2000000000000002e26 < f < 6.4999999999999998e37Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in f around 0 73.3%
associate-*r/73.3%
Simplified73.3%
Final simplification76.9%
(FPCore (f n) :precision binary64 (if (or (<= f -3.6e+25) (not (<= f 2.8e+37))) (/ f (- n f)) (+ 1.0 (/ (* f 2.0) n))))
double code(double f, double n) {
double tmp;
if ((f <= -3.6e+25) || !(f <= 2.8e+37)) {
tmp = f / (n - f);
} else {
tmp = 1.0 + ((f * 2.0) / n);
}
return tmp;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
real(8) :: tmp
if ((f <= (-3.6d+25)) .or. (.not. (f <= 2.8d+37))) then
tmp = f / (n - f)
else
tmp = 1.0d0 + ((f * 2.0d0) / n)
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if ((f <= -3.6e+25) || !(f <= 2.8e+37)) {
tmp = f / (n - f);
} else {
tmp = 1.0 + ((f * 2.0) / n);
}
return tmp;
}
def code(f, n): tmp = 0 if (f <= -3.6e+25) or not (f <= 2.8e+37): tmp = f / (n - f) else: tmp = 1.0 + ((f * 2.0) / n) return tmp
function code(f, n) tmp = 0.0 if ((f <= -3.6e+25) || !(f <= 2.8e+37)) tmp = Float64(f / Float64(n - f)); else tmp = Float64(1.0 + Float64(Float64(f * 2.0) / n)); end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if ((f <= -3.6e+25) || ~((f <= 2.8e+37))) tmp = f / (n - f); else tmp = 1.0 + ((f * 2.0) / n); end tmp_2 = tmp; end
code[f_, n_] := If[Or[LessEqual[f, -3.6e+25], N[Not[LessEqual[f, 2.8e+37]], $MachinePrecision]], N[(f / N[(n - f), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(f * 2.0), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq -3.6 \cdot 10^{+25} \lor \neg \left(f \leq 2.8 \cdot 10^{+37}\right):\\
\;\;\;\;\frac{f}{n - f}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{f \cdot 2}{n}\\
\end{array}
\end{array}
if f < -3.60000000000000015e25 or 2.7999999999999998e37 < f Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in f around inf 80.5%
if -3.60000000000000015e25 < f < 2.7999999999999998e37Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in f around 0 73.3%
associate-*r/73.3%
Simplified73.3%
Final simplification76.8%
(FPCore (f n) :precision binary64 (if (or (<= f -1.4e+26) (not (<= f 5.2e+37))) (/ f (- n f)) (/ (+ f n) n)))
double code(double f, double n) {
double tmp;
if ((f <= -1.4e+26) || !(f <= 5.2e+37)) {
tmp = f / (n - f);
} else {
tmp = (f + n) / n;
}
return tmp;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
real(8) :: tmp
if ((f <= (-1.4d+26)) .or. (.not. (f <= 5.2d+37))) then
tmp = f / (n - f)
else
tmp = (f + n) / n
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if ((f <= -1.4e+26) || !(f <= 5.2e+37)) {
tmp = f / (n - f);
} else {
tmp = (f + n) / n;
}
return tmp;
}
def code(f, n): tmp = 0 if (f <= -1.4e+26) or not (f <= 5.2e+37): tmp = f / (n - f) else: tmp = (f + n) / n return tmp
function code(f, n) tmp = 0.0 if ((f <= -1.4e+26) || !(f <= 5.2e+37)) tmp = Float64(f / Float64(n - f)); else tmp = Float64(Float64(f + n) / n); end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if ((f <= -1.4e+26) || ~((f <= 5.2e+37))) tmp = f / (n - f); else tmp = (f + n) / n; end tmp_2 = tmp; end
code[f_, n_] := If[Or[LessEqual[f, -1.4e+26], N[Not[LessEqual[f, 5.2e+37]], $MachinePrecision]], N[(f / N[(n - f), $MachinePrecision]), $MachinePrecision], N[(N[(f + n), $MachinePrecision] / n), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq -1.4 \cdot 10^{+26} \lor \neg \left(f \leq 5.2 \cdot 10^{+37}\right):\\
\;\;\;\;\frac{f}{n - f}\\
\mathbf{else}:\\
\;\;\;\;\frac{f + n}{n}\\
\end{array}
\end{array}
if f < -1.4e26 or 5.1999999999999998e37 < f Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in f around inf 80.5%
if -1.4e26 < f < 5.1999999999999998e37Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in n around inf 99.9%
mul-1-neg99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in n around inf 72.7%
Final simplification76.5%
(FPCore (f n) :precision binary64 (if (or (<= f -4.2e+25) (not (<= f 3e-43))) (/ f (- n f)) (/ n (- n f))))
double code(double f, double n) {
double tmp;
if ((f <= -4.2e+25) || !(f <= 3e-43)) {
tmp = f / (n - f);
} else {
tmp = n / (n - f);
}
return tmp;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
real(8) :: tmp
if ((f <= (-4.2d+25)) .or. (.not. (f <= 3d-43))) then
tmp = f / (n - f)
else
tmp = n / (n - f)
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if ((f <= -4.2e+25) || !(f <= 3e-43)) {
tmp = f / (n - f);
} else {
tmp = n / (n - f);
}
return tmp;
}
def code(f, n): tmp = 0 if (f <= -4.2e+25) or not (f <= 3e-43): tmp = f / (n - f) else: tmp = n / (n - f) return tmp
function code(f, n) tmp = 0.0 if ((f <= -4.2e+25) || !(f <= 3e-43)) tmp = Float64(f / Float64(n - f)); else tmp = Float64(n / Float64(n - f)); end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if ((f <= -4.2e+25) || ~((f <= 3e-43))) tmp = f / (n - f); else tmp = n / (n - f); end tmp_2 = tmp; end
code[f_, n_] := If[Or[LessEqual[f, -4.2e+25], N[Not[LessEqual[f, 3e-43]], $MachinePrecision]], N[(f / N[(n - f), $MachinePrecision]), $MachinePrecision], N[(n / N[(n - f), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq -4.2 \cdot 10^{+25} \lor \neg \left(f \leq 3 \cdot 10^{-43}\right):\\
\;\;\;\;\frac{f}{n - f}\\
\mathbf{else}:\\
\;\;\;\;\frac{n}{n - f}\\
\end{array}
\end{array}
if f < -4.1999999999999998e25 or 3.00000000000000003e-43 < f Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in f around inf 77.9%
if -4.1999999999999998e25 < f < 3.00000000000000003e-43Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in f around 0 74.7%
Final simplification76.4%
(FPCore (f n) :precision binary64 (if (or (<= f -8.8e+26) (not (<= f 1.5e-44))) (/ f (- n f)) 1.0))
double code(double f, double n) {
double tmp;
if ((f <= -8.8e+26) || !(f <= 1.5e-44)) {
tmp = f / (n - f);
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
real(8) :: tmp
if ((f <= (-8.8d+26)) .or. (.not. (f <= 1.5d-44))) then
tmp = f / (n - f)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if ((f <= -8.8e+26) || !(f <= 1.5e-44)) {
tmp = f / (n - f);
} else {
tmp = 1.0;
}
return tmp;
}
def code(f, n): tmp = 0 if (f <= -8.8e+26) or not (f <= 1.5e-44): tmp = f / (n - f) else: tmp = 1.0 return tmp
function code(f, n) tmp = 0.0 if ((f <= -8.8e+26) || !(f <= 1.5e-44)) tmp = Float64(f / Float64(n - f)); else tmp = 1.0; end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if ((f <= -8.8e+26) || ~((f <= 1.5e-44))) tmp = f / (n - f); else tmp = 1.0; end tmp_2 = tmp; end
code[f_, n_] := If[Or[LessEqual[f, -8.8e+26], N[Not[LessEqual[f, 1.5e-44]], $MachinePrecision]], N[(f / N[(n - f), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq -8.8 \cdot 10^{+26} \lor \neg \left(f \leq 1.5 \cdot 10^{-44}\right):\\
\;\;\;\;\frac{f}{n - f}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if f < -8.80000000000000028e26 or 1.5000000000000001e-44 < f Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in f around inf 77.9%
if -8.80000000000000028e26 < f < 1.5000000000000001e-44Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in f around 0 73.9%
Final simplification76.1%
(FPCore (f n) :precision binary64 (if (<= f -3.5e+25) -1.0 (if (<= f 1e-44) 1.0 -1.0)))
double code(double f, double n) {
double tmp;
if (f <= -3.5e+25) {
tmp = -1.0;
} else if (f <= 1e-44) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
real(8) :: tmp
if (f <= (-3.5d+25)) then
tmp = -1.0d0
else if (f <= 1d-44) then
tmp = 1.0d0
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if (f <= -3.5e+25) {
tmp = -1.0;
} else if (f <= 1e-44) {
tmp = 1.0;
} else {
tmp = -1.0;
}
return tmp;
}
def code(f, n): tmp = 0 if f <= -3.5e+25: tmp = -1.0 elif f <= 1e-44: tmp = 1.0 else: tmp = -1.0 return tmp
function code(f, n) tmp = 0.0 if (f <= -3.5e+25) tmp = -1.0; elseif (f <= 1e-44) tmp = 1.0; else tmp = -1.0; end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if (f <= -3.5e+25) tmp = -1.0; elseif (f <= 1e-44) tmp = 1.0; else tmp = -1.0; end tmp_2 = tmp; end
code[f_, n_] := If[LessEqual[f, -3.5e+25], -1.0, If[LessEqual[f, 1e-44], 1.0, -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq -3.5 \cdot 10^{+25}:\\
\;\;\;\;-1\\
\mathbf{elif}\;f \leq 10^{-44}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if f < -3.49999999999999999e25 or 9.99999999999999953e-45 < f Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in f around inf 77.3%
if -3.49999999999999999e25 < f < 9.99999999999999953e-45Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in f around 0 73.9%
(FPCore (f n) :precision binary64 (/ (+ f n) (- n f)))
double code(double f, double n) {
return (f + n) / (n - f);
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
code = (f + n) / (n - f)
end function
public static double code(double f, double n) {
return (f + n) / (n - f);
}
def code(f, n): return (f + n) / (n - f)
function code(f, n) return Float64(Float64(f + n) / Float64(n - f)) end
function tmp = code(f, n) tmp = (f + n) / (n - f); end
code[f_, n_] := N[(N[(f + n), $MachinePrecision] / N[(n - f), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{f + n}{n - f}
\end{array}
Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
(FPCore (f n) :precision binary64 -1.0)
double code(double f, double n) {
return -1.0;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
code = -1.0d0
end function
public static double code(double f, double n) {
return -1.0;
}
def code(f, n): return -1.0
function code(f, n) return -1.0 end
function tmp = code(f, n) tmp = -1.0; end
code[f_, n_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 99.9%
distribute-frac-neg99.9%
distribute-neg-frac299.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
Taylor expanded in f around inf 52.5%
herbie shell --seed 2024116
(FPCore (f n)
:name "subtraction fraction"
:precision binary64
(/ (- (+ f n)) (- f n)))