
(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 8 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 (/ (+ 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 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
(FPCore (f n) :precision binary64 (if (<= n -4.8e-11) (/ n (- n f)) (if (<= n 3.4e-69) (+ -1.0 (/ (* n -2.0) f)) (/ (+ f n) n))))
double code(double f, double n) {
double tmp;
if (n <= -4.8e-11) {
tmp = n / (n - f);
} else if (n <= 3.4e-69) {
tmp = -1.0 + ((n * -2.0) / 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 (n <= (-4.8d-11)) then
tmp = n / (n - f)
else if (n <= 3.4d-69) then
tmp = (-1.0d0) + ((n * (-2.0d0)) / f)
else
tmp = (f + n) / n
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if (n <= -4.8e-11) {
tmp = n / (n - f);
} else if (n <= 3.4e-69) {
tmp = -1.0 + ((n * -2.0) / f);
} else {
tmp = (f + n) / n;
}
return tmp;
}
def code(f, n): tmp = 0 if n <= -4.8e-11: tmp = n / (n - f) elif n <= 3.4e-69: tmp = -1.0 + ((n * -2.0) / f) else: tmp = (f + n) / n return tmp
function code(f, n) tmp = 0.0 if (n <= -4.8e-11) tmp = Float64(n / Float64(n - f)); elseif (n <= 3.4e-69) tmp = Float64(-1.0 + Float64(Float64(n * -2.0) / f)); else tmp = Float64(Float64(f + n) / n); end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if (n <= -4.8e-11) tmp = n / (n - f); elseif (n <= 3.4e-69) tmp = -1.0 + ((n * -2.0) / f); else tmp = (f + n) / n; end tmp_2 = tmp; end
code[f_, n_] := If[LessEqual[n, -4.8e-11], N[(n / N[(n - f), $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 3.4e-69], N[(-1.0 + N[(N[(n * -2.0), $MachinePrecision] / f), $MachinePrecision]), $MachinePrecision], N[(N[(f + n), $MachinePrecision] / n), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -4.8 \cdot 10^{-11}:\\
\;\;\;\;\frac{n}{n - f}\\
\mathbf{elif}\;n \leq 3.4 \cdot 10^{-69}:\\
\;\;\;\;-1 + \frac{n \cdot -2}{f}\\
\mathbf{else}:\\
\;\;\;\;\frac{f + n}{n}\\
\end{array}
\end{array}
if n < -4.8000000000000002e-11Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around 0
Simplified85.7%
if -4.8000000000000002e-11 < n < 3.40000000000000008e-69Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around inf
+-commutativeN/A
associate--r+N/A
associate-*r/N/A
div-subN/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lft-identityN/A
distribute-rgt-out--N/A
metadata-evalN/A
*-lowering-*.f6478.7%
Simplified78.7%
if 3.40000000000000008e-69 < n Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in n around inf
Simplified76.6%
(FPCore (f n) :precision binary64 (if (<= n -1.2e-8) (/ n (- n f)) (if (<= n 7e-52) (/ f (- n f)) (/ (+ f n) n))))
double code(double f, double n) {
double tmp;
if (n <= -1.2e-8) {
tmp = n / (n - f);
} else if (n <= 7e-52) {
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 (n <= (-1.2d-8)) then
tmp = n / (n - f)
else if (n <= 7d-52) 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 (n <= -1.2e-8) {
tmp = n / (n - f);
} else if (n <= 7e-52) {
tmp = f / (n - f);
} else {
tmp = (f + n) / n;
}
return tmp;
}
def code(f, n): tmp = 0 if n <= -1.2e-8: tmp = n / (n - f) elif n <= 7e-52: tmp = f / (n - f) else: tmp = (f + n) / n return tmp
function code(f, n) tmp = 0.0 if (n <= -1.2e-8) tmp = Float64(n / Float64(n - f)); elseif (n <= 7e-52) 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 (n <= -1.2e-8) tmp = n / (n - f); elseif (n <= 7e-52) tmp = f / (n - f); else tmp = (f + n) / n; end tmp_2 = tmp; end
code[f_, n_] := If[LessEqual[n, -1.2e-8], N[(n / N[(n - f), $MachinePrecision]), $MachinePrecision], If[LessEqual[n, 7e-52], N[(f / N[(n - f), $MachinePrecision]), $MachinePrecision], N[(N[(f + n), $MachinePrecision] / n), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.2 \cdot 10^{-8}:\\
\;\;\;\;\frac{n}{n - f}\\
\mathbf{elif}\;n \leq 7 \cdot 10^{-52}:\\
\;\;\;\;\frac{f}{n - f}\\
\mathbf{else}:\\
\;\;\;\;\frac{f + n}{n}\\
\end{array}
\end{array}
if n < -1.19999999999999999e-8Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around 0
Simplified85.7%
if -1.19999999999999999e-8 < n < 7.0000000000000001e-52Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around inf
Simplified78.2%
if 7.0000000000000001e-52 < n Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in n around inf
Simplified77.3%
(FPCore (f n) :precision binary64 (let* ((t_0 (/ n (- n f)))) (if (<= n -9.5e-14) t_0 (if (<= n 1.2e-47) (/ f (- n f)) t_0))))
double code(double f, double n) {
double t_0 = n / (n - f);
double tmp;
if (n <= -9.5e-14) {
tmp = t_0;
} else if (n <= 1.2e-47) {
tmp = f / (n - f);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(f, n)
real(8), intent (in) :: f
real(8), intent (in) :: n
real(8) :: t_0
real(8) :: tmp
t_0 = n / (n - f)
if (n <= (-9.5d-14)) then
tmp = t_0
else if (n <= 1.2d-47) then
tmp = f / (n - f)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double f, double n) {
double t_0 = n / (n - f);
double tmp;
if (n <= -9.5e-14) {
tmp = t_0;
} else if (n <= 1.2e-47) {
tmp = f / (n - f);
} else {
tmp = t_0;
}
return tmp;
}
def code(f, n): t_0 = n / (n - f) tmp = 0 if n <= -9.5e-14: tmp = t_0 elif n <= 1.2e-47: tmp = f / (n - f) else: tmp = t_0 return tmp
function code(f, n) t_0 = Float64(n / Float64(n - f)) tmp = 0.0 if (n <= -9.5e-14) tmp = t_0; elseif (n <= 1.2e-47) tmp = Float64(f / Float64(n - f)); else tmp = t_0; end return tmp end
function tmp_2 = code(f, n) t_0 = n / (n - f); tmp = 0.0; if (n <= -9.5e-14) tmp = t_0; elseif (n <= 1.2e-47) tmp = f / (n - f); else tmp = t_0; end tmp_2 = tmp; end
code[f_, n_] := Block[{t$95$0 = N[(n / N[(n - f), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[n, -9.5e-14], t$95$0, If[LessEqual[n, 1.2e-47], N[(f / N[(n - f), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{n}{n - f}\\
\mathbf{if}\;n \leq -9.5 \cdot 10^{-14}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;n \leq 1.2 \cdot 10^{-47}:\\
\;\;\;\;\frac{f}{n - f}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if n < -9.4999999999999999e-14 or 1.2e-47 < n Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around 0
Simplified81.1%
if -9.4999999999999999e-14 < n < 1.2e-47Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around inf
Simplified78.2%
(FPCore (f n) :precision binary64 (if (<= n -2.5e+14) 1.0 (if (<= n 1e-50) (/ f (- n f)) 1.0)))
double code(double f, double n) {
double tmp;
if (n <= -2.5e+14) {
tmp = 1.0;
} else if (n <= 1e-50) {
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 (n <= (-2.5d+14)) then
tmp = 1.0d0
else if (n <= 1d-50) 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 (n <= -2.5e+14) {
tmp = 1.0;
} else if (n <= 1e-50) {
tmp = f / (n - f);
} else {
tmp = 1.0;
}
return tmp;
}
def code(f, n): tmp = 0 if n <= -2.5e+14: tmp = 1.0 elif n <= 1e-50: tmp = f / (n - f) else: tmp = 1.0 return tmp
function code(f, n) tmp = 0.0 if (n <= -2.5e+14) tmp = 1.0; elseif (n <= 1e-50) tmp = Float64(f / Float64(n - f)); else tmp = 1.0; end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if (n <= -2.5e+14) tmp = 1.0; elseif (n <= 1e-50) tmp = f / (n - f); else tmp = 1.0; end tmp_2 = tmp; end
code[f_, n_] := If[LessEqual[n, -2.5e+14], 1.0, If[LessEqual[n, 1e-50], N[(f / N[(n - f), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -2.5 \cdot 10^{+14}:\\
\;\;\;\;1\\
\mathbf{elif}\;n \leq 10^{-50}:\\
\;\;\;\;\frac{f}{n - f}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if n < -2.5e14 or 1.00000000000000001e-50 < n Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around 0
Simplified81.0%
if -2.5e14 < n < 1.00000000000000001e-50Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around inf
Simplified77.7%
(FPCore (f n) :precision binary64 (if (<= n -3.7e-10) 1.0 (if (<= n 2.7e-74) (- -1.0 (/ n f)) 1.0)))
double code(double f, double n) {
double tmp;
if (n <= -3.7e-10) {
tmp = 1.0;
} else if (n <= 2.7e-74) {
tmp = -1.0 - (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 (n <= (-3.7d-10)) then
tmp = 1.0d0
else if (n <= 2.7d-74) then
tmp = (-1.0d0) - (n / f)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double f, double n) {
double tmp;
if (n <= -3.7e-10) {
tmp = 1.0;
} else if (n <= 2.7e-74) {
tmp = -1.0 - (n / f);
} else {
tmp = 1.0;
}
return tmp;
}
def code(f, n): tmp = 0 if n <= -3.7e-10: tmp = 1.0 elif n <= 2.7e-74: tmp = -1.0 - (n / f) else: tmp = 1.0 return tmp
function code(f, n) tmp = 0.0 if (n <= -3.7e-10) tmp = 1.0; elseif (n <= 2.7e-74) tmp = Float64(-1.0 - Float64(n / f)); else tmp = 1.0; end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if (n <= -3.7e-10) tmp = 1.0; elseif (n <= 2.7e-74) tmp = -1.0 - (n / f); else tmp = 1.0; end tmp_2 = tmp; end
code[f_, n_] := If[LessEqual[n, -3.7e-10], 1.0, If[LessEqual[n, 2.7e-74], N[(-1.0 - N[(n / f), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -3.7 \cdot 10^{-10}:\\
\;\;\;\;1\\
\mathbf{elif}\;n \leq 2.7 \cdot 10^{-74}:\\
\;\;\;\;-1 - \frac{n}{f}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if n < -3.70000000000000015e-10 or 2.70000000000000018e-74 < n Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around 0
Simplified80.1%
if -3.70000000000000015e-10 < n < 2.70000000000000018e-74Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around inf
Simplified78.6%
Taylor expanded in f around inf
sub-negN/A
metadata-evalN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
--lowering--.f64N/A
/-lowering-/.f6478.5%
Simplified78.5%
(FPCore (f n) :precision binary64 (if (<= n -1.45e+14) 1.0 (if (<= n 3e-69) -1.0 1.0)))
double code(double f, double n) {
double tmp;
if (n <= -1.45e+14) {
tmp = 1.0;
} else if (n <= 3e-69) {
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.45d+14)) then
tmp = 1.0d0
else if (n <= 3d-69) 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.45e+14) {
tmp = 1.0;
} else if (n <= 3e-69) {
tmp = -1.0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(f, n): tmp = 0 if n <= -1.45e+14: tmp = 1.0 elif n <= 3e-69: tmp = -1.0 else: tmp = 1.0 return tmp
function code(f, n) tmp = 0.0 if (n <= -1.45e+14) tmp = 1.0; elseif (n <= 3e-69) tmp = -1.0; else tmp = 1.0; end return tmp end
function tmp_2 = code(f, n) tmp = 0.0; if (n <= -1.45e+14) tmp = 1.0; elseif (n <= 3e-69) tmp = -1.0; else tmp = 1.0; end tmp_2 = tmp; end
code[f_, n_] := If[LessEqual[n, -1.45e+14], 1.0, If[LessEqual[n, 3e-69], -1.0, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;n \leq -1.45 \cdot 10^{+14}:\\
\;\;\;\;1\\
\mathbf{elif}\;n \leq 3 \cdot 10^{-69}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if n < -1.45e14 or 2.99999999999999989e-69 < n Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around 0
Simplified80.5%
if -1.45e14 < n < 2.99999999999999989e-69Initial program 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around inf
Simplified77.5%
(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 100.0%
distribute-frac-negN/A
distribute-neg-frac2N/A
/-lowering-/.f64N/A
+-lowering-+.f64N/A
sub-negN/A
+-commutativeN/A
distribute-neg-inN/A
unsub-negN/A
remove-double-negN/A
--lowering--.f64100.0%
Simplified100.0%
Taylor expanded in f around inf
Simplified48.3%
herbie shell --seed 2024170
(FPCore (f n)
:name "subtraction fraction"
:precision binary64
(/ (- (+ f n)) (- f n)))