Average Error: 0.0 → 0.0
Time: 3.8s
Precision: binary64
Cost: 13248
\[\frac{-\left(f + n\right)}{f - n} \]
\[\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{f + n}{n - f}\right)\right) \]
(FPCore (f n) :precision binary64 (/ (- (+ f n)) (- f n)))
(FPCore (f n) :precision binary64 (log1p (expm1 (/ (+ f n) (- n f)))))
double code(double f, double n) {
	return -(f + n) / (f - n);
}
double code(double f, double n) {
	return log1p(expm1(((f + n) / (n - f))));
}
public static double code(double f, double n) {
	return -(f + n) / (f - n);
}
public static double code(double f, double n) {
	return Math.log1p(Math.expm1(((f + n) / (n - f))));
}
def code(f, n):
	return -(f + n) / (f - n)
def code(f, n):
	return math.log1p(math.expm1(((f + n) / (n - f))))
function code(f, n)
	return Float64(Float64(-Float64(f + n)) / Float64(f - n))
end
function code(f, n)
	return log1p(expm1(Float64(Float64(f + n) / Float64(n - f))))
end
code[f_, n_] := N[((-N[(f + n), $MachinePrecision]) / N[(f - n), $MachinePrecision]), $MachinePrecision]
code[f_, n_] := N[Log[1 + N[(Exp[N[(N[(f + n), $MachinePrecision] / N[(n - f), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]
\frac{-\left(f + n\right)}{f - n}
\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{f + n}{n - f}\right)\right)

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 0.0

    \[\frac{-\left(f + n\right)}{f - n} \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\frac{f + n}{n - f}} \]
    Proof
    (/.f64 (+.f64 f n) (-.f64 n f)): 0 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= /-rgt-identity_binary64 (/.f64 (+.f64 f n) 1)) (-.f64 n f)): 0 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (+.f64 f n) (Rewrite<= metadata-eval (/.f64 -1 -1))) (-.f64 n f)): 0 points increase in error, 0 points decrease in error
    (/.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (+.f64 f n) -1) -1)) (-.f64 n f)): 0 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 -1 (+.f64 f n))) -1) (-.f64 n f)): 0 points increase in error, 0 points decrease in error
    (/.f64 (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 (+.f64 f n))) -1) (-.f64 n f)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-/r*_binary64 (/.f64 (neg.f64 (+.f64 f n)) (*.f64 -1 (-.f64 n f)))): 0 points increase in error, 0 points decrease in error
    (/.f64 (neg.f64 (+.f64 f n)) (Rewrite<= neg-mul-1_binary64 (neg.f64 (-.f64 n f)))): 0 points increase in error, 0 points decrease in error
    (/.f64 (neg.f64 (+.f64 f n)) (Rewrite<= sub0-neg_binary64 (-.f64 0 (-.f64 n f)))): 0 points increase in error, 0 points decrease in error
    (/.f64 (neg.f64 (+.f64 f n)) (Rewrite<= associate-+l-_binary64 (+.f64 (-.f64 0 n) f))): 0 points increase in error, 0 points decrease in error
    (/.f64 (neg.f64 (+.f64 f n)) (+.f64 (Rewrite<= neg-sub0_binary64 (neg.f64 n)) f)): 0 points increase in error, 0 points decrease in error
    (/.f64 (neg.f64 (+.f64 f n)) (Rewrite<= +-commutative_binary64 (+.f64 f (neg.f64 n)))): 0 points increase in error, 0 points decrease in error
    (/.f64 (neg.f64 (+.f64 f n)) (Rewrite<= sub-neg_binary64 (-.f64 f n))): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.0

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{f + n}{n - f}\right)\right)} \]
  4. Final simplification0.0

    \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{f + n}{n - f}\right)\right) \]

Alternatives

Alternative 1
Error16.4
Cost976
\[\begin{array}{l} t_0 := -2 \cdot \frac{n}{f} + -1\\ \mathbf{if}\;f \leq -2.3826463233323765 \cdot 10^{+94}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;f \leq -5.6102037593422895 \cdot 10^{+23}:\\ \;\;\;\;1\\ \mathbf{elif}\;f \leq -2.62901775538803 \cdot 10^{-23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;f \leq 2.703182165732232 \cdot 10^{+44}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error15.9
Cost976
\[\begin{array}{l} t_0 := -2 \cdot \frac{n}{f} + -1\\ t_1 := 1 + 2 \cdot \frac{f}{n}\\ \mathbf{if}\;f \leq -2.3826463233323765 \cdot 10^{+94}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;f \leq -3.348645957551755 \cdot 10^{+45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;f \leq -2.62901775538803 \cdot 10^{-23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;f \leq 2.703182165732232 \cdot 10^{+44}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error16.2
Cost592
\[\begin{array}{l} \mathbf{if}\;f \leq -5.140898434508113 \cdot 10^{+62}:\\ \;\;\;\;-1\\ \mathbf{elif}\;f \leq -3.348645957551755 \cdot 10^{+45}:\\ \;\;\;\;1\\ \mathbf{elif}\;f \leq -2.62901775538803 \cdot 10^{-23}:\\ \;\;\;\;-1\\ \mathbf{elif}\;f \leq 2.703182165732232 \cdot 10^{+44}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 4
Error0.0
Cost448
\[\frac{f + n}{n - f} \]
Alternative 5
Error32.2
Cost64
\[-1 \]

Error

Reproduce

herbie shell --seed 2022317 
(FPCore (f n)
  :name "subtraction fraction"
  :precision binary64
  (/ (- (+ f n)) (- f n)))