Average Error: 20.0 → 0.0
Time: 23.9s
Precision: 64
Internal Precision: 128
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\log \left(e^{\frac{y + x}{\sqrt{x^2 + y^2}^*} \cdot \frac{x - y}{\sqrt{x^2 + y^2}^*}}\right)\]

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.0
Target0.0
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;0.5 \lt \left|\frac{x}{y}\right| \lt 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\ \end{array}\]

Derivation

  1. Initial program 20.0

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
  2. Simplified20.0

    \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(y + x\right)}{(x \cdot x + \left(y \cdot y\right))_*}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt20.0

    \[\leadsto \frac{\left(x - y\right) \cdot \left(y + x\right)}{\color{blue}{\sqrt{(x \cdot x + \left(y \cdot y\right))_*} \cdot \sqrt{(x \cdot x + \left(y \cdot y\right))_*}}}\]
  5. Applied times-frac20.1

    \[\leadsto \color{blue}{\frac{x - y}{\sqrt{(x \cdot x + \left(y \cdot y\right))_*}} \cdot \frac{y + x}{\sqrt{(x \cdot x + \left(y \cdot y\right))_*}}}\]
  6. Simplified20.1

    \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x^2 + y^2}^*}} \cdot \frac{y + x}{\sqrt{(x \cdot x + \left(y \cdot y\right))_*}}\]
  7. Simplified0.0

    \[\leadsto \frac{x - y}{\sqrt{x^2 + y^2}^*} \cdot \color{blue}{\frac{x + y}{\sqrt{x^2 + y^2}^*}}\]
  8. Using strategy rm
  9. Applied add-log-exp0.0

    \[\leadsto \color{blue}{\log \left(e^{\frac{x - y}{\sqrt{x^2 + y^2}^*} \cdot \frac{x + y}{\sqrt{x^2 + y^2}^*}}\right)}\]
  10. Final simplification0.0

    \[\leadsto \log \left(e^{\frac{y + x}{\sqrt{x^2 + y^2}^*} \cdot \frac{x - y}{\sqrt{x^2 + y^2}^*}}\right)\]

Reproduce

herbie shell --seed 2019007 +o rules:numerics
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0 x 1) (< y 1))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1 (/ 2 (+ 1 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))

Details

Time bar (total: 23.4s)Debug log

sample57.0ms

Algorithm
intervals

simplify314.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

314.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

prune16.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 21.3b

localize34.0ms

Local error

Found 2 expressions with local error:

21.3b
(/ (* (- x y) (+ y x)) (fma x x (* y y)))
0.0b
(fma x x (* y y))

rewrite8.0ms

Algorithm
rewrite-expression-head
Counts
2 → 41
Calls

2 calls. Slowest were:

7.0ms
(/ (* (- x y) (+ y x)) (fma x x (* y y)))
0.0ms
(fma x x (* y y))

series86.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

53.0ms
(/ (* (- x y) (+ y x)) (fma x x (* y y)))
32.0ms
(fma x x (* y y))

simplify3.0s

Counts
28 → 47
Calls

28 calls. Slowest were:

610.0ms
(/ (* (* (* (- x y) (- x y)) (- x y)) (* (* (+ y x) (+ y x)) (+ y x))) (* (* (fma x x (* y y)) (fma x x (* y y))) (fma x x (* y y))))
336.0ms
(* (- (* x x) (* y y)) (+ (pow y 3) (pow x 3)))
293.0ms
(* (- (pow x 3) (pow y 3)) (+ y x))

prune428.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.0b

localize27.0ms

Local error

Found 4 expressions with local error:

0.0b
(/ (- x y) (hypot x y))
0.0b
(/ (+ x y) (hypot x y))
0.0b
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
0.0b
(hypot x y)

rewrite31.0ms

Algorithm
rewrite-expression-head
Counts
4 → 121
Calls

4 calls. Slowest were:

17.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
6.0ms
(/ (+ x y) (hypot x y))
6.0ms
(/ (- x y) (hypot x y))

series220.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

77.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
54.0ms
(/ (+ x y) (hypot x y))
50.0ms
(/ (- x y) (hypot x y))
39.0ms
(hypot x y)

simplify2.8s

Counts
105 → 133
Calls

