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

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.1
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. Initial simplification20.0

    \[\leadsto \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.0

    \[\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.0

    \[\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 associate-*l/0.0

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

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

Reproduce

herbie shell --seed 2018365 +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: 22.2s)Debug log

start76.0ms

Algorithm
intervals

setup353.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 23.9b

localize17.0ms

Local error

Found 2 expressions with local error:

23.9b
(/ (* (- 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))

series78.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

54.0ms
(/ (* (- x y) (+ y x)) (fma x x (* y y)))
24.0ms
(fma x x (* y y))

simplify3.2s

Counts
28 → 47
Calls

28 calls. Slowest were:

443.0ms
(* (- (* x x) (* y y)) (+ y x))
394.0ms
(* (- (* x x) (* y y)) (+ (pow y 3) (pow x 3)))
391.0ms
(* (- (pow x 3) (pow y 3)) (+ y x))

prune452.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.0b

localize16.0ms

Local error

Found 4 expressions with local error:

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

rewrite30.0ms

Algorithm
rewrite-expression-head
Counts
4 → 121
Calls

4 calls. Slowest were:

15.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))

series229.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

77.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
57.0ms
(/ (+ x y) (hypot x y))
54.0ms
(/ (- x y) (hypot x y))
41.0ms
(hypot x y)

simplify3.3s

Counts
105 → 133
Calls

105 calls. Slowest were:

408.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
313.0ms
(+ (- (log (- x y)) (log (hypot x y))) (- (log (+ x y)) (log (hypot x y))))
313.0ms
(/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y)))

prune1.3s

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0b

localize15.0ms

Local error

Found 4 expressions with local error:

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

rewrite40.0ms

Algorithm
rewrite-expression-head
Counts
4 → 107
Calls

4 calls. Slowest were:

17.0ms
(/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))
13.0ms
(* (- x y) (/ (+ x y) (hypot x y)))
8.0ms
(/ (+ x y) (hypot x y))

series274.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

80.0ms
(* (- x y) (/ (+ x y) (hypot x y)))
79.0ms
(/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))
73.0ms
(/ (+ x y) (hypot x y))
41.0ms
(hypot x y)

simplify4.1s

Counts
87 → 119
Calls

87 calls. Slowest were:

337.0ms
(/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y)))
333.0ms
(* (- (pow x 3) (pow y 3)) (+ x y))
328.0ms
(* (- (pow x 3) (pow y 3)) (+ x y))

prune1.1s

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0b

localize7.0ms

Local error

Found 4 expressions with local error:

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

rewrite33.0ms

Algorithm
rewrite-expression-head
Counts
4 → 118
Calls

4 calls. Slowest were:

13.0ms
(/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))
9.0ms
(log (exp (/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))))
6.0ms
(* (- x y) (/ (+ x y) (hypot x y)))

series267.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

75.0ms
(* (- x y) (/ (+ x y) (hypot x y)))
73.0ms
(/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))
65.0ms
(/ (+ x y) (hypot x y))
53.0ms
(log (exp (/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))))

simplify5.6s

Counts
98 → 130
Calls

98 calls. Slowest were:

331.0ms
(sqrt (/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y)))
330.0ms
(/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))
321.0ms
(log (* (cbrt (exp (/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y)))) (cbrt (exp (/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))))))

prune1.6s

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 0b

regimes77.0ms

Accuracy

0% (0.0b remaining)

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

bsearch2.0ms