Average Error: 33.2 → 6.7
Time: 31.6s
Precision: 64
Internal Precision: 128
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -8.276414657528413 \cdot 10^{+95}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -6.321237892731252 \cdot 10^{-282}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\left(-b\right) + \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}} \cdot \sqrt{\left(-b\right) + \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}}\\ \mathbf{elif}\;b \le 3.7085352995569145 \cdot 10^{+106}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.2
Target20.7
Herbie6.7
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -8.276414657528413e+95

    1. Initial program 58.1

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. Simplified2.4

      \[\leadsto \color{blue}{\frac{-c}{b}}\]

    if -8.276414657528413e+95 < b < -6.321237892731252e-282

    1. Initial program 32.3

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{2 \cdot c}}{\left(-b\right) + \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrt8.6

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

    if -6.321237892731252e-282 < b < 3.7085352995569145e+106

    1. Initial program 9.6

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

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

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

    if 3.7085352995569145e+106 < b

    1. Initial program 46.2

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

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

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification6.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.276414657528413 \cdot 10^{+95}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -6.321237892731252 \cdot 10^{-282}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\left(-b\right) + \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}} \cdot \sqrt{\left(-b\right) + \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}}\\ \mathbf{elif}\;b \le 3.7085352995569145 \cdot 10^{+106}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right) \cdot \frac{1}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019008 +o rules:numerics
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

Details

Time bar (total: 30.4s)Debug log

sample149.0ms

Algorithm
intervals

simplify109.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

109.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

prune20.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 33.9b

localize39.0ms

Local error

Found 4 expressions with local error:

23.7b
(sqrt (fma (* -4 a) c (* b b)))
0.8b
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
0.1b
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
0.0b
(fma (* -4 a) c (* b b))

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
4 → 100
Calls

4 calls. Slowest were:

12.0ms
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
5.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
1.0ms
(sqrt (fma (* -4 a) c (* b b)))

series241.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

79.0ms
(sqrt (fma (* -4 a) c (* b b)))
61.0ms
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
57.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
44.0ms
(fma (* -4 a) c (* b b))

simplify3.4s

Counts
93 → 112
Calls

93 calls. Slowest were:

284.0ms
(- (* (- b) (- b)) (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b)))))
182.0ms
(- (pow (- b) 3) (pow (sqrt (fma (* -4 a) c (* b b))) 3))
124.0ms
(/ (* (* (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (- (- b) (sqrt (fma (* -4 a) c (* b b))))) (- (- b) (sqrt (fma (* -4 a) c (* b b))))) (* (* (* 2 a) (* 2 a)) (* 2 a)))

prune1.6s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 6.6b

localize7.0ms

Local error

Found 4 expressions with local error:

23.7b
(sqrt (fma (* -4 a) c (* b b)))
0.8b
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
0.2b
(* (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (/ 1 (* 2 a)))
0.0b
(fma (* -4 a) c (* b b))

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
4 → 100
Calls

4 calls. Slowest were:

13.0ms
(* (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (/ 1 (* 2 a)))
5.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
1.0ms
(sqrt (fma (* -4 a) c (* b b)))

series194.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

64.0ms
(* (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (/ 1 (* 2 a)))
47.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
46.0ms
(sqrt (fma (* -4 a) c (* b b)))
36.0ms
(fma (* -4 a) c (* b b))

simplify5.2s

Counts
92 → 112
Calls

92 calls. Slowest were:

647.0ms
(* (- (* (- b) (- b)) (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b))))) 1)
590.0ms
(* (- (pow (- b) 3) (pow (sqrt (fma (* -4 a) c (* b b))) 3)) 1)
369.0ms
(* (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (/ 1 (* 2 a)))

prune1.4s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 6.6b

localize34.0ms

Local error

Found 4 expressions with local error:

23.7b
(sqrt (fma (* -4 a) c (* b b)))
15.4b
(* (- 0 (* (* c a) -4)) (/ 1/2 a))
0.9b
(+ (- b) (sqrt (fma (* -4 a) c (* b b))))
0.1b
(/ (* (- 0 (* (* c a) -4)) (/ 1/2 a)) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))

rewrite39.0ms

Algorithm
rewrite-expression-head
Counts
4 → 92
Calls

4 calls. Slowest were:

20.0ms
(/ (* (- 0 (* (* c a) -4)) (/ 1/2 a)) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))
8.0ms
(+ (- b) (sqrt (fma (* -4 a) c (* b b))))
7.0ms
(* (- 0 (* (* c a) -4)) (/ 1/2 a))

series250.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

162.0ms
(/ (* (- 0 (* (* c a) -4)) (/ 1/2 a)) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))
44.0ms
(+ (- b) (sqrt (fma (* -4 a) c (* b b))))
39.0ms
(sqrt (fma (* -4 a) c (* b b)))
5.0ms
(* (- 0 (* (* c a) -4)) (/ 1/2 a))

simplify7.7s

Counts
61 → 104
Calls

61 calls. Slowest were:

678.0ms
(* (- 0 (* (* c a) -4)) (/ 1/2 a))
493.0ms
(* (- (pow 0 3) (pow (* (* c a) -4) 3)) (/ 1/2 a))
489.0ms
(* (- (pow 0 3) (pow (* (* c a) -4) 3)) (/ 1/2 a))

prune1.9s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 6.6b

localize8.0ms

Local error

Found 4 expressions with local error:

23.7b
(sqrt (fma (* -4 a) c (* b b)))
0.9b
(+ (- b) (sqrt (fma (* -4 a) c (* b b))))
0.1b
(/ (* 2 c) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))
0.0b
(fma (* -4 a) c (* b b))

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
4 → 68
Calls

4 calls. Slowest were:

7.0ms
(/ (* 2 c) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))
4.0ms
(+ (- b) (sqrt (fma (* -4 a) c (* b b))))
1.0ms
(sqrt (fma (* -4 a) c (* b b)))

series330.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

142.0ms
(/ (* 2 c) (+ (- b) (sqrt (fma (* -4 a) c (* b b)))))
72.0ms
(+ (- b) (sqrt (fma (* -4 a) c (* b b))))
66.0ms
(sqrt (fma (* -4 a) c (* b b)))
50.0ms
(fma (* -4 a) c (* b b))

simplify1.3s

Counts
36 → 80
Calls

36 calls. Slowest were:

530.0ms
(+ (* (- b) (- b)) (- (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b)))) (* (- b) (sqrt (fma (* -4 a) c (* b b))))))
104.0ms
(/ (* (* (* 2 c) (* 2 c)) (* 2 c)) (* (* (+ (- b) (sqrt (fma (* -4 a) c (* b b)))) (+ (- b) (sqrt (fma (* -4 a) c (* b b))))) (+ (- b) (sqrt (fma (* -4 a) c (* b b))))))
73.0ms
(* (exp (- b)) (exp (sqrt (fma (* -4 a) c (* b b)))))

prune921.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 6.6b

regimes429.0ms

Accuracy

95% (1.2b remaining)

Error of 6.7b against oracle of 5.5b and baseline of 29.7b

bsearch421.0ms

end0.0ms

sample4.6s

Algorithm
intervals