Average Error: 20.0 → 4.9
Time: 1.7m
Precision: 64
Internal Precision: 128
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.3385669613614879 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.11638679057694 \cdot 10^{-162} \lor \neg \left(y \le 1.6449638335729248 \cdot 10^{-162}\right):\\ \;\;\;\;\frac{\frac{x - y}{\frac{y \cdot y + x \cdot x}{x \cdot x - y \cdot y}}}{x - y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

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
Herbie4.9
\[\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. Split input into 3 regimes
  2. if y < -1.3385669613614879e+154

    1. Initial program 63.6

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

      \[\leadsto \color{blue}{-1}\]

    if -1.3385669613614879e+154 < y < -4.11638679057694e-162 or 1.6449638335729248e-162 < y

    1. Initial program 0.1

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied associate-/l*0.5

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
    4. Using strategy rm
    5. Applied flip-+0.1

      \[\leadsto \frac{x - y}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{x \cdot x - y \cdot y}{x - y}}}}\]
    6. Applied associate-/r/0.1

      \[\leadsto \frac{x - y}{\color{blue}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y} \cdot \left(x - y\right)}}\]
    7. Applied associate-/r*0.1

      \[\leadsto \color{blue}{\frac{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y}}}{x - y}}\]
    8. Using strategy rm
    9. Applied +-commutative0.1

      \[\leadsto \frac{\frac{x - y}{\frac{\color{blue}{y \cdot y + x \cdot x}}{x \cdot x - y \cdot y}}}{x - y}\]

    if -4.11638679057694e-162 < y < 1.6449638335729248e-162

    1. Initial program 29.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied associate-/l*30.0

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
    4. Using strategy rm
    5. Applied flip-+29.6

      \[\leadsto \frac{x - y}{\frac{x \cdot x + y \cdot y}{\color{blue}{\frac{x \cdot x - y \cdot y}{x - y}}}}\]
    6. Applied associate-/r/29.6

      \[\leadsto \frac{x - y}{\color{blue}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y} \cdot \left(x - y\right)}}\]
    7. Applied associate-/r*29.6

      \[\leadsto \color{blue}{\frac{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x \cdot x - y \cdot y}}}{x - y}}\]
    8. Taylor expanded around -inf 15.2

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification4.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3385669613614879 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.11638679057694 \cdot 10^{-162} \lor \neg \left(y \le 1.6449638335729248 \cdot 10^{-162}\right):\\ \;\;\;\;\frac{\frac{x - y}{\frac{y \cdot y + x \cdot x}{x \cdot x - y \cdot y}}}{x - y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019004 
(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: 1.7m)Debug log

sample47.0ms

Algorithm
intervals

simplify187.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune5.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 23.5b

localize35.0ms

Local error

Found 2 expressions with local error:

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

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
2 → 42
Calls

2 calls. Slowest were:

8.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
2.0ms
(+ (* x x) (* y y))

series56.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

41.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
15.0ms
(+ (* x x) (* y y))

simplify2.8s

Counts
31 → 48
Calls

31 calls. Slowest were:

419.0ms
(* (- (* x x) (* y y)) (+ x y))
342.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
319.0ms
(* (- (* x x) (* y y)) (+ (pow x 3) (pow y 3)))

prune454.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.8b

localize0.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Counts
0 → 0
Calls

0 calls. Slowest were:

series0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

simplify0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

prune6.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.8b

localize8.0ms

Local error

Found 3 expressions with local error:

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

rewrite17.0ms

Algorithm
rewrite-expression-head
Counts
3 → 123
Calls

3 calls. Slowest were:

8.0ms
(/ (+ (* x x) (* y y)) (+ x y))
5.0ms
(/ (- x y) (/ (+ (* x x) (* y y)) (+ x y)))
2.0ms
(+ (* x x) (* y y))

series98.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

41.0ms
(/ (+ (* x x) (* y y)) (+ x y))
40.0ms
(/ (- x y) (/ (+ (* x x) (* y y)) (+ x y)))
17.0ms
(+ (* x x) (* y y))

simplify6.9s

Counts
154 → 132
Calls

154 calls. Slowest were:

550.0ms
(/ (* (* (- x y) (- x y)) (- x y)) (* (* (/ (+ (* x x) (* y y)) (+ x y)) (/ (+ (* x x) (* y y)) (+ x y))) (/ (+ (* x x) (* y y)) (+ x y))))
359.0ms
(/ (* (cbrt (- x y)) (cbrt (- x y))) (/ (* (cbrt (+ (* x x) (* y y))) (cbrt (+ (* x x) (* y y)))) (* (cbrt (+ x y)) (cbrt (+ x y)))))
316.0ms
(/ (* (cbrt (- x y)) (cbrt (- x y))) (/ (+ (* x x) (* y y)) (+ (pow x 3) (pow y 3))))

prune1.0s

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.8b

localize19.0ms

Local error

Found 4 expressions with local error:

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

rewrite84.0ms

Algorithm
rewrite-expression-head
Counts
4 → 398
Calls

4 calls. Slowest were:

28.0ms
(/ (/ (- x y) (/ (+ (* x x) (* y y)) (- (* x x) (* y y)))) (- x y))
19.0ms
(/ (+ (* x x) (* y y)) (- (* x x) (* y y)))
14.0ms
(/ (- x y) (/ (+ (* x x) (* y y)) (- (* x x) (* y y))))

series150.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

48.0ms
(/ (- x y) (/ (+ (* x x) (* y y)) (- (* x x) (* y y))))
45.0ms
(/ (+ (* x x) (* y y)) (- (* x x) (* y y)))
34.0ms
(/ (/ (- x y) (/ (+ (* x x) (* y y)) (- (* x x) (* y y)))) (- x y))
23.0ms
(+ (* x x) (* y y))

simplify1.5m

Counts
610 → 410
Calls

610 calls. Slowest were:

1.6s
(/ (/ (* (cbrt (- x y)) (cbrt (- x y))) (/ 1 (+ x y))) (* (cbrt (- x y)) (cbrt (- x y))))
1.3s
(/ (/ (* (cbrt (- x y)) (cbrt (- x y))) (/ 1 (sqrt (- (* x x) (* y y))))) (* (cbrt (- x y)) (cbrt (- x y))))
1.0s
(/ (/ (* (cbrt (- x y)) (cbrt (- x y))) 1) (* (cbrt (- x y)) (cbrt (- x y))))

prune2.6s

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0.8b

regimes92.0ms

Accuracy

79.2% (4.4b remaining)

Error of 4.9b against oracle of 0.5b and baseline of 21.6b

bsearch117.0ms

end0.0ms

sample944.0ms

Algorithm
intervals