Average Error: 29.6 → 0.2
Time: 12.7s
Precision: 64
Internal Precision: 128
\[\sqrt{x + 1} - \sqrt{x}\]
\[\frac{1}{(\left(\sqrt{\sqrt{x + 1}}\right) \cdot \left(\sqrt{\sqrt{x + 1}}\right) + \left(\sqrt{x}\right))_*}\]

Error

Bits error versus x

Target

Original29.6
Target0.2
Herbie0.2
\[\frac{1}{\sqrt{x + 1} + \sqrt{x}}\]

Derivation

  1. Initial program 29.6

    \[\sqrt{x + 1} - \sqrt{x}\]
  2. Using strategy rm
  3. Applied flip--29.4

    \[\leadsto \color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}}\]
  4. Taylor expanded around inf 0.2

    \[\leadsto \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}}\]
  5. Using strategy rm
  6. Applied add-sqr-sqrt0.2

    \[\leadsto \frac{1}{\sqrt{\color{blue}{\sqrt{x + 1} \cdot \sqrt{x + 1}}} + \sqrt{x}}\]
  7. Applied sqrt-prod0.3

    \[\leadsto \frac{1}{\color{blue}{\sqrt{\sqrt{x + 1}} \cdot \sqrt{\sqrt{x + 1}}} + \sqrt{x}}\]
  8. Applied fma-def0.2

    \[\leadsto \frac{1}{\color{blue}{(\left(\sqrt{\sqrt{x + 1}}\right) \cdot \left(\sqrt{\sqrt{x + 1}}\right) + \left(\sqrt{x}\right))_*}}\]
  9. Final simplification0.2

    \[\leadsto \frac{1}{(\left(\sqrt{\sqrt{x + 1}}\right) \cdot \left(\sqrt{\sqrt{x + 1}}\right) + \left(\sqrt{x}\right))_*}\]

Reproduce

herbie shell --seed 2019016 +o rules:numerics
(FPCore (x)
  :name "2sqrt (example 3.1)"

  :herbie-target
  (/ 1 (+ (sqrt (+ x 1)) (sqrt x)))

  (- (sqrt (+ x 1)) (sqrt x)))

Details

Time bar (total: 11.6s)Debug log

sample107.0ms

Algorithm
intervals
Results
573×(pre true 80)
316×(body nan 80)
138×(body real 80)
60×(body real 1280)
39×(body real 640)
12×(body real 320)
(body real 160)

simplify8.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
8.0ms
(- (sqrt (+ x 1)) (sqrt x))

prune9.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 28.5b

localize21.0ms

Local error

Found 2 expressions with local error:

2.4b
(- (sqrt (+ x 1)) (sqrt x))
0.0b
(sqrt (+ x 1))

rewrite15.0ms

Algorithm
rewrite-expression-head
Rules
22×add-sqr-sqrt
19×*-un-lft-identity
18×prod-diff
17×add-cube-cbrt
16×sqrt-prod
fma-neg
add-log-exp
difference-of-squares
log1p-expm1-u
add-exp-log
sqrt-div
add-cbrt-cube
pow1
expm1-log1p-u
distribute-lft-out--
flip--
flip-+
diff-log
pow1/2
flip3--
flip3-+
sub-neg
rem-sqrt-square
Counts
2 → 57
Calls
2 calls:
Slowest
12.0ms
(- (sqrt (+ x 1)) (sqrt x))
1.0ms
(sqrt (+ x 1))

series46.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
26.0ms
(- (sqrt (+ x 1)) (sqrt x))
20.0ms
(sqrt (+ x 1))

simplify863.0ms

Counts
59 → 63
Calls
59 calls:
Slowest
56.0ms
(- (+ (* 1/2 x) 1) (* 1/8 (pow x 2)))
41.0ms
(fma (sqrt (sqrt (+ x 1))) (sqrt (sqrt (+ x 1))) (- (* (sqrt (sqrt x)) (sqrt (sqrt x)))))
31.0ms
(fma (sqrt (sqrt (+ x 1))) (sqrt (sqrt (+ x 1))) (- (* (sqrt (sqrt x)) (sqrt (sqrt x)))))
31.0ms
(fma (- (cbrt (sqrt x))) (* (cbrt (sqrt x)) (cbrt (sqrt x))) (* (cbrt (sqrt x)) (* (cbrt (sqrt x)) (cbrt (sqrt x)))))
29.0ms
(fma (* (cbrt (sqrt (+ x 1))) (cbrt (sqrt (+ x 1)))) (cbrt (sqrt (+ x 1))) (- (* (cbrt (sqrt x)) (* (cbrt (sqrt x)) (cbrt (sqrt x))))))

prune479.0ms

Pruning

14 alts after pruning (14 fresh and 0 done)

