Average Error: 33.2 → 13.4
Time: 17.9s
Precision: 64
Internal Precision: 128
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le 2.1566096146303247 \cdot 10^{-232}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.1234815487678856 \cdot 10^{+63}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{c}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 3 regimes
  2. if b < 2.1566096146303247e-232

    1. Initial program 21.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified21.1

      \[\leadsto \color{blue}{\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{2 \cdot a}}\]
    3. Taylor expanded around -inf 21.1

      \[\leadsto \frac{\sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}} - b}{2 \cdot a}\]
    4. Simplified21.1

      \[\leadsto \frac{\sqrt{\color{blue}{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}} - b}{2 \cdot a}\]

    if 2.1566096146303247e-232 < b < 3.1234815487678856e+63

    1. Initial program 33.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified33.0

      \[\leadsto \color{blue}{\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied flip--33.1

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} \cdot \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b \cdot b}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b}}}{2 \cdot a}\]
    5. Applied associate-/l/37.1

      \[\leadsto \color{blue}{\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} \cdot \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b \cdot b}{\left(2 \cdot a\right) \cdot \left(\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b\right)}}\]
    6. Simplified21.0

      \[\leadsto \frac{\color{blue}{\left(a \cdot -4\right) \cdot c}}{\left(2 \cdot a\right) \cdot \left(\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b\right)}\]
    7. Using strategy rm
    8. Applied times-frac7.9

      \[\leadsto \color{blue}{\frac{a \cdot -4}{2 \cdot a} \cdot \frac{c}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b}}\]
    9. Simplified7.9

      \[\leadsto \color{blue}{-2} \cdot \frac{c}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b}\]

    if 3.1234815487678856e+63 < b

    1. Initial program 56.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified56.6

      \[\leadsto \color{blue}{\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{2 \cdot a}}\]
    3. Using strategy rm
    4. Applied flip--56.6

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} \cdot \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b \cdot b}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b}}}{2 \cdot a}\]
    5. Applied associate-/l/57.2

      \[\leadsto \color{blue}{\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} \cdot \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b \cdot b}{\left(2 \cdot a\right) \cdot \left(\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b\right)}}\]
    6. Simplified29.5

      \[\leadsto \frac{\color{blue}{\left(a \cdot -4\right) \cdot c}}{\left(2 \cdot a\right) \cdot \left(\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b\right)}\]
    7. Using strategy rm
    8. Applied times-frac26.7

      \[\leadsto \color{blue}{\frac{a \cdot -4}{2 \cdot a} \cdot \frac{c}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b}}\]
    9. Simplified26.7

      \[\leadsto \color{blue}{-2} \cdot \frac{c}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b}\]
    10. Taylor expanded around 0 3.5

      \[\leadsto -2 \cdot \frac{c}{\color{blue}{b} + b}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 2.1566096146303247 \cdot 10^{-232}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.1234815487678856 \cdot 10^{+63}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{c}{b + b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019016 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))

Details

Time bar (total: 17.1s)Debug log

sample182.0ms

Algorithm
intervals
Results
378×(pre true 80)
187×(body real 80)
93×(body nan 80)
36×(body real 2560)
30×(body real 1280)
16×(body real 640)
(body real 160)
(body real 320)
(body real 5120)

simplify71.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
71.0ms
(/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))

prune14.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 35.0b

localize34.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a -4) c (* b b)))
2.2b
(- (sqrt (fma (* a -4) c (* b b))) b)
0.1b
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
0.0b
(fma (* a -4) c (* b b))

rewrite19.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
add-exp-log
fma-neg
add-cbrt-cube
add-log-exp
log1p-expm1-u
pow1
expm1-log1p-u
associate-/l*
times-frac
associate-/l/
flip--
flip3--
div-inv
fma-udef
div-exp
div-sub
pow1/2
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
Counts
4 → 67
Calls
4 calls:
Slowest
11.0ms
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
6.0ms
(- (sqrt (fma (* a -4) c (* b b))) b)
2.0ms
(sqrt (fma (* a -4) c (* b b)))
0.0ms
(fma (* a -4) c (* b b))

