Average Error: 34.2 → 6.3
Time: 19.6s
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 -8.422430181155895 \cdot 10^{+146}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -1.347277676039659 \cdot 10^{-308}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 4.331216038455128 \cdot 10^{+110}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \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

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

Derivation

  1. Split input into 4 regimes
  2. if b < -8.422430181155895e+146

    1. Initial program 57.7

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

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

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

    if -8.422430181155895e+146 < b < -1.347277676039659e-308

    1. Initial program 8.4

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

      \[\leadsto \frac{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} - b}{2 \cdot a}\]
    3. Taylor expanded around 0 8.4

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

    if -1.347277676039659e-308 < b < 4.331216038455128e+110

    1. Initial program 33.8

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

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

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

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

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

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

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

    if 4.331216038455128e+110 < b

    1. Initial program 59.2

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -8.422430181155895 \cdot 10^{+146}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -1.347277676039659 \cdot 10^{-308}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 4.331216038455128 \cdot 10^{+110}:\\ \;\;\;\;\frac{c \cdot -2}{b + \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2018360 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

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

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

Details

Time bar (total: 13.8s)Debug log

start163.0ms

Algorithm
intervals

setup394.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.6b

localize22.0ms

Local error

Found 4 expressions with local error:

22.5b
(sqrt (- (* b b) (* (* c a) 4)))
0.9b
(- (sqrt (- (* b b) (* (* c a) 4))) b)
0.4b
(- (* b b) (* (* c a) 4))
0.1b
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))

rewrite41.0ms

Algorithm
rewrite-expression-head
Counts
4 → 59
Calls

4 calls. Slowest were:

25.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
11.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
2.0ms
(- (* b b) (* (* c a) 4))

series240.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

72.0ms
(- (sqrt (- (* b b) (* (* c a) 4))) b)
69.0ms
(sqrt (- (* b b) (* (* c a) 4)))
68.0ms
(/ (- (sqrt (- (* b b) (* (* c a) 4))) b) (* 2 a))
30.0ms
(- (* b b) (* (* c a) 4))

simplify1.6s

Counts
32 → 71
Calls

32 calls. Slowest were:

241.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))
188.0ms
(- (pow (sqrt (- (* b b) (* (* c a) 4))) 3) (pow b 3))
146.0ms
(- (* (sqrt (- (* b b) (* (* c a) 4))) (sqrt (- (* b b) (* (* c a) 4)))) (* b b))

prune1.0s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 4.8b

localize16.0ms

Local error

Found 4 expressions with local error:

22.5b
(sqrt (- (* b b) (* (* c a) 4)))
13.3b
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
0.8b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.4b
(- (* b b) (* (* c a) 4))

rewrite30.0ms

Algorithm
rewrite-expression-head
Counts
4 → 55
Calls

4 calls. Slowest were:

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

series304.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

139.0ms
(/ (* (* c -4) a) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)))
71.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
68.0ms
(sqrt (- (* b b) (* (* c a) 4)))
26.0ms
(- (* b b) (* (* c a) 4))

simplify3.0s

Counts
29 → 67
Calls

29 calls. Slowest were:

789.0ms
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b)) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b))) (* (* 2 a) (+ (sqrt (- (* b b) (* (* c a) 4))) b))))
684.0ms
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* (* 2 a) (* 2 a)) (* 2 a)) (* (* (+ (sqrt (- (* b b) (* (* c a) 4))) b) (+ (sqrt (- (* b b) (* (* c a) 4))) b)) (+ (sqrt (- (* b b) (* (* c a) 4))) b))))
363.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))

prune894.0ms

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 4.7b

localize6.0ms

Local error

Found 4 expressions with local error:

22.5b
(sqrt (- (* b b) (* (* c a) 4)))
12.4b
(/ (* (* c -4) a) (* 2 a))
0.8b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.4b
(- (* b b) (* (* c a) 4))

rewrite18.0ms

Algorithm
rewrite-expression-head
Counts
4 → 51
Calls

4 calls. Slowest were:

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

series128.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

50.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
46.0ms
(sqrt (- (* b b) (* (* c a) 4)))
28.0ms
(- (* b b) (* (* c a) 4))
5.0ms
(/ (* (* c -4) a) (* 2 a))

simplify1.6s

Counts
24 → 63
Calls

24 calls. Slowest were:

444.0ms
(/ (* (* (* (* c -4) a) (* (* c -4) a)) (* (* c -4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
289.0ms
(- (log (* (* c -4) a)) (log (* 2 a)))
277.0ms
(sqrt (- (pow (* b b) 3) (pow (* (* c a) 4) 3)))

prune830.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 4.7b

localize12.0ms

Local error

Found 4 expressions with local error:

22.5b
(sqrt (- (* b b) (* (* c a) 4)))
0.8b
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
0.4b
(- (* b b) (* (* c a) 4))
0.1b
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* c a) 4))) b))

rewrite25.0ms

Algorithm
rewrite-expression-head
Counts
4 → 57
Calls

4 calls. Slowest were:

11.0ms
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* c a) 4))) b))
8.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
2.0ms
(- (* b b) (* (* c a) 4))

series273.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

118.0ms
(/ (* -2 c) (+ (sqrt (- (* b b) (* (* c a) 4))) b))
59.0ms
(sqrt (- (* b b) (* (* c a) 4)))
54.0ms
(+ (sqrt (- (* b b) (* (* c a) 4))) b)
41.0ms
(- (* b b) (* (* c a) 4))

simplify1.5s

Counts
32 → 69
Calls

32 calls. Slowest were:

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

prune742.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 4.7b

regimes327.0ms

Accuracy

96.6% (0.8b remaining)

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

bsearch532.0ms