Merged error: 27.7b

localize26.0ms

Local error

Found 4 expressions with local error:

1.7b
(- (* (sqrt (+ x 1)) (sqrt (+ x 1))) (* (sqrt x) (sqrt x)))
0.5b
(* (sqrt x) (sqrt x))
0.3b
(* (sqrt (+ x 1)) (sqrt (+ x 1)))
0.1b
(/ (- (* (sqrt (+ x 1)) (sqrt (+ x 1))) (* (sqrt x) (sqrt x))) (+ (sqrt (+ x 1)) (sqrt x)))

rewrite83.0ms

Algorithm
rewrite-expression-head
Rules
30×*-un-lft-identity
20×add-cube-cbrt
20×add-sqr-sqrt
16×times-frac
14×pow1
12×sqrt-div
10×add-exp-log
10×add-cbrt-cube
associate-*l*
associate-*r*
pow1/2
flip-+
flip3-+
difference-of-squares
add-log-exp
sqrt-prod
distribute-lft-out
associate-/l*
log1p-expm1-u
pow-prod-up
pow-prod-down
associate-/r*
frac-times
expm1-log1p-u
associate-/l/
flip--
cbrt-unprod
*-commutative
associate-/r/
associate-*r/
prod-exp
associate-*l/
sqrt-unprod
flip3--
pow-plus
rem-square-sqrt
pow2
div-inv
prod-diff
div-exp
div-sub
diff-log
fma-neg
frac-2neg
sub-neg
clear-num
cbrt-undiv
Counts
4 → 126
Calls
4 calls:
Slowest
43.0ms
(/ (- (* (sqrt (+ x 1)) (sqrt (+ x 1))) (* (sqrt x) (sqrt x))) (+ (sqrt (+ x 1)) (sqrt x)))
20.0ms
(- (* (sqrt (+ x 1)) (sqrt (+ x 1))) (* (sqrt x) (sqrt x)))
10.0ms
(* (sqrt (+ x 1)) (sqrt (+ x 1)))
7.0ms
(* (sqrt x) (sqrt x))

series93.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
50.0ms
(/ (- (* (sqrt (+ x 1)) (sqrt (+ x 1))) (* (sqrt x) (sqrt x))) (+ (sqrt (+ x 1)) (sqrt x)))
17.0ms
(* (sqrt x) (sqrt x))
15.0ms
(* (sqrt (+ x 1)) (sqrt (+ x 1)))
11.0ms
(- (* (sqrt (+ x 1)) (sqrt (+ x 1))) (* (sqrt x) (sqrt x)))

simplify3.1s

Counts
111 → 138
Calls
111 calls:
Slowest
818.0ms
(- (* (* (sqrt (+ x 1)) (sqrt (+ x 1))) (* (sqrt (+ x 1)) (sqrt (+ x 1)))) (* (* (sqrt x) (sqrt x)) (* (sqrt x) (sqrt x))))
277.0ms
(* (* (* (sqrt (+ x 1)) (sqrt (+ x 1))) (sqrt (+ x 1))) (* (* (sqrt (+ x 1)) (sqrt (+ x 1))) (sqrt (+ x 1))))
175.0ms
(/ (* (* (- (* (sqrt (+ x 1)) (sqrt (+ x 1))) (* (sqrt x) (sqrt x))) (- (* (sqrt (+ x 1)) (sqrt (+ x 1))) (* (sqrt x) (sqrt x)))) (- (* (sqrt (+ x 1)) (sqrt (+ x 1))) (* (sqrt x) (sqrt x)))) (* (* (+ (sqrt (+ x 1)) (sqrt x)) (+ (sqrt (+ x 1)) (sqrt x))) (+ (sqrt (+ x 1)) (sqrt x))))
167.0ms
(- (pow (* (sqrt (+ x 1)) (sqrt (+ x 1))) 3) (pow (* (sqrt x) (sqrt x)) 3))
93.0ms
(+ (* (sqrt (+ x 1)) (sqrt (+ x 1))) (- (* (sqrt x) (sqrt x)) (* (sqrt (+ x 1)) (sqrt x))))

prune1.4s

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 0.1b

localize3.0ms

Local error

Found 3 expressions with local error:

0.2b
(/ 1 (+ (sqrt (+ x 1)) (sqrt x)))
0.0b
(+ (sqrt (+ x 1)) (sqrt x))
0.0b
(sqrt (+ x 1))

rewrite18.0ms