series275.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
102.0ms
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
71.0ms
(- (sqrt (fma (* a -4) c (* b b))) b)
68.0ms
(sqrt (fma (* a -4) c (* b b)))
33.0ms
(fma (* a -4) c (* b b))

simplify1.4s

Counts
34 → 79
Calls
34 calls:
Slowest
717.0ms
(- (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (* b b))
145.0ms
(- (pow (sqrt (fma (* a -4) c (* b b))) 3) (pow b 3))
71.0ms
(/ (* (* (- (sqrt (fma (* a -4) c (* b b))) b) (- (sqrt (fma (* a -4) c (* b b))) b)) (- (sqrt (fma (* a -4) c (* b b))) b)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
63.0ms
(- (log (- (sqrt (fma (* a -4) c (* b b))) b)) (log (* 2 a)))
46.0ms
(- (pow b 2) (* 4 (* a c)))

prune895.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 22.1b

localize22.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a -4) c (* b b)))
16.3b
(/ (* (* a -4) c) (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b)))
1.2b
(+ (sqrt (fma (* a -4) c (* b b))) b)
0.1b
(* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))

rewrite29.0ms

Algorithm
rewrite-expression-head
Rules
11×add-exp-log
11×add-cbrt-cube
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
fma-def
pow1
add-log-exp
log1p-expm1-u
associate-*r/
expm1-log1p-u
flip-+
associate-*r*
flip3-+
cbrt-unprod
associate-/r/
prod-exp
div-exp
cbrt-undiv
associate-/l*
div-inv
*-commutative
pow-prod-down
associate-*l*
pow1/2
times-frac
distribute-lft-in
frac-2neg
associate-/r*
clear-num
rem-sqrt-square
+-commutative
distribute-rgt-in
Counts
4 → 74
Calls
4 calls:
Slowest
15.0ms
(/ (* (* a -4) c) (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b)))
8.0ms
(* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))
4.0ms
(+ (sqrt (fma (* a -4) c (* b b))) b)
2.0ms
(sqrt (fma (* a -4) c (* b b)))

series318.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
107.0ms
(/ (* (* a -4) c) (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b)))
101.0ms
(* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))
60.0ms
(+ (sqrt (fma (* a -4) c (* b b))) b)
49.0ms
(sqrt (fma (* a -4) c (* b b)))

simplify3.7s

Counts
41 → 86
Calls
41 calls:
Slowest
1.0s
(/ (* (* (* (* a -4) c) (* (* a -4) c)) (* (* a -4) c)) (* (* (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b)) (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))) (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))))
608.0ms
(- (log (* (* a -4) c)) (+ (log (* 2 a)) (log (+ (sqrt (fma (* a -4) c (* b b))) b))))
535.0ms
(/ (* (* (* (* a -4) c) (* (* a -4) c)) (* (* a -4) c)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (sqrt (fma (* a -4) c (* b b))) b) (+ (sqrt (fma (* a -4) c (* b b))) b)) (+ (sqrt (fma (* a -4) c (* b b))) b))))
375.0ms
(- (log (* (* a -4) c)) (log (* (* 2 a) (+ (sqrt (fma (* a -4) c (* b b))) b))))
257.0ms
(+ (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (- (* b b) (* (sqrt (fma (* a -4) c (* b b))) b)))

prune1.0s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 15.5b

localize13.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a -4) c (* b b)))
1.2b
(+ (sqrt (fma (* a -4) c (* b b))) b)
0.1b
(/ c (+ (sqrt (fma (* a -4) c (* b b))) b))
0.0b
(fma (* a -4) c (* b b))

rewrite9.0ms

