Average Error: 33.8 → 6.5
Time: 21.3s
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 -7.170102184885046 \cdot 10^{+152}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 7.1019336895705 \cdot 10^{-310}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\left(c \cdot a\right) \cdot -4 + b \cdot b} - b}\\ \mathbf{elif}\;b \le 5.212862281681239 \cdot 10^{+99}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\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.8
Target21.1
Herbie6.5
\[\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 < -7.170102184885046e+152

    1. Initial program 62.8

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

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

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

    if -7.170102184885046e+152 < b < 7.1019336895705e-310

    1. Initial program 33.7

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

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

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

      \[\leadsto \frac{\color{blue}{\left(c \cdot 4\right) \cdot a}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\]
    6. Using strategy rm
    7. Applied associate-/r*14.1

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

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

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

    if 7.1019336895705e-310 < b < 5.212862281681239e+99

    1. Initial program 9.0

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

    if 5.212862281681239e+99 < b

    1. Initial program 45.2

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

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

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

      \[\leadsto \frac{\color{blue}{\left(c \cdot 4\right) \cdot a}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\]
    6. Using strategy rm
    7. Applied associate-/r*61.9

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    11. Simplified3.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.170102184885046 \cdot 10^{+152}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 7.1019336895705 \cdot 10^{-310}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{\left(c \cdot a\right) \cdot -4 + b \cdot b} - b}\\ \mathbf{elif}\;b \le 5.212862281681239 \cdot 10^{+99}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Reproduce

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

sample152.0ms

Algorithm
intervals

simplify67.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune6.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.2b

localize24.0ms

Local error

Found 4 expressions with local error:

24.5b
(sqrt (- (* b b) (* 4 (* a c))))
1.7b
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
1.2b
(- (* b b) (* 4 (* a c)))
0.1b
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))

rewrite28.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

18.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)))

series181.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

52.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
49.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
40.0ms
(- (* b b) (* 4 (* a c)))
40.0ms
(sqrt (- (* b b) (* 4 (* a c))))

simplify2.3s

Counts
46 → 82
Calls

46 calls. Slowest were:

297.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
181.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
155.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))

prune989.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 6.4b

localize23.0ms

Local error

Found 4 expressions with local error:

24.5b
(sqrt (- (* b b) (* 4 (* a c))))
16.8b
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
1.5b
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
1.2b
(- (* b b) (* 4 (* a c)))

rewrite49.0ms

Algorithm
rewrite-expression-head
Counts
4 → 58
Calls

4 calls. Slowest were:

23.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
11.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
9.0ms
(sqrt (- (* b b) (* 4 (* a c))))

series339.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

172.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
72.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
63.0ms
(sqrt (- (* b b) (* 4 (* a c))))
32.0ms
(- (* b b) (* 4 (* a c)))

simplify3.4s

Counts
31 → 70
Calls

31 calls. Slowest were:

825.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* (* 2 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))))))))
801.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))) (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))))))
284.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))

prune892.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 6.3b

localize16.0ms

Local error

Found 4 expressions with local error:

24.5b
(sqrt (+ (* -4 (* a c)) (* b b)))
16.1b
(/ (* (* c 4) a) (* 2 a))
1.5b
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
1.2b
(+ (* -4 (* a c)) (* b b))

rewrite25.0ms

Algorithm
rewrite-expression-head
Counts
4 → 51
Calls

4 calls. Slowest were:

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

series169.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

55.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))
54.0ms
(+ (* -4 (* a c)) (* b b))
52.0ms
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
8.0ms
(/ (* (* c 4) a) (* 2 a))

simplify2.0s

Counts
24 → 63
Calls

24 calls. Slowest were:

768.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
627.0ms
(- (log (* (* c 4) a)) (log (* 2 a)))
224.0ms
(sqrt (- (* (* -4 (* a c)) (* -4 (* a c))) (* (* b b) (* b b))))

prune752.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 6.3b

localize15.0ms

Local error

Found 4 expressions with local error:

24.5b
(sqrt (+ (* -4 (* a c)) (* b b)))
1.5b
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
1.2b
(+ (* -4 (* a c)) (* b b))
0.1b
(/ (* 2 c) (- (sqrt (+ (* -4 (* a c)) (* b b))) b))

rewrite57.0ms

Algorithm
rewrite-expression-head
Counts
4 → 57
Calls

4 calls. Slowest were:

25.0ms
(/ (* 2 c) (- (sqrt (+ (* -4 (* a c)) (* b b))) b))
22.0ms
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
5.0ms
(+ (* -4 (* a c)) (* b b))

series344.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

166.0ms
(/ (* 2 c) (- (sqrt (+ (* -4 (* a c)) (* b b))) b))
71.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))
57.0ms
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
50.0ms
(+ (* -4 (* a c)) (* b b))

simplify1.5s

Counts
32 → 69
Calls

32 calls. Slowest were:

556.0ms
(/ (* (* (* 2 c) (* 2 c)) (* 2 c)) (* (* (- (sqrt (+ (* -4 (* a c)) (* b b))) b) (- (sqrt (+ (* -4 (* a c)) (* b b))) b)) (- (sqrt (+ (* -4 (* a c)) (* b b))) b)))
210.0ms
(sqrt (- (* (* -4 (* a c)) (* -4 (* a c))) (* (* b b) (* b b))))
184.0ms
(sqrt (+ (pow (* -4 (* a c)) 3) (pow (* b b) 3)))

prune772.0ms

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 6.3b

regimes431.0ms

Accuracy

96.1% (1.0b remaining)

Error of 6.5b against oracle of 5.5b and baseline of 29.8b

bsearch992.0ms

end0.0ms

sample4.7s

Algorithm
intervals