Average Error: 19.7 → 5.3
Time: 18.5s
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 -2.2820246712762874 \cdot 10^{-41}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.402706151578305 \cdot 10^{-166} \lor \neg \left(y \le 3.611390805282423 \cdot 10^{-195}\right):\\ \;\;\;\;\frac{y + x}{y \cdot y + x \cdot x} \cdot \left(x - y\right)\\ \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

Original19.7
Target0.1
Herbie5.3
\[\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 < -2.2820246712762874e-41

    1. Initial program 27.1

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity27.1

      \[\leadsto \frac{\left(x - y\right) \cdot \left(x + y\right)}{\color{blue}{1 \cdot \left(x \cdot x + y \cdot y\right)}}\]
    4. Applied times-frac26.6

      \[\leadsto \color{blue}{\frac{x - y}{1} \cdot \frac{x + y}{x \cdot x + y \cdot y}}\]
    5. Simplified26.6

      \[\leadsto \color{blue}{\left(x - y\right)} \cdot \frac{x + y}{x \cdot x + y \cdot y}\]
    6. Taylor expanded around 0 0.5

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

    if -2.2820246712762874e-41 < y < -7.402706151578305e-166 or 3.611390805282423e-195 < y

    1. Initial program 3.4

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity3.4

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

      \[\leadsto \color{blue}{\frac{x - y}{1} \cdot \frac{x + y}{x \cdot x + y \cdot y}}\]
    5. Simplified4.3

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

    if -7.402706151578305e-166 < y < 3.611390805282423e-195

    1. Initial program 30.3

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num30.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.2820246712762874 \cdot 10^{-41}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.402706151578305 \cdot 10^{-166} \lor \neg \left(y \le 3.611390805282423 \cdot 10^{-195}\right):\\ \;\;\;\;\frac{y + x}{y \cdot y + x \cdot x} \cdot \left(x - y\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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

sample73.0ms

Algorithm
intervals

simplify214.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune9.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 16.1b

localize21.0ms

Local error

Found 2 expressions with local error:

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

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
2 → 42
Calls

2 calls. Slowest were:

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

series71.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

54.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
16.0ms
(+ (* x x) (* y y))

simplify2.9s

Counts
31 → 48
Calls

31 calls. Slowest were:

395.0ms
(* (- (* x x) (* y y)) (+ x y))
392.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
277.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))))

prune479.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.9b

localize6.0ms

Local error

Found 3 expressions with local error:

16.0b
(/ (+ (* x x) (* y y)) (* (- x y) (+ x y)))
0.0b
(/ 1 (/ (+ (* x x) (* y y)) (* (- x y) (+ x y))))
0.0b
(+ (* x x) (* y y))

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
3 → 73
Calls

3 calls. Slowest were:

11.0ms
(/ (+ (* x x) (* y y)) (* (- x y) (+ x y)))
4.0ms
(/ 1 (/ (+ (* x x) (* y y)) (* (- x y) (+ x y))))
2.0ms
(+ (* x x) (* y y))

series132.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

55.0ms
(/ 1 (/ (+ (* x x) (* y y)) (* (- x y) (+ x y))))
54.0ms
(/ (+ (* x x) (* y y)) (* (- x y) (+ x y)))
24.0ms
(+ (* x x) (* y y))

simplify2.5s

Counts
50 → 82
Calls

50 calls. Slowest were:

266.0ms
(/ (* (* (+ (* x x) (* y y)) (+ (* x x) (* y y))) (+ (* x x) (* y y))) (* (* (* (- x y) (+ x y)) (* (- x y) (+ x y))) (* (- x y) (+ x y))))
247.0ms
(/ (* (* (+ (* x x) (* y y)) (+ (* x x) (* y y))) (+ (* x x) (* y y))) (* (* (* (- x y) (- x y)) (- x y)) (* (* (+ x y) (+ x y)) (+ x y))))
186.0ms
(/ (+ (* x x) (* y y)) (* (- x y) (+ x y)))

prune787.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.9b

localize5.0ms

Local error

Found 3 expressions with local error:

15.4b
(/ (+ x y) (+ (* x x) (* y y)))
0.2b
(* (- x y) (/ (+ x y) (+ (* x x) (* y y))))
0.0b
(+ (* x x) (* y y))

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
3 → 78
Calls

3 calls. Slowest were:

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

series111.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

56.0ms
(* (- x y) (/ (+ x y) (+ (* x x) (* y y))))
30.0ms
(/ (+ x y) (+ (* x x) (* y y)))
25.0ms
(+ (* x x) (* y y))

simplify3.4s

Counts
68 → 87
Calls

68 calls. Slowest were:

481.0ms
(* (* (* (- x y) (- x y)) (- x y)) (* (* (/ (+ x y) (+ (* x x) (* y y))) (/ (+ x y) (+ (* x x) (* y y)))) (/ (+ x y) (+ (* x x) (* y y)))))
438.0ms
(* (- (pow x 3) (pow y 3)) (/ (+ x y) (+ (* x x) (* y y))))
400.0ms
(* (- (* x x) (* y y)) (+ x y))

prune690.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.9b

localize10.0ms

Local error

Found 4 expressions with local error:

16.7b
(* (+ (* x x) (* y y)) (/ 1 (* (- x y) (+ x y))))
0.5b
(/ 1 (* (- x y) (+ x y)))
0.0b
(/ 1 (* (+ (* x x) (* y y)) (/ 1 (* (- x y) (+ x y)))))
0.0b
(+ (* x x) (* y y))

rewrite27.0ms

Algorithm
rewrite-expression-head
Counts
4 → 93
Calls

4 calls. Slowest were:

11.0ms
(* (+ (* x x) (* y y)) (/ 1 (* (- x y) (+ x y))))
8.0ms
(/ 1 (* (+ (* x x) (* y y)) (/ 1 (* (- x y) (+ x y)))))
4.0ms
(/ 1 (* (- x y) (+ x y)))

series152.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

50.0ms
(/ 1 (* (+ (* x x) (* y y)) (/ 1 (* (- x y) (+ x y)))))
40.0ms
(/ 1 (* (- x y) (+ x y)))
38.0ms
(* (+ (* x x) (* y y)) (/ 1 (* (- x y) (+ x y))))
23.0ms
(+ (* x x) (* y y))

simplify3.8s

Counts
60 → 105
Calls

60 calls. Slowest were:

267.0ms
(+ (log (+ (* x x) (* y y))) (log (/ 1 (* (- x y) (+ x y)))))
260.0ms
(* (+ (* x x) (* y y)) (/ 1 (* (- x y) (+ x y))))
213.0ms
(* (- (* (* x x) (* x x)) (* (* y y) (* y y))) (/ 1 (* (- x y) (+ x y))))

prune917.0ms

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.9b

regimes140.0ms

Accuracy

75.4% (4.8b remaining)

Error of 5.3b against oracle of 0.5b and baseline of 20.0b

bsearch214.0ms

end0.0ms

sample1.5s

Algorithm
intervals