Average Error: 20.4 → 5.0
Time: 11.1s
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.36198182498291 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.296211233254968 \cdot 10^{-186}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le -3.348557597659889 \cdot 10^{-197}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.0226387308524757 \cdot 10^{-166}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{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.4
Target0.1
Herbie5.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. Split input into 3 regimes
  2. if y < -1.36198182498291e+154 or -3.296211233254968e-186 < y < -3.348557597659889e-197

    1. Initial program 61.8

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

      \[\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-frac60.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}}}\]
    5. Taylor expanded around 0 2.2

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

    if -1.36198182498291e+154 < y < -3.296211233254968e-186 or 1.0226387308524757e-166 < y

    1. Initial program 1.3

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]

    if -3.348557597659889e-197 < y < 1.0226387308524757e-166

    1. Initial program 30.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.36198182498291 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.296211233254968 \cdot 10^{-186}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le -3.348557597659889 \cdot 10^{-197}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.0226387308524757 \cdot 10^{-166}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \end{array}\]

Reproduce

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

sample59.0ms

Algorithm
intervals

simplify178.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune5.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 18.2b

localize19.0ms

Local error

Found 2 expressions with local error:

18.2b
(/ (* (- 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:

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

series74.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

46.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
28.0ms
(+ (* x x) (* y y))

simplify2.7s

Counts
31 → 48
Calls

31 calls. Slowest were:

448.0ms
(* (- (* x x) (* y y)) (+ x y))
337.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
317.0ms
(* (- (* x x) (* y y)) (+ (pow x 3) (pow y 3)))

prune365.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.3b

localize16.0ms

Local error

Found 4 expressions with local error:

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

rewrite23.0ms

Algorithm
rewrite-expression-head
Counts
4 → 139
Calls

4 calls. Slowest were:

12.0ms
(* (/ (- x y) (sqrt (+ (* x x) (* y y)))) (/ (+ x y) (sqrt (+ (* x x) (* y y)))))
5.0ms
(/ (+ x y) (sqrt (+ (* x x) (* y y))))
2.0ms
(sqrt (+ (* x x) (* y y)))

series160.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

60.0ms
(/ (+ x y) (sqrt (+ (* x x) (* y y))))
49.0ms
(* (/ (- x y) (sqrt (+ (* x x) (* y y)))) (/ (+ x y) (sqrt (+ (* x x) (* y y)))))
30.0ms
(sqrt (+ (* x x) (* y y)))
21.0ms
(sqrt (+ (* x x) (* y y)))

simplify3.8s

Counts
134 → 151
Calls

134 calls. Slowest were:

295.0ms
(+ (- (log (- x y)) (log (sqrt (+ (* x x) (* y y))))) (- (log (+ x y)) (log (sqrt (+ (* x x) (* y y))))))
250.0ms
(+ (- (log (- x y)) (log (sqrt (+ (* x x) (* y y))))) (log (/ (+ x y) (sqrt (+ (* x x) (* y y))))))
243.0ms
(/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (sqrt (+ (* x x) (* y y))) (sqrt (+ (* x x) (* y y)))) (sqrt (+ (* x x) (* y y)))))

prune1.6s

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.3b

localize1.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:

prune4.0ms

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 0.3b

localize1.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:

prune1.0ms

Pruning

4 alts after pruning (0 fresh and 4 done)

Merged error: 0.3b

regimes157.0ms

Accuracy

77.6% (4.5b remaining)

Error of 5.0b against oracle of 0.5b and baseline of 20.4b

bsearch137.0ms

end0.0ms

sample1.3s

Algorithm
intervals