Average Error: 33.8 → 6.5
Time: 22.9s
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}^{2} - \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 62.8

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. 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}\]
    2. Taylor expanded around inf 9.0

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - 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. Taylor expanded around 0 3.3

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    7. 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}^{2} - \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 "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: 22.1s)Debug log

sample158.0ms

Algorithm
intervals

simplify108.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune7.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 34.2b

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

rewrite57.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

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

series218.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

68.0ms
(sqrt (- (* b b) (* 4 (* a c))))
65.0ms
(/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a))
57.0ms
(- (- b) (sqrt (- (* b b) (* 4 (* a c)))))
28.0ms
(- (* b b) (* 4 (* a c)))

simplify2.8s

Counts
46 → 82
Calls

46 calls. Slowest were:

302.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))
298.0ms
(- (* (- b) (- b)) (* (sqrt (- (* b b) (* 4 (* a c)))) (sqrt (- (* b b) (* 4 (* a c))))))
244.0ms
(- (pow (- b) 3) (pow (sqrt (- (* b b) (* 4 (* a c)))) 3))

prune1.0s

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 6.4b

localize31.0ms

Local error

Found 4 expressions with local error:

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

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

series194.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

72.0ms
(/ (- (- b) (sqrt (- (pow b 2) (* 4 (* a c))))) (* 2 a))
56.0ms
(- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))
42.0ms
(sqrt (- (pow b 2) (* 4 (* a c))))
25.0ms
(- (pow b 2) (* 4 (* a c)))

simplify3.7s

Counts
46 → 82
Calls

46 calls. Slowest were:

930.0ms
(- (* (- b) (- b)) (* (sqrt (- (pow b 2) (* 4 (* a c)))) (sqrt (- (pow b 2) (* 4 (* a c))))))
403.0ms
(/ (sqrt (- (- b) (sqrt (- (pow b 2) (* 4 (* a c)))))) a)
371.0ms
(sqrt (- (pow (pow b 2) 3) (pow (* 4 (* a c)) 3)))

prune1.0s

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 6.4b

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

rewrite22.0ms

Algorithm
rewrite-expression-head
Counts
4 → 58
Calls

4 calls. Slowest were:

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

series274.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

142.0ms
(/ (* (* c 4) a) (* (* 2 a) (+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))))
53.0ms
(sqrt (- (* b b) (* 4 (* a c))))
44.0ms
(+ (- b) (sqrt (- (* b b) (* 4 (* a c)))))
35.0ms
(- (* b b) (* 4 (* a c)))

simplify3.0s

Counts
31 → 70
Calls

31 calls. Slowest were:

685.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))))))))
676.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))))))))
303.0ms
(sqrt (- (pow (* b b) 3) (pow (* 4 (* a c)) 3)))

prune741.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 6.3b

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

rewrite28.0ms

Algorithm
rewrite-expression-head
Counts
4 → 51
Calls

4 calls. Slowest were:

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

series171.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

70.0ms
(sqrt (+ (* -4 (* a c)) (* b b)))
50.0ms
(- (sqrt (+ (* -4 (* a c)) (* b b))) b)
44.0ms
(+ (* -4 (* a c)) (* b b))
8.0ms
(/ (* (* c 4) a) (* 2 a))

simplify2.0s

Counts
24 → 63
Calls

24 calls. Slowest were:

802.0ms
(/ (* (* (* (* c 4) a) (* (* c 4) a)) (* (* c 4) a)) (* (* (* 2 a) (* 2 a)) (* 2 a)))
603.0ms
(- (log (* (* c 4) a)) (log (* 2 a)))
201.0ms
(sqrt (- (* (* -4 (* a c)) (* -4 (* a c))) (* (* b b) (* b b))))

prune793.0ms

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 6.3b

regimes213.0ms

Accuracy

96.1% (1.0b remaining)

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

bsearch621.0ms

end0.0ms

sample4.7s

Algorithm
intervals