Algorithm
rewrite-expression-head
Rules
11×*-un-lft-identity
add-sqr-sqrt
add-cube-cbrt
sqrt-prod
fma-def
add-log-exp
add-exp-log
associate-/r*
pow1
log1p-expm1-u
flip-+
add-cbrt-cube
flip3-+
expm1-log1p-u
distribute-lft-out
associate-/r/
sqrt-div
inv-pow
pow-flip
div-inv
pow1/2
frac-2neg
sum-log
clear-num
rec-exp
rem-sqrt-square
+-commutative
Counts
3 → 57
Calls
3 calls:
Slowest
10.0ms
(+ (sqrt (+ x 1)) (sqrt x))
6.0ms
(/ 1 (+ (sqrt (+ x 1)) (sqrt x)))
1.0ms
(sqrt (+ x 1))

series89.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
49.0ms
(/ 1 (+ (sqrt (+ x 1)) (sqrt x)))
29.0ms
(+ (sqrt (+ x 1)) (sqrt x))
10.0ms
(sqrt (+ x 1))

simplify276.0ms

Counts
29 → 66
Calls
29 calls:
Slowest
127.0ms
(+ (* (sqrt (+ x 1)) (sqrt (+ x 1))) (- (* (sqrt x) (sqrt x)) (* (sqrt (+ x 1)) (sqrt x))))
59.0ms
(- (+ (* 1/2 x) 1) (* 1/8 (pow x 2)))
23.0ms
(sqrt (- (* x x) (* 1 1)))
7.0ms
(* (exp (sqrt (+ x 1))) (exp (sqrt x)))
6.0ms
(cbrt (+ (sqrt (+ x 1)) (sqrt x)))

prune489.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 0.1b

localize12.0ms

Local error

Found 4 expressions with local error:

0.2b
(/ 1 (fma (sqrt (sqrt (+ x 1))) (sqrt (sqrt (+ x 1))) (sqrt x)))
0.1b
(fma (sqrt (sqrt (+ x 1))) (sqrt (sqrt (+ x 1))) (sqrt x))
0.1b
(sqrt (sqrt (+ x 1)))
0.1b
(sqrt (sqrt (+ x 1)))

rewrite4.0ms

Algorithm
rewrite-expression-head
Rules
20×sqrt-prod
13×add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-div
add-exp-log
pow1
add-log-exp
log1p-expm1-u
add-cbrt-cube
rem-sqrt-square
expm1-log1p-u
associate-/r*
flip-+
pow1/2
flip3-+
inv-pow
pow-flip
div-inv
fma-udef
frac-2neg
clear-num
rec-exp
Counts
4 → 68
Calls
4 calls:
Slowest
1.0ms
(sqrt (sqrt (+ x 1)))
1.0ms
(sqrt (sqrt (+ x 1)))
1.0ms
(/ 1 (fma (sqrt (sqrt (+ x 1))) (sqrt (sqrt (+ x 1))) (sqrt x)))
0.0ms
(fma (sqrt (sqrt (+ x 1))) (sqrt (sqrt (+ x 1))) (sqrt x))

series313.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
129.0ms
(/ 1 (fma (sqrt (sqrt (+ x 1))) (sqrt (sqrt (+ x 1))) (sqrt x)))
119.0ms
(fma (sqrt (sqrt (+ x 1))) (sqrt (sqrt (+ x 1))) (sqrt x))
34.0ms
(sqrt (sqrt (+ x 1)))
31.0ms
(sqrt (sqrt (+ x 1)))

simplify807.0ms

Counts
36 → 80
Calls
36 calls:
Slowest
225.0ms
(- (+ (* 1/4 (/ (exp (* 1/4 (- (log -1) (log (/ -1 x))))) x)) (exp (* 1/4 (- (log -1) (log (/ -1 x)))))) (* 3/32 (/ (exp (* 1/4 (- (log -1) (log (/ -1 x))))) (pow x 2))))
162.0ms
(- (+ (* 1/4 (/ (exp (* 1/4 (- (log -1) (log (/ -1 x))))) x)) (exp (* 1/4 (- (log -1) (log (/ -1 x)))))) (* 3/32 (/ (exp (* 1/4 (- (log -1) (log (/ -1 x))))) (pow x 2))))
83.0ms
(- (+ (* 1/4 x) 1) (* 3/32 (pow x 2)))
76.0ms
(- (+ (* 1/4 x) 1) (* 3/32 (pow x 2)))
61.0ms
(- (+ (pow (/ 1 x) -1/4) (* 1/4 (pow (/ 1 (pow x 3)) 1/4))) (* 3/32 (pow (/ 1 (pow x 7)) 1/4)))

prune834.0ms

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 0.0b

regimes67.0ms

Accuracy

0% (0.2b remaining)

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

bsearch1.0ms

end0.0ms

sample2.5s

Algorithm
intervals
Results
16094×(pre true 80)
8093×(body nan 80)
4126×(body real 80)
1738×(body real 1280)
1214×(body real 640)
608×(body real 320)
315×(body real 160)