Algorithm
rewrite-expression-head
Rules
add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
fma-def
add-log-exp
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
associate-/r*
flip-+
associate-/r/
flip3-+
div-inv
fma-udef
pow1/2
frac-2neg
clear-num
rem-sqrt-square
+-commutative
Counts
4 → 59
Calls
4 calls:
Slowest
4.0ms
(+ (sqrt (fma (* a -4) c (* b b))) b)
3.0ms
(/ c (+ (sqrt (fma (* a -4) c (* b b))) b))
2.0ms
(sqrt (fma (* a -4) c (* b b)))
0.0ms
(fma (* a -4) c (* b b))

series278.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
138.0ms
(/ c (+ (sqrt (fma (* a -4) c (* b b))) b))
72.0ms
(+ (sqrt (fma (* a -4) c (* b b))) b)
40.0ms
(sqrt (fma (* a -4) c (* b b)))
28.0ms
(fma (* a -4) c (* b b))

simplify547.0ms

Counts
26 → 71
Calls
26 calls:
Slowest
224.0ms
(+ (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (- (* b b) (* (sqrt (fma (* a -4) c (* b b))) b)))
34.0ms
(- (pow b 2) (* 4 (* a c)))
33.0ms
(- (pow b 2) (* 4 (* a c)))
28.0ms
(- (sqrt (fma (* a -4) c (* b b))) b)
28.0ms
(sqrt (sqrt (fma (* a -4) c (* b b))))

prune809.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 11.8b

localize2.0ms

Local error

Found 4 expressions with local error:

23.2b
(sqrt (fma (* a -4) c (* b b)))
2.2b
(- (sqrt (fma (* a -4) c (* b b))) b)
0.1b
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
0.0b
(fma (* a -4) c (* b b))

rewrite28.0ms

Algorithm
rewrite-expression-head
Rules
10×add-sqr-sqrt
add-cube-cbrt
*-un-lft-identity
sqrt-prod
add-exp-log
fma-neg
add-cbrt-cube
add-log-exp
log1p-expm1-u
pow1
expm1-log1p-u
associate-/l*
times-frac
associate-/l/
flip--
flip3--
div-inv
fma-udef
div-exp
div-sub
pow1/2
frac-2neg
sub-neg
associate-/r*
clear-num
rem-sqrt-square
cbrt-undiv
Counts
4 → 67
Calls
4 calls:
Slowest
15.0ms
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
10.0ms
(- (sqrt (fma (* a -4) c (* b b))) b)
2.0ms
(sqrt (fma (* a -4) c (* b b)))
0.0ms
(fma (* a -4) c (* b b))

series231.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
75.0ms
(- (sqrt (fma (* a -4) c (* b b))) b)
68.0ms
(/ (- (sqrt (fma (* a -4) c (* b b))) b) (* 2 a))
44.0ms
(fma (* a -4) c (* b b))
43.0ms
(sqrt (fma (* a -4) c (* b b)))

simplify1.6s

Counts
34 → 79
Calls
34 calls:
Slowest
798.0ms
(- (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (* b b))
130.0ms
(- (pow (sqrt (fma (* a -4) c (* b b))) 3) (pow b 3))
61.0ms
(/ (* (* (- (sqrt (fma (* a -4) c (* b b))) b) (- (sqrt (fma (* a -4) c (* b b))) b)) (- (sqrt (fma (* a -4) c (* b b))) b)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
59.0ms
(- (log (- (sqrt (fma (* a -4) c (* b b))) b)) (log (* 2 a)))
51.0ms
(- (pow b 2) (* 4 (* a c)))

prune842.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 11.8b

regimes246.0ms

Accuracy

95.3% (0.8b remaining)

Error of 13.4b against oracle of 12.6b and baseline of 29.6b

bsearch470.0ms

end0.0ms

sample4.0s

Algorithm
intervals
Results
11500×(pre true 80)
5932×(body real 80)
2746×(body nan 80)
1013×(body real 2560)
888×(body real 1280)
455×(body real 640)
223×(body real 320)
126×(body real 160)
117×(body real 5120)