
(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 (/ 1.0 (/ (- n f) (+ n f))))
double code(double f, double n) {
return 1.0 / ((n - f) / (n + f));
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
code = 1.0d0 / ((n - f) / (n + f))
end function
public static double code(double f, double n) {
return 1.0 / ((n - f) / (n + f));
}
def code(f, n): return 1.0 / ((n - f) / (n + f))
function code(f, n) return Float64(1.0 / Float64(Float64(n - f) / Float64(n + f))) end
function tmp = code(f, n) tmp = 1.0 / ((n - f) / (n + f)); end
code[f_, n_] := N[(1.0 / N[(N[(n - f), $MachinePrecision] / N[(n + f), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{n - f}{n + f}}
\end{array}
Initial program 99.9%
neg-mul-199.9%
*-commutative99.9%
associate-/l*99.9%
div-sub99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
div-sub99.9%
unsub-neg99.9%
remove-double-neg99.9%
+-commutative99.9%
sub-neg99.9%
metadata-eval99.9%
/-rgt-identity99.9%
Simplified99.9%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
unpow-199.9%
+-commutative99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (f n) :precision binary64 (if (or (<= n -2.1e+23) (not (<= n 4.8e+23))) (+ 1.0 (* 2.0 (/ f n))) (/ (- f) (- f n))))
double code(double f, double n) {
double tmp;
if ((n <= -2.1e+23) || !(n <= 4.8e+23)) {
tmp = 1.0 + (2.0 * (f / n));
} else {
tmp = -f / (f - n);
}
return tmp;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
real(8) :: tmp
if ((n <= (-2.1d+23)) .or. (.not. (n <= 4.8d+23))) then
tmp = 1.0d0 + (2.0d0 * (f / n))
else
tmp = -f / (f - n)
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if ((n <= -2.1e+23) || !(n <= 4.8e+23)) {
tmp = 1.0 + (2.0 * (f / n));
} else {
tmp = -f / (f - n);
}
return tmp;
}
def code(f, n): tmp = 0 if (n <= -2.1e+23) or not (n <= 4.8e+23): tmp = 1.0 + (2.0 * (f / n)) else: tmp = -f / (f - n) return tmp
function code(f, n) tmp = 0.0 if ((n <= -2.1e+23) || !(n <= 4.8e+23)) tmp = Float64(1.0 + Float64(2.0 * Float64(f / n))); else tmp = Float64(Float64(-f) / Float64(f - n)); end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if ((n <= -2.1e+23) || ~((n <= 4.8e+23))) tmp = 1.0 + (2.0 * (f / n)); else tmp = -f / (f - n); end tmp_2 = tmp; end
code[f_, n_] := If[Or[LessEqual[n, -2.1e+23], N[Not[LessEqual[n, 4.8e+23]], $MachinePrecision]], N[(1.0 + N[(2.0 * N[(f / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-f) / N[(f - n), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -2.1 \cdot 10^{+23} \lor \neg \left(n \leq 4.8 \cdot 10^{+23}\right):\\
\;\;\;\;1 + 2 \cdot \frac{f}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{-f}{f - n}\\
\end{array}
\end{array}
if n < -2.1000000000000001e23 or 4.8e23 < n Initial program 99.9%
neg-mul-199.9%
*-commutative99.9%
associate-/l*99.9%
div-sub99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
div-sub99.9%
unsub-neg99.9%
remove-double-neg99.9%
+-commutative99.9%
sub-neg99.9%
metadata-eval99.9%
/-rgt-identity99.9%
Simplified99.9%
Taylor expanded in f around 0 79.3%
if -2.1000000000000001e23 < n < 4.8e23Initial program 100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
div-sub100.0%
unsub-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
/-rgt-identity100.0%
Simplified100.0%
clear-num99.9%
inv-pow99.9%
flip-+63.0%
associate-/r/62.9%
unpow-prod-down62.7%
inv-pow62.7%
Applied egg-rr62.7%
associate-*r/62.8%
*-rgt-identity62.8%
unpow-162.8%
associate-/r/62.8%
Simplified62.8%
Taylor expanded in n around 0 77.7%
mul-1-neg77.7%
Simplified77.7%
Final simplification78.5%
(FPCore (f n) :precision binary64 (if (or (<= n -1.8e+24) (not (<= n 6.2e+23))) (+ 1.0 (/ f n)) (/ (- f) (- f n))))
double code(double f, double n) {
double tmp;
if ((n <= -1.8e+24) || !(n <= 6.2e+23)) {
tmp = 1.0 + (f / n);
} else {
tmp = -f / (f - n);
}
return tmp;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
real(8) :: tmp
if ((n <= (-1.8d+24)) .or. (.not. (n <= 6.2d+23))) then
tmp = 1.0d0 + (f / n)
else
tmp = -f / (f - n)
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if ((n <= -1.8e+24) || !(n <= 6.2e+23)) {
tmp = 1.0 + (f / n);
} else {
tmp = -f / (f - n);
}
return tmp;
}
def code(f, n): tmp = 0 if (n <= -1.8e+24) or not (n <= 6.2e+23): tmp = 1.0 + (f / n) else: tmp = -f / (f - n) return tmp
function code(f, n) tmp = 0.0 if ((n <= -1.8e+24) || !(n <= 6.2e+23)) tmp = Float64(1.0 + Float64(f / n)); else tmp = Float64(Float64(-f) / Float64(f - n)); end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if ((n <= -1.8e+24) || ~((n <= 6.2e+23))) tmp = 1.0 + (f / n); else tmp = -f / (f - n); end tmp_2 = tmp; end
code[f_, n_] := If[Or[LessEqual[n, -1.8e+24], N[Not[LessEqual[n, 6.2e+23]], $MachinePrecision]], N[(1.0 + N[(f / n), $MachinePrecision]), $MachinePrecision], N[((-f) / N[(f - n), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.8 \cdot 10^{+24} \lor \neg \left(n \leq 6.2 \cdot 10^{+23}\right):\\
\;\;\;\;1 + \frac{f}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{-f}{f - n}\\
\end{array}
\end{array}
if n < -1.79999999999999992e24 or 6.19999999999999941e23 < n Initial program 99.9%
neg-mul-199.9%
*-commutative99.9%
associate-/l*99.9%
div-sub99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
div-sub99.9%
unsub-neg99.9%
remove-double-neg99.9%
+-commutative99.9%
sub-neg99.9%
metadata-eval99.9%
/-rgt-identity99.9%
Simplified99.9%
clear-num100.0%
inv-pow100.0%
flip-+42.0%
associate-/r/42.0%
unpow-prod-down41.9%
inv-pow41.9%
Applied egg-rr41.9%
associate-*r/41.8%
*-rgt-identity41.8%
unpow-141.8%
associate-/r/41.9%
Simplified41.9%
Taylor expanded in n around inf 78.2%
neg-mul-178.2%
Simplified78.2%
Taylor expanded in n around inf 78.4%
if -1.79999999999999992e24 < n < 6.19999999999999941e23Initial program 100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
div-sub100.0%
unsub-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
/-rgt-identity100.0%
Simplified100.0%
clear-num99.9%
inv-pow99.9%
flip-+63.0%
associate-/r/62.9%
unpow-prod-down62.7%
inv-pow62.7%
Applied egg-rr62.7%
associate-*r/62.8%
*-rgt-identity62.8%
unpow-162.8%
associate-/r/62.8%
Simplified62.8%
Taylor expanded in n around 0 77.7%
mul-1-neg77.7%
Simplified77.7%
Final simplification78.0%
(FPCore (f n) :precision binary64 (if (<= n -3.5e+24) (+ 1.0 (/ f n)) (if (<= n 3.1e+23) (/ (- f) (- f n)) (/ (- n) (- f n)))))
double code(double f, double n) {
double tmp;
if (n <= -3.5e+24) {
tmp = 1.0 + (f / n);
} else if (n <= 3.1e+23) {
tmp = -f / (f - n);
} else {
tmp = -n / (f - n);
}
return tmp;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
real(8) :: tmp
if (n <= (-3.5d+24)) then
tmp = 1.0d0 + (f / n)
else if (n <= 3.1d+23) then
tmp = -f / (f - n)
else
tmp = -n / (f - n)
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if (n <= -3.5e+24) {
tmp = 1.0 + (f / n);
} else if (n <= 3.1e+23) {
tmp = -f / (f - n);
} else {
tmp = -n / (f - n);
}
return tmp;
}
def code(f, n): tmp = 0 if n <= -3.5e+24: tmp = 1.0 + (f / n) elif n <= 3.1e+23: tmp = -f / (f - n) else: tmp = -n / (f - n) return tmp
function code(f, n) tmp = 0.0 if (n <= -3.5e+24) tmp = Float64(1.0 + Float64(f / n)); elseif (n <= 3.1e+23) tmp = Float64(Float64(-f) / Float64(f - n)); else tmp = Float64(Float64(-n) / Float64(f - n)); end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if (n <= -3.5e+24) tmp = 1.0 + (f / n); elseif (n <= 3.1e+23) tmp = -f / (f - n); else tmp = -n / (f - n); end tmp_2 = tmp; end
code[f_, n_] := If[LessEqual[n, -3.5e+24], N[(1.0 + N[(f / n), $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 3.1e+23], N[((-f) / N[(f - n), $MachinePrecision]), $MachinePrecision], N[((-n) / N[(f - n), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -3.5 \cdot 10^{+24}:\\
\;\;\;\;1 + \frac{f}{n}\\
\mathbf{elif}\;n \leq 3.1 \cdot 10^{+23}:\\
\;\;\;\;\frac{-f}{f - n}\\
\mathbf{else}:\\
\;\;\;\;\frac{-n}{f - n}\\
\end{array}
\end{array}
if n < -3.5000000000000002e24Initial program 99.9%
neg-mul-199.9%
*-commutative99.9%
associate-/l*99.9%
div-sub99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
div-sub99.9%
unsub-neg99.9%
remove-double-neg99.9%
+-commutative99.9%
sub-neg99.9%
metadata-eval99.9%
/-rgt-identity99.9%
Simplified99.9%
clear-num100.0%
inv-pow100.0%
flip-+43.1%
associate-/r/43.0%
unpow-prod-down42.8%
inv-pow42.8%
Applied egg-rr42.8%
associate-*r/42.8%
*-rgt-identity42.8%
unpow-142.8%
associate-/r/42.8%
Simplified42.8%
Taylor expanded in n around inf 77.2%
neg-mul-177.2%
Simplified77.2%
Taylor expanded in n around inf 77.7%
if -3.5000000000000002e24 < n < 3.09999999999999971e23Initial program 100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
div-sub100.0%
unsub-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
/-rgt-identity100.0%
Simplified100.0%
clear-num99.9%
inv-pow99.9%
flip-+63.0%
associate-/r/62.9%
unpow-prod-down62.7%
inv-pow62.7%
Applied egg-rr62.7%
associate-*r/62.8%
*-rgt-identity62.8%
unpow-162.8%
associate-/r/62.8%
Simplified62.8%
Taylor expanded in n around 0 77.7%
mul-1-neg77.7%
Simplified77.7%
if 3.09999999999999971e23 < n Initial program 100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
div-sub100.0%
unsub-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
/-rgt-identity100.0%
Simplified100.0%
clear-num100.0%
inv-pow100.0%
flip-+41.0%
associate-/r/41.0%
unpow-prod-down40.8%
inv-pow40.8%
Applied egg-rr40.8%
associate-*r/40.8%
*-rgt-identity40.8%
unpow-140.8%
associate-/r/40.8%
Simplified40.8%
Taylor expanded in n around inf 79.3%
neg-mul-179.3%
Simplified79.3%
Final simplification78.1%
(FPCore (f n) :precision binary64 (if (or (<= n -2.3e+22) (not (<= n 1.16e+24))) (+ 1.0 (/ f n)) -1.0))
double code(double f, double n) {
double tmp;
if ((n <= -2.3e+22) || !(n <= 1.16e+24)) {
tmp = 1.0 + (f / n);
} 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 ((n <= (-2.3d+22)) .or. (.not. (n <= 1.16d+24))) then
tmp = 1.0d0 + (f / n)
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if ((n <= -2.3e+22) || !(n <= 1.16e+24)) {
tmp = 1.0 + (f / n);
} else {
tmp = -1.0;
}
return tmp;
}
def code(f, n): tmp = 0 if (n <= -2.3e+22) or not (n <= 1.16e+24): tmp = 1.0 + (f / n) else: tmp = -1.0 return tmp
function code(f, n) tmp = 0.0 if ((n <= -2.3e+22) || !(n <= 1.16e+24)) tmp = Float64(1.0 + Float64(f / n)); else tmp = -1.0; end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if ((n <= -2.3e+22) || ~((n <= 1.16e+24))) tmp = 1.0 + (f / n); else tmp = -1.0; end tmp_2 = tmp; end
code[f_, n_] := If[Or[LessEqual[n, -2.3e+22], N[Not[LessEqual[n, 1.16e+24]], $MachinePrecision]], N[(1.0 + N[(f / n), $MachinePrecision]), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -2.3 \cdot 10^{+22} \lor \neg \left(n \leq 1.16 \cdot 10^{+24}\right):\\
\;\;\;\;1 + \frac{f}{n}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if n < -2.3000000000000002e22 or 1.16000000000000005e24 < n Initial program 99.9%
neg-mul-199.9%
*-commutative99.9%
associate-/l*99.9%
div-sub99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
div-sub99.9%
unsub-neg99.9%
remove-double-neg99.9%
+-commutative99.9%
sub-neg99.9%
metadata-eval99.9%
/-rgt-identity99.9%
Simplified99.9%
clear-num100.0%
inv-pow100.0%
flip-+42.0%
associate-/r/42.0%
unpow-prod-down41.9%
inv-pow41.9%
Applied egg-rr41.9%
associate-*r/41.8%
*-rgt-identity41.8%
unpow-141.8%
associate-/r/41.9%
Simplified41.9%
Taylor expanded in n around inf 78.2%
neg-mul-178.2%
Simplified78.2%
Taylor expanded in n around inf 78.4%
if -2.3000000000000002e22 < n < 1.16000000000000005e24Initial program 100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
div-sub100.0%
unsub-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
/-rgt-identity100.0%
Simplified100.0%
Taylor expanded in f around inf 76.8%
Final simplification77.6%
(FPCore (f n) :precision binary64 (if (or (<= n -1.25e+23) (not (<= n 6.8e+25))) (+ 1.0 (/ f n)) (- -1.0 (/ n f))))
double code(double f, double n) {
double tmp;
if ((n <= -1.25e+23) || !(n <= 6.8e+25)) {
tmp = 1.0 + (f / n);
} else {
tmp = -1.0 - (n / f);
}
return tmp;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
real(8) :: tmp
if ((n <= (-1.25d+23)) .or. (.not. (n <= 6.8d+25))) then
tmp = 1.0d0 + (f / n)
else
tmp = (-1.0d0) - (n / f)
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if ((n <= -1.25e+23) || !(n <= 6.8e+25)) {
tmp = 1.0 + (f / n);
} else {
tmp = -1.0 - (n / f);
}
return tmp;
}
def code(f, n): tmp = 0 if (n <= -1.25e+23) or not (n <= 6.8e+25): tmp = 1.0 + (f / n) else: tmp = -1.0 - (n / f) return tmp
function code(f, n) tmp = 0.0 if ((n <= -1.25e+23) || !(n <= 6.8e+25)) tmp = Float64(1.0 + Float64(f / n)); else tmp = Float64(-1.0 - Float64(n / f)); end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if ((n <= -1.25e+23) || ~((n <= 6.8e+25))) tmp = 1.0 + (f / n); else tmp = -1.0 - (n / f); end tmp_2 = tmp; end
code[f_, n_] := If[Or[LessEqual[n, -1.25e+23], N[Not[LessEqual[n, 6.8e+25]], $MachinePrecision]], N[(1.0 + N[(f / n), $MachinePrecision]), $MachinePrecision], N[(-1.0 - N[(n / f), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.25 \cdot 10^{+23} \lor \neg \left(n \leq 6.8 \cdot 10^{+25}\right):\\
\;\;\;\;1 + \frac{f}{n}\\
\mathbf{else}:\\
\;\;\;\;-1 - \frac{n}{f}\\
\end{array}
\end{array}
if n < -1.25e23 or 6.79999999999999967e25 < n Initial program 99.9%
neg-mul-199.9%
*-commutative99.9%
associate-/l*99.9%
div-sub99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
div-sub99.9%
unsub-neg99.9%
remove-double-neg99.9%
+-commutative99.9%
sub-neg99.9%
metadata-eval99.9%
/-rgt-identity99.9%
Simplified99.9%
clear-num100.0%
inv-pow100.0%
flip-+42.0%
associate-/r/42.0%
unpow-prod-down41.9%
inv-pow41.9%
Applied egg-rr41.9%
associate-*r/41.8%
*-rgt-identity41.8%
unpow-141.8%
associate-/r/41.9%
Simplified41.9%
Taylor expanded in n around inf 78.2%
neg-mul-178.2%
Simplified78.2%
Taylor expanded in n around inf 78.4%
if -1.25e23 < n < 6.79999999999999967e25Initial program 100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
div-sub100.0%
unsub-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
/-rgt-identity100.0%
Simplified100.0%
clear-num99.9%
inv-pow99.9%
flip-+63.0%
associate-/r/62.9%
unpow-prod-down62.7%
inv-pow62.7%
Applied egg-rr62.7%
associate-*r/62.8%
*-rgt-identity62.8%
unpow-162.8%
associate-/r/62.8%
Simplified62.8%
Taylor expanded in n around 0 77.7%
mul-1-neg77.7%
Simplified77.7%
Taylor expanded in f around inf 77.4%
fma-neg77.4%
metadata-eval77.4%
*-rgt-identity77.4%
metadata-eval77.4%
rem-square-sqrt0.0%
unpow20.0%
rem-square-sqrt0.0%
unpow20.0%
pow-sqr0.0%
metadata-eval0.0%
*-commutative0.0%
metadata-eval0.0%
rem-square-sqrt0.0%
unpow20.0%
fma-def0.0%
+-commutative0.0%
mul-1-neg0.0%
unsub-neg0.0%
unpow20.0%
rem-square-sqrt0.0%
metadata-eval0.0%
Simplified77.4%
Final simplification77.9%
(FPCore (f n) :precision binary64 (/ (+ n f) (- n f)))
double code(double f, double n) {
return (n + f) / (n - f);
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
code = (n + f) / (n - f)
end function
public static double code(double f, double n) {
return (n + f) / (n - f);
}
def code(f, n): return (n + f) / (n - f)
function code(f, n) return Float64(Float64(n + f) / Float64(n - f)) end
function tmp = code(f, n) tmp = (n + f) / (n - f); end
code[f_, n_] := N[(N[(n + f), $MachinePrecision] / N[(n - f), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{n + f}{n - f}
\end{array}
Initial program 99.9%
neg-mul-199.9%
*-commutative99.9%
associate-/l*99.9%
div-sub99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
div-sub99.9%
unsub-neg99.9%
remove-double-neg99.9%
+-commutative99.9%
sub-neg99.9%
metadata-eval99.9%
/-rgt-identity99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (f n) :precision binary64 (if (<= n -1.8e+24) 1.0 (if (<= n 2e+27) -1.0 1.0)))
double code(double f, double n) {
double tmp;
if (n <= -1.8e+24) {
tmp = 1.0;
} else if (n <= 2e+27) {
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 (n <= (-1.8d+24)) then
tmp = 1.0d0
else if (n <= 2d+27) 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 (n <= -1.8e+24) {
tmp = 1.0;
} else if (n <= 2e+27) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(f, n): tmp = 0 if n <= -1.8e+24: tmp = 1.0 elif n <= 2e+27: tmp = -1.0 else: tmp = 1.0 return tmp
function code(f, n) tmp = 0.0 if (n <= -1.8e+24) tmp = 1.0; elseif (n <= 2e+27) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if (n <= -1.8e+24) tmp = 1.0; elseif (n <= 2e+27) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[f_, n_] := If[LessEqual[n, -1.8e+24], 1.0, If[LessEqual[n, 2e+27], -1.0, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.8 \cdot 10^{+24}:\\
\;\;\;\;1\\
\mathbf{elif}\;n \leq 2 \cdot 10^{+27}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if n < -1.79999999999999992e24 or 2e27 < n Initial program 99.9%
neg-mul-199.9%
*-commutative99.9%
associate-/l*99.9%
div-sub99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
div-sub99.9%
unsub-neg99.9%
remove-double-neg99.9%
+-commutative99.9%
sub-neg99.9%
metadata-eval99.9%
/-rgt-identity99.9%
Simplified99.9%
Taylor expanded in f around 0 77.7%
if -1.79999999999999992e24 < n < 2e27Initial program 100.0%
neg-mul-1100.0%
*-commutative100.0%
associate-/l*100.0%
div-sub100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-/l*100.0%
*-commutative100.0%
neg-mul-1100.0%
div-sub100.0%
unsub-neg100.0%
remove-double-neg100.0%
+-commutative100.0%
sub-neg100.0%
metadata-eval100.0%
/-rgt-identity100.0%
Simplified100.0%
Taylor expanded in f around inf 76.8%
Final simplification77.3%
(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%
neg-mul-199.9%
*-commutative99.9%
associate-/l*99.9%
div-sub99.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
metadata-eval99.9%
metadata-eval99.9%
associate-/l*99.9%
*-commutative99.9%
neg-mul-199.9%
div-sub99.9%
unsub-neg99.9%
remove-double-neg99.9%
+-commutative99.9%
sub-neg99.9%
metadata-eval99.9%
/-rgt-identity99.9%
Simplified99.9%
Taylor expanded in f around inf 48.5%
Final simplification48.5%
herbie shell --seed 2023172
(FPCore (f n)
:name "subtraction fraction"
:precision binary64
(/ (- (+ f n)) (- f n)))