Average Error: 20.5 → 5.5
Time: 18.2s
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.326101464362353 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.866138089097476 \cdot 10^{-160}:\\ \;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\right)\\ \mathbf{elif}\;y \le 2.903536397889742 \cdot 10^{-204}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\sqrt{y \cdot y + x \cdot x}} \cdot \frac{y + x}{\sqrt{y \cdot y + x \cdot x}}\\ \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.5
Target0.0
Herbie5.5
\[\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 4 regimes
  2. if y < -1.326101464362353e+154

    1. Initial program 63.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-log-exp63.6

      \[\leadsto \color{blue}{\log \left(e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right)}\]
    4. Taylor expanded around 0 0

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

    if -1.326101464362353e+154 < y < -7.866138089097476e-160

    1. Initial program 0.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-log-exp0.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right)}\]

    if -7.866138089097476e-160 < y < 2.903536397889742e-204

    1. Initial program 29.9

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-log-exp29.9

      \[\leadsto \color{blue}{\log \left(e^{\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}}\right)}\]
    4. Taylor expanded around inf 14.9

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

    if 2.903536397889742e-204 < y

    1. Initial program 5.9

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt5.9

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}}}\]
    4. Applied times-frac6.3

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.326101464362353 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.866138089097476 \cdot 10^{-160}:\\ \;\;\;\;\log \left(e^{\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}}\right)\\ \mathbf{elif}\;y \le 2.903536397889742 \cdot 10^{-204}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\sqrt{y \cdot y + x \cdot x}} \cdot \frac{y + x}{\sqrt{y \cdot y + x \cdot x}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019002 
(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: 17.7s)Debug log

sample58.0ms

Algorithm
intervals

simplify195.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune9.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 19.5b

localize26.0ms

Local error

Found 2 expressions with local error:

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

series59.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

39.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
19.0ms
(+ (* x x) (* y y))

simplify2.9s

Counts
31 → 48
Calls

31 calls. Slowest were:

433.0ms
(* (- (* x x) (* y y)) (+ x y))
377.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
337.0ms
(/ (* (* (* (- x y) (+ x y)) (* (- x y) (+ x y))) (* (- x y) (+ x y))) (* (* (+ (* x x) (* y y)) (+ (* x x) (* y y))) (+ (* x x) (* y y))))

prune416.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 0.5b

localize22.0ms

Local error

Found 4 expressions with local error:

18.6b
(sqrt (+ (* x x) (* y y)))
18.6b
(sqrt (+ (* x x) (* y y)))
0.0b
(* (/ (- x y) (sqrt (+ (* x x) (* y y)))) (/ (+ x y) (sqrt (+ (* x x) (* y y)))))
0.0b
(/ (+ x y) (sqrt (+ (* x x) (* y y))))

rewrite41.0ms

Algorithm
rewrite-expression-head
Counts
4 → 139
Calls

4 calls. Slowest were:

23.0ms
(* (/ (- x y) (sqrt (+ (* x x) (* y y)))) (/ (+ x y) (sqrt (+ (* x x) (* y y)))))
8.0ms
(/ (+ x y) (sqrt (+ (* x x) (* y y))))
4.0ms
(sqrt (+ (* x x) (* y y)))

series140.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

63.0ms
(/ (+ x y) (sqrt (+ (* x x) (* y y))))
38.0ms
(* (/ (- x y) (sqrt (+ (* x x) (* y y)))) (/ (+ x y) (sqrt (+ (* x x) (* y y)))))
20.0ms
(sqrt (+ (* x x) (* y y)))
19.0ms
(sqrt (+ (* x x) (* y y)))

simplify4.2s

Counts
134 → 151
Calls

134 calls. Slowest were:

429.0ms
(+ (- (log (- x y)) (log (sqrt (+ (* x x) (* y y))))) (- (log (+ x y)) (log (sqrt (+ (* x x) (* y y))))))
328.0ms
(+ (- (log (- x y)) (log (sqrt (+ (* x x) (* y y))))) (log (/ (+ x y) (sqrt (+ (* x x) (* y y))))))
281.0ms
(* (* (* (/ (- x y) (sqrt (+ (* x x) (* y y)))) (/ (- x y) (sqrt (+ (* x x) (* y y))))) (/ (- x y) (sqrt (+ (* x x) (* y y))))) (/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (sqrt (+ (* x x) (* y y))) (sqrt (+ (* x x) (* y y)))) (sqrt (+ (* x x) (* y y))))))

prune1.5s

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0.5b

localize7.0ms

Local error

Found 4 expressions with local error:

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

rewrite34.0ms

Algorithm
rewrite-expression-head
Counts
4 → 80
Calls

4 calls. Slowest were:

11.0ms
(exp (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
8.0ms
(log (exp (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
8.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

series142.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

55.0ms
(exp (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
39.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
32.0ms
(log (exp (/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))))
15.0ms
(+ (* x x) (* y y))

simplify5.5s

Counts
60 → 92
Calls

60 calls. Slowest were:

546.0ms
(cbrt (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
353.0ms
(* (- (* x x) (* y y)) (+ x y))
348.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))

prune901.0ms

Pruning

5 alts after pruning (2 fresh and 3 done)

Merged error: 0.5b

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:

prune0.0ms

Pruning

5 alts after pruning (1 fresh and 4 done)

Merged error: 0.5b

regimes161.0ms

Accuracy

74.7% (5.1b remaining)

Error of 5.5b against oracle of 0.4b and baseline of 20.5b

bsearch130.0ms

end0.0ms

sample1.2s

Algorithm
intervals