Average Error: 33.3 → 9.7
Time: 25.1s
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 -1.7715196556134555 \cdot 10^{+46}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.1090157738250754 \cdot 10^{-76}:\\ \;\;\;\;\frac{\left(a \cdot c\right) \cdot 4}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{{b}^{2} - \left(a \cdot c\right) \cdot 4}\right)}\\ \mathbf{elif}\;b \le 5.973421650485517 \cdot 10^{+105}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - \left(a \cdot c\right) \cdot 4}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.3
Target20.4
Herbie9.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 < -1.7715196556134555e+46

    1. Initial program 56.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 56.2

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

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

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

    if -1.7715196556134555e+46 < b < -1.1090157738250754e-76

    1. Initial program 42.2

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 42.2

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

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

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

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

    if -1.1090157738250754e-76 < b < 5.973421650485517e+105

    1. Initial program 13.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around -inf 13.0

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

    if 5.973421650485517e+105 < b

    1. Initial program 46.5

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Taylor expanded around inf 3.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.7715196556134555 \cdot 10^{+46}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.1090157738250754 \cdot 10^{-76}:\\ \;\;\;\;\frac{\left(a \cdot c\right) \cdot 4}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{{b}^{2} - \left(a \cdot c\right) \cdot 4}\right)}\\ \mathbf{elif}\;b \le 5.973421650485517 \cdot 10^{+105}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - \left(a \cdot c\right) \cdot 4}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Reproduce

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

sample132.0ms

Algorithm
intervals

simplify101.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune6.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 32.3b

localize27.0ms

Local error

Found 4 expressions with local error:

22.2b
(sqrt (- (* b b) (* 4 (* a c))))
1.9b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.6b
(- (* b b) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

rewrite26.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

15.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
5.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
2.0ms
(- (* b b) (* 4 (* a c)))

series250.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

87.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
71.0ms
(sqrt (- (* b b) (* 4 (* a c))))
62.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
30.0ms
(- (* b b) (* 4 (* a c)))

simplify2.8s

Counts
46 → 82
Calls

46 calls. Slowest were:

332.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
332.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
282.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))

prune950.0ms

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 5.0b

localize14.0ms

Local error

Found 4 expressions with local error:

22.2b
(sqrt (- (pow b 2) (* 4 (* a c))))
1.9b
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
0.6b
(- (pow b 2) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))

rewrite33.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

19.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
7.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
3.0ms
(- (pow b 2) (* 4 (* a c)))

series228.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

67.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
64.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
55.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
41.0ms
(- (pow b 2) (* 4 (* a c)))

simplify4.0s

Counts
46 → 82
Calls

46 calls. Slowest were:

1.3s
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
404.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))
275.0ms
(- (pow (- b) 3) (pow (sqrt (- (pow b 2) (* 4 (* a c)))) 3))

prune915.0ms

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 5.0b

localize12.0ms

Local error

Found 4 expressions with local error:

22.2b
(sqrt (- (* b b) (* 4 (* a c))))
1.9b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
0.6b
(- (* b b) (* 4 (* a c)))
0.2b
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (* b b) (* 4 (* a c)))))))

rewrite32.0ms

Algorithm
rewrite-expression-head
Counts
4 → 69
Calls

4 calls. Slowest were:

12.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
11.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
4.0ms
(- (* b b) (* 4 (* a c)))

series238.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

88.0ms
(/ 1 (/ (* 2 a) (- (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
66.0ms
(sqrt (- (* b b) (* 4 (* a c))))
55.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
28.0ms
(- (* b b) (* 4 (* a c)))

simplify2.5s

Counts
39 → 81
Calls

39 calls. Slowest were:

395.0ms
(+ (* (- b) (- b)) (+ (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))) (* (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
370.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
187.0ms
(sqrt (- (* (* b b) (* b b)) (* (* 4 (* a c)) (* 4 (* a c)))))

prune920.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 5.0b

localize26.0ms

Local error

Found 4 expressions with local error:

22.2b
(sqrt (- (pow b 2) (* 4 (* a c))))
15.4b
(/ (* (* c a) 4) (* (* 2 a) (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))
1.3b
(+ (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
0.6b
(- (pow b 2) (* 4 (* a c)))

rewrite38.0ms

Algorithm
rewrite-expression-head
Counts
4 → 58
Calls

4 calls. Slowest were:

19.0ms
(/ (* (* c a) 4) (* (* 2 a) (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))
10.0ms
(+ (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
5.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))

series343.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

177.0ms
(/ (* (* c a) 4) (* (* 2 a) (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))))
61.0ms
(+ (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
61.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
44.0ms
(- (pow b 2) (* 4 (* a c)))

simplify4.1s

Counts
31 → 70
Calls

31 calls. Slowest were:

982.0ms
(/ (* (* (* (* c a) 4) (* (* c a) 4)) (* (* c a) 4)) (* (* (* (* 2 a) (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))) (* (* 2 a) (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c))))))) (* (* 2 a) (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c))))))))
959.0ms
(/ (* (* (* (* c a) 4) (* (* c a) 4)) (* (* c a) 4)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))) (+ (- b) (sqrt (- (pow b 2) (* 4 (* a c))))))))
434.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))

prune1.1s

Pruning

7 alts after pruning (4 fresh and 3 done)

Merged error: 5.0b

regimes339.0ms

Accuracy

85.3% (4.1b remaining)

Error of 9.7b against oracle of 5.7b and baseline of 33.3b

bsearch478.0ms

end0.0ms

sample4.7s

Algorithm
intervals