105 calls. Slowest were:

286.0ms
(* (/ (* (* (- x y) (- x y)) (- x y)) (* (* (hypot x y) (hypot x y)) (hypot x y))) (/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y))))
279.0ms
(+ (- (log (- x y)) (log (hypot x y))) (log (/ (+ x y) (hypot x y))))
268.0ms
(+ (- (log (- x y)) (log (hypot x y))) (- (log (+ x y)) (log (hypot x y))))

prune1.2s

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0b

localize13.0ms

Local error

Found 4 expressions with local error:

0.0b
(/ (- x y) (hypot x y))
0.0b
(/ (+ x y) (hypot x y))
0.0b
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
0.0b
(log (exp (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))))

rewrite32.0ms

Algorithm
rewrite-expression-head
Counts
4 → 127
Calls

4 calls. Slowest were:

14.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
6.0ms
(/ (+ x y) (hypot x y))
5.0ms
(log (exp (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))))

series246.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

71.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
67.0ms
(log (exp (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))))
57.0ms
(/ (- x y) (hypot x y))
51.0ms
(/ (+ x y) (hypot x y))

simplify3.3s

Counts
111 → 139
Calls

111 calls. Slowest were:

349.0ms
(+ (- (log (- x y)) (log (hypot x y))) (log (/ (+ x y) (hypot x y))))
325.0ms
(+ (- (log (- x y)) (log (hypot x y))) (- (log (+ x y)) (log (hypot x y))))
288.0ms
(/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y)))

prune1.4s

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0b

localize14.0ms

Local error

Found 4 expressions with local error:

0.0b
(* (* (/ (- x y) (hypot x y)) (* (cbrt (/ (+ x y) (hypot x y))) (cbrt (/ (+ x y) (hypot x y))))) (cbrt (/ (+ x y) (hypot x y))))
0.0b
(cbrt (/ (+ x y) (hypot x y)))
0.0b
(cbrt (/ (+ x y) (hypot x y)))
0.0b
(cbrt (/ (+ x y) (hypot x y)))

rewrite44.0ms

Algorithm
rewrite-expression-head
Counts
4 → 127
Calls

4 calls. Slowest were:

39.0ms
(* (* (/ (- x y) (hypot x y)) (* (cbrt (/ (+ x y) (hypot x y))) (cbrt (/ (+ x y) (hypot x y))))) (cbrt (/ (+ x y) (hypot x y))))
1.0ms
(cbrt (/ (+ x y) (hypot x y)))
1.0ms
(cbrt (/ (+ x y) (hypot x y)))

series369.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

108.0ms
(cbrt (/ (+ x y) (hypot x y)))
99.0ms
(cbrt (/ (+ x y) (hypot x y)))
86.0ms
(cbrt (/ (+ x y) (hypot x y)))
76.0ms
(* (* (/ (- x y) (hypot x y)) (* (cbrt (/ (+ x y) (hypot x y))) (cbrt (/ (+ x y) (hypot x y))))) (cbrt (/ (+ x y) (hypot x y))))

simplify6.6s

Counts
106 → 139
Calls

106 calls. Slowest were:

564.0ms
(+ (+ (- (log (- x y)) (log (hypot x y))) (+ (log (cbrt (/ (+ x y) (hypot x y)))) (log (cbrt (/ (+ x y) (hypot x y)))))) (log (cbrt (/ (+ x y) (hypot x y)))))
504.0ms
(+ (+ (- (log (- x y)) (log (hypot x y))) (log (* (cbrt (/ (+ x y) (hypot x y))) (cbrt (/ (+ x y) (hypot x y)))))) (log (cbrt (/ (+ x y) (hypot x y)))))
365.0ms
(* (* (/ (- x y) (hypot x y)) (* (cbrt (/ (+ x y) (hypot x y))) (cbrt (/ (+ x y) (hypot x y))))) (cbrt (/ (+ x y) (hypot x y))))

prune1.5s

Pruning

3 alts after pruning (0 fresh and 3 done)

Merged error: 0b

regimes49.0ms

Accuracy

0% (0.0b remaining)

Error of 0.0b against oracle of 0.0b and baseline of 0.0b

bsearch1.0ms

end0.0ms

sample1.5s

Algorithm
intervals