Average Error: 33.2 → 9.6
Time: 35.2s
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 -4.9529633933266 \cdot 10^{-08}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.432147794020809 \cdot 10^{-104}:\\ \;\;\;\;\frac{\left(a \cdot c\right) \cdot 4}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right)}\\ \mathbf{elif}\;b \le -5.51185453096989 \cdot 10^{-127}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 8.046684077965657 \cdot 10^{+99}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}}\\ \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.4
Herbie9.6
\[\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 < -4.9529633933266e-08 or -1.432147794020809e-104 < b < -5.51185453096989e-127

    1. Initial program 53.5

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

      \[\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 7.8

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

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

    if -4.9529633933266e-08 < b < -1.432147794020809e-104

    1. Initial program 34.9

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

      \[\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 flip--34.9

      \[\leadsto \frac{\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))_*}}}}{2 \cdot a}\]
    5. Applied associate-/l/38.7

      \[\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(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right)}}\]
    6. Simplified21.5

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

    if -5.51185453096989e-127 < b < 8.046684077965657e+99

    1. Initial program 11.0

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

      \[\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 11.0

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

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

      \[\leadsto \frac{\left(-b\right) - \color{blue}{1 \cdot \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}{2 \cdot a}\]
    7. Applied *-un-lft-identity11.0

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

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

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

    if 8.046684077965657e+99 < b

    1. Initial program 44.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified44.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. Taylor expanded around inf 3.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.9529633933266 \cdot 10^{-08}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.432147794020809 \cdot 10^{-104}:\\ \;\;\;\;\frac{\left(a \cdot c\right) \cdot 4}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right)}\\ \mathbf{elif}\;b \le -5.51185453096989 \cdot 10^{-127}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 8.046684077965657 \cdot 10^{+99}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

herbie shell --seed 2019004 +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :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: 33.8s)Debug log

sample192.0ms

Algorithm
intervals

simplify108.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune11.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 33.9b

localize33.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma (* -4 a) c (* b b)))
0.9b
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
0.2b
(fma (* -4 a) c (* b b))
0.1b
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))

rewrite26.0ms

Algorithm
rewrite-expression-head
Counts
4 → 100
Calls

4 calls. Slowest were:

16.0ms
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
7.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
2.0ms
(sqrt (fma (* -4 a) c (* b b)))

series204.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

60.0ms
(/ (- (- b) (sqrt (fma (* -4 a) c (* b b)))) (* 2 a))
55.0ms
(- (- b) (sqrt (fma (* -4 a) c (* b b))))
51.0ms
(sqrt (fma (* -4 a) c (* b b)))
38.0ms
(fma (* -4 a) c (* b b))

simplify3.3s

Counts
93 → 112
Calls

93 calls. Slowest were:

341.0ms
(- (* (- b) (- b)) (* (sqrt (fma (* -4 a) c (* b b))) (sqrt (fma (* -4 a) c (* b b)))))
165.0ms
(- (pow (- b) 3) (pow (sqrt (fma (* -4 a) c (* b b))) 3))
98.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))

prune1.4s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 5.1b

localize17.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma (* a -4) c (* b b)))
0.9b
(- (- b) (sqrt (fma (* a -4) c (* b b))))
0.2b
(fma (* a -4) c (* b b))
0.1b
(/ (- (- b) (sqrt (fma (* a -4) c (* b b)))) (* 2 a))

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
4 → 100
Calls

4 calls. Slowest were:

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

series232.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

85.0ms
(/ (- (- b) (sqrt (fma (* a -4) c (* b b)))) (* 2 a))
59.0ms
(- (- b) (sqrt (fma (* a -4) c (* b b))))
54.0ms
(sqrt (fma (* a -4) c (* b b)))
34.0ms
(fma (* a -4) c (* b b))

simplify3.4s

Counts
93 → 112
Calls

93 calls. Slowest were:

343.0ms
(- (* (- b) (- b)) (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))))
215.0ms
(- (pow (- b) 3) (pow (sqrt (fma (* a -4) c (* b b))) 3))
95.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))

prune1.7s

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 5.1b

localize12.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma (* a -4) c (* b b)))
0.9b
(- (- b) (sqrt (fma (* a -4) c (* b b))))
0.2b
(fma (* a -4) c (* b b))
0.2b
(/ 1 (/ (* 2 a) (- (- b) (sqrt (fma (* a -4) c (* b b))))))

rewrite21.0ms

Algorithm
rewrite-expression-head
Counts
4 → 99
Calls

4 calls. Slowest were:

9.0ms
(- (- b) (sqrt (fma (* a -4) c (* b b))))
8.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (fma (* a -4) c (* b b))))))
2.0ms
(sqrt (fma (* a -4) c (* b b)))

series252.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

86.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (fma (* a -4) c (* b b))))))
72.0ms
(sqrt (fma (* a -4) c (* b b)))
61.0ms
(- (- b) (sqrt (fma (* a -4) c (* b b))))
33.0ms
(fma (* a -4) c (* b b))

simplify3.2s

Counts
86 → 111
Calls

86 calls. Slowest were:

413.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (* (- b) (sqrt (fma (* a -4) c (* b b))))))
74.0ms
(- (* 2 (/ (* a c) b)) (* 2 b))
70.0ms
(/ (* 2 a) (- (- b) (sqrt (fma (* a -4) c (* b b)))))

prune1.3s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 5.1b

localize16.0ms

Local error

Found 4 expressions with local error:

22.0b
(sqrt (fma (* a -4) c (* b b)))
0.9b
(- (- b) (sqrt (fma (* a -4) c (* b b))))
0.3b
(/ (/ 1 (* 2 a)) (/ 1 (- (- b) (sqrt (fma (* a -4) c (* b b))))))
0.2b
(fma (* a -4) c (* b b))

rewrite46.0ms

Algorithm
rewrite-expression-head
Counts
4 → 123
Calls

4 calls. Slowest were:

32.0ms
(- (- b) (sqrt (fma (* a -4) c (* b b))))
10.0ms
(/ (/ 1 (* 2 a)) (/ 1 (- (- b) (sqrt (fma (* a -4) c (* b b))))))
2.0ms
(sqrt (fma (* a -4) c (* b b)))

series229.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

72.0ms
(sqrt (fma (* a -4) c (* b b)))
65.0ms
(/ (/ 1 (* 2 a)) (/ 1 (- (- b) (sqrt (fma (* a -4) c (* b b))))))
48.0ms
(fma (* a -4) c (* b b))
44.0ms
(- (- b) (sqrt (fma (* a -4) c (* b b))))

simplify10.5s

Counts
134 → 135
Calls

134 calls. Slowest were:

620.0ms
(/ 1 (/ 1 (- (* (- b) (- b)) (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))))))
570.0ms
(/ 1 (/ 1 (- (* (- b) (- b)) (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))))))
560.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (fma (* a -4) c (* b b))) (sqrt (fma (* a -4) c (* b b)))) (* (- b) (sqrt (fma (* a -4) c (* b b))))))

prune1.6s

Pruning

10 alts after pruning (8 fresh and 2 done)

Merged error: 5.1b

regimes404.0ms

Accuracy

85.3% (4.1b remaining)

Error of 9.6b against oracle of 5.5b and baseline of 33.2b

bsearch734.0ms

end0.0ms

sample4.9s

Algorithm